diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h index d9c52616549..e91717c0285 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Face_graph_output_builder.h @@ -127,6 +127,9 @@ class Face_graph_output_builder const VpmOutTuple& output_vpms; EdgeMarkMapTuple& out_edge_mark_maps; UserVisitor& user_visitor; + // mapping vertex to node id + Node_id_map vertex_to_node_id1, vertex_to_node_id2; + // output meshes const cpp11::array, 4>& requested_output; // input meshes closed ? @@ -445,6 +448,17 @@ public: } } + void set_vertex_id(vertex_descriptor v, Node_id node_id, const TriangleMesh& tm) + { + if (&tm == &tm1) + vertex_to_node_id1.insert( std::make_pair(v, node_id) ); + else + { + CGAL_assertion(&tm == &tm2); + vertex_to_node_id2.insert( std::make_pair(v, node_id) ); + } + } + template void operator()( const Nodes_vector& nodes, @@ -452,30 +466,12 @@ public: const boost::dynamic_bitset<>& is_node_of_degree_one, const Mesh_to_map_node&) { - // first build an unordered_map mapping a vertex to its node id + CGAL_assertion( vertex_to_node_id1.size() == vertex_to_node_id2.size()); + CGAL_assertion( vertex_to_node_id1.size() == nodes.size()); + + // TODO check if Intersection_edge_map needs to be so complicated (id stored...) Intersection_edge_map& intersection_edges1 = mesh_to_intersection_edges[&tm1]; - Node_id_map vertex_to_node_id1; - - for (typename Intersection_edge_map::iterator - it=intersection_edges1.begin(), - it_end=intersection_edges1.end(); it!=it_end; ++it) - { - vertex_to_node_id1[source(it->first,tm1)]=it->second.first; - vertex_to_node_id1[target(it->first,tm1)]=it->second.second; - } - Intersection_edge_map& intersection_edges2 = mesh_to_intersection_edges[&tm2]; - Node_id_map vertex_to_node_id2; - - for (typename Intersection_edge_map::iterator - it=intersection_edges2.begin(), - it_end=intersection_edges2.end(); it!=it_end; ++it) - { - vertex_to_node_id2[source(it->first,tm2)]=it->second.first; - vertex_to_node_id2[target(it->first,tm2)]=it->second.second; - } - - CGAL_assertion(intersection_edges1.size()==intersection_edges2.size()); // this will initialize face indices if the face index map is writable. helpers::init_face_indices(tm1, fids1); @@ -650,7 +646,7 @@ public: .face_index_map(fids2)); std::vector tm2_patch_sizes(nb_patches_tm2, 0); - BOOST_FOREACH(std::size_t i, tm2_patch_ids) + BOOST_FOREACH(Node_id i, tm2_patch_ids) if(i!=NID) ++tm2_patch_sizes[i]; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h index ba32b8948f2..0b04ec00e8b 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Output_builder_for_autorefinement.h @@ -110,6 +110,7 @@ class Output_builder_for_autorefinement const VertexPointMap &vpm; const FaceIdMap &fids; Ecm& ecm; + Node_id_map vertex_to_node_id; // input meshes closed ? bool is_tm_closed; // orientation of input surface mesh @@ -208,6 +209,13 @@ public: all_intersection_edges_map[indices].add(hedge); } + void set_vertex_id(vertex_descriptor v, Node_id node_id, const TriangleMesh& tm_) + { + CGAL_USE(tm_); + CGAL_assertion(&tm_==&tm); + vertex_to_node_id.insert( std::make_pair(v, node_id) ); + } + template void operator()( const Nodes_vector& nodes, @@ -220,7 +228,6 @@ public: // first build an unordered_map mapping a vertex to its node id + a set // of all intersection edges - Node_id_map vertex_to_node_id; typedef boost::unordered_set Intersection_edge_map; Intersection_edge_map intersection_edges; @@ -233,10 +240,10 @@ public: // and will be discarded later if (p.second.h2==boost::graph_traits::null_halfedge()) continue; - vertex_to_node_id[source(p.second.h1, tm)] = p.first.first; - vertex_to_node_id[target(p.second.h1, tm)] = p.first.second; - vertex_to_node_id[source(p.second.h2, tm)] = p.first.first; - vertex_to_node_id[target(p.second.h2, tm)] = p.first.second; + CGAL_assertion( vertex_to_node_id[source(p.second.h1, tm)] == p.first.first); + CGAL_assertion( vertex_to_node_id[target(p.second.h1, tm)] == p.first.second); + CGAL_assertion( vertex_to_node_id[source(p.second.h2, tm)] == p.first.first); + CGAL_assertion( vertex_to_node_id[target(p.second.h2, tm)] == p.first.second); intersection_edges.insert(edge(p.second.h1, tm)); intersection_edges.insert(edge(p.second.h2, tm)); } diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Visitor.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Visitor.h index 7b73309e1c9..68866f70c7c 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Visitor.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/Visitor.h @@ -96,6 +96,8 @@ struct No_extra_output_from_corefinement void set_edge_per_polyline(G& /*tm*/, Node_id_pair /*indices*/, halfedge_descriptor /*hedge*/){} + template + void set_vertex_id(vertex_descriptor, Node_id, const G&){} template void operator()( @@ -359,6 +361,7 @@ public: node_id_to_vertex[node_id]=target(h_2,tm2); all_incident_faces_got_a_node_as_vertex(h_2,node_id,*tm2_ptr); // check_node_on_non_manifold_vertex(node_id,h_2,tm2); + output_builder.set_vertex_id(target(h_2, tm2), node_id, tm2); } break; default: @@ -376,6 +379,8 @@ public: node_id_to_vertex.resize(node_id+1,Graph_traits::null_vertex()); node_id_to_vertex[node_id]=target(h_1,tm1); all_incident_faces_got_a_node_as_vertex(h_1,node_id, *tm1_ptr); + // register the vertex in the output builder + output_builder.set_vertex_id(target(h_1, tm1), node_id, tm1); // check_node_on_non_manifold_vertex(node_id,h_1,tm1); } else{ @@ -388,6 +393,8 @@ public: node_id_to_vertex.resize(node_id+1,Graph_traits::null_vertex()); node_id_to_vertex[node_id]=source(h_1,tm1); all_incident_faces_got_a_node_as_vertex(h_1_opp,node_id, *tm1_ptr); + // register the vertex in the output builder + output_builder.set_vertex_id(source(h_1, tm1), node_id, tm1); // check_node_on_non_manifold_vertex(node_id,h_1_opp,tm1); } else{ @@ -752,7 +759,8 @@ public: vertex_descriptor vnew=target(hnew,tm); // user_visitor.new_vertex_added(node_id, vnew, tm); // NODE_VISITOR_TAG nodes.call_put(vpm, vnew, node_id, tm); - + // register the new vertex in the output builder + output_builder.set_vertex_id(vnew, node_id, tm); node_id_to_vertex[node_id]=vnew; if (first){ first=false; @@ -996,7 +1004,7 @@ public: // import the triangle in `cdt` in the face `f` of `tm` triangulate_a_face(f, tm, nodes, node_ids, node_id_to_vertex, - edge_to_hedge, cdt, vpm, user_visitor); + edge_to_hedge, cdt, vpm, output_builder, user_visitor); // TODO Here we do the update only for internal edges. // Update for border halfedges could be done during the split diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index be442040d31..ff7b54ae717 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -263,6 +263,7 @@ template < class TriangleMesh, class Node_id, class Node_vector, class CDT, + class OutputBuilder, class UserVisitor> void triangulate_a_face( @@ -277,6 +278,7 @@ triangulate_a_face( ::halfedge_descriptor>& edge_to_hedge, const CDT& cdt, const VertexPointMap& vpm, + OutputBuilder& output_builder, UserVisitor& user_visitor) { typedef boost::graph_traits GT; @@ -292,6 +294,9 @@ triangulate_a_face( vertex_descriptor v=add_vertex(tm); // user_visitor.new_vertex_added(node_id, v, tm); // NODE_VISITOR_TAG nodes.call_put(vpm, v, node_id, tm); + // register the new vertex in the output builder + output_builder.set_vertex_id(v, node_id, tm); + CGAL_assertion(node_id_to_vertex.size()>node_id); node_id_to_vertex[node_id]=v; }