Hide menu
cadex::ModelPrs_SceneNodeFactory Class Reference

Creates a scene nodes and its children from input data model objects. More...

Inheritance diagram for cadex::ModelPrs_SceneNodeFactory:

Public Types

typedef cadex::internal::ModelPrs_SceneNodeFactoryImpl ImplType

Public Member Functions

 ModelPrs_SceneNodeFactory ()
 Constructor. More...
 ModelPrs_SceneNodeFactory (const ModelPrs_SceneNodeFactoryParameters &theParameters)
 Constructor. More...
ModelPrs_SceneNodeFactoryParametersParameters ()
 Returns factory parameters.
const ModelPrs_SceneNodeFactoryParametersParameters () const
 Returns factory parameters.
ModelPrs_SceneNode CreateGraph (const ModelData_Model &theModel, ModelData_RepresentationMask theRepresentationMask)
 Creates scene graph using ModelData_Model.
ModelPrs_SceneNode CreateGraph (const ModelData_Model &theModel, const Base_UTF16String &theRepresentationName)
 Creates scene graph using ModelData_Model.
ModelPrs_SceneNode CreateNode (const ModelData_SceneGraphElement &theSceneGraphElement)
 Creates scene node using ModelData_SceneGraphElement.
ModelPrs_SceneNode CreateNode (const ModelData_Representation &theRepresentation)
 Creates scene node using ModelData_PolyRepresentation or ModelData_BRepRepresentation.
ModelPrs_SceneNode CreateNode (const ModelData_PolyVertexSet &thePolyVertexSet)
 Creates scene node using ModelData_PolyVertexSet.
ModelPrs_SceneNode CreateNode (const ModelData_Body &theBody, const ModelData_BRepRepresentation &theRep=ModelData_BRepRepresentation())
 Creates scene node using ModelData_Body with optional owning ModelData_BRepRepresentation.
ModelPrs_SceneNode CreateNode (const ModelPrs_Measurement &theMeasurement)
 Creates scene node using ModelPrs_Measurement.
ModelPrs_SceneNode CreateNode (const ModelData_PMIGraphicalElement &thePMIGraphicalElement)
 Creates scene node using ModelData_PMIGraphicalElement.
- Public Member Functions inherited from cadex::Base_PublicObject
 Base_PublicObject ()
 Constructor. More...
void Nullify ()
 Resets reference to implementation object.
bool IsNull () const
 Returns true if the object is nullified. More...
 operator bool () const
 Casts the object to the bool type. More...
internal::Base_HandledObject * Impl () const
 Return a handle to backend (reserved for internal use).
const internal::Base_Handle & HImpl () const
template<typename T >
T * Impl () const
 Reserved for internal use.
bool operator== (const Base_PublicObject &theObject) const
bool operator!= (const Base_PublicObject &theObject) const

Additional Inherited Members

- Protected Member Functions inherited from cadex::Base_PublicObject
 Base_PublicObject (const internal::Base_HandledObject *theObject)
 Constructor (reserved for internal use).
template<typename T >
T * GetOrCreateImpl ()
 Reserved for internal use.

Detailed Description

Creates a scene nodes and its children from input data model objects.

This class is a part of Visualization Toolkit add-on, which is licensed separately from the base CAD Exchanger SDK.

The factory supports various input types to create scene nodes from:

  • Entire ModelData_Model;
  • Assembly, part or instance;
  • B-Rep or polygonal representation.
  • Individual body inside B-Rep representation;
  • Individual mesh (triangle set, polyline set or point set).

There are two ways to create scene nodes:

  • The first is to use CreateGraph that traverses a model entirely, creates scene nodes and their children. This prevents you from influencing the creation of the scene nodes. Therefore, it is more suitable for simply displaying the entire model. For example, to take screenshots. sdk_examples_offscreen
  • The second is to use CreateNode that creates a single scene node. It gives you the ability to process each scene node and manually create a scene graph. For example, to create items for tree view and add a relation to scene nodes. sdk_examples_selectionhandling

The following example demonstrates creating a scene from the entire model. Note that if the model has multiple roots then resulting scene nodes will be children of a single root scene node:

ModelData_Model aModel = ...;
ModelPrs_SceneNodeFactory aFactory ({ModelData_RM_BRep});
ModelPrs_SceneNode aRootNode = aFactory.CreateGraph (aModel);
ModelPrs_Scene aScene;
aScene.AddRoot (aRootNode);

The following example demonstrates creating a scene node for a single B-Rep solid:

ModelData_Solid aSphere = ModelAlgo_TopoPrimitives::CreateSphere (5.);
ModelData_Body aBody = ModelData_Body::Create (aSphere);
ModelPrs_Scene aBodyNode = aFactory.CreateNode (aBody);

Scene nodes for B-Rep shapes

Given that B-Rep sub-shapes may only refer to meta-data (such as visual appearances) in the context of B-Rep representation that own them, specifying that owning B-Rep representation is important when creating a node. Consider an example of a B-Rep solid with three colored faces:

ModelData_Solid aBox = ModelAlgo_TopoPrimitives::CreateBox (10., 20., 30.);
ModelData_Body aBody = ModelData_Body::Create (aBox);
ModelData_BRepRepresentation aBRep (aBody);
ModelData_Shape::Iterator anIt (aBox);
auto aF1 = anIt.Next();
auto aF2 = anIt.Next();
auto aF3 = anIt.Next();
aBRep.SetAppearance (aF1, ModelData_Color (1.f, 0.f, 0.f);
aBRep.SetAppearance (aF2, ModelData_Color (0.f, 1.f, 0.f);
aBRep.SetAppearance (aF3, ModelData_Color (0.f, 0.f, 1.f);

In order to transmit these attributes to the scene nodes the owning B-Rep representation must be specified:

auto aNode = aFactory.CreateNode (aBody, aBRep);

If the B-Rep representation is not provided then the appearance will be lost:

auto aNode2 = aFactory.CreateNode (aBody);

The results are shown on the following screenshots:

Body with owning B-Rep
Body without owning B-Rep

Of course, to achieve an equivalent correct result the factory could be simply used as follows:

auto aNode = aFactory.CreateNode (aBRep);

A scene node factory contains a shared pointer to its internal implementation, so simple copying an object will just copy a shared pointer. Therefore any modification of the copied object will propagate to original object.

See also
Using pimpl pattern
visualization/offscreen/main.cxx, visualization/qtquick_qml/baseviewer/main.cxx, visualization/qtquick_qml/measurements/main.cxx, visualization/qtquick_qml/pmiviewer/main.cxx, and visualization/qtquick_qml/selectionhandling/main.cxx.

Constructor & Destructor Documentation

◆ ModelPrs_SceneNodeFactory() [1/2]

cadex::ModelPrs_SceneNodeFactory::ModelPrs_SceneNodeFactory ( )


Creates factory with default parameters.

◆ ModelPrs_SceneNodeFactory() [2/2]

cadex::ModelPrs_SceneNodeFactory::ModelPrs_SceneNodeFactory ( const ModelPrs_SceneNodeFactoryParameters myParameters)


Creates factory with custom parameters.

static ModelData_Solid CreateBox(double theDx, double theDy, double theDz)
Creates a box.
Definition: ModelAlgo_TopoPrimitives.cxx:82
Definition: ModelPrs_SceneNodeFactory.cxx:495
static ModelData_Body Create(const ModelData_Shape &theShape)
Creates a body from an arbitrary shape.
Definition: ModelData_Body.cxx:223
static ModelData_Solid CreateSphere(double theRadius, double theU=2 *M_PI, double theVmin=-M_PI_2, double theVmax=M_PI_2)
Creates a sphere.
Definition: ModelAlgo_TopoPrimitives.cxx:144