CAD Exchanger SDK
B-Rep Representation


B-Rep representation (ModelData_BRepRepresentation) contains an exact geometrical description of a part (ModelData_Part). A part may have none or one B-Rep representation.

B-Rep representation contains ModelData_BodyList, which is a list of bodies (ModelData_Body). As a rule B-Rep representation consists of a single body.

The following example demonstrates how to iterate over root bodies:

ModelData_Part aPart = ...;
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];
B-Rep representations of different parts shall not share bodies or their subshapes. Bodies in the B-Rep representation shall not share sub-shapes. That is, each body must be self-contained and shall not share subshapes with other bodies. If this requirement is not met then behavior may be undefined (up to a crash or corrupting representation).
See also
Part representations, Polygonal Representation.

Body types

CAD Exchanger supports body types (defined by the ModelData_BodyType enumeration) defined in the following table:

Solid body
solid - contains a single solid
Sheet body
sheet - contains a single face or a single shell or a flat group of face(s) and/or shell(s)
Wireframe body
wireframe - contains a single edge or a single wire or a flat group of edge(s) and/or wire(s)
Acorn body
acorn - contains a single vertex

The body type is returned by ModelData_Body::BodyType().

Although it is not illegal to mix different body types in one B-Rep representation, it is recommended to use consistent body types (or even single body per part). This is to ensure greater compatibility with target formats which might not allow to mix different body types or multiple bodies per part.

For detailed description of B-Rep data model, topology and geometry, refer to B-Rep Topology and B-Rep Geometry.


B-Rep representation is initially created with an empty list of bodies. Adding body(ies) to is done with ModelData_BRepRepresentation::Add() or provided in the constructor, for instance:

ModelData_Solid aBox = ModelAlgo_TopoPrimitives::CreateBox (50, 50, 1);
ModelData_BRepRepresentation aBRep (aBox);
ModelData_Part aPart (aBRep, "my_part");

Currently SDK provides high level API create solid primitives, such as box, sphere, cylinder, etc using the ModelAlgo_TopoPrimitives class.

A body can also be created with the help of ModelData_Body::Create() from any arbitrary topological shape (ModelData_Shape).

Generation from polygonal representation

A B-Rep representation can be created from polygonal representation. This takes place when exporting a model with parts containing only polygonal representations to a format that requires B-Rep representation. For instance, this may happen when a model previously imported from an STL file to a file in IGES, STEP, ACIS or Parasolid format.

In this case each triangle of ModelData_IndexedTriangleSet will be converted to a planar triangle ModelData_Face. The whole triangle set will be converted into one or several ModelData_Shells where each shell will correspond to a connected subset of triangles (i.e. triangles sharing the same vertex indices). Each closed shell will be additionally converted into a ModelData_Solid.

Given that such B-Rep will have very high memory footprint on the one hand and may have limited usability in any CAD system for modeling operations on the other, this conversion is discouraged and should only be used when direct use of polygonal representations is impossible.

Subshape attributes

In addition to root bodies, the B-Rep representation may also register subshapes (i.e. sub-elements of bodies) with associated names, appearance attributes, user-defined properties or layers. This registration is needed, as the topological structure itself does not allow to define meta data.

The following example demonstrates how to assign attributes to subshapes:

ModelData_Solid aSolid = ...;
ModelData_BRepRepresentation aBRep (aSolid);
aBRep.SetName (aSolid, "solid");
ModelData_Shape::Iterator aShellIt (aSolid);
ModelData_Shape aShape = aShellIt.Next();
aBRep.SetName (aShape, "shell");
aBRep.SetAppearance (aShape, ModelData_Color (0.f, 0.f, 1.f)); //blue
ModelData_Shape::Iterator aFaceIt (aSolid, ModelData_ST_Face);
aShape = aFaceIt.Next();
aBRep.SetName (aShape, "face0");
aBRep.SetAppearance (aShape, ModelData_Color (1.f, 0.f, 0.f)); //red

The screenshot below demonstrates how this B-Rep representation would be displayed:

B-Rep with subshape attributes

The following example demonstrates how to iterate over registered subshapes and to retrieve their attributes:

ModelData_BRepRepresentation::SubshapeIterator i (aBRep);
while (i.HasNext()) {
const ModelData_Shape& aShape = i.Next();
Base_UTF16String aName = aBRep.Name (aShape);
if (!aName.IsEmpty()) { //subshape has name
ModelData_Appearance anAppearance = aBRep.Appearance (aShape);
if (anAppearance) { //subshape has appearance