summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph/curve
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph/curve')
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/OutlineShape.java6
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java14
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java6
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java213
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulation.java44
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java69
7 files changed, 128 insertions, 226 deletions
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<OutlineShape> {
sortOutlines();
generateVertexIds();
- CDTriangulator2D triangulator2d = new CDTriangulator2D();
+ Triangulator triangulator2d = Triangulation.create();
for(int index = 0; index<outlines.size(); index++) {
triangulator2d.addCurve(outlines.get(index));
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 46bdedee4..168d8dd70 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -39,9 +39,11 @@ public abstract class Region {
public static final boolean DEBUG = Debug.debug("graph.curve");
public static final boolean DEBUG_INSTANCE = false;
- /** Two pass region rendering, slower and more resource hungry (FBO), but AA is perfect.
- * Otherwise the default fast one pass MSAA region rendering is being used. */
- public static final int TWO_PASS_RENDERING_BIT = 1 << 0;
+ /** View based Anti-Aliasing, A Two pass region rendering, slower
+ * and more resource hungry (FBO), but AA is perfect.
+ * Otherwise the default fast one pass MSAA region rendering is being used.
+ */
+ public static final int VBAA_RENDERING_BIT = 1 << 0;
/** Use non uniform weights [0.0 .. 1.9] for curve region rendering.
* Otherwise the default weight 1.0 for Bezier curve region rendering is being applied. */
@@ -57,8 +59,8 @@ public abstract class Region {
protected ArrayList<Triangle> triangles = new ArrayList<Triangle>();
protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- 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<Loop> loops;
- private ArrayList<Vertex> vertices;
-
- private ArrayList<Triangle> 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<Vertex>();
- triangles = new ArrayList<Triangle>(3);
- loops = new ArrayList<Loop>();
- }
-
- /** 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<Triangle> generate() {
- for(int i=0;i<loops.size();i++) {
- Loop loop = loops.get(i);
- int numTries = 0;
- int size = loop.computeLoopSize();
- while(!loop.isSimplex()){
- Triangle tri = null;
- if(numTries > 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<GraphVertex> 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<Vertex> 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<Triangle> generate();
+
+ /** Reset the triangulation to initial state
+ * Clearing cached data
+ */
+ public void reset();
+}