From b5fc0b0d7299e770a217b0d853661c534788bd32 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 21 Feb 2022 16:09:55 +0000 Subject: [PATCH 1/5] PMP: Add example for extrude_mesh() --- .../Polygon_mesh_processing/CMakeLists.txt | 1 + .../Polygon_mesh_processing/extrude.cpp | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt index 03d04019afd..1a70c77eab4 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt @@ -54,6 +54,7 @@ if(TARGET CGAL::Eigen3_support) target_link_libraries(mesh_smoothing_example PUBLIC CGAL::Eigen3_support) endif() +create_single_source_cgal_program( "extrude.cpp" ) create_single_source_cgal_program( "polyhedral_envelope.cpp" ) create_single_source_cgal_program( "polyhedral_envelope_of_triangle_soup.cpp" ) create_single_source_cgal_program( "polyhedral_envelope_mesh_containment.cpp" ) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp new file mode 100644 index 00000000000..f847bf0c1bf --- /dev/null +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef CGAL::Surface_mesh SM; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +typedef Kernel::Vector_3 Vector; +typedef boost::property_map::type VPMap; +typedef SM::template Property_map VNMap; + +struct Bottom +{ + Bottom(VPMap pmap, VNMap nmap, double vlen) + : pmap(pmap), nmap(nmap), vlen(vlen) + {} + + + void operator()(const vertex_descriptor& vin, const vertex_descriptor vout) const + { + put(pmap, vout, get(pmap, vout) - vlen* get(nmap, vin)); + } + + VPMap pmap; + VNMap nmap; + double vlen; +}; + +struct Top +{ + Top(VPMap pmap, VNMap nmap, double vlen) + : pmap(pmap), nmap(nmap), vlen(vlen) + {} + + + void operator()(const vertex_descriptor& vin, const vertex_descriptor vout) const + { + put(pmap, vout, get(pmap, vout) + vlen* get(nmap, vin)); + } + + VPMap pmap; + VNMap nmap; + double vlen; +}; + +int main(int argc, char* argv[]) +{ + SM in, out; + + std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/sphere_selection_facets.off"); + double vlen = (argc > 2) ? std::stod(argv[2]) : 0.1; + + CGAL::IO::read_polygon_mesh(filename, in); + + VNMap vnormals = in.template add_property_map("v:normals", CGAL::NULL_VECTOR).first; + + CGAL::Polygon_mesh_processing::compute_vertex_normals(in, vnormals); + Bottom bottom(get(CGAL::vertex_point,out), vnormals, vlen); + Top top(get(CGAL::vertex_point,out), vnormals, vlen); + CGAL::Polygon_mesh_processing::extrude_mesh(in, out, bottom, top); + + + filename = filename.substr(filename.find_last_of("/") + 1, filename.length() - 1); + filename = filename.substr(0, filename.find_last_of(".")); + filename = filename + "_" + std::to_string(vlen) + ".off"; + CGAL::IO::write_polygon_mesh(filename, out, CGAL::parameters::stream_precision(17)); + return 0; +} From 716d70adb6689524343a29e1df41737f32cac3b0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 21 Feb 2022 16:41:39 +0000 Subject: [PATCH 2/5] Add to the documentation --- Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt index 496897e2349..1b053016791 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/examples.txt @@ -1,5 +1,6 @@ /*! +\example Polygon_mesh_processing/extrude.cpp \example Polygon_mesh_processing/polyhedral_envelope.cpp \example Polygon_mesh_processing/polyhedral_envelope_of_triangle_soup.cpp \example Polygon_mesh_processing/polyhedral_envelope_mesh_containment.cpp From 680ef92dde4d35325923092ea26eca6b580f522b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 24 Feb 2022 10:23:21 +0000 Subject: [PATCH 3/5] Add a subsection in the manual and explain the example --- .../Polygon_mesh_processing.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt index 8757bba98d4..f2c0161640f 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt @@ -185,6 +185,14 @@ Shape smoothing of the devil model, using the mean curvature flow with a time st constraining border vertices (located at the neck, where the mesh is open). \cgalFigureCaptionEnd + +\subsubsection Extrusion + +This package provides two functions to extrude a triangle mesh with boundaries. A first one extrudes by offsetting each vertex by a user provided vector. +A second one is more general: It takes two users provided functors which extrude "up" and "down". In both cases the boundaries are connected by a triangle strip. +Note that the extrusion may generate self intersecting surfaces. + + \subsection MeshingExamples Meshing Examples \subsubsection MeshingExample_1 Refine and Fair a Region on a Triangle Mesh @@ -218,6 +226,16 @@ Once this is done, remeshing is run on all the surface, with protection of const \cgalExample{Polygon_mesh_processing/isotropic_remeshing_example.cpp} + +\subsubsection ExtrusionExample Extrusion of a Triangle Mesh + +The following example extrudes in both directions by projecting points along the vertex normal. + +\cgalExample{Polygon_mesh_processing/extrude.cpp} + +In case the function `Bottom` was the identity this would have been a one-sided extrusion. + + \section Coref_section Corefinement and Boolean Operations \subsection coref_def_subsec Definitions From 46b3031c3ac229fea42420206d3abf3c5136c823 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 24 Feb 2022 11:34:16 +0000 Subject: [PATCH 4/5] Move sentence before the example --- .../doc/Polygon_mesh_processing/Polygon_mesh_processing.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt index f2c0161640f..90c62b0fd66 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt @@ -230,10 +230,11 @@ Once this is done, remeshing is run on all the surface, with protection of const \subsubsection ExtrusionExample Extrusion of a Triangle Mesh The following example extrudes in both directions by projecting points along the vertex normal. +In case the function `Bottom` was the identity this would have been a one-sided extrusion. \cgalExample{Polygon_mesh_processing/extrude.cpp} -In case the function `Bottom` was the identity this would have been a one-sided extrusion. + \section Coref_section Corefinement and Boolean Operations From 808b3fb24c37ca5561ddf73c34e20d133c685fa3 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 3 Mar 2022 10:04:37 +0000 Subject: [PATCH 5/5] Use existing data set --- .../examples/Polygon_mesh_processing/extrude.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp index f847bf0c1bf..aa7c2bd40ea 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/extrude.cpp @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) { SM in, out; - std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/sphere_selection_facets.off"); + std::string filename = (argc > 1) ? std::string(argv[1]) : CGAL::data_file_path("meshes/cube-ouvert.off"); double vlen = (argc > 2) ? std::stod(argv[2]) : 0.1; CGAL::IO::read_polygon_mesh(filename, in);