From: ysn Date: Thu, 9 Oct 2014 12:33:21 +0000 (+0400) Subject: 0022859: Developers guide with code samples X-Git-Tag: V6_8_0_beta~9 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=beb18c1f6e98d118b7bc49251f3443824e72fa6f 0022859: Developers guide with code samples A user's guide for VTK Interactive Services has been added in the documentation quick fix Minor corrections in documentation syntax --- diff --git a/dox/FILES_HTML.txt b/dox/FILES_HTML.txt index 6f8c3948d1..c3e94b4bba 100644 --- a/dox/FILES_HTML.txt +++ b/dox/FILES_HTML.txt @@ -32,6 +32,7 @@ user_guides/ocaf_functionmechanism_wp/ocaf_functionmechanism_wp.md user_guides/ocaf_tree_wp/ocaf_tree_wp.md user_guides/ocaf_wp/ocaf_wp.md user_guides/voxels_wp/voxels_wp.md +user_guides/vis/vis.md dev_guides/dev_guides.md dev_guides/documentation/documentation.md diff --git a/dox/FILES_PDF.txt b/dox/FILES_PDF.txt index 9d17f162bb..2be9c76d3a 100644 --- a/dox/FILES_PDF.txt +++ b/dox/FILES_PDF.txt @@ -21,6 +21,7 @@ user_guides/tobj/tobj.md user_guides/visualization/visualization.md user_guides/voxels_wp/voxels_wp.md user_guides/xde/xde.md +user_guides/vis/vis.md dev_guides/contribution_workflow/contribution_workflow.md dev_guides/documentation/documentation.md diff --git a/dox/dev_guides/building/android/android.md b/dox/dev_guides/building/android/android.md index 8f21cb69ca..5408efff68 100644 --- a/dox/dev_guides/building/android/android.md +++ b/dox/dev_guides/building/android/android.md @@ -17,7 +17,7 @@ with following tools: Run GUI tool provided by CMake: cmake-gui ### Tools configuration - - Specify the root folder of OCCT ($CASROOT, which contains *CMakelists.txt* file) by clicking **Browse Source**. + - Specify the root folder of OCCT ($CASROOT, which contains *CMakelists.txt* file) by clicking **Browse Source**. - Specify the location (build folder) for Cmake generated project files by clicking **Browse Build**. @figure{/dev_guides/building/android/images/android_image001.png} diff --git a/dox/dev_guides/building/cmake/cmake.md b/dox/dev_guides/building/cmake/cmake.md index ae63555e6b..5e6e93eb3c 100644 --- a/dox/dev_guides/building/cmake/cmake.md +++ b/dox/dev_guides/building/cmake/cmake.md @@ -189,8 +189,8 @@ The install folder contains the scripts to run *DRAWEXE* (*draw.bat* or *draw.sh * **samples** - tcl sample files * **src** - all required source files for OCCT * **tests** - OCCT test suite -* **win32/vc10/bind**> - example relative directory tree of binary files (3rdparty and occt) (the abstract one is //bin) -* **win32/vc9/lib**> - example relative directory tree of libraries (3rdparty and occt) (the abstract one is //lib) +* **win32/vc10/bind**> - example relative directory tree of binary files (3rdparty and occt) +* **win32/vc9/lib**> - example relative directory tree of libraries (3rdparty and occt) ### Windows (Visual studio) @@ -228,4 +228,4 @@ On Windows you can also build binaries of MFC samples together with OCCT. For th @figure{/dev_guides/building/cmake/images/cmake_image007.png} Please take into account that MFC sample binaries will be installed in the same folder as OCCT binaries during building of *INSTALL* project. -To run an MFC sample use *sample.bat* launcher. The command format is: sample.bat (e.g. sample.bat ImportExport). +To run an MFC sample use *sample.bat* launcher. The command format is: sample.bat *SampleName* (e.g. sample.bat ImportExport). diff --git a/dox/user_guides/user_guides.md b/dox/user_guides/user_guides.md index 10b9011891..70b1a20a72 100644 --- a/dox/user_guides/user_guides.md +++ b/dox/user_guides/user_guides.md @@ -11,6 +11,7 @@ OCCT User Guides are organized by OCCT modules: * @subpage occt_user_guides__shape_healing "Shape Healing" * @subpage occt_user_guides__visualization "Visualization" * @subpage occt_user_guides__voxels_wp "Voxels" + * @subpage occt_user_guides__vis "VTK Integration Services" * Data Exchange * @subpage occt_user_guides__iges "IGES translator" * @subpage occt_user_guides__step "STEP translator" diff --git a/dox/user_guides/vis/images/vis_image001.png b/dox/user_guides/vis/images/vis_image001.png new file mode 100644 index 0000000000..aaad6168b8 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image001.png differ diff --git a/dox/user_guides/vis/images/vis_image002.png b/dox/user_guides/vis/images/vis_image002.png new file mode 100644 index 0000000000..2e3bd055a9 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image002.png differ diff --git a/dox/user_guides/vis/images/vis_image003.png b/dox/user_guides/vis/images/vis_image003.png new file mode 100644 index 0000000000..fc92ee036b Binary files /dev/null and b/dox/user_guides/vis/images/vis_image003.png differ diff --git a/dox/user_guides/vis/images/vis_image004.png b/dox/user_guides/vis/images/vis_image004.png new file mode 100644 index 0000000000..1367d89ef8 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image004.png differ diff --git a/dox/user_guides/vis/images/vis_image005.png b/dox/user_guides/vis/images/vis_image005.png new file mode 100644 index 0000000000..639fe0fdc9 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image005.png differ diff --git a/dox/user_guides/vis/images/vis_image006.png b/dox/user_guides/vis/images/vis_image006.png new file mode 100644 index 0000000000..583c35bde4 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image006.png differ diff --git a/dox/user_guides/vis/images/vis_image007.png b/dox/user_guides/vis/images/vis_image007.png new file mode 100644 index 0000000000..4c812997b5 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image007.png differ diff --git a/dox/user_guides/vis/images/vis_image008.png b/dox/user_guides/vis/images/vis_image008.png new file mode 100644 index 0000000000..02c6649a14 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image008.png differ diff --git a/dox/user_guides/vis/images/vis_image009.png b/dox/user_guides/vis/images/vis_image009.png new file mode 100644 index 0000000000..aaf20555e3 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image009.png differ diff --git a/dox/user_guides/vis/images/vis_image010.png b/dox/user_guides/vis/images/vis_image010.png new file mode 100644 index 0000000000..8e0aaac70e Binary files /dev/null and b/dox/user_guides/vis/images/vis_image010.png differ diff --git a/dox/user_guides/vis/images/vis_image011.png b/dox/user_guides/vis/images/vis_image011.png new file mode 100644 index 0000000000..8fdd9f2819 Binary files /dev/null and b/dox/user_guides/vis/images/vis_image011.png differ diff --git a/dox/user_guides/vis/images/vis_image012.png b/dox/user_guides/vis/images/vis_image012.png new file mode 100644 index 0000000000..7f886c161f Binary files /dev/null and b/dox/user_guides/vis/images/vis_image012.png differ diff --git a/dox/user_guides/vis/images/vis_image013.png b/dox/user_guides/vis/images/vis_image013.png new file mode 100644 index 0000000000..99eaa9545e Binary files /dev/null and b/dox/user_guides/vis/images/vis_image013.png differ diff --git a/dox/user_guides/vis/vis.md b/dox/user_guides/vis/vis.md new file mode 100644 index 0000000000..be40d47241 --- /dev/null +++ b/dox/user_guides/vis/vis.md @@ -0,0 +1,540 @@ + VTK Integration Services (VIS) {#occt_user_guides__vis} +============================ + +@tableofcontents + +@section occt_vis_1 Introduction +VIS component provides adaptation functionality for visualization of OCCT topological shapes by means of VTK library. This User’s Guide describes how to apply VIS classes in application dealing with 3D visualization based on VTK library. + +@figure{/user_guides/vis/images/vis_image001.png} + +There are two ways to use VIS in the application: +* Use a **high-level API**. It is a simple scenario to use VTK viewer with displayed OCCT shapes. It considers usage of tools provided with VIS component such as a specific VTK data source, a picker class and specific VTK filters. Basically, in this scenario you enrich your custom VTK pipeline with extensions coming from VIS. +* Use a **low-level API**. It is an advanced scenario for the users with specific needs, which are not addressed by the higher-level utilities of VIS. It presumes implementation of custom VTK algorithms (such as filters) with help of low-level API of VIS component. +This document describes both scenarios of VIS integration into application. To understand this document, it is necessary to be familiar with VTK and OCCT libraries. + +@section occt_vis_2 Component Architecture +@subsection occt_vis_2_1 Common structure +VIS component consists of the following packages: +* **IVtk** – common interfaces which define the principal objects playing as foundation of VIS. +* **IVtkOCC** – implementation of interfaces related to CAD domain. The classes from this package deal with topological shapes, faceting and interactive selection facilities of OCCT; +* **IVtkVTK** – implementation of interfaces related to VTK visualization toolkit; +* **IVtkTools** – high-level tools designed for integration into VTK visualization pipelines. + +@figure{/user_guides/vis/images/vis_image002.png "Dependencies of VIS packages"} + +The idea behind the mentioned organization of packages is separation of interfaces from their actual implementations by their dependencies from a particular library (OCCT, VTK). Besides providing of semantic separation, such splitting helps to avoid excessive dependencies on other OCCT toolkits and VTK. +* **IVtk** package does not depend on VTK libraries at all and needs OCCT libraries only because of collections usage (*TKernel* library); +* Implementation classes from **IVtkOCC** package depend on OCCT libraries only and do not need VTK; +* **IVtkVTK** package depends on VTK libraries only and does not need any OCCT functionality except collections. + +@figure{/user_guides/vis/images/vis_image003.png "Dependencies of VIS packages"} + +Basically, it is enough to use the first three packages in the end user’s application (*IVtk, IVtkOCC* and *IVtkVTK*) to be able to work with OCCT shapes in VTK viewer. However, *IVtkTools* package is also provided as a part of the component to make the work more comfortable. + + +@subsection occt_vis_2_2 IVtk package +**IVtk** package contains the following classes: +* *IVtk_Interface* - Base class for all interfaces of the component. Provides inheritance for *Handle* (OCCT “smart pointer”) functionality. +* *IVtk_IShape* - Represents a 3D shape of arbitrary nature. Provides its ID property. Implementation of this interface should maintain unique IDs for all visualized shapes. These IDs can be easily converted into original shape objects at the application level. +* *IVtk_IShapeData* - Represents faceted data. Provides methods for adding coordinates and cells (vertices, lines, triangles). +* *IVtk_IShapeMesher* - Interface for faceting, i.e. constructing *IVtk_IShapeData* from *IVtk_IShape* input shape. +* *IVtk_IShapePickerAlgo* - Algorithmic interface for interactive picking of shapes in a scene. Provides methods for finding shapes and their parts (sub-shapes) at a given location according to the chosen selection mode. +* *IVtk_IView* Interface for obtaining view transformation parameters. It is used by *IVtk_IShapePickerAlgo*. + +@subsection occt_vis_2_3 IVtkOCC package + +**IVtkOCC** package contains the implementation of classes depending on OCCT: +* *IVtkOCC_Shape* - Implementation of *IVtk_IShape* interface as a wrapper for *TopoDS_Shape*. +* *IVtkOCC_ShapeMesher* - Implementation of *IVtk_IShapeMesher* interface for construction of facets from *TopoDS* shapes. +* *IVtkOCC_ShapePickerAlgo* Implementation of interactive picking algorithm. It provides enabling/disabling of selection modes for shapes (*IVtk_IShape* instances) and picking facilities for a given position of cursor. +* *IVtkOCC_ViewerSelector* - Interactive selector, which implements *Pick()* methods for the picking algorithm *IVtkOCC_ShapePickerAlgo* and connects to the visualization layer with help of abstract *IView* interface. + +*IVtkOCC_ViewerSelector* is a descendant of OCCT native *SelectMgr_ViewerSelector*, so it implements OCCT selection mechanism for *IVtkVTK_View* (similarly to *StdSelect_ViewerSelector3D* which implements *SelectMgr_ViewerSelector* for OCCT native *V3d_View*). *IVtkOCC_ViewerSelector* encapsulates all projection transformations for the picking mechanism. These transformations are extracted from *vtkCamera* instance available via VTK Renderer. *IVtkOCC_ViewerSelector* operates with native OCCT *SelectMgr_Selection* entities. Each entity represents one selection mode of an OCCT selectable object. *ViewerSelector* is an internal class, so it is not a part of the public API. +* *IVtkOCC_SelectableObject* - OCCT shape wrapper used in the picking algorithm for computation of selection primitives of a shape for a chosen selection mode. + +@subsection occt_vis_2_4 IVtkVtk package +**IVtkVTK** package contains implementation classes depending on VTK: +* *IVtkVTK_ShapeData* - Implementation of *IVtk_IShapeData* interface for VTK polydata. This class also stores information related to sub-shape IDs and sub-shape mesh type *IVtk_MeshType* (free vertex, shared vertex, free edge, boundary edge, shared edge, wireframe face or shaded face). This information is stored in VTK data arrays for cells. +* *IVtkVTK_View* - Implementation of *IVtk_IView* interface for VTK viewer. This implementation class is used to connect *IVtkOCC_ViewerSelector* to VTK renderer. + +@subsection occt_vis_2_5 IVtkTools package +**IVtkTools** package gives you a ready-to-use toolbox of algorithms facilitating the integration of OCCT shapes into visualization pipeline of VTK. This package contains the following classes: +* *IVtkTools_ShapeDataSource* - VTK polygonal data source for OCCT shapes. It inherits *vtkPolyDataAlgorithm* class and provides a faceted representation of OCCT shape for visualization pipelines. +* *IVtkTools_ShapeObject* - Auxiliary wrapper class for OCCT shapes to pass them through pipelines by means of VTK information keys. +* *IVtkTools_ShapePicker* - VTK picker for shape actors. Uses OCCT selection algorithm internally. +* *IVtkTools_DisplayModeFilter* - VTK filter for extracting cells of a particular mesh type according to a given display mode *IVtk_DisplayMode* (Wireframe or Shading). +* *IVtkTools_SubPolyDataFilter* - VTK filter for extracting the cells corresponding to a given set of sub-shape IDs. + +Additionally, *IVtkTools* package contains auxiliary methods in *IVtkTools* namespace. E.g. there is a convenience function populating *vtkLookupTable* instances to set up a color scheme for better visualization of sub-shapes. + +@section occt_vis_3 Using high-level API (simple scenario) +@subsection occt_vis_3_1 OCCT shape presentation in VTK viewer + +To visualize an OCCT topological shape in VTK viewer, it is necessary to perform the following steps: + +1. Create *IVtkOCC_Shape* instance (VIS wrapper for OCCT shape) and initialize it with *TopoDS_Shape* object containing the actual geometry: +~~~~ +TopoDS_Shape aShape; + +// Initialize aShape variable: e.g. load it from BREP file + +IVtkOCC_Shape::Handle aShapeImpl = new IVtkOCC_Shape(aShape); +~~~~ +2. Create VTK polygonal data source for the target OCCT topological shape and initialize it with created *IVtkOCC_Shape* instance. At this stage the faceter is implicitly plugged: +~~~~ +vtkSmartPointer DS = vtkSmartPointer::New(); + +DS->SetShape(aShapeImpl); +~~~~ +3. Visualize the loaded shape in usual VTK way starting a pipeline from the newly created specific source: +~~~~ +vtkSmartPointer Mapper = vtkSmartPointer::New(); + +Mapper->SetInputConnection(aDS->GetOutputPort()); +vtkSmartPointer Actor = vtkSmartPointer::New(); + +Actor->SetMapper(Mapper); +~~~~ + +It is always possible to access the shape data source from VTK actor by means of dedicated methods from *IVtkTools_ShapeObject* class: +~~~~ +IVtkTools_ShapeDataSource* DS = IVtkTools_ShapeObject::GetShapeSource(Actor); + +IVtkOCC_Shape::Handle occShape = IVtkTools_ShapeObject::GetOccShape(Actor); +~~~~ + +It is also possible to get a shape wrapper from the shape data source: +~~~~ +IVtkOCC_Shape::Handle occShape = DS->GetShape(); +~~~~ + +@subsection occt_vis_3_2 Color schemes +@subsubsection occt_vis_3_2_1 Default OCCT color scheme + +To colorize different parts of a shape according to the default OCCT color scheme, it is possible to configure the corresponding VTK mapper using a dedicated auxiliary function of *IVtkTools* namespace: + +~~~~ +IVtkTools::InitShapeMapper(Mapper); +~~~~ +It is possible to get an instance of *vtkLookupTable class* with a default OCCT color scheme by means of the following method: + +~~~~ +vtkLookupTable* Table = IVtkTools::InitLookupTable(); +~~~~ + +@subsubsection occt_vis_3_2_2 Custom color scheme +To set up application-specific colors for a shape presentation, use *InitShapeMapper* function with an additional argument passing a custom lookup table: + +~~~~ +IVtkTools::InitShapeMapper(Mapper, Table); +~~~~ + +@subsubsection occt_vis_3_2_3 Setting custom colors for sub-shapes + +It is also possible to bind custom colors to any sub-shape type listed in *IVtk_MeshType* enumeration. For example, to access the color bound to *free edge* entities, the following calls are available in *IVtkTools* namespace: +~~~~ +SetLookupTableColor(aLookupTable, MT_FreeEdge, R, G, B); +SetLookupTableColor(aLookupTable, MT_FreeEdge, R, G, B, A); +GetLookupTableColor(aLookupTable, MT_FreeEdge, R, G, B); +GetLookupTableColor(aLookupTable, MT_FreeEdge, R, G, B, A); +~~~~ +Here *R, G, B* are double values of red, green and blue components of a color from the range [0, 1]. The optional parameter *A* stands for the alpha value (the opacity) as a double from the same range [0, 1]. By default alpha value is 1, i.e. a color is not transparent. + +@subsubsection occt_vis_3_2_4 Using color scheme of mapper + +As VTK color mapping approach is based on associating scalar data arrays to VTK cells, the coloring of shape components can be turned on/off in the following way: + +~~~~ +Mapper->ScalarVisibilityOn(); // use colors from lookup table +Mapper->ScalarVisibilityOff(); // use a color of actor’s property +~~~~ + +For example, the scalar-based coloring can be disabled to bind a single color to the entire VTK actor representing the shape. + +@subsection occt_vis_3_3 Display modes +The output of the shape data source can be presented in wireframe or shading display mode. A specific filter from class *IVtkTools_DisplayModeFilter* can be applied to select the display mode. The filter passes only the cells corresponding to the given mode. The set of available modes is defined by *IVtk_DisplayMode* enumeration. + +@figure{/user_guides/vis/images/vis_image004.png} + +For example, the shading representation can be obtained in the following way: + +~~~~ +vtkSmartPointer DS = vtkSmartPointer::New(); + +vtkSmartPointer DMFilter = vtkSmartPointer::New(); + +DMFilter->AddInputConnection(DS->GetOutputPort()); +DMFilter->SetDisplayMode(DM_Shading); + +vtkSmartPointer M = vtkSmartPointer::New(); +M->SetInputConnection(DMFilter->GetOutputPort()); +~~~~ + +By default, the display mode filter works in a wireframe mode. + +TIP: to make the shading representation smooth, use additional *vtkPolyDataNormals* filter. This filter must be applied after the display mode filter. + +@figure{/user_guides/vis/images/vis_image005.png} + +@subsection occt_vis_3_4 Interactive selection +*IVtkTools* package provides *IVtkTools_ShapePicker* class to perform selection of OCCT shapes and sub-shapes in VTK viewer and access the picking results. The typical usage of *IVtkTools_ShapePicker* tool consists in the following sequence of actions: +1. Create a picker and set its renderer to your active VTK renderer: +~~~~ +vtkSmartPointer aPicker = vtkSmartPointer::New(); + +aPicker->SetRenderer(aRenderer); +~~~~ +2. Activate the desired selection mode by choosing the corresponding sub-shape types from *IVtk_SelectionMode* enumeration. For example, the following call allows selection of edges on all selectable shape actors of the renderer: +~~~~ +aPicker->SetSelectionMode(SM_Edge); +~~~~ +If it is necessary to limit selection by a particular shape actor, one can use the mentioned *SetSelectionMode* method with *IVtk_IShape* handle or *vtkActor* pointer as the first argument: +~~~~ +IVtk_IShape::Handle aShape = new IVtkOCC_Shape(occShape); +aPicker->SetSelectionMode(aShape, SM_Edge); // If shape handle is available +aPicker->SetSelectionMode(anActor, SM_Edge); // If shape actor is available +~~~~ +Different selection modes can be turned on/off for a picker at the same time independently from each other. +~~~~ +aPicker->SetSelectionMode(SM_Edge); +aPicker->SetSelectionMode(SM_Face); +~~~~ +To turn off a selection mode, the additional optional Boolean parameter is used with *false* value, for example: +~~~~ +aPicker->SetSelectionMode(aShape, SM_Edge, false); +~~~~ +3. Call *Pick* method passing the mouse display coordinates: +~~~~ +aPicker->Pick(x, y, 0); +~~~~ +By default, the renderer passed in the step 1 is used. In order to perform pick operation for another renderer an additional optional parameter can be specified: +~~~~ +aPicker->Pick(x, y, 0, aRenderer); +~~~~ +4. Obtain the top-level picking results as a collection of picked VTK actors: +~~~~ +vtkActorCollection* anActorCollection = aPicker->GetPickedActors(); +~~~~ +or as a collection of picked shape IDs: +~~~~ +IVtk_ShapeIdList ids = aPicker->GetPickedShapesIds(); +~~~~ +These methods return a single top picked actor or a shape by default. To get all the picked actors or shapes it is necessary to send “true” value in the optional Boolean parameter: +~~~~ +anActorCollection = aPicker->GetPickedActors(true); +ids = aPicker->GetPickedShapesIds(true); +~~~~ +5. Obtain the picked sub-shape IDs: +~~~~ +IVtk_ShapeIdList subShapeIds = aPicker->GetPickedSubShapesIds(shapeId); +~~~~ +This method also returns a single ID of a top-level picked sub-shape and has the same optional Boolean parameter to get all the picked sub-shapes of a shape: +~~~~ +subShapeIds = aPicker->GetPickedSubShapesIds(shapeId, true); +~~~~ + +It should be noted that it is more efficient to create a sole picker instance and feed it with the renderer only once. The matter is that the picking algorithm performs internal calculations each time the renderer or some of its parameters are changed. Therefore, it makes sense to minimize the number of such updates. + +OCCT picking algorithm *IVtkTools_ShapePicker* calculates a new transformation matrix for building of projection each time some parameters of a view are changed. Likewise, the shape selection primitives for each selection mode are built once an appropriate selection mode is turned on for this shape in *SetSelectionMode* method. + +WARNING: VIS picker essentially works on the initial topological data structures rather than on the actually visualized actors. This peculiarity allows VIS to take advantage of standard OCCT selection mechanism, but puts strict limitations on the corresponding visualization pipelines. Once constructed, the faceted shape representation should not be morphed or translated anyhow. Otherwise, the picking results will lose their associativity with the source geometry. E.g. you should never use *vtkTransform* filter, but rather apply OCCT isometric transformation on the initial model in order to work on already relocated facet. These limitations are often acceptable for CAD visualization. If not, consider usage of a custom VTK-style picker working on the actually visualized actors. + +@figure{/user_guides/vis/images/vis_image006.png} + +@subsubsection occt_vis_3_5 Selection of sub-shapes + +*IVtkTools_SubPolyDataFilter* is a handy VTK filter class which allows extraction of polygonal cells corresponding to the sub-shapes of the initial shape. It can be used to produce a *vtkPolyData* object from the input *vtkPolyData* object, using selection results from *IVTkTools_ShapePicker* tool. + +For example, sub-shapes can be represented in VTK viewer in the following way: + +~~~~ +// Load a shape into data source (see 3.1) +... +vtkSmartPointer DS = vtkSmartPointer::New(); + +DS->SetShape(shapeImpl); +... + +// Create a new sub-polydata filter for sub-shapes filtering +vtkSmartPointer subShapesFilter = IVtkTools_SubPolyDataFilter::New(); + +// Set a shape source as an input of the subpolydata filter +subShapesFilter->SetInputConnection(DS->GetOutputPort()); + +// Get all picked sub-shapes ids of the shape from a picker (see 3.4) +IVtk_ShapeIdList subShapeIds = aPicker->GetPickedSubShapesIds(ds->GetId(), true); + +// Set ids to the filter to pass only picked sub-shapes +subShapesFilter->SetData(subShapeIds); +subShapesFilter->Modified(); + +// Output the result into a mapper +vtkSmartPointer aMapper = vtkPolyDataMapper::New(); +aMapper->AddInputConnection(subShapesFilter->GetOutputPort()); +... +~~~~ + +@section occt_vis_4 Using of low-level API (advanced scenario) +@subsection occt_vis_4_1 Shape presentation +The usage of low-level tools is justified in cases when the utilities from *IVtkTools* are not enough. + +The low-level scenario of VIS usage in VTK pipeline is shown in the figure below. The Mesher component produces shape facet (VTK polygonal data) using implementation of *IShapeData* interface. Then result can be retrieved from this implementation as a *vtkPolyData* instance. + +@figure{/user_guides/vis/images/vis_image007.png "Low-level VIS usage with VTK"} + +The visualization pipeline for OCCT shape presentation can be initialized as follows: +1. Create an instance of *IShape* class initialized by OCCT topological shape: +~~~~ +TopoDS_Shape aShape; + +// Load or create a TopoDS_Shape in the variable a Shape +... +IVtkOCC_Shape::Handle aShapeImpl = new IVtkOCC_Shape(aShape); +~~~~ +2. Create an empty instance of IShapeData implementation for VTK: +~~~~ +IVtk_IShapeData::Handle aDataImpl = new IVtkVTK_ShapeData(); +~~~~ +3 Create an instance of *IShapeMesher* implementation for OCCT (any faceter can be used at this stage): +~~~~ +IVtk_IShapeMesher::Handle aMesher = new IVtkOCC_ShapeMesher(); +~~~~ +4 Triangulate the OCCT topological shape by means of the Mesher and access the result: +~~~~ +aMesher->Build (aShapeImpl, aDataImpl); + +vtkPolyData* aPolyData = aDataImpl->GetVtkPolyData(); +~~~~ + +The resulting *vtkPolyData* instance can be used for initialization of VTK pipelines. +*IVtkVTK_ShapeData* object is used to keep and pass the mapping between sub-shapes, their mesh types and the resulting mesh cells through a pipeline. It stores sub-shape IDs and mesh type in VTK data arrays for each generated cell. As a result, the generated VTK cells get the following data arrays populated: +* *SUBSHAPE_IDS* – array of *vtkIdTypeArray* type. It contains the shape IDs the corresponding cells were generated for. The name of this array is defined in *ARRNAME_SUBSHAPE_IDS* constant of *IVtkVTK_ShapeData* class. +* *MESH_TYPES* – array of *vtkShortArray type*. It contains the type tags of the shape parts the corresponding cells were generated for. The name of this array is defined in *ARRNAME_MESH_TYPES* constant of *IVtkVTK_ShapeData* class. + +@subsection occt_vis_4_2 Usage of OCCT picking algorithm + +It is possible to create a custom VTK picker for interactive selection of OCCT 3D shapes using an instance of the picking algorithm *IVtk_IShapePickerAlgo*. + +Picking algorithm uses an instance of viewer selector (OCCT term), which manages picking along with activation and deactivation of selection modes. VIS component implements OCCT selection principle in *IVtkOCC_ShapePickerAlgo* and *IVtkOCC_ViewerSelector* classes. *IVtkOCC_ViewerSelector* is an internal class that implements OCCT selection mechanism applied in *IVtkVTK_View*. + +*IVtkOCC_ShapePickerAlgo* has to be used to activate/deactivate selection modes for shapes *IVtk_IShape*. *IVtkOCC_ShapePickerAlgo* is the implementation of *IVtk_IShapePickerAlgo* interface. + +The typical usage of *IVtk_IShapePickerAlgo* consists in the following sequence of actions: +1. Create an instance of the picker class: +~~~~ +IVtkOCC_ShapePickerAlgo::Handle Picker = new IVtkOCC_ShapePickerAlgo(); +~~~~ + +2. Set an instance of *IVtk_IView* class to the algorithm in order to define the viewer parameters: +~~~~ +IVtkVTK_View::Handle View = new IVtkVTK_View(Renderer); +Picker->SetView(View); +~~~~ +3. Activate the desired selection modes using values from *IVtk_SelectionMode* enumeration. For example, the following call allows selection of edges: +~~~~ +TopoDS_Shape aShape; +// Load or create a TopoDS_Shape in the variable a Shape +... +IVtk_IShape::Handle shapeImpl = new IVtkOCC_Shape(aShape); +... +myOccPickerAlgo->SetSelectionMode(occShape, SM_Edge); +~~~~ +Different selection modes can be turned on/off for a picker at the same time independently from each other. +To turn off a selection mode the additional optional Boolean parameter is used with *false* value, for example: +~~~~ +myOccPickerAlgo->SetSelectionMode(occShape, SM_Edge, false); +~~~~ +4. Call *Pick* method passing the mouse coordinates: +~~~~ +myOccPickerAlgo->Pick(x, y); +~~~~ +5. Obtain top-level picking results as IDs of the picked top-level shapes: +~~~~ +IVtk_ShapeIdList ids = myOccPickerAlgo->ShapesPicked(); +~~~~ +6. Obtain IDs of the picked sub-shapes: +~~~~ +IVtk_ShapeIdList subShapeIds + = myOccPickerAlgo->SubShapesPicked(shapeId); +~~~~ + +@section occt_vis_5 DRAW Test Harness + +*TKIVtkDraw* toolkit contains classes for embedding VIS functionality into DRAW Test Harness with possibility of simple interactions, including detection and highlighting. +* *IVtkDraw_HighlightAndSelectionPipeline* - Creates VTK pipeline with OCCT shape data source and properly initialized VIS filters. +* *IVtkDraw_Interactor* - Controls simple interactive actions, such as detection and selection of the displayed shapes. + +@section occt_vis_6 Test Harness Commands +A specific plugin with alias *VIS* should be loaded to have access to VIS functionality in DRAW Test Harness: + +~~~~ +\> pload VIS +~~~~ + +Typical use cases are available in non-regression tests scripts +@subsection occt_vis_6_1 ivtkinit + +Purpose: Creates a window for VTK viewer. + +Syntax: *ivtkinit* + +@figure{/user_guides/vis/images/vis_image008.png} + +@subsection occt_vis_6_2 ivtkdisplay + +Purpose: Displays named objects. + +Syntax: ivtkdisplay name1 [name2] …[name n] + +Example + +~~~~ +ivtkinit +# create cone +pcone c 5 0 10 +ivtkdisplay c +~~~~ + +@figure{/user_guides/vis/images/vis_image009.png} + +@subsection occt_vis_6_3 ivtkerase + +Purpose: Erases named objects. If no arguments are passed, erases all displayed objects. + +Syntax: ivtkerase [name1] [name2] … [name n] + +Example +~~~~ +ivtkinit +# create a sphere +psphere s 10 +# create a cone +pcone c 5 0 10 +# create a cylinder +pcylinder cy 5 10 +# display objects +ivtkdisplay s c cy +# erase only the cylinder +ivtkerase cy +# erase the sphere and the cone +ivtkerase s c +~~~~ + +@subsection occt_vis_6_4 ivtkfit + +Purpose: Automatic zoom/panning. + +Syntax: *ivtkfit* + +@subsection occt_vis_6_5 ivtkdispmode + +Purpose: Sets display mode for a named object. If no arguments are passed, sets the given display mode for all displayed objects +The possible modes are: 0 (WireFrame) and 1 (Shading). + +Syntax: ivtksetdispmode [name] mode(0,1) + +Example + +~~~~ +ivtkinit +# create a cone +pcone c 5 0 10 +# display the cone +ivtkdisplay c +# set shading mode for the cone +ivtksetdispmode c 1 +~~~~ + +@figure{/user_guides/vis/images/vis_image010.png} + +@subsection occt_vis_6_6 ivtksetselmode + +Purpose: Sets selection mode for a named object. If no arguments are passed, sets the given selection mode for all the displayed objects + +Syntax: ivtksetselmode [name] mode on/off(0/1) + +Example +~~~~ +ivtkinit +# load a shape from file +restore CrankArm.brep a +# display the loaded shape +ivtkdisplay a +# set the face selection mode +ivtksetselmode a 4 1 +~~~~ + +@figure{/user_guides/vis/images/vis_image011.png} + +@subsection occt_vis_6_7 ivtkmoveto + +Purpose: Imitates mouse cursor moving to point with the given display coordinates. + +Syntax: ivtkmoveto x y + +Example +~~~~ +ivtkinit +pcone c 5 0 10 +ivtkdisplay c +ivtkmoveto 40 50 +~~~~ + +@subsection occt_vis_6_8 ivtkselect + +Purpose: Imitates mouse cursor moving to point with the given display coordinates and performs selection at this point. + +Syntax: ivtkselect x y + +Example +~~~~ +ivtkinit +pcone c 5 0 10 +ivtkdisplay c +ivtkselect 40 50 +~~~~ + +@subsection occt_vis_6_9 ivtkdump + +Purpose: Dumps the contents of VTK viewer to image. It supports: +* dumping in different raster graphics formats: PNG, BMP, JPEG, TIFF or PNM. +* dumping of different buffers: RGB, RGBA or depth buffer. +* defining of image sizes (width and height in pixels). +* dumping of stereo projections (left or right). + +Syntax: ivtkdump *filename* [buffer={rgb|rgba|depth}] [width height] [stereoproj={L|R}] + +Example +~~~~ +ivtkinit +pcone c 5 0 10 +ivtkdisplay c +ivtkdump D:/ConeSnapshot.png rgb 768 768 +~~~~ + +@subsection occt_vis_6_10 ivtkbgcolor + +Purpose: Sets uniform background color or gradient background if second triple of parameters is set. Color parameters r,g,b have to be chosen in the interval [0..255]. + +Syntax: ivtkbgcolor r g b [r2 g2 b2] + +Example +~~~~ +ivtkinit +ivtkbgcolor 200 220 250 +~~~~ + +@figure{/user_guides/vis/images/vis_image012.png} + +~~~~ +ivtkbgcolor 10 30 80 255 255 255 +~~~~ + +@figure{/user_guides/vis/images/vis_image013.png} + +@section occt_vis_7 Non-regression tests +The test scenarios are available in /test/v3d/ivtk directory to test the functionality of VIS component. This directory contains test cases for all DRAW commands described above. + + +