From cd6ffdc12ae79e7a94d7d2ce8bf1080ef1ed59b2 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 17 May 2018 09:41:57 +0200 Subject: [PATCH] Add property maps for simplex mapping. Also adds an operator()(const T&){} to Emptyset_iterator so it can be used by boost::function_output_iterator(). --- BGL/doc/BGL/NamedParameters.txt | 30 ++++++ .../BGL_polyhedron_3/copy_polyhedron.cpp | 9 +- .../CGAL/boost/graph/copy_face_graph.h | 99 +++++++++++++++++-- .../CGAL/boost/graph/parameters_interface.h | 4 + BGL/test/BGL/test_cgal_bgl_named_params.cpp | 10 ++ STL_Extension/include/CGAL/iterator.h | 3 + 6 files changed, 147 insertions(+), 8 deletions(-) diff --git a/BGL/doc/BGL/NamedParameters.txt b/BGL/doc/BGL/NamedParameters.txt index 4c104c6be88..4bde1971424 100644 --- a/BGL/doc/BGL/NamedParameters.txt +++ b/BGL/doc/BGL/NamedParameters.txt @@ -143,6 +143,36 @@ operation.\n Default: Emptyset_iterator \cgalNPEnd +\cgalNPBegin{vertex_to_vertex_map} \anchor BGL_vertex_to_vertex_map +is a property map storing for each vertex of a source mesh the corresponding vertex of another mesh.\n +A typical use case is mapping the vertices from a source mesh to its copy's after a `copy_face_graph()` +operation.\n +Type:a class model of `ReadWritePropertyMap` with +`boost::graph_traits::%vertex_descriptor` as key type and +`boost::graph_traits::%vertex_descriptor` as value type.\n +Default: None. +\cgalNPEnd + +\cgalNPBegin{halfedge_to_halfedge_map} \anchor BGL_halfedge_to_halfedge_map +is a property map storing for each halfedge of a source mesh the corresponding halfedge of another mesh.\n +A typical use case is mapping the vertices from a source mesh to its copy's after a `copy_face_graph()` +operation.\n +Type:a class model of `ReadWritePropertyMap` with +`boost::graph_traits::%halfedge_descriptor` as key type and +`boost::graph_traits::%halfedge_descriptor` as value type.\n +Default: None. +\cgalNPEnd + +\cgalNPBegin{face_to_face_map} \anchor BGL_face_to_face_map +is a property map storing for each face of a source mesh the corresponding face of another mesh.\n +A typical use case is mapping the vertices from a source mesh to its copy's after a `copy_face_graph()` +operation.\n +Type:a class model of `ReadWritePropertyMap` with +`boost::graph_traits::%face_descriptor` as key type and +`boost::graph_traits::%face_descriptor` as value type.\n +Default: None. +\cgalNPEnd + \cgalNPTableEnd diff --git a/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp index d0751244077..75e8bc7a224 100644 --- a/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp +++ b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp @@ -67,16 +67,23 @@ int main(int argc, char* argv[]) { typedef boost::graph_traits::vertex_descriptor source_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor source_halfedge_descriptor; + typedef boost::graph_traits::face_descriptor source_face_descriptor; typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; + typedef boost::graph_traits::face_descriptor tm_face_descriptor; + boost::unordered_map v2v; boost::unordered_map h2h; - + boost::unordered_map f2f; CGAL::copy_face_graph(T1, S, std::inserter(v2v, v2v.end()), std::inserter(h2h, h2h.end())); std::ofstream out("reverse.off"); out << S; + CGAL::copy_face_graph(T1, S, CGAL::parameters::vertex_to_vertex_map(boost::make_assoc_property_map(v2v)) + .halfedge_to_halfedge_output_iterator(std::inserter(h2h, h2h.end())) + .face_to_face_map(boost::make_assoc_property_map(f2f))); + CGAL::copy_face_graph(T1, S); } return 0; } diff --git a/BGL/include/CGAL/boost/graph/copy_face_graph.h b/BGL/include/CGAL/boost/graph/copy_face_graph.h index 57feb8f9c1c..2db81eaa49c 100644 --- a/BGL/include/CGAL/boost/graph/copy_face_graph.h +++ b/BGL/include/CGAL/boost/graph/copy_face_graph.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace CGAL { @@ -211,6 +212,35 @@ void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, sm_vpm, tm_vpm); } +template +struct Output_iterator_functor +{ + typedef typename boost::property_traits::key_type input_t; + typedef typename boost::property_traits::value_type output_t; + PMAP map; + Output_iterator_functor(PMAP map) + :map(map) + { + } + void operator()(const typename std::pair& pair) + { + put(map, pair.first, pair.second); + } + +}; + +template +Output_iterator_functor make_functor(PMAP map) +{ + return Output_iterator_functor(map); +} + +Emptyset_iterator make_functor(const boost::param_not_found&) +{ + return Emptyset_iterator(); +} + + } // end of namespace internal @@ -242,14 +272,26 @@ void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` should be available in `SourceMesh` (`TargetMesh`) \cgalParamEnd - \cgalParamBegin{vertex_to_vertex_output_iterator} an `OutputIterator`containing the - pairs source-vertex, traget-vertex. + \cgalParamBegin{vertex_to_vertex_output_iterator} an `OutputIterator` containing the + pairs source-vertex, target-vertex. If this parameter is given, then + `vertex_to_vertex_map` cannot be used. \cgalParamEnd - \cgalParamBegin{halfedge_to_halfedge_output_iterator} an `OutputIterator`containing the - pairs source-halfedge, traget-halfedge. + \cgalParamBegin{halfedge_to_halfedge_output_iterator} an `OutputIterator` containing the + pairs source-halfedge, target-halfedge. If this parameter is given, then + `halfedge_to_halfedge_map` cannot be used. \cgalParamEnd - \cgalParamBegin{face_to_face_output_iterator} an `OutputIterator`containing the - pairs source-face, traget-face. + \cgalParamBegin{face_to_face_output_iterator} an `OutputIterator` containing the + pairs source-face, target-face. If this parameter is given, then + `face_to_face_map` cannot be used. + \cgalParamEnd + \cgalParamBegin{vertex_to_vertex_map} a `ReadWritePropertyMap` containing the + pairs source-vertex, target-vertex. + \cgalParamEnd + \cgalParamBegin{halfedge_to_halfedge_map} a `ReadWritePropertyMap` containing the + pairs source-halfedge, target-halfedge. + \cgalParamEnd + \cgalParamBegin{face_to_face_map} a `ReadWritePropertyMap` containing the + pairs source-face, target-face. \cgalParamEnd \cgalNamedParamsEnd @@ -289,6 +331,49 @@ void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, ) { using boost::choose_param; + if (boost::is_default_param(get_param(np1, internal_np::vertex_to_vertex_output_iterator))) + { + if (boost::is_default_param(get_param(np1, internal_np::vertex_to_vertex_map))){ + copy_face_graph(sm, tm, CGAL::parameters:: + vertex_to_vertex_output_iterator( + boost::make_function_output_iterator(internal::make_functor(get_param(np1, internal_np::vertex_to_vertex_map)))) + .halfedge_to_halfedge_output_iterator(get_param(np1, internal_np::halfedge_to_halfedge_output_iterator)) + .face_to_face_output_iterator(get_param(np1, internal_np::face_to_face_output_iterator)) + .halfedge_to_halfedge_map(get_param(np1, internal_np::halfedge_to_halfedge_map)) + .face_to_face_map(get_param(np1, internal_np::face_to_face_map)) + ,np2); + return; + } + } + else if (!boost::is_default_param(get_param(np1, internal_np::halfedge_to_halfedge_output_iterator))) + { + if (!boost::is_default_param(get_param(np1, internal_np::halfedge_to_halfedge_map))){ + copy_face_graph(sm, tm, CGAL::parameters:: + vertex_to_vertex_output_iterator(get_param(np1, internal_np::vertex_to_vertex_output_iterator)) + .halfedge_to_halfedge_output_iterator( + boost::make_function_output_iterator(internal::make_functor(get_param(np1, internal_np::halfedge_to_halfedge_map)))) + .face_to_face_output_iterator(get_param(np1, internal_np::face_to_face_output_iterator)) + .vertex_to_vertex_map(get_param(np1, internal_np::vertex_to_vertex_map)) + .face_to_face_map(get_param(np1, internal_np::face_to_face_map)) + ,np2); + return; + } + } + else if (!boost::is_default_param(get_param(np1, internal_np::face_to_face_output_iterator))) + { + if (!boost::is_default_param(get_param(np1, internal_np::face_to_face_map))) + { + copy_face_graph(sm, tm, CGAL::parameters:: + vertex_to_vertex_output_iterator(get_param(np1, internal_np::vertex_to_vertex_output_iterator)) + .halfedge_to_halfedge_output_iterator(get_param(np1, internal_np::halfedge_to_halfedge_output_iterator)) + .face_to_face_output_iterator( + boost::make_function_output_iterator(internal::make_functor(get_param(np1, internal_np::face_to_face_map)))) + .vertex_to_vertex_map(get_param(np1, internal_np::vertex_to_vertex_map)) + .halfedge_to_halfedge_map(get_param(np1, internal_np::halfedge_to_halfedge_map)) + ,np2); + return; + } + } internal::copy_face_graph(sm, tm, CGAL::graph_has_property(), choose_param(get_param(np1, internal_np::vertex_to_vertex_output_iterator), @@ -300,7 +385,7 @@ void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, choose_param(get_param(np1, internal_np::vertex_point), get(vertex_point, sm)), choose_param(get_param(np2, internal_np::vertex_point), - get(vertex_point, tm))); + get(vertex_point, tm))); } template diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index e2992063009..4be6eee42c9 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -37,6 +37,10 @@ CGAL_add_named_parameter(vertex_to_vertex_output_iterator_t, vertex_to_vertex_ou CGAL_add_named_parameter(halfedge_to_halfedge_output_iterator_t, halfedge_to_halfedge_output_iterator, halfedge_to_halfedge_output_iterator) CGAL_add_named_parameter(face_to_face_output_iterator_t, face_to_face_output_iterator, face_to_face_output_iterator) +CGAL_add_named_parameter(vertex_to_vertex_map_t, vertex_to_vertex_map, vertex_to_vertex_map) +CGAL_add_named_parameter(halfedge_to_halfedge_map_t, halfedge_to_halfedge_map, halfedge_to_halfedge_map) +CGAL_add_named_parameter(face_to_face_map_t, face_to_face_map, face_to_face_map) + // List of named parameters that we use in the package 'Mesh_3' CGAL_add_named_parameter(vertex_feature_degree_t, vertex_feature_degree, vertex_feature_degree_map) diff --git a/BGL/test/BGL/test_cgal_bgl_named_params.cpp b/BGL/test/BGL/test_cgal_bgl_named_params.cpp index eae588e550d..ac0402ad18d 100644 --- a/BGL/test/BGL/test_cgal_bgl_named_params.cpp +++ b/BGL/test/BGL/test_cgal_bgl_named_params.cpp @@ -47,6 +47,10 @@ void test(const NamedParameters& np) assert(get_param(np, CGAL::internal_np::vertex_to_vertex_output_iterator).v == 800000004); assert(get_param(np, CGAL::internal_np::halfedge_to_halfedge_output_iterator).v == 800000005); assert(get_param(np, CGAL::internal_np::face_to_face_output_iterator).v == 800000006); + + assert(get_param(np, CGAL::internal_np::vertex_to_vertex_map).v == 800000007); + assert(get_param(np, CGAL::internal_np::halfedge_to_halfedge_map).v == 800000008); + assert(get_param(np, CGAL::internal_np::face_to_face_map).v == 800000009); // Named parameters that we use in the package 'Mesh_3' @@ -115,6 +119,9 @@ void test(const NamedParameters& np) check_same_type<800000004>(get_param(np, CGAL::internal_np::vertex_to_vertex_output_iterator)); check_same_type<800000005>(get_param(np, CGAL::internal_np::halfedge_to_halfedge_output_iterator)); check_same_type<800000006>(get_param(np, CGAL::internal_np::face_to_face_output_iterator)); + check_same_type<800000007>(get_param(np, CGAL::internal_np::vertex_to_vertex_map)); + check_same_type<800000008>(get_param(np, CGAL::internal_np::halfedge_to_halfedge_map)); + check_same_type<800000009>(get_param(np, CGAL::internal_np::face_to_face_map)); // Named parameters that we use in the package 'Mesh_3' check_same_type<9>(get_param(np, CGAL::internal_np::vertex_feature_degree)); @@ -177,6 +184,9 @@ int main() .vertex_to_vertex_output_iterator(A<800000004>(800000004)) .halfedge_to_halfedge_output_iterator(A<800000005>(800000005)) .face_to_face_output_iterator(A<800000006>(800000006)) + .vertex_to_vertex_map(A<800000007>(800000007)) + .halfedge_to_halfedge_map(A<800000008>(800000008)) + .face_to_face_map(A<800000009>(800000009)) .vertex_feature_degree_map(A<9>(9)) .geom_traits(A<10>(10)) .vertex_incident_patches_map(A<11>(11)) diff --git a/STL_Extension/include/CGAL/iterator.h b/STL_Extension/include/CGAL/iterator.h index b88ed0cfd28..1526c50c566 100644 --- a/STL_Extension/include/CGAL/iterator.h +++ b/STL_Extension/include/CGAL/iterator.h @@ -113,6 +113,9 @@ struct iterator struct Emptyset_iterator : public CGAL::iterator< std::output_iterator_tag, void, void, void, void > { + template + void operator()(const T&) {} + template< class T > Emptyset_iterator& operator=(const T&) { return *this; }