diff --git a/Triangulation_on_sphere_2/include/CGAL/Regular_triangulation_on_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Regular_triangulation_on_sphere_2.h index c775ededa2f..c929e540981 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Regular_triangulation_on_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Regular_triangulation_on_sphere_2.h @@ -38,23 +38,29 @@ class Regular_triangulation_on_sphere_2 double _minDistSquared; public: - typedef Tds Triangulation_data_structure; - typedef Gt Geom_traits; - typedef typename Gt::Point_2 Point; - typedef typename Base::size_type size_type; - typedef typename Base::Face_handle Face_handle; - typedef typename Base::Vertex_handle Vertex_handle; - typedef typename Base::Vertex Vertex; - typedef typename Base::Edge Edge; - typedef typename Base::Locate_type Locate_type; - typedef typename Base::Face_circulator Face_circulator; - typedef typename Base::Edge_circulator Edge_circulator; - typedef typename Base::Vertex_circulator Vertex_circulator; - typedef typename Base::Vertices_iterator Vertices_iterator; - typedef typename Base::Edges_iterator Edges_iterator; - typedef typename Base::Faces_iterator Faces_iterator; - typedef typename Base::Face::Vertex_list Vertex_list; - typedef typename Vertex_list::iterator Vertex_list_iterator; + typedef Tds Triangulation_data_structure; + typedef Gt Geom_traits; + typedef typename Gt::Point_2 Point; + typedef typename Base::size_type size_type; + typedef typename Base::Face_handle Face_handle; + typedef typename Base::Vertex_handle Vertex_handle; + typedef typename Base::Vertex Vertex; + typedef typename Base::Edge Edge; + typedef typename Base::Locate_type Locate_type; + typedef typename Base::Face_circulator Face_circulator; + typedef typename Base::Edge_circulator Edge_circulator; + typedef typename Base::Vertex_circulator Vertex_circulator; + typedef typename Base::All_vertices_iterator All_vertices_iterator; + typedef typename Base::All_edges_iterator All_edges_iterator; + typedef typename Base::All_faces_iterator All_faces_iterator; + typedef typename Base::Solid_faces_iterator Solid_faces_iterator; + typedef typename Base::Solid_edges_iterator Solid_edges_iterator; + typedef typename Base::Contour_edges_iterator Contour_edges_iterator; + + + + typedef typename Base::Face::Vertex_list Vertex_list; + typedef typename Vertex_list::iterator Vertex_list_iterator; @@ -68,10 +74,18 @@ public: using Base::create_face; using Base::number_of_faces; using Base::number_of_vertices; - using Base::faces_begin; - using Base::faces_end; - using Base::edges_begin; - using Base::edges_end; + using Base::all_faces_begin; + using Base::all_faces_end; + using Base::all_edges_begin; + using Base::all_edges_end; + using Base::solid_faces_begin; + using Base::solid_faces_end; + using Base::solid_edges_begin; + using Base::solid_edges_end; + using Base::contour_edges_begin; + using Base::contour_edges_end; + + using Base::vertices_begin; using Base::vertices_end; using Base::OUTSIDE_AFFINE_HULL; @@ -134,9 +148,9 @@ void set_radius(double radius){ bool check_neighboring() { - Faces_iterator eit; + All_faces_iterator eit; if(dimension()==1){ - for(eit=faces_begin();eit!=faces_end();++eit) + for(eit=all_faces_begin();eit!=all_faces_end();++eit) { Face_handle f1 = eit->neighbor(0); Face_handle f2 = eit->neighbor(1); @@ -146,7 +160,7 @@ void set_radius(double radius){ } - for(eit=faces_begin();eit!=faces_end();++eit) + for(eit=all_faces_begin();eit!=all_faces_end();++eit) { Face_handle f1 = eit->neighbor(0); Face_handle f2 = eit->neighbor(1); @@ -216,7 +230,7 @@ template Stream &write_triangulation_to_off_2(Stream &out,Stream &out2){ // Points of triangulation - for (Faces_iterator it = this->_tds.face_iterator_base_begin(); it != faces_end(); it++) { + for (All_faces_iterator it = this->_tds.face_iterator_base_begin(); it !=all_faces_end(); it++) { if(!it->is_ghost() /*(t.orientation(it->vertex(0)->point(),it->vertex(1)->point(),it->vertex(2)->point())==1)*/ ){//assert(orientation(it)==POSITIVE); @@ -252,7 +266,7 @@ Stream &write_triangulation_to_off(Stream &out) { std::vector faces; // Points of triangulation - for (Faces_iterator it = faces_begin(); it != faces_end(); it++) { + for (All_faces_iterator it =all_faces_begin(); it !=all_faces_end(); it++) { for (int i=0 ; i<3 ; i++) { Point p = it->vertex(i)->point(); out << p.x() << " " @@ -494,7 +508,7 @@ is_plane()const{ return false; if(number_of_vertices() > 3){ - Vertices_iterator it1 = vertices_begin(), + All_vertices_iterator it1 = vertices_begin(), it2(it1), it3(it1), it4(it1); ++it2; ++it3; ++it3; @@ -538,10 +552,10 @@ is_valid(bool verbose, int level ) const //int level return false; } - for(Faces_iterator fit = faces_begin(); fit != faces_end(); ++fit) + for(All_faces_iterator fit =all_faces_begin(); fit !=all_faces_end(); ++fit) is_valid_face(fit, verbose, level); - for(Vertices_iterator vit = vertices_begin(); vit != vertices_end(); ++vit) + for(All_vertices_iterator vit = vertices_begin(); vit != vertices_end(); ++vit) is_valid_vertex(vit, verbose, level); @@ -552,7 +566,7 @@ is_valid(bool verbose, int level ) const //int level CGAL_triangulation_assertion(this->is_plane()); break; case 2 : - for(Faces_iterator it=faces_begin(); it!=faces_end(); it++) { + for(All_faces_iterator it=all_faces_begin(); it!=all_faces_end(); it++) { Orientation s = orientation(it->vertex(0)->point(), it->vertex(1)->point(), it->vertex(2)->point()); result = result && ( s == LEFT_TURN || it->is_ghost()); CGAL_triangulation_assertion(result); @@ -758,7 +772,7 @@ insert(const Point &p, Locate_type lt, Face_handle loc, int li) { case 1: if(test_dim_up(p)){ - Face_handle f=edges_begin()->first; + Face_handle f=all_edges_begin()->first; Vertex_handle v1=f->vertex(0); Vertex_handle v2=f->vertex(1); Vertex_handle v3=f->neighbor(0)->vertex(1); @@ -809,14 +823,14 @@ insert_outside_affine_hull_regular(const Point& p,bool plane) nv->set_point(p); - CGAL_triangulation_assertion( orientation(edges_begin()->first->vertex(0)->point(), - edges_begin()->first->vertex(1)->point(), - edges_begin()->first->neighbor(0)->vertex(1)->point()) + CGAL_triangulation_assertion( orientation(all_edges_begin()->first->vertex(0)->point(), + all_edges_begin()->first->vertex(1)->point(), + all_edges_begin()->first->neighbor(0)->vertex(1)->point()) != RIGHT_TURN ); //seting ghost edge if needed bool done=false; - Edges_iterator eit=edges_begin(); + All_edges_iterator eit=all_edges_begin(); do{ Face_handle f=eit->first; Face_handle fn=f->neighbor(0); @@ -828,14 +842,14 @@ insert_outside_affine_hull_regular(const Point& p,bool plane) f->ghost()=false; } ++eit; - }while( eit!=edges_end() && !done ); + }while( eit!=all_edges_end() && !done ); return nv; } else{ //dimension=1 bool conform = false; - Face_handle f = (edges_begin())->first; + Face_handle f = (all_edges_begin())->first; if(plane){//points coplanar with geom_traits->sphere Vertex_handle v1 = f->vertex(0); @@ -862,7 +876,7 @@ insert_outside_affine_hull_regular(const Point& p,bool plane) //find smalest vertex Vertex_handle w=vertices_begin(); - Vertices_iterator vi; + All_vertices_iterator vi; for( vi = vertices_begin(); vi != vertices_end(); vi++){ if(compare_xyz(w->point(), vi->point())<0) w=vi; @@ -874,12 +888,12 @@ insert_outside_affine_hull_regular(const Point& p,bool plane) Vertex_handle v = this->_tds.insert_dim_up( w, conform); v->set_point(p); - this->_ghost=faces_begin(); + this->_ghost=all_faces_begin(); //seting ghost faces if needed - Faces_iterator fit; - for(fit = faces_begin(); fit != faces_end(); fit++) { + All_faces_iterator fit; + for(fit =all_faces_begin(); fit !=all_faces_end(); fit++) { //if(orientation(fit)==NEGATIVE){ if(orientation(fit)!=POSITIVE){ fit->ghost()=true; @@ -900,7 +914,7 @@ update_ghost_faces(Vertex_handle v) { bool neg_found=false; if(dimension()==1){ - Edges_iterator eit=edges_begin(); + All_edges_iterator eit=all_edges_begin(); do{ Face_handle f=eit->first; Face_handle fn=f->neighbor(0); @@ -912,7 +926,7 @@ update_ghost_faces(Vertex_handle v) else f->ghost()=false; ++eit; - }while( eit!=edges_end()); + }while( eit!=all_edges_end()); } else{//dimension==2 @@ -1037,7 +1051,7 @@ test_dim_up(const Point &p) const{ // dimension of triangulation increase from 1 to 2 iff the new vertex in not coplanar with the old vertices std::cout<first; + Face_handle f=all_edges_begin()->first; Vertex_handle v1=f->vertex(0); Vertex_handle v2=f->vertex(1); Vertex_handle v3=f->neighbor(0)->vertex(1); diff --git a/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2.h index 02f23d103f0..67a607ffac5 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Triangulation_on_sphere_2.h @@ -55,7 +55,7 @@ class Triangulation_on_sphere_2 public: typedef Tds Triangulation_data_structure; typedef Gt Geom_traits; -//typedef Triangulation_2 Triangulation_2; +//typedef TriangAll_vertices_iteratorulation_2 Triangulation_2; typedef typename Geom_traits::Point_2 Point; @@ -77,10 +77,68 @@ public: typedef typename Tds::Vertex_circulator Vertex_circulator; typedef typename Tds::Edge_circulator Edge_circulator; - typedef typename Tds::Face_iterator Faces_iterator; - typedef typename Tds::Edge_iterator Edges_iterator; - typedef typename Tds::Vertex_iterator Vertices_iterator; + typedef typename Tds::Face_iterator All_faces_iterator; + typedef typename Tds::Edge_iterator All_edges_iterator; + typedef typename Tds::Vertex_iterator All_vertices_iterator; + + // This class is used to generate the Finite_*_iterators. + class Ghost_tester + { + const Triangulation_on_sphere_2 *t; + public: + Ghost_tester() {} + Ghost_tester(const Triangulation_on_sphere_2 *tr) : t(tr) {} + + bool operator()(const All_faces_iterator & fit ) const { + return fit->is_ghost(); + } + bool operator()(const All_edges_iterator & eit) const { + Face_handle f = eit->first(); + bool edge1 = f->is_ghost(); + bool edge2 = f->neighbor(eit->second)->is_ghost(); + bool result = edge1&&edge2; + return !result; + } + }; + + class Contour_tester + { + const Triangulation_on_sphere_2 *t; + public: + Contour_tester() {} + Contour_tester(const Triangulation_on_sphere_2 *tr) : t(tr) {} + + bool operator() (const All_edges_iterator & eit) const { + Face_handle f = eit->first(); + bool edge1 = f->is_ghost(); + bool edge2 = f->neighbor(eit->second)->is_ghost(); + return edge1 !=edge2; + } + }; + + + + + //We derive in order to add a conversion to handle. + class Solid_faces_iterator + : public Filter_iterator + { + typedef Filter_iterator Base; + typedef Solid_faces_iterator Self; + public: + Solid_faces_iterator() : Base() {} + Solid_faces_iterator(const Base &b) : Base(b) {} + Self & operator++() { Base::operator++(); return *this; } + Self & operator--() { Base::operator--(); return *this; } + Self operator++(int) { Self tmp(*this); ++(*this); return tmp; } + Self operator--(int) { Self tmp(*this); --(*this); return tmp; } + operator const Face_handle() const { return Base::base(); } + }; + + typedef Filter_iterator Solid_edges_iterator; + typedef Filter_iterator Contour_edges_iterator; + enum Locate_type {VERTEX=0, EDGE, //1 FACE, //2 @@ -205,27 +263,69 @@ Orientation coplanar_orientation(const Point& p, const Point& q,const Point& r, //--------------------------------------------------------------TRAVERSING : ITERATORS AND CIRCULATORS------------------------------------------- - Faces_iterator faces_begin() const { + All_faces_iterator all_faces_begin() const { return _tds.faces_begin(); } - Faces_iterator faces_end() const { + All_faces_iterator all_faces_end() const { return _tds.faces_end(); } - Vertices_iterator vertices_begin() const{ + Solid_faces_iterator solid_faces_begin() const { + if (dimension() < 2) + return solid_faces_end(); + return CGAL::filter_iterator( all_faces_end(), + Ghost_tester(this), + all_faces_begin() ); + } + + + + Solid_faces_iterator solid_faces_end() const { + return CGAL::filter_iterator( all_faces_end(), + Ghost_tester(this) );; + + + } + + Solid_edges_iterator solid_edges_begin() const { + if ( dimension() < 1 ) + return solid_edges_end(); + return CGAL::filter_iterator (all_edges_begin(), Ghost_tester(this), + all_edges_end()); + } + + Solid_edges_iterator solid_edges_end() const { + return CGAL::filter_iterator (all_edges_end(), Ghost_tester(this)); + } + + Contour_edges_iterator contour_edges_begin() const{ + if(dimension()<1) + return contour_edges_begin(); + return CGAL::filter_iterator (all_edges_begin(), Ghost_tester(this), + all_edges_end()); + } + + Contour_edges_iterator contour_edges_end() const{ + return CGAL::filter_iterator (all_edges_end(), Contour_tester(this)); + } + + + + + All_vertices_iterator vertices_begin() const{ return _tds.vertices_begin(); } - Vertices_iterator vertices_end() const { + All_vertices_iterator vertices_end() const { return _tds.vertices_end(); } - Edges_iterator edges_begin() const{ + All_edges_iterator all_edges_begin() const{ return _tds.edges_begin(); } - Edges_iterator edges_end() const{ + All_edges_iterator all_edges_end() const{ return _tds.edges_end(); } @@ -346,13 +446,13 @@ is_valid(bool verbose, int level) const (dimension()==1 && number_of_vertices() == 3 ) ) return result; if (dimension() == 1) { - Vertices_iterator vit=vertices_begin(); + All_vertices_iterator vit=vertices_begin(); } else { //dimension() == 2 - for(Faces_iterator it=faces_begin(); - it!=faces_end(); it++) { + for(All_faces_iterator it=all_faces_begin(); + it!=all_faces_end(); it++) { Orientation s = orientation(it->vertex(0)->point(), it->vertex(1)->point(), it->vertex(2)->point()); @@ -438,8 +538,8 @@ locate_edge(const Point& p, Locate_type& lt, int& li, bool plane)const { Face_handle loc; if(plane){ - Edges_iterator eit; - for(eit = edges_begin(); eit != edges_end(); eit ++){ + All_edges_iterator eit; + for(eit = all_edges_begin(); eit !=all_edges_end(); eit ++){ if(!eit->first->is_ghost()) if(collinear_between(eit->first->vertex(0)->point(), eit->first->vertex(1)->point(),p)){ test_distance( p, (*eit).first, lt, li); @@ -455,9 +555,9 @@ locate_edge(const Point& p, Locate_type& lt, int& li, bool plane)const } else {//not plane - Edges_iterator eit; + All_edges_iterator eit; Face_handle f; - for(eit = edges_begin(); eit!= edges_end(); eit ++){ + for(eit = all_edges_begin(); eit!=all_edges_end(); eit ++){ f=eit->first; Vertex_handle v1 = f->vertex(0); Vertex_handle v2 = f -> vertex(1); @@ -518,7 +618,7 @@ typename Triangulation_on_sphere_2::Face_handle Triangulation_on_sphere_2:: march_locate_1D(const Point& p, Locate_type& lt, int& li) const { - Face_handle f = edges_begin()->first; + Face_handle f =all_edges_begin()->first; //check if p is coplanar with existing points //first three points of triangulation @@ -535,7 +635,7 @@ march_locate_1D(const Point& p, Locate_type& lt, int& li) const } //check if p is coradial with one existing point - Vertices_iterator vi; + All_vertices_iterator vi; for( vi = vertices_begin(); vi != vertices_end(); vi++){ if (xy_equal(vi->point(), p)){ lt = VERTEX; @@ -783,7 +883,7 @@ locate(const Point& p,Locate_type& lt,int& li, Face_handle start) const lt=OUTSIDE_AFFINE_HULL; } li=4; - test_distance(p, faces_begin(), lt, li); + test_distance(p, all_faces_begin(), lt, li); return Face_handle(); } @@ -812,11 +912,11 @@ locate(const Point& p,Locate_type& lt,int& li, Face_handle start) const } if(start==Face_handle()){ - start=faces_begin(); + start=all_faces_begin(); } if(start->is_ghost()){ - for (Faces_iterator it = this->_tds.face_iterator_base_begin(); it != faces_end(); it++) { + for (All_faces_iterator it = this->_tds.face_iterator_base_begin(); it !=all_faces_end(); it++) { if(!it->is_ghost()){ start = it; break; @@ -992,8 +1092,8 @@ show_all() const if (dimension() < 1) return; if(dimension() == 1) { std::cerr<<" all edges dim 1 "<first); std::cerr<<" ------------ " <1) { std::cerr << "affichage des sommets de la triangulation" <:: number_of_ghost_faces() { int nb=0; - for(Faces_iterator it=faces_begin();it!=faces_end();++it) + for(All_faces_iterator it=all_faces_begin();it!=all_faces_end();++it) if(it->is_ghost()) nb++; return nb; diff --git a/Triangulation_on_sphere_2/test/bugs_minimal_examples.cpp b/Triangulation_on_sphere_2/test/bugs_minimal_examples.cpp index 17af7d82b93..16b0fd77c32 100644 --- a/Triangulation_on_sphere_2/test/bugs_minimal_examples.cpp +++ b/Triangulation_on_sphere_2/test/bugs_minimal_examples.cpp @@ -31,8 +31,8 @@ typedef CGAL::Regular_triangulation_on_sphere_2 RTOS; typedef RTOS::Vertex_handle Vertex_handle; typedef RTOS::Face_handle Face_handle; typedef RTOS::Point Point; -typedef RTOS::Faces_iterator Face_iterator; -typedef RTOS::Vertices_iterator Vertex_iterator; +typedef RTOS::All_faces_iterator Face_iterator; +typedef RTOS::All_vertices_iterator Vertex_iterator; typedef RTOS::Locate_type Locate_type; typedef RTOS::Edge Edge; @@ -72,11 +72,11 @@ bool are_equal(RTOS triA, RTOS triB){ bool test = false; Face_iterator fiA; Face_iterator fiB; - fiA = triA.faces_begin(); - fiB = triB.faces_begin(); - for( ; fiA != triA.faces_end(); ++fiA ){ + fiA = triA.all_faces_begin(); + fiB = triB.all_faces_begin(); + for( ; fiA != triA.all_faces_end(); ++fiA ){ //**face of fiA in fiB? - for( ; fiB != triB.faces_end(); ++fiB ){ + for( ; fiB != triB.all_faces_end(); ++fiB ){ test = has_face(fiB, fiA->vertex(0), fiA->vertex(1), fiA->vertex(2)); if(has_face) break; } diff --git a/Triangulation_on_sphere_2/test/test_random.cpp b/Triangulation_on_sphere_2/test/test_random.cpp index ac0cfb4fa50..84458d17c42 100644 --- a/Triangulation_on_sphere_2/test/test_random.cpp +++ b/Triangulation_on_sphere_2/test/test_random.cpp @@ -23,8 +23,9 @@ typedef CGAL::Regular_triangulation_on_sphere_2 RTOS; typedef RTOS::Vertex_handle Vertex_handle; typedef RTOS::Face_handle Face_handle; typedef RTOS::Point Point; -typedef RTOS::Faces_iterator Face_iterator; -typedef RTOS::Vertices_iterator Vertex_iterator; +typedef RTOS::All_faces_iterator Face_iterator; +typedef RTOS::All_vertices_iterator Vertex_iterator; +typedef RTOS::Solid_faces_iterator Solid_faces_iterator; typedef RTOS::Locate_type Locate_type; typedef RTOS::Edge Edge; @@ -81,11 +82,11 @@ bool are_equal(RTOS triA, RTOS triB){ bool test = false; Face_iterator fiA; Face_iterator fiB; - fiA = triA.faces_begin(); - fiB = triB.faces_begin(); - for( ; fiA != triA.faces_end(); ++fiA ){ + fiA = triA.all_faces_begin(); + fiB = triB.all_faces_begin(); + for( ; fiA != triA.all_faces_end(); ++fiA ){ //**face of fiA in fiB? - for( ; fiB != triB.faces_end(); ++fiB ){ + for( ; fiB != triB.all_faces_end(); ++fiB ){ test = has_face(fiB, fiA->vertex(0), fiA->vertex(1), fiA->vertex(2)); if(has_face) break; } @@ -166,7 +167,7 @@ int main(){ //====insert new points============ - for (int count=0; countis_ghost()); + count ++; + } + std::cout<<"number of solid faces "<