0027191: Documentation - redesign of information architecture -- revision (user guides)
[occt.git] / dox / user_guides / visualization / visualization.md
CommitLineData
ba06f8bb 1Visualization {#occt_user_guides__visualization}
bf62b306 2========================
3@tableofcontents
72b7576f 4
bf62b306 5@section occt_visu_1 Introduction
72b7576f 6
7c42f3f4 7Visualization in Open CASCADE Technology is based on the separation of:
8 * on the one hand -- the data which stores the geometry and topology of the entities you want to display and select, and
453103d1 9 * on the other hand -- its **presentation** (what you see when an object is displayed in a scene)
10 and **selection** (possibility to choose the whole object or its sub-parts interactively to apply application-defined operations to the selected entities).
72b7576f 11
18006a0f 12Presentations are managed through the **Presentation** component, and selection through the **Selection** component.
72b7576f 13
453103d1 14**Application Interactive Services** (AIS) provides the means to create links between an application GUI viewer and the packages,
15which are used to manage selection and presentation, which makes management of these functionalities in 3D more intuitive and consequently, more transparent.
72b7576f 16
453103d1 17*AIS* uses the notion of the *Interactive Object*, a displayable and selectable entity, which represents an element from the application data.
18As a result, in 3D, you, the user, have no need to be familiar with any functions underlying AIS unless you want to create your own interactive objects or selection filters.
72b7576f 19
453103d1 20If, however, you require types of interactive objects and filters other than those provided, you will need to know the mechanics of presentable and selectable objects, specifically how to implement their virtual functions.
21To do this requires familiarity with such fundamental concepts as the Sensitive Primitive and the Presentable Object.
72b7576f 22
2683e647 23The the following packages are used to display 3D objects:
7c42f3f4 24 * *AIS*;
25 * *StdPrs*;
26 * *Prs3d*;
27 * *PrsMgr*;
28 * *V3d*;
4ee1bdf4 29 * *Graphic3d*.
72b7576f 30
18006a0f 31The packages used to display 3D objects are also applicable for visualization of 2D objects.
72b7576f 32
453103d1 33The figure below presents a schematic overview of the relations between the key concepts and packages in visualization.
34Naturally, "Geometry & Topology" is just an example of application data that can be handled by *AIS*, and application-specific interactive objects can deal with any kind of data.
72b7576f 35
d6b4d3d0 36@figure{visualization_image003.png,"Key concepts and packages in visualization",400}
72b7576f 37
2683e647 38To answer different needs of CASCADE users, this User's Guide offers the following three paths in reading it.
7c42f3f4 39
40 * If the 3D services proposed in AIS meet your requirements, you need only read chapter 3 @ref occt_visu_3 "AIS: Application Interactive Services".
453103d1 41 * If you need more detail, for example, a selection filter on another type of entity -- you should read
42 chapter 2 @ref occt_visu_2 "Fundamental Concepts", chapter 3 @ref occt_visu_3 "AIS: Application Interactive Services", and 4 @ref occt_visu_4 "3D Presentations".
43 You may want to begin with the chapter presenting AIS.
7c42f3f4 44
7c42f3f4 45@section occt_visu_2 Fundamental Concepts
72b7576f 46
7c42f3f4 47@subsection occt_visu_2_1 Presentation
72b7576f 48
453103d1 49In Open CASCADE Technology, presentation services are separated from the data, which they represent, which is generated by applicative algorithms.
50This division allows you to modify a geometric or topological algorithm and its resulting objects without modifying the visualization services.
72b7576f 51
7c42f3f4 52@subsubsection occt_visu_2_1_1 Structure of the Presentation
72b7576f 53
2683e647 54Displaying an object on the screen involves three kinds of entities:
bf62b306 55 * a presentable object, the *AIS_InteractiveObject*
7c42f3f4 56 * a viewer
57 * an interactive context, the *AIS_InteractiveContext*.
58
59#### The presentable object
60
453103d1 61The purpose of a presentable object is to provide the graphical representation of an object in the form of *Graphic3d_Structure*.
62On the first display request, it creates this structure by calling the appropriate algorithm and retaining this framework for further display.
7c42f3f4 63
453103d1 64Standard presentation algorithms are provided in the *StdPrs* and *Prs3d* packages.
65You can, however, write specific presentation algorithms of your own, provided that they create presentations made of structures from the *Graphic3d* packages.
66You can also create several presentations of a single presentable object: one for each visualization mode supported by your application.
72b7576f 67
7c42f3f4 68Each object to be presented individually must be presentable or associated with a presentable object.
72b7576f 69
7c42f3f4 70#### The viewer
72b7576f 71
453103d1 72The viewer allows interactively manipulating views of the object.
73When you zoom, translate or rotate a view, the viewer operates on the graphic structure created by the presentable object and not on the data model of the application.
74Creating Graphic3d structures in your presentation algorithms allows you to use the 3D viewers provided in Open CASCADE Technology for 3D visualization.
72b7576f 75
7c42f3f4 76#### The Interactive Context
72b7576f 77
453103d1 78The interactive context controls the entire presentation process from a common high-level API.
79When the application requests the display of an object, the interactive context requests the graphic structure from the presentable object and sends it to the viewer for displaying.
72b7576f 80
bf62b306 81@subsubsection occt_visu_2_1_2 Presentation packages
72b7576f 82
453103d1 83Presentation involves at least the *AIS, PrsMgr, StdPrs* and *V3d* packages.
84Additional packages, such as *Prs3d* and *Graphic3d* may be used if you need to implement your own presentation algorithms.
85
86* Standard Interactive Objects
87 * *AIS* package provides classes to implement interactive objects (presentable and selectable entities).
88 * *PrsDim* package provides presentable objects for drawing dimensions and relations.
89 * *MeshVS* package provides presentable object MeshVS_Mesh for working with mesh data.
90* Standard presentation builders
91 * *Prs3d* package provides ready-to-use standard presentation algorithms for simple geometries like arrow, cylinder, sphere.
92 It also defines *Prs3d_Drawer* class controlling the attributes of the presentation to be created in terms of color, line type, thickness, etc.
93 * *StdPrs* package provides ready-to-use standard presentation algorithms for B-Rep shapes.
94 It provides generic presentation algorithms such as shading, wireframe, isolines and hidden line removal.
95 * *DsgPrs* package provides tools for display of dimensions, relations and XYZ trihedrons.
96* Selection services
97 * *Select3D*, *SelectBasics* and *SelectMgr* implement selection (picking) services.
98 * *StdSelect* package provide selection builders for B-Rep shapes.
99* Viewer management
100 *V3d* package provides the services supported by the 3D viewer.
101* Low-level interfaces
102 * *PrsMgr* package defines basic interfaces and tools for presentable object.
103 It contains all classes needed to implement the presentation process:
104 abstract classes *PrsMgr_Presentation* and *PrsMgr_PresentableObject* and concrete class *PrsMgr_PresentationManager*.
105 * *Graphic3d* package provides low-level graphic structures.
106 It also defines an interface of Graphic3d_GraphicDriver providing a connection with low-level graphics APIs like OpenGL.
72b7576f 107
7c42f3f4 108@subsubsection occt_visu_2_1_3 A Basic Example: How to display a 3D object
72b7576f 109
453103d1 110~~~~~{.cpp}
7c42f3f4 111Handle(V3d_Viewer) theViewer;
112Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (theViewer);
bf62b306 113
7c42f3f4 114BRepPrimAPI_MakeWedge aWedgeMaker (theWedgeDX, theWedgeDY, theWedgeDZ, theWedgeLtx);
115TopoDS_Solid aShape = aWedgeMaker.Solid();
116Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape); // creation of the presentable object
7863dabb 117aContext->Display (aShapePrs, AIS_Shaded, 0, true); // display the presentable object and redraw 3d viewer
bf62b306 118~~~~~
dba69de2 119
453103d1 120The shape is created using the *BRepPrimAPI_MakeWedge* command.
121An *AIS_Shape* is then created from the shape.
122When calling the *Display* command, the interactive context calls the Compute method of the presentable object to calculate the presentation data and transfer it to the viewer.
123See figure below.
72b7576f 124
d6b4d3d0 125@figure{visualization_image004.svg,"Processes involved in displaying a presentable shape",400}
72b7576f 126
7c42f3f4 127@subsection occt_visu_2_2 Selection
72b7576f 128
453103d1 129Standard OCCT selection algorithm is represented by 2 parts: dynamic and static.
130Dynamic selection causes objects to be automatically highlighted as the mouse cursor moves over them.
131Static selection allows to pick particular object (or objects) for further processing.
72b7576f 132
a7d4dd94 133There are 3 different selection types:
134 - **Point selection** -- allows picking and highlighting a single object (or its part) located under the mouse cursor;
135 - **Rectangle selection** -- allows picking objects or parts located under the rectangle defined by the start and end mouse cursor positions;
136 - **Polyline selection** -- allows picking objects or parts located under a user-defined non-self-intersecting polyline.
72b7576f 137
453103d1 138For OCCT selection algorithm, all selectable objects are represented as a set of sensitive zones, called **sensitive entities**.
139When the mouse cursor moves in the view, the sensitive entities of each object are analyzed for collision.
72b7576f 140
a7d4dd94 141@subsubsection occt_visu_2_2_1 Terms and notions
72b7576f 142
a7d4dd94 143This section introduces basic terms and notions used throughout the algorithm description.
72b7576f 144
7c42f3f4 145#### Sensitive entity
72b7576f 146
a7d4dd94 147Sensitive entities in the same way as entity owners are links between objects and the selection mechanism.
72b7576f 148
453103d1 149The purpose of entities is to define what parts of the object will be selectable in particular.
150Thus, any object that is meant to be selectable must be split into sensitive entities (one or several).
151For instance, to apply face selection to an object it is necessary to explode it into faces and use them for creation of a sensitive entity set.
72b7576f 152
d6b4d3d0 153@figure{visualization_image005.png,"Example of a shape divided into sensitive entities",400}
72b7576f 154
453103d1 155Depending on the user's needs, sensitive entities may be atomic (point or edge) or complex.
156Complex entities contain many sub-elements that can be handled by detection mechanism in a similar way
157(for example, a polyline stored as a set of line segments or a triangulation).
72b7576f 158
453103d1 159Entities are used as internal units of the selection algorithm and do not contain any topological data,
160hence they have a link to an upper-level interface that maintains topology-specific methods.
72b7576f 161
7c42f3f4 162#### Entity owner
72b7576f 163
453103d1 164Each *Select3D_SensitiveEntity* stores a reference to its owner *SelectMgr_EntityOwner*,
165which is a class connecting the entity and the corresponding selectable object (*SelectMgr_SelectableObject*).
166Besides, owners can store any additional information, for example, the topological shape of the sensitive entity, highlight colors and methods, or if the entity is selected or not.
72b7576f 167
7c42f3f4 168#### Selection
72b7576f 169
453103d1 170To simplify the handling of different selection modes of an object, sensitive entities linked to their owners are organized into sets, called **selections** (*SelectMgr_Selection*).
a7d4dd94 171Each selection contains entities created for a certain mode along with the sensitivity and update states.
72b7576f 172
7c42f3f4 173#### Selectable object
72b7576f 174
453103d1 175Selectable object (*SelectMgr_SelectableObject* or more precisely *AIS_InteractiveObject*) stores information about all created selection modes and sensitive entities.
a7d4dd94 176
453103d1 177All successors of a selectable object must implement the method that splits its presentation into sensitive entities according to the given mode.
178The computed entities are arranged in one selection and added to the list of all selections of this object.
179No selection will be removed from the list until the object is deleted permanently.
a7d4dd94 180
453103d1 181For all standard OCCT interactive objects, zero mode is supposed to select the whole object (but it may be redefined in the custom object).
182For example, the *AIS_Shape* object determine the following modes (see AIS_Shape::SelectionMode()):
183 - 0 -- selection of the entire object (AIS_Shape);
7863dabb 184 - 1 -- selection of the vertices (TopAbs_VERTEX);
185 - 2 -- selection of the edges (TopAbs_EDGE);
186 - 3 -- selection of the wires (TopAbs_WIRE);
187 - 4 -- selection of the faces (TopAbs_FACE);
188 - 5 -- selection of the shells (TopAbs_SHELL);
189 - 6 -- selection of the constituent solids (TopAbs_SOLID).
a7d4dd94 190
d6b4d3d0 191@figure{visualization_image006.png,"Hierarchy of references from sensitive entity to selectable object",400}
a7d4dd94 192
d6b4d3d0 193@figure{visualization_image007.png,"The principle of entities organization within the selectable object",400}
a7d4dd94 194
7c42f3f4 195#### Viewer selector
a7d4dd94 196
453103d1 197For each OCCT viewer there is a **Viewer selector** class *SelectMgr_ViewerSelector3d*.
198It provides a high-level API for the whole selection algorithm and encapsulates the processing of objects and sensitive entities for each mouse pick.
199The viewer selector maintains activation and deactivation of selection modes, launches the algorithm, which detects candidate entities to be picked,
200and stores its results, as well as implements an interface for keeping selection structures up-to-date.
a7d4dd94 201
7c42f3f4 202#### Selection manager
a7d4dd94 203
453103d1 204Selection manager *SelectMgr_SelectionManager* is a high-level API to manipulate selection of all displayed objects.
205It handles all viewer selectors, activates and deactivates selection modes for the objects in all or particular selectors,
206manages computation and update of selections for each object.
207Moreover, it keeps selection structures updated taking into account applied changes.
a7d4dd94 208
d6b4d3d0 209@figure{visualization_image008.png,"The relations chain between viewer selector and selection manager",400}
a7d4dd94 210
211@subsubsection occt_visu_2_2_2 Algorithm
212
453103d1 213All three types of OCCT selection are implemented as a single concept,
214based on the search for overlap between frustum and sensitive entity through 3-level BVH tree traversal.
a7d4dd94 215
7c42f3f4 216#### Selection Frustum
a7d4dd94 217
218The first step of each run of selection algorithm is to build the selection frustum according to the currently activated selection type.
219
453103d1 220For the point or the rectangular selection the base of the frustum is a rectangle built in conformity with the pixel tolerance or the dimensions of a user-defined area, respectively.
221For the polyline selection, the polygon defined by the constructed line is triangulated and each triangle is used as the base for its own frustum.
222Thus, this type of selection uses a set of triangular frustums for overlap detection.
a7d4dd94 223
224The frustum length is limited by near and far view volume planes and each plane is built parallel to the corresponding view volume plane.
225
d6b4d3d0 226@figure{visualization_image009.png,"",400}
72b7576f 227
d6b4d3d0 228The image above shows the rectangular frustum: a) after mouse move or click, b) after applying the rectangular selection.
229
230@figure{visualization_image010.png,"",400}
231
232In the image above triangular frustum is set: a) by a user-defined polyline, b) by triangulation of the polygon based on the given polyline, c) by a triangular frustum based on one of the triangles.
72b7576f 233
7c42f3f4 234#### BVH trees
72b7576f 235
a7d4dd94 236To maintain selection mechanism at the viewer level, a speedup structure composed of 3 BVH trees is used.
72b7576f 237
453103d1 238The first level tree is constructed of axis-aligned bounding boxes of each selectable object.
239Hence, the root of this tree contains the combination of all selectable boundaries even if they have no currently activated selections.
240Objects are added during the display of *AIS_InteractiveObject* and will be removed from this tree only when the object is destroyed.
241The 1st level BVH tree is build on demand simultaneously with the first run of the selection algorithm.
72b7576f 242
453103d1 243The second level BVH tree consists of all sensitive entities of one selectable object.
244The 2nd level trees are built automatically when the default mode is activated and rebuilt whenever a new selection mode is calculated for the first time.
72b7576f 245
453103d1 246The third level BVH tree is used for complex sensitive entities that contain many elements: for example, triangulations, wires with many segments, point sets, etc.
247It is built on demand for sensitive entities with more than 800K sub-elements (defined by *StdSelect_BRepSelectionTool::PreBuildBVH()*).
72b7576f 248
d6b4d3d0 249@figure{visualization_image022.png,"Selection BVH tree hierarchy: from the biggest object-level (first) to the smallest complex entity level (third)",400}
72b7576f 250
7c42f3f4 251#### Stages of the algorithm
72b7576f 252
a7d4dd94 253The algorithm includes pre-processing and three main stages.
72b7576f 254
7c42f3f4 255##### Pre-processing
256
257Implies calculation of the selection frustum and its main characteristics.
72b7576f 258
7c42f3f4 259##### First stage -- traverse of the first level BVH tree
72b7576f 260
453103d1 261After successful building of the selection frustum, the algorithm starts traversal of the object-level BVH tree.
262The nodes containing axis-aligned bounding boxes are tested for overlap with the selection frustum following the terms of *separating axis theorem (SAT)*.
263When the traversal goes down to the leaf node, it means that a candidate object with possibly overlapping sensitive entities has been found.
264If no such objects have been detected, the algorithm stops and it is assumed that no object needs to be selected.
265Otherwise it passes to the next stage to process the entities of the found selectable object.
7c42f3f4 266
267##### Second stage -- traversal of the second level BVH tree
72b7576f 268
a7d4dd94 269At this stage it is necessary to determine if there are candidates among all sensitive entities of one object.
72b7576f 270
453103d1 271First of all, at this stage the algorithm checks if there is any transformation applied for the current object.
272If it has its own location, then the correspondingly transformed frustum will be used for further calculations.
273At the next step the nodes of the second level BVH tree of the given object are visited to search for overlapping leaves.
274If no such leafs have been found, the algorithm returns to the second stage.
275Otherwise it starts processing the found entities by performing the following checks:
a7d4dd94 276 - activation check - the entity may be inactive at the moment as it belongs to deactivated selection;
453103d1 277 - tolerance check - current selection frustum may be too large for further checks as it is always built with the maximum tolerance among all activated entities;
278 thus, at this step the frustum may be scaled.
72b7576f 279
a7d4dd94 280After these checks the algorithm passes to the last stage.
72b7576f 281
7c42f3f4 282##### Third stage -- overlap or inclusion test of a particular sensitive entity
18006a0f 283
453103d1 284If the entity is atomic, a simple SAT test is performed.
285In case of a complex entity, the third level BVH tree is traversed.
286The quantitative characteristics (like depth, distance to the center of geometry) of matched sensitive entities is analyzed and clipping planes are applied (if they have been set).
287The result of detection is stored and the algorithm returns to the second stage.
72b7576f 288
a7d4dd94 289@subsubsection occt_visu_2_2_3 Packages and classes
72b7576f 290
7c42f3f4 291Selection is implemented as a combination of various algorithms divided among several packages -- *SelectBasics*, *Select3D*, *SelectMgr* and *StdSelect*.
18006a0f 292
7c42f3f4 293#### SelectBasics
18006a0f 294
453103d1 295*SelectBasics* package contains basic classes and interfaces for selection.
296The most notable are:
7c42f3f4 297 - *SelectBasics_PickResult* -- the structure for storing quantitative results of detection procedure, for example, depth and distance to the center of geometry;
298 - *SelectBasics_SelectingVolumeManager* -- the interface for interaction with the current selection frustum.
18006a0f 299
7c42f3f4 300Each custom sensitive entity must inherit at least *SelectBasics_SensitiveEntity*.
18006a0f 301
7c42f3f4 302#### Select3D
18006a0f 303
7c42f3f4 304*Select3D* package provides a definition of standard sensitive entities, such as:
a7d4dd94 305 - box;
306 - circle;
307 - curve;
308 - face;
309 - group;
310 - point;
311 - segment;
312 - triangle;
313 - triangulation;
314 - wire.
18006a0f 315
0ef04197 316Each basic sensitive entity inherits *Select3D_SensitiveEntity*.
7c42f3f4 317The package also contains two auxiliary classes, *Select3D_SensitivePoly* and *Select3D_SensitiveSet*.
18006a0f 318
0ef04197 319*Select3D_SensitiveEntity* -- the base definition of a sensitive entity.
320
453103d1 321*Select3D_SensitiveSet* -- a base class for all complex sensitive entities that require the third level BVH usage.
322It implements traverse of the tree and defines an interface for the methods that check sub-entities.
72b7576f 323
453103d1 324*Select3D_SensitivePoly* -- describes an arbitrary point set and implements basic functions for selection.
325It is important to know that this class does not perform any internal data checks.
326Hence, custom implementations of sensitive entity inherited from *Select3D_SensitivePoly* must satisfy the terms of Separating Axis Theorem to use standard OCCT overlap detection methods.
18006a0f 327
7c42f3f4 328#### SelectMgr
18006a0f 329
453103d1 330*SelectMgr* package is used to maintain the whole selection process.
331For this purpose, the package provides the following services:
a7d4dd94 332 - activation and deactivation of selection modes for all selectable objects;
333 - interfaces to compute selection mode of the object;
334 - definition of selection filter classes;
335 - keeping selection BVH data up-to-date.
18006a0f 336
a7d4dd94 337A brief description of the main classes:
453103d1 338 - *SelectMgr_BaseFrustum*, *SelectMgr_Frustum*, *SelectMgr_RectangularFrustum*, *SelectMgr_TriangularFrustum* and *SelectMgr_TriangularFrustumSet* -- interfaces and implementations of selecting frustums.
339 These classes implement different SAT tests for overlap and inclusion detection.
340 They also contain methods to measure characteristics of detected entities (depth, distance to center of geometry).
341 - *SelectMgr_SensitiveEntity*, *SelectMgr_Selection* and *SelectMgr_SensitiveEntitySet* -- store and handle sensitive entities.
342 *SelectMgr_SensitiveEntitySet* implements a primitive set for the second level BVH tree.
343 - *SelectMgr_SelectableObject* and *SelectMgr_SelectableObjectSet* -- describe selectable objects.
344 They also manage storage, calculation and removal of selections.
345 *SelectMgr_SelectableObjectSet* implements a primitive set for the first level BVH tree.
346 - *SelectMgr_ViewerSelector* -- encapsulates all logics of the selection algorithm and implements the third level BVH tree traverse.
7c42f3f4 347 - *SelectMgr_SelectionManager* -- manages activation/deactivation, calculation and update of selections of every selectable object, and keeps BVH data up-to-date.
18006a0f 348
7c42f3f4 349#### StdSelect
a7d4dd94 350
453103d1 351*StdSelect* package contains the implementation of some *SelectMgr* classes and tools for creation of selection structures.
352For example,
7c42f3f4 353 - *StdSelect_BRepOwner* -- defines an entity owner with a link to its topological shape and methods for highlighting;
354 - *StdSelect_BRepSelectionTool* -- contains algorithms for splitting standard AIS shapes into sensitive primitives;
7c42f3f4 355 - *StdSelect_FaceFilter*, *StdSelect_EdgeFilter* -- implementation of selection filters.
a7d4dd94 356
357@subsubsection occt_visu_2_2_4 Examples of usage
358
453103d1 359The first code snippet illustrates the implementation of *SelectMgr_SelectableObject::ComputeSelection()* method in a custom interactive object.
360The method is used for computation of user-defined selection modes.
a7d4dd94 361Let us assume it is required to make a box selectable in two modes -- the whole shape (mode 0) and each of its edges (mode 1).
453103d1 362To select the whole box, the application can create a sensitive primitive for each face of the interactive object.
363In this case, all primitives share the same owner -- the box itself.
364To select box's edge, the application must create one sensitive primitive per edge.
365Here all sensitive entities cannot share the owner since different geometric primitives must be highlighted as the result of selection procedure.
18006a0f 366
453103d1 367~~~~{.cpp}
7c42f3f4 368void InteractiveBox::ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
18006a0f 369 const Standard_Integer theMode)
370{
a7d4dd94 371 switch (theMode)
18006a0f 372 {
7c42f3f4 373 case 0: // creation of face sensitives for selection of the whole box
18006a0f 374 {
7c42f3f4 375 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this, 5);
376 for (Standard_Integer aFaceIter = 1; aFaceIter <= myNbFaces; ++aFaceIter)
377 {
378 Select3D_TypeOfSensitivity aSensType = myIsInterior;
453103d1 379 theSel->Add (new Select3D_SensitiveFace (anOwner, myFaces[aFaceIter]->PointArray(), aSensType));
7c42f3f4 380 }
381 break;
18006a0f 382 }
7c42f3f4 383 case 1: // creation of edge sensitives for selection of box edges only
18006a0f 384 {
7c42f3f4 385 for (Standard_Integer anEdgeIter = 1; anEdgeIter <= 12; ++anEdgeIter)
386 {
387 // 1 owner per edge, where 6 is a priority of the sensitive
388 Handle(MySelection_EdgeOwner) anOwner = new MySelection_EdgeOwner (this, anEdgeIter, 6);
453103d1 389 theSel->Add (new Select3D_SensitiveSegment (anOwner, myFirstPnt[anEdgeIter]), myLastPnt[anEdgeIter]));
7c42f3f4 390 }
391 break;
18006a0f 392 }
393 }
394}
18006a0f 395~~~~
396
453103d1 397The algorithms for creating selection structures store sensitive primitives in *SelectMgr_Selection* instance.
398Each *SelectMgr_Selection* sequence in the list of selections of the object must correspond to a particular selection mode.
399To describe the decomposition of the object into selectable primitives, a set of ready-made sensitive entities is supplied in *Select3D* package.
400Custom sensitive primitives can be defined through inheritance from *Select3D_SensitiveEntity*.
401To make custom interactive objects selectable or customize selection modes of existing objects, the entity owners must be defined.
402They must inherit *SelectMgr_EntityOwner* interface.
a7d4dd94 403
7c42f3f4 404Selection structures for any interactive object are created in *SelectMgr_SelectableObject::ComputeSelection()* method.
405The example below shows how computation of different selection modes of the topological shape can be done using standard OCCT mechanisms, implemented in *StdSelect_BRepSelectionTool*.
18006a0f 406
453103d1 407~~~~{.cpp}
a7d4dd94 408 void MyInteractiveObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
409 const Standard_Integer theMode)
18006a0f 410 {
411 switch (theMode)
412 {
7c42f3f4 413 case 0: StdSelect_BRepSelectionTool::Load (theSelection, this, myShape, TopAbs_SHAPE); break;
414 case 1: StdSelect_BRepSelectionTool::Load (theSelection, this, myShape, TopAbs_VERTEX); break;
415 case 2: StdSelect_BRepSelectionTool::Load (theSelection, this, myShape, TopAbs_EDGE); break;
416 case 3: StdSelect_BRepSelectionTool::Load (theSelection, this, myShape, TopAbs_WIRE); break;
417 case 4: StdSelect_BRepSelectionTool::Load (theSelection, this, myShape, TopAbs_FACE); break;
18006a0f 418 }
419 }
420~~~~
421
7c42f3f4 422The *StdSelect_BRepSelectionTool* class provides a high level API for computing sensitive entities of the given type (for example, face, vertex, edge, wire and others) using topological data from the given *TopoDS_Shape*.
18006a0f 423
453103d1 424The traditional way of highlighting selected entity owners adopted by Open CASCADE Technology assumes that each entity owner highlights itself on its own.
425This approach has two drawbacks:
18006a0f 426
7863dabb 427 - each entity owner has to maintain its own *Graphic3d_Structure* object, that results in a considerable memory overhead;
7c42f3f4 428 - drawing selected owners one by one is not efficient from the visualization point of view.
72b7576f 429
453103d1 430Therefore, to overcome these limitations, OCCT has an alternative way to implement the highlighting of a selected presentation.
431Using this approach, the interactive object itself will be responsible for the highlighting, not the entity owner.
18006a0f 432
453103d1 433On the basis of *SelectMgr_EntityOwner::IsAutoHilight()* return value, *AIS_InteractiveContext* object either uses the traditional way of highlighting
434(in case if *IsAutoHilight()* returns TRUE) or groups such owners according to their selectable objects and finally calls *SelectMgr_SelectableObject::HilightSelected()* or *SelectMgr_SelectableObject::ClearSelected()*,
435passing a group of owners as an argument.
18006a0f 436
453103d1 437Hence, an application can derive its own interactive object and redefine virtual methods *HilightSelected()*, *ClearSelected()* and *HilightOwnerWithColor()* from *SelectMgr_SelectableObject*.
438*SelectMgr_SelectableObject::GetHilightPresentation* and *SelectMgr_SelectableObject::GetSelectPresentation* methods can be used to optimize filling of selection and highlight presentations according to the user's needs.
72b7576f 439
453103d1 440After all the necessary sensitive entities are computed and packed in *SelectMgr_Selection* instance with the corresponding owners
441in a redefinition of *SelectMgr_SelectableObject::ComputeSelection()* method,
442it is necessary to register the prepared selection in *SelectMgr_SelectionManager* through the following steps:
7c42f3f4 443 - if there was no *AIS_InteractiveContext* opened, create an interactive context and display the selectable object in it;
453103d1 444 - load the selectable object to the selection manager of the interactive context using *AIS_InteractiveContext::Load()* method.
445 If the selection mode passed as a parameter to this method is not equal to -1, *ComputeSelection()* for this selection mode will be called;
7c42f3f4 446 - activate or deactivate the defined selection mode using *AIS_InteractiveContext::Activate()* or *AIS_InteractiveContext::Deactivate()* methods.
72b7576f 447
7c42f3f4 448After these steps, the selection manager of the created interactive context will contain the given object and its selection entities, and they will be involved in the detection procedure.
72b7576f 449
453103d1 450The code snippet below illustrates the above steps.
451It also contains the code to start the detection procedure and parse the results of selection.
72b7576f 452
453103d1 453~~~~~{.cpp}
a7d4dd94 454// Suppose there is an instance of class InteractiveBox from the previous sample.
455// It contains an implementation of method InteractiveBox::ComputeSelection() for selection
456// modes 0 (whole box must be selected) and 1 (edge of the box must be selectable)
7c42f3f4 457Handle(InteractiveBox) theBox;
458Handle(AIS_InteractiveContext) theContext;
a7d4dd94 459// To prevent automatic activation of the default selection mode
7c42f3f4 460theContext->SetAutoActivateSelection (false);
461theContext->Display (theBox, false);
a7d4dd94 462
463// Load a box to the selection manager without computation of any selection mode
7c42f3f4 464theContext->Load (theBox, -1, true);
a7d4dd94 465// Activate edge selection
7c42f3f4 466theContext->Activate (theBox, 1);
a7d4dd94 467
7c42f3f4 468// Run the detection mechanism for activated entities in the current mouse coordinates and in the current view.
469// Detected owners will be highlighted with context highlight color
7863dabb 470theContext->MoveTo (aXMousePos, aYMousePos, myView, false);
a7d4dd94 471// Select the detected owners
7c42f3f4 472theContext->Select();
a7d4dd94 473// Iterate through the selected owners
7c42f3f4 474for (theContext->InitSelected(); theContext->MoreSelected() && !aHasSelected; theContext->NextSelected())
a7d4dd94 475{
7c42f3f4 476 Handle(AIS_InteractiveObject) anIO = theContext->SelectedInteractive();
a7d4dd94 477}
72b7576f 478
a7d4dd94 479// deactivate all selection modes for aBox1
7c42f3f4 480theContext->Deactivate (aBox1);
bf62b306 481~~~~~
72b7576f 482
a7d4dd94 483It is also important to know, that there are 2 types of detection implemented for rectangular selection in OCCT:
453103d1 484 - <b>inclusive</b> detection.
485 In this case the sensitive primitive is considered detected only when all its points are included in the area defined by the selection rectangle;
486 - <b>overlap</b> detection.
487 In this case the sensitive primitive is considered detected when it is partially overlapped by the selection rectangle.
72b7576f 488
453103d1 489The standard OCCT selection mechanism uses inclusion detection by default.
490To change this, use the following code:
72b7576f 491
453103d1 492~~~~~{.cpp}
7c42f3f4 493// Assume there is a created interactive context
494const Handle(AIS_InteractiveContext) theContext;
a7d4dd94 495// Retrieve the current viewer selector
7c42f3f4 496const Handle(StdSelect_ViewerSelector3d)& aMainSelector = theContext->MainSelector();
a7d4dd94 497// Set the flag to allow overlap detection
7c42f3f4 498aMainSelector->AllowOverlapDetection (true);
a7d4dd94 499~~~~~
72b7576f 500
7c42f3f4 501@section occt_visu_3 Application Interactive Services
502@subsection occt_visu_3_1 Introduction
72b7576f 503
7c42f3f4 504Application Interactive Services allow managing presentations and dynamic selection in a viewer in a simple and transparent manner.
453103d1 505The central entity for management of visualization and selections is the **Interactive Context** (*AIS_InteractiveContext*).
506It is connected to the main viewer (*V3d_Viewer*).
72b7576f 507
453103d1 508Interactive context by default starts at **Neutral Point** with each selectable object picked as a whole,
509but the user might activate **Local Selection** for specific objects to make selectable parts of the objects.
7c42f3f4 510Local/global selection is managed by a list of selection modes activated for each displayed object with 0 (default selection mode) usually meaning Global (entire object) selection.
72b7576f 511
453103d1 512**Interactive Objects** (*AIS_InteractiveObject*) are the entities, which are visualized and selected.
513You can use classes of standard interactive objects for which all necessary functions have already been programmed,
514or you can implement your own classes of interactive objects, by respecting a certain number of rules and conventions described below.
72b7576f 515
453103d1 516An Interactive Object is a "virtual" entity, which can be presented and selected.
517An Interactive Object can have a certain number of specific graphic attributes, such as visualization mode, color and material.
518When an Interactive Object is visualized, the required graphic attributes are taken from its own **Drawer** (*Prs3d_Drawer*)
519if it has the required custom attributes or otherwise from the context drawer.
72b7576f 520
d6b4d3d0 521@figure{visualization_image017.png,"",360}
72b7576f 522
453103d1 523It can be necessary to filter the entities to be selected.
524Consequently there are **Filter** entities (*SelectMgr_Filter*), which allow refining the dynamic detection context.
525Some of these filters can be used only within at the Neutral Point, others only within Local Selection.
526It is possible to program custom filters and load them into the interactive context.
72b7576f 527
bf62b306 528@subsection occt_visu_3_2 Interactive objects
72b7576f 529
453103d1 530Entities which are visualized and selected in the AIS viewer are objects (*AIS_InteractiveObject*).
531They connect the underlying reference geometry of a model to its graphic representation in *AIS*.
532You can use the predefined OCCT classes of standard interactive objects, for which all necessary functions have already been programmed,
533or, if you are an advanced user, you can implement your own classes of interactive objects.
18006a0f 534
bf62b306 535@subsubsection occt_visu_3_2_1 Presentations
72b7576f 536
7c42f3f4 537An interactive object can have as many presentations as its creator wants to give it.
453103d1 5383D presentations are managed by **Presentation Manager** (*PrsMgr_PresentationManager*).
539As this is transparent in AIS, the user does not have to worry about it.
72b7576f 540
7c42f3f4 541A presentation is identified by an index (*Display Mode*) and by the reference to the Presentation Manager, which it depends on.
542By convention, the default mode of representation for the Interactive Object has index 0.
72b7576f 543
d6b4d3d0 544@figure{visualization_image018.png,"",360}
72b7576f 545
453103d1 546Calculation of different presentations of an interactive object is done by the *Compute* functions inheriting from *PrsMgr_PresentableObject::Compute* functions.
547They are automatically called by *PresentationManager* at a visualization or an update request.
72b7576f 548
7c42f3f4 549If you are creating your own type of interactive object, you must implement the Compute function in one of the following ways:
72b7576f 550
bf62b306 551#### For 3D:
72b7576f 552
453103d1 553~~~~~{.cpp}
7c42f3f4 554void PackageName_ClassName::Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
555 const Handle(Prs3d_Presentation)& thePresentation,
556 const Standard_Integer theMode);
bf62b306 557~~~~~
72b7576f 558
7c42f3f4 559#### For hidden line removal (HLR) mode in 3D:
7863dabb 560
453103d1 561~~~~~{.cpp}
7c42f3f4 562void PackageName_ClassName::Compute (const Handle(Prs3d_Projector)& theProjector,
563 const Handle(Prs3d_Presentation)& thePresentation);
bf62b306 564~~~~~
72b7576f 565
bf62b306 566@subsubsection occt_visu_3_2_2 Hidden Line Removal
72b7576f 567
453103d1 568The view can have two states: the normal mode or the computed mode (Hidden Line Removal mode).
569When the latter is active, the view looks for all presentations displayed in the normal mode, which have been signaled as accepting HLR mode.
570An internal mechanism allows calling the interactive object's own *Compute*, that is projector function.
72b7576f 571
453103d1 572By convention, the Interactive Object accepts or rejects the representation of HLR mode.
573It is possible to make this declaration in one of two ways:
72b7576f 574
7863dabb 575* Initially by using one of the values of the enumeration *PrsMgr_TypeOfPresentation3d*:
bf62b306 576 * *PrsMgr_TOP_AllView*,
577 * *PrsMgr_TOP_ProjectorDependant*
72b7576f 578
7c42f3f4 579* Later by using the function *PrsMgr_PresentableObject::SetTypeOfPresentation*
72b7576f 580
7c42f3f4 581*AIS_Shape* class is an example of an interactive object that supports HLR representation.
453103d1 582The type of the HLR algorithm is stored in *Prs3d_Drawer* of the shape.
583It is a value of the *Prs3d_TypeOfHLR* enumeration and can be set to:
7c42f3f4 584 * *Prs3d_TOH_PolyAlgo* for a polygonal algorithm based on the shape's triangulation;
585 * *Prs3d_TOH_Algo* for an exact algorithm that works with the shape's real geometry;
586 * *Prs3d_TOH_NotSet* if the type of algorithm is not set for the given interactive object instance.
72b7576f 587
7c42f3f4 588The type of the HLR algorithm used for *AIS_Shape* can be changed by calling the *AIS_Shape::SetTypeOfHLR()* method.
589The current HLR algorithm type can be obtained using *AIS_Shape::TypeOfHLR()* method is to be used.
72b7576f 590
453103d1 591These methods get the value from the drawer of *AIS_Shape*.
592If the HLR algorithm type in the *Prs3d_Drawer* is set to *Prs3d_TOH_NotSet*, the *Prs3d_Drawer* gets the value from the default drawer of *AIS_InteractiveContext*.
593So it is possible to change the default HLR algorithm used by all newly displayed interactive objects.
594The value of the HLR algorithm type stored in the context drawer can be *Prs3d_TOH_Algo* or *Prs3d_TOH_PolyAlgo*.
595The polygonal algorithm is the default one.
72b7576f 596
bf62b306 597@subsubsection occt_visu_3_2_3 Presentation modes
72b7576f 598
7c42f3f4 599There are four types of interactive objects in AIS:
600 * the "construction element" or Datum,
601 * the Relation (dimensions and constraints)
602 * the Object
603 * the None type (when the object is of an unknown type).
72b7576f 604
453103d1 605Inside these categories, additional characterization is available by means of a signature (an index).
606By default, the interactive object has a NONE type and a signature of 0 (equivalent to NONE).
607If you want to give a particular type and signature to your interactive object, you must redefine two virtual functions:
7c42f3f4 608 * *AIS_InteractiveObject::Type*
609 * *AIS_InteractiveObject::Signature*.
72b7576f 610
7c42f3f4 611**Note** that some signatures are already used by "standard" objects provided in AIS (see the @ref occt_visu_3_5 "List of Standard Interactive Object Classes").
72b7576f 612
453103d1 613The interactive context can have a default mode of representation for the set of interactive objects.
614This mode may not be accepted by a given class of objects.
7c42f3f4 615Consequently, to get information about this class it is necessary to use virtual function *AIS_InteractiveObject::AcceptDisplayMode*.
72b7576f 616
bf62b306 617#### Display Mode
72b7576f 618
453103d1 619The functions *AIS_InteractiveContext::SetDisplayMode* and *AIS_InteractiveContext::UnsetDisplayMode* allow setting a custom display mode for an objects,
620which can be different from that proposed by the interactive context.
72b7576f 621
bf62b306 622#### Highlight Mode
72b7576f 623
7c42f3f4 624At dynamic detection, the presentation echoed by the Interactive Context, is by default the presentation already on the screen.
72b7576f 625
453103d1 626The functions *AIS_InteractiveObject::SetHilightMode* and *AIS_InteractiveObject::UnsetHilightMode* allow specifying the display mode used for highlighting (so called highlight mode),
627which is valid independently from the active representation of the object.
628It makes no difference whether this choice is temporary or definitive.
72b7576f 629
453103d1 630Note that the same presentation (and consequently the same highlight mode) is used for highlighting *detected* objects and for highlighting *selected* objects,
631the latter being drawn with a special *selection color* (refer to the section related to *Interactive Context* services).
72b7576f 632
453103d1 633For example, you want to systematically highlight the wireframe presentation of a shape - non regarding if it is visualized in wireframe presentation or with shading.
634Thus, you set the highlight mode to *0* in the constructor of the interactive object.
635Do not forget to implement this representation mode in the *Compute* functions.
72b7576f 636
bf62b306 637#### Infinite Status
7c42f3f4 638
453103d1 639If you do not want an object to be affected by a *FitAll* view, you must declare it infinite;
640you can cancel its "infinite" status using *AIS_InteractiveObject::SetInfiniteState* and *AIS_InteractiveObject::IsInfinite* functions.
7c42f3f4 641
642Let us take for example the class called *IShape* representing an interactive object:
643
453103d1 644~~~~~{.cpp}
7863dabb 645myPk_IShape::myPk_IShape (const TopoDS_Shape& theShape, PrsMgr_TypeOfPresentation theType)
7c42f3f4 646: AIS_InteractiveObject (theType), myShape (theShape) { SetHilightMode (0); }
647
7863dabb 648Standard_Boolean myPk_IShape::AcceptDisplayMode (const Standard_Integer theMode) const
649{
650 return theMode == 0 || theMode == 1;
651}
652
7c42f3f4 653void myPk_IShape::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
654 const Handle(Prs3d_Presentation)& thePrs,
655 const Standard_Integer theMode)
656{
657 switch (theMode)
658 {
659 // algo for calculation of wireframe presentation
660 case 0: StdPrs_WFDeflectionShape::Add (thePrs, myShape, myDrawer); return;
661 // algo for calculation of shading presentation
662 case 1: StdPrs_ShadedShape::Add (thePrs, myShape, myDrawer); return;
663 }
664}
665
666void myPk_IShape::Compute (const Handle(Prs3d_Projector)& theProjector,
667 const Handle(Prs3d_Presentation)& thePrs)
668{
669 // Hidden line mode calculation algorithm
670 StdPrs_HLRPolyShape::Add (thePrs, myShape, myDrawer, theProjector);
bf62b306 671}
672~~~~~
72b7576f 673
7c42f3f4 674@subsubsection occt_visu_3_2_4 Selection
72b7576f 675
453103d1 676An interactive object can have an indefinite number of selection modes, each representing a "decomposition" into sensitive primitives.
677Each primitive has an **Owner** (*SelectMgr_EntityOwner*) which allows identifying the exact interactive object or shape which has been detected (see @ref occt_visu_2_2 "Selection" chapter).
72b7576f 678
7c42f3f4 679The set of sensitive primitives, which correspond to a given mode, is stocked in a **Selection** (*SelectMgr_Selection*).
72b7576f 680
453103d1 681Each selection mode is identified by an index.
682By convention, the default selection mode that allows us to grasp the interactive object in its entirety is mode *0*.
683However, it can be modified in the custom interactive objects using method *SelectMgr_SelectableObject::setGlobalSelMode()*.
72b7576f 684
453103d1 685The calculation of selection primitives (or sensitive entities) is done in a virtual function *ComputeSelection*.
686It should be implemented for each type of interactive object that is assumed to have different selection modes using the function *AIS_InteractiveObject::ComputeSelection*.
a7d4dd94 687A detailed explanation of the mechanism and the manner of implementing this function has been given in @ref occt_visu_2_2 "Selection" chapter.
72b7576f 688
453103d1 689There are some examples of selection mode calculation for the most widely used interactive object in OCCT -- *AIS_Shape* (selection by vertex, by edges, etc).
690To create new classes of interactive objects with the same selection behavior as *AIS_Shape* -- such as vertices and edges -- you must redefine the virtual function *AIS_InteractiveObject::AcceptShapeDecomposition*.
2683e647 691
bf62b306 692@subsubsection occt_visu_3_2_5 Graphic attributes
72b7576f 693
7c42f3f4 694Graphic attributes manager, or *Prs3d_Drawer*, stores graphic attributes for specific interactive objects and for interactive objects controlled by interactive context.
18006a0f 695
696Initially, all drawer attributes are filled out with the predefined values which will define the default 3D object appearance.
18006a0f 697When an interactive object is visualized, the required graphic attributes are first taken from its own drawer if one exists, or from the context drawer if no specific drawer for that type of object exists.
698
699Keep in mind the following points concerning graphic attributes:
7c42f3f4 700 * Each interactive object can have its own visualization attributes.
453103d1 701 * By default, the interactive object takes the graphic attributes of the context in which it is visualized
702 (visualization mode, deflection values for the calculation of presentations, number of isoparameters, color, type of line, material, etc.)
703 * In the *AIS_InteractiveObject* abstract class, standard attributes including color, line thickness, material, and transparency have been privileged.
704 Consequently, there is a certain number of virtual functions, which allow acting on these attributes.
705 Each new class of interactive object can redefine these functions and change the behavior of the class.
72b7576f 706
7c42f3f4 707@figure{visualization_image020.svg,"Redefinition of virtual functions for changes in AIS_Shape and AIS_TextLabel.",360}
72b7576f 708
7c42f3f4 709The following virtual functions provide settings for color, width, material and transparency:
710 * *AIS_InteractiveObject::UnsetColor*
711 * *AIS_InteractiveObject::SetWidth*
712 * *AIS_InteractiveObject::UnsetWidth*
713 * *AIS_InteractiveObject::SetMaterial*
714 * *AIS_InteractiveObject::UnsetMaterial*
715 * *AIS_InteractiveObject::SetTransparency*
716 * *AIS_InteractiveObject::UnsetTransparency*
72b7576f 717
7c42f3f4 718These methods can be used as a shortcut assigning properties in common way, but result might be not available.
719Some interactive objects might not implement these methods at all or implement only a sub-set of them.
720Direct modification of *Prs3d_Drawer* properties returned by *AIS_InteractiveObject::Attributes* can be used for more precise and predictable configuration.
72b7576f 721
7c42f3f4 722It is important to know which functions may imply the recalculation of presentations of the object.
723If the presentation mode of an interactive object is to be updated, a flag from *PrsMgr_PresentableObject* indicates this.
724The mode can be updated using the functions *Display* and *Redisplay* in *AIS_InteractiveContext*.
72b7576f 725
7c42f3f4 726@subsubsection occt_visu_3_2_6 Complementary Services
72b7576f 727
7c42f3f4 728When you use complementary services for interactive objects, pay special attention to the cases mentioned below.
72b7576f 729
bf62b306 730#### Change the location of an interactive object
72b7576f 731
7c42f3f4 732The following functions allow "moving" the representation and selection of Interactive Objects in a view without recalculation (and modification of the original shape).
733 * *AIS_InteractiveContext::SetLocation*
734 * *AIS_InteractiveContext::ResetLocation*
735 * *AIS_InteractiveContext::HasLocation*
736 * *AIS_InteractiveContext::Location*
72b7576f 737
7c42f3f4 738#### Connect an interactive object to an applicative entity
72b7576f 739
7863dabb 740Each Interactive Object has functions that allow attributing it an *GetOwner* in form of a *Transient*.
7c42f3f4 741 * *AIS_InteractiveObject::SetOwner*
742 * *AIS_InteractiveObject::HasOwner*
7863dabb 743 * *AIS_InteractiveObject::GetOwner*
72b7576f 744
7c42f3f4 745An interactive object can therefore be associated or not with an applicative entity, without affecting its behavior.
72b7576f 746
7863dabb 747**NOTE:** Don't be confused by owners of another kind - *SelectMgr_EntityOwner* used for identifying selectable parts of the object or object itself.
72b7576f 748
7c42f3f4 749#### Resolving coincident topology
72b7576f 750
7c42f3f4 751Due to the fact that the accuracy of three-dimensional graphics coordinates has a finite resolution the elements of topological objects can coincide producing the effect of "popping" some elements one over another.
72b7576f 752
453103d1 753To the problem when the elements of two or more Interactive Objects are coincident you can apply the polygon offset.
754It is a sort of graphics computational offset, or depth buffer offset, that allows you to arrange elements (by modifying their depth value) without changing their coordinates.
755The graphical elements that accept this kind of offsets are solid polygons or displayed as boundary lines and points.
756The polygons could be displayed as lines or points by setting the appropriate interior style.
72b7576f 757
7c42f3f4 758The methods *AIS_InteractiveObject::SetPolygonOffsets* and *AIS_InteractiveContext::SetPolygonOffsets* allow setting up the polygon offsets.
ebcbd824 759
760@subsubsection occt_visu_3_2_7 Object hierarchy
761
762Each *PrsMgr_PresentableObject* has a list of objects called *myChildren*.
453103d1 763Any transformation of *PrsMgr_PresentableObject* is also applied to its children.
764This hierarchy does not propagate to *Graphic3d* level and below.
ebcbd824 765
766*PrsMgr_PresentableObject* sends its combined (according to the hierarchy) transformation down to *Graphic3d_Structure*.
ebcbd824 767The materials of structures are not affected by the hierarchy.
768
769Object hierarchy can be controlled by the following API calls:
7c42f3f4 770* *PrsMgr_PresentableObject::AddChild*;
771* *PrsMgr_PresentableObject::RemoveChild*.
ebcbd824 772
773@subsubsection occt_visu_3_2_8 Instancing
774
775The conception of instancing operates the object hierarchy as follows:
7c42f3f4 776* Instances are represented by separated *AIS* objects.
777* Instances do not compute any presentations.
ebcbd824 778
779Classes *AIS_ConnectedInteractive* and *AIS_MultipleConnectedInteractive* are used to implement this conception.
780
453103d1 781*AIS_ConnectedInteractive* is an object instance, which reuses the geometry of the connected object but has its own transformation and visibility flag.
782This connection is propagated down to *OpenGl* level, namely to *OpenGl_Structure*.
783*OpenGl_Structure* can be connected only to a single other structure.
ebcbd824 784
453103d1 785*AIS_ConnectedInteractive* can be referenced to any *AIS_InteractiveObject* in general.
786When it is referenced to another *AIS_ConnectedInteractive*, it just copies the reference.
ebcbd824 787
453103d1 788*AIS_MultipleConnectedInteractive* represents an assembly, which does not have its own presentation.
789The assemblies are able to participate in the object hierarchy and are intended to handle a grouped set of instanced objects.
790It behaves as a single object in terms of selection.
791It applies high level transformation to all sub-elements since it is located above in the hierarchy.
ebcbd824 792
453103d1 793All *AIS_MultipleConnectedInteractive* are able to have child assemblies.
794Deep copy of object instances tree is performed if one assembly is attached to another.
ebcbd824 795
453103d1 796Note that *AIS_ConnectedInteractive* cannot reference *AIS_MultipleConnectedInteractive*.
797*AIS_ConnectedInteractive* copies sensitive entities of the origin object for selection, unlike *AIS_MultipleConnectedInteractive* that re-uses the entities of the origin object.
ebcbd824 798
799Instances can be controlled by the following DRAW commands:
7c42f3f4 800* *vconnect* : Creates and displays *AIS_MultipleConnectedInteractive* object from input objects and location.
801* *vconnectto* : Makes an instance of object with the given position.
802* *vdisconnect* : Disconnects all objects from an assembly or disconnects an object by name or number.
803* *vaddconnected* : Adds an object to the assembly.
804* *vlistconnected* : Lists objects in the assembly.
ebcbd824 805
806Have a look at the examples below:
807~~~~~
453103d1 808pload MODELING VISUALIZATION
ebcbd824 809vinit
810psphere s 1
811vdisplay s
812vconnectto s2 3 0 0 s # make instance
813vfit
814~~~~~
815
816See how proxy *OpenGl_Structure* is used to represent instance:
817
d6b4d3d0 818@figure{/user_guides/visualization/images/visualization_image029.png,"",240}
ebcbd824 819
453103d1 820The original object does not have to be displayed in order to make instance.
821Also selection handles transformations of instances correctly:
ebcbd824 822
823~~~~~
453103d1 824pload MODELING VISUALIZATION
ebcbd824 825vinit
826psphere s 1
827psphere p 0.5
828vdisplay s # p is not displayed
829vsetloc s -2 0 0
830vconnect x 3 0 0 s p # make assembly
831vfit
832~~~~~
833
d6b4d3d0 834@figure{/user_guides/visualization/images/visualization_image030.png,"",420}
ebcbd824 835
836Here is the example of a more complex hierarchy involving sub-assemblies:
837
838~~~~~
453103d1 839pload MODELING VISUALIZATION
ebcbd824 840vinit
841box b 1 1 1
842psphere s 0.5
843vdisplay b s
844vsetlocation s 0 2.5 0
845box d 0.5 0.5 3
846box d2 0.5 3 0.5
847vdisplay d d2
848
849vconnectto b1 -2 0 0 b
850vconnect z 2 0 0 b s
851vconnect z2 4 0 0 d d2
852vconnect z3 6 0 0 z z2
853vfit
854~~~~~
855
7c42f3f4 856@subsection occt_visu_3_3 Interactive Context
ebcbd824 857
7c42f3f4 858@subsubsection occt_visu_3_3_1 Rules
72b7576f 859
453103d1 860The Interactive Context allows managing in a transparent way the graphic and **selectable** behavior of interactive objects in one or more viewers.
861Most functions which allow modifying the attributes of interactive objects, and which were presented in the preceding chapter, will be looked at again here.
72b7576f 862
453103d1 863There is one essential rule to follow: the modification of an interactive object, which is already known by the Context, must be done using Context functions.
864You can only directly call the functions available for an interactive object if it has not been loaded into an Interactive Context.
72b7576f 865
453103d1 866~~~~~{.cpp}
7c42f3f4 867Handle(AIS_Shape) aShapePrs = new AIS_Shape (theShape);
868myIntContext->Display (aShapePrs, AIS_Shaded, 0, false, aShapePrs->AcceptShapeDecomposition());
869myIntContext->SetColor(aShapePrs, Quantity_NOC_RED);
bf62b306 870~~~~~
72b7576f 871
7c42f3f4 872You can also write
72b7576f 873
453103d1 874~~~~~{.cpp}
7c42f3f4 875Handle(AIS_Shape) aShapePrs = new AIS_Shape (theShape);
876aShapePrs->SetColor (Quantity_NOC_RED);
877aShapePrs->SetDisplayMode (AIS_Shaded);
878myIntContext->Display (aShapePrs);
bf62b306 879~~~~~
72b7576f 880
7c42f3f4 881@subsubsection occt_visu_3_3_2 Groups of functions
72b7576f 882
453103d1 883**Neutral Point** and **Local Selection** constitute the two operating modes or states of the **Interactive Context**,
884which is the central entity which pilots visualizations and selections.
7c42f3f4 885The **Neutral Point**, which is the default mode, allows easily visualizing and selecting interactive objects, which have been loaded into the context.
886Activating **Local Selection** for specific Objects allows selecting of their sub-parts.
72b7576f 887
7c42f3f4 888@subsubsection occt_visu_3_3_3 Management of the Interactive Context
18006a0f 889
453103d1 890An interactive object can have a certain number of specific graphic attributes, such as visualization mode, color, and material.
891Correspondingly, the interactive context has a set of graphic attributes, the *Drawer*, which is valid by default for the objects it controls.
7c42f3f4 892When an interactive object is visualized, the required graphic attributes are first taken from the object's own *Drawer* if it exists, or from the context drawer if otherwise.
18006a0f 893
7c42f3f4 894The following adjustable settings allow personalizing the behavior of presentations and selections:
895 * Default Drawer, containing all the color and line attributes which can be used by interactive objects, which do not have their own attributes.
896 * Default Visualization Mode for interactive objects. By default: *mode 0*;
897 * Highlight color of entities detected by mouse movement. By default: *Quantity_NOC_CYAN1*;
898 * Pre-selection color. By default: *Quantity_NOC_GREEN*;
899 * Selection color (when you click on a detected object). By default: *Quantity_NOC_GRAY80*;
72b7576f 900
453103d1 901All of these settings can be modified by functions proper to the AIS_InteractiveContext.
7c42f3f4 902When you change a graphic attribute pertaining to the Context (visualization mode, for example), all interactive objects, which do not have the corresponding appropriate attribute, are updated.
18006a0f 903
7c42f3f4 904Let us examine the case of two interactive objects: *theObj1* and *theObj2*:
72b7576f 905
453103d1 906~~~~~{.cpp}
7c42f3f4 907theCtx->Display (theObj1, false);
908theCtx->Display (theObj2, true); // TRUE for viewer update
909theCtx->SetDisplayMode (theObj1, 3, false);
910theCtx->SetDisplayMode (2, true);
453103d1 911// theObj2 is visualized in mode 2 (if it accepts this mode)
912// theObj1 stays visualized in its mode 3
bf62b306 913~~~~~
72b7576f 914
453103d1 915*PrsMgr_PresentationManager* and *SelectMgr_ViewerSelector3d*, which manage the presentation and selection of present interactive objects, are associated to the main Viewer.
72b7576f 916
7863dabb 917*WARNING!* Do NOT use integer values (like in sample above) in real code - use appropriate enumerations instead!
918Each presentable object has independent list of supported display and selection modes; for instance, *AIS_DisplayMode* enumeration is applicable only to *AIS_Shape* presentations.
919
7c42f3f4 920@subsection occt_visu_3_4 Local Selection
72b7576f 921
7c42f3f4 922@subsubsection occt_visu_3_4_1 Selection Modes
72b7576f 923
453103d1 924The Local Selection is defined by index (Selection Mode).
925The Selection Modes implemented by a specific interactive object and their meaning should be checked within the documentation of this class.
7c42f3f4 926See, for example, *MeshVS_SelectionModeFlags* for *MeshVS_Mesh* object.
72b7576f 927
453103d1 928*AIS_Shape* is the most used interactive object.
929It provides API to manage selection operations on the constituent elements of shapes (selection of vertices, edges, faces, etc.).
930The Selection Mode for a specific shape type (*TopAbs_ShapeEnum*) is returned by method *AIS_Shape::SelectionMode()*.
72b7576f 931
7863dabb 932The method *AIS_InteractiveContext::Display()* without a Selection Mode argument activates the default Selection Mode of the object.
14deaf42 933The methods *AIS_InteractiveContext::Activate()* and *AIS_InteractiveContext::Deactivate()* activate and deactivate a specific Selection Mode.
72b7576f 934
7c42f3f4 935More than one Selection Mode can be activated at the same time (but default 0 mode for selecting entire object is exclusive - it cannot be combined with others).
936The list of active modes can be retrieved using function *AIS_InteractiveContext::ActivatedModes*.
72b7576f 937
7c42f3f4 938@subsubsection occt_visu_3_4_2 Filters
bf62b306 939
7c42f3f4 940To define an environment of dynamic detection, you can use standard filter classes or create your own.
453103d1 941A filter questions the owner of the sensitive primitive to determine if it has the desired qualities.
942If it answers positively, it is kept. If not, it is rejected.
bf62b306 943
453103d1 944The root class of objects is *SelectMgr_Filter*.
945The principle behind it is straightforward: a filter tests to see whether the owners (*SelectMgr_EntityOwner*) detected in mouse position by selector answer *OK*.
946If so, it is kept, otherwise it is rejected.
7c42f3f4 947You can create a custom class of filter objects by implementing the deferred function *SelectMgr_Filter::IsOk()*.
72b7576f 948
453103d1 949In *SelectMgr*, there are also Composition filters (AND Filters, OR Filters), which allow combining several filters.
950In Interactive Context, all filters that you add are stored in an OR filter (which answers *OK* if at least one filter answers *OK*).
72b7576f 951
7c42f3f4 952There are Standard filters, which have already been implemented in several packages:
953 * *StdSelect_EdgeFilter* -- for edges, such as lines and circles;
954 * *StdSelect_FaceFilter* -- for faces, such as planes, cylinders and spheres;
955 * *StdSelect_ShapeTypeFilter* -- for shape types, such as compounds, solids, shells and wires;
956 * *AIS_TypeFilter* -- for types of interactive objects;
957 * *AIS_SignatureFilter* -- for types and signatures of interactive objects;
958 * *AIS_AttributeFilter* -- for attributes of Interactive Objects, such as color and width.
72b7576f 959
7c42f3f4 960There are several functions to manipulate filters:
961* *AIS_InteractiveContext::AddFilter* adds a filter passed as an argument.
962* *AIS_InteractiveContext::RemoveFilter* removes a filter passed as an argument.
963* *AIS_InteractiveContext::RemoveFilters* removes all present filters.
964* *AIS_InteractiveContext::Filters* gets the list of filters active in a context.
72b7576f 965
7c42f3f4 966#### Example
72b7576f 967
453103d1 968~~~~~{.cpp}
7c42f3f4 969// shading visualization mode, no specific mode, authorization for decomposition into sub-shapes
970const TopoDS_Shape theShape;
971Handle(AIS_Shape) aShapePrs = new AIS_Shape (theShape);
972myContext->Display (aShapePrs, AIS_Shaded, -1, true, true);
72b7576f 973
7c42f3f4 974// activates decomposition of shapes into faces
975const int aSubShapeSelMode = AIS_Shape::SelectionMode (TopAbs_Face);
976myContext->Activate (aShapePrs, aSubShapeSelMode);
72b7576f 977
7c42f3f4 978Handle(StdSelect_FaceFilter) aFil1 = new StdSelect_FaceFilter (StdSelect_Revol);
979Handle(StdSelect_FaceFilter) aFil2 = new StdSelect_FaceFilter (StdSelect_Plane);
980myContext->AddFilter (aFil1);
981myContext->AddFilter (aFil2);
72b7576f 982
7c42f3f4 983// only faces of revolution or planar faces will be selected
7863dabb 984myContext->MoveTo (thePixelX, thePixelY, myView, true);
bf62b306 985~~~~~
72b7576f 986
7c42f3f4 987@subsubsection occt_visu_3_4_6 Selection
72b7576f 988
453103d1 989Dynamic detection and selection are put into effect in a straightforward way.
990There are only a few conventions and functions to be familiar with:
7c42f3f4 991 * *AIS_InteractiveContext::MoveTo* -- passes mouse position to Interactive Context selectors.
453103d1 992 * *AIS_InteractiveContext::Select* -- stores what has been detected at the last *MoveTo*.
993 Replaces the previously selected object.
994 Empties the stack if nothing has been detected at the last move.
995 * *AIS_InteractiveContext::ShiftSelect* -- if the object detected at the last move was not already selected, it is added to the list of the selected objects.
996 If not, it is withdrawn. Nothing happens if you click on an empty area.
7c42f3f4 997 * *AIS_InteractiveContext::Select* -- selects everything found in the surrounding area.
998 * *AIS_InteractiveContext::ShiftSelect* -- selects what was not previously in the list of selected, deselects those already present.
bf62b306 999
453103d1 1000Highlighting of detected and selected entities is automatically managed by the Interactive Context.
1001The Highlight colors are those dealt with above. You can nonetheless disconnect this automatic mode if you want to manage this part yourself:
1002~~~~~{.cpp}
7c42f3f4 1003 AIS_InteractiveContext::SetAutomaticHilight
1004 AIS_InteractiveContext::AutomaticHilight
bf62b306 1005~~~~~
72b7576f 1006
453103d1 1007You can question the Interactive context by moving the mouse.
1008The following functions can be used:
7c42f3f4 1009 * *AIS_InteractiveContext::HasDetected* -- checks if there is a detected entity;
1010 * *AIS_InteractiveContext::DetectedOwner* -- returns the (currently highlighted) detected entity.
bf62b306 1011
453103d1 1012After using the *Select* and *ShiftSelect* functions, you can explore the list of selections.
1013The following functions can be used:
7c42f3f4 1014 * *AIS_InteractiveContext::InitSelected* -- initializes an iterator;
1015 * *AIS_InteractiveContext::MoreSelected* -- checks if the iterator is valid;
1016 * *AIS_InteractiveContext::NextSelected* -- moves the iterator to the next position;
1017 * *AIS_InteractiveContext::SelectedOwner* -- returns an entity at the current iterator position.
72b7576f 1018
14deaf42 1019The owner object *SelectMgr_EntityOwner* is a key object identifying the selectable entity in the viewer (returned by methods *AIS_InteractiveContext::DetectedOwner* and *AIS_InteractiveContext::SelectedOwner*).
1020The Interactive Object itself can be retrieved by method *SelectMgr_EntityOwner::Selectable*, while identifying a sub-part depends on the type of Interactive Object.
7c42f3f4 1021In case of *AIS_Shape*, the (sub)shape is returned by method *StdSelect_BRepOwner::Shape*.
72b7576f 1022
7c42f3f4 1023#### Example
7863dabb 1024
453103d1 1025~~~~~{.cpp}
7c42f3f4 1026for (myAISCtx->InitSelected(); myAISCtx->MoreSelected(); myAISCtx->NextSelected())
bf62b306 1027{
7c42f3f4 1028 Handle(SelectMgr_EntityOwner) anOwner = myAISCtx->SelectedOwner();
1029 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
1030 if (Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner))
1031 {
1032 // to be able to use the picked shape
1033 TopoDS_Shape aShape = aBRepOwner->Shape();
1034 }
bf62b306 1035}
1036~~~~~
72b7576f 1037
7c42f3f4 1038@subsection occt_visu_3_5 Standard Interactive Object Classes
72b7576f 1039
18006a0f 1040Interactive Objects are selectable and viewable objects connecting graphic representation and the underlying reference geometry.
1041
1042They are divided into four types:
3f812249 1043 * the **Datum** -- a construction geometric element;
1044 * the **Relation** -- a constraint on the interactive shape and the corresponding reference geometry;
1045 * the **Object** -- a topological shape or connection between shapes;
1046 * **None** -- a token, that instead of eliminating the object, tells the application to look further until it finds an acceptable object definition in its generation.
18006a0f 1047
453103d1 1048Inside these categories, there is a possibility of additional characterization by means of a signature.
1049The signature provides an index to the further characterization.
1050By default, the **Interactive Object** has a *None* type and a signature of 0 (equivalent to *None*).
7c42f3f4 1051If you want to give a particular type and signature to your interactive object, you must redefine the two virtual methods: *Type* and *Signature*.
18006a0f 1052
1053@subsubsection occt_visu_3_5_1 Datum
1054
1055The **Datum** groups together the construction elements such as lines, circles, points, trihedrons, plane trihedrons, planes and axes.
7c42f3f4 1056
1057*AIS_Point, AIS_Axis, AIS_Line, AIS_Circle, AIS_Plane* and *AIS_Trihedron* have four selection modes:
7863dabb 1058 * mode AIS_TrihedronSelectionMode_EntireObject : selection of a trihedron;
1059 * mode AIS_TrihedronSelectionMode_Origin : selection of the origin of the trihedron;
1060 * mode AIS_TrihedronSelectionMode_Axes : selection of the axes;
1061 * mode AIS_TrihedronSelectionMode_MainPlanes : selection of the planes XOY, YOZ, XOZ.
7c42f3f4 1062
7863dabb 1063when you activate one of modes, you pick AIS objects of type:
7c42f3f4 1064 * *AIS_Point*;
1065 * *AIS_Axis* (and information on the type of axis);
1066 * *AIS_Plane* (and information on the type of plane).
1067
1068*AIS_PlaneTrihedron* offers three selection modes:
1069 * mode 0 : selection of the whole trihedron;
1070 * mode 1 : selection of the origin of the trihedron;
3f812249 1071 * mode 2 : selection of the axes -- same remarks as for the Trihedron.
72b7576f 1072
453103d1 1073For the presentation of planes and trihedra, the default length unit is millimeter and the default value for the representation of axes is 10.
1074To modify these dimensions, you must temporarily recover the object **Drawer**.
1075From it, take the *DatumAspect()* and change the value *FirstAxisLength*.
1076Finally, recalculate the presentation.
e5bd0d98 1077
18006a0f 1078@subsubsection occt_visu_3_5_2 Object
1079
1080The **Object** type includes topological shapes, and connections between shapes.
e5bd0d98 1081
7c42f3f4 1082*AIS_Shape* has two visualization modes:
7863dabb 1083 * mode AIS_WireFrame : Line (default mode)
1084 * mode AIS_Shaded : Shading (depending on the type of shape)
72b7576f 1085
453103d1 1086*AIS_ConnectedInteractive* is an Interactive Object connecting to another interactive object reference,
1087and located elsewhere in the viewer makes it possible not to calculate presentation and selection, but to deduce them from your object reference.
1088*AIS_MultipleConnectedInteractive* is an object connected to a list of interactive objects
1089(which can also be Connected objects; it does not require memory-hungry presentation calculations).
72b7576f 1090
453103d1 1091*MeshVS_Mesh* is an Interactive Object that represents meshes, it has a data source that provides geometrical information (nodes, elements)
1092and can be built up from the source data with a custom presentation builder.
18006a0f 1093
1094The class *AIS_ColoredShape* allows using custom colors and line widths for *TopoDS_Shape* objects and their sub-shapes.
1095
453103d1 1096~~~~~{.cpp}
18006a0f 1097 AIS_ColoredShape aColoredShape = new AIS_ColoredShape (theShape);
1098
1099 // setup color of entire shape
7c42f3f4 1100 aColoredShape->SetColor (Quantity_NOC_RED);
18006a0f 1101
1102 // setup line width of entire shape
1103 aColoredShape->SetWidth (1.0);
1104
1105 // set transparency value
1106 aColoredShape->SetTransparency (0.5);
1107
1108 // customize color of specified sub-shape
7c42f3f4 1109 aColoredShape->SetCustomColor (theSubShape, Quantity_NOC_BLUE1);
18006a0f 1110
1111 // customize line width of specified sub-shape
1112 aColoredShape->SetCustomWidth (theSubShape, 0.25);
1113~~~~~
1114
453103d1 1115The presentation class *AIS_PointCloud* can be used for efficient drawing of large arbitrary sets of colored points.
1116It uses *Graphic3d_ArrayOfPoints* to pass point data into OpenGl graphic driver to draw a set points as an array of "point sprites".
1117The point data is packed into vertex buffer object for performance.
18006a0f 1118- The type of point marker used to draw points can be specified as a presentation aspect.
453103d1 1119- The presentation provides selection by a bounding box of the visualized set of points.
1120 It supports two display / highlighting modes: points or bounding box.
18006a0f 1121
d6b4d3d0 1122@figure{point_cloud.png,"A random colored cloud of points",240}
18006a0f 1123
1124Example:
453103d1 1125~~~~~{.cpp}
18006a0f 1126Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (2000, Standard_True);
1127aPoints->AddVertex (gp_Pnt(-40.0, -40.0, -40.0), Quantity_Color (Quantity_NOC_BLUE1));
1128aPoints->AddVertex (gp_Pnt (40.0, 40.0, 40.0), Quantity_Color (Quantity_NOC_BLUE2));
1129
1130Handle(AIS_PointCloud) aPntCloud = new AIS_PointCloud();
1131aPntCloud->SetPoints (aPoints);
1132~~~~~
1133
1134The draw command *vpointcloud* builds a cloud of points from shape triangulation.
1135This command can also draw a sphere surface or a volume with a large amount of points (more than one million).
1136
bf62b306 1137@subsubsection occt_visu_3_5_3 Relations
18006a0f 1138
453103d1 1139The **Relation** is made up of constraints on one or more interactive shapes and the corresponding reference geometry.
1140For example, you might want to constrain two edges in a parallel relation.
1141This constraint is considered as an object in its own right, and is shown as a sensitive primitive.
1142This takes the graphic form of a perpendicular arrow marked with the || symbol and lying between the two edges.
18006a0f 1143
787ff240 1144The following relations are provided by *PrsDim*:
1145 * *PrsDim_ConcentricRelation*
1146 * *PrsDim_FixRelation*
1147 * *PrsDim_IdenticRelation*
1148 * *PrsDim_ParallelRelation*
1149 * *PrsDim_PerpendicularRelation*
1150 * *PrsDim_Relation*
1151 * *PrsDim_SymmetricRelation*
1152 * *PrsDim_TangentRelation*
72b7576f 1153
7c42f3f4 1154The list of relations is not exhaustive.
72b7576f 1155
bf62b306 1156@subsubsection occt_visu_3_5_4 Dimensions
787ff240 1157 * *PrsDim_AngleDimension*
1158 * *PrsDim_Chamf3dDimension*
1159 * *PrsDim_DiameterDimension*
1160 * *PrsDim_DimensionOwner*
1161 * *PrsDim_LengthDimension*
1162 * *PrsDim_OffsetDimension*
1163 * *PrsDim_RadiusDimension*
72b7576f 1164
7c42f3f4 1165@subsubsection occt_visu_3_5_5 MeshVS_Mesh
72b7576f 1166
453103d1 1167*MeshVS_Mesh* is an Interactive Object that represents meshes.
1168This object differs from the *AIS_Shape* as its geometrical data is supported by the data source *MeshVS_DataSource* that describes nodes and elements of the object.
1169As a result, you can provide your own data source.
72b7576f 1170
7c42f3f4 1171However, the *DataSource* does not provide any information on attributes, for example nodal colors, but you can apply them in a special way -- by choosing the appropriate presentation builder.
72b7576f 1172
453103d1 1173The presentations of *MeshVS_Mesh* are built with the presentation builders *MeshVS_PrsBuilder*.
1174You can choose between the builders to represent the object in a different way.
1175Moreover, you can redefine the base builder class and provide your own presentation builder.
72b7576f 1176
7c42f3f4 1177You can add/remove builders using the following methods:
453103d1 1178~~~~~{.cpp}
7c42f3f4 1179 MeshVS_Mesh::AddBuilder (const Handle(MeshVS_PrsBuilder)& theBuilder, Standard_Boolean theToTreatAsHilighter);
1180 MeshVS_Mesh::RemoveBuilder (const Standard_Integer theIndex);
1181 MeshVS_Mesh::RemoveBuilderById (const Standard_Integer theId);
bf62b306 1182~~~~~
72b7576f 1183
453103d1 1184There is a set of reserved display and highlighting mode flags for *MeshVS_Mesh*.
1185Mode value is a number of bits that allows selecting additional display parameters and combining the following mode flags,
1186which allow displaying mesh in wireframe, shading and shrink modes:
1187~~~~~{.cpp}
bf62b306 1188 MeshVS_DMF_WireFrame
1189 MeshVS_DMF_Shading
1190 MeshVS_DMF_Shrink
7c42f3f4 1191~~~~~
72b7576f 1192
453103d1 1193It is also possible to display deformed mesh in wireframe, shading or shrink modes using:
1194~~~~~{.cpp}
7c42f3f4 1195 MeshVS_DMF_DeformedPrsWireFrame
1196 MeshVS_DMF_DeformedPrsShading
1197 MeshVS_DMF_DeformedPrsShrink
bf62b306 1198~~~~~
72b7576f 1199
7c42f3f4 1200The following methods represent different kinds of data:
453103d1 1201~~~~~{.cpp}
7c42f3f4 1202 MeshVS_DMF_VectorDataPrs
bf62b306 1203 MeshVS_DMF_NodalColorDataPrs
1204 MeshVS_DMF_ElementalColorDataPrs
1205 MeshVS_DMF_TextDataPrs
1206 MeshVS_DMF_EntitiesWithData
7c42f3f4 1207~~~~~
bf62b306 1208
7c42f3f4 1209The following methods provide selection and highlighting:
453103d1 1210~~~~~{.cpp}
bf62b306 1211 MeshVS_DMF_SelectionPrs
1212 MeshVS_DMF_HilightPrs
7c42f3f4 1213~~~~~
72b7576f 1214
7c42f3f4 1215*MeshVS_DMF_User* is a user-defined mode.
72b7576f 1216
7c42f3f4 1217These values will be used by the presentation builder.
1218There is also a set of selection modes flags that can be grouped in a combination of bits:
bf62b306 1219 * *MeshVS_SMF_0D*
1220 * *MeshVS_SMF_Link*
1221 * *MeshVS_SMF_Face*
1222 * *MeshVS_SMF_Volume*
7c42f3f4 1223 * *MeshVS_SMF_Element* -- groups *0D, Link, Face* and *Volume* as a bit mask;
bf62b306 1224 * *MeshVS_SMF_Node*
7c42f3f4 1225 * *MeshVS_SMF_All* -- groups *Element* and *Node* as a bit mask;
bf62b306 1226 * *MeshVS_SMF_Mesh*
1227 * *MeshVS_SMF_Group*
1228
7c42f3f4 1229Such an object, for example, can be used for displaying the object and stored in the STL file format:
72b7576f 1230
453103d1 1231~~~~~{.cpp}
bf62b306 1232// read the data and create a data source
4178b353 1233Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFileName);
1234Handle(XSDRAWSTLVRML_DataSource) aDataSource = new XSDRAWSTLVRML_DataSource (aSTLMesh);
72b7576f 1235
7c42f3f4 1236// create mesh
1237Handle(MeshVS_Mesh) aMeshPrs = new MeshVS();
1238aMeshPrs->SetDataSource (aDataSource);
72b7576f 1239
bf62b306 1240// use default presentation builder
7c42f3f4 1241Handle(MeshVS_MeshPrsBuilder) aBuilder = new MeshVS_MeshPrsBuilder (aMeshPrs);
1242aMeshPrs->AddBuilder (aBuilder, true);
bf62b306 1243~~~~~
72b7576f 1244
7c42f3f4 1245*MeshVS_NodalColorPrsBuilder* allows representing a mesh with a color scaled texture mapped on it.
1246To do this you should define a color map for the color scale, pass this map to the presentation builder, and define an appropriate value in the range of 0.0 - 1.0 for every node.
1247The following example demonstrates how you can do this (check if the view has been set up to display textures):
bf62b306 1248
453103d1 1249~~~~~{.cpp}
bf62b306 1250// assign nodal builder to the mesh
7c42f3f4 1251Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder (theMeshPrs, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
1252aBuilder->UseTexture (true);
bf62b306 1253
1254// prepare color map
7c42f3f4 1255Aspect_SequenceOfColor aColorMap;
1256aColorMap.Append (Quantity_NOC_RED);
1257aColorMap.Append (Quantity_NOC_BLUE1);
bf62b306 1258
1259// assign color scale map values (0..1) to nodes
7c42f3f4 1260TColStd_DataMapOfIntegerReal aScaleMap;
2683e647 1261...
bf62b306 1262// iterate through the nodes and add an node id and an appropriate value to the map
7c42f3f4 1263aScaleMap.Bind (anId, aValue);
1264
bf62b306 1265// pass color map and color scale values to the builder
7c42f3f4 1266aBuilder->SetColorMap (aColorMap);
1267aBuilder->SetInvalidColor (Quantity_NOC_BLACK);
1268aBuilder->SetTextureCoords (aScaleMap);
1269aMesh->AddBuilder (aBuilder, true);
bf62b306 1270~~~~~
72b7576f 1271
7c42f3f4 1272@subsection occt_visu_3_6 Dynamic Selection
72b7576f 1273
453103d1 1274The dynamic selection represents the topological shape, which you want to select,
1275by decomposition of *sensitive primitives* -- the sub-parts of the shape that will be detected and highlighted.
1276The sets of these primitives are handled by the powerful three-level BVH tree selection algorithm.
72b7576f 1277
07f2b741 1278For more details on the algorithm and examples of usage, refer to @ref occt_visu_2_2 "Selection" chapter.
72b7576f 1279
bf62b306 1280@section occt_visu_4 3D Presentations
72b7576f 1281
7c42f3f4 1282@subsection occt_visu_4_1 Glossary of 3D terms
72b7576f 1283
453103d1 1284* **Group** -- a set of primitives and attributes on those primitives.
1285 Primitives and attributes may be added to a group but cannot be removed from it, unless erased globally.
1286 A group can have a pick identity.
1287* **Light**
1288 There are five kinds of light source -- ambient, headlight, directional, positional and spot.
1289* **Primitive** -- a drawable element.
1290 It has a definition in 3D space.
1291 Primitives can either be lines, faces, text, or markers.
1292 Once displayed markers and text remain the same size.
1293 Lines and faces can be modified e.g. zoomed.
1294 Attributes are set within the group.
1295 Primitives must be stored in a group.
1296* **Structure** -- manages a set of groups.
1297 The groups are mutually exclusive.
1298 A structure can be edited, adding or removing groups.
1299 A structure can reference other structures to form a hierarchy.
1300 It has a default (identity) transformation and other transformations may be applied to it (rotation, translation, scale, etc).
1301 Each structure has a display priority associated with it, which rules the order in which it is redrawn in a 3D viewer.
7c42f3f4 1302* **View** -- is defined by a view orientation, a view mapping, and a context view.
3f812249 1303* **Viewer** -- manages a set of views.
1304* **View orientation** -- defines the manner in which the observer looks at the scene in terms of View Reference Coordinates.
453103d1 1305* **View mapping** -- defines the transformation from View Reference Coordinates to the Normalized Projection Coordinates.
1306 This follows the Phigs scheme.
1307* **Z-Buffering** -- a form of hidden surface removal in shading mode only.
1308 This is always active for a view in the shading mode and cannot be suppressed.
72b7576f 1309
18006a0f 1310@subsection occt_visu_4_2 Graphic primitives
72b7576f 1311
453103d1 1312The *Graphic3d* package is used to create 3D graphic objects in a 3D viewer.
1313These objects called **structures** are made up of groups of primitives, such as line segments, triangles, text and markers,
1314and attributes, such as color, transparency, reflection, line type, line width, and text font.
1315A group is the smallest editable element of a structure.
1316A transformation can be applied to a structure.
1317Structures can be connected to form a tree of structures, composed by transformations.
1318Structures are globally manipulated by the viewer.
72b7576f 1319
7c42f3f4 1320Graphic structures can be:
1321 * Displayed,
1322 * Highlighted,
1323 * Erased,
1324 * Transformed,
18006a0f 1325 * Connected to form a tree hierarchy of structures, created by transformations.
7c42f3f4 1326
1327There are classes for:
1328 * Visual attributes for lines, faces, markers, text, materials,
1329 * Vectors and vertices,
1330 * Graphic objects, groups, and structures.
72b7576f 1331
18006a0f 1332@subsubsection occt_visu_4_2_2 Structure hierarchies
bf62b306 1333
453103d1 1334The root is the top of a structure hierarchy or structure network.
1335The attributes of a parent structure are passed to its descendants.
1336The attributes of the descendant structures do not affect the parent.
1337Recursive structure networks are not supported.
18006a0f 1338
1339@subsubsection occt_visu_4_2_3 Graphic primitives
7c42f3f4 1340* **Markers**
1341 * Have one or more vertices,
1342 * Have a type, a scale factor, and a color,
1343 * Have a size, shape, and orientation independent of transformations.
1344* **Triangulation**
14deaf42 1345 * Has at least three vertices,
1346 * Has nodal normals defined for shading,
1347 * Has interior attributes -- style, color, front and back material, texture and reflection ratio.
7c42f3f4 1348* **Polylines** or **Segments**
1349 * Have two or more vertices,
1350 * Have the following attributes -- type, width scale factor, color.
1351* **Text**
1352 * Has geometric and non-geometric attributes,
1353 * Geometric attributes -- character height, character up vector, text path, horizontal and vertical alignment, orientation, three-dimensional position, zoomable flag
1354 * Non-geometric attributes -- text font, character spacing, character expansion factor, color.
1355
1356@subsubsection occt_visu_4_2_4 Primitive arrays
1357
1358The different types of primitives could be presented with the following primitive arrays:
bf62b306 1359 * *Graphic3d_ArrayOfPoints,*
bf62b306 1360 * *Graphic3d_ArrayOfPolylines,*
bf62b306 1361 * *Graphic3d_ArrayOfSegments,*
1362 * *Graphic3d_ArrayOfTriangleFans,*
1363 * *Graphic3d_ArrayOfTriangles,*
1364 * *Graphic3d_ArrayOfTriangleStrips.*
1365
7c42f3f4 1366The *Graphic3d_ArrayOfPrimitives* is a base class for these primitive arrays.
1367Method set *Graphic3d_ArrayOfPrimitives::AddVertex* allows adding vertices to the primitive array with their attributes (color, normal, texture coordinates).
1368You can also modify the values assigned to the vertex or query these values by the vertex index.
bf62b306 1369
7c42f3f4 1370The following example shows how to define an array of points:
72b7576f 1371
453103d1 1372~~~~~{.cpp}
bf62b306 1373// create an array
7c42f3f4 1374Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (theVerticiesMaxCount);
bf62b306 1375
1376// add vertices to the array
7c42f3f4 1377anArray->AddVertex (10.0, 10.0, 10.0);
1378anArray->AddVertex (0.0, 10.0, 10.0);
72b7576f 1379
bf62b306 1380// add the array to the structure
7c42f3f4 1381Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
1382aGroup->AddPrimitiveArray (anArray);
1383aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect());
bf62b306 1384~~~~~
72b7576f 1385
7c42f3f4 1386If the primitives share the same vertices (polygons, triangles, etc.) then you can define them as indices of the vertices array.
453103d1 1387The method *Graphic3d_ArrayOfPrimitives::AddEdge* allows defining the primitives by indices.
1388This method adds an "edge" in the range *[1, VertexNumber()]* in the array.
7c42f3f4 1389It is also possible to query the vertex defined by an edge using method *Graphic3d_ArrayOfPrimitives::Edge*.
72b7576f 1390
7c42f3f4 1391The following example shows how to define an array of triangles:
72b7576f 1392
453103d1 1393~~~~~{.cpp}
bf62b306 1394// create an array
453103d1 1395Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (theVerticesMaxCount, theEdgesMaxCount, Graphic3d_ArrayFlags_None);
bf62b306 1396// add vertices to the array
7c42f3f4 1397anArray->AddVertex (-1.0, 0.0, 0.0); // vertex 1
1398anArray->AddVertex ( 1.0, 0.0, 0.0); // vertex 2
1399anArray->AddVertex ( 0.0, 1.0, 0.0); // vertex 3
1400anArray->AddVertex ( 0.0,-1.0, 0.0); // vertex 4
bf62b306 1401
1402// add edges to the array
453103d1 1403anArray->AddEdges (1, 2, 3); // first triangle
1404anArray->AddEdges (1, 2, 4); // second triangle
bf62b306 1405
1406// add the array to the structure
7c42f3f4 1407Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
1408aGroup->AddPrimitiveArray (anArray);
1409aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
bf62b306 1410~~~~~
1411
18006a0f 1412@subsubsection occt_visu_4_2_5 Text primitive
72b7576f 1413
453103d1 1414*TKOpenGl* toolkit renders text labels using texture fonts.
1415*Graphic3d* text primitives have the following features:
7c42f3f4 1416 * fixed size (non-zoomable) or zoomable,
72b7576f 1417 * can be rotated to any angle in the view plane,
1418 * support unicode charset.
1419
7c42f3f4 1420The text attributes for the group could be defined with the *Graphic3d_AspectText3d* attributes group.
1421To add any text to the graphic structure you can use the following methods:
453103d1 1422~~~~~{.cpp}
7863dabb 1423void Graphic3d_Group::AddText (const Handle(Graphic3d_Text)& theTextParams,
1424 const Standard_Boolean theToEvalMinMax);
1425~~~~~
14deaf42 1426
453103d1 1427You can pass FALSE as *theToEvalMinMax* if you do not want the Graphic3d structure boundaries to be affected by the text position.
7c42f3f4 1428
1429**Note** that the text orientation angle can be defined by *Graphic3d_AspectText3d* attributes.
72b7576f 1430
bf62b306 1431See the example:
453103d1 1432~~~~~{.cpp}
bf62b306 1433// get the group
7c42f3f4 1434Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
72b7576f 1435
7c42f3f4 1436// change the text aspect
1437Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d();
1438aTextAspect->SetTextZoomable (true);
1439aTextAspect->SetTextAngle (45.0);
1440aGroup->SetPrimitivesAspect (aTextAspect);
72b7576f 1441
7c42f3f4 1442// add a text primitive to the structure
7863dabb 1443Handle(Graphic3d_Text) aText = new Graphic3d_Text (16.0f);
1444aText->SetText ("Text");
1445aText->SetPosition (gp_Pnt (1, 1, 1));
1446aGroup->AddText (aText);
bf62b306 1447~~~~~
1448
18006a0f 1449@subsubsection occt_visu_4_2_6 Materials
1450
453103d1 1451A *Graphic3d_MaterialAspect* defines the following Common material properties:
18006a0f 1452 * Transparency;
3f812249 1453 * Diffuse reflection -- a component of the object color;
18006a0f 1454 * Ambient reflection;
453103d1 1455 * Specular reflection -- a component of the color of the light source.
18006a0f 1456
1457The following items are required to determine the three colors of reflection:
1458 * Color;
1459 * Coefficient of diffuse reflection;
1460 * Coefficient of ambient reflection;
1461 * Coefficient of specular reflection.
1462
453103d1 1463Common material properties are used within Gouraud and Phong shading models (Graphic3d_TOSM_FACET, Graphic3d_TOSM_VERTEX and Graphic3d_TOSM_FRAGMENT).
1464Within PBR shading model (Graphic3d_TOSM_PBR and Graphic3d_TOSM_PBR_FACET), material properties are defined by the following *Graphic3d_PBRMaterial* properties (Graphic3d_MaterialAspect::PBRMaterial()):
1465 * Albedo (main color);
1466 * Metallic factor;
1467 * Roughness factor;
1468 * Transparency;
1469 * Index of refraction.
1470
18006a0f 1471@subsubsection occt_visu_4_2_7 Textures
1472
1473A *texture* is defined by a name.
1474Three types of texture are available:
1475 * 1D;
1476 * 2D;
1477 * Environment mapping.
1478
453103d1 1479@subsubsection occt_visu_4_2_8 Custom shaders
18006a0f 1480
453103d1 1481OCCT visualization core supports GLSL shaders.
1482Custom shaders can be assigned to a generic presentation by its drawer attributes (Graphic3d aspects).
1483To enable custom shader for a specific AIS_Shape in your application, the following API functions can be used:
18006a0f 1484
453103d1 1485~~~~~{.cpp}
18006a0f 1486// Create shader program
1487Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
1488
1489// Attach vertex shader
7c42f3f4 1490aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, "<Path to VS>"));
18006a0f 1491
1492// Attach fragment shader
7c42f3f4 1493aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, "<Path to FS>"));
18006a0f 1494
1495// Set values for custom uniform variables (if they are)
7c42f3f4 1496aProgram->PushVariable ("MyColor", Graphic3d_Vec3 (0.0f, 1.0f, 0.0f));
18006a0f 1497
7c42f3f4 1498// Set aspect property for specific AIS_Shape
18006a0f 1499theAISShape->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);
1500~~~~~
72b7576f 1501
18006a0f 1502@subsection occt_visu_4_3 Graphic attributes
72b7576f 1503
18006a0f 1504@subsubsection occt_visu_4_3_1 Aspect package overview
72b7576f 1505
18006a0f 1506The *Aspect* package provides classes for the graphic elements in the viewer:
1507 * Groups of graphic attributes;
1508 * Edges, lines, background;
1509 * Window;
1510 * Driver;
1511 * Enumerations for many of the above.
72b7576f 1512
18006a0f 1513@subsection occt_visu_4_4 3D view facilities
72b7576f 1514
18006a0f 1515@subsubsection occt_visu_4_4_1 Overview
72b7576f 1516
453103d1 1517The *V3d* package provides the resources to define a 3D viewer and the views attached to this viewer (orthographic, perspective).
1518This package provides the commands to manipulate the graphic scene of any 3D object visualized in a view on screen.
72b7576f 1519
7c42f3f4 1520A set of high-level commands allows the separate manipulation of parameters and the result of a projection (Rotations, Zoom, Panning, etc.) as well as the visualization attributes (Mode, Lighting, Clipping, etc.) in any particular view.
bf62b306 1521
453103d1 1522The *V3d* package is basically a set of tools directed by commands from the viewer front-end.
1523This tool set contains methods for creating and editing classes of the viewer such as:
7c42f3f4 1524 * Default parameters of the viewer,
1525 * Views (orthographic, perspective),
1526 * Lighting (positional, directional, ambient, spot, headlight),
89a929ea 1527 * Clipping planes,
453103d1 1528 * Instantiated sequences of views, planes, light sources, graphic structures, and picks,
7c42f3f4 1529 * Various package methods.
72b7576f 1530
18006a0f 1531@subsubsection occt_visu_4_4_2 A programming example
72b7576f 1532
cfece3ef 1533This sample TEST program for the *V3d* Package uses primary packages *Xw* and *Graphic3d* and secondary packages *Visual3d, Aspect, Quantity* and *math*.
1534
453103d1 1535~~~~~{.cpp}
7c42f3f4 1536// create a default display connection
cfece3ef 1537Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
7c42f3f4 1538// create a Graphic Driver
cfece3ef 1539Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection);
7c42f3f4 1540// create a Viewer to this Driver
453103d1 1541Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver);
1542aViewer->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET);
cfece3ef 1543// Create a structure in this Viewer
0784d6e3 1544Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (aViewer->StructureManager());
453103d1 1545aStruct->SetVisual (Graphic3d_TOS_SHADING); // Type of structure
e6c8fcfe 1546
4ee1bdf4 1547// Create a group of primitives in this structure
0784d6e3 1548Handle(Graphic3d_Group) aPrsGroup = aStruct->NewGroup();
e6c8fcfe 1549
cfece3ef 1550// Fill this group with one quad of size 100
1551Handle(Graphic3d_ArrayOfTriangleStrips) aTriangles = new Graphic3d_ArrayOfTriangleStrips (4);
1552aTriangles->AddVertex (-100./2., -100./2., 0.0);
1553aTriangles->AddVertex (-100./2., 100./2., 0.0);
1554aTriangles->AddVertex ( 100./2., -100./2., 0.0);
1555aTriangles->AddVertex ( 100./2., 100./2., 0.0);
e6c8fcfe 1556
0784d6e3 1557Handle(Graphic3d_AspectFillArea3d) anAspects = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, Quantity_NOC_RED,
1558 Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0f,
1559 Graphic3d_NOM_GOLD, Graphic3d_NOM_GOLD);
1560aPrsGroup->SetGroupPrimitivesAspect (anAspects);
7c42f3f4 1561aPrsGroup->AddPrimitiveArray (aTriangles);
e6c8fcfe 1562
7c42f3f4 1563// Create Ambient and Infinite Lights in this Viewer
453103d1 1564Handle(V3d_AmbientLight) aLight1 = new V3d_AmbientLight (Quantity_NOC_GRAY50);
0784d6e3 1565Handle(V3d_DirectionalLight) aLight2 = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE, true);
453103d1 1566aViewer->AddLight (aLight1);
1567aViewer->AddLight (aLight2);
0784d6e3 1568aViewer->SetLightOn();
e6c8fcfe 1569
4ee1bdf4 1570// Create a 3D quality Window with the same DisplayConnection
453103d1 1571Handle(Xw_Window) aWindow = new Xw_Window (aDispConnection, "Test V3d", 100, 100, 500, 500);
1572aWindow->Map(); // Map this Window to this screen
e6c8fcfe 1573
4ee1bdf4 1574// Create a Perspective View in this Viewer
453103d1 1575Handle(V3d_View) aView = new V3d_View (aViewer);
18006a0f 1576aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
1577// Associate this View with the Window
453103d1 1578aView->SetWindow (aWindow);
0784d6e3 1579// Display presentation in this View
1580aStruct->Display();
18006a0f 1581// Finally update the Visualization in this View
1582aView->Update();
18006a0f 1583// Fit view to object size
453103d1 1584aView->FitAll();
18006a0f 1585~~~~~
72b7576f 1586
18006a0f 1587@subsubsection occt_visu_4_4_3 Define viewing parameters
72b7576f 1588
453103d1 1589View projection and orientation in OCCT *V3d_View* are driven by camera.
1590The camera calculates and supplies projection and view orientation matrices for rendering by OpenGL.
1591The allows to the user to control all projection parameters.
1592The camera is defined by the following properties:
1593
1594 * **Eye** -- defines the observer (camera) position.
1595 Make sure the Eye point never gets between the Front and Back clipping planes.
1596 * **Center** -- defines the origin of View Reference Coordinates (where camera is aimed at).
1597 * **Direction** -- defines the direction of camera view (from the Eye to the Center).
1598 * **Distance** -- defines the distance between the Eye and the Center.
1599 * **Front** Plane -- defines the position of the front clipping plane in View Reference Coordinates system.
1600 * **Back** Plane -- defines the position of the back clipping plane in View Reference Coordinates system.
1601 * **ZNear** -- defines the distance between the Eye and the Front plane.
1602 * **ZFar** -- defines the distance between the Eye and the Back plane.
1603
1604Most common view manipulations (panning, zooming, rotation) are implemented as convenience methods of *V3d_View* class or by *AIS_ViewController* tool.
1605However *Graphic3d_Camera* class can also be used directly by application developers.
18006a0f 1606Example:
453103d1 1607~~~~~{.cpp}
18006a0f 1608// rotate camera by X axis on 30.0 degrees
1609gp_Trsf aTrsf;
453103d1 1610aTrsf.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0)), M_PI / 4.0);
18006a0f 1611aView->Camera()->Transform (aTrsf);
1612~~~~~
72b7576f 1613
18006a0f 1614@subsubsection occt_visu_4_4_4 Orthographic Projection
1615
d6b4d3d0 1616@figure{view_frustum.png,"Perspective and orthographic projection",420}
72b7576f 1617
18006a0f 1618The following code configures the camera for orthographic rendering:
72b7576f 1619
453103d1 1620~~~~~{.cpp}
18006a0f 1621// Create an orthographic View in this Viewer
453103d1 1622Handle(V3d_View) aView = new V3d_View (theViewer);
18006a0f 1623aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
453103d1 1624aView->Update(); // update the Visualization in this View
18006a0f 1625~~~~~
72b7576f 1626
18006a0f 1627@subsubsection occt_visu_4_4_5 Perspective Projection
72b7576f 1628
e6c8fcfe 1629**Field of view (FOVy)** -- defines the field of camera view by y axis in degrees (45° is default).
72b7576f 1630
d6b4d3d0 1631@figure{camera_perspective.png,"Perspective frustum",420}
72b7576f 1632
18006a0f 1633The following code configures the camera for perspective rendering:
72b7576f 1634
453103d1 1635~~~~~{.cpp}
18006a0f 1636// Create a perspective View in this Viewer
453103d1 1637Handle(V3d_View) aView = new V3d_View (theViewer);
18006a0f 1638aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
1639aView->Update();
1640~~~~~
72b7576f 1641
18006a0f 1642@subsubsection occt_visu_4_4_6 Stereographic Projection
72b7576f 1643
3f812249 1644**IOD** -- defines the intraocular distance (in world space units).
18006a0f 1645
1646There are two types of IOD:
7863dabb 1647* _Graphic3d_Camera::IODType_Absolute_ : Intraocular distance is defined as an absolute value.
1648* _Graphic3d_Camera::IODType_Relative_ : Intraocular distance is defined relative to the camera focal length (as its coefficient).
18006a0f 1649
e6c8fcfe 1650**Field of view (FOV)** -- defines the field of camera view by y axis in degrees (45° is default).
18006a0f 1651
3f812249 1652**ZFocus** -- defines the distance to the point of stereographic focus.
18006a0f 1653
d6b4d3d0 1654@figure{stereo.png,"Stereographic projection",420}
18006a0f 1655
453103d1 1656To enable stereo projection for active (shutter) 3D glasses, your workstation should meet the following requirements:
18006a0f 1657
1658* The graphic card should support quad buffering.
1659* You need active 3D glasses (LCD shutter glasses).
453103d1 1660* The graphic driver needs to be configured to impose quad buffering for newly created OpenGl contexts;
1661 the viewer and the view should be created after that.
18006a0f 1662
453103d1 1663In stereographic projection mode the camera prepares two projection matrices to display different stereo-pictures for the left and for the right eye.
1664In a non-stereo camera this effect is not visible because only the same projection is used for both eyes.
18006a0f 1665
7863dabb 1666To enable quad buffering support you should provide the following settings to the graphic driver *OpenGl_Caps*:
72b7576f 1667
453103d1 1668~~~~~{.cpp}
18006a0f 1669Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver();
1670OpenGl_Caps& aCaps = aDriver->ChangeOptions();
1671aCaps.contextStereo = Standard_True;
bf62b306 1672~~~~~
72b7576f 1673
18006a0f 1674The following code configures the camera for stereographic rendering:
72b7576f 1675
453103d1 1676~~~~~{.cpp}
18006a0f 1677// Create a Stereographic View in this Viewer
453103d1 1678Handle(V3d_View) aView = new V3d_View (theViewer);
18006a0f 1679aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
1680// Change stereo parameters
1681aView->Camera()->SetIOD (IODType_Absolute, 5.0);
1682// Finally update the Visualization in this View
1683aView->Update();
1684~~~~~
72b7576f 1685
453103d1 1686Other 3D displays are also supported, including row-interlaced with passive glasses and anaglyph glasses - see *Graphic3d_StereoMode* enumeration.
1687Example to activate another stereoscopic display:
1688~~~~~{.cpp}
1689Handle(V3d_View) theView;
1690theView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
1691theView->ChangeRenderingParams().StereoParams = Graphic3d_StereoMode_RowInterlaced;
1692~~~~~
1693
1694Supporting of VR/AR headsets in application is more involving.
1695Class *Aspect_XRSession* defines a basic interface for working with extended reality.
1696
18006a0f 1697@subsubsection occt_visu_4_4_7 View frustum culling
72b7576f 1698
453103d1 1699The algorithm of frustum culling on CPU-side is activated by default for 3D viewer.
1700This algorithm allows skipping the presentation outside camera at the rendering stage, providing better performance.
1701The following features support this method:
18006a0f 1702* *Graphic3d_Structure::CalculateBoundBox()* is used to calculate axis-aligned bounding box of a presentation considering its transformation.
1703* *V3d_View::SetFrustumCulling* enables or disables frustum culling for the specified view.
7863dabb 1704* Classes *Graphic3d_BvhCStructureSet* and *Graphic3d_CullingTool* handle the detection of outer objects and usage of acceleration structure for frustum culling.
18006a0f 1705* *BVH_BinnedBuilder* class splits several objects with null bounding box.
72b7576f 1706
18006a0f 1707@subsubsection occt_visu_4_4_9 View background styles
453103d1 1708There are several types of background styles available for *V3d_View*: solid color, gradient color, image and environment cubemap.
72b7576f 1709
7c42f3f4 1710To set solid color for the background you can use the following method:
453103d1 1711~~~~~{.cpp}
7c42f3f4 1712void V3d_View::SetBackgroundColor (const Quantity_Color& theColor);
bf62b306 1713~~~~~
72b7576f 1714
7c42f3f4 1715The gradient background style could be set up with the following method:
453103d1 1716~~~~~{.cpp}
7c42f3f4 1717void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
1718 const Quantity_Color& theColor2,
1719 const Aspect_GradientFillMethod theFillStyle,
1720 const Standard_Boolean theToUpdate = false);
bf62b306 1721~~~~~
72b7576f 1722
7c42f3f4 1723The *theColor1* and *theColor2* parameters define the boundary colors of interpolation, the *theFillStyle* parameter defines the direction of interpolation.
72b7576f 1724
7c42f3f4 1725To set the image as a background and change the background image style you can use the following method:
453103d1 1726~~~~~{.cpp}
7c42f3f4 1727void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
1728 const Aspect_FillMethod theFillStyle,
1729 const Standard_Boolean theToUpdate = false);
bf62b306 1730~~~~~
72b7576f 1731
453103d1 1732The *theFileName* parameter defines the image file name and the path to it, the *theFillStyle* parameter defines the method of filling the background with the image.
1733The methods are:
3f812249 1734 * *Aspect_FM_NONE* -- draws the image in the default position;
1735 * *Aspect_FM_CENTERED* -- draws the image at the center of the view;
1736 * *Aspect_FM_TILED* -- tiles the view with the image;
1737 * *Aspect_FM_STRETCH* -- stretches the image over the view.
72b7576f 1738
18006a0f 1739@subsubsection occt_visu_4_4_10 Dumping a 3D scene into an image file
72b7576f 1740
7c42f3f4 1741The 3D scene displayed in the view can be dumped into image file with resolution independent from window size (using offscreen buffer).
1742The *V3d_View* has the following methods for dumping the 3D scene:
453103d1 1743~~~~{.cpp}
7c42f3f4 1744Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
1745 const Image_TypeOfImage theBufferType);
4ee1bdf4 1746~~~~
7c42f3f4 1747Dumps the scene into an image file with the view dimensions.
453103d1 1748The raster image data handling algorithm is based on the *Image_AlienPixMap* class.
1749The supported extensions are ".png", ".bmp", ".jpg" and others supported by **FreeImage** library.
1750The value passed as *theBufferType* argument defines the type of the buffer for an output image (RGB, RGBA, floating-point, RGBF, RGBAF).
1751Method returns TRUE if the scene has been successfully dumped.
72b7576f 1752
453103d1 1753~~~~{.cpp}
7c42f3f4 1754Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage,
1755 const V3d_ImageDumpOptions& theParams);
4ee1bdf4 1756~~~~
7c42f3f4 1757Dumps the displayed 3d scene into a pixmap with a width and height passed through parameters structure *theParams*.
72b7576f 1758
18006a0f 1759@subsubsection occt_visu_4_4_13 Ray tracing support
72b7576f 1760
453103d1 1761OCCT visualization provides rendering by real-time ray tracing technique.
1762It is allowed to switch easily between usual rasterization and ray tracing rendering modes.
1763The core of OCCT ray tracing is written using GLSL shaders.
1764The ray tracing has a wide list of features:
18006a0f 1765* Hard shadows
1766* Refractions
1767* Reflection
1768* Transparency
1769* Texturing
1770* Support of non-polygon objects, such as lines, text, highlighting, selection.
1771* Performance optimization using 2-level bounding volume hierarchy (BVH).
72b7576f 1772
453103d1 1773The ray tracing algorithm is recursive (Whitted's algorithm).
1774It uses BVH effective optimization structure.
1775The structure prepares optimized data for a scene geometry for further displaying it in real-time.
1776The time-consuming re-computation of the BVH is not necessary for view operations, selections, animation and even editing of the scene by transforming location of the objects.
1777It is only necessary when the list of displayed objects or their geometry changes.
18006a0f 1778To make the BVH reusable it has been added into an individual reusable OCCT package *TKMath/BVH*.
1779
1780There are several ray-tracing options that user can switch on/off:
1781* Maximum ray tracing depth
1782* Shadows rendering
1783* Specular reflections
1784* Adaptive anti aliasing
1785* Transparency shadow effects
1786
1787Example:
453103d1 1788~~~~~{.cpp}
18006a0f 1789Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
1790// specifies rendering mode
1791aParams.Method = Graphic3d_RM_RAYTRACING;
1792// maximum ray-tracing depth
1793aParams.RaytracingDepth = 3;
1794// enable shadows rendering
7c42f3f4 1795aParams.IsShadowEnabled = true;
453103d1 1796// enable specular reflections
7c42f3f4 1797aParams.IsReflectionEnabled = true;
18006a0f 1798// enable adaptive anti-aliasing
7c42f3f4 1799aParams.IsAntialiasingEnabled = true;
453103d1 1800// enable light propagation through transparent media
7c42f3f4 1801aParams.IsTransparentShadowEnabled = true;
18006a0f 1802// update the view
1803aView->Update();
1804~~~~~
1805
1806@subsubsection occt_visu_4_4_14 Display priorities
1807
453103d1 1808Structure display priorities control the order, in which structures are drawn.
1809When you display a structure you specify its priority.
1810The lower is the value, the lower is the display priority.
1811When the display is regenerated, the structures with the lowest priority are drawn first.
1812The structures with the same display priority are drawn in the same order as they have been displayed.
1813OCCT supports eleven structure display priorities within [0, 10] range.
18006a0f 1814
1815@subsubsection occt_visu_4_4_15 Z-layer support
1816
453103d1 1817OCCT features depth-arranging functionality called z-layer.
1818A graphical presentation can be put into a z-layer.
1819In general, this function can be used for implementing "bring to front" functionality in a graphical application.
18006a0f 1820
1821Example:
1822
453103d1 1823~~~~~{.cpp}
18006a0f 1824// set z-layer to an interactive object
7c42f3f4 1825Handle(AIS_InteractiveContext) theContext;
1826Handle(AIS_InteractiveObject) theInterObj;
453103d1 1827Standard_Integer anId = -1;
18006a0f 1828aViewer->AddZLayer (anId);
7c42f3f4 1829theContext->SetZLayer (theInterObj, anId);
18006a0f 1830~~~~~
1831
1832For each z-layer, it is allowed to:
1833* Enable / disable depth test for layer.
1834* Enable / disable depth write for layer.
1835* Enable / disable depth buffer clearing.
1836* Enable / disable polygon offset.
1837
453103d1 1838You can get the options using getter from *V3d_Viewer*.
1839It returns *Graphic3d_ZLayerSettings* for a given *LayerId*.
18006a0f 1840
1841Example:
453103d1 1842~~~~~{.cpp}
18006a0f 1843// change z-layer settings
1844Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
7c42f3f4 1845aSettings.SetEnableDepthTest (true);
1846aSettings.SetEnableDepthWrite(true);
1847aSettings.SetClearDepth (true);
7c3ef2f7 1848aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
18006a0f 1849aViewer->SetZLayerSettings (anId, aSettings);
1850~~~~~
1851
7c3ef2f7 1852Another application for Z-Layer feature is treating visual precision issues when displaying objects far from the World Center.
1853The key problem with such objects is that visualization data is stored and manipulated with single precision floating-point numbers (32-bit).
ebcbd824 1854Single precision 32-bit floating-point numbers give only 6-9 significant decimal digits precision,
1855while double precision 64-bit numbers give 15-17 significant decimal digits precision, which is sufficient enough for most applications.
7c3ef2f7 1856
ebcbd824 1857When moving an Object far from the World Center, float number steadily eats precision.
1858The camera Eye position adds leading decimal digits to the overall Object transformation, which discards smaller digits due to floating point number nature.
7c3ef2f7 1859For example, the object of size 0.0000123 moved to position 1000 has result transformation 1000.0000123,
1860which overflows single precision floating point - considering the most optimistic scenario of 9 significant digits (but it is really not this case), the result number will be 1000.00001.
1861
ebcbd824 1862This imprecision results in visual artifacts of two kinds in the 3D Viewer:
7c3ef2f7 1863
1864* Overall per-vertex Object distortion.
ebcbd824 1865 This happens when each vertex position has been defined within World Coordinate system.
1866* The object itself is not distorted, but its position in the World is unstable and imprecise - the object jumps during camera manipulations.
7c3ef2f7 1867 This happens when vertices have been defined within Local Coordinate system at the distance small enough to keep precision within single precision float,
1868 however Local Transformation applied to the Object is corrupted due to single precision float.
1869
ebcbd824 1870The first issue cannot be handled without switching the entire presentation into double precision (for each vertex position).
7c3ef2f7 1871However, visualization hardware is much faster using single precision float number rather than double precision - so this is not an option in most cases.
1872The second issue, however, can be negated by applying special rendering tricks.
1873
7c42f3f4 1874So, to apply this feature in OCCT, the application:
7c3ef2f7 1875
ebcbd824 1876* Defines Local Transformation for each object to fit the presentation data into single precision float without distortion.
1877* Spatially splits the world into smaller areas/cells where single precision float will be sufficient.
7c3ef2f7 1878 The size of such cell might vary and depends on the precision required by application (e.g. how much user is able to zoom in camera within application).
ebcbd824 1879* Defines a Z-Layer for each spatial cell containing any object.
1880* Defines the Local Origin property of the Z-Layer according to the center of the cell.
7c42f3f4 1881
453103d1 1882~~~~~{.cpp}
7c42f3f4 1883Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
1884aSettings.SetLocalOrigin (400.0, 0.0, 0.0);
1885~~~~~
ebcbd824 1886* Assigns a presentable object to the nearest Z-Layer.
7c3ef2f7 1887
ebcbd824 1888Note that Local Origin of the Layer is used only for rendering - everything outside will be still defined in the World Coordinate System,
7c3ef2f7 1889including Local Transformation of the Object and Detection results.
ebcbd824 1890E.g., while moving the presentation between Z-layers with different Local Origins, the Object will stay at the same place - only visualization quality will vary.
18006a0f 1891
1892@subsubsection occt_visu_4_4_16 Clipping planes
1893
453103d1 1894The ability to define custom clipping planes could be very useful for some tasks.
1895OCCT provides such an opportunity.
18006a0f 1896
453103d1 1897The *Graphic3d_ClipPlane* class provides the services for clipping planes:
1898it holds the plane equation coefficients and provides its graphical representation.
1899To set and get plane equation coefficients you can use the following methods:
18006a0f 1900
453103d1 1901~~~~~{.cpp}
7c42f3f4 1902Graphic3d_ClipPlane::Graphic3d_ClipPlane (const gp_Pln& thePlane)
18006a0f 1903void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
7c42f3f4 1904Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Equation& theEquation)
18006a0f 1905void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
1906gp_Pln Graphic3d_ClipPlane::ToPlane() const
1907~~~~~
1908
1909The clipping planes can be activated with the following method:
453103d1 1910~~~~~{.cpp}
18006a0f 1911void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
1912~~~~~
1913
453103d1 1914The number of clipping planes is limited.
1915You can check the limit value via method *Graphic3d_GraphicDriver::InquireLimit()*;
18006a0f 1916
453103d1 1917~~~~~{.cpp}
18006a0f 1918// get the limit of clipping planes for the current view
7c42f3f4 1919Standard_Integer aMaxClipPlanes = aView->Viewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxNbClipPlanes);
18006a0f 1920~~~~~
1921
1922Let us see for example how to create a new clipping plane with custom parameters and add it to a view or to an object:
453103d1 1923~~~~~{.cpp}
18006a0f 1924// create a new clipping plane
453103d1 1925Handle(Graphic3d_ClipPlane) aClipPlane = new Graphic3d_ClipPlane();
18006a0f 1926// change equation of the clipping plane
453103d1 1927Standard_Real aCoeffA, aCoeffB, aCoeffC, aCoeffD = ...
18006a0f 1928aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
1929// set capping
1930aClipPlane->SetCapping (aCappingArg == "on");
1931// set the material with red color of clipping plane
1932Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
1933Quantity_Color aColor (1.0, 0.0, 0.0, Quantity_TOC_RGB);
1934aMat.SetAmbientColor (aColor);
1935aMat.SetDiffuseColor (aColor);
1936aClipPlane->SetCappingMaterial (aMat);
1937// set the texture of clipping plane
2683e647 1938Handle(Graphic3d_Texture2Dmanual) aTexture = ...
18006a0f 1939aTexture->EnableModulate();
1940aTexture->EnableRepeat();
1941aClipPlane->SetCappingTexture (aTexture);
1942// add the clipping plane to an interactive object
2683e647 1943Handle(AIS_InteractiveObject) aIObj = ...
18006a0f 1944aIObj->AddClipPlane (aClipPlane);
1945// or to the whole view
1946aView->AddClipPlane (aClipPlane);
1947// activate the clipping plane
453103d1 1948aClipPlane->SetOn (Standard_True);
18006a0f 1949// update the view
1950aView->Update();
1951~~~~~
1952
18006a0f 1953@subsubsection occt_visu_4_4_17 Automatic back face culling
1954
453103d1 1955Back face culling reduces the rendered number of triangles (which improves the performance) and eliminates artifacts at shape boundaries.
1956However, this option can be used only for solid objects, where the interior is actually invisible from any point of view.
1957Automatic back-face culling mechanism is turned on by default, which is controlled by *V3d_View::SetBackFacingModel()*.
18006a0f 1958
7863dabb 1959The following features are applied in *StdPrs_ToolTriangulatedShape::IsClosed()*, which is used for definition of back face culling in *ShadingAspect*:
18006a0f 1960* disable culling for free closed Shells (not inside the Solid) since reversed orientation of a free Shell is a valid case;
1961* enable culling for Solids packed into a compound;
1962* ignore Solids with incomplete triangulation.
1963
1964Back face culling is turned off at TKOpenGl level in the following cases:
1965* clipping/capping planes are in effect;
1966* for translucent objects;
1967* with hatching presentation style.
1968
1969@subsection occt_visu_4_5 Examples: creating a 3D scene
1970
7c42f3f4 1971To create 3D graphic objects and display them in the screen, follow the procedure below:
18006a0f 19721. Create attributes.
19732. Create a 3D viewer.
19743. Create a view.
19754. Create an interactive context.
19765. Create interactive objects.
7c42f3f4 19776. Create primitives in the interactive object.
18006a0f 19787. Display the interactive object.
1979
1980@subsubsection occt_visu_4_5_1 Create attributes
1981
1982Create colors.
1983
453103d1 1984~~~~~{.cpp}
18006a0f 1985Quantity_Color aBlack (Quantity_NOC_BLACK);
1986Quantity_Color aBlue (Quantity_NOC_MATRABLUE);
1987Quantity_Color aBrown (Quantity_NOC_BROWN4);
1988Quantity_Color aFirebrick (Quantity_NOC_FIREBRICK);
1989Quantity_Color aForest (Quantity_NOC_FORESTGREEN);
1990Quantity_Color aGray (Quantity_NOC_GRAY70);
1991Quantity_Color aMyColor (0.99, 0.65, 0.31, Quantity_TOC_RGB);
1992Quantity_Color aBeet (Quantity_NOC_BEET);
1993Quantity_Color aWhite (Quantity_NOC_WHITE);
1994~~~~~
1995
1996Create line attributes.
1997
453103d1 1998~~~~~{.cpp}
18006a0f 1999Handle(Graphic3d_AspectLine3d) anAspectBrown = new Graphic3d_AspectLine3d();
453103d1 2000Handle(Graphic3d_AspectLine3d) anAspectBlue = new Graphic3d_AspectLine3d();
18006a0f 2001Handle(Graphic3d_AspectLine3d) anAspectWhite = new Graphic3d_AspectLine3d();
2002anAspectBrown->SetColor (aBrown);
2003anAspectBlue ->SetColor (aBlue);
2004anAspectWhite->SetColor (aWhite);
2005~~~~~
2006
2007Create marker attributes.
453103d1 2008~~~~~{.cpp}
18006a0f 2009Handle(Graphic3d_AspectMarker3d aFirebrickMarker = new Graphic3d_AspectMarker3d();
2010// marker attributes
2011aFirebrickMarker->SetColor (Firebrick);
453103d1 2012aFirebrickMarker->SetScale (1.0f);
18006a0f 2013aFirebrickMarker->SetType (Aspect_TOM_BALL);
453103d1 2014// or custom image
18006a0f 2015aFirebrickMarker->SetMarkerImage (theImage)
2016~~~~~
2017
2018Create facet attributes.
453103d1 2019~~~~~{.cpp}
2020Handle(Graphic3d_AspectFillArea3d) aFaceAspect = new Graphic3d_AspectFillArea3d();
18006a0f 2021Graphic3d_MaterialAspect aBrassMaterial (Graphic3d_NOM_BRASS);
2022Graphic3d_MaterialAspect aGoldMaterial (Graphic3d_NOM_GOLD);
2a332745 2023aFaceAspect->SetInteriorStyle (Aspect_IS_SOLID_WIREFRAME);
18006a0f 2024aFaceAspect->SetInteriorColor (aMyColor);
2025aFaceAspect->SetDistinguishOn ();
2026aFaceAspect->SetFrontMaterial (aGoldMaterial);
2027aFaceAspect->SetBackMaterial (aBrassMaterial);
18006a0f 2028~~~~~
2029
2030Create text attributes.
453103d1 2031~~~~~{.cpp}
2032Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d (aForest, Font_NOF_MONOSPACE, 1.0, 0.0);
18006a0f 2033~~~~~
2034
2035@subsubsection occt_visu_4_5_2 Create a 3D Viewer (a Windows example)
2036
453103d1 2037~~~~~{.cpp}
2038// create a graphic driver
2039Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (Handle(Aspect_DisplayConnection)());
18006a0f 2040// create a viewer
7c42f3f4 2041myViewer = new V3d_Viewer (aGraphicDriver);
18006a0f 2042// set parameters for V3d_Viewer
2043// defines default lights -
2044// positional-light 0.3 0.0 0.0
2045// directional-light V3d_XnegYposZpos
2046// directional-light V3d_XnegYneg
2047// ambient-light
2048a3DViewer->SetDefaultLights();
2049// activates all the lights defined in this viewer
2050a3DViewer->SetLightOn();
2051// set background color to black
2052a3DViewer->SetDefaultBackgroundColor (Quantity_NOC_BLACK);
2053~~~~~
2054
18006a0f 2055@subsubsection occt_visu_4_5_3 Create a 3D view (a Windows example)
2056
7c42f3f4 2057It is assumed that a valid Windows window may already be accessed via the method *GetSafeHwnd()* (as in case of MFC sample).
453103d1 2058~~~~~{.cpp}
7c42f3f4 2059Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
18006a0f 2060myView = myViewer->CreateView();
2061myView->SetWindow (aWNTWindow);
2062~~~~~
2063
2064@subsubsection occt_visu_4_5_4 Create an interactive context
2065
453103d1 2066~~~~~{.cpp}
18006a0f 2067myAISContext = new AIS_InteractiveContext (myViewer);
2068~~~~~
2069
2070You are now able to display interactive objects such as an *AIS_Shape*.
2071
453103d1 2072~~~~~{.cpp}
18006a0f 2073TopoDS_Shape aShape = BRepAPI_MakeBox (10, 20, 30).Solid();
7c42f3f4 2074Handle(AIS_Shape) anAISShape = new AIS_Shape (aShape);
453103d1 2075myAISContext->Display (anAISShape, true);
18006a0f 2076~~~~~
2077
2683e647 2078@subsubsection occt_visu_4_5_5 Create your own interactive object
18006a0f 2079
2080Follow the procedure below to compute the presentable object:
2081
67d7f07f 20821. Build a presentable object inheriting from *AIS_InteractiveObject* (refer to the Chapter on @ref occt_visu_2_1 "Presentable Objects").
7863dabb 20832. Reuse the *Graphic3d_Structure* provided as an argument of the compute methods.
18006a0f 2084
453103d1 2085**Note** that there are two compute methods: one for a standard representation, and the other for a degenerated representation,
2086i.e. in hidden line removal and wireframe modes.
18006a0f 2087
18006a0f 2088Let us look at the example of compute methods
2089
453103d1 2090~~~~~{.cpp}
7c42f3f4 2091void MyPresentableObject::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsManager,
7863dabb 2092 const Handle(Graphic3d_Structure)& thePrs,
7c42f3f4 2093 const Standard_Integer theMode)
18006a0f 2094(
2095 //...
2096)
2097
7c42f3f4 2098void MyPresentableObject::Compute (const Handle(Prs3d_Projector)& theProjector,
7863dabb 2099 const Handle(Graphic3d_Structure)& thePrs)
18006a0f 2100(
2101 //...
2102)
2103~~~~~
2104
2105@subsubsection occt_visu_4_5_6 Create primitives in the interactive object
2106
7863dabb 2107Get the group used in *Graphic3d_Structure*.
18006a0f 2108
453103d1 2109~~~~~{.cpp}
7c42f3f4 2110Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
18006a0f 2111~~~~~
2112
2113Update the group attributes.
2114
453103d1 2115~~~~~{.cpp}
7c42f3f4 2116aGroup->SetGroupPrimitivesAspect (anAspectBlue);
18006a0f 2117~~~~~
2118
2119Create two triangles in *aGroup*.
2120
453103d1 2121~~~~~{.cpp}
18006a0f 2122Standard_Integer aNbTria = 2;
453103d1 2123Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles (3 * aNbTria, 0, Graphic3d_ArrayFlags_VertexNormal);
7c42f3f4 2124for (Standard_Integer aTriIter = 1; aTriIter <= aNbTria; ++aTriIter)
18006a0f 2125{
7c42f3f4 2126 aTriangles->AddVertex (aTriIter * 5., 0., 0., 1., 1., 1.);
2127 aTriangles->AddVertex (aTriIter * 5 + 5, 0., 0., 1., 1., 1.);
2128 aTriangles->AddVertex (aTriIter * 5 + 2.5, 5., 0., 1., 1., 1.);
18006a0f 2129}
18006a0f 2130aGroup->AddPrimitiveArray (aTriangles);
7c42f3f4 2131aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectFillArea3d());
18006a0f 2132~~~~~
2133
18006a0f 2134Use the polyline function to create a boundary box for the *thePrs* structure in group *aGroup*.
2135
453103d1 2136~~~~~{.cpp}
18006a0f 2137Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2138thePrs->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2139
2140Handle(Graphic3d_ArrayOfPolylines) aPolylines = new Graphic3d_ArrayOfPolylines (16, 4);
2141aPolylines->AddBound (4);
2142aPolylines->AddVertex (Xm, Ym, Zm);
2143aPolylines->AddVertex (Xm, Ym, ZM);
2144aPolylines->AddVertex (Xm, YM, ZM);
2145aPolylines->AddVertex (Xm, YM, Zm);
2146aPolylines->AddBound (4);
2147aPolylines->AddVertex (Xm, Ym, Zm);
2148aPolylines->AddVertex (XM, Ym, Zm);
2149aPolylines->AddVertex (XM, Ym, ZM);
2150aPolylines->AddVertex (XM, YM, ZM);
2151aPolylines->AddBound (4);
2152aPolylines->AddVertex (XM, YM, Zm);
2153aPolylines->AddVertex (XM, Ym, Zm);
2154aPolylines->AddVertex (XM, YM, Zm);
2155aPolylines->AddVertex (Xm, YM, Zm);
2156aPolylines->AddBound (4);
2157aPolylines->AddVertex (Xm, YM, ZM);
2158aPolylines->AddVertex (XM, YM, ZM);
2159aPolylines->AddVertex (XM, Ym, ZM);
2160aPolylines->AddVertex (Xm, Ym, ZM);
2161
18006a0f 2162aGroup->AddPrimitiveArray(aPolylines);
7c42f3f4 2163aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d());
18006a0f 2164~~~~~
2165
2166Create text and markers in group *aGroup*.
2167
453103d1 2168~~~~~{.cpp}
2169static char* THE_TEXT[3] =
18006a0f 2170{
2171 "Application title",
2172 "My company",
2173 "My company address."
2174};
2175Handle(Graphic3d_ArrayOfPoints) aPtsArr = new Graphic3d_ArrayOfPoints (2, 1);
2176aPtsArr->AddVertex (-40.0, -40.0, -40.0);
2177aPtsArr->AddVertex (40.0, 40.0, 40.0);
18006a0f 2178aGroup->AddPrimitiveArray (aPtsArr);
7c42f3f4 2179aGroup->SetGroupPrimitivesAspect (new Graphic3d_AspectText3d());
18006a0f 2180
2181Graphic3d_Vertex aMarker (0.0, 0.0, 0.0);
7c42f3f4 2182for (int i = 0; i <= 2; i++)
18006a0f 2183{
2184 aMarker.SetCoord (-(Standard_Real )i * 4 + 30,
2185 (Standard_Real )i * 4,
2186 -(Standard_Real )i * 4);
453103d1 2187 aGroup->Text (THE_TEXT[i], Marker, 20.);
18006a0f 2188}
18006a0f 2189~~~~~
2190
2191@section occt_visu_5 Mesh Visualization Services
2192
453103d1 2193*MeshVS* (Mesh Visualization Service) component extends 3D visualization capabilities of Open CASCADE Technology.
2194It provides flexible means of displaying meshes along with associated pre- and post-processor data.
18006a0f 2195
2196From a developer's point of view, it is easy to integrate the *MeshVS* component into any mesh-related application with the following guidelines:
2197
2198* Derive a data source class from the *MeshVS_DataSource* class.
453103d1 2199* Re-implement its virtual methods, so as to give the *MeshVS* component access to the application data model.
2200 This is the most important part of the job, since visualization performance is affected by performance of data retrieval methods of your data source class.
7c42f3f4 2201* Create an instance of *MeshVS_Mesh* class.
2202* Create an instance of your data source class and pass it to a *MeshVS_Mesh* object through the *SetDataSource()* method.
2203* Create one or several objects of *MeshVS_PrsBuilder*-derived classes (standard, included in the *MeshVS* package, or your custom ones).
453103d1 2204* Each *PrsBuilder* is responsible for drawing a *MeshVS_Mesh* presentation in a certain display mode(s) specified as a *PrsBuilder* constructor's argument.
2205 Display mode is treated by *MeshVS* classes as a combination of bit flags (two least significant bits are used to encode standard display modes: wireframe, shading and shrink).
2206* Pass these objects to the *MeshVS_Mesh::AddBuilder()* method.
2207 *MeshVS_Mesh* takes advantage of improved selection highlighting mechanism: it highlights its selected entities itself, with the help of so called "highlighter" object.
2208 You can set one of *PrsBuilder* objects to act as a highlighter with the help of a corresponding argument of the *AddBuilder()* method.
72b7576f 2209
453103d1 2210Visual attributes of the *MeshVS_Mesh* object (such as shading color, shrink coefficient and so on) are controlled through *MeshVS_Drawer* object.
2211It maintains a map "Attribute ID --> attribute value" and can be easily extended with any number of custom attributes.
d6b4d3d0 2212
453103d1 2213In all other respects, *MeshVS_Mesh* is very similar to any other class derived from *AIS_InteractiveObject*
2214and it should be used accordingly (refer to the description of *AIS package* in the documentation).