Re: How to access Facet Data in a 3D surface

Hi Bill,

Thanks for the insight into this method (PickManipulationRendererJ3D).  For
recall, I am looking into a way to find out what facet intersects with a
ray which is created when the user clicks somewhere on the surface of our
3D object.  I can create the ray from the location of the camera and the
point clicked on in 3D space, but I'm still looking into how to determine
what facet or point is closest to that ray.  It looks like it will do what
I am looking for, but I had some more questions on its implementation.  Im
looking at the function checkClose() ...

  public synchronized float checkClose(double[] origin, double[] direction)
    int mouseModifiers = getLastMouseModifiers();
    if ((mouseModifiers & mouseModifiersMask) != mouseModifiersValue)
      return Float.MAX_VALUE;

    float distance = Float.MAX_VALUE;
    if (spatialValues == null) return distance;
    float o_x = (float) origin[0];
    float o_y = (float) origin[1];
    float o_z = (float) origin[2];
    float d_x = (float) direction[0];
    float d_y = (float) direction[1];
    float d_z = (float) direction[2];

    for (int i=0; i<spatialValues[0].length; i++)
      float x = spatialValues[0][i] - o_x;
      float y = spatialValues[1][i] - o_y;
      float z = spatialValues[2][i] - o_z;
      float dot = x * d_x + y * d_y + z * d_z;
      x = x - dot * d_x;
      y = y - dot * d_y;
      z = z - dot * d_z;
      float d = (float) Math.sqrt(x * x + y * y + z * z);
      if (d < distance)
        distance = d;
        closeIndex = i;

    return distance;

I can see where it parses this spatialValues[][] float array and calculates
the distance of the ray to each point in this array and returns the closest
index in that array.  My question is this:  I cannot see where the values
of the spatialArray are actually set to anything.  There is a
setSpatialValues() function that sets the class float array spatialValues
to an array that is passed into that function, but the setSpatialValues()
function is never called within this code.  My question thus is how are
these values in the spatialValues determined?

Thanks in advance!


Bill Hibbard writes:

> Hi Greg,
> > I am working on a project in which we are using VisAd to display a 3
> > dimensional image of data points.  We essentially create a 3d surface out
> > of these data points, which are made up of triangular facets, made out of
> > the data points.  My question is pretty simple, but I am having a really
> > interesting time figuring out how exactly VisAd creates all of these
> > triangular facets, and how to access those facets.
> >
> > Essentially, I want the user to be able to click on the screen somewhere
> > and be able to report what facet the user clicked on, and report any data
> > associated with that facet. What I can't figure out is how VisAd stores the
> > data associated with the facets that it is drawing.
> >
> > I have looked into MouseHelperJ3D and I see how to get the location in
> > world space of the observer (eye_position) and how to get the location in
> > 3D space that the user clicked on (position).  I can create a vector out of
> > this and this is my ray in 3D space.  I want to know if that ray,
> > emminating from the observer, going out into space, intersects with any of
> > the facets in the data set we are displaying.
> >
> > I have looked into the following classes and elucidated the following (tell
> > me where I am incorrect):
> >
> > FlatField is a container for the entire "data model"?
> > DataReferenceJ3D setData() is a gateway of some kind in setting the data
> > for each of the facets in the 3D surface?
> Actually, FlatField is the class for Data objects that are
> finite samplings of functions, with certain simple types.
> DataReference is the interface for linking Data objects to
> Displays of Cells (computations).
> Some, but not all, Data depictions are composed of 3-D facets.
> > The confusion I encounter is that when I try to go past the
> > DataReferenceJ3D, it starts referencing an object called "Thing".  I am
> > having difficulty understanding exactly what a "Thing" is.  Is it in any
> > way related to how I access where the facets are in 3D space?
> >
> > Typically in 3D graphics one uses some kind of data structure to hold all
> > of the facets in an object.  I understand this could be different for
> > Java3D, but essentially, the data for displaying the facets has to be
> > stored somewhere, and there has to be a way to access it.  Im just having
> > difficulty finding it.
> You might get some idea of how Data depictions are computed in
> the draft DataRenderer tutorial. However, you don't need to dig
> into all this - it is pretty complex. Rather, you might use
> visad/bom/ It will tell you
> which vertex (vertex rather than facet) in the surface is closest
> to the mouse ray when the right mouse button is clicked. See
> the main() method in this class for an example of how it should
> be used.
> Good luck,
> Bill