de.jreality.geometry
Class IndexedFaceSetUtility

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

public class IndexedFaceSetUtility
extends Object

Static methods for editing and processing instances of IndexedFaceSet.

Author:
Charles Gunn and others

Method Summary
static void assignSmoothVertexNormals(IndexedFaceSet ifs, double maxAngle, int digits)
          Averages the vertex normals for duplicate coordinates.
static void assignSmoothVertexNormals(IndexedFaceSet ifs, int digits)
          Averages the vertex normals for duplicate coordinates.
static void assignVertexTangents(IndexedFaceSet ifs)
           
static IndexedFaceSet binaryRefine(IndexedFaceSet ifs)
          Only applicable for ifs all of whose faces are triangles; then each triangle is broken into four smaller triangles by bisecting the edges.
static void calculateAndSetEdgesFromFaces(IndexedFaceSet ifs)
           
static void calculateAndSetFaceNormals(IndexedFaceSet ifs)
           
static void calculateAndSetFaceNormals(IndexedFaceSet ifs, int metric)
           
static void calculateAndSetNormals(IndexedFaceSet ifs)
           
static void calculateAndSetVertexNormals(IndexedFaceSet ifs)
           
static double[][] calculateFaceNormals(IndexedFaceSet ifs)
           
static double[][] calculateFaceNormals(IndexedFaceSet ifs, int metric)
           
static double[][] calculateFaceNormals(int[][] indices, double[][] verts, int metric)
          Calculate face normals for the faces defined by the index list indices and the vertex list verts, with respect to the given metric.
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 metric)
           
static double[][] calculateVertexNormals(int[][] indices, double[][] vertsAs2D, double[][] fn, int metric)
          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 double[][] calculateVertexTangents(DoubleArrayArray texCoords, DoubleArrayArray vertexCoordinates, DoubleArrayArray vertexNormals, IntArrayArray faceIndices)
          calculates face tangents, converted from http://www.terathon.com/code/tangent.php
static IndexedFaceSet constructPolygon(double[][] points)
          A simple constructor for an IndexedFaceSet with a single face.
static IndexedFaceSet constructPolygon(IndexedFaceSet ifs, double[][] points)
          A simple constructor for an IndexedFaceSet with a single face.
static IndexedFaceSet constructPolygon(IndexedFaceSet ifs, double[][] points, int sig)
           
static SceneGraphComponent displayFaceNormals(IndexedFaceSet ifs, double scale, int metric)
          Generates an instance of IndexedLineSet which contains one line segment for each face normal of the input ifs.
static IntArrayArray edgesFromFaces(int[][] faces)
           
static IntArrayArray edgesFromFaces(IntArrayArray faces)
          TODO optimize in case its a QuadMesh (u+v curves instead of u*v segments)
static double[][] extractEdge(double[][] curve, IndexedFaceSet ifs, int which)
          Deprecated. Use IndexedLineSetUtility.extractCurve(double[][], IndexedLineSet, int).
static IndexedFaceSet extractFace(IndexedFaceSet ifs, int which)
           
static IndexedFaceSet implode(IndexedFaceSet ifs, double factor)
          For each face of ifs, replace it with a face gotten by: if factor > 0: a shrunken version of the face (factor == 1 gives original face), or if factor < 0: a hole is cut out of the face, corresponding to the shrunken version with the same absolute value.
static boolean makeConsistentOrientation(IndexedFaceSet ifs)
          makes a consistent orientated version of the "face Indices" if possible.
static IndexedFaceSet removeTextureCoordinateJumps(IndexedFaceSet src, double jumpSize)
          A special purpose code for the Buddy-Baer project which might be useful for other situations where texture coordinates wrap around.
static IndexedFaceSet representAsSceneGraph(IndexedFaceSet exists, Rectangle3D box)
          Update the vertices of an existing IFS to match the state of box.
static IndexedFaceSet representAsSceneGraph(Rectangle3D box)
          Represent an instance of Rectangle3D as an instance of IndexedFaceSet.
static void simpleTriangulate(IndexedFaceSet ifs)
          Do a simple (dumb) triangulation of the indexed face set Edit the input IFS; if you want a copy, make it before calling this method.
