![]() |
Open CASCADE Technology 7.8.2.dev
|
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.
There are two ways to use VIS in the application:
VIS component consists of the following 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.
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.
IVtk package contains the following classes:
IVtkOCC package contains the implementation of classes depending on OCCT:
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.
IVtkVTK package contains implementation of classes depending on VTK:
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:
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.
To visualize an OCCT topological shape in VTK viewer, it is necessary to perform the following steps:
It is always possible to access the shape data source from VTK actor by means of dedicated methods from IVtkTools_ShapeObject class:
It is also possible to get a shape wrapper from the shape data source:
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:
It is possible to get an instance of vtkLookupTable class with a default OCCT color scheme by means of the following method:
To set up application-specific colors for a shape presentation, use InitShapeMapper function with an additional argument passing a custom lookup table:
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:
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.
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:
For example, the scalar-based coloring can be disabled to bind a single color to the entire VTK actor representing the shape.
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.
For example, the shading representation can be obtained in the following way:
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.
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:
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.
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:
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.
420
The visualization pipeline for OCCT shape presentation can be initialized as follows:
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:
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:
TKIVtkDraw toolkit contains classes for embedding VIS functionality into DRAW Test Harness with possibility of simple interactions, including detection and highlighting.