CAD Exchanger SDK
cadex::ModelData_IndexedTriangleSet Class Reference

Defines a polygonal shape consisting of triangles. More...

Inheritance diagram for cadex::ModelData_IndexedTriangleSet:
cadex::ModelData_PolyVertexSet cadex::ModelData_PolyShape cadex::ModelData_BaseObject

Public Types

typedef ModelData_Vectorf NormalType
 Defines a type of the normal vector. More...
 
typedef ModelData_Point2d UVCoordinateType
 Defines a type of the UV coordinate.
 
- Public Types inherited from cadex::ModelData_PolyVertexSet
typedef int IndexType
 Type of indices.
 
typedef cadex::internal::cadex_vector< IndexType >::type IndexVecType
 
typedef ModelData_Point CoordType
 
typedef ModelData_Color ColorType
 
- Public Types inherited from cadex::ModelData_BaseObject
typedef int IdType
 Defines a type identifier.
 

Public Member Functions

 ModelData_IndexedTriangleSet ()
 Constructor. More...
 
 ModelData_IndexedTriangleSet (initialized)
 Constructor. More...
 
 ModelData_IndexedTriangleSet (internal::ModelData_IndexedTriangleSetImpl *theImpl)
 Constructor (reserved for internal use).
 
IndexType NumberOfFaces () const
 Returns a number of faces (triangles).
 
IndexType NumberOfNormals () const
 Returns a number of (unique) normals.
 
IndexType NumberOfUVCoordinates () const
 Returns a number of UV coordinates.
 
const CoordTypeCoordinate (IndexType theFace, IndexType theVertexSlot) const
 Returns a vertex coordinate. More...
 
IndexType CoordinateIndex (IndexType theFace, IndexType theVertexSlot) const
 Returns a coordinate index for a vertex in a face.
 
NormalType FaceNormal (IndexType theFace) const
 Returns a normal of a face.
 
bool HasNormals () const
 Returns true if the triangle set has explicitly defined normals. More...
 
const NormalTypeVertexNormal (IndexType theFace, IndexType theVertexSlot) const
 Returns a normal at a vertex in a face. More...
 
const NormalTypeNormal (IndexType theIndex) const
 Returns a normal per its index.
 
IndexType NormalIndex (IndexType theFace, IndexType theVertexSlot) const
 Returns a normal index for a vertex in a face.
 
const ColorTypeVertexColor (IndexType theFace, IndexType theVertexSlot) const
 Returns a color at a vertex in a face.
 
IndexType ColorIndex (IndexType theFace, IndexType theVertexSlot) const
 Returns a color index for a vertex in a face.
 
bool HasUVCoordinates () const
 Returns true if the triangle set has UV coordinates associated with vertices. More...
 
const ModelData_Point2dUVCoordinate (IndexType theFace, IndexType theVertexSlot) const
 Returns a UV coordinate associated with a vertex. More...
 
IndexType UVCoordinateIndex (IndexType theFace, IndexType theVertexSlot) const
 Returns a UV coordinate index for a vertex in a face. More...
 
void AddCoordinates (const CoordType theVertices[], size_t theVertexNb)
 Adds vertex coordinates. More...
 
void AddCoordinates (const CoordType theVertices[], size_t theVertexNb, const IndexType theIndices[], size_t theIndexNb)
 Adds vertex coordinates and triangles. More...
 
void AddCoordinates (const CoordType theVertices[], size_t theVertexNb, const IndexType theIndices[], const IndexType theCounts[], size_t theCountNb)
 Adds vertex coordinates and their indices.
 
void AddNormals (const NormalType theNormals[], size_t theNormalNb, const IndexType theIndices[], size_t theIndexNb)
 Adds vertex normals.
 
void AddNormals (const NormalType theNormals[], size_t theNormalNb, const IndexType theIndices[], const IndexType theCounts[], size_t theCountNb)
 Adds vertex normals.
 
void AddColors (const ColorType theColors[], size_t theColorNb, const IndexType theIndices[], size_t theIndexNb)
 Adds vertex colors. More...
 
void AddColors (const ColorType theColors[], size_t theColorNb, const IndexType theIndices[], const IndexType theCounts[], size_t theCountNb)
 Adds vertex colors. More...
 
void AddUVCoordinates (const UVCoordinateType theUVCoordinates[], size_t theUVCoordinateNb, const IndexType theIndices[], size_t theIndexNb)
 Adds UV coordinates.
 
void AddUVCoordinates (const UVCoordinateType theUVCoordinates[], size_t theUVCoordinateNb, const IndexType theIndices[], const IndexType theCounts[], size_t theCountNb)
 Adds UV coordinates.
 
void Merge ()
 
- Public Member Functions inherited from cadex::ModelData_PolyVertexSet
void SetAppearance (const ModelData_Appearance &theAppearance)
 
ModelData_Appearance Appearance () const
 
const CoordTypeCoordinate (IndexType theVertexIndex) const
 Returns a vertex coordinate.
 
bool HasColors () const
 
const ColorTypeColor (IndexType theIndex) const
 
IndexType NumberOfVertices () const
 
IndexType NumberOfColors () const
 Returns a number of unique colors.
 
bool IsEmpty () const
 
- Public Member Functions inherited from cadex::ModelData_PolyShape
 ModelData_PolyShape ()
 Constructor. More...
 
- Public Member Functions inherited from cadex::ModelData_BaseObject
 ModelData_BaseObject ()
 Constructor. More...
 
IdType TypeId () const
 Returns an object type id. More...
 
template<typename T >
bool IsOfType () const
 Returns true if the object has a type T. More...
 
void SetName (const Base_UTF16String &theName)
 Sets an object name. More...
 
Base_UTF16String Name () const
 Returns an object name. More...
 
void Nullify ()
 Resets reference to implementation object. More...
 
bool IsNull () const
 Returns true if the object is nullified. More...
 
 operator bool () const
 Casts the object to the bool type. More...
 
internal::ModelData_BaseObjectImpl * Impl () const
 Return a handle to backend (reserved for internal use).
 

Static Public Member Functions

static IdType GetTypeId ()
 

Additional Inherited Members

- Protected Member Functions inherited from cadex::ModelData_PolyVertexSet
 ModelData_PolyVertexSet (internal::ModelData_BaseObjectImpl *theImpl)
 Constructor (reserved for internal use).
 
- Protected Member Functions inherited from cadex::ModelData_PolyShape
 ModelData_PolyShape (const internal::ModelData_BaseObjectImpl *theImpl)
 Constructor (reserved for internal use).
 
- Protected Member Functions inherited from cadex::ModelData_BaseObject
 ModelData_BaseObject (const internal::ModelData_BaseObjectImpl *theImpl)
 Constructor (reserved for internal use).
 
 ModelData_BaseObject (const internal::ModelData_BaseObjectImpl *theImpl, const Base_UTF16String &theName)
 Constructor (reserved for internal use).
 
template<typename T >
T * GetOrCreateImpl ()
 Reserved for internal use.
 

Detailed Description

Defines a polygonal shape consisting of triangles.

Triangles are defined via array of unique vertex coordinates 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 vertex coordinates. Colors are used very rarely, instead Appearance() attached to entire triangle set is used, as a rule.

A triangle set can be constructed at once or step-by-step using AddCoordinates(), supplying unique coordinates and indices describing triangles, for instance:

//coordinates
ModelData_IndexedTriangleSet::CoordType aCoordArr[4] = {
ModelData_IndexedTriangleSet::CoordType (0., 0., 0.),
ModelData_IndexedTriangleSet::CoordType (1., 0., 0.),
ModelData_IndexedTriangleSet::CoordType (1., 1., 0.),
ModelData_IndexedTriangleSet::CoordType (0., 1., 1.)
};
//triangles (coordinate indices)
0, 1, 2,
0, 2, 3
};
aFaceSet.AddCoordinates (aCoordArr, 4, aCoordIndArr, 6);

Normals and/or colors can be optionally added with the help of AddNormals() and AddColors():

//normals
ModelData_IndexedTriangleSet::NormalType (0., 0., 1.), //to triangle {0, 1, 2}
ModelData_IndexedTriangleSet::NormalType (1., -1., 1.), //to triangle {0, 2, 3}
};
//normal indices
0, 0, 0,
1, 1, 1
};
aFaceSet.AddNormals (aNormalArr, 2, aNormalIndArr, 6);

The user must ensure data consistency so that the number of added normals and/or colors is equal to number of added coordinates. Otherwise, behavior is undefined.

Data can be queried using the rank number of triangle and a vertex slot (0 to 2), for instance:

int n = aTS.NumberOfFaces();
for (int i = 0; i < n; ++i) {
cout << "Triangle " << i << ":" << endl;
for (int j = 0; j < 3; ++j) {
const ModelData_IndexedTriangleSet::CoordType& aV = aTS.Coordinate (i, j);
const ModelData_IndexedTriangleSet::NormalType& aN = aTS.VertexNormal (i, j);
}
}

Coordinate, normal and color indices into respective arrays of unique values can be queried using CoordinateIndex(), NormalIndex() and ColorIndex() respectively.

The triangle set can optionally contain UV coordinates of mesh vertices in parametric domain of original B-Rep surface. HasUVCoordinates() returns whether UV coordinates are available, UVCoordinate() returns coordinate of a specified vertex.

Examples:
exploring/polyrepresentation/main.cxx, meshing/lods/main.cxx, and modeling/poly/main.cxx.

Member Typedef Documentation

◆ NormalType

Defines a type of the normal vector.

The vector can be not-normalized and even have a zero-length (in the case of incorrect input data or degenerated triangle).

Constructor & Destructor Documentation

◆ ModelData_IndexedTriangleSet() [1/2]

cadex::ModelData_IndexedTriangleSet::ModelData_IndexedTriangleSet ( )

Constructor.

Creates a null triangle set. IsNull() will return true.

◆ ModelData_IndexedTriangleSet() [2/2]

cadex::ModelData_IndexedTriangleSet::ModelData_IndexedTriangleSet ( initialized  )

Constructor.

Creates an initialized empty triangle set. IsNull() will return false.

Member Function Documentation

◆ AddColors() [1/2]

void cadex::ModelData_IndexedTriangleSet::AddColors ( const ColorType  theColors[],
size_t  theColorNb,
const IndexType  theIndices[],
size_t  theIndexNb 
)

Adds vertex colors.

Sets colors.

Examples:
modeling/poly/main.cxx.

◆ AddColors() [2/2]

void cadex::ModelData_IndexedTriangleSet::AddColors ( const ColorType  theColors[],
size_t  theColorNb,
const IndexType  theIndices[],
const IndexType  theCounts[],
size_t  theCountNb 
)

Adds vertex colors.

Sets colors.

◆ AddCoordinates() [1/2]

void cadex::ModelData_IndexedTriangleSet::AddCoordinates ( const CoordType  theVertices[],
size_t  theVertexNb 
)

Adds vertex coordinates.

theVertices must contain multiple of three vertices, where each triplet defines a triangle.

Warning
Also adds triangles, one for each triplet of vertices, i.e. the vector of coordinate indices will be {0, 1, 2, 3, ...}. This behavior may likely change in the future (e.g. so that no triangle will be added). For adding triangles it is strongly recommended to use an overload of AddCoordinates() with explicitly defined indices.
Examples:
modeling/poly/main.cxx.

◆ AddCoordinates() [2/2]

void cadex::ModelData_IndexedTriangleSet::AddCoordinates ( const CoordType  theVertices[],
size_t  theVertexNb,
const IndexType  theIndices[],
size_t  theIndexNb 
)

Adds vertex coordinates and triangles.

Defines a face set via vertex coordinates and their indices.

◆ Coordinate()

const ModelData_IndexedTriangleSet::CoordType & cadex::ModelData_IndexedTriangleSet::Coordinate ( IndexType  theFace,
IndexType  theVertexSlot 
) const

Returns a vertex coordinate.

Returns Coordinate (CoordinateIndex (theFace, theVertexSlot));

Examples:
exploring/polyrepresentation/main.cxx.

◆ HasNormals()

bool cadex::ModelData_IndexedTriangleSet::HasNormals ( ) const

Returns true if the triangle set has explicitly defined normals.

See also
FaceNormal(), VertexNormal(), IsNormalPerVertex(), Normal().
Examples:
exploring/polyrepresentation/main.cxx.

◆ HasUVCoordinates()

bool cadex::ModelData_IndexedTriangleSet::HasUVCoordinates ( ) const

Returns true if the triangle set has UV coordinates associated with vertices.

See also
UVCoordinate(), UV coordinates retrieval.
Examples:
exploring/polyrepresentation/main.cxx.

◆ UVCoordinate()

const ModelData_Point2d & cadex::ModelData_IndexedTriangleSet::UVCoordinate ( IndexType  theFace,
IndexType  theVertexSlot 
) const

Returns a UV coordinate associated with a vertex.

This method may only be used if HasUVCoordinates() returns true, otherwise behavior is undefined.

See also
UV coordinates retrieval.
Examples:
exploring/polyrepresentation/main.cxx.

◆ UVCoordinateIndex()

ModelData_IndexedTriangleSet::IndexType cadex::ModelData_IndexedTriangleSet::UVCoordinateIndex ( IndexType  theFace,
IndexType  theVertexSlot 
) const

Returns a UV coordinate index for a vertex in a face.

This method may only be used if HasUVCoordinates() returns true, otherwise behavior is undefined.

See also
UV coordinates retrieval.

◆ VertexNormal()

const ModelData_IndexedTriangleSet::NormalType & cadex::ModelData_IndexedTriangleSet::VertexNormal ( IndexType  theFace,
IndexType  theVertexSlot 
) const

Returns a normal at a vertex in a face.

theFace must be a valid face index, from 0 to NumberOfFaces() - 1. theVertexSlot must be a vertex slot index, from 0 to NumberOfVertices(theFace) - 1. Returns Normal (NormalIndex (theFace, theVertexSlot));

Examples:
exploring/polyrepresentation/main.cxx.