com.sun.j3d.utils.picking
Class PickIntersection

java.lang.Object
  extended by com.sun.j3d.utils.picking.PickIntersection

public class PickIntersection
extends java.lang.Object

Holds information about an intersection of a PickShape with a Node as part of a PickResult. Information about the intersected geometry, intersected primitive, intersection point, and closest vertex can be inquired.

The intersected geometry is indicated by an index into the list of geometry arrays on the PickResult. It can also be inquired from this object.

The intersected primitive indicates which primitive out of the GeometryArray was intersected (where the primitive is a point, line, triangle or quad, not a com.sun.j3d.utils.geometry.Primitive). For example, the intersection would indicate which triangle out of a triangle strip was intersected. The methods which return primitive data will have one value if the primitive is a point, two values if the primitive is a line, three values if the primitive is a triangle and four values if the primitive is quad.

The primitive's VWorld coordinates are saved when then intersection is calculated. The local coordinates, normal, color and texture coordinates for the primitive can also be inquired if they are present and readable.

The intersection point is the location on the primitive which intersects the pick shape closest to the center of the pick shape. The intersection point's location in VWorld coordinates is saved when the intersection is calculated. The local coordinates, normal, color and texture coordiantes of at the intersection can be interpolated if they are present and readable.

The closest vertex is the vertex of the primitive closest to the intersection point. The vertex index, VWorld coordinates and local coordinates of the closest vertex can be inquired. The normal, color and texture coordinate of the closest vertex can be inquired from the geometry array:

      Vector3f getNormal(PickIntersection pi, int vertexIndex) {
          int index;
          Vector3d normal = new Vector3f();
          GeometryArray ga = pickIntersection.getGeometryArray();
          if (pickIntersection.geometryIsIndexed()) {
              index = ga.getNormalIndex(vertexIndex);
          } else {
              index = vertexIndex;
          }
          ga.getNormal(index, normal);
          return normal;
      }
 

The color, normal and texture coordinate information for the intersected primitive and the intersection point can be inquired the geometry includes them and the corresponding READ capibility bits are set. PickTool.setCapabilties(Node, int) can be used to set the capability bits to allow this data to be inquired.


Field Summary
(package private)  Point3d closestVertexCoordinates
          Coordinates of the closest vertex
(package private)  Point3d closestVertexCoordinatesVW
          Coordinates of the closest vertex (World coordinates)
(package private)  int closestVertexIndex
          Index of the closest vertex
(package private) static boolean debug
           
(package private)  double distance
          Distance between start point and intersection point (see comment above)
(package private)  GeometryArray geom
           
(package private)  int geomIndex
          index of GeometryArray in PickResult
(package private)  boolean hasColors
           
(package private)  boolean hasNormals
           
(package private)  boolean hasTexCoords
           
(package private)  IndexedGeometryArray iGeom
           
(package private)  double[] interpWeights
          Weight factors for interpolation, values correspond to vertex indices, sum == 1
(package private)  PickResult pickResult
          PickResult for intersection is part of
(package private)  Color4f pointColor
          Color at the intersection point
(package private)  Point3d pointCoordinates
          Local Coordinates of the intersection point
(package private)  Point3d pointCoordinatesVW
          VWorld Coordinates of the intersection point
(package private)  Vector3f pointNormal
          Normal at the intersection point
(package private)  TexCoord3f pointTexCoord
          TexCoord at the intersection point
(package private)  int[] primitiveColorIndices
           
(package private)  Color4f[] primitiveColors
           
(package private)  int[] primitiveCoordinateIndices
           
(package private)  Point3d[] primitiveCoordinates
           
(package private)  Point3d[] primitiveCoordinatesVW
          VWorld coordinates of intersected primitive
(package private)  int[] primitiveNormalIndices
           
(package private)  Vector3f[] primitiveNormals
           
(package private)  int[] primitiveTexCoordIndices
           
(package private)  TexCoord3f[] primitiveTexCoords
           
(package private)  int[] primitiveVertexIndices
          Indices of the intersected primitive
(package private) static double TOL
           
(package private) static int X_AXIS
           
(package private) static int Y_AXIS
           
(package private) static int Z_AXIS
           
 
Constructor Summary
PickIntersection(PickResult pr, GeometryArray geomArr)
          Constructor
 
