From 9cefde9395002717bb6bfde461f4a65c69a888dd Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Thu, 2 Jun 2011 16:00:01 +0300 Subject: Font and TypecastRender generate array of OutlineShapes instead of Path2D GlyphShape and GlyphString use only OutlineShapes --- .../jogamp/graph/curve/text/GlyphShape.java | 64 +++------------------- .../jogamp/graph/curve/text/GlyphString.java | 40 ++++++-------- src/jogl/classes/jogamp/graph/font/FontInt.java | 9 +-- .../jogamp/graph/font/typecast/TypecastFont.java | 12 +++- .../graph/font/typecast/TypecastRenderer.java | 61 ++++++++++++++++++++- 5 files changed, 98 insertions(+), 88 deletions(-) (limited to 'src/jogl/classes/jogamp/graph') diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java index ed51cce98..578148699 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java @@ -29,10 +29,9 @@ package jogamp.graph.curve.text; import java.util.ArrayList; -import jogamp.graph.geom.plane.PathIterator; - import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; +import com.jogamp.graph.geom.Vertex.Factory; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.math.Quaternion; @@ -40,7 +39,6 @@ import com.jogamp.graph.math.Quaternion; public class GlyphShape { private Quaternion quat= null; - private int numVertices = 0; private OutlineShape shape = null; /** Create a new Glyph shape @@ -50,70 +48,24 @@ public class GlyphShape { shape = new OutlineShape(factory); } - /** Create a GlyphShape from a font Path Iterator - * @param pathIterator the path iterator - * - * @see PathIterator + /** Create a new GlyphShape from a {@link OutlineShape} + * @param factory vertex impl factory {@link Factory} + * @param shape {@link OutlineShape} representation of the Glyph */ - public GlyphShape(Vertex.Factory factory, PathIterator pathIterator){ + public GlyphShape(Vertex.Factory factory, OutlineShape shape){ this(factory); - - if(null != pathIterator){ - while(!pathIterator.isDone()){ - float[] coords = new float[6]; - int segmentType = pathIterator.currentSegment(coords); - addOutlineVerticesFromGlyphVector(coords, segmentType); - - pathIterator.next(); - } - } - shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS); + this.shape = shape; + this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS); } public final Vertex.Factory vertexFactory() { return shape.vertexFactory(); } - private void addVertexToLastOutline(Vertex vertex) { - //FIXME: assuming font outline comes in CW order - shape.addVertex(0, vertex); - } - - private void addOutlineVerticesFromGlyphVector(float[] coords, int segmentType){ - switch(segmentType) { - case PathIterator.SEG_MOVETO: - shape.closeLastOutline(); - shape.addEmptyOutline(); - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); - numVertices++; - break; - case PathIterator.SEG_LINETO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); - numVertices++; - break; - case PathIterator.SEG_QUADTO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 2, 2, true)); - numVertices+=2; - break; - case PathIterator.SEG_CUBICTO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 2, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 4, 2, true)); - numVertices+=3; - break; - case PathIterator.SEG_CLOSE: - shape.closeLastOutline(); - break; - default: - throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); - } - } - public OutlineShape getShape() { return shape; } public int getNumVertices() { - return numVertices; + return shape.getVertices().size(); } /** Get the rotational Quaternion attached to this Shape diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index cd6cd56aa..c07b41a7b 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -40,10 +40,6 @@ import javax.media.opengl.GL2ES2; import jogamp.graph.curve.opengl.RegionFactory; import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; -import jogamp.graph.geom.plane.PathIterator; - import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; @@ -68,9 +64,9 @@ public class GlyphString { *

No caching is performed.

* * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory - * @param font - * @param str + * @param vertexFactory vertex impl factory {@link Factory} + * @param font the target {@link Font} + * @param str string text * @return the created {@link GlyphString} instance */ public static GlyphString createString(OutlineShape shape, Factory vertexFactory, Font font, String str) { @@ -81,20 +77,17 @@ public class GlyphString { *

No caching is performed.

* * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory - * @param font - * @param size - * @param str + * @param vertexFactory vertex impl factory {@link Factory} + * @param font the target {@link Font} + * @param size font size + * @param str string text * @return the created {@link GlyphString} instance */ public static GlyphString createString(OutlineShape shape, Factory vertexFactory, Font font, int fontSize, String str) { - AffineTransform affineTransform = new AffineTransform(vertexFactory); - - Path2D[] paths = new Path2D[str.length()]; - ((FontInt)font).getPaths(str, fontSize, affineTransform, paths); + ArrayList shapes = ((FontInt)font).getOutlineShapes(str, fontSize, vertexFactory); GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str); - glyphString.createfromFontPath(vertexFactory, paths, affineTransform); + glyphString.createfromOutlineShapes(vertexFactory, shapes); if(null != shape) { for(int i=0; i vertexFactory, Path2D[] paths, AffineTransform affineTransform) { - final int numGlyps = paths.length; + public void createfromOutlineShapes(Factory vertexFactory, ArrayList shapes) { + final int numGlyps = shapes.size(); for (int index=0;index getOutlineShapes(CharSequence string, float pixelSize, Factory vertexFactory); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 2e692e5ce..8806f537d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -27,6 +27,8 @@ */ package jogamp.graph.font.typecast; +import java.util.ArrayList; + import jogamp.graph.font.FontInt; import jogamp.graph.font.typecast.ot.OTFont; import jogamp.graph.font.typecast.ot.OTFontCollection; @@ -39,9 +41,12 @@ import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; import com.jogamp.common.util.IntObjectHashMap; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; class TypecastFont implements FontInt { static final boolean DEBUG = false; @@ -208,9 +213,10 @@ class TypecastFont implements FontInt { } return result; } - - public void getPaths(CharSequence string, float pixelSize, AffineTransform transform, Path2D[] result) { - TypecastRenderer.getPaths(this, string, pixelSize, transform, result); + + public ArrayList getOutlineShapes(CharSequence string, float pixelSize, Factory vertexFactory) { + AffineTransform transform = new AffineTransform(vertexFactory); + return TypecastRenderer.getOutlineShapes(this, string, pixelSize, transform, vertexFactory); } public float getStringWidth(CharSequence string, float pixelSize) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index 310b2b274..50b510d23 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -27,12 +27,19 @@ */ package jogamp.graph.font.typecast; +import java.util.ArrayList; + +import jogamp.graph.curve.text.GlyphShape; import jogamp.graph.font.typecast.ot.OTGlyph; import jogamp.graph.font.typecast.ot.Point; import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; +import jogamp.graph.geom.plane.PathIterator; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; /** * Factory to build a {@link com.jogamp.graph.geom.Path2D Path2D} from @@ -40,7 +47,7 @@ import com.jogamp.graph.font.Font; */ public class TypecastRenderer { - public static void getPaths(TypecastFont font, + private static void getPaths(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Path2D[] p) { if (string == null) { @@ -82,6 +89,58 @@ public class TypecastRenderer { } } + public static ArrayList getOutlineShapes(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory vertexFactory) { + Path2D[] paths = new Path2D[string.length()]; + getPaths(font, string, pixelSize, transform, paths); + + ArrayList shapes = new ArrayList(); + final int numGlyps = paths.length; + for (int index=0;index vertexFactory, float[] coords, int segmentType){ + switch(segmentType) { + case PathIterator.SEG_MOVETO: + shape.closeLastOutline(); + shape.addEmptyOutline(); + shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); + //numVertices++; + break; + case PathIterator.SEG_LINETO: + shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); + break; + case PathIterator.SEG_QUADTO: + shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); + shape.addVertex(0, vertexFactory.create(coords, 2, 2, true)); + break; + case PathIterator.SEG_CUBICTO: + shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); + shape.addVertex(0, vertexFactory.create(coords, 2, 2, false)); + shape.addVertex(0, vertexFactory.create(coords, 4, 2, true)); + break; + case PathIterator.SEG_CLOSE: + shape.closeLastOutline(); + break; + default: + throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); + } + } + /** * Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then -- cgit v1.2.3 From 820fd3f4e45cfa79e94fad385eb47ff26a5fea2b Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Sun, 5 Jun 2011 16:17:47 +0300 Subject: Add Factory for triangulation with base Interface; misc cleanup CDTriangulation moved to impl (jogamp.graph), where additional triangulations or a wrapper to GLU triangulation can be added to triangulator. TWO_PASS_RENDERING renamed to VBAA (algorithm name) misc comments cleanups --- .../com/jogamp/graph/curve/OutlineShape.java | 6 +- .../classes/com/jogamp/graph/curve/Region.java | 14 +- .../jogamp/graph/curve/opengl/RegionRenderer.java | 2 +- .../jogamp/graph/curve/opengl/TextRenderer.java | 6 +- .../jogamp/graph/curve/tess/CDTriangulator2D.java | 213 --------------------- .../com/jogamp/graph/curve/tess/Triangulation.java | 44 +++++ .../com/jogamp/graph/curve/tess/Triangulator.java | 69 +++++++ .../jogamp/graph/curve/opengl/RegionFactory.java | 6 +- .../jogamp/graph/curve/tess/CDTriangulator2D.java | 203 ++++++++++++++++++++ .../jogamp/graph/curve/text/GlyphString.java | 2 +- .../test/junit/graph/TestRegionRendererNEWT01.java | 2 +- .../test/junit/graph/TestTextRendererNEWT01.java | 2 +- .../junit/graph/demos/GPURegionNewtDemo02.java | 2 +- .../graph/demos/GPURendererListenerBase01.java | 2 +- .../test/junit/graph/demos/GPUTextNewtDemo02.java | 2 +- 15 files changed, 340 insertions(+), 235 deletions(-) delete mode 100644 src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java create mode 100644 src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java create mode 100644 src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java create mode 100644 src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java (limited to 'src/jogl/classes/jogamp/graph') diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java index 16bd054e2..e4f80ab76 100755 --- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java +++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java @@ -30,14 +30,14 @@ package com.jogamp.graph.curve; import java.util.ArrayList; import java.util.Collections; - +import com.jogamp.graph.curve.tess.Triangulation; +import com.jogamp.graph.curve.tess.Triangulator; import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.math.VectorUtil; -import com.jogamp.graph.curve.tess.CDTriangulator2D; /** A Generic shape objects which is defined by a list of Outlines. * This Shape can be transformed to Triangulations. @@ -433,7 +433,7 @@ public class OutlineShape implements Comparable { sortOutlines(); generateVertexIds(); - CDTriangulator2D triangulator2d = new CDTriangulator2D(); + Triangulator triangulator2d = Triangulation.create(); for(int index = 0; index triangles = new ArrayList(); protected ArrayList vertices = new ArrayList(); - public static boolean usesTwoPassRendering(int renderModes) { - return 0 != ( renderModes & Region.TWO_PASS_RENDERING_BIT ); + public static boolean isVBAA(int renderModes) { + return 0 != ( renderModes & Region.VBAA_RENDERING_BIT ); } public static boolean usesVariableCurveWeight(int renderModes) { @@ -71,7 +73,7 @@ public abstract class Region { public final int getRenderModes() { return renderModes; } - public boolean usesTwoPassRendering() { return Region.usesTwoPassRendering(renderModes); } + public boolean isVBAA() { return Region.isVBAA(renderModes); } public boolean usesVariableCurveWeight() { return Region.usesVariableCurveWeight(renderModes); } /** Get the current number of vertices associated diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java index 8624c582c..86d962fd8 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -38,7 +38,7 @@ public abstract class RegionRenderer extends Renderer { /** * Create a Hardware accelerated Region Renderer. * @param rs the used {@link RenderState} - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT} + * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} * @return an instance of Region Renderer */ public static RegionRenderer create(RenderState rs, int renderModes) { diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java index 5e25a4ced..b466670cc 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -41,10 +41,10 @@ public abstract class TextRenderer extends Renderer { /** * Create a Hardware accelerated Text Renderer. * @param rs the used {@link RenderState} - * @param renderModes either {@link com.jogamp.graph.curve.opengl.GLRegion#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS_RENDERING_BIT} + * @param renderModes either {@link com.jogamp.graph.curve.opengl.GLRegion#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#VBAA_RENDERING_BIT} */ - public static TextRenderer create(RenderState rs, int type) { - return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, type); + public static TextRenderer create(RenderState rs, int renderModes) { + return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, renderModes); } protected TextRenderer(RenderState rs, int type) { diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java deleted file mode 100644 index f71105983..000000000 --- a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.graph.curve.tess; - -import java.util.ArrayList; - -import jogamp.graph.curve.tess.GraphOutline; -import jogamp.graph.curve.tess.GraphVertex; -import jogamp.graph.curve.tess.Loop; - -import com.jogamp.graph.geom.Outline; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.math.VectorUtil; - -import jogamp.opengl.Debug; - -/** Constrained Delaunay Triangulation - * implementation of a list of Outlines that define a set of - * Closed Regions with optional n holes. - * - */ -public class CDTriangulator2D { - - protected static final boolean DEBUG = Debug.debug("Triangulation"); - - private float sharpness = 0.5f; - private ArrayList loops; - private ArrayList vertices; - - private ArrayList triangles; - private int maxTriID = 0; - - - /** Constructor for a new Delaunay triangulator - */ - public CDTriangulator2D() { - reset(); - } - - /** Reset the triangulation to initial state - * Clearing cached data - */ - public void reset() { - maxTriID = 0; - vertices = new ArrayList(); - triangles = new ArrayList(3); - loops = new ArrayList(); - } - - /** Add a curve to the list of profiles provided - * @param polyline a bounding {@link Outline} - */ - public void addCurve(Outline polyline) { - Loop loop = null; - - // FIXME: multiple in/out and CW/CCW tests (as follows) ?? - - if(!loops.isEmpty()) { - loop = getContainerLoop(polyline); - } - - if(loop == null) { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(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()); - loop.addConstraintCurve(innerPoly); - } - } - - /** Generate the triangulation of the provided - * List of {@link Outline}s - */ - public ArrayList generate() { - for(int i=0;i size){ - tri = loop.cut(false); - } - else{ - tri = loop.cut(true); - } - numTries++; - - if(tri != null) { - numTries = 0; - size--; - tri.setId(maxTriID++); - triangles.add(tri); - if(DEBUG){ - System.err.println(tri); - } - } - if(numTries > size*2){ - if(DEBUG){ - System.err.println("Triangulation not complete!"); - } - break; - } - } - Triangle tri = loop.cut(true); - if(tri != null) - triangles.add(tri); - } - return triangles; - } - - 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; - - if(!currentVertex.getPoint().isOnCurve()) { - Vertex v0 = gv0.getPoint().clone(); - Vertex v2 = gv2.getPoint().clone(); - Vertex v1 = gv1.getPoint().clone(); - - gv0.setBoundaryContained(true); - gv1.setBoundaryContained(true); - gv2.setBoundaryContained(true); - - final Triangle t; - final boolean holeLike; - if(VectorUtil.ccw(v0,v1,v2)) { - holeLike = false; - t = new Triangle(v0, v1, v2); - } else { - holeLike = true; - t = new Triangle(v2, v1, v0); - } - t.setId(maxTriID++); - triangles.add(t); - if(DEBUG){ - System.err.println(t); - } - if( hole || holeLike ) { - v0.setTexCoord(0, -0.1f); - v2.setTexCoord(1, -0.1f); - v1.setTexCoord(0.5f, -1*sharpness -0.1f); - innerOutline.addVertex(currentVertex); - } else { - v0.setTexCoord(0, 0.1f); - v2.setTexCoord(1, 0.1f); - v1.setTexCoord(0.5f, sharpness+0.1f); - } - } - else { - if(!gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve()){ - currentVertex.setBoundaryContained(true); - } - innerOutline.addVertex(currentVertex); - } - } - return innerOutline; - } - - private Loop getContainerLoop(Outline polyline) { - ArrayList vertices = polyline.getVertices(); - for(int i=0; i < loops.size(); i++) { - Loop loop = loops.get(i); - boolean inside = false; - for(int j=0; j < vertices.size(); j++) { - Vertex v = vertices.get(j); - inside |= loop.checkInside(v); - } - if(inside) { - return loop; - } - } - return null; - } -} diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java new file mode 100644 index 000000000..7728efcaf --- /dev/null +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java @@ -0,0 +1,44 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.graph.curve.tess; + +import jogamp.graph.curve.tess.CDTriangulator2D; + + +public class Triangulation { + /** Create a new instance of a triangulation. + * Currently only a modified version of Constraint Delaunay + * is implemented. + * @return instance of a triangulator + * @see Triangulator + */ + public static Triangulator create() { + return new CDTriangulator2D(); + } +} diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java new file mode 100644 index 000000000..1ffaccebc --- /dev/null +++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java @@ -0,0 +1,69 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.graph.curve.tess; + +import java.util.ArrayList; + +import com.jogamp.graph.geom.Outline; +import com.jogamp.graph.geom.Triangle; + +/** Interface to the triangulation algorithms provided + * A triangulation of 2D outlines where you can + * provides an easy one or more outlines to be triangulated + * + * example usage: + * addCurve(o1); + * addCurve(o2); + * addCurve(o3); + * generate(); + * reset(); + * + * @see Outline + * @see Triangulation + */ +public interface Triangulator { + + /** Add a curve to the list of Outlines + * describing the shape + * @param outline a bounding {@link Outline} + */ + public void addCurve(Outline outline); + + /** Generate the triangulation of the provided + * List of {@link Outline}s + * @return an arraylist of {@link Triangle}s resembling the + * final shape. + */ + public ArrayList generate(); + + /** Reset the triangulation to initial state + * Clearing cached data + */ + public void reset(); +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java index b5a89b40a..e33a78ed8 100755 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java @@ -39,14 +39,14 @@ public class RegionFactory { /** * Create a Region using the passed render mode * - *

In case {@link Region#TWO_PASS_RENDERING_BIT} is being requested the default texture unit + *

In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.

* * @param rs the RenderState to be used - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT} + * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} */ public static GLRegion create(int renderModes) { - if( 0 != ( Region.TWO_PASS_RENDERING_BIT & renderModes ) ){ + if( 0 != ( Region.VBAA_RENDERING_BIT & renderModes ) ){ return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT); } else{ diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java new file mode 100644 index 000000000..10b6d6847 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -0,0 +1,203 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.graph.curve.tess; + +import java.util.ArrayList; + + +import com.jogamp.graph.curve.tess.Triangulator; +import com.jogamp.graph.geom.Outline; +import com.jogamp.graph.geom.Triangle; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.math.VectorUtil; + +import jogamp.opengl.Debug; + +/** Constrained Delaunay Triangulation + * implementation of a list of Outlines that define a set of + * Closed Regions with optional n holes. + * + */ +public class CDTriangulator2D implements Triangulator{ + + protected static final boolean DEBUG = Debug.debug("Triangulation"); + + private float sharpness = 0.5f; + private ArrayList loops; + private ArrayList vertices; + + private ArrayList triangles; + private int maxTriID = 0; + + + /** Constructor for a new Delaunay triangulator + */ + public CDTriangulator2D() { + reset(); + } + + /** Reset the triangulation to initial state + * Clearing cached data + */ + public void reset() { + maxTriID = 0; + vertices = new ArrayList(); + triangles = new ArrayList(3); + loops = new ArrayList(); + } + + 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); + 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()); + loop.addConstraintCurve(innerPoly); + } + } + + public ArrayList generate() { + for(int i=0;i size){ + tri = loop.cut(false); + } + else{ + tri = loop.cut(true); + } + numTries++; + + if(tri != null) { + numTries = 0; + size--; + tri.setId(maxTriID++); + triangles.add(tri); + if(DEBUG){ + System.err.println(tri); + } + } + if(numTries > size*2){ + if(DEBUG){ + System.err.println("Triangulation not complete!"); + } + break; + } + } + Triangle tri = loop.cut(true); + if(tri != null) + triangles.add(tri); + } + return triangles; + } + + 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; + + if(!currentVertex.getPoint().isOnCurve()) { + Vertex v0 = gv0.getPoint().clone(); + Vertex v2 = gv2.getPoint().clone(); + Vertex v1 = gv1.getPoint().clone(); + + gv0.setBoundaryContained(true); + gv1.setBoundaryContained(true); + gv2.setBoundaryContained(true); + + final Triangle t; + final boolean holeLike; + if(VectorUtil.ccw(v0,v1,v2)) { + holeLike = false; + t = new Triangle(v0, v1, v2); + } else { + holeLike = true; + t = new Triangle(v2, v1, v0); + } + t.setId(maxTriID++); + triangles.add(t); + if(DEBUG){ + System.err.println(t); + } + if( hole || holeLike ) { + v0.setTexCoord(0, -0.1f); + v2.setTexCoord(1, -0.1f); + v1.setTexCoord(0.5f, -1*sharpness -0.1f); + innerOutline.addVertex(currentVertex); + } else { + v0.setTexCoord(0, 0.1f); + v2.setTexCoord(1, 0.1f); + v1.setTexCoord(0.5f, sharpness+0.1f); + } + } + else { + if(!gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve()){ + currentVertex.setBoundaryContained(true); + } + innerOutline.addVertex(currentVertex); + } + } + return innerOutline; + } + + private Loop getContainerLoop(Outline polyline) { + ArrayList vertices = polyline.getVertices(); + for(int i=0; i < loops.size(); i++) { + Loop loop = loops.get(i); + boolean inside = false; + for(int j=0; j < vertices.size(); j++) { + Vertex v = vertices.get(j); + inside |= loop.checkInside(v); + } + if(inside) { + return loop; + } + } + return null; + } +} diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index c07b41a7b..2fa708404 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -137,7 +137,7 @@ public class GlyphString { /** Generate a OGL Region to represent this Object. * @param gl the current gl object * @param rs the current attached RenderState - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT} + * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} */ public GLRegion createRegion(GL2ES2 gl, int renderModes){ region = RegionFactory.create(renderModes); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java index c9c235c69..13aa266dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java @@ -67,7 +67,7 @@ public class TestRegionRendererNEWT01 extends UITestCase { GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.TWO_PASS_RENDERING_BIT, 1140, false, false); + GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 1140, false, false); demo02Listener.attachInputListenerTo(window); window.addGLEventListener(demo02Listener); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java index a3bf215d9..acbcbc7da 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java @@ -69,7 +69,7 @@ public class TestTextRendererNEWT01 extends UITestCase { GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - TextGLListener textGLListener = new TextGLListener(rs, Region.TWO_PASS_RENDERING_BIT, DEBUG, TRACE); + TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java index 4cba9cbd5..f1db1ccdd 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -64,7 +64,7 @@ public class GPURegionNewtDemo02 { window.setTitle("GPU Curve Region Newt Demo 02 - vbaa1 msaa0"); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.TWO_PASS_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 1140, DEBUG, TRACE); + GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 1140, DEBUG, TRACE); regionGLListener.attachInputListenerTo(window); window.addGLEventListener(regionGLListener); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index 9587a672d..e9df473ac 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -274,7 +274,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { autoDrawable.invoke(false, new GLRunnable() { public void run(GLAutoDrawable drawable) { try { - final String type = Region.usesTwoPassRendering(renderModes) ? "r2t0-msaa1" : "r2t1-msaa0" + ( Region.usesVariableCurveWeight(renderModes) ? "-vc" : "-uc" ) ; + final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.usesVariableCurveWeight(renderModes) ? "-vc" : "-uc" ) ; printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false); screenshot_num++; } catch (GLException e) { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 320e79472..d7dff5170 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -71,7 +71,7 @@ public class GPUTextNewtDemo02 { window.setTitle("GPU Text Newt Demo 02 - vbaa1 msaa0"); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.TWO_PASS_RENDERING_BIT, window.getWidth()*3, DEBUG, TRACE); + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, window.getWidth()*3, DEBUG, TRACE); // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); -- cgit v1.2.3