diff options
author | Rami Santina <[email protected]> | 2011-05-21 15:35:37 +0300 |
---|---|---|
committer | Rami Santina <[email protected]> | 2011-05-21 15:35:37 +0300 |
commit | 9e599f84bc02ef2db63b6eb1cadfa33f56dddd66 (patch) | |
tree | 64326af6d103c06ebe0a181aa236d9ae929b186e /src/jogl/classes/jogamp/graph | |
parent | 23163408131b077362439ec4f898d0ad3ce084e1 (diff) |
Fix: vertex in loop test; using crossing method
Changed algo for in/out test of vertex wrt arbitrary polygon
to crossing test since angle based is shown prune to precision errors
Diffstat (limited to 'src/jogl/classes/jogamp/graph')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java | 9 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/tess/Loop.java | 74 |
2 files changed, 15 insertions, 68 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java index d1245f4b8..6a2f47c79 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java @@ -56,11 +56,6 @@ public class GraphOutline { return outline; } - /*public void setOutline(Outline<T> outline) { - this.outline = outline; - }*/ - - public ArrayList<GraphVertex> getGraphPoint() { return controlpoints; } @@ -69,10 +64,6 @@ public class GraphOutline { return outline.getVertices(); } - /*public void setControlpoints(ArrayList<GraphPoint<T>> controlpoints) { - this.controlpoints = controlpoints; - }*/ - public void addVertex(GraphVertex v) { controlpoints.add(v); outline.addVertex(v.getPoint()); diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index acccea503..a511ed26e 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -102,7 +102,6 @@ public class Loop { if(vertices.size()<3) { throw new IllegalArgumentException("outline's vertices < 3: " + vertices.size()); } - //final VectorUtil.Winding hasWinding = VectorUtil.getWinding(outline.getVertices()); final VectorUtil.Winding hasWinding = VectorUtil.getWinding( vertices.get(0).getPoint(), vertices.get(1).getPoint(), @@ -298,74 +297,31 @@ public class Loop { return boundary; } - - /** Check if vertex inside the Loop - * @param vertex the Vertex - * @return true if the vertex is inside, false otherwise - */ - public boolean checkInside(Vertex vertex) { - if(!box.contains(vertex.getX(), vertex.getY(), vertex.getZ())){ + public boolean checkInside(Vertex v) { + if(!box.contains(v.getX(), v.getY(), v.getZ())){ return false; } - float[] center = box.getCenter(); - - int hits = 0; + boolean inside = false; HEdge current = root; HEdge next = root.getNext(); - while(next!= root){ - if(current.getType() == HEdge.INNER || next.getType() == HEdge.INNER){ - current = next; - next = current.getNext(); - continue; - } - Vertex vert1 = current.getGraphPoint().getPoint(); - Vertex vert2 = next.getGraphPoint().getPoint(); - - /** The ray is P0+s*D0, where P0 is the ray origin, D0 is a direction vector and s >= 0. - * The segment is P1+t*D1, where P1 and P1+D1 are the endpoints, and 0 <= t <= 1. - * perp(x,y) = (y,-x). - * if Dot(perp(D1),D0) is not zero, - * s = Dot(perp(D1),P1-P0)/Dot(perp(D1),D0) - * t = Dot(perp(D0),P1-P0)/Dot(perp(D1),D0) - */ - - float[] d0 = new float[]{center[0] - vertex.getX(), center[1]-vertex.getY(), - center[2]-vertex.getZ()}; - float[] d1 = {vert2.getX() - vert1.getX(), vert2.getY() - vert1.getY(), - vert2.getZ() - vert1.getZ()}; - - float[] prep_d1 = {d1[1],-1*d1[0], d1[2]}; - float[] prep_d0 = {d0[1],-1*d0[0], d0[2]}; - - float[] p0p1 = new float[]{vert1.getX() - vertex.getX(), vert1.getY() - vertex.getY(), - vert1.getZ() - vertex.getZ()}; - - float dotD1D0 = VectorUtil.dot(prep_d1, d0); - if(dotD1D0 == 0){ - /** ray parallel to segment */ - current = next; - next = current.getNext(); - continue; - } - - float s = VectorUtil.dot(prep_d1,p0p1)/dotD1D0; - float t = VectorUtil.dot(prep_d0,p0p1)/dotD1D0; + do { + Vertex v2 = current.getGraphPoint().getPoint(); + Vertex v1 = next.getGraphPoint().getPoint(); - if(s >= 0 && t >= 0 && t<= 1){ - hits++; + if ( ((v1.getY() > v.getY()) != (v2.getY() > v.getY())) && + (v.getX() < (v2.getX() - v1.getX()) * (v.getY() - v1.getY()) / (v2.getY() - v1.getY()) + v1.getX()) ){ + inside = !inside; } + current = next; next = current.getNext(); - } - - if(hits % 2 != 0){ - /** check if hit count is even */ - return true; - } - return false; + + } while(current != root); + + return inside; } - + public int computeLoopSize(){ int size = 0; HEdge e = root; |