Method Summary
(package private)  double abs(double value)
           
 boolean geometryIsIndexed()
          Returns true if the geometry is indexed
 Point3d getClosestVertexCoordinates()
          Get coordinates of closest vertex (local)
 Point3d getClosestVertexCoordinatesVW()
          Get coordinates of closest vertex (world)
 int getClosestVertexIndex()
          Get index of closest vertex
 double getDistance()
          Get the distance from the PickShape start point to the intersection point
 GeometryArray getGeometryArray()
          Returns the GeometryArray for the intersection
 int getGeometryArrayIndex()
          Returns the index of the intersected GeometryArray into the geometry arrays in the PickResult
(package private)  int getInterleavedColorOffset(GeometryArray geo)
           
(package private)  int getInterleavedNormalOffset(GeometryArray geo)
           
(package private)  int getInterleavedStride(GeometryArray geo)
           
(package private)  int getInterleavedVertexOffset(GeometryArray geo)
           
private static float getInterpFactor(Point3d p, Point3d p1, Point3d p2, int axis)
          Calculate the interpolation factor for point p by projecting it along an axis (x,y,z) onto the edge between p1 and p2.
private static float getInterpFactorForBase(Point3d p, Point3d p1, Point3d p2, int axis)
          Calculate the interpolation factor for point p by projecting it along an axis (x,y,z) onto the edge between p1 and p2.
(package private)  double[] getInterpWeights()
           
(package private)  PickResult getPickResult()
          Gets the PickResult this intersection is part of
 Color4f getPointColor()
          Returns the color of the intersection point.
 Point3d getPointCoordinates()
          Returns the coordinates of the intersection point (local coordinates), if available.
 Point3d getPointCoordinatesVW()
          Returns the coordinates of the intersection point (world coordinates), if available.
 Vector3f getPointNormal()
          Returns the normal of the intersection point.
 TexCoord3f getPointTextureCoordinate(int index)
          Returns the texture coordinate of the intersection point at the specifed index in the specified texture coordinate set.
 int[] getPrimitiveColorIndices()
          Get the color indices for the intersected primitive.
 Color4f[] getPrimitiveColors()
          Get the colors of the intersected primitive.
 int[] getPrimitiveCoordinateIndices()
          Get the coordinates indices for the intersected primitive.
 Point3d[] getPrimitiveCoordinates()
          Get the local coordinates intersected primitive
 Point3d[] getPrimitiveCoordinatesVW()
          Get VWorld coordinates of the intersected primitive
 int[] getPrimitiveNormalIndices()
          Get the normal indices for the intersected primitive.
 Vector3f[] getPrimitiveNormals()
          Get the normals of the intersected primitive.
 int[] getPrimitiveTexCoordIndices(int index)
          Get the texture coordinate indices for the intersected primitive at the specifed index in the specified texture coordinate set.
 TexCoord3f[] getPrimitiveTexCoords(int index)
          Get the texture coordinates of the intersected primitive at the specifed index in the specified texture coordinate set.
 int[] getPrimitiveVertexIndices()
          Get vertex indices of the intersected primitive
(package private)  boolean interpTriangle(int index0, int index1, int index2, Point3d[] coords, Point3d intPt)
           
(package private)  int maxAxis(Vector3d delta)
           
(package private)  void setDistance(double dist)
          Set the distance to intersection point
(package private)  void setGeomIndex(int gi)
          Sets the geom index into the pick result
(package private)  void setPointCoordinatesVW(Point3d pt)
          Sets the coordinates of the intersection point (world coordinates).
(package private)  void setPrimitiveCoordinatesVW(Point3d[] coords)
          Set VWorld coordinates of the picked primtive
(package private)  void setVertexIndices(int[] verts)
          Set vertex indices of primitive's vertices
(package private)  void storeClosestVertex()
          Calculates and stores the closest vertex information
 java.lang.String toString()
          String representation of this object
(package private)  java.lang.String toString2()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pickResult

PickResult pickResult
PickResult for intersection is part of


distance

double distance
Distance between start point and intersection point (see comment above)


geomIndex

int geomIndex
index of GeometryArray in PickResult


primitiveVertexIndices

int[] primitiveVertexIndices
Indices of the intersected primitive


primitiveCoordinatesVW

Point3d[] primitiveCoordinatesVW
VWorld coordinates of intersected primitive


pointCoordinatesVW

Point3d pointCoordinatesVW
VWorld Coordinates of the intersection point


geom

GeometryArray geom

iGeom

IndexedGeometryArray iGeom

hasNormals

boolean hasNormals

hasColors

boolean hasColors

hasTexCoords

boolean hasTexCoords

primitiveCoordinateIndices

