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..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 @@ -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,17 @@ 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. +In case the function `Bottom` was the identity this would have been a one-sided extrusion. + +\cgalExample{Polygon_mesh_processing/extrude.cpp} + + + + \section Coref_section Corefinement and Boolean Operations \subsection coref_def_subsec Definitions 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 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..aa7c2bd40ea --- /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/cube-ouvert.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; +}