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/com/jogamp/graph/curve/OutlineShape.java | 28 ++++----- src/com/jogamp/graph/curve/Region.java | 2 +- .../jogamp/graph/curve/opengl/RegionRenderer.java | 4 +- .../jogamp/graph/curve/tess/CDTriangulator2D.java | 69 +++++++++++----------- src/com/jogamp/graph/geom/Outline.java | 29 ++++----- src/com/jogamp/graph/geom/Triangle.java | 8 +-- 6 files changed, 68 insertions(+), 72 deletions(-) (limited to 'src/com/jogamp') diff --git a/src/com/jogamp/graph/curve/OutlineShape.java b/src/com/jogamp/graph/curve/OutlineShape.java index 9373808f1..2a6e3745f 100755 --- a/src/com/jogamp/graph/curve/OutlineShape.java +++ b/src/com/jogamp/graph/curve/OutlineShape.java @@ -52,13 +52,13 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D; public class OutlineShape { public static final int QUADRATIC_NURBS = 10; private final Vertex.Factory pointFactory; - private ArrayList> outlines = new ArrayList>(3); + private ArrayList outlines = new ArrayList(3); /** Create a new Outline based Shape */ public OutlineShape(Vertex.Factory factory) { pointFactory = factory; - outlines.add(new Outline()); + outlines.add(new Outline()); } public final Vertex.Factory pointFactory() { return pointFactory; } @@ -68,7 +68,7 @@ public class OutlineShape { * be placed at the end of the outline list. */ public void addEmptyOutline(){ - outlines.add(new Outline()); + outlines.add(new Outline()); } /** Adds an outline to the OutlineShape object @@ -77,7 +77,7 @@ public class OutlineShape { * it will do nothing. * @param outline an Outline object */ - public void addOutline(Outline outline){ + public void addOutline(Outline outline){ if(outline.isEmpty()){ return; } @@ -120,7 +120,7 @@ public class OutlineShape { * of outlines that define the shape * @return the last outline */ - public final Outline getLastOutline(){ + public final Outline getLastOutline(){ return outlines.get(outlines.size()-1); } /** Make sure that the outlines represent @@ -135,13 +135,13 @@ public class OutlineShape { } private void transformOutlinesQuadratic(){ - ArrayList> newOutlines = new ArrayList>(3); + ArrayList newOutlines = new ArrayList(3); /**loop over the outlines and make sure no * adj off-curve vertices */ - for(Outline outline:outlines){ - Outline newOutline = new Outline(); + for(Outline outline:outlines){ + Outline newOutline = new Outline(); ArrayList vertices = outline.getVertices(); int size =vertices.size()-1; @@ -165,7 +165,7 @@ public class OutlineShape { private void generateVertexIds(){ int maxVertexId = 0; - for(Outline outline:outlines){ + for(Outline outline:outlines){ ArrayList vertices = outline.getVertices(); for(Vertex vert:vertices){ vert.setId(maxVertexId); @@ -179,7 +179,7 @@ public class OutlineShape { */ public ArrayList getVertices(){ ArrayList vertices = new ArrayList(); - for(Outline polyline:outlines){ + for(Outline polyline:outlines){ vertices.addAll(polyline.getVertices()); } return vertices; @@ -189,21 +189,21 @@ public class OutlineShape { /** Triangluate the graph object * @param sharpness sharpness of the curved regions default = 0.5 */ - public ArrayList> triangulate(float sharpness){ + public ArrayList triangulate(float sharpness){ if(outlines.size() == 0){ return null; } sortOutlines(); generateVertexIds(); - CDTriangulator2D triangulator2d = new CDTriangulator2D(sharpness); + CDTriangulator2D triangulator2d = new CDTriangulator2D(sharpness); for(int index = 0; index< outlines.size();index++){ - Outline outline = outlines.get(index); + Outline outline = outlines.get(index); triangulator2d.addCurve(outline); } - ArrayList> triangles = triangulator2d.generateTriangulation(); + ArrayList triangles = triangulator2d.generateTriangulation(); triangulator2d.reset(); return triangles; diff --git a/src/com/jogamp/graph/curve/Region.java b/src/com/jogamp/graph/curve/Region.java index f3a87bb7f..143b6f502 100755 --- a/src/com/jogamp/graph/curve/Region.java +++ b/src/com/jogamp/graph/curve/Region.java @@ -80,7 +80,7 @@ public interface Region { * * @see update() */ - public void addTriangles(ArrayList> tris); + public void addTriangles(ArrayList tris); /** Get the current number of vertices associated * with this region. This number is not necessary equal to diff --git a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java index 4be1506d5..602399010 100644 --- a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -63,7 +63,7 @@ public abstract class RegionRenderer extends Renderer { outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - ArrayList> triangles = (ArrayList>) outlineShape.triangulate(sharpness); + ArrayList triangles = (ArrayList) outlineShape.triangulate(sharpness); ArrayList vertices = (ArrayList) outlineShape.getVertices(); region.addVertices(vertices); region.addTriangles(triangles); @@ -84,7 +84,7 @@ public abstract class RegionRenderer extends Renderer { for(OutlineShape outlineShape:outlineShapes){ outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - ArrayList> triangles = outlineShape.triangulate(sharpness); + ArrayList triangles = outlineShape.triangulate(sharpness); region.addTriangles(triangles); ArrayList vertices = outlineShape.getVertices(); diff --git a/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java index 0a7cf08d4..beef2d4a5 100644 --- a/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -46,15 +46,15 @@ import jogamp.opengl.Debug; * Closed Regions with optional n holes. * */ -public class CDTriangulator2D { +public class CDTriangulator2D { protected static final boolean DEBUG = Debug.debug("Triangulation"); private float sharpness = 0.5f; - private ArrayList> loops; - private ArrayList vertices; + private ArrayList loops; + private ArrayList vertices; - private ArrayList> triangles; + private ArrayList triangles; private int maxTriID = 0; @@ -76,31 +76,31 @@ public class CDTriangulator2D { */ public void reset() { maxTriID = 0; - vertices = new ArrayList(); - triangles = new ArrayList>(3); - loops = new ArrayList>(); + vertices = new ArrayList(); + triangles = new ArrayList(3); + loops = new ArrayList(); } /** Add a curve to the list of profiles provided * @param polyline a bounding Outline */ - public void addCurve(Outline polyline){ - Loop loop = null; + public void addCurve(Outline polyline){ + Loop loop = null; if(!loops.isEmpty()){ loop = getContainerLoop(polyline); } if(loop == null) { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, false); + GraphOutline outline = new GraphOutline(polyline); + GraphOutline innerPoly = extractBoundaryTriangles(outline, false); vertices.addAll(polyline.getVertices()); - loop = new Loop(innerPoly, VectorUtil.CCW); + loop = new Loop(innerPoly, VectorUtil.CCW); loops.add(loop); } else { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, true); + GraphOutline outline = new GraphOutline(polyline); + GraphOutline innerPoly = extractBoundaryTriangles(outline, true); vertices.addAll(innerPoly.getPoints()); loop.addConstraintCurve(innerPoly); } @@ -109,13 +109,13 @@ public class CDTriangulator2D { /** Generate the triangulation of the provided * List of Outlines */ - public ArrayList> generateTriangulation(){ + public ArrayList generateTriangulation(){ for(int i=0;i loop = loops.get(i); + Loop loop = loops.get(i); int numTries = 0; int size = loop.computeLoopSize(); while(!loop.isSimplex()){ - Triangle tri = null; + Triangle tri = null; if(numTries > size){ tri = loop.cut(false); } @@ -140,41 +140,40 @@ public class CDTriangulator2D { break; } } - Triangle tri = loop.cut(true); + Triangle tri = loop.cut(true); if(tri != null) triangles.add(tri); } return triangles; } - @SuppressWarnings("unchecked") - private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole){ - GraphOutline innerOutline = new GraphOutline(); - ArrayList> outVertices = outline.getGraphPoint(); + private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole){ + GraphOutline innerOutline = new GraphOutline(); + ArrayList outVertices = outline.getGraphPoint(); int size = outVertices.size(); for(int i=0; i < size; i++) { - GraphVertex currentVertex = outVertices.get(i); - GraphVertex gv0 = outVertices.get((i+size-1)%size); - GraphVertex gv2 = outVertices.get((i+1)%size); - GraphVertex gv1 = currentVertex; + GraphVertex currentVertex = outVertices.get(i); + GraphVertex gv0 = outVertices.get((i+size-1)%size); + GraphVertex gv2 = outVertices.get((i+1)%size); + GraphVertex gv1 = currentVertex; if(!currentVertex.getPoint().isOnCurve()) { - T v0 = (T) gv0.getPoint().clone(); - T v2 = (T) gv2.getPoint().clone(); - T v1 = (T) gv1.getPoint().clone(); + Vertex v0 = gv0.getPoint().clone(); + Vertex v2 = gv2.getPoint().clone(); + Vertex v1 = gv1.getPoint().clone(); gv0.setBoundaryContained(true); gv1.setBoundaryContained(true); gv2.setBoundaryContained(true); - Triangle t= null; + Triangle t= null; boolean holeLike = false; if(VectorUtil.ccw(v0,v1,v2)){ - t = new Triangle(v0, v1, v2); + t = new Triangle(v0, v1, v2); } else { holeLike = true; - t = new Triangle(v2, v1, v0); + t = new Triangle(v2, v1, v0); } t.setId(maxTriID++); triangles.add(t); @@ -203,10 +202,10 @@ public class CDTriangulator2D { return innerOutline; } - private Loop getContainerLoop(Outline polyline){ - T v = polyline.getVertex(0); + private Loop getContainerLoop(Outline polyline){ + Vertex v = polyline.getVertex(0); - for (Loop loop:loops){ + for (Loop loop:loops){ if(loop.checkInside(v)){ return loop; } diff --git a/src/com/jogamp/graph/geom/Outline.java b/src/com/jogamp/graph/geom/Outline.java index 4e588623e..85b6e8001 100644 --- a/src/com/jogamp/graph/geom/Outline.java +++ b/src/com/jogamp/graph/geom/Outline.java @@ -45,9 +45,9 @@ import com.jogamp.graph.math.VectorUtil; * @see OutlineShape, Region * */ -public class Outline implements Comparable>{ +public class Outline implements Comparable { - private ArrayList vertices = new ArrayList(3); + private ArrayList vertices = new ArrayList(3); private boolean closed = false; private AABBox box = new AABBox(); @@ -63,7 +63,7 @@ public class Outline implements Comparable>{ * end of the outline loop/strip. * @param vertex Vertex to be added */ - public final void addVertex(T vertex) { + public final void addVertex(Vertex vertex) { vertices.add(vertex); box.resize(vertex.getX(), vertex.getY(), vertex.getZ()); } @@ -72,38 +72,36 @@ public class Outline implements Comparable>{ addVertex(factory, x, y, 0f, onCurve); } - @SuppressWarnings("unchecked") public final void addVertex(Vertex.Factory factory, float x, float y, float z, boolean onCurve) { Vertex v = factory.create(x, y, z); v.setOnCurve(onCurve); - addVertex((T)v); + addVertex(v); } - @SuppressWarnings("unchecked") public final void addVertex(Vertex.Factory factory, float[] coordsBuffer, int offset, int length, boolean onCurve) { Vertex v = factory.create(coordsBuffer, offset, length); v.setOnCurve(onCurve); - addVertex((T)v); + addVertex(v); } - public T getVertex(int index){ + public Vertex getVertex(int index){ return vertices.get(index); } public boolean isEmpty(){ return (vertices.size() == 0); } - public T getLastVertex(){ + public Vertex getLastVertex(){ if(isEmpty()){ return null; } return vertices.get(vertices.size()-1); } - public ArrayList getVertices() { + public ArrayList getVertices() { return vertices; } - public void setVertices(ArrayList vertices) { + public void setVertices(ArrayList vertices) { this.vertices = vertices; } public AABBox getBox() { @@ -122,11 +120,10 @@ public class Outline implements Comparable>{ public void setClosed(boolean closed) { this.closed = closed; if(closed){ - T first = vertices.get(0); - T last = getLastVertex(); + Vertex first = vertices.get(0); + Vertex last = getLastVertex(); if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){ - @SuppressWarnings("unchecked") - T v = (T) first.clone(); + Vertex v = first.clone(); vertices.add(v); } } @@ -136,7 +133,7 @@ public class Outline implements Comparable>{ * as criteria. * @see java.lang.Comparable#compareTo(java.lang.Object) */ - public int compareTo(Outline outline) { + public int compareTo(Outline outline) { float size = box.getSize(); float newSize = outline.getBox().getSize(); if(size < newSize){ diff --git a/src/com/jogamp/graph/geom/Triangle.java b/src/com/jogamp/graph/geom/Triangle.java index 7b11ba23d..d13e8ddb1 100644 --- a/src/com/jogamp/graph/geom/Triangle.java +++ b/src/com/jogamp/graph/geom/Triangle.java @@ -27,13 +27,13 @@ */ package com.jogamp.graph.geom; -public class Triangle { +public class Triangle { private int id = Integer.MAX_VALUE; - final private T[] vertices; + final private Vertex[] vertices; private boolean[] boundaryEdges = new boolean[3]; private boolean[] boundaryVertices = null; - public Triangle(T ... v123){ + public Triangle(Vertex ... v123){ vertices = v123; } @@ -45,7 +45,7 @@ public class Triangle { this.id = id; } - public T[] getVertices() { + public Vertex[] getVertices() { return vertices; } -- cgit v1.2.3