int[] primitiveCoordinateIndices

primitiveNormalIndices

int[] primitiveNormalIndices

primitiveColorIndices

int[] primitiveColorIndices

primitiveTexCoordIndices

int[] primitiveTexCoordIndices

primitiveCoordinates

Point3d[] primitiveCoordinates

primitiveNormals

Vector3f[] primitiveNormals

primitiveColors

Color4f[] primitiveColors

primitiveTexCoords

TexCoord3f[] primitiveTexCoords

pointCoordinates

Point3d pointCoordinates
Local Coordinates of the intersection point


pointNormal

Vector3f pointNormal
Normal at the intersection point


pointColor

Color4f pointColor
Color at the intersection point


pointTexCoord

TexCoord3f pointTexCoord
TexCoord at the intersection point


closestVertexIndex

int closestVertexIndex
Index of the closest vertex


closestVertexCoordinates

Point3d closestVertexCoordinates
Coordinates of the closest vertex


closestVertexCoordinatesVW

Point3d closestVertexCoordinatesVW
Coordinates of the closest vertex (World coordinates)


interpWeights

double[] interpWeights
Weight factors for interpolation, values correspond to vertex indices, sum == 1


debug

static final boolean debug
See Also:
Constant Field Values

X_AXIS

static final int X_AXIS
See Also:
Constant Field Values

Y_AXIS

static final int Y_AXIS
See Also:
Constant Field Values

Z_AXIS

static final int Z_AXIS
See Also:
Constant Field Values

TOL

static final double TOL
See Also:
Constant Field Values
Constructor Detail

PickIntersection

PickIntersection(PickResult pr,
                 GeometryArray geomArr)
Constructor

Parameters:
pickResult - The pickResult this intersection is part of.
Method Detail

toString

public java.lang.String toString()
String representation of this object

Overrides:
toString in class java.lang.Object

toString2

java.lang.String toString2()

getPickResult

PickResult getPickResult()
Gets the PickResult this intersection is part of


setGeomIndex

void setGeomIndex(int gi)
Sets the geom index into the pick result


setPointCoordinatesVW

void setPointCoordinatesVW(Point3d pt)
Sets the coordinates of the intersection point (world coordinates).

Parameters:
pt - the coordinates

getPointCoordinatesVW

public Point3d getPointCoordinatesVW()
Returns the coordinates of the intersection point (world coordinates), if available.

Returns:
coordinates of the point

getDistance

public double getDistance()
Get the distance from the PickShape start point to the intersection point

Returns:
the distance to the intersection point, if available.

setDistance

void setDistance(double dist)
Set the distance to intersection point

Parameters:
dist - the distance to the intersection point

setPrimitiveCoordinatesVW

void setPrimitiveCoordinatesVW(Point3d[] coords)
Set VWorld coordinates of the picked primtive

Parameters:
coords -

getPrimitiveCoordinatesVW

public Point3d[] getPrimitiveCoordinatesVW()
Get VWorld coordinates of the intersected primitive

Returns:
an array of Point3d's for the primitive that was picked

setVertexIndices

void setVertexIndices(int[] verts)
Set vertex indices of primitive's vertices

Parameters:
verts - array of coordinate indices

getPrimitiveVertexIndices

public int[] getPrimitiveVertexIndices()
Get vertex indices of the intersected primitive

Returns:
an array which contains the list of indices

getGeometryArrayIndex

public int getGeometryArrayIndex()
Returns the index of the intersected GeometryArray into the geometry arrays in the PickResult


getGeometryArray

public GeometryArray getGeometryArray()
Returns the GeometryArray for the intersection


geometryIsIndexed

public boolean geometryIsIndexed()
Returns true if the geometry is indexed


getClosestVertexCoordinates

public Point3d getClosestVertexCoordinates()
Get coordinates of closest vertex (local)

Returns:
the coordinates of the vertex closest to the intersection point

getClosestVertexCoordinatesVW

public Point3d getClosestVertexCoordinatesVW()
Get coordinates of closest vertex (world)

Returns:
the coordinates of the vertex closest to the intersection point

getClosestVertexIndex

public int getClosestVertexIndex()
Get index of closest vertex

Returns:
the index of the closest vertex

storeClosestVertex

void storeClosestVertex()
Calculates and stores the closest vertex information


getPrimitiveCoordinateIndices

public int[] getPrimitiveCoordinateIndices()
Get the coordinates indices for the intersected primitive. For a non-indexed primitive, this will be the same as the primitive vertex indices

