add CGAL::draw for CCDT_3

This commit is contained in:
Laurent Rineau 2025-04-28 17:06:33 +02:00
parent 58bc7b1a76
commit c0abf42c57
7 changed files with 131 additions and 8 deletions

View File

@ -10,6 +10,9 @@
\defgroup PkgConstrainedTriangulation3Classes Classes and Class Templates
\ingroup PkgConstrainedTriangulation3Ref
\defgroup PkgDrawCDT_3 Draw a 3D Constrained Triangulation
\ingroup PkgConstrainedTriangulation3Ref
\addtogroup PkgConstrainedTriangulation3Ref
\cgalPkgDescriptionBegin{3D Constrained Triangulations,PkgConstrainedTriangulation3}
\cgalPkgPicture{cdt3-small.png}
@ -56,4 +59,9 @@ a conforming constrained Delaunay triangulation in 3D, an instance of the class
- `CGAL::Conforming_constrained_Delaunay_triangulation_3<Traits, Triangulation>`
- `CGAL::Conforming_constrained_Delaunay_triangulation_vertex_base_3<Traits, Vertex_base>`
- `CGAL::Conforming_constrained_Delaunay_triangulation_cell_base_3<Traits, Cell_base>`
\cgalCRPSection{Draw a 3D Constrained Triangulation}
- \link PkgDrawCDT_3 CGAL::draw() \endlink
*/

View File

@ -1,7 +1,7 @@
#include <CGAL/make_conforming_constrained_Delaunay_triangulation_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/draw_triangulation_3.h>
#include <CGAL/draw_constrained_triangulation_3.h>
#include <algorithm>
@ -28,7 +28,7 @@ int main(int argc, char* argv[])
<< "Number of constrained facets in the CDT: "
<< ccdt.number_of_constrained_facets() << '\n';
CGAL::draw(ccdt.triangulation());
CGAL::draw(ccdt);
return EXIT_SUCCESS;
}
}

View File

@ -1,7 +1,7 @@
#include <CGAL/make_conforming_constrained_Delaunay_triangulation_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <vector>
#include <CGAL/draw_triangulation_3.h>
#include <CGAL/draw_constrained_triangulation_3.h>
#include <algorithm>
@ -29,7 +29,7 @@ int main(int argc, char* argv[])
<< "Number of constrained facets in the CDT: "
<< ccdt.number_of_constrained_facets() << '\n';
CGAL::draw(ccdt.triangulation());
CGAL::draw(ccdt);
return EXIT_SUCCESS;
}

View File

@ -1,5 +1,5 @@
// Copy the content from the old file to the new file, but update all occurrences of 'fmap' in the filename and code to 'fpmap'.
#include <CGAL/draw_triangulation_3.h>
#include <CGAL/draw_constrained_triangulation_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/make_conforming_constrained_Delaunay_triangulation_3.h>
#include <CGAL/Polygon_mesh_processing/connected_components.h>
@ -57,7 +57,8 @@ int main(int argc, char* argv[])
<< "Number of constrained facets in the CDT: "
<< ccdt.number_of_constrained_facets() << '\n';
CGAL::draw(ccdt.triangulation());
CGAL::draw(ccdt);
return EXIT_SUCCESS;
}

View File

