DGtal
1.4.2
|
This part of the manual describes how to extend the standard Viewer3D interface of DGtal. For instance, you wish to assign new handlers keys or to mouse event, or you wish to display or select other graphical elements. To do that, you just have to write a class that derived from Viewer3D::Extension and overrides some methods to get your desired behaviour.
Related examples: viewer3D-11-extension.cpp
Related modules: Limited interaction when using selection with QGLViewer Viewer3D stream mechanism
The Viewer3D interface provides a very handy way of visualising 3D scenes, digital objects or meshes in DGtal, and is bundled with many functionalities (like moving the light, selecting some objects, etc). However it is not directly extensible as is, and, for several reasons, you cannot derive from the Viewer3D class directly to add some new functionalities.
Therefore we provide the class Viewer3D::Extension so that you can extend the viewer in several ways. The principle is very easy. This interface provides a set of empty virtual methods so you just have to override them in order to change the behavior of the viewer. For instance, you just have to override Viewer3D::Extension::keyPressEvent to capture other key events. You can override all the following methods:
The example below shows how to capture "Shift+R" key pressed events, so that each time this event occurs random points are added to the 3D scene.
Once you have built a class that derives from Viewer3D::Extension, it remains to create some instance of this extension and to hand it to your viewer. This is done by the following lines.
The viewer will take care of freeing your instanciated extension object. For a complete example, see viewer3D-11-extension.cpp.