1 Visualization {#occt_user_guides__visualization}
2 ========================
5 @section occt_visu_1 Introduction
7 Visualization 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
9 * on the other hand -- its **presentation** (what you see when an object is displayed in a scene) and **selection** (possibility to choose the whole object or its sub-parts interactively to apply application-defined operations to the selected entities).
11 Presentations are managed through the **Presentation** component, and selection through the **Selection** component.
13 **Application Interactive Services** (AIS) provides the means to create links between an application GUI viewer and the packages, which are used to manage selection and presentation, which makes management of these functionalities in 3D more intuitive and consequently, more transparent.
15 *AIS* uses the notion of the *interactive object*, a displayable and selectable entity, which represents an element from the application data. As 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.
17 If, 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. To do this requires familiarity with such fundamental concepts as the sensitive primitive and the presentable object.
19 The the following packages are used to display 3D objects:
27 The packages used to display 3D objects are also applicable for visualization of 2D objects.
29 The figure below presents a schematic overview of the relations between the key concepts and packages in visualization. Naturally, "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.
31 @image html visualization_image003.png "Key concepts and packages in visualization"
32 @image latex visualization_image003.png "Key concepts and packages in visualization"
34 To answer different needs of CASCADE users, this User's Guide offers the following three paths in reading it.
36 * If the 3D services proposed in AIS meet your requirements, you need only read chapter 3 @ref occt_visu_3 "AIS: Application Interactive Services".
37 * If you need more detail, for example, a selection filter on another type of entity -- you should read 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". You may want to begin with the chapter presenting AIS.
39 For advanced information on visualization algorithms, see our <a href="http://www.opencascade.com/content/tutorial-learning">E-learning & Training</a> offerings.
41 @section occt_visu_2 Fundamental Concepts
43 @subsection occt_visu_2_1 Presentation
45 In Open CASCADE Technology, presentation services are separated from the data, which they represent, which is generated by applicative algorithms. This division allows you to modify a geometric or topological algorithm and its resulting objects without modifying the visualization services.
47 @subsubsection occt_visu_2_1_1 Structure of the Presentation
49 Displaying an object on the screen involves three kinds of entities:
50 * a presentable object, the *AIS_InteractiveObject*
52 * an interactive context, the *AIS_InteractiveContext*.
54 <h4>The presentable object</h4>
55 The purpose of a presentable object is to provide the graphical representation of an object in the form of *Graphic3d* structure. On the first display request, it creates this structure by calling the appropriate algorithm and retaining this framework for further display.
57 Standard presentation algorithms are provided in the *StdPrs* and *Prs3d* packages. You can, however, write specific presentation algorithms of your own, provided that they create presentations made of structures from the *Graphic3d* packages. You can also create several presentations of a single presentable object: one for each visualization mode supported by your application.
59 Each object to be presented individually must be presentable or associated with a presentable object.
62 The viewer allows interactively manipulating views of the object. When 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. Creating Graphic3d structures in your presentation algorithms allows you to use the 3D viewers provided in Open CASCADE Technology for 3D visualisation.
64 <h4>The Interactive Context </h4>
65 The interactive context controls the entire presentation process from a common high-level API. When 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.
67 @subsubsection occt_visu_2_1_2 Presentation packages
69 Presentation involves at least the *AIS, PrsMgr, StdPrs* and *V3d* packages. Additional packages, such as *Prs3d* and *Graphic3d* may be used if you need to implement your own presentation algorithms.
71 * *AIS* package provides all classes to implement interactive objects (presentable and selectable entities).
72 * *PrsMgr* package provides low level services and is only to be used when you do not want to use the services provided by AIS. It contains all classes needed to implement the presentation process: abstract classes *Presentation* and *PresentableObject* and concrete class *PresentationManager3d*.
73 * *StdPrs* package provides ready-to-use standard presentation algorithms for specific geometries: points, curves and shapes of the geometry and topology toolkits.
74 * *Prs3d* package provides generic presentation algorithms such as wireframe, shading and hidden line removal associated with a *Drawer* class, which controls the attributes of the presentation to be created in terms of color, line type, thickness, etc.
75 * *V3d* package provides the services supported by the 3D viewer.
76 * *Graphic3d* package provides resources to create 3D graphic structures.
77 * *Visual3d* package contains classes implementing commands for 3D viewer.
78 * *DsgPrs* package provides tools for display of dimensions, relations and XYZ trihedrons.
80 @subsubsection occt_visu_2_1_3 A Basic Example: How to display a 3D object
83 Void Standard_Real dx = ...; //Parameters
84 Void Standard_Real dy = ...; //to build a wedge
85 Void Standard_Real dz = ...;
86 Void Standard_Real ltx = ...;
88 Handle(V3d_Viewer)aViewer = ...;
89 Handle(AIS_InteractiveContext)aContext;
90 aContext = new AIS_InteractiveContext(aViewer);
92 BRepPrimAPI_MakeWedge w(dx, dy, dz, ltx);
93 TopoDS_Solid & = w.Solid();
94 Handle(AIS_Shape) anAis = new AIS_Shape(S);
95 //creation of the presentable object
96 aContext -> Display(anAis);
97 //Display the presentable object in the 3d viewer.
100 The shape is created using the *BRepPrimAPI_MakeWedge* command. An *AIS_Shape* is then created from the shape. When 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. See figure below.
102 @image html visualization_image004.svg "Processes involved in displaying a presentable shape"
103 @image latex visualization_image004.svg "Processes involved in displaying a presentable shape"
105 @subsection occt_visu_2_2 Selection
107 Standard OCCT selection algorithm is represented by 2 parts: dynamic and static. Dynamic selection causes objects to be automatically highlighted as the mouse cursor moves over them. Static selection allows to pick particular object (or objects) for further processing.
109 There are 3 different selection types:
110 - **Point selection** -- allows picking and highlighting a single object (or its part) located under the mouse cursor;
111 - **Rectangle selection** -- allows picking objects or parts located under the rectangle defined by the start and end mouse cursor positions;
112 - **Polyline selection** -- allows picking objects or parts located under a user-defined non-self-intersecting polyline.
114 For OCCT selection algorithm, all selectable objects are represented as a set of sensitive zones, called <b>sensitive entities</b>. When the mouse cursor moves in the view, the sensitive entities of each object are analyzed for collision.
116 @subsubsection occt_visu_2_2_1 Terms and notions
118 This section introduces basic terms and notions used throughout the algorithm description.
120 <h4>Sensitive entity</h4>
122 Sensitive entities in the same way as entity owners are links between objects and the selection mechanism.
124 The purpose of entities is to define what parts of the object will be selectable in particular. Thus, any object that is meant to be selectable must be split into sensitive entities (one or several). For 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.
126 @image html visualization_image005.png "Example of a shape divided into sensitive entities"
127 @image latex visualization_image005.png "Example of a shape divided into sensitive entities"
129 Depending on the user's needs, sensitive entities may be atomic (point or edge) or complex. Complex entities contain many sub-elements that can be handled by detection mechanism in a similar way (for example, a polyline stored as a set of line segments or a triangulation).
131 Entities are used as internal units of the selection algorithm and do not contain any topological data, hence they have a link to an upper-level interface that maintains topology-specific methods.
133 <h4>Entity owner</h4>
135 Each sensitive entity stores a reference to its owner, which is a class connecting the entity and the corresponding selectable object. Besides, 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.
139 To simplify the handling of different selection modes of an object, sensitive entities linked to its owners are organized into sets, called **selections**.
141 Each selection contains entities created for a certain mode along with the sensitivity and update states.
143 <h4>Selectable object</h4>
145 Selectable object stores information about all created selection modes and sensitive entities.
147 All successors of a selectable object must implement the method that splits its presentation into sensitive entities according to the given mode. The computed entities are arranged in one selection and added to the list of all selections of this object. No selection will be removed from the list until the object is deleted permanently.
149 For all standard OCCT shapes, zero mode is supposed to select the whole object (but it may be redefined easily in the custom object). For example, the standard OCCT selection mechanism and *AIS_Shape* determine the following modes:
150 - 0 -- selection of the *AIS_Shape*;
151 - 1 -- selection of the vertices;
152 - 2 -- selection of the edges;
153 - 3 -- selection of the wires;
154 - 4 -- selection of the faces;
155 - 5 -- selection of the shells;
156 - 6 -- selection of the constituent solids.
158 @image html visualization_image006.png "Hierarchy of references from sensitive entity to selectable object"
159 @image latex visualization_image006.png "Hierarchy of references from sensitive entity to selectable object"
161 @image html visualization_image007.png "The principle of entities organization within the selectable object"
162 @image latex visualization_image007.png "The principle of entities organization within the selectable object"
164 <h4>Viewer selector</h4>
166 For each OCCT viewer there is a **Viewer selector** class instance. It provides a high-level API for the whole selection algorithm and encapsulates the processing of objects and sensitive entities for each mouse pick.
168 The viewer selector maintains activation and deactivation of selection modes, launches the algorithm, which detects candidate entities to be picked, and stores its results, as well as implements an interface for keeping selection structures up-to-date.
170 <h4>Selection manager</h4>
172 Selection manager is a high-level API to manipulate selection of all displayed objects. It handles all viewer selectors, activates and deactivates selection modes for the objects in all or particular selectors, manages computation and update of selections for each object. Moreover, it keeps selection structures updated taking into account applied changes.
174 @image html visualization_image008.png "The relations chain between viewer selector and selection manager"
175 @image latex visualization_image008.png "The relations chain between viewer selector and selection manager"
177 @subsubsection occt_visu_2_2_2 Algorithm
179 All three types of OCCT selection are implemented as a single concept, based on the search for overlap between frustum and sensitive entity through 3-level BVH tree traversal.
181 <h4>Selection Frustum</h4>
183 The first step of each run of selection algorithm is to build the selection frustum according to the currently activated selection type.
185 For 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. For the polyline selection, the polygon defined by the constructed line is triangulated and each triangle is used as the base for its own frustum. Thus, this type of selection uses a set of triangular frustums for overlap detection.
187 The frustum length is limited by near and far view volume planes and each plane is built parallel to the corresponding view volume plane.
189 @image html visualization_image009.png "Rectangular frustum: a) after mouse move or click, b) after applying the rectangular selection"
190 @image latex visualization_image009.png "Rectangular frustum: a) after mouse move or click, b) after applying the rectangular selection"
192 @image html visualization_image010.png "Triangular frustum set: a) user-defined polyline, b) triangulation of the polygon based on the given polyline, c) triangular frustum based on one of the triangles"
193 @image latex visualization_image010.png "Triangular frustum set: a) user-defined polyline, b) triangulation of the polygon based on the given polyline, c) triangular frustum based on one of the triangles"
197 To maintain selection mechanism at the viewer level, a speedup structure composed of 3 BVH trees is used.
199 The first level tree is constructed of axis-aligned bounding boxes of each selectable object. Hence, the root of this tree contains the combination of all selectable boundaries even if they have no currently activated selections. Objects are added during the display of <i>AIS_InteractiveObject</i> and will be removed from this tree only when the object is destroyed. The 1st level BVH tree is build on demand simultaneously with the first run of the selection algorithm.
201 The second level BVH tree consists of all sensitive entities of one selectable object. The 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.
203 The third level BVH tree is used for complex sensitive entities that contain many elements: for example, triangulations, wires with many segments, point sets, etc. It is built on demand for sensitive entities with under 800K sub-elements.
205 @image html visualization_image022.png "Selection BVH tree hierarchy: from the biggest object-level (first) to the smallest complex entity level (third)"
206 @image latex visualization_image022.png "Selection BVH tree hierarchy: from the biggest object-level (first) to the smallest complex entity level (third)"
208 <h4>Stages of the algorithm</h4>
210 The algorithm includes pre-processing and three main stages.
212 * **Pre-processing** -- implies calculation of the selection frustum and its main characteristics.
213 * **First stage** -- traverse of the first level BVH tree.
215 After successful building of the selection frustum, the algorithm starts traversal of the object-level BVH tree. The nodes containing axis-aligned bounding boxes are tested for overlap with the selection frustum following the terms of <i>separating axis theorem (SAT)</i>. When the traverse goes down to the leaf node, it means that a candidate object with possibly overlapping sensitive entities has been found. If no such objects have been detected, the algorithm stops and it is assumed that no object needs to be selected. Otherwise it passes to the next stage to process the entities of the found selectable.
217 * **Second stage** -- traverse of the second level BVH tree
219 At this stage it is necessary to determine if there are candidates among all sensitive entities of one object.
221 First of all, at this stage the algorithm checks if there is any transformation applied for the current object. If it has its own location, then the correspondingly transformed frustum will be used for further calculations. At the next step the nodes of the second level BVH tree of the given object are visited to search for overlapping leaves. If no such leafs have been found, the algorithm returns to the second stage. Otherwise it starts processing the found entities by performing the following checks:
222 - activation check - the entity may be inactive at the moment as it belongs to deactivated selection;
223 - 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. Thus, at this step the frustum may be scaled.
225 After these checks the algorithm passes to the last stage.
227 * **Third stage** -- overlap or inclusion test of a particular sensitive entity
229 If the entity is atomic, a simple SAT test is performed. In case of a complex entity, the third level BVH tree is traversed. The 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). The result of detection is stored and the algorithm returns to the second stage.
231 @subsubsection occt_visu_2_2_3 Packages and classes
233 Selection is implemented as a combination of various algorithms divided among several packages -- <i>SelectBasics</i>, <i>Select3D</i>, <i>SelectMgr</i> and <i>StdSelect</i>.
235 <h4>SelectBasics</h4>
237 <i>SelectBasics</i> package contains basic classes and interfaces for selection. The most notable are:
238 - <i>SelectBasics_SensitiveEntity</i> -- the base definition of a sensitive entity;
239 - <i>SelectBasics_EntityOwner</i> -- the base definition of the an entity owner -- the link between the sensitive entity and the object to be selected;
240 - <i>SelectBasics_PickResult</i> -- the structure for storing quantitative results of detection procedure, for example, depth and distance to the center of geometry;
241 - <i>SelectBasics_SelectingVolumeManager</i> -- the interface for interaction with the current selection frustum.
244 Each custom sensitive entity must inherit at least <i>SelectBasics_SensitiveEntity</i>.
248 <i>Select3D</i> package provides a definition of standard sensitive entities, such as:
260 Each basic sensitive entity inherits <i>Select3D_SensitiveEntity</i>, which is a child class of <i>SelectBasics_SensitiveEntity</i>.
262 The package also contains two auxiliary classes, <i>Select3D_SensitivePoly</i> and <i>Select3D_SensitiveSet</i>.
264 <i>Select3D_SensitivePoly</i> -- describes an arbitrary point set and implements basic functions for selection. It is important to know that this class does not perform any internal data checks. Hence, custom implementations of sensitive entity inherited from <i>Select3D_SensitivePoly</i> must satisfy the terms of Separating Axis Theorem to use standard OCCT overlap detection methods.
266 <i>Select3D_SensitiveSet</i> -- a base class for all complex sensitive entities that require the third level BVH usage. It implements traverse of the tree and defines an interface for the methods that check sub-entities.
270 <i>SelectMgr</i> package is used to maintain the whole selection process. For this purpose, the package provides the following services:
271 - activation and deactivation of selection modes for all selectable objects;
272 - interfaces to compute selection mode of the object;
273 - definition of selection filter classes;
274 - keeping selection BVH data up-to-date.
276 A brief description of the main classes:
277 - <i>SelectMgr_FrustumBase</i>, <i>SelectMgr_Frustum</i>, <i>SelectMgr_RectangularFrustum</i>, <i>SelectMgr_TriangluarFrustum</i> and <i>SelectMgr_TriangularFrustumSet</i> -- interfaces and implementations of selecting frustums, these classes implement different SAT tests for overlap and inclusion detection. They also contain methods to measure characteristics of detected entities (depth, distance to center of geometry);
278 - <i>SelectMgr_SensitiveEntity</i>, <i>SelectMgr_Selection</i> and <i>SelectMgr_SensitiveEntitySet</i> -- store and handle sensitive entities; <i>SelectMgr_SensitiveEntitySet</i> implements a primitive set for the second level BVH tree;
279 - <i>SelectMgr_SelectableObject</i> and <i>SelectMgr_SelectableObjectSet</i> -- describe selectable objects. They also manage storage, calculation and removal of selections. <i>SelectMgr_SelectableObjectSet</i> implements a primitive set for the first level BVH tree;
280 - <i>SelectMgr_ViewerSelector</i> -- encapsulates all logics of the selection algorithm and implements the third level BVH tree traverse;
281 - <i>SelectMgr_SelectionManager</i> -- manages activation/deactivation, calculation and update of selections of every selectable object, and keeps BVH data up-to-date.
285 <i>StdSelect</i> package contains the implementation of some <i>SelectMgr</i> classes and tools for creation of selection structures. For example,
286 - <i>StdSelect_BRepOwner</i> -- defines an entity owner with a link to its topological shape and methods for highlighting;
287 - <i>StdSelect_BRepSelectionTool</i> -- contains algorithms for splitting standard AIS shapes into sensitive primitives;
288 - <i>StdSelect_ViewerSelector3d</i> -- an example of <i>SelectMgr_ViewerSelecor</i> implementation, which is used in a default OCCT selection mechanism;
289 - <i>StdSelect_FaceFilter</i>, <i>StdSelect_EdgeFilter</i> -- implementation of selection filters.
291 @subsubsection occt_visu_2_2_4 Examples of usage
293 The first code snippet illustrates the implementation of <i>SelectMgr_SelectableObject::ComputeSelection()</i> method in a custom interactive object. The method is used for computation of user-defined selection modes.
295 Let 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).
297 To select the whole box, the application can create a sensitive primitive for each face of the interactive object. In this case, all primitives share the same owner -- the box itself.
299 To select box's edge, the application must create one sensitive primitive per edge. Here all sensitive entities cannot share the owner since different geometric primitives must be highlighted as the result of selection procedure.
303 void InteractiveBox::ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
304 const Standard_Integer theMode)
308 case 0: // creation of face sensitives for selection of the whole box
310 Handle(SelectMgr_EntityOwner) anOwnr = new SelectMgr_EntityOwner (this, 5);
311 for (Standard_Integer aFaceIdx = 1; aFaceIdx <= myNbFaces; aFaceIdx++)
313 Select3D_TypeOfSensitivity aIsInteriorSensitivity = myIsInterior;
314 theSel->Add (new Select3D_SensitiveFace (anOwnr,
315 myFaces[aFaceIdx]->PointArray(),
316 aIsInteriorSensitivity));
320 case 1: // creation of edge sensitives for selection of box edges only
322 for (Standard_Integer anEdgeIdx = 1; anEdgeIdx <= 12; anEdgeIdx++)
324 // 1 owner per edge, where 6 is a priority of the sensitive
325 Handle(MySelection_EdgeOwner) anOwnr = new MySelection_EdgeOwner (this, anEdgeIdx, 6);
326 theSel->Add (new Select3D_SensitiveSegment (anOwnr,
327 FirstPnt[anEdgeIdx]),
328 LastPnt[anEdgeIdx]));
337 The algorithms for creating selection structures store sensitive primitives in <i>SelectMgr_Selection</i> instance. Each <i>SelectMgr_Selection</i> sequence in the list of selections of the object must correspond to a particular selection mode.
339 To describe the decomposition of the object into selectable primitives, a set of ready-made sensitive entities is supplied in <i>Select3D</i> package. Custom sensitive primitives can be defined through inheritance from <i>SelectBasics_SensitiveEntity</i>.
341 To make custom interactive objects selectable or customize selection modes of existing objects, the entity owners must be defined. They must inherit <i>SelectMgr_EntityOwner</i> interface.
344 Selection structures for any interactive object are created in <i>SelectMgr_SelectableObject::ComputeSelection()</i> method.
346 The example below shows how computation of different selection modes of the topological shape can be done using standard OCCT mechanisms, implemented in <i>StdSelect_BRepSelectionTool</i>.
349 void MyInteractiveObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
350 const Standard_Integer theMode)
355 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_SHAPE);
358 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_VERTEX);
361 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_EDGE);
364 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_WIRE);
367 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_FACE);
373 The <i>StdSelect_BRepSelectionTool</i> 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 <i>TopoDS_Shape</i>.
375 The traditional way of highlighting selected entity owners adopted by Open CASCADE Technology assumes that each entity owner highlights itself on its own. This approach has two drawbacks:
377 - each entity owner has to maintain its own <i>Prs3d_Presentation</i> object, that results in a large memory overhead for thousands of owners;
378 - drawing selected owners one by one is not efficient from the OpenGL usage viewpoint.
380 Therefore, to overcome these limitations, OCCT has an alternative way to implement the highlighting of a selected presentation. Using this approach, the interactive object itself will be responsible for the highlighting, not the entity owner.
382 On the basis of <i>SelectMgr_EntityOwner::IsAutoHilight()</i> return value, <i>AIS_LocalContext</i> object either uses the traditional way of highlighting (in case if <i>IsAutoHilight()</i> returns true) or groups such owners according to their selectable objects and finally calls <i> SelectMgr_SelectableObject::HilightSelected()</i> or <i>SelectMgr_SelectableObject::ClearSelected()</i>, passing a group of owners as an argument.
385 Hence, an application can derive its own interactive object and redefine virtual methods <i>HilightSelected()</i>, <i>ClearSelected()</i> and <i>HilightOwnerWithColor()</i> from <i>SelectMgr_SelectableObject</i>. <i>SelectMgr_SelectableObject::GetHilightPresentation</i> and <i>SelectMgr_SelectableObject::GetSelectPresentation</i> methods can be used to optimize filling of selection and highlight presentations according to the user's needs.
387 The <i>AIS_InteractiveContext::HighlightSelected()</i> method can be used for efficient redrawing of the selection presentation for a given interactive object from an application code.
390 After all the necessary sensitive entities are computed and packed in <i>SelectMgr_Selection</i> instance with the corresponding owners in a redefinition of <i>SelectMgr_SelectableObject::ComputeSelection()</i> method, it is necessary to register the prepared selection in <i>SelectMgr_SelectionManager</i> through the following steps:
391 - if there was no <i>AIS_InteractiveContext</i> opened, create an interactive context and display the selectable object in it;
392 - load the selectable object to the selection manager of the interactive context using <i>AIS_InteractiveContext::Load()</i> method. If the selection mode passed as a parameter to this method is not equal to -1, <i>ComputeSelection()</i> for this selection mode will be called;
393 - activate or deactivate the defined selection mode using <i>AIS_InteractiveContext::Activate()</i> or <i>AIS_InteractiveContext::Deactivate()</i> methods.
395 After 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.
397 The code snippet below illustrates the above steps. It also contains the code to start the detection procedure and parse the results of selection.
401 // Suppose there is an instance of class InteractiveBox from the previous sample.
402 // It contains an implementation of method InteractiveBox::ComputeSelection() for selection
403 // modes 0 (whole box must be selected) and 1 (edge of the box must be selectable)
404 Handle(InteractiveBox) aBox;
406 // Assume there is a created interactive context
407 const Handle(AIS_InteractiveContext)& aContext = GetContext();
408 // To prevent automatic activation of the default selection mode
409 aContext->SetAutoActivateSelection (Standard_False);
411 aContext->Display (aBox);
413 // Load a box to the selection manager without computation of any selection mode
414 aContext->Load (aBox, -1, Standard_True);
415 // Activate edge selection
416 aContext->Activate (aBox, 1);
418 // Run the detection mechanism for activated entities in the current mouse coordinates and
419 // in the current view. Detected owners will be highlighted with context highlight color
420 aContext->MoveTo (aXMousePos, aYMousePos, myView);
421 // Select the detected owners
423 // Iterate through the selected owners
424 for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected())
426 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
429 // deactivate all selection modes for aBox1
430 aContext->Deactivate (aBox1);
434 It is also important to know, that there are 2 types of detection implemented for rectangular selection in OCCT:
435 - <b>inclusive</b> detection. In this case the sensitive primitive is considered detected only when all its points are included in the area defined by the selection rectangle;
436 - <b>overlap</b> detection. In this case the sensitive primitive is considered detected when it is partially overlapped by the selection rectangle.
438 The standard OCCT selection mechanism uses inclusion detection by default. To change this, use the following code:
442 // Assume there is a created interactive context
443 const Handle(AIS_InteractiveContext)& aContext = GetContext();
444 // Retrieve the current viewer selector
445 const Handle(StdSelect_ViewerSelector3d)& aMainSelector = aContext->MainSelector();
446 // Set the flag to allow overlap detection
447 aMainSelector->AllowOverlapDetection (Standard_True);
451 @section occt_visu_3 Application Interactive Services
452 @subsection occt_visu_3_1 Introduction
454 Application Interactive Services allow managing presentations and dynamic selection in a viewer in a simple and transparent manner.
456 The central entity for management of visualization and selections is the **Interactive Context**. It is connected to the main viewer (and if need be, the trash bin viewer). It has two operating modes: the Neutral Point and the local visualization and selection context.
458 The neutral point, which is the default mode, allows easily visualizing and selecting interactive objects loaded into the context.
460 **Local Contexts** can be opened to prepare and use a temporary selection environment without disturbing
461 the neutral point. It is possible to choose the interactive objects, which you want to act on, the selection modes, which you want to activate, and the temporary visualizations, which you will execute.
463 When the operation is finished, you close the current local context and return to the state
464 in which you were before opening it (neutral point or previous local context).
466 **Interactive Objects** are the entities, which are visualized and selected. You can use classes of standard interactive objects for which all necessary functions have already been programmed, or you can implement your own classes of interactive objects, by respecting a certain number of rules and conventions described below.
468 @image html visualization_image016.png
469 @image latex visualization_image016.png
471 An Interactive Object is a "virtual" entity, which can be presented and selected. An Interactive Object can have a certain number of specific graphic attributes, such as visualization mode, color and material.
473 When an Interactive Object is visualized, the required graphic attributes are taken from its own **Drawer** if it has the required custom attributes or otherwise from the context drawer.
475 @image html visualization_image017.png
476 @image latex visualization_image017.png
478 It can be necessary to filter the entities to be selected. Consequently there are **Filter** entities, which allow refining the dynamic detection context. Some of these filters can be used at the Neutral Point, others only in an open local context. It is possible to program custom filters and load them into the interactive context.
480 @subsection occt_visu_3_2 Interactive objects
482 Entities which are visualized and selected in the AIS viewer are objects. They connect the underlying reference geometry of a model to its graphic representation in *AIS*. You can use the predefined OCCT classes of standard interactive objects, for which all necessary functions have already been programmed, or, if you are an advanced user, you can implement your own classes of interactive objects.
484 @subsubsection occt_visu_3_2_1 Presentations
486 An interactive object can have as many presentations as its creator wants to give it.
488 3D presentations are managed by PresentationManager3D. As this is transparent in AIS, the user does not have to worry about it.
490 A presentation is identified by an index and by the reference to the Presentation Manager which it depends on.
492 By convention, the default mode of representation for the Interactive Object has index 0.
494 @image html visualization_image018.png
495 @image latex visualization_image018.png
497 Calculation of different presentations of an interactive object is done by the *Compute* functions inheriting from *PrsMgr_ PresentableObject::Compute* functions. They are automatically called by *PresentationManager* at a visualization or an update request.
499 If you are creating your own type of interactive object, you must implement the Compute function in one of the following ways:
504 void PackageName_ClassName::Compute
505 (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
506 const Handle(Prs3d_Presentation)& aPresentation,
507 const Standard_Integer aMode = 0);
510 #### For hidden line removal (HLR) mode in 3D:
512 void PackageName_ClassName::Compute
513 (const Handle(Prs3d_Projector)& aProjector,
514 const Handle(Prs3d_Presentation)& aPresentation);
517 @subsubsection occt_visu_3_2_2 Hidden Line Removal
519 The view can have two states: the normal mode or the computed mode (Hidden Line Removal mode). When the latter is active, the view looks for all presentations displayed in the normal mode, which have been signalled as accepting HLR mode. An internal mechanism allows calling the interactive object's own *Compute*, that is projector function.
521 By convention, the Interactive Object accepts or rejects the representation of HLR mode. It is possible to make this declaration in one of two ways:
523 * Initially by using one of the values of the enumeration *PrsMgr_TypeOfPresentation*:
524 * *PrsMgr_TOP_AllView*,
525 * *PrsMgr_TOP_ProjectorDependant*
527 * Later by using the function *PrsMgr_PresentableObject::SetTypeOfPresentation*
529 *AIS_Shape* class is an example of an interactive object that supports HLR representation. It supports two types of the HLR algorithm:
530 * the polygonal algorithm based on the shape's triangulation;
531 * the exact algorithm that works with the shape's real geometry.
533 The type of the HLR algorithm is stored in *AIS_Drawer* of the shape. It is a value of the *Prs3d_TypeOfHLR* enumeration and can be set to:
534 * *Prs3d_TOH_PolyAlgo* for a polygonal algorithm;
535 * *Prs3d_TOH_Algo* for an exact algorithm;
536 * *Prs3d_TOH_NotSet* if the type of algorithm is not set for the given interactive object instance.
538 The type of the HLR algorithm used for *AIS_Shape* can be changed by calling the *AIS_Shape::SetTypeOfHLR()* method.
540 The current HLR algorithm type can be obtained using *AIS_Shape::TypeOfHLR()* method is to be used.
542 These methods get the value from the drawer of *AIS_Shape*. If the HLR algorithm type in the *AIS_Drawer* is set to *Prs3d_TOH_NotSet*, the *AIS_Drawer* gets the value from the default drawer of *AIS_InteractiveContext*.
544 So it is possible to change the default HLR algorithm used by all newly displayed interactive objects. The value of the HLR algorithm type stored in the context drawer can be *Prs3d_TOH_Algo* or *Prs3d_TOH_PolyAlgo*. The polygonal algorithm is the default one.
546 @subsubsection occt_visu_3_2_3 Presentation modes
548 There are four types of interactive objects in AIS:
549 * the "construction element" or Datum,
550 * the Relation (dimensions and constraints)
552 * the None type (when the object is of an unknown type).
554 Inside these categories, additional characterization is available by means of a signature (an index.) By default, the interactive object has a NONE type and a signature of 0 (equivalent to NONE.) If you want to give a particular type and signature to your interactive object, you must redefine two virtual functions:
555 * *AIS_InteractiveObject::Type*
556 * *AIS_InteractiveObject::Signature*.
558 **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".
560 The interactive context can have a default mode of representation for the set of interactive objects. This mode may not be accepted by a given class of objects.
562 Consequently, to get information about this class it is necessary to use virtual function *AIS_InteractiveObject::AcceptDisplayMode*.
566 The functions *AIS_InteractiveContext::SetDisplayMode* and *AIS_InteractiveContext::UnsetDisplayMode* allow setting a custom display mode for an objects, which can be different from that proposed by the interactive context.
570 At dynamic detection, the presentation echoed by the Interactive Context, is by default the presentation already on the screen.
572 The functions *AIS_InteractiveObject::SetHilightMode* and *AIS_InteractiveObject::UnSetHilightMode* allow specifying the display mode used for highlighting (so called highlight mode), which is valid independently from the active representation of the object. It makes no difference whether this choice is temporary or definitive.
574 Note that the same presentation (and consequently the same highlight mode) is used for highlighting *detected* objects and for highlighting *selected* objects, the latter being drawn with a special *selection color* (refer to the section related to *Interactive Context* services).
576 For example, you want to systematically highlight the wireframe presentation of a shape - non regarding if it is visualized in wireframe presentation or with shading. Thus, you set the highlight mode to *0* in the constructor of the interactive object. Do not forget to implement this representation mode in the *Compute* functions.
579 If you do not want an object to be affected by a *FitAll* view, you must declare it infinite; you can cancel its "infinite" status using *AIS_InteractiveObject::SetInfiniteState* and *AIS_InteractiveObject::IsInfinite* functions.
581 Let us take for example the class called *IShape* representing an interactive object :
584 myPk_IShape::myPK_IShape
585 (const TopoDS_Shape& SH, PrsMgr_TypeOfPresentation aType):
586 AIS_InteractiveObject(aType), myShape(SH), myDrwr(new AIS_Drawer()) {SetHilightMode(0);}
587 void myPk_IShape::Compute
588 (const Handle(PrsMgr_PresentationManager3d) & PM,
589 const Handle(Prs3d_Presentation)& P,
590 const Standard_Integer TheMode)
594 StdPrs_WFDeflectionShape::Add (P,myShape,myDrwr); //algo for calculation of wireframe presentation break;
596 StdPrs_ShadedShape::Add (P,myShape,myDrwr); //algo for calculation of shading presentation.
600 void myPk_IsShape::Compute
601 (const Handle(Prs3d_Projector)& Prj,
602 const Handle(Prs3d_Presentation) P)
604 StdPrs_HLRPolyShape::Add(P,myShape,myDrwr);
605 //Hidden line mode calculation algorithm
609 @subsubsection occt_visu_3_2_4 Selection
611 An interactive object can have an indefinite number of selection modes, each representing a "decomposition" into sensitive primitives. Each primitive has an <i>owner</i> (*SelectMgr_EntityOwner*) which allows identifying the exact interactive object or shape which has been detected (see @ref occt_visu_2_2 "Selection" chapter).
613 The set of sensitive primitives, which correspond to a given mode, is stocked in a <b>selection</b> (*SelectMgr_Selection*).
615 Each selection mode is identified by an index. By convention, the default selection mode that allows us to grasp the interactive object in its entirety is mode *0*. However, it can be modified in the custom interactive objects using method <i>SelectMgr_SelectableObject::setGlobalSelMode()</i>.
617 The calculation of selection primitives (or sensitive entities) is done in a virtual function *ComputeSelection*. It should be implemented for each type of interactive object that is assumed to have different selection modes using the function *AIS_InteractiveObject::ComputeSelection*.
619 A detailed explanation of the mechanism and the manner of implementing this function has been given in @ref occt_visu_2_2 "Selection" chapter.
621 There are some examples of selection mode calculation for the most widely used interactive object in OCCT -- *AIS_Shape* (selection by vertex, by edges, etc). To 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*.
623 You can change the default selection mode index of a custom interactive object using the following functions:
624 * *AIS_InteractiveObject::setGlobalSelMode* sets global selection mode;
625 * *AIS_InteractiveObject::GlobalSelectionMode* returns global selection mode of the object;
626 * *AIS_InteractiveObject::GlobalSelOwner* returns an entity owner that corresponds to a global selection mode.
628 You also can temporarily change the priority of some interactive objects for selection of the global mode to facilitate their graphic detection using the following functions:
629 * *AIS_InteractiveObject::HasSelectionPriority* checks if there is a selection priority setting for the owner;
630 * *AIS_InteractiveObject::SelectionPriority* checks the current priority;
631 * *AIS_InteractiveObject::SetSelectionPriority* sets a priority;
632 * *AIS_InteractiveObject::UnsetSelectionPriority* unsets the priority.
635 @subsubsection occt_visu_3_2_5 Graphic attributes
637 Graphic attributes manager, or *AIS Drawer*, stores graphic attributes for specific interactive objects and for interactive objects controlled by interactive context.
639 Initially, all drawer attributes are filled out with the predefined values which will define the default 3D object appearance.
641 When 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.
643 Keep in mind the following points concerning graphic attributes:
644 * Each interactive object can have its own visualization attributes.
645 * The set of graphic attributes of an interactive object is stocked in an *AIS_Drawer*, which is only a *Prs3d_Drawer* with the possibility of a link to another drawer
646 * By default, the interactive object takes the graphic attributes of the context in which it is visualized (visualization mode, deflection values for the calculation of presentations, number of isoparameters, color, type of line, material, etc.)
647 * In the *AIS_InteractiveObject* abstract class, standard attributes including color, line thickness, material, and transparency have been privileged. Consequently, there is a certain number of virtual functions, which allow acting on these attributes. Each new class of interactive object can redefine these functions and change the behavior of the class.
649 @image html visualization_image019.png "Figure 13. Redefinition of virtual functions for changes in AIS_Point"
650 @image latex visualization_image019.png "Figure 13. Redefinition of virtual functions for changes in AIS_Point"
652 @image html visualization_image020.png "Figure 14. Redefinition of virtual functions for changes in AIS_Shape."
653 @image latex visualization_image020.png "Figure 14. Redefinition of virtual functions for changes in AIS_Shape."
655 The following virtual functions provide settings for color, width, material and transparency:
656 * *AIS_InteractiveObject::UnsetColor*
657 * *AIS_InteractiveObject::SetWidth*
658 * *AIS_InteractiveObject::UnsetWidth*
659 * *AIS_InteractiveObject::SetMaterial (const Graphic3d_NameOfPhysicalMaterial & aName)*
660 * *AIS_InteractiveObject::SetMaterial (const Graphic3d_MaterialAspect & aMat)*
661 * *AIS_InteractiveObject::UnsetMaterial*
662 * *AIS_InteractiveObject::SetTransparency*
663 * *AIS_InteractiveObject::UnsetTransparency*
665 For other types of attribute, it is appropriate to change the Drawer of the object directly using:
666 * *AIS_InteractiveObject::SetAttributes*
667 * *AIS_InteractiveObject::UnsetAttributes*
669 It is important to know which functions may imply the recalculation of presentations of the object.
671 If the presentation mode of an interactive object is to be updated, a flag from *PrsMgr_PresentableObject* indicates this.
673 The mode can be updated using the functions *Display* and *Redisplay* in *AIS_InteractiveContext*.
675 @subsubsection occt_visu_3_2_6 Complementary Services
677 When you use complementary services for interactive objects, pay special attention to the cases mentioned below.
679 #### Change the location of an interactive object
681 The following functions allow temporarily "moving" the representation and selection of Interactive Objects in a view without recalculation.
682 * *AIS_InteractiveContext::SetLocation*
683 * *AIS_InteractiveContext::ResetLocation*
684 * *AIS_InteractiveContext::HasLocation*
685 * *AIS_InteractiveContext::Location*
687 #### Connect an interactive object to an applicative entity
689 Each Interactive Object has functions that allow attributing it an *Owner* in form of a *Transient*.
690 * *AIS_InteractiveObject::SetOwner*
691 * *AIS_InteractiveObject::HasOwner*
692 * *AIS_InteractiveObject::Owner*
694 An interactive object can therefore be associated or not with an applicative entity, without affecting its behavior.
696 #### Resolving coincident topology
698 Due 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.
700 To the problem when the elements of two or more Interactive Objects are coincident you can apply the polygon offset. It 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. The graphical elements that accept this kind of offsets are solid polygons or displayed as boundary lines and points. The polygons could be displayed as lines or points by setting the appropriate interior style.
702 The method *AIS_InteractiveObject::SetPolygonOffsets (const Standard_Integer aMode, const Standard_Real aFactor, const Standard_Real aUnits)* allows setting up the polygon offsets.
704 The parameter *aMode* can contain various combinations of *Aspect_PolygonOffsetMode* enumeration elements:
712 The combination of these elements defines the polygon display modes that will use the given offsets. You can switch off the polygon offsets by passing *Aspect_POM_Off*. Passing *Aspect_POM_None* allows changing the *aFactor* and *aUnits* values without changing the mode. If *aMode* is different from *Aspect_POM_Off*, the *aFactor* and *aUnits* arguments are used by the graphics renderer to calculate the depth offset value:
714 offset = aFactor * m + aUnits * r
716 where *m* is the maximum depth slope for the currently displayed polygons, r is the minimum depth resolution (implementation-specific).
718 Negative offset values move polygons closer to the viewer while positive values shift polygons away.
722 This method has a side effect -- it creates its own shading aspect if not yet created, so it is better to set up the object shading aspect first.
724 You can use the following functions to obtain the current settings for polygon offsets:
726 void AIS_InteractiveObject::PolygonOffsets
727 (Standard_Integer &aMode,
728 Standard_Real &aFactor,
729 Standard_Real &aUnits)
730 Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets()
733 The same operation could be performed for the interactive object known by the *AIS_InteractiveContext* with the following methods:
735 void AIS_InteractiveContext::SetPolygonOffsets
736 (const Handle(AIS_InteractiveObject) &anObj,
737 const Standard_Integer aMode,
738 const Standard_Real aFactor,
739 const Standard_Real aUnits)
740 void AIS_InteractiveContext::PolygonOffsets
741 (const Handle(AIS_InteractiveObject) &anObj,
742 Standard_Integer &aMode,
743 Standard_Real &aFactor,
744 Standard_Real &aUnits)
745 Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets
746 (const Handle(AIS_InteractiveObject) &anObj)
750 @subsubsection occt_visu_3_2_7 Object hierarchy
752 Each *PrsMgr_PresentableObject* has a list of objects called *myChildren*.
753 Any transformation of *PrsMgr_PresentableObject* is also applied to its children. This hierarchy does not propagate to *Graphic3d* level and below.
755 *PrsMgr_PresentableObject* sends its combined (according to the hierarchy) transformation down to *Graphic3d_Structure*.
757 The materials of structures are not affected by the hierarchy.
759 Object hierarchy can be controlled by the following API calls:
760 * *PrsMgr_PresentableObject::AddChild*;
761 * *PrsMgr_PresentableObject::RemoveChild*.
763 @subsubsection occt_visu_3_2_8 Instancing
765 The conception of instancing operates the object hierarchy as follows:
766 * Instances are represented by separated *AIS* objects.
767 * Instances do not compute any presentations.
769 Classes *AIS_ConnectedInteractive* and *AIS_MultipleConnectedInteractive* are used to implement this conception.
771 *AIS_ConnectedInteractive* is an object instance, which reuses the geometry of the connected object but has its own transformation, material, visibility flag, etc. This connection is propagated down to *OpenGl* level, namely to *OpenGl_Structure*. *OpenGl_Structure* can be connected only to a single other structure.
773 *AIS_ConnectedInteractive* can be referenced to any *AIS_Interactive* object in general. When it is referenced to another *AIS_ConnectedInteractive*, it just copies the reference.
775 *AIS_MultipleConnectedInteractive* represents an assembly, which does not have its own presentation. The assemblies are able to participate in the object hierarchy and are intended to handle a grouped set of instanced objects. It behaves as a single object in terms of selection. It applies high level transformation to all sub-elements since it is located above in the hierarchy.
777 All *AIS_MultipleConnectedInteractive* are able to have child assemblies. Deep copy of object instances tree is performed if one assembly is attached to another.
779 Note that *AIS_ConnectedInteractive* cannot reference *AIS_MultipleConnectedInteractive*. *AIS_ConnectedInteractive* copies sensitive entities of the origin object for selection, unlike *AIS_MultipleConnectedInteractive* that re-uses the entities of the origin object.
781 Instances can be controlled by the following DRAW commands:
782 * *vconnect* : Creates and displays *AIS_MultipleConnectedInteractive* object from input objects and location.
783 * *vconnectto* : Makes an instance of object with the given position.
784 * *vdisconnect* : Disconnects all objects from an assembly or disconnects an object by name or number.
785 * *vaddconnected* : Adds an object to the assembly.
786 * *vlistconnected* : Lists objects in the assembly.
788 Have a look at the examples below:
794 vconnectto s2 3 0 0 s # make instance
798 See how proxy *OpenGl_Structure* is used to represent instance:
800 @figure{/user_guides/visualization/images/visualization_image029.png}
802 The original object does not have to be displayed in order to make instance. Also selection handles transformations of instances correctly:
809 vdisplay s # p is not displayed
811 vconnect x 3 0 0 s p # make assembly
815 @figure{/user_guides/visualization/images/visualization_image030.png}
817 Here is the example of a more complex hierarchy involving sub-assemblies:
825 vsetlocation s 0 2.5 0
830 vconnectto b1 -2 0 0 b
832 vconnect z2 4 0 0 d d2
833 vconnect z3 6 0 0 z z2
838 @subsection occt_visu_3_3 Interactive Context
840 @subsubsection occt_visu_3_3_1 Rules
842 The Interactive Context allows managing in a transparent way the graphic and **selectable** behavior of interactive objects in one or more viewers. Most functions which allow modifying the attributes of interactive objects, and which were presented in the preceding chapter, will be looked at again here.
844 There 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. You can only directly call the functions available for an interactive object if it has not been loaded into an Interactive Context.
847 Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);
848 myIntContext->Display(TheAISShape);
849 myIntContext->SetDisplayMode(TheAISShape ,1);
850 myIntContext->SetColor(TheAISShape,Quantity_NOC_RED);
856 Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);
857 TheAISShape->SetColor(Quantity_NOC_RED);
858 TheAISShape->SetDisplayMode(1);
859 myIntContext->Display(TheAISShape);
862 @subsubsection occt_visu_3_3_2 Groups of functions
864 **Neutral Point** and **Local Context** constitute the two operating modes or states of the **Interactive Context**, which is the central entity which pilots visualizations and selections.
866 The **Neutral Point**, which is the default mode, allows easily visualizing and selecting interactive objects, which have been loaded into the context. Opening **Local contexts** allows preparing and using a temporary selection environment without disturbing the neutral point.
868 A set of functions allows choosing the interactive objects which you want to act on, the selection modes which you want to activate, and the temporary visualizations which you will execute. When the operation is finished, you close the current local context and return to the state in which you were before opening it (neutral point or previous local context).
870 The Interactive Context is composed of many functions, which can be conveniently grouped according to the theme:
871 * management proper to the context;
872 * management in the local context;
873 * presentations and selection in open/closed context;
874 * selection strictly speaking.
876 Some functions can only be used in open Local Context; others in closed local context; others do not have the same behavior in one state as in the other.
878 @subsubsection occt_visu_3_3_3 Management of the Interactive Context
880 The **Interactive Context** is made up of a **Principal Viewer** and, optionally, a trash bin or **Collector Viewer**.
882 An interactive object can have a certain number of specific graphic attributes, such as visualization mode, color, and material. Correspondingly, the interactive context has a set of graphic attributes, the *Drawer*, which is valid by default for the objects it controls.
884 When an interactive object is visualized, the required graphic attributes are first taken from the object's own <i>Drawer</i> if one exists, or from the context drawer for the others.
886 The following adjustable settings allow personalizing the behavior of presentations and selections:
887 * Default Drawer, containing all the color and line attributes which can be used by interactive objects, which do not have their own attributes.
888 * Default Visualization Mode for interactive objects. By default: *mode 0* ;
889 * Highlight color of entities detected by mouse movement. By default: *Quantity_NOC_CYAN1*;
890 * Pre-selection color. By default: *Quantity_NOC_GREEN*;
891 * Selection color (when you click on a detected object). By default: *Quantity_NOC_GRAY80*;
892 * Sub-Intensity color. By default: *Quantity_NOC_GRAY40*.
894 All of these settings can be modified by functions proper to the Context.
896 When 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.
898 Let us examine the case of two interactive objects: *obj1* and *obj2*:
901 TheCtx->Display(obj1,Standard_False); // False = no viewer update
902 TheCtx->Display(obj2,Standard_True); // True = viewer update
903 TheCtx->SetDisplayMode(obj1,3,Standard_False);
904 TheCtx->SetDisplayMode(2);
905 // obj2 is visualised in mode 2 (if it accepts this mode)
906 // obj1 stays visualised in its mode 3.
909 *PresentationManager3D* and *Selector3D*, which manage the presentation and selection of present interactive objects, are associated to the main Viewer. The same is true of the optional Collector.
911 @subsection occt_visu_3_4 Local Context
913 @subsubsection occt_visu_3_4_1 Rules and Conventions
915 * Opening a local context allows preparing an environment for temporary presentations and selections, which will disappear once the local context is closed.
916 * It is possible to open several local contexts, but only the last one will be active.
917 * When you close a local context, the previous one, which is still on the stack, is activated again. If none is left, you return to Neutral Point.
918 * Each local context has an index created when the context opens. You should close the local context, which you have opened.
920 The interactive object, which is used the most by applications, is *AIS_Shape*. Consequently, standard functions are available which allow you to easily prepare selection operations on the constituent elements of shapes (selection of vertices, edges, faces etc) in an open local context. The selection modes specific to "Shape" type objects are called **Standard Activation Mode**. These modes are only taken into account in open local context and only act on interactive objects which have redefined the virtual function *AcceptShapeDecomposition()* so that it returns *TRUE*.
921 * Objects, which are temporarily in a local context, are not recognized by other local contexts a priori. Only objects visualized in Neutral Point are recognized by all local contexts.
922 * The state of a temporary interactive object in a local context can only be modified while another local context is open.
926 The specific modes of selection only concern the interactive objects, which are present in the Main Viewer. In the Collector, you can only locate interactive objects, which answer positively to the positioned filters when a local context is open, however, they are never decomposed in standard mode.
928 @subsubsection occt_visu_3_4_2 Management of Local Context
930 The local context can be opened using method *AIS_InteractiveContext::OpenLocalContext*. The following options are available:
931 * *UseDisplayedObjects*: allows loading the interactive objects visualized at Neutral Point in the opened local context. If *FALSE*, the local context is empty after being opened. If *TRUE*, the objects at Neutral Point are modified by their default selection mode.
932 * *AllowShapeDecomposition*: *AIS_Shape* allows or prevents decomposition in standard shape location mode of objects at Neutral Point, which are type-privileged (see @ref occt_visu_3_2_4 "Selection" chapter). This Flag is only taken into account when *UseDisplayedObjects* is *TRUE*.
933 * *AcceptEraseOfObjects*: authorizes other local contexts to erase the interactive objects present in this context. This option is rarely used. The last option has no current use.
935 This function returns the index of the created local context. It should be kept and used when the context is closed.
937 To load objects visualized at Neutral Point into a local context or remove them from it use methods
939 AIS_InteractiveContext::UseDisplayedObjects
940 AIS_InteractiveContext::NotUseDisplayedObjects
942 Closing Local Contexts is done by:
944 AIS_InteractiveContext::CloseLocalContext
945 AIS_InteractiveContext::CloseAllContexts
949 When the index is not specified in the first function, the current Context is closed. This option can be dangerous, as other Interactive Functions can open local contexts without necessarily warning the user. For greater security, you have to close the context with the index given on opening.
951 To get the index of the current context, use function *AIS_InteractiveContext::IndexOfCurrentLocal*. It allows closing all open local contexts at one go. In this case, you find yourself directly at Neutral Point.
953 When you close a local context, all temporary interactive objects are deleted, all selection modes concerning the context are canceled, and all content filters are emptied.
956 @subsubsection occt_visu_3_4_3 Presentation in a Neutral Point
958 You must distinguish between the **Neutral Point** and the **Open Local Context** states. Although the majority of visualization functions can be used in both situations, their behavior is different.
960 Neutral Point should be used to visualize the interactive objects, which represent and select an applicative entity. Visualization and Erasing orders are straightforward:
963 AIS_InteractiveContext::Display
964 (const Handle(AIS_InteractiveObject)& anIobj,
965 const Standard_Boolean updateviewer=Standard_True);
967 AIS_InteractiveContext::Display
968 (const Handle(AIS_InteractiveObject)& anIobj,
969 const Standard_Integer amode,
970 const Standard_Integer aSelectionMode,
971 const Standard_Boolean updateviewer = Standard_True,
972 const Standard_Boolean allowdecomposition = Standard_True);
974 AIS_InteractiveContext::Erase
975 AIS_InteractiveContext::EraseMode
976 AIS_InteractiveContext::ClearPrs
977 AIS_InteractiveContext::Redisplay
978 AIS_InteractiveContext::Remove
979 AIS_InteractiveContext::EraseAll
980 AIS_InteractiveContext::Hilight
981 AIS_InteractiveContext::HilightWithColor
984 Bear in mind the following points:
985 * It is recommended to display and erase interactive objects when no local context is opened, and open a local context for local selection only.
986 * The first *Display* function among the two ones available in *InteractiveContext* visualizes the object in its default mode (set with help of SetDisplayMode() method of InteractiveObject prior to Display() call), or in the default context mode, if applicable. If it has neither, the function displays it in 0 presentation mode. The object's default selection mode is automatically activated (0 mode by convention).
987 * Activating the displayed object by default can be turned off with help of *SetAutoActivateSelection()* method. This might be efficient if you are not interested in selection immediately after displaying an object.
988 * The second *Display* function should only be used in Neutral Point to visualize a supplementary mode for the object, which you can erase by *EraseMode (...)*. You activate the selection mode. This is passed as an argument. By convention, if you do not want to activate a selection mode, you must set the *SelectionMode* argument to -1. This function is especially interesting in open local context, as we will see below.
989 * In Neutral Point, it is not advisable to activate other selection modes than the default selection one. It is preferable to open a local context in order to activate particular selection modes.
990 * When you call *Erase(Interactive object)* function, the *PutIncollector* argument, which is *FALSE* by default, allows you to visualize the object directly in the Collector and makes it selectable (by activation of 0 mode). You can nonetheless block its passage through the Collector by changing the value of this option. In this case, the object is present in the Interactive Context, but is not seen anywhere.
991 * *Erase()* with *putInCollector = Standard_True* might be slow as it recomputes the object presentation in the Collector. Set *putInCollector* to *Standard_False* if you simply want to hide the object's presentation temporarily.
992 * Visualization attributes and graphic behavior can be modified through a set of functions similar to those for the interactive object (color, thickness of line, material, transparency, locations, etc.) The context then manages immediate and deferred updates.
993 * Call *Remove()* method of *InteractiveContext* as soon as the interactive object is no longer needed and you want to destroy it.. Otherwise, references to *InteractiveObject* are kept by *InteractiveContext*, and the *Object* is not destroyed, which results in memory leaks. In general, if the presentation of an interactive object can be computed quickly, it is recommended to *Remove()* it instead of using *Erase()* method.
995 @subsubsection occt_visu_3_4_4 Presentation in the Local Context
997 In open local context, the *Display* functions presented above can be as well.
1001 The function *AIS_InteractiveObject::Display* automatically activates the object's default selection mode. When you only want to visualize an Interactive Object in open Context, you must call the function *AIS_InteractiveContext::Display*.
1003 You can activate or deactivate specific selection modes in the local open context in several different ways:
1004 Use the Display functions with the appropriate modes.
1007 AIS_InteractiveContext::ActivateStandardMode
1008 //can be used only if a Local Context is opened.
1009 AIS_InteractiveContext::DeactivateStandardMode
1010 AIS_InteractiveContext::ActivatedStandardModes
1011 AIS_InteractiveContext::SetShapeDecomposition
1014 This activates the corresponding selection mode for all objects in Local Context, which accept decomposition into sub-shapes. Every new Object which has been loaded into the interactive context and which meets the decomposition criteria is automatically activated according to these modes.
1018 If you have opened a local context by loading an object with the default options <i>(AllowShapeDecomposition = Standard_True)</i>, all objects of the "Shape" type are also activated with the same modes. You can change the state of these "Standard" objects by using *SetShapeDecomposition(Status)*.
1020 Load an interactive object by the function *AIS_InteractiveContext::Load*.
1022 This function allows loading an Interactive Object whether it is visualized or not with a given selection mode, and/or with the necessary decomposition option. If *AllowDecomp=TRUE* and obviously, if the interactive object is of the "Shape" type, these "standard" selection modes will be automatically activated as a function of the modes present in the Local Context.
1024 Use *AIS_InteractiveContext::Activate* and *AIS_InteractiveContext::Deactivate* to directly activate/deactivate selection modes on an object.
1026 @subsubsection occt_visu_3_4_5 Filters
1028 To define an environment of dynamic detection, you can use standard filter classes or create your own.
1029 A filter questions the owner of the sensitive primitive in local context to determine if it has the desired qualities. If it answers positively, it is kept. If not, it is rejected.
1031 The root class of objects is *SelectMgr_Filter*. The principle behind it is straightforward: a filter tests to see whether the owners <i>(SelectMgr_EntityOwner)</i> detected in mouse position by the Local context selector answer *OK*. If so, it is kept, otherwise it is rejected.
1033 You can create a custom class of filter objects by implementing the deferred function *IsOk()*:
1036 class MyFilter : public SelectMgr_Filter { };
1037 virtual Standard_Boolean MyFilter::IsOk
1038 (const Handle(SelectMgr_EntityOwner)& anObj) const = 0;
1041 In *SelectMgr*, there are also Composition filters (AND Filters, OR Filters), which allow combining several filters. In InteractiveContext , all filters that you add are stocked in an OR filter (which answers *OK* if at least one filter answers *OK*).
1043 There are Standard filters, which have already been implemented in several packages:
1044 * *StdSelect_EdgeFilter* -- for edges, such as lines and circles;
1045 * *StdSelect_FaceFilter* -- for faces, such as planes, cylinders and spheres;
1046 * *StdSelect_ShapeTypeFilter* -- for shape types, such as compounds, solids, shells and wires;
1047 * *AIS_TypeFilter* -- for types of interactive objects;
1048 * *AIS_SignatureFilter* -- for types and signatures of interactive objects;
1049 * *AIS_AttributeFilter* -- for attributes of Interactive Objects, such as color and width.
1051 As there are specific behaviors on shapes, each new *Filter* class must, if necessary, redefine *AIS_LocalContext::ActsOn* function, which informs the Local Context if it acts on specific types of sub-shapes. By default, this function answers *FALSE*.
1055 Only type filters are activated in Neutral Point to make it possible to identify a specific type of visualized object. For filters to come into play, one or more object selection modes must be activated.
1057 There are several functions to manipulate filters:
1058 * *AIS_InteractiveContext::AddFilter* adds a filter passed as an argument.
1059 * *AIS_InteractiveContext::RemoveFilter* removes a filter passed as an argument.
1060 * *AIS_InteractiveContext::RemoveFilters* removes all present filters.
1061 * *AIS_InteractiveContext::Filters* gets the list of filters active in a local context.
1066 myContext->OpenLocalContext(Standard_False);
1067 // no object in neutral point is loaded
1069 myContext->ActivateStandardMode(TopAbs_Face);
1070 //activates decomposition of shapes into faces.
1071 Handle (AIS_Shape) myAIShape = new AIS_Shape ( ATopoShape);
1073 myContext->Display(myAIShape,1,-1,Standard_True,Standard_True);
1075 //shading visualization mode, no specific mode, authorization for decomposition into sub-shapes. At this Stage, myAIShape is decomposed into faces...
1077 Handle(StdSelect_FaceFilter) Fil1= new
1078 StdSelect_FaceFilter(StdSelect_Revol);
1079 Handle(StdSelect_FaceFilter) Fil2= new
1080 StdSelect_FaceFilter(StdSelect_Plane);
1082 myContext->AddFilter(Fil1);
1083 myContext->AddFilter(Fil2);
1085 //only faces of revolution or planar faces will be selected
1087 myContext->MoveTo( xpix,ypix,Vue);
1088 // detects the mouse position
1091 @subsubsection occt_visu_3_4_6 Selection in the Local Context
1093 Dynamic detection and selection are put into effect in a straightforward way. There are only a few conventions and functions to be familiar with. The functions are the same in neutral point and in open local context:
1094 * *AIS_InteractiveContext::MoveTo* -- passes mouse position to Interactive Context selectors
1095 * *AIS_InteractiveContext::Select* -- stocks what has been detected on the last *MoveTo*. Replaces the previously selected object. Empties the stack if nothing has been detected at the last move
1096 * *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. If not, it is withdrawn. Nothing happens if you click on an empty area.
1097 * *AIS_InteractiveContext::Select* -- selects everything found in the surrounding area.
1098 * *AIS_InteractiveContext::ShiftSelect* -- selects what was not previously in the list of selected, deselects those already present.
1100 Highlighting of detected and selected entities is automatically managed by the Interactive Context, whether you are in neutral point or Local Context. The Highlight colors are those dealt with above. You can nonetheless disconnect this automatic mode if you want to manage this part yourself :
1102 AIS_InteractiveContext::SetAutomaticHilight
1103 AIS_InteractiveContext::AutomaticHilight
1106 If there is no open local context, the objects selected are called **current objects**. If there is a local context, they are called **selected objects**. Iterators allow entities to be recovered in either case. A set of functions allows manipulating the objects, which have been placed in these different lists.
1110 When a Local Context is open, you can select entities other than interactive objects (vertices, edges etc.) from decompositions in standard modes, or from activation in specific modes on specific interactive objects. Only interactive objects are stocked in the list of selected objects.
1112 You can question the Interactive context by moving the mouse. The following functions can be used:
1113 * *AIS_InteractiveContext::HasDetected* informs if something has been detected;
1114 * *AIS_InteractiveContext::HasDetectedShape* informs if it is a shape;
1115 * *AIS_InteractiveContext::DetectedShape* gets the shape if the detected entity is an object;
1116 * *AIS_InteractiveContext::DetectedInteractive* gets the interactive object if the detected entity is an object.
1118 After using the *Select* and *ShiftSelect* functions in Neutral Point, you can explore the list of selections, referred to as current objects in this context. The following functions can be used:
1119 * *AIS_InteractiveContext::InitCurrent* initiates a scan of this list;
1120 * *AIS_InteractiveContext::MoreCurrent* extends the scan;
1121 * *AIS_InteractiveContext::NextCurrent* resumes the scan;
1122 * *AIS_InteractiveContext::Current* gets the name of the current object detected in the scan;
1123 * *AIS_InteractiveContext::FirstCurrentObject* gets the first current interactive object;
1124 * *AIS_InteractiveContext::HilightCurrents* highlights current objects;
1125 * *AIS_InteractiveContext::UnhilightCurrents* removes highlight from current objects;
1126 * *AIS_InteractiveContext::ClearCurrents* empties the list of current objects in order to update it;
1127 * *AIS_InteractiveContext::IsCurrent* finds the current object.
1129 In the Local Context, you can explore the list of selected objects available. The following functions can be used:
1130 * *AIS_InteractiveContext::InitSelected* initiates the list of objects;
1131 * *AIS_InteractiveContext::MoreSelected* extends the list of objects;
1132 * *AIS_InteractiveContext::NextSelected* resumes a scan;
1133 * *AIS_InteractiveContext::SelectedShape* gets the name of the selected object;
1134 * *AIS_InteractiveContext::HasSelectedShape* checks if the selected shape is obtained;
1135 * *AIS_InteractiveContext::Interactive* gets the picked interactive object;
1136 * *AIS_InteractiveContext::HasApplicative* checks if the applicative object has an owner from Interactive attributed to it;
1137 * *AIS_InteractiveContext::Applicative* gets the owner of the detected applicative entity;
1138 * *AIS_InteractiveContext::IsSelected* gets the name of the selected object.
1143 myAISCtx->InitSelected();
1144 while (myAISCtx->MoreSelected())
1146 if (myAISCtx->HasSelectedShape)
1148 TopoDS_Shape ashape = myAISCtx->SelectedShape();
1149 // to be able to use the picked shape
1153 Handle_AIS_InteractiveObject anyobj = myAISCtx->Interactive();
1154 // to be able to use the picked interactive object
1156 myAISCtx->NextSelected();
1160 You have to ask whether you have selected a shape or an interactive object before you can recover the entity in the Local Context or in the iteration loop. If you have selected a Shape from *TopoDS* on decomposition in standard mode, the *Interactive()* function returns the interactive object, which provided the selected shape. Other functions allow you to manipulate the content of Selected or Current Objects:
1161 * *AIS_InteractiveContext::EraseSelected* erases the selected objects;
1162 * *AIS_InteractiveContext::DisplaySelected* displays them;
1163 * *AIS_InteractiveContext::SetSelected* puts the objects in the list of selections;
1164 * *AIS_InteractiveContext::SetSelectedCurrent* takes the list of selected objects from a local context and puts it into the list of current objects in Neutral Point;
1165 * *AIS_InteractiveContext::AddOrRemoveSelected* adds or removes an object from the list of selected entities;
1166 * *AIS_InteractiveContext::HilightSelected* highlights the selected object;
1167 * *AIS_InteractiveContext::UnhilightSelected* removes highlighting from the selected object;
1168 * *AIS_InteractiveContext::ClearSelected* empties the list of selected objects.
1171 You can highlight and remove highlighting from a current object, and empty the list of current objects using the following functions:
1173 AIS_InteractiveContext::HilightCurrents
1174 AIS_InteractiveContext::UnhilightCurrents
1175 AIS_InteractiveContext::ClearCurrents
1177 When you are in an open Local Context, you may need to keep "temporary" interactive objects. This is possible using the following functions:
1178 * *AIS_InteractiveContext::KeepTemporary* transfers the characteristics of the interactive object seen in its local context (visualization mode, etc.) to the neutral point. When the local context is closed, the object does not disappear.
1179 * *AIS_InteractiveContext::SetSelectedCurrent* allows the selected object to become the current object when you close the local context.
1181 You can also want to use function *AIS_InteractiveContext::ClearLocalContext* to modify in a general way the state of the local context before continuing a selection (emptying objects, removing filters, standard activation modes).
1183 @subsubsection occt_visu_3_4_7 Recommendations
1185 The possibilities of use for local contexts are numerous depending on the type of operation that you want to perform:
1186 * working on all visualized interactive objects,
1187 * working on only a few objects,
1188 * working on a single object.
1190 When you want to work on one type of entity, you should open a local context with the option *UseDisplayedObjects* set to FALSE. Some functions which allow you to recover the visualized interactive objects, which have a given Type, and Signature from the "Neutral Point" are:
1193 AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& aListOfIO) const;
1194 AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive WhichKind, const Standard_Integer WhichSignature;
1195 AIS_ListOfInteractive& aListOfIO) const;
1198 At this stage, you only have to load the functions *Load, Activate,* and so on.
1200 When you open a Local Context with default options, you must keep the following points in mind:
1201 * The Interactive Objects visualized at Neutral Point are activated with their default selection mode. You must deactivate those, which you do not want to use.
1202 * The Shape Type Interactive Objects are automatically decomposed into sub-shapes when standard activation modes are launched.
1203 * The "temporary" Interactive Objects present in the Local Contexts are not automatically taken into account. You have to load them manually if you want to use them.
1205 The stages could be the following:
1206 1. Open a Local Context with the right options;
1207 2. Load/Visualize the required complementary objects with the desired activation modes.
1208 3. Activate Standard modes if necessary
1209 4. Create its filters and add them to the Local Context
1210 5. Detect/Select/recover the desired entities
1211 6. Close the Local Context with the adequate index.
1213 It is useful to create an **interactive editor**, to which you pass the Interactive Context. This allow setting up different contexts of selection/presentation according to the operation, which you want to perform.
1215 Let us assume that you have visualized several types of interactive objects: *AIS_Points*, *AIS_Axes*, *AIS_Trihedrons*, and *AIS_Shapes*.
1217 For your applicative function, you need an axis to create a revolved object. You could obtain this axis by identifying:
1218 * an axis which is already visualized,
1220 * a rectilinear edge on the shapes which are present,
1221 * a cylindrical face on the shapes (You will take the axis of this face)
1224 myIHMEditor::myIHMEditor
1225 (const Handle(AIS_InteractiveContext)& Ctx,
1232 myIHMEditor::PrepareContext()
1234 myIndex =myCtx->OpenLocalContext();
1238 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Point);
1239 //filter on the points
1241 Handle(AIS_SignatureFilter) F2 = new AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Axis);
1242 //filters on the axes.
1244 Handle(StdSelect_FaceFilter) F3 = new StdSelect_FaceFilter(AIS_Cylinder);
1245 //cylindrical face filters
1247 // activation of standard modes on the shapes..
1248 myCtx->ActivateStandardMode(TopAbs_FACE);
1249 myCtx->ActivateStandardMode(TopAbs_VERTEX);
1254 // at this point, you can call the selection/detection function
1257 void myIHMEditor::MoveTo(xpix,ypix,Vue)
1259 { myCTX->MoveTo(xpix,ypix,vue);
1260 // the highlight of what is detected is automatic.
1262 Standard_Boolean myIHMEditor::Select()
1264 // returns true if you should continue the selection
1266 myCTX->InitSelected();
1267 if(myCTX->MoreSelected())
1269 if(myCTX->HasSelectedShape())
1270 { const TopoDS_Shape& sh = myCTX->SelectedShape();
1274 //if it is the first vertex, you stock it, then you deactivate the faces and only keep the filter on the points:
1276 myCtx->RemoveFilters();
1277 myCTX->DeactivateStandardMode(TopAbs_FACE);
1279 // the filter on the AIS_Points
1280 myFirstV = Standard_False;
1281 return Standard_True;
1286 // construction of the axis return Standard_False;
1291 //it is a cylindrical face : you recover the axis; visualize it; and stock it.
1292 return Standard_False;
1295 // it is not a shape but is no doubt a point.
1298 Handle(AIS_InteractiveObject)
1299 SelObj = myCTX->SelectedInteractive();
1300 if(SelObj->Type()==AIS_KOI_Datum)
1302 if(SelObj->Signature()==1)
1307 return Standard_True;
1312 //construction of the axis, visualization, stocking
1313 return Standard_False;
1319 // you have selected an axis; stock the axis
1320 return Standard_False;
1326 void myIHMEditor::Terminate()
1328 myCtx->CloseLocalContext(myIndex);
1333 @subsection occt_visu_3_5 Standard Interactive Object Classes
1335 Interactive Objects are selectable and viewable objects connecting graphic representation and the underlying reference geometry.
1337 They are divided into four types:
1338 * the **Datum** -- a construction geometric element;
1339 * the **Relation** -- a constraint on the interactive shape and the corresponding reference geometry;
1340 * the **Object** -- a topological shape or connection between shapes;
1341 * **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.
1343 Inside these categories, there is a possibility of additional characterization by means of a signature. The signature provides an index to the further characterization. By default, the **Interactive Object** has a *None* type and a signature of 0 (equivalent to *None*).
1344 If you want to give a particular type and signature to your interactive object, you must redefine the two virtual methods: <i>Type</i> and <i>Signature</i>.
1346 @subsubsection occt_visu_3_5_1 Datum
1348 The **Datum** groups together the construction elements such as lines, circles, points, trihedrons, plane trihedrons, planes and axes.
1350 *AIS_Point, AIS_Axis, AIS_Line, AIS_Circle, AIS_Plane* and *AIS_Trihedron* have four selection modes:
1351 * mode 0 : selection of a trihedron;
1352 * mode 1 : selection of the origin of the trihedron;
1353 * mode 2 : selection of the axes;
1354 * mode 3 : selection of the planes XOY, YOZ, XOZ.
1356 when you activate one of modes: 1 2 3 4, you pick AIS objects of type:
1358 * *AIS_Axis* (and information on the type of axis)
1359 * *AIS_Plane* (and information on the type of plane).
1361 *AIS_PlaneTrihedron* offers three selection modes:
1362 * mode 0 : selection of the whole trihedron;
1363 * mode 1 : selection of the origin of the trihedron;
1364 * mode 2 : selection of the axes -- same remarks as for the Trihedron.
1366 For the presentation of planes and trihedra, the default length unit is millimeter and the default value for the representation of axes is 10. To modify these dimensions, you must temporarily recover the object **Drawer**. From it, take the *DatumAspect()* and change the value *FirstAxisLength*. Finally, recalculate the presentation.
1368 @subsubsection occt_visu_3_5_2 Object
1370 The **Object** type includes topological shapes, and connections between shapes.
1372 *AIS_Shape* has three visualization modes :
1373 * mode 0 : Line (default mode)
1374 * mode 1 : Shading (depending on the type of shape)
1375 * mode 2 : Bounding Box
1377 And at maximum seven selection modes, depending on the shape complexity:
1378 * mode 0 : selection of the *AIS_Shape*;
1379 * mode 1 : selection of the vertices;
1380 * mode 2 : selection of the edges;
1381 * mode 3 : selection of the wires;
1382 * mode 4 : selection of the faces;
1383 * mode 5 : selection of the shells;
1384 * mode 6 : selection of the constituent solids.
1386 * *AIS_Triangulation* is a simple interactive object for displaying triangular mesh contained in *Poly_Triangulation* container.
1387 * *AIS_ConnectedInteractive* is an Interactive Object connecting to another interactive object reference, and located elsewhere in the viewer makes it possible not to calculate presentation and selection, but to deduce them from your object reference.
1388 * *AIS_MultipleConnectedInteractive* is an object connected to a list of interactive objects (which can also be Connected objects. It does not require memory hungry calculations of presentation)
1389 * *AIS_TexturedShape* is an Interactive Object that supports texture mapping. It is constructed as a usual AIS_Shape, but has additional methods that allow to map a texture on it.
1390 * *MeshVS_Mesh* is an Interactive Object that represents meshes, it has a data source that provides geometrical information (nodes, elements) and can be built up from the source data with a custom presentation builder.
1393 The class *AIS_ColoredShape* allows using custom colors and line widths for *TopoDS_Shape* objects and their sub-shapes.
1396 AIS_ColoredShape aColoredShape = new AIS_ColoredShape (theShape);
1398 // setup color of entire shape
1399 aColoredShape->SetColor (Quantity_Color (Quantity_NOC_RED));
1401 // setup line width of entire shape
1402 aColoredShape->SetWidth (1.0);
1404 // set transparency value
1405 aColoredShape->SetTransparency (0.5);
1407 // customize color of specified sub-shape
1408 aColoredShape->SetCustomColor (theSubShape, Quantity_Color (Quantity_NOC_BLUE1));
1410 // customize line width of specified sub-shape
1411 aColoredShape->SetCustomWidth (theSubShape, 0.25);
1414 The presentation class *AIS_PointCloud* can be used for efficient drawing of large arbitrary sets of colored points. It uses *Graphic3d_ArrayOfPoints* to pass point data into OpenGl graphic driver to draw a set points as an array of "point sprites". The point data is packed into vertex buffer object for performance.
1415 - The type of point marker used to draw points can be specified as a presentation aspect.
1416 - The presentation provides selection by a bounding box of the visualized set of points. It supports two display / highlighting modes: points or bounding box.
1418 @image html point_cloud.png "A random colored cloud of points"
1422 Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (2000, Standard_True);
1423 aPoints->AddVertex (gp_Pnt(-40.0, -40.0, -40.0), Quantity_Color (Quantity_NOC_BLUE1));
1424 aPoints->AddVertex (gp_Pnt (40.0, 40.0, 40.0), Quantity_Color (Quantity_NOC_BLUE2));
1426 Handle(AIS_PointCloud) aPntCloud = new AIS_PointCloud();
1427 aPntCloud->SetPoints (aPoints);
1430 The draw command *vpointcloud* builds a cloud of points from shape triangulation.
1431 This command can also draw a sphere surface or a volume with a large amount of points (more than one million).
1434 @subsubsection occt_visu_3_5_3 Relations
1436 The **Relation** is made up of constraints on one or more interactive shapes and the corresponding reference geometry. For example, you might want to constrain two edges in a parallel relation. This constraint is considered as an object in its own right, and is shown as a sensitive primitive. This takes the graphic form of a perpendicular arrow marked with the || symbol and lying between the two edges.
1438 The following relations are provided by *AIS*:
1439 * *AIS_ConcentricRelation*
1441 * *AIS_IdenticRelation*
1442 * *AIS_ParallelRelation*
1443 * *AIS_PerpendicularRelation*
1445 * *AIS_SymmetricRelation*
1446 * *AIS_TangentRelation*
1448 The list of relations is not exhaustive.
1450 @subsubsection occt_visu_3_5_4 Dimensions
1451 * *AIS_AngleDimension*
1452 * *AIS_Chamf3dDimension*
1453 * *AIS_DiameterDimension*
1454 * *AIS_DimensionOwner*
1455 * *AIS_LengthDimension*
1456 * *AIS_OffsetDimension*
1457 * *AIS_RadiusDimension*
1459 @subsubsection occt_visu_3_5_5 MeshVS_Mesh
1461 *MeshVS_Mesh* is an Interactive Object that represents meshes. This 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. As a result, you can provide your own data source.
1463 However, 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.
1465 The presentations of *MeshVS_Mesh* are built with the presentation builders *MeshVS_PrsBuilder*. You can choose between the builders to represent the object in a different way. Moreover, you can redefine the base builder class and provide your own presentation builder.
1467 You can add/remove builders using the following methods:
1469 MeshVS_Mesh::AddBuilder (const Handle (MeshVS_PrsBuilder) &Builder, Standard_Boolean TreatAsHilighter)
1470 MeshVS_Mesh::RemoveBuilder (const Standard_Integer Index)
1471 MeshVS_Mesh::RemoveBuilderById (const Standard_Integer Id)
1474 There is a set of reserved display and highlighting mode flags for *MeshVS_Mesh*. Mode value is a number of bits that allows selecting additional display parameters and combining the following mode flags, which allow displaying mesh in wireframe, shading and shrink modes:
1476 MeshVS_DMF_WireFrame
1481 It is also possible to display deformed mesh in wireframe, shading or shrink modes usung :
1483 MeshVS_DMF_DeformedPrsWireFrame
1484 MeshVS_DMF_DeformedPrsShading
1485 MeshVS_DMF_DeformedPrsShrink
1488 The following methods represent different kinds of data :
1490 MeshVS_DMF_VectorDataPrs
1491 MeshVS_DMF_NodalColorDataPrs
1492 MeshVS_DMF_ElementalColorDataPrs
1493 MeshVS_DMF_TextDataPrs
1494 MeshVS_DMF_EntitiesWithData
1497 The following methods provide selection and highlighting :
1499 MeshVS_DMF_SelectionPrs
1500 MeshVS_DMF_HilightPrs
1503 *MeshVS_DMF_User* is a user-defined mode.
1505 These values will be used by the presentation builder.
1506 There is also a set of selection modes flags that can be grouped in a combination of bits:
1510 * *MeshVS_SMF_Volume*
1511 * *MeshVS_SMF_Element* -- groups *0D, Link, Face* and *Volume* as a bit mask ;
1513 * *MeshVS_SMF_All* -- groups *Element* and *Node* as a bit mask;
1515 * *MeshVS_SMF_Group*
1517 Such an object, for example, can be used for displaying the object and stored in the STL file format:
1520 // read the data and create a data source
1521 Handle (StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFileName);
1522 Handle (XSDRAWSTLVRML_DataSource) aDataSource = new XSDRAWSTLVRML_DataSource (aSTLMesh);
1525 Handle (MeshVS_Mesh) aMesh = new MeshVS();
1526 aMesh->SetDataSource (aDataSource);
1528 // use default presentation builder
1529 Handle (MeshVS_MeshPrsBuilder) aBuilder = new MeshVS_MeshPrsBuilder (aMesh);
1530 aMesh->AddBuilder (aBuilder, Standard_True);
1533 *MeshVS_NodalColorPrsBuilder* allows representing a mesh with a color scaled texture mapped on it.
1534 To do this you should define a color map for the color scale, pass this map to the presentation builder,
1535 and define an appropriate value in the range of 0.0 - 1.0 for every node.
1537 The following example demonstrates how you can do this (check if the view has been set up to display textures):
1540 // assign nodal builder to the mesh
1541 Handle (MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder
1542 (aMesh,MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
1543 aBuilder->UseTexture (Standard_True);
1545 // prepare color map
1546 Aspect_SequenceOfColor aColorMap;
1547 aColorMap.Append ((Quantity_NameOfColor) Quantity_NOC_RED);
1548 aColorMap.Append ((Quantity_NameOfColor) Quantity_NOC_BLUE1);
1550 // assign color scale map values (0..1) to nodes
1551 TColStd_DataMapOfIntegerReal aScaleMap;
1553 // iterate through the nodes and add an node id and an appropriate value to the map
1554 aScaleMap.Bind (anId, aValue);
1556 // pass color map and color scale values to the builder
1557 aBuilder->SetColorMap (aColorMap);
1558 aBuilder->SetInvalidColor (Quantity_NOC_BLACK);
1559 aBuilder->SetTextureCoords (aScaleMap);
1560 aMesh->AddBuilder (aBuilder, Standard_True);
1563 @subsection occt_visu_3_6 Dynamic Selection
1565 The dynamic selection represents the topological shape, which you want to select, by decomposition of <i>sensitive primitives</i> -- the sub-parts of the shape that will be detected and highlighted. The sets of these primitives are handled by the powerful three-level BVH tree selection algorithm.
1567 For more details on the algorithm and examples of usage, please, refer to @ref occt_visu_2_2 "Selection" chapter.
1569 @section occt_visu_4 3D Presentations
1571 @subsection occt_visu_4_1 Glossary of 3D terms
1573 * **Anti-aliasing** This mode attempts to improve the screen resolution by drawing lines and curves in a mixture of colors so that to the human eye the line or curve is smooth. The quality of the result is linked to the quality of the algorithm used by the workstation hardware.
1574 * **Group** -- a set of primitives and attributes on those primitives. Primitives and attributes may be added to a group but cannot be removed from it, unless erased globally. A group can have a pick identity.
1575 * **Light** There are five kinds of light source -- ambient, headlight, directional, positional and spot. The light is only activated in a shading context in a view.
1576 * **Primitive** -- a drawable element. It has a definition in 3D space. Primitives can either be lines, faces, text, or markers. Once displayed markers and text remain the same size. Lines and faces can be modified e.g. zoomed. Primitives must be stored in a group.
1577 * **Structure** -- manages a set of groups. The groups are mutually exclusive. A structure can be edited, adding or removing groups. A structure can reference other structures to form a hierarchy. It has a default (identity) transformation and other transformations may be applied to it (rotation, translation, scale, etc). It has no default attributes for the primitive lines, faces, markers, and text. Attributes may be set in a structure but they are overridden by the attributes in each group. Each structure has a display priority associated with it, which rules the order in which it is redrawn in a 3D viewer. If the visualization mode is incompatible with the view it is not displayed in that view, e.g. a shading-only object is not visualized in a wireframe view.
1578 * **View** -- is defined by a view orientation, a view mapping, and a context view.
1579 * **Viewer** -- manages a set of views.
1580 * **View orientation** -- defines the manner in which the observer looks at the scene in terms of View Reference Coordinates.
1581 * **View mapping** -- defines the transformation from View Reference Coordinates to the Normalized Projection Coordinates. This follows the Phigs scheme.
1582 * **Z-Buffering** -- a form of hidden surface removal in shading mode only. This is always active for a view in the shading mode. It cannot be suppressed.
1584 @subsection occt_visu_4_2 Graphic primitives
1586 The *Graphic3d* package is used to create 3D graphic objects in a 3D viewer. These objects called **structures** are made up of groups of primitives and attributes, such as polylines, planar polygons with or without holes, text and markers, and attributes, such as color, transparency, reflection, line type, line width, and text font. A group is the smallest editable element of a structure. A transformation can be applied to a structure. Structures can be connected to form a tree of structures, composed by transformations. Structures are globally manipulated by the viewer.
1588 Graphic structures can be:
1593 * Connected to form a tree hierarchy of structures, created by transformations.
1595 There are classes for:
1596 * Visual attributes for lines, faces, markers, text, materials,
1597 * Vectors and vertices,
1598 * Graphic objects, groups, and structures.
1600 @subsubsection occt_visu_4_2_2 Structure hierarchies
1602 The root is the top of a structure hierarchy or structure network. The attributes of a parent structure are passed to its descendants. The attributes of the descendant structures do not affect the parent. Recursive structure networks are not supported.
1604 @subsubsection occt_visu_4_2_3 Graphic primitives
1606 * Have one or more vertices,
1607 * Have a type, a scale factor, and a color,
1608 * Have a size, shape, and orientation independent of transformations.
1610 * Have one closed boundary,
1611 * Have at least three vertices,
1612 * Are planar and have a normal,
1613 * Have interior attributes -- style, color, front and back material, texture and reflection ratio,
1614 * Have a boundary with the following attributes -- type, width scale factor, color. The boundary is only drawn when the interior style is hollow.
1616 * **Polygons with holes**
1617 * Have multiple closed boundaries, each one with at least three vertices,
1618 * Are planar and have a normal,
1619 * Have interior attributes -- style, color, front and back material,
1620 * Have a boundary with the following attributes -- type, width scale factor, color. The boundary is only drawn when the interior style is hollow.
1623 * Have two or more vertices,
1624 * Have the following attributes -- type, width scale factor, color.
1627 * Has geometric and non-geometric attributes,
1628 * Geometric attributes -- character height, character up vector, text path, horizontal and vertical alignment, orientation, three-dimensional position, zoomable flag
1629 * Non-geometric attributes -- text font, character spacing, character expansion factor, color.
1631 @subsubsection occt_visu_4_2_4 Primitive arrays
1633 Primitive arrays are a more efficient approach to describe and display the primitives from the aspects of memory usage and graphical performance. The key feature of the primitive arrays is that the primitive data is not duplicated. For example, two polygons could share the same vertices, so it is more efficient to keep the vertices in a single array and specify the polygon vertices with indices of this array. In addition to such kind of memory savings, the OpenGl graphics driver provides the Vertex Buffer Objects (VBO). VBO is a sort of video memory storage that can be allocated to hold the primitive arrays, thus making the display operations more efficient and releasing the RAM memory.
1635 The Vertex Buffer Objects are enabled by default, but VBOs availability depends on the implementation of OpenGl. If the VBOs are unavailable or there is not enough video memory to store the primitive arrays, the RAM memory will be used to store the arrays.
1637 The Vertex Buffer Objects can be disabled at the application level. You can use the method *Graphic3d_GraphicDriver::EnableVBO (const Standard_Boolean status)* to enable/disable VBOs:
1639 The following example shows how to disable the VBO support:
1642 // get the graphic driver
1643 Handle (Graphic3d_GraphicDriver) aDriver =
1644 myAISContext->CurrentViewer()->Driver();
1646 // disable VBO support
1647 aDriver->EnableVBO (Standard_False);
1650 **Note** that the use of Vertex Buffer Objects requires the application level primitive data provided by the *Graphic3d_ArrayOfPrimitives* to be transferred to the video memory. *TKOpenGl* transfers the data and releases the *Graphic3d_ArrayOfPrimitives* internal pointers to the primitive data. Thus it might be necessary to pay attention to such kind of behaviour, as the pointers could be modified (nullified) by the *TKOpenGl*.
1652 The different types of primitives could be presented with the following primitive arrays:
1653 * *Graphic3d_ArrayOfPoints,*
1654 * *Graphic3d_ArrayOfPolygons,*
1655 * *Graphic3d_ArrayOfPolylines,*
1656 * *Graphic3d_ArrayOfQuadrangles,*
1657 * *Graphic3d_ArrayOfQuadrangleStrips,*
1658 * *Graphic3d_ArrayOfSegments,*
1659 * *Graphic3d_ArrayOfTriangleFans,*
1660 * *Graphic3d_ArrayOfTriangles,*
1661 * *Graphic3d_ArrayOfTriangleStrips.*
1663 The *Graphic3d_ArrayOfPrimitives* is a base class for these primitive arrays.
1665 Method *Graphic3d_ArrayOfPrimitives::AddVertex* allows adding There is a set of similar methods to add vertices to the primitive array.
1667 These methods take vertex coordinates as an argument and allow you to define the color, the normal and the texture coordinates assigned to the vertex. The return value is the actual number of vertices in the array.
1669 You can also modify the values assigned to the vertex or query these values by the vertex index:
1670 * *void Graphic3d_ArrayOfPrimitives::SetVertice*
1671 * *void Graphic3d_ArrayOfPrimitives::SetVertexColor*
1672 * *void Graphic3d_ArrayOfPrimitives::SetVertexNormal*
1673 * *void Graphic3d_ArrayOfPrimitives::SetVertexTexel*
1674 * *gp_Pnt Graphic3d_ArrayOfPrimitives::Vertices*
1675 * *gp_Dir Graphic3d_ArrayOfPrimitives::VertexNormal*
1676 * *gp_Pnt3d Graphic3d_ArrayOfPrimitives::VertexTexel*
1677 * *Quantity_Color Graphic3d_ArrayOfPrimitives::VertexColor*
1678 * *void Graphic3d_ArrayOfPrimitives::Vertices*
1679 * *void Graphic3d_ArrayOfPrimitives::VertexNormal*
1680 * *void Graphic3d_ArrayOfPrimitives::VertexTexel*
1681 * *void Graphic3d_ArrayOfPrimitives::VertexColor*
1683 The following example shows how to define an array of points:
1687 Handle (Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (aVerticiesMaxCount);
1689 // add vertices to the array
1690 anArray->AddVertex (10.0, 10.0, 10.0);
1691 anArray->AddVertex (0.0, 10.0, 10.0);
1693 // add the array to the structure
1694 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
1695 aGroup->BeginPrimitives ();
1696 aGroup->AddPrimitiveArray (anArray);
1697 aGroup->EndPrimitives ();
1700 If the primitives share the same vertices (polygons, triangles, etc.) then you can define them as indices of the vertices array.
1702 The method *Graphic3d_ArrayOfPrimitives::AddEdge* allows defining the primitives by indices. This method adds an "edge" in the range <i> [1, VertexNumber() ] </i> in the array.
1704 It is also possible to query the vertex defined by an edge using method *Graphic3d_ArrayOfPrimitives::Edge*
1706 The following example shows how to define an array of triangles:
1710 Standard_Boolean IsNormals = Standard_False;
1711 Standard_Boolean IsColors = Standard_False;
1712 Standard_Boolean IsTextureCrds = Standard_False;
1713 Handle (Graphic3d_ArrayOfTriangles) anArray =
1714 new Graphic3d_ArrayOfTriangles (aVerticesMaxCount,
1719 // add vertices to the array
1720 anArray->AddVertex (-1.0, 0.0, 0.0); // vertex 1
1721 anArray->AddVertex ( 1.0, 0.0, 0.0); // vertex 2
1722 anArray->AddVertex ( 0.0, 1.0, 0.0); // vertex 3
1723 anArray->AddVertex ( 0.0,-1.0, 0.0); // vertex 4
1725 // add edges to the array
1726 anArray->AddEdge (1); // first triangle
1727 anArray->AddEdge (2);
1728 anArray->AddEdge (3);
1729 anArray->AddEdge (1); // second triangle
1730 anArray->AddEdge (2);
1731 anArray->AddEdge (4);
1733 // add the array to the structure
1734 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
1735 aGroup->BeginPrimitives ();
1736 aGroup->AddPrimitiveArray (anArray);
1737 aGroup->EndPrimitives ();
1740 If the primitive array presents primitives built from sequential sets of vertices, for example polygons, then you can specify the bounds, or the number of vertices for each primitive. You can use the method *Graphic3d_ArrayOfPrimitives::AddBound* to define the bounds and the color for each bound. This method returns the actual number of bounds.
1742 It is also possible to set the color and query the number of edges in the bound and bound color.
1744 Standard_Integer Graphic3d_ArrayOfPrimitives::Bound
1745 Quantity_Color Graphic3d_ArrayOfPrimitives::BoundColor
1746 void Graphic3d_ArrayOfPrimitives::BoundColor
1749 The following example shows how to define an array of polygons:
1753 Standard_Boolean IsNormals = Standard_False;
1754 Standard_Boolean IsVertexColors = Standard_False;
1755 Standard_Boolean IsFaceColors = Standard_False;
1756 Standard_Boolean IsTextureCrds = Standard_False;
1757 Handle (Graphic3d_ArrayOfPolygons) anArray =
1758 new Graphic3d_ArrayOfPolygons (aVerticesMaxCount,
1766 // add bounds to the array, first polygon
1767 anArray->AddBound (3);
1768 anArray->AddVertex (-1.0, 0.0, 0.0);
1769 anArray->AddVertex ( 1.0, 0.0, 0.0);
1770 anArray->AddVertex ( 0.0, 1.0, 0.0);
1772 // add bounds to the array, second polygon
1773 anArray->AddBound (4);
1774 anArray->AddVertex (-1.0, 0.0, 0.0);
1775 anArray->AddVertex ( 1.0, 0.0, 0.0);
1776 anArray->AddVertex ( 1.0,-1.0, 0.0);
1777 anArray->AddVertex (-1.0,-1.0, 0.0);
1779 // add the array to the structure
1780 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
1781 aGroup->BeginPrimitives ();
1782 aGroup->AddPrimitiveArray (anArray);
1783 aGroup->EndPrimitives ();
1786 There are also several helper methods. You can get the type of the primitive array:
1788 Graphic3d_TypeOfPrimitiveArray
1789 Graphic3d_ArrayOfPrimitives::Type
1790 Standard_CString Graphic3d_ArrayOfPrimitives::StringType
1793 and check if the primitive array provides normals, vertex colors and vertex texels (texture coordinates):
1796 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals
1797 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors
1798 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels
1800 or get the number of vertices, edges and bounds:
1802 Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber
1803 Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber
1804 Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber
1807 @subsubsection occt_visu_4_2_5 Text primitive
1809 The OpenGl graphics driver uses advanced text rendering powered by FTGL library. This library provides vector text rendering, as a result the text can be rotated and zoomed without quality loss.
1810 *Graphic3d* text primitives have the following features:
1811 * fixed size (non-zoomable) or zoomable,
1812 * can be rotated to any angle in the view plane,
1813 * support unicode charset.
1815 The text attributes for the group could be defined with the *Graphic3d_AspectText3d* attributes group.
1816 To add any text to the graphic structure you can use the following methods:
1818 void Graphic3d_Group::Text
1819 (const Standard_CString AText,
1820 const Graphic3d_Vertex& APoint,
1821 const Standard_Real AHeight,
1822 const Quantity_PlaneAngle AAngle,
1823 const Graphic3d_TextPath ATp,
1824 const Graphic3d_HorizontalTextAlignment AHta,
1825 const Graphic3d_VerticalTextAlignment AVta,
1826 const Standard_Boolean EvalMinMax),
1828 *AText* parameter is the text string, *APoint* is the three-dimensional position of the text, *AHeight* is the text height, *AAngle* is the orientation of the text (at the moment, this parameter has no effect, but you can specify the text orientation through the *Graphic3d_AspectText3d* attributes).
1830 *ATp* parameter defines the text path, *AHta* is the horizontal alignment of the text, *AVta* is the vertical alignment of the text.
1832 You can pass *Standard_False* as *EvalMinMax* if you do not want the graphic3d structure boundaries to be affected by the text position.
1834 **Note** that the text orientation angle can be defined by *Graphic3d_AspectText3d* attributes.
1836 void Graphic3d_Group::Text
1837 (const Standard_CString AText,
1838 const Graphic3d_Vertex& APoint,
1839 const Standard_Real AHeight,
1840 const Standard_Boolean EvalMinMax)
1841 void Graphic3d_Group::Text
1842 (const TCcollection_ExtendedString &AText,
1843 const Graphic3d_Vertex& APoint,
1844 const Standard_Real AHeight,
1845 const Quantity_PlaneAngle AAngle,
1846 const Graphic3d_TextPath ATp,
1847 const Graphic3d_HorizontalTextAlignment AHta,
1848 const Graphic3d_VerticalTextAlignment AVta,
1849 const Standard_Boolean EvalMinMax)
1850 void Graphic3d_Group::Text
1851 (const TCcollection_ExtendedString &AText,
1852 const Graphic3d_Vertex& APoint,
1853 const Standard_Real AHeight,
1854 const Standard_Boolean EvalMinMax)
1860 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
1862 // change the text aspect
1863 Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d ();
1864 aTextAspect->SetTextZoomable (Standard_True);
1865 aTextAspect->SetTextAngle (45.0);
1866 aGroup->SetPrimitivesAspect (aTextAspect);
1868 // add a text primitive to the structure
1869 Graphic3d_Vertex aPoint (1, 1, 1);
1870 aGroup->Text (Standard_CString ("Text"), aPoint, 16.0);
1873 @subsubsection occt_visu_4_2_6 Materials
1875 A *Graphic3d_MaterialAspect* is defined by:
1877 * Diffuse reflection -- a component of the object color;
1878 * Ambient reflection;
1879 * Specular reflection -- a component of the color of the light source;
1882 The following items are required to determine the three colors of reflection:
1884 * Coefficient of diffuse reflection;
1885 * Coefficient of ambient reflection;
1886 * Coefficient of specular reflection.
1888 @subsubsection occt_visu_4_2_7 Textures
1890 A *texture* is defined by a name.
1891 Three types of texture are available:
1894 * Environment mapping.
1896 @subsubsection occt_visu_4_2_8 Shaders
1898 OCCT visualization core supports GLSL shaders. Currently OCCT supports only vertex and fragment GLSL shader. Shaders can be assigned to a generic presentation by its drawer attributes (Graphic3d aspects). To enable custom shader for a specific AISShape in your application, the following API functions are used:
1901 // Create shader program
1902 Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
1904 // Attach vertex shader
1905 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
1906 Graphic3d_TOS_VERTEX, "<Path to VS>"));
1908 // Attach fragment shader
1909 aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
1910 Graphic3d_TOS_FRAGMENT, "<Path to FS>"));
1912 // Set values for custom uniform variables (if they are)
1913 aProgram->PushVariable ("MyColor", Graphic3d_Vec3(0.0f, 1.0f, 0.0f));
1915 // Set aspect property for specific AISShape
1916 theAISShape->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);
1919 @subsection occt_visu_4_3 Graphic attributes
1921 @subsubsection occt_visu_4_3_1 Aspect package overview
1923 The *Aspect* package provides classes for the graphic elements in the viewer:
1924 * Groups of graphic attributes;
1925 * Edges, lines, background;
1928 * Enumerations for many of the above.
1930 @subsection occt_visu_4_4 3D view facilities
1932 @subsubsection occt_visu_4_4_1 Overview
1934 The *V3d* package provides the resources to define a 3D viewer and the views attached to this viewer (orthographic, perspective). This package provides the commands to manipulate the graphic scene of any 3D object visualized in a view on screen.
1936 A 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.
1938 The *V3d* package is basically a set of tools directed by commands from the viewer front-end. This tool set contains methods for creating and editing classes of the viewer such as:
1939 * Default parameters of the viewer,
1940 * Views (orthographic, perspective),
1941 * Lighting (positional, directional, ambient, spot, headlight),
1943 * Instantiated sequences of views, planes, light sources, graphic structures, and picks,
1944 * Various package methods.
1946 @subsubsection occt_visu_4_4_2 A programming example
1948 This sample TEST program for the *V3d* Package uses primary packages *Xw* and *Graphic3d* and secondary packages *Visual3d, Aspect, Quantity* and *math*.
1951 // Create a default display connection
1952 Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
1954 // Create a Graphic Driver from the default Aspect_DisplayConnection
1955 Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection);
1957 // Create a Viewer to this Driver
1958 Handle(V3d_Viewer) VM = new V3d_Viewer (aGraphicDriver);
1959 VM->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET);
1960 VM->SetDefaultViewProj (V3d_Xpos);
1961 // Create a structure in this Viewer
1962 Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (VM->Viewer());
1964 // Type of structure
1965 aStruct->SetVisual (Graphic3d_TOS_SHADING);
1967 // Create a group of primitives in this structure
1968 Handle(Graphic3d_Group) aPrsGroup = new Graphic3d_Group (aStruct);
1970 // Fill this group with one quad of size 100
1971 Handle(Graphic3d_ArrayOfTriangleStrips) aTriangles = new Graphic3d_ArrayOfTriangleStrips (4);
1972 aTriangles->AddVertex (-100./2., -100./2., 0.0);
1973 aTriangles->AddVertex (-100./2., 100./2., 0.0);
1974 aTriangles->AddVertex ( 100./2., -100./2., 0.0);
1975 aTriangles->AddVertex ( 100./2., 100./2., 0.0);
1976 aPrsGroup->Polygon (aTriangles);
1978 // Create Ambient and Infinite Lights in this Viewer
1979 Handle(V3d_AmbientLight) aLight1 = new V3d_AmbientLight (VM, Quantity_NOC_GRAY50);
1980 Handle(V3d_DirectionalLight) aLight2 = new V3d_DirectionalLight (VM, V3d_XnegYnegZneg, Quantity_NOC_WHITE);
1982 // Create a 3D quality Window with the same DisplayConnection
1983 Handle(Xw_Window) aWindow = new Xw_Window (aDispConnection, "Test V3d", 0.5, 0.5, 0.5, 0.5);
1985 // Map this Window to this screen
1988 // Create a Perspective View in this Viewer
1989 Handle(V3d_View) aView = new V3d_View (VM);
1990 aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
1991 // Associate this View with the Window
1992 aView ->SetWindow (aWindow);
1993 // Display ALL structures in this View
1994 VM->Viewer()->Display();
1995 // Finally update the Visualization in this View
1999 As an alternative to manual setting of perspective parameters the *V3d_View::ZfitAll()* and *V3d_View::FitAll()* functions can be used:
2002 // Display shape in Viewer VM
2003 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (VM);
2004 aContext->Display(shape);
2005 // Create a Perspective View in Viewer VM
2006 Handle(V3d_View) V = new V3d_View (VM);
2007 aview->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
2008 // Change Z-min and Z-max planes of projection volume to match the displayed objects
2010 // Fit view to object size
2014 @subsubsection occt_visu_4_4_3 Define viewing parameters
2016 View projection and orientation in OCCT *v3d* view are driven by camera. The camera calculates and supplies projection and view orientation matrices for rendering by OpenGL. The allows to the user to control all projection parameters. The camera is defined by the following properties:
2018 * **Eye** -- defines the observer (camera) position. Make sure the Eye point never gets between the Front and Back clipping planes.
2020 * **Center** -- defines the origin of View Reference Coordinates (where camera is aimed at).
2022 * **Direction** -- defines the direction of camera view (from the Eye to the Center).
2024 * **Distance** -- defines the distance between the Eye and the Center.
2026 * **Front** Plane -- defines the position of the front clipping plane in View Reference Coordinates system.
2028 * **Back** Plane -- defines the position of the back clipping plane in View Reference Coordinates system.
2030 * **ZNear** -- defines the distance between the Eye and the Front plane.
2032 * **ZFar** -- defines the distance between the Eye and the Back plane.
2034 Most common view manipulations (panning, zooming, rotation) are implemented as convenience methods of *V3d_View* class, however *Graphic3d_Camera* class can also be used directly by application developers:
2038 // rotate camera by X axis on 30.0 degrees
2040 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0)), 30.0);
2041 aView->Camera()->Transform (aTrsf);
2044 @subsubsection occt_visu_4_4_4 Orthographic Projection
2046 @image html view_frustum.png "Perspective and orthographic projection"
2048 The following code configures the camera for orthographic rendering:
2051 // Create an orthographic View in this Viewer
2052 Handle(V3d_View) aView = new V3d_View (VM);
2053 aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
2054 // update the Visualization in this View
2058 @subsubsection occt_visu_4_4_5 Perspective Projection
2060 **Field of view (FOVy)** -- defines the field of camera view by y axis in degrees (45° is default).
2062 @image html camera_perspective.png "Perspective frustum"
2064 The following code configures the camera for perspective rendering:
2067 // Create a perspective View in this Viewer
2068 Handle(V3d_View) aView = new V3d_View(VM);
2069 aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
2074 @subsubsection occt_visu_4_4_6 Stereographic Projection
2076 **IOD** -- defines the intraocular distance (in world space units).
2078 There are two types of IOD:
2079 * _IODType_Absolute_ : Intraocular distance is defined as an absolute value.
2080 * _IODType_Relative_ : Intraocular distance is defined relative to the camera focal length (as its coefficient).
2082 **Field of view (FOV)** -- defines the field of camera view by y axis in degrees (45° is default).
2084 **ZFocus** -- defines the distance to the point of stereographic focus.
2086 @image html stereo.png "Stereographic projection"
2088 To enable stereo projection, your workstation should meet the following requirements:
2090 * The graphic card should support quad buffering.
2091 * You need active 3D glasses (LCD shutter glasses).
2092 * The graphic driver needs to be configured to impose quad buffering for newly created OpenGl contexts; the viewer and the view should be created after that.
2094 In stereographic projection mode the camera prepares two projection matrices to display different stereo-pictures for the left and for the right eye. In a non-stereo camera this effect is not visible because only the same projection is used for both eyes.
2096 To enable quad buffering support you should provide the following settings to the graphic driver *opengl_caps*:
2099 Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver();
2100 OpenGl_Caps& aCaps = aDriver->ChangeOptions();
2101 aCaps.contextStereo = Standard_True;
2104 The following code configures the camera for stereographic rendering:
2107 // Create a Stereographic View in this Viewer
2108 Handle(V3d_View) aView = new V3d_View(VM);
2109 aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
2110 // Change stereo parameters
2111 aView->Camera()->SetIOD (IODType_Absolute, 5.0);
2112 // Finally update the Visualization in this View
2116 @subsubsection occt_visu_4_4_7 View frustum culling
2118 The algorithm of frustum culling on CPU-side is activated by default for 3D viewer. This algorithm allows skipping the presentation outside camera at the rendering stage, providing better performance. The following features support this method:
2119 * *Graphic3d_Structure::CalculateBoundBox()* is used to calculate axis-aligned bounding box of a presentation considering its transformation.
2120 * *V3d_View::SetFrustumCulling* enables or disables frustum culling for the specified view.
2121 * Classes *OpenGl_BVHClipPrimitiveSet* and *OpenGl_BVHTreeSelector* handle the detection of outer objects and usage of acceleration structure for frustum culling.
2122 * *BVH_BinnedBuilder* class splits several objects with null bounding box.
2124 @subsubsection occt_visu_4_4_8 Underlay and overlay layers management
2126 In addition to interactive 3d graphics displayed in the view you can display underlying and overlying graphics: text, color scales and drawings.
2128 All *V3d* view graphical objects in the overlay are managed by the default layer manager (*V3d_LayerMgr*). The *V3d* view has a basic layer manager capable of displaying the color scale, but you can redefine this class to provide your own overlay and underlay graphics.
2130 The method *V3d_View::SetLayerMgr(const Handle (V3d_LayerMgr)& aMgr)* allows assigning a custom layer manager to the *V3d* view.
2132 There are three virtual methods to prepare graphics in the manager for further drawing: setting up layer dimensions and drawing static graphics. These methods can be redefined:
2135 void V3d_LayerMgr::Begin ()
2136 void V3d_LayerMgr::Redraw ()
2137 void V3d_LayerMgr::End ()
2140 The layer manager controls layers (*Visual3d_Layer*) and layer items (*Visual3d_LayerItem*). Both the overlay and underlay layers can be created by the layer manager.
2142 The layer entity is presented by the *Visual3d_Layer* class. This entity provides drawing services in the layer, for example:
2144 void Visual3d_Layer::DrawText
2145 void Visual3d_Layer::DrawRectangle
2146 void Visual3d_Layer::SetColor
2147 void Visual3d_Layer::SetViewport
2150 The following example demonstrates how to draw overlay graphics by the *V3d_LayerMgr*:
2153 // redefined method of V3d_LayerMgr
2154 void MyLayerMgr::Redraw ()
2156 Quantity_Color aRed (Quantity_NOC_RED);
2157 myOverlayLayer->SetColor (aRed);
2158 myOverlayLayer->DrawRectangle (0, 0, 100, 100);
2162 The layer contains layer items that will be displayed on view redraw. Such items are *Visual3d_LayerItem* entities. To manipulate *Visual3d_LayerItem* entities assigned to the layer's internal list you can use the following methods:
2165 void Visual3d_Layer::AddLayerItem (const Handle (Visual3d_LayerItem)& Item)
2166 void Visual3d_Layer::RemoveLayerItem (const Handle (Visual3d_LayerItem)& Item)
2167 void Visual3d_Layer::RemoveAllLayerItems ()
2168 const Visual3d_NListOfLayerItem& Visual3d_Layer::GetLayerItemList ()
2170 The layer's items are rendered when the method *void Visual3d_Layer::RenderLayerItems()* is called by the graphical driver.
2172 The *Visual3d_LayerItem* has virtual methods that are used to render the item:
2174 void Visual3d_LayerItem::RedrawLayerPrs ()
2175 void Visual3d_LayerItem::ComputeLayerPrs ()
2178 The item presentation can be computed before drawing by the *ComputeLayerPrs* method to save time on redraw. It also has an additional flag that is used to tell that the presentation should be recomputed:
2180 void Visual3d_LayerItem::SetNeedToRecompute (const Standard_Boolean NeedToRecompute)
2181 Standard_Boolean Visual3d_LayerItem::IsNeedToRecompute
2184 An example of *Visual3d_LayerItem* is *V3d_ColorScaleLayerItem* that represents the color scale entity as the layer's item.
2185 The *V3d_ColorScaleLayerItem* sends render requests to the color scale entity represented by it. As this entity (*V3d_ColorScale*) is assigned to the *V3d_LayerMgr* it uses its overlay layer's services for drawing:
2190 // tell V3d_ColorScale to draw itself
2191 void V3d_ColorScaleLayerItem::RedrawLayerPrs ()
2193 Visual3d_LayerItem::RedrawLayerPrs ()
2194 if (!MyColorScale.IsNull ())
2195 MyColorScale->DrawScale ();
2198 // V3d_ColorScale has a reference to a LayerMgr
2199 void V3d_ColorScale::DrawScale ()
2201 // calls V3d_ColorScale::PaintRect, V3d_ColorScale::PaintText, etc.
2204 // PaintRect method uses overlay layer of LayerMgr to draw a rectangle
2205 void V3d_ColorScale::PaintRect
2206 (const Standard_Integer X, const Standard_Integer Y,
2207 const Standard_Integer W, const Standard_Integer H,
2208 const Quantity_Color aColor,
2209 const Standard_Boolean aFilled)
2211 const Handle (Visual3d_Layer)& theLayer = myLayerMgr->Overlay ();
2213 theLayer->SetColor (aColor);
2214 theLayer->DrawRectangle (X, Y, W, H);
2219 @subsubsection occt_visu_4_4_9 View background styles
2220 There are three types of background styles available for *V3d_view*: solid color, gradient color and image.
2222 To set solid color for the background you can use the following methods:
2224 void V3d_View::SetBackgroundColor
2225 (const Quantity_TypeOfColor Type,
2226 const Quantity_Parameter V1,
2227 const Quantity_Parameter V2,
2228 const Quantity_Parameter V3)
2231 This method allows you to specify the background color in RGB (red, green, blue) or HLS (hue, lightness, saturation) color spaces, so the appropriate values of the Type parameter are *Quantity_TOC_RGB* and *Quantity_TOC_HLS*.
2233 **Note** that the color value parameters *V1,V2,V3* should be in the range between *0.0-1.0.*
2236 void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
2237 void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
2240 The gradient background style could be set up with the following methods:
2242 void V3d_View::SetBgGradientColors
2243 (const Quantity_Color& Color1,
2244 const Quantity_Color& Color2,
2245 const Aspect_GradientFillMethod FillStyle,
2246 const Standard_Boolean update)
2248 void V3d_View::SetBgGradientColors
2249 (const Quantity_NameOfColor Color1,
2250 const Quantity_NameOfColor Color2,
2251 const Aspect_GradientFillMethod FillStyle,
2252 const Standard_Boolean update)
2255 The *Color1* and *Color2* parameters define the boundary colors of interpolation, the *FillStyle* parameter defines the direction of interpolation. You can pass *Standard_True* as the last parameter to update the view.
2257 The fill style can be also set with the method *void V3d_View::SetBgGradientStyle(const Aspect_GradientFillMethod AMethod, const Standard_Boolean update)*.
2259 To get the current background color you can use the following methods:
2261 void V3d_View::BackgroundColor
2262 (const Quantity_TypeOfColor Type,
2263 Quantity_Parameter &V1,
2264 Quantity_Parameter &V2,
2265 Quantity_Parameter &V3)
2266 Quantity_Color V3d_View::BackgroundColor()
2267 void V3d_View::GradientBackgroundColors(Quantity_Color& Color1, Quantity_Color& Color2)
2268 Aspect_GradientBackground GradientBackground()
2271 To set the image as a background and change the background image style you can use the following methods:
2273 void V3d_View::SetBackgroundImage
2274 (const Standard_CString FileName,
2275 const Aspect_FillMethod FillStyle,
2276 const Standard_Boolean update)
2277 void V3d_View::SetBgImageStyle
2278 (const Aspect_FillMethod FillStyle,
2279 const Standard_Boolean update)
2282 The *FileName* parameter defines the image file name and the path to it, the *FillStyle* parameter defines the method of filling the background with the image. The methods are:
2283 * *Aspect_FM_NONE* -- draws the image in the default position;
2284 * *Aspect_FM_CENTERED* -- draws the image at the center of the view;
2285 * *Aspect_FM_TILED* -- tiles the view with the image;
2286 * *Aspect_FM_STRETCH* -- stretches the image over the view.
2289 @subsubsection occt_visu_4_4_10 Dumping a 3D scene into an image file
2291 The 3D scene displayed in the view can be dumped in high resolution into an image file. The high resolution (8192x8192 on some implementations) is achieved using the Frame Buffer Objects (FBO) provided by the graphic driver. Frame Buffer Objects enable off-screen rendering into a virtual view to produce images in the background mode (without displaying any graphics on the screen).
2293 The *V3d_View* has the following methods for dumping the 3D scene:
2295 Standard_Boolean V3d_View::Dump
2296 (const Standard_CString theFile,
2297 const Image_TypeOfImage theBufferType)
2299 Dumps the scene into an image file with the view dimensions.
2302 Standard_Boolean V3d_View::Dump
2303 (const Standard_CString theFile,
2304 const Aspect_FormatOfSheetPaper theFormat,
2305 const Image_TypeOfImage theBufferType)
2307 Makes the dimensions of the output image compatible to a certain format of printing paper passed by *theFormat* argument.
2309 These methods dump the 3D scene into an image file passed by its name and path as theFile.
2311 The raster image data handling algorithm is based on the *Image_PixMap* class. The supported extensions are ".png", ".bmp", ".png", ".png".
2313 The value passed as *theBufferType* argument defines the type of the buffer for an output image <i>(RGB, RGBA, floating-point, RGBF, RGBAF)</i>. Both methods return *Standard_True* if the scene has been successfully dumped.
2315 There is also class *Image_AlienPixMap* providing import / export from / to external image files in formats supported by **FreeImage** library.
2317 **Note** that dumping the image for a paper format with large dimensions is a memory consuming operation, it might be necessary to take care of preparing enough free memory to perform this operation.
2320 Handle_Image_PixMap V3d_View::ToPixMap
2321 (const Standard_Integer theWidth,
2322 const Standard_Integer theHeight,
2323 const Image_TypeOfImage theBufferType,
2324 const Standard_Boolean theForceCentered)
2326 Dumps the displayed 3d scene into a pixmap with a width and height passed as *theWidth* and theHeight arguments.
2328 The value passed as *theBufferType* argument defines the type of the buffer for a pixmap <i>(RGB, RGBA, floating-point, RGBF, RGBAF)</i>. The last parameter allows centering the 3D scene on dumping.
2330 All these methods assume that you have created a view and displayed a 3d scene in it. However, the window used for such a view could be virtual, so you can dump the 3d scene in the background mode without displaying it on the screen. To use such an opportunity you can perform the following steps:
2331 * Create display connection;
2332 * Initialize graphic driver;
2334 * Set up the window as virtual, *Aspect_Window::SetVirtual()* ;
2335 * Create a view and an interactive context;
2336 * Assign the virtual window to the view;
2337 * Display a 3D scene;
2338 * Use one of the functions described above to dump the 3D scene.
2340 The following example demonstrates this procedure for *WNT_Window* :
2343 // create a dummy display connection
2344 Handle(Aspect_DisplayConnection) aDisplayConnection;
2346 // create a graphic driver
2347 Handle (Graphic3d_GraphicDriver) aDriver = Graphic3d::InitGraphicDriver (aDisplayConnection);
2350 Standard_Integer aDefWidth = 800;
2351 Standard_Integer aDefHeight = 600;
2352 Handle (WNT_WClass) aWClass = new WNT_WClass ("Virtual Class",DefWindowProc,
2353 CS_VREDRAW | CS_HREDRAW, 0, 0,
2354 ::LoadCursor (NULL, IDC_ARROW));
2355 Handle (WNT_Window) aWindow = new WNT_Window ("VirtualWnd", aWClass,
2356 WS_OVERLAPPEDWINDOW, 0, 0,
2357 aDefWidth, aDefHeight);
2359 // set up the window as virtual
2360 aWindow->SetVirtual (Standard_True);
2362 // create a view and an interactive context
2363 Handle (V3d_Viewer) aViewer = new V3d_Viewer (aDriver,
2364 Standard_ExtString ("Virtual"));
2365 Handle (AIS_InteractiveContext) aContext = new AIS_InteractiveContext (aViewer);
2366 Handle (V3d_View) aView = aViewer->CreateView ();
2368 // assign the virtual window to the view
2369 aView->SetWindow (aWindow);
2371 // display a 3D scene
2372 Handle (AIS_Shape) aBox = new AIS_Shape (BRepPrimAPI_MakeBox (5, 5, 5));
2373 aContext->Display (aBox);
2376 // dump the 3D scene into an image file
2377 aView->Dump ("3dscene.png");
2380 @subsubsection occt_visu_4_4_11 Printing a 3D scene
2382 The contents of a view can be printed out. Moreover, the OpenGl graphic driver used by the v3d view supports printing in high resolution. The print method uses the OpenGl frame buffer (Frame Buffer Object) for rendering the view contents and advanced print algorithms that allow printing in, theoretically, any resolution.
2384 The method *void V3d_View::Print(const Aspect_Handle hPrnDC, const Standard_Boolean showDialog, const Standard_Boolean showBackground, const Standard_CString filename, const Aspect_PrintAlgo printAlgorithm)* prints the view contents:
2386 *hPrnDC* is the printer device handle. You can pass your own printer handle or *NULL* to select the printer by the default dialog. In that case you can use the default dialog or pass *Standard_False* as the *showDialog* argument to select the default printer automatically.
2388 You can define the filename for the printer driver if you want to print out the result into a file.
2389 If you do not want to print the background, you can pass *Standard_False* as the *showBackground* argument.
2390 The *printAlgorithm* argument allows choosing between two print algorithms that define how the 3d scene is mapped to the print area when the maximum dimensions of the frame buffer are smaller than the dimensions of the print area by choosing *Aspect_PA_STRETCH* or *Aspect_PA_TILE*
2392 The first value defines the stretch algorithm: the scene is drawn with the maximum possible frame buffer dimensions and then is stretched to the whole printing area. The second value defines *TileSplit* algorithm: covering the whole printing area by rendering multiple parts of the viewer.
2394 **Note** that at the moment the printing is implemented only for Windows.
2396 @subsubsection occt_visu_4_4_12 Vector image export
2398 The 3D content of a view can be exported to the vector image file format. The vector image export is powered by the *GL2PS* library. You can export 3D scenes into a file format supported by the GL2PS library: PostScript (PS), Encapsulated PostScript (EPS), Portable Document Format (PDF), Scalable Vector Graphics (SVG), LaTeX file format and Portable LaTeX Graphics (PGF).
2400 The method *void Visual3d_View::Export (const Standard_CString FileName, const Graphic3d_ExportFormat Format, const Graphic3d_SortType aSortType, const Standard_Real Precision, const Standard_Address ProgressBarFunc, const Standard_Address ProgressObject)* of *Visual3d_View* class allows exporting a 3D scene:
2402 The *FileName* defines the output image file name and the *Format* argument defines the output file format:
2403 * *Graphic3d_EF_PostScript (PS)*,
2404 * *Graphic3d_EF_EhnPostScript (EPS)*,
2405 * *Graphic3d_EF_TEX (TEX)*,
2406 * *Graphic3d_EF_PDF (PDF)*,
2407 * *Graphic3d_EF_SVG (SVG)*,
2408 * *Graphic3d_EF_PGF (PGF)*.
2410 The *aSortType* parameter defines *GL2PS* sorting algorithm for the primitives. The *Precision, ProgressBarFunc* and *ProgressObject* parameters are implemented for future uses and at the moment have no effect.
2412 The *Export* method supports only basic 3d graphics and has several limitations:
2413 * Rendering large scenes could be slow and can lead to large output files;
2414 * Transparency is only supported for PDF and SVG output;
2415 * Textures and some effects are not supported by the *GL2PS* library.
2417 @subsubsection occt_visu_4_4_13 Ray tracing support
2419 OCCT visualization provides rendering by real-time ray tracing technique. It is allowed to switch easily between usual rasterization and ray tracing rendering modes. The core of OCCT ray tracing is written using GLSL shaders. The ray tracing has a wide list of features:
2425 * Support of non-polygon objects, such as lines, text, highlighting, selection.
2426 * Performance optimization using 2-level bounding volume hierarchy (BVH).
2428 The ray tracing algorithm is recursive (Whitted's algorithm). It uses BVH effective optimization structure. The structure prepares optimized data for a scene geometry for further displaying it in real-time. The 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. It is only necessary when the list of displayed objects or their geometry changes.
2429 To make the BVH reusable it has been added into an individual reusable OCCT package *TKMath/BVH*.
2431 There are several ray-tracing options that user can switch on/off:
2432 * Maximum ray tracing depth
2434 * Specular reflections
2435 * Adaptive anti aliasing
2436 * Transparency shadow effects
2440 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
2441 // specifies rendering mode
2442 aParams.Method = Graphic3d_RM_RAYTRACING;
2443 // maximum ray-tracing depth
2444 aParams.RaytracingDepth = 3;
2445 // enable shadows rendering
2446 aParams.IsShadowEnabled = Standard_True;
2447 // enable specular reflections.
2448 aParams.IsReflectionEnabled = Standard_True;
2449 // enable adaptive anti-aliasing
2450 aParams.IsAntialiasingEnabled = Standard_True;
2451 // enable light propagation through transparent media.
2452 aParams.IsTransparentShadowEnabled = Standard_True;
2457 @subsubsection occt_visu_4_4_14 Display priorities
2459 Structure display priorities control the order, in which structures are drawn. When you display a structure you specify its priority. The lower is the value, the lower is the display priority. When the display is regenerated, the structures with the lowest priority are drawn first. The structures with the same display priority are drawn in the same order as they have been displayed. OCCT supports eleven structure display priorities.
2461 @subsubsection occt_visu_4_4_15 Z-layer support
2463 OCCT features depth-arranging functionality called z-layer. A graphical presentation can be put into a z-layer. In general, this function can be used for implementing "bring to front" functionality in a graphical application.
2468 // set z-layer to an interactive object
2469 Handle(AIS_InteractiveContext) aContext = ...
2470 Handle(AIS_InteractiveObject) anInterObj = ...
2471 Standard_Integer anId = 3;
2472 aViewer->AddZLayer (anId);
2473 aContext->SetZLayer (anInterObj, anId);
2476 For each z-layer, it is allowed to:
2477 * Enable / disable depth test for layer.
2478 * Enable / disable depth write for layer.
2479 * Enable / disable depth buffer clearing.
2480 * Enable / disable polygon offset.
2482 You can get the options using getter from *Visual3d_ViewManager* and *V3d_Viewer*. It returns *Graphic3d_ZLayerSettings* for a given *LayerId*.
2486 // change z-layer settings
2487 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
2488 aSettings.SetEnableDepthTest (Standard_True);
2489 aSettings.SetEnableDepthWrite(Standard_True);
2490 aSettings.SetClearDepth (Standard_True);
2491 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
2492 aViewer->SetZLayerSettings (anId, aSettings);
2495 Another application for Z-Layer feature is treating visual precision issues when displaying objects far from the World Center.
2496 The key problem with such objects is that visualization data is stored and manipulated with single precision floating-point numbers (32-bit).
2497 Single precision 32-bit floating-point numbers give only 6-9 significant decimal digits precision,
2498 while double precision 64-bit numbers give 15-17 significant decimal digits precision, which is sufficient enough for most applications.
2500 When moving an Object far from the World Center, float number steadily eats precision.
2501 The camera Eye position adds leading decimal digits to the overall Object transformation, which discards smaller digits due to floating point number nature.
2502 For example, the object of size 0.0000123 moved to position 1000 has result transformation 1000.0000123,
2503 which 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.
2505 This imprecision results in visual artifacts of two kinds in the 3D Viewer:
2507 * Overall per-vertex Object distortion.
2508 This happens when each vertex position has been defined within World Coordinate system.
2509 * The object itself is not distorted, but its position in the World is unstable and imprecise - the object jumps during camera manipulations.
2510 This happens when vertices have been defined within Local Coordinate system at the distance small enough to keep precision within single precision float,
2511 however Local Transformation applied to the Object is corrupted due to single precision float.
2513 The first issue cannot be handled without switching the entire presentation into double precision (for each vertex position).
2514 However, visualization hardware is much faster using single precision float number rather than double precision - so this is not an option in most cases.
2515 The second issue, however, can be negated by applying special rendering tricks.
2517 So, to apply this feature in OCCT, the application :
2519 * Defines Local Transformation for each object to fit the presentation data into single precision float without distortion.
2520 * Spatially splits the world into smaller areas/cells where single precision float will be sufficient.
2521 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).
2522 * Defines a Z-Layer for each spatial cell containing any object.
2523 * Defines the Local Origin property of the Z-Layer according to the center of the cell.
2526 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
2527 aSettings.SetLocalOrigin (400.0, 0.0, 0.0);
2529 * Assigns a presentable object to the nearest Z-Layer.
2531 Note that Local Origin of the Layer is used only for rendering - everything outside will be still defined in the World Coordinate System,
2532 including Local Transformation of the Object and Detection results.
2533 E.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.
2535 @subsubsection occt_visu_4_4_16 Clipping planes
2537 The ability to define custom clipping planes could be very useful for some tasks. OCCT provides such an opportunity.
2539 The *Graphic3d_ClipPlane* class provides the services for clipping planes: it holds the plane equation coefficients and provides its graphical representation. To set and get plane equation coefficients you can use the following methods:
2542 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
2543 void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
2544 Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
2545 void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
2546 gp_Pln Graphic3d_ClipPlane::ToPlane() const
2549 The clipping planes can be activated with the following method:
2551 void Graphic3d_ClipPlane::SetOn (const Standard_Boolean theIsOn)
2554 The number of clipping planes is limited. You can check the limit value via method *Graphic3d_GraphicDriver::InquirePlaneLimit()*;
2557 // get the limit of clipping planes for the current view
2558 Standard_Integer aMaxClipPlanes = aView->Viewer()->Driver()->InquirePlaneLimit();
2561 Let us see for example how to create a new clipping plane with custom parameters and add it to a view or to an object:
2563 // create a new clipping plane
2564 const Handle(Graphic3d_ClipPlane)& aClipPlane = new Graphic3d_ClipPlane();
2565 // change equation of the clipping plane
2566 Standard_Real aCoeffA = ...
2567 Standard_Real aCoeffB = ...
2568 Standard_Real aCoeffC = ...
2569 Standard_Real aCoeffD = ...
2570 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
2572 aClipPlane->SetCapping (aCappingArg == "on");
2573 // set the material with red color of clipping plane
2574 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
2575 Quantity_Color aColor (1.0, 0.0, 0.0, Quantity_TOC_RGB);
2576 aMat.SetAmbientColor (aColor);
2577 aMat.SetDiffuseColor (aColor);
2578 aClipPlane->SetCappingMaterial (aMat);
2579 // set the texture of clipping plane
2580 Handle(Graphic3d_Texture2Dmanual) aTexture = ...
2581 aTexture->EnableModulate();
2582 aTexture->EnableRepeat();
2583 aClipPlane->SetCappingTexture (aTexture);
2584 // add the clipping plane to an interactive object
2585 Handle(AIS_InteractiveObject) aIObj = ...
2586 aIObj->AddClipPlane (aClipPlane);
2587 // or to the whole view
2588 aView->AddClipPlane (aClipPlane);
2589 // activate the clipping plane
2590 aClipPlane->SetOn(Standard_True);
2596 @subsubsection occt_visu_4_4_17 Automatic back face culling
2598 Back face culling reduces the rendered number of triangles (which improves the performance) and eliminates artifacts at shape boundaries. However, this option can be used only for solid objects, where the interior is actually invisible from any point of view. Automatic back-face culling mechanism is turned on by default, which is controlled by *V3d_View::SetBackFacingModel()*.
2600 The following features are applied in *StdPrs_ToolShadedShape::IsClosed()*, which is used for definition of back face culling in *ShadingAspect*:
2601 * disable culling for free closed Shells (not inside the Solid) since reversed orientation of a free Shell is a valid case;
2602 * enable culling for Solids packed into a compound;
2603 * ignore Solids with incomplete triangulation.
2605 Back face culling is turned off at TKOpenGl level in the following cases:
2606 * clipping/capping planes are in effect;
2607 * for translucent objects;
2608 * with hatching presentation style.
2610 @subsection occt_visu_4_5 Examples: creating a 3D scene
2612 To create 3D graphic objects and display them in the screen, follow the procedure below:
2613 1. Create attributes.
2614 2. Create a 3D viewer.
2616 4. Create an interactive context.
2617 5. Create interactive objects.
2618 6. Create primitives in the interactive object.
2619 7. Display the interactive object.
2621 @subsubsection occt_visu_4_5_1 Create attributes
2626 Quantity_Color aBlack (Quantity_NOC_BLACK);
2627 Quantity_Color aBlue (Quantity_NOC_MATRABLUE);
2628 Quantity_Color aBrown (Quantity_NOC_BROWN4);
2629 Quantity_Color aFirebrick (Quantity_NOC_FIREBRICK);
2630 Quantity_Color aForest (Quantity_NOC_FORESTGREEN);
2631 Quantity_Color aGray (Quantity_NOC_GRAY70);
2632 Quantity_Color aMyColor (0.99, 0.65, 0.31, Quantity_TOC_RGB);
2633 Quantity_Color aBeet (Quantity_NOC_BEET);
2634 Quantity_Color aWhite (Quantity_NOC_WHITE);
2637 Create line attributes.
2640 Handle(Graphic3d_AspectLine3d) anAspectBrown = new Graphic3d_AspectLine3d();
2641 Handle(Graphic3d_AspectLine3d) anAspectBlue = new Graphic3d_AspectLine3d();
2642 Handle(Graphic3d_AspectLine3d) anAspectWhite = new Graphic3d_AspectLine3d();
2643 anAspectBrown->SetColor (aBrown);
2644 anAspectBlue ->SetColor (aBlue);
2645 anAspectWhite->SetColor (aWhite);
2648 Create marker attributes.
2650 Handle(Graphic3d_AspectMarker3d aFirebrickMarker = new Graphic3d_AspectMarker3d();
2651 // marker attributes
2652 aFirebrickMarker->SetColor (Firebrick);
2653 aFirebrickMarker->SetScale (1.0);
2654 aFirebrickMarker->SetType (Aspect_TOM_BALL);
2656 // it is a preferred way (supports full-color images on modern hardware).
2657 aFirebrickMarker->SetMarkerImage (theImage)
2660 Create facet attributes.
2662 Handle(Graphic3d_AspectFillArea3d) aFaceAspect = new Graphic3d_AspectFillArea3d();
2663 Graphic3d_MaterialAspect aBrassMaterial (Graphic3d_NOM_BRASS);
2664 Graphic3d_MaterialAspect aGoldMaterial (Graphic3d_NOM_GOLD);
2665 aFaceAspect->SetInteriorStyle (Aspect_IS_SOLID);
2666 aFaceAspect->SetInteriorColor (aMyColor);
2667 aFaceAspect->SetDistinguishOn ();
2668 aFaceAspect->SetFrontMaterial (aGoldMaterial);
2669 aFaceAspect->SetBackMaterial (aBrassMaterial);
2670 aFaceAspect->SetEdgeOn();
2673 Create text attributes.
2675 Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d (aForest, Graphic3d_NOF_ASCII_MONO, 1.0, 0.0);
2678 @subsubsection occt_visu_4_5_2 Create a 3D Viewer (a Windows example)
2681 // create a default connection
2682 Handle(Aspect_DisplayConnection) aDisplayConnection;
2683 // create a graphic driver from default connection
2684 Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
2686 TCollection_ExtendedString aName ("3DV");
2687 myViewer = new V3d_Viewer (aGraphicDriver,aName.ToExtString(), "");
2688 // set parameters for V3d_Viewer
2689 // defines default lights -
2690 // positional-light 0.3 0.0 0.0
2691 // directional-light V3d_XnegYposZpos
2692 // directional-light V3d_XnegYneg
2694 a3DViewer->SetDefaultLights();
2695 // activates all the lights defined in this viewer
2696 a3DViewer->SetLightOn();
2697 // set background color to black
2698 a3DViewer->SetDefaultBackgroundColor (Quantity_NOC_BLACK);
2702 @subsubsection occt_visu_4_5_3 Create a 3D view (a Windows example)
2704 It is assumed that a valid Windows window may already be accessed via the method *GetSafeHwnd()*.
2706 Handle (WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
2707 myView = myViewer->CreateView();
2708 myView->SetWindow (aWNTWindow);
2711 @subsubsection occt_visu_4_5_4 Create an interactive context
2714 myAISContext = new AIS_InteractiveContext (myViewer);
2717 You are now able to display interactive objects such as an *AIS_Shape*.
2720 TopoDS_Shape aShape = BRepAPI_MakeBox (10, 20, 30).Solid();
2721 Handle(AIS_Shape) anAISShape = new AIS_Shape(aShape);
2722 myAISContext->Display (anAISShape);
2725 @subsubsection occt_visu_4_5_5 Create your own interactive object
2727 Follow the procedure below to compute the presentable object:
2729 1. Build a presentable object inheriting from *AIS_InteractiveObject* (refer to the Chapter on @ref occt_visu_2_1 "Presentable Objects").
2730 2. Reuse the *Prs3d_Presentation* provided as an argument of the compute methods.
2732 **Note** that there are two compute methods: one for a standard representation, and the other for a degenerated representation, i.e. in hidden line removal and wireframe modes.
2735 Let us look at the example of compute methods
2739 myPresentableObject::Compute
2740 (const Handle(PrsMgr_PresentationManager3d)& thePrsManager,
2741 const Handle(Prs3d_Presentation)& thePrs,
2742 const Standard_Integer theMode)
2748 myPresentableObject::Compute (const Handle(Prs3d_Projector)& ,
2749 const Handle(Prs3d_Presentation)& thePrs)
2755 @subsubsection occt_visu_4_5_6 Create primitives in the interactive object
2757 Get the group used in *Prs3d_Presentation*.
2760 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePrs);
2763 Update the group attributes.
2766 aGroup->SetPrimitivesAspect (anAspectBlue);
2769 Create two triangles in *aGroup*.
2772 Standard_Integer aNbTria = 2;
2773 Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles (3 * aNbTria, 0, Standard_True);
2774 Standard_Integer anIndex;
2775 for (anIndex = 1; anIndex <= aNbTria; nt++)
2777 aTriangles->AddVertex (anIndex * 5., 0., 0., 1., 1., 1.);
2778 aTriangles->AddVertex (anIndex * 5 + 5, 0., 0., 1., 1., 1.);
2779 aTriangles->AddVertex (anIndex * 5 + 2.5, 5., 0., 1., 1., 1.);
2781 aGroup->BeginPrimitives();
2782 aGroup->AddPrimitiveArray (aTriangles);
2783 aGroup->EndPrimitives();
2786 The methods *BeginPrimitives()* and *EndPrimitives()* are used when creating a set of various primitives in the same group.
2787 Use the polyline function to create a boundary box for the *thePrs* structure in group *aGroup*.
2790 Standard_Real Xm, Ym, Zm, XM, YM, ZM;
2791 thePrs->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
2793 Handle(Graphic3d_ArrayOfPolylines) aPolylines = new Graphic3d_ArrayOfPolylines (16, 4);
2794 aPolylines->AddBound (4);
2795 aPolylines->AddVertex (Xm, Ym, Zm);
2796 aPolylines->AddVertex (Xm, Ym, ZM);
2797 aPolylines->AddVertex (Xm, YM, ZM);
2798 aPolylines->AddVertex (Xm, YM, Zm);
2799 aPolylines->AddBound (4);
2800 aPolylines->AddVertex (Xm, Ym, Zm);
2801 aPolylines->AddVertex (XM, Ym, Zm);
2802 aPolylines->AddVertex (XM, Ym, ZM);
2803 aPolylines->AddVertex (XM, YM, ZM);
2804 aPolylines->AddBound (4);
2805 aPolylines->AddVertex (XM, YM, Zm);
2806 aPolylines->AddVertex (XM, Ym, Zm);
2807 aPolylines->AddVertex (XM, YM, Zm);
2808 aPolylines->AddVertex (Xm, YM, Zm);
2809 aPolylines->AddBound (4);
2810 aPolylines->AddVertex (Xm, YM, ZM);
2811 aPolylines->AddVertex (XM, YM, ZM);
2812 aPolylines->AddVertex (XM, Ym, ZM);
2813 aPolylines->AddVertex (Xm, Ym, ZM);
2815 aGroup->BeginPrimitives();
2816 aGroup->AddPrimitiveArray(aPolylines);
2817 aGroup->EndPrimitives();
2820 Create text and markers in group *aGroup*.
2823 static char* texte[3] =
2825 "Application title",
2827 "My company address."
2829 Handle(Graphic3d_ArrayOfPoints) aPtsArr = new Graphic3d_ArrayOfPoints (2, 1);
2830 aPtsArr->AddVertex (-40.0, -40.0, -40.0);
2831 aPtsArr->AddVertex (40.0, 40.0, 40.0);
2832 aGroup->BeginPrimitives();
2833 aGroup->AddPrimitiveArray (aPtsArr);
2834 aGroup->EndPrimitives();
2836 Graphic3d_Vertex aMarker (0.0, 0.0, 0.0);
2837 for (i=0; i <= 2; i++)
2839 aMarker.SetCoord (-(Standard_Real )i * 4 + 30,
2840 (Standard_Real )i * 4,
2841 -(Standard_Real )i * 4);
2842 aGroup->Text (texte[i], Marker, 20.);
2847 @section occt_visu_5 Mesh Visualization Services
2849 <i>MeshVS</i> (Mesh Visualization Service) component extends 3D visualization capabilities of Open CASCADE Technology. It provides flexible means of displaying meshes along with associated pre- and post-processor data.
2851 From a developer's point of view, it is easy to integrate the *MeshVS* component into any mesh-related application with the following guidelines:
2853 * Derive a data source class from the *MeshVS_DataSource* class.
2854 * Re-implement its virtual methods, so as to give the <i>MeshVS</i> component access to the application data model. 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.
2855 * Create an instance of <i>MeshVS_Mesh</i> class.
2856 * Create an instance of your data source class and pass it to a <i>MeshVS_Mesh</i> object through the <i>SetDataSource()</i> method.
2857 * Create one or several objects of <i>MeshVS_PrsBuilder</i>-derived classes (standard, included in the <i>MeshVS</i> package, or your custom ones).
2858 * Each <i>PrsBuilder</i> is responsible for drawing a <i> MeshVS_Mesh</i> presentation in a certain display mode(s) specified as a <i>PrsBuilder</i> constructor's argument. Display mode is treated by <i>MeshVS</i> classes as a combination of bit flags (two least significant bits are used to encode standard display modes: wireframe, shading and shrink).
2859 * Pass these objects to the <i>MeshVS_Mesh::AddBuilder()</i> method. <i>MeshVS_Mesh</i> takes advantage of improved selection highlighting mechanism: it highlights its selected entities itself, with the help of so called "highlighter" object. You can set one of <i>PrsBuilder</i> objects to act as a highlighter with the help of a corresponding argument of the <i>AddBuilder()</i> method.
2861 Visual attributes of the <i>MeshVS_Mesh</i> object (such as shading color, shrink coefficient and so on) are controlled through <i>MeshVS_Drawer</i> object. It maintains a map "Attribute ID --> attribute value" and can be easily extended with any number of custom attributes.
2863 In all other respects, <i>MeshVS_Mesh</i> is very similar to any other class derived from <i>AIS_InteractiveObject</i> and it should be used accordingly (refer to the description of <i>AIS package</i> in the documentation).