diff --git a/Mesh_3/include/CGAL/Mesh_3/Protect_edges_sizing_field.h b/Mesh_3/include/CGAL/Mesh_3/Protect_edges_sizing_field.h index 3fdc4cf0b0b8..1f3c4fb13547 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Protect_edges_sizing_field.h +++ b/Mesh_3/include/CGAL/Mesh_3/Protect_edges_sizing_field.h @@ -1334,8 +1334,8 @@ refine_balls() restart = false; boost::unordered_map new_sizes; - for(typename Tr::Finite_edges_iterator eit = tr.finite_edges_begin(), - end = tr.finite_edges_end(); eit != end; ++eit) + for(typename Tr::Finite_marking_edges_iterator eit = tr.finite_marking_edges_begin(), + end = tr.finite_marking_edges_end(); eit != end; ++eit) { if(forced_stop()) break; const Vertex_handle& va = eit->first->vertex(eit->second); @@ -1384,6 +1384,10 @@ refine_balls() } } } + + tr.clear_marked_edges(); + + if(forced_stop()) new_sizes.clear(); // The std::map with Vertex_handle as the key is not robust, because diff --git a/Periodic_3_mesh_3/include/CGAL/Periodic_3_mesh_triangulation_3.h b/Periodic_3_mesh_3/include/CGAL/Periodic_3_mesh_triangulation_3.h index 4bef87373f51..da14606110ed 100644 --- a/Periodic_3_mesh_3/include/CGAL/Periodic_3_mesh_triangulation_3.h +++ b/Periodic_3_mesh_3/include/CGAL/Periodic_3_mesh_triangulation_3.h @@ -72,6 +72,7 @@ class Periodic_3_regular_triangulation_3_wrapper typedef typename Base::Cell_iterator Finite_cells_iterator; typedef typename Base::Facet_iterator Finite_facets_iterator; typedef typename Base::Edge_iterator Finite_edges_iterator; + typedef typename Base::Marking_edge_iterator Finite_marking_edges_iterator; typedef typename Base::Vertex_iterator Finite_vertices_iterator; typedef typename Base::Vertex_handle Vertex_handle; diff --git a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_regular_triangulation_3.h b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_regular_triangulation_3.h index 1664b9cbd32b..fbdf78b7f71d 100644 --- a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_regular_triangulation_3.h +++ b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_regular_triangulation_3.h @@ -94,6 +94,7 @@ class Periodic_3_regular_triangulation_3 typedef typename Tr_Base::Vertex_iterator Vertex_iterator; typedef typename Tr_Base::Edge_iterator Edge_iterator; + typedef typename Tr_Base::Marking_edge_iterator Marking_edge_iterator; typedef typename Tr_Base::Facet_iterator Facet_iterator; typedef typename Tr_Base::Facet_circulator Facet_circulator; typedef typename Tr_Base::Cell_iterator Cell_iterator; diff --git a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h index c96cb05bc111..a0b8e99e868c 100644 --- a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h +++ b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h @@ -158,6 +158,7 @@ class Periodic_3_triangulation_3 typedef typename TDS::Cell_iterator Cell_iterator; typedef typename TDS::Facet_iterator Facet_iterator; typedef typename TDS::Edge_iterator Edge_iterator; + typedef typename TDS::Marking_edge_iterator Marking_edge_iterator; typedef typename TDS::Vertex_iterator Vertex_iterator; typedef typename TDS::Cell_circulator Cell_circulator; @@ -225,6 +226,7 @@ class Periodic_3_triangulation_3 typedef Cell_iterator Finite_cells_iterator; typedef Facet_iterator Finite_facets_iterator; typedef Edge_iterator Finite_edges_iterator; + typedef Marking_edge_iterator Finite_marking_edges_iterator; typedef Vertex_iterator Finite_vertices_iterator; int dimension() const { return (number_of_vertices() == 0) ? -2 : 3; } @@ -1501,6 +1503,14 @@ class Periodic_3_triangulation_3 return _tds.vertices_end(); } + Finite_marking_edges_iterator finite_marking_edges_begin() const { return _tds.marking_edges_begin(); } + Finite_marking_edges_iterator finite_marking_edges_end() const { return _tds.marking_edges_end(); } + + void clear_marked_edges() + { + _tds.clear_marked_edges(); + } + All_edges_iterator all_edges_begin() const { return _tds.edges_begin(); } diff --git a/TDS_3/include/CGAL/Triangulation_data_structure_3.h b/TDS_3/include/CGAL/Triangulation_data_structure_3.h index 968da3301cae..008d56dadf92 100644 --- a/TDS_3/include/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/include/CGAL/Triangulation_data_structure_3.h @@ -95,24 +95,76 @@ class Triangulation_data_structure_3 class Cell_data { unsigned char conflict_state; + public: - Cell_data() : conflict_state(0) {} + Cell_data() : conflict_state(0) + {} + + void clear() + { + conflict_state &= 0B11111100 ; + } + + void mark_in_conflict() + { + conflict_state |= 0B00000001 ; + conflict_state &= 0B11111101 ; + } + + void mark_on_boundary() + { + conflict_state &= 0B11111110 ; + conflict_state |= 0B00000010 ; + + } + + void mark_processed() + { + conflict_state |= 0B00000001 ; + conflict_state &= 0B11111101 ; + } + + bool is_clear() const + { + return (conflict_state & 3) == 0; + } + + bool is_in_conflict() const + { + return (conflict_state & 3) == 1; + } + + bool is_on_boundary() const + { + return (conflict_state & 3) == 2; + } - void clear() { conflict_state = 0; } - void mark_in_conflict() { conflict_state = 1; } - void mark_on_boundary() { conflict_state = 2; } - void mark_processed() { conflict_state = 1; } + bool processed() const + { + return (conflict_state & 3) == 1; + } + + void set_edge(int i) + { + conflict_state |= (1 << (i+2)); + } + + bool edge(int i) + { + return (conflict_state >> (i+2)) & 0B00000001; + } - bool is_clear() const { return conflict_state == 0; } - bool is_in_conflict() const { return conflict_state == 1; } - bool is_on_boundary() const { return conflict_state == 2; } - bool processed() const { return conflict_state == 1; } + void clear_edges() + { + conflict_state &= 0B00000011; + } }; private: friend class internal::Triangulation_ds_facet_iterator_3; friend class internal::Triangulation_ds_edge_iterator_3; + friend class internal::Triangulation_ds_marking_edge_iterator_3; friend class internal::Triangulation_ds_cell_circulator_3; friend class internal::Triangulation_ds_facet_circulator_3; @@ -156,6 +208,7 @@ class Triangulation_data_structure_3 typedef internal::Triangulation_ds_facet_iterator_3 Facet_iterator; typedef internal::Triangulation_ds_edge_iterator_3 Edge_iterator; + typedef internal::Triangulation_ds_marking_edge_iterator_3 Marking_edge_iterator; typedef internal::Triangulation_ds_cell_circulator_3 Cell_circulator; typedef internal::Triangulation_ds_facet_circulator_3 Facet_circulator; @@ -678,6 +731,25 @@ class Triangulation_data_structure_3 return Edge_iterator(this,1); } + Marking_edge_iterator marking_edges_begin() const + { + if ( dimension() < 1 ) + return marking_edges_end(); + return Marking_edge_iterator(this); + } + + Marking_edge_iterator marking_edges_end() const + { + return Marking_edge_iterator(this,1); + } + + void clear_marked_edges() + { + for(Cell_handle ch : cell_handles()){ + ch->tds_data().clear_edges(); + } + } + Edges edges() const { return Edges(edges_begin(), edges_end()); @@ -4084,6 +4156,10 @@ count_edges(size_type & i, bool verbose, int level) const if (verbose) std::cerr << "invalid edge" << std::endl; CGAL_triangulation_assertion(false); + + for(Cell_iterator aci = cells_begin(); aci != cells_end(); ++aci){ + aci->tds_data().clear_edges(); + } return false; } ++i; diff --git a/TDS_3/include/CGAL/Triangulation_utils_3.h b/TDS_3/include/CGAL/Triangulation_utils_3.h index 8b99c725a65f..72a3aeab6069 100644 --- a/TDS_3/include/CGAL/Triangulation_utils_3.h +++ b/TDS_3/include/CGAL/Triangulation_utils_3.h @@ -25,6 +25,7 @@ namespace CGAL { template < class T = void > struct Triangulation_utils_base_3 { + static const int tab_edge_index[4][4]; static const char tab_next_around_edge[4][4]; static const int tab_vertex_triple_index[4][3]; @@ -33,6 +34,10 @@ struct Triangulation_utils_base_3 static const int cw_map[3]; }; +template < class T > +const int Triangulation_utils_base_3::tab_edge_index[4][4] = { + { -1, 0, 2, 3 }, { 0, -1, 1, 4}, {2, 1, -1, 5}, {3, 4, 5, -1} }; + template < class T > const char Triangulation_utils_base_3::tab_next_around_edge[4][4] = { {5, 2, 3, 1}, @@ -93,6 +98,10 @@ struct Triangulation_utils_3 return tab_vertex_triple_index[i][j]; } + static int edge_index(const int i, const int j) + { + return tab_edge_index[i][j]; + } }; } //namespace CGAL diff --git a/TDS_3/include/CGAL/internal/Triangulation_ds_iterators_3.h b/TDS_3/include/CGAL/internal/Triangulation_ds_iterators_3.h index 29936523cf62..af3f6d449347 100644 --- a/TDS_3/include/CGAL/internal/Triangulation_ds_iterators_3.h +++ b/TDS_3/include/CGAL/internal/Triangulation_ds_iterators_3.h @@ -449,6 +449,261 @@ class Triangulation_ds_edge_iterator_3 } }; + + +template < class Tds > +class Triangulation_ds_marking_edge_iterator_3 +{ +// traverses the list of cells and reports each edge. +public: + + typedef typename Tds::Edge value_type; + typedef const typename Tds::Edge * pointer; + typedef const typename Tds::Edge & reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + typedef typename Tds::Edge Edge; + typedef Triangulation_ds_marking_edge_iterator_3 Edge_iterator; + typedef typename Tds::Cell_iterator Cell_iterator; + typedef typename Tds::Cell_handle Cell_handle; + typedef internal::Triangulation_ds_cell_circulator_3 Cell_circulator; + + Triangulation_ds_marking_edge_iterator_3() + : _tds(nullptr) + { + edge.second = 0; + edge.third = 1; + } + + Triangulation_ds_marking_edge_iterator_3(const Tds * tds) + : _tds(tds) + { + edge.second = 0; + edge.third = 1; + switch ( _tds->dimension() ) { + case 1: + { + pos = _tds->cells().begin(); + return; + } + case 2: + { + pos = _tds->cells().begin(); + while ( // there must be at least one edge + pos->neighbor(3-edge.second-edge.third) < pos ) { + increment2(); + } + return; + } + case 3: + { + pos = _tds->cells().begin(); + int i(0), j(0); + int mini(0), minj(0); + for( ;; ) { + int ei = Tds::edge_index(edge.second,edge.third); + if(pos->tds_data().edge(ei)){ + increment3(); + continue; + } + // this edge was not yet considered + // now find the incident cell with the smallest index + edge.first = pos; + { + Cell_handle min = pos; + + Cell_circulator ccir = _tds->incident_cells(edge), done(ccir); + do { + Cell_handle ch = ccir; + i = ch->index(pos->vertex(edge.second)); + j = ch->index(pos->vertex(edge.third)); + int ei = Tds::edge_index(i,j); + ch->tds_data().set_edge(ei); + + if(ch <= min){ + min = ch; + mini = i; + minj = j; + } + + ++ccir; + }while(ccir != done); + report.first = min; + report.second = mini; + report.third = minj; + break; + } + + } + return; + } + default: + { + pos = _tds->cells().end(); + return; + } + } + } + + // used to initialize the past-the end iterator + Triangulation_ds_marking_edge_iterator_3(const Tds* tds, int) + : _tds(tds) + { + edge.second = 0; + edge.third = 1; + pos = _tds->cells().end(); + } + + Edge_iterator& operator++() + { + switch ( _tds->dimension() ) { + case 1: + { + ++pos; + break; + } + case 2: + { + do { + increment2(); + } while ( pos != _tds->cells().end() && + pos->neighbor(3-edge.second-edge.third) < pos ); + break; + } + case 3: + { + int i(0), j(0); + int mini(0), minj(0); + for( ;; ){ + increment3(); + if (pos != _tds->cells().end()) { + int ei = Tds::edge_index(edge.second,edge.third); + if(pos->tds_data().edge(ei)){ + continue; + } + // this edge was not yet considered + // now find the incident cell with the smallest index + Cell_handle min = pos; + edge.first = pos; + Cell_circulator ccir = _tds->incident_cells(edge), done(ccir); + + do { + Cell_handle ch = ccir; + i = ch->index(pos->vertex(edge.second)); + j = ch->index(pos->vertex(edge.third)); + int ei = Tds::edge_index(i,j); + ch->tds_data().set_edge(ei); + if(ch <= min){ + min = ch; + mini = i; + minj = j; + } + ++ccir; + }while(ccir != done); + report.first = min; + report.second = mini; + report.third = minj; + break; + + } else { + edge.second=0; edge.third=1; + break; + } + } + break; + } + default: + { + return *this; + } + } + return *this; + } + + Edge_iterator operator++(int) + { + Edge_iterator tmp(*this); + ++(*this); + return tmp; + } + + + bool operator==(const Edge_iterator& ei) const + { + return _tds == ei._tds && pos == ei.pos && + edge.second == ei.edge.second && edge.third == ei.edge.third; + } + + bool operator!=(const Edge_iterator& ei) const + { + return !(*this == ei); + } + + reference operator*() const + { + if(_tds->dimension() == 3){ + return report; + } + edge.first = pos; + return edge; + } + + pointer operator->() const + { + if(_tds->dimension() == 3){ + return &report; + } + edge.first = pos; + return &edge; + } + +private: + const Tds* _tds; + Cell_iterator pos; // current "cell". Even if the dimension is <3 when + // there is no true cell yet. + mutable Edge edge; // keeps the indices of the current edge. + mutable Edge report; + + void increment2() + { + if (edge.second == 2) { // edge.third == 0 + // all the edges of the current cell have been examined + edge.second = 0; edge.third = 1; + ++pos; + } + // be careful : index should always be 0 when pos = cells_end + else { + ++edge.second; + if ( edge.second == 2 ) + edge.third = 0; + else // edge.second==1 + edge.third = 2; + } + } + + void increment3() + { + if (edge.second == 2) { // then edge.third == 3 + // all the edges of the current cell have been examined + edge.second = 0; edge.third = 1; + ++pos; + } + else { + if (edge.third == 3) { + edge.second++; + edge.third = edge.second+1; + } + else + ++edge.third; + } + } +}; + + + + }} // namespace CGAL::internal #endif // CGAL_INTERNAL_TRIANGULATION_DS_ITERATORS_3_H diff --git a/Triangulation_3/include/CGAL/Regular_triangulation_3.h b/Triangulation_3/include/CGAL/Regular_triangulation_3.h index 5e39156dc524..a563ab9caca5 100644 --- a/Triangulation_3/include/CGAL/Regular_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Regular_triangulation_3.h @@ -116,6 +116,7 @@ class Regular_triangulation_3 typedef typename Tr_Base::Finite_cells_iterator Finite_cells_iterator; typedef typename Tr_Base::Finite_facets_iterator Finite_facets_iterator; typedef typename Tr_Base::Finite_edges_iterator Finite_edges_iterator; + typedef typename Tr_Base::Finite_marking_edges_iterator Finite_marking_edges_iterator; typedef typename Tr_Base::All_cells_iterator All_cells_iterator; // Traits are not supposed to define Bare_point, but leaving below diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 5341859314a3..65da34a66557 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -422,11 +422,13 @@ class Triangulation_3 typedef typename Tds::Cell_iterator Cell_iterator; typedef typename Tds::Facet_iterator Facet_iterator; typedef typename Tds::Edge_iterator Edge_iterator; + typedef typename Tds::Marking_edge_iterator Marking_edge_iterator; typedef typename Tds::Vertex_iterator Vertex_iterator; typedef Cell_iterator All_cells_iterator; typedef Facet_iterator All_facets_iterator; typedef Edge_iterator All_edges_iterator; + typedef Marking_edge_iterator All_marking_edges_iterator; typedef Vertex_iterator All_vertices_iterator; typedef typename Tds::Cell_handles All_cell_handles; @@ -470,6 +472,11 @@ class Triangulation_3 return t->is_infinite(*e); } + bool operator()(const Marking_edge_iterator& e) const + { + return t->is_infinite(*e); + } + bool operator()(const Facet_iterator& f) const { return t->is_infinite(*f); @@ -519,6 +526,7 @@ class Triangulation_3 typedef Iterator_range > Finite_vertex_handles; typedef Filter_iterator Finite_edges_iterator; + typedef Filter_iterator Finite_marking_edges_iterator; typedef Filter_iterator Finite_facets_iterator; typedef Iterator_range Finite_edges; @@ -1829,6 +1837,19 @@ class Triangulation_3 return CGAL::filter_iterator(edges_end(), Infinite_tester(this)); } + Finite_marking_edges_iterator finite_marking_edges_begin() const + { + if(dimension() < 1) + return finite_marking_edges_end(); + + return CGAL::filter_iterator(marking_edges_end(), Infinite_tester(this), marking_edges_begin()); + } + + Finite_marking_edges_iterator finite_marking_edges_end() const + { + return CGAL::filter_iterator(marking_edges_end(), Infinite_tester(this)); + } + Finite_edges finite_edges() const { return Finite_edges(finite_edges_begin(),finite_edges_end()); @@ -1837,6 +1858,13 @@ class Triangulation_3 Edge_iterator edges_begin() const { return _tds.edges_begin(); } Edge_iterator edges_end() const { return _tds.edges_end(); } + Marking_edge_iterator marking_edges_begin() const { return _tds.marking_edges_begin(); } + Marking_edge_iterator marking_edges_end() const { return _tds.marking_edges_end(); } + + void clear_marked_edges() + { + _tds.clear_marked_edges(); + } All_edges_iterator all_edges_begin() const { return _tds.edges_begin(); } All_edges_iterator all_edges_end() const { return _tds.edges_end(); }