Hide menu
Loading...
Searching...
No Matches
cadex::ModelData_IndexedTriangleSet Class Reference

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

#include <cadex/ModelData_IndexedTriangleSet.hxx>

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.
 
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.
 
 ModelData_IndexedTriangleSet (initialized)
 Constructor.
 
 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.
 
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.
 
const NormalTypeVertexNormal (IndexType theFace, IndexType theVertexSlot) const
 Returns a normal at a vertex in a face.
 
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.
 
const ModelData_Point2dUVCoordinate (IndexType theFace, IndexType theVertexSlot) const
 Returns a UV coordinate associated with a vertex.
 
const ModelData_Point2dUVCoordinate (IndexType theIndex) const
 //! Returns a UV coordinate per its index.
 
IndexType UVCoordinateIndex (IndexType theFace, IndexType theVertexSlot) const
 Returns a UV coordinate index for a vertex in a face.
 
void AddCoordinates (const CoordType theVertices[], size_t theVertexNb)
 Adds vertex coordinates.
 
void AddCoordinates (const CoordType theVertices[], size_t theVertexNb, const IndexType theIndices[], size_t theIndexNb)
 Adds vertex coordinates and triangles.
 
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.
 
void AddColors (const ColorType theColors[], size_t theColorNb, const IndexType theIndices[], const IndexType theCounts[], size_t theCountNb)
 Adds vertex colors.
 
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 ()
 
const CoordTypeCoordinate (IndexType theVertexIndex) const
 Returns a vertex coordinate.
 
- 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.
 
- Public Member Functions inherited from cadex::ModelData_BaseObject
 ModelData_BaseObject ()
 Constructor.
 
IdType TypeId () const
 Returns an object type id.
 
template<typename T >
bool IsOfType () const
 Returns true if the object has a type T.
 
void SetName (const Base_UTF16String &theName)
 Sets an object name.
 
Base_UTF16String Name () const
 
void SetUuid (const Base_Uuid &theUuid)
 
Base_Uuid Uuid () const
 
void Nullify ()
 Resets reference to implementation object.
 
bool IsNull () const
 Returns true if the object is nullified.
 
 operator bool () const
 Casts the object to the bool type.
 
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
};
//triangles (coordinate indices)
0, 1, 2,
0, 2, 3
};
aFaceSet.AddCoordinates (aCoordArr, 4, aCoordIndArr, 6);
ModelData_IndexedTriangleSet()
Constructor.
Definition: ModelData_IndexedTriangleSet.cxx:138
Defines a 3D point.
Definition: ModelData_Point.hxx:295
int IndexType
Type of indices.
Definition: ModelData_PolyVertexSet.hxx:35

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);
ModelData_Vectorf NormalType
Defines a type of the normal vector.
Definition: ModelData_IndexedTriangleSet.hxx:42

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
MTKConverter/Program.cs, MTKConverter/main.cxx, advgeom/meshsimplify/Program.cs, advgeom/meshsimplify/main.cxx, exploring/polyrepresentation/Program.cs, exploring/polyrepresentation/main.cxx, helpers/shape_processor.cs, helpers/shape_processor.hxx, machining/dfm_analyzer/Program.cs, machining/dfm_analyzer/main.cxx, machining/feature_recognizer/Program.cs, machining/feature_recognizer/main.cxx, meshing/lods/Program.cs, meshing/lods/main.cxx, meshing/visualizationmesher/Program.cs, meshing/visualizationmesher/main.cxx, modeling/poly/Program.cs, modeling/poly/main.cxx, modification/coloring/Program.cs, modification/coloring/main.cxx, modification/renaming/Program.cs, modification/renaming/main.cxx, sheet_metal/dfm_analyzer/Program.cs, sheet_metal/dfm_analyzer/main.cxx, sheet_metal/feature_recognizer/Program.cs, sheet_metal/feature_recognizer/main.cxx, wall_thickness/analyzer/Program.cs, wall_thickness/analyzer/main.cxx, wall_thickness/visualization/Program.cs, and wall_thickness/visualization/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[],
const IndexType  theCounts[],
size_t  theCountNb 
)

Adds vertex colors.

Sets colors.

◆ AddColors() [2/2]

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

◆ 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/Program.cs, and 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/Program.cs, exploring/polyrepresentation/main.cxx, meshing/visualizationmesher/Program.cs, and meshing/visualizationmesher/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/Program.cs, and 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/Program.cs, and exploring/polyrepresentation/main.cxx.

◆ UVCoordinate() [1/2]

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/Program.cs, and exploring/polyrepresentation/main.cxx.

◆ UVCoordinate() [2/2]

const ModelData_Point2d & cadex::ModelData_IndexedTriangleSet::UVCoordinate ( IndexType  theIndex) const

//! Returns a UV coordinate per its index.

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

See also
UV coordinates retrieval.

◆ 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/Program.cs, and exploring/polyrepresentation/main.cxx.