Fri, 07/10/2015 - 13:02
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.
Overview
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.
Using
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:
vtkSmartPointer
aSource = vtkSmartPointer ::New(); aSource ->SetShape(aShapeImpl); - Visualize the loaded shape in usual VTK way starting a pipeline from the newly created specific source:
vtkSmartPointer
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:
vtkSmartPointer
aSelActor = vtkSmartPointer ::New(); aSelActor ->SetPickable(0); aSelActor ->SetVisibility(1); aSelActor ->GetProperty()->SetOpacity(1); - Set mapper for actor:
aSelActor->SetMapper (aSelMapper);
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.
Limitations
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).
More information
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.
Feedback
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!
Fri, 07/17/2015 - 13:57
In FreeCAD we are not using VTK for visualisation, but coin3D (an openInventor implementation), nonetheless the enhanced fast selection mechanism sounds very promising. Our custom implementation becomes rather slow for large amount of objects when dealing with preselection and selection. Do you have any plans in extending the integration services to other toolkits, like for example openInventor?
Sun, 07/19/2015 - 09:42
Yes, I have noticed that FreeCAD viewer suffers from performance issues - not just selection but presentation as well.
It would be interesting to try to integrate OCCT viewer/selection features into FreeCAD / openInventor, however for the moment we have no plans for such R&D.
Mon, 07/20/2015 - 12:35
Hello ickby,
In theory, you could try BVH selection in FreeCAD yourselves.
Start with this post, then maybe have a look at VIS sources regarding the way how OCCT selection is used outside OCCT viewer. This should be enough for you to begin your work, most likely the sensitive entities you have to deal with in FreeCAD are the same as in OCCT (sensitive triangulation, curve, segment and vertex). This would be really an interesting case, you would gain selection performance, and for us it is interesting to get external feedback regarding our algorithms.
Good luck in your work,
with best regards,
Sergey
Tue, 07/21/2015 - 16:46
Thanks for your input. If I find time for this I will for sure try the new selection, maybe I can find a easy way to make it work.
Mon, 02/18/2019 - 16:18
Hello,
I am working on the shape selection but I am not able to select the instances. You say that there is an example by I could not find it. Do you know where can I find other examples of projects using TKIVtk?
Thank you.
Tue, 02/19/2019 - 04:15
Draw Test Harness src/IVtkDraw