Defines a polygonal shape consisting of triangles. More...
#include <cadex/ModelData/IndexedTriangleSet.hxx>
Public Types | |
| typedef Geom::Point | VertexType |
| typedef Geom::Vector | NormalType |
| typedef Materials::Color | ColorType |
| typedef std::vector< VertexType > | VertexVecType |
| typedef std::vector< NormalType > | NormalVecType |
| typedef std::vector< ColorType > | ColorVecType |
| typedef std::vector< int > | IndexVecType |
Public Types inherited from cadex::BaseObject | |
| typedef std::shared_ptr< internal::BaseObjectImpl > | ImplType |
Public Member Functions | |
| IndexedTriangleSet () | |
| Constructor. | |
| bool | AddTriangles (const VertexVecType &theVertices, const IndexVecType &theVertexIndices) |
| Adds triangles. | |
| bool | AddTriangles (const VertexVecType &theVertices, const IndexVecType &theVertexIndices, const NormalVecType &theNormals, const IndexVecType &theNormalIndices) |
| Adds triangles. | |
| bool | AddTriangles (const VertexVecType &theVertices, const IndexVecType &theVertexIndices, const NormalVecType &theNormals, const IndexVecType &theNormalIndices, const ColorVecType &theColors, const IndexVecType &theColorIndices) |
| Adds triangles. | |
| bool | AddTriangles (const IndexedTriangleSet &theTriangleSet) |
| Adds triangles from theTriangleSet. | |
| IndexedTriangleSet | WithColors (const ColorVecType &theColors, const IndexVecType &theColorIndices) const |
| Returns a new IndexedTriangleSet. Vertices and Normals copies from the caller. | |
| const VertexType & | Vertex (int theIndex) const |
| Returns a vertex. | |
| size_t | NumberOfVertices () const |
| Returns a number of vertices. | |
| bool | HasNormals () const |
| Returns true if the triangle set has explicitly defined normals. | |
| const NormalType & | Normal (int theIndex) const |
| Returns a normal. | |
| size_t | NumberOfNormals () const |
| Returns a number of normals. | |
| bool | HasColors () const |
| Returns true if the triangle set has explicitly defined colors. | |
| const Materials::Color & | Color (int theIndex) const |
| Returns a color. | |
| size_t | NumberOfColors () const |
| Returns a number of colors. | |
| const VertexType & | TriangleVertex (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a vertex of a triangle. | |
| int | TriangleVertexIndex (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a vertex index in a triangle. | |
| const NormalType & | TriangleVertexNormal (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a normal at vertex in a triangle. | |
| int | TriangleVertexNormalIndex (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a normal index for vertex in a triangle. | |
| NormalType | TriangleNormal (size_t theTriangleIndex) const |
| Returns a normal of a triangle. | |
| const Materials::Color & | TriangleVertexColor (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a color at vertex in a triangle. | |
| int | TriangleVertexColorIndex (size_t theTriangleIndex, size_t theVertexSlot) const |
| Returns a color index for vertex in a triangle. | |
| size_t | NumberOfTriangles () const |
| Returns a number of triangles. | |
Public Member Functions inherited from cadex::BaseObject | |
| size_t | Id () const |
| Return unique identifier of public object. | |
| internal::BaseObjectImpl * | Impl () const |
| bool | IsNull () const |
| operator bool () const | |
| template<typename T > | |
| bool | IsOfType () const |
| template<typename T > | |
| T * | Impl () const |
| Reserved for internal use. | |
Static Public Member Functions | |
| static bool | CompareType (const BaseObject &theObject) |
Static Public Member Functions inherited from cadex::ModelData::MeshShape | |
| static bool | CompareType (const BaseObject &theObject) |
| Check the type of object. Returns true if the specified object is this class type. | |
Additional Inherited Members | |
Protected Member Functions inherited from cadex::ModelData::MeshShape | |
| MeshShape (const ImplType &theImpl) | |
Protected Member Functions inherited from cadex::BaseObject | |
| BaseObject (const ImplType &theImpl) | |
Defines a polygonal shape consisting of triangles.
Triangles are defined via array of unique vertices and triplets of indices in this array. This is to describe connectivity and to reduce data required to describe a triangle set.
The triangle set can optionally contain normals and/or colors which are defined per each vertex. Normals and colors also use indexing in the same manner as vertices.
A triangle set can be constructed using AddTriangles(), supplying unique vertices and indices describing triangles, for instance:
The user must ensure data consistency so that the number of added normals and/or colors is equal to number of added vertices. Otherwise, triangles won't be added.
Data can be queried using the rank number of triangle and a vertex slot (0 to 2), for instance:
Coordinate and normal indices into respective arrays of unique values can be queried using TriangleVertexIndex() and TriangleVertexNormalIndex() respectively.
|
inline |
Constructor.
Creates not initialized object, for which IsNull() returns true.
| bool cadex::ModelData::IndexedTriangleSet::AddTriangles | ( | const VertexVecType & | theVertices, |
| const IndexVecType & | theVertexIndices ) |
Adds triangles.
The number of values in theVertexIndices must be a multiple of three, since each triplet defines a triangle.
Returns true if the triangles were successfully added and false otherwise.
| bool cadex::ModelData::IndexedTriangleSet::AddTriangles | ( | const VertexVecType & | theVertices, |
| const IndexVecType & | theVertexIndices, | ||
| const NormalVecType & | theNormals, | ||
| const IndexVecType & | theNormalIndices ) |
Adds triangles.
The number of values in theVertexIndices and theNormalIndices must be the same and a multiple of three, since each triple defines a vertex and vertex normal of a triangle, respectively.
Returns true if the triangles were successfully added and false otherwise.
| bool cadex::ModelData::IndexedTriangleSet::AddTriangles | ( | const VertexVecType & | theVertices, |
| const IndexVecType & | theVertexIndices, | ||
| const NormalVecType & | theNormals, | ||
| const IndexVecType & | theNormalIndices, | ||
| const ColorVecType & | theColors, | ||
| const IndexVecType & | theColorIndices ) |
Adds triangles.
The number of values in theVertexIndices, theNormalIndices and theColorIndices should be the same and a multiple of three, since each triple defines a vertex, vertex normal and vertex color of a triangle, respectively. However, if there is no need to add normals, then theNormals and theNormalIndices can be empty.
Returns true if the triangles were successfully added and false otherwise.
| const Materials::Color & cadex::ModelData::IndexedTriangleSet::Color | ( | int | theIndex | ) | const |
Returns a color.
theIndex must be in the range [0, NumberOfColors()-1]. Otherwise the result is undefined.
| bool cadex::ModelData::IndexedTriangleSet::HasColors | ( | ) | const |
Returns true if the triangle set has explicitly defined colors.
| bool cadex::ModelData::IndexedTriangleSet::HasNormals | ( | ) | const |
Returns true if the triangle set has explicitly defined normals.
| const IndexedTriangleSet::NormalType & cadex::ModelData::IndexedTriangleSet::Normal | ( | int | theIndex | ) | const |
Returns a normal.
theIndex must be in the range [0, NumberOfNormals()-1]. Otherwise the result is undefined.
| IndexedTriangleSet::NormalType cadex::ModelData::IndexedTriangleSet::TriangleNormal | ( | size_t | theTriangleIndex | ) | const |
Returns a normal of a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. Otherwise the result is undefined.
The normal is calculated on the fly based on the vertices of the triangle.
In case of a degenerate triangle the zero vector will be returned.
| const IndexedTriangleSet::VertexType & cadex::ModelData::IndexedTriangleSet::TriangleVertex | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a vertex of a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. Otherwise the result is undefined. theVertexSlot must be in the range [0, 2]. Otherwise the result is undefined.
| const Materials::Color & cadex::ModelData::IndexedTriangleSet::TriangleVertexColor | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a color at vertex in a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. Otherwise the result is undefined. theVertexSlot must be in the range [0, 2]. Otherwise the result is undefined.
| int cadex::ModelData::IndexedTriangleSet::TriangleVertexColorIndex | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a color index for vertex in a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. theVertexSlot must be in the range [0, 2].
If the color index was not found -1 will be returned.
| int cadex::ModelData::IndexedTriangleSet::TriangleVertexIndex | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a vertex index in a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. theVertexSlot must be in the range [0, 2].
If the vertex index was not found -1 will be returned.
| const IndexedTriangleSet::NormalType & cadex::ModelData::IndexedTriangleSet::TriangleVertexNormal | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a normal at vertex in a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. Otherwise the result is undefined. theVertexSlot must be in the range [0, 2]. Otherwise the result is undefined.
| int cadex::ModelData::IndexedTriangleSet::TriangleVertexNormalIndex | ( | size_t | theTriangleIndex, |
| size_t | theVertexSlot ) const |
Returns a normal index for vertex in a triangle.
theTriangleIndex must be in the range [0, NumberOfTriangles()-1]. theVertexSlot must be in the range [0, 2].
If the normal index was not found -1 will be returned.
| const IndexedTriangleSet::VertexType & cadex::ModelData::IndexedTriangleSet::Vertex | ( | int | theIndex | ) | const |
Returns a vertex.
theIndex must be in the range [0, NumberOfVertices()-1]. Otherwise the result is undefined.
| IndexedTriangleSet cadex::ModelData::IndexedTriangleSet::WithColors | ( | const ColorVecType & | theColors, |
| const IndexVecType & | theColorIndices ) const |
Returns a new IndexedTriangleSet. Vertices and Normals copies from the caller.
The size of theColorIndices must be equal to the size of theVertexIndices (NumberOfTriangles() * 3). Otherwise an empty IndexedTriangleSet will be returned.