OCCT provides built-in Interactive Services based on own OpenGL-based Visualization component. The basic functionality consists of but not limited to presentation and selection of topological shapes (TopoDS_Shape), which are the key objects in OCCT, but also various presentations for arbitrary mesh data, text annotations and others. Nowadays it works on wide range of platforms, including mobile ones, supports custom GLSL programs, GPU-accelerated Ray Tracing, and plenty of other modern features.
However one might decide to use alternative Visualization component, for historical reasons or for project-specific features. One of the most popular and powerful among freely available visualization toolkits is VTK.
A lot of people use VTK to display discrete datasets coming from different domains, and CAE is one of such domains. In a CAE application, it is often necessary to see the original CAD model in a 3D scene, however VTK is not tailored to deal with CAD data, and this is an area where the CAD-oriented power of OCCT could be combined efficiently with VTK mesh visualization capabilities.
OCCT framework made a step towards developers of VTK-based CAE applications, and since 6.8.0 version it became possible to render OCCT models in VTK viewer with help of VTK Integration Services, or VIS.
VIS is a new OCCT component providing a bridge between OCCT CAD data (topology) and VTK polygonal data visualization.
Using VIS, developers can add some OCCT-based functionality to VTK-based applications or use VTK visualization in OCCT-based applications if it is needed.
VIS component is implemented in TKIVtk library, so all classes related to VIS begin with IVtk prefix. The toolkit uses capabilities of VTK and provides CAD model visualization and picking following the OCCT style. It includes functionality for rendering in standard display modes like wireframe and shading.
Picking capabilities include interactive shape and sub-shape highlighting and selection (high-performance OCCT interactive selection algorithm is used internally вЂ“ see the article for more detail):
TKIVtk library mainly consists of two independent parts:
- OCCT-side functionality
- VTK-side functionality
These parts interact inside IVtk with help of additional tools:
TKIVtk visualization mechanism is based on VTK pipeline concept. This concept is also used to convert a model from OCCT data to VTK objects (vtkPolyData entities), and to implement display and selection modes mechanism:
TKIVtk inherits the idea of interactive objects from the OCCT visualization component for shape picking needs. IVtk selectable object uses topological information to create and store VTK polygonal data and selection information.
The TKIVtk is designed to be easy to use. We have tried to minimize its API dependence of OCCT data types to facilitate VIS using to developers not familiar with OCCT functionality. To visualize an OCCT topological shape in VTK viewer, it is necessary to perform the following steps:
- Create IVtkOCC_Shape instance (VIS wrapper for OCCT shape) and initialize it with TopoDS_Shape object containing the actual geometry:
TopoDS_Shape aShape; вЂ¦ IVtkOCC_Shape::Handle aShapeImpl = new IVtkOCC_Shape(aShape);
- Create VTK polygonal data source for the target OCCT topological shape and initialize it with created IVtkOCC_Shape instance:
aSource = vtkSmartPointer ::New(); aSource ->SetShape(aShapeImpl);
- Visualize the loaded shape in usual VTK way starting a pipeline from the newly created specific source:
aMapper = vtkSmartPointer ::New(); aMapper->SetInputConnection(aSource ->GetOutputPort()); vtkSmartPointer anActor = vtkSmartPointer ::New(); anActor->SetMapper(Mapper);
To make possible selection of the shape in VTK viewer:
- Create shape and sub-shape selection filters:
IVtkTools_DisplayModeFilter* aDMFilter = vtkSmartPointer
::New(); IVtkTools_SubPolyDataFilter* aSUBFilter = vtkSmartPointer< IVtkTools_SubPolyDataFilter >::New();
- Start VTK pipeline with the source created before:
aSUBFilter->SetInputConnection (aSource ->GetOutputPort() ); aDMFilter->SetInputConnection (aSUBFilter->GetOutputPort() ); vtkSmartPointer
aSelMapper = vtkSmartPointer ::New(); aSelMapper->SetInputConnection (aDMFilter->GetOutputPort() );
- Create non-pickable actor:
aSelActor = vtkSmartPointer ::New(); aSelActor ->SetPickable(0); aSelActor ->SetVisibility(1); aSelActor ->GetProperty()->SetOpacity(1);
- Set mapper for actor:
TKIVtk is a kind of building blocks which fits smoothly into a VTK pipeline. You can easily widen a set of display or selection filters with custom ones.
The current implementation of the toolkit has some limitations:
- It does not support computation of normal for polygonal data with OCCT, and does this using vtkPolyDataNormals standard filter. Therefore the rendering quality for some models can degrade relatively to rendering in OCCT viewer.
- Its sub-shape selection implementation is only partially adapted to new selection mechanism and is to be further optimized.
- TKIVtk selection mechanism (picker) works with initial topological data structures and does not take into account VTK actor transformation (made with vtkTransform).
A real working example of TKIVtk usage for OCCT shape visualization and selection can be found in TKVtkDraw package. This package contains a set of Draw Harness commands providing a test VTK render window and wrapping all main VIS capabilities. You can read more about VTK Integration Services in user guide and documentation , or try TKIVtk with Draw Harness right now.
We are interested in a community opinion and will consider extending TKIVtk in the future with new features based on experience of use of this new component in real projects. Please give your feedback; all ideas and remarks are welcome!