diff options
Diffstat (limited to 'src')
7 files changed, 72 insertions, 43 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index f4cdffd5e..44a8e7384 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -133,6 +133,8 @@ public class OutlineShape implements Comparable<OutlineShape> { /** dirty bits DIRTY_BOUNDS */ private int dirtyBits; + private float sharpness; + /** Create a new Outline based Shape */ public OutlineShape(Vertex.Factory<? extends Vertex> factory) { @@ -144,6 +146,16 @@ public class OutlineShape implements Comparable<OutlineShape> { this.triangles = new ArrayList<Triangle>(); this.vertices = new ArrayList<Vertex>(); this.dirtyBits = 0; + this.sharpness = 0.5f; + } + + public float getSharpness() { return sharpness; } + + public void setSharpness(final float s) { + if( this.sharpness != s ) { + clearCache(); + sharpness=s; + } } /** Clears all data and reset all states as if this instance was newly created */ @@ -157,6 +169,13 @@ public class OutlineShape implements Comparable<OutlineShape> { dirtyBits = 0; } + /** Clears cached triangulated data, i.e. {@link #getTriangles(VerticesState)} and {@link #getVertices()}. */ + public void clearCache() { + vertices.clear(); + triangles.clear(); + dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; + } + /** * Returns the associated vertex factory of this outline shape * @return Vertex.Factory object @@ -236,7 +255,7 @@ public class OutlineShape implements Comparable<OutlineShape> { /** * Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape, * using {@link #addOutline(Outline)} for each element. - * <p>Closes the current last outline via {@link #closeLastOutline()} before adding the new ones.</p> + * <p>Closes the current last outline via {@link #closeLastOutline(boolean)} before adding the new ones.</p> * @param outlineShape OutlineShape elements to be added. * @throws NullPointerException if the {@link OutlineShape} is null * @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber()) @@ -245,7 +264,7 @@ public class OutlineShape implements Comparable<OutlineShape> { if (null == outlineShape) { throw new NullPointerException("OutlineShape is null"); } - closeLastOutline(); + closeLastOutline(true); for(int i=0; i<outlineShape.getOutlineNumber(); i++) { addOutline(outlineShape.getOutline(i)); } @@ -369,11 +388,15 @@ public class OutlineShape implements Comparable<OutlineShape> { /** * Closes the last outline in the shape. - * <p>If last vertex is not equal to first vertex. - * A new temp vertex is added at the end which - * is equal to the first.</p> + * <p> + * Checks whether the last vertex equals to the first of the last outline. + * If not equal, it either appends a clone of the first vertex + * or prepends a clone of the last vertex, depending on <code>closeTail</code>. + * </p> + * @param closeTail if true, a clone of the first vertex will be appended, + * otherwise a clone of the last vertex will be prepended. */ - public final void closeLastOutline() { + public final void closeLastOutline(boolean closeTail) { if( getLastOutline().setClosed(true) ) { dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES; } @@ -588,7 +611,7 @@ public class OutlineShape implements Comparable<OutlineShape> { triangles.clear(); final Triangulator triangulator2d = Triangulation.create(); for(int index = 0; index<outlines.size(); index++) { - triangulator2d.addCurve(triangles, outlines.get(index)); + triangulator2d.addCurve(triangles, outlines.get(index), sharpness); } triangulator2d.generate(triangles); triangulator2d.reset(); diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java index 39e84171b..96ff4bbb8 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java @@ -54,8 +54,9 @@ public interface Triangulator { * describing the shape * @param sink list where the generated triangles will be added * @param outline a bounding {@link Outline} + * @param sharpness TODO */ - public void addCurve(List<Triangle> sink, Outline outline); + public void addCurve(List<Triangle> sink, Outline outline, float sharpness); /** Generate the triangulation of the provided * List of {@link Outline}s diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java index 26eba2741..2d9d74966 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java @@ -62,7 +62,8 @@ public class Outline implements Cloneable, Comparable<Outline> { return vertices.size(); } - /** Appends a vertex to the outline loop/strip. + /** + * Appends a vertex to the outline loop/strip. * @param vertex Vertex to be added * @throws NullPointerException if the {@link Vertex} element is null */ @@ -70,7 +71,8 @@ public class Outline implements Cloneable, Comparable<Outline> { addVertex(vertices.size(), vertex); } - /** Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip. + /** + * Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip. * @param position of the added Vertex * @param vertex Vertex object to be added * @throws NullPointerException if the {@link Vertex} element is null @@ -151,21 +153,28 @@ public class Outline implements Cloneable, Comparable<Outline> { return closed; } - /** define if this outline is closed or not. - * if set to closed, checks if the last vertex is - * equal to the first vertex. If not Equal adds a - * vertex at the end to the list. - * @param closed + /** + * Ensure this outline is closed. + * <p> + * Checks whether the last vertex equals to the first. + * If not equal, it either appends a clone of the first vertex + * or prepends a clone of the last vertex, depending on <code>closeTail</code>. + * </p> + * @param closeTail if true, a clone of the first vertex will be appended, + * otherwise a clone of the last vertex will be prepended. * @return true if closing performed, otherwise false for NOP */ - public final boolean setClosed(boolean closed) { - this.closed = closed; - if( closed && !isEmpty() ) { + public final boolean setClosed(boolean closeTail) { + this.closed = true; + if( !isEmpty() ) { final Vertex first = vertices.get(0); final Vertex last = getLastVertex(); - if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){ - Vertex v = first.clone(); - vertices.add(v); + if( !VectorUtil.checkEquality( first.getCoord(), last.getCoord() ) ) { + if( closeTail ) { + vertices.add(first.clone()); + } else { + vertices.add(0, last.clone()); + } return true; } } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java index a82c2ee7a..0034c8f57 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -44,11 +44,10 @@ import jogamp.opengl.Debug; * Closed Regions with optional n holes. * */ -public class CDTriangulator2D implements Triangulator{ +public class CDTriangulator2D implements Triangulator { protected static final boolean DEBUG = Debug.debug("Triangulation"); - private final float sharpness = 0.5f; private ArrayList<Loop> loops; // FIXME ? private ArrayList<Vertex> vertices; @@ -61,18 +60,15 @@ public class CDTriangulator2D implements Triangulator{ reset(); } - /** Reset the triangulation to initial state - * Clearing cached data - */ @Override - public void reset() { + public final void reset() { maxTriID = 0; // vertices = new ArrayList<Vertex>(); loops = new ArrayList<Loop>(); } @Override - public void addCurve(List<Triangle> sink, Outline polyline) { + public final void addCurve(final List<Triangle> sink, final Outline polyline, final float sharpness) { Loop loop = null; if(!loops.isEmpty()) { @@ -81,20 +77,20 @@ public class CDTriangulator2D implements Triangulator{ if(loop == null) { final GraphOutline outline = new GraphOutline(polyline); - final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false, sharpness); // vertices.addAll(polyline.getVertices()); loop = new Loop(innerPoly, VectorUtil.Winding.CCW); loops.add(loop); } else { final GraphOutline outline = new GraphOutline(polyline); - final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true, sharpness); // vertices.addAll(innerPoly.getVertices()); loop.addConstraintCurve(innerPoly); } } @Override - public void generate(List<Triangle> sink) { + public final void generate(List<Triangle> sink) { for(int i=0;i<loops.size();i++) { Loop loop = loops.get(i); int numTries = 0; @@ -132,7 +128,7 @@ public class CDTriangulator2D implements Triangulator{ } } - private GraphOutline extractBoundaryTriangles(List<Triangle> sink, GraphOutline outline, boolean hole) { + private GraphOutline extractBoundaryTriangles(final List<Triangle> sink, final GraphOutline outline, final boolean hole, final float sharpness) { GraphOutline innerOutline = new GraphOutline(); ArrayList<GraphVertex> outVertices = outline.getGraphPoint(); int size = outVertices.size(); @@ -168,7 +164,7 @@ public class CDTriangulator2D implements Triangulator{ if( hole || holeLike ) { v0.setTexCoord(0, -0.1f); v2.setTexCoord(1, -0.1f); - v1.setTexCoord(0.5f, -1*sharpness -0.1f); + v1.setTexCoord(0.5f, -1*sharpness-0.1f); innerOutline.addVertex(currentVertex); } else { v0.setTexCoord(0, 0.1f); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java index 2673a0e85..84c816b7a 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java @@ -62,13 +62,13 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { outlineShape.addVertex(6.0f,15.0f, false); outlineShape.addVertex(5.0f,8.0f, false); outlineShape.addVertex(0.0f,10.0f,true); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); outlineShape.addEmptyOutline(); outlineShape.addVertex(5.0f,-5.0f,true); outlineShape.addVertex(10.0f,-5.0f, false); outlineShape.addVertex(10.0f,0.0f, true); outlineShape.addVertex(5.0f,0.0f, false); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); /** Same shape as above but without any off-curve vertices */ offset = 30; @@ -80,13 +80,13 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { outlineShape.addVertex(offset+7.0f,15.0f, true); outlineShape.addVertex(offset+6.0f,8.0f, true); outlineShape.addVertex(offset+0.0f,10.0f, true); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); outlineShape.addEmptyOutline(); outlineShape.addVertex(offset+5.0f,0.0f, true); outlineShape.addVertex(offset+5.0f,-5.0f, true); outlineShape.addVertex(offset+10.0f,-5.0f, true); outlineShape.addVertex(offset+10.0f,0.0f, true); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); region = GLRegion.create(getRenderModes()); region.addOutlineShape(outlineShape, null); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java index 0e92bd2b6..83b37ac0b 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java @@ -63,13 +63,13 @@ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 { shape.addVertex(6.0f,15.0f, false); shape.addVertex(5.0f,8.0f, false); shape.addVertex(0.0f,10.0f,true); - shape.closeLastOutline(); + shape.closeLastOutline(true); shape.addEmptyOutline(); shape.addVertex(5.0f,-5.0f,true); shape.addVertex(10.0f,-5.0f, false); shape.addVertex(10.0f,0.0f, true); shape.addVertex(5.0f,0.0f, false); - shape.closeLastOutline(); + shape.closeLastOutline(true); /** Same shape as above but without any off-curve vertices */ shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); @@ -82,13 +82,13 @@ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 { shape.addVertex(offset+7.0f,15.0f, true); shape.addVertex(offset+6.0f,8.0f, true); shape.addVertex(offset+0.0f,10.0f, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); shape.addEmptyOutline(); shape.addVertex(offset+5.0f,0.0f, true); shape.addVertex(offset+5.0f,-5.0f, true); shape.addVertex(offset+10.0f,-5.0f, true); shape.addVertex(offset+10.0f,0.0f, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); region = GLRegion.create(getRenderModes()); region.addOutlineShapes(outlineShapes, null); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java index 6a3b9fc73..8c64e1463 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java @@ -115,7 +115,7 @@ public abstract class RIButton extends UIShape { shape.addVertex(minX+tw, minY, minZ, true); shape.addVertex(minX+tw, minY + th, minZ, true); shape.addVertex(minX, minY + th, minZ, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); } private void createCurvedOutline(AABBox lbox){ @@ -140,7 +140,7 @@ public abstract class RIButton extends UIShape { shape.addVertex(minX + cw, minY + th, minZ, true); shape.addVertex(minX, minY + th, minZ, false); shape.addVertex(minX, minY + th - ch, minZ, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); } public void setCorner(float corner) { |