From 3e73d8fe2cbbf1ed880848b496a3246b4fe2bfb9 Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Tue, 3 Jul 2001 09:51:10 +0000 Subject: [PATCH] - _previous_cell and _next_cell are not set in the cell constructor and destructor automatically, so we do it by hand now for the list members of the TDS (via init_cell_list). - add_cell made private. --- .../CGAL/Triangulation_data_structure_3.h | 81 +++--- .../include/CGAL/Triangulation_ds_cell_3.h | 241 ++++++++++-------- 2 files changed, 180 insertions(+), 142 deletions(-) diff --git a/Packages/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h b/Packages/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h index afce0faa34f..48814a509fe 100644 --- a/Packages/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h +++ b/Packages/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h @@ -53,23 +53,16 @@ CGAL_BEGIN_NAMESPACE -template class Triangulation_ds_cell_iterator_3; -template class Triangulation_ds_facet_iterator_3; -template class Triangulation_ds_edge_iterator_3; -template class Triangulation_ds_vertex_iterator_3; - -template class Triangulation_ds_cell_circulator_3; -template class Triangulation_ds_facet_circulator_3; - template class Triangulation_data_structure_3; + template std::istream& operator >> (std::istream&, Triangulation_data_structure_3&); template class Triangulation_data_structure_3 - :public Triangulation_utils_3 + : public Triangulation_utils_3 { public: @@ -85,27 +78,34 @@ public: friend class Triangulation_ds_cell_circulator_3; friend class Triangulation_ds_facet_circulator_3; - typedef Triangulation_ds_vertex_3 Vertex; - typedef Triangulation_ds_cell_3 Cell; - typedef std::pair Facet; - typedef triple Edge; + typedef Triangulation_ds_vertex_3 Vertex; + typedef Triangulation_ds_cell_3 Cell; + typedef std::pair Facet; + typedef triple Edge; - typedef Triangulation_ds_cell_iterator_3 Cell_iterator; - typedef Triangulation_ds_facet_iterator_3 Facet_iterator; - typedef Triangulation_ds_edge_iterator_3 Edge_iterator; - typedef Triangulation_ds_vertex_iterator_3 Vertex_iterator; + typedef Triangulation_ds_cell_iterator_3 Cell_iterator; + typedef Triangulation_ds_facet_iterator_3 Facet_iterator; + typedef Triangulation_ds_edge_iterator_3 Edge_iterator; + typedef Triangulation_ds_vertex_iterator_3 Vertex_iterator; - typedef Triangulation_ds_cell_circulator_3 Cell_circulator; + typedef Triangulation_ds_cell_circulator_3 Cell_circulator; typedef Triangulation_ds_facet_circulator_3 Facet_circulator; Triangulation_data_structure_3() : _dimension(-2), _number_of_vertices(0) - {} + { + init_cell_list(&_list_of_cells); + init_cell_list(&_list_of_free_cells); + init_cell_list(&_list_of_temporary_free_cells); + } Triangulation_data_structure_3(const Tds & tds) : _number_of_vertices(0) // _number_of_vertices is set to 0 so that clear() in copy_tds() works { + init_cell_list(&_list_of_cells); + init_cell_list(&_list_of_free_cells); + init_cell_list(&_list_of_temporary_free_cells); copy_tds(tds); } @@ -194,6 +194,13 @@ private: return cnew; } + // Used to initialize the lists to empty lists. + void init_cell_list(Cell* c) + { + c->_next_cell = c; + c->_previous_cell = c; + } + void link_cells(Cell* a, Cell *b) { a->_next_cell = b; @@ -239,6 +246,14 @@ private: &_list_of_temporary_free_cells); } + void add_cell( Cell* c ) + { + CGAL_triangulation_precondition( c != NULL ); + + link_cells(c, _list_of_cells._next_cell); + link_cells(&_list_of_cells, c); + } + public: // not documented std::istream& read_cells(std::istream& is, @@ -249,14 +264,6 @@ public: std::ostream& print_cells(std::ostream& os, std::map< void*, int > &V ) const; - void add_cell( Cell* c ) - { - CGAL_triangulation_precondition( c != NULL ); - - link_cells(c, _list_of_cells._next_cell); - link_cells(&_list_of_cells, c); - } - // ACCESS FUNCTIONS void delete_cell( Cell* c ) @@ -306,16 +313,13 @@ public: bool flip(Cell* c, int i); void flip_flippable(Facet f); void flip_flippable(Cell* c, int i); -private: - // common to flip and filp_flippable - void flip_really(Cell* c, int i, Cell* n, int in); -public: bool flip(Edge e); bool flip(Cell* c, int i, int j); void flip_flippable(Edge e); void flip_flippable(Cell* c, int i, int j); private: // common to flip and filp_flippable + void flip_really(Cell* c, int i, Cell* n, int in); void flip_really(Cell* c, int i, int j, Cell* c1, Vertex* v1, int i1, int j1, int next1, Cell* c2, Vertex* v2, int i2, int j2, int next2, @@ -577,7 +581,6 @@ public: void clear_cells_only(std::vector & Vertices); - private: // in dimension i, number of vertices >= i+2 // ( the boundary of a simplex in dimension i+1 has i+2 vertices ) @@ -711,7 +714,6 @@ operator<<(std::ostream& os, const Triangulation_data_structure_3 &tds) } CGAL_triangulation_assertion( i == n ); - //print_cells(os, tds, V); tds.print_cells(os, V); return os; @@ -2480,14 +2482,18 @@ clear_cells_only(std::vector & Vertices) // Delete the cells in the free_list. for (it = _list_of_free_cells._next_cell; it != &_list_of_free_cells; - it = _list_of_free_cells._next_cell) + it = _list_of_free_cells._next_cell) { + remove_cell_from_list(it); delete it; + } if (number_of_vertices() == 0) { // the list of cells must be cleared even in this case for (it = _list_of_cells._next_cell; it != past_end_cell(); - it = _list_of_cells._next_cell) - delete it; // The ds_cell destructor removes it from the list. + it = _list_of_cells._next_cell) { + remove_cell_from_list(it); + delete it; + } // then _list_of_cells points on itself, nothing more to do set_dimension(-2); @@ -2507,7 +2513,8 @@ clear_cells_only(std::vector & Vertices) for (int i=0; i<=std::max(0,dimension()); i++) if (it->vertex(i)->cell() == it) Vertices.push_back(&(*it->vertex(i))); - delete it; // The ds_cell destructor removes it from the list. + remove_cell_from_list(it); + delete it; } // then _list_of_cells points on itself, nothing more to do diff --git a/Packages/Triangulation_3/include/CGAL/Triangulation_ds_cell_3.h b/Packages/Triangulation_3/include/CGAL/Triangulation_ds_cell_3.h index 2be9b9683b7..187a1d70853 100644 --- a/Packages/Triangulation_3/include/CGAL/Triangulation_ds_cell_3.h +++ b/Packages/Triangulation_3/include/CGAL/Triangulation_ds_cell_3.h @@ -60,11 +60,8 @@ public: typedef Triangulation_ds_vertex_3 Vertex; typedef Triangulation_ds_cell_3 Cell; - // used only for initializing _list_of_*cells by the constructors of - // Triangulation_data_structure_3 - // private ? Triangulation_ds_cell_3() - : Cb(), _previous_cell(this), _next_cell(this), in_conflict_flag(0) + : Cb(), in_conflict_flag(0) {} Triangulation_ds_cell_3(Cell* c) @@ -73,13 +70,13 @@ public: Triangulation_ds_cell_3(Vertex* v0, Vertex* v1, Vertex* v2, Vertex* v3) - : Cb(v0,v1,v2,v3), in_conflict_flag(0) + : Cb(v0,v1,v2,v3), in_conflict_flag(0) {} Triangulation_ds_cell_3(Vertex* v0, Vertex* v1, Vertex* v2, Vertex* v3, Cell* n0, Cell* n1, Cell* n2, Cell* n3) - : Cb(v0,v1,v2,v3,n0,n1,n2,n3), in_conflict_flag(0) + : Cb(v0,v1,v2,v3,n0,n1,n2,n3), in_conflict_flag(0) {} // not documented @@ -87,17 +84,11 @@ public: Triangulation_ds_cell_3(Vertex* v0, Vertex* v1, Vertex* v2, Vertex* v3, const Cell& old_cell) - : Cb(old_cell), in_conflict_flag(0) + : Cb(old_cell), in_conflict_flag(0) { set_vertices(v0,v1,v2,v3); } - ~Triangulation_ds_cell_3() - { - _previous_cell->_next_cell = _next_cell; - _next_cell->_previous_cell = _previous_cell; - } - // SETTING void set_vertex(int i, Vertex* v) @@ -198,14 +189,6 @@ private: return in_conflict_flag; } -// void add_list(Tds & tds) -// { -// this->_next_cell = tds.list_of_cells()._next_cell; -// tds.list_of_cells()._next_cell=this; -// this->_next_cell->_previous_cell = this; -// this->_previous_cell = tds.past_end_cell(); -// } - void error_orient( Cell * , int i ) const { std::cerr << " pb orientation with neighbor " << i << std::endl; @@ -229,19 +212,25 @@ Triangulation_ds_cell_3::is_valid case -1: { if ( vertex(0) == NULL ) { - if (verbose) { std::cerr << "vertex 0 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 0 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } vertex(0)->is_valid(verbose,level); if ( vertex(1) != NULL || vertex(2) != NULL || vertex(3) != NULL ) { - if (verbose) { std::cerr << "vertex 1,2 or 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 1,2 or 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( neighbor(0) != NULL || neighbor(1) != NULL || neighbor(2) != NULL || neighbor(3) != NULL ) { - if (verbose) { std::cerr << "one neighbor != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "one neighbor != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } break; } @@ -249,29 +238,37 @@ Triangulation_ds_cell_3::is_valid case 0: { if ( vertex(0) == NULL ) { - if (verbose) { std::cerr << "vertex 0 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 0 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } vertex(0)->is_valid(verbose,level); if ( neighbor (0) == NULL ) { - if (verbose) { std::cerr << "neighbor 0 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 0 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } - if ( vertex(1) != NULL || - vertex(2) != NULL || vertex(3) != NULL ) { - if (verbose) { std::cerr << "vertex 1, 2 or 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if ( vertex(1) != NULL || vertex(2) != NULL || vertex(3) != NULL ) { + if (verbose) + std::cerr << "vertex 1, 2 or 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( neighbor(1) != NULL || neighbor(2) != NULL || neighbor(3) != NULL ) { - if (verbose) { std::cerr << "neighbor 1, 2 or 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 1, 2 or 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( ! neighbor(0)->has_vertex(vertex(0)) ) { - if (verbose) { std::cerr << "neighbor 0 does not have vertex 0" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 0 does not have vertex 0" << std::endl; + CGAL_triangulation_assertion(false); + return false; } break; } @@ -284,48 +281,60 @@ Triangulation_ds_cell_3::is_valid Cell* n1 = neighbor(1); if ( v0 == NULL || v1 == NULL ) { - if (verbose) { std::cerr << "vertex 0 or 1 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 0 or 1 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } vertex(0)->is_valid(verbose,level); vertex(1)->is_valid(verbose,level); if ( n0 == NULL || n1 == NULL ) { - if (verbose) { std::cerr << "neighbor 0 or 1 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 0 or 1 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( vertex(2) != NULL || vertex(3) != NULL ) { - if (verbose) { std::cerr << "vertex 2 or 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 2 or 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( neighbor(2) != NULL || neighbor(3) != NULL ) { - if (verbose) { std::cerr << "neighbor 2 or 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 2 or 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( v0 != n1->vertex(1) ) { - if (verbose) { std::cerr << - "neighbor 1 does not have vertex 0 as vertex 1" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 1 does not have vertex 0 as vertex 1" + << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( v1 != n0->vertex(0) ) { - if (verbose) { std::cerr << - "neighbor 0 does not have vertex 1 as vertex 0" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 0 does not have vertex 1 as vertex 0" + << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( this != n0->neighbor(1) ) { - if (verbose) { std::cerr << - "neighbor 0 does not have this as neighbor 1" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 0 does not have this as neighbor 1" + << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( this != n1->neighbor(0) ) { - if (verbose) { std::cerr << - "neighbor 1 does not have this as neighbor 0" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 1 does not have this as neighbor 0" + << std::endl; + CGAL_triangulation_assertion(false); + return false; } break; @@ -334,19 +343,25 @@ Triangulation_ds_cell_3::is_valid case 2: { if ( vertex(0) == NULL || vertex(1) == NULL || vertex(2) == NULL ) { - if (verbose) { std::cerr << "vertex 0, 1, or 2 NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 0, 1, or 2 NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } vertex(0)->is_valid(verbose,level); vertex(1)->is_valid(verbose,level); vertex(2)->is_valid(verbose,level); if ( vertex(3) != NULL ) { - if (verbose) { std::cerr << "vertex 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( neighbor(3) != NULL ) { - if (verbose) { std::cerr << "neighbor 3 != NULL" << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor 3 != NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } int in; @@ -354,28 +369,34 @@ Triangulation_ds_cell_3::is_valid for(int i = 0; i < 3; i++) { n = neighbor(i); if ( n == NULL ) { - if (verbose) { std::cerr << "neighbor " << i << " NULL" - << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor " << i << " NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( ! n->has_vertex(vertex(cw(i)),in ) ) { - if (verbose) { std::cerr << "vertex " << cw(i) - << " not vertex of neighbor " << i - << std::endl; } - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex " << cw(i) + << " not vertex of neighbor " << i << std::endl; + CGAL_triangulation_assertion(false); + return false; } in = cw(in); if ( this != n->neighbor(in) ) { - if (verbose) { std::cerr << "neighbor " << i - << " does not have this as neighbor " - << in << std::endl; } - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "neighbor " << i + << " does not have this as neighbor " + << in << std::endl; + CGAL_triangulation_assertion(false); + return false; } if ( vertex(ccw(i)) != n->vertex(cw(in)) ) { - if (verbose) { std::cerr << "vertex " << ccw(i) - << " is not vertex " << cw(in) - << " of neighbor " << i << std::endl;} - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex " << ccw(i) + << " is not vertex " << cw(in) + << " of neighbor " << i << std::endl; + CGAL_triangulation_assertion(false); + return false; } } break; @@ -386,10 +407,10 @@ Triangulation_ds_cell_3::is_valid int i; for(i = 0; i < 4; i++) { if ( vertex(i) == NULL ) { - if (verbose) { - std::cerr << "vertex " << i << " NULL" << std::endl; - } - CGAL_triangulation_assertion(false); return false; + if (verbose) + std::cerr << "vertex " << i << " NULL" << std::endl; + CGAL_triangulation_assertion(false); + return false; } vertex(i)->is_valid(verbose,level); } @@ -397,18 +418,18 @@ Triangulation_ds_cell_3::is_valid for(i = 0; i < 4; i++) { Cell* n = neighbor(i); if ( n == NULL ) { - if (verbose) { + if (verbose) std::cerr << "neighbor " << i << " NULL" << std::endl; - } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } int in; if ( ! n->has_neighbor(this,in) ) { - if (verbose) { + if (verbose) error_neighbor(n,i,in); - } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } int j1n,j2n,j3n; @@ -416,25 +437,29 @@ Triangulation_ds_cell_3::is_valid if (verbose) { std::cerr << "vertex " << ((i+1)&3) << " not vertex of neighbor " << i << std::endl; } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } if ( ! n->has_vertex(vertex((i+2)&3),j2n) ) { if (verbose) { std::cerr << "vertex " << ((i+2)&3) << " not vertex of neighbor " << i << std::endl; } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } if ( ! n->has_vertex(vertex((i+3)&3),j3n) ) { if (verbose) { std::cerr << "vertex " << ((i+3)&3) << " not vertex of neighbor " << i << std::endl; } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } if ( in+j1n+j2n+j3n != 6) { if (verbose) { std::cerr << "sum of the indices != 6 " << std::endl; } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } // tests whether the orientations of this and n are consistent @@ -444,7 +469,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } if ( j1n == ((in+2)&3) ) { @@ -452,7 +478,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } if ( j1n == ((in+3)&3) ) { @@ -460,7 +487,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } } @@ -470,7 +498,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } if ( j1n == ((in+2)&3) ) { @@ -478,7 +507,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } if ( j1n == ((in+3)&3) ) { @@ -486,7 +516,8 @@ Triangulation_ds_cell_3::is_valid if (verbose) { error_orient(n,i); } - CGAL_triangulation_assertion(false); return false; + CGAL_triangulation_assertion(false); + return false; } } }