hmi.graphics.geometry
Class Triangulator

java.lang.Object
  extended by hmi.graphics.geometry.Triangulator

public class Triangulator
extends Object

A utility class for operations on polygons, like triangulation.


Field Summary
private static Logger logger
           
private  float nx
           
private  float ny
           
private  float nz
           
private  int[] polyIndex
           
private  int polyVCount
           
private  float[] vertexCoords
           
private  int vertexOffset
           
private  int vertexStride
           
 
Constructor Summary
Triangulator()
          Creates a new Triangulator object, specifying vertex coordinates, vertex indices, and polygon vertex counts.
 
Method Summary
private  void calcNormal()
          calculates the normal vector for a polygon representing its surface area and orientation.
private  void delete(int pi)
          remove polgon vertex nr pi, within the rangle 0 .. vCount-1;
private  boolean insideTriangle(int pi0, int pi1, int pi2, int q)
           
 boolean isEar(int pi)
          check whether the pi-1 mod vCount, pi, pi+1 mod vCount triangle forms an ear: left turn, and no other polgon point inside (or on the border of) the triangle.
private  int next(int p)
           
private  int prev(int p)
           
private  boolean toLeft(int pi, int qi, int ri)
           
 String toString()
          Returns a String representation for debugging purposes
 int[] triangulate(float[] vertexCoords, int vertexStride, int[] indices, int[] vCounts)
          triangulates the polygons of this Triangulator object, and returns the result in a new index array.
private  int triangulatePolygon(int[] triangles, int triangleOffset)
          turn a single polygon into triangles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertexCoords

private float[] vertexCoords

vertexStride

private int vertexStride

vertexOffset

private int vertexOffset

polyIndex

private int[] polyIndex

polyVCount

private int polyVCount

nx

private float nx

ny

private float ny

nz

private float nz

logger

private static Logger logger
Constructor Detail

Triangulator

public Triangulator()
Creates a new Triangulator object, specifying vertex coordinates, vertex indices, and polygon vertex counts. Vertex coordinates are stored inside vertexCoords, by means of three consecutive floats. Indices refer to these vertices: index i refers to a vertex starting at position i * vertexStride. Each element of vCounts defines the size of a polygon. The indices of each of these polygons are assumed to be stored consecutively in the indices array.

Method Detail

triangulate

public int[] triangulate(float[] vertexCoords,
                         int vertexStride,
                         int[] indices,
                         int[] vCounts)
triangulates the polygons of this Triangulator object, and returns the result in a new index array.


calcNormal

private void calcNormal()
calculates the normal vector for a polygon representing its surface area and orientation. The polygon vertices are allocated as floats within the vertices array; three consecutive floats represent one vertex. The offsets for the polygon vertices within the vertices array are provided within a set of indices, stored within the indices array. It is assumed that these indices are stored consecutively, starting at indexOffset, and that the number of vertices (therefore the number of indices) is specified by vCount.


toLeft

private boolean toLeft(int pi,
                       int qi,
                       int ri)

insideTriangle

private boolean insideTriangle(int pi0,
                               int pi1,
                               int pi2,
                               int q)

isEar

public boolean isEar(int pi)
check whether the pi-1 mod vCount, pi, pi+1 mod vCount triangle forms an ear: left turn, and no other polgon point inside (or on the border of) the triangle.


prev

private int prev(int p)

next

private int next(int p)

delete

private void delete(int pi)
remove polgon vertex nr pi, within the rangle 0 .. vCount-1;


triangulatePolygon

private int triangulatePolygon(int[] triangles,
                               int triangleOffset)
turn a single polygon into triangles. The vertex coordinate data still resides in the vertexCoord datat array used by this polygon; This method requires an initialized int array, plus an offset into that array. The triangles will be added to this array, starting at the position denoted by offset, in the form of indices. The total number of triangles is returned.


toString

public String toString()
Returns a String representation for debugging purposes

Overrides:
toString in class Object