chai3d::cTriangleArray Class Reference

This class implements an array of 3D triangles. More...

#include <CTriangleArray.h>

Inheritance diagram for chai3d::cTriangleArray:

Public Member Functions

 cTriangleArray (cVertexArrayPtr a_vertexArray)
 
 ~cTriangleArray ()
 
void clear ()
 Clear all triangles from array. More...
 
virtual unsigned int getNumVerticesPerElement ()
 This method returns the number of vertices that compose a triangle. More...
 
cTriangleArrayPtr copy ()
 This method copies all triangle data and returns a new triangle array. More...
 
void compress ()
 This method removes all non allocated triangles. More...
 
int newTriangle (const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2)
 
void removeTriangle (const unsigned int a_triangleIndex)
 
void setVertices (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2)
 
void setVertexIndex0 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0)
 
unsigned int getVertexIndex0 (const unsigned int a_triangleIndex) const
 
void setVertexIndex1 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex1)
 
unsigned int getVertexIndex1 (const unsigned int a_triangleIndex) const
 
void setVertexIndex2 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex2)
 
unsigned int getVertexIndex2 (const unsigned int a_triangleIndex) const
 
virtual unsigned int getVertexIndex (const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const
 
cVector3d getTexCoordAtPosition (const unsigned int a_triangleIndex, const cVector3d &a_localPos)
 
void flip (const unsigned int a_triangleIndex)
 
void computeBTN ()
 
void renderInitialize ()
 
void renderFinalize ()
 
virtual bool computeCollision (const unsigned int a_elementIndex, cGenericObject *a_object, cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings) const
 This method checks if the given line segment intersects a selected triangle from this array. More...
 
double computeArea (const unsigned int a_triangleIndex)
 
cVector3d computeNormal (const unsigned int a_triangleIndex, const bool a_applyNormalToVertices)
 
- Public Member Functions inherited from chai3d::cGenericArray
 cGenericArray (cVertexArrayPtr a_vertexArray)
 
 ~cGenericArray ()
 
virtual unsigned int getNumElements ()
 This method returns the number of allocated elements. More...
 
void compress ()
 This method removes non used elements. This compresses the array. More...
 
bool getAllocated (const unsigned int a_index) const
 
cVector3d getTexCoordAtPosition (const unsigned int a_elementIndex, const cVector3d &a_localPos)
 
virtual void render ()
 This method render the OpenGL vertex buffer object. More...
 

Static Public Member Functions

static cTriangleArrayPtr create (cVertexArrayPtr a_vertexArray)
 Shared cTriangleArray allocator. More...
 
- Static Public Member Functions inherited from chai3d::cGenericArray
static cGenericArrayPtr create (cVertexArrayPtr a_vertexArray)
 Shared cGenericArray allocator. More...
 

Additional Inherited Members

- Public Attributes inherited from chai3d::cGenericArray
cVertexArrayPtr m_vertices
 Vertex array that contains all vertices used to describe the elements of this array. More...
 
std::vector< unsigned int > m_indices
 Element indices to vertices. More...
 
std::vector< bool > m_allocated
 Element allocation flags. More...
 
bool m_flagMarkForUpdate
 If true then element data has been modified. More...
 
bool m_flagMarkForResize
 If true then element array size has changed. More...
 
GLuint m_elementBuffer
 OpenGL Buffer for storing elements. More...
 
- Protected Attributes inherited from chai3d::cGenericArray
std::list< unsigned int > m_freeElements
 List of free elements. More...
 

Detailed Description

cTriangleArray defines an array of triangles, typically bound to a mesh for describing its geometry.
A triangle array is created by first passing a reference to an array of vertices (cVertexArray) from which the triangles are composed.
Every triangle is described by a set of three vertex indices. The indices point to the vertices, or points, that describe the shape of the triangle.
For graphic rendering purposes and memory efficiency, triangles are stored in large arrays. The number of allocated triangles in an array can be retrieved by call getNumElements().
New triangles can be added or removed by calling newTriangle() and removeTriangle(). respectively.
When a triangle is removed from the array, the vertex indices are set to zero and the triangle index number is added to a list of free triangles for future allocation. Triangles are therefore never removed from memory, but become a point until they are converted to an active triangle again.
To avoid accumulating large numbers of free triangles, it is possible to compress the array by calling compress(). This method removes all non used triangles from memory.

Constructor & Destructor Documentation

chai3d::cTriangleArray::cTriangleArray ( cVertexArrayPtr  a_vertexArray)
inline

Constructor of cTriangleArray.

Parameters
a_vertexArrayArray of vertices used to describe the triangles.
chai3d::cTriangleArray::~cTriangleArray ( )
inline

Destructor of cTriangleArray.

Member Function Documentation

void chai3d::cTriangleArray::clear ( )
inlinevirtual

Reimplemented from chai3d::cGenericArray.

static cTriangleArrayPtr chai3d::cTriangleArray::create ( cVertexArrayPtr  a_vertexArray)
inlinestatic
virtual unsigned int chai3d::cTriangleArray::getNumVerticesPerElement ( )
inlinevirtual

Reimplemented from chai3d::cGenericArray.

cTriangleArrayPtr chai3d::cTriangleArray::copy ( )

This method copies all allocated triangles. Please note that this method does copy triangles that were previously deallocated.

Returns
New triangle array.
void chai3d::cTriangleArray::compress ( )

This method compressed the triangle array by removing all non allocated triangles. If many triangles are unused, this method can effectively reduce the memory footprint allocated by the array.
IMPORTANT:
After calling this method, it is important to immediately update any collision detector as the collision tree may try to access triangles that no longer exist.

int chai3d::cTriangleArray::newTriangle ( const unsigned int  a_vertexIndex0,
const unsigned int  a_vertexIndex1,
const unsigned int  a_vertexIndex2 
)
inline

This method creates a new triangle.

Parameters
a_vertexIndex0index of vertex 0.
a_vertexIndex1index of vertex 1.
a_vertexIndex2index of vertex 2.
Returns
Index number of new triangle.
void chai3d::cTriangleArray::removeTriangle ( const unsigned int  a_triangleIndex)
inline

This method deallocates a selected triangle from the array. The three vertices of the triangle are set to zero, and the triangle is added to the free list for future allocation.

Parameters
a_triangleIndexIndex of selected triangle.
void chai3d::cTriangleArray::setVertices ( const unsigned int  a_triangleIndex,
const unsigned int  a_vertexIndex0,
const unsigned int  a_vertexIndex1,
const unsigned int  a_vertexIndex2 
)
inline

This method set the vertices of a selected triangle by passing their index numbers.

Parameters
a_triangleIndexIndex of selected triangle.
a_vertexIndex0Index of vertex 0.
a_vertexIndex1Index of vertex 1.
a_vertexIndex2Index of vertex 2.
void chai3d::cTriangleArray::setVertexIndex0 ( const unsigned int  a_triangleIndex,
const unsigned int  a_vertexIndex0 
)
inline

This method sets vertex 0 of a selected triangle by passing their index numbers.

Parameters
a_triangleIndexIndex of triangle.
a_vertexIndex0Index of vertex 0.
unsigned int chai3d::cTriangleArray::getVertexIndex0 ( const unsigned int  a_triangleIndex) const
inline

This method returns the index of vertex 0 of a selected triangle.

Parameters
a_triangleIndexIndex of triangle.
Returns
Index to vertex 0.
void chai3d::cTriangleArray::setVertexIndex1 ( const unsigned int  a_triangleIndex,
const unsigned int  a_vertexIndex1 
)
inline

This method sets vertex 1 of a selected triangle by passing their index numbers.

Parameters
a_triangleIndexIndex of triangle.
a_vertexIndex1Index of vertex 1.
unsigned int chai3d::cTriangleArray::getVertexIndex1 ( const unsigned int  a_triangleIndex) const
inline

This method returns the index of vertex 1 of a selected triangle.

Parameters
a_triangleIndexIndex of selected triangle.
Returns
Index to vertex 1.
void chai3d::cTriangleArray::setVertexIndex2 ( const unsigned int  a_triangleIndex,
const unsigned int  a_vertexIndex2 
)
inline

This method sets vertex 2 of a selected triangle by passing their index numbers.

Parameters
a_triangleIndexIndex of triangle.
a_vertexIndex2Index of vertex 2.
unsigned int chai3d::cTriangleArray::getVertexIndex2 ( const unsigned int  a_triangleIndex) const
inline

This method returns the index of vertex 2 of a selected triangle.

Parameters
a_triangleIndexIndex of triangle.
Returns
Index to vertex 2.
virtual unsigned int chai3d::cTriangleArray::getVertexIndex ( const unsigned int  a_elementIndex,
const unsigned int  a_vertexNumber 
) const
inlinevirtual

This method returns the index number of a selected vertex for a selected triangle. In the case of a triangle a_vertexNumber takes either 0, 1 or 2.

Parameters
a_elementIndexIndex number of selected triangle.
a_vertexNumberVertex number.
Returns
Index number of the requested vertex.

Reimplemented from chai3d::cGenericArray.

cVector3d chai3d::cTriangleArray::getTexCoordAtPosition ( const unsigned int  a_triangleIndex,
const cVector3d a_localPos 
)
inline

This method returns the texture coordinate at the nearest point on the triangle from an input location.

Parameters
a_triangleIndexIndex number of selected triangle.
a_localPosLocal point on triangle.
Returns
Interpolated texture coordinate at desired location.
void chai3d::cTriangleArray::flip ( const unsigned int  a_triangleIndex)
inline

This method flips the vertices of the triangle.

Parameters
a_triangleIndexIndex number of selected triangle.
void chai3d::cTriangleArray::computeBTN ( )
inline

This method computes the normal matrix vectors for all triangles.

void chai3d::cTriangleArray::renderInitialize ( )
inline

This method renders the OpenGL vertex buffer object.

void chai3d::cTriangleArray::renderFinalize ( )
inline

This method finalizes rendering the OpenGL vertex buffer object.

bool chai3d::cTriangleArray::computeCollision ( const unsigned int  a_elementIndex,
cGenericObject a_object,
cVector3d a_segmentPointA,
cVector3d a_segmentPointB,
cCollisionRecorder a_recorder,
cCollisionSettings a_settings 
) const
virtual

This method checks if the given line segment intersects a selected a triangle from this array.
If a collision occurs, the collision point is reported in the collision recorder.

Parameters
a_elementIndexTriangle index number.
a_objectPointer to the object on which collision detection is being performed.
a_segmentPointAPoint from where collision ray starts (in local frame).
a_segmentPointBDirection vector of collision ray (in local frame).
a_recorderStores collision events
a_settingsCollision detector settings.
Returns
true if a collision occurred, otherwise false.

Reimplemented from chai3d::cGenericArray.

double chai3d::cTriangleArray::computeArea ( const unsigned int  a_triangleIndex)
inline

This method computes and returns the area for a selected triangle.

Returns
Area for selected triangle.
cVector3d chai3d::cTriangleArray::computeNormal ( const unsigned int  a_triangleIndex,
const bool  a_applyNormalToVertices 
)
inline

This method computes the surface normal of a triangle and if requested, updates the normal of each of the three vertices.

Parameters
a_triangleIndexIndex number of selected triangle.
a_applyNormalToVerticesIf true, then update normal of each vertex.
Returns
Computed surface normal for selected triangle.

The documentation for this class was generated from the following files: