From 277117613bfb9c346e7e70f17e906b0ee05ea343 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 23 Mar 2021 11:49:47 +0100 Subject: [PATCH] Add a NP for orientation requirement --- .../CGAL/Polygon_mesh_processing/measure.h | 30 ++++++++++++++++--- .../Diff_between_meshes_plugin.cpp | 16 +++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h index 6a87d56e85f..c74e18103d7 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h @@ -34,6 +34,7 @@ #include #include +#include #ifdef DOXYGEN_RUNNING #define CGAL_PMP_NP_TEMPLATE_PARAMETERS NamedParameters @@ -51,7 +52,20 @@ public: }; namespace Polygon_mesh_processing { - +namespace pmp_internal { +void rearrange_face_ids(boost::container::small_vector& ids, bool orientation_counts) +{ + if(!orientation_counts) + { + std::sort(ids.begin(), ids.end()); + } + else + { + auto min_elem = std::min_element(ids.begin(), ids.end()); + std::rotate(ids.begin(), min_elem, ids.end()); + } +} +}//end pmp_internal /** * \ingroup measure_grp * computes the length of an edge of a given polygon mesh. @@ -827,7 +841,6 @@ centroid(const TriangleMesh& tmesh) * \ingroup measure_grp * given two meshes, separates the faces that are only in one, the faces * that are only in the other one, and the faces that are common to both. - * The orientation of the faces is ignored during the comparison. * * @tparam PolygonMesh a model of `HalfedgeListGraph` and `FaceListGraph` * @tparam OutputFaceIterator model of `OutputIterator` @@ -867,6 +880,14 @@ centroid(const TriangleMesh& tmesh) * or using an external map. The latter might result in - slightly - worsened performance * in case of non-constant complexity for index access.} * \cgalParamNEnd + * \cgalParamNBegin{require_same_orientation} + * \cgalParamDescription{Parameter (np1 only) to indicate if face orientation should be taken + * into account when determining whether two faces are duplicates, + * that is, whether e.g. the triangles `0,1,2` and `0,2,1` are duplicates.} + * \cgalParamType{Boolean} + * \cgalParamDefault{`false`} + *\cgalParamNEnd + * \cgalNamedParamsEnd * */ @@ -887,6 +908,7 @@ void compare_meshes(const PolygonMesh& m1, const PolygonMesh& m2, get_const_property_map(vertex_point, m2)); VIMap1 vim1 = get_initialized_vertex_index_map(m1, np1); VIMap1 vim2 = get_initialized_vertex_index_map(m2, np2); + const bool same_orientation = choose_parameter(get_parameter(np1, internal_np::require_same_orientation), false); typedef typename boost::property_traits::value_type Point_3; typedef typename boost::graph_traits::face_descriptor face_descriptor; @@ -935,7 +957,7 @@ void compare_meshes(const PolygonMesh& m1, const PolygonMesh& m2, } if(all_shared) { - std::sort(ids.begin(), ids.end()); + pmp_internal::rearrange_face_ids(ids, same_orientation); m1_faces_map.insert({ids, f}); } else @@ -957,7 +979,7 @@ void compare_meshes(const PolygonMesh& m1, const PolygonMesh& m2, } if(all_shared) { - std::sort(ids.begin(), ids.end()); + pmp_internal::rearrange_face_ids(ids, same_orientation); auto it = m1_faces_map.find(ids); if(it != m1_faces_map.end()) { diff --git a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Diff_between_meshes_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Diff_between_meshes_plugin.cpp index c3c5d59302a..11d61ac8916 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Diff_between_meshes_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Diff_between_meshes_plugin.cpp @@ -75,6 +75,14 @@ void Polyhedron_demo_diff_between_meshes_plugin::diff() typedef CGAL::Face_filtered_graph Filtered_graph; QCursor c(Qt::WaitCursor); + + QMessageBox msgBox; + msgBox.setText("Require the Same Orientation ?"); + msgBox.setInformativeText("Should face orientation count for duplicate detection ?"); + msgBox.setStandardButtons(QMessageBox::Yes| QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + int ret = msgBox.exec(); + bool same_orientation = (ret == QMessageBox::Yes); CGAL::Three::Three::CursorScopeGuard guard(c); //Get the two meshes. No need to check their existance, applicable() @@ -88,7 +96,13 @@ void Polyhedron_demo_diff_between_meshes_plugin::diff() m2=*m2_item->face_graph(); std::vector m1_only, m2_only; std::vector > common; - CGAL::Polygon_mesh_processing::compare_meshes(m1, m2, std::back_inserter(common), std::back_inserter(m1_only), std::back_inserter(m2_only)); + CGAL::Polygon_mesh_processing::compare_meshes( + m1, + m2, + std::back_inserter(common), + std::back_inserter(m1_only), + std::back_inserter(m2_only), + CGAL::parameters::require_same_orientation(same_orientation)); Filtered_graph filter1(m1, m1_only); SMesh mesh1_only, mesh2_only, common_mesh;