@ -14,6 +14,8 @@
#include <CGAL/license/Constrained_triangulation_3.h>
#include <CGAL/Conforming_constrained_Delaunay_triangulation_3_fwd.h>
#include <CGAL/Constrained_triangulation_3/internal/config.h>
#include <CGAL/Base_with_time_stamp.h>
@ -876,7 +878,7 @@ public:
* This allows the use of all non-modifying functions of the base triangulation.
* See the other overload for a way to move the triangulation out of this object and then modify it.
*/
const Triangulation& triangulation() & {
const Triangulation& triangulation() const& {
return cdt_impl;
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2025 GeometryFactory Sarl (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) : Laurent Rineau
#ifndef CGAL_CONFORMING_CONSTRAINED_DELAUNAY_TRIANGULATION_3_FWD_H
#define CGAL_CONFORMING_CONSTRAINED_DELAUNAY_TRIANGULATION_3_FWD_H
#include <CGAL/license/Constrained_triangulation_3.h>
namespace CGAL {
template <typename Traits, typename Tr>
class Conforming_constrained_Delaunay_triangulation_3;
} // namespace CGAL
#endif // CGAL_CONFORMING_CONSTRAINED_DELAUNAY_TRIANGULATION_3_FWD_H

View File

@ -0,0 +1,88 @@
// Copyright (c) 2025 GeometryFactory SARL (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) : Laurent Rineau
#ifndef CGAL_DRAW_CONSTRAINED_T3_H
#define CGAL_DRAW_CONSTRAINED_T3_H
#include <CGAL/license/Constrained_triangulation_3.h>
#include <CGAL/draw_triangulation_3.h>
#include <CGAL/Conforming_constrained_Delaunay_triangulation_3_fwd.h>
#include <CGAL/type_traits.h>
#include <algorithm>
namespace CGAL {
#if defined(CGAL_USE_BASIC_VIEWER) || defined(DOXYGEN_RUNNING)
/*!
\ingroup PkgDrawCDT_3
opens a new window and draws the constrained triangulation.
A call to this function blocks the execution of the program until the drawing window is closed. 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`.
*/
template <typename Traits, typename Tr_or_default>
void draw(const Conforming_constrained_Delaunay_triangulation_3<Traits, Tr_or_default>& ccdt,
const char *title="Constrained 3D Triangulation Basic Viewer")
{
using Tr = CGAL::cpp20::remove_cvref_t<decltype(ccdt.triangulation())>;
using Vertex_handle = typename Tr::Vertex_handle;
using Cell_handle = typename Tr::Cell_handle;
using Edge_descriptor = typename Tr::Finite_edges_iterator;
using Facet_descriptor = typename Tr::Finite_facets_iterator;
using Face_index = CGAL::cpp20::remove_cvref_t<
decltype(std::declval<Cell_handle>()->surface_patch_index(0))>;
Face_index nb_colors = 0;
std::for_each(
ccdt.constrained_facets_begin(), ccdt.constrained_facets_end(),
[&](const auto& f) {
auto [c, index] = f;
nb_colors = (std::max)(nb_colors, c->ccdt_3_data().face_constraint_index(index) + 1);
});
std::vector<CGAL::IO::Color> colors(nb_colors);
std::generate(colors.begin(), colors.end(), []() {
return CGAL::get_random_color(CGAL::get_default_random());
});
CGAL::Graphics_scene_options<Tr, Vertex_handle, Edge_descriptor, Facet_descriptor> options;
options.draw_face = [](const Tr&, Facet_descriptor f) {
auto [c, index] = *f;
return c->ccdt_3_data().is_facet_constrained(index);
};
options.colored_face = [](const Tr&, Facet_descriptor f) {
return true;
};
options.face_color = [&](const Tr&, Facet_descriptor f) {
auto [c, index] = *f;
return colors[c->ccdt_3_data().face_constraint_index(index)];
};
draw(ccdt.triangulation(), options, title);
}
/*!
\ingroup PkgDrawCDT_3
A shortcut to \link PkgDrawTriangulation3 `CGAL::add_to_graphics_scene(ccdt.triangulation(), gs_options, title)` \endlink.
*/
template <typename Traits, typename Tr, typename GSOptions>
void draw(const Conforming_constrained_Delaunay_triangulation_3<Traits, Tr>& ccdt,
const GSOptions& gs_options,
const char *title="Constrained 3D Triangulation Basic Viewer")
{
draw(ccdt.triangulation(), gs_options, title);
}
#endif // CGAL_USE_BASIC_VIEWER || DOXYGEN_RUNNING
} // End namespace CGAL
#endif // CGAL_DRAW_CONSTRAINED_T3_H