de.jreality.geometry
Class GeometryUtility

java.lang.Object
  extended by de.jreality.geometry.GeometryUtility

public class GeometryUtility
extends Object

Static methods for various geometric operations.

There are a few basic categories:

Author:
Charles Gunn and others

Field Summary
static String BOUNDING_BOX
          For setting the bounding box of the geometry; Value: Rectangle3D.
static String HEIGHT_FIELD_SHAPE
          For identifying this IndexedFaceSet as a QuadMesh with a single value at each point (z-value on a regular x-y 2D domain); Value: Rectangle2D identifies the 2D domain.
static String QUAD_MESH_SHAPE
          For identifying this IndexedFaceSet as a QuadMesh; Value: Dimension.
static String SIGNATURE
          For setting the signature (Pn) of the geometry; Value: Integer
 
Method Summary
static void calculateAndSetFaceNormals(IndexedFaceSet ifs)
           
static void calculateAndSetNormals(IndexedFaceSet ifs)
           
static void calculateAndSetVertexNormals(IndexedFaceSet ifs)
           
static Rectangle3D calculateBoundingBox(double[][] verts)
          Calculate the bounding box of the vertices verts.
static Rectangle3D calculateBoundingBox(double[] initialMatrix, SceneGraphComponent sgc)
          Calculate the bounding box assuming that the scene graph is first transformed by the matrix initialMatrix
static Rectangle3D calculateBoundingBox(PointSet ps)
           
static Rectangle3D calculateBoundingBox(SceneGraphComponent sgc)
           
static Rectangle3D calculateBoundingBox(Sphere sph)
           
static Rectangle3D calculateChildrenBoundingBox(SceneGraphComponent sgc)
          Calculate the bounding box for the scene graph tooted at sgc but do not apply the transformation, if any, attached to sgc.
static double[][] calculateFaceNormals(IndexedFaceSet ifs)
           
static double[][] calculateFaceNormals(IndexedFaceSet ifs, int signature)
           
static double[][] calculateFaceNormals(int[][] indices, double[][] verts, int signature)
          Calculate face normals for the faces defined by the index list indices and the vertex list verts, with respect to the given signature.
static void calculateFaceNormals(SceneGraphComponent c)
          Traverse a scene graph, calculating (and setting) face normals for all instances of IndexedFaceSet.
static double[][] calculateVertexNormals(IndexedFaceSet ifs)
           
static double[][] calculateVertexNormals(IndexedFaceSet ifs, int signature)
           
static double[][] calculateVertexNormals(int[][] indices, double[][] vertsAs2D, double[][] fn, int signature)
          Calculate the vertex normals of the vertices by averaging the face normals of all faces to which the vertex belongs.
static void calculateVertexNormals(SceneGraphComponent c)
          Traverse a scene graph, calculating (and setting) vertex normals for all instances of IndexedFaceSet.
static SceneGraphComponent flatten(SceneGraphComponent sgc)
           
static SceneGraphComponent flatten(SceneGraphComponent sgc, boolean rejectInvis)
          Apply transformations recursively to all instances of PointSet and produce a flat scene graph with no transformations.
static int getSignature(Geometry g)
           
static int getVectorLength(DataList ps)
          Find out the length of the first element of this DataList.
static int getVectorLength(PointSet ps)
          Find out the length of the coordinates for a single vertex of this PointSet.
static void setSignature(Geometry g, int s)
          Set the signature (Pn) associated to this geometry.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOUNDING_BOX

public static String BOUNDING_BOX
For setting the bounding box of the geometry; Value: Rectangle3D.

See Also:
Geometry#setGeometryAttributes(Attribute, Object).

QUAD_MESH_SHAPE

public static String QUAD_MESH_SHAPE
For identifying this IndexedFaceSet as a QuadMesh; Value: Dimension.

See Also:
Geometry#setGeometryAttributes(Attribute, Object)., QuadMeshFactory

HEIGHT_FIELD_SHAPE

public static String HEIGHT_FIELD_SHAPE
For identifying this IndexedFaceSet as a QuadMesh with a single value at each point (z-value on a regular x-y 2D domain); Value: Rectangle2D identifies the 2D domain.

See Also:
Geometry#setGeometryAttributes(Attribute, Object)., HeightFieldFactory

SIGNATURE

public static String SIGNATURE
For setting the signature (Pn) of the geometry; Value: Integer

See Also:
Geometry#setGeometryAttributes(Attribute, Object).
Method Detail

