org.jagatoo.geometry
Class SimpleGeometryDataContainer

java.lang.Object
  extended by org.jagatoo.geometry.SimpleGeometryDataContainer
All Implemented Interfaces:
org.openmali.spatial.VertexContainer
Direct Known Subclasses:
GeometryDataContainer

public class SimpleGeometryDataContainer
extends java.lang.Object
implements org.openmali.spatial.VertexContainer

This is a simple geometry data container, that contains only coordinates and indices. This can be useful for physical data, that doesn't need or know normals, colors, texture-coordinates or vertex-attributes.


Field Summary
static int BY_REFERENCE
           
static int COORDINATES
           
protected  GeomNioFloatData coords
           
protected  long coordsOffset
           
protected  GeomNioIntData indexData
           
static int INTERLEAVED
           
protected  GeomNioFloatData interleavedData
           
protected  boolean isInterleaved
           
protected  int maxVertices
           
protected  int numIndices
           
protected  int numVertices
           
protected static boolean reversed
           
 
Constructor Summary
protected SimpleGeometryDataContainer(GeometryArrayType type, boolean hasIndex, int coordsSize, int vertexCount, int[] stripCounts, int indexCount)
           
  SimpleGeometryDataContainer(GeometryArrayType type, int coordsSize, int vertexCount)
           
  SimpleGeometryDataContainer(GeometryArrayType type, int coordsSize, int vertexCount, int indexCount)
           
  SimpleGeometryDataContainer(GeometryArrayType type, int coordsSize, int vertexCount, int[] stripCounts)
           
  SimpleGeometryDataContainer(GeometryArrayType type, int coordsSize, int vertexCount, int[] stripCounts, int indexCount)
           
 
Method Summary
protected  void checkCoordsExistence(int coordsSize)
           
protected  void copyFrom(SimpleGeometryDataContainer o, boolean forceDuplicate)
          Copies details from the given container.
protected  void createCoordinates()
           
 void getCoordinate(int vertexIndex, float[] floatArray)
           
<T extends org.openmali.vecmath2.Tuple3f>
T
getCoordinate(int index, T point)
           
 void getCoordinates(int vertexIndex, float[] floatArray)
           
 void getCoordinates(int vertexIndex, org.openmali.vecmath2.Tuple3f[] point3fArray)
           
 GeomNioFloatData getCoordinatesData()
           
 long getCoordinatesOffset()
           
 int getCoordinatesSize()
           
 float[] getCoordRefFloat()
           
 int getFaceSize()
           
 int getIndex(int i)
           
 void getIndex(int[] index)
          Gets all index values.
 int getIndexCount()
           
 GeomNioIntData getIndexData()
           
 int getInitialIndex()
           
 GeomNioFloatData getInterleavedData()
           
 int getMaxVertexCount()
           
 int getNumStrips()
           
 int[] getStripCounts()
          Gets the counts for each strip.
 void getStripCounts(int[] sCounts)
          Gets the strip counts.
 boolean getTriangle(int i0, int i1, int i2, org.openmali.spatial.polygons.Triangle triangle)
          Retrieves the the n-th Triangle from the GeometryArray.
 GeometryArrayType getType()
           
 int getValidVertexCount()
           
 boolean getVertex(int i, org.openmali.vecmath2.Tuple3f pos)
          
 int getVertexCount()
          
 boolean hasIndex()
           
 boolean isInterleaved()
           
 boolean isStrip()
           
protected  GeomNioFloatData newNioFloatData(int maxElements, int elemSize, int stride, boolean reversed)
           
