Hide menu
Exploring 3D Models

Table of Contents


CAD Exchanger SDK allows to explore 3D models (imported from external files or created inside users' applications) traversing over their product structures, part representations and various associated data (properties, materials, transformation matrices, etc).

This scenario can be used if you need to visualize 3D data in your application, to perform some computations, to identify some components (assemblies, parts) or to retrieve some information from the external files.

When importing a file CAD Exchanger SDK populates a ModelData_Model object which can then be explored. Depending on the application needs, the following information can be retrieved:

  • product structure - root elements, hierarchical graph of sub-assemblies and parts, transformation matrices applied to instances of parts/assemblies;
  • B-Rep representation - detailed geometrical and topological description of part bodies (curves and surfaces, edges and faces, point coordinates, etc);
  • polygonal representation - tessellated representation of parts (sets of triangles, polylines or point clouds, including vertex coordinates, normals, etc);
  • associated names, visual appearance attributes (colors, materials), layers, properties and other meta-data.

The following example provides some excerpts of how the exploration could be organized:

static void DumpTriangleSet (const ModelData_IndexedTriangleSet& theTS,
const ModelData_Transformation& theTrsf)
ModelData_IndexedTriangleSet::IndexType n = theTS.NumberOfFaces();
cout << "Triangle set contains " << n << " triangles" << endl;
for (int i = 0; i < n; ++i) {
cout << "Triangle " << i << ":" << endl;
cout << " Node coordinates:" << endl;
for (int j = 0; j < 3; ++j) {
const ModelData_IndexedTriangleSet::CoordType& aV = theTS.Coordinate (i, j);
double aX = aV.X(), aY = aV.Y(), aZ = aV.Z();
theTrsf.Transform (aX, aY, aZ);
cout << " (" << aX << ", " << aY << ", " << aZ << ")" << endl;
static void ExplorePoly (const ModelData_PolyRepresentation& thePoly, const ModelData_Transformation& theTrsf)
const ModelData_PolyShapeList& aList = thePoly.Get();
for (ModelData_PolyShapeList::SizeType i = 0; i < aList.Size(); ++i) {
const ModelData_PolyVertexSet& aPVS = aList[i];
if (aPVS.TypeId() == ModelData_IndexedTriangleSet::GetTypeId()) {
DumpTriangleSet (static_cast<const ModelData_IndexedTriangleSet&> (aPVS), theTrsf);
class SceneGraphVisitor : public ModelData_Model::ElementVisitor
ModelData_Transformation anIdentity;
myTrsfs.push (anIdentity);
virtual void operator() (const ModelData_Part& thePart) override
PrintName ("Part", thePart.Name());
ModelData_Part::RepresentationIterator i (thePart);
while (i.HasNext()) {
const ModelData_Representation& aRep = i.Next();
if (aRep.TypeId() == ModelData_PolyRepresentation::GetTypeId()) {
ExplorePoly (static_cast<const ModelData_PolyRepresentation&> (aRep), CurrentTransformation());
virtual bool VisitEnter (const ModelData_Instance& theInstance) override
PrintName ("Instance", theInstance.Name());
// Get a transformation matrix
ModelData_Transformation aTrsf;
if (theInstance.HasTransformation()) {
aTrsf = theInstance.Transformation();
ModelData_Transformation aCumulativeTrsf = CurrentTransformation() * aTrsf;
myTrsfs.push (aCumulativeTrsf);
return true;
virtual void VisitLeave (const ModelData_Instance& /*theInstance*/) override
const ModelData_Transformation& CurrentTransformation() const
return myTrsfs.top();
std::stack<ModelData_Transformation> myTrsfs;
ModelData_Model aModel;
JT_Reader aReader;
if (aReader.ReadFile (theSource) && aReader.Transfer (theModel)) {
SceneGraphVisitor aSGVisitor;
aModel.Accept (aSGVisitor);

When traversing the assembly graph which may contain multiple shared components, make sure to track transformation matrices applied to different instances along the graph in order to correctly convert local coordinates to global ones. If visiting already visited elements is not required make sure to use ModelData_SceneGraphElementUniqueVisitor.

For detailed descriptions of how to retrieve particular elements refer to particular documentation sections, including Traversal of the product structure, Traversal over the representations, Traversal over properties, B-Rep Topology Exploration and others.


Refer to Model Exploring.

int IndexType
Type of indices.
Definition: ModelData_PolyVertexSet.hxx:35