diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt index fb6cf9b1939..00c4ab2f722 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/CMakeLists.txt @@ -74,7 +74,7 @@ create_single_source_cgal_program( "polygon_soup_example.cpp") create_single_source_cgal_program( "triangulate_polyline_example.cpp") create_single_source_cgal_program( "refine_fair_example.cpp") create_single_source_cgal_program( "mesh_slicer_example.cpp") - +create_single_source_cgal_program( "remove_degeneracies_example.cpp") else(EIGEN3_FOUND) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/remove_degeneracies_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/remove_degeneracies_example.cpp new file mode 100644 index 00000000000..b063a83ecee --- /dev/null +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/remove_degeneracies_example.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_3 Point; +typedef K::Vector_3 Vector; + +typedef CGAL::Surface_mesh Surface_mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::face_descriptor face_descriptor; + +int main(int argc, char* argv[]) +{ + const char* filename = (argc > 1) ? argv[1] : "data/eight.off"; + std::ifstream input(filename); + + Surface_mesh mesh; + if (!input || !(input >> mesh) || mesh.is_empty()) { + std::cerr << "Not a valid off file." << std::endl; + return 1; + } + + std::size_t nb + = CGAL::Polygon_mesh_processing::remove_degenerate_faces(mesh); + + std::cout << "There were " << nb << " degenerate faces in this mesh" << std::endl; + + return 0; +} diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair.h index bee86cf1b68..1bbca056188 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair.h @@ -26,6 +26,9 @@ #include #include +#include +#include + namespace CGAL{ namespace Polygon_mesh_processing { @@ -230,27 +233,48 @@ namespace internal { } // end of namespace internal /// \ingroup PkgPolygonMeshProcessing +/// removes the degenerate faces from a triangle mesh. +/// +/// @tparam TriangleMesh a model of `FaceListGraph` and `MutableFaceGraph` +/// that has a property map for `boost::vertex_point_t` +/// @tparam NamedParameters a sequence of \ref namedparameters +/// +/// @param np optional \ref namedparameters described below +/// +/// \b Named \b parameters +///
    +///
  • \b vertex_point_map the property map with the points associated to the vertices of `pmesh`. The type of this mad is model of `ReadWritePropertyMap`. +///
  • \b kernel a geometric traits class instance. +/// The traits class must provide the nested types : +/// - `Point_3`, +/// - `Compare_distance_3` to compute the distance between 2 points +/// - `Collinear_are_ordered_along_line_3` to check whether 3 collinear points are ordered +/// - `Collinear_3` to check whether 3 points are collinear +/// - `Less_xyz_3` to compare lexicographically two points +/// - `Equal_3` to check whether 2 points are identical +/// - for each functor Foo, a function `Foo foo_object()` +///
+ /// \return number of degenerate faces found -/// \tparam Traits must provide the nested types: -/// - `Point_3`, -/// - `Compare_distance_3` to compute the distance between 2 points -/// - `Collinear_are_ordered_along_line_3` to check whether 3 collinear points are ordered -/// - `Collinear_3` to check whether 3 points are collinear -/// - `Less_xyz_3` to compare lexicographically two points -/// - `Equal_3` to check whether 2 points are identical -/// - for each functor Foo, a function `Foo foo_object()` -/// \tparam VertexPointMap model of `ReadWritePropertyMap` with -/// `boost::graph_traits::vertex_descriptor` as key -/// and `Traits::Point_3` as value type. -template -std::size_t remove_degenerate_faces(TriangleMesh& tmesh, const VertexPointMap& vpmap, const Traits& traits) +/// +template +std::size_t remove_degenerate_faces(TriangleMesh& tmesh, + const NamedParameters& np) { + typedef TriangleMesh TM; typedef typename boost::graph_traits GT; typedef typename GT::edge_descriptor edge_descriptor; typedef typename GT::halfedge_descriptor halfedge_descriptor; typedef typename GT::face_descriptor face_descriptor; typedef typename GT::vertex_descriptor vertex_descriptor; + typedef typename GetVertexPointMap::type VertexPointMap; + VertexPointMap vpmap = choose_const_pmap(get_param(np, boost::vertex_point), + tmesh, + boost::vertex_point); + typedef typename GetKernel::Kernel Traits; + Traits traits = choose_param(get_param(np, geom_traits), Traits()); + std::size_t nb_deg_faces = 0; // First remove edges of length 0 @@ -641,10 +665,11 @@ std::size_t remove_degenerate_faces(TriangleMesh& tmesh, const VertexPointMap& v } /// \cond SKIP_IN_MANUAL -template -std::size_t remove_degenerate_faces(TriangleMesh& tmesh, const Traits& traits = Traits()) +template +std::size_t remove_degenerate_faces(TriangleMesh& tmesh) { - return remove_degenerate_faces(tmesh, get(vertex_point, tmesh), traits); + return remove_degenerate_faces(tmesh, + CGAL::Polygon_mesh_processing::parameters::all_default()); } /// \endcond