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
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(
        at java.util.ArrayList.get(
        at visad.java3d.RendererJ3D.getBranch(
        at LineTest6.displayChanged(
        at visad.DisplayImpl.notifyListeners(
        at visad.DisplayImpl.notifyListeners(
        at visad.DisplayImpl.doAction(
        at visad.util.ThreadPool$

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

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 Hilbring

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

// 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 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)  
        // 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 );

        // 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 );


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

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

    public void makeProfileView() {
        try {
            if (counter==0) {
                float[][] eastNorthSamples = new float[2][50];
                for (int i=0;i<50;i++) {
                Gridded2DSet setGrid2D = new Gridded2DSet(xy, eastNorthSamples, 
                FlatField terrain_new = (FlatField) 
                DataReferenceImpl data_ref5 = new 
                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) {
                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);
    public static void main(String[] args)
        throws RemoteException, VisADException
        new LineTest6(args);
        //JFrame jframe = new JFrame("LineTest6");
        // Set window size and make it visible  
        //jframe.setSize(300, 300);