diff --git a/Packages/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h b/Packages/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h index 755f16d3e28..d9804ede278 100644 --- a/Packages/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h +++ b/Packages/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h @@ -134,8 +134,16 @@ public: // to be made private after tests void make_hole_3D(Vertex_handle v, - std::set & boundhole, - std::set & boundvert); + std::set & boundhole, + std::set & boundvert, + std::list & outside, + std::list & inside); + + void undo_make_hole_3D(std::list & outside, + std::list & inside); + + void delete_cells(std::list & cells); + void delete_cells(std::list & cells); bool fill_hole_3D(std::set & boundhole, std::set & boundvert); @@ -368,21 +376,28 @@ remove_3D(Vertex_handle v) // std::cout << "removed point " << v->point() << std::endl; - make_hole_3D(v, boundary, bdvert); - bool b = fill_hole_3D(boundary, bdvert); - - delete( &(*v) ); - set_number_of_vertices(number_of_vertices()-1); - - return b; + std::list outside, inside; + make_hole_3D(v, boundary, bdvert, outside, inside); + bool filled = fill_hole_3D(boundary, bdvert); +if(filled){ + delete( &(*v) ); + delete_cells(inside); + set_number_of_vertices(number_of_vertices()-1); + } else { + undo_make_hole_3D(outside, inside); + } + return filled; + }// remove_3D(v) template < class Gt, class Tds > void Delaunay_triangulation_3:: make_hole_3D( Vertex_handle v, - std::set & boundhole, - std::set & boundvert) + std::set & boundhole, + std::set & boundvert, + std::list & outside, + std::list & inside) { CGAL_triangulation_precondition( ! test_dim_down(v) ); @@ -401,7 +416,9 @@ make_hole_3D( Vertex_handle v, opp_cit = (*cit)->neighbor( indv ); boundhole.insert - ( std::make_pair( opp_cit, opp_cit->index(*cit)) ); + ( std::make_pair( opp_cit, opp_cit->index(*cit)) ); + outside.push_back( std::make_pair( opp_cit, opp_cit->index(*cit)) ); + inside.push_back( std::make_pair( Cell_handle(*cit), indv) ); for ( i=0; i<4; i++) { if ( i != indv ) { vi = (*cit)->vertex(i); @@ -412,8 +429,6 @@ make_hole_3D( Vertex_handle v, } } } - - _tds.delete_cell( &*(*cit) ); ++cit; } while ( cit != cdone ); @@ -421,6 +436,52 @@ make_hole_3D( Vertex_handle v, return; }// make_hole_3D + + + + + +template < class Gt, class Tds > +void +Delaunay_triangulation_3:: +undo_make_hole_3D(std::list & outside, + std::list & inside){ + std::list::iterator cit = inside.begin(); + for(std::list::iterator fit = outside.begin(); + fit != outside.end(); + fit++) { + Cell_handle ch = (*fit).first; + ch->set_neighbor((*fit).second, (*cit).first); + CGAL_triangulation_assertion( (*cit).first->neighbor((*cit).second) == ch ); + for(int i = 0; i < 4; i++) { + ch->vertex(i)->set_cell(ch); + } + cit++; + } +} + + +template < class Gt, class Tds > +void +Delaunay_triangulation_3:: +delete_cells(std::list & hole) { + for(std::list::iterator cit = hole.begin(); cit != hole.end(); cit++) { + _tds.delete_cell( &*(*cit) ); + } +} + + +template < class Gt, class Tds > +void +Delaunay_triangulation_3:: +delete_cells(std::list & hole) { + for(std::list::iterator cit = hole.begin(); cit != hole.end(); cit++) { + _tds.delete_cell( &*((*cit).first) ); + } +} + + + //debug template < class Gt, class Tds > void @@ -444,6 +505,7 @@ fill_hole_3D( std::set & boundhole, typename std::set::iterator fit; typename std::set::iterator fitset_tmp; + std::list cells; Facet fit_stick; typename std::list::iterator fitlist_tmp; @@ -534,6 +596,7 @@ fill_hole_3D( std::set & boundhole, if ( nbnew == 0 ) { // the program is looping std::cerr << " !!!!! IMPOSSIBLE TO RETRIANGULATE !!!!! " << std::endl; + delete_cells(cells); return false; } nbnew = 0;