diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/tess')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java | 45 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/tess/Loop.java | 6 |
2 files changed, 24 insertions, 27 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java index f0910c465..a82c2ee7a 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -29,7 +29,7 @@ package jogamp.graph.curve.tess; import java.util.ArrayList; - +import java.util.List; import com.jogamp.graph.curve.tess.Triangulator; import com.jogamp.graph.geom.Outline; @@ -48,11 +48,10 @@ public class CDTriangulator2D implements Triangulator{ protected static final boolean DEBUG = Debug.debug("Triangulation"); - private float sharpness = 0.5f; + private final float sharpness = 0.5f; private ArrayList<Loop> loops; - private ArrayList<Vertex> vertices; + // FIXME ? private ArrayList<Vertex> vertices; - private ArrayList<Triangle> triangles; private int maxTriID = 0; @@ -68,13 +67,12 @@ public class CDTriangulator2D implements Triangulator{ @Override public void reset() { maxTriID = 0; - vertices = new ArrayList<Vertex>(); - triangles = new ArrayList<Triangle>(3); + // vertices = new ArrayList<Vertex>(); loops = new ArrayList<Loop>(); } @Override - public void addCurve(Outline polyline) { + public void addCurve(List<Triangle> sink, Outline polyline) { Loop loop = null; if(!loops.isEmpty()) { @@ -82,27 +80,27 @@ public class CDTriangulator2D implements Triangulator{ } if(loop == null) { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, false); - vertices.addAll(polyline.getVertices()); + final GraphOutline outline = new GraphOutline(polyline); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false); + // vertices.addAll(polyline.getVertices()); loop = new Loop(innerPoly, VectorUtil.Winding.CCW); loops.add(loop); } else { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, true); - vertices.addAll(innerPoly.getVertices()); + final GraphOutline outline = new GraphOutline(polyline); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true); + // vertices.addAll(innerPoly.getVertices()); loop.addConstraintCurve(innerPoly); } } @Override - public ArrayList<Triangle> generate() { + public void generate(List<Triangle> sink) { for(int i=0;i<loops.size();i++) { Loop loop = loops.get(i); int numTries = 0; int size = loop.computeLoopSize(); while(!loop.isSimplex()){ - Triangle tri = null; + final Triangle tri; if(numTries > size){ tri = loop.cut(false); } @@ -115,7 +113,7 @@ public class CDTriangulator2D implements Triangulator{ numTries = 0; size--; tri.setId(maxTriID++); - triangles.add(tri); + sink.add(tri); if(DEBUG){ System.err.println(tri); } @@ -127,15 +125,14 @@ public class CDTriangulator2D implements Triangulator{ break; } } - Triangle tri = loop.cut(true); + final Triangle tri = loop.cut(true); if(tri != null) { - triangles.add(tri); + sink.add(tri); } } - return triangles; } - private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole) { + private GraphOutline extractBoundaryTriangles(List<Triangle> sink, GraphOutline outline, boolean hole) { GraphOutline innerOutline = new GraphOutline(); ArrayList<GraphVertex> outVertices = outline.getGraphPoint(); int size = outVertices.size(); @@ -146,9 +143,9 @@ public class CDTriangulator2D implements Triangulator{ GraphVertex gv1 = currentVertex; if(!currentVertex.getPoint().isOnCurve()) { - Vertex v0 = gv0.getPoint().clone(); - Vertex v2 = gv2.getPoint().clone(); - Vertex v1 = gv1.getPoint().clone(); + final Vertex v0 = gv0.getPoint().clone(); + final Vertex v2 = gv2.getPoint().clone(); + final Vertex v1 = gv1.getPoint().clone(); gv0.setBoundaryContained(true); gv1.setBoundaryContained(true); @@ -164,7 +161,7 @@ public class CDTriangulator2D implements Triangulator{ t = new Triangle(v2, v1, v0); } t.setId(maxTriID++); - triangles.add(t); + sink.add(t); if(DEBUG){ System.err.println(t); } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index c1dafc0d1..5810e3bc9 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -37,7 +37,7 @@ import com.jogamp.opengl.math.geom.AABBox; public class Loop { private HEdge root = null; - private AABBox box = new AABBox(); + private final AABBox box = new AABBox(); private GraphOutline initialOutline = null; public Loop(GraphOutline polyline, VectorUtil.Winding winding){ @@ -272,13 +272,13 @@ public class Loop { * @return the triangle iff it satisfies, null otherwise */ private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){ - Triangle t = new Triangle(v1, v2, v3); + final Triangle t = new Triangle(v1, v2, v3); t.setVerticesBoundary(checkVerticesBoundary(rootT)); return t; } private boolean[] checkVerticesBoundary(HEdge rootT) { - boolean[] boundary = new boolean[3]; + final boolean[] boundary = new boolean[3]; HEdge e1 = rootT; HEdge e2 = rootT.getNext(); HEdge e3 = rootT.getNext().getNext(); |