DGtal
0.6.devel
|
This part of the manual describes how to visualize 3D objects and how to import them from binary file (.obj or pgm3d)
The semi abstract class Display3D defines the stream mechanism to display 3d primitive (like PointVector, DigitalSetBySTLSet, Object ...). The class Viewer3D and Board3DTo2D implement two different ways to display 3D objects. The first one (Viewer3D), permits an interactive visualisation (based on OpenGL) and the second one (Board3DTo2D) provides 3D visualisation from 2D vectorial display (based on the CAIRO library).
The class Viewer3D inherits from the base class QGLViewer (which is based on QGLwidget). It permits to display simple 3D shapes. LibQGLViewer ( http://www.libqglviewer.com ) is a C++ library based on QT allowing to access to simple 3D fonctionalities like camera moving, mouse, keyboard interaction, clipping plane .... etc.
First to use the Viewer3D stream, you need to include the following hearders:
The following code snippet defines three points and a rectangular domain in Z3. It then displays them in a Viewer3D object. The full code is in viewer3D-1-points.cpp.
The first step to visualize 3D object with Viewer3D is to create a QApplication from the main():
Then we can display some 3D primitives:
You should obtain the following visualisation:
The same visualization can be obtain with the Board2Dto3D class. You just need to adapt the camera settings (see example: dgtalBoard3DTo2D-1-points.cpp ).
This example should provides a comparable visualization.
The Viewer3D class allows also to display directly a DigitalSet
. The first step is to create a DigitalSet
for example from the Shape class.
You should obtain the following visualisation (see example: viewer3D-2-sets.cpp ):
As for Board2D, a mode can be choosed to display elements (SetMode3D
). You just have to specify the classname (the easiest way is to call the method className()
on an instance of the correct type and the desired mode (a string).
*or change the couple of adjacency
You should obtain the two following visualisations (see example: viewer3D-3-objects.cpp ):
Note that digital set was displayed with transparency by setting a custom colors.
As for Board2D
the object can be displayed with different possible mode:
Note that for KhalimskyCell and SignedKhalimskyCell the defaul colors (with CustomColors3D objects) can be changed only with the empty mode ("") and "IllustrationCustomColor" mode.
The file viewer3D-4-modes.cpp illustrates several possible modes to display these objects:
We can display the set of point and the domain
without mode change (see image (a)):
We can change the mode for displaying the domain (see image (b)):
(Note that to avoid transparency displaying artifacts, we need to display the domain after the voxel elements included in the domain)
It is also possible to change the mode for displaying the voxels: (see image (c))
we obtain the following visualisations:
The "Illustration" mode is defined to construct illustrations composed of KhalimskyCell. In particular it permits to increase the space between cells and improve the display visibility. It can be used typically as follows: First you need to add the following header:
From a SignedKhalimskyCell (SCell in DGtal::Z3i) you have to select the "Illustration" mode :
Then, to display a surfel with its associated voxel, you need to transform the surfel by constructing a shifted and resized version (DGtal::TransformedKSSurfel) according to its associated voxel:
You will obtain such type of illustration (obtained from the example viewer3D-4bis-illustrationMode.cpp ).
As for Board2D, it is possible to custom the way to display 3D elements by using an instance of the following classes:
The custom color can be applied by an instance of the CustomColors3D as follow:
The example viewer3D-5-custom.cpp illustrates some possible customs :
It also possible through the stream mechanism to add clipping plane with the object ClippingPlane
. We just have to add the real plane equation and adding as for displaying an element. The file viewer3D-6-clipping.cpp gives a simple example.
From displaying a digital set defined from a Norm2 ball,
we can add for instance two differents clipping planes: