0029011: Draw Harness - simplify diffimage command syntax
[occt.git] / dox / user_guides / visualization / visualization.md
Content-type: text/html OCCT Git - occt.git/blame - dox/user_guides/visualization/visualization.md


500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 8) line 1, <$fd> line 4297.
CommitLineData
ba06f8bb 1Visualization {#occt_user_guides__visualization}
bf62b306 2========================
3@tableofcontents
72b7576f 4
bf62b306 5@section occt_visu_1 Introduction
72b7576f 6
2683e647 7Visualization in Open CASCADE Technology is based on the separation of:
3f812249 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).
72b7576f 10
18006a0f 11Presentations are managed through the **Presentation** component, and selection through the **Selection** component.
72b7576f 12
18006a0f 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.
72b7576f 14
18006a0f 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.
72b7576f 16
bf62b306 17If, 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.
72b7576f 18
2683e647 19The the following packages are used to display 3D objects:
4ee1bdf4 20 * *AIS*;
21 * *StdPrs*;
22 * *Prs3d*;
23 * *PrsMgr*;
24 * *V3d*;
25 * *Graphic3d*.
72b7576f 26
18006a0f 27The packages used to display 3D objects are also applicable for visualization of 2D objects.
72b7576f 28
bf62b306 29The 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.
72b7576f 30
d6b4d3d0 31@figure{visualization_image003.png,"Key concepts and packages in visualization",400}
72b7576f 32
2683e647 33To answer different needs of CASCADE users, this User's Guide offers the following three paths in reading it.
34
67d7f07f 35 * If the 3D services proposed in AIS meet your requirements, you need only read chapter 3 @ref occt_visu_3 "AIS: Application Interactive Services".
3f812249 36 * 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.
e2ba9cb1 37
38For advanced information on visualization algorithms, see our <a href="http://www.opencascade.com/content/tutorial-learning">E-learning & Training</a> offerings.
72b7576f 39
2683e647 40@section occt_visu_2 Fundamental Concepts
72b7576f 41
bf62b306 42@subsection occt_visu_2_1 Presentation
72b7576f 43
bf62b306 44In 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.
72b7576f 45
bf62b306 46@subsubsection occt_visu_2_1_1 Structure of the Presentation
72b7576f 47
2683e647 48Displaying an object on the screen involves three kinds of entities:
bf62b306 49 * a presentable object, the *AIS_InteractiveObject*
72b7576f 50 * a viewer
51 * an interactive context, the *AIS_InteractiveContext*.
52
18006a0f 53<h4>The presentable object</h4>
bf62b306 54The 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.
72b7576f 55
bf62b306 56Standard 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.
72b7576f 57
bf62b306 58Each object to be presented individually must be presentable or associated with a presentable object.
72b7576f 59
bf62b306 60<h4>The viewer </h4>
18006a0f 61The 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.
72b7576f 62
bf62b306 63<h4>The Interactive Context </h4>
64The 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.
72b7576f 65
bf62b306 66@subsubsection occt_visu_2_1_2 Presentation packages
72b7576f 67
18006a0f 68Presentation 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.
69
bf62b306 70* *AIS* package provides all classes to implement interactive objects (presentable and selectable entities).
18006a0f 71* *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*.
72* *StdPrs* package provides ready-to-use standard presentation algorithms for specific geometries: points, curves and shapes of the geometry and topology toolkits.
73* *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.
74* *V3d* package provides the services supported by the 3D viewer.
2683e647 75* *Graphic3d* package provides resources to create 3D graphic structures.
18006a0f 76* *Visual3d* package contains classes implementing commands for 3D viewer.
77* *DsgPrs* package provides tools for display of dimensions, relations and XYZ trihedrons.
72b7576f 78
bf62b306 79@subsubsection occt_visu_2_1_3 A Basic Example: How to display a 3D object
72b7576f 80
bf62b306 81~~~~~
2683e647 82Void Standard_Real dx = ...; //Parameters
83Void Standard_Real dy = ...; //to build a wedge
84Void Standard_Real dz = ...;
bf62b306 85Void Standard_Real ltx = ...;
86
87Handle(V3d_Viewer)aViewer = ...;
88Handle(AIS_InteractiveContext)aContext;
89aContext = new AIS_InteractiveContext(aViewer);
90
91BRepPrimAPI_MakeWedge w(dx, dy, dz, ltx);
92TopoDS_Solid & = w.Solid();
93Handle(AIS_Shape) anAis = new AIS_Shape(S);
94//creation of the presentable object
4ee1bdf4 95aContext -> Display(anAis);
bf62b306 96//Display the presentable object in the 3d viewer.
97~~~~~
dba69de2 98
bf62b306 99The 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.
72b7576f 100
d6b4d3d0 101@figure{visualization_image004.svg,"Processes involved in displaying a presentable shape",400}
72b7576f 102
bf62b306 103@subsection occt_visu_2_2 Selection
72b7576f 104
a7d4dd94 105Standard 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.
72b7576f 106
a7d4dd94 107There are 3 different selection types:
108 - **Point selection** -- allows picking and highlighting a single object (or its part) located under the mouse cursor;
109 - **Rectangle selection** -- allows picking objects or parts located under the rectangle defined by the start and end mouse cursor positions;
110 - **Polyline selection** -- allows picking objects or parts located under a user-defined non-self-intersecting polyline.
72b7576f 111
a7d4dd94 112For 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.
72b7576f 113
a7d4dd94 114@subsubsection occt_visu_2_2_1 Terms and notions
72b7576f 115
a7d4dd94 116This section introduces basic terms and notions used throughout the algorithm description.
72b7576f 117
a7d4dd94 118<h4>Sensitive entity</h4>
72b7576f 119
a7d4dd94 120Sensitive entities in the same way as entity owners are links between objects and the selection mechanism.
72b7576f 121
a7d4dd94 122The 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.
72b7576f 123
d6b4d3d0 124@figure{visualization_image005.png,"Example of a shape divided into sensitive entities",400}
72b7576f 125
a7d4dd94 126Depending 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).
72b7576f 127
a7d4dd94 128Entities 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.
72b7576f 129
a7d4dd94 130<h4>Entity owner</h4>
72b7576f 131
a7d4dd94 132Each 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.
72b7576f 133
a7d4dd94 134<h4>Selection</h4>
72b7576f 135
a7d4dd94 136To simplify the handling of different selection modes of an object, sensitive entities linked to its owners are organized into sets, called **selections**.
72b7576f 137
a7d4dd94 138Each selection contains entities created for a certain mode along with the sensitivity and update states.
72b7576f 139
a7d4dd94 140<h4>Selectable object</h4>
72b7576f 141
a7d4dd94 142Selectable object stores information about all created selection modes and sensitive entities.
143
144All 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.
145
146For 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:
147 - 0 -- selection of the *AIS_Shape*;
148 - 1 -- selection of the vertices;
149 - 2 -- selection of the edges;
150 - 3 -- selection of the wires;
151 - 4 -- selection of the faces;
152 - 5 -- selection of the shells;
153 - 6 -- selection of the constituent solids.
154
d6b4d3d0 155@figure{visualization_image006.png,"Hierarchy of references from sensitive entity to selectable object",400}
a7d4dd94 156
d6b4d3d0 157@figure{visualization_image007.png,"The principle of entities organization within the selectable object",400}
a7d4dd94 158
159<h4>Viewer selector</h4>
160
161For 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.
162
163The 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.
164
165<h4>Selection manager</h4>
166
167Selection 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.
168
d6b4d3d0 169@figure{visualization_image008.png,"The relations chain between viewer selector and selection manager",400}
a7d4dd94 170
171@subsubsection occt_visu_2_2_2 Algorithm
172
173All 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.
174
175<h4>Selection Frustum</h4>
176
177The first step of each run of selection algorithm is to build the selection frustum according to the currently activated selection type.
178
179For 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.
180
181The frustum length is limited by near and far view volume planes and each plane is built parallel to the corresponding view volume plane.
182
d6b4d3d0 183@figure{visualization_image009.png,"",400}
72b7576f 184
d6b4d3d0 185The image above shows the rectangular frustum: a) after mouse move or click, b) after applying the rectangular selection.
186
187@figure{visualization_image010.png,"",400}
188
189In the image above triangular frustum is set: a) by a user-defined polyline, b) by triangulation of the polygon based on the given polyline, c) by a triangular frustum based on one of the triangles.
72b7576f 190
a7d4dd94 191<h4>BVH trees</h4>
72b7576f 192
a7d4dd94 193To maintain selection mechanism at the viewer level, a speedup structure composed of 3 BVH trees is used.
72b7576f 194
a7d4dd94 195The 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.
72b7576f 196
a7d4dd94 197The 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.
72b7576f 198
a7d4dd94 199The 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.
72b7576f 200
d6b4d3d0 201@figure{visualization_image022.png,"Selection BVH tree hierarchy: from the biggest object-level (first) to the smallest complex entity level (third)",400}
72b7576f 202
a7d4dd94 203<h4>Stages of the algorithm</h4>
72b7576f 204
a7d4dd94 205The algorithm includes pre-processing and three main stages.
72b7576f 206
a7d4dd94 207* **Pre-processing** -- implies calculation of the selection frustum and its main characteristics.
208* **First stage** -- traverse of the first level BVH tree.
72b7576f 209
a7d4dd94 210After 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.
72b7576f 211
a7d4dd94 212* **Second stage** -- traverse of the second level BVH tree
72b7576f 213
a7d4dd94 214At this stage it is necessary to determine if there are candidates among all sensitive entities of one object.
72b7576f 215
a7d4dd94 216First 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:
217 - activation check - the entity may be inactive at the moment as it belongs to deactivated selection;
218 - 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.
72b7576f 219
a7d4dd94 220After these checks the algorithm passes to the last stage.
72b7576f 221
a7d4dd94 222* **Third stage** -- overlap or inclusion test of a particular sensitive entity
18006a0f 223
a7d4dd94 224If 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.
72b7576f 225
a7d4dd94 226@subsubsection occt_visu_2_2_3 Packages and classes
72b7576f 227
a7d4dd94 228Selection 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>.
72b7576f 229
a7d4dd94 230<h4>SelectBasics</h4>
18006a0f 231
a7d4dd94 232<i>SelectBasics</i> package contains basic classes and interfaces for selection. The most notable are:
233 - <i>SelectBasics_SensitiveEntity</i> -- the base definition of a sensitive entity;
234 - <i>SelectBasics_EntityOwner</i> -- the base definition of the an entity owner -- the link between the sensitive entity and the object to be selected;
235 - <i>SelectBasics_PickResult</i> -- the structure for storing quantitative results of detection procedure, for example, depth and distance to the center of geometry;
236 - <i>SelectBasics_SelectingVolumeManager</i> -- the interface for interaction with the current selection frustum.
18006a0f 237
18006a0f 238
a7d4dd94 239Each custom sensitive entity must inherit at least <i>SelectBasics_SensitiveEntity</i>.
18006a0f 240
a7d4dd94 241<h4>Select3D</h4>
18006a0f 242
a7d4dd94 243<i>Select3D</i> package provides a definition of standard sensitive entities, such as:
244 - box;
245 - circle;
246 - curve;
247 - face;
248 - group;
249 - point;
250 - segment;
251 - triangle;
252 - triangulation;
253 - wire.
18006a0f 254
a7d4dd94 255Each basic sensitive entity inherits <i>Select3D_SensitiveEntity</i>, which is a child class of <i>SelectBasics_SensitiveEntity</i>.
18006a0f 256
a7d4dd94 257The package also contains two auxiliary classes, <i>Select3D_SensitivePoly</i> and <i>Select3D_SensitiveSet</i>.
72b7576f 258
a7d4dd94 259<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.
18006a0f 260
a7d4dd94 261<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.
18006a0f 262
a7d4dd94 263<h4>SelectMgr</h4>
18006a0f 264
a7d4dd94 265<i>SelectMgr</i> package is used to maintain the whole selection process. For this purpose, the package provides the following services:
266 - activation and deactivation of selection modes for all selectable objects;
267 - interfaces to compute selection mode of the object;
268 - definition of selection filter classes;
269 - keeping selection BVH data up-to-date.
18006a0f 270
a7d4dd94 271A brief description of the main classes:
272 - <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);
273 - <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;
274 - <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;
275 - <i>SelectMgr_ViewerSelector</i> -- encapsulates all logics of the selection algorithm and implements the third level BVH tree traverse;
276 - <i>SelectMgr_SelectionManager</i> -- manages activation/deactivation, calculation and update of selections of every selectable object, and keeps BVH data up-to-date.
18006a0f 277
a7d4dd94 278<h4>StdSelect</h4>
279
280<i>StdSelect</i> package contains the implementation of some <i>SelectMgr</i> classes and tools for creation of selection structures. For example,
281 - <i>StdSelect_BRepOwner</i> -- defines an entity owner with a link to its topological shape and methods for highlighting;
282 - <i>StdSelect_BRepSelectionTool</i> -- contains algorithms for splitting standard AIS shapes into sensitive primitives;
283 - <i>StdSelect_ViewerSelector3d</i> -- an example of <i>SelectMgr_ViewerSelecor</i> implementation, which is used in a default OCCT selection mechanism;
284 - <i>StdSelect_FaceFilter</i>, <i>StdSelect_EdgeFilter</i> -- implementation of selection filters.
285
286@subsubsection occt_visu_2_2_4 Examples of usage
287
288The 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.
289
290Let 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).
291
292To 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.
293
294To 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.
18006a0f 295
296~~~~
297
a7d4dd94 298void InteractiveBox::ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
18006a0f 299 const Standard_Integer theMode)
300{
a7d4dd94 301 switch (theMode)
18006a0f 302 {
a7d4dd94 303 case 0: // creation of face sensitives for selection of the whole box
304 {
305 Handle(SelectMgr_EntityOwner) anOwnr = new SelectMgr_EntityOwner (this, 5);
306 for (Standard_Integer aFaceIdx = 1; aFaceIdx <= myNbFaces; aFaceIdx++)
18006a0f 307 {
a7d4dd94 308 Select3D_TypeOfSensitivity aIsInteriorSensitivity = myIsInterior;
309 theSel->Add (new Select3D_SensitiveFace (anOwnr,
310 myFaces[aFaceIdx]->PointArray(),
311 aIsInteriorSensitivity));
18006a0f 312 }
a7d4dd94 313 break;
314 }
315 case 1: // creation of edge sensitives for selection of box edges only
18006a0f 316 {
a7d4dd94 317 for (Standard_Integer anEdgeIdx = 1; anEdgeIdx <= 12; anEdgeIdx++)
18006a0f 318 {
a7d4dd94 319 // 1 owner per edge, where 6 is a priority of the sensitive
320 Handle(MySelection_EdgeOwner) anOwnr = new MySelection_EdgeOwner (this, anEdgeIdx, 6);
321 theSel->Add (new Select3D_SensitiveSegment (anOwnr,
322 FirstPnt[anEdgeIdx]),
323 LastPnt[anEdgeIdx]));
18006a0f 324 }
a7d4dd94 325 break;
326 }
18006a0f 327 }
328}
329
330~~~~
331
a7d4dd94 332The 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.
333
334To 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>.
335
336To 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.
337
338
339Selection structures for any interactive object are created in <i>SelectMgr_SelectableObject::ComputeSelection()</i> method.
18006a0f 340
a7d4dd94 341The 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>.
18006a0f 342
343~~~~
a7d4dd94 344 void MyInteractiveObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
345 const Standard_Integer theMode)
18006a0f 346 {
347 switch (theMode)
348 {
349 case 0:
a7d4dd94 350 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_SHAPE);
18006a0f 351 break;
352 case 1:
a7d4dd94 353 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_VERTEX);
18006a0f 354 break;
355 case 2:
a7d4dd94 356 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_EDGE);
18006a0f 357 break;
358 case 3:
a7d4dd94 359 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_WIRE);
18006a0f 360 break;
361 case 4:
a7d4dd94 362 StdSelect_BRepSelectionTool::Load (theSelection, this, myTopoDSShape, TopAbs_FACE);
18006a0f 363 break;
364 }
365 }
366~~~~
367
a7d4dd94 368The <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>.
18006a0f 369
370The 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:
371
a7d4dd94 372 - each entity owner has to maintain its own <i>Prs3d_Presentation</i> object, that results in a large memory overhead for thousands of owners;
373 - drawing selected owners one by one is not efficient from the OpenGL usage viewpoint.
72b7576f 374
a7d4dd94 375Therefore, 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.
18006a0f 376
a7d4dd94 377On 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.
18006a0f 378
18006a0f 379
a7d4dd94 380Hence, 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.
72b7576f 381
a7d4dd94 382The <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.
72b7576f 383
72b7576f 384
a7d4dd94 385After 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:
386 - if there was no <i>AIS_InteractiveContext</i> opened, create an interactive context and display the selectable object in it;
387 - 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;
388 - activate or deactivate the defined selection mode using <i>AIS_InteractiveContext::Activate()</i> or <i>AIS_InteractiveContext::Deactivate()</i> methods.
72b7576f 389
a7d4dd94 390After these steps, the selection manager of the created interactive context will contain the given object and its selection entities, and they will be involved in the detection procedure.
72b7576f 391
a7d4dd94 392The code snippet below illustrates the above steps. It also contains the code to start the detection procedure and parse the results of selection.
72b7576f 393
a7d4dd94 394~~~~~
72b7576f 395
a7d4dd94 396// Suppose there is an instance of class InteractiveBox from the previous sample.
397// It contains an implementation of method InteractiveBox::ComputeSelection() for selection
398// modes 0 (whole box must be selected) and 1 (edge of the box must be selectable)
399Handle(InteractiveBox) aBox;
400
401// Assume there is a created interactive context
402const Handle(AIS_InteractiveContext)& aContext = GetContext();
403// To prevent automatic activation of the default selection mode
404aContext->SetAutoActivateSelection (Standard_False);
405
406aContext->Display (aBox);
407
408// Load a box to the selection manager without computation of any selection mode
409aContext->Load (aBox, -1, Standard_True);
410// Activate edge selection
411aContext->Activate (aBox, 1);
412
413// Run the detection mechanism for activated entities in the current mouse coordinates and
414// in the current view. Detected owners will be highlighted with context highlight color
415aContext->MoveTo (aXMousePos, aYMousePos, myView);
416// Select the detected owners
417aContext->Select();
418// Iterate through the selected owners
419for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected())
420{
421 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
422}
72b7576f 423
a7d4dd94 424// deactivate all selection modes for aBox1
425aContext->Deactivate (aBox1);
72b7576f 426
bf62b306 427~~~~~
72b7576f 428
a7d4dd94 429It is also important to know, that there are 2 types of detection implemented for rectangular selection in OCCT:
430 - <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;
431 - <b>overlap</b> detection. In this case the sensitive primitive is considered detected when it is partially overlapped by the selection rectangle.
72b7576f 432
a7d4dd94 433The standard OCCT selection mechanism uses inclusion detection by default. To change this, use the following code:
72b7576f 434
a7d4dd94 435~~~~~
72b7576f 436
a7d4dd94 437// Assume there is a created interactive context
438const Handle(AIS_InteractiveContext)& aContext = GetContext();
439// Retrieve the current viewer selector
440const Handle(StdSelect_ViewerSelector3d)& aMainSelector = aContext->MainSelector();
441// Set the flag to allow overlap detection
442aMainSelector->AllowOverlapDetection (Standard_True);
72b7576f 443
a7d4dd94 444~~~~~
72b7576f 445
bf62b306 446@section occt_visu_3 Application Interactive Services
447@subsection occt_visu_3_1 Introduction
72b7576f 448
bf62b306 449Application Interactive Services allow managing presentations and dynamic selection in a viewer in a simple and transparent manner.
72b7576f 450
bf62b306 451The 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.
72b7576f 452
bf62b306 453The neutral point, which is the default mode, allows easily visualizing and selecting interactive objects loaded into the context.
72b7576f 454
bf62b306 455**Local Contexts** can be opened to prepare and use a temporary selection environment without disturbing
456the 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.
72b7576f 457
bf62b306 458When the operation is finished, you close the current local context and return to the state
459in which you were before opening it (neutral point or previous local context).
72b7576f 460
bf62b306 461**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.
72b7576f 462
d6b4d3d0 463@figure{visualization_image016.png,"",240}
72b7576f 464
bf62b306 465An 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.
72b7576f 466
bf62b306 467When 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.
72b7576f 468
d6b4d3d0 469@figure{visualization_image017.png,"",360}
72b7576f 470
bf62b306 471It 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.
72b7576f 472
bf62b306 473@subsection occt_visu_3_2 Interactive objects
72b7576f 474
18006a0f 475Entities 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.
476
bf62b306 477@subsubsection occt_visu_3_2_1 Presentations
72b7576f 478
bf62b306 479An interactive object can have as many presentations as its creator wants to give it.
72b7576f 480
bf62b306 4813D presentations are managed by PresentationManager3D. As this is transparent in AIS, the user does not have to worry about it.
72b7576f 482
bf62b306 483A presentation is identified by an index and by the reference to the Presentation Manager which it depends on.
72b7576f 484
bf62b306 485By convention, the default mode of representation for the Interactive Object has index 0.
72b7576f 486
d6b4d3d0 487@figure{visualization_image018.png,"",360}
72b7576f 488
bf62b306 489Calculation 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.
72b7576f 490
bf62b306 491If you are creating your own type of interactive object, you must implement the Compute function in one of the following ways:
72b7576f 492
bf62b306 493#### For 3D:
72b7576f 494
bf62b306 495~~~~~
496void PackageName_ClassName::Compute
497 (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
2683e647 498 const Handle(Prs3d_Presentation)& aPresentation,
499 const Standard_Integer aMode = 0);
bf62b306 500~~~~~
72b7576f 501
bf62b306 502#### For hidden line removal (HLR) mode in 3D:
503~~~~~
504void PackageName_ClassName::Compute
505 (const Handle(Prs3d_Projector)& aProjector,
2683e647 506 const Handle(Prs3d_Presentation)& aPresentation);
bf62b306 507~~~~~
72b7576f 508
bf62b306 509@subsubsection occt_visu_3_2_2 Hidden Line Removal
72b7576f 510
2683e647 511The 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.
72b7576f 512
bf62b306 513By convention, the Interactive Object accepts or rejects the representation of HLR mode. It is possible to make this declaration in one of two ways:
72b7576f 514
bf62b306 515* Initially by using one of the values of the enumeration *PrsMgr_TypeOfPresentation*:
516 * *PrsMgr_TOP_AllView*,
517 * *PrsMgr_TOP_ProjectorDependant*
72b7576f 518
bf62b306 519* Later by using the function *PrsMgr_PresentableObject::SetTypeOfPresentation*
72b7576f 520
bf62b306 521*AIS_Shape* class is an example of an interactive object that supports HLR representation. It supports two types of the HLR algorithm:
2683e647 522* the polygonal algorithm based on the shape's triangulation;
523* the exact algorithm that works with the shape's real geometry.
72b7576f 524
bf62b306 525The 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:
526 * *Prs3d_TOH_PolyAlgo* for a polygonal algorithm;
527 * *Prs3d_TOH_Algo* for an exact algorithm;
528 * *Prs3d_TOH_NotSet* if the type of algorithm is not set for the given interactive object instance.
72b7576f 529
bf62b306 530The type of the HLR algorithm used for *AIS_Shape* can be changed by calling the *AIS_Shape::SetTypeOfHLR()* method.
72b7576f 531
bf62b306 532The current HLR algorithm type can be obtained using *AIS_Shape::TypeOfHLR()* method is to be used.
72b7576f 533
bf62b306 534These 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*.
72b7576f 535
bf62b306 536So 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.
72b7576f 537
bf62b306 538@subsubsection occt_visu_3_2_3 Presentation modes
72b7576f 539
bf62b306 540There are four types of interactive objects in AIS:
541 * the "construction element" or Datum,
542 * the Relation (dimensions and constraints)
543 * the Object
544 * the None type (when the object is of an unknown type).
72b7576f 545
bf62b306 546Inside 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:
547 * *AIS_InteractiveObject::Type*
548 * *AIS_InteractiveObject::Signature*.
72b7576f 549
67d7f07f 550**Note** that some signatures are already used by "standard" objects provided in AIS (see the @ref occt_visu_3_5 "List of Standard Interactive Object Classes".
72b7576f 551
bf62b306 552The 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.
72b7576f 553
bf62b306 554Consequently, to get information about this class it is necessary to use virtual function *AIS_InteractiveObject::AcceptDisplayMode*.
72b7576f 555
bf62b306 556#### Display Mode
72b7576f 557
bf62b306 558The 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.
72b7576f 559
bf62b306 560#### Highlight Mode
72b7576f 561
bf62b306 562At dynamic detection, the presentation echoed by the Interactive Context, is by default the presentation already on the screen.
72b7576f 563
bf62b306 564The 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.
72b7576f 565
bf62b306 566Note 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).
72b7576f 567
bf62b306 568For 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.
72b7576f 569
bf62b306 570#### Infinite Status
2683e647 571If 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.
72b7576f 572
bf62b306 573Let us take for example the class called *IShape* representing an interactive object :
72b7576f 574
bf62b306 575~~~~~
576myPk_IShape::myPK_IShape
577 (const TopoDS_Shape& SH, PrsMgr_TypeOfPresentation aType):
2683e647 578 AIS_InteractiveObject(aType), myShape(SH), myDrwr(new AIS_Drawer()) {SetHilightMode(0);}
bf62b306 579void myPk_IShape::Compute
580 (const Handle(PrsMgr_PresentationManager3d) & PM,
2683e647 581 const Handle(Prs3d_Presentation)& P,
bf62b306 582 const Standard_Integer TheMode)
583{
584 switch (TheMode){
585 case 0:
586 StdPrs_WFDeflectionShape::Add (P,myShape,myDrwr); //algo for calculation of wireframe presentation break;
587 case 1:
588 StdPrs_ShadedShape::Add (P,myShape,myDrwr); //algo for calculation of shading presentation.
589 break;
590 }
591}
592void myPk_IsShape::Compute
593 (const Handle(Prs3d_Projector)& Prj,
594 const Handle(Prs3d_Presentation) P)
595{
596 StdPrs_HLRPolyShape::Add(P,myShape,myDrwr);
597 //Hidden line mode calculation algorithm
598}
599~~~~~
72b7576f 600
bf62b306 601@subsubsection occt_visu_3_2_4 Selection
72b7576f 602
a7d4dd94 603An 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).
72b7576f 604
a7d4dd94 605The set of sensitive primitives, which correspond to a given mode, is stocked in a <b>selection</b> (*SelectMgr_Selection*).
72b7576f 606
a7d4dd94 607Each 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>.
72b7576f 608
ebcbd824 609The 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*.
72b7576f 610
a7d4dd94 611A detailed explanation of the mechanism and the manner of implementing this function has been given in @ref occt_visu_2_2 "Selection" chapter.
72b7576f 612
a7d4dd94 613There 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*.
72b7576f 614
a7d4dd94 615You can change the default selection mode index of a custom interactive object using the following functions:
616 * *AIS_InteractiveObject::setGlobalSelMode* sets global selection mode;
617 * *AIS_InteractiveObject::GlobalSelectionMode* returns global selection mode of the object;
618 * *AIS_InteractiveObject::GlobalSelOwner* returns an entity owner that corresponds to a global selection mode.
bf62b306 619
a7d4dd94 620You 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:
bf62b306 621 * *AIS_InteractiveObject::HasSelectionPriority* checks if there is a selection priority setting for the owner;
622 * *AIS_InteractiveObject::SelectionPriority* checks the current priority;
623 * *AIS_InteractiveObject::SetSelectionPriority* sets a priority;
624 * *AIS_InteractiveObject::UnsetSelectionPriority* unsets the priority.
625
2683e647 626
bf62b306 627@subsubsection occt_visu_3_2_5 Graphic attributes
72b7576f 628
18006a0f 629Graphic attributes manager, or *AIS Drawer*, stores graphic attributes for specific interactive objects and for interactive objects controlled by interactive context.
630
631Initially, all drawer attributes are filled out with the predefined values which will define the default 3D object appearance.
632
633When 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.
634
635Keep in mind the following points concerning graphic attributes:
bf62b306 636 * Each interactive object can have its own visualization attributes.
637 * 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
638 * 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.)
639 * 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.
72b7576f 640
d6b4d3d0 641@figure{visualization_image019.png,"Redefinition of virtual functions for changes in AIS_Point",360}
72b7576f 642
d6b4d3d0 643@figure{visualization_image020.png,"Redefinition of virtual functions for changes in AIS_Shape.",360}
72b7576f 644
bf62b306 645The following virtual functions provide settings for color, width, material and transparency:
646 * *AIS_InteractiveObject::UnsetColor*
647 * *AIS_InteractiveObject::SetWidth*
648 * *AIS_InteractiveObject::UnsetWidth*
649 * *AIS_InteractiveObject::SetMaterial (const Graphic3d_NameOfPhysicalMaterial & aName)*
2683e647 650 * *AIS_InteractiveObject::SetMaterial (const Graphic3d_MaterialAspect & aMat)*
bf62b306 651 * *AIS_InteractiveObject::UnsetMaterial*
652 * *AIS_InteractiveObject::SetTransparency*
653 * *AIS_InteractiveObject::UnsetTransparency*
72b7576f 654
bf62b306 655For other types of attribute, it is appropriate to change the Drawer of the object directly using:
656 * *AIS_InteractiveObject::SetAttributes*
657 * *AIS_InteractiveObject::UnsetAttributes*
72b7576f 658
bf62b306 659It is important to know which functions may imply the recalculation of presentations of the object.
72b7576f 660
bf62b306 661If the presentation mode of an interactive object is to be updated, a flag from *PrsMgr_PresentableObject* indicates this.
72b7576f 662
bf62b306 663The mode can be updated using the functions *Display* and *Redisplay* in *AIS_InteractiveContext*.
72b7576f 664
bf62b306 665@subsubsection occt_visu_3_2_6 Complementary Services
72b7576f 666
bf62b306 667When you use complementary services for interactive objects, pay special attention to the cases mentioned below.
72b7576f 668
bf62b306 669#### Change the location of an interactive object
72b7576f 670
bf62b306 671The following functions allow temporarily "moving" the representation and selection of Interactive Objects in a view without recalculation.
672 * *AIS_InteractiveContext::SetLocation*
673 * *AIS_InteractiveContext::ResetLocation*
674 * *AIS_InteractiveContext::HasLocation*
675 * *AIS_InteractiveContext::Location*
676
677#### Connect an interactive object to an applicative entity
72b7576f 678
bf62b306 679Each Interactive Object has functions that allow attributing it an *Owner* in form of a *Transient*.
680 * *AIS_InteractiveObject::SetOwner*
681 * *AIS_InteractiveObject::HasOwner*
682 * *AIS_InteractiveObject::Owner*
72b7576f 683
bf62b306 684An interactive object can therefore be associated or not with an applicative entity, without affecting its behavior.
72b7576f 685
bf62b306 686#### Resolving coincident topology
72b7576f 687
bf62b306 688Due to the fact that the accuracy of three-dimensional graphics coordinates has a finite resolution the elements of topological objects can coincide producing the effect of "popping" some elements one over another.
72b7576f 689
bf62b306 690To 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.
72b7576f 691
2683e647 692The method *AIS_InteractiveObject::SetPolygonOffsets (const Standard_Integer aMode, const Standard_Real aFactor, const Standard_Real aUnits)* allows setting up the polygon offsets.
72b7576f 693
bf62b306 694The parameter *aMode* can contain various combinations of *Aspect_PolygonOffsetMode* enumeration elements:
695 * *Aspect_POM_None*
696 * *Aspect_POM_Off*
4ee1bdf4 697 * *Aspect_POM_Fill*
698 * *Aspect_POM_Line*
699 * *Aspect_POM_Point*
700 * *Aspect_POM_All*
72b7576f 701
bf62b306 702The 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:
703~~~~~
704 offset = aFactor * m + aUnits * r
705~~~~~
706where *m* is the maximum depth slope for the currently displayed polygons, r is the minimum depth resolution (implementation-specific).
72b7576f 707
bf62b306 708Negative offset values move polygons closer to the viewer while positive values shift polygons away.
72b7576f 709
bf62b306 710**Warning**
711
3f812249 712This 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.
72b7576f 713
bf62b306 714You can use the following functions to obtain the current settings for polygon offsets:
715~~~~~
716 void AIS_InteractiveObject::PolygonOffsets
717 (Standard_Integer &aMode,
2683e647 718 Standard_Real &aFactor,
719 Standard_Real &aUnits)
bf62b306 720 Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets()
721~~~~~
72b7576f 722
bf62b306 723The same operation could be performed for the interactive object known by the *AIS_InteractiveContext* with the following methods:
724~~~~~
725void AIS_InteractiveContext::SetPolygonOffsets
726 (const Handle(AIS_InteractiveObject) &anObj,
2683e647 727 const Standard_Integer aMode,
728 const Standard_Real aFactor,
729 const Standard_Real aUnits)
bf62b306 730void AIS_InteractiveContext::PolygonOffsets
731 (const Handle(AIS_InteractiveObject) &anObj,
2683e647 732 Standard_Integer &aMode,
733 Standard_Real &aFactor,
734 Standard_Real &aUnits)
735Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets
bf62b306 736 (const Handle(AIS_InteractiveObject) &anObj)
737~~~~~
72b7576f 738
ebcbd824 739
740@subsubsection occt_visu_3_2_7 Object hierarchy
741
742Each *PrsMgr_PresentableObject* has a list of objects called *myChildren*.
743Any transformation of *PrsMgr_PresentableObject* is also applied to its children. This hierarchy does not propagate to *Graphic3d* level and below.
744
745*PrsMgr_PresentableObject* sends its combined (according to the hierarchy) transformation down to *Graphic3d_Structure*.
746
747The materials of structures are not affected by the hierarchy.
748
749Object hierarchy can be controlled by the following API calls:
750* *PrsMgr_PresentableObject::AddChild*;
751* *PrsMgr_PresentableObject::RemoveChild*.
752
753@subsubsection occt_visu_3_2_8 Instancing
754
755The conception of instancing operates the object hierarchy as follows:
756* Instances are represented by separated *AIS* objects.
757* Instances do not compute any presentations.
758
759Classes *AIS_ConnectedInteractive* and *AIS_MultipleConnectedInteractive* are used to implement this conception.
760
761*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.
762
763*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.
764
765*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.
766
767All *AIS_MultipleConnectedInteractive* are able to have child assemblies. Deep copy of object instances tree is performed if one assembly is attached to another.
768
769Note 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.
770
771Instances can be controlled by the following DRAW commands:
772* *vconnect* : Creates and displays *AIS_MultipleConnectedInteractive* object from input objects and location.
773* *vconnectto* : Makes an instance of object with the given position.
774* *vdisconnect* : Disconnects all objects from an assembly or disconnects an object by name or number.
775* *vaddconnected* : Adds an object to the assembly.
776* *vlistconnected* : Lists objects in the assembly.
777
778Have a look at the examples below:
779~~~~~
780pload ALL
781vinit
782psphere s 1
783vdisplay s
784vconnectto s2 3 0 0 s # make instance
785vfit
786~~~~~
787
788See how proxy *OpenGl_Structure* is used to represent instance:
789
d6b4d3d0 790@figure{/user_guides/visualization/images/visualization_image029.png,"",240}
ebcbd824 791
792The original object does not have to be displayed in order to make instance. Also selection handles transformations of instances correctly:
793
794~~~~~
795pload ALL
796vinit
797psphere s 1
798psphere p 0.5
799vdisplay s # p is not displayed
800vsetloc s -2 0 0
801vconnect x 3 0 0 s p # make assembly
802vfit
803~~~~~
804
d6b4d3d0 805@figure{/user_guides/visualization/images/visualization_image030.png,"",420}
ebcbd824 806
807Here is the example of a more complex hierarchy involving sub-assemblies:
808
809~~~~~
810pload ALL
811vinit
812box b 1 1 1
813psphere s 0.5
814vdisplay b s
815vsetlocation s 0 2.5 0
816box d 0.5 0.5 3
817box d2 0.5 3 0.5
818vdisplay d d2
819
820vconnectto b1 -2 0 0 b
821vconnect z 2 0 0 b s
822vconnect z2 4 0 0 d d2
823vconnect z3 6 0 0 z z2
824vfit
825~~~~~
826
827
bf62b306 828@subsection occt_visu_3_3 Interactive Context
72b7576f 829
bf62b306 830@subsubsection occt_visu_3_3_1 Rules
72b7576f 831
18006a0f 832The 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.
72b7576f 833
bf62b306 834There 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.
72b7576f 835
bf62b306 836~~~~~
837Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);
4ee1bdf4 838 myIntContext->Display(TheAISShape);
839 myIntContext->SetDisplayMode(TheAISShape ,1);
840 myIntContext->SetColor(TheAISShape,Quantity_NOC_RED);
bf62b306 841~~~~~
72b7576f 842
bf62b306 843You can also write
72b7576f 844
bf62b306 845~~~~~
846Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);
4ee1bdf4 847 TheAISShape->SetColor(Quantity_NOC_RED);
848 TheAISShape->SetDisplayMode(1);
849 myIntContext->Display(TheAISShape);
bf62b306 850~~~~~
72b7576f 851
bf62b306 852@subsubsection occt_visu_3_3_2 Groups of functions
72b7576f 853
18006a0f 854**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.
72b7576f 855
18006a0f 856The **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.
857
858A 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).
72b7576f 859
bf62b306 860The Interactive Context is composed of many functions, which can be conveniently grouped according to the theme:
861 * management proper to the context;
862 * management in the local context;
863 * presentations and selection in open/closed context;
864 * selection strictly speaking.
72b7576f 865
18006a0f 866Some 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.
72b7576f 867
bf62b306 868@subsubsection occt_visu_3_3_3 Management of the Interactive Context
72b7576f 869
18006a0f 870The **Interactive Context** is made up of a **Principal Viewer** and, optionally, a trash bin or **Collector Viewer**.
871
872An 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.
873
874When 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.
875
876The following adjustable settings allow personalizing the behavior of presentations and selections:
877 * Default Drawer, containing all the color and line attributes which can be used by interactive objects, which do not have their own attributes.
bf62b306 878 * Default Visualization Mode for interactive objects. By default: *mode 0* ;
879 * Highlight color of entities detected by mouse movement. By default: *Quantity_NOC_CYAN1*;
880 * Pre-selection color. By default: *Quantity_NOC_GREEN*;
881 * Selection color (when you click on a detected object). By default: *Quantity_NOC_GRAY80*;
18006a0f 882 * Sub-Intensity color. By default: *Quantity_NOC_GRAY40*.
72b7576f 883
bf62b306 884All of these settings can be modified by functions proper to the Context.
72b7576f 885
bf62b306 886When 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.
72b7576f 887
bf62b306 888Let us examine the case of two interactive objects: *obj1* and *obj2*:
72b7576f 889
bf62b306 890~~~~~
4ee1bdf4 891TheCtx->Display(obj1,Standard_False); // False = no viewer update
892TheCtx->Display(obj2,Standard_True); // True = viewer update
893TheCtx->SetDisplayMode(obj1,3,Standard_False);
894TheCtx->SetDisplayMode(2);
bf62b306 895// obj2 is visualised in mode 2 (if it accepts this mode)
896// obj1 stays visualised in its mode 3.
897~~~~~
72b7576f 898
18006a0f 899*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.
72b7576f 900
bf62b306 901@subsection occt_visu_3_4 Local Context
18006a0f 902
bf62b306 903@subsubsection occt_visu_3_4_1 Rules and Conventions
72b7576f 904
bf62b306 905 * Opening a local context allows preparing an environment for temporary presentations and selections, which will disappear once the local context is closed.
906 * It is possible to open several local contexts, but only the last one will be active.
907 * 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.
908 * Each local context has an index created when the context opens. You should close the local context, which you have opened.
72b7576f 909
bf62b306 910The 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*.
911 * 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.
912 * The state of a temporary interactive object in a local context can only be modified while another local context is open.
72b7576f 913
bf62b306 914**Warning**
72b7576f 915
bf62b306 916The 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.
72b7576f 917
bf62b306 918@subsubsection occt_visu_3_4_2 Management of Local Context
72b7576f 919
bf62b306 920The local context can be opened using method *AIS_InteractiveContext::OpenLocalContext*. The following options are available:
4ee1bdf4 921 * *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.
67d7f07f 922 * *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*.
18006a0f 923 * *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.
72b7576f 924
bf62b306 925This function returns the index of the created local context. It should be kept and used when the context is closed.
72b7576f 926
bf62b306 927To load objects visualized at Neutral Point into a local context or remove them from it use methods
928~~~~~
929 AIS_InteractiveContext::UseDisplayedObjects
930 AIS_InteractiveContext::NotUseDisplayedObjects
931~~~~~
932Closing Local Contexts is done by:
933~~~~~
934 AIS_InteractiveContext::CloseLocalContext
935 AIS_InteractiveContext::CloseAllContexts
936~~~~~
72b7576f 937
bf62b306 938*Warning*
2683e647 939When 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.
72b7576f 940
18006a0f 941To 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.
72b7576f 942
18006a0f 943When 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.
72b7576f 944
72b7576f 945
bf62b306 946@subsubsection occt_visu_3_4_3 Presentation in a Neutral Point
72b7576f 947
18006a0f 948You 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.
72b7576f 949
bf62b306 950Neutral Point should be used to visualize the interactive objects, which represent and select an applicative entity. Visualization and Erasing orders are straightforward:
72b7576f 951
bf62b306 952~~~~~
953AIS_InteractiveContext::Display
954 (const Handle(AIS_InteractiveObject)& anIobj,
2683e647 955 const Standard_Boolean updateviewer=Standard_True);
bf62b306 956
957AIS_InteractiveContext::Display
958 (const Handle(AIS_InteractiveObject)& anIobj,
2683e647 959 const Standard_Integer amode,
960 const Standard_Integer aSelectionMode,
961 const Standard_Boolean updateviewer = Standard_True,
962 const Standard_Boolean allowdecomposition = Standard_True);
bf62b306 963
964 AIS_InteractiveContext::Erase
965 AIS_InteractiveContext::EraseMode
966 AIS_InteractiveContext::ClearPrs
967 AIS_InteractiveContext::Redisplay
968 AIS_InteractiveContext::Remove
969 AIS_InteractiveContext::EraseAll
970 AIS_InteractiveContext::Hilight
971 AIS_InteractiveContext::HilightWithColor
972~~~~~
973
974Bear in mind the following points:
975 * It is recommended to display and erase interactive objects when no local context is opened, and open a local context for local selection only.
2683e647 976 * 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).
bf62b306 977 * 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.
978 * 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.
979 * 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.
4ee1bdf4 980 * 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.
2683e647 981 * *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.
bf62b306 982 * 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.
983 * 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.
72b7576f 984
18006a0f 985@subsubsection occt_visu_3_4_4 Presentation in the Local Context
72b7576f 986
bf62b306 987In open local context, the *Display* functions presented above can be as well.
72b7576f 988
bf62b306 989**WARNING**
72b7576f 990
2683e647 991The 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*.
72b7576f 992
bf62b306 993You can activate or deactivate specific selection modes in the local open context in several different ways:
994Use the Display functions with the appropriate modes.
995
996~~~~~
997 AIS_InteractiveContext::ActivateStandardMode
998 //can be used only if a Local Context is opened.
999 AIS_InteractiveContext::DeactivateStandardMode
1000 AIS_InteractiveContext::ActivatedStandardModes
1001 AIS_InteractiveContext::SetShapeDecomposition
1002~~~~~
72b7576f 1003
bf62b306 1004This 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.
72b7576f 1005
bf62b306 1006**WARNING**
72b7576f 1007
4ee1bdf4 1008If 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)*.
72b7576f 1009
bf62b306 1010Load an interactive object by the function *AIS_InteractiveContext::Load*.
72b7576f 1011
bf62b306 1012This 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.
72b7576f 1013
bf62b306 1014Use *AIS_InteractiveContext::Activate* and *AIS_InteractiveContext::Deactivate* to directly activate/deactivate selection modes on an object.
72b7576f 1015
bf62b306 1016@subsubsection occt_visu_3_4_5 Filters
72b7576f 1017
18006a0f 1018To define an environment of dynamic detection, you can use standard filter classes or create your own.
1019A 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.
1020
1021The 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.
72b7576f 1022
bf62b306 1023You can create a custom class of filter objects by implementing the deferred function *IsOk()*:
72b7576f 1024
bf62b306 1025~~~~~
1026class MyFilter : public SelectMgr_Filter { };
1027virtual Standard_Boolean MyFilter::IsOk
1028 (const Handle(SelectMgr_EntityOwner)& anObj) const = 0;
1029~~~~~
72b7576f 1030
bf62b306 1031In *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*).
72b7576f 1032
bf62b306 1033There are Standard filters, which have already been implemented in several packages:
3f812249 1034 * *StdSelect_EdgeFilter* -- for edges, such as lines and circles;
1035 * *StdSelect_FaceFilter* -- for faces, such as planes, cylinders and spheres;
1036 * *StdSelect_ShapeTypeFilter* -- for shape types, such as compounds, solids, shells and wires;
1037 * *AIS_TypeFilter* -- for types of interactive objects;
1038 * *AIS_SignatureFilter* -- for types and signatures of interactive objects;
1039 * *AIS_AttributeFilter* -- for attributes of Interactive Objects, such as color and width.
72b7576f 1040
18006a0f 1041As 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*.
72b7576f 1042
bf62b306 1043**WARNING**
1044
1045Only 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.
72b7576f 1046
bf62b306 1047There are several functions to manipulate filters:
4ee1bdf4 1048* *AIS_InteractiveContext::AddFilter* adds a filter passed as an argument.
1049* *AIS_InteractiveContext::RemoveFilter* removes a filter passed as an argument.
1050* *AIS_InteractiveContext::RemoveFilters* removes all present filters.
1051* *AIS_InteractiveContext::Filters* gets the list of filters active in a local context.
dba69de2 1052
72b7576f 1053<h4>Example </h4>
1054
bf62b306 1055~~~~~
4ee1bdf4 1056myContext->OpenLocalContext(Standard_False);
bf62b306 1057// no object in neutral point is loaded
72b7576f 1058
4ee1bdf4 1059myContext->ActivateStandardMode(TopAbs_Face);
bf62b306 1060//activates decomposition of shapes into faces.
1061Handle (AIS_Shape) myAIShape = new AIS_Shape ( ATopoShape);
72b7576f 1062
4ee1bdf4 1063myContext->Display(myAIShape,1,-1,Standard_True,Standard_True);
72b7576f 1064
4ee1bdf4 1065//shading visualization mode, no specific mode, authorization for decomposition into sub-shapes. At this Stage, myAIShape is decomposed into faces...
72b7576f 1066
bf62b306 1067Handle(StdSelect_FaceFilter) Fil1= new
1068 StdSelect_FaceFilter(StdSelect_Revol);
1069Handle(StdSelect_FaceFilter) Fil2= new
2683e647 1070 StdSelect_FaceFilter(StdSelect_Plane);
72b7576f 1071
4ee1bdf4 1072myContext->AddFilter(Fil1);
1073myContext->AddFilter(Fil2);
72b7576f 1074
bf62b306 1075//only faces of revolution or planar faces will be selected
1076
4ee1bdf4 1077myContext->MoveTo( xpix,ypix,Vue);
bf62b306 1078// detects the mouse position
1079~~~~~
72b7576f 1080
bf62b306 1081@subsubsection occt_visu_3_4_6 Selection in the Local Context
1082
1083Dynamic 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:
3f812249 1084 * *AIS_InteractiveContext::MoveTo* -- passes mouse position to Interactive Context selectors
1085 * *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
1086 * *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.
1087 * *AIS_InteractiveContext::Select* -- selects everything found in the surrounding area.
1088 * *AIS_InteractiveContext::ShiftSelect* -- selects what was not previously in the list of selected, deselects those already present.
bf62b306 1089
1090Highlighting 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 :
1091~~~~~
1092 AIS_InteractiveContext::SetAutomaticHilight
1093 AIS_InteractiveContext::AutomaticHilight
1094~~~~~
72b7576f 1095
bf62b306 1096If 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.
1097
1098**WARNING**
1099
1100When 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.
1101
1102You can question the Interactive context by moving the mouse. The following functions can be used:
1103 * *AIS_InteractiveContext::HasDetected* informs if something has been detected;
1104 * *AIS_InteractiveContext::HasDetectedShape* informs if it is a shape;
1105 * *AIS_InteractiveContext::DetectedShape* gets the shape if the detected entity is an object;
1106 * *AIS_InteractiveContext::DetectedInteractive* gets the interactive object if the detected entity is an object.
1107
1108After 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:
1109 * *AIS_InteractiveContext::InitCurrent* initiates a scan of this list;
1110 * *AIS_InteractiveContext::MoreCurrent* extends the scan;
1111 * *AIS_InteractiveContext::NextCurrent* resumes the scan;
1112 * *AIS_InteractiveContext::Current* gets the name of the current object detected in the scan;
1113 * *AIS_InteractiveContext::FirstCurrentObject* gets the first current interactive object;
1114 * *AIS_InteractiveContext::HilightCurrents* highlights current objects;
1115 * *AIS_InteractiveContext::UnhilightCurrents* removes highlight from current objects;
1116 * *AIS_InteractiveContext::ClearCurrents* empties the list of current objects in order to update it;
1117 * *AIS_InteractiveContext::IsCurrent* finds the current object.
1118
1119In the Local Context, you can explore the list of selected objects available. The following functions can be used:
1120 * *AIS_InteractiveContext::InitSelected* initiates the list of objects;
1121 * *AIS_InteractiveContext::MoreSelected* extends the list of objects;
1122 * *AIS_InteractiveContext::NextSelected* resumes a scan;
1123 * *AIS_InteractiveContext::SelectedShape* gets the name of the selected object;
1124 * *AIS_InteractiveContext::HasSelectedShape* checks if the selected shape is obtained;
1125 * *AIS_InteractiveContext::Interactive* gets the picked interactive object;
1126 * *AIS_InteractiveContext::HasApplicative* checks if the applicative object has an owner from Interactive attributed to it;
1127 * *AIS_InteractiveContext::Applicative* gets the owner of the detected applicative entity;
1128 * *AIS_InteractiveContext::IsSelected* gets the name of the selected object.
72b7576f 1129
72b7576f 1130
bf62b306 1131<h4>Example </h4>
1132~~~~~
4ee1bdf4 1133myAISCtx->InitSelected();
1134while (myAISCtx->MoreSelected())
bf62b306 1135 {
4ee1bdf4 1136 if (myAISCtx->HasSelectedShape)
bf62b306 1137 {
4ee1bdf4 1138 TopoDS_Shape ashape = myAISCtx->SelectedShape();
bf62b306 1139 // to be able to use the picked shape
2683e647 1140 }
bf62b306 1141 else
1142 {
4ee1bdf4 1143 Handle_AIS_InteractiveObject anyobj = myAISCtx->Interactive();
bf62b306 1144 // to be able to use the picked interactive object
1145 }
4ee1bdf4 1146myAISCtx->NextSelected();
bf62b306 1147}
1148~~~~~
72b7576f 1149
bf62b306 1150You 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:
1151 * *AIS_InteractiveContext::EraseSelected* erases the selected objects;
1152 * *AIS_InteractiveContext::DisplaySelected* displays them;
1153 * *AIS_InteractiveContext::SetSelected* puts the objects in the list of selections;
1154 * *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;
1155 * *AIS_InteractiveContext::AddOrRemoveSelected* adds or removes an object from the list of selected entities;
1156 * *AIS_InteractiveContext::HilightSelected* highlights the selected object;
1157 * *AIS_InteractiveContext::UnhilightSelected* removes highlighting from the selected object;
1158 * *AIS_InteractiveContext::ClearSelected* empties the list of selected objects.
72b7576f 1159
72b7576f 1160
bf62b306 1161You can highlight and remove highlighting from a current object, and empty the list of current objects using the following functions:
1162~~~~~
1163 AIS_InteractiveContext::HilightCurrents
1164 AIS_InteractiveContext::UnhilightCurrents
1165 AIS_InteractiveContext::ClearCurrents
1166~~~~~
1167When you are in an open Local Context, you may need to keep "temporary" interactive objects. This is possible using the following functions:
1168 * *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.
1169 * *AIS_InteractiveContext::SetSelectedCurrent* allows the selected object to become the current object when you close the local context.
72b7576f 1170
bf62b306 1171You 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).
72b7576f 1172
bf62b306 1173@subsubsection occt_visu_3_4_7 Recommendations
72b7576f 1174
bf62b306 1175The possibilities of use for local contexts are numerous depending on the type of operation that you want to perform:
72b7576f 1176 * working on all visualized interactive objects,
1177 * working on only a few objects,
1178 * working on a single object.
1179
bf62b306 1180When 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:
72b7576f 1181
bf62b306 1182~~~~~
1183AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& aListOfIO) const;
1184AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive WhichKind, const Standard_Integer WhichSignature;
1185AIS_ListOfInteractive& aListOfIO) const;
1186~~~~~
72b7576f 1187
bf62b306 1188At this stage, you only have to load the functions *Load, Activate,* and so on.
72b7576f 1189
bf62b306 1190When you open a Local Context with default options, you must keep the following points in mind:
1191* 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.
1192* The Shape Type Interactive Objects are automatically decomposed into sub-shapes when standard activation modes are launched.
1193* 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.
72b7576f 1194
bf62b306 1195The stages could be the following:
1196 1. Open a Local Context with the right options;
1197 2. Load/Visualize the required complementary objects with the desired activation modes.
1198 3. Activate Standard modes if necessary
1199 4. Create its filters and add them to the Local Context
1200 5. Detect/Select/recover the desired entities
1201 6. Close the Local Context with the adequate index.
72b7576f 1202
bf62b306 1203It 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.
1204
1205Let us assume that you have visualized several types of interactive objects: *AIS_Points*, *AIS_Axes*, *AIS_Trihedrons*, and *AIS_Shapes*.
72b7576f 1206
bf62b306 1207For your applicative function, you need an axis to create a revolved object. You could obtain this axis by identifying:
72b7576f 1208 * an axis which is already visualized,
1209 * 2 points,
1210 * a rectilinear edge on the shapes which are present,
bf62b306 1211 * a cylindrical face on the shapes (You will take the axis of this face)
72b7576f 1212
bf62b306 1213~~~~~
1214myIHMEditor::myIHMEditor
1215 (const Handle(AIS_InteractiveContext)& Ctx,
2683e647 1216 ....) :
1217 myCtx(Ctx),
bf62b306 1218 ...
72b7576f 1219{
1220}
1221
1222myIHMEditor::PrepareContext()
1223{
4ee1bdf4 1224myIndex =myCtx->OpenLocalContext();
72b7576f 1225
bf62b306 1226//the filters
72b7576f 1227
2683e647 1228Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Point);
bf62b306 1229//filter on the points
72b7576f 1230
bf62b306 1231Handle(AIS_SignatureFilter) F2 = new AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Axis);
1232//filters on the axes.
72b7576f 1233
bf62b306 1234Handle(StdSelect_FaceFilter) F3 = new StdSelect_FaceFilter(AIS_Cylinder);
1235//cylindrical face filters
72b7576f 1236//...
bf62b306 1237// activation of standard modes on the shapes..
4ee1bdf4 1238myCtx->ActivateStandardMode(TopAbs_FACE);
1239myCtx->ActivateStandardMode(TopAbs_VERTEX);
1240myCTX->Add(F1);
1241myCTX->Add(F2);
1242myCTX->Add(F3);
72b7576f 1243
bf62b306 1244// at this point, you can call the selection/detection function
72b7576f 1245}
1246
1247void myIHMEditor::MoveTo(xpix,ypix,Vue)
1248
4ee1bdf4 1249{ myCTX->MoveTo(xpix,ypix,vue);
bf62b306 1250// the highlight of what is detected is automatic.
1251}
1252Standard_Boolean myIHMEditor::Select()
1253{
1254// returns true if you should continue the selection
4ee1bdf4 1255 myCTX->Select();
1256 myCTX->InitSelected();
1257 if(myCTX->MoreSelected())
2683e647 1258 {
1259 if(myCTX->HasSelectedShape())
4ee1bdf4 1260 { const TopoDS_Shape& sh = myCTX->SelectedShape();
bf62b306 1261 if( vertex){
1262 if(myFirstV...)
1263 {
4ee1bdf4 1264 //if it is the first vertex, you stock it, then you deactivate the faces and only keep the filter on the points:
bf62b306 1265 mypoint1 = ....;
4ee1bdf4 1266 myCtx->RemoveFilters();
1267 myCTX->DeactivateStandardMode(TopAbs_FACE);
1268 myCtx->Add(F1);
bf62b306 1269 // the filter on the AIS_Points
4ee1bdf4 1270 myFirstV = Standard_False;
1271 return Standard_True;
2683e647 1272 }
bf62b306 1273 else
2683e647 1274 {
bf62b306 1275 mypoint2 =...;
1276 // construction of the axis return Standard_False;
1277 }
2683e647 1278 }
1279 else
1280 {
bf62b306 1281 //it is a cylindrical face : you recover the axis; visualize it; and stock it.
1282 return Standard_False;
1283 }
2683e647 1284 }
bf62b306 1285 // it is not a shape but is no doubt a point.
1286 else
1287 {
1288 Handle(AIS_InteractiveObject)
4ee1bdf4 1289 SelObj = myCTX->SelectedInteractive();
1290 if(SelObj->Type()==AIS_KOI_Datum)
bf62b306 1291 {
4ee1bdf4 1292 if(SelObj->Signature()==1)
bf62b306 1293 {
1294 if (firstPoint)
1295 {
1296 mypoint1 =...
1297 return Standard_True;
1298 }
1299 else
1300 {
1301 mypoint2 = ...;
1302 //construction of the axis, visualization, stocking
1303 return Standard_False;
1304 }
1305 }
1306
1307 else
1308 {
1309 // you have selected an axis; stock the axis
1310 return Standard_False;
1311 }
1312 }
1313 }
1314 }
1315 }
1316void myIHMEditor::Terminate()
1317{
1318myCtx->CloseLocalContext(myIndex);
1319...
1320}
1321~~~~~
72b7576f 1322
bf62b306 1323@subsection occt_visu_3_5 Standard Interactive Object Classes
72b7576f 1324
18006a0f 1325Interactive Objects are selectable and viewable objects connecting graphic representation and the underlying reference geometry.
1326
1327They are divided into four types:
3f812249 1328 * the **Datum** -- a construction geometric element;
1329 * the **Relation** -- a constraint on the interactive shape and the corresponding reference geometry;
1330 * the **Object** -- a topological shape or connection between shapes;
1331 * **None** -- a token, that instead of eliminating the object, tells the application to look further until it finds an acceptable object definition in its generation.
18006a0f 1332
1333Inside 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*).
1334If 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>.
1335
1336@subsubsection occt_visu_3_5_1 Datum
1337
1338The **Datum** groups together the construction elements such as lines, circles, points, trihedrons, plane trihedrons, planes and axes.
bf62b306 1339
1340*AIS_Point, AIS_Axis, AIS_Line, AIS_Circle, AIS_Plane* and *AIS_Trihedron* have four selection modes:
1341 * mode 0 : selection of a trihedron;
1342 * mode 1 : selection of the origin of the trihedron;
1343 * mode 2 : selection of the axes;
1344 * mode 3 : selection of the planes XOY, YOZ, XOZ.
72b7576f 1345
bf62b306 1346when you activate one of modes: 1 2 3 4, you pick AIS objects of type:
1347 * *AIS_Point*
1348 * *AIS_Axis* (and information on the type of axis)
1349 * *AIS_Plane* (and information on the type of plane).
72b7576f 1350
bf62b306 1351*AIS_PlaneTrihedron* offers three selection modes:
1352 * mode 0 : selection of the whole trihedron;
1353 * mode 1 : selection of the origin of the trihedron;
3f812249 1354 * mode 2 : selection of the axes -- same remarks as for the Trihedron.
72b7576f 1355
f3495b01 1356For 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.
e5bd0d98 1357
18006a0f 1358@subsubsection occt_visu_3_5_2 Object
1359
1360The **Object** type includes topological shapes, and connections between shapes.
e5bd0d98 1361
ba06f8bb 1362*AIS_Shape* has three visualization modes :
72b7576f 1363 * mode 0 : Line (default mode)
1364 * mode 1 : Shading (depending on the type of shape)
1365 * mode 2 : Bounding Box
1366
ba06f8bb 1367And at maximum seven selection modes, depending on the shape complexity:
bf62b306 1368 * mode 0 : selection of the *AIS_Shape*;
1369 * mode 1 : selection of the vertices;
1370 * mode 2 : selection of the edges;
1371 * mode 3 : selection of the wires;
1372 * mode 4 : selection of the faces;
1373 * mode 5 : selection of the shells;
e5bd0d98 1374 * mode 6 : selection of the constituent solids.
72b7576f 1375
ba06f8bb 1376 * *AIS_Triangulation* is a simple interactive object for displaying triangular mesh contained in *Poly_Triangulation* container.
1377 * *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.
ba06f8bb 1378 * *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)
ba06f8bb 1379 * *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.
1380 * *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.
72b7576f 1381
18006a0f 1382
1383The class *AIS_ColoredShape* allows using custom colors and line widths for *TopoDS_Shape* objects and their sub-shapes.
1384
1385~~~~~
1386 AIS_ColoredShape aColoredShape = new AIS_ColoredShape (theShape);
1387
1388 // setup color of entire shape
1389 aColoredShape->SetColor (Quantity_Color (Quantity_NOC_RED));
1390
1391 // setup line width of entire shape
1392 aColoredShape->SetWidth (1.0);
1393
1394 // set transparency value
1395 aColoredShape->SetTransparency (0.5);
1396
1397 // customize color of specified sub-shape
1398 aColoredShape->SetCustomColor (theSubShape, Quantity_Color (Quantity_NOC_BLUE1));
1399
1400 // customize line width of specified sub-shape
1401 aColoredShape->SetCustomWidth (theSubShape, 0.25);
1402~~~~~
1403
1404The 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.
1405- The type of point marker used to draw points can be specified as a presentation aspect.
1406- The presentation provides selection by a bounding box of the visualized set of points. It supports two display / highlighting modes: points or bounding box.
1407
d6b4d3d0 1408@figure{point_cloud.png,"A random colored cloud of points",240}
18006a0f 1409
1410Example:
1411~~~~~
1412Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (2000, Standard_True);
1413aPoints->AddVertex (gp_Pnt(-40.0, -40.0, -40.0), Quantity_Color (Quantity_NOC_BLUE1));
1414aPoints->AddVertex (gp_Pnt (40.0, 40.0, 40.0), Quantity_Color (Quantity_NOC_BLUE2));
1415
1416Handle(AIS_PointCloud) aPntCloud = new AIS_PointCloud();
1417aPntCloud->SetPoints (aPoints);
1418~~~~~
1419
1420The draw command *vpointcloud* builds a cloud of points from shape triangulation.
1421This command can also draw a sphere surface or a volume with a large amount of points (more than one million).
1422
1423
bf62b306 1424@subsubsection occt_visu_3_5_3 Relations
18006a0f 1425
1426The **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.
1427
1428The following relations are provided by *AIS*:
bf62b306 1429 * *AIS_ConcentricRelation*
1430 * *AIS_FixRelation*
1431 * *AIS_IdenticRelation*
1432 * *AIS_ParallelRelation*
1433 * *AIS_PerpendicularRelation*
1434 * *AIS_Relation*
1435 * *AIS_SymmetricRelation*
1436 * *AIS_TangentRelation*
72b7576f 1437
bf62b306 1438The list of relations is not exhaustive.
72b7576f 1439
bf62b306 1440@subsubsection occt_visu_3_5_4 Dimensions
1441 * *AIS_AngleDimension*
1442 * *AIS_Chamf3dDimension*
1443 * *AIS_DiameterDimension*
1444 * *AIS_DimensionOwner*
1445 * *AIS_LengthDimension*
1446 * *AIS_OffsetDimension*
1447 * *AIS_RadiusDimension*
72b7576f 1448
bf62b306 1449 @subsubsection occt_visu_3_5_5 MeshVS_Mesh
72b7576f 1450
bf62b306 1451*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.
72b7576f 1452
3f812249 1453However, the *DataSource* does not provide any information on attributes, for example nodal colors, but you can apply them in a special way -- by choosing the appropriate presentation builder.
72b7576f 1454
bf62b306 1455The 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.
72b7576f 1456
72b7576f 1457You can add/remove builders using the following methods:
bf62b306 1458~~~~~
1459 MeshVS_Mesh::AddBuilder (const Handle (MeshVS_PrsBuilder) &Builder, Standard_Boolean TreatAsHilighter)
1460 MeshVS_Mesh::RemoveBuilder (const Standard_Integer Index)
1461 MeshVS_Mesh::RemoveBuilderById (const Standard_Integer Id)
1462~~~~~
72b7576f 1463
bf62b306 1464There 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:
1465~~~~~
1466 MeshVS_DMF_WireFrame
1467 MeshVS_DMF_Shading
1468 MeshVS_DMF_Shrink
1469~~~~~
72b7576f 1470
bf62b306 1471It is also possible to display deformed mesh in wireframe, shading or shrink modes usung :
1472~~~~~
1473 MeshVS_DMF_DeformedPrsWireFrame
1474 MeshVS_DMF_DeformedPrsShading
1475 MeshVS_DMF_DeformedPrsShrink
1476~~~~~
72b7576f 1477
bf62b306 1478The following methods represent different kinds of data :
1479~~~~~
1480 MeshVS_DMF_VectorDataPrs
1481 MeshVS_DMF_NodalColorDataPrs
1482 MeshVS_DMF_ElementalColorDataPrs
1483 MeshVS_DMF_TextDataPrs
1484 MeshVS_DMF_EntitiesWithData
1485~~~~~
1486
1487The following methods provide selection and highlighting :
1488~~~~~
1489 MeshVS_DMF_SelectionPrs
1490 MeshVS_DMF_HilightPrs
1491~~~~~
72b7576f 1492
bf62b306 1493*MeshVS_DMF_User* is a user-defined mode.
72b7576f 1494
bf62b306 1495These values will be used by the presentation builder.
1496There is also a set of selection modes flags that can be grouped in a combination of bits:
1497 * *MeshVS_SMF_0D*
1498 * *MeshVS_SMF_Link*
1499 * *MeshVS_SMF_Face*
1500 * *MeshVS_SMF_Volume*
3f812249 1501 * *MeshVS_SMF_Element* -- groups *0D, Link, Face* and *Volume* as a bit mask ;
bf62b306 1502 * *MeshVS_SMF_Node*
3f812249 1503 * *MeshVS_SMF_All* -- groups *Element* and *Node* as a bit mask;
bf62b306 1504 * *MeshVS_SMF_Mesh*
1505 * *MeshVS_SMF_Group*
1506
1507Such an object, for example, can be used for displaying the object and stored in the STL file format:
72b7576f 1508
bf62b306 1509~~~~~
1510// read the data and create a data source
4178b353 1511Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFileName);
1512Handle(XSDRAWSTLVRML_DataSource) aDataSource = new XSDRAWSTLVRML_DataSource (aSTLMesh);
72b7576f 1513
bf62b306 1514// create mesh
1515Handle (MeshVS_Mesh) aMesh = new MeshVS();
4ee1bdf4 1516aMesh->SetDataSource (aDataSource);
72b7576f 1517
bf62b306 1518// use default presentation builder
1519Handle (MeshVS_MeshPrsBuilder) aBuilder = new MeshVS_MeshPrsBuilder (aMesh);
4ee1bdf4 1520aMesh->AddBuilder (aBuilder, Standard_True);
bf62b306 1521~~~~~
72b7576f 1522
bf62b306 1523*MeshVS_NodalColorPrsBuilder* allows representing a mesh with a color scaled texture mapped on it.
1524To do this you should define a color map for the color scale, pass this map to the presentation builder,
2683e647 1525and define an appropriate value in the range of 0.0 - 1.0 for every node.
72b7576f 1526
bf62b306 1527The following example demonstrates how you can do this (check if the view has been set up to display textures):
1528
1529~~~~~
1530// assign nodal builder to the mesh
1531Handle (MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder
2683e647 1532 (aMesh,MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
4ee1bdf4 1533aBuilder->UseTexture (Standard_True);
bf62b306 1534
1535// prepare color map
1536Aspect_SequenceOfColor aColorMap;
1537aColorMap.Append ((Quantity_NameOfColor) Quantity_NOC_RED);
1538aColorMap.Append ((Quantity_NameOfColor) Quantity_NOC_BLUE1);
1539
1540// assign color scale map values (0..1) to nodes
1541TColStd_DataMapOfIntegerReal aScaleMap;
2683e647 1542...
bf62b306 1543// iterate through the nodes and add an node id and an appropriate value to the map
1544aScaleMap.Bind (anId, aValue);
2683e647 1545
bf62b306 1546// pass color map and color scale values to the builder
4ee1bdf4 1547aBuilder->SetColorMap (aColorMap);
1548aBuilder->SetInvalidColor (Quantity_NOC_BLACK);
1549aBuilder->SetTextureCoords (aScaleMap);
1550aMesh->AddBuilder (aBuilder, Standard_True);
bf62b306 1551~~~~~
72b7576f 1552
bf62b306 1553@subsection occt_visu_3_6 Dynamic Selection
72b7576f 1554
a7d4dd94 1555The 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.
72b7576f 1556
a7d4dd94 1557For more details on the algorithm and examples of usage, please, refer to @ref occt_visu_2_2 "Selection" chapter.
72b7576f 1558
bf62b306 1559@section occt_visu_4 3D Presentations
72b7576f 1560
bf62b306 1561@subsection occt_visu_4_1 Glossary of 3D terms
72b7576f 1562
bf62b306 1563* **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.
3f812249 1564* **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.
1565* **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.
1566* **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.
1567* **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.
1568* **View** -- is defined by a view orientation, a view mapping, and a context view.
1569* **Viewer** -- manages a set of views.
1570* **View orientation** -- defines the manner in which the observer looks at the scene in terms of View Reference Coordinates.
1571* **View mapping** -- defines the transformation from View Reference Coordinates to the Normalized Projection Coordinates. This follows the Phigs scheme.
1572* **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.
72b7576f 1573
18006a0f 1574@subsection occt_visu_4_2 Graphic primitives
72b7576f 1575
18006a0f 1576The *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.
72b7576f 1577
bf62b306 1578Graphic structures can be:
72b7576f 1579 * Displayed,
1580 * Highlighted,
1581 * Erased,
1582 * Transformed,
18006a0f 1583 * Connected to form a tree hierarchy of structures, created by transformations.
bf62b306 1584
1585There are classes for:
72b7576f 1586 * Visual attributes for lines, faces, markers, text, materials,
1587 * Vectors and vertices,
72b7576f 1588 * Graphic objects, groups, and structures.
1589
18006a0f 1590@subsubsection occt_visu_4_2_2 Structure hierarchies
bf62b306 1591
18006a0f 1592The 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.
1593
1594@subsubsection occt_visu_4_2_3 Graphic primitives
bf62b306 1595* **Markers**
72b7576f 1596 * Have one or more vertices,
1597 * Have a type, a scale factor, and a color,
bf62b306 1598 * Have a size, shape, and orientation independent of transformations.
1599* **Polygons**
72b7576f 1600 * Have one closed boundary,
1601 * Have at least three vertices,
1602 * Are planar and have a normal,
3f812249 1603 * Have interior attributes -- style, color, front and back material, texture and reflection ratio,
1604 * Have a boundary with the following attributes -- type, width scale factor, color. The boundary is only drawn when the interior style is hollow.
72b7576f 1605
bf62b306 1606* **Polygons with holes**
1607 * Have multiple closed boundaries, each one with at least three vertices,
72b7576f 1608 * Are planar and have a normal,
3f812249 1609 * Have interior attributes -- style, color, front and back material,
1610 * Have a boundary with the following attributes -- type, width scale factor, color. The boundary is only drawn when the interior style is hollow.
72b7576f 1611
bf62b306 1612* **Polylines**
72b7576f 1613 * Have two or more vertices,
3f812249 1614 * Have the following attributes -- type, width scale factor, color.
72b7576f 1615
bf62b306 1616* **Text**
72b7576f 1617 * Has geometric and non-geometric attributes,
3f812249 1618 * Geometric attributes -- character height, character up vector, text path, horizontal and vertical alignment, orientation, three-dimensional position, zoomable flag
1619 * Non-geometric attributes -- text font, character spacing, character expansion factor, color.
72b7576f 1620
18006a0f 1621@subsubsection occt_visu_4_2_4 Primitive arrays
72b7576f 1622
bf62b306 1623Primitive 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.
72b7576f 1624
bf62b306 1625The 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.
72b7576f 1626
bf62b306 1627The 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:
1628
1629The following example shows how to disable the VBO support:
72b7576f 1630
bf62b306 1631~~~~~
4ee1bdf4 1632// get the graphic driver
bf62b306 1633Handle (Graphic3d_GraphicDriver) aDriver =
2683e647 1634 myAISContext->CurrentViewer()->Driver();
72b7576f 1635
4ee1bdf4 1636// disable VBO support
1637aDriver->EnableVBO (Standard_False);
bf62b306 1638~~~~~
72b7576f 1639
bf62b306 1640**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*.
1641
1642The different types of primitives could be presented with the following primitive arrays:
1643 * *Graphic3d_ArrayOfPoints,*
1644 * *Graphic3d_ArrayOfPolygons,*
1645 * *Graphic3d_ArrayOfPolylines,*
1646 * *Graphic3d_ArrayOfQuadrangles,*
1647 * *Graphic3d_ArrayOfQuadrangleStrips,*
1648 * *Graphic3d_ArrayOfSegments,*
1649 * *Graphic3d_ArrayOfTriangleFans,*
1650 * *Graphic3d_ArrayOfTriangles,*
1651 * *Graphic3d_ArrayOfTriangleStrips.*
1652
1653The *Graphic3d_ArrayOfPrimitives* is a base class for these primitive arrays.
1654
1655Method *Graphic3d_ArrayOfPrimitives::AddVertex* allows adding There is a set of similar methods to add vertices to the primitive array.
1656
1657These 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.
1658
1659You can also modify the values assigned to the vertex or query these values by the vertex index:
1660 * *void Graphic3d_ArrayOfPrimitives::SetVertice*
1661 * *void Graphic3d_ArrayOfPrimitives::SetVertexColor*
1662 * *void Graphic3d_ArrayOfPrimitives::SetVertexNormal*
1663 * *void Graphic3d_ArrayOfPrimitives::SetVertexTexel*
1664 * *gp_Pnt Graphic3d_ArrayOfPrimitives::Vertices*
2683e647 1665 * *gp_Dir Graphic3d_ArrayOfPrimitives::VertexNormal*
bf62b306 1666 * *gp_Pnt3d Graphic3d_ArrayOfPrimitives::VertexTexel*
1667 * *Quantity_Color Graphic3d_ArrayOfPrimitives::VertexColor*
1668 * *void Graphic3d_ArrayOfPrimitives::Vertices*
1669 * *void Graphic3d_ArrayOfPrimitives::VertexNormal*
1670 * *void Graphic3d_ArrayOfPrimitives::VertexTexel*
1671 * *void Graphic3d_ArrayOfPrimitives::VertexColor*
1672
1673The following example shows how to define an array of points:
72b7576f 1674
bf62b306 1675~~~~~
1676// create an array
1677Handle (Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (aVerticiesMaxCount);
1678
1679// add vertices to the array
4ee1bdf4 1680anArray->AddVertex (10.0, 10.0, 10.0);
1681anArray->AddVertex (0.0, 10.0, 10.0);
72b7576f 1682
bf62b306 1683// add the array to the structure
1684Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
4ee1bdf4 1685aGroup->BeginPrimitives ();
1686aGroup->AddPrimitiveArray (anArray);
1687aGroup->EndPrimitives ();
bf62b306 1688~~~~~
72b7576f 1689
bf62b306 1690If the primitives share the same vertices (polygons, triangles, etc.) then you can define them as indices of the vertices array.
72b7576f 1691
bf62b306 1692The 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.
72b7576f 1693
bf62b306 1694It is also possible to query the vertex defined by an edge using method *Graphic3d_ArrayOfPrimitives::Edge*
72b7576f 1695
bf62b306 1696The following example shows how to define an array of triangles:
72b7576f 1697
bf62b306 1698~~~~~
1699// create an array
2683e647 1700Standard_Boolean IsNormals = Standard_False;
1701Standard_Boolean IsColors = Standard_False;
bf62b306 1702Standard_Boolean IsTextureCrds = Standard_False;
1703Handle (Graphic3d_ArrayOfTriangles) anArray =
2683e647 1704 new Graphic3d_ArrayOfTriangles (aVerticesMaxCount,
1705 aEdgesMaxCount,
1706 IsNormals,
1707 IsColors,
1708 IsTextureCrds);
bf62b306 1709// add vertices to the array
2683e647 1710anArray->AddVertex (-1.0, 0.0, 0.0); // vertex 1
1711anArray->AddVertex ( 1.0, 0.0, 0.0); // vertex 2
1712anArray->AddVertex ( 0.0, 1.0, 0.0); // vertex 3
1713anArray->AddVertex ( 0.0,-1.0, 0.0); // vertex 4
bf62b306 1714
1715// add edges to the array
2683e647 1716anArray->AddEdge (1); // first triangle
4ee1bdf4 1717anArray->AddEdge (2);
1718anArray->AddEdge (3);
2683e647 1719anArray->AddEdge (1); // second triangle
4ee1bdf4 1720anArray->AddEdge (2);
1721anArray->AddEdge (4);
bf62b306 1722
1723// add the array to the structure
1724Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
4ee1bdf4 1725aGroup->BeginPrimitives ();
1726aGroup->AddPrimitiveArray (anArray);
1727aGroup->EndPrimitives ();
bf62b306 1728~~~~~
72b7576f 1729
bf62b306 1730If 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.
72b7576f 1731
bf62b306 1732It is also possible to set the color and query the number of edges in the bound and bound color.
1733~~~~~
1734 Standard_Integer Graphic3d_ArrayOfPrimitives::Bound
1735 Quantity_Color Graphic3d_ArrayOfPrimitives::BoundColor
1736 void Graphic3d_ArrayOfPrimitives::BoundColor
1737~~~~~
1738
1739The following example shows how to define an array of polygons:
72b7576f 1740
bf62b306 1741~~~~~
1742// create an array
2683e647 1743Standard_Boolean IsNormals = Standard_False;
bf62b306 1744Standard_Boolean IsVertexColors = Standard_False;
2683e647 1745Standard_Boolean IsFaceColors = Standard_False;
1746Standard_Boolean IsTextureCrds = Standard_False;
bf62b306 1747Handle (Graphic3d_ArrayOfPolygons) anArray =
2683e647 1748 new Graphic3d_ArrayOfPolygons (aVerticesMaxCount,
1749 aBoundsMaxCount,
1750 aEdgesMaxCount,
1751 IsNormals,
1752 IsVertexColors,
1753 IsFaceColors,
1754 IsTextureCrds);
bf62b306 1755
1756// add bounds to the array, first polygon
4ee1bdf4 1757anArray->AddBound (3);
2683e647 1758anArray->AddVertex (-1.0, 0.0, 0.0);
1759anArray->AddVertex ( 1.0, 0.0, 0.0);
1760anArray->AddVertex ( 0.0, 1.0, 0.0);
bf62b306 1761
1762// add bounds to the array, second polygon
4ee1bdf4 1763anArray->AddBound (4);
2683e647 1764anArray->AddVertex (-1.0, 0.0, 0.0);
1765anArray->AddVertex ( 1.0, 0.0, 0.0);
1766anArray->AddVertex ( 1.0,-1.0, 0.0);
1767anArray->AddVertex (-1.0,-1.0, 0.0);
bf62b306 1768
1769// add the array to the structure
1770Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
4ee1bdf4 1771aGroup->BeginPrimitives ();
1772aGroup->AddPrimitiveArray (anArray);
1773aGroup->EndPrimitives ();
bf62b306 1774~~~~~
72b7576f 1775
bf62b306 1776There are also several helper methods. You can get the type of the primitive array:
1777~~~~~
1778 Graphic3d_TypeOfPrimitiveArray
1779 Graphic3d_ArrayOfPrimitives::Type
1780 Standard_CString Graphic3d_ArrayOfPrimitives::StringType
1781~~~~~
72b7576f 1782
bf62b306 1783and check if the primitive array provides normals, vertex colors and vertex texels (texture coordinates):
72b7576f 1784
bf62b306 1785~~~~~
1786 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals
1787 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors
1788 Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels
1789~~~~~
72b7576f 1790or get the number of vertices, edges and bounds:
bf62b306 1791~~~~~
1792 Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber
1793 Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber
1794 Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber
1795~~~~~
1796
18006a0f 1797@subsubsection occt_visu_4_2_5 Text primitive
72b7576f 1798
bf62b306 1799The 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.
1800*Graphic3d* text primitives have the following features:
72b7576f 1801 * fixed size (non-zoomable) or zoomable,
1802 * can be rotated to any angle in the view plane,
1803 * support unicode charset.
1804
bf62b306 1805The text attributes for the group could be defined with the *Graphic3d_AspectText3d* attributes group.
1806To add any text to the graphic structure you can use the following methods:
1807~~~~~
1808 void Graphic3d_Group::Text
1809 (const Standard_CString AText,
2683e647 1810 const Graphic3d_Vertex& APoint,
1811 const Standard_Real AHeight,
1812 const Quantity_PlaneAngle AAngle,
1813 const Graphic3d_TextPath ATp,
1814 const Graphic3d_HorizontalTextAlignment AHta,
1815 const Graphic3d_VerticalTextAlignment AVta,
1816 const Standard_Boolean EvalMinMax),
bf62b306 1817~~~~~
1818*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).
1819
1820*ATp* parameter defines the text path, *AHta* is the horizontal alignment of the text, *AVta* is the vertical alignment of the text.
1821
2683e647 1822You can pass *Standard_False* as *EvalMinMax* if you do not want the graphic3d structure boundaries to be affected by the text position.
bf62b306 1823
1824**Note** that the text orientation angle can be defined by *Graphic3d_AspectText3d* attributes.
1825~~~~~
1826 void Graphic3d_Group::Text
1827 (const Standard_CString AText,
2683e647 1828 const Graphic3d_Vertex& APoint,
1829 const Standard_Real AHeight,
1830 const Standard_Boolean EvalMinMax)
bf62b306 1831 void Graphic3d_Group::Text
1832 (const TCcollection_ExtendedString &AText,
1833 const Graphic3d_Vertex& APoint,
2683e647 1834 const Standard_Real AHeight,
1835 const Quantity_PlaneAngle AAngle,
1836 const Graphic3d_TextPath ATp,
1837 const Graphic3d_HorizontalTextAlignment AHta,
1838 const Graphic3d_VerticalTextAlignment AVta,
1839 const Standard_Boolean EvalMinMax)
bf62b306 1840 void Graphic3d_Group::Text
1841 (const TCcollection_ExtendedString &AText,
2683e647 1842 const Graphic3d_Vertex& APoint,
1843 const Standard_Real AHeight,
1844 const Standard_Boolean EvalMinMax)
bf62b306 1845~~~~~
72b7576f 1846
bf62b306 1847See the example:
1848~~~~~
1849// get the group
1850Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
72b7576f 1851
bf62b306 1852// change the text aspect
1853Handle(Graphic3d_AspectText3d) aTextAspect = new Graphic3d_AspectText3d ();
4ee1bdf4 1854aTextAspect->SetTextZoomable (Standard_True);
1855aTextAspect->SetTextAngle (45.0);
1856aGroup->SetPrimitivesAspect (aTextAspect);
72b7576f 1857
bf62b306 1858// add a text primitive to the structure
72b7576f 1859Graphic3d_Vertex aPoint (1, 1, 1);
4ee1bdf4 1860aGroup->Text (Standard_CString ("Text"), aPoint, 16.0);
bf62b306 1861~~~~~
1862
18006a0f 1863@subsubsection occt_visu_4_2_6 Materials
1864
1865A *Graphic3d_MaterialAspect* is defined by:
1866 * Transparency;
3f812249 1867 * Diffuse reflection -- a component of the object color;
18006a0f 1868 * Ambient reflection;
3f812249 1869 * Specular reflection -- a component of the color of the light source;
18006a0f 1870 * Refraction index.
1871
1872The following items are required to determine the three colors of reflection:
1873 * Color;
1874 * Coefficient of diffuse reflection;
1875 * Coefficient of ambient reflection;
1876 * Coefficient of specular reflection.
1877
1878@subsubsection occt_visu_4_2_7 Textures
1879
1880A *texture* is defined by a name.
1881Three types of texture are available:
1882 * 1D;
1883 * 2D;
1884 * Environment mapping.
1885
1886@subsubsection occt_visu_4_2_8 Shaders
1887
1888OCCT 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:
1889
1890~~~~~
1891// Create shader program
1892Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();
1893
1894// Attach vertex shader
1895aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
1896 Graphic3d_TOS_VERTEX, "<Path to VS>"));
1897
1898// Attach fragment shader
1899aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
1900 Graphic3d_TOS_FRAGMENT, "<Path to FS>"));
1901
1902// Set values for custom uniform variables (if they are)
1903aProgram->PushVariable ("MyColor", Graphic3d_Vec3(0.0f, 1.0f, 0.0f));
1904
1905// Set aspect property for specific AISShape
1906theAISShape->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);
1907~~~~~
72b7576f 1908
18006a0f 1909@subsection occt_visu_4_3 Graphic attributes
72b7576f 1910
18006a0f 1911@subsubsection occt_visu_4_3_1 Aspect package overview
72b7576f 1912
18006a0f 1913The *Aspect* package provides classes for the graphic elements in the viewer:
1914 * Groups of graphic attributes;
1915 * Edges, lines, background;
1916 * Window;
1917 * Driver;
1918 * Enumerations for many of the above.
72b7576f 1919
18006a0f 1920@subsection occt_visu_4_4 3D view facilities
72b7576f 1921
18006a0f 1922@subsubsection occt_visu_4_4_1 Overview
72b7576f 1923
bf62b306 1924The *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.
72b7576f 1925
89a929ea 1926A set of high-level commands allows the separate manipulation of parameters and the result of a projection (Rotations, Zoom, Panning, etc.) as well as the visualization attributes (Mode, Lighting, Clipping, etc.) in any particular view.
bf62b306 1927
bf62b306 1928The *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:
72b7576f 1929 * Default parameters of the viewer,
1930 * Views (orthographic, perspective),
1931 * Lighting (positional, directional, ambient, spot, headlight),
89a929ea 1932 * Clipping planes,
bf62b306 1933 * Instantiated sequences of views, planes, light sources, graphic structures, and picks,
72b7576f 1934 * Various package methods.
1935
18006a0f 1936@subsubsection occt_visu_4_4_2 A programming example
72b7576f 1937
cfece3ef 1938This sample TEST program for the *V3d* Package uses primary packages *Xw* and *Graphic3d* and secondary packages *Visual3d, Aspect, Quantity* and *math*.
1939
1940~~~~~
1941// Create a default display connection
1942Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
1943
1944// Create a Graphic Driver from the default Aspect_DisplayConnection
1945Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection);
1946
1947// Create a Viewer to this Driver
1948Handle(V3d_Viewer) VM = new V3d_Viewer (aGraphicDriver);
1949VM->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET);
1950VM->SetDefaultViewProj (V3d_Xpos);
1951// Create a structure in this Viewer
1952Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (VM->Viewer());
1953
1954// Type of structure
1955aStruct->SetVisual (Graphic3d_TOS_SHADING);
4ee1bdf4 1956
1957// Create a group of primitives in this structure
cfece3ef 1958Handle(Graphic3d_Group) aPrsGroup = new Graphic3d_Group (aStruct);
72b7576f 1959
cfece3ef 1960// Fill this group with one quad of size 100
1961Handle(Graphic3d_ArrayOfTriangleStrips) aTriangles = new Graphic3d_ArrayOfTriangleStrips (4);
1962aTriangles->AddVertex (-100./2., -100./2., 0.0);
1963aTriangles->AddVertex (-100./2., 100./2., 0.0);
1964aTriangles->AddVertex ( 100./2., -100./2., 0.0);
1965aTriangles->AddVertex ( 100./2., 100./2., 0.0);
1966aPrsGroup->Polygon (aTriangles);
72b7576f 1967
4ee1bdf4 1968// Create Ambient and Infinite Lights in this Viewer
cfece3ef 1969Handle(V3d_AmbientLight) aLight1 = new V3d_AmbientLight (VM, Quantity_NOC_GRAY50);
1970Handle(V3d_DirectionalLight) aLight2 = new V3d_DirectionalLight (VM, V3d_XnegYnegZneg, Quantity_NOC_WHITE);
72b7576f 1971
4ee1bdf4 1972// Create a 3D quality Window with the same DisplayConnection
cfece3ef 1973Handle(Xw_Window) aWindow = new Xw_Window (aDispConnection, "Test V3d", 0.5, 0.5, 0.5, 0.5);
72b7576f 1974
cfece3ef 1975// Map this Window to this screen
1976aWindow->Map();
72b7576f 1977
4ee1bdf4 1978// Create a Perspective View in this Viewer
cfece3ef 1979Handle(V3d_View) aView = new V3d_View (VM);
18006a0f 1980aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
1981// Associate this View with the Window
cfece3ef 1982aView ->SetWindow (aWindow);
18006a0f 1983// Display ALL structures in this View
1984VM->Viewer()->Display();
1985// Finally update the Visualization in this View
1986aView->Update();
1987~~~~~
1988
3f812249 1989As an alternative to manual setting of perspective parameters the *V3d_View::ZfitAll()* and *V3d_View::FitAll()* functions can be used:
72b7576f 1990
18006a0f 1991~~~~~
1992// Display shape in Viewer VM
1993Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (VM);
1994aContext->Display(shape);
1995// Create a Perspective View in Viewer VM
1996Handle(V3d_View) V = new V3d_View (VM);
1997aview->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
1998// Change Z-min and Z-max planes of projection volume to match the displayed objects
1999V->ZFitAll();
2000// Fit view to object size
2001V->FitAll();
2002~~~~~
72b7576f 2003
18006a0f 2004@subsubsection occt_visu_4_4_3 Define viewing parameters
72b7576f 2005
18006a0f 2006View 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:
72b7576f 2007
3f812249 2008* **Eye** -- defines the observer (camera) position. Make sure the Eye point never gets between the Front and Back clipping planes.
72b7576f 2009
3f812249 2010* **Center** -- defines the origin of View Reference Coordinates (where camera is aimed at).
72b7576f 2011
3f812249 2012* **Direction** -- defines the direction of camera view (from the Eye to the Center).
72b7576f 2013
3f812249 2014* **Distance** -- defines the distance between the Eye and the Center.
72b7576f 2015
3f812249 2016* **Front** Plane -- defines the position of the front clipping plane in View Reference Coordinates system.
72b7576f 2017
3f812249 2018* **Back** Plane -- defines the position of the back clipping plane in View Reference Coordinates system.
72b7576f 2019
3f812249 2020* **ZNear** -- defines the distance between the Eye and the Front plane.
72b7576f 2021
3f812249 2022* **ZFar** -- defines the distance between the Eye and the Back plane.
dba69de2 2023
18006a0f 2024Most 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:
72b7576f 2025
18006a0f 2026Example:
2027~~~~~
2028// rotate camera by X axis on 30.0 degrees
2029gp_Trsf aTrsf;
2030aTrsf.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Dir (1.0, 0.0, 0.0)), 30.0);
2031aView->Camera()->Transform (aTrsf);
2032~~~~~
72b7576f 2033
18006a0f 2034@subsubsection occt_visu_4_4_4 Orthographic Projection
2035
d6b4d3d0 2036@figure{view_frustum.png,"Perspective and orthographic projection",420}
72b7576f 2037
18006a0f 2038The following code configures the camera for orthographic rendering:
72b7576f 2039
bf62b306 2040~~~~~
18006a0f 2041// Create an orthographic View in this Viewer
2042Handle(V3d_View) aView = new V3d_View (VM);
2043aView->Camera()->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
2044// update the Visualization in this View
2045aView->Update();
2046~~~~~
72b7576f 2047
18006a0f 2048@subsubsection occt_visu_4_4_5 Perspective Projection
72b7576f 2049
3f812249 2050