diff --git a/TDS_2/doc/TDS_2/Concepts/TriangulationDataStructure_2.h b/TDS_2/doc/TDS_2/Concepts/TriangulationDataStructure_2.h index 6294a7ea62d..69fd89e0640 100644 --- a/TDS_2/doc/TDS_2/Concepts/TriangulationDataStructure_2.h +++ b/TDS_2/doc/TDS_2/Concepts/TriangulationDataStructure_2.h @@ -550,6 +550,31 @@ void dim_down(Face_handle f, int i); /// @{ +/*! +\cgalModifBegin +creates a new vertex `v` and uses it to star the hole +described by the sequence of edges `[edge_begin, edge_end]`. +The pre-existing faces in the hole are destroyed. +Returns a handle to the vertex `v`. + +\pre The sequence of edges `[edge_begin, edge_end]` is oriented counter-clockwise. +\cgalModifEnd +*/ +template< class EdgeIt > +Vertex_handle insert_in_hole(EdgeIt edge_begin, EdgeIt edge_end); + +/*! +\cgalModifBegin +uses the vertex `v` to star the hole described by the sequence +of edges `[edge_begin, edge_end]`. The pre-existing faces in the hole are destroyed. + +\pre The sequence of edges `[edge_begin, edge_end]` is oriented counter-clockwise. +\cgalModifEnd +*/ +template< class EdgeIt > +void insert_in_hole(Vertex_handle v, EdgeIt edge_begin, EdgeIt edge_end); + + /*! creates a new vertex `v` and use it to star the hole whose boundary is described by the sequence of edges `[edge_begin, edge_end)`. Returns a handle to the vertex. diff --git a/TDS_2/include/CGAL/Triangulation_data_structure_2.h b/TDS_2/include/CGAL/Triangulation_data_structure_2.h index 5dd7bd4d665..38ea308b2eb 100644 --- a/TDS_2/include/CGAL/Triangulation_data_structure_2.h +++ b/TDS_2/include/CGAL/Triangulation_data_structure_2.h @@ -428,6 +428,97 @@ public: // template members definition public: + + /************* START OF MODIFICATIONS (iiordanov) ***************/ + + + /* + * Creates a new vertex new_v and uses it to star the hole described + * by the sequence of edges [edge_begin, edge_end]. The pre-existing + * faces in the hole are destroyed. + * + * Prerequisite: the sequence [edge_begin, edge_end] is oriented + * counter-clockwise. + */ + + template< class EdgeIt > + Vertex_handle insert_in_hole(EdgeIt edge_begin, EdgeIt edge_end) + { + Vertex_handle new_v = create_vertex(); + insert_in_hole(new_v, edge_begin, edge_end); + return new_v; + } + + + /* + * Uses the vertex v to star the hole described by the sequence + * of edges [edge_begin, edge_end]. The pre-existing faces in + * the hole are destroyed. + * + * Prerequisite: the sequence [edge_begin, edge_end] is oriented + * counter-clockwise. + */ + template< class EdgeIt > + void insert_in_hole(Vertex_handle v, EdgeIt edge_begin, EdgeIt edge_end) + { + + // Keep new faces in a vector + std::vector new_faces; + + // Exploit std::set functionality to keep unique old faces + std::set old; + + for (EdgeIt it = edge_begin; it != edge_end; it++) { + Face_handle fh = (*it).first; + int i = (*it).second; + + old.insert(fh); + + // v + // . + // / \ + // / \ + // / \ + // / new_f \ + // v1 /_________\ v2 + // \ / + // \ nf / + // \ / + // \ / + // \ / + // * + // nf->vertex(j) + + Vertex_handle v1 = fh->vertex(ccw(i)); + Vertex_handle v2 = fh->vertex(cw(i)); + + Face_handle nf = fh->neighbor(i); + int j = mirror_index(fh, i); + + Face_handle new_f = create_face(v, v1, v2); + set_adjacency(new_f, 0, nf, j); + new_faces.push_back(new_f); + } + + // Set adjacency for the new faces + for (int i = 0; i < new_faces.size() - 1; i++) { + set_adjacency(new_faces[i], 1, new_faces[i+1], 2); + } + // The last one has to be treated separately + set_adjacency(new_faces[0], 2, new_faces[new_faces.size()-1], 1); + + // Delete the old faces + for (typename std::set::iterator it = old.begin(); it != old.end(); it++) { + delete_face(*it); + } + + // Set the new vertex to point at the first new face (arbitrarily) + v->set_face(new_faces[0]); + } + + /************* END OF MODIFICATIONS (iiordanov) ***************/ + + template< class EdgeIt> Vertex_handle star_hole(EdgeIt edge_begin, EdgeIt edge_end) // creates a new vertex diff --git a/TDS_2/test/TDS_2/include/CGAL/_test_cls_tds_2.h b/TDS_2/test/TDS_2/include/CGAL/_test_cls_tds_2.h index ea60804cbb0..b93b89c1160 100644 --- a/TDS_2/test/TDS_2/include/CGAL/_test_cls_tds_2.h +++ b/TDS_2/test/TDS_2/include/CGAL/_test_cls_tds_2.h @@ -128,7 +128,6 @@ _test_cls_tds_2( const Tds &) assert(tds3.dimension()== 1); assert(tds3.number_of_vertices() == 4); assert(tds3.is_valid() ); - Vertex_handle w4 = tds4.insert_first(); Vertex_handle v4_1 = tds4.insert_second(); @@ -187,6 +186,41 @@ _test_cls_tds_2( const Tds &) u4 = tds4.star_hole(hole); tds4.remove_degree_3(u4); + + // insert_in_hole + // Count also the faces with the vertex at infinity! + // + // 1 |------| 3 1 |------| 3 + // |\ | |\ /| + // | \ | | \ 4/ | + // | \ | --> | \/ | + // | \ | | /\ | + // | \ | | / \ | + // | \| |/ \| + // 2 |------| 0 2 |------| 0 + // + // + + std::cout << " insert_in_hole" << std::endl; + Tds td45; + Vertex_handle v045 = td45.insert_first(); + Vertex_handle v145 = td45.insert_second(); + Vertex_handle v245 = td45.insert_dim_up(v045, true); + Vertex_handle v345 = td45.insert_dim_up(v045, true); + + assert(td45.is_valid() && td45.number_of_vertices() == 4 && td45.number_of_faces() == 4); + + Face_iterator fi = td45.faces_begin(); + std::vector vhole; + vhole.push_back( Edge( fi, 2) ); + vhole.push_back( Edge( fi, 0) ); + vhole.push_back( Edge(++fi, 1) ); + vhole.push_back( Edge( fi, 2) ); + + Vertex_handle nv45 = td45.insert_in_hole(vhole.begin(), vhole.end()); + + assert(td45.is_valid() && td45.number_of_vertices() == 5 && td45.number_of_faces() == 6); + // dim_down std::cout << " dim_down" << std::endl; Tds td5;