protected  GeomNioIntData newNioIntData(int maxElems, int elemSize, boolean reversed)
           
 void setCoordinate(int vertexIndex, float[] floatArray)
          Sets the coordinates of the specified vertex.
 void setCoordinate(int vertexIndex, float x, float y, float z)
          Sets the coordinates of the vertex at the given index
 void setCoordinate(int vertexIndex, org.openmali.vecmath2.Tuple3f point3f)
          Sets the coordinates of the vertex at the given index
 void setCoordinateData(GeomNioFloatData data)
          Directly sets the coordinates data buffer.
 void setCoordinates(int vertexIndex, float[] floatArray)
          Sets the coordinates of the vertices starting at the specified index.
 void setCoordinates(int vertexIndex, float[] floatArray, int startIndex, int length)
          Sets the coordinates of the vertices starting at the specified index.
 void setCoordinates(int vertexIndex, java.util.List<org.openmali.vecmath2.Tuple3f> point3fList)
           
 void setCoordinates(int vertexIndex, org.openmali.vecmath2.Tuple3f[] point3fArray)
          Sets the coordinates of the vertices starting at the specified index.
 void setCoordinates(int vertexIndex, org.openmali.vecmath2.Tuple3f[] point3fArray, int startIndex, int length)
          Sets the coordinates of the vertices starting at the specified index
 void setIndex(int[] indices)
          Sets all index values.
 void setIndex(int i, int idx)
          Sets the i-th index value.
 void setInitialIndex(int initialIndex)
          Sets the index of the first vertex which will be rendered from this geometry array.
protected  void setNioBuffers()
          Sets up an NIO buffer for each type of data needed for the geometry.
 void setStripCounts(int[] stripCounts)
          Sets the counts for each strip.
 boolean setTriangle(int i0, int i1, int i2, org.openmali.spatial.polygons.Triangle triangle)
          Applies the the n-th Triangle to the GeometryArray.
 boolean setTriangle(org.openmali.spatial.polygons.Triangle triangle)
          Applies the the n-th Triangle to the GeometryArray.
 void setValidVertexCount(int count)
          Sets the number of vertices which will be rendered from this geometry array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COORDINATES

public static final int COORDINATES
See Also:
Constant Field Values

BY_REFERENCE

public static final int BY_REFERENCE
See Also:
Constant Field Values

INTERLEAVED

public static final int INTERLEAVED
See Also:
Constant Field Values

coords

protected GeomNioFloatData coords

indexData

protected GeomNioIntData indexData

interleavedData

protected GeomNioFloatData interleavedData

isInterleaved

protected boolean isInterleaved

maxVertices

protected final int maxVertices

numVertices

protected int numVertices

numIndices

protected int numIndices

coordsOffset

protected long coordsOffset

reversed

protected static final boolean reversed
See Also:
Constant Field Values
Constructor Detail

SimpleGeometryDataContainer

protected SimpleGeometryDataContainer(GeometryArrayType type,
                                      boolean hasIndex,
                                      int coordsSize,
                                      int vertexCount,
                                      int[] stripCounts,
                                      int indexCount)

SimpleGeometryDataContainer

public SimpleGeometryDataContainer(GeometryArrayType type,
                                   int coordsSize,
                                   int vertexCount)

SimpleGeometryDataContainer

public SimpleGeometryDataContainer(GeometryArrayType type,
                                   int coordsSize,
                                   int vertexCount,
                                   int indexCount)

SimpleGeometryDataContainer

public SimpleGeometryDataContainer(GeometryArrayType type,
                                   int coordsSize,
                                   int vertexCount,
                                   int[] stripCounts)

SimpleGeometryDataContainer

public SimpleGeometryDataContainer(GeometryArrayType type,
                                   int coordsSize,
                                   int vertexCount,
                                   int[] stripCounts,
                                   int indexCount)
Method Detail

getType

public final GeometryArrayType getType()
Returns:
this Geometry's basic type (used by OpenGL).

isStrip

public final boolean isStrip()
Returns:
true, if this Geometry is a Strip

getFaceSize

public final int getFaceSize()
Returns:
the number of vertices per face (3 for triangles).

getVertexCount

public final int getVertexCount()

Specified by:
getVertexCount in interface org.openmali.spatial.VertexContainer

isInterleaved

public final boolean isInterleaved()
Returns:
true, if this Geometry is constructed by interleaved data (one ByteBuffer for all data except index).

