chai3d::cSegmentArray Class Reference

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

#include <CSegmentArray.h>

Inheritance diagram for chai3d::cSegmentArray:

Public Member Functions

 cSegmentArray (cVertexArrayPtr a_vertexArray)
 
 ~cSegmentArray ()
 
void clear ()
 This method clears all segments from array. More...
 
virtual unsigned int getNumVerticesPerElement ()
 This method returns the number of vertices that compose a segment. More...
 
cSegmentArrayPtr copy ()
 This method create a copy of all segment data and returns a new segment array. More...
 
void compress ()
 This method compresses the array by removing non used segments. More...
 
int newSegment (const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1)
 
void removeSegment (const unsigned int a_segmentIndex)
 
void setVertices (const unsigned int a_segmentIndex, const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1)
 
unsigned int getVertexIndex0 (const unsigned int a_segmentIndex) const
 
unsigned int getVertexIndex1 (const unsigned int a_segmentIndex) const
 
virtual unsigned int getVertexIndex (const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const
 
cVector3d getTexCoordAtPosition (const unsigned int a_segmentIndex, const cVector3d &a_localPos)
 
void render ()
 
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 segment from this array. More...
 
- 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)
 

Static Public Member Functions

static cSegmentArrayPtr create (cVertexArrayPtr a_vertexArray)
 Shared cSegmentArray 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

This class defines an array of segments each composed of two vertices.
A segment array is created by first passing a reference to an array of vertices (cVertexArray) from which the segments are composed.
Every segment is described by a set of two vertex indices. The indices point to the vertices that describe the segment.
For graphic rendering purposes and memory efficiency, segments are stored in large arrays. The number of allocated segments in an array can be retrieved by call getNumElements().
New segments can be added or removed by calling newSegment() and removeSegment(). respectively.
When a segment is removed from the array, the vertex indices are set to zero and the segment index number is added to a list of free segments for future allocation. Segments are therefore never removed from memory, but become a point until they are converted to an active segment again.
To avoid accumulating large numbers of free segments, it is possible to compress the array by calling compress(). This method removes all non used segments from memory.

Constructor & Destructor Documentation

chai3d::cSegmentArray::cSegmentArray ( cVertexArrayPtr  a_vertexArray)
inline

Constructor of cSegmentArray.

Parameters
a_vertexArrayArray of vertices used to describe the segments.
chai3d::cSegmentArray::~cSegmentArray ( )
inline

Destructor of cSegmentArray.

Member Function Documentation

void chai3d::cSegmentArray::clear ( )
inlinevirtual

Reimplemented from chai3d::cGenericArray.

static cSegmentArrayPtr chai3d::cSegmentArray::create ( cVertexArrayPtr  a_vertexArray)
inlinestatic
virtual unsigned int chai3d::cSegmentArray::getNumVerticesPerElement ( )
inlinevirtual

Reimplemented from chai3d::cGenericArray.

cSegmentArrayPtr chai3d::cSegmentArray::copy ( )

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

Returns
New segment array.
void chai3d::cSegmentArray::compress ( )

This method compresses the segment array by removing all non allocated segments. If many segments 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 segments that no longer exist.

int chai3d::cSegmentArray::newSegment ( const unsigned int  a_vertexIndex0,
const unsigned int  a_vertexIndex1 
)
inline

This method creates a new segment.

Parameters
a_vertexIndex0index of vertex 0.
a_vertexIndex1index of vertex 1.
Returns
Index number of new segment.
void chai3d::cSegmentArray::removeSegment ( const unsigned int  a_segmentIndex)
inline

This method deallocates a selected segment from the array. The two vertex indices of the segment are set to zero, and the segment is added to the free list for future allocation.

Parameters
a_segmentIndexIndex number of selected segment.
void chai3d::cSegmentArray::setVertices ( const unsigned int  a_segmentIndex,
const unsigned int  a_vertexIndex0,
const unsigned int  a_vertexIndex1 
)
inline

This method sets the vertices of a selected segment by passing their index numbers.

Parameters
a_segmentIndexIndex of selected segment.
a_vertexIndex0Index of vertex 0.
a_vertexIndex1Index of vertex 1.
unsigned int chai3d::cSegmentArray::getVertexIndex0 ( const unsigned int  a_segmentIndex) const
inline

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

Parameters
a_segmentIndexIndex of segment.
Returns
Index to vertex 0.
unsigned int chai3d::cSegmentArray::getVertexIndex1 ( const unsigned int  a_segmentIndex) const
inline

This method returns index of vertex 1 of a selected segment.

Parameters
a_segmentIndexIndex of selected segment.
Returns
Index to vertex 1.
virtual unsigned int chai3d::cSegmentArray::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 segment. In the case of a segment a_vertexNumber takes either 0 or 1.

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

Reimplemented from chai3d::cGenericArray.

cVector3d chai3d::cSegmentArray::getTexCoordAtPosition ( const unsigned int  a_segmentIndex,
const cVector3d a_localPos 
)
inline

This method returns the texture coordinate at the nearest point on the segment from a location passed as argument.

Parameters
a_segmentIndexIndex number of selected segment.
a_localPosLocal point along the segment.
Returns
Interpolated texture coordinate at desired location.
void chai3d::cSegmentArray::render ( )
inlinevirtual

This method renders the OpenGL vertex buffer object.

Reimplemented from chai3d::cGenericArray.

bool chai3d::cSegmentArray::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 segment from this array.
If a collision occurs, the collision point is reported through the collision recorder.

Parameters
a_elementIndexSegment 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 detection settings.
Returns
true if a collision occurred, otherwise false.

Reimplemented from chai3d::cGenericArray.


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