CAD Exchanger SDK
Part representations

Representations are associated with a part and define its shape.

The following representations are supported:

Each part may have zero or one B-Rep representation and zero, one or several polygonal representations. Representations must be consistent with each other.

The following picture demonstrates the nut part from the assembly as1, with one BRep (as solid body) and one polygonal representation:

dm_nut_brep.png
B-Rep representation
dm_nut_poly.png
Polygonal representation

Levels of Details (LOD's)

A part may have multiple polygonal representations. In this case a part is considered having levels of details (LOD's), i.e. granularity or accuracy of approximation of a part.

By convention, LODs must be sorted from the most accurate (fine) to the least accurate (coarse) representations.

The following example demonstrates a part with one BRep (as a sheet body) and three polygonal representations:

dm_bsurf_brep.png
BRep
dm_bsurf_lod1.png
Fine LOD
dm_bsurf_lod2.png
Medium LOD
dm_bsurf_lod3.png
Coarse LOD

Polygonal representations can be either explicitly created bottom-up or generated from B-Rep with the help of meshers (see Mesh Generation).

The following code snippet demonstrates creation of a part with BRep and two polygonal representations:

ModelData_Solid aSolid = ...; //exact solid shape
ModelData_BRepRepresentation aBRep (aSolid);
//automatically generates polygonal representations from BRep
ModelData_PolyRepresentation aFinePoly (aBRep, ModelAlgo_BRepMesherParameters::Fine);
ModelData_PolyRepresentation aMediumPoly (aBRep, ModelAlgo_BRepMesherParameters::Medium);
ModelData_Part aPart (aBRep, aFinePoly, aMediumPoly, "my_part");

Semantics of LOD is application-specific. The data model only provides a mechanism to define multiple polygonal representations.

B-Rep representation contains ModelData_BodyList, which is a list of bodies (ModelData_Body), which define exact part geometry. Each ModelData_Body can be solid, sheet, wireframe or acorn (see ModelData_BodyType enumeration).

Each polygonal representation contains ModelData_PolyShapeList, which is a list of vertex sets. Each vertex set (subclass of ModelData_PolyVertexSet) defines either a set of triangles (ModelData_IndexedTriangleSet), polylines (ModelData_PolyLineSet) or just a point cloud ( ModelData_PolyPointSet).

Traversal over the representations

The part representations can be traversed as follows:

  • with the help of direct search;
  • with the help of iterator;
  • with the help of visitors.

The following examples demonstrate using each approach:

ModelData_Part aPart = ...;
//find B-Rep representation
ModelData_BRepRepresentation aBRep = aPart.BRepRepresentation();
if (aBRep) {
const ModelData_BodyList& aList = aBRep.Get(); //retrieve root bodies
for (ModelData_BodyList::SizeType i = 0; i < aList.Size(); ++i) {
const ModelData_Body& aBody = aList[i];
//...
}
}
//find first polygonal representation
ModelData_PolyRepresentation aPoly = aPart.PolyRepresentation (ModelData_RM_FineLOD);
if (aPoly) {
const ModelData_PolyShapeList& aList = aPoly.Get(); //retrive root vertex sets
for (ModelData_PolyShapeList::SizeType i = 0; i < aList.Size(); ++i) {
const ModelData_PolyVertexSet& aPVSet = aList[i];
//...
}
}
class MyRepresentationVisitor : public ModelData_Part::RepresentationVisitor
{
public:
virtual void operator() (const ModelData_BRepRepresentation& theRep) override { /*...*/ }
virtual void operator() (const ModelData_PolyRepresentation& theRep) override { /*...*/ }
};
MyRepresentationVisitor aVisitor;
aPart.Accept (aVisitor);

In the above example a respective operator() of MyRepresentationVisitor will be invoked for each representation encountered in the part.

ModelData_Part::RepresentationIterator anIt (aPart);
while (anIt.HasNext()) {
const ModelData_Representation& aRep = anIt.Next();
if (aRep.TypeId() == ModelData_PolyRepresentation::GetTypeId()) {
const ModelData_PolyRepresentation& aPoly = static_cast<const ModelData_PolyRepresentation&> (aRep);
} else if (aRep.TypeId() == ModelData_BRepRepresentation::GetTypeId()) {
const ModelData_BRepRepresentation& aBRep = static_cast<const ModelData_BRepRepresentation&> (aRep);
}
}