aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2015-11-26 21:52:00 +0100
committerJulien Gouesse <[email protected]>2015-11-26 21:52:00 +0100
commitc658d3657620ce0d1a3f1632f869465ee184d61c (patch)
tree4b3c18868d5dca4faea73a4318ce93ce4d8b5051
parentad8bc1fcd732d57a448d131d42cf909966ef7df3 (diff)
parent623b5ddab831a0b364e6df3c068699d42f4583fb (diff)
Merge pull request #1 from scijava/circular-deps
Eliminate circular dependency between core & utils
-rw-r--r--build.xml4
-rw-r--r--src/javax/media/j3d/Font3D.java45
-rw-r--r--src/javax/media/j3d/GeometryService.java40
3 files changed, 64 insertions, 25 deletions
diff --git a/build.xml b/build.xml
index dd1df25..9bfe448 100644
--- a/build.xml
+++ b/build.xml
@@ -84,7 +84,7 @@
<copy todir="${class.dir}">
<fileset dir="${src.dir}" includes="**/*.properties"/>
- <fileset dir="${j3dtools.src.dir}/classes/share" includes="**/*.properties"/>
+ <fileset dir="${j3dtools.src.dir}/classes/share" includes="META-INF/** **/*.properties"/>
</copy>
</target>
@@ -118,7 +118,7 @@
<attribute name="Extension-Name" value="javax.media.j3d"/>
<attribute name="Implementation-Vendor-Id" value="${build.impl.vendor.id}"/>
</manifest>
- <fileset dir="${class.dir}" includes="com/**/*"/>
+ <fileset dir="${class.dir}" includes="META-INF/** com/**/*"/>
</jar>
<zip destfile="${build.dir}/jars/j3dcore-src.zip">
diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java
index 7dc3a44..0d7c631 100644
--- a/src/javax/media/j3d/Font3D.java
+++ b/src/javax/media/j3d/Font3D.java
@@ -37,14 +37,13 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.ServiceLoader;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
-import com.sun.j3d.utils.geometry.GeometryInfo;
-import com.sun.j3d.utils.geometry.NormalGenerator;
-
/**
* The Font3D object is used to store extruded 2D glyphs. These
* 3D glyphs can then be used to construct Text3D NodeComponent
@@ -460,29 +459,19 @@ private static class IntVector {
vertices = null;
int[] contourCounts = new int[1];
- int currCoordIndex = 0, vertOffset = 0;
- ArrayList<GeometryArray> triangData = new ArrayList<GeometryArray>();
+ ArrayList<GeometryArray> triangData = new ArrayList<GeometryArray>();
Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f();
Vector3f n1 = new Vector3f(), n2 = new Vector3f();
numPoints = 0;
- //Now loop thru each island, calling triangulator once per island.
- //Combine triangle data for all islands together in one object.
- NormalGenerator ng = new NormalGenerator();
- for (i = 0; i < islandCounts.length; i++) {
- contourCounts[0] = islandCounts[i].length;
- numPoints += outVerts[i].length;
- GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
- gi.setCoordinates(outVerts[i]);
- gi.setStripCounts(islandCounts[i]);
- gi.setContourCounts(contourCounts);
- ng.generateNormals(gi);
-
- GeometryArray ga = gi.getGeometryArray(false, false, false);
- vertOffset += ga.getVertexCount();
-
- triangData.add(ga);
- }
+ for (i = 0; i < islandCounts.length; i++) {
+ numPoints += outVerts[i].length;
+ }
+
+ final GeometryService gs = newGeometryService();
+ int vertOffset =
+ gs.triangulateIslands(islandCounts, outVerts, contourCounts, triangData);
+
// Multiply by 2 since we create 2 faces of the font
// Second term is for side-faces along depth of the font
if (fontExtrusion == null)
@@ -508,7 +497,7 @@ private static class IntVector {
// last known non-degenerate normal
Vector3f goodNormal = new Vector3f();
-
+ int currCoordIndex = 0;
for (j=0;j < islandCounts.length;j++) {
GeometryArray ga = triangData.get(j);
vertOffset = ga.getVertexCount();
@@ -957,6 +946,16 @@ private static class IntVector {
return geo;
}
+ private GeometryService newGeometryService() {
+ final ServiceLoader<GeometryService> gsLoader =
+ ServiceLoader.load(GeometryService.class);
+
+ final Iterator<GeometryService> iter = gsLoader.iterator();
+ if (iter.hasNext()) return iter.next();
+
+ throw new IllegalStateException("No GeometryService implementation found. "
+ + "Please add j3d-core-utils to the classpath.");
+ }
static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) {
Vector3f v1 = new Vector3f();
diff --git a/src/javax/media/j3d/GeometryService.java b/src/javax/media/j3d/GeometryService.java
new file mode 100644
index 0000000..346087c
--- /dev/null
+++ b/src/javax/media/j3d/GeometryService.java
@@ -0,0 +1,40 @@
+
+package javax.media.j3d;
+
+import java.util.ArrayList;
+
+import javax.vecmath.Point3f;
+
+/**
+ * A service interface for certain geometric operations that are not available
+ * in core Java 3D.
+ * <p>
+ * In particular, the {@code j3d-core-utils} project provides additional
+ * functionality under a different license, which is needed in some
+ * circumstances by core Java 3D. Thus, historically, these two projects have
+ * been co-dependent. This interface breaks the circular dependency by using
+ * Java's service discovery mechanism: if {@code j3d-core-utils} is present on
+ * the classpath, its {@code GeometryServiceImpl} will provide the functionality
+ * defined here. Or if not (i.e., no suitable {@code GeometryService}
+ * implementation can be discovered and instantiated}), then the Java3D core
+ * will fail as gracefully as possible.
+ * </p>
+ *
+ * @see Font3D#triangulateGlyphs
+ */
+public interface GeometryService {
+
+ /**
+ * Loops through each island, calling triangulator once per island. Combines
+ * triangle data for all islands together in one object.
+ *
+ * @param islandCounts TODO
+ * @param outVerts TODO
+ * @param contourCounts TODO
+ * @param triangData TODO
+ * @return total vertex count of the combined array
+ */
+ int triangulateIslands(int[][] islandCounts, Point3f[][] outVerts,
+ int[] contourCounts, ArrayList<GeometryArray> triangData);
+
+}