diff options
7 files changed, 44 insertions, 94 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index 7f8e386a1..5b94d6bda 100755 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -394,7 +394,8 @@ public class OutlineShape implements Comparable<OutlineShape> { int maxVertexId = 0;
for(int i=0; i<outlines.size(); i++) {
final ArrayList<Vertex> vertices = outlines.get(i).getVertices();
- for(Vertex vert:vertices){
+ for(int pos=0; pos<vertices.size(); pos++) {
+ Vertex vert = vertices.get(pos);
vert.setId(maxVertexId);
maxVertexId++;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index 20b4d61a1..c6165b6b3 100755 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -60,14 +60,16 @@ public abstract class GLRegion extends Region { int numVertices = region.getNumVertices();
- for(OutlineShape outlineShape:outlineShapes){
+ for(int index=0; index<outlineShapes.length; index++) {
+ OutlineShape outlineShape = outlineShapes[index];
outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
ArrayList<Triangle> triangles = outlineShape.triangulate();
region.addTriangles(triangles);
ArrayList<Vertex> vertices = outlineShape.getVertices();
- for(Vertex vert:vertices){
+ for(int pos=0; pos < vertices.size(); pos++){
+ Vertex vert = vertices.get(pos);
vert.setId(numVertices++);
}
region.addVertices(vertices);
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java index 4c1ea3fe6..fce2e1bae 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -83,22 +83,17 @@ public class CDTriangulator2D { // FIXME: multiple in/out and CW/CCW tests (as follows) ?? if(!loops.isEmpty()) { - // FIXME: #1 in/out test loop = getContainerLoop(polyline); } if(loop == null) { - // Claim: CCW (out) GraphOutline outline = new GraphOutline(polyline); - // FIXME: #2/#3 extract..(CCW) and new Loop(CCW).. does CW/CCW tests GraphOutline innerPoly = extractBoundaryTriangles(outline, false); vertices.addAll(polyline.getVertices()); loop = new Loop(innerPoly, VectorUtil.Winding.CCW); loops.add(loop); } else { - // Claim: CW (in) GraphOutline outline = new GraphOutline(polyline); - // FIXME: #3/#4 extract..(CW) and addContraint..(CW) does CW/CCW tests GraphOutline innerPoly = extractBoundaryTriangles(outline, true); vertices.addAll(innerPoly.getVertices()); loop.addConstraintCurve(innerPoly); @@ -200,14 +195,17 @@ public class CDTriangulator2D { return innerOutline; } - private Loop getContainerLoop(Outline polyline){ + private Loop getContainerLoop(Outline polyline) { ArrayList<Vertex> vertices = polyline.getVertices(); - // FIXME: remove implicit iterator - for(Vertex vert: vertices){ - for (Loop loop:loops){ - if(loop.checkInside(vert)){ - return loop; - } + for(int i=0; i < loops.size(); i++) { + Loop loop = loops.get(i); + boolean inside = false; + for(int j=0; j < vertices.size(); j++) { + Vertex v = vertices.get(j); + inside |= loop.checkInside(v); + } + if(inside) { + return loop; } } return null; diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java index d1245f4b8..c8251af15 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java @@ -47,8 +47,8 @@ public class GraphOutline { public GraphOutline(Outline ol){ this.outline = ol; ArrayList<Vertex> vertices = this.outline.getVertices(); - for(Vertex v:vertices){ - this.controlpoints.add(new GraphVertex(v)); + for(int i = 0; i< vertices.size(); i++){ + this.controlpoints.add(new GraphVertex(vertices.get(i))); } } @@ -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/GraphVertex.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java index 5efe57c28..52d02baa5 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java @@ -86,7 +86,8 @@ public class GraphVertex { } } public HEdge findNextEdge(GraphVertex nextVert){ - for(HEdge e:edges){ + for(int i=0; i<edges.size(); i++) { + HEdge e = edges.get(i); if(e.getNext().getGraphPoint() == nextVert){ return e; } @@ -94,7 +95,8 @@ public class GraphVertex { return null; } public HEdge findBoundEdge(){ - for(HEdge e:edges){ + for(int i=0; i<edges.size(); i++) { + HEdge e = edges.get(i); if((e.getType() == HEdge.BOUNDARY) || (e.getType() == HEdge.HOLE)){ return e; } @@ -102,7 +104,8 @@ public class GraphVertex { return null; } public HEdge findPrevEdge(GraphVertex prevVert){ - for(HEdge e:edges){ + for(int i=0; i<edges.size(); i++) { + HEdge e = edges.get(i); if(e.getPrev().getGraphPoint() == prevVert){ return e; } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index acccea503..b4b796b51 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -102,18 +102,14 @@ 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(), vertices.get(2).getPoint()); - // isCCW && (reqWinding == VectorUtil.CW); - // skips inversion CW -> CCW ? + //FIXME: handle case when vertices come inverted - Rami + // skips inversion CW -> CCW final boolean invert = hasWinding != reqWinding && reqWinding == VectorUtil.Winding.CW; - if( hasWinding != reqWinding ) { - System.err.println("Winding: i "+invert+" "+hasWinding+" -> "+reqWinding); - } final int max; final int edgeType = reqWinding == VectorUtil.Winding.CCW ? HEdge.BOUNDARY : HEdge.HOLE ; @@ -202,7 +198,8 @@ public class Loop { for(int i=0; i< initVertices.size()-1; i++){ GraphVertex v = initVertices.get(i); GraphVertex nextV = initVertices.get(i+1); - for(GraphVertex cand:vertices){ + for(int pos=0; pos<vertices.size(); pos++) { + GraphVertex cand = vertices.get(pos); float distance = VectorUtil.computeLength(v.getCoord(), cand.getCoord()); if(distance < minDistance){ for (GraphVertex vert:vertices){ @@ -298,74 +295,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; - } + do { + Vertex v2 = current.getGraphPoint().getPoint(); + Vertex v1 = next.getGraphPoint().getPoint(); - float s = VectorUtil.dot(prep_d1,p0p1)/dotD1D0; - float t = VectorUtil.dot(prep_d0,p0p1)/dotD1D0; - - 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; diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java index b47612f51..ed51cce98 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java @@ -80,6 +80,7 @@ public class GlyphShape { private void addOutlineVerticesFromGlyphVector(float[] coords, int segmentType){ switch(segmentType) { case PathIterator.SEG_MOVETO: + shape.closeLastOutline(); shape.addEmptyOutline(); addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); numVertices++; |