Hi,
I just upgraded to Java3D 1.3. The programs compiles fine.
In my application I am mixing 3D-objects created with Java3D and
3D-objects created with VisAD. The VisAD-created object are not longer
displayed in my 3D view.
I am attaching the code, creating the VisAD-object.
Any ideas?
Thanks, Desiree
oooooooooooooooooooooooooooooooooooooooooooooooo
Desiree Hilbring
Institut fuer Photogrammetrie und Fernerkundung
Universitaet Karlsruhe, Germany
email: hilbring@xxxxxxxxxxxxxxxxxxxx
# 0721 6083676
oooooooooooooooooooooooooooooooooooooooooooooooo
// -------------------------------------------------------------------
// TerrainLayer3D.java
//
// Copyright (c) 2000 by IPF
// -------------------------------------------------------------------
package gis.services.gis3D.content;
import gis.services.gis3D.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
import gis.gisterm.*;
import gis.gisterm.map.*;
import gis.gisterm.management.*;
import gis.services.log.*;
import gis.shared.shapefile.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import visad.*;
import visad.java3d.*;
import java.rmi.RemoteException;
/**
* TerrainLayer3D
* This class provides administration methods for threedimensional terrain
* layers.
* The Layer3D class is extended from BranchGroup
*
* @author Desiree Hilbring
*/
public class TerrainLayer3D extends FeatureLayer3D implements DisplayListener{
DisplayImplJ3D display;
float[] eastValues;
float[] northValues;
float[] heightValues;
//double[] eastValues;
//double[] northValues;
//double[] heightValues;
DefaultRendererJ3D renderer;
public DisplayListener listener;
float ulx,uly,lrx,lry,lz,uz,conNorth,conEast;
GIS3DView gis3dView;
Transposition transposition;
WorldVolume wv;
// For debbuging messages
private Logger logger;
/**
* Constructor
*
* This constructor is used from subclasses of TerrainLayer3D.
* They specify the gis3dView in which the components have to be added and
* they need to set east, north and height values through set methods in
* this class.
*
* @param gis3dView
*/
public TerrainLayer3D(GIS3DView gis3dView) {
super();
this.gis3dView = gis3dView;
transposition = new Transposition();
wv = new WorldVolume();
LogService s = (LogService)
GisTerm.lookupService("gis.services.log.LogService");
logger = s.getInstance( GIS3DView.class.getName() );
}
/**
* Constructor
*
* Constructs a TerrainLayer3D from east, north and height values and
* displays it in the specified gis3dView.
*
* @param eastValues float Array with east values
* @param northValues float Array with north values
* @param heightValues float Array with height values
* @param gis3dView
*/
public TerrainLayer3D(float[] eastValues, float[] northValues, float[]
heightValues,GIS3DView gis3dView,float ce,float cn) {
//public TerrainLayer3D(double[] eastValues, double[] northValues,
double[] heightValues,GIS3DView gis3dView,float ce,float cn) {
super();
this.listener = this;
this.eastValues = eastValues;
this.northValues = northValues;
this.heightValues = heightValues;
this.gis3dView = gis3dView;
this.conEast = ce;
this.conNorth = cn;
transposition = new Transposition();
wv = new WorldVolume();
LogService s = (LogService)
GisTerm.lookupService("gis.services.log.LogService");
logger = s.getInstance( GIS3DView.class.getName() );
}
/**
* Constructor
*
* Constructs a TerrainLayer3D from east, north and height values and
* displays it in the specified gis3dView.
*
* @param eastValues float Array with east values.
* @param northValues float Array with north values.
* @param heightValues float Array with height values.
* @param gis3dView in which layer is to be displayed.
*/
public TerrainLayer3D(float[] eastValues, float[] northValues, float[]
heightValues,GIS3DView gis3dView) {
//public TerrainLayer3D(double[] eastValues, double[] northValues,
double[] heightValues,GIS3DView gis3dView) {
super();
this.listener = this;
this.eastValues = eastValues;
this.northValues = northValues;
this.heightValues = heightValues;
this.gis3dView = gis3dView;
//this.conEast = ce;
//this.conNorth = cn;
transposition = new Transposition();
wv = new WorldVolume();
LogService s = (LogService)
GisTerm.lookupService("gis.services.log.LogService");
logger = s.getInstance( GIS3DView.class.getName() );
}
/**
* Triangulation of given set of points with delaunay. This method
* throws an event, when 3D-Objects are ready.
*
* @see displayChanged().
*/
public void makeSurface() {
// Change [Tue May 22 14:27:37 2001]hilbring:
// Koordinatenrange kleiner machen
// Test ob z-Buffer besser wird
// will ich aber eigentloch nicht machen
/*
for (int i=0;i<eastValues.length;i++) {
//System.out.println("e: "+eastValues[i]+" n: "+northValues[i]+" h:
"+heightValues[i]);
//eastValues[i]=eastValues[i]-3550000.0f;
//northValues[i]=northValues[i]-5490000.0f;
//System.out.println("ed: "+eastValues[i]+" nd: "+northValues[i]);
}
*/
// Change [Tue May 22 14:27:38 2001]hilbring:
RealType x = RealType.getRealType("x");
RealType y = RealType.getRealType("y");
RealType height = RealType.getRealType("height");
try {
RealTupleType xy = new RealTupleType(x, y);
FunctionType terrain_type = new FunctionType(xy, height);
Irregular2DSet set = new Irregular2DSet(xy,new float[][]
{eastValues,northValues});
//Irregular2DSet set = new Irregular2DSet(xy,new double[][]
{eastValues,northValues});
FlatField terrain = new FlatField(terrain_type, set);
terrain.setSamples(new float[][] {heightValues});
//terrain.setSamples(new double[][] {heightValues});
//float[] eastValuesIntpol = new float[eastValues.length+1];
//float[] northValuesIntpol = new float[northValues.length+1];
double[] eastValuesIntpol = new double[eastValues.length+1];
double[] northValuesIntpol = new double[northValues.length+1];
for (int i=0;i<northValues.length;i++) {
eastValuesIntpol[i]=eastValues[i];
northValuesIntpol[i]=northValues[i];
//System.out.println("eastValue"+eastValues[i]);
//System.out.println("northValue"+northValues[i]);
}
display = new DisplayImplJ3D("display1");
ScalarMap hoxmap = new ScalarMap(x, Display.XAxis);
ScalarMap reymap = new ScalarMap(y, Display.YAxis);
ScalarMap heightmap = new ScalarMap(height, Display.ZAxis);
display.addMap(hoxmap);
display.addMap(reymap);
display.addMap(heightmap);
hoxmap.setRange(-1.0, 1.0);
reymap.setRange(-1.0, 1.0);
heightmap.setRange(-1.0, 1.0);
DataReferenceImpl data_ref = new DataReferenceImpl("data_ref");
data_ref.setData( terrain );
renderer = new DefaultRendererJ3D();
display.addReferences(renderer,data_ref);
display.addDisplayListener(listener);
}
catch (VisADException ve) {
System.out.println("VisAd TupleType Exception");
}
catch (RemoteException re) {
System.out.println("RemoteExcpetion");
}
}
/**
* Set east values
*
* @param eastValues
*/
/*
public void setEastValues(double[] eastValues) {
this.eastValues = eastValues;
}
*/
public void setEastValues(float[] eastValues) {
this.eastValues = eastValues;
}
/**
* set north values
*
* @param northValues
*/
public void setNorthValues(float[] northValues) {
this.northValues = northValues;
}
/*
public void setNorthValues(double[] northValues) {
this.northValues = northValues;
}
*/
/**
* set height values
*
* @param heightValues
*/
/*
public void setHeightValues(double[] heightValues) {
this.heightValues = heightValues;
}
*/
public void setHeightValues(float[] heightValues) {
this.heightValues = heightValues;
}
/**
* Get the Shape3D object from the delaunay triangulation, change
* the Geometry to satisfy the needs of the GISterm 3D-Service
* and display it.
*
* @param DisplayEvent e
*/
public synchronized void displayChanged(DisplayEvent e) {
if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
// Branch from VisAD with Shape3D
BranchGroup branchGroup = renderer.getBranch();
// test reduce memory visad is using
try {
renderer.clearScene();
renderer.clearBranch();
display.destroy();
}
catch (VisADException ex) {
System.err.println(ex);
}
catch (RemoteException re) {
System.err.println(re);
}
// test reduce memory visad is using end
if (branchGroup != null) {
branchGroup.detach();
Enumeration enum = branchGroup.getAllChildren();
while(enum.hasMoreElements()) {
Object o;
int[] vert = null;
o = enum.nextElement();
if (o instanceof BranchGroup) {
//System.out.println((BranchGroup) o);
}
if (o instanceof Shape3D) {
//System.out.println((Shape3D) o);
Shape3D shape3d = (Shape3D) o;
Geometry geom = shape3d.getGeometry();
// Count number of points in shape3d
if (geom instanceof TriangleStripArray) {
//System.out.println("TriangleStripArray");
TriangleStripArray tri = (TriangleStripArray) geom;
//System.out.println("numstrips
tri"+tri.getNumStrips());
vert = new int[1];
tri.getStripVertexCounts(vert);
}
if (geom instanceof GeometryStripArray) {
//System.out.println("GeometryStripArray");
GeometryStripArray tri = (GeometryStripArray) geom;
//System.out.println("numstrips
geo"+tri.getNumStrips());
vert = new int[1];
tri.getStripVertexCounts(vert);
// Change the represenation of the axes towards
// 3D-Service
GeometryArray geomarr = (GeometryArray) geom;
Point3d[] point3d = new Point3d[vert[0]];
for (int i=0;i<point3d.length;i++) {
point3d[i]= new Point3d();
}
geomarr.getCoordinates(0,point3d);
// Change [Wed Mar 28 16:04:57 2001]hilbring:
point3d = transposition.java3DToWorld(point3d);
wv =
transposition.calculateWorldVolumeFromJava3D(point3d);
geomarr.setCoordinates(0,point3d);
//System.out.println("T%%%%%%%%%%%%%%%%%%%%%%ulx
"+ulx+"lrx "+lrx+"lry "+lry+"uly "+uly+"lz "+lz+"uz "+uz);
// Change [Wed Mar 28 16:04:59 2001]hilbring: ende
}
// Fuer NullpointerExceptionsuche, hoffentlich
// eliminiert
/*
if (!(geom instanceof GeometryStripArray)) {
//System.out.println("hier fehler"+geom);
}
*/
Shape3D terrain = new Shape3D();
Appearance app = shape3d.getAppearance();
terrain.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
terrain.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
// test hilbring March 22
terrain.setCapability(Group.ENABLE_PICK_REPORTING);
terrain.setCapability(Node.ALLOW_PICKABLE_READ);
terrain.setCapability(Node.ALLOW_PICKABLE_WRITE);
// test hilbring March 22 end
// test java3d 1.3
app.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
app.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
app.setCapability(Appearance.ALLOW_MATERIAL_READ);
app.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
app.setTransparencyAttributes(new
TransparencyAttributes());
// test java3d 1.3 ende
// Change [Wed May 16 13:56:33 2001]hilbring:
// rendering issue test
// see j3d.org FAQ scene appearance
// including this results in triangles
/*
RenderingAttributes ra = new RenderingAttributes();
ra.setDepthBufferEnable(true);
app.setRenderingAttributes(ra);
*/
// Change [Wed May 16 13:56:34 2001]hilbring: end
PolygonAttributes pa = app.getPolygonAttributes();
//pa.setPolygonOffset(200);
//pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
geom.setCapability(Geometry.ALLOW_INTERSECT);
terrain.setGeometry(geom);
terrain.setAppearance(app);
this.setBBox(wv);
this.addShape(terrain);
this.setUniformColor(this.getLegendLayer().getTree().getGraphicsContext().getForegroundColor());
logger.debug("add layer "+this);
gis3dView.addLayer(this);
}
}
}
}
}
}