Returns:
an array indices

getPrimitiveCoordinates

public Point3d[] getPrimitiveCoordinates()
Get the local coordinates intersected primitive

Returns:
an array of Point3d's for the primitive that was intersected

getInterleavedVertexOffset

int getInterleavedVertexOffset(GeometryArray geo)

getInterleavedStride

int getInterleavedStride(GeometryArray geo)

getInterleavedColorOffset

int getInterleavedColorOffset(GeometryArray geo)

getInterleavedNormalOffset

int getInterleavedNormalOffset(GeometryArray geo)

getPrimitiveNormalIndices

public int[] getPrimitiveNormalIndices()
Get the normal indices for the intersected primitive. For a non-indexed primitive, this will be the same as the primitive vertex indices If the geometry array does not contain normals this will return null

Returns:
an array indices

getPrimitiveNormals

public Vector3f[] getPrimitiveNormals()
Get the normals of the intersected primitive. This will return null if the primitive does not contain normals.

Returns:
an array of Point3d's for the primitive that was intersected

getPrimitiveColorIndices

public int[] getPrimitiveColorIndices()
Get the color indices for the intersected primitive. For a non-indexed primitive, this will be the same as the primitive vertex indices If the geometry array does not contain colors this will return null.

Returns:
an array indices

getPrimitiveColors

public Color4f[] getPrimitiveColors()
Get the colors of the intersected primitive. This will return null if the primitive does not contain colors. If the geometry was defined using GeometryArray.COLOR_3, the 'w' value of the color will be set to 1.0.

Returns:
an array of Point3d's for the primitive that was intersected

getPrimitiveTexCoordIndices

public int[] getPrimitiveTexCoordIndices(int index)
Get the texture coordinate indices for the intersected primitive at the specifed index in the specified texture coordinate set. For a non-indexed primitive, this will be the same as the primitive vertex indices If the geometry array does not contain texture coordinates, this will return null.

Returns:
an array indices

getPrimitiveTexCoords

public TexCoord3f[] getPrimitiveTexCoords(int index)
Get the texture coordinates of the intersected primitive at the specifed index in the specified texture coordinate set. null if the primitive does not contain texture coordinates. If the geometry was defined using GeometryArray.TEXTURE_COORDINATE_2, the 'z' value of the texture coordinate will be set to 0.0.

Returns:
an array of TexCoord3f's for the primitive that was intersected

getPointCoordinates

public Point3d getPointCoordinates()
Returns the coordinates of the intersection point (local coordinates), if available.

Returns:
coordinates of the intersection point

getPointNormal

public Vector3f getPointNormal()
Returns the normal of the intersection point. Returns null if the geometry does not contain normals.

Returns:
normal at the intersection point.

getPointColor

public Color4f getPointColor()
Returns the color of the intersection point. Returns null if the geometry does not contain colors. If the geometry was defined with GeometryArray.COLOR_3, the 'w' component of the color will initialized to 1.0

Returns:
color at the intersection point.

getPointTextureCoordinate

public TexCoord3f getPointTextureCoordinate(int index)
Returns the texture coordinate of the intersection point at the specifed index in the specified texture coordinate set. Returns null if the geometry does not contain texture coordinates. If the geometry was defined with GeometryArray.TEXTURE_COORDINATE_3, the 'z' component of the texture coordinate will initialized to 0.0

Returns:
texture coordinate at the intersection point.

abs

double abs(double value)

maxAxis

int maxAxis(Vector3d delta)

interpTriangle

boolean interpTriangle(int index0,
                       int index1,
                       int index2,
                       Point3d[] coords,
                       Point3d intPt)

getInterpWeights

double[] getInterpWeights()

getInterpFactor

private static float getInterpFactor(Point3d p,
                                     Point3d p1,
                                     Point3d p2,
                                     int axis)
Calculate the interpolation factor for point p by projecting it along an axis (x,y,z) onto the edge between p1 and p2. If the result is in the 0->1 range, point is between p1 and p2 (0 = point is at p1, 1 => point is at p2).


getInterpFactorForBase

private static float getInterpFactorForBase(Point3d p,
                                            Point3d p1,
                                            Point3d p2,
                                            int axis)
Calculate the interpolation factor for point p by projecting it along an axis (x,y,z) onto the edge between p1 and p2. If the result is in the 0->1 range, point is between p1 and p2 (0 = point is at p1, 1 => point is at p2). return MAX_VALUE if component of vertices are the same.



Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.