From 630a9ea52b16da6badb31a98b70893f8d294b4e8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 30 Mar 2011 15:25:18 +0200 Subject: Remove generics notion of Type, since Vertex _is_ the lowest denominator for our implementation and curve API --- src/jogamp/graph/curve/tess/GraphOutline.java | 24 +++--- src/jogamp/graph/curve/tess/GraphVertex.java | 34 ++++---- src/jogamp/graph/curve/tess/HEdge.java | 43 +++++----- src/jogamp/graph/curve/tess/Loop.java | 114 +++++++++++++------------- 4 files changed, 106 insertions(+), 109 deletions(-) (limited to 'src/jogamp/graph/curve/tess') diff --git a/src/jogamp/graph/curve/tess/GraphOutline.java b/src/jogamp/graph/curve/tess/GraphOutline.java index bb262ce5b..5dae296e5 100644 --- a/src/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/jogamp/graph/curve/tess/GraphOutline.java @@ -32,27 +32,27 @@ import java.util.ArrayList; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Vertex; -public class GraphOutline { - final private Outline outline; - final private ArrayList> controlpoints = new ArrayList>(3); +public class GraphOutline { + final private Outline outline; + final private ArrayList controlpoints = new ArrayList(3); public GraphOutline(){ - this.outline = new Outline(); + this.outline = new Outline(); } /**Create a control polyline of control vertices * the curve pieces can be identified by onCurve flag * of each cp the control polyline is open by default */ - public GraphOutline(Outline ol){ + public GraphOutline(Outline ol){ this.outline = ol; - ArrayList vertices = this.outline.getVertices(); - for(T v:vertices){ - this.controlpoints.add(new GraphVertex(v)); + ArrayList vertices = this.outline.getVertices(); + for(Vertex v:vertices){ + this.controlpoints.add(new GraphVertex(v)); } } - public Outline getOutline() { + public Outline getOutline() { return outline; } @@ -61,11 +61,11 @@ public class GraphOutline { }*/ - public ArrayList> getGraphPoint() { + public ArrayList getGraphPoint() { return controlpoints; } - public ArrayList getPoints() { + public ArrayList getPoints() { return outline.getVertices(); } @@ -73,7 +73,7 @@ public class GraphOutline { this.controlpoints = controlpoints; }*/ - public void addVertex(GraphVertex v) { + public void addVertex(GraphVertex v) { controlpoints.add(v); outline.addVertex(v.getPoint()); } diff --git a/src/jogamp/graph/curve/tess/GraphVertex.java b/src/jogamp/graph/curve/tess/GraphVertex.java index a474a002e..b9f95a0e7 100644 --- a/src/jogamp/graph/curve/tess/GraphVertex.java +++ b/src/jogamp/graph/curve/tess/GraphVertex.java @@ -31,16 +31,16 @@ import java.util.ArrayList; import com.jogamp.graph.geom.Vertex; -public class GraphVertex { - private T point; - private ArrayList> edges = null; +public class GraphVertex { + private Vertex point; + private ArrayList edges = null; private boolean boundaryContained = false; - public GraphVertex(T point) { + public GraphVertex(Vertex point) { this.point = point; } - public T getPoint() { + public Vertex getPoint() { return point; } @@ -59,25 +59,25 @@ public class GraphVertex { return point.getCoord(); } - public void setPoint(T point) { + public void setPoint(Vertex point) { this.point = point; } - public ArrayList> getEdges() { + public ArrayList getEdges() { return edges; } - public void setEdges(ArrayList> edges) { + public void setEdges(ArrayList edges) { this.edges = edges; } - public void addEdge(HEdge edge){ + public void addEdge(HEdge edge){ if(edges == null){ - edges = new ArrayList>(); + edges = new ArrayList(); } edges.add(edge); } - public void removeEdge(HEdge edge){ + public void removeEdge(HEdge edge){ if(edges == null) return; edges.remove(edge); @@ -85,24 +85,24 @@ public class GraphVertex { edges = null; } } - public HEdge findNextEdge(GraphVertex nextVert){ - for(HEdge e:edges){ + public HEdge findNextEdge(GraphVertex nextVert){ + for(HEdge e:edges){ if(e.getNext().getGraphPoint() == nextVert){ return e; } } return null; } - public HEdge findBoundEdge(){ - for(HEdge e:edges){ + public HEdge findBoundEdge(){ + for(HEdge e:edges){ if((e.getType() == HEdge.BOUNDARY) || (e.getType() == HEdge.HOLE)){ return e; } } return null; } - public HEdge findPrevEdge(GraphVertex prevVert){ - for(HEdge e:edges){ + public HEdge findPrevEdge(GraphVertex prevVert){ + for(HEdge e:edges){ if(e.getPrev().getGraphPoint() == prevVert){ return e; } diff --git a/src/jogamp/graph/curve/tess/HEdge.java b/src/jogamp/graph/curve/tess/HEdge.java index 5635e2c31..d1bcc6e17 100644 --- a/src/jogamp/graph/curve/tess/HEdge.java +++ b/src/jogamp/graph/curve/tess/HEdge.java @@ -31,24 +31,24 @@ import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; -public class HEdge { +public class HEdge { public static int BOUNDARY = 3; public static int INNER = 1; public static int HOLE = 2; - private GraphVertex vert; - private HEdge prev = null; - private HEdge next = null; - private HEdge sibling = null; + private GraphVertex vert; + private HEdge prev = null; + private HEdge next = null; + private HEdge sibling = null; private int type = BOUNDARY; - private Triangle triangle = null; + private Triangle triangle = null; - public HEdge(GraphVertex vert, int type) { + public HEdge(GraphVertex vert, int type) { this.vert = vert; this.type = type; } - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type) { + public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type) { this.vert = vert; this.prev = prev; this.next = next; @@ -56,8 +56,7 @@ public class HEdge { this.type = type; } - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type, - Triangle triangle) { + public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type, Triangle triangle) { this.vert = vert; this.prev = prev; this.next = next; @@ -66,35 +65,35 @@ public class HEdge { this.triangle = triangle; } - public GraphVertex getGraphPoint() { + public GraphVertex getGraphPoint() { return vert; } - public void setVert(GraphVertex vert) { + public void setVert(GraphVertex vert) { this.vert = vert; } - public HEdge getPrev() { + public HEdge getPrev() { return prev; } - public void setPrev(HEdge prev) { + public void setPrev(HEdge prev) { this.prev = prev; } - public HEdge getNext() { + public HEdge getNext() { return next; } - public void setNext(HEdge next) { + public void setNext(HEdge next) { this.next = next; } - public HEdge getSibling() { + public HEdge getSibling() { return sibling; } - public void setSibling(HEdge sibling) { + public void setSibling(HEdge sibling) { this.sibling = sibling; } @@ -106,20 +105,20 @@ public class HEdge { this.type = type; } - public Triangle getTriangle() { + public Triangle getTriangle() { return triangle; } - public void setTriangle(Triangle triangle) { + public void setTriangle(Triangle triangle) { this.triangle = triangle; } - public static void connect(HEdge first, HEdge next){ + public static void connect(HEdge first, HEdge next){ first.setNext(next); next.setPrev(first); } - public static void makeSiblings(HEdge first, HEdge second){ + public static void makeSiblings(HEdge first, HEdge second){ first.setSibling(second); second.setSibling(first); } diff --git a/src/jogamp/graph/curve/tess/Loop.java b/src/jogamp/graph/curve/tess/Loop.java index 80b96b939..d2162bbeb 100644 --- a/src/jogamp/graph/curve/tess/Loop.java +++ b/src/jogamp/graph/curve/tess/Loop.java @@ -35,56 +35,55 @@ import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.math.VectorUtil; -public class Loop { - private HEdge root = null; +public class Loop { + private HEdge root = null; private AABBox box = new AABBox(); - private GraphOutline initialOutline = null; + private GraphOutline initialOutline = null; - public Loop(GraphOutline polyline, int direction){ + public Loop(GraphOutline polyline, int direction){ initialOutline = polyline; this.root = initFromPolyline(initialOutline, direction); } - public HEdge getHEdge(){ + public HEdge getHEdge(){ return root; } - public Triangle cut(boolean delaunay){ + public Triangle cut(boolean delaunay){ if(isSimplex()){ - @SuppressWarnings("unchecked") - Triangle t = new Triangle(root.getGraphPoint().getPoint(), root.getNext().getGraphPoint().getPoint(), + Triangle t = new Triangle(root.getGraphPoint().getPoint(), root.getNext().getGraphPoint().getPoint(), root.getNext().getNext().getGraphPoint().getPoint()); t.setVerticesBoundary(checkVerticesBoundary(root)); return t; } - HEdge prev = root.getPrev(); - HEdge next1 = root.getNext(); + HEdge prev = root.getPrev(); + HEdge next1 = root.getNext(); - HEdge next2 =findClosestValidNeighbor(next1.getNext(), delaunay); + HEdge next2 = findClosestValidNeighbor(next1.getNext(), delaunay); if(next2 == null){ root = root.getNext(); return null; } - GraphVertex v1 = root.getGraphPoint(); - GraphVertex v2 = next1.getGraphPoint(); - GraphVertex v3 = next2.getGraphPoint(); + GraphVertex v1 = root.getGraphPoint(); + GraphVertex v2 = next1.getGraphPoint(); + GraphVertex v3 = next2.getGraphPoint(); - HEdge v3Edge = new HEdge(v3, HEdge.INNER); + HEdge v3Edge = new HEdge(v3, HEdge.INNER); HEdge.connect(v3Edge, root); HEdge.connect(next1, v3Edge); - HEdge v3EdgeSib = v3Edge.getSibling(); + HEdge v3EdgeSib = v3Edge.getSibling(); if(v3EdgeSib == null){ - v3EdgeSib = new HEdge(v3Edge.getNext().getGraphPoint(), HEdge.INNER); + v3EdgeSib = new HEdge(v3Edge.getNext().getGraphPoint(), HEdge.INNER); HEdge.makeSiblings(v3Edge, v3EdgeSib); } HEdge.connect(prev, v3EdgeSib); HEdge.connect(v3EdgeSib, next2); - Triangle t = createTriangle(v1.getPoint(), v2.getPoint(), v3.getPoint(), root); + Triangle t = createTriangle(v1.getPoint(), v2.getPoint(), v3.getPoint(), root); this.root = next2; return t; } @@ -97,8 +96,8 @@ public class Loop { * from the boundary profile * @param direction requested winding of edges (CCW or CW) */ - private HEdge initFromPolyline(GraphOutline outline, int direction){ - ArrayList> vertices = outline.getGraphPoint(); + private HEdge initFromPolyline(GraphOutline outline, int direction){ + ArrayList vertices = outline.getGraphPoint(); if(vertices.size()<3) { throw new IllegalArgumentException("outline's vertices < 3: " + vertices.size()); @@ -107,8 +106,8 @@ public class Loop { vertices.get(2).getPoint()); boolean invert = isCCW && (direction == VectorUtil.CW); - HEdge firstEdge = null; - HEdge lastEdge = null; + HEdge firstEdge = null; + HEdge lastEdge = null; int index =0; int max = vertices.size(); @@ -120,10 +119,10 @@ public class Loop { } while(index != max){ - GraphVertex v1 = vertices.get(index); + GraphVertex v1 = vertices.get(index); box.resize(v1.getX(), v1.getY(), v1.getZ()); - HEdge edge = new HEdge(v1, edgeType); + HEdge edge = new HEdge(v1, edgeType); v1.addEdge(edge); if(lastEdge != null){ @@ -157,22 +156,22 @@ public class Loop { return firstEdge; } - public void addConstraintCurve(GraphOutline polyline) { + public void addConstraintCurve(GraphOutline polyline) { // GraphOutline outline = new GraphOutline(polyline); /**needed to generate vertex references.*/ initFromPolyline(polyline, VectorUtil.CW); - GraphVertex v3 = locateClosestVertex(polyline); - HEdge v3Edge = v3.findBoundEdge(); - HEdge v3EdgeP = v3Edge.getPrev(); - HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); + GraphVertex v3 = locateClosestVertex(polyline); + HEdge v3Edge = v3.findBoundEdge(); + HEdge v3EdgeP = v3Edge.getPrev(); + HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); HEdge.connect(root.getPrev(), crossEdge); HEdge.connect(crossEdge, v3Edge); - HEdge crossEdgeSib = crossEdge.getSibling(); + HEdge crossEdgeSib = crossEdge.getSibling(); if(crossEdgeSib == null) { - crossEdgeSib = new HEdge(crossEdge.getNext().getGraphPoint(), HEdge.INNER); + crossEdgeSib = new HEdge(crossEdge.getNext().getGraphPoint(), HEdge.INNER); HEdge.makeSiblings(crossEdge, crossEdgeSib); } @@ -186,22 +185,22 @@ public class Loop { * to search for closestvertices * @return the vertex that is closest to the newly set root Hedge. */ - private GraphVertex locateClosestVertex(GraphOutline polyline) { - HEdge closestE = null; - GraphVertex closestV = null; + private GraphVertex locateClosestVertex(GraphOutline polyline) { + HEdge closestE = null; + GraphVertex closestV = null; float minDistance = Float.MAX_VALUE; boolean inValid = false; - ArrayList> initVertices = initialOutline.getGraphPoint(); - ArrayList> vertices = polyline.getGraphPoint(); + ArrayList initVertices = initialOutline.getGraphPoint(); + ArrayList vertices = polyline.getGraphPoint(); for(int i=0; i< initVertices.size()-1; i++){ - GraphVertex v = initVertices.get(i); - GraphVertex nextV = initVertices.get(i+1); - for(GraphVertex cand:vertices){ + GraphVertex v = initVertices.get(i); + GraphVertex nextV = initVertices.get(i+1); + for(GraphVertex cand:vertices){ float distance = VectorUtil.computeLength(v.getCoord(), cand.getCoord()); if(distance < minDistance){ - for (GraphVertex vert:vertices){ + for (GraphVertex vert:vertices){ if(vert == v || vert == nextV || vert == cand) continue; inValid = VectorUtil.inCircle(v.getPoint(), nextV.getPoint(), @@ -227,20 +226,20 @@ public class Loop { return closestV; } - private HEdge findClosestValidNeighbor(HEdge edge, boolean delaunay) { - HEdge next = root.getNext(); + private HEdge findClosestValidNeighbor(HEdge edge, boolean delaunay) { + HEdge next = root.getNext(); if(!VectorUtil.ccw(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), edge.getGraphPoint().getPoint())){ return null; } - HEdge candEdge = edge; + HEdge candEdge = edge; boolean inValid = false; if(delaunay){ - T cand = candEdge.getGraphPoint().getPoint(); - HEdge e = candEdge.getNext(); + Vertex cand = candEdge.getGraphPoint().getPoint(); + HEdge e = candEdge.getNext(); while (e != candEdge){ if(e.getGraphPoint() == root.getGraphPoint() || e.getGraphPoint() == next.getGraphPoint() @@ -270,18 +269,17 @@ public class Loop { * @param root and edge of this triangle * @return the triangle iff it satisfies, null otherwise */ - private Triangle createTriangle(T v1, T v2, T v3, HEdge rootT){ - @SuppressWarnings("unchecked") - Triangle t = new Triangle(v1, v2, v3); + private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){ + Triangle t = new Triangle(v1, v2, v3); t.setVerticesBoundary(checkVerticesBoundary(rootT)); return t; } - private boolean[] checkVerticesBoundary(HEdge rootT) { + private boolean[] checkVerticesBoundary(HEdge rootT) { boolean[] boundary = new boolean[3]; - HEdge e1 = rootT; - HEdge e2 = rootT.getNext(); - HEdge e3 = rootT.getNext().getNext(); + HEdge e1 = rootT; + HEdge e2 = rootT.getNext(); + HEdge e3 = rootT.getNext().getNext(); if(e1.getGraphPoint().isBoundaryContained()){ boundary[0] = true; @@ -300,7 +298,7 @@ public class Loop { * @param vertex the Vertex * @return true if the vertex is inside, false otherwise */ - public boolean checkInside(T vertex) { + public boolean checkInside(Vertex vertex) { if(!box.contains(vertex.getX(), vertex.getY(), vertex.getZ())){ return false; } @@ -308,8 +306,8 @@ public class Loop { float[] center = box.getCenter(); int hits = 0; - HEdge current = root; - HEdge next = root.getNext(); + HEdge current = root; + HEdge next = root.getNext(); while(next!= root){ if(current.getType() == HEdge.INNER || next.getType() == HEdge.INNER){ current = next; @@ -317,8 +315,8 @@ public class Loop { continue; } - T vert1 = current.getGraphPoint().getPoint(); - T vert2 = next.getGraphPoint().getPoint(); + 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. @@ -366,7 +364,7 @@ public class Loop { public int computeLoopSize(){ int size = 0; - HEdge e = root; + HEdge e = root; do{ size++; e = e.getNext(); -- cgit v1.2.3