calculateAndSetFaceNormals

public static void calculateAndSetFaceNormals(IndexedFaceSet ifs)

calculateAndSetNormals

public static void calculateAndSetNormals(IndexedFaceSet ifs)

calculateAndSetVertexNormals

public static void calculateAndSetVertexNormals(IndexedFaceSet ifs)

calculateBoundingBox

public static Rectangle3D calculateBoundingBox(double[] initialMatrix,
                                               SceneGraphComponent sgc)
Calculate the bounding box assuming that the scene graph is first transformed by the matrix initialMatrix

Parameters:
tmp -
sgc -
Returns:

calculateBoundingBox

public static Rectangle3D calculateBoundingBox(double[][] verts)
Calculate the bounding box of the vertices verts. These may be 3- or 4-d points.

Parameters:
verts -
Returns:
Pn for details.

calculateBoundingBox

public static Rectangle3D calculateBoundingBox(PointSet ps)

calculateBoundingBox

public static Rectangle3D calculateBoundingBox(SceneGraphComponent sgc)

calculateBoundingBox

public static Rectangle3D calculateBoundingBox(Sphere sph)

calculateChildrenBoundingBox

public static Rectangle3D calculateChildrenBoundingBox(SceneGraphComponent sgc)
Calculate the bounding box for the scene graph tooted at sgc but do not apply the transformation, if any, attached to sgc.

Parameters:
sgc -
Returns:

calculateFaceNormals

public static double[][] calculateFaceNormals(IndexedFaceSet ifs)

calculateFaceNormals

public static double[][] calculateFaceNormals(IndexedFaceSet ifs,
                                              int signature)

calculateFaceNormals

public static double[][] calculateFaceNormals(int[][] indices,
                                              double[][] verts,
                                              int signature)
Calculate face normals for the faces defined by the index list indices and the vertex list verts, with respect to the given signature. The method attempts to skip over degenerate vertices (in the euclidean case only currently!), but otherwise assumes the faces are planar.

Parameters:
indices -
verts -
signature -
Returns:

calculateFaceNormals

public static void calculateFaceNormals(SceneGraphComponent c)
Traverse a scene graph, calculating (and setting) face normals for all instances of IndexedFaceSet. If face normals are already present, they are not calculated again. The setting has to take place after the traversal due to locking considerations.

Parameters:
c -

calculateVertexNormals

public static double[][] calculateVertexNormals(IndexedFaceSet ifs)

calculateVertexNormals

public static double[][] calculateVertexNormals(IndexedFaceSet ifs,
                                                int signature)

calculateVertexNormals

public static double[][] calculateVertexNormals(int[][] indices,
                                                double[][] vertsAs2D,
                                                double[][] fn,
                                                int signature)
Calculate the vertex normals of the vertices by averaging the face normals of all faces to which the vertex belongs.

Note: This method currently does not correctly average vertices lying on the boundary of a closed quad mesh.

Parameters:
indices -
vertsAs2D -
fn -
signature -
Returns:

calculateVertexNormals

public static void calculateVertexNormals(SceneGraphComponent c)
Traverse a scene graph, calculating (and setting) vertex normals for all instances of IndexedFaceSet. If vertex normals are already present, they are not calculated again. The setting has to take place after the traversal due to locking considerations.

Parameters:
c -

flatten

public static SceneGraphComponent flatten(SceneGraphComponent sgc)

flatten

public static SceneGraphComponent flatten(SceneGraphComponent sgc,
                                          boolean rejectInvis)
Apply transformations recursively to all instances of PointSet and produce a flat scene graph with no transformations. It collects these instances, and transforms them into world coordinates. All these instances are put into one parent, and this parent is returned. Geometry that is not PointSet is simply ignored. Attributes are copied as much as possible, normals are also transformed. The code is not robust.

Parameters:
sgc -
rejectInvis - if true, non-visible scene graph components are skipped (default: false)
Returns:

getSignature

public static int getSignature(Geometry g)

getVectorLength

public static int getVectorLength(DataList ps)
Find out the length of the first element of this DataList.

Parameters:
ps -
Returns:

getVectorLength

public static int getVectorLength(PointSet ps)
Find out the length of the coordinates for a single vertex of this PointSet.

Parameters:
ps -
Returns:

setSignature

public static void setSignature(Geometry g,
                                int s)
Set the signature (Pn) associated to this geometry.

Parameters:
g -
s -