static IndexedFaceSet[] splitIfsToPrimitiveFaces(IndexedFaceSet ifs)
           
static IndexedFaceSet triangulate(IndexedFaceSet fs)
          Deprecated. This mehtod may lead to an infinite loop. Use with care, or use the simpler method simpleTriangulate(IndexedFaceSet).
static void triangulateBarycentric(IndexedFaceSet ifs)
           
static IndexedFaceSet triangulateRectangularPatch(double[][][] levels)
          Generates a triangulated sphere from a given set of equally spaced longitude (theta) circles.
static IndexedFaceSet truncate(IndexedFaceSet ifs)
          Truncate the corners of each face of ifs.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

binaryRefine

public static IndexedFaceSet binaryRefine(IndexedFaceSet ifs)
Only applicable for ifs all of whose faces are triangles; then each triangle is broken into four smaller triangles by bisecting the edges.

Parameters:
ifs -
Returns:

calculateAndSetEdgesFromFaces

public static void calculateAndSetEdgesFromFaces(IndexedFaceSet ifs)

constructPolygon

public static IndexedFaceSet constructPolygon(double[][] points)
A simple constructor for an IndexedFaceSet with a single face.

Parameters:
points -
Returns:

constructPolygon

public static IndexedFaceSet constructPolygon(IndexedFaceSet ifs,
                                              double[][] points)
A simple constructor for an IndexedFaceSet with a single face. Currently the argument exists is not used.

Parameters:
ifs -
points -
Returns:

constructPolygon

public static IndexedFaceSet constructPolygon(IndexedFaceSet ifs,
                                              double[][] points,
                                              int sig)

edgesFromFaces

public static IntArrayArray edgesFromFaces(int[][] faces)

edgesFromFaces

public static IntArrayArray edgesFromFaces(IntArrayArray faces)
TODO optimize in case its a QuadMesh (u+v curves instead of u*v segments)

Parameters:
faces -
Returns:

extractEdge

public static double[][] extractEdge(double[][] curve,
                                     IndexedFaceSet ifs,
                                     int which)
Deprecated. Use IndexedLineSetUtility.extractCurve(double[][], IndexedLineSet, int).

Extract the which edge from the edge list of ifs. In case the latter is a generic IndexedFaceSet, then this will consist of two points. But if it is marked as a quad mesh (see GeometryUtility.QUAD_MESH_SHAPE), then this will correspond to a u- or v- parameter curve.

Parameters:
curve -
ifs -
which -
Returns:

extractFace

public static IndexedFaceSet extractFace(IndexedFaceSet ifs,
                                         int which)

implode

public static IndexedFaceSet implode(IndexedFaceSet ifs,
                                     double factor)
For each face of ifs, replace it with a face gotten by:

Parameters:
ifs -
factor -
Returns:

removeTextureCoordinateJumps

public static IndexedFaceSet removeTextureCoordinateJumps(IndexedFaceSet src,
                                                          double jumpSize)
A special purpose code for the Buddy-Baer project which might be useful for other situations where texture coordinates wrap around.

Parameters:
src -
jumpSize -
Returns:

representAsSceneGraph

public static IndexedFaceSet representAsSceneGraph(IndexedFaceSet exists,
                                                   Rectangle3D box)
Update the vertices of an existing IFS to match the state of box.

Parameters:
exists -
box -
Returns:

representAsSceneGraph

public static IndexedFaceSet representAsSceneGraph(Rectangle3D box)
Represent an instance of Rectangle3D as an instance of IndexedFaceSet.

Parameters:
box -
Returns:

splitIfsToPrimitiveFaces

public static IndexedFaceSet[] splitIfsToPrimitiveFaces(IndexedFaceSet ifs)
Parameters:
ifs -
Returns:

triangulate

@Deprecated
public static IndexedFaceSet triangulate(IndexedFaceSet fs)
Deprecated. This mehtod may lead to an infinite loop. Use with care, or use the simpler method simpleTriangulate(IndexedFaceSet).

This mehtod assumes that the faces in the given IndexedFaceSet are planar embedded polygons. They need not be convex. Moreover it assumes that the facenormals are set. This method is not R4 safe at the moment.