hasIndex

public final boolean hasIndex()
Returns:
true, if this Geometry has an Index.

setCoordinateData

public void setCoordinateData(GeomNioFloatData data)
Directly sets the coordinates data buffer.

Parameters:
data -

getCoordinatesData

public final GeomNioFloatData getCoordinatesData()
Returns:
the data buffer for coordinate data.

getCoordinatesSize

public final int getCoordinatesSize()
Returns:
3 for 3D-coordinates, etc.

getCoordinatesOffset

public final long getCoordinatesOffset()
Returns:
the offset in the data buffer, if this is interleaved data.

getInterleavedData

public final GeomNioFloatData getInterleavedData()
Returns:
the data buffer for interleaved data. If this Geometry is not interleaved, an error is thrown.

setInitialIndex

public void setInitialIndex(int initialIndex)
Sets the index of the first vertex which will be rendered from this geometry array. The extact vertices which will be rendered is from InitialVertexIndex to InitialVertexIndex + ValidVertexCount-1.

Parameters:
initialIndex -

getInitialIndex

public final int getInitialIndex()
Returns:
the index of the first vertex which will be rendered from this geometry array. The extact vertices which will be rendered is from InitialVertexIndex to InitialVertexIndex + ValidVertexCount-1.

setValidVertexCount

public void setValidVertexCount(int count)
Sets the number of vertices which will be rendered from this geometry array. The extact vertices which will be rendered is from InitialVertexIndex to InitialVertexIndex + ValidVertexCount-1.

Parameters:
count -

getValidVertexCount

public final int getValidVertexCount()
Returns:
the number of vertices which will be rendered from this geometry array. The extact vertices which will be rendered is from InitialVertexIndex to InitialVertexIndex + ValidVertexCount-1.

getMaxVertexCount

public final int getMaxVertexCount()
Returns:
the maximum number of vertices, this geometry can hold.

newNioFloatData

protected GeomNioFloatData newNioFloatData(int maxElements,
                                           int elemSize,
                                           int stride,
                                           boolean reversed)
Parameters:
maxElements -
elemSize -
stride -
reversed -
Returns:
a new instance

createCoordinates

protected void createCoordinates()

checkCoordsExistence

protected final void checkCoordsExistence(int coordsSize)

setCoordinate

public void setCoordinate(int vertexIndex,
                          float[] floatArray)
Sets the coordinates of the specified vertex. The coordinates should occupy the first three indices of the given array.


setCoordinate

public void setCoordinate(int vertexIndex,
                          org.openmali.vecmath2.Tuple3f point3f)
Sets the coordinates of the vertex at the given index

Parameters:
vertexIndex - The index of the vertex to modify
point3f - The new coordinates

setCoordinates

public void setCoordinates(int vertexIndex,
                           float[] floatArray,
                           int startIndex,
                           int length)
Sets the coordinates of the vertices starting at the specified index.

Parameters:
vertexIndex - The index of the first vertex to be modified.
floatArray - The new coordinates. The size of the array must be a multiple of 3.
startIndex - The index of the first coordinate in the given array. The first read item of the array will be startIndex*3.
length - The number of vertices to copy

setCoordinates

public void setCoordinates(int vertexIndex,
                           org.openmali.vecmath2.Tuple3f[] point3fArray,
                           int startIndex,
                           int length)
Sets the coordinates of the vertices starting at the specified index

Parameters:
vertexIndex - The index of the first vertex to be modified.
point3fArray - The new coordinates
startIndex - The index of the first coordinate in the given array
length - The number of coordinates to copy

setCoordinates

public void setCoordinates(int vertexIndex,
                           float[] floatArray)
Sets the coordinates of the vertices starting at the specified index.

Parameters:
vertexIndex - The index of the first vertex to modify
floatArray - The new coordinates. The size of the array must be a multiple of 3.

setCoordinates

public void setCoordinates(int vertexIndex,
                           org.openmali.vecmath2.Tuple3f[] point3fArray)
