Add a NP for orientation requirement

This commit is contained in:
Maxime Gimeno 2021-03-23 11:49:47 +01:00
parent aa2b527156
commit 277117613b
2 changed files with 41 additions and 5 deletions

View File

@ -34,6 +34,7 @@
#include <boost/dynamic_bitset.hpp>
#include <utility>
#include <algorithm>
#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<std::size_t, 4>& 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<VPMap2>::value_type Point_3;
typedef typename boost::graph_traits<PolygonMesh>::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())
{

View File

@ -75,6 +75,14 @@ void Polyhedron_demo_diff_between_meshes_plugin::diff()
typedef CGAL::Face_filtered_graph<SMesh> 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<face_descriptor> m1_only, m2_only;
std::vector<std::pair<face_descriptor, face_descriptor> > 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;