Re: Strange Results for Resampled Irregular3DSet

Hi Eugen,

the last thing I need for my application is the use of a set of
not-evenly-spaced data. I thought, it should work by creating a
Irregular3DSet and resampling it to a Linear3DSet (like it is done in Curtis
Rueden's IrregularRenderTest.java).

I tested the code you sent, and it appears that you have found a bug in the Delaunay triangulation logic (used by Irregular3DSets). The invalid triangulation produced is what causes the erroneous resampling's large number of missing values, which is why the final visualization looks so strange. I will look into this problem as time permits.

Fortunately, you may not need to use IrregularSets at all. If the data is merely unevenly spaced, but still a convex grid, as in your code example, you can use Gridded3DSet.

I took your example and expanded it to demonstrate the idea (below). It creates four FlatFields: the first with Irregular3DSet, the second resampled from that, the third with Gridded3DSet, and the fourth resampled from that. Then it lines them all up in a row in one JFrame to demonstrate the difference.

Please let the list know if you have any further questions or problems.

-Curtis

---------------
// IrregularRenderTest2.java

import javax.swing.*;
import visad.*;
import visad.java3d.*;

public class IrregularRenderTest2 {

 public static void main(String[] args) throws Exception {
   // First construct a irregular 3D set with given coordinates...

   RealType x = RealType.getRealType("x");
   RealType y = RealType.getRealType("y");
   RealType z = RealType.getRealType("z");
   RealTupleType xyz = new RealTupleType(x, y, z);
   RealType value = RealType.getRealType("value");

   int xDim = 3;
   int yDim = 3;
   int zDim = 8;
int count = xDim*yDim*zDim;

   // Create coordinates
   int i = 0;
float[] testX = new float[] {0,3,10}; // X coordinates
   float[] testY = new float[] {0,3,10}; // Y coordinates
float[] testZ = new float[] {0,1.5F,3,4.5F,6,7.5F,9,10}; // Z coordinates float[][] samples = new float[3][testX.length*testY.length*testZ.length];
   for (int zc=0; zc<testZ.length; zc++) {
    for (int yc=0; yc<testY.length; yc++) {
      for (int xc=0; xc<testX.length; xc++) {
       samples[0][i] = testX[xc];
       samples[1][i] = testY[yc];
       samples[2][i] = testZ[zc];
       i++;
     }
    }
   }

   Irregular3DSet iset = new Irregular3DSet(xyz, samples);
   boolean success = iset.Delan.test(samples, true);


   // ...then to create a field for the Irregular3DSet...

   FunctionType ftype = new FunctionType(xyz, value);
   FlatField field = new FlatField(ftype, iset);
float[][] values = new float[1][count];
   for (i=0; i<count; i++) {
    values[0][i] = (float) (10*Math.random()); // Some temperature values
   }
   field.setSamples(values, false);


   // ...then to resample the irregular Data to regular Data...

   int size = 60;

   Linear3DSet set = new Linear3DSet(xyz,
         0, 10, size, 0, 10, size, 0, 10, size);

   FlatField field2 = new FlatField(ftype, set);

   field2 = (FlatField)
         field.resample(set, Data.WEIGHTED_AVERAGE, Data.NO_ERRORS);


   // ...also create a field for the data as a Gridded3DSet...

   Gridded3DSet gset = new Gridded3DSet(xyz, samples,
     testX.length, testY.length, testZ.length);

   FlatField field3 = new FlatField(ftype, gset);
   field3.setSamples(values, false);


   // ...then resample that to another evenly space grid...

   FlatField field4 = new FlatField(ftype, set);

   field4 = (FlatField)
         field3.resample(set, Data.WEIGHTED_AVERAGE, Data.NO_ERRORS);



   // ...and finally to add the data to the display...

   DisplayImplJ3D display = new DisplayImplJ3D("display");
   display.addMap(new ScalarMap(x, Display.XAxis));
   display.addMap(new ScalarMap(y, Display.YAxis));
   display.addMap(new ScalarMap(z, Display.ZAxis));
   display.addMap(new ScalarMap(value, Display.RGB));
   display.getGraphicsModeControl().setPointSize(10);

   DataReferenceImpl ref = new DataReferenceImpl("ref");
   ref.setData(field);
   display.addReference(ref);

   DisplayImplJ3D display2 = new DisplayImplJ3D("display2");
   display2.addMap(new ScalarMap(x, Display.XAxis));
   display2.addMap(new ScalarMap(y, Display.YAxis));
   display2.addMap(new ScalarMap(z, Display.ZAxis));
   display2.addMap(new ScalarMap(value, Display.RGB));

   DataReferenceImpl ref2 = new DataReferenceImpl("ref2");
   ref2.setData(field2);
   display2.addReference(ref2);

   DisplayImplJ3D display3 = new DisplayImplJ3D("display3");
   display3.addMap(new ScalarMap(x, Display.XAxis));
   display3.addMap(new ScalarMap(y, Display.YAxis));
   display3.addMap(new ScalarMap(z, Display.ZAxis));
   display3.addMap(new ScalarMap(value, Display.RGB));

   DataReferenceImpl ref3 = new DataReferenceImpl("ref3");
   ref3.setData(field3);
   display3.addReference(ref3);

   DisplayImplJ3D display4 = new DisplayImplJ3D("display4");
   display4.addMap(new ScalarMap(x, Display.XAxis));
   display4.addMap(new ScalarMap(y, Display.YAxis));
   display4.addMap(new ScalarMap(z, Display.ZAxis));
   display4.addMap(new ScalarMap(value, Display.RGB));

   DataReferenceImpl ref4 = new DataReferenceImpl("ref4");
   ref4.setData(field4);
   display4.addReference(ref4);

   // show display onscreen
   JFrame frame = new JFrame("Irregular rendering test 2");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   JPanel pane = new JPanel();
   pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
   pane.add(display.getComponent());
   pane.add(display2.getComponent());
   pane.add(display3.getComponent());
   pane.add(display4.getComponent());
   frame.setContentPane(pane);
   frame.setBounds(50, 50, 1100, 300);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.show();
 }

}