From ea0059f01866bd6257d4a06164db1b6c906a2949 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 28 Feb 2014 12:12:58 +0100 Subject: Bug 801: Outline.setClosed(boolean [closed->closeTail]): Always close, but allow to either close-tail or head; OutlineShape/Triangulator: Pass 'sharpness' (very little effect though) --- .../com/jogamp/graph/curve/OutlineShape.java | 37 ++++++++++++++++++---- .../com/jogamp/graph/curve/tess/Triangulator.java | 3 +- .../classes/com/jogamp/graph/geom/Outline.java | 35 ++++++++++++-------- .../jogamp/graph/curve/tess/CDTriangulator2D.java | 20 +++++------- 4 files changed, 62 insertions(+), 33 deletions(-) (limited to 'src/jogl') 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 { /** dirty bits DIRTY_BOUNDS */ private int dirtyBits; + private float sharpness; + /** Create a new Outline based Shape */ public OutlineShape(Vertex.Factory factory) { @@ -144,6 +146,16 @@ public class OutlineShape implements Comparable { this.triangles = new ArrayList(); this.vertices = new ArrayList(); 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 { 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 { /** * Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape, * using {@link #addOutline(Outline)} for each element. - *

Closes the current last outline via {@link #closeLastOutline()} before adding the new ones.

+ *

Closes the current last outline via {@link #closeLastOutline(boolean)} before adding the new ones.

* @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 { if (null == outlineShape) { throw new NullPointerException("OutlineShape is null"); } - closeLastOutline(); + closeLastOutline(true); for(int i=0; i { /** * Closes the last outline in the shape. - *

If last vertex is not equal to first vertex. - * A new temp vertex is added at the end which - * is equal to the first.

+ *

+ * 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 closeTail. + *

+ * @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 { triangles.clear(); final Triangulator triangulator2d = Triangulation.create(); for(int index = 0; index sink, Outline outline); + public void addCurve(List 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 { 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 { 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 { 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. + *

+ * 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 closeTail. + *

+ * @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 loops; // FIXME ? private ArrayList 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(); loops = new ArrayList(); } @Override - public void addCurve(List sink, Outline polyline) { + public final void addCurve(final List 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 sink) { + public final void generate(List sink) { for(int i=0;i sink, GraphOutline outline, boolean hole) { + private GraphOutline extractBoundaryTriangles(final List sink, final GraphOutline outline, final boolean hole, final float sharpness) { GraphOutline innerOutline = new GraphOutline(); ArrayList 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); -- cgit v1.2.3