From 83fcb5d24e10c8e74b0c6292f3ea4f190816201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Sun, 25 Aug 2019 09:46:56 +0200 Subject: [PATCH] add new named parmeters to extract more info from the function --- .../CGAL/boost/graph/parameters_interface.h | 3 + BGL/test/BGL/test_cgal_bgl_named_params.cpp | 4 + .../Polygon_mesh_processing/orientation.h | 77 +++++++++++++++++-- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index 193a496e26a..37fdf34a95e 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -84,6 +84,9 @@ CGAL_add_named_parameter(error_codes_t, error_codes, error_codes) CGAL_add_named_parameter(volume_inclusions_t, volume_inclusions, volume_inclusions) CGAL_add_named_parameter(face_cc_map_t, face_connected_component_map, face_connected_component_map) +CGAL_add_named_parameter(ccid_to_vid_vector_t, connected_component_id_to_volume_id, connected_component_id_to_volume_id) +CGAL_add_named_parameter(is_cc_outward_oriented_bs_t, is_cc_outward_oriented, is_cc_outward_oriented); + // List of named parameters that we use in the package 'Surface Mesh Simplification' CGAL_add_named_parameter(get_cost_policy_t, get_cost_policy, get_cost) CGAL_add_named_parameter(get_placement_policy_t, get_placement_policy, get_placement) diff --git a/BGL/test/BGL/test_cgal_bgl_named_params.cpp b/BGL/test/BGL/test_cgal_bgl_named_params.cpp index 59120379db6..ed60b02f4f5 100644 --- a/BGL/test/BGL/test_cgal_bgl_named_params.cpp +++ b/BGL/test/BGL/test_cgal_bgl_named_params.cpp @@ -166,6 +166,8 @@ void test(const NamedParameters& np) check_same_type<49>(get_param(np, CGAL::internal_np::error_codes)); check_same_type<50>(get_param(np, CGAL::internal_np::volume_inclusions)); check_same_type<51>(get_param(np, CGAL::internal_np::face_connected_component_map)); + check_same_type<52>(get_param(np, CGAL::internal_np::connected_component_id_to_volume_id)); + check_same_type<53>(get_param(np, CGAL::internal_np::is_cc_outward_oriented)); // Named parameters that we use in the package 'Surface Mesh Simplification' check_same_type<34>(get_param(np, CGAL::internal_np::get_cost_policy)); @@ -248,6 +250,8 @@ int main() .error_codes(A<49>(49)) .volume_inclusions(A<50>(50)) .face_connected_component_map(A<51>(51)) + .connected_component_id_to_volume_id(A<52>(52)) + .is_cc_outward_oriented(A<53>(53)) ); return EXIT_SUCCESS; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 77afe890828..6e122e5c92a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -776,6 +776,46 @@ void set_f_cc_id(const std::vector&, const TriangleMesh&) {} +template +void copy_cc_to_volume_id( + std::vector& cc_volume_ids, + RefToVector ref_to_vector) +{ + ref_to_vector.get().swap( cc_volume_ids ); +} + +inline void copy_cc_to_volume_id( + const std::vector&, + boost::param_not_found) +{} + +template +void copy_orientation_bitset( + const std::vector& is_cc_outward_oriented, + RefToBitset ref_to_bs) +{ + ref_to_bs.get() = is_cc_outward_oriented; +} + +inline void copy_orientation_bitset( + const boost::dynamic_bitset<>&, + boost::param_not_found) +{} + +template +void set_cc_intersecting_pairs(const std::set< std::pair >& self_intersecting_cc, + OutputIterator out) +{ + for (const std::pair& p : self_intersecting_cc) + { + *out++=p; + } +} + +inline void set_cc_intersecting_pairs(const std::set< std::pair >&, + boost::param_not_found) +{} + } // internal @@ -867,6 +907,21 @@ void set_f_cc_id(const std::vector&, * if `true`, the input might contain some self-intersections and a test is done * prior to the volume decomposition. * \cgalParamEnd + * \cgalParamBegin{connected_component_id_to_volume_id} + * a `reference_wrapper` (either from `boost` or the standard library) containing + * a reference to an object of type `std::vector< std::size_t >`. + * The size of the vector is exactly the number of connected components. + * For each connected component identified using its id `ccid`, the id of the volume it contributes + * to describe is the value at the position `ccid` in the parameter vector. + * \cgalParamEnd + * \cgalParamBegin{is_cc_outward_oriented} + * a `reference_wrapper` (either from `boost` or the standard library) containing + * a reference to an object of type `std::vector`. + * The size of the vector is exactly the number of connected components. + * For each connected component identified using its id `ccid`, the output of `is_outward_oriented` + * called on the submesh corresponding to this connected component + * is the value at the position `ccid` in the parameter vector. + * \cgalParamEnd * \cgalNamedParamsEnd * * \return the number of volume components defined by `tm` @@ -913,8 +968,13 @@ volume_connected_components(const TriangleMesh& tm, const bool do_self_intersection_tests = boost::choose_param(boost::get_param(np, internal_np::do_self_intersection_tests), false); + const bool ignore_orientation_of_cc = + !boost::choose_param(boost::get_param(np, internal_np::do_orientation_tests), + true); std::vector error_codes; + std::vector is_cc_outward_oriented; + std::vector cc_volume_ids(nb_cc, -1); if (nb_cc == 1) { @@ -926,11 +986,17 @@ volume_connected_components(const TriangleMesh& tm, internal::copy_error_codes(error_codes, boost::get_param(np, internal_np::error_codes)); // nested_cc_per_cc is empty and used to clear the vector passed in case it was not empty internal::copy_nested_parents(nested_cc_per_cc, boost::get_param(np, internal_np::volume_inclusions)); + if (!ignore_orientation_of_cc && + !boost::is_default_param(get_param(np, internal_np::connected_component_id_to_volume_id))) + { + is_cc_outward_oriented.push_back(is_outward_oriented(tm, np)); + internal::copy_orientation_bitset(is_cc_outward_oriented, boost::get_param(np, internal_np::is_cc_outward_oriented)); + } + internal::copy_cc_to_volume_id(cc_volume_ids, boost::get_param(np, internal_np::connected_component_id_to_volume_id)); return 1; } boost::dynamic_bitset<> cc_handled(nb_cc, 0); - std::vector cc_volume_ids(nb_cc, -1); std::size_t next_volume_id = 0; // Handle open connected components @@ -994,12 +1060,7 @@ volume_connected_components(const TriangleMesh& tm, xtrm_vertices[cc_id]=vd; } - const bool ignore_orientation_of_cc = - !boost::choose_param(boost::get_param(np, internal_np::do_orientation_tests), - true); - // fill orientation vector for each surface CC - boost::dynamic_bitset<> is_cc_outward_oriented; if (!ignore_orientation_of_cc) { is_cc_outward_oriented.resize(nb_cc); @@ -1267,6 +1328,10 @@ volume_connected_components(const TriangleMesh& tm, CGAL_assertion(next_volume_id == error_codes.size()); internal::copy_error_codes(error_codes, boost::get_param(np, internal_np::error_codes)); internal::copy_nested_parents(nesting_parents, boost::get_param(np, internal_np::volume_inclusions)); + internal::copy_cc_to_volume_id(cc_volume_ids, boost::get_param(np, internal_np::connected_component_id_to_volume_id)); + internal::copy_orientation_bitset(is_cc_outward_oriented, boost::get_param(np, internal_np::is_cc_outward_oriented)); + //internal::set_cc_intersecting_pairs + return next_volume_id; }