Parameters:
fs -
Returns:

simpleTriangulate

public static void simpleTriangulate(IndexedFaceSet ifs)
Do a simple (dumb) triangulation of the indexed face set Edit the input IFS; if you want a copy, make it before calling this method.

Parameters:
ifs -

truncate

public static IndexedFaceSet truncate(IndexedFaceSet ifs)
Truncate the corners of each face of ifs.

Parameters:
ifs -
Returns:

assignVertexTangents

public static void assignVertexTangents(IndexedFaceSet ifs)

calculateVertexTangents

public static double[][] calculateVertexTangents(DoubleArrayArray texCoords,
                                                 DoubleArrayArray vertexCoordinates,
                                                 DoubleArrayArray vertexNormals,
                                                 IntArrayArray faceIndices)
calculates face tangents, converted from http://www.terathon.com/code/tangent.php

Parameters:
texCoords -
vertexCoordinates -
vertexNormals -
faceIndices -
Returns:
a double[verts.length][4] array containing the face tangents and the orienation (sign of 4th coordinate).

assignSmoothVertexNormals

public static void assignSmoothVertexNormals(IndexedFaceSet ifs,
                                             double maxAngle,
                                             int digits)
Averages the vertex normals for duplicate coordinates. If one normal is antipodal to another, the average is calculated with the antipodal one flipped, and the result is then flipped back again.

Parameters:
ifs - the IndexedFaceSet to change
maxAngle - the maximum angle in degrees between two normals for being flipped
digits - the number of digits to respect for comparing coordinates

assignSmoothVertexNormals

public static void assignSmoothVertexNormals(IndexedFaceSet ifs,
                                             int digits)
Averages the vertex normals for duplicate coordinates.

Parameters:
ifs -
digits -

triangulateBarycentric

public static void triangulateBarycentric(IndexedFaceSet ifs)

triangulateRectangularPatch

public static IndexedFaceSet triangulateRectangularPatch(double[][][] levels)
Generates a triangulated sphere from a given set of equally spaced longitude (theta) circles. The data for each circle (levels[i]) starts at phi=0 and ends at phi=2PI and is also equally spaced. Computes texture coordinates and smoothes vertex normals along the "cut" phi=0/2*PI. It is assumed that levels contains the following data: levels[i][j] = f(i*PI/(levels.length-1), j*2*PI/(levels[i].length-1), where f is a function of longitude and lattitude. NOTE: currently for a pole you need to give 2 points, for phi=0 and phi=2PI. TODO: move to SphereUtility


makeConsistentOrientation

public static boolean makeConsistentOrientation(IndexedFaceSet ifs)
makes a consistent orientated version of the "face Indices" if possible. if it fails, false will be returned and nothing changes.

Parameters:
numVertices -
faces -
Throws:
Exception

displayFaceNormals

public static SceneGraphComponent displayFaceNormals(IndexedFaceSet ifs,
                                                     double scale,
                                                     int metric)
Generates an instance of IndexedLineSet which contains one line segment for each face normal of the input ifs. This IndexedLineSet is then stuffed into a SceneGraphComponent whose appearance is set with tube drawing disabled, which is then returned. If normals are not provided in ifs, the metric (see Pn) metric is respected in the calculation of the normals.

Parameters:
ifs -
scale -
metric -
Returns:

calculateAndSetFaceNormals

public static void calculateAndSetFaceNormals(IndexedFaceSet ifs)

calculateAndSetFaceNormals

public static void calculateAndSetFaceNormals(IndexedFaceSet ifs,
                                              int metric)

calculateAndSetNormals

public static void calculateAndSetNormals(IndexedFaceSet ifs)

calculateAndSetVertexNormals

public static void calculateAndSetVertexNormals(IndexedFaceSet ifs)

calculateFaceNormals

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

calculateFaceNormals

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

calculateFaceNormals

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

Parameters:
indices -
verts -
metric -
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 metric)

calculateVertexNormals

public static double[][] calculateVertexNormals(int[][] indices,
                                                double[][] vertsAs2D,
                                                double[][] fn,
                                                int metric)
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 -
metric -
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 -