Sets the coordinates of the vertices starting at the specified index.

Parameters:
vertexIndex - The index of the first vertex to modify
point3fArray - The new coordinates.

setCoordinates

public void setCoordinates(int vertexIndex,
                           java.util.List<org.openmali.vecmath2.Tuple3f> point3fList)

setCoordinate

public void setCoordinate(int vertexIndex,
                          float x,
                          float y,
                          float z)
Sets the coordinates of the vertex at the given index

Parameters:
vertexIndex - The index of the vertex to modify
x - The new coordinates
y - The new coordinates
z - The new coordinates

getCoordinate

public void getCoordinate(int vertexIndex,
                          float[] floatArray)

getCoordinate

public <T extends org.openmali.vecmath2.Tuple3f> T getCoordinate(int index,
                                                                 T point)

getVertex

public boolean getVertex(int i,
                         org.openmali.vecmath2.Tuple3f pos)

Specified by:
getVertex in interface org.openmali.spatial.VertexContainer

getCoordinates

public void getCoordinates(int vertexIndex,
                           float[] floatArray)

getCoordinates

public void getCoordinates(int vertexIndex,
                           org.openmali.vecmath2.Tuple3f[] point3fArray)

setTriangle

public boolean setTriangle(int i0,
                           int i1,
                           int i2,
                           org.openmali.spatial.polygons.Triangle triangle)
Applies the the n-th Triangle to the GeometryArray. This method must be overridden by concrete classes to fix the vertex-index (e.g. for an IndexedTriangleArray)

Parameters:
i0 - the first triangle's vertex-index
i1 - the second triangle's vertex-index
i2 - the third triangle's vertex-index
triangle -
Returns:
true, if the triangle could be applied

setTriangle

public final boolean setTriangle(org.openmali.spatial.polygons.Triangle triangle)
Applies the the n-th Triangle to the GeometryArray. This method must be overridden by concrete classes to fix the vertex-index (e.g. for an IndexedTriangleArray)

Parameters:
triangle -
Returns:
true, if the triangle could be applied

getTriangle

public boolean getTriangle(int i0,
                           int i1,
                           int i2,
                           org.openmali.spatial.polygons.Triangle triangle)
Retrieves the the n-th Triangle from the GeometryArray. This method must be overridden by concrete classes to fix the vertex-index (e.g. for an IndexedTriangleArray)

Parameters:
i0 - the first triangle's vertex-index
i1 - the second triangle's vertex-index
i2 - the third triangle's vertex-index
triangle -
Returns:
true, if the triangle could be retrieved

getIndexCount

public final int getIndexCount()
Returns:
the number of index values. This is the number of generated/rendered vertices.

setIndex

public void setIndex(int[] indices)
Sets all index values.

Parameters:
indices -

setIndex

public void setIndex(int i,
                     int idx)
Sets the i-th index value.

Parameters:
i -
idx -

getIndex

public final void getIndex(int[] index)
Gets all index values.


getIndex

public final int getIndex(int i)
Returns:
the i-th index value.

getIndexData

public final GeomNioIntData getIndexData()
Returns:
the data buffer for the index.

getNumStrips

public final int getNumStrips()
Returns:
the number of strips.

setStripCounts

public void setStripCounts(int[] stripCounts)
Sets the counts for each strip.

Parameters:
stripCounts -

getStripCounts

public final int[] getStripCounts()
Gets the counts for each strip.


getStripCounts

public void getStripCounts(int[] sCounts)
Gets the strip counts.

Parameters:
sCounts -

getCoordRefFloat

public float[] getCoordRefFloat()

setNioBuffers

protected void setNioBuffers()
Sets up an NIO buffer for each type of data needed for the geometry.


copyFrom

protected void copyFrom(SimpleGeometryDataContainer o,
                        boolean forceDuplicate)
Copies details from the given container.

Parameters:
o -
forceDuplicate -

newNioIntData

protected GeomNioIntData newNioIntData(int maxElems,
                                       int elemSize,
                                       boolean reversed)