Re: The random colour changing bug

Hi,

Do any other Wisconsin folks see the
color change running Andrew's test program?

I tried it on my machine (Linux running Java 1.4.2_09 and Java3D 1.3.1 with an nVidia graphics card), and saw the bug. The yellow box gets slightly darker once the middle button is pressed and the cursor is moved at all.

I tried a few other tests. The problem occurs regardless of texture mapping on or off. It does not occur with Java2D, or with a color mapping to RGB instead of ConstantMaps to Red, Green and Blue. I've included a modified version of the test program that uses a mapping to Display.RGB to avoid the problem.

Bill, any ideas how I could continue investigating this issue? I can just dig into the ConstantMap logic, since that seems likely. The fact that you aren't seeing the problem on your machine suggests that it's either specific to newer versions of Java3D, or dependent on graphics card hardware.

-Curtis

-----
import java.awt.*;
import javax.swing.*;
import visad.*;
//import visad.java2d.DisplayImplJ2D;
import visad.java3d.*;

public class ColourBug {

 private DataReferenceImpl dataReference;

 public ColourBug() throws Exception {
   DisplayImpl display;
   ScalarMap latMap, lonMap;

   DisplayRendererJ3D displayRenderer = new TwoDDisplayRendererJ3D();
   display = new DisplayImplJ3D("display", displayRenderer);
   //display = new DisplayImplJ2D("display");

   RealType pixel = RealType.getRealType("PIXEL");

   lonMap = new ScalarMap(RealType.Longitude, Display.XAxis);
   latMap = new ScalarMap(RealType.Latitude, Display.YAxis);
   ScalarMap pixelMap = new ScalarMap(pixel, Display.RGB); // CTR

   FunctionType functionType = new FunctionType(
     RealTupleType.LatitudeLongitudeTuple, pixel);
   Set domainSet = new Integer2DSet(
     RealTupleType.LatitudeLongitudeTuple, 2, 2);

   float[][] flatSamples = new float[1][2*2];
   flatSamples[0][0] = 1;
   flatSamples[0][1] = 1;
   flatSamples[0][2] = 1;
   flatSamples[0][3] = 1;

   FlatField ffVals = new FlatField(functionType, domainSet);
   ffVals.setSamples(flatSamples);

   DataReferenceImpl dataRef = new DataReferenceImpl("dataRef");
   dataRef.setData(ffVals);

   display.addMap(lonMap);
   display.addMap(latMap);
   display.addMap(pixelMap); // CTR

   // CTR - Why are the ranges -0.5 to 1.5, and why don't they autoscale?
   // Is this another bug? It doesn't happen with color ConstantMaps.
   lonMap.setRange(-0.5, 1.5);
   latMap.setRange(-0.5, 1.5);

   Color colour = new Color(254,240,179);
   /* CTR
   ConstantMap[] colourConstantMap = new ConstantMap[3];
   colourConstantMap[0] = new ConstantMap(colour.getRed()/255.0f,
     Display.Red);
   colourConstantMap[1] = new ConstantMap(colour.getGreen()/255.0f,
     Display.Green);
   colourConstantMap[2] = new ConstantMap(colour.getBlue()/255.0f,
     Display.Blue);
   */
   ColorControl cc = (ColorControl) pixelMap.getControl();
   float[][] table = cc.getTable();
   int numColors = table[0].length;
   table[0][numColors / 2] = colour.getRed()/255.0f;
   table[1][numColors / 2] = colour.getGreen()/255.0f;
   table[2][numColors / 2] = colour.getBlue()/255.0f;
   //java.util.Arrays.fill(table[0], colour.getRed()/255.0f);
   //java.util.Arrays.fill(table[1], colour.getGreen()/255.0f);
   //java.util.Arrays.fill(table[2], colour.getBlue()/255.0f);
   cc.setTable(table);

   //display.getGraphicsModeControl().setScaleEnable(true);
   //display.getGraphicsModeControl().setTextureEnable(false);
   display.addReference(dataRef/*, colourConstantMap*/);

   // Swing stuff
   JFrame frame = new JFrame("ColourBug example program");
   frame.getContentPane().add(display.getComponent());
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   frame.setSize(500, 500);
   frame.setVisible(true);
 }

public static void main(String[] args) throws Exception { new ColourBug(); }

}