New in CGAL: Basic Viewer

CGAL/cgal

New in CGAL: Basic Viewer


Guillaume Damiand°, Mostafa Ashraf.

°LIRIS / CNRS


Visualizing the data structures used by CGAL's algorithms can help understand and analyze results. Since CGAL 4.13, the global function CGAL::draw(...) can be used to visualize (almost) all CGAL data structures including point sets, polygon meshes, cell complexes, and straight skeletons. Calling CGAL::draw(...) opens an interactive window displaying the data structure, enabling users to navigate the scene, show or hide specific elements, and even view the interior of the model, if applicable.


The example below illustrates how we can use the function CGAL::draw() to visualize an OFF file loaded into a CGAL::Surface_mesh data structure.

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/draw_surface_mesh.h>

int main(int argc, char* argv[])
{
  using Point=CGAL::Simple_cartesian<double>::Point_3;
  CGAL::Surface_mesh<Point> sm;
  CGAL::IO::read_polygon_mesh(argv[1], sm);
  CGAL::draw(sm);
  return EXIT_SUCCESS;
}

Unfortunately, this function had several limitations. Firstly, it was not easy to customize the drawing, for example changing the color or hiding of some elements. Secondly, it was not possible to draw different data structures simultaneously. Finally, it was not easy to add interaction with the drawing, or to use it in an higher level widget. All these limitations are solved with a new package: the CGAL Basic Viewer.

Basic viewer

The goal of this package is:

  • to enable easy customization of the drawing by using the Graphics_scene_options class;
  • to enable different data structures within the same window, by using the Graphics_scene class;
  • to use the basic viewer in a full Qt application, thanks to the widget CGAL::Qt::Basic_viewer;
  • to add some (limited) interaction with users, through different keyboard shortcuts, by using the class CGAL::Qt::QApplication_and_basic_viewer which regroups a Qt::QApplication and a CGAL::Qt::Basic_viewer.

Example of tuned drawing of a 3D surface mesh where some vertex colors are changed.


Example of mesh drawing with a color for each face computed depending on its height.


Example of drawing of a point cloud and a polyhedron in a same viewer.


Example of drawing of two Basic_viewer side by side.


Two examples of drawing of a mesh with small faces in red. Left: With the initial threshold. Right: After having increased the threshold.

Status

This work was initiated by Mostafa Ashraf during his 2022 GSoC project. Guillaume Damiand, who mentored the GSoC project, reworked large parts of the package afterwards. As future work, a version based on GLFW is planned, avoiding the dependency to Qt.


The Basic Viewer package is already integrated in CGAL's master branch on the CGAL GitHub repository, and will be officially released in the upcoming version of CGAL, CGAL 6.0.

Documentation of the Basic viewer package
CGAL master branch on GitHub