Hide menu
cadex::ModelPrs_SceneNodeFactory Class Reference

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

Inheritance diagram for cadex::ModelPrs_SceneNodeFactory:
cadex::Base_PublicObject

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 Create (const ModelData_Model &theModel)
 Creates scene graph using ModelData_Model.
 
ModelPrs_SceneNode Create (const ModelData_SceneGraphElement &theSGE)
 Creates scene graph using ModelData_SceneGraphElement.
 
ModelPrs_SceneNode Create (const ModelData_PolyVertexSet &thePVS)
 Creates scene graph using ModelData_PolyVertexSet.
 
ModelPrs_SceneNode Create (const ModelData_Representation &theRep)
 Creates scene graph using ModelData_PolyRepresentation or ModelData_BRepRepresentation.
 
ModelPrs_SceneNode Create (const ModelData_Body &theBody, const ModelData_BRepRepresentation &theRep=ModelData_BRepRepresentation())
 Creates scene graph using ModelData_Body with optional owning ModelData_BRepRepresentation.
 
ModelPrs_SceneNode Create (const ModelPrs_Measurement &theMeasurement)
 Creates scene graph using ModelPrs_Measurement.
 
ModelPrs_SceneNode Create (const ModelData_PMIGraphicalElement &thePMIGraphicalElement)
 Creates scene graph 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).
 

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 node and its children from input data model objects.

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).

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_GeometryFactory aFactory (ModelData_RM_BRep);
ModelPrs_SceneNode aRootNode = aFactory.Create (aModel);
ModelPrs_Scene aScene;
aScene.AddRoot (aRootNode);
aScene.Update();

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

ModelData_Solid aSphere = ModelAlgo_TopoPrimitives::CreateSphere (5.);
ModelData_Body aBody = ModelData_Body::Create (aSphere);
ModelPrs_Scene aRootNode2 = aFactory.Create (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.Create (aBody, aBRep);

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

auto aNode2 = aFactory.Create (aBody);

The results are shown on the following screenshots:

vis_part_colored.png
Body with owning B-Rep
vis_part_default_color.png
Body without owning B-Rep

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

auto aNode = aFactory.Create (aBRep);

Factory Parameters

The factory supports various parameters (encapsulated in ModelPrs_SceneNodeFactoryParameters) that affect which internal data elements are selected to create a scene node.

The following example demonstrates selection of different representations from a part as well as distinct “grouping/ungrouping” preferences.

Imagine a part that contains both B-Rep and polygonal representations, and each contains multiple sub-elements (B-Rep bodies or PolyVertexSet’s respectively):

vis_part_rerpesentations.png
Part with two representations

Using default and custom factory parameters may result in distinct resulting scene nodes:

ModelData_Part aPart = ...;
ModelPrs_SceneNodeFactory aDefaultFactory;
ModelPrs_SceneNodeFactory aCustomFactory ({ModelData_RM_BRep, true});
auto aFirstRoot = aDefaultFactory.Create (aPart);
auto aSecondRoot = aCustomFactory.Create (aPart);

The following figures demonstrate scene nodes constructed in the above example:

vis_scene_graph_default.png
Scene node constructed with default factory parameters
vis_scene_graph_with_decomposition.png
Scene node constructed with custom factory
parameters

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
Examples:
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

cadex::ModelPrs_SceneNodeFactory::ModelPrs_SceneNodeFactory ( )

Constructor.

Creates factory with default parameters.

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

Constructor.

Creates factory with custom parameters.