IndexOutOfBoundsException with RendererJ3D

Hi Bill,

a few years ago you helped me to grab my created VisAD-Shape3Ds and put
them into my own scenegraph.
Today I tried to grab my newly created 3D-lines for the profile and put
them into my scenegraph as well. Unforetunately I get an

J:\java\visad\tutorial>java LineTest6
In enumeration
Located Shape3D javax.media.j3d.Shape3D@d10a5c
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:508)
        at java.util.ArrayList.get(ArrayList.java:320)
        at javax.media.j3d.GroupRetained.getChild(GroupRetained.java:408)
        at javax.media.j3d.Group.getChild(Group.java:224)
        at visad.java3d.RendererJ3D.getBranch(RendererJ3D.java:258)
        at LineTest6.displayChanged(LineTest6.java:165)
        at visad.DisplayImpl.notifyListeners(DisplayImpl.java:484)
        at visad.DisplayImpl.notifyListeners(DisplayImpl.java:466)
        at visad.DisplayImpl.doAction(DisplayImpl.java:1510)
        at visad.ActionImpl.run(ActionImpl.java:303)
        at visad.util.ThreadPool$ThreadMinnow.run(ThreadPool.java:95)

exception the second time I try to get hold of the VisAD-BranchGroup.

A little test programm trying to simulate the flow is attached:

First I am creating my terrain and add it two the view.
The terrain is grabbed and in reality put into my own scene.
After that I am creating my 3D-line and add it into the VisAD-View (In
reality I need some user input to create the clipping plane).
Trying to grab the VisAD BranchGroup a second time, directs me to the
error.

I was thinking of not detaching the BranchGroup in the first place, so
that I only need to grap the group once. But then I am not allowed to look
for the geometry, because of capability bits, which are not set.

Can I avoid the error?
Is it possible to reattach the VisAD-BranchGroup, and would that help?
Or is there another solution?

Thanks for your help

Desiree

oooooooooooooooooooooooooooooooooooooooooooooooo
Desiree Hilbring

Institut fuer Photogrammetrie und Fernerkundung  
Universitaet Karlsruhe, Germany
email: hilbring@xxxxxxxxxxxxxxxxxxxx             
# 0721 6083676                                   
oooooooooooooooooooooooooooooooooooooooooooooooo


// Import needed classes

import visad.*;
import visad.util.*;
//import visad.java3d.DisplayImplJ3D;
import visad.java3d.*;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import javax.media.j3d.*;
import java.util.Enumeration;


public class LineTest6 implements DisplayListener{

    int counter;
    public DisplayListener listener;  
    DefaultRendererJ3D renderer;

    // Declare variables
    // The domain quantities longitude and latitude
    // and the dependent quantity rgbVal
    
    private RealType x,y,height;
    
    // Tuple to pack x and y together    
    private RealTupleType xy;
    
    // The function (domain_tuple -> rgbVal )    
    private FunctionType terrain_type;
        
    // Our Data values for the domain are represented by the Set    
    private Set set;
        
    // The Data class FlatField    
    private FlatField terrain;
    
    // The DataReference from data to display    
    private DataReferenceImpl data_ref;
    
    // The 2D display, and its the maps    
    static private DisplayImpl display;
    private ScalarMap hoxmap,reymap,heightmap;
    
