0024336: Content of OCCT documentation should be updated. Iter 2
[occt.git] / dox / user_guides / visualization / visualization.md
1 Visualization    {#user_guides__visualization}
2 ========================
3 @tableofcontents 
4
5 @section occt_visu_1 Introduction
6
7 This manual provides basic documentation on setting up and using  Visualization. For advanced information on Visualization and its applications,  see our offerings on our web site (Training and E-Learning) at http://www.opencascade.org/support/training/
8
9 Visualization in Open CASCADE Technology is based on the  separation of:  
10   * on the one hand - the data which stores the geometry and topology  of the entities you want to display and select, and 
11   * 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). 
12
13 @subsection occt_visu_1_1 Open CASCADE Technology Visualization and the Organization of this guide 
14
15 Presentations are managed through the Presentation  component, and selection through the Selection component.  
16
17 To make management of these functionalities in 3D more  intuitive and consequently, more transparent, *Application Interactive Services* have been created. *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.  
18
19 If, however, you require types of interactive objects and  filters other than those provided, you will need to know the mechanics of  presentable and selectable objects, specifically how to implement their virtual  functions. To do this requires familiarity with such fundamental concepts as the sensitive primitive and the presentable object.  
20
21 The packages used to display 3D objects are the following:  
22   * AIS 
23   * StdPrs 
24   * Prs3d 
25   * PrsMgr 
26   * V3d 
27   * Graphic3d 
28
29 If you are concerned with 2D visualization, you must familiarize yourself  with the fundamental concepts of  presentation as outlined in the section on this subject in chapter Fundamental Concepts.   In brief, the packages used to display 3D objects are  applicable for visualization of 2D objects too. 
30
31 The figure below presents a schematic overview of the relations between the key concepts and packages in visualization. Naturally, "Geometry & Topology" is just an example of application data that can be handled by *AIS*, and application-specific interactive objects can deal with any  kind of data. 
32
33 @image html visualization_image003.png "Key concepts and packages in visualization"
34 @image latex visualization_image003.png "Key concepts and packages in visualization"
35
36 To answer different needs of CASCADE users, this user’s  guide offers the following three paths in reading it. 
37   
38   * If the 3D services proposed in AIS meet your requirements, you  need only read chapter 3 <a href="#occt_visu_3">AIS: Application Interactive Services</a>.   
39   * If you need more detail, for example, a selection filter on another type of entity - you should  read chapter 2 <a href="#occt_visu_2">Fundamental Concepts</a>, chapter 3 <a href="#occt_visu_3">AIS: Application Interactive Services</a>, and possibly chapters 4 and 5 <a href="#occt_visu_4">3D Presentations</a> and  <a href="#occt_visu_5">3D Resources</a>. You may want to begin with the chapter presenting AIS. 
40
41 @section occt_visu_2  Fundamental Concepts
42
43 @subsection occt_visu_2_1 Presentation 
44
45 In Open CASCADE Technology, presentation services are  separated from the data, which they represent, which is generated by  applicative algorithms.  This division allows you to modify a geometric or topological   algorithm and its resulting objects without modifying the visualization  services.  
46
47 @subsubsection occt_visu_2_1_1 Structure of  the Presentation
48
49 Displaying an object on the screen involves three kinds of entities:  
50   * a presentable object, the *AIS_InteractiveObject*
51   * a viewer 
52   * an interactive context, the *AIS_InteractiveContext*. 
53
54 <h4>The presentable object </h4>
55 The purpose of a presentable object is to provide the  graphical representation of an object in the form of *Graphic3d* structure. On  the first display request, it creates this structure by calling the appropriate  algorithm and retaining this framework for further display.  
56
57 Standard presentation algorithms are provided in the *StdPrs*  and *Prs3d* packages. You can, however, write specific presentation algorithms of  your own, provided that they create presentations made of structures from the *Graphic3d* packages. You can also create several presentations of a single  presentable object: one for each visualization mode supported by your  application.  
58
59 Each object to be presented individually must be presentable  or associated with a presentable object. 
60
61 <h4>The viewer </h4>
62 The viewer allows interactively manipulating views of  the object. When you zoom, translate or rotate a view, the viewer operates on  the graphic structure created by the presentable object and not on the data  model of the application. Creating Graphic3d structures in your presentation  algorithms allows you to use the 3D viewers provided in Open CASCADE Technology for 3D visualisation.  
63
64 <h4>The Interactive Context </h4>
65 The  interactive context controls the entire presentation process from a common  high-level API. When the application requests the display of an object, the  interactive context requests the graphic structure from the presentable object  and sends it to the viewer for displaying. 
66
67 @subsubsection occt_visu_2_1_2 Presentation packages
68
69 Presentation involves at least the *AIS, PrsMgr, StdPrs* and  *V3d* packages. Additional packages such as *Prs3d* and *Graphic3d* may be used if  you need to implement your own presentation algorithms.  
70 * *AIS* package provides all  classes to implement interactive objects (presentable and selectable entities).  
71 * *PrsMgr* package  provides all the classes needed to implement the presentation process: the *Presentation*  and *PresentableObject* abstract classes and *PresentationManager3d* concrete class.  
72 * *StdPrs* package  provides ready-to-use standard presentation algorithms of points, curves and  shapes of the geometry and topology toolkits.  
73 * *V3d* package provides  the services supported by the 3D viewer.  
74 * *Prs3d* package provides  some 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, and so on. 
75 * *Graphic3d* package provides resources to create 3D graphic structures.  
76
77 @subsubsection occt_visu_2_1_3 A Basic Example: How to display a 3D object 
78
79 ~~~~~
80 Void Standard_Real dx  = ...; //Parameters   
81 Void Standard_Real dy  = ...; //to build  a wedge  
82 Void Standard_Real dz  = ...;  
83 Void Standard_Real ltx = ...; 
84
85 Handle(V3d_Viewer)aViewer = ...;  
86 Handle(AIS_InteractiveContext)aContext;  
87 aContext = new AIS_InteractiveContext(aViewer);     
88
89 BRepPrimAPI_MakeWedge w(dx, dy, dz, ltx);  
90 TopoDS_Solid & = w.Solid();  
91 Handle(AIS_Shape) anAis = new AIS_Shape(S);  
92 //creation of the presentable  object  
93 aContext - Display(anAis);  
94 //Display the presentable  object in the 3d viewer. 
95 ~~~~~
96
97 The shape is created using the *BRepPrimAPI_MakeWedge*  command. An *AIS_Shape* is then created from the shape. When calling the *Display* command, the interactive context calls the Compute method of the  presentable object to calculate the presentation data and transfer it to the  viewer. See figure below.  
98
99 @image html visualization_image004.png "Processes involved in displaying a presentable shape"
100 @image latex visualization_image004.png "Processes involved in displaying a presentable shape"
101
102 @subsection occt_visu_2_2 Selection 
103
104 Objects that may be selected graphically, are displayed as sets of sensitive primitives, which provide sensitive zones in 2D graphic space. These zones are sorted according to their position on the screen when starting the selection process.  
105   
106 @image html visualization_image006.png "A model"  
107 @image latex visualization_image006.png "A model"  
108
109 The position of the mouse is also associated with a sensitive zone. When moving within the window where objects are displayed, the areas touched by the zone of the mouse are analyzed. The owners of these areas  are then highlighted or signaled by other means such as the name of the object highlighted in a list. That way, you are informed of the identity of the detected element.  
110
111 @image html visualization_image007.png "Modeling faces with sensitive primitives"
112 @image latex visualization_image007.png "Modeling faces with sensitive primitives"
113
114 @image html visualization_image008.png "In a dynamic selection, each sensitive polygon is represented by its  bounding rectangle"   
115 @image latex visualization_image008.png "In a dynamic selection, each sensitive polygon is represented by its  bounding rectangle"
116
117 @image html visualization_image009.png "Reference to the sensitive primitive, then to the owner"
118 @image latex visualization_image009.png "Reference to the sensitive primitive, then to the owner"
119
120
121 @subsubsection occt_visu_2_2_1 The Sensitive Primitive  
122
123 The sensitive primitive along with the entity owner allows defining what can be made selectable, and providing the link between the applicative object and the sensitive zones defined by the 2D bounding boxes. To be dynamically selectable, an object has to be  represented either as a sensitive primitive or a set of them, e.g. 2D  boxes that will be included in a sorting algorithm.
124
125 The use of 2D boxes allows a pre-selection of the detected  entities. After pre-selection, the algorithm checks which sensitive primitives are actually detected. When detected, the primitives provide their owners’ identity.
126
127 @image html visualization_image010.png "Example of sensitive primitives"
128 @image latex visualization_image010.png "Example of sensitive primitives"  
129
130 In the example, the sensitive line segment proposes a bounding box to the selector. During selection, positions 1 and 2 of the mouse detect the box  but after sorting, only position 2 retains the line segment as selected by the  algorithm.  
131
132 When the Box associated with the position of the mouse intersects the Box of a sensitive primitive, the owner of the sensitive  primitive is called and its presentation is highlighted.  
133
134 The notion of sensitive primitive is important for the developer when defining his own classes of sensitive primitives for the chosen selection modes. The classes must contain *Areas* and *Matches*  functions. 
135
136 The former provides the list of 2D sensitive boxes representing the sensitive primitive at pre-selection and the latter determines if the detection of the primitive by the 2D boxes is valid. 
137
138
139 @subsubsection occt_visu_2_2_2 Dynamic Selection 
140
141 Dynamic selection causes objects in a view to be  automatically highlighted 
142 as the mouse cursor moves over them. This allows the  user to be certain that the picked object
143  is the correct one. Dynamic Selection  is based on the following two concepts:  
144
145   * a Selectable Object (*AIS_InteractiveObject*) 
146   * an Interactive Context
147   
148 <h4>Selectable Object</h4>
149
150 A selectable object presents a given number of selection  modes which can be redefined, and which will be activated or deactivated in the selection manager’s selectors.  
151
152 Note that the selection mode of a selectable object, can refer to the selection mode of  the object itself or to the selection mode of its part.
153
154 For each selection mode, a *SelectMgr_Selection* object  class is included in the selectable object. (Each selection mode establishes a  priority of selection for each class of selectable object defined.)  
155
156 The notion of **Selection** is comparable to the notion of **Display**.  Just as a display contains a set of graphic primitives that allow display of  the entity in a specific display mode, a **Selection** contains a set of sensitive  primitives, which allow detection of the entities they are associated with.  
157
158 <h4>Interactive Context</h4>
159
160 The interactive context is used to manage both selectable  objects and selection processes.  
161
162 Selection modes may be activated or de-activated for given  selectable objects. Information is then provided about the status of  activated/de-activated selection modes for a given object in a given selector. 
163
164 See also <a href="#occt_visu_3">AIS: Application Interactive Services</a>.
165
166 Let us consider, for example, a 3D selectable shape object, which  corresponds to a topological shape.  
167
168 For this class, seven selection modes can be defined:  
169 * mode 0 - selection of the shape itself  
170 * mode 1 - selection of vertices  
171 * mode 2 - selection of edges  
172 * mode 3 - selection of wires  
173 * mode 4 - selection of faces  
174 * mode 5 - selection of shells  
175 * mode 6 - selection of solids  
176 * mode 7 - selection of compsolids 
177 * mode 8 - selection of compounds  
178
179 Selection 2 includes the sensitive primitives that model all  the edges of the shape. Each of these primitives contains a reference to the  edge it represents.  
180
181 The selections may be calculated before any activation and  are graph independent as long as they are not activated in a given selector.  Activation of selection mode 3 in a selector associated with a view V leads to  the projection of the 3D sensitive primitives contained in the selection; then  the 2D areas which represent the 2D bounding boxes of these primitives are  provided to the sorting process of the selector containing all the detectable  areas.  
182
183 To deactivate selection mode 3 remove all those 2D areas. 
184
185
186 @subsubsection occt_visu_2_2_3  Selection Packages
187
188 The following selection packages exist : *SelectBasics*,  *SelectMgr*, *Select3D*, *StdSelect*.  
189
190 *SelectBasics* package contains the basic classes  of the selection:  
191   * the main definition of a sensitive primitive: *SensitiveEntity* 
192   * the definition of a sensitive primitive owner: *EntityOwner* 
193   * the algorithm used for sorting sensitive boxes: *SortAlgo* 
194
195 *EntityOwner* is used to establish a link from *SensitiveEntity*  to application-level objects. For example, *SelectMgr_EntityOwner* (see  below) class holds a pointer to corresponding *SelectableObject*. 
196
197 *SelectMgr* package is used to manage the whole  dynamic selection process. It contains the *SelectableObject*, Entity  Owner containing a link to its SelectableObject,* *Selection*, *SelectionManager*,  and *ViewSelector* classes.  
198 There are also implementations of *ViewerSelector*  interface for 3D selection in *StdSelect* package: *ViewerSelector3d*. 
199
200 *Select3D* package contains all 3D standard  sensitive primitives such as point, curve and face. All these classes inherit  from 3D *SensitiveEntry* from *SelectBasics* with an additional  method, which allows recovery of the bounding boxes in the 2D graphic selection  space, if required. This package also includes the 3D-2D projector.  
201
202 *StdSelect* package provides standard uses of the  classes described above and main tools used to prevent the developer from  redefining the selection objects. In particular, *StdSelect* includes  standard means for selection of topological objects (shapes). 
203
204 @subsubsection occt_visu_2_2_4 How to use dynamic selection
205
206 Several operations must be performed prior to using dynamic  selection:  
207 1. Implement specific sensitive primitives  if those defined in Select3D are not sufficient. These primitives must inherit  from *SensitiveEntity* from *SelectBasics* or from a suitable Select3D  sensitive entity class when a projection from 3D to 2D is necessary.  
208 2. Define all the owner types, which will  be used, and the classes of selectable objects, i.e. the number of possible  selection modes for these objects and the calculation of the decomposition of  the object into sensitive primitives of all the primitives describing this  mode. It is possible to define only one default selection mode for a selectable  object if this object is to be selectable in a unique way.  
209 3. Install the process, which provides the  user with the identity of the owner of the detected entities in the selection  loop.  
210
211 When all these steps have been carried out, follow the  procedure below:  
212 1. Create an interactive context.  
213 2. Create the selectable objects and  calculate their various possible selections.  
214 3. Load these selectable objects in the  interactive context. The objects may be common to all the selectors, i.e. they  will be seen by all the selectors in the selection manager, or local to one  selector or more.  
215 4. Activate or deactivate the objects’ selection modes in  the selector(s). When activating a selection mode in a selector for a given  object, the manager sends the order to make the sensitive primitives in this  selector selectable. If the primitives are to projected from 3D to 2D, the  selector calls the specific method used to carry out this projection.  
216
217 At this stage, the selection of selectable entities in the  selectors is available.  
218 The selection loop informs constantly the selectors with the  position of the mouse and questions them about the detected entities.  
219
220 Let us suppose that you create an application that displays  houses in a viewer of the V3d package and you want to select houses or parts of  these houses (windows, doors, etc.) in the graphic window.  
221 You define a selectable object called *House* and  propose four possible selection modes for this object:  
222 1. selection of the house itself; 
223 2. selection of the rooms  
224 3. selection of the walls  
225 4. selection of the doors.  
226
227 You have to write the method, which calculates the four  selections above, i.e. the sensitive primitives which are activated when the  mode is.  
228 You must define the class *Owner* specific to your  application. This class will contain the reference to the house element it  represents: wall, door or room. It inherits from *EntityOwner* from *SelectMgr*.   
229 For example, let us consider a house with the following  representation:  
230
231 @image html visualization_image011.png "Selection of rooms in a house"
232 @image latex visualization_image011.png "Selection of rooms in a house"
233
234 To build the selection, which corresponds to the mode "selection  of the rooms" 
235 (selection 2 in the list of selection modes), use the following  procedure:  
236
237 ~~~~~
238
239 Void House::ComputeSelection 
240         (Const  Handle(SelectMgr_Selection)& Sel, 
241          const Standard_Integer mode { 
242                  switch(mode){   case 0: //Selection of the rooms  
243                 {   for(Standard_Integer i = 1; i = myNbRooms; i++)   { //for every room, create an instance of the owner, the given room  and its name. 
244                 Handle(RoomOwner) aRoomOwner = new RoomOwner (Room(i),  NameRoom(i)); //Room() returns a room and NameRoom() returns its name.  
245         Handle(Select3d_SensitiveBox) aSensitiveBox; 
246         aSensitiveBox = new Select3d_SensitiveBox  
247                 (aRoomOwner, Xmin, Ymin, Zmin,  Xmax, Ymax, Zmax); 
248                  Sel - Add(aSensitiveBox);   }   break;   Case 1: ... //Selection of the doors   } //Switch     
249 ) // ComputeSelection  
250 ~~~~~
251
252 @image html visualization_image012.png "Activated sensitive boxes  corresponding to selection mode 0 (selection of rooms)"
253 @image latex visualization_image012.png "Activated sensitive boxes  corresponding to selection mode 0 (selection of rooms)"
254
255 @image html visualization_image013.png "Activated sensitive rectangles in the selector during dynamic selection in view 1"
256 @image latex visualization_image013.png "Activated sensitive rectangles in the selector during dynamic selection in view 1"
257
258 @image html visualization_image014.png "Activated sensitive polygons corresponding  to selection mode 1 (selection of doors)"
259 @image latex visualization_image014.png "Activated sensitive polygons corresponding  to selection mode 1 (selection of doors)"
260
261 @image html visualization_image015.png "Sensitive rectangles in the selector during  dynamic selection in view 2"
262 @image latex visualization_image015.png "Sensitive rectangles in the selector during  dynamic selection in view 2"
263
264 @section occt_visu_3 Application Interactive Services 
265 @subsection occt_visu_3_1 Introduction 
266
267 Application Interactive Services allow managing presentations and dynamic selection in a viewer in a simple and  transparent manner. 
268
269 The central entity for management of visualization and selections is the **Interactive Context**. It is connected to the main viewer (and if  need be, the trash bin viewer). It has two operating modes: the Neutral Point and  the local visualization and selection context. 
270
271 The neutral point, which is the  default mode, allows easily visualizing and selecting interactive objects loaded into the context. 
272
273 **Local Contexts** can be opened to prepare and use a temporary selection environment without disturbing
274 the neutral point. It is possible to choose the interactive objects, which you want to act on, the selection modes, which you want to activate, and the temporary visualizations, which you will execute. 
275
276 When the operation is finished, you close the current local context and return to the state 
277 in which you were before opening it (neutral point or previous local context).  
278
279 **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.  
280
281 @image html visualization_image016.png 
282 @image latex visualization_image016.png 
283
284 An Interactive Object is a "virtual" entity, which can be  presented and selected. An Interactive Object can have a certain number of specific graphic attributes, such as visualization mode, color and  material. 
285
286 When an Interactive Object is visualized, the required graphic attributes are taken from its own **Drawer** if it has the required custom attributes or otherwise from the context drawer. 
287
288 @image html visualization_image017.png 
289 @image latex visualization_image017.png 
290
291 It can be necessary to filter the entities to be selected. Consequently there are **Filter** entities, which allow refining the dynamic detection context.  Some of these filters can be used at the Neutral Point, others only in an open local context. It is possible to program custom filters and load them into the interactive context.  
292
293 @subsection occt_visu_3_2 Interactive objects
294
295 @subsubsection occt_visu_3_2_1 Presentations
296
297 An interactive object can have as many  presentations as its creator wants to give it. 
298
299 3D presentations are managed by PresentationManager3D. As this is  transparent in AIS, the user does not have to worry about it. 
300
301 A presentation is identified by an index and by the reference to  the Presentation Manager which it depends on. 
302
303 By convention, the default mode of  representation for the Interactive Object has index 0. 
304
305 @image html visualization_image018.png 
306 @image latex visualization_image018.png 
307
308 Calculation of different presentations of an interactive  object is done by the *Compute* functions inheriting from *PrsMgr_  PresentableObject::Compute* functions. They are automatically called by *PresentationManager*  at a visualization or an update request.  
309
310 If you are creating your own type of interactive object, you  must implement the Compute function in one of the following ways:  
311
312 #### For 3D:
313
314 ~~~~~
315 void PackageName_ClassName::Compute  
316         (const  Handle(PrsMgr_PresentationManager3d)& aPresentationManager,   
317          const  Handle(Prs3d_Presentation)& aPresentation,  
318          const Standard_Integer aMode =  0);  
319 ~~~~~
320
321 ####  For hidden line removal (HLR) mode in 3D:
322 ~~~~~
323 void PackageName_ClassName::Compute  
324         (const  Handle(Prs3d_Projector)& aProjector,  
325          const  Handle(Prs3d_Presentation)& aPresentation);  
326 ~~~~~
327
328 @subsubsection occt_visu_3_2_2 Hidden Line Removal
329
330 The view can have two states: the normal mode or the computed  mode (Hidden Line Removal mode). When the latter is active, the view looks for all presentations displayed in the normal mode, which have been signalled  as accepting HLR mode. An internal mechanism allows calling the interactive  object’s own *Compute*, that is projector function. 
331
332 By  convention, the Interactive Object accepts or rejects the  representation of HLR mode. It is possible to make this declaration in one of two ways:
333
334 * Initially by using one of the values of the enumeration  *PrsMgr_TypeOfPresentation*: 
335   * *PrsMgr_TOP_AllView*,
336   * *PrsMgr_TOP_ProjectorDependant*
337
338 * Later by using the function *PrsMgr_PresentableObject::SetTypeOfPresentation* 
339
340 *AIS_Shape* class is an example of an interactive object that supports  HLR representation. It supports two types of the HLR algorithm:  
341 * the  polygonal algorithm based on the shape’s triangulation; 
342 * the  exact algorithm that works with the shape’s real geometry. 
343
344 The type of the HLR algorithm is stored in *AIS_Drawer* of the  shape. It is a value of the *Prs3d_TypeOfHLR* enumeration and can be set to: 
345         * *Prs3d_TOH_PolyAlgo* for a polygonal algorithm; 
346         * *Prs3d_TOH_Algo*  for an exact algorithm; 
347         * *Prs3d_TOH_NotSet*  if the type of algorithm is not set for the given interactive object instance. 
348
349 The type of the HLR algorithm used for *AIS_Shape* can be changed by calling the *AIS_Shape::SetTypeOfHLR()* method. 
350
351 The current  HLR algorithm type can be obtained using *AIS_Shape::TypeOfHLR()* method  is to be used. 
352
353 These methods get the  value from the drawer of *AIS_Shape*. If the HLR algorithm type in the *AIS_Drawer* is set to *Prs3d_TOH_NotSet*, the *AIS_Drawer* gets the value from the default  drawer of *AIS_InteractiveContext*.
354
355 So it is possible to change the default HLR algorithm used by all newly displayed interactive objects. The  value of the HLR algorithm type stored in the context drawer can be *Prs3d_TOH_Algo* or *Prs3d_TOH_PolyAlgo*. The polygonal algorithm is the default one. 
356
357 @subsubsection occt_visu_3_2_3 Presentation modes
358
359 There are four types of interactive objects in AIS:  
360   * the "construction element" or Datum, 
361   * the Relation (dimensions and constraints) 
362   * the Object 
363   * the None type (when the object is  of an unknown type). 
364
365 Inside these categories, additional characterization is  available by means of a signature (an index.) By default, the interactive  object has a NONE type and a signature of 0 (equivalent to NONE.) If you want  to give a particular type and signature to your interactive object, you must  redefine two virtual functions:  
366   * *AIS_InteractiveObject::Type*  
367   * *AIS_InteractiveObject::Signature*.  
368
369 **Note** that some signatures are already used by "standard" objects provided in AIS (see the <a href="#occt_visu_3_5">list of Standard Interactive Object Classes</a>).  
370
371 The interactive context can have a  default mode of representation for the set of interactive objects. This mode  may not be accepted by a given class of objects. 
372
373 Consequently, to get information about this class it is necessary to use virtual  function *AIS_InteractiveObject::AcceptDisplayMode*.  
374
375 #### Display Mode
376
377 The functions *AIS_InteractiveContext::SetDisplayMode* and *AIS_InteractiveContext::UnsetDisplayMode* allow setting a custom display mode for an objects, which can be different from that proposed by the interactive context.
378
379 #### Highlight Mode
380
381 At dynamic detection, the presentation echoed  by the Interactive Context, is by default the presentation already on the screen. 
382
383 The functions  *AIS_InteractiveObject::SetHilightMode* and *AIS_InteractiveObject::UnSetHilightMode* allow specifying the display mode used for highlighting (so called highlight mode), which is valid independently from the active  representation of the object. It makes no difference whether this choice is  temporary or definitive. 
384
385 Note that the same presentation (and consequently the same  highlight mode) is used for highlighting *detected* objects and for  highlighting *selected* objects, the latter being drawn with a special *selection  color* (refer to the section related to *Interactive Context*  services). 
386
387 For example, you want to systematically highlight  the wireframe presentation of a shape - non regarding if it is visualized in  wireframe presentation or with shading. Thus, you set the highlight mode to *0* in the constructor of the interactive object. Do not forget to implement this representation mode in the *Compute* functions.  
388
389 #### Infinite Status
390 If you don’t 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. 
391
392 Let us take for example the class called *IShape* representing  an interactive object :
393
394 ~~~~~ 
395 myPk_IShape::myPK_IShape  
396         (const TopoDS_Shape& SH,  PrsMgr_TypeOfPresentation aType):  
397         AIS_InteractiveObject(aType), myShape(SH), myDrwr(new AIS_Drawer())  {SetHilightMode(0);}   
398 void myPk_IShape::Compute  
399         (const Handle(PrsMgr_PresentationManager3d)  & PM,  
400          const Handle(Prs3d_Presentation)& P,   
401          const Standard_Integer TheMode) 
402
403         switch (TheMode){  
404         case 0: 
405         StdPrs_WFDeflectionShape::Add  (P,myShape,myDrwr);  //algo for  calculation of wireframe presentation break;  
406         case 1: 
407         StdPrs_ShadedShape::Add  (P,myShape,myDrwr);   //algo for calculation of shading presentation.  
408         break; 
409         }  
410 }  
411 void myPk_IsShape::Compute  
412         (const  Handle(Prs3d_Projector)& Prj,  
413         const  Handle(Prs3d_Presentation) P)  
414
415         StdPrs_HLRPolyShape::Add(P,myShape,myDrwr); 
416         //Hidden line mode calculation algorithm  
417 }  
418 ~~~~~
419
420 @subsubsection occt_visu_3_2_4 Selection 
421
422 An interactive object can have an indefinite number of selection modes, each representing a "decomposition" into sensitive primitives;  each primitive has an Owner (*SelectMgr_EntityOwner*) which allows identifying the exact entity which has been detected (see <a href="#occt_visu_3_6"> Dynamic Selection</a> chapter).  
423
424 The set of sensitive primitives, which correspond to a given  mode, is stocked in a SELECTION (*SelectMgr_Selection*). 
425
426 Each Selection mode is identified by an index. By  Convention, the default selection mode that allows us to grasp the Interactive  object in its entirety is mode *0*.  
427
428 The calculation of Selection primitives (or sensitive  primitives) is done by the intermediary of a virtual function, *ComputeSelection*.  This should be implemented for each type of interactive object on which you  want to make different type selections using the function *AIS_ConnectedInteractive::ComputeSelection*.  
429
430 A detailed explanation of the mechanism and the manner of  implementing this function has been given in <a href="#occt_visu_3_6"> Dynamic Selection</a> chapter.  
431
432 Moreover, just as the most frequently manipulated entity is *TopoDS_Shape*, the most used Interactive Object is *AIS_Shape*. You will see below activation functions for standard selection modes are proposed in the  Interactive context (selection by vertex, by edges etc). To create new classes  of interactive object with the same behavior as *AIS_Shape* - such as vertices  and edges - you must redefine the virtual function *AIS_ConnectedInteractive::AcceptShapeDecomposition*.  
433
434 You can change the default selection mode index of an  Interactive Object using the following functions: 
435   * *AIS_InteractiveObject::HasSelectionMode* checks if there is a selection mode; 
436   * *AIS_InteractiveObject::SelectionMode* check the current selection mode; 
437   * *AIS_InteractiveContext::SetSelectionMode* sets a selection mode; 
438   * *AIS_InteractiveContext::UnsetSelectionMode* unsets a selection mode.
439   
440 These functions can be useful if you decide that the *0*  mode used by default will not do. In the same way, you can temporarily  change the priority of certain interactive objects for selection of 0 mode to facilitate detecting them graphically using the following functions: 
441   * *AIS_InteractiveObject::HasSelectionPriority* checks if there is a selection priority setting for the  owner; 
442   * *AIS_InteractiveObject::SelectionPriority* checks the current priority; 
443   * *AIS_InteractiveObject::SetSelectionPriority* sets a priority; 
444   * *AIS_InteractiveObject::UnsetSelectionPriority* unsets the priority.
445   
446     
447 @subsubsection occt_visu_3_2_5 Graphic attributes
448
449 Keep  in mind the following points concerning graphic attributes:  
450   * Each interactive object can have its own visualization  attributes.
451   * 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 
452   * 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.) 
453   * 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. 
454
455
456 @image html visualization_image019.png "Figure 13. Redefinition of virtual functions for changes in AIS_Point"
457 @image latex visualization_image019.png "Figure 13. Redefinition of virtual functions for changes in AIS_Point"
458
459 @image html visualization_image020.png "Figure 14. Redefinition of virtual functions for changes in AIS_Shape."
460 @image latex visualization_image020.png "Figure 14. Redefinition of virtual functions for changes in AIS_Shape."
461
462 The  following virtual functions provide settings for color, width, material and transparency:  
463   * *AIS_InteractiveObject::UnsetColor* 
464   * *AIS_InteractiveObject::SetWidth* 
465   * *AIS_InteractiveObject::UnsetWidth* 
466   * *AIS_InteractiveObject::SetMaterial   (const Graphic3d_NameOfPhysicalMaterial & aName)* 
467   * *AIS_InteractiveObject::SetMaterial   (const Graphic3d_MaterialAspect & aMat)* 
468   * *AIS_InteractiveObject::UnsetMaterial* 
469   * *AIS_InteractiveObject::SetTransparency* 
470   * *AIS_InteractiveObject::UnsetTransparency* 
471
472 For other types of attribute, it is  appropriate to change the Drawer of the object directly using:  
473   * *AIS_InteractiveObject::SetAttributes*
474   * *AIS_InteractiveObject::UnsetAttributes*
475
476 It is important to know which functions may imply the recalculation of  presentations of the object. 
477
478 If the presentation mode of an interactive object is to be updated, a flag from *PrsMgr_PresentableObject*  indicates this. 
479
480 The mode can be updated using the functions *Display*  and *Redisplay* in *AIS_InteractiveContext*.  
481
482 @subsubsection occt_visu_3_2_6 Complementary  Services
483
484 When you use complementary services for interactive objects, pay special attention to the cases mentioned below. 
485
486 #### Change the location of an interactive object
487
488 The following functions  allow temporarily "moving" the representation and selection of  Interactive Objects in a view without recalculation.  
489   * *AIS_InteractiveContext::SetLocation*  
490   * *AIS_InteractiveContext::ResetLocation*  
491   * *AIS_InteractiveContext::HasLocation*  
492   * *AIS_InteractiveContext::Location*  
493  
494 #### Connect an interactive object to an applicative  entity
495
496 Each Interactive Object has functions that allow attributing it an *Owner* in form of a *Transient*.  
497   * *AIS_InteractiveObject::SetOwner*  
498   * *AIS_InteractiveObject::HasOwner*  
499   * *AIS_InteractiveObject::Owner*  
500
501 An interactive object can therefore be associated or not with an applicative entity, without affecting its behavior. 
502
503 #### Resolving coincident topology
504
505 Due to the fact that the accuracy of three-dimensional  graphics coordinates has a finite resolution the elements of topological  objects can coincide producing the effect of "popping" some elements one over  another. 
506
507 To the problem when the elements of two or  more Interactive Objects are coincident you can apply the polygon offset. It is a  sort of graphics computational offset, or depth buffer offset, that allows you  to arrange elements (by modifying their depth value) without changing their  coordinates. The graphical elements that accept this kind of offsets are solid  polygons or displayed as boundary lines and points. The polygons could be  displayed as lines or points by setting the appropriate interior style. 
508
509 The method *AIS_InteractiveObject::SetPolygonOffsets (const Standard_Integer aMode, const Standard_Real aFactor, const Standard_Real aUnits)* allows setting up the polygon  offsets.
510
511 The  parameter *aMode* can contain various combinations of *Aspect_PolygonOffsetMode* enumeration elements: 
512   * *Aspect_POM_None*
513   * *Aspect_POM_Off*
514   * Aspect_POM_Fill
515   * Aspect_POM_Line
516   * Aspect_POM_Point
517   * Aspect_POM_All
518
519 The combination  of these elements defines the polygon display modes that will use the given  offsets. You can switch off the polygon offsets by passing *Aspect_POM_Off*.  Passing *Aspect_POM_None* allows changing the *aFactor* and *aUnits* values  without changing the mode. If *aMode* is different from *Aspect_POM_Off*, the  *aFactor* and *aUnits* arguments are used by the graphics renderer to calculate the  depth offset value: 
520 ~~~~~
521  offset  = aFactor * m + aUnits * r
522 ~~~~~
523 where  *m* is the maximum depth slope for the currently displayed polygons, r is the minimum  depth resolution (implementation-specific). 
524
525 Negative  offset values move polygons closer to the viewer while positive values shift  polygons away. 
526
527 **Warning**
528  
529 This  method has a side effect – it creates its own shading aspect if not yet  created, so it is better to set up the object shading aspect first. 
530
531 You can use the following  functions to obtain the current settings for polygon offsets: 
532 ~~~~~
533   void  AIS_InteractiveObject::PolygonOffsets
534                 (Standard_Integer &aMode, 
535                  Standard_Real &aFactor, 
536                  Standard_Real &aUnits) 
537   Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() 
538 ~~~~~
539
540 The same  operation could be performed for the interactive object known by the *AIS_InteractiveContext* with the following methods: 
541 ~~~~~
542 void  AIS_InteractiveContext::SetPolygonOffsets
543         (const Handle(AIS_InteractiveObject) &anObj, 
544          const Standard_Integer aMode,  
545          const Standard_Real aFactor, 
546          const Standard_Real aUnits) 
547 void  AIS_InteractiveContext::PolygonOffsets
548         (const Handle(AIS_InteractiveObject) &anObj, 
549          Standard_Integer &aMode,  
550          Standard_Real &aFactor, 
551          Standard_Real &aUnits) 
552 Standard_Boolean      AIS_InteractiveContext::HasPolygonOffsets
553         (const Handle(AIS_InteractiveObject) &anObj) 
554 ~~~~~
555
556 @subsection occt_visu_3_3 Interactive Context 
557
558 @subsubsection occt_visu_3_3_1 Rules 
559
560 The Interactive Context allows us to manage in a transparent  way, the graphic and "selectable" behavior of interactive objects in one or  more viewers. Most functions which allow us to modify the attributes of  interactive objects, and which were presented in the preceding chapter, will be  looked at again here.  
561
562 There is one essential rule to follow: the modification of  an interactive object, which is already known by the Context, must be done  using Context functions. You can only directly call the functions available for  an interactive object if it has not been loaded into an Interactive Context.  
563
564 ~~~~~
565 Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);  
566         myIntContext-Display(TheAISShape);  
567         myIntContext-SetDisplayMode(TheAISShape ,1);  
568         myIntContext-SetColor(TheAISShape,Quantity_NOC_RED);  
569 ~~~~~
570
571 You can also write  
572
573 ~~~~~
574 Handle (AIS_Shape) TheAISShape = new AIS_Shape (ashape);  
575         TheAISShape-SetColor(Quantity_NOC_RED);  
576         TheAISShape-SetDisplayMode(1);  
577         myIntContext-Display(TheAISShape);  
578 ~~~~~
579
580 @subsubsection occt_visu_3_3_2 Groups of functions 
581
582 You must distinguish two states in the Interactive Context:  
583 *  No Open Local Context; which will be referred to as Neutral  Point.  
584 *  One or several open local contexts, each representing a temporary  state of selection and presentation.  
585
586 Some functions can only be used in open Local Context;  others in closed local context; others do not have the same behavior in one  state as in the other.  
587
588 The Interactive Context is composed of many  functions, which can be conveniently grouped according to the theme:  
589   * management proper to the context; 
590   * management in the local context; 
591   * presentations and selection in open/closed context; 
592   * selection strictly speaking. 
593
594
595 @subsubsection occt_visu_3_3_3 Management of the Interactive Context 
596
597 The Interactive Context is made up of a Principal Viewer  and, optionally, a trash bin or "Collector" Viewer. It also has a group of  adjustable settings allowing you to personalize the behavior of presentations  and selections:  
598   * Default Drawer, containing all the color and line attributes  which can be used by interactive objects, which do not have their own  attributes. 
599   * Default Visualization Mode for interactive objects.  By default: *mode  0* ;  
600   * Highlight color of entities detected by mouse movement. By default: *Quantity_NOC_CYAN1*;  
601   * Pre-selection color. By default:  *Quantity_NOC_GREEN*;  
602   * Selection color (when you click on a detected object). By default:  *Quantity_NOC_GRAY80*;  
603   * Sub-Intensity color. By default:  *Quantity_NOC_GRAY40*.  
604
605 All of these settings can be modified by functions proper to  the Context.  
606
607 When you change a graphic attribute pertaining to the  Context (visualization mode, for example), all interactive objects, which do  not have the corresponding appropriate attribute, are updated.  
608
609 Let us examine the case of two interactive objects: *obj1* and *obj2*:  
610
611 ~~~~~
612 TheCtx-Display(obj1,Standard_False); // False = no viewer update 
613 TheCtx-Display(obj2,Standard_True); // True = viewer update  
614 TheCtx-SetDisplayMode(obj1,3,Standard_False); 
615 TheCtx-SetDisplayMode(2); 
616 // obj2 is visualised in mode 2 (if it accepts this mode) 
617 // obj1 stays visualised in its mode 3.  
618 ~~~~~
619
620 *PresentationManager3D*  and a *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. 
621
622 @subsection occt_visu_3_4 Local Context 
623 @subsubsection occt_visu_3_4_1 Rules and Conventions 
624
625   * Opening a local context allows preparing an environment for  temporary presentations and selections, which will disappear once the local  context is closed. 
626   * It is possible to open several local contexts, but only the last  one will be active. 
627   * 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. 
628   * Each local context has an index created when the context opens. You  should close the local context, which you have opened. 
629
630 The interactive object, which is used the most by  applications, is *AIS_Shape*. Consequently, standard functions are  available which allow you to easily prepare selection operations on the  constituent elements of shapes (selection of vertices, edges, faces etc) in an  open local context. The selection modes specific to "Shape" type objects are  called **Standard Activation Mode**. These modes are only taken into account  in open local context and only act on interactive objects which have redefined  the virtual function *AcceptShapeDecomposition()* so that it returns *TRUE*.   
631   * 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. 
632   * The state of a temporary interactive object in a local context  can only be modified while another local context is open. 
633
634 **Warning**
635
636 The specific modes of selection only concern the interactive  objects, which are present in the Main Viewer. In the Collector, you can only  locate interactive objects, which answer positively to the positioned filters  when a local context is open, however, they are never decomposed in  standard mode.  
637
638 @subsubsection occt_visu_3_4_2 Management of Local Context
639
640 The local context can be opened using method *AIS_InteractiveContext::OpenLocalContext*. The following options are available:
641   * *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. 
642   * *AllowShapeDecomposition*: *AIS_Shape* allows or prevents  decomposition in standard shape location mode of objects at Neutral Point,  which are type-privileged (see <a href="#occt_visu_3_2_4"> Selection</a> chapter). This Flag is only taken  into account when *UseDisplayedObjects* is *TRUE*. 
643   * *AcceptEraseOfObjects*: authorises other local contexts to erase  the interactive objects present in this context. This option is rarely used.  The last option has no current use. 
644
645 This function returns the index of the created local context.  It should be kept and used when the context is closed.  
646
647 To load objects visualized at Neutral Point into a local  context or remove them from it use methods
648 ~~~~~ 
649   AIS_InteractiveContext::UseDisplayedObjects  
650   AIS_InteractiveContext::NotUseDisplayedObjects  
651 ~~~~~
652 Closing Local Contexts is done by:  
653 ~~~~~
654   AIS_InteractiveContext::CloseLocalContext  
655   AIS_InteractiveContext::CloseAllContexts  
656 ~~~~~
657
658 *Warning* 
659 When the index isn’t 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. 
660
661 To get the index of the current context, use function "AIS_InteractiveContext::IndexOfCurrentLocal". It allows closing all open local  contexts at one go. In this case, you find yourself directly at Neutral Point.  
662
663 When you close a local context, all temporary interactive  objects are deleted, all selection modes concerning the context are  cancelled, and all content filters are emptied.  
664
665
666 @subsubsection occt_visu_3_4_3 Presentation in a Neutral Point 
667
668 You must distinguish between the Neutral  Point and the Open Local Context states. Although the majority of visualization  functions can be used in both situations, their behavior is different.
669
670 Neutral Point should be used to visualize the interactive  objects, which represent and select an applicative entity. Visualization and  Erasing orders are straightforward: 
671
672 ~~~~~
673 AIS_InteractiveContext::Display  
674         (const  Handle(AIS_InteractiveObject)& anIobj, 
675          const  Standard_Boolean updateviewer=Standard_True);  
676
677 AIS_InteractiveContext::Display  
678         (const  Handle(AIS_InteractiveObject)& anIobj,  
679          const  Standard_Integer amode, 
680          const  Standard_Integer aSelectionMode, 
681          const  Standard_Boolean updateviewer = Standard_True,  
682          const  Standard_Boolean allowdecomposition =  Standard_True);  
683
684   AIS_InteractiveContext::Erase  
685   AIS_InteractiveContext::EraseMode  
686   AIS_InteractiveContext::ClearPrs  
687   AIS_InteractiveContext::Redisplay  
688   AIS_InteractiveContext::Remove  
689   AIS_InteractiveContext::EraseAll  
690   AIS_InteractiveContext::Hilight  
691   AIS_InteractiveContext::HilightWithColor  
692 ~~~~~
693   
694 Bear in mind the following points:  
695   * It is recommended to display and erase interactive objects when  no local context is opened, and open a local context for local selection only.
696   * 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). 
697   * 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.
698   * 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. 
699   * 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. 
700   * 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. 
701   * *Erase()* with *putInCollector = Standard_True*  might be slow as it computes again the object presentation in the Collector. Set *putInCollector* to *Standard_False* if you simply want to hide the object’s  presentation temporarily.
702   * 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. 
703   * 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.
704
705 @subsubsection occt_visu_3_4_4 Presentation in Local Context 
706
707 In open local context, the *Display* functions presented above can be as well.  
708
709 **WARNING** 
710
711 The function *AIS_InteractiveObject::Display* automatically  activates the object’s default selection mode. When you only want to visualize  an Interactive Object in open Context, you must call the function *AIS_InteractiveContext::Display*.  
712
713 You can activate or deactivate specific selection modes in the local open context in several different ways:  
714 Use the Display functions with the appropriate modes.
715    
716 ~~~~~
717   AIS_InteractiveContext::ActivateStandardMode
718   //can be used only if a  Local Context is opened.   
719   AIS_InteractiveContext::DeactivateStandardMode  
720   AIS_InteractiveContext::ActivatedStandardModes  
721   AIS_InteractiveContext::SetShapeDecomposition  
722 ~~~~~
723
724 This activates the corresponding  selection mode for all objects in Local Context, which accept decomposition  into sub-shapes. Every new Object which has been loaded into the interactive  context and which meets the decomposition criteria is automatically  activated according to these modes.  
725
726 **WARNING**
727
728 If you have opened a local context by loading an object with  the default options *(AllowShapeDecomposition = Standard_True)*, 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)*.  
729
730 Load an interactive object by the function *AIS_InteractiveContext::Load*.  
731
732 This function allows loading an Interactive Object  whether it is visualized or not with a given selection mode, and/or with the necessary decomposition option. If *AllowDecomp=TRUE* and obviously, if the  interactive object is of the "Shape" type, these "standard" selection modes  will be automatically activated as a function of the modes present in the Local  Context.  
733
734 Use *AIS_InteractiveContext::Activate* and *AIS_InteractiveContext::Deactivate* to directly activate/deactivate selection modes on an object.
735
736 @subsubsection occt_visu_3_4_5 Filters 
737
738 When Interactive objects have been "prepared" in the local  context, you can add rejection filters. The root class of objects is *SelectMgr_Filter*.  The principle behind it is straightforward: a filter tests to see whether the  owners *(SelectMgr_EntityOwner)* detected in mouse position by the Local  context selector answer *OK*. If so, it is kept, otherwise it is rejected.  
739
740 You can create a custom class of filter objects by  implementing the deferred function *IsOk()*:  
741
742 ~~~~~
743 class MyFilter : public SelectMgr_Filter { };  
744 virtual Standard_Boolean MyFilter::IsOk  
745         (const Handle(SelectMgr_EntityOwner)&  anObj) const = 0; 
746 ~~~~~
747
748 In *SelectMgr*, there are also Composition filters (AND  Filters, OR Filters), which allow combining several filters. In  InteractiveContext , all filters that you add are stocked in an OR filter  (which answers *OK* if at least one filter answers *OK*).  
749
750 There are Standard filters, which have already been  implemented in several packages:  
751   * *StdSelect_EdgeFilter* - for edges, such as lines and circles;  
752   * *StdSelect_FaceFilter* - for faces, such as planes, cylinders and spheres;  
753   * *StdSelect_ShapeTypeFilter* - for shape types, such as compounds, solids, shells and wires;  
754   * *AIS_TypeFilter* - for types  of interactive objects;  
755   * *AIS_SignatureFilter* - for types  and signatures of interactive objects; 
756   * *AIS_AttributeFilter* - for attributes of Interactive Objects, such as color and width.  
757
758 As there are specific behaviors on shapes, each new  Filter class must, if necessary, redefine *AIS_LocalContext::ActsOn* function, which informs the Local Context if it acts on specific types of sub-shapes.  By default, this  function answers *FALSE*.  
759
760 **WARNING**
761  
762 Only type filters are activated in Neutral Point to  make it possible to identify a specific type of visualized object. For filters to come into play, one or more object selection modes must be activated.  
763
764 There are several functions to manipulate filters:  
765   * *AIS_InteractiveContext::AddFilter* adds a filter passed as an argument.  
766   * *AIS_InteractiveContext::RemoveFilter* removes a filter passed as an argument.  
767   * *AIS_InteractiveContext::RemoveFilters* removes all present filters.  
768   * *AIS_InteractiveContext::Filters* gets the list of filters active in a local context.  
769   
770 <h4>Example </h4>
771
772 ~~~~~
773 myContext-OpenLocalContext(Standard_False);  
774 // no object in neutral point is  loaded  
775
776 myContext-ActivateStandardMode(TopAbs_Face);  
777 //activates decomposition of  shapes into faces.  
778 Handle (AIS_Shape) myAIShape = new AIS_Shape (  ATopoShape);  
779
780 myContext-Display(myAIShape,1,-1,Standard_True,Standard_True);  
781
782 //shading visualization mode,  no specific mode, authorization for //decomposition into sub-shapes. At this  Stage, myAIShape is decomposed into faces...  
783
784 Handle(StdSelect_FaceFilter) Fil1= new  
785         StdSelect_FaceFilter(StdSelect_Revol);   
786 Handle(StdSelect_FaceFilter) Fil2= new 
787       StdSelect_FaceFilter(StdSelect_Plane);  
788
789 myContext-AddFilter(Fil1);   
790 myContext-AddFilter(Fil2);  
791
792 //only faces of revolution or  planar faces will be selected 
793       
794 myContext-MoveTo( xpix,ypix,Vue);  
795 // detects the mouse position  
796 ~~~~~
797
798 @subsubsection occt_visu_3_4_6 Selection in the Local Context
799  
800 Dynamic detection and selection are put into effect in a  straightforward way. There are only a few conventions and functions to be  familiar with. The functions are the same in neutral point and in open local context:   
801   * *AIS_InteractiveContext::MoveTo* - passes  mouse position to Interactive Context selectors  
802   * *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  
803   * *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.  
804   * *AIS_InteractiveContext::Select* selects  everything found in the surrounding area.  
805   * *AIS_InteractiveContext::ShiftSelect* selects  what was not previously in the list of selected, deselects those already present.  
806
807 Highlighting of detected and selected entities is  automatically managed by the Interactive Context, whether you are in neutral  point or Local Context. The Highlight colors are those dealt with above. You  can nonetheless disconnect this automatic mode if you want to manage this part yourself :  
808 ~~~~~
809   AIS_InteractiveContext::SetAutomaticHilight  
810   AIS_InteractiveContext::AutomaticHilight  
811 ~~~~~
812
813 If there is no open local context, the objects selected are called **current objects**. If there is a  local context, they are called **selected objects**. Iterators allow  entities to be recovered in either case. A set of functions allows manipulating the objects, which have been placed in these different lists.  
814
815 **WARNING**
816
817 When a Local Context is open, you can select entities other  than interactive objects (vertices, edges etc.) from decompositions in standard  modes, or from activation in specific modes on specific interactive objects.  Only interactive objects are stocked in the list of selected objects. 
818
819 You can  question the Interactive context by moving the mouse. The following functions can be used:  
820   * *AIS_InteractiveContext::HasDetected* informs if something has been detected; 
821   * *AIS_InteractiveContext::HasDetectedShape* informs if it is a shape; 
822   * *AIS_InteractiveContext::DetectedShape* gets the shape if the detected entity is an object;
823   * *AIS_InteractiveContext::DetectedInteractive* gets the interactive object if the detected entity is an object. 
824
825 After using the *Select* and *ShiftSelect* functions in Neutral Point, you can explore the list of selections, referred to as current objects  in this context. The following functions can be used:    
826   * *AIS_InteractiveContext::InitCurrent* initiates a scan of this list; 
827   * *AIS_InteractiveContext::MoreCurrent* extends the scan; 
828   * *AIS_InteractiveContext::NextCurrent* resumes the scan; 
829   * *AIS_InteractiveContext::Current* gets the name of the current object  detected in the scan; 
830   * *AIS_InteractiveContext::FirstCurrentObject* gets the first current interactive object; 
831   * *AIS_InteractiveContext::HilightCurrents* highlights current objects; 
832   * *AIS_InteractiveContext::UnhilightCurrents* removes highlight from current objects; 
833   * *AIS_InteractiveContext::ClearCurrents* empties the list of current objects in order to update it; 
834   * *AIS_InteractiveContext::IsCurrent* finds the current object. 
835
836 In the Local Context, you can explore the list of selected  objects available. The following functions can be used:    
837   * *AIS_InteractiveContext::InitSelected* initiates the list of objects; 
838   * *AIS_InteractiveContext::MoreSelected* extends the list of objects; 
839   * *AIS_InteractiveContext::NextSelected* resumes a scan;
840   * *AIS_InteractiveContext::SelectedShape* gets the name of the selected object; 
841   * *AIS_InteractiveContext::HasSelectedShape* checks if the selected shape is obtained; 
842   * *AIS_InteractiveContext::Interactive* gets the picked interactive object; 
843   * *AIS_InteractiveContext::HasApplicative* checks if the applicative object has an owner from  Interactive attributed to it; 
844   * *AIS_InteractiveContext::Applicative* gets the owner of the detected applicative entity; 
845   * *AIS_InteractiveContext::IsSelected* gets the name of the selected object. 
846
847
848 <h4>Example </h4>
849 ~~~~~
850 myAISCtx-InitSelected();  
851 while (myAISCtx-MoreSelected())  
852         { 
853         if  (myAISCtx-HasSelectedShape) 
854                 { 
855                 TopoDS_Shape  ashape = myAISCtx-SelectedShape(); 
856                         // to be able  to use the picked shape 
857                                     }  
858                 else  
859                 { 
860                 Handle_AIS_InteractiveObject  aniobj = myAISCtx-Interactive(); 
861                 // to be able to use the picked interactive object  
862                 }  
863 myAISCtx-NextSelected();  
864 }     
865 ~~~~~
866
867 You have to ask whether you have selected a shape  or an interactive object before you can recover the entity in the Local Context or in the iteration loop. If you have  selected a Shape from *TopoDS* on decomposition in standard mode, the *Interactive()* function returns the interactive object, which provided the selected  shape. Other functions allow you to manipulate the content of Selected or  Current Objects:  
868   * *AIS_InteractiveContext::EraseSelected* erases the selected objects; 
869   * *AIS_InteractiveContext::DisplaySelected* displays them; 
870   * *AIS_InteractiveContext::SetSelected* puts the objects in the list of  selections;
871   * *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;
872   * *AIS_InteractiveContext::AddOrRemoveSelected* adds or removes an object from the list of selected entities; 
873   * *AIS_InteractiveContext::HilightSelected* highlights the selected object;
874   * *AIS_InteractiveContext::UnhilightSelected* removes highlighting from the selected object; 
875   * *AIS_InteractiveContext::ClearSelected* empties the list of selected objects. 
876
877
878 You can highlight and remove highlighting from a current  object, and empty the list of current objects using the following functions:  
879 ~~~~~
880   AIS_InteractiveContext::HilightCurrents  
881   AIS_InteractiveContext::UnhilightCurrents  
882   AIS_InteractiveContext::ClearCurrents  
883 ~~~~~
884 When you are in an open Local Context, you may need to keep  "temporary" interactive objects. This is possible using the following functions: 
885   * *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.  
886   * *AIS_InteractiveContext::SetSelectedCurrent* allows the selected object to become the current object when you  close the local context.  
887
888 You can also want to use function *AIS_InteractiveContext::ClearLocalContext* to modify in a general way the state of the local context before continuing a selection (emptying objects, removing  filters, standard activation modes). 
889
890 @subsubsection occt_visu_3_4_7 Recommendations 
891
892 The possibilities of use for local contexts are numerous  depending on the type of operation that you want to perform:  
893   * working on all visualized interactive objects, 
894   * working on only a few objects, 
895   * working on a single object. 
896
897 When you want to work on one type of entity, you should  open a local context with the option *UseDisplayedObjects* set to FALSE. Some  functions which allow you to recover the visualized interactive objects, which  have a given Type, and Signature from the "Neutral Point" are:  
898
899 ~~~~~
900 AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive&  aListOfIO) const;  
901 AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive  WhichKind, const Standard_Integer  WhichSignature;
902 AIS_ListOfInteractive&  aListOfIO) const;  
903 ~~~~~
904
905 At this stage, you only have to load the functions *Load, Activate,* and so on.  
906
907 When you open a Local Context with default options, you  must keep the following points in mind:  
908 * 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.  
909 * The Shape Type  Interactive Objects are automatically decomposed into sub-shapes when standard  activation modes are launched.  
910 * 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.  
911
912 The stages could be the following:
913   1. Open  a Local Context with the right options;  
914   2. Load/Visualize  the required complementary objects with the desired activation modes.  
915   3. Activate  Standard modes if necessary  
916   4. Create  its filters and add them to the Local Context  
917   5. Detect/Select/recover  the desired entities  
918   6. Close  the Local Context with the adequate index.  
919
920 It is useful to create an **interactive editor**, to which you  pass the Interactive Context. This allow setting up different  contexts of selection/presentation according to the operation, which you want  to perform. 
921  
922 Let us assume that you have visualized several types of interactive objects: *AIS_Points*,  *AIS_Axes*, *AIS_Trihedrons*, and *AIS_Shapes*.  
923
924 For your applicative function, you need an axis to create a  revolved object. You could obtain this axis by identifying:  
925   * an axis which is already visualized,
926   * 2 points,
927   * a rectilinear edge on the shapes which are present,
928   * a cylindrical face on the shapes (You will take the axis of this  face) 
929
930 ~~~~~
931 myIHMEditor::myIHMEditor  
932         (const  Handle(AIS_InteractiveContext)& Ctx, 
933          ....) : 
934          myCtx(Ctx),  
935         ...  
936
937
938
939 myIHMEditor::PrepareContext() 
940
941 myIndex =myCtx-OpenLocalContext();  
942
943 //the filters  
944
945 Handle(AIS_SignatureFilter) F1 = new  AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Point);   
946 //filter on the points  
947
948 Handle(AIS_SignatureFilter) F2 = new AIS_SignatureFilter(AIS_KOI_Datum,AIS_SD_Axis);   
949 //filters on the axes.  
950
951 Handle(StdSelect_FaceFilter) F3 = new StdSelect_FaceFilter(AIS_Cylinder);   
952 //cylindrical face filters  
953 //... 
954 // activation of standard modes  on the shapes..  
955 myCtx-ActivateStandardMode(TopAbs_FACE); 
956 myCtx-ActivateStandardMode(TopAbs_VERTEX); 
957 myCTX-Add(F1); 
958 myCTX-Add(F2); 
959 myCTX-Add(F3);  
960
961 // at  this point, you can call the selection/detection function  
962
963
964 void myIHMEditor::MoveTo(xpix,ypix,Vue) 
965
966 {  myCTX-MoveTo(xpix,ypix,vue);  
967 // the highlight of what is  detected is automatic.  
968 }      
969 Standard_Boolean myIHMEditor::Select()  
970 {
971 // returns true if you should  continue the selection      
972                 myCTX-Select();   
973                 myCTX-InitSelected();  
974                 if(myCTX-MoreSelected()) 
975                  {
976                  if(myCTX-HasSelectedShape())     
977                 { const  TopoDS_Shape& sh = myCTX-SelectedShape(); 
978                 if(  vertex){  
979                         if(myFirstV...)   
980                         {  
981                         //if it’s the  first vertex, you stock it, then you deactivate the faces and only keep the  filter on the points: 
982                         mypoint1 =  ....; 
983                         myCtx-RemoveFilters(); 
984                         myCTX-DeactivateStandardMode(TopAbs_FACE);   
985                         myCtx-Add(F1);   
986                         // the filter  on the AIS_Points  
987                         myFirstV =  Standard_False;  
988                         return  Standard_True;  
989                          }
990                         else
991                          { 
992                         mypoint2 =...;  
993                         //  construction of the axis return Standard_False;  
994                         } 
995                  } 
996                  else  
997                   {  
998                 //it is a  cylindrical face : you recover the axis; visualize it; and stock it.  
999                 return  Standard_False;  
1000                 }  
1001                   }  
1002                 // it is not  a shape but is no doubt a point.  
1003                 else  
1004                 {  
1005                 Handle(AIS_InteractiveObject)   
1006                 SelObj =  myCTX-SelectedInteractive(); 
1007                 if(SelObj-Type()==AIS_KOI_Datum)   
1008                 { 
1009                         if(SelObj-Signature()==1)   
1010                         { 
1011                                 if  (firstPoint) 
1012                                 { 
1013                                 mypoint1  =...  
1014                                 return  Standard_True;  
1015                                 } 
1016                                 else 
1017                                 {  
1018                                 mypoint2 =  ...;  
1019                                 //construction  of the axis, visualization, stocking  
1020                                 return  Standard_False;  
1021                 } 
1022                 } 
1023
1024                 else  
1025                 {  
1026                 // you have  selected an axis; stock the axis  
1027                 return  Standard_False; 
1028                 } 
1029                 } 
1030                 } 
1031                 } 
1032                 }  
1033 void myIHMEditor::Terminate()
1034 {
1035 myCtx->CloseLocalContext(myIndex); 
1036 ...
1037 }
1038 ~~~~~
1039
1040 @subsection occt_visu_3_5 Standard Interactive Object Classes 
1041
1042 @subsubsection occt_visu_3_5_1 Datums
1043   
1044 *AIS_Point,  AIS_Axis,  AIS_Line,  AIS_Circle,  AIS_Plane* and *AIS_Trihedron* have four selection modes: 
1045   * mode 0 : selection of a trihedron; 
1046   * mode 1 : selection of the origin of the trihedron; 
1047   * mode 2 : selection of the axes; 
1048   * mode 3 : selection of the planes XOY, YOZ, XOZ. 
1049
1050 when you activate one of modes: 1 2 3 4, you pick AIS  objects of type:  
1051   * *AIS_Point* 
1052   * *AIS_Axis* (and information on the type of axis) 
1053   * *AIS_Plane* (and information on the type of plane). 
1054
1055 *AIS_PlaneTrihedron* offers three selection modes:  
1056   * mode 0 : selection of the whole trihedron; 
1057   * mode 1 : selection of the origin of the trihedron; 
1058   * mode 2 : selection of the axes - same remarks as for the  Trihedron. 
1059
1060 For the presentation of planes and trihedra, the default  unit of length is millimeter, and the default value for the representation of  axes is 100. If you modify these dimensions, you must temporarily recover the  object **Drawer**. From it, take the *Aspects* in which the values for length  are stored (*PlaneAspect* for the plane, *FirstAxisAspect* for trihedra), and  change these values inside these Aspects. Finally, recalculate the  presentation.  
1061
1062 @subsubsection occt_visu_3_5_2 Objects 
1063
1064 *AIS_Shape* has three visualization modes :  
1065   * mode 0 : Line (default mode) 
1066   * mode 1 : Shading (depending on the type of shape) 
1067   * mode 2 : Bounding Box 
1068
1069 And at maximum seven selection modes, depending on the shape complexity:  
1070   * mode 0 : selection of the *AIS_Shape*; 
1071   * mode 1 : selection of the vertices; 
1072   * mode 2 : selection of the edges; 
1073   * mode 3 : selection of the wires; 
1074   * mode 4 : selection of the faces; 
1075   * mode 5 : selection of the shells; 
1076   * mode 6 : selection of the constituent solids. 
1077
1078 * *AIS_Triangulation* is a simple interactive object for displaying  triangular mesh contained in *Poly_Triangulation* container. 
1079 * *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.  
1080 * *AIS_ConnectedShape* is an object connected to interactive objects  having a shape; this class has the same decompositions as *AIS_Shape*. What’s  more, it allows a presentation of hidden parts, which are calculated  automatically from the shape of its reference.  
1081 * *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) 
1082 * *AIS_MultipleConnectedShape* is an interactive Object connected to  a list of interactive objects having a Shape <i>(AIS_Shape, AIS_ConnectedShape,  AIS_MultipleConnectedShape)</i>. The presentation of hidden parts is calculated  automatically.  
1083 * *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. 
1084 * *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. 
1085
1086 @subsubsection occt_visu_3_5_3 Relations 
1087   * *AIS_ConcentricRelation* 
1088   * *AIS_FixRelation*
1089   * *AIS_IdenticRelation* 
1090   * *AIS_ParallelRelation*
1091   * *AIS_PerpendicularRelation*
1092   * *AIS_Relation*
1093   * *AIS_SymmetricRelation*
1094   * *AIS_TangentRelation*
1095
1096 The list of relations is not exhaustive.    
1097
1098 @subsubsection occt_visu_3_5_4 Dimensions
1099   * *AIS_AngleDimension* 
1100   * *AIS_Chamf3dDimension* 
1101   * *AIS_DiameterDimension* 
1102   * *AIS_DimensionOwner*
1103   * *AIS_LengthDimension*
1104   * *AIS_OffsetDimension*
1105   * *AIS_RadiusDimension*
1106
1107   @subsubsection occt_visu_3_5_5 MeshVS_Mesh
1108
1109 *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.  
1110
1111 However, the *DataSource* does not provide any  information on attributes, for example nodal colors, but you can apply them in  a special way – by choosing the appropriate presentation builder.  
1112
1113 The presentations of *MeshVS_Mesh* are built with the  presentation builders *MeshVS_PrsBuilder*. You can choose between the  builders to represent the object in a different way. Moreover, you can redefine  the base builder class and provide your own presentation builder. 
1114
1115 You can add/remove builders using the following methods: 
1116 ~~~~~
1117   MeshVS_Mesh::AddBuilder (const Handle (MeshVS_PrsBuilder) &Builder, Standard_Boolean TreatAsHilighter) 
1118   MeshVS_Mesh::RemoveBuilder (const Standard_Integer  Index) 
1119   MeshVS_Mesh::RemoveBuilderById (const Standard_Integer Id) 
1120 ~~~~~
1121
1122 There is a set of reserved display and highlighting mode flags for *MeshVS_Mesh*. Mode value is a number of bits that allows selecting additional display parameters and combining the following mode flags, which allow displaying mesh in wireframe, shading and shrink modes: 
1123 ~~~~~
1124   MeshVS_DMF_WireFrame
1125   MeshVS_DMF_Shading
1126   MeshVS_DMF_Shrink
1127 ~~~~~  
1128
1129 It is also possible to display  deformed mesh in wireframe, shading or shrink modes usung :  
1130 ~~~~~
1131         MeshVS_DMF_DeformedPrsWireFrame
1132         MeshVS_DMF_DeformedPrsShading  
1133         MeshVS_DMF_DeformedPrsShrink
1134 ~~~~~  
1135
1136 The following methods represent  different kinds of data :
1137 ~~~~~
1138   MeshVS_DMF_VectorDataPrs  
1139   MeshVS_DMF_NodalColorDataPrs
1140   MeshVS_DMF_ElementalColorDataPrs
1141   MeshVS_DMF_TextDataPrs
1142   MeshVS_DMF_EntitiesWithData
1143 ~~~~~  
1144
1145 The following methods provide selection  and highlighting :
1146 ~~~~~
1147   MeshVS_DMF_SelectionPrs
1148   MeshVS_DMF_HilightPrs
1149 ~~~~~  
1150
1151 *MeshVS_DMF_User* is a user-defined  mode.  
1152
1153 These values will be used by the  presentation builder. 
1154 There is also a set of selection modes flags that can be grouped in a combination of bits: 
1155   * *MeshVS_SMF_0D*
1156   * *MeshVS_SMF_Link*
1157   * *MeshVS_SMF_Face*
1158   * *MeshVS_SMF_Volume*
1159   * *MeshVS_SMF_Element* - groups *0D, Link, Face* and *Volume*  as a bit mask ;
1160   * *MeshVS_SMF_Node*
1161   * *MeshVS_SMF_All* - groups *Element* and *Node* as a bit mask; 
1162   * *MeshVS_SMF_Mesh*
1163   * *MeshVS_SMF_Group*
1164
1165 Such an object, for example, can be used for displaying the object and stored in the STL file format: 
1166
1167 ~~~~~
1168 // read the data and create a data source
1169 Handle  (StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFileName); 
1170 Handle  (XSDRAWSTLVRML_DataSource) aDataSource = new XSDRAWSTLVRML_DataSource (aSTLMesh); 
1171
1172 // create mesh 
1173 Handle  (MeshVS_Mesh) aMesh = new MeshVS(); 
1174 aMesh-SetDataSource  (aDataSource); 
1175
1176 // use default presentation builder
1177 Handle  (MeshVS_MeshPrsBuilder) aBuilder =  new  MeshVS_MeshPrsBuilder (aMesh); 
1178 aMesh-AddBuilder  (aBuilder, Standard_True); 
1179 ~~~~~
1180
1181 *MeshVS_NodalColorPrsBuilder* allows representing a mesh  with a color scaled texture mapped on it. 
1182 To do this you should define a color  map for the color scale, pass this map to the presentation builder, 
1183 and define an appropriate value in the range of 0.0 – 1.0 for every node. 
1184
1185 The following example demonstrates how you can do this (check if the view has been set up to display textures): 
1186
1187 ~~~~~
1188 // assign nodal builder to the mesh
1189 Handle  (MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder 
1190      (aMesh,MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask); 
1191 aBuilder-UseTexture  (Standard_True); 
1192
1193 // prepare color map
1194 Aspect_SequenceOfColor  aColorMap; 
1195 aColorMap.Append  ((Quantity_NameOfColor) Quantity_NOC_RED); 
1196 aColorMap.Append  ((Quantity_NameOfColor) Quantity_NOC_BLUE1); 
1197
1198 // assign color scale map  values (0..1) to nodes
1199 TColStd_DataMapOfIntegerReal  aScaleMap; 
1200
1201 // iterate through the  nodes and add an node id and an appropriate value to the map
1202 aScaleMap.Bind  (anId, aValue); 
1203   
1204 // pass color map and color scale values to the builder
1205 aBuilder-SetColorMap  (aColorMap); 
1206 aBuilder-SetInvalidColor  (Quantity_NOC_BLACK); 
1207 aBuilder-SetTextureCoords  (aScaleMap); 
1208 aMesh-AddBuilder  (aBuilder, Standard_True); 
1209 ~~~~~
1210
1211 @subsection occt_visu_3_6 Dynamic Selection 
1212
1213 The idea of dynamic selection is to represent the entities, which you want to select by a bounding box in the actual 2D space of the selection view. The set of these zones is ordered by a powerful sorting  algorithm. 
1214 To then find the applicative entities actually detected at this position, all you have to do is read which rectangles are touched at mouse position (X,Y) of the view, and judiciously reject some of the entities which  have provided these rectangles.  
1215
1216 @subsubsection occt_visu_3_6_1 How to go from the objects to 2D boxes 
1217
1218
1219 An intermediary stage consists in representing what you can  make selectable by means of sensitive primitives and owners, entities of a high enough level to be known by the selector mechanisms.  
1220
1221 The sensitive primitive is capable of:  
1222   * giving a 2D bounding box to the selector. 
1223   * answering the rejection criteria positively or negatively by a  "Matches" function. 
1224   * being projected from 3D in the 2D space of the view if need be. 
1225   * returning the owner which it will represent in terms of  selection. 
1226
1227 A set of standard sensitive primitives exists in Select3D  packages for 3D primitives.  
1228
1229 The owner is the entity, which makes it possible to link the  sensitive primitives and the objects that you really wanted to detect. It  stocks the diverse information, which makes it possible to find objects. An  owner has a priority (*5* by default), which you can change to  make one entity more selectable than another.  
1230
1231 @image html visualization_image021.png 
1232 @image latex visualization_image021.png 
1233
1234 @subsubsection occt_visu_3_6_2 Implementation in an interactive/selectable object 
1235    
1236 Define the number of selection modes possible, i.e. what  you want to identify by activating each of the selection modes. 
1237
1238 For example: for an  interactive object representing a topological shape:  
1239 * mode 0: selection of the interactive object itself;  
1240 * mode 1: selection of the vertices; 
1241 * mode 2: selection of the edges;  
1242 * mode 3: selection of the wires;  
1243 * mode 4: selection of the detectable faces. 
1244
1245 For each selection mode of an interactive object, "model" is the set of entities, which you want to locate by these primitives and these  owners.  
1246
1247 There is an "owner" root class, *SelectMgr_EntityOwner*,  containing a reference to a selectable object, which has created it. If you  want to stock its information, you have to create classes derived from this  root class. Example: for shapes, there is the *StdSelect_BRepOwner* class,  which can save a *TopoDS* shape as a field as well as the Interactive Object.  
1248
1249 The set of sensitive primitives which has been calculated  for a given mode is stocked in *SelectMgr_Selection*.  
1250
1251 For an Interactive object, the modeling is done in the *ComputeSelection* virtual function.  
1252
1253 Let us consider an example of an interactive object representing a box. 
1254
1255 We are interested in two location modes: 
1256   * mode 0: location of the whole box.  
1257   * mode 1: location of the edges on the box. 
1258
1259 For the first  mode, all sensitive primitives will have the same owner, which will represent  the interactive object. In the second case, we have to create an owner for each  edge, and this owner will have to contain the index for the edge, which it  represents. You will create a class of owner, which derives from *SelectMgr_EntityOwner*. 
1260
1261 The *ComputeSelection*  function for the interactive box can have the following form:  
1262
1263 ~~~~~
1264 void InteractiveBox::ComputeSelection  
1265         (const  Handle(SelectMgr_Selection)& Sel, 
1266          const Standard_Integer Mode)  
1267
1268         switch(Mode) 
1269                 {  case 0:   //locating the whole box by  making its faces sensitive...  
1270                 { 
1271         Handle(SelectMgr_EntityOwner)  Ownr = new SelectMgr_EntityOwner(this,5);   
1272         for(Standard_Integer  I=1;I=Nbfaces;I++)  
1273         {  
1274         //Array is a  TColgp_Array1OfPnt: which represents the array of vertices. Sensitivity is  
1275         Select3D_TypeOfSensitivity value 
1276         Sel-Add(new  
1277 Select3D_SensitiveFace(Ownr,Array,Sensitivity));  
1278                         } 
1279                         break;  
1280            } 
1281           case 1:  
1282         // locates the edges  {  
1283         for(Standard_Integer i=1;i=12;i++)  
1284                         { 
1285                                 // 1 owner  per edge... 
1286                                 Handle(mypk_EdgeOwner)  Ownr =  
1287                                         new  mypk_EdgeOwner(this,i,6); 
1288                                         //6-priority 
1289                                         Sel-Add(new  Select3D_SensitiveSegment (Ownr,firstpt(i),lastpt(i)));  
1290                                         } 
1291                                 break;  
1292                         } 
1293                 } 
1294         } 
1295 ~~~~~
1296
1297 Selectable objects are loaded in the selection manager,  which has one or more selectors; in general, we suggest assigning one selector  per viewer. All you have to do afterwards is to activate or deactivate the  different selection modes for selectable objects. The *SelectionManager*  looks after the call to the *ComputeSelection* functions for different  objects. 
1298
1299 NOTE: This procedure is completely hidden if you use the <a href="#occt_visu_3_3"> AIS Interactive Context </a>
1300
1301 <h4>Example </h4>
1302 ~~~~~
1303 //We have several " interactive boxes " box1, box2, box3;  
1304         Handle(SelectMgr_SelectionManager) SM = new  SelectMgr_SelectionManager();  
1305         Handle(StdSelect_ViewerSelector3d) VS = new  StdSelect_ViewerSelector3d();  
1306                 SM-Add(VS); 
1307                 SM-Load(box1);SM-Load(box2);SM-Load(box3); 
1308                 // box load.  
1309                 SM-Activate(box1,0,VS); 
1310                 // activates  mode 0 of box 1 in the selector VS 
1311                 SM-Activate(box1,1,VS);   
1312                 M-Activate(box3,1,VS);   
1313 VS-Pick(xpix,ypix,vue3d)  
1314 // detection of primitives by mouse position.  
1315 Handle(EntityOwner)  POwnr = VS-OnePicked();  
1316 // picking of the "best" owner detected  
1317 for(VS-Init();VS-More();VS-Next())   
1318         { 
1319         VS-Picked();   
1320         // picking of all owners  detected  
1321           } 
1322         SM-Deactivate(box1);   
1323         // deactivate all active modes  of box1  
1324 ~~~~~
1325
1326 @section occt_visu_4 3D Presentations
1327
1328 @subsection occt_visu_4_1 Glossary of 3D terms 
1329
1330 * **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.
1331 * **Depth-cueing**      Reduces the color intensity for the portion of an object further away from the eye to give the impression of depth. This is used for wireframe objects. Shaded objects do not require this.
1332 * **Group**     - a set of primitives and attributes on those primitives. Primitives and attributes may be added to a group but cannot be removed from a group, except by erasing them globally. A group can have a pick identity.
1333 * **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.
1334 * **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.
1335 * **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. 
1336 * **View**      - is defined by a view orientation, a view mapping, and a context view.
1337 * **Viewer** - manages a set of views.
1338 * **View orientation** - defines the manner in which the observer looks at the scene in terms of View Reference Coordinates.
1339 * **View mapping** - defines the transformation from View Reference Coordinates to the Normalized Projection Coordinates. This follows the Phigs scheme.
1340 * **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.
1341
1342 @subsection occt_visu_4_2 Creating a 3D scene 
1343
1344 To create 3D graphic objects and display them on the screen,  follow the procedure below:  
1345 1. Create attributes.  
1346 2. Create a 3D viewer..  
1347 3. Create a view.  
1348 4. Create an interactive context.  
1349 5. Create interactive objects.  
1350 6. Create primitives in the interactive  object  
1351 7. Display the interactive object.  
1352
1353 @subsubsection occt_visu_4_2_1 Create attributes 
1354
1355 Create colors.  
1356
1357 ~~~~~
1358 Quantity_Color Black (Quantity_NOC_BLACK);  
1359 Quantity_Color Blue (Quantity_NOC_MATRABLUE);  
1360 Quantity_Color Brown (Quantity_NOC_BROWN4);  
1361 Quantity_Color Firebrick (Quantity_NOC_FIREBRICK);  
1362 Quantity_Color Forest (Quantity_NOC_FORESTGREEN);  
1363 Quantity_Color Gray (Quantity_NOC_GRAY70);  
1364 Quantity_Color MyColor (0.99, 0.65, 0.31,  Quantity_TOC_RGB);  
1365 Quantity_Color Beet (Quantity_NOC_BEET);  
1366 Quantity_Color White (Quantity_NOC_WHITE);  
1367 ~~~~~
1368
1369
1370 Create line attributes.  
1371
1372 ~~~~~
1373 Handle(Graphic3d_AspectLine3d)  CTXLBROWN =  new Graphic3d_AspectLine3d ();  
1374 Handle(Graphic3d_AspectLine3d)  CTXLBLUE =  new Graphic3d_AspectLine3d ();  
1375 Handle(Graphic3d_AspectLine3d)  CTXLWHITE = new Graphic3d_AspectLine3d();  
1376                                                                 CTXLBROWN-SetColor (Brown);  
1377                                                                 CTXLBLUE-SetColor (Blue);  
1378                                                                 CTXLWHITE-SetColor (White);  
1379 ~~~~~
1380
1381 Create marker attributes.  
1382 ~~~~~
1383 Handle(Graphic3d_AspectMarker3d) CTXMFIREBRICK =  new Graphic3d_AspectMarker3d();   
1384                                                                  CTXMFIREBRICK-SetColor (Firebrick);  
1385                                                                  CTXMFIREBRICK-SetScale (1.0);  
1386                                                                  CTXMFIREBRICK-SetType (Aspect_TOM_BALL);  
1387 ~~~~~
1388
1389 Create facet attributes.  
1390 ~~~~~
1391 Handle(Graphic3d_AspectFillArea3d) CTXF =  new Graphic3d_AspectFillArea3d  ();  
1392 Graphic3d_MaterialAspect BrassMaterial  (Graphic3d_NOM_BRASS);  
1393 Graphic3d_MaterialAspect GoldMaterial  (Graphic3d_NOM_GOLD);  
1394         CTXF-SetInteriorStyle (Aspect_IS_SOLID);  
1395         CTXF-SetInteriorColor (MyColor);  
1396         CTXF-SetDistinguishOn ();  
1397         CTXF-SetFrontMaterial (GoldMaterial);  
1398         CTXF-SetBackMaterial (BrassMaterial);  
1399         CTXF-SetEdgeOn ();  
1400 ~~~~~
1401
1402 Create text attributes.  
1403 ~~~~~
1404 Handle(Graphic3d_AspectText3d) CTXT =  new  Graphic3d_AspectText3d  (Forest,  Graphic3d_NOF_ASCII_MONO, 1., 0.);  
1405 ~~~~~
1406
1407 @subsubsection occt_visu_4_2_2 Create a 3D Viewer (a Windows example) 
1408
1409 ~~~~~
1410 Handle(Aspect_DisplayConnection) aDisplayConnection; 
1411 Handle(Graphic3d_GraphicDriver) aGraphicDriver =  Graphic3d::InitGraphicDriver (aDisplayConnection); 
1412 TCollection_ExtendedString aName("3DV"); 
1413 myViewer = new V3d_Viewer (aGraphicDriver,aName.ToExtString  (), ""); 
1414 myViewer - SetDefaultLights ();  
1415 myViewer - SetLightOn ();  
1416 ~~~~~
1417
1418 @subsubsection occt_visu_4_2_3 Create a 3D view (a Windows example) 
1419
1420 It is assumed that a valid Windows window may already be  accessed via the method *GetSafeHwnd()*.  
1421 ~~~~~
1422 Handle (WNT_Window) aWNTWindow;
1423 aWNTWindow = new WNT_Window (GetSafeHwnd());
1424 myView = myViewer -> CreateView();
1425 myView -> SetWindow (a WNTWindow);
1426 ~~~~~
1427
1428 @subsubsection occt_visu_4_2_4 Create an interactive context 
1429
1430 ~~~~~
1431 myAISContext = new AIS_InteractiveContext (myViewer);  
1432 ~~~~~
1433
1434 You are now able to display interactive objects such as an  *AIS_Shape*.  
1435
1436 ~~~~~
1437 TopoDS_Shape aShape = BRepAPI_MakeBox(10,20,30)_Solid();  
1438 Handle (AIS_Shape) aAISShape = new AIS_Shape(aShape);  
1439 myAISContext - Display (aAISShape);  
1440 ~~~~~
1441
1442 @subsubsection occt_visu_4_2_5 Create your own interactive object 
1443
1444 Follow the procedure below to compute the  presentable object:  
1445
1446 1. Build  a presentable object inheriting from *AIS_InteractiveObject* (refer to the  Chapter on Presentable Objects).  
1447 2. Reuse  the *Prs3d_Presentation* provided as an argument of the compute methods.  
1448
1449 **Note** that there  are two compute methods: one for a standard representation, and the other for  a degenerated representation, i.e. in hidden line removal and wireframe modes.
1450
1451
1452 Let us look at the example of compute methods
1453
1454 ~~~~~
1455 Void 
1456 myPresentableObject::Compute  
1457         (const  Handle(PrsMgr_PresentationManager3d)&  
1458                 aPresentationManager,   
1459                 const  Handle(Prs3d_Presentation)& aPrs,  
1460                 const  Standard_Integer aMode) 
1461
1462 //...  
1463 )  
1464
1465 void 
1466 myPresentableObject::Compute  
1467                 (const  Handle(Prs3d_Projector)&,  
1468                 const Handle(Prs3d_Presentation)&  aPrs)  
1469 (  
1470 //...  
1471 )  
1472 ~~~~~
1473
1474 @subsubsection occt_visu_4_2_6 Create primitives in the interactive object 
1475
1476 Get the group used in *Prs3d_Presentation*.  
1477
1478 ~~~~~
1479 Handle(Graphic3d_Group) TheGroup =  Prs3d_Root::CurrentGroup(aPrs);  
1480 ~~~~~
1481
1482 Update the group attributes.  
1483
1484 ~~~~~
1485 TheGroup - SetPrimitivesAspect(CTXLBLUE);  
1486 ~~~~~
1487
1488 Create two triangles in *TheGroup*.  
1489
1490 ~~~~~
1491 Standard_Integer aNbTria = 2; 
1492 Handle(Graphic3d_ArrayOfTriangles) aTriangles = new  Graphic3d_ArrayOfTriangles(3 * aNbTria, 0, Standard_True); 
1493 Standard_Integer anIndex; 
1494 for (anIndex = 1; anIndex = aNbTria; nt++) 
1495
1496   aTriangles-AddVertex(anIndex * 5., 0., 0., 1., 1.,  1.); 
1497   aTriangles-AddVertex(anIndex * 5 + 5, 0., 0., 1.,  1., 1.); 
1498   aTriangles-AddVertex(anIndex * 5 + 2.5, 5., 0., 1.,  1., 1.); 
1499
1500 TheGroup-BeginPrimitives (); 
1501 mygroup-AddPrimitiveArray(aTriangles); 
1502 TheGroup-EndPrimitives (); 
1503 ~~~~~
1504
1505 The *BeginPrimitives()* and *EndPrimitives()* methods are used  when creating a set of various primitives in the same group.  
1506 Use the polyline function to create a boundary box for the *Struct* structure in group *TheGroup*.  
1507
1508 ~~~~~
1509 Standard_Real Xm, Ym, Zm, XM, YM, ZM;  
1510 Struct-MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);   
1511
1512 Handle(Graphic3d_ArrayOfPolylines)  aPolylines = new Graphic3d_ArrayOfPolylines(16, 4); 
1513 aPolylines-AddBound (4); 
1514 aPolylines-AddVertex (Xm,  Ym, Zm); 
1515 aPolylines-AddVertex (Xm,  Ym, ZM); 
1516 aPolylines-AddVertex (Xm,  YM, ZM); 
1517 aPolylines-AddVertex (Xm,  YM, Zm); 
1518 aPolylines-AddBound (4); 
1519 aPolylines-AddVertex (Xm,  Ym, Zm); 
1520 aPolylines-AddVertex (XM,  Ym, Zm); 
1521 aPolylines-AddVertex (XM,  Ym, ZM); 
1522 aPolylines-AddVertex (XM,  YM, ZM); 
1523 aPolylines-AddBound (4); 
1524 aPolylines-AddVertex (XM,  YM, Zm); 
1525 aPolylines-AddVertex (XM,  Ym, Zm); 
1526 aPolylines-AddVertex (XM,  YM, Zm); 
1527 aPolylines-AddVertex (Xm,  YM, Zm); 
1528 aPolylines-AddBound (4); 
1529 aPolylines-AddVertex (Xm,  YM, ZM); 
1530 aPolylines-AddVertex (XM,  YM, ZM); 
1531 aPolylines-AddVertex (XM,  Ym, ZM); 
1532 aPolylines-AddVertex (Xm,  Ym, ZM); 
1533
1534 TheGroup-BeginPrimitives  (); 
1535 TheGroup-AddPrimitiveArray(aPolylines); 
1536 TheGroup-EndPrimitives  (); 
1537 ~~~~~
1538
1539 Create text and markers in group *TheGroup*.  
1540
1541 ~~~~~
1542 static char *texte[3] = {   "Application title",  
1543                                                         "My  company",  
1544                                                         "My company  address." };  
1545 Graphic3d_Array1OfVertex Tpts8 (0, 1);  
1546 Tpts8(0).SetCoord (-40.0, -40.0, -40.0);  
1547 Tpts8(1).SetCoord (40.0, 40.0, 40.0);  
1548 TheGroup-MarkerSet (Tpts8);  
1549 Graphic3d_Vertex Marker (0.0, 0.0, 0.0);  
1550
1551 for (i=0; i=2; i++) {  
1552   Marker.SetCoord (-(Standard_Real)i*4 + 30, 
1553                     (Standard_Real)i*4, 
1554                    -(Standard_Real)i*4);  
1555   TheGroup-Text (texte[i], Marker, 20.); 
1556 }  
1557 ~~~~~
1558
1559 @section occt_visu_5 3D Resources
1560
1561 The 3D resources include the *Graphic3d* and *V3d* packages.  
1562
1563 @subsection occt_visu_5_1 Graphic3D Package
1564
1565 @subsubsection occt_visu_5_1_1 Overview 
1566
1567 The *Graphic3d* package is used to create 3D graphic  objects in a 3D viewer. These objects called **structures** are made up of  groups of primitives and attributes. 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.  
1568
1569 @subsubsection occt_visu_5_1_2 Provided services 
1570
1571 Graphic structures can be:  
1572   * Displayed, 
1573   * Highlighted, 
1574   * Erased, 
1575   * Transformed, 
1576   * Connected to form a tree.
1577   
1578 There are classes for: 
1579   * Visual attributes for lines, faces, markers, text, materials, 
1580   * Vectors and vertices, 
1581   * Graphic objects, groups, and structures. 
1582
1583 @subsubsection occt_visu_5_1_3 About the primitives 
1584
1585 * **Markers** 
1586   * Have one or more vertices, 
1587   * Have a type, a scale factor, and a color, 
1588   * Have a size, shape, and orientation independent of  transformations. 
1589 * **Polygons** 
1590   * Have one closed boundary, 
1591   * Have at least three vertices, 
1592   * Are planar and have a normal, 
1593   * Have interior attributes - style, color, front and back material,  texture and reflection ratio, 
1594   * Have a boundary with the following attributes - type, width scale  factor, color. The boundary is only drawn when the interior style is hollow. 
1595
1596 * **Polygons with holes** 
1597   * Have multiple closed boundaries, each one with at least three  vertices, 
1598   * Are planar and have a normal, 
1599   * Have interior attributes - style, color, front and back material,  
1600   * Have a boundary with the following attributes - type, width scale  factor, color. The boundary is only drawn when the interior style is hollow. 
1601
1602 * **Polylines** 
1603   * Have two or more vertices, 
1604   * Have the following attributes - type, width scale factor, color. 
1605
1606 * **Text** 
1607   * Has geometric and non-geometric attributes, 
1608   * Geometric attributes - character height, character up vector,  text path, horizontal and vertical alignment, orientation, three-dimensional  position, zoomable flag
1609   * Non-geometric attributes - text font, character spacing,  character expansion factor, color. 
1610
1611 @subsubsection occt_visu_5_1_4 Primitive  arrays
1612
1613 Primitive arrays are a more efficient approach to describe  and display the primitives from the aspects of memory usage and graphical  performance. The key feature of the primitive arrays is that the primitive data  is not duplicated. For example, two polygons could share the same vertices, so  it is more efficient to keep the vertices in a single array and specify the  polygon vertices with indices of this array. In addition to such kind of memory  savings, the OpenGl graphics driver provides the Vertex Buffer Objects (VBO).  VBO is a sort of video memory storage that can be allocated to hold the  primitive arrays, thus making the display operations more efficient and  releasing the RAM memory. 
1614
1615 The Vertex Buffer Objects are enabled by default, but VBOs  availability depends on the implementation of OpenGl. If the VBOs are  unavailable or there is not enough video memory to store the primitive arrays,  the RAM memory will be used to store the arrays.  
1616
1617 The Vertex Buffer Objects can be disabled at the application  level. You can use the method *Graphic3d_GraphicDriver::EnableVBO (const Standard_Boolean status)* to enable/disable VBOs: 
1618   
1619 The following example shows how to disable the VBO support:  
1620
1621 ~~~~~
1622 *// get the graphic  driver* 
1623 Handle (Graphic3d_GraphicDriver) aDriver =  
1624   myAISContext-CurrentViewer()-Driver(); 
1625
1626 *// disable VBO support* 
1627 aDriver-EnableVBO (Standard_False); 
1628 ~~~~~
1629
1630 **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*. 
1631
1632 The different types of primitives could be presented with  the following primitive arrays: 
1633   * *Graphic3d_ArrayOfPoints,*
1634   * *Graphic3d_ArrayOfPolygons,*
1635   * *Graphic3d_ArrayOfPolylines,*
1636   * *Graphic3d_ArrayOfQuadrangles,*
1637   * *Graphic3d_ArrayOfQuadrangleStrips,*
1638   * *Graphic3d_ArrayOfSegments,*
1639   * *Graphic3d_ArrayOfTriangleFans,*
1640   * *Graphic3d_ArrayOfTriangles,*
1641   * *Graphic3d_ArrayOfTriangleStrips.*
1642
1643 The *Graphic3d_ArrayOfPrimitives* is a base class for these  primitive arrays. 
1644
1645 Method *Graphic3d_ArrayOfPrimitives::AddVertex* allows adding There is a set of similar methods to add vertices to the  primitive array.
1646
1647 These methods take vertex coordinates as an argument and  allow you to define the color, the normal and the texture coordinates assigned  to the vertex. The return value is the actual number of vertices in the array. 
1648
1649 You can also modify the values assigned to the vertex or  query these values by the vertex index: 
1650   * *void Graphic3d_ArrayOfPrimitives::SetVertice*
1651   * *void  Graphic3d_ArrayOfPrimitives::SetVertexColor*
1652   * *void  Graphic3d_ArrayOfPrimitives::SetVertexNormal*
1653   * *void  Graphic3d_ArrayOfPrimitives::SetVertexTexel*
1654   * *gp_Pnt  Graphic3d_ArrayOfPrimitives::Vertices*
1655   * *gp_Dir   Graphic3d_ArrayOfPrimitives::VertexNormal*
1656   * *gp_Pnt3d  Graphic3d_ArrayOfPrimitives::VertexTexel*
1657   * *Quantity_Color  Graphic3d_ArrayOfPrimitives::VertexColor*
1658   * *void  Graphic3d_ArrayOfPrimitives::Vertices*
1659   * *void  Graphic3d_ArrayOfPrimitives::VertexNormal*
1660   * *void  Graphic3d_ArrayOfPrimitives::VertexTexel*
1661   * *void  Graphic3d_ArrayOfPrimitives::VertexColor*
1662
1663 The following example shows how to define an array of  points: 
1664
1665 ~~~~~
1666 // create an array
1667 Handle (Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints (aVerticiesMaxCount); 
1668
1669 // add vertices to the array
1670 anArray-AddVertex  (10.0, 10.0, 10.0); 
1671 anArray-AddVertex  (0.0, 10.0, 10.0); 
1672
1673 // add the array to the structure
1674 Handle (Graphic3d_Group) aGroup  =  Prs3d_Root::CurrentGroup (aPrs); 
1675 aGroup-BeginPrimitives (); 
1676 aGroup-AddPrimitiveArray (anArray); 
1677 aGroup-EndPrimitives (); 
1678 ~~~~~
1679
1680 If the primitives share the same vertices (polygons,  triangles, etc.) then you can define them as indices of the vertices array. 
1681
1682 The method *Graphic3d_ArrayOfPrimitives::AddEdge* allows defining the primitives by indices. This method adds an "edge" in the range <i> [1, VertexNumber() ] </i>  in the array. 
1683
1684 It is also possible to query the vertex defined by an edge using method *Graphic3d_ArrayOfPrimitives::Edge*
1685
1686 The following example shows how to define an array of  triangles: 
1687
1688 ~~~~~
1689 // create an array
1690 Standard_Boolean  IsNormals     = Standard_False;  
1691 Standard_Boolean  IsColors      = Standard_False; 
1692 Standard_Boolean  IsTextureCrds = Standard_False; 
1693 Handle (Graphic3d_ArrayOfTriangles) anArray =  
1694           new Graphic3d_ArrayOfTriangles (aVerticesMaxCount, 
1695                                           aEdgesMaxCount, 
1696                                           IsNormals, 
1697                                           IsColors, 
1698                                           IsTextureCrds); 
1699 // add vertices to the array
1700 anArray-AddVertex  (-1.0, 0.0, 0.0);   // vertex 1
1701 anArray-AddVertex  ( 1.0, 0.0, 0.0);   // vertex 2
1702 anArray-AddVertex  ( 0.0, 1.0, 0.0);   // vertex 3 
1703 anArray-AddVertex  ( 0.0,-1.0, 0.0);   // vertex 4 
1704
1705 // add edges to the array
1706 anArray-AddEdge  (1);  // first triangle
1707 anArray-AddEdge  (2); 
1708 anArray-AddEdge  (3); 
1709 anArray-AddEdge  (1);  // second triangle
1710 anArray-AddEdge  (2); 
1711 anArray-AddEdge  (4); 
1712
1713 // add the array to the structure
1714 Handle  (Graphic3d_Group) aGroup =  Prs3d_Root::CurrentGroup (aPrs); 
1715 aGroup-BeginPrimitives  (); 
1716 aGroup-AddPrimitiveArray  (anArray); 
1717 aGroup-EndPrimitives  (); 
1718 ~~~~~
1719
1720 If the primitive array presents primitives built from  sequential sets of vertices, for example polygons, then you can specify the  bounds, or the number of vertices for each primitive. You can use the method *Graphic3d_ArrayOfPrimitives::AddBound* to define the bounds and the color for each bound. This method returns the actual number of bounds. 
1721
1722 It is also possible to set the color and query the number of  edges in the bound and bound color. 
1723 ~~~~~
1724   Standard_Integer  Graphic3d_ArrayOfPrimitives::Bound
1725   Quantity_Color  Graphic3d_ArrayOfPrimitives::BoundColor
1726   void  Graphic3d_ArrayOfPrimitives::BoundColor
1727 ~~~~~
1728
1729 The following example shows how to define an array of  polygons: 
1730
1731 ~~~~~
1732 // create an array
1733 Standard_Boolean  IsNormals      = Standard_False;  
1734 Standard_Boolean  IsVertexColors = Standard_False; 
1735 Standard_Boolean  IsFaceColors   = Standard_False; 
1736 Standard_Boolean  IsTextureCrds  = Standard_False; 
1737 Handle (Graphic3d_ArrayOfPolygons) anArray =  
1738           new Graphic3d_ArrayOfPolygons (aVerticesMaxCount, 
1739                                          aBoundsMaxCount, 
1740                                          aEdgesMaxCount, 
1741                                          IsNormals, 
1742                                          IsVertexColors, 
1743                                          IsFaceColors, 
1744                                          IsTextureCrds); 
1745
1746 // add bounds to the array, first polygon
1747 anArray-AddBound (3);  
1748 anArray-AddVertex (-1.0,  0.0, 0.0);    
1749 anArray-AddVertex  ( 1.0, 0.0, 0.0);    
1750 anArray-AddVertex  ( 0.0, 1.0, 0.0);    
1751
1752 // add bounds to the array, second polygon
1753 anArray-AddBound (4); 
1754 anArray-AddVertex (-1.0,  0.0, 0.0);    
1755 anArray-AddVertex  ( 1.0, 0.0, 0.0);    
1756 anArray-AddVertex  ( 1.0,-1.0, 0.0);    
1757 anArray-AddVertex  (-1.0,-1.0, 0.0);    
1758
1759 // add the array to the structure 
1760 Handle  (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup  (aPrs); 
1761 aGroup-BeginPrimitives  (); 
1762 aGroup-AddPrimitiveArray  (anArray); 
1763 aGroup-EndPrimitives  (); 
1764 ~~~~~
1765
1766 There are also several helper methods. You can get the type  of the primitive array: 
1767 ~~~~~
1768   Graphic3d_TypeOfPrimitiveArray 
1769   Graphic3d_ArrayOfPrimitives::Type
1770   Standard_CString  Graphic3d_ArrayOfPrimitives::StringType
1771 ~~~~~
1772
1773 and check if the primitive array provides normals, vertex colors and vertex texels (texture coordinates): 
1774
1775 ~~~~~
1776   Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals
1777   Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors
1778   Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels
1779 ~~~~~
1780 or get the number of vertices, edges and bounds: 
1781 ~~~~~
1782   Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber
1783   Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber
1784   Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber
1785 ~~~~~
1786   
1787 @subsubsection occt_visu_5_1_5 Materials 
1788
1789 A *material* is defined by :  
1790   * Transparency, 
1791   * Diffuse reflection - a component of the object color;
1792   * Ambient reflection;
1793   * Specular reflection - a component of the color of the light source.
1794
1795 The following items are  required to determine the three colors of reflection:  
1796   * Color, 
1797   * Coefficient of diffuse reflection, 
1798   * Coefficient of ambient reflection, 
1799   * Coefficient of specular reflection. 
1800
1801 @subsubsection occt_visu_5_1_6 Textures 
1802
1803 A *texture* is defined by a name.  
1804 Three types of texture are available:  
1805   * 1D, 
1806   * 2D, 
1807   * Environment mapping. 
1808
1809 @subsubsection occt_visu_5_1_7 Graphic3d text  
1810
1811 The OpenGl graphics driver uses advanced text rendering  powered by FTGL library. This library provides vector text rendering, as a  result the text can be rotated and zoomed without quality loss.  
1812 *Graphic3d* text primitives have the following features: 
1813   * fixed size (non-zoomable) or zoomable, 
1814   * can be rotated to any angle in the view plane,
1815   * support unicode charset.
1816
1817 The text attributes for the group could be defined with the *Graphic3d_AspectText3d* attributes group. 
1818 To add any text to the graphic structure you can use the  following methods: 
1819 ~~~~~
1820  void Graphic3d_Group::Text
1821                         (const Standard_CString AText, 
1822                          const Graphic3d_Vertex& APoint, 
1823                          const Standard_Real AHeight, 
1824                          const Quantity_PlaneAngle AAngle, 
1825                          const Graphic3d_TextPath ATp, 
1826                          const Graphic3d_HorizontalTextAlignment  AHta, 
1827                          const Graphic3d_VerticalTextAlignment  AVta, 
1828                          const Standard_Boolean EvalMinMax), 
1829 ~~~~~                   
1830 *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). 
1831
1832 *ATp* parameter defines the text path, *AHta* is the horizontal alignment of the text,  *AVta* is the vertical alignment of the text. 
1833
1834 You can  pass *Standard_False* as *EvalMinMax* if you don’t want the graphic3d structure  boundaries to be affected by the text position.  
1835
1836 **Note** that the text orientation angle can be defined by *Graphic3d_AspectText3d* attributes. 
1837 ~~~~~
1838   void  Graphic3d_Group::Text
1839                         (const Standard_CString AText, 
1840                          const Graphic3d_Vertex& APoint, 
1841                          const Standard_Real AHeight, 
1842                          const Standard_Boolean EvalMinMax) 
1843   void  Graphic3d_Group::Text
1844                         (const TCcollection_ExtendedString  &AText,  
1845                          const Graphic3d_Vertex& APoint, 
1846                          const Standard_Real AHeight, 
1847                          const Quantity_PlaneAngle AAngle, 
1848                          const Graphic3d_TextPath ATp, 
1849                          const Graphic3d_HorizontalTextAlignment  AHta, 
1850                          const Graphic3d_VerticalTextAlignment  AVta, 
1851                          const Standard_Boolean EvalMinMax) 
1852   void  Graphic3d_Group::Text
1853                         (const TCcollection_ExtendedString  &AText,  
1854                          const Graphic3d_Vertex& APoint, 
1855                          const Standard_Real AHeight, 
1856                          const Standard_Boolean EvalMinMax) 
1857 ~~~~~
1858
1859 See the example:
1860 ~~~~~
1861 // get the group
1862 Handle (Graphic3d_Group) aGroup =  Prs3d_Root::CurrentGroup  (aPrs);  
1863
1864 // change the text  aspect
1865 Handle(Graphic3d_AspectText3d) aTextAspect =  new Graphic3d_AspectText3d (); 
1866 aTextAspect-SetTextZoomable  (Standard_True); 
1867 aTextAspect-SetTextAngle  (45.0); 
1868 aGroup-SetPrimitivesAspect (aTextAspect);   
1869
1870 // add a text primitive  to the structure
1871 Graphic3d_Vertex aPoint (1, 1, 1); 
1872 aGroup-Text (Standard_CString ("Text"), aPoint, 16.0); 
1873 ~~~~~
1874
1875 @subsubsection occt_visu_5_1_8 Display priorities 
1876
1877 Structure display priorities control the order in which  structures are drawn. When you display a structure you specify its priority.  The lower the value, the lower the display priority. When the display is  regenerated the structures with the lowest priority are drawn first. For  structures with the same display priority the order in which they were  displayed determines the drawing order. OCCT supports eleven structure  display priorities.  
1878
1879 @subsubsection occt_visu_5_1_9 About structure hierarchies 
1880
1881 The root is the top of a structure hierarchy or structure  network. The attributes of a parent structure are passed to its descendants.  The attributes of the descendant structures do not affect the parent. Recursive  structure networks are not supported.  
1882
1883 @subsection occt_visu_5_2 V3d Package
1884
1885 @subsubsection occt_visu_5_2_1 Overview 
1886
1887 The *V3d* package provides the resources to define a 3D  viewer and the views attached to this viewer (orthographic, perspective). This  package provides the commands to manipulate the graphic scene of any 3D object  visualized in a view on screen.  
1888
1889 A set of high-level commands allows the separate  manipulation of parameters and the result of a projection (Rotations, Zoom,  Panning, etc.) as well as the visualization attributes (Mode, Lighting,  Clipping, Depth-cueing, etc.) in any particular view.  
1890
1891 @subsubsection occt_visu_5_2_2 Provided services 
1892
1893 The *V3d* package is basically a set of tools directed by  commands from the viewer front-end. This tool set contains methods for creating  and editing classes of the viewer such as:  
1894   * Default parameters of the viewer, 
1895   * Views (orthographic, perspective), 
1896   * Lighting (positional, directional, ambient, spot, headlight), 
1897   * Clipping planes (note that only Z-clipping planes can work with  the Phigs interface), 
1898   * Instantiated sequences of views, planes, light sources, graphic  structures, and picks, 
1899   * Various package methods. 
1900
1901 @subsubsection occt_visu_5_2_3 A programming example 
1902
1903 This sample TEST program for the *V3d* Package uses primary  packages *Xw* and *Graphic3d* and secondary packages *Visual3d, Aspect, Quantity,  Phigs* and *math*.  
1904
1905 ~~~~~
1906 //Create a default display  connection
1907 Handle(Aspect_DisplayConnection)  aDisplayConnection = new  Aspect_DisplayConnection(); 
1908
1909 //Create a Graphic Driver from  the default *Aspect_DisplayConnection* 
1910 Handle(Graphic3d_GraphicDriver)  GD = Graphic3d::InitGraphicDriver (aDisplayConnection);   
1911
1912 //Create a Viewer to this Driver 
1913 Handle(V3d_Viewer)  VM = new V3d_Viewer(GD, 400.,  
1914 // Space size  
1915 V3d_Xpos,// Default projection  Quantity_NOC_DARKVIOLET, 
1916 // Default  background  
1917 V3d_ZBUFFER, 
1918 // Type of  visualization  
1919 V3d_GOURAUD, 
1920 // Shading  model  
1921 V3d_WAIT); 
1922 // Update mode   
1923 *// Create a structure in this  Viewer * 
1924 Handle(Graphic3d_Structure) S =  
1925 new  Graphic3d_Structure(VM-Viewer()) ;  
1926
1927 *// Type of structure * 
1928 S-SetVisual (Graphic3d_TOS_SHADING);  
1929
1930 *// Create a group of primitives  in this structure*  
1931 Handle(Graphic3d_Group) G = new Graphic3d_Group(S) ;  
1932
1933 *// Fill this group with  one polygon of size 100*  
1934 Graphic3d_Array1OfVertex Points(0,3) ;  
1935 Points(0).SetCoord(-100./2.,-100./2.,-100./2.) ;  
1936 Points(1).SetCoord(-100./2., 100./2.,-100./2.) ;  
1937 Points(2).SetCoord( 100./2., 100./2.,-100./2.) ;  
1938 Points(3).SetCoord( 100./2.,-100./2.,-100./2.) ;  Normal.SetCoord(0.,0.,1.) ;  
1939 G-Polygon(Points,Normal) ;  
1940
1941 *//  Create Ambient and Infinite Lights in this Viewer* 
1942 Handle(V3d_AmbientLight) L1  = new V3d_AmbientLight  
1943 (VM,Quantity_NOC_GRAY50)  ;  
1944 Handle(V3d_DirectionalLight)  L2 = new V3d_DirectionalLight  
1945 (VM,V3d_XnegYnegZneg,Quantity_NOC_WHITE)  ;  
1946
1947 *// Create a 3D quality  Window with the same DisplayConnection* 
1948 Handle(Xw_Window) W =  
1949 new Xw_Window(aDisplayConnection,"Test  V3d",0.5,0.5,0.5,0.5) ;  
1950
1951 *// Map this Window to  this screen* 
1952  W-Map() ;  
1953
1954 *// Create a Perspective  View in this Viewer* 
1955 Handle(V3d_PerspectiveView) V =  
1956 new V3d_PerspectiveView(VM);  
1957
1958 *// Set the Eye position* 
1959 V-SetEye(100.,100.,100.) ;  
1960
1961 *// Associate this View  with the Window * 
1962 V-SetWindow(W) ;  
1963
1964 *// Activate ALL defined  Lights in this View * 
1965 V-SetLightOn() ;  
1966
1967 *// Display ALL  structures in this View * 
1968 (VM-Viewer())-Display() ;  
1969
1970 *// Finally update the  Visualization in this View * 
1971 V-Update() ;  
1972 ~~~~~
1973
1974 @subsubsection occt_visu_5_2_4 Glossary of  view transformations 
1975
1976 The following terms are used to define view orientation,  i.e. transformation from World Coordinates (WC) to the View Reference  Coordinates system (VRC): 
1977 * **View Reference Point (VRP)** - defines the origin of View Reference Coordinates.
1978 * **View Reference Plane Normal (VPN)** - defines the normal of projection plane of the view.
1979 * **View Reference Up Vector (VUP)** - defines the vertical of observer of the view.
1980
1981 The following terms are used to define view mapping, i.e.  transformation from View Reference Coordinates (VRC) to the Normalized  Projection Coordinates (NPC): 
1982 * **Projection type** - Orthographic or perspective.
1983 * **Projection Reference Point (PRP)** -        Defines the observer position. 
1984 * **Front Plane Distance (FPD)** -      Defines the position of the front clipping plane in View Reference Coordinates system.
1985 * **Back Plane Distance (BPD)** Defines the position of the back clipping plane in View Reference Coordinates system.
1986 * **View Plane Distance (VPD)** Defines the position of the view projection plane in View Reference Coordinates system. View plane must be located between front and back clipping planes. 
1987 * **Window Limits**     Defines the visible part of the view projection plane (left, right, top and bottom boundaries: *Umin, Umax, Vmax* and *Vmin* respectively) in View Reference Coordinates.
1988
1989 The *V3d_View* API uses the following terms to define view  orientation and mapping: 
1990 * **At** -      Position of View Reference Point (VRP) in World Coordinates
1991 * **Eye** -     Position of the observer (projection reference point) in World Coordinates. Influences to the view projection vector and depth value. 
1992 * **Proj** -    View projection vector (VPN)
1993 * **Up** -      Position of the high point / view up vector (VUP)
1994 * **Depth** - Distance between Eye and At point
1995 * **ZSize** - Distance between front and back clipping planes
1996 * **Size** - Window size in View Reference Coordinates 
1997 * **Focal Reference point** -   Position of Projection Reference Point (PRP) in World Coordinates
1998 * **Focale** -  Distance between Projection Reference Point (PRP) and View projection plane
1999
2000
2001 @subsubsection occt_visu_5_2_5 Management of  perspective projection 
2002
2003 The perspective projection allows definition of viewing  volume as a truncated pyramid (frustum) with apex at the Projection Reference  Point. In the View Reference Coordinate system it can be presented by the  following picture: 
2004
2005 @image html visualization_image023.png "View Reference Coordinate System, perspective viewing volume and view mapping parameter"
2006 @image latex visualization_image023.png "View Reference Coordinate System, perspective viewing volume and view mapping parameter"
2007   
2008 During panning, window limits are changed, as if a sort of  "frame" through which the user sees a portion of the view plane was moved over  the view. The perspective frustum itself remains unchanged.  
2009
2010 The perspective projection is defined by two parameters: 
2011   * *Depth* value defines distance between Projection Reference  Point and the nearest (front) clipping plane. 
2012   * *ZSize* defines distance between Front and Back clipping  planes. The influence of this parameter is caused by the OCCT specific to  center viewing volume around View Reference Point so the front and back plane  distances were the same: *FPD = BPD = ZSize / 2*.
2013   
2014 **Note** that the closer the displayed object to the  Projection Reference Point the more visible its perspective distortion. Thus,  in order to get a good perspective it is recommended to set **ZSize** value  comparable with the expected model size and small Depth value. 
2015
2016 However, very small  Depth values might lead to inaccuracy of "fit all" operation and to  non-realistic perspective distortion.  
2017
2018 Let us see the example:
2019 ~~~~~
2020 // Create a Perspective  View in Viewer VM
2021 Handle(V3d_PerspectiveView) V =  new V3d_PerspectiveView(VM);  
2022
2023 // Set the ZSize 
2024 V-SetZSize(2000.) ;  
2025
2026 // Set the Depth value
2027 V-SetDepth(20.) ;  
2028
2029 // Set the current  mapping as default to be used by  Reset() operation
2030 V-SetViewMappingDefault() ;  
2031 ~~~~~
2032
2033 As an alternative to  manual setting of perspective parameters the *V3d_View::DepthFitAll* function  can be used.  
2034
2035 ~~~~~
2036 // Display  shape in  Viewer VM
2037 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(VM);   
2038 aContext-Display(shape); 
2039
2040 // Create a Perspective  View in Viewer VM
2041 Handle(V3d_PerspectiveView) V =  new V3d_PerspectiveView(VM);  
2042
2043 // Set automatically  the perspective parameters
2044 V-DepthFitAll() ;  
2045
2046 // Fit view to object  size 
2047 V-FitAll(); 
2048
2049 // Set the current  mapping as default to be used by  Reset() operation
2050 V-SetViewMappingDefault() ;  
2051 ~~~~~
2052
2053 It is necessary to take  into account that during rotation Z size of the view might be modified  automatically to fit the model into the viewing volume.  
2054
2055 Make sure the Eye point  never gets between the Front and Back clipping planes.  
2056
2057 In perspective view,  changing Z size results in changed perspective effect. To avoid this, an  application should specify the maximum expected Z size using *V3d_View::SetZSize()* method in advance.  
2058
2059 *V3d_View::FitAll()*  with *FitZ = Standard_True* and *V3d_View::ZFitAll()* also change the perspective effect  and should therefore be used with precautions similar to those for rotation. 
2060
2061 @subsubsection occt_visu_5_2_6 Underlay and overlay layers management
2062
2063 In addition to interactive 3d graphics displayed in the view  you can display an underlying and overlying graphics: text, color scales,  drawings.  
2064
2065 All *V3d* view graphical objects in the overlay are  managed by the default layer manager (*V3d_LayerMgr*). The *V3d* view has a  basic layer manager capable of displaying the color scale, but you can redefine  this class to provide your own overlay and underlay graphics.  
2066
2067 The method *V3d_View::SetLayerMgr(const Handle (V3d_LayerMgr)& aMgr)* allows assigning a custom layer manager to the *V3d* view.
2068
2069 There are three virtual methods to prepare graphics in the  manager for further drawing (set up layer dimensions, draw static graphics).  These methods can be redefined: 
2070 ~~~~~
2071    void  V3d_LayerMgr::Begin ()
2072    void  V3d_LayerMgr::Redraw ()
2073    void V3d_LayerMgr::End  ()
2074 ~~~~~
2075
2076 The layer manager controls layers (*Visual3d_Layer*)  and layer items (*Visual3d_LayerItem*). Both the overlay and  underlay layers can be created by the layer manager.  
2077
2078 The layer entity is presented by the *Visual3d_Layer*  class. This entity provides drawing services in the layer, for example:
2079 ~~~~~ 
2080    void  Visual3d_Layer::DrawText
2081    void Visual3d_Layer::DrawRectangle
2082    void  Visual3d_Layer::SetColor
2083    void  Visual3d_Layer::SetViewport
2084 ~~~~~
2085 The following example demonstrates how to  draw overlay graphics by the *V3d_LayerMgr*: 
2086
2087 ~~~~~
2088 // redefined method of  V3d_LayerMgr
2089 void  MyLayerMgr::Redraw () 
2090
2091    Quantity_Color aRed (Quantity_NOC_RED); 
2092    myOverlayLayer-SetColor (aRed); 
2093    myOverlayLayer-DrawRectangle (0, 0, 100, 100); 
2094
2095 ~~~~~
2096
2097 The layer contains layer items that will be displayed on  view redraw. Such items are *Visual3d_LayerItem* entities. To manipulate *Visual3d_LayerItem* entities assigned to the layer’s internal list you can use  the following methods: 
2098
2099 ~~~~~
2100    void  Visual3d_Layer::AddLayerItem (const Handle (Visual3d_LayerItem)&  Item)  
2101    void  Visual3d_Layer::RemoveLayerItem (const Handle (Visual3d_LayerItem)&  Item)   
2102    void  Visual3d_Layer::RemoveAllLayerItems ()
2103    const  Visual3d_NListOfLayerItem& Visual3d_Layer::GetLayerItemList ()    
2104 ~~~~~
2105 The layer’s items are rendered when the method *void  Visual3d_Layer::RenderLayerItems()* is  called by the graphical driver.
2106
2107 The *Visual3d_LayerItem* has virtual methods that are  used to render the item: 
2108 ~~~~~
2109    void  Visual3d_LayerItem::RedrawLayerPrs () 
2110    void  Visual3d_LayerItem::ComputeLayerPrs () 
2111 ~~~~~
2112
2113 The item presentation can be computed before drawing by the *ComputeLayerPrs* method to save time on redraw. It also has an additional  flag that is used to tell that the presentation should be recomputed: 
2114 ~~~~~
2115    void  Visual3d_LayerItem::SetNeedToRecompute (const Standard_Boolean NeedToRecompute)  
2116    Standard_Boolean  Visual3d_LayerItem::IsNeedToRecompute 
2117 ~~~~~
2118
2119 An example of *Visual3d_LayerItem* is *V3d_ColorScaleLayerItem*  that represents the color scale entity as the layer’s item.  
2120 The *V3d_ColorScaleLayerItem* sends render requests to  the color scale entity represented by it. As this entity (*V3d_ColorScale*)  is assigned to the *V3d_LayerMgr* it uses its overlay layer’s services for  drawing: 
2121
2122 <h4>Example </h4>
2123
2124 ~~~~~
2125 // tell V3d_ColorScale to draw itself
2126 void  V3d_ColorScaleLayerItem::RedrawLayerPrs () 
2127
2128    Visual3d_LayerItem::RedrawLayerPrs () 
2129   if  (!MyColorScale.IsNull ()) 
2130     MyColorScale-DrawScale  (); 
2131
2132
2133 // V3d_ColorScale has a reference to a LayerMgr
2134 void  V3d_ColorScale::DrawScale () 
2135
2136     // calls *V3d_ColorScale::PaintRect,  V3d_ColorScale::PaintText, etc … 
2137
2138
2139 // PaintRect method uses overlay layer of LayerMgr to  draw a rectangle 
2140 void V3d_ColorScale::PaintRect   
2141        (const  Standard_Integer X, const Standard_Integer Y, 
2142         const  Standard_Integer W, const Standard_Integer H, 
2143         const  Quantity_Color aColor, 
2144         const  Standard_Boolean aFilled) 
2145
2146   const Handle  (Visual3d_Layer)& theLayer = 
2147                                   myLayerMgr-Overlay (); 
2148     …
2149    theLayer-SetColor (aColor); 
2150    theLayer-DrawRectangle (X, Y, W, H); 
2151     … 
2152
2153 ~~~~~
2154
2155 @subsubsection occt_visu_5_2_7 View background styles 
2156 There are three types of  background styles available for *V3d_view*: solid color, gradient color and  image.  
2157
2158 To set solid color for  the background you can use the following methods: 
2159 ~~~~~
2160    void  V3d_View::SetBackgroundColor
2161                 (const Quantity_TypeOfColor Type,  
2162                  const Quantity_Parameter V1, 
2163                  const Quantity_Parameter V2, 
2164                  const Quantity_Parameter V3) 
2165 ~~~~~
2166
2167 This method allows you to specify the background color in RGB (red,  green, blue) or HLS (hue, lightness, saturation) color spaces, so the  appropriate values of the Type parameter are *Quantity_TOC_RGB* and  *Quantity_TOC_HLS*. 
2168
2169 **Note** that the color  value parameters *V1,V2,V3* should be in the range between *0.0-1.0.* 
2170
2171 ~~~~~
2172   void  V3d_View::SetBackgroundColor(const Quantity_Color &Color)  
2173   void  V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)  
2174 ~~~~~
2175
2176 The gradient background  style could be set up with the following methods: 
2177 ~~~~~
2178   void  V3d_View::SetBgGradientColors
2179                 (const Quantity_Color& Color1,  
2180                  const Quantity_Color& Color2, 
2181                  const Aspect_GradientFillMethod  FillStyle, 
2182                  const Standard_Boolean update) 
2183                 
2184    void  V3d_View::SetBgGradientColors
2185                 (const Quantity_NameOfColor Color1,  
2186                  const Quantity_NameOfColor Color2, 
2187                  const Aspect_GradientFillMethod  FillStyle, 
2188                  const Standard_Boolean update) 
2189 ~~~~~
2190
2191 The *Color1* and *Color2* parameters define the boundary colors of  interpolation, the *FillStyle* parameter defines the direction of interpolation.  You can pass *Standard_True* as the last parameter to update the view.  
2192
2193 The fill style can be also set with the method *void  V3d_View::SetBgGradientStyle(const Aspect_GradientFillMethod AMethod, const Standard_Boolean update)*. 
2194
2195 To get the current  background color you can use the following methods: 
2196 ~~~~~
2197    void  V3d_View::BackgroundColor
2198                 (const Quantity_TypeOfColor Type,  
2199                  Quantity_Parameter &V1, 
2200                  Quantity_Parameter &V2, 
2201                  Quantity_Parameter &V3) 
2202    Quantity_Color  V3d_View::BackgroundColor()
2203    void V3d_View::GradientBackgroundColors(Quantity_Color& Color1, Quantity_Color& Color2) 
2204    Aspect_GradientBackground  GradientBackground()
2205 ~~~~~
2206    
2207 To set the image as a  background and change the background image style you can use the following  methods: 
2208 ~~~~~  
2209   * void V3d_View::SetBackgroundImage
2210                 (const Standard_CString FileName,  
2211                  const Aspect_FillMethod FillStyle, 
2212                  const Standard_Boolean update) 
2213   * void  V3d_View::SetBgImageStyle
2214                 (const Aspect_FillMethod FillStyle,  
2215                  const Standard_Boolean update) 
2216 ~~~~~
2217
2218 The *FileName* parameter defines the image file name and the path to it,  the *FillStyle* parameter defines the method of filling the background with the  image. The methods are:  
2219   * *Aspect_FM_NONE* -  draws the image in the default position;
2220   * *Aspect_FM_CENTERED* - draws the image at the center of the view;
2221   * *Aspect_FM_TILED* tiles the view with the image;
2222   * *Aspect_FM_STRETCH* stretches the image over the view.
2223
2224 @subsubsection occt_visu_5_2_8 User-defined  clipping planes
2225 The ability to define  custom clipping planes could be very useful for some tasks. The *V3d* view provides such an  opportunity.  
2226
2227 The *V3d_Plane* class provides the services of clipping  planes: it holds the plane equation coefficients and provides its graphical  representation. To set and get plane equation coefficients you can use the  following methods: 
2228 ~~~~~
2229   void  V3d_Plane::SetPlane
2230                 (const Quantity_Parameter A,  
2231                  const Quantity_Parameter B, 
2232                  const Quantity_Parameter C, 
2233                  const Quantity_Parameter D) 
2234   void V3d_Plane::Plane
2235                 (Quantity_Parameter& A,  
2236                  Quantity_Parameter& B, 
2237                  Quantity_Parameter& C, 
2238                  Quantity_Parameter& D) 
2239 ~~~~~
2240  *V3d_Plane* also provides display services: 
2241 ~~~~~
2242   * void  V3d_Plane::Display
2243                 (const Handle(V3d_View)& aView,  
2244                  const Quantity_Color& aColor) 
2245   * void V3d_Plane::Erase  ()
2246   * Standard_Boolean  V3d_Plane::IsDisplayed ()
2247 ~~~~~  
2248 The *Display*  method could be redefined to provide custom representation of the clipping  plane. 
2249
2250 The clipping planes could be activated with the methods *void  V3d_View::SetPlaneOn (const Handle(V3d_Plane)& MyPlane)*  and *void  V3d_View::SetPlaneOn()* 
2251
2252 The first method  appends the given *V3d_Plane* to the internal list of user-defined clipping  planes of a view and activates it. If the plane is already in the list, it  becomes activated. The second method activates all of the planes defined for  the view.  
2253
2254 The clipping planes could be deactivated  with the similar methods *void V3d_View::SetPlaneOff(const Handle(V3d_Plane)& MyPlane)* and *void  V3d_View::SetPlaneOff()*
2255
2256 The only difference is that these methods  remove the user-defined clipping planes from the internal list. Thus, the view  retains only active clipping planes.  
2257
2258 You can iterate through the active planes  using the following methods: 
2259   * *void  V3d_View::InitActivePlanes()* - sets  the iterator to the beginning of the internal list of clipping planes; 
2260   * *Standard_Boolean  V3d_View::MoreActivePlanes()* returns *Standard_True* if there are more active planes to return; 
2261   * *void  V3d_View::NextActivePlanes()* sets the iterator to the next active plane in the list; 
2262   * *Handle(V3d_Plane)  V3d_View::ActivePlane()* returns the active plane 
2263
2264 or check if a certain clipping plane has  been activated with method *Standard_Boolean V3d_View::IsActivePlane  (const  Handle (V3d_Plane)& aPlane)*
2265   
2266 The number of clipping  planes is limited. The method *Standard_Boolean V3d_View::IfMorePlanes()* allows checking if it is possible to activate at least one more plane  in the view or the limit has been reached.
2267   
2268 <h4>Example </h4>
2269
2270 ~~~~~
2271 // try to use an existing  clipping plane or create a new one
2272 Handle(V3d_Plane)  aCustomPlane; 
2273 myView-InitActivePlanes  (); 
2274 if  (myView-MoreActivePlanes ()) 
2275    aCustomPlane = myView-ActivePlane (); 
2276 else 
2277    aCustomPlane = new V3d_Plane (); 
2278
2279 // calculate new coefficients
2280 Standard_Real  a, b, c, d; 
2281 Standard_Real  x = 0.0, y = 0.0, z = 10.0; 
2282 Standard_Real  dx = 0.0, dy = 0.0, dz = 1.0; 
2283 gp_Pln  aPln (gp_Pnt (x, y, z), gp_Dir (dx, dy, dz)); 
2284 aPln.Coefficients  (a, b, c, d); 
2285
2286 // update plane
2287 aCustomPlane-SetPlane  (a, b, c, d); 
2288 myView-SetPlaneOn  (aCustomPlane); 
2289 ~~~~~
2290
2291 @subsubsection occt_visu_5_2_9 Dumping a 3D scene into an image file
2292 The 3D scene displayed in the view could be  dumped in high resolution into an image file. The high resolution (8192x8192 on  some implementations) is achieved using the Frame Buffer Objects (FBO) provided  by the graphic driver. Frame Buffer Objects enable off-screen rendering into a  virtual view to produce images in the background mode (without displaying any  graphics on the screen). 
2293
2294 The *V3d_View* has the following methods for  dumping the 3D scene: 
2295 * *Standard_Boolean  V3d_View::Dump (const Standard_CString theFile, const Image_TypeOfImage theBufferType)* - dumps the scene into an image file with the view  dimensions.
2296 * *Standard_Boolean  V3d_View::Dump (const Standard_CString theFile, const Aspect_FormatOfSheetPaper  theFormat, const Image_TypeOfImage theBufferType)* - allows making the dimensions of the output image compatible to a certain format of printing paper passed by *theFormat* argument.  
2297   
2298 These methods dump the 3D scene into an image file passed by its name  and path as theFile.  
2299
2300 The raster image data handling algorithm is based on the Image_PixMap  class. The supported extensions are ".png", ".bmp", ".png", ".png".  
2301
2302 The value passed as *theBufferType* argument defines the type of the  buffer for an output image *(RGB, RGBA, floating-point, RGBF, RGBAF)*. Both  methods return *Standard_True* if the scene has been successfully dumped.  
2303
2304 **Note** that dumping the image for a paper format with  large dimensions is a memory consuming operation, it might be necessary to take  care of preparing enough free memory to perform this operation. 
2305
2306 * Handle_Image_PixMap  V3d_View::ToPixMap (const Standard_Integer theWidth, const Standard_Integer theHeight, const Image_TypeOfImage theBufferType, const Standard_Boolean theForceCentered)* allows dumping the displayed 3d scene into a pixmap  with a width and height passed as *theWidth* and theHeight arguments.  
2307
2308 The value passed as *theBufferType* argument defines the type of the  buffer for a pixmap *(RGB, RGBA, floating-point, RGBF, RGBAF)*.  The last parameter allows centering the 3D scene on dumping. 
2309
2310 All these methods assume that you have  created a view and displayed a 3d scene in it. However, the window used for  such a view could be virtual, so you can dump the 3d scene in the background  mode without displaying it on the screen. To use such an opportunity you can  perform the following steps: 
2311 * Create display connection; 
2312 * Initialize graphic driver; 
2313 * Create a window; 
2314 * Set up the window as virtual, *Aspect_Window::SetVirtual()* ; 
2315 * Create a view and an interactive context; 
2316 * Assign the virtual window to the view; 
2317 * Display a 3D scene; 
2318 *  Use one of the functions described above to dump the 3D scene. 
2319
2320 The following example demonstrates this  procedure for *WNT_Window* : 
2321
2322 ~~~~~
2323 // create a dummy display  connection
2324 Handle(Aspect_DisplayConnection)  aDisplayConnection;
2325
2326 // create a graphic driver
2327 Handle  (Graphic3d_GraphicDriver) aDriver = Graphic3d::InitGraphicDriver (aDisplayConnection); 
2328
2329 // create a window
2330 Standard_Integer  aDefWidth  = 800; 
2331 Standard_Integer  aDefHeight = 600; 
2332 Handle  (WNT_WClass) aWClass =  
2333               new WNT_WClass ("Virtual Class",DefWindowProc, 
2334                               CS_VREDRAW | CS_HREDRAW, 0, 0,  
2335                               ::LoadCursor (NULL, IDC_ARROW)); 
2336 Handle  (WNT_Window) aWindow =  
2337               new WNT_Window ("VirtualWnd",  aWClass,  
2338                               WS_OVERLAPPEDWINDOW, 0, 0,  
2339                               aDefWidth, aDefHeight); 
2340
2341 // set up the window as  virtual
2342 aWindow-SetVirtual  (Standard_True); 
2343
2344 // create a view and an  interactive context
2345 Handle  (V3d_Viewer) aViewer =  
2346               new V3d_Viewer (aDriver, 
2347                               Standard_ExtString ("Virtual")); 
2348 Handle  (AIS_InteractiveContext) aContext = 
2349               new AIS_InteractiveContext (aViewer); 
2350 Handle  (V3d_View) aView = aViewer-CreateView (); 
2351
2352 // assign the virtual window  to the view
2353 aView-SetWindow  (aWindow); 
2354
2355 // display a 3D scene
2356 Handle  (AIS_Shape) aBox =  
2357               new AIS_Shape (BRepPrimAPI_MakeBox (5, 5, 5)); 
2358 aContext-Display  (aBox); 
2359 aView-FitAll(); 
2360
2361 // dump the 3D scene into an  image file
2362 aView-Dump  ("3dscene.png"); 
2363 ~~~~~
2364
2365 @subsubsection occt_visu_5_2_10 Printing a 3D scene
2366
2367 The contents of a view can be printed out. Moreover, the OpenGl graphic driver used by the v3d view supports printing in high  resolution. The print method uses the OpenGl frame buffer (Frame Buffer Object)  for rendering the view contents and advanced print algorithms that allow  printing in, theoretically, any resolution.  
2368
2369 The method *void V3d_View::Print(const Aspect_Handle hPrnDC, const Standard_Boolean showDialog, const Standard_Boolean showBackground, const Standard_CString  filename, const Aspect_PrintAlgo printAlgorithm)* prints the view  contents: 
2370
2371 *hPrnDC* is the printer device handle. You can pass your own printer handle  or "NULL" to select the printer by the default dialog. In that case you can use  the default dialog or pass "Standard_False" as the showDialog argument to  select the default printer automatically.  
2372
2373 You can define  the filename for the printer driver if you want to print out the result into a  file.  
2374 If you do not want to print the  background, you can pass *Standard_False* as the *showBackground* argument. 
2375 The *printAlgorithm* argument allows choosing between two print algorithms that  define how the 3d scene is mapped to the print area when the maximum dimensions of the frame buffer are smaller than the dimensions of the print area by choosing *Aspect_PA_STRETCH* or *Aspect_PA_TILE*
2376
2377 The first value  defines the stretch algorithm: the scene is drawn with the maximum possible  frame buffer dimensions and then is stretched to the whole printing area. The  second value defines *TileSplit* algorithm: covering the whole printing area by  rendering multiple parts of the viewer. 
2378
2379 **Note** that at the moment printing is implemented only for Windows. 
2380
2381 @subsubsection occt_visu_5_2_11 Vector image export
2382
2383 The 3D content of a view can be exported to  the vector image file format. The vector image export is powered by the GL2PS  library. You can export your 3D scenes into a file format supported by the  GL2PS library: PostScript (PS), Encapsulated PostScript (EPS), Portable  Document Format (PDF), Scalable Vector Graphics (SVG), LaTeX file format and  Portable LaTeX Graphics (PGF).  
2384
2385 The method   *void  Visual3d_View::Export (const Standard_CString FileName, const Graphic3d_ExportFormat Format, const Graphic3d_SortType aSortType, const Standard_Real Precision, const Standard_Address ProgressBarFunc, const Standard_Address ProgressObject)* of *Visual3d_View* class  allows exporting a 3D scene: 
2386
2387 The *FileName*  defines the output image file name and the *Format* argument defines the output  file format:  
2388   * Graphic3d_EF_PostScript  (PS),
2389   * Graphic3d_EF_EhnPostScript  (EPS),
2390   * Graphic3d_EF_TEX  (TEX), 
2391   * Graphic3d_EF_PDF  (PDF),
2392   * Graphic3d_EF_SVG  (SVG),
2393   * Graphic3d_EF_PGF  (PGF)
2394
2395 The *aSortType* parameter defines *GL2PS* sorting algorithm for the  primitives. The *Precision, ProgressBarFunc* and *ProgressObject* parameters are  implemented for future uses and at the moment have no effect. 
2396
2397 The *Export* method supports only basic 3d  graphics and has several limitations: 
2398   * Rendering large scenes could be slow and  can lead to large output files;
2399   * Transparency is only supported for PDF and  SVG output;
2400   * Textures and some effects are not supported by  the GL2PS library.
2401
2402 @section occt_visu_6 Graphic Attributes
2403
2404 @subsection occt_visu_6_1 Aspect Package
2405
2406 The *Aspect* package provides classes for the graphic elements in the viewer:
2407   * Color maps,  
2408   * Pixels,  
2409   * Groups of graphic attributes,  
2410   * Edges, lines, background,  
2411   * Font classes,  
2412   * Width map classes,  
2413   * Marker map classes,  
2414   * Type of Line map classes,  
2415   * Window,  
2416   * Driver, PlotterDriver (inherited by  PS_Driver), WindowDriver,  
2417   * Enumerations for many of the above,  
2418   * Array instantiations for edges,  
2419   * Array instantiations for map entries for  color, type, font, width, and marker. 
2420
2421