Re: Scaling?

Hi Bill,

I got it to work, I added accidently a layer with no content and deleted
the one with content. I really need the

> > eastMap.setRange(-1.0, 1.0);
> > northMap.setRange(-1.0, 1.0);
> > heightMap.setRange(-1.0, 1.0);
> > 

to get the original coordinates in my Java3D shape.

Never mind it is working now. The implementation is in the attached file.

I still have one problem.
I can load only on ascii .dhm file with the format
east.north.height

but trying to load a second dem from another file results in a

 VisAd TupleType Exception

What can cause this error?

Thanks Desiree

> 
> So the range of all is 1000.0. The surface will look very flat.

I had only 6 points in my test example. In reality it is a dgm with 13000
vertices with heights between 400 and 800m , which does not look very flat
:-).

 > 
> Cheers,
> Bill
> 
> 
// -------------------------------------------------------------------
//  GridLayer3D.java
//
//  Copyright (c) 2001 by IPF
// -------------------------------------------------------------------
package gis.services.gis3D.content;
import gis.services.gis3D.*;

import java.util.Enumeration;

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.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;

/**
 * GridLayer3D
 * This class provides administration methods for threedimensional grid
 * layers.
 * The Layer3D class is extended from BranchGroup
 *
 * @version [Mon May 28 15:22:18 2001]hilbring
 * @author Desiree Hilbring
 */
public class GridLayer3D extends FeatureLayer3D implements DisplayListener{

    float[] east;
    float[] north;
    float[] height;
    DefaultRendererJ3D renderer;
    public DisplayListener listener;     
    float ulx,uly,lrx,lry,lz,uz,conNorth,conEast;
    GIS3DView gis3dView;
    Transposition transposition;
    WorldVolume wv;
    private RealType eastValues,northValues;
    private RealType heightValues;
    private RealTupleType domain_tuple;
    private FunctionType func_en_h;
    private Set domain_set;
    private FlatField vals_ff;  
    private DataReferenceImpl data_ref;
    private DisplayImpl display;
    private ScalarMap eastMap, northMap, heightMap;
    int nCols,nRows;
    double eastMin,eastMax,northMin,northMax;

    /**
     * Constructor
     *
     * This constructor is used from subclasses of GridLayer3D.
     * 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 GridLayer3D(GIS3DView gis3dView) {           
        super();
        this.gis3dView = gis3dView;
        transposition = new Transposition();
        wv = new WorldVolume();
    }    

    /**
     * Constructor
     *
     * Constructs a GridLayer3D 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 GridLayer3D(float[] east, float[] north, float[] height,GIS3DView 
gis3dView) {     
    public GridLayer3D(DGMReader dgmReader, GIS3DView gis3dView) {              
        super();
        this.listener = this;
        this.east = dgmReader.getEastArray();
        this.north = dgmReader.getNorthArray();
        this.height = dgmReader.getHeightArray();
        this.nCols = dgmReader.getNCols();
        this.nRows = dgmReader.getNRows();
        this.eastMin = dgmReader.getEastMin();
        this.eastMax = dgmReader.getEastMax();
        this.northMin = dgmReader.getNorthMin();
        this.northMax = dgmReader.getNorthMax();
        this.gis3dView = gis3dView;
        transposition = new Transposition();
        wv = new WorldVolume();
        for (int i=0;i<east.length;i++) {
            System.out.println(east[i]);
            System.out.println(north[i]);
            System.out.println(height[i]);
        }
    }    

    /**
     * This method throws an event, when 3D-Objects are ready. 
     *
     * @see displayChanged().
     */
    public void makeSurface() {

        // Change [Mon May 28 15:23:29 2001]hilbring:
        try {
            
            eastValues = new RealType("eastValues");
            northValues = new RealType("northValues");
            domain_tuple = new RealTupleType(northValues,eastValues);
            heightValues = new RealType("heightValues");
            
            // Create a FunctionType (domain_tuple -> range_tuple);
            func_en_h = new FunctionType(domain_tuple, heightValues);
            
            //int NCOLS = 2;
            //int NROWS = 3;
            
            //domain_set = new 
Linear2DSet(domain_tuple,5379000,5380000,NROWS,3532000, 3533000, NCOLS); 
            System.out.println("nCols "+nCols);
            System.out.println("nRows "+nRows);
            System.out.println(northMin+" "+northMax+" "+eastMin+" "+eastMax);
            domain_set = new 
Linear2DSet(domain_tuple,northMin,northMax,nRows,eastMin, eastMax, nCols); 

            System.out.println("hallo");
            
            // Get the Set samples to facilitate the calculations
            float[][] set_samples = domain_set.getSamples( true );
            
            // We create another array, with the same number of elements of
            // altitude and temperature, but organized as 
            // float[2][ number_of_samples ]        
            //float[][] flat_samples = new float[1][NCOLS * NROWS]; 
            float[][] flat_samples = new float[1][nCols * nRows]; 
            
            // ...and then we fill our 'flat' array with the generated values
            // by looping over NCOLS and NROWS     
            // specifiy height
            for(int c = 0; c < nCols; c++){
                for(int r = 0; r < nRows; r++){     
                    flat_samples[0][c*nRows+r] = height[c*nRows+r];             
     
                    //System.out.println("height "+height[c*nRows+r]);
                }
            }
            
            // Create a FlatField  
            // Use FlatField(FunctionType type, Set domain_set)    
            vals_ff = new FlatField( func_en_h, domain_set);
            
            // ...and put the values above into it
            // Note the argument false, meaning that the array won't be copied 
            vals_ff.setSamples( flat_samples , false ); 

            System.out.println("hallo2");
            
            // Create Display and its maps    
            // A 2D display    
            display = new DisplayImplJ3D("display1");    
            
            // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
            // altitude to RGB and temperature to IsoContour
            // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar) 
            eastMap = new ScalarMap( eastValues, Display.YAxis );
            northMap = new ScalarMap( northValues, Display.XAxis );    
            heightMap = new ScalarMap(heightValues,Display.ZAxis);

            // Change [Wed May 30 12:18:36 2001]hilbring:
            eastMap.setRange(-1.0, 1.0);
            northMap.setRange(-1.0, 1.0);
            heightMap.setRange(-1.0, 1.0);
            //heightMap.setRange(0, 10000);
            // Change [Wed May 30 12:18:41 2001]hilbring:

            
            // Add maps to display
            display.addMap( eastMap );
            display.addMap( northMap );    
            display.addMap( heightMap );

            System.out.println("hallo3");
            
            // Create a data reference and set the FlatField as our data 
            data_ref = new DataReferenceImpl("data_ref");
            data_ref.setData( vals_ff );
            renderer = new DefaultRendererJ3D();
            
            // Add reference to display
            display.addReferences(renderer,data_ref);
            //display.addReference( data_ref );
            display.addDisplayListener(listener);

            // Create application window and add display to window
            /*
            JFrame jframe = new JFrame("VisAD Fenster");
            jframe.getContentPane().add(display.getComponent());        
            // Set window size and make it visible
            jframe.setSize(300, 300);
            jframe.setVisible(true);        
            */
            // Change [Mon May 28 15:23:31 2001]hilbring:
        }
        catch (VisADException ve) {
            System.out.println("VisAd TupleType Exception");
        }       
        catch (RemoteException re) {
            System.out.println("RemoteExcpetion");
        }

        /*
        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);
            Gridded2DSet set = new Gridded2DSet(xy,new float[][] 
{eastValues,northValues},eastValues.length*2);
            FlatField terrain = new FlatField(terrain_type, set);
            terrain.setSamples(new float[][] {heightValues});
            float[] eastValuesIntpol = new float[eastValues.length+1];
            float[] northValuesIntpol = new float[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(float[] eastValues) {
        this.east = east;
    }

    /**
     * set north values
     *
     * @param northValues
     */
    public void setNorthValues(float[] northValues) {
        this.north = north;
    }

    /**
     * set height values
     *
     * @param heightValues
     */
    public void setHeightValues(float[] heightValues) {
        this.height = height;
    }

    /**
     * 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 void displayChanged(DisplayEvent e) {
        System.out.println("in displayChanged");
        if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
            //System.out.println("transform done");
            // Branch from VisAD with Shape3D
            BranchGroup branchGroup = renderer.getBranch();
            //System.out.println("branchGroup "+branchGroup);
            if (branchGroup != null) {
                System.out.println("get branch");
                branchGroup.detach();
                Enumeration enum = branchGroup.getAllChildren();
                while(enum.hasMoreElements()) {
                    int[] vert = null;
                    Object o = enum.nextElement();
                    System.out.println("Object "+o);
                    if (o instanceof BranchGroup) {
                        System.out.println("BG "+(BranchGroup) o);
                        BranchGroup bg = (BranchGroup) o;
                        Enumeration enum2 = bg.getAllChildren();
                        while (enum2.hasMoreElements()) {
                            Object o2 = enum2.nextElement();
                            if (o2 instanceof Shape3D) {
                                Shape3D shape3d = (Shape3D) o2;
                                Geometry geom = shape3d.getGeometry();
                                if (geom instanceof TriangleStripArray) {
                                    System.out.println("TriangleStripArray");
                                    TriangleStripArray tri = 
(TriangleStripArray) geom;
                                    //System.out.println("numstrips 
tri"+tri.getNumStrips());
                                    //vert = new int[1];
                                    vert = new int[tri.getNumStrips()];
                                    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];
                                    vert = new int[tri.getNumStrips()];
                                    tri.getStripVertexCounts(vert);
                                    // Change the represenation of the axes 
towards
                                    // 3D-Service
                                    GeometryArray geomarr = (GeometryArray) 
geom;
                                    // hier anzahl erhoehe summe aller verts!
                                    //Point3d[] point3d = new Point3d[vert[0]]; 
                                    //Point3d[] point3d = new Point3d[4]; 
                                    //Point3d[] point3d = new 
Point3d[nRows*nCols];
                                    Point3d[] point3d = new 
Point3d[geomarr.getVertexCount()];
                                    System.out.println("vc 
"+geomarr.getVertexCount());
                                    System.out.println("l "+point3d.length);
                                    for (int i=0;i<point3d.length;i++) {
                                        point3d[i]= new Point3d();
                                    }
                                    geomarr.getCoordinates(0,point3d);

                                    for (int i=0;i<point3d.length;i++) {
                                        System.out.println(point3d[i]);
                                    }
                                    
                                    point3d = 
transposition.java3DToWorld(point3d);
                                    wv = 
transposition.calculateWorldVolumeFromJava3D(point3d);                          
                                        
                                    geomarr.setCoordinates(0,point3d);
                                    
                                    for (int i=0;i<point3d.length;i++) {
                                        System.out.println(point3d[i]);
                                    }
                                    System.out.println("wv "+wv.toString());
                                }
                                                        
                                Shape3D terrain = new Shape3D();
                                Appearance app = shape3d.getAppearance();
                                
terrain.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
                                
terrain.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
                                
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());
                                PolygonAttributes pa = 
app.getPolygonAttributes();
                                
//pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
                                geom.setCapability(Geometry.ALLOW_INTERSECT);
                                terrain.setGeometry(geom);
                                terrain.setAppearance(app);

                                this.setBBox(wv);
                                this.addShape(terrain);
                                //this.addShape(shape3d);
                                
this.setUniformColor(this.getLegendLayer().getTree().getGraphicsContext().getForegroundColor());
                                gis3dView.addLayer(this);
                            }
                        }
                        
                    }
                    if (o instanceof Shape3D) {
                        System.out.println("Shape "+(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);
                        
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());
                        PolygonAttributes pa = app.getPolygonAttributes();
                        //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());
                        gis3dView.addLayer(this);
                    }
                }
            }
        }
    }
}
  • Follow-Ups:
    • Re: Scaling?
      • From: From: Bill Hibbard <hibbard@xxxxxxxxxxxxxxxxx>
  • References:
    • Re: Scaling?
      • From: From: Bill Hibbard <hibbard@xxxxxxxxxxxxxxxxx>
  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: