diff options
Diffstat (limited to 'src/GeometryByReference')
-rw-r--r-- | src/GeometryByReference/GeometryByReferenceNIOBuffer.java | 514 | ||||
-rw-r--r-- | src/GeometryByReference/GeometryByReferenceTest.html | 15 | ||||
-rw-r--r-- | src/GeometryByReference/GeometryByReferenceTest.java | 552 | ||||
-rw-r--r-- | src/GeometryByReference/GeometryByReferenceTest_plugin.html | 39 | ||||
-rw-r--r-- | src/GeometryByReference/ImageComponentByReferenceTest.html | 15 | ||||
-rw-r--r-- | src/GeometryByReference/ImageComponentByReferenceTest.java | 328 | ||||
-rw-r--r-- | src/GeometryByReference/ImageComponentByReferenceTest_plugin.html | 39 | ||||
-rw-r--r-- | src/GeometryByReference/InterleavedNIOBuffer.java | 531 | ||||
-rw-r--r-- | src/GeometryByReference/InterleavedTest.html | 15 | ||||
-rw-r--r-- | src/GeometryByReference/InterleavedTest.java | 504 | ||||
-rw-r--r-- | src/GeometryByReference/InterleavedTest_plugin.html | 39 | ||||
-rw-r--r-- | src/GeometryByReference/TiledImage.java | 356 | ||||
-rw-r--r-- | src/GeometryByReference/build.xml | 66 |
13 files changed, 3013 insertions, 0 deletions
diff --git a/src/GeometryByReference/GeometryByReferenceNIOBuffer.java b/src/GeometryByReference/GeometryByReferenceNIOBuffer.java new file mode 100644 index 0000000..183b7b1 --- /dev/null +++ b/src/GeometryByReference/GeometryByReferenceNIOBuffer.java @@ -0,0 +1,514 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; +import javax.media.j3d.*; +import javax.vecmath.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.border.*; +import com.sun.j3d.utils.behaviors.vp.*; +import java.nio.*; + +public class GeometryByReferenceNIOBuffer extends JApplet implements ActionListener, +GeometryUpdater { + + RenderingAttributes ra; + ColoringAttributes ca; + Material mat; + Appearance app; + JComboBox geomType; + JComboBox vertexType; + JComboBox colorType; + JCheckBox transparency; + JComboBox updates; + Shape3D shape; + TransparencyAttributes transp; + int updateIndex = 0; + int colorCount = 0, vertexCount = 0; + int vertexIndex = 0, colorIndex = 0; + + GeometryArray tetraRegular, tetraStrip, tetraIndexed, tetraIndexedStrip; + GeometryArray[] geoArrays = new GeometryArray[4]; + + private static final float sqrt3 = (float) Math.sqrt(3.0); + private static final float sqrt3_3 = sqrt3 / 3.0f; + private static final float sqrt24_3 = (float) Math.sqrt(24.0) / 3.0f; + + private static final float ycenter = 0.5f * sqrt24_3; + private static final float zcenter = -sqrt3_3; + + private static final Point3f p1 = + new Point3f(-1.0f, -ycenter, -zcenter); + private static final Point3f p2 = + new Point3f(1.0f, -ycenter, -zcenter); + private static final Point3f p3 = + new Point3f(0.0f, -ycenter, -sqrt3 - zcenter); + private static final Point3f p4 = + new Point3f(0.0f, sqrt24_3 - ycenter, 0.0f); + + private static final float[] floatVerts = { + p1.x, p1.y, p1.z, // front face + p2.x, p2.y, p2.z, + p4.x, p4.y, p4.z, + + p1.x, p1.y, p1.z,// left, back face + p4.x, p4.y, p4.z, + p3.x, p3.y, p3.z, + + p2.x, p2.y, p2.z,// right, back face + p3.x, p3.y, p3.z, + p4.x, p4.y, p4.z, + + p1.x, p1.y, p1.z,// bottom face + p3.x, p3.y, p3.z, + p2.x, p2.y, p2.z, + }; + + private static final Color3f c1 = new Color3f(0.6f, 0.0f, 0.0f); + private static final Color3f c2 = new Color3f(0.0f, 0.6f, 0.0f); + private static final Color3f c3 = new Color3f(0.0f, 0.6f, 0.6f); + private static final Color3f c4 = new Color3f(0.6f, 0.6f, 0.0f); + + + + private static final float[] floatClrs = { + c1.x, c1.y, c1.z, // front face + c2.x, c2.y, c2.z, + c4.x, c4.y, c4.z, + + c1.x, c1.y, c1.z,// left, back face + c4.x, c4.y, c4.z, + c3.x, c3.y, c3.z, + + c2.x, c2.y, c2.z,// right, back face + c3.x, c3.y, c3.z, + c4.x, c4.y, c4.z, + + c1.x, c1.y, c1.z,// bottom face + c3.x, c3.y, c3.z, + c2.x, c2.y, c2.z, + }; + + private static final float[] indexedFloatVerts = { + p1.x,p1.y,p1.z, + p2.x,p2.y,p2.z, + p3.x,p3.y,p3.z, + p4.x,p4.y,p4.z, + + }; + + + private static final float[] indexedFloatClrs = { + c1.x,c1.y,c1.z, + c2.x,c2.y,c2.z, + c3.x,c3.y,c3.z, + c4.x,c4.y,c4.z, + }; + + private static final int[] indices = {0,1,3,0,3,2,1,2,3,0,2,1}; + private int[] stripVertexCounts = {3,3,3,3}; + + private SimpleUniverse u; + + private J3DBuffer floatBufferCoord; + private J3DBuffer floatBufferColor; + private J3DBuffer indexedFloatBufferCoord; + private J3DBuffer indexedFloatBufferColor; + + void createJ3DBuffers() { + int i; + ByteOrder order = ByteOrder.nativeOrder(); + + FloatBuffer coord = ByteBuffer.allocateDirect(36 * 4).order(order).asFloatBuffer(); + coord.put(floatVerts, 0, 36); + floatBufferCoord = new J3DBuffer(coord); + + FloatBuffer color = ByteBuffer.allocateDirect(36 * 4).order(order).asFloatBuffer(); + color.put(floatClrs, 0, 36); + floatBufferColor = new J3DBuffer(color); + + FloatBuffer indexedCoord = ByteBuffer.allocateDirect(12 * 4).order(order).asFloatBuffer(); + indexedCoord.put(indexedFloatVerts, 0, 12); + indexedFloatBufferCoord = new J3DBuffer(indexedCoord); + + FloatBuffer indexedColor = ByteBuffer.allocateDirect(12 * 4).order(order).asFloatBuffer(); + indexedColor.put(indexedFloatClrs, 0, 12); + indexedFloatBufferColor = new J3DBuffer(indexedColor); + } + + BranchGroup createSceneGraph() { + BranchGroup objRoot = new BranchGroup(); + + // Set up attributes to render lines + app = new Appearance(); + + transp = new TransparencyAttributes(); + transp.setTransparency(0.5f); + transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); + transp.setTransparencyMode(TransparencyAttributes.NONE); + app.setTransparencyAttributes(transp); + + //create the direct nio buffer + createJ3DBuffers(); + + tetraRegular = createGeometry(1); + tetraStrip =createGeometry(2); + tetraIndexed = createGeometry(3); + tetraIndexedStrip = createGeometry(4); + + geoArrays[0] = tetraRegular; + geoArrays[1] = tetraStrip; + geoArrays[2] = tetraIndexed; + geoArrays[3] = tetraIndexedStrip; + + shape = new Shape3D(tetraRegular, app); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + + Transform3D t = new Transform3D(); + // move the object upwards + t.set(new Vector3f(0.0f, 0.3f, 0.0f)); + + // rotate the shape + Transform3D temp = new Transform3D(); + temp.rotX(Math.PI/4.0d); + t.mul(temp); + temp.rotY(Math.PI/4.0d); + t.mul(temp); + + // Shrink the object + t.setScale(0.6); + + TransformGroup trans = new TransformGroup(t); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); + + objRoot.addChild(trans); + trans.addChild(shape); + + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Set up the global lights + Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); + Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); + Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); + + AmbientLight aLgt = new AmbientLight(alColor); + aLgt.setInfluencingBounds(bounds); + DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); + lgt1.setInfluencingBounds(bounds); + objRoot.addChild(aLgt); + objRoot.addChild(lgt1); + + // Let Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + JPanel createGeometryByReferencePanel() { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Geometry Type")); + + String values[] = {"Array", "Strip", "Indexed", "IndexedStrip"}; + geomType = new JComboBox(values); + geomType.setLightWeightPopupEnabled(false); + geomType.addActionListener(this); + geomType.setSelectedIndex(0); + panel.add(new JLabel("Geometry Type")); + panel.add(geomType); + + return panel; + } + + JPanel createUpdatePanel() { + + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Other Attributes")); + + String updateComp[] = { "None","Geometry", "Color"}; + + transparency = new JCheckBox("EnableTransparency", + false); + transparency.addActionListener(this); + panel.add(transparency); + + + updates = new JComboBox(updateComp); + updates.setLightWeightPopupEnabled(false); + updates.addActionListener(this); + updates.setSelectedIndex(0); + panel.add(new JLabel("UpdateData")); + panel.add(updates); + + return panel; + } + + + + public GeometryByReferenceNIOBuffer() { + } + + public void init() { + Container contentPane = getContentPane(); + + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); + contentPane.add("Center", c); + + BranchGroup scene = createSceneGraph(); + // SimpleUniverse is a Convenience Utility class + u = new SimpleUniverse(c); + + // add mouse behaviors to the viewingPlatform + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + u.addBranchGraph(scene); + + // add Orbit behavior to the ViewingPlatform + OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + // Create GUI + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.add(createGeometryByReferencePanel()); + p.add(createUpdatePanel()); + p.setLayout(boxlayout); + + contentPane.add("South", p); + } + + public void destroy() { + u.cleanup(); + } + + public void actionPerformed(ActionEvent e) { + Object target = e.getSource(); + GeometryArray geo; + boolean setColor = false, setVertex = false; + if (target == geomType) { + geo = geoArrays[geomType.getSelectedIndex()]; + // Set everything to null, and set it later .. + geo.setColorRefBuffer(null); + geo.setCoordRefBuffer(null); + shape.setGeometry(geoArrays[geomType.getSelectedIndex()]); + + setColor = true; + setVertex= true; + + + } + else if (target == transparency) { + if (transparency.isSelected()) { + transp.setTransparencyMode(TransparencyAttributes.BLENDED); + } + else { + transp.setTransparencyMode(TransparencyAttributes.NONE); + } + + } + else if (target == updates) { + updateIndex = updates.getSelectedIndex(); + if (updateIndex == 1) { + System.out.println("Doing coordinate update"); + ((GeometryArray)(shape.getGeometry())).updateData(this); + } + else if (updateIndex == 2) { + System.out.println("Doing color update"); + ((GeometryArray)(shape.getGeometry())).updateData(this); + } + + } + + if (setVertex) { + geo = (GeometryArray) shape.getGeometry(); + if (geo instanceof IndexedGeometryArray) + geo.setCoordRefBuffer(indexedFloatBufferCoord); + else + geo.setCoordRefBuffer(floatBufferCoord); + + } + if (setColor) { + geo = (GeometryArray) shape.getGeometry(); + if (geo instanceof IndexedGeometryArray) + geo.setColorRefBuffer(indexedFloatBufferColor); + else + geo.setColorRefBuffer(floatBufferColor); + } + } + + + + public static void main(String[] args) { + Frame frame = new MainFrame(new GeometryByReferenceNIOBuffer(), 800, 800); + } + + public GeometryArray createGeometry (int type) { + GeometryArray tetra = null; + if (type == 1) { + tetra =new TriangleArray(12, + TriangleArray.COORDINATES| + TriangleArray.COLOR_3| + TriangleArray.BY_REFERENCE| + TriangleArray.USE_NIO_BUFFER); + + tetra.setCoordRefBuffer(floatBufferCoord); + tetra.setColorRefBuffer(floatBufferColor); + + } + else if (type == 2) { + tetra = new TriangleStripArray(12, + TriangleStripArray.COORDINATES| + TriangleStripArray.COLOR_3| + TriangleStripArray.BY_REFERENCE| + TriangleStripArray.USE_NIO_BUFFER, + stripVertexCounts); + tetra.setCoordRefBuffer(floatBufferCoord); + tetra.setColorRefBuffer(floatBufferColor); + + } + else if (type == 3) { // Indexed Geometry + tetra = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES| + IndexedTriangleArray.COLOR_3| + IndexedTriangleArray.BY_REFERENCE| + IndexedTriangleArray.USE_NIO_BUFFER, + //IndexedTriangleStripArray.USE_COORD_INDEX_ONLY, + 12); + tetra.setCoordRefBuffer(indexedFloatBufferCoord); + tetra.setColorRefBuffer(indexedFloatBufferColor); + ((IndexedTriangleArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleArray)tetra).setColorIndices(0, indices); + } + else if (type == 4) { // Indexed strip geometry + tetra = new IndexedTriangleStripArray(4, + IndexedTriangleStripArray.COORDINATES| + IndexedTriangleStripArray.COLOR_3| + IndexedTriangleStripArray.BY_REFERENCE| + IndexedTriangleStripArray.USE_NIO_BUFFER| + IndexedTriangleStripArray.USE_COORD_INDEX_ONLY, + 12, + stripVertexCounts); + tetra.setCoordRefBuffer(indexedFloatBufferCoord); + tetra.setColorRefBuffer(indexedFloatBufferColor); + ((IndexedTriangleStripArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setColorIndices(0, indices); + } + + if (tetra != null) + tetra.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE); + return tetra; + } + + public void updateData(Geometry geometry) { + int i; + float val; + float val1; + if (updateIndex == 1) { // geometry + // Translate the geometry by a small amount in x + vertexCount++; + if ((vertexCount &1) == 1) + val = 0.2f; + else + val = -0.2f; + + FloatBuffer indexedCoord = (FloatBuffer)indexedFloatBufferCoord.getBuffer(); + indexedCoord.rewind(); + FloatBuffer coord = (FloatBuffer)floatBufferCoord.getBuffer(); + coord.rewind(); + + if (vertexIndex == 0) { + // Do Indexed geometry + for (i = 0; i < indexedCoord.limit(); i+=3) { + val1 = indexedCoord.get(i); + indexedCoord.put(i, val1 + val); + } + // Do non-indexed float geometry + for (i = 0; i < coord.limit(); i+=3) { + val1 = coord.get(i); + coord.put(i, val1 + val); + } + } + } + else if (updateIndex == 2) { // colors + colorCount++; + if ((colorCount & 1) == 1) + val = 0.4f; + else + val = -0.4f; + + FloatBuffer indexedColors = (FloatBuffer)indexedFloatBufferColor.getBuffer(); + indexedColors.rewind(); + FloatBuffer colors = (FloatBuffer)floatBufferColor.getBuffer(); + colors.rewind(); + + if (colorIndex == 0) { + // Do Indexed geometry + for (i = 0; i < indexedColors.limit(); i+=3) { + indexedColors.put(i, indexedColors.get(i) + val); + } + // Do non-indexed float geometry + for (i = 0; i < colors.limit(); i+=3) { + colors.put(i, colors.get(i) + val); + } + } + + } + + } +} diff --git a/src/GeometryByReference/GeometryByReferenceTest.html b/src/GeometryByReference/GeometryByReferenceTest.html new file mode 100644 index 0000000..8bc7c8a --- /dev/null +++ b/src/GeometryByReference/GeometryByReferenceTest.html @@ -0,0 +1,15 @@ +<HTML> +<HEAD> +<TITLE>GeometryByReferenceTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<applet align=middle code="GeometryByReferenceTest.class" width=800 height=800> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</applet> +</BODY> +</HTML> diff --git a/src/GeometryByReference/GeometryByReferenceTest.java b/src/GeometryByReference/GeometryByReferenceTest.java new file mode 100644 index 0000000..486f5dc --- /dev/null +++ b/src/GeometryByReference/GeometryByReferenceTest.java @@ -0,0 +1,552 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; +import javax.media.j3d.*; +import javax.vecmath.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.border.*; +import com.sun.j3d.utils.behaviors.vp.*; + +public class GeometryByReferenceTest extends JApplet implements ActionListener, +GeometryUpdater { + + RenderingAttributes ra; + ColoringAttributes ca; + Material mat; + Appearance app; + JComboBox geomType; + JComboBox vertexType; + JComboBox colorType; + JCheckBox transparency; + JComboBox updates; + Shape3D shape; + TransparencyAttributes transp; + int updateIndex = 0; + int colorCount = 0, vertexCount = 0; + int vertexIndex = 0, colorIndex = 0; + + GeometryArray tetraRegular, tetraStrip, tetraIndexed, tetraIndexedStrip; + GeometryArray[] geoArrays = new GeometryArray[4]; + + private static final float sqrt3 = (float) Math.sqrt(3.0); + private static final float sqrt3_3 = sqrt3 / 3.0f; + private static final float sqrt24_3 = (float) Math.sqrt(24.0) / 3.0f; + + private static final float ycenter = 0.5f * sqrt24_3; + private static final float zcenter = -sqrt3_3; + + private static final Point3f p1 = + new Point3f(-1.0f, -ycenter, -zcenter); + private static final Point3f p2 = + new Point3f(1.0f, -ycenter, -zcenter); + private static final Point3f p3 = + new Point3f(0.0f, -ycenter, -sqrt3 - zcenter); + private static final Point3f p4 = + new Point3f(0.0f, sqrt24_3 - ycenter, 0.0f); + + + private static final float[] floatVerts = { + p1.x, p1.y, p1.z, // front face + p2.x, p2.y, p2.z, + p4.x, p4.y, p4.z, + + p1.x, p1.y, p1.z,// left, back face + p4.x, p4.y, p4.z, + p3.x, p3.y, p3.z, + + p2.x, p2.y, p2.z,// right, back face + p3.x, p3.y, p3.z, + p4.x, p4.y, p4.z, + + p1.x, p1.y, p1.z,// bottom face + p3.x, p3.y, p3.z, + p2.x, p2.y, p2.z, + }; + + private static final Color3f c1 = new Color3f(0.6f, 0.0f, 0.0f); + private static final Color3f c2 = new Color3f(0.0f, 0.6f, 0.0f); + private static final Color3f c3 = new Color3f(0.0f, 0.6f, 0.6f); + private static final Color3f c4 = new Color3f(0.6f, 0.6f, 0.0f); + + + private static final float[] floatClrs = { + c1.x, c1.y, c1.z, // front face + c2.x, c2.y, c2.z, + c4.x, c4.y, c4.z, + + c1.x, c1.y, c1.z,// left, back face + c4.x, c4.y, c4.z, + c3.x, c3.y, c3.z, + + c2.x, c2.y, c2.z,// right, back face + c3.x, c3.y, c3.z, + c4.x, c4.y, c4.z, + + c1.x, c1.y, c1.z,// bottom face + c3.x, c3.y, c3.z, + c2.x, c2.y, c2.z, + } ; + + private static final float[] indexedFloatVerts = { + p1.x,p1.y,p1.z, + p2.x,p2.y,p2.z, + p3.x,p3.y,p3.z, + p4.x,p4.y,p4.z, + + }; + private static final float[] indexedFloatClrs = { + c1.x,c1.y,c1.z, + c2.x,c2.y,c2.z, + c3.x,c3.y,c3.z, + c4.x,c4.y,c4.z, + }; + private static final Point3f[] p3fVerts = { + p1, p2, p4, p1, p4, p3, p2, p3, p4, p1, p3, p2}; + + private static final Point3f[] indexedP3fVerts = {p1, p2, p3, p4}; + + private static final Color3f[] c3fClrs = { + c1, c2, c4, c1, c4, c3, c2, c3, c4, c1, c3, c2}; + + private static final Color3f[] indexedC3fClrs = {c1, c2, c3, c4}; + + + private static final int[] indices = {0,1,3,0,3,2,1,2,3,0,2,1}; + private int[] stripVertexCounts = {3,3,3,3}; + + private SimpleUniverse u; + + BranchGroup createSceneGraph() { + BranchGroup objRoot = new BranchGroup(); + + // Set up attributes to render lines + app = new Appearance(); + + transp = new TransparencyAttributes(); + transp.setTransparency(0.5f); + transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); + transp.setTransparencyMode(TransparencyAttributes.NONE); + app.setTransparencyAttributes(transp); + + tetraRegular = createGeometry(1); + tetraStrip =createGeometry(2); + tetraIndexed = createGeometry(3); + tetraIndexedStrip = createGeometry(4); + + geoArrays[0] = tetraRegular; + geoArrays[1] = tetraStrip; + geoArrays[2] = tetraIndexed; + geoArrays[3] = tetraIndexedStrip; + + shape = new Shape3D(tetraRegular, app); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ); + + Transform3D t = new Transform3D(); + // move the object upwards + t.set(new Vector3f(0.0f, 0.3f, 0.0f)); + + // rotate the shape + Transform3D temp = new Transform3D(); + temp.rotX(Math.PI/4.0d); + t.mul(temp); + temp.rotY(Math.PI/4.0d); + t.mul(temp); + + // Shrink the object + t.setScale(0.6); + + TransformGroup trans = new TransformGroup(t); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); + + objRoot.addChild(trans); + trans.addChild(shape); + + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Set up the global lights + Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); + Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); + Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); + + AmbientLight aLgt = new AmbientLight(alColor); + aLgt.setInfluencingBounds(bounds); + DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); + lgt1.setInfluencingBounds(bounds); + objRoot.addChild(aLgt); + objRoot.addChild(lgt1); + + // Let Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + JPanel createGeometryByReferencePanel() { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Geometry Type")); + + String values[] = {"Array", "Strip", "Indexed", "IndexedStrip"}; + geomType = new JComboBox(values); + geomType.setLightWeightPopupEnabled(false); + geomType.addActionListener(this); + geomType.setSelectedIndex(0); + panel.add(new JLabel("Geometry Type")); + panel.add(geomType); + + + String vertex_types[] = { "Float","P3F"}; + + vertexType = new JComboBox(vertex_types); + vertexType.setLightWeightPopupEnabled(false); + vertexType.addActionListener(this); + vertexType.setSelectedIndex(0); + panel.add(new JLabel("VertexType")); + panel.add(vertexType); + + + String color_types[] = { "Float","C3F"}; + + colorType = new JComboBox(color_types); + colorType.setLightWeightPopupEnabled(false); + colorType.addActionListener(this); + colorType.setSelectedIndex(0); + panel.add(new JLabel("ColorType")); + panel.add(colorType); + + + + + return panel; + } + + JPanel createUpdatePanel() { + + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Other Attributes")); + + String updateComp[] = { "None","Geometry", "Color"}; + + transparency = new JCheckBox("EnableTransparency", + false); + transparency.addActionListener(this); + panel.add(transparency); + + + updates = new JComboBox(updateComp); + updates.setLightWeightPopupEnabled(false); + updates.addActionListener(this); + updates.setSelectedIndex(0); + panel.add(new JLabel("UpdateData")); + panel.add(updates); + + return panel; + } + + + + public GeometryByReferenceTest() { + } + + public void init() { + Container contentPane = getContentPane(); + + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); + contentPane.add("Center", c); + + BranchGroup scene = createSceneGraph(); + // SimpleUniverse is a Convenience Utility class + u = new SimpleUniverse(c); + + // add mouse behaviors to the viewingPlatform + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + u.addBranchGraph(scene); + + // add Orbit behavior to the ViewingPlatform + OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + // Create GUI + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.add(createGeometryByReferencePanel()); + p.add(createUpdatePanel()); + p.setLayout(boxlayout); + + contentPane.add("South", p); + } + + public void destroy() { + u.cleanup(); + } + + public void actionPerformed(ActionEvent e) { + Object target = e.getSource(); + GeometryArray geo; + boolean setColor = false, setVertex = false; + if (target == geomType) { + geo = geoArrays[geomType.getSelectedIndex()]; + // Set everything to null, and set it later .. + geo.setColorRefFloat(null); + geo.setColorRef3f(null); + geo.setCoordRefFloat(null); + geo.setCoordRef3f(null); + shape.setGeometry(geoArrays[geomType.getSelectedIndex()]); + + setColor = true; + setVertex= true; + + + } + else if (target == transparency) { + if (transparency.isSelected()) { + transp.setTransparencyMode(TransparencyAttributes.BLENDED); + } + else { + transp.setTransparencyMode(TransparencyAttributes.NONE); + } + + + } + else if (target == updates) { + updateIndex = updates.getSelectedIndex(); + if (updateIndex == 1) { + System.out.println("Doing coordinate update"); + ((GeometryArray)(shape.getGeometry())).updateData(this); + } + else if (updateIndex == 2) { + System.out.println("Doing color update"); + ((GeometryArray)(shape.getGeometry())).updateData(this); + } + + } + else if (target == vertexType) { + geo = ((GeometryArray)shape.getGeometry()); + if (vertexIndex == 0) { + geo.setCoordRefFloat(null); + } + else if (vertexIndex == 1) { + geo.setCoordRef3f(null); + } + vertexIndex = vertexType.getSelectedIndex(); + setVertex = true; + } + else if (target == colorType) { + geo = (GeometryArray) shape.getGeometry(); + if (colorIndex == 0) { + geo.setColorRefFloat(null); + } + else if (colorIndex == 1) { + geo.setColorRef3f(null); + } + colorIndex = colorType.getSelectedIndex(); + setColor = true; + } + + if (setVertex) { + geo = (GeometryArray) shape.getGeometry(); + if (vertexIndex == 0) { + if (geo instanceof IndexedGeometryArray) + geo.setCoordRefFloat(indexedFloatVerts); + else + geo.setCoordRefFloat(floatVerts); + } + else if (vertexIndex == 1) { + if (geo instanceof IndexedGeometryArray) + geo.setCoordRef3f(indexedP3fVerts); + else + geo.setCoordRef3f(p3fVerts); + } + + } + if (setColor) { + geo = (GeometryArray) shape.getGeometry(); + if (colorIndex == 0) { + if (geo instanceof IndexedGeometryArray) + geo.setColorRefFloat(indexedFloatClrs); + else + geo.setColorRefFloat(floatClrs); + } + else if (colorIndex == 1) { + if (geo instanceof IndexedGeometryArray) + geo.setColorRef3f(indexedC3fClrs); + else + geo.setColorRef3f(c3fClrs); + } + } + + } + + + + public static void main(String[] args) { + Frame frame = new MainFrame(new GeometryByReferenceTest(), 800, 800); + } + + public GeometryArray createGeometry (int type) { + GeometryArray tetra = null; + if (type == 1) { + tetra =new TriangleArray(12, + TriangleArray.COORDINATES| + TriangleArray.COLOR_3| + TriangleArray.BY_REFERENCE); + + tetra.setCoordRefFloat(floatVerts); + tetra.setColorRefFloat(floatClrs); + + } + else if (type == 2) { + tetra = new TriangleStripArray(12, + TriangleStripArray.COORDINATES| + TriangleStripArray.COLOR_3| + TriangleStripArray.BY_REFERENCE, + stripVertexCounts); + tetra.setCoordRefFloat(floatVerts); + tetra.setColorRefFloat(floatClrs); + + } + else if (type == 3) { // Indexed Geometry + tetra = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES| + IndexedTriangleArray.COLOR_3| + IndexedTriangleArray.BY_REFERENCE, + 12); + tetra.setCoordRefFloat(indexedFloatVerts); + tetra.setColorRefFloat(indexedFloatClrs); + ((IndexedTriangleArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleArray)tetra).setColorIndices(0, indices); + } + else if (type == 4) { // Indexed strip geometry + tetra = new IndexedTriangleStripArray(4, + IndexedTriangleStripArray.COORDINATES| + IndexedTriangleStripArray.COLOR_3| + IndexedTriangleStripArray.BY_REFERENCE, + 12, + stripVertexCounts); + tetra.setCoordRefFloat(indexedFloatVerts); + tetra.setColorRefFloat(indexedFloatClrs); + ((IndexedTriangleStripArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setColorIndices(0, indices); + } + + if (tetra != null) + tetra.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE); + return tetra; + } + + public void updateData(Geometry geometry) { + int i; + float val; + + + if (updateIndex == 1) { // geometry + // Translate the geometry by a small amount in x + vertexCount++; + if ((vertexCount &1) == 1) + val = 0.2f; + else + val = -0.2f; + + if (vertexIndex == 0) { + // Do Indexed geometry + for (i = 0; i < indexedFloatVerts.length; i+=3) { + indexedFloatVerts[i] += val; + } + // Do non-indexed float geometry + for (i = 0; i < floatVerts.length; i+=3) { + floatVerts[i] += val; + } + } + else { + // If p3f do each point only once + for (i = 0; i < indexedP3fVerts.length; i++) { + indexedP3fVerts[i].x += val; + } + } + + } + else if (updateIndex == 2) { // colors + colorCount++; + if ((colorCount & 1) == 1) + val = 0.4f; + else + val = -0.4f; + if (colorIndex == 0) { + // Do Indexed geometry + for (i = 0; i < indexedFloatClrs.length; i+=3) { + indexedFloatClrs[i] += val; + } + // Do non-indexed float geometry + for (i = 0; i < floatClrs.length; i+=3) { + floatClrs[i] += val; + } + } + else { + // If c3f do each point only once + for (i = 0; i < indexedC3fClrs.length; i++) { + indexedC3fClrs[i].x += val; + } + } + + } + + } +} diff --git a/src/GeometryByReference/GeometryByReferenceTest_plugin.html b/src/GeometryByReference/GeometryByReferenceTest_plugin.html new file mode 100644 index 0000000..2e3b979 --- /dev/null +++ b/src/GeometryByReference/GeometryByReferenceTest_plugin.html @@ -0,0 +1,39 @@ +<HTML> +<HEAD> +<TITLE>GeometryByReferenceTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<!--"CONVERTED_APPLET"--> +<!-- CONVERTER VERSION 1.3 --> +<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" +WIDTH = 800 HEIGHT = 800 ALIGN = middle codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> +<PARAM NAME = CODE VALUE = "GeometryByReferenceTest.class" > + +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2"> +<PARAM NAME="scriptable" VALUE="false"> +<COMMENT> +<EMBED type="application/x-java-applet;version=1.2.2" CODE = "GeometryByReferenceTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</NOEMBED></EMBED> +</OBJECT> + +<!-- +<APPLET CODE = "GeometryByReferenceTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> + +</APPLET> +--> +<!--"END_CONVERTED_APPLET"--> + +</BODY> +</HTML> diff --git a/src/GeometryByReference/ImageComponentByReferenceTest.html b/src/GeometryByReference/ImageComponentByReferenceTest.html new file mode 100644 index 0000000..a9b0d60 --- /dev/null +++ b/src/GeometryByReference/ImageComponentByReferenceTest.html @@ -0,0 +1,15 @@ +<HTML> +<HEAD> +<TITLE>ImageComponentByReferenceTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<applet align=middle code="ImageComponentByReferenceTest.class" width=800 height=800> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</applet> +</BODY> +</HTML> diff --git a/src/GeometryByReference/ImageComponentByReferenceTest.java b/src/GeometryByReference/ImageComponentByReferenceTest.java new file mode 100644 index 0000000..3c378e0 --- /dev/null +++ b/src/GeometryByReference/ImageComponentByReferenceTest.java @@ -0,0 +1,328 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; +import javax.media.j3d.*; +import javax.vecmath.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.border.*; +import com.sun.j3d.utils.behaviors.mouse.*; +import com.sun.j3d.utils.image.TextureLoader; +import com.sun.j3d.utils.geometry.Sphere; +import com.sun.j3d.utils.geometry.Box; +import com.sun.j3d.utils.geometry.ColorCube; +import java.awt.image.*; +import java.awt.color.ColorSpace; +import com.sun.j3d.utils.geometry.*; + +public class ImageComponentByReferenceTest extends JApplet implements ActionListener { + + Shape3D s1,s2; + TextureLoader t0, t1, t2; + int count = 0; + + Appearance app = new Appearance(); + BranchGroup objRoot = new BranchGroup(); + TransformGroup objTrans = new TransformGroup(); + BufferedImage bImage1; + TiledImage checkBoard; + boolean yUp = false; + boolean byRef = true; + JComboBox rasterType, texType; + ImageComponent2D[] image = new ImageComponent2D[8]; + Appearance dummyApp = new Appearance(); + Texture2D texOne, texCheckBoard; + javax.media.j3d.Raster raster; + Box textureCube; + Shape3D boxShape; + int w1 = 64, h1 = 32, checkw = 16 , checkh = 16; + + private java.net.URL texImage = null; + + private SimpleUniverse u = null; + + public BranchGroup createSceneGraph() { + objRoot = new BranchGroup(); + + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE); + + objRoot.addChild(objTrans); + + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + app.setCapability(Appearance.ALLOW_TEXTURE_WRITE); + + + textureCube = new Box(0.4f, 0.4f, 0.4f, + Box.GENERATE_TEXTURE_COORDS| + Box.GENERATE_NORMALS, app); + boxShape = textureCube.getShape(Box.FRONT); + boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + objTrans.addChild(textureCube); + + checkBoard = new TiledImage(); + TextureLoader texLoader = new TextureLoader( texImage, this); + ImageComponent2D oneImage = texLoader.getImage(); + bImage1 = oneImage.getImage(); + + int index = 0; + image[index++] = new ImageComponent2D(oneImage.getFormat(), + (RenderedImage)bImage1, + false, + true); + + image[index++] = new ImageComponent2D(oneImage.getFormat(), + (RenderedImage)bImage1, + true, + true); + + + image[index++] = new ImageComponent2D(oneImage.getFormat(), + (RenderedImage)bImage1, + false, + false); + + + image[index++] = new ImageComponent2D(oneImage.getFormat(), + (RenderedImage)bImage1, + true, + false); + + createRaster(objRoot); + + image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, + checkBoard, + false, + true); + + image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, + checkBoard, + true, + true); + + + image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, + checkBoard, + false, + false); + + + image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, + checkBoard, + true, + false); + + + + texOne = new Texture2D(Texture.BASE_LEVEL, + Texture.RGBA, + image[2].getWidth(), image[2].getHeight()); + + texOne.setCapability(Texture.ALLOW_IMAGE_WRITE); + texOne.setImage(0, image[2]); + + app.setTexture(texOne); + + texCheckBoard = new Texture2D(Texture.BASE_LEVEL, + Texture.RGBA, + image[4].getWidth(), image[4].getHeight()); + + texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE); + objRoot.compile(); + return objRoot; + } + + public void actionPerformed(ActionEvent e ) { + Object target = e.getSource(); + + if (target == rasterType) { + if (rasterType.getSelectedIndex() < 4) { + raster.setSize(w1, h1); + } + else { + raster.setSize(checkw, checkh); + } + raster.setImage(image[rasterType.getSelectedIndex()]); + } + else if (target == texType) { + boxShape.setAppearance(dummyApp); + if (texType.getSelectedIndex() < 4) { + texOne.setImage(0, image[texType.getSelectedIndex()]); + app.setTexture(texOne); + } + else { + texCheckBoard.setImage(0, image[texType.getSelectedIndex()]); + app.setTexture(texCheckBoard); + } + + boxShape.setAppearance(app); + } + + + } + + JPanel createImagePanel() { + JPanel panel = new JPanel(); + String texVals[] = { "One_Yup_ByCopy", + "One_Yup_ByReference", + "One_Ydown_ByCopy", + "One_Ydown_ByReference", + "Checkered_Yup_ByCopy", + "Checkered_Yup_ByReference", + "Checkered_Ydown_ByCopy", + "Checkered_Ydown_ByReference"}; + + rasterType = new JComboBox(texVals); + rasterType.setLightWeightPopupEnabled(false); + rasterType.addActionListener(this); + rasterType.setSelectedIndex(2); + panel.add(new JLabel("Raster Image")); + panel.add(rasterType); + + texType = new JComboBox(texVals); + texType.setLightWeightPopupEnabled(false); + texType.addActionListener(this); + texType.setSelectedIndex(2); + panel.add(new JLabel("Texture Image")); + panel.add(texType); + return panel; + + } + + + + public ImageComponentByReferenceTest() + { + } + + public ImageComponentByReferenceTest(java.net.URL url) { + texImage = url; + } + + public void init() { + if (texImage == null) { + // the path to the image for an applet + try { + texImage = new java.net.URL(getCodeBase().toString() + + "../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } + + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); + BranchGroup scene = createSceneGraph();u = new SimpleUniverse(c); + u.getViewingPlatform().setNominalViewingTransform(); + u.addBranchGraph(scene); + Container contentPane = getContentPane(); + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.setLayout(boxlayout); + contentPane.add("Center", c); + + contentPane.add("South", p); + + p.add(createImagePanel()); + + } + + public void destroy() { + u.cleanup(); + } + + public static void main(String[] args) { + java.net.URL url = null; + // the path to the image file for an application + try { + url = new java.net.URL("file:../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + + new MainFrame(new ImageComponentByReferenceTest(url), 800, 700); + } + + void createRaster( BranchGroup scene) { + + + + // Create raster geometries and shapes + Vector3f trans = new Vector3f( ); + Transform3D tr = new Transform3D( ); + TransformGroup tg; + + // Left + raster = new javax.media.j3d.Raster( ); + raster.setCapability(javax.media.j3d.Raster.ALLOW_IMAGE_WRITE); + raster.setCapability(javax.media.j3d.Raster.ALLOW_SIZE_WRITE); + raster.setPosition( new Point3f( -0.9f, 0.75f, 0.0f ) ); + raster.setType( javax.media.j3d.Raster.RASTER_COLOR ); + raster.setOffset( 0, 0 ); + + raster.setSize( image[2].getWidth(), image[2].getHeight() ); + raster.setImage( image[2] ); + Shape3D sh = new Shape3D( raster, new Appearance( ) ); + scene.addChild( sh ); + + + + } +} + + + + diff --git a/src/GeometryByReference/ImageComponentByReferenceTest_plugin.html b/src/GeometryByReference/ImageComponentByReferenceTest_plugin.html new file mode 100644 index 0000000..6bf3689 --- /dev/null +++ b/src/GeometryByReference/ImageComponentByReferenceTest_plugin.html @@ -0,0 +1,39 @@ +<HTML> +<HEAD> +<TITLE>ImageComponentByReferenceTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<!--"CONVERTED_APPLET"--> +<!-- CONVERTER VERSION 1.3 --> +<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" +WIDTH = 800 HEIGHT = 800 ALIGN = middle codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> +<PARAM NAME = CODE VALUE = "ImageComponentByReferenceTest.class" > + +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2"> +<PARAM NAME="scriptable" VALUE="false"> +<COMMENT> +<EMBED type="application/x-java-applet;version=1.2.2" CODE = "ImageComponentByReferenceTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</NOEMBED></EMBED> +</OBJECT> + +<!-- +<APPLET CODE = "ImageComponentByReferenceTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> + +</APPLET> +--> +<!--"END_CONVERTED_APPLET"--> + +</BODY> +</HTML> diff --git a/src/GeometryByReference/InterleavedNIOBuffer.java b/src/GeometryByReference/InterleavedNIOBuffer.java new file mode 100644 index 0000000..9b6c721 --- /dev/null +++ b/src/GeometryByReference/InterleavedNIOBuffer.java @@ -0,0 +1,531 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.image.TextureLoader; +import javax.media.j3d.*; +import javax.vecmath.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.border.*; +import com.sun.j3d.utils.behaviors.vp.*; +import java.nio.*; + +public class InterleavedNIOBuffer extends JApplet implements ActionListener { + + RenderingAttributes ra; + ColoringAttributes ca; + Material mat; + Appearance app; + JComboBox geomType; + JCheckBox transparency; + JCheckBox textureBox; + Shape3D shape; + TransparencyAttributes transp; + + GeometryArray tetraRegular, tetraStrip, tetraIndexed, tetraIndexedStrip; + GeometryArray[] geoArrays = new GeometryArray[4]; + + // Globally used colors + Color3f white = new Color3f(1.0f, 1.0f, 1.0f); + Color3f red = new Color3f(1.0f, 0.0f, 0.0f); + Color3f green = new Color3f(0.0f, 1.0f, 0.0f); + Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); + Color3f[] colors = {white, red, green, blue}; + + private static final float sqrt3 = (float) Math.sqrt(3.0); + private static final float sqrt3_3 = sqrt3 / 3.0f; + private static final float sqrt24_3 = (float) Math.sqrt(24.0) / 3.0f; + + private static final float ycenter = 0.5f * sqrt24_3; + private static final float zcenter = -sqrt3_3; + + private static final Point3f p1 = + new Point3f(-1.0f, -ycenter, -zcenter); + private static final Point3f p2 = + new Point3f(1.0f, -ycenter, -zcenter); + private static final Point3f p3 = + new Point3f(0.0f, -ycenter, -sqrt3 - zcenter); + private static final Point3f p4 = + new Point3f(0.0f, sqrt24_3 - ycenter, 0.0f); + + private static final Point2f t1 = new Point2f(0.0f, 0.0f); + private static final Point2f t2 = new Point2f(0.5f, 1.0f); + private static final Point2f t3 = new Point2f(1.0f, 0.0f); + private static final Point2f t4 = new Point2f(1.0f, 1.0f); + + private static final Color3f c1 = new Color3f(1.0f, 0.0f, 0.0f); + private static final Color3f c2 = new Color3f(0.0f, 1.0f, 0.0f); + private static final Color3f c3 = new Color3f(0.0f, 1.0f, 1.0f); + private static final Color3f c4 = new Color3f(1.0f, 1.0f, 0.0f); + + + private static final float[] interleaved = { + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z, // front face + p1.x, p1.y, p1.z, // front face + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z, + p2.x, p2.y, p2.z, + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z,// left, back face + p1.x, p1.y, p1.z,// left, back face + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z,// right, back face + p2.x, p2.y, p2.z,// right, back face + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z,// bottom face + p1.x, p1.y, p1.z,// bottom face + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z, + p2.x, p2.y, p2.z, + }; + + private static final float[] indexedInterleaved = { + t1.x,t1.y, + t1.x,t1.y, + c1.x,c1.y,c1.z, + p1.x,p1.y,p1.z, + t2.x,t2.y, + t2.x,t2.y, + c2.x,c2.y,c2.z, + p2.x,p2.y,p2.z, + t3.x,t3.y, + t3.x,t3.y, + c3.x,c3.y,c3.z, + p3.x,p3.y,p3.z, + t4.x,t4.y, + t4.x,t4.y, + c4.x,c4.y,c4.z, + p4.x,p4.y,p4.z, + }; + + + private static final int[] indices = {0,1,3,0,3,2,1,2,3,0,2,1}; + private int[] stripVertexCounts = {3,3,3,3}; + + TextureUnitState textureUnitState[] = new TextureUnitState[2]; + Texture tex1; + Texture tex2; + + private java.net.URL texImage1 = null; + private java.net.URL texImage2 = null; + + private SimpleUniverse u; + + private J3DBuffer interleavedBuffer; + private J3DBuffer indexedInterleavedBuffer; + + void createInterleavedBuffers() { + int size; + ByteOrder order = ByteOrder.nativeOrder(); + + size = (2 + 2 + 3 + 3 ) * 3 * 4; + FloatBuffer vertex = ByteBuffer.allocateDirect(size * 4).order(order).asFloatBuffer(); + vertex.put(interleaved, 0, size); + interleavedBuffer = new J3DBuffer(vertex); + + size = ( 2 + 2 + 3 + 3) * 4; + FloatBuffer indexedVertex = ByteBuffer.allocateDirect(size * 4).order(order).asFloatBuffer(); + indexedVertex.put(indexedInterleaved, 0, size); + indexedInterleavedBuffer = new J3DBuffer(indexedVertex); + } + + BranchGroup createSceneGraph() { + BranchGroup objRoot = new BranchGroup(); + + // Set up attributes to render lines + app = new Appearance(); + app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); + + transp = new TransparencyAttributes(); + transp.setTransparency(0.5f); + transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); + transp.setTransparencyMode(TransparencyAttributes.NONE); + app.setTransparencyAttributes(transp); + + // load textures + TextureAttributes texAttr1 = new TextureAttributes(); + texAttr1.setTextureMode(TextureAttributes.DECAL); + TextureAttributes texAttr2 = new TextureAttributes(); + texAttr2.setTextureMode(TextureAttributes.MODULATE); + + TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); + if (tex == null) + return null; + tex1 = tex.getTexture(); + + tex = new TextureLoader(texImage2, new String("RGB"), this); + if (tex == null) + return null; + tex2 = tex.getTexture(); + + textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); + textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); + + createInterleavedBuffers(); + + tetraRegular = createGeometry(1); + tetraStrip =createGeometry(2); + tetraIndexed = createGeometry(3); + tetraIndexedStrip = createGeometry(4); + + geoArrays[0] = tetraRegular; + geoArrays[1] = tetraStrip; + geoArrays[2] = tetraIndexed; + geoArrays[3] = tetraIndexedStrip; + + shape = new Shape3D(tetraRegular, app); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + + Transform3D t = new Transform3D(); + // move the object upwards + t.set(new Vector3f(0.0f, 0.3f, 0.0f)); + + // rotate the shape + Transform3D temp = new Transform3D(); + temp.rotX(Math.PI/4.0d); + t.mul(temp); + temp.rotY(Math.PI/4.0d); + t.mul(temp); + + // Shrink the object + t.setScale(0.6); + + TransformGroup trans = new TransformGroup(t); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); + + objRoot.addChild(trans); + trans.addChild(shape); + + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Set up the global lights + Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); + Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); + Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); + + AmbientLight aLgt = new AmbientLight(alColor); + aLgt.setInfluencingBounds(bounds); + DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); + lgt1.setInfluencingBounds(bounds); + objRoot.addChild(aLgt); + objRoot.addChild(lgt1); + + // Let Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + JPanel createGeometryByReferencePanel() { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Geometry Type")); + + String values[] = {"Array", "Strip", "Indexed", "IndexedStrip"}; + geomType = new JComboBox(values); + geomType.setLightWeightPopupEnabled(false); + geomType.addActionListener(this); + geomType.setSelectedIndex(0); + panel.add(new JLabel("Geometry Type")); + panel.add(geomType); + + transparency = new JCheckBox("EnableTransparency", + false); + transparency.addActionListener(this); + panel.add(transparency); + + textureBox = new JCheckBox("EnableTexture", false); + textureBox.addActionListener(this); + panel.add(textureBox); + + return panel; + } + + public InterleavedNIOBuffer() { + } + + public InterleavedNIOBuffer(java.net.URL texURL1, java.net.URL texURL2) { + texImage1 = texURL1; + texImage2 = texURL2; + } + + public void init() { + + // create textures + + if (texImage1 == null) { + // the path to the image for an applet + try { + texImage1 = new java.net.URL(getCodeBase().toString() + + "../images/bg.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } + + if (texImage2 == null) { + // the path to the image for an applet + try { + texImage2 = new java.net.URL(getCodeBase().toString() + + "../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } + + Container contentPane = getContentPane(); + + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); + contentPane.add("Center", c); + + BranchGroup scene = createSceneGraph(); + // SimpleUniverse is a Convenience Utility class + u = new SimpleUniverse(c); + + // add mouse behaviors to the viewingPlatform + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + // add Orbit behavior to the viewing platform + OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + u.addBranchGraph(scene); + + + // Create GUI + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.add(createGeometryByReferencePanel()); + p.setLayout(boxlayout); + + contentPane.add("South", p); + } + + public void destroy() { + u.cleanup(); + } + + public void actionPerformed(ActionEvent e) { + Object target = e.getSource(); + if (target == geomType) { + shape.setGeometry(geoArrays[geomType.getSelectedIndex()]); + + } + else if (target == transparency) { + if (transparency.isSelected()) { + transp.setTransparencyMode(TransparencyAttributes.BLENDED); + } + else { + transp.setTransparencyMode(TransparencyAttributes.NONE); + } + } + else if (target == textureBox) { + if (textureBox.isSelected()) { + app.setTextureUnitState(textureUnitState); + } + else { + app.setTextureUnitState(null); + } + } + } + + + + public static void main(String[] args) { + java.net.URL texURL1 = null; + java.net.URL texURL2 = null; + // the path to the image for an application + try { + texURL1 = new java.net.URL("file:../images/bg.jpg"); + texURL2 = new java.net.URL("file:../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + + Frame frame = new MainFrame(new InterleavedNIOBuffer(texURL1, texURL2), + 800, 800); + } + + public GeometryArray createGeometry (int type) { + GeometryArray tetra = null; + int texCoordSetMap[] = {0, 0}; + + if (type == 1) { + tetra =new TriangleArray(12, + TriangleArray.COORDINATES| + TriangleArray.COLOR_3| + /* + TriangleArray.NORMAL_3| + */ + TriangleArray.TEXTURE_COORDINATE_2 | + TriangleArray.INTERLEAVED| + TriangleArray.BY_REFERENCE| + TriangleArray.USE_NIO_BUFFER, + 2, texCoordSetMap); + + tetra.setInterleavedVertexBuffer(interleavedBuffer); + + } + else if (type == 2) { + tetra = new TriangleStripArray(12, + TriangleStripArray.COORDINATES| + TriangleStripArray.COLOR_3| + /* + TriangleArray.NORMAL_3| + */ + TriangleArray.TEXTURE_COORDINATE_2 | + TriangleStripArray.INTERLEAVED| + TriangleStripArray.BY_REFERENCE| + TriangleStripArray.USE_NIO_BUFFER, + 2, texCoordSetMap, + stripVertexCounts); + tetra.setInterleavedVertexBuffer(interleavedBuffer); + + + } + else if (type == 3) { // Indexed Geometry + tetra = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES| + IndexedTriangleArray.COLOR_3| + /* + IndexedTriangleArray.NORMAL_3| + */ + IndexedTriangleArray.TEXTURE_COORDINATE_2 | + IndexedTriangleArray.INTERLEAVED| + IndexedTriangleArray.BY_REFERENCE| + IndexedTriangleArray.USE_NIO_BUFFER| + IndexedTriangleArray.USE_COORD_INDEX_ONLY, + 2, texCoordSetMap, + 12); + tetra.setInterleavedVertexBuffer(indexedInterleavedBuffer); + ((IndexedTriangleArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleArray)tetra).setColorIndices(0, indices); + ((IndexedTriangleArray)tetra).setTextureCoordinateIndices( + 0, 0, indices); + ((IndexedTriangleArray)tetra).setTextureCoordinateIndices( + 1, 0, indices); + } + else if (type == 4) { // Indexed strip geometry + tetra = new IndexedTriangleStripArray(4, + IndexedTriangleStripArray.COORDINATES| + IndexedTriangleStripArray.COLOR_3| + /* + IndexedTriangleArray.NORMAL_3| + */ + IndexedTriangleArray.TEXTURE_COORDINATE_2 | + IndexedTriangleStripArray.INTERLEAVED| + IndexedTriangleStripArray.BY_REFERENCE| + IndexedTriangleStripArray.USE_NIO_BUFFER, + //IndexedTriangleStripArray.USE_COORD_INDEX_ONLY, + 2, texCoordSetMap, + 12, + stripVertexCounts); + tetra.setInterleavedVertexBuffer(indexedInterleavedBuffer); + ((IndexedTriangleStripArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setColorIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setTextureCoordinateIndices( + 0, 0, indices); + ((IndexedTriangleStripArray)tetra).setTextureCoordinateIndices( + 1, 0, indices); + } + else if (type == 5) { // Interleaved array + } + return tetra; + } +} diff --git a/src/GeometryByReference/InterleavedTest.html b/src/GeometryByReference/InterleavedTest.html new file mode 100644 index 0000000..7aa9e10 --- /dev/null +++ b/src/GeometryByReference/InterleavedTest.html @@ -0,0 +1,15 @@ +<HTML> +<HEAD> +<TITLE>InterleavedTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<applet align=middle code="InterleavedTest.class" width=800 height=800> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</applet> +</BODY> +</HTML> diff --git a/src/GeometryByReference/InterleavedTest.java b/src/GeometryByReference/InterleavedTest.java new file mode 100644 index 0000000..781c49b --- /dev/null +++ b/src/GeometryByReference/InterleavedTest.java @@ -0,0 +1,504 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.image.TextureLoader; +import javax.media.j3d.*; +import javax.vecmath.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.border.*; +import com.sun.j3d.utils.behaviors.vp.*; + +public class InterleavedTest extends JApplet implements ActionListener { + + RenderingAttributes ra; + ColoringAttributes ca; + Material mat; + Appearance app; + JComboBox geomType; + JCheckBox transparency; + JCheckBox textureBox; + Shape3D shape; + TransparencyAttributes transp; + + GeometryArray tetraRegular, tetraStrip, tetraIndexed, tetraIndexedStrip; + GeometryArray[] geoArrays = new GeometryArray[4]; + + // Globally used colors + Color3f white = new Color3f(1.0f, 1.0f, 1.0f); + Color3f red = new Color3f(1.0f, 0.0f, 0.0f); + Color3f green = new Color3f(0.0f, 1.0f, 0.0f); + Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); + Color3f[] colors = {white, red, green, blue}; + + private static final float sqrt3 = (float) Math.sqrt(3.0); + private static final float sqrt3_3 = sqrt3 / 3.0f; + private static final float sqrt24_3 = (float) Math.sqrt(24.0) / 3.0f; + + private static final float ycenter = 0.5f * sqrt24_3; + private static final float zcenter = -sqrt3_3; + + private static final Point3f p1 = + new Point3f(-1.0f, -ycenter, -zcenter); + private static final Point3f p2 = + new Point3f(1.0f, -ycenter, -zcenter); + private static final Point3f p3 = + new Point3f(0.0f, -ycenter, -sqrt3 - zcenter); + private static final Point3f p4 = + new Point3f(0.0f, sqrt24_3 - ycenter, 0.0f); + + private static final Point2f t1 = new Point2f(0.0f, 0.0f); + private static final Point2f t2 = new Point2f(0.5f, 1.0f); + private static final Point2f t3 = new Point2f(1.0f, 0.0f); + private static final Point2f t4 = new Point2f(1.0f, 1.0f); + + private static final Color3f c1 = new Color3f(1.0f, 0.0f, 0.0f); + private static final Color3f c2 = new Color3f(0.0f, 1.0f, 0.0f); + private static final Color3f c3 = new Color3f(0.0f, 1.0f, 1.0f); + private static final Color3f c4 = new Color3f(1.0f, 1.0f, 0.0f); + + + private static final float[] interleaved = { + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z, // front face + p1.x, p1.y, p1.z, // front face + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z, + p2.x, p2.y, p2.z, + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z,// left, back face + p1.x, p1.y, p1.z,// left, back face + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z,// right, back face + p2.x, p2.y, p2.z,// right, back face + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + t4.x, t4.y, + t4.x, t4.y, + c4.x, c4.y, c4.z, + p4.x, p4.y, p4.z, + + t1.x, t1.y, + t1.x, t1.y, + c1.x, c1.y, c1.z,// bottom face + p1.x, p1.y, p1.z,// bottom face + t3.x, t3.y, + t3.x, t3.y, + c3.x, c3.y, c3.z, + p3.x, p3.y, p3.z, + t2.x, t2.y, + t2.x, t2.y, + c2.x, c2.y, c2.z, + p2.x, p2.y, p2.z, + }; + + private static final float[] indexedInterleaved = { + t1.x,t1.y, + t1.x,t1.y, + c1.x,c1.y,c1.z, + p1.x,p1.y,p1.z, + t2.x,t2.y, + t2.x,t2.y, + c2.x,c2.y,c2.z, + p2.x,p2.y,p2.z, + t3.x,t3.y, + t3.x,t3.y, + c3.x,c3.y,c3.z, + p3.x,p3.y,p3.z, + t4.x,t4.y, + t4.x,t4.y, + c4.x,c4.y,c4.z, + p4.x,p4.y,p4.z, + }; + + + private static final int[] indices = {0,1,3,0,3,2,1,2,3,0,2,1}; + private int[] stripVertexCounts = {3,3,3,3}; + + TextureUnitState textureUnitState[] = new TextureUnitState[2]; + Texture tex1; + Texture tex2; + + private java.net.URL texImage1 = null; + private java.net.URL texImage2 = null; + + private SimpleUniverse u; + + BranchGroup createSceneGraph() { + BranchGroup objRoot = new BranchGroup(); + + // Set up attributes to render lines + app = new Appearance(); + app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE); + + transp = new TransparencyAttributes(); + transp.setTransparency(0.5f); + transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); + transp.setTransparencyMode(TransparencyAttributes.NONE); + app.setTransparencyAttributes(transp); + + // load textures + TextureAttributes texAttr1 = new TextureAttributes(); + texAttr1.setTextureMode(TextureAttributes.DECAL); + TextureAttributes texAttr2 = new TextureAttributes(); + texAttr2.setTextureMode(TextureAttributes.MODULATE); + + TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this); + if (tex == null) + return null; + tex1 = tex.getTexture(); + + tex = new TextureLoader(texImage2, new String("RGB"), this); + if (tex == null) + return null; + tex2 = tex.getTexture(); + + textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null); + textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null); + + tetraRegular = createGeometry(1); + tetraStrip =createGeometry(2); + tetraIndexed = createGeometry(3); + tetraIndexedStrip = createGeometry(4); + + geoArrays[0] = tetraRegular; + geoArrays[1] = tetraStrip; + geoArrays[2] = tetraIndexed; + geoArrays[3] = tetraIndexedStrip; + + shape = new Shape3D(tetraRegular, app); + shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); + + Transform3D t = new Transform3D(); + // move the object upwards + t.set(new Vector3f(0.0f, 0.3f, 0.0f)); + + // rotate the shape + Transform3D temp = new Transform3D(); + temp.rotX(Math.PI/4.0d); + t.mul(temp); + temp.rotY(Math.PI/4.0d); + t.mul(temp); + + // Shrink the object + t.setScale(0.6); + + TransformGroup trans = new TransformGroup(t); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); + + objRoot.addChild(trans); + trans.addChild(shape); + + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Set up the global lights + Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); + Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); + Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); + + AmbientLight aLgt = new AmbientLight(alColor); + aLgt.setInfluencingBounds(bounds); + DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); + lgt1.setInfluencingBounds(bounds); + objRoot.addChild(aLgt); + objRoot.addChild(lgt1); + + // Let Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + JPanel createGeometryByReferencePanel() { + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder("Geometry Type")); + + String values[] = {"Array", "Strip", "Indexed", "IndexedStrip"}; + geomType = new JComboBox(values); + geomType.setLightWeightPopupEnabled(false); + geomType.addActionListener(this); + geomType.setSelectedIndex(0); + panel.add(new JLabel("Geometry Type")); + panel.add(geomType); + + transparency = new JCheckBox("EnableTransparency", + false); + transparency.addActionListener(this); + panel.add(transparency); + + textureBox = new JCheckBox("EnableTexture", false); + textureBox.addActionListener(this); + panel.add(textureBox); + + return panel; + } + + public InterleavedTest() { + } + + public InterleavedTest(java.net.URL texURL1, java.net.URL texURL2) { + texImage1 = texURL1; + texImage2 = texURL2; + } + + public void init() { + + // create textures + + if (texImage1 == null) { + // the path to the image for an applet + try { + texImage1 = new java.net.URL(getCodeBase().toString() + + "../images/bg.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } + + if (texImage2 == null) { + // the path to the image for an applet + try { + texImage2 = new java.net.URL(getCodeBase().toString() + + "../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } + + Container contentPane = getContentPane(); + + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); + contentPane.add("Center", c); + + BranchGroup scene = createSceneGraph(); + // SimpleUniverse is a Convenience Utility class + u = new SimpleUniverse(c); + + // add mouse behaviors to the viewingPlatform + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + // add Orbit behavior to the viewing platform + OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + u.addBranchGraph(scene); + + + // Create GUI + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.add(createGeometryByReferencePanel()); + p.setLayout(boxlayout); + + contentPane.add("South", p); + } + + public void destroy() { + u.cleanup(); + } + + public void actionPerformed(ActionEvent e) { + Object target = e.getSource(); + if (target == geomType) { + shape.setGeometry(geoArrays[geomType.getSelectedIndex()]); + + } + else if (target == transparency) { + if (transparency.isSelected()) { + transp.setTransparencyMode(TransparencyAttributes.BLENDED); + } + else { + transp.setTransparencyMode(TransparencyAttributes.NONE); + } + } + else if (target == textureBox) { + if (textureBox.isSelected()) { + app.setTextureUnitState(textureUnitState); + } + else { + app.setTextureUnitState(null); + } + } + } + + + + public static void main(String[] args) { + java.net.URL texURL1 = null; + java.net.URL texURL2 = null; + // the path to the image for an application + try { + texURL1 = new java.net.URL("file:../images/bg.jpg"); + texURL2 = new java.net.URL("file:../images/one.jpg"); + } + catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + + Frame frame = new MainFrame(new InterleavedTest(texURL1, texURL2), + 800, 800); + } + + public GeometryArray createGeometry (int type) { + GeometryArray tetra = null; + int texCoordSetMap[] = {0, 0}; + + if (type == 1) { + tetra =new TriangleArray(12, + TriangleArray.COORDINATES| + TriangleArray.COLOR_3| + /* + TriangleArray.NORMAL_3| + */ + TriangleArray.TEXTURE_COORDINATE_2 | + TriangleArray.INTERLEAVED| + TriangleArray.BY_REFERENCE, + 2, texCoordSetMap); + + tetra.setInterleavedVertices(interleaved); + + } + else if (type == 2) { + tetra = new TriangleStripArray(12, + TriangleStripArray.COORDINATES| + TriangleStripArray.COLOR_3| + /* + TriangleArray.NORMAL_3| + */ + TriangleArray.TEXTURE_COORDINATE_2 | + TriangleStripArray.INTERLEAVED| + TriangleStripArray.BY_REFERENCE, + 2, texCoordSetMap, + stripVertexCounts); + tetra.setInterleavedVertices(interleaved); + + + } + else if (type == 3) { // Indexed Geometry + tetra = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES| + IndexedTriangleArray.COLOR_3| + /* + IndexedTriangleArray.NORMAL_3| + */ + IndexedTriangleArray.TEXTURE_COORDINATE_2 | + IndexedTriangleArray.INTERLEAVED| + IndexedTriangleArray.BY_REFERENCE, + 2, texCoordSetMap, + 12); + tetra.setInterleavedVertices(indexedInterleaved); + ((IndexedTriangleArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleArray)tetra).setColorIndices(0, indices); + ((IndexedTriangleArray)tetra).setTextureCoordinateIndices( + 0, 0, indices); + ((IndexedTriangleArray)tetra).setTextureCoordinateIndices( + 1, 0, indices); + } + else if (type == 4) { // Indexed strip geometry + tetra = new IndexedTriangleStripArray(4, + IndexedTriangleStripArray.COORDINATES| + IndexedTriangleStripArray.COLOR_3| + /* + IndexedTriangleArray.NORMAL_3| + */ + IndexedTriangleArray.TEXTURE_COORDINATE_2 | + IndexedTriangleStripArray.INTERLEAVED| + IndexedTriangleStripArray.BY_REFERENCE, + 2, texCoordSetMap, + 12, + stripVertexCounts); + tetra.setInterleavedVertices(indexedInterleaved); + ((IndexedTriangleStripArray)tetra).setCoordinateIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setColorIndices(0, indices); + ((IndexedTriangleStripArray)tetra).setTextureCoordinateIndices( + 0, 0, indices); + ((IndexedTriangleStripArray)tetra).setTextureCoordinateIndices( + 1, 0, indices); + } + else if (type == 5) { // Interleaved array + } + return tetra; + } +} diff --git a/src/GeometryByReference/InterleavedTest_plugin.html b/src/GeometryByReference/InterleavedTest_plugin.html new file mode 100644 index 0000000..87af1cb --- /dev/null +++ b/src/GeometryByReference/InterleavedTest_plugin.html @@ -0,0 +1,39 @@ +<HTML> +<HEAD> +<TITLE>InterleavedTest</TITLE> +</HEAD> +<BODY BGCOLOR="#000000"> +<!--"CONVERTED_APPLET"--> +<!-- CONVERTER VERSION 1.3 --> +<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" +WIDTH = 800 HEIGHT = 800 ALIGN = middle codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> +<PARAM NAME = CODE VALUE = "InterleavedTest.class" > + +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2"> +<PARAM NAME="scriptable" VALUE="false"> +<COMMENT> +<EMBED type="application/x-java-applet;version=1.2.2" CODE = "InterleavedTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> +</NOEMBED></EMBED> +</OBJECT> + +<!-- +<APPLET CODE = "InterleavedTest.class" WIDTH = 800 HEIGHT = 800 ALIGN = middle> +<blockquote> +<hr> +If you were using a Java-capable browser, +you would see Hello Universe! instead of this paragraph. +<hr> +</blockquote> + +</APPLET> +--> +<!--"END_CONVERTED_APPLET"--> + +</BODY> +</HTML> diff --git a/src/GeometryByReference/TiledImage.java b/src/GeometryByReference/TiledImage.java new file mode 100644 index 0000000..c985495 --- /dev/null +++ b/src/GeometryByReference/TiledImage.java @@ -0,0 +1,356 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +import java.awt.*; +import java.awt.image.*; +import java.util.Vector; +import java.awt.color.ColorSpace; + +public class TiledImage extends Object implements RenderedImage { + + + WritableRaster[][] tile = new WritableRaster[3][3]; + + WritableRaster bigTile; + ComponentColorModel colorModel; + BufferedImage checkBoard; + int minX = -2; + int minY = -1; + + TiledImage() { + ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); + int[] nBits = {8, 8, 8, 8}; + int i, j, k, cc = 255; + int[] bandOffset = new int[4]; + colorModel = + new ComponentColorModel(cs, nBits, true, false, Transparency.OPAQUE, 0); + // Create 9 tiles + bandOffset[0] = 3; + bandOffset[1] = 2; + bandOffset[2] = 1; + bandOffset[3] = 0; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + tile[i][j] = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 8, 8 , 32, 4, bandOffset, null); + } + } + + // tile {-2, -1} + byte[] byteData = ((DataBufferByte)tile[0][0].getDataBuffer()).getData(); + for (i=4, k = 8 * 4 * 4+4 * 4;i < 8;i++, k+= 16){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)cc; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + + // tile {-1, -1} + byteData = ((DataBufferByte)tile[1][0].getDataBuffer()).getData(); + for (i=4, k = 8 * 4 * 4;i < 8;i++){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)cc; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + + // tile {1, -1} + byteData = ((DataBufferByte)tile[2][0].getDataBuffer()).getData(); + for (i=4, k = 8 * 4 * 4;i < 8;i++, k+= 16){ + for (j=0;j < 4;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + + // tile {-2, 0} + byteData = ((DataBufferByte)tile[0][1].getDataBuffer()).getData(); + for (i=0, k = 16;i < 4;i++, k+=16){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)cc; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + for (i=4, k = 8*4*4+16;i < 8;i++, k+=16){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)0 ; + } + } + // tile {-1, 0} + byteData = ((DataBufferByte)tile[1][1].getDataBuffer()).getData(); + for (i=0, k = 0;i < 4;i++){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)cc; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + for (i=0, k = 8 * 4 * 4;i < 4;i++){ + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)0 ; + } + + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)cc ; + } + + } + + + // tile {0, 0} + byteData = ((DataBufferByte)tile[2][1].getDataBuffer()).getData(); + for (i=0, k = 0;i < 4;i++, k+= 16) { + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + for (i=4, k = 8 * 4* 4;i < 8;i++, k+= 16) { + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)cc ; + } + } + + + // tile {-2, 1} + byteData = ((DataBufferByte)tile[0][2].getDataBuffer()).getData(); + for (i=4, k = 16;i < 8;i++, k+= 16) { + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)0 ; + } + } + + + // tile {-1, 1} + byteData = ((DataBufferByte)tile[1][2].getDataBuffer()).getData(); + for (i=0, k = 0;i < 8;i++) { + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)0 ; + } + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)cc ; + } + } + + + + // tile {0, 1} + byteData = ((DataBufferByte)tile[2][2].getDataBuffer()).getData(); + for (i=4, k = 0;i < 8;i++, k+= 16) { + for (j=4;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)cc ; + } + } + + bigTile = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 16, 16 , 64, 4, bandOffset, null);; + byteData = ((DataBufferByte)bigTile.getDataBuffer()).getData(); + for (i=0, k = 0;i < 8;i++){ + for (j=0;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)cc; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + for (;j < 16;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)0; + byteData[k+3] = (byte)cc ; + } + } + for (;i < 16;i++){ + for (j=0;j < 8;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)0; + } + for (;j < 16;j++, k+=4){ + byteData[k] = (byte)0; + byteData[k+1] = (byte)0; + byteData[k+2] = (byte)cc; + byteData[k+3] = (byte)cc ; + } + } + checkBoard = new BufferedImage(colorModel, bigTile, false, null); + } + + + + // create four tiles {r, g, b, y} + public WritableRaster copyData(WritableRaster raster) { + return checkBoard.copyData(raster); + } + + public ColorModel getColorModel() { + return checkBoard.getColorModel(); + } + + public Raster getData() { + return checkBoard.getData(); + } + + public Raster getData(Rectangle rect) { + return checkBoard.getData(rect); + } + + public int getHeight() { + return 16; + } + + public int getMinTileX() { + return minX; + } + + public int getMinTileY() { + return minY; + } + + public int getMinX () { + return -8; + } + + public int getMinY () { + return -8; + } + + public int getNumXTiles() { + return 3; + } + + public int getNumYTiles() { + return 3; + } + + public Object getProperty(String name) { + return checkBoard.getProperty(name); + } + + public String[] getPropertyNames() { + return checkBoard.getPropertyNames(); + } + + + public SampleModel getSampleModel() { + return checkBoard.getSampleModel(); + } + + public Vector getSources() { + return null; + } + + public Raster getTile(int tileX, int tileY) { + return tile[tileX- minX][tileY - minY]; + } + + public int getTileGridXOffset() { + return 4; + } + + public int getTileGridYOffset() { + return -4; + } + + + public int getTileHeight() { + return 8; + } + + + public int getTileWidth() { + return 8; + } + + public int getWidth() { + return 16; + } +} + + diff --git a/src/GeometryByReference/build.xml b/src/GeometryByReference/build.xml new file mode 100644 index 0000000..cbf53a8 --- /dev/null +++ b/src/GeometryByReference/build.xml @@ -0,0 +1,66 @@ +<?xml version="1.0"?> + +<!-- +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + --> + +<project basedir="." default="compile"> + <target name="compile"> + <javac debug="true" deprecation="true" destdir="." srcdir="."> + </javac> + </target> + + <target name="all" depends="compile"> + </target> + + <target description="Clean all build products." name="clean"> + <delete> + <fileset dir="."> + <include name="**/*.class"/> + </fileset> + </delete> + </target> + +</project> |