    public LineTest6(String []args) throws RemoteException, VisADException {

        counter = 0;
        this.listener = this;
        
        // Create the quantities
        // Use RealType(String name, Unit unit, Set set);
        
        RealType x = RealType.getRealType("x");
        RealType y = RealType.getRealType("y");
        RealType height = RealType.getRealType("height");

        xy = new RealTupleType(x, y);
        RealTupleType xheight = new RealTupleType(x, height);
        
        terrain_type = new FunctionType( xy, height);
        
        FunctionType line_type = new FunctionType(x,height);

        float[] eastValues = {1,2,7,7,13};
        float[] northValues = {3,8,1,6,3};
        float[] heightValues = {1,2,3,2,1};

        set = new Irregular2DSet(xy,new float[][] {eastValues, northValues});
        
        // Create a FlatField
        // Use FlatField(FunctionType type, Set domain_set)
        
        terrain = new FlatField( terrain_type, set);
        
        // ...and put the rgbVal values above into it
        
        // Note the argument false, meaning that the array won't be copied
        
        terrain.setSamples(new float[][] {heightValues});
        
        // Create Display and its maps
        
        // This is new: a 3D display
        
        display = new DisplayImplJ3D("display1");
        
        // Get display's graphics mode control and draw scales
        
        GraphicsModeControl dispGMC = (GraphicsModeControl)  
display.getGraphicsModeControl();
        dispGMC.setScaleEnable(true);
        
        
        // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
        // rgbVal to ZAxis and to RGB
        // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
        
        hoxmap = new ScalarMap( x, Display.XAxis );
        reymap = new ScalarMap( y, Display.YAxis );
        heightmap = new ScalarMap( height, Display.ZAxis );
        
        // Add maps to display
        
        display.addMap( hoxmap );
        display.addMap( reymap );
        display.addMap( heightmap );

        heightmap.setRange(0,15);
        hoxmap.setRange(0,15);
        reymap.setRange(0,15);
        
        // Create a data reference and set the FlatField as our data
        
        data_ref = new DataReferenceImpl("data_ref");   
        data_ref.setData( terrain );

        renderer = new DefaultRendererJ3D();
        display.addReferences( renderer, data_ref );

        display.addDisplayListener(listener);

        // Create application window and add display to window
        
        JFrame jframe = new JFrame("LineTest6");
        jframe.getContentPane().add(display.getComponent());

        // Set window size and make it visible
        
        jframe.setSize(300, 300);
        jframe.setVisible(true);
    }

    public void makeProfileView() {
        try {
            if (counter==0) {
                counter++;
                
                float[][] eastNorthSamples = new float[2][50];
                for (int i=0;i<50;i++) {
                    eastNorthSamples[0][i]=i;
                    eastNorthSamples[1][i]=i;
                }
                Gridded2DSet setGrid2D = new Gridded2DSet(xy, eastNorthSamples, 
50);
                
                FlatField terrain_new = (FlatField) 
terrain.resample(setGrid2D,Data.WEIGHTED_AVERAGE,Data.NO_ERRORS);
                
                DataReferenceImpl data_ref5 = new 
DataReferenceImpl("data_ref5");
                data_ref5.setData( terrain_new );
                display.addReference( data_ref5 );
            }
        }
        catch (VisADException ve) {
            System.out.println("VisAd TupleType Exception "+ve);
        }       
        catch (RemoteException re) {
            System.out.println("RemoteExcpetion "+re);
        }
    }

    public synchronized void displayChanged(DisplayEvent e) {
        //System.out.println("DISPLAY CHANGED !!!!!!!!!!!!!!!");
        if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
            // Branch from VisAD with Shape3D       
            BranchGroup branchGroup = renderer.getBranch();
            if (branchGroup != null) {
                branchGroup.detach();
                Enumeration enum = branchGroup.getAllChildren();
                while(enum.hasMoreElements()) {
                    System.out.println("In enumeration");
                    Object o;
                    o = enum.nextElement();
                    if (o instanceof Shape3D) {
                        System.out.println("Located Shape3D "+(Shape3D) o);
                    }
                }
            }
        }
        makeProfileView();
    }
    
    
    public static void main(String[] args)
        throws RemoteException, VisADException
    {
        new LineTest6(args);
        /*
        System.out.println("111111111111111");
        //JFrame jframe = new JFrame("LineTest6");
        //jframe.getContentPane().add(display.getComponent());
        System.out.println("22222222222222222222");     
        // Set window size and make it visible  
        //jframe.setSize(300, 300);
        //jframe.setVisible(true);
        System.out.println("3333333333333333333");
        */
    }
    
}
  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: