// Copyright (c) 2018-2020 GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Guillaume Damiand #ifndef CGAL_DRAW_SURFACE_MESH_H #define CGAL_DRAW_SURFACE_MESH_H #ifdef DOXYGEN_RUNNING /*! \ingroup PkgDrawSurfaceMesh Open a new window and draw `asm`, an instance of the `CGAL::Surface_mesh` class. The function is blocking, that is the program continues as soon as the user closes the window. This function requires `CGAL_Qt6`, and is only available if the macro `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt6` and add the definition `CGAL_USE_BASIC_VIEWER`. \tparam SM an instance of the `CGAL::Surface_mesh` class. \param asm the surface mesh to draw. */ template void draw(const SM& asm); #else // DOXYGEN_RUNNING #include #include #ifdef CGAL_USE_BASIC_VIEWER #include #include #include #include namespace CGAL { // Check if there are any color maps that could be used, random otherwise template struct Surface_mesh_basic_viewer_color_map : DefaultColorFunctorFaceGraph { using Base = DefaultColorFunctorFaceGraph; using SM = ::CGAL::Surface_mesh; using vertex_descriptor = typename boost::graph_traits::vertex_descriptor; using edge_descriptor = typename boost::graph_traits::edge_descriptor; using face_descriptor = typename boost::graph_traits::face_descriptor; using vertex_colors = typename SM::template Property_map; using edge_colors = typename SM::template Property_map; using face_colors = typename SM::template Property_map; Surface_mesh_basic_viewer_color_map(const SM& amesh) { bool found = false; std::tie(vcolors, found) = amesh.template property_map("v:color"); std::tie(ecolors, found) = amesh.template property_map("e:color"); std::tie(fcolors, found) = amesh.template property_map("f:color"); CGAL_USE(found); } CGAL::IO::Color operator()(const Surface_mesh& amesh, const vertex_descriptor v) const { return vcolors ? get(vcolors, v) : Base::operator()(amesh, v); } CGAL::IO::Color operator()(const Surface_mesh& amesh, const edge_descriptor e) const { return ecolors ? get(ecolors, e) : Base::operator()(amesh, e); } CGAL::IO::Color operator()(const Surface_mesh& amesh, const face_descriptor f) const { return fcolors ? get(fcolors, f) : Base::operator()(amesh, f); } private: vertex_colors vcolors; edge_colors ecolors; face_colors fcolors; }; // Specialization of draw function. template void draw(const Surface_mesh& amesh, const char* title="Surface_mesh Basic Viewer", bool nofill=false) { #if defined(CGAL_TEST_SUITE) bool cgal_test_suite=true; #else bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); #endif if (!cgal_test_suite) { CGAL::Qt::init_ogl_context(4,3); int argc=1; const char* argv[2]={"surface_mesh_viewer", nullptr}; QApplication app(argc,const_cast(argv)); SimpleFaceGraphViewerQt mainwindow(app.activeWindow(), amesh, title, nofill, Surface_mesh_basic_viewer_color_map(amesh)); mainwindow.show(); app.exec(); } } } // End namespace CGAL #endif // CGAL_USE_BASIC_VIEWER #endif // DOXYGEN_RUNNING #endif // CGAL_DRAW_SURFACE_MESH_H