hmi.graphics.geometry
Class Polygon

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

public class Polygon
extends Object

A utility class for operations on polygons, like triangulation.


Field Summary
private  int[] index
           
private  int[] indices
           
private static Logger logger
           
private  float nx
           
private  float ny
           
private  float nz
           
private  int vCount
           
private  float[] vertexCoords
           
private  int vertexOffset
           
private  int vertexStride
           
 
Constructor Summary
Polygon()
          creates an empty/uninitialzed polgon object
Polygon(float[] vertexCoords, int vertexStride, int[] indices)
           
 
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;
 float getArea()
           
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)
           
 void setVertexData(float[] vertexCoords, int vertexStride, int[] indices)
           
 void setVertices(int indexOffset, int vCount)
          assumes that setVertices has been called before,
private  boolean toLeft(int pi, int qi, int ri)
           
 String toString()
          Returns a String representation for debugging purposes
 int triangulate(int[] triangles, int triangleOffset)
          turn 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

indices

private int[] indices

vertexStride

private int vertexStride

vertexOffset

private int vertexOffset

index

private int[] index

vCount

private int vCount

nx

private float nx

ny

private float ny

nz

private float nz

logger

private static Logger logger
Constructor Detail

Polygon

public Polygon()
creates an empty/uninitialzed polgon object


Polygon

public Polygon(float[] vertexCoords,
               int vertexStride,
               int[] indices)
Method Detail

setVertexData

public void setVertexData(float[] vertexCoords,
                          int vertexStride,
                          int[] indices)

setVertices

public void setVertices(int indexOffset,
                        int vCount)
assumes that setVertices has been called before,


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.


getArea

public float getArea()

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;


triangulate

public int triangulate(int[] triangles,
                       int triangleOffset)
turn 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