diff --git a/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex.cpp b/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex.cpp index b24b462b147..a3054764d4d 100644 --- a/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex.cpp +++ b/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex.cpp @@ -1,24 +1,22 @@ #include + #include #include - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef CGAL::Delaunay_triangulation_sphere_traits_2 Traits; -typedef CGAL::Delaunay_triangulation_sphere_2 DToS2; + +typedef CGAL::Delaunay_triangulation_sphere_traits_2 Traits; +typedef CGAL::Delaunay_triangulation_sphere_2 DToS2; int main() { std::vector points; - points.push_back( K::Point_3(2,1,1) ); - points.push_back( K::Point_3(-2,1,1) ); - points.push_back( K::Point_3(1,2,1) ); - points.push_back( K::Point_3(1,-2,1) ); - + points.push_back(K::Point_3(2,1,1)); + points.push_back(K::Point_3(-2,1,1)); + points.push_back(K::Point_3(1,2,1)); + points.push_back(K::Point_3(1,-2,1)); Traits traits(K::Point_3(1,1,1)); DToS2 dtos(traits); - dtos.insert(points.begin(),points.end()); + dtos.insert(points.begin(), points.end()); } - - diff --git a/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex_proj.cpp b/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex_proj.cpp index f9fded0292e..528cff682b9 100644 --- a/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex_proj.cpp +++ b/Triangulation_on_sphere_2/examples/Triangulation_on_sphere_2/triang_on_sphere_ex_proj.cpp @@ -1,20 +1,22 @@ #include + #include #include + #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; + typedef CGAL::Projection_sphere_traits_3 Projection_traits; typedef CGAL::Delaunay_triangulation_sphere_2 Projected_DToS2; int main() { std::vector points; - points.push_back( K::Point_3(3,1,1) ); - points.push_back( K::Point_3(-8,1,1) ); - points.push_back( K::Point_3(1,2,1) ); - points.push_back( K::Point_3(1,-2,1) ); - + points.push_back(K::Point_3(3,1,1)); + points.push_back(K::Point_3(-8,1,1)); + points.push_back(K::Point_3(1,2,1)); + points.push_back(K::Point_3(1,-2,1)); Projection_traits traits(K::Point_3(1,1,1)); Projected_DToS2 dtos(traits); @@ -22,11 +24,7 @@ int main() Projection_traits::Construct_projected_point_3 cst = traits.construct_projected_point_3_object(); - - dtos.insert( - boost::make_transform_iterator(points.begin(), cst), - boost::make_transform_iterator(points.end(), cst) - ); + dtos.insert(boost::make_transform_iterator(points.begin(), cst), + boost::make_transform_iterator(points.end(), cst) + ); } - - diff --git a/Triangulation_on_sphere_2/include/CGAL/Constrained_triangulation_face_base_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Constrained_triangulation_face_base_sphere_2.h index 1a5e82f1696..0eb689b915d 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Constrained_triangulation_face_base_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Constrained_triangulation_face_base_sphere_2.h @@ -14,7 +14,7 @@ // // $URL$ // $Id$ -// +// SPDX-License-Identifier: GPL-3.0+ // // Author(s) : Claudia Werner, Mariette Yvinec @@ -24,104 +24,103 @@ #include #include -namespace CGAL { +namespace CGAL { -template > +template < class Gt, + class Fb = Triangulation_face_base_sphere_2 > class Constrained_triangulation_face_base_sphere_2 - : public Fb + : public Fb { - typedef Fb Base; typedef typename Fb::Triangulation_data_structure TDS; + public: - typedef Gt Geom_traits; - typedef TDS Triangulation_data_structure; - typedef typename TDS::Vertex_handle Vertex_handle; - typedef typename TDS::Face_handle Face_handle; + typedef Gt Geom_traits; + typedef TDS Triangulation_data_structure; + + typedef typename TDS::Vertex_handle Vertex_handle; + typedef typename TDS::Face_handle Face_handle; template < typename TDS2 > - struct Rebind_TDS { - typedef typename Fb::template Rebind_TDS::Other Fb2; - typedef Constrained_triangulation_face_base_sphere_2 Other; + struct Rebind_TDS + { + typedef typename Fb::template Rebind_TDS::Other Fb2; + typedef Constrained_triangulation_face_base_sphere_2 Other; }; - protected: bool C[3]; - + public: Constrained_triangulation_face_base_sphere_2() : Base() { - set_constraints(false,false,false); + set_constraints(false, false, false); } - Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2) - : Base(v0,v1,v2) + Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2) + : Base(v0, v1, v2) { - set_constraints(false,false,false); + set_constraints(false, false, false); } - Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2, - Face_handle n0, - Face_handle n1, - Face_handle n2) - : Base(v0,v1,v2,n0,n1,n2) + Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2, + Face_handle n0, + Face_handle n1, + Face_handle n2) + : Base(v0, v1, v2, n0, n1, n2) { - set_constraints(false,false,false); + set_constraints(false, false, false); } - - Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2, - Face_handle n0, - Face_handle n1, - Face_handle n2, - bool c0, - bool c1, - bool c2 ) - : Base(v0,v1,v2,n0,n1,n2) + Constrained_triangulation_face_base_sphere_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2, + Face_handle n0, + Face_handle n1, + Face_handle n2, + bool c0, + bool c1, + bool c2) + : Base(v0, v1, v2, n0, n1, n2) { - set_constraints(c0,c1,c2); + set_constraints(c0, c1, c2); } - bool is_constrained(int i) const ; void set_constraints(bool c0, bool c1, bool c2) ; void set_constraint(int i, bool b); void reorient(); void ccw_permute(); void cw_permute(); - }; template inline void -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: set_constraints(bool c0, bool c1, bool c2) { - C[0]=c0; - C[1]=c1; - C[2]=c2; + C[0] = c0; + C[1] = c1; + C[2] = c2; } template inline void -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: set_constraint(int i, bool b) { - CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2); + CGAL_triangulation_precondition(i == 0 || i == 1 || i == 2); C[i] = b; } - + template inline bool -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: is_constrained(int i) const { return(C[i]); @@ -129,31 +128,31 @@ is_constrained(int i) const template inline void -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: reorient() { Base::reorient(); - set_constraints(C[1],C[0],C[2]); + set_constraints(C[1], c[0], c[2]); } template inline void -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: ccw_permute() { Base::ccw_permute(); - set_constraints(C[2],C[0],C[1]); + set_constraints(C[2], c[0], c[1]); } template inline void -Constrained_triangulation_face_base_sphere_2:: +Constrained_triangulation_face_base_sphere_2:: cw_permute() { Base::cw_permute(); - set_constraints(C[1],C[2],C[0]); + set_constraints(C[1], c[2], c[0]); } - -} //namespace CGAL - + +} // namespace CGAL + #endif //CGAL_CONSTRAINED_TRIANGULATION_FACE_BASE_SPHERE_2_H diff --git a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_2.h index 516ab9688ff..4eb89e7549c 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_2.h @@ -1,3 +1,23 @@ +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Mariette Yvinec, Claudia Werner + #ifndef CGAL_Delaunay_triangulation_sphere_2_H #define CGAL_Delaunay_triangulation_sphere_2_H @@ -6,47 +26,52 @@ #include #include #include + +#include #include -#include +#include +#include +#include +#include - -namespace CGAL { - +namespace CGAL { template < class Gt, - class Tds = Triangulation_data_structure_2 < - Triangulation_vertex_base_2, - Triangulation_face_base_sphere_2 > > + class Tds = Triangulation_data_structure_2 < + Triangulation_vertex_base_2, + Triangulation_face_base_sphere_2 > > class Delaunay_triangulation_sphere_2 - : public Triangulation_sphere_2 + : public Triangulation_sphere_2 { + typedef Delaunay_triangulation_sphere_2 Self; + typedef Triangulation_sphere_2 Base; - typedef Delaunay_triangulation_sphere_2 Self; - typedef Triangulation_sphere_2 Base; - - public: - typedef Tds Triangulation_data_structure; + typedef Tds Triangulation_data_structure; typedef Gt Geom_traits; + typedef typename Gt::Point_2 Point; - typedef typename Gt::Segment_3 Segment; + typedef typename Gt::Segment_3 Segment; + 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::Vertex_handle Vertex_handle; typedef typename Base::Edge Edge; + typedef typename Base::Face_handle Face_handle; + 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::Edge_circulator Edge_circulator; + typedef typename Base::Face_circulator Face_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::Contour_edges_iterator Contour_edges_iterator; #ifndef CGAL_CFG_USING_BASE_MEMBER_BUG_2 using Base::cw; @@ -65,1087 +90,1112 @@ public: 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::contour_edges_end; + using Base::vertices_begin; + using Base::vertices_end; using Base::OUTSIDE_AFFINE_HULL; using Base::FACE; using Base::OUTSIDE_CONVEX_HULL; - using Base ::NOT_ON_SPHERE; - using Base :: VERTEX; - using Base :: TOO_CLOSE; + using Base::NOT_ON_SPHERE; + using Base::VERTEX; + using Base::TOO_CLOSE; using Base::orientation; - using Base ::show_all; - using Base ::show_face; - using Base ::show_vertex; + using Base::show_all; + using Base::show_face; + using Base::show_vertex; using Base::clear; using Base::delete_faces; using Base::compare_xyz; using Base::coplanar_orientation; using Base::set_radius; using Base::circumcenter; - - #endif - -//class for sorting points lexicographically. -//This sorting is used for the perturbation in power_test -class Perturbation_order { - const Self *t; +#endif + + // class to sort points lexicographically. + // This sorting is used for the symbolic perturbation in power_test + class Perturbation_order + { + const Self *t; public: - Perturbation_order(const Self *tr) - : t(tr) {} - - bool operator()(const Point *p, const Point *q) const { - return t->compare_xyz(*p, *q) == SMALLER; - } -}; + Perturbation_order(const Self *tr) : t(tr) { } -public: - //CONSTRUCTORS - Delaunay_triangulation_sphere_2(const Gt& gt=Gt()) - :Base(Gt(gt)) - {} + bool operator()(const Point *p, const Point *q) const + { + return t->compare_xyz(*p, *q) == SMALLER; + } + }; +public: + // CONSTRUCTORS + Delaunay_triangulation_sphere_2(const Gt& gt=Gt()) + : Base(Gt(gt)) + { } -//CHECK + // CHECK bool is_valid(bool verbose = false, int level = 0) const; - bool is_valid_face(Face_handle fh,bool verbose = false, int level = 0 ) const; + bool is_valid_face(Face_handle fh, bool verbose = false, int level = 0) const; bool is_valid_vertex(Vertex_handle fh, bool verbose = false, int level = 0) const; bool is_plane() const; -//checks whether neighboring faces are linked correctly to each other. + + // checks whether neighboring faces are linked correctly to each other. void check_neighboring() { All_faces_iterator eit; - if(dimension()==1){ - for(eit=all_faces_begin();eit!=all_faces_end();++eit) + if(dimension() == 1) + { + for(eit=all_faces_begin(); eit!=all_faces_end(); ++eit) { - Face_handle f1 = eit->neighbor(0); - Face_handle f2 = eit->neighbor(1); - CGAL_triangulation_assertion(f1->has_neighbor(eit)); - CGAL_triangulation_assertion(f2->has_neighbor(eit)); + Face_handle f1 = eit->neighbor(0); + Face_handle f2 = eit->neighbor(1); + CGAL_triangulation_assertion(f1->has_neighbor(eit)); + CGAL_triangulation_assertion(f2->has_neighbor(eit)); } - } for(eit=all_faces_begin();eit!=all_faces_end();++eit) - { - Face_handle f1 = eit->neighbor(0); - Face_handle f2 = eit->neighbor(1); - Face_handle f3 = eit->neighbor(2); - CGAL_triangulation_assertion(f1->has_neighbor(eit)); - CGAL_triangulation_assertion(f2->has_neighbor(eit)); - CGAL_triangulation_assertion(f3->has_neighbor(eit)); - } - + { + Face_handle f1 = eit->neighbor(0); + Face_handle f2 = eit->neighbor(1); + Face_handle f3 = eit->neighbor(2); + CGAL_triangulation_assertion(f1->has_neighbor(eit)); + CGAL_triangulation_assertion(f2->has_neighbor(eit)); + CGAL_triangulation_assertion(f3->has_neighbor(eit)); + } } - //INSERTION - Vertex_handle insert(const Point &p, Locate_type lt, Face_handle loc, int li ); - Vertex_handle insert(const Point &p, Face_handle f = Face_handle() ); - Vertex_handle insert_first(const Point &p); - Vertex_handle insert_second(const Point &p); + Vertex_handle insert(const Point& p, Locate_type lt, Face_handle loc, int li); + Vertex_handle insert(const Point& p, Face_handle f = Face_handle()); + Vertex_handle insert_first(const Point& p); + Vertex_handle insert_second(const Point& p); Vertex_handle insert_outside_affine_hull_regular(const Point& p); - Vertex_handle insert_cocircular(const Point &p, Locate_type lt, Face_handle loc); - - bool test_conflict(const Point &p, Face_handle fh) const; - bool update_ghost_faces(Vertex_handle v=Vertex_handle(), bool first = false); - + Vertex_handle insert_cocircular(const Point& p, Locate_type lt, Face_handle loc); + + bool test_conflict(const Point& p, Face_handle fh) const; + bool update_ghost_faces(Vertex_handle v = Vertex_handle(), bool first = false); + //REMOVAL void remove_degree_3(Vertex_handle v, Face_handle f = Face_handle()); void remove(Vertex_handle v); void remove_1D(Vertex_handle v); void remove_2D(Vertex_handle v); bool test_dim_down(Vertex_handle v); - bool test_dim_up(const Point &p)const; + bool test_dim_up(const Point& p) const; void fill_hole_regular(std::list & hole); - - Oriented_side power_test(const Point &p,const Point &q, const Point &r, const Point &s, bool perturb = false) const; - Oriented_side power_test(const Point &p,const Point &q, const Point &r) const; - Oriented_side power_test(const Point &p, const Point &r) const; - Oriented_side power_test(const Face_handle &f,const Point &p, bool perturb = false) const; - Oriented_side power_test(const Face_handle& f, int i, const Point &p) const; - - //dual - Point dual (Face_handle f) const; - Object dual(const Edge &e) const ; - Object dual(const Edge_circulator& ec) const; - Object dual(const All_edges_iterator& ei) const; + Oriented_side power_test(const Point& p, const Point& q, const Point& r, const Point& s, bool perturb = false) const; + Oriented_side power_test(const Point& p, const Point& q, const Point& r) const; + Oriented_side power_test(const Point& p, const Point& r) const; + Oriented_side power_test(const Face_handle &f, const Point& p, bool perturb = false) const; + Oriented_side power_test(const Face_handle& f, int i, const Point& p) const; - - //TEMPLATE MEMBERS - //----------------------------------------------------------------------HOLE APPROACH - -template -Stream &write_vertices(Stream &out,std::vector &t) + //dual + Point dual(Face_handle f) const; + Object dual(const Edge &e) const ; + Object dual(const Edge_circulator& ec) const; + Object dual(const All_edges_iterator& ei) const; + + // TEMPLATE MEMBERS + //------------------------ HOLE APPROACH + + template + Stream& write_vertices(Stream& out, std::vector &t) { - for(typename std::vector::iterator it= t.begin(); it!= t.end(); ++it) - {if((*it)->face()==Face_handle()){ - Point p=(*it)->point(); - out << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - } + for(typename std::vector::iterator it=t.begin(); it!=t.end(); ++it) + { + if((*it)->face() == Face_handle()) + { + Point p=(*it)->point(); + out << p.x() << " " << p.y() << " " << p.z() << std::endl; } + } + return out; } - -template - Stream &write_triangulation_to_off_2(Stream &out,Stream &out2) -{ + + template + Stream& write_triangulation_to_off_2(Stream& out, Stream& out2) + { + // Points of triangulation + for(All_faces_iterator it=this->_tds.face_iterator_base_begin(); it!=all_faces_end(); ++it) + { + if(!it->is_ghost()) + { + // assert(orientation(it) == POSITIVE); + for(int i=0; i<3; ++i) + { + if(it->vertex(i)!=Vertex_handle()) + { + Point p = it->vertex(i)->point(); + out << p.x() << " " << p.y() << " " << p.z() << std::endl; + } + } + } + else + { + for(int i=0; i<3; ++i) + { + if(it->vertex(i)!=Vertex_handle()) + { + Point p = it->vertex(i)->point(); + out2 << p.x() << " " << p.y() << " " << p.z() << std::endl; + } + } + } + } + + return out; + } + + template + Stream& write_triangulation_to_off(Stream& out) + { + std::vector faces; // Points of triangulation - for (All_faces_iterator it = this->_tds.face_iterator_base_begin(); it !=all_faces_end(); it++) { - if(!it->is_ghost()){//assert(orientation(it)==POSITIVE); - for (int i=0 ; i<3 ; i++) { - if(it->vertex(i)!=Vertex_handle()) - { - Point p = it->vertex(i)->point(); - out << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - } - } - } - else{ - for (int i=0 ; i<3 ; i++){ - if(it->vertex(i)!=Vertex_handle()) - { - Point p = it->vertex(i)->point(); - out2 << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - } - } + 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() << " " << p.y() << " " << p.z() << std::endl; } } - - return out; -} - -template -Stream &write_triangulation_to_off(Stream &out) -{ - std::vector faces; - - // Points of triangulation - 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() << " " - << p.y() << " " - << p.z() << std::endl; - } + return out; } - return out; -} - -template -Stream &write_face_to_off(Stream &out,Face_handle f) -{ - - for (int i=0 ; i<3 ; i++) { - Point p = f->vertex(i)->point(); - out << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - } - - - return out; -} - - -template -Stream &write_faces_to_off(Stream &out,FaceIt face_begin, FaceIt face_end) -{ - - FaceIt fit=face_begin; - for(;fit!=face_end;++fit) + template + Stream& write_face_to_off(Stream& out, Face_handle f) + { + for(int i=0; i<3; ++i) { - for (int i=0 ; i<3 ; i++) { - Point p = (*fit)->vertex(i)->point(); - out << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - } - } - - return out; -} - -template -Stream &write_edges_to_off(Stream &out,FaceIt face_begin, FaceIt face_end) -{ - - FaceIt fit=face_begin; - for(;fit!=face_end;++fit) - { - Face_handle f=(*fit).first; - int i=(*fit).second; - - Point p=f->vertex(cw(i))->point(); - Point q=f->vertex(ccw(i))->point(); - - out << p.x() << " " - << p.y() << " " - << p.z() << std::endl; - - out << q.x() << " " - << q.y() << " " - << q.z() << std::endl; + Point p = f->vertex(i)->point(); + out << p.x() << " " << p.y() << " " << p.z() << std::endl; } - return out; -} -//insert points in a given range using spacial sorting -template < class InputIterator > -int insert(InputIterator first, InputIterator last) -{ - int n = number_of_vertices(); - - std::vector points (first, last); - std::random_shuffle (points.begin(), points.end()); - spatial_sort (points.begin(), points.end()); - - Face_handle hint; - Vertex_handle v; - for (typename std::vector::const_iterator p = points.begin(),end = points.end(); p != end; ++p){ - v = insert (*p, hint); - if( v != Vertex_handle())//could happen if the point is not on the sphere - hint = v->face(); - } - - return number_of_vertices() - n; -} + return out; + } -template -std::pair -get_conflicts_and_boundary(const Point &p, OutputItFaces fit, OutputItBoundaryEdges eit, - Face_handle fh ) const -{ - CGAL_triangulation_precondition( dimension() == 2); - CGAL_triangulation_precondition(test_conflict(p,fh)); - - *fit++ = fh; //put fh in OutputItFaces - fh->set_in_conflict_flag(1); - std::pair - pit = std::make_pair(fit,eit); - pit = propagate_conflicts(p,fh,0,pit); - pit = propagate_conflicts(p,fh,1,pit); - pit = propagate_conflicts(p,fh,2,pit); - - return std::make_pair(fit,eit); -} + template + Stream& write_faces_to_off(Stream& out, FaceIt face_begin, FaceIt face_end) + { + FaceIt fit = face_begin; + for(; fit!=face_end; ++fit) + { + for(int i=0; i<3; ++i) + { + Point p = (*fit)->vertex(i)->point(); + out << p.x() << " " << p.y() << " " << p.z() << std::endl; + } + } + + return out; + } + + template + Stream& write_edges_to_off(Stream& out, FaceIt face_begin, FaceIt face_end) + { + FaceIt fit=face_begin; + for(; fit!=face_end; ++fit) + { + Face_handle f = (*fit).first; + int i = (*fit).second; + + Point p = f->vertex(cw(i))->point(); + Point q = f->vertex(ccw(i))->point(); + + out << p.x() << " " << p.y() << " " << p.z() << std::endl; + out << q.x() << " " << q.y() << " " << q.z() << std::endl; + } + + return out; + } + + //insert points in a given range using spacial sorting + template < class InputIterator > + int insert(InputIterator first, InputIterator last) + { + int n = number_of_vertices(); + + std::vector points(first, last); + std::random_shuffle(points.begin(), points.end()); + spatial_sort(points.begin(), points.end()); + + Face_handle hint; + Vertex_handle v; + for(typename std::vector::const_iterator p=points.begin(), end=points.end(); p != end; ++p) + { + v = insert(*p, hint); + if(v != Vertex_handle())//could happen if the point is not on the sphere + hint = v->face(); + } + + return number_of_vertices() - n; + } + + template + std::pair + get_conflicts_and_boundary(const Point& p, + OutputItFaces fit, + OutputItBoundaryEdges eit, + Face_handle fh) const + { + CGAL_triangulation_precondition(dimension() == 2); + CGAL_triangulation_precondition(test_conflict(p, fh)); + + *fit++ = fh; //put fh in OutputItFaces + fh->set_in_conflict_flag(1); + + std::pair pit = std::make_pair(fit, eit); + pit = propagate_conflicts(p, fh,0, pit); + pit = propagate_conflicts(p, fh,1, pit); + pit = propagate_conflicts(p, fh,2, pit); + + return std::make_pair(fit, eit); + } - private: -template -std::pair -propagate_conflicts (const Point &p, Face_handle fh, int i, - std::pair pit) const -{ - Face_handle fn = fh->neighbor(i); - if (fn->get_in_conflict_flag() ==1) - return pit; - if (! test_conflict(p,fn)) - *(pit.second)++ = Edge(fn, fn->index(fh)); - else { - *(pit.first)++ = fn; - fn->set_in_conflict_flag(1); - int j = fn->index(fh); - pit = propagate_conflicts(p,fn,ccw(j),pit); - pit = propagate_conflicts(p,fn,cw(j), pit); - } - return pit; - } + template + std::pair + propagate_conflicts(const Point& p, Face_handle fh, int i, + std::pair pit) const + { + Face_handle fn = fh->neighbor(i); + if(fn->get_in_conflict_flag() == 1) + return pit; - + if(!test_conflict(p, fn)) + { + *(pit.second)++ = Edge(fn, fn->index(fh)); + } + else + { + *(pit.first)++ = fn; + fn->set_in_conflict_flag(1); + int j = fn->index(fh); + pit = propagate_conflicts(p, fn, ccw(j), pit); + pit = propagate_conflicts(p, fn, cw(j), pit); + } + return pit; + } }; - + //------------power-test template < class Gt, class Tds > Oriented_side -Delaunay_triangulation_sphere_2:: -power_test(const Face_handle &f, const Point &p, bool perturb) const +Delaunay_triangulation_sphere_2:: +power_test(const Face_handle &f, const Point& p, bool perturb) const { - return power_test(f->vertex(0)->point(), f->vertex(1)->point(), f->vertex(2)->point(),p, perturb); + return power_test(f->vertex(0)->point(), f->vertex(1)->point(), f->vertex(2)->point(), p, perturb); } - + template < class Gt, class Tds > Oriented_side -Delaunay_triangulation_sphere_2:: -power_test(const Face_handle& f, int i, const Point &p) const +Delaunay_triangulation_sphere_2:: +power_test(const Face_handle& f, int i, const Point& p) const { - CGAL_triangulation_precondition ( orientation(f->vertex(ccw(i))->point(), - f->vertex( cw(i))->point(), p) - == COLLINEAR); - - return power_test(f->vertex(ccw(i))->point(), f->vertex( cw(i))->point(), p); + CGAL_triangulation_precondition(orientation(f->vertex(ccw(i))->point(), + f->vertex(cw(i))->point(), p) + == COLLINEAR); + + return power_test(f->vertex(ccw(i))->point(), f->vertex(cw(i))->point(), p); } -//computes the power-test of 4 points. perturb defines whether a symbolic perturbation -//is used (by default : perturb == false) - //in the perturbation the smalest vertex is in conflict with the others + +// computes the power-test of 4 points. perturb defines whether a symbolic perturbation +// is used (by default : perturb == false) +// in the perturbation the smalest vertex is in conflict with the others template < class Gt, class Tds > inline Oriented_side -Delaunay_triangulation_sphere_2:: -power_test(const Point &p0, const Point &p1, const Point &p2, const Point &p, bool perturb) const +Delaunay_triangulation_sphere_2:: +power_test(const Point& p0, const Point& p1, const Point& p2, const Point& p, bool perturb) const { - Oriented_side os = geom_traits().power_test_2_object()(p0,p1,p2,p); - if(os!=ON_ORIENTED_BOUNDARY || !perturb) - return os; - // We are now in a degenerate case => we do a symbolic perturbation. - - // We sort the points lexicographically. - const Point * points[3] = {&p0, &p1, &p2}; - std::sort(points, points+3, Perturbation_order(this) ); - - - if(points[0] == &p0){ - if(compare_xyz(p, p0)==SMALLER) - return ON_POSITIVE_SIDE; - if(coplanar_orientation(p0,p1,p,p2)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - if(coplanar_orientation(p0,p2,p,p1)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - - return ON_POSITIVE_SIDE; - } - - if(points[0] == &p1){ - if(compare_xyz(p, p1)==SMALLER) - return ON_POSITIVE_SIDE; - if(coplanar_orientation(p1,p0,p,p2)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - if(coplanar_orientation(p1,p2,p,p0)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - - return ON_POSITIVE_SIDE; - } - - if(points[0] == &p2){ - if(compare_xyz(p, p2)==SMALLER) - return ON_POSITIVE_SIDE; - if(coplanar_orientation(p2,p1,p,p0)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - if(coplanar_orientation(p2,p0,p1,p)==ON_NEGATIVE_SIDE) - return ON_NEGATIVE_SIDE; - - return ON_POSITIVE_SIDE; - } - - CGAL_assertion(false); - return ON_NEGATIVE_SIDE; - + Oriented_side os = geom_traits().power_test_2_object()(p0, p1, p2, p); + if(os != ON_ORIENTED_BOUNDARY || !perturb) + return os; + + // We are now in a degenerate case => we do a symbolic perturbation. + + // We sort the points lexicographically. + const Point * points[3] = { &p0, &p1, &p2 }; + std::sort(points, points+3, Perturbation_order(this)); + + if(points[0] == &p0) + { + if(compare_xyz(p, p0) == SMALLER) + return ON_POSITIVE_SIDE; + if(coplanar_orientation(p0, p1, p, p2) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + if(coplanar_orientation(p0, p2, p, p1) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + + return ON_POSITIVE_SIDE; + } + + if(points[0] == &p1) + { + if(compare_xyz(p, p1) == SMALLER) + return ON_POSITIVE_SIDE; + if(coplanar_orientation(p1, p0, p, p2) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + if(coplanar_orientation(p1, p2, p, p0) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + + return ON_POSITIVE_SIDE; + } + + if(points[0] == &p2) + { + if(compare_xyz(p, p2) == SMALLER) + return ON_POSITIVE_SIDE; + if(coplanar_orientation(p2, p1, p, p0) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + if(coplanar_orientation(p2, p0, p1, p) == ON_NEGATIVE_SIDE) + return ON_NEGATIVE_SIDE; + + return ON_POSITIVE_SIDE; + } + + CGAL_assertion(false); + return ON_NEGATIVE_SIDE; } - - + template < class Gt, class Tds > inline Oriented_side -Delaunay_triangulation_sphere_2:: -power_test(const Point &p, const Point &q, const Point &r) const +Delaunay_triangulation_sphere_2:: +power_test(const Point& p, const Point& q, const Point& r) const { - if(number_of_vertices()==2) - if(orientation_1(p,q)==COLLINEAR) - return ON_POSITIVE_SIDE; - return geom_traits().power_test_2_object()(p,q,r); + if(number_of_vertices() == 2) + if(orientation_1(p, q) == COLLINEAR) + return ON_POSITIVE_SIDE; + + return geom_traits().power_test_2_object()(p, q, r); } + //----------------------------------------------------------------------CHECK---------------------------------------------------------------// //checks whether a given triangulation is plane (all points are coplanar) template bool Delaunay_triangulation_sphere_2:: -is_plane()const{ +is_plane() const +{ bool plane = true; - if(dimension()==2) - return false; - - if(number_of_vertices() > 3){ - All_vertices_iterator it1 = vertices_begin(), - it2(it1), it3(it1), it4(it1); - ++it2; - ++it3; ++it3; - ++it4; ++it4; ++it4; - while( it4 != vertices_end()) { - Orientation s =power_test( it1->point(),it2->point(),it3->point(), it4->point()); - plane = plane && s == ON_ORIENTED_BOUNDARY ; - ++it1 ; ++it2; ++it3;++it4; - if (!plane) - return plane; - }return true; + if(dimension() == 2) + return false; + + if(number_of_vertices() > 3) + { + All_vertices_iterator it1 = vertices_begin(), it2(it1), it3(it1), it4(it1); + ++it2; + ++it3; ++it3; + ++it4; ++it4; ++it4; + + while(it4 != vertices_end()) + { + Orientation s = power_test(it1->point(), it2->point(), it3->point(), it4->point()); + plane = plane && s == ON_ORIENTED_BOUNDARY; + ++it1; + ++it2; + ++it3; + ++it4; + + if(!plane) + return plane; } - - if(number_of_vertices()==3) - return true; - + return true; + } + + if(number_of_vertices() == 3) + return true; + return plane; } - -template < class Gt, class Tds > -bool -Delaunay_triangulation_sphere_2:: -is_valid(bool verbose, int level ) const -{ - bool result = true; - - if ( !this-> _tds.is_valid(verbose,level) ) { - if (verbose) - std::cerr << "invalid data structure" << std::endl; - CGAL_triangulation_assertion(false); - return false; - } - - for(All_faces_iterator fit =all_faces_begin(); fit !=all_faces_end(); ++fit) - is_valid_face(fit, verbose, level); - - for(All_vertices_iterator vit = vertices_begin(); vit != vertices_end(); ++vit) - is_valid_vertex(vit, verbose, level); - - - switch(dimension()) { - case 0 : - break; - case 1: - CGAL_triangulation_assertion(this->is_plane()); - break; - case 2 : - 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 != NEGATIVE || it->is_ghost()); - CGAL_triangulation_assertion(result); - } - - result = result && (number_of_faces() == 2*(number_of_vertices()) - 4 ); - CGAL_triangulation_assertion( result); - break; - } - - // in any dimension - if(verbose) - std::cerr << " number of vertices " << number_of_vertices() << "\t" << std::endl; - - CGAL_triangulation_assertion( result); - return result; -} - - -template < class Gt, class Tds > -bool -Delaunay_triangulation_sphere_2:: -is_valid_vertex(Vertex_handle vh, bool verbose, int level) const -{ - bool result = vh->face()->has_vertex(vh); - if ( !result ) { - if(verbose) { - std::cerr << " from is_valid_vertex " << std::endl; - std::cerr << "normal vertex " << &(*vh) << std::endl; - std::cerr << vh->point() << " " << std::endl; - std::cerr << "vh_>face " << &*(vh->face()) << " " << std::endl; - show_face(vh->face()); - } - CGAL_triangulation_assertion(false); - return false; - } -return true; -} template < class Gt, class Tds > bool -Delaunay_triangulation_sphere_2:: -is_valid_face(Face_handle fh, bool verbose, int level) const +Delaunay_triangulation_sphere_2:: +is_valid(bool verbose, int level) const { - bool result = fh->get_in_conflict_flag()==0; - for (int i = 0; i<+2; i++) { - Orientation test = power_test(fh, fh->vertex(i)->point()); - result = result && test == ON_ORIENTED_BOUNDARY; - CGAL_triangulation_assertion(result); - } - if (!result) - if (verbose){ - std::cerr<<" from is_valid_face "< _tds.is_valid(verbose, level)) + { + if(verbose) + std::cerr << "invalid data structure" << std::endl; + + CGAL_triangulation_assertion(false); + return false; + } + + for(All_faces_iterator fit=all_faces_begin(); fit!=all_faces_end(); ++fit) + is_valid_face(fit, verbose, level); + + for(All_vertices_iterator vit=vertices_begin(); vit!=vertices_end(); ++vit) + is_valid_vertex(vit, verbose, level); + + switch(dimension()) + { + case 0 : + break; + case 1: + CGAL_triangulation_assertion(this->is_plane()); + break; + case 2 : + 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 != NEGATIVE || it->is_ghost()); + CGAL_triangulation_assertion(result); + } + + result = result && (number_of_faces() == 2*(number_of_vertices()) - 4); + CGAL_triangulation_assertion(result); + break; + } + + // in any dimension + if(verbose) + std::cerr << " number of vertices " << number_of_vertices() << "\t" << std::endl; + + CGAL_triangulation_assertion(result); return result; } - - //tests whether there is a conflict between p and the face fh +template < class Gt, class Tds > +bool +Delaunay_triangulation_sphere_2:: +is_valid_vertex(Vertex_handle vh, bool verbose, int level) const +{ + bool result = vh->face()->has_vertex(vh); + if(!result) + { + if(verbose) + { + std::cerr << " from is_valid_vertex " << std::endl; + std::cerr << "normal vertex " << &(*vh) << std::endl; + std::cerr << vh->point() << " " << std::endl; + std::cerr << "vh_>face " << &*(vh->face()) << " " << std::endl; + + show_face(vh->face()); + } + + CGAL_triangulation_assertion(false); + return false; + } + + return true; +} + +template < class Gt, class Tds > +bool +Delaunay_triangulation_sphere_2:: +is_valid_face(Face_handle fh, bool verbose, int level) const +{ + bool result = fh->get_in_conflict_flag() == 0; + for(int i=0; i<+2; ++i) + { + Orientation test = power_test(fh, fh->vertex(i)->point()); + result = result && test == ON_ORIENTED_BOUNDARY; + CGAL_triangulation_assertion(result); + } + + if(!result) + { + if(verbose) + { + std::cerr << " from is_valid_face " << std::endl; + std::cerr << " face " << std::endl; + show_face(fh); + } + } + + CGAL_triangulation_assertion(result); + return result; +} + +// tests whether there is a conflict between p and the face fh template < class Gt, class Tds > inline bool -Delaunay_triangulation_sphere_2:: -test_conflict(const Point &p, Face_handle fh) const +Delaunay_triangulation_sphere_2:: +test_conflict(const Point& p, Face_handle fh) const { - return(power_test(fh,p, true) != ON_NEGATIVE_SIDE); -} - - -//----------------------------------------------------------------------INSERTION-------------------------------------------------------------// + return(power_test(fh, p, true) != ON_NEGATIVE_SIDE); +} +// ------------------------ INSERTION --------------------------------// template < class Gt, class Tds > -typename Delaunay_triangulation_sphere_2::Vertex_handle -Delaunay_triangulation_sphere_2:: -insert(const Point &p, Face_handle start) +typename Delaunay_triangulation_sphere_2::Vertex_handle +Delaunay_triangulation_sphere_2:: +insert(const Point& p, Face_handle start) { Locate_type lt; int li; Face_handle loc = Base::locate(p, lt, li, start); - switch (lt){ - case NOT_ON_SPHERE: + + switch (lt) + { + case NOT_ON_SPHERE: return Vertex_handle(); - case TOO_CLOSE:{ - if(dimension()==2) - return loc->vertex(li); - return Vertex_handle(); - } - case VERTEX:{ - if(number_of_vertices()==1) - return vertices_begin(); - return (loc->vertex(li)); - } - default: //point can be inserted - return insert(p, lt, loc, li); + case TOO_CLOSE: + { + if(dimension() == 2) + return loc->vertex(li); + return Vertex_handle(); + } + case VERTEX: + { + if(number_of_vertices() == 1) + return vertices_begin(); + + return (loc->vertex(li)); + } + default: //point can be inserted + return insert(p, lt, loc, li); } } -//inserts a new point to a 1d triangulation, the new point is also coplanar with the existing points. +// inserts a new point to a 1d triangulation, the new point is also coplanar with the existing points. template < class Gt, class Tds> -typename Delaunay_triangulation_sphere_2::Vertex_handle +typename Delaunay_triangulation_sphere_2::Vertex_handle Delaunay_triangulation_sphere_2:: -insert_cocircular(const Point &p, Locate_type lt, Face_handle loc) +insert_cocircular(const Point& p, Locate_type lt, Face_handle loc) { - - CGAL_triangulation_precondition(!test_dim_up(p)); - CGAL_triangulation_precondition(dimension()==1); - - - Vertex_handle v0 = loc->vertex(0); - Vertex_handle v1 = loc->vertex(1); - Vertex_handle v=this->_tds.create_vertex(); - v->set_point(p); - - Face_handle f1 = this->_tds.create_face(v0, v, Vertex_handle()); - Face_handle f2 = this->_tds.create_face(v, v1, Vertex_handle()); - - v->set_face(f1); - v0->set_face(f1); - v1->set_face(f2); - - this->_tds.set_adjacency(f1,0,f2,1); - this->_tds.set_adjacency(f1,1,loc->neighbor(1),0); - this->_tds.set_adjacency(f2,0,loc->neighbor(0),1); - - - this->delete_face(loc); - - update_ghost_faces(v); - return v; + CGAL_triangulation_precondition(!test_dim_up(p)); + CGAL_triangulation_precondition(dimension() == 1); + + Vertex_handle v0 = loc->vertex(0); + Vertex_handle v1 = loc->vertex(1); + Vertex_handle v = this->_tds.create_vertex(); + v->set_point(p); + + Face_handle f1 = this->_tds.create_face(v0, v, Vertex_handle()); + Face_handle f2 = this->_tds.create_face(v, v1, Vertex_handle()); + + v->set_face(f1); + v0->set_face(f1); + v1->set_face(f2); + + this->_tds.set_adjacency(f1,0, f2,1); + this->_tds.set_adjacency(f1,1, loc->neighbor(1),0); + this->_tds.set_adjacency(f2,0, loc->neighbor(0),1); + + this->delete_face(loc); + + update_ghost_faces(v); + return v; } - template -typename Triangulation_sphere_2::Vertex_handle -Delaunay_triangulation_sphere_2:: +typename Triangulation_sphere_2::Vertex_handle +Delaunay_triangulation_sphere_2:: insert_first(const Point& p) { - CGAL_triangulation_precondition(number_of_vertices() == 0); - Vertex_handle v =this->_tds.insert_first(); - v->set_point(p); - return v; + CGAL_triangulation_precondition(number_of_vertices() == 0); + Vertex_handle v = this->_tds.insert_first(); + v->set_point(p); + return v; } - + template -typename Triangulation_sphere_2::Vertex_handle -Delaunay_triangulation_sphere_2:: +typename Triangulation_sphere_2::Vertex_handle +Delaunay_triangulation_sphere_2:: insert_second(const Point& p) { - CGAL_triangulation_precondition(number_of_vertices() == 1); - Vertex_handle v =this->_tds.insert_second(); - v->set_point(p); - return v; + CGAL_triangulation_precondition(number_of_vertices() == 1); + Vertex_handle v =this->_tds.insert_second(); + v->set_point(p); + return v; } - -//inserts a point which location is known. Calls the corresponding insert-function - //e.g. insert_first +// inserts a point which location is known. Calls the corresponding insert-function +// e.g. insert_first template < class Gt, class Tds > -typename Delaunay_triangulation_sphere_2::Vertex_handle -Delaunay_triangulation_sphere_2:: -insert(const Point &p, Locate_type lt, Face_handle loc, int li) +typename Delaunay_triangulation_sphere_2::Vertex_handle +Delaunay_triangulation_sphere_2:: +insert(const Point& p, Locate_type lt, Face_handle loc, int li) { - Vertex_handle v; - switch (dimension()){ - case -2 : - return insert_first(p); - case -1: - return insert_second(p); - case 0: - return insert_outside_affine_hull_regular(p); - case 1:{ - if(test_dim_up(p)){ - 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); - return insert_outside_affine_hull_regular(p); - } - else - return insert_cocircular(p,lt,loc); - } - case 2:{ - std::vector faces; - std::vector edges; - faces.reserve(32); - edges.reserve(32); - - get_conflicts_and_boundary(p, std::back_inserter(faces), std::back_inserter(edges), loc); - v =this->_tds.star_hole(edges.begin(), edges.end()); - v->set_point(p); - delete_faces(faces.begin(), faces.end()); - - if( lt != FACE ) - update_ghost_faces(v); - - return v; - } - } - CGAL_assertion(false); - return v; -} + Vertex_handle v; + switch (dimension()) + { + case -2 : + return insert_first(p); + case -1: + return insert_second(p); + case 0: + return insert_outside_affine_hull_regular(p); + case 1: + { + if(test_dim_up(p)) + { + 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); + return insert_outside_affine_hull_regular(p); + } + else + { + return insert_cocircular(p, lt, loc); + } + } + case 2: + { + std::vector faces; + std::vector edges; + faces.reserve(32); + edges.reserve(32); + + get_conflicts_and_boundary(p, std::back_inserter(faces), std::back_inserter(edges), loc); + v = this->_tds.star_hole(edges.begin(), edges.end()); + v->set_point(p); + delete_faces(faces.begin(), faces.end()); + + if(lt != FACE) + update_ghost_faces(v); + + return v; + } + } + + CGAL_assertion(false); + return v; +} - //inserts a new point which lies outside the affine hull of the other points template -typename Triangulation_sphere_2::Vertex_handle -Delaunay_triangulation_sphere_2:: +typename Triangulation_sphere_2::Vertex_handle +Delaunay_triangulation_sphere_2:: insert_outside_affine_hull_regular(const Point& p) { - if(dimension()==0){ - Vertex_handle v = vertices_begin(); - Vertex_handle u=v->face()->neighbor(0)->vertex(0); - Vertex_handle nv; - - //orientation is given by the 2 first points - if( this->collinear_between(v->point(),u->point(),p) || orientation(u->point(),v->point(),p) == LEFT_TURN ) - nv=Base::tds().insert_dim_up(v,false); - else - nv=Base::tds().insert_dim_up(v,true); - - nv->set_point(p); - - Face_handle f=all_edges_begin()->first; - CGAL_triangulation_assertion( orientation(f->vertex(0)->point(), f->vertex(1)->point(), - f->neighbor(0)->vertex(1)->point()) != RIGHT_TURN ); - - update_ghost_faces(nv); - return nv; - } - - else{ //dimension 1 - bool conform = false; - Face_handle f = (all_edges_begin())->first; - Face_handle fn=f->neighbor(0); - const Point p0=f->vertex(0)->point(); - const Point p1=f->vertex(1)->point(); - const Point p2=fn->vertex(1)->point(); - - CGAL_triangulation_assertion(orientation(p0, p1, p2)!=NEGATIVE); - Orientation orient2 = power_test(p0, p1, p2, p); - - - if(orient2==POSITIVE) - conform =true; - - //find smalest vertex this step garanties a unique triangulation - Vertex_handle w=vertices_begin(); - All_vertices_iterator vi; - for( vi = vertices_begin(); vi != vertices_end(); vi++){ - if(compare_xyz(vi->point(), w->point())==SMALLER){ - w=vi; - } - } - - Vertex_handle v = this->_tds.insert_dim_up( w, conform); - v->set_point(p); - this->_ghost=all_faces_begin(); - update_ghost_faces(v, true); - - return v; + if(dimension() == 0) + { + Vertex_handle v = vertices_begin(); + Vertex_handle u = v->face()->neighbor(0)->vertex(0); + Vertex_handle nv; + + //orientation is given by the 2 first points + if(this->collinear_between(v->point(), u->point(), p) || + orientation(u->point(), v->point(), p) == LEFT_TURN) + nv = Base::tds().insert_dim_up(v, false); + else + nv = Base::tds().insert_dim_up(v, true); + + nv->set_point(p); + + Face_handle f = all_edges_begin()->first; + CGAL_triangulation_assertion(orientation(f->vertex(0)->point(), f->vertex(1)->point(), + f->neighbor(0)->vertex(1)->point()) != RIGHT_TURN); + + update_ghost_faces(nv); + return nv; + } + else // dimension 1 + { + bool conform = false; + Face_handle f = (all_edges_begin())->first; + Face_handle fn = f->neighbor(0); + const Point p0 = f->vertex(0)->point(); + const Point p1 = f->vertex(1)->point(); + const Point p2 = fn->vertex(1)->point(); + + CGAL_triangulation_assertion(orientation(p0, p1, p2)!=NEGATIVE); + Orientation orient2 = power_test(p0, p1, p2, p); + + if(orient2 == POSITIVE) + conform = true; + + // find smalest vertex this step garanties a unique triangulation + Vertex_handle w=vertices_begin(); + All_vertices_iterator vi; + for(vi=vertices_begin(); vi!=vertices_end(); ++vi) + { + if(compare_xyz(vi->point(), w->point()) == SMALLER) + w = vi; + } + + Vertex_handle v = this->_tds.insert_dim_up(w, conform); + v->set_point(p); + this->_ghost = all_faces_begin(); + update_ghost_faces(v, true); + + return v; } } - - -/*method to mark faces incident to v as ghost-faces or solid-faces. - bool first defines whether dimension of the triangulation increased - from one to two by inserting v - If first == true all faces are updated. +/* + * method to mark faces incident to v as ghost-faces or solid-faces. + * bool first defines whether dimension of the triangulation increased + * from one to two by inserting v + * If first == true all faces are updated. */ template < class Gt, class Tds > bool -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: update_ghost_faces(Vertex_handle v, bool first) { - if (number_of_vertices()<3) - return false; - - bool neg_found=false; - if(dimension()==1){ - All_edges_iterator eit=all_edges_begin(); - for (; eit!=all_edges_end(); eit++){ - Face_handle f=eit->first; - Face_handle fn=f->neighbor(0); - Point q=fn->vertex(1)->point(); - if(this->collinear_between(f->vertex(0)->point(),f->vertex(1)->point(),q)){ - f->ghost()=true; - neg_found = true; - } - else - f->ghost()=false; - } - } - else{//dimension==2 - if (first){ //first time dimension 2 - All_faces_iterator fi = all_faces_begin(); - for(;fi!=all_faces_end();fi++){ - if(orientation(fi)!=POSITIVE){ - fi->ghost()=true; - neg_found=true; - this->_ghost=fi; - } - else - fi->ghost()=false; - } - } - - else { //not first - Face_circulator fc=this->incident_faces(v,v->face()); - Face_circulator done(fc); - do{ - if(orientation(fc)!=POSITIVE){ - fc->ghost()=true; - neg_found=true; - this->_ghost=fc; + if(number_of_vertices() < 3) + return false; + + bool neg_found = false; + if(dimension() == 1) + { + All_edges_iterator eit = all_edges_begin(); + for(; eit!=all_edges_end(); ++eit) + { + Face_handle f=eit->first; + Face_handle fn=f->neighbor(0); + Point q=fn->vertex(1)->point(); + if(this->collinear_between(f->vertex(0)->point(), f->vertex(1)->point(), q)) + { + f->ghost() = true; + neg_found = true; + } + else + f->ghost()=false; + } + } + else // dimension==2 + { + if(first) // first time dimension 2 + { + All_faces_iterator fi = all_faces_begin(); + for(; fi!=all_faces_end(); fi++) + { + if(orientation(fi) != POSITIVE) + { + fi->ghost() = true; + neg_found = true; + this->_ghost = fi; } else - fc->ghost()=false; - }while(++fc!=done); - } - - } - return neg_found; + { + fi->ghost() = false; + } + } + } + else // not first + { + Face_circulator fc = this->incident_faces(v, v->face()); + Face_circulator done(fc); + do + { + if(orientation(fc) != POSITIVE) + { + fc->ghost() = true; + neg_found = true; + this->_ghost = fc; + } + else + { + fc->ghost() = false; + } + } while(++fc != done); + } + } + return neg_found; } //-------------------------------------------------------------------------------REMOVAL----------------------------------------------------// template < class Gt, class Tds > void -Delaunay_triangulation_sphere_2:: -remove_degree_3(Vertex_handle v, Face_handle f) +Delaunay_triangulation_sphere_2:: +remove_degree_3(Vertex_handle v, Face_handle f) { - if (f == Face_handle()) f=v->face(); - this->_tds.remove_degree_3(v,f); + if(f == Face_handle()) + f = v->face(); + + this->_tds.remove_degree_3(v, f); } - - - template < class Gt, class Tds > void -Delaunay_triangulation_sphere_2:: -remove(Vertex_handle v ) +Delaunay_triangulation_sphere_2:: +remove(Vertex_handle v) { -CGAL_triangulation_precondition( v != Vertex_handle() ); - if(number_of_vertices()<=3) - this->_tds.remove_dim_down(v); - - else if(dimension()==2) - remove_2D (v); - - else - remove_1D(v); - + CGAL_triangulation_precondition(v != Vertex_handle()); + if(number_of_vertices()<=3) + this->_tds.remove_dim_down(v); + else if(dimension() == 2) + remove_2D (v); + else + remove_1D(v); } - - template void Delaunay_triangulation_sphere_2:: remove_1D(Vertex_handle v) { - this->_tds.remove_1D(v); - update_ghost_faces(); + this->_tds.remove_1D(v); + update_ghost_faces(); } - - - - + template < class Gt, class Tds > void -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: remove_2D(Vertex_handle v) { - CGAL_triangulation_precondition(dimension()==2); - - if (test_dim_down(v)) { //resulting triangulation has dim 1 + CGAL_triangulation_precondition(dimension() == 2); + + if(test_dim_down(v)) // resulting triangulation has dim 1 + { this->_tds.remove_dim_down(v); - update_ghost_faces(); //1d triangulation, no vertex needed to update ghost-faces + update_ghost_faces(); //1d triangulation, no vertex needed to update ghost-faces } - else { + else + { std::list hole; this->make_hole(v, hole); fill_hole_regular(hole); - } - return; + } } - - -//tests whether the dimension will decrease when removing v from the triangulation. +// tests whether the dimension will decrease when removing v from the triangulation. template bool -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: test_dim_down(Vertex_handle v) { - CGAL_triangulation_precondition(dimension()==2); - bool dim1 = true; - if(number_of_vertices()==4){ + CGAL_triangulation_precondition(dimension() == 2); + bool dim1 = true; + if(number_of_vertices() == 4) return dim1; + + std::vector points; + All_vertices_iterator it = vertices_begin(); + for(; it!=vertices_end(); ++it) + if(it != v) + points.push_back(it->point()); + + for(int i=0; i<(int)points.size()-4; ++i) + { + Orientation s = power_test(points.at(i), points.at(i+1), points.at(i+2), points.at(i+3)); + dim1 = dim1 && s == ON_ORIENTED_BOUNDARY; + if(!dim1) + return dim1; } - - std::vector points; - All_vertices_iterator it = vertices_begin(); - for(; it!=vertices_end();it ++) - if (it != v) - points.push_back(it->point()); - - for(int i=0; i<(int)points.size()-4; i++){ - Orientation s = power_test(points.at(i), points.at(i+1),points.at(i+2),points.at(i+3)); - dim1 = dim1 && s == ON_ORIENTED_BOUNDARY ; - if (!dim1) - return dim1; - }return true; - + + return true; } - -//tests whether the dimension will increase when adding p to the triangulation. +// tests whether the dimension will increase when adding p to the triangulation. template bool -Delaunay_triangulation_sphere_2:: -test_dim_up(const Point &p) const - { - CGAL_triangulation_precondition(dimension()!=2); - 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); - - v1->point(); - return (power_test(v1->point(), v2->point(), v3->point(),p)!=ON_ORIENTED_BOUNDARY); - +Delaunay_triangulation_sphere_2:: +test_dim_up(const Point& p) const +{ + CGAL_triangulation_precondition(dimension()!=2); + 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); + + v1->point(); + return (power_test(v1->point(), v2->point(), v3->point(), p) != ON_ORIENTED_BOUNDARY); } - -//fill the hole in a triangulation after vertex removal. + +//fill the hole in a triangulation after vertex removal. template < class Gt, class Tds > void -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: fill_hole_regular(std::list & first_hole) { typedef std::list Hole; typedef std::list Hole_list; - + Hole hole; Hole_list hole_list; Face_handle ff, fn; int i, ii, in; - + hole_list.push_front(first_hole); - - while (! hole_list.empty()) + + while(! hole_list.empty()) + { + hole = hole_list.front(); + hole_list.pop_front(); + typename Hole::iterator hit = hole.begin(); + + // if the hole has only three edges, create the triangle + if(hole.size() == 3) { - hole = hole_list.front(); - hole_list.pop_front(); - typename Hole::iterator hit = hole.begin(); - - // if the hole has only three edges, create the triangle - if (hole.size() == 3) - { - Face_handle newf = create_face(); - hit = hole.begin(); - for(int j=0; j<3; j++) - { - ff = (*hit).first; - ii = (*hit).second; - hit++; - ff->set_neighbor(ii,newf); - newf->set_neighbor(j,ff); - newf->set_vertex(newf->ccw(j),ff->vertex(ff->cw(ii))); - } - if(orientation(newf) != POSITIVE){ - this->_ghost=newf; - newf->ghost()=true; - } - continue; - } - - // else find an edge with two finite vertices - // on the hole boundary - // and the new triangle adjacent to that edge - // cut the hole and push it back - - // take the first neighboring face and pop it; - ff = hole.front().first; - ii = hole.front().second; - hole.pop_front(); - - Vertex_handle v0 = ff->vertex(ff->cw(ii)); - const Point& p0 = v0->point(); - Vertex_handle v1 = ff->vertex(ff->ccw(ii)); - const Point& p1 = v1->point(); - Vertex_handle v2 = Vertex_handle(); - Point p2; - Vertex_handle vv; - Point p; - - typename Hole::iterator hdone = hole.end(); + Face_handle newf = create_face(); hit = hole.begin(); - typename Hole::iterator cut_after(hit); - - // if tested vertex is c with respect to the vertex opposite - // to NULL neighbor, - // stop at the before last face; - hdone--; - while (hit != hdone) - { - fn = (*hit).first; - in = (*hit).second; - vv = fn->vertex(ccw(in)); - p = vv->point(); - if ( /*orientation(p0,p1,p) == COUNTERCLOCKWISE*/ 1) - { - if (v2==Vertex_handle()) - { - v2=vv; - p2=p; - cut_after=hit; - } - else if (power_test(p0,p1,p2,p) == - ON_POSITIVE_SIDE) - { - v2=vv; - p2=p; - cut_after=hit; - } - } - - ++hit; - } - - // create new triangle and update adjacency relations - Face_handle newf = create_face(v0,v1,v2); - newf->set_neighbor(2,ff); - ff->set_neighbor(ii, newf); - if(orientation(newf) != POSITIVE){ - this->_ghost=newf; - newf->ghost()=true; + for(int j=0; j<3; ++j) + { + ff = (*hit).first; + ii = (*hit).second; + hit++; + ff->set_neighbor(ii, newf); + newf->set_neighbor(j, ff); + newf->set_vertex(newf->ccw(j), ff->vertex(ff->cw(ii))); } - //update the hole and push back in the Hole_List stack - // if v2 belongs to the neighbor following or preceding *f - // the hole remain a single hole - // otherwise it is split in two holes - - fn = hole.front().first; - in = hole.front().second; - if (fn->has_vertex(v2, i) && i == (int)fn->ccw(in)) - { - newf->set_neighbor(0,fn); - fn->set_neighbor(in,newf); - hole.pop_front(); - hole.push_front(Edge(newf,1)); - hole_list.push_front(hole); - } - else - { - fn = hole.back().first; - in = hole.back().second; - if (fn->has_vertex(v2, i) && i == (int)fn->cw(in)) - { - newf->set_neighbor(1,fn); - fn->set_neighbor(in,newf); - hole.pop_back(); - hole.push_back(Edge(newf,0)); - hole_list.push_front(hole); - } - else - { // split the hole in two holes - Hole new_hole; - ++cut_after; - while (hole.begin() != cut_after) - { - new_hole.push_back(hole.front()); - hole.pop_front(); - } - - hole.push_front(Edge(newf,1)); - new_hole.push_front(Edge(newf,0)); - hole_list.push_front(hole); - hole_list.push_front(new_hole); - } - } + + if(orientation(newf) != POSITIVE) + { + this->_ghost = newf; + newf->ghost() = true; + } + continue; } + + // else find an edge with two finite vertices + // on the hole boundary + // and the new triangle adjacent to that edge + // cut the hole and push it back + + // take the first neighboring face and pop it; + ff = hole.front().first; + ii = hole.front().second; + hole.pop_front(); + + Vertex_handle v0 = ff->vertex(ff->cw(ii)); + const Point& p0 = v0->point(); + Vertex_handle v1 = ff->vertex(ff->ccw(ii)); + const Point& p1 = v1->point(); + Vertex_handle v2 = Vertex_handle(); + Point p2; + Vertex_handle vv; + Point p; + + typename Hole::iterator hdone = hole.end(); + hit = hole.begin(); + typename Hole::iterator cut_after(hit); + + // if tested vertex is c with respect to the vertex opposite + // to NULL neighbor, + // stop at the before last face; + --hdone; + + while(hit != hdone) + { + fn = (*hit).first; + in = (*hit).second; + vv = fn->vertex(ccw(in)); + p = vv->point(); + + if(/*orientation(p0, p1, p) == COUNTERCLOCKWISE*/ 1) + { + if(v2==Vertex_handle()) + { + v2=vv; + p2=p; + cut_after=hit; + } + else if(power_test(p0, p1, p2, p) == ON_POSITIVE_SIDE) + { + v2 = vv; + p2 = p; + cut_after = hit; + } + } + + ++hit; + } + + // create new triangle and update adjacency relations + Face_handle newf = create_face(v0, v1, v2); + newf->set_neighbor(2, ff); + ff->set_neighbor(ii, newf); + if(orientation(newf) != POSITIVE) + { + this->_ghost = newf; + newf->ghost() = true; + } + + //update the hole and push back in the Hole_List stack + // if v2 belongs to the neighbor following or preceding *f + // the hole remain a single hole + // otherwise it is split in two holes + + fn = hole.front().first; + in = hole.front().second; + if(fn->has_vertex(v2, i) && i == (int)fn->ccw(in)) + { + newf->set_neighbor(0, fn); + fn->set_neighbor(in, newf); + hole.pop_front(); + hole.push_front(Edge(newf, 1)); + hole_list.push_front(hole); + } + else + { + fn = hole.back().first; + in = hole.back().second; + if(fn->has_vertex(v2, i) && i == (int)fn->cw(in)) + { + newf->set_neighbor(1, fn); + fn->set_neighbor(in, newf); + hole.pop_back(); + hole.push_back(Edge(newf, 0)); + hole_list.push_front(hole); + } + else + { // split the hole in two holes + Hole new_hole; + ++cut_after; + while(hole.begin() != cut_after) + { + new_hole.push_back(hole.front()); + hole.pop_front(); + } + + hole.push_front(Edge(newf, 1)); + new_hole.push_front(Edge(newf, 0)); + hole_list.push_front(hole); + hole_list.push_front(new_hole); + } + } + } } -//-----------------dual------------------------ - - //Following methods are used to compute the Voronoi-Diagram +//-----------------dual------------------------ + +//Following methods are used to compute the Voronoi-Diagram template inline -typename Delaunay_triangulation_sphere_2:: Point +typename Delaunay_triangulation_sphere_2::Point Delaunay_triangulation_sphere_2:: -dual (Face_handle f)const +dual(Face_handle f) const { - CGAL_triangulation_precondition(this->_tds.is_face(f)); - CGAL_triangulation_precondition (this->dimension()==2); - return circumcenter(f); + CGAL_triangulation_precondition(this->_tds.is_face(f)); + CGAL_triangulation_precondition(this->dimension() == 2); + return circumcenter(f); } - + template < class Gt, class Tds > Object -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: dual(const Edge &e) const { - CGAL_triangulation_precondition(this->_tds.is_edge(e.first,e.second)); - CGAL_triangulation_precondition(dimension()==2); - Segment s = this->geom_traits().construct_segment_2_object() - (dual(e.first),dual(e.first->neighbor(e.second))); - return make_object(s); + CGAL_triangulation_precondition(this->_tds.is_edge(e.first, e.second)); + CGAL_triangulation_precondition(dimension() == 2); + Segment s = this->geom_traits().construct_segment_2_object()( + dual(e.first), dual(e.first->neighbor(e.second))); + + return make_object(s); } - + template < class Gt, class Tds > inline Object -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: dual(const Edge_circulator& ec) const { - return dual(*ec); + return dual(*ec); } - + template < class Gt, class Tds > inline Object -Delaunay_triangulation_sphere_2:: +Delaunay_triangulation_sphere_2:: dual(const All_edges_iterator& ei) const { - return dual(*ei); + return dual(*ei); } - -} //namespace CGAL + +} // namespace CGAL #endif // CGAL_Delaunay_triangulation_sphere_2_H diff --git a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_filtered_traits_2.h b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_filtered_traits_2.h index cc31a4bd4a1..5953f8efe90 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_filtered_traits_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_filtered_traits_2.h @@ -1,12 +1,27 @@ -// Author(s) : +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Mariette Yvinec, Claudia Werner #ifndef CGAL_DELAUNAY_TRIANGULATION_SPHERE_FILTERED_TRAITS_2_H #define CGAL_DELAUNAY_TRIANGULATION_SPHERE_FILTERED_TRAITS_2_H -#include #include -#include -//#include namespace CGAL { @@ -34,15 +49,12 @@ struct Delaunay_weighted_converter_2 return Target_wp(Converter::operator()(wp.point()), Converter::operator()(wp.weight())); }*/ - Target_wp - operator()(const Source_wp &wp) const - { - return Converter::operator()(wp); - } + + Target_wp operator()(const Source_wp &wp) cons { return Converter::operator()(wp); } }; - /* - + /* + // The argument is supposed to be a Filtered_kernel like kernel. template < typename K > class Delaunay_triangulation_sphere_filtered_traits_2 @@ -99,7 +111,7 @@ public: Delaunay_weighted_converter_2 > In_cone_3; Power_test_2 power_test_2_object() const - { return Power_test_2();} + { return Power_test_2(); } Compare_power_distance_2 compare_power_distance_2_object() const { return Compare_power_distance_2(); } @@ -112,7 +124,7 @@ public: } Side_of_oriented_circle_2 - side_of_oriented_circle_2_object() const { + side_of_oriented_circle_2_object() const { return Side_of_oriented_circle_2(); } diff --git a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_traits_2.h b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_traits_2.h index fec26586f7f..2baa70ab98d 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_traits_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Delaunay_triangulation_sphere_traits_2.h @@ -1,308 +1,291 @@ +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Mariette Yvinec, Claudia Werner #ifndef CGAL_DELAUNAY_TRIANGULATION_SPHERE_TRAITS_2_H #define CGAL_DELAUNAY_TRIANGULATION_SPHERE_TRAITS_2_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include -#include -#include +namespace CGAL { - -namespace CGAL { - -template +template < typename K > class Power_test_2 { - public: - typedef typename K::Point_2 Point_2; - typedef typename K::Oriented_side Oriented_side; - typedef typename K::Comparison_result Comparison_result; - +public: + typedef typename K::Point_2 Point_2; + typedef typename K::Oriented_side Oriented_side; + typedef typename K::Comparison_result Comparison_result; Power_test_2(const Point_2& sphere); - Oriented_side operator() (const Point_2& p, - const Point_2& q, - const Point_2& r, - const Point_2& s) const - { return orientation(p,q,r,s); } - - - Oriented_side operator() (const Point_2& p, - const Point_2& q, - const Point_2& r) const + Oriented_side operator()(const Point_2& p, + const Point_2& q, + const Point_2& r, + const Point_2& s) const { - return -coplanar_orientation(p,q,_sphere,r); + return orientation(p, q, r, s); } - - Oriented_side operator() (const Point_2& p, - const Point_2& q) const + Oriented_side operator()(const Point_2& p, + const Point_2& q, + const Point_2& r) const { - Comparison_result pq=compare_xyz(p,q); - - if(pq==EQUAL){ + return -coplanar_orientation(p, q,_sphere, r); + } + + Oriented_side operator()(const Point_2& p, + const Point_2& q) const + { + Comparison_result pq = compare_xyz(p, q); + + if(pq == EQUAL) return ON_ORIENTED_BOUNDARY; - } - Comparison_result sq=compare_xyz(_sphere,q); - if(pq==sq){ + + Comparison_result sq = compare_xyz(_sphere, q); + if(pq == sq) return ON_POSITIVE_SIDE; - } + return ON_NEGATIVE_SIDE; } -public: - typedef Oriented_side result_type; - protected: - Point_2 _sphere; +public: + typedef Oriented_side result_type; + +protected: + Point_2 _sphere; }; - + template < typename K > Power_test_2:: Power_test_2(const Point_2& sphere) -: _sphere(sphere) -{} - - + : _sphere(sphere) +{ } + template < typename K > class Orientation_sphere_1 { public: - typedef typename K::Point_2 Point_2; - typedef typename K::Comparison_result Comparison_result; + typedef typename K::Point_2 Point_2; + typedef typename K::Comparison_result Comparison_result; + typedef Comparison_result result_type; + + Orientation_sphere_1(const Point_2& sphere); + + Comparison_result operator()(const Point_2& p, const Point_2& q) const + { + return coplanar_orientation(_sphere, p, q); + } + + Comparison_result operator()(const Point_2& p, const Point_2& q, const Point_2& r) const + { + return coplanar_orientation(p, q, r, _sphere); + } + + Comparison_result operator()(const Point_2& p, const Point_2& q, const Point_2& r, const Point_2& s) const + { + return coplanar_orientation(p, q, r, s); + } - Orientation_sphere_1(const Point_2& sphere); - - Comparison_result operator()(const Point_2& p, const Point_2& q) const - { return coplanar_orientation(_sphere,p,q);} - - Comparison_result operator()(const Point_2& p, const Point_2& q, const Point_2& r) const - { return coplanar_orientation(p,q,r,_sphere); } - - Comparison_result operator()(const Point_2& p, const Point_2& q, const Point_2& r,const Point_2& s) const - { return coplanar_orientation(p,q,r,s);} - - protected : -Point_2 _sphere; - -public: - typedef Comparison_result result_type; + Point_2 _sphere; }; template < typename K > Orientation_sphere_1:: Orientation_sphere_1(const Point_2& sphere) -: _sphere(sphere) -{} - - - + : _sphere(sphere) +{ } + template < typename K > class Orientation_sphere_2 { public: - typedef typename K::Point_2 Point_2; - typedef typename K::Comparison_result Comparison_result; - - typedef Comparison_result result_type; - - Orientation_sphere_2(const Point_2& sphere); - - Comparison_result operator()(const Point_2& p, const Point_2& q, - const Point_2& r) const - { return orientation(_sphere,p,q,r);} - - Comparison_result operator()(const Point_2& p, const Point_2& q, - const Point_2& r, const Point_2 & s) const - {return orientation(p,q,r,s);} - - + typedef typename K::Point_2 Point_2; + typedef typename K::Comparison_result Comparison_result; + + typedef Comparison_result result_type; + + Orientation_sphere_2(const Point_2& sphere); + + Comparison_result operator()(const Point_2& p, const Point_2& q, + const Point_2& r) const + { return orientation(_sphere, p, q, r); } + + Comparison_result operator()(const Point_2& p, const Point_2& q, + const Point_2& r, const Point_2& s) const + { return orientation(p, q, r, s); } + protected : -Point_2 _sphere; + Point_2 _sphere; }; - - + template < typename K > Orientation_sphere_2:: - Orientation_sphere_2(const Point_2& sphere) - : _sphere(sphere) - {} - - +Orientation_sphere_2(const Point_2& sphere) + : _sphere(sphere) +{ } + template < typename K > class Coradial_sphere_2 { public: - typedef typename K::Point_2 Point_2; -Coradial_sphere_2(const Point_2& sphere); + typedef typename K::Point_2 Point_2; + typedef bool result_type; + + Coradial_sphere_2(const Point_2& sphere); + + bool operator()(const Point_2& p, const Point_2 q) const + { + return collinear(_sphere, p, q) && + (are_ordered_along_line(_sphere, p, q) || + are_ordered_along_line(_sphere, q, p)); + } - bool operator()(const Point_2& p, const Point_2 q) const - { - return collinear(_sphere,p,q) && - ( are_ordered_along_line(_sphere,p,q) || are_ordered_along_line(_sphere,q,p) ); - } - protected : -Point_2 _sphere; - - -public: - typedef bool result_type; + Point_2 _sphere; }; - + template < typename K > Coradial_sphere_2:: Coradial_sphere_2(const Point_2& sphere) -: _sphere(sphere) -{} - - + : _sphere(sphere) +{ } + template < typename K > class Inside_cone_2 { public: - typedef typename K::Point_2 Point_2; - - Inside_cone_2(const Point_2& sphere); - -bool operator()(const Point_2& p, const Point_2& q, const Point_2& r) const -{ - if( collinear(_sphere,p,r)||collinear(_sphere,q,r)||orientation(_sphere,p,q,r)!=COLLINEAR) - return false; - if( collinear(_sphere,p,q) ) - return true; - return coplanar_orientation(_sphere,p,q,r) == ( POSITIVE==coplanar_orientation(_sphere,q,p,r) ); -} - + typedef typename K::Point_2 Point_2; + typedef bool result_type; + + Inside_cone_2(const Point_2& sphere); + + bool operator()(const Point_2& p, const Point_2& q, const Point_2& r) const + { + if(collinear(_sphere, p, r) || + collinear(_sphere, q, r) || + orientation(_sphere, p, q, r) != COLLINEAR) + return false; + + if(collinear(_sphere, p, q)) + return true; + + return coplanar_orientation(_sphere, p, q, r) == + (POSITIVE == coplanar_orientation(_sphere, q, p, r)); + } + protected : - Point_2 _sphere; - -public: - typedef bool result_type; + Point_2 _sphere; }; template < typename K > Inside_cone_2:: Inside_cone_2(const Point_2& sphere) -: _sphere(sphere) -{} - + : _sphere(sphere) +{ } + template < class R > class Delaunay_triangulation_sphere_traits_2 : public R { public: - - typedef typename R::Point_3 Point_2; + typedef typename R::Point_3 Point_2; typedef typename R::Point_3 Weighted_point_2; - typedef typename R::Ray_3 Ray_2; + typedef typename R::Ray_3 Ray_2; typedef typename R::Line_3 Line_2; typedef typename R::Construct_ray_3 Construct_ray_3; typedef typename R::Construct_circumcenter_3 Construct_circumcenter_3; typedef typename R::Construct_bisector_3 Construct_bisector_3; typedef typename R::Construct_segment_3 Construct_segment_3; - - typedef Delaunay_triangulation_sphere_traits_2 Self; - typedef CGAL::Power_test_2 Power_test_2; - typedef CGAL::Orientation_sphere_2 Orientation_2; - typedef CGAL::Coradial_sphere_2 Coradial_sphere_2; - typedef CGAL::Inside_cone_2 Inside_cone_2; - //typedef CGAL::Orientation_sphere_1 Orientation_1; - typedef typename R::Coplanar_orientation_3 Orientation_1; - typedef typename R::Compute_squared_distance_3 Compute_squared_distance_2; - typedef typename R::Compare_xyz_3 Compare_xyz_3; - - double _radius; - - - typedef boost::true_type requires_test; - void set_radius(double a){_radius = a;} - - Delaunay_triangulation_sphere_traits_2(const Point_2& sphere=Point_2(0,0,0)); + typedef Delaunay_triangulation_sphere_traits_2 Self; + typedef CGAL::Power_test_2 Power_test_2; + typedef CGAL::Orientation_sphere_2 Orientation_2; + typedef CGAL::Coradial_sphere_2 Coradial_sphere_2; + typedef CGAL::Inside_cone_2 Inside_cone_2; + //typedef CGAL::Orientation_sphere_1 Orientation_1; + typedef typename R::Coplanar_orientation_3 Orientation_1; + typedef typename R::Compute_squared_distance_3 Compute_squared_distance_2; + typedef typename R::Compare_xyz_3 Compare_xyz_3; + + typedef boost::true_type requires_test; + + double _radius; + + void set_radius(double a) { _radius = a; } + + Delaunay_triangulation_sphere_traits_2(const Point_2& sphere = Point_2(0,0,0)); Compare_xyz_3 compare_xyz_3_object() const - {return Compare_xyz_3();} - + { return Compare_xyz_3(); } + Compute_squared_distance_2 compute_squared_distance_2_object() const - {return Compute_squared_distance_2();} - + { return Compute_squared_distance_2(); } Orientation_2 - orientation_2_object()const - {return Orientation_2(_sphere);} + orientation_2_object() const + { return Orientation_2(_sphere); } Orientation_1 orientation_1_object() const - {return Orientation_1();} + { return Orientation_1(); } - Power_test_2 + Power_test_2 power_test_2_object() const - {return Power_test_2(_sphere);} + { return Power_test_2(_sphere); } Coradial_sphere_2 coradial_sphere_2_object() const - {return Coradial_sphere_2(_sphere);} + { return Coradial_sphere_2(_sphere); } Inside_cone_2 inside_cone_2_object() const - {return Inside_cone_2(_sphere);} - - Construct_ray_3 construct_ray_2_object() const - {return Construct_ray_3();} + { return Inside_cone_2(_sphere); } - Construct_circumcenter_3 - construct_circumcenter_2_object() const - { return Construct_circumcenter_3();} + Construct_ray_3 + construct_ray_2_object() const + { return Construct_ray_3(); } - - Construct_segment_3 - construct_segment_2_object()const - {return Construct_segment_3();} + Construct_circumcenter_3 + construct_circumcenter_2_object() const + { return Construct_circumcenter_3(); } + + Construct_segment_3 + construct_segment_2_object() const + { return Construct_segment_3(); } + + Compute_squared_distance_2 + compute_squared_distance_3_object() const + { return Compute_squared_distance_2(); } - - Compute_squared_distance_2 compute_squared_distance_3_object() const - { return Compute_squared_distance_2(); } - protected : Point_2 _sphere; - }; template < class R > Delaunay_triangulation_sphere_traits_2 :: Delaunay_triangulation_sphere_traits_2(const Point_2& sphere) -: _sphere(sphere) - {} + : _sphere(sphere) +{ } - -} //namespace CGAL +} // namespace CGAL #endif // CGAL_Reg_TRIANGULATION_SPHERE_TRAITS_2_H - - - - - - - - - - - - - diff --git a/Triangulation_on_sphere_2/include/CGAL/Projection_sphere_traits_3.h b/Triangulation_on_sphere_2/include/CGAL/Projection_sphere_traits_3.h index 3cdb9bff670..ff3c8e352cb 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Projection_sphere_traits_3.h +++ b/Triangulation_on_sphere_2/include/CGAL/Projection_sphere_traits_3.h @@ -1,231 +1,231 @@ +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Mariette Yvinec, Claudia Werner #ifndef CGAL_PROJECTION_SPHERE_TRAITS_3_H #define CGAL_PROJECTION_SPHERE_TRAITS_3_H -#include -#include -#include #include -namespace CGAL{template +#include + +#include +#include + +namespace CGAL { + +template class Projection_sphere_traits_3; - - template < typename K> -class Projected_point -: public K::Point_3{ - + +template < typename K> +class Projected_point + : public K::Point_3 +{ public: - typedef typename K::Point_3 Base_point; - Projected_point() - :Base_point(){} - + typedef typename K::Point_3 Base_point; -Projected_point(const Base_point &p, const typename K::Point_3& sphere_center) - :Base_point(p){compute_scale( p-(sphere_center-ORIGIN) );} - - -public: - double _scale; - - void scale(){return _scale;} - -private: - void compute_scale(double x, double y, double z){ - double tmp = x*x+y*y+z*z; - if (tmp == 0 ) - _scale = 0; - - else - _scale = 1/sqrt(tmp); - } - - void compute_scale(const Base_point &p){ - return compute_scale(p.x(), p.y(), p.z()); + Projected_point() : Base_point() { } + Projected_point(const Base_point& p, + const typename K::Point_3& sphere_center) + : Base_point(p) + { + compute_scale(p-(sphere_center-ORIGIN)); } - -}; -//the following two different adaptors are necessary because the Predicates don not need _sphere - //compared to Predicates from Delaunay_sphere_traits - - -//adaptor for calling the Predicate_ with the points projected on the sphere -template < class K, class P, class Predicate_ > -class Traits_with_projection_adaptor { + public: - typedef Predicate_ Predicate; - - typedef typename P::Point_2 Point; - typedef typename K::Point_2 Base_point; - Traits_with_projection_adaptor(Base_point sphere, double radius):_radius(radius), _sphere(sphere){} - double _radius; - Base_point _sphere ; - - typedef typename Predicate::result_type result_type; - - - result_type operator()(const Point& p0, const Point& p1) - {return Predicate(_sphere)(project(p0), project(p1));} - - - result_type operator()(const Point& p0, const Point& p1, const Point& p2) - {return Predicate(_sphere)(project(p0), project(p1), project(p2));} - - - result_type operator ()(const Point& p0, const Point& p1, const Point& p2, const Point& p3) - {return Predicate(_sphere)(project(p0), project(p1), project(p2), project(p3));} - - - result_type operator()(const Point& p0, const Point& p1, const Point& p2, const Point& p3, const Point& p4) - {return Predicate(_sphere)(project(p0), project(p1), project(p2), project(p3), project(p4));} - - + double _scale; + + void scale() { return _scale; } + private: - Base_point project (const Point& p){ - double scale = _radius*p._scale; - return Base_point(scale*p.x(), scale*p.y(), scale*p.z()); - } + void compute_scale(double x, double y, double z) + { + double tmp = x*x+y*y+z*z; + if(tmp == 0) + _scale = 0; + else + _scale = 1 / sqrt(tmp); + } + + void compute_scale(const Base_point& p) + { + return compute_scale(p.x(), p.y(), p.z()); + } }; -//adaptor for calling the Predicate_ with the points projected on the sphere for predicates from the Kernel +// the following two different adaptors are necessary because the Predicates don not need _sphere +// compared to Predicates from Delaunay_sphere_traits + +// adaptor for calling the Predicate_ with the points projected on the sphere template < class K, class P, class Predicate_ > -class Traits_with_projection_adaptorKernel { +class Traits_with_projection_adaptor +{ public: - typedef Predicate_ Predicate; + typedef Predicate_ Predicate; - typedef typename P::Point_2 Point; - typedef typename K::Point_3 Base_point; - Traits_with_projection_adaptorKernel( double radius):_radius(radius){} - double _radius; - Base_point _sphere ; - - typedef typename Predicate::result_type result_type; - - - - result_type operator()(const Point& p0, const Point& p1) - {return Predicate()(project(p0), project(p1));} + typedef typename P::Point_2 Point; + typedef typename K::Point_2 Base_point; - - result_type operator()(const Point& p0, const Point& p1, const Point& p2) - {return Predicate()(project(p0), project(p1), project(p2));} + Traits_with_projection_adaptor(Base_point sphere, double radius) : _radius(radius), _sphere(sphere) { } - - result_type operator ()(const Point& p0, const Point& p1, const Point& p2, const Point& p3) - {return Predicate()(project(p0), project(p1), project(p2), project(p3));} + double _radius; + Base_point _sphere ; - - result_type operator()(const Point& p0, const Point& p1, const Point& p2, const Point& p3, const Point& p4) - {return Predicate()(project(p0), project(p1), project(p2), project(p3), project(p4));} + typedef typename Predicate::result_type result_type; + + result_type operator()(const Point& p0, const Point& p1) + { return Predicate(_sphere)(project(p0), project(p1)); } + + result_type operator()(const Point& p0, const Point& p1, const Point& p2) + { return Predicate(_sphere)(project(p0), project(p1), project(p2)); } + + result_type operator ()(const Point& p0, const Point& p1, const Point& p2, const Point& p3) + { return Predicate(_sphere)(project(p0), project(p1), project(p2), project(p3)); } + + result_type operator()(const Point& p0, const Point& p1, const Point& p2, const Point& p3, const Point& p4) + { return Predicate(_sphere)(project(p0), project(p1), project(p2), project(p3), project(p4)); } - private: - Base_point project (const Point& p){ - double scale = _radius*p._scale; - return Base_point(scale*p.x(), scale*p.y(), scale*p.z()); - } + Base_point project (const Point& p) + { + double scale = _radius * p._scale; + return Base_point(scale*p.x(), scale*p.y(), scale*p.z()); + } }; - - + +//adaptor for calling the Predicate_ with the points projected on the sphere for predicates from the Kernel +template < class K, class P, class Predicate_ > +class Traits_with_projection_adaptorKernel +{ +public: + typedef Predicate_ Predicate; + + typedef typename P::Point_2 Point; + typedef typename K::Point_3 Base_point; + + Traits_with_projection_adaptorKernel(double radius) : _radius(radius) { } + + double _radius; + Base_point _sphere; + + typedef typename Predicate::result_type result_type; + + result_type operator()(const Point& p0, const Point& p1) + { return Predicate()(project(p0), project(p1)); } + + result_type operator()(const Point& p0, const Point& p1, const Point& p2) + { return Predicate()(project(p0), project(p1), project(p2)); } + + result_type operator ()(const Point& p0, const Point& p1, const Point& p2, const Point& p3) + { return Predicate()(project(p0), project(p1), project(p2), project(p3)); } + + result_type operator()(const Point& p0, const Point& p1, const Point& p2, const Point& p3, const Point& p4) + { return Predicate()(project(p0), project(p1), project(p2), project(p3), project(p4)); } + +private: + Base_point project (const Point& p) + { + double scale = _radius * p._scale; + return Base_point(scale*p.x(), scale*p.y(), scale*p.z()); + } +}; + template < class R > class Projection_sphere_traits_3 -: public R + : public R { protected: - + public: double _radius; - typedef Projection_sphere_traits_3 Self; - typedef Delaunay_triangulation_sphere_traits_2 Base; - typedef typename Projected_point::Projected_point Point_2; - typedef typename R::Point_3 Base_point; + typedef Projection_sphere_traits_3 Self; + typedef Delaunay_triangulation_sphere_traits_2 Base; + typedef typename Projected_point::Projected_point Point_2; + typedef typename R::Point_3 Base_point; - typedef Point_2 result_type; - -typedef Traits_with_projection_adaptor - Power_test_2; - typedef Traits_with_projection_adaptor - Orientation_2; - typedef Traits_with_projection_adaptor - Coradial_sphere_2; - typedef Traits_with_projection_adaptor - Inside_cone_2; -typedef Traits_with_projection_adaptorKernel - Orientation_1; - typedef Traits_with_projection_adaptorKernel - Compute_squared_distance_2; -typedef Traits_with_projection_adaptorKernel - Compare_xyz_3; + typedef Point_2 result_type; - - typedef boost::false_type requires_test; - - void set_radius(double radius){ _radius = radius;} - -Projection_sphere_traits_3(const Base_point& sphere=Base_point(0,0,0), double radius = 1); + typedef Traits_with_projection_adaptor Power_test_2; + typedef Traits_with_projection_adaptor Orientation_2; + typedef Traits_with_projection_adaptor Coradial_sphere_2; + typedef Traits_with_projection_adaptor Inside_cone_2; + typedef Traits_with_projection_adaptorKernel Orientation_1; + typedef Traits_with_projection_adaptorKernel Compute_squared_distance_2; + typedef Traits_with_projection_adaptorKernel Compare_xyz_3; - - -Orientation_2 -orientation_2_object()const -{return Orientation_2(_sphere, _radius);} - -Orientation_1 -orientation_1_object() const -{return Orientation_1( _radius);} - -Power_test_2 -power_test_2_object() const -{ return Power_test_2(_sphere, _radius);} - -Coradial_sphere_2 -coradial_sphere_2_object() const -{return Coradial_sphere_2(_sphere, _radius);} - -Inside_cone_2 -inside_cone_2_object() const -{return Inside_cone_2(_sphere, _radius);} - -Compute_squared_distance_2 -compute_squared_distance_3_object() const -{ return Compute_squared_distance_2( _radius);} - -Compare_xyz_3 -compare_xyz_3_object()const - {return Compare_xyz_3(_radius);} + typedef boost::false_type requires_test; -struct Construct_projected_point_3 - : public std::unary_function -{ - const Base_point& sphere_center; + void set_radius(double radius) { _radius = radius; } -Point_2 operator()(const Base_point& pt) const - { return Point_2(pt, sphere_center); } + Projection_sphere_traits_3(const Base_point& sphere=Base_point(0,0,0), double radius = 1); -Construct_projected_point_3(const Base_point& sc) - :sphere_center(sc) {} -}; + Orientation_2 + orientation_2_object() const + { return Orientation_2(_sphere, _radius); } -Construct_projected_point_3 -construct_projected_point_3_object() const { - return Construct_projected_point_3(_sphere); -}; + Orientation_1 + orientation_1_object() const + { return Orientation_1(_radius); } + + Power_test_2 + power_test_2_object() const + { return Power_test_2(_sphere, _radius); } + + Coradial_sphere_2 + coradial_sphere_2_object() const + { return Coradial_sphere_2(_sphere, _radius); } + + Inside_cone_2 + inside_cone_2_object() const + { return Inside_cone_2(_sphere, _radius); } + + Compute_squared_distance_2 + compute_squared_distance_3_object() const + { return Compute_squared_distance_2(_radius); } + + Compare_xyz_3 + compare_xyz_3_object() const + { return Compare_xyz_3(_radius); } + + struct Construct_projected_point_3 + : public std::unary_function + { + const Base_point& sphere_center; + + Point_2 operator()(const Base_point& pt) const { return Point_2(pt, sphere_center); } + + Construct_projected_point_3(const Base_point& sc) : sphere_center(sc) { } + }; + + Construct_projected_point_3 + construct_projected_point_3_object() const + { return Construct_projected_point_3(_sphere); } protected : - Base_point _sphere; - - + Base_point _sphere; }; template < class R > Projection_sphere_traits_3 :: Projection_sphere_traits_3(const Base_point& sphere, double radius) -: _radius(radius), _sphere(sphere) -{} - - -} //namespace CGAL - -#endif - - + : _radius(radius), _sphere(sphere) +{ } +} // namespace CGAL +#endif // CGAL_PROJECTION_SPHERE_TRAITS_3_H diff --git a/Triangulation_on_sphere_2/include/CGAL/Triangulation_face_base_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Triangulation_face_base_sphere_2.h index 44dcb6a0cf6..0712c5be872 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Triangulation_face_base_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Triangulation_face_base_sphere_2.h @@ -1,9 +1,10 @@ -// Copyright (c) 1997 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). // All rights reserved. // -// This file is part of CGAL (www.cgal.org); you may redistribute it under -// the terms of the Q Public License version 1.0. -// See the file LICENSE.QPL distributed with CGAL. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. @@ -11,28 +12,23 @@ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // -// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.4-branch/Triangulation_2/include/CGAL/Triangulation_face_base_sphere_2.h $ -// $Id: Triangulation_face_base_sphere_2.h 28567 2006-02-16 14:30:13Z lsaboret $ -// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ // // Author(s) : Mariette Yvinec, Claudia Werner #ifndef CGAL_TRIANGULATION_FACE_BASE_SPHERE_2_H #define CGAL_TRIANGULATION_FACE_BASE_SPHERE_2_H -#include -#include #include -namespace CGAL { +namespace CGAL { template < typename Gt, typename Fb = Triangulation_ds_face_base_2<> > -class Triangulation_face_base_sphere_2 +class Triangulation_face_base_sphere_2 : public Fb { -protected: -bool _ghost; - public: typedef Gt Geom_traits; typedef typename Fb::Vertex_handle Vertex_handle; @@ -41,76 +37,48 @@ public: template < typename TDS2 > struct Rebind_TDS { typedef typename Fb::template Rebind_TDS::Other Fb2; - typedef Triangulation_face_base_sphere_2 Other; + typedef Triangulation_face_base_sphere_2 Other; }; -unsigned char _in_conflict_flag; + + unsigned char _in_conflict_flag; public: void set_in_conflict_flag(unsigned char f) { _in_conflict_flag = f; } unsigned char get_in_conflict_flag() const { return _in_conflict_flag; } + public: Triangulation_face_base_sphere_2() -: Fb(),_ghost(false) { - set_in_conflict_flag(0); -} - - Triangulation_face_base_sphere_2(Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2) -: Fb(v0,v1,v2),_ghost(false) { - set_in_conflict_flag(0); -} - - Triangulation_face_base_sphere_2(Vertex_handle v0, - Vertex_handle v1, - Vertex_handle v2, - Face_handle n0, - Face_handle n1, - Face_handle n2) - : Fb(v0,v1,v2,n0,n1,n2),_ghost(false) { + : Fb(), _ghost(false) + { set_in_conflict_flag(0); -} + } + + Triangulation_face_base_sphere_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2) + : Fb(v0, v1, v2), _ghost(false) + { + set_in_conflict_flag(0); + } + + Triangulation_face_base_sphere_2(Vertex_handle v0, + Vertex_handle v1, + Vertex_handle v2, + Face_handle n0, + Face_handle n1, + Face_handle n2) + : Fb(v0, v1, v2, n0, n1, n2), _ghost(false) + { + set_in_conflict_flag(0); + } - static int ccw(int i) {return Triangulation_cw_ccw_2::ccw(i);} - static int cw(int i) {return Triangulation_cw_ccw_2::cw(i);} const bool& is_ghost() const { return _ghost; } - bool& ghost() { return _ghost; } - -#ifndef CGAL_NO_DEPRECATED_CODE - Vertex_handle mirror_vertex(int i) const; - int mirror_index(int i) const; -#endif + bool& ghost() { return _ghost; } +protected: + bool _ghost; }; -#ifndef CGAL_NO_DEPRECATED_CODE -template < class Gt, class Fb > -inline -typename Triangulation_face_base_sphere_2::Vertex_handle -Triangulation_face_base_sphere_2:: -mirror_vertex(int i) const -{ - CGAL_triangulation_precondition ( this->neighbor(i) != Face_handle() - && this->dimension() >= 1); - //return neighbor(i)->vertex(neighbor(i)->index(this->handle())); - return this->neighbor(i)->vertex(mirror_index(i)); -} - -template < class Gt, class Fb > -inline int -Triangulation_face_base_sphere_2:: -mirror_index(int i) const -{ - // return the index of opposite vertex in neighbor(i); - CGAL_triangulation_precondition (this->neighbor(i) != Face_handle() && - this->dimension() >= 1); - if (this->dimension() == 1) { - return 1 - (this->neighbor(i)->index(this->vertex(1-i))); - } - return this->ccw( this->neighbor(i)->index(this->vertex(this->ccw(i)))); -} -#endif - -} //namespace CGAL +} // namespace CGAL #endif //CGAL_Triangulation_face_base_sphere_2_H diff --git a/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_2.h b/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_2.h index 082aa975025..36813fae6f1 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_2.h @@ -1,62 +1,74 @@ +// Copyright (c) 1997, 2012, 2019 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the Licenxse, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// Author(s) : Mariette Yvinec, Claudia Werner + #ifndef CGAL_TRIANGULATION_SPHERE_2_H #define CGAL_TRIANGULATION_SPHERE_2_H - -#include -#include -#include -#include -#include -#include #include #include #include - #include #include - #include #include #include #include - #include #include -#include + #include #include +#include +#include +#include +#include +#include +#include + // this class just provides some basic methods and can not be used independently. No insertion or remove implemented. namespace CGAL { template < class Gt, class Tds > class Triangulation_sphere_2; template < class Gt, class Tds > std::istream& operator>> - (std::istream& is, Triangulation_sphere_2 &tr); +(std::istream& is, Triangulation_sphere_2& tr); template < class Gt, class Tds > std::ostream& operator<< - (std::ostream& os, const Triangulation_sphere_2 &tr); - +(std::ostream& os, const Triangulation_sphere_2& tr); -template < class Gt, + +template < class Gt, class Tds = Triangulation_data_structure_2 < - Triangulation_vertex_base_2, - Triangulation_face_base_sphere_2 > > - + Triangulation_vertex_base_2, + Triangulation_face_base_sphere_2 > > - - class Triangulation_sphere_2 : public Triangulation_cw_ccw_2 { - friend std::istream& operator>> <> - (std::istream& is, Triangulation_sphere_2 &tr); - typedef Triangulation_sphere_2 Self; - + friend std::istream& operator>> <>(std::istream& is, Triangulation_sphere_2& tr); + typedef Triangulation_sphere_2 Self; public: typedef Tds Triangulation_data_structure; typedef Gt Geom_traits; - + typedef typename Geom_traits::Point_2 Point; typedef typename Geom_traits::Orientation_2 Orientation_2; typedef typename Geom_traits::Coradial_sphere_2 Coradial_sphere_2; @@ -68,382 +80,351 @@ public: typedef typename Tds::Vertex Vertex; typedef typename Tds::Face Face; typedef typename Tds::Edge Edge; - typedef typename Tds::Vertex_handle Vertex_handle; - typedef typename Tds::Face_handle Face_handle; - typedef typename Tds::Face_circulator Face_circulator; - typedef typename Tds::Vertex_circulator Vertex_circulator; - typedef typename Tds::Edge_circulator Edge_circulator; - typedef typename Tds::Face_iterator All_faces_iterator; - typedef typename Tds::Edge_iterator All_edges_iterator; - typedef typename Tds::Vertex_iterator All_vertices_iterator; + typedef typename Tds::Vertex_handle Vertex_handle; + typedef typename Tds::Face_handle Face_handle; + + typedef typename Tds::Vertex_circulator Vertex_circulator; + typedef typename Tds::Edge_circulator Edge_circulator; + typedef typename Tds::Face_circulator Face_circulator; + + typedef typename Tds::Vertex_iterator All_vertices_iterator; + typedef typename Tds::Edge_iterator All_edges_iterator; + typedef typename Tds::Face_iterator All_faces_iterator; + + // This class is used to generate the Solid*_iterators. + class Ghost_tester + { + const Triangulation_sphere_2 *t; - -// This class is used to generate the Solid*_iterators. -class Ghost_tester -{ - const Triangulation_sphere_2 *t; public: - Ghost_tester() {} - Ghost_tester(const Triangulation_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 { - //int dim = t->dimension(); - Face_handle f = eit->first; - bool edge1 = f->is_ghost(); - Face_handle f2 = f->neighbor(eit->second); - //bool edge2b = f2->is_ghost(); - bool edge2 = (f->neighbor(eit->second))->is_ghost(); - bool result = edge1&&edge2; - return !result; - } -}; - -class Contour_tester -{ - const Triangulation_sphere_2 *t; - public: - Contour_tester() {} - Contour_tester(const Triangulation_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; //Solid edges : both adjacent faces are solid -typedef Filter_iterator Contour_edges_iterator; //one solid and one ghost face adjacent to this face - - enum Locate_type {VERTEX=0, - EDGE, //1 - FACE, //2 - OUTSIDE_CONVEX_HULL, //3 - OUTSIDE_AFFINE_HULL,//4 - CONTOUR,//5 - NOT_ON_SPHERE, - TOO_CLOSE}; - - + Ghost_tester() { } + Ghost_tester(const Triangulation_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 + { + // int dim = t->dimension(); + Face_handle f = eit->first; + bool edge1 = f->is_ghost(); + Face_handle f2 = f->neighbor(eit->second); + // bool edge2b = f2->is_ghost(); + bool edge2 = (f->neighbor(eit->second))->is_ghost(); + bool result = edge1 && edge2; + return !result; + } + }; + + class Contour_tester + { + const Triangulation_sphere_2 *t; + + public: + Contour_tester() { } + Contour_tester(const Triangulation_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; //Solid edges : both adjacent faces are solid + typedef Filter_iterator Contour_edges_iterator; //one solid and one ghost face adjacent to this face + + enum Locate_type {VERTEX=0, + EDGE, //1 + FACE, //2 + OUTSIDE_CONVEX_HULL, //3 + OUTSIDE_AFFINE_HULL,//4 + CONTOUR,//5 + NOT_ON_SPHERE, + TOO_CLOSE}; protected: - - Gt _gt; + Gt _gt; Tds _tds; - Face_handle _ghost; //stores an arbitary ghost-face - double _minDistSquared; //minimal distance of two points to each other - double _minRadiusSquared;//minimal distance of a point from center of the sphere - double _maxRadiusSquared; //maximal distance of a point from center of the sphere - mutable Random rng; //used to decide how tostart the march_locate - - + Face_handle _ghost; // stores an arbitary ghost-face + double _minDistSquared; // minimal distance of two points to each other + double _minRadiusSquared; // minimal distance of a point from center of the sphere + double _maxRadiusSquared; // maximal distance of a point from center of the sphere + mutable Random rng; // used to decide how tostart the march_locate public: - // CONSTRUCTORS Triangulation_sphere_2(const Geom_traits& geom_traits=Geom_traits()); - Triangulation_sphere_2(const Point& sphere); - Triangulation_sphere_2(const Triangulation_sphere_2 &tr); - void clear(); - + Triangulation_sphere_2(const Point& sphere); + Triangulation_sphere_2(const Triangulation_sphere_2& tr); + void clear(); + private: - void init(double radius); - + void init(double radius); + public: - -//setting function for the radius of the sphere. Attention: the triangulation is cleared in this step! -void set_radius(double radius){ - clear(); - init(radius); -} + //setting function for the radius of the sphere. Attention: the triangulation is cleared in this step! + void set_radius(double radius) + { + clear(); + init(radius); + } //Assignement - Triangulation_sphere_2 &operator=(const Triangulation_sphere_2 &tr); + Triangulation_sphere_2& operator=(const Triangulation_sphere_2& tr); //Helping - void copy_triangulation(const Triangulation_sphere_2 &tr); - void swap(Triangulation_sphere_2 &tr); - + void copy_triangulation(const Triangulation_sphere_2& tr); + void swap(Triangulation_sphere_2& tr); + // CHECKING - bool is_valid(bool verbose = false, int level = 0) const; - double squared_distance(const Point& p, const Point& q)const; - - + bool is_valid(bool verbose = false, int level = 0) const; + double squared_distance(const Point& p, const Point& q) const; // TESTS bool is_edge(Vertex_handle va, Vertex_handle vb) const; - bool is_edge(Vertex_handle va, Vertex_handle vb, Face_handle& fr,int & i) const; + bool is_edge(Vertex_handle va, Vertex_handle vb, Face_handle& fr, int& i) const; bool is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3) const; bool is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3, Face_handle &fr) const; - - //ACCESS FUNCTION - const Geom_traits& geom_traits() const { return _gt;} - const Tds & tds() const { return _tds;} - Tds & tds() { return _tds;} - - - int dimension() const { return _tds.dimension();} - size_type number_of_vertices() const {return _tds.number_of_vertices();} -size_type number_of_faces() const{return _tds.number_of_faces();}//total number of faces (solid + ghost) - + + //ACCESS FUNCTION + const Geom_traits& geom_traits() const { return _gt; } + const Tds& tds() const { return _tds; } + Tds& tds() { return _tds; } + + int dimension() const { return _tds.dimension(); } + size_type number_of_vertices() const { return _tds.number_of_vertices(); } + size_type number_of_faces() const { return _tds.number_of_faces(); }//total number of faces (solid + ghost) + int number_of_ghost_faces(); - - - //-----------------------------------------------------------------LOCATION------------------------------------------------- - Face_handle march_locate_2D(Face_handle c, const Point& t,Locate_type& lt, int& li) const; + + //-----------------------------------------------------------------LOCATION----------------------- + Face_handle march_locate_2D(Face_handle c, const Point& t,Locate_type& lt, int& li) const; Face_handle march_locate_1D(const Point& t, Locate_type& lt, int& li) const ; Face_handle locate(const Point& p, Locate_type& lt, int& li, Face_handle start) const; - Face_handle locate(const Point &p, Face_handle start) const; - Face_handle locate_edge(const Point& p, Locate_type& lt, int& li, bool plane)const; - void test_distance( const Point& p, Face_handle f, Locate_type <, int &li)const; - bool is_too_close(const Point& p, const Point& q)const; - //------------------------------------------------------------------------PREDICATES---------------------------------------- + Face_handle locate(const Point& p, Face_handle start) const; + Face_handle locate_edge(const Point& p, Locate_type& lt, int& li, bool plane) const; + void test_distance(const Point& p, Face_handle f, Locate_type <, int& li) const; + bool is_too_close(const Point& p, const Point& q) const; + + //------------------------------------------------------------------------PREDICATES-------------- Orientation orientation(const Point& p, const Point& q, const Point& r) const; Orientation orientation(const Face_handle f) const; - Orientation orientation(const Face_handle f, const Point& p)const; - Orientation orientation(const Point&p, const Point& q, const Point& r, const Point &s) const; + Orientation orientation(const Face_handle f, const Point& p) const; + Orientation orientation(const Point&p, const Point& q, const Point& r, const Point& s) const; Comparison_result compare_xyz(const Point& p, const Point& q) const; bool equal (const Point& p, const Point& q) const; - Oriented_side oriented_side(Face_handle f, const Point &p) const; + Oriented_side oriented_side(Face_handle f, const Point& p) const; bool xy_equal(const Point& p, const Point& q) const; bool collinear_between(const Point& p, const Point& q, const Point& r) const; - //Orientation coplanar_orientation(const Point& p, const Point& q,const Point& r ) const; -Orientation coplanar_orientation(const Point& p, const Point& q,const Point& r, const Point& s ) const; + //Orientation coplanar_orientation(const Point& p, const Point& q, const Point& r) const; + Orientation coplanar_orientation(const Point& p, const Point& q, const Point& r, const Point& s) const; + //------------------------------------------------------------------DEBUG--------------------------------------------------- void show_all() const; void show_vertex(Vertex_handle vh) const; void show_face(Face_handle fh) const; //----------------------------------------------------------Creation--------------------------------------------------- - void make_hole(Vertex_handle v, std::list & hole); - Face_handle create_face(Face_handle f1, int i1,Face_handle f2, int i2, - Face_handle f3, int i3); - Face_handle create_face(Face_handle f1, int i1, Face_handle f2, int i2); - Face_handle create_face(); - Face_handle create_face(Face_handle f, int i, Vertex_handle v); - Face_handle create_face(Vertex_handle v1, Vertex_handle v2,Vertex_handle v3); - Face_handle create_face(Vertex_handle v1, Vertex_handle v2,Vertex_handle v3, - Face_handle f1, Face_handle f2, Face_handle f3); - Face_handle create_face(Face_handle); - void delete_face(Face_handle f); - void delete_vertex(Vertex_handle v); - -//-----------------------GEOMETRIC FEATURES AND CONSTRUCTION--------------------------- -Point circumcenter(Face_handle f) const; -Point circumcenter(const Point& p0, - const Point& p1, - const Point& p2) const; - - - - // IN/OUT + void make_hole(Vertex_handle v, std::list& hole); + Face_handle create_face(Face_handle f1, int i1, Face_handle f2, int i2, + Face_handle f3, int i3); + Face_handle create_face(Face_handle f1, int i1, Face_handle f2, int i2); + Face_handle create_face(); + Face_handle create_face(Face_handle f, int i, Vertex_handle v); + Face_handle create_face(Vertex_handle v1, Vertex_handle v2,Vertex_handle v3); + Face_handle create_face(Vertex_handle v1, Vertex_handle v2,Vertex_handle v3, + Face_handle f1, Face_handle f2, Face_handle f3); + Face_handle create_face(Face_handle); + void delete_face(Face_handle f); + void delete_vertex(Vertex_handle v); + + //-----------------------GEOMETRIC FEATURES AND CONSTRUCTION--------------------------- + Point circumcenter(Face_handle f) const; + Point circumcenter(const Point& p0, const Point& p1, const Point& p2) const; + + // IN/OUT Vertex_handle file_input(std::istream& is); void file_output(std::ostream& os) const; - - //--------------------------------------------------------------TRAVERSING : ITERATORS AND CIRCULATORS------------------------------------------- -All_faces_iterator all_faces_begin() const { - return _tds.faces_begin(); -} - -All_faces_iterator all_faces_end() const { - return _tds.faces_end(); -} - -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_end(), Ghost_tester(this), - all_edges_begin()); - } - -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_end(), Ghost_tester(this), - all_edges_begin()); -} - -Contour_edges_iterator contour_edges_end() const{ - return CGAL::filter_iterator (all_edges_end(), Contour_tester(this)); -} + //--------------------------------------------------------------TRAVERSING : ITERATORS AND CIRCULATORS------------------------------------------- + All_faces_iterator all_faces_begin() const { return _tds.faces_begin(); } + All_faces_iterator all_faces_end() const { return _tds.faces_end(); } -All_vertices_iterator vertices_begin() const{ - return _tds.vertices_begin(); -} + Solid_faces_iterator solid_faces_begin() const + { + if(dimension() < 2) + return solid_faces_end(); -All_vertices_iterator vertices_end() const { - return _tds.vertices_end(); -} - -All_edges_iterator all_edges_begin() const{ - return _tds.edges_begin(); -} - -All_edges_iterator all_edges_end() const{ - return _tds.edges_end(); -} - -Face_circulator incident_faces( Vertex_handle v, Face_handle f = Face_handle()) const{ - return _tds.incident_faces(v,f); -} - -Vertex_circulator incident_vertices(Vertex_handle v, Face_handle f = Face_handle()) const{ - return _tds.incident_vertices(v,f); -} - - -Edge_circulator incident_edges(Vertex_handle v, Face_handle f = Face_handle()) const{ - return _tds.incident_edges(v,f); -} - - -size_type degree(Vertex_handle v) const { - return _tds.degree(v); -} - -Vertex_handle mirror_vertex(Face_handle f, int i) const{ - return _tds.mirror_vertex(f,i); -} - -int mirror_index(Face_handle v, int i) const{ - return _tds.mirror_index(v,i); -} - -Edge mirror_edge(const Edge e) const -{ - return _tds.mirror_edge(e); -} - -/*---------------------------------------------------------------------TEMPLATE MEMBERS--------------------------------------*/ - public: - - template - void delete_faces(FaceIt face_begin, FaceIt face_end) - { - FaceIt fit=face_begin; - for(;fit!=face_end;++fit) - delete_face(*fit); - } - -//is_on_sphere test whether a given point lies close enough to the sphere. Whether a test is necessary or not is defined in the traits (requires test) -//additional test needed + 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_end(), Ghost_tester(this), all_edges_begin()); + } + + 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_end(), Ghost_tester(this), all_edges_begin()); + } + + 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(); } + All_vertices_iterator vertices_end() const { return _tds.vertices_end(); } + All_edges_iterator all_edges_begin() const { return _tds.edges_begin(); } + All_edges_iterator all_edges_end() const { return _tds.edges_end(); } + + Face_circulator incident_faces(Vertex_handle v, + Face_handle f = Face_handle()) const + { + return _tds.incident_faces(v, f); + } + + Vertex_circulator incident_vertices(Vertex_handle v, + Face_handle f = Face_handle()) const + { + return _tds.incident_vertices(v, f); + } + + Edge_circulator incident_edges(Vertex_handle v, + Face_handle f = Face_handle()) const + { + return _tds.incident_edges(v, f); + } + + size_type degree(Vertex_handle v) const { return _tds.degree(v); } + + Vertex_handle mirror_vertex(Face_handle f, int i) const { return _tds.mirror_vertex(f, i); } + int mirror_index(Face_handle v, int i) const { return _tds.mirror_index(v, i); } + Edge mirror_edge(const Edge e) const { return _tds.mirror_edge(e); } + + /*-----------------------TEMPLATE MEMBERS---------------------------*/ +public: + + template + void delete_faces(FaceIt face_begin, FaceIt face_end) + { + FaceIt fit = face_begin; + for(; fit!=face_end; ++fit) + delete_face(*fit); + } + + // is_on_sphere test whether a given point lies close enough to the sphere. Whether a test is necessary or not is defined in the traits (requires test) + // additional test needed private: -void -is_on_sphere(boost::true_type, const Point &p, Locate_type <) const { - double distance2 = pow(p.x(),2)+pow(p.y(),2)+pow(p.z(),2); - bool test = _minRadiusSquared empty function -void -is_on_sphere(boost::false_type, const Point &p, Locate_type <) const{ -} - + void is_on_sphere(boost::true_type, + const Point& p, + Locate_type <) const + { + double distance2 = pow(p.x(), 2) + pow(p.y(), 2) + pow(p.z(), 2); + bool test = _minRadiusSquared < distance2 && distance2 < _maxRadiusSquared; + if(!test) + lt = NOT_ON_SPHERE; + } - + // no test needed -> empty function + void is_on_sphere(boost::false_type, const Point& p, Locate_type <) const { } }; - + // CONSTRUCTORS - + template Triangulation_sphere_2:: -Triangulation_sphere_2(const Geom_traits& geom_traits) -: _gt(geom_traits), _tds() - {init(1);} - +Triangulation_sphere_2(const Geom_traits& geom_traits) + : _gt(geom_traits), _tds() +{ + init(1); +} + template Triangulation_sphere_2:: -Triangulation_sphere_2(const Point& sphere) -: _gt(sphere), _tds() - { init(1);} - - -//initializes the requiered data to proof the preconditons for the lemma about hidden vertices. By default radius ==1; +Triangulation_sphere_2(const Point& sphere) + : _gt(sphere), _tds() +{ + init(1); +} + +// initializes the requiered data to proof the preconditons for the lemma about hidden vertices. By default radius ==1; template void Triangulation_sphere_2:: -init(double radius){ - double minRadius = radius*(1-pow(2, -50)); - _minRadiusSquared = minRadius * minRadius; - double maxRadius = radius*(1+pow(2, -50)); - _maxRadiusSquared = maxRadius * maxRadius; - double minDist = radius*pow (2, -23); - _minDistSquared = minDist *minDist; - _gt.set_radius(radius); - +init(const double radius) +{ + const double minRadius = radius * (1 - pow(2, -50)); + _minRadiusSquared = minRadius * minRadius; + const double maxRadius = radius * (1 + pow(2, -50)); + _maxRadiusSquared = maxRadius * maxRadius; + const double minDist = radius * pow(2, -23); + _minDistSquared = minDist *minDist; + _gt.set_radius(radius); } - // copy constructor duplicates vertices and faces template Triangulation_sphere_2:: -Triangulation_sphere_2(const Triangulation_sphere_2 &tr) +Triangulation_sphere_2(const Triangulation_sphere_2 &tr) : _gt(tr._gt), _tds(tr._tds) - {init(_gt._radius);} +{ + init(_gt._radius); +} template void -Triangulation_sphere_2:: +Triangulation_sphere_2:: clear() { - _tds.clear(); - + _tds.clear(); } - - + template void -Triangulation_sphere_2:: +Triangulation_sphere_2:: copy_triangulation(const Triangulation_sphere_2 &tr) { _tds.clear(); _gt = tr._gt; _tds = tr._tds; - init(_gt._radius); + init(_gt._radius); } - //Assignement +// Assignement template -Triangulation_sphere_2 & +Triangulation_sphere_2& Triangulation_sphere_2:: operator=(const Triangulation_sphere_2 &tr) { @@ -453,20 +434,20 @@ operator=(const Triangulation_sphere_2 &tr) template void -Triangulation_sphere_2:: +Triangulation_sphere_2:: swap(Triangulation_sphere_2 &tr) { _tds.swap(tr._tds); Geom_traits t = geom_traits(); _gt = tr.geom_traits(); - tr._gt = t; + tr._gt = t; } //--------------------------CHECKING--------------------------- -//is_valid is used by in the instream method, Delaunay_tri... - //has its own is_valid +// is_valid is used by in the instream method, Delaunay_tri... +// has its own is_valid template bool @@ -474,56 +455,53 @@ Triangulation_sphere_2:: is_valid(bool verbose, int level) const { bool result = _tds.is_valid(verbose, level); - if (dimension() <= 0 || - (dimension()==1 && number_of_vertices() == 3 ) ) return result; - - if (dimension() == 1) { + if(dimension() <= 0 || (dimension() == 1 && number_of_vertices() == 3)) + return result; + + if(dimension() == 1) { All_vertices_iterator vit=vertices_begin(); - } - - else { //dimension() == 2 - - for(All_faces_iterator it=all_faces_begin(); - it!=all_faces_end(); it++) { + } + else //dimension() == 2 + { + 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()); - CGAL_triangulation_assertion( s == LEFT_TURN || it->is_ghost() ); - result = result && ( s == LEFT_TURN || it->is_ghost() ); + it->vertex(1)->point(), + it->vertex(2)->point()); + CGAL_triangulation_assertion(s == LEFT_TURN || it->is_ghost()); + result = result && (s == LEFT_TURN || it->is_ghost()); } // check number of faces. This cannot be done by the Tds // which does not know the number of components nor the genus - result = result && (number_of_faces() == (2*number_of_vertices()- 4) ); - - CGAL_triangulation_assertion( result); + result = result && (number_of_faces() == (2 * number_of_vertices() - 4)); + + CGAL_triangulation_assertion(result); } + return result; } - - - -//TESTS +// TESTS template inline bool Triangulation_sphere_2:: is_edge(Vertex_handle va, Vertex_handle vb) const { - return _tds.is_edge( va, vb); + return _tds.is_edge(va, vb); } template inline bool Triangulation_sphere_2:: -is_edge(Vertex_handle va, Vertex_handle vb, Face_handle& fr, int & i) const +is_edge(Vertex_handle va, Vertex_handle vb, Face_handle& fr, int& i) const { return _tds.is_edge(va, vb, fr, i); } template -inline bool +inline bool Triangulation_sphere_2:: is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3) const { @@ -531,448 +509,518 @@ is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3) const } template -inline bool +inline bool Triangulation_sphere_2:: -is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3,Face_handle &fr) const +is_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3, Face_handle &fr) const { return _tds.is_face(v1, v2, v3, fr); } //---------------------------------------------------------------------------/POINT LOCATION---------------------------------------// -// tests whether the two points p and q are too close according to the lemma about hidden vertices. +// tests whether the two points p and q are too close according to the lemma about hidden vertices. template inline bool Triangulation_sphere_2 :: -is_too_close(const Point& p, const Point& q)const{ - return squared_distance(p,q)<=_minDistSquared; +is_too_close(const Point& p, const Point& q) const +{ + return squared_distance(p, q)<=_minDistSquared; } -/*location for degenerated cases: locates the conflicting edge in a 1 dimensional triangulation. - This methode is used, when the new point is coplanar with the existing vertices. - bool plane defines whether the points are also coplanar with the center of the sphere (true) or not (false). +/* + * Location for degenerated cases: locates the conflicting edge in a 1 dimensional triangulation. + * This methode is used when the new point is coplanar with the existing vertices. + * bool plane defines whether the points are also coplanar with the center of the sphere (true) or not (false). */ - template typename Triangulation_sphere_2 ::Face_handle Triangulation_sphere_2:: -locate_edge(const Point& p, Locate_type& lt, int& li, bool plane)const +locate_edge(const Point& p, Locate_type& lt, int& li, bool plane) const { Face_handle loc; - if(plane){ - 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); - return (*eit).first; - } - - if (eit->first->is_ghost()) - loc = eit->first; - }//end for - - test_distance(p, loc, lt, li); - return loc; - } - - else {//not plane - All_edges_iterator eit; - Face_handle f; - 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); - if(orientation(v1->point(), v2->point(), p)==RIGHT_TURN){ - lt=EDGE; - li=2; - test_distance( p, (*eit).first, lt, li); - return (*eit).first; - } - }//end for - - test_distance(p, loc, lt, li); - return loc; - }//end else + + if(plane) + { + 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); + return (*eit).first; + } + } + + if(eit->first->is_ghost()) + loc = eit->first; + } + + test_distance(p, loc, lt, li); + return loc; + } + else // not plane + { + All_edges_iterator eit; + Face_handle f; + 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); + if(orientation(v1->point(), v2->point(), p) == RIGHT_TURN) + { + lt = EDGE; + li = 2; + test_distance(p, (*eit).first, lt, li); + return (*eit).first; + } + } + + test_distance(p, loc, lt, li); + return loc; + } } - + /* calls too_close for possible conflicts. If the point p is too close to an existing vertex, this vertex is returned. should be replaced by a nearest neighbor search. */ -template +template inline void Triangulation_sphere_2:: -test_distance( const Point& p, Face_handle f, Locate_type& lt, int& li)const{ -CGAL_precondition(dimension()>=-1); - switch (dimension()){ - case -1 : { - if(is_too_close(p, vertices_begin()->point())){ - lt = TOO_CLOSE; - li=0; - return; - } - } break; - - case 0: - case 1:{ - - All_vertices_iterator vi=vertices_begin(); - for(;vi!=vertices_end();vi++) - if(is_too_close(vi->point(),p)){ - lt = TOO_CLOSE; - li=1; - return; - } - - } break; - - case 2:{ - Vertex_handle v0 = f->vertex(0); - Vertex_handle v1= f->vertex(1); - Vertex_handle v2 = f->vertex(2); - - if(is_too_close(v0->point(),p)){ - lt = TOO_CLOSE; - li = 0; - return; - } - if(is_too_close(v1->point(),p)){ - lt = TOO_CLOSE; - li = 1; - return; - } - if(is_too_close(v2->point(),p)){ - lt = TOO_CLOSE; - li = 2; - return; - } - }break; +test_distance(const Point& p, Face_handle f, Locate_type& lt, int& li) const +{ + CGAL_precondition(dimension() >= -1); + + switch (dimension()) + { + case -1 : + { + if(is_too_close(p, vertices_begin()->point())) + { + lt = TOO_CLOSE; + li=0; + return; + } + } break; + + case 0: + case 1: + { + All_vertices_iterator vi=vertices_begin(); + for(; vi!=vertices_end(); ++vi) + { + if(is_too_close(vi->point(), p)) + { + lt = TOO_CLOSE; + li = 1; + return; + } + } + } break; + + case 2: + { + Vertex_handle v0 = f->vertex(0); + Vertex_handle v1= f->vertex(1); + Vertex_handle v2 = f->vertex(2); + + if(is_too_close(v0->point(), p)) + { + lt = TOO_CLOSE; + li = 0; + return; + } + + if(is_too_close(v1->point(), p)) + { + lt = TOO_CLOSE; + li = 1; + return; + } + + if(is_too_close(v2->point(), p)) + { + lt = TOO_CLOSE; + li = 2; + return; + } + } break; } -} - - -template +} + +template typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: march_locate_1D(const Point& p, Locate_type& lt, int& li) const -{ - Face_handle f =all_edges_begin()->first; - //check if p is coplanar with existing points - - //first three points of triangulation - Vertex_handle v1=f->vertex(0); - Vertex_handle v2=f->vertex(1); - Vertex_handle v3=f->neighbor(0)->vertex(1); - - Orientation orient = orientation(v1->point(), v2->point(), v3->point(),p); - if(orient !=ON_ORIENTED_BOUNDARY){ - lt = OUTSIDE_AFFINE_HULL; - li = 4; - test_distance(p, f, lt, li); - return f; - } - - //check if p is coradial with one existing point - All_vertices_iterator vi; - for( vi = vertices_begin(); vi != vertices_end(); vi++){ - if (xy_equal(vi->point(), p)){ - lt = VERTEX; - li = 1; - return f; - } - } - -//***find conflicting edge*** - lt=EDGE; - li = 2; - Orientation pqr = orientation(v1->point(),v2->point(),v3->point()); - if(pqr == ON_ORIENTED_BOUNDARY) - return locate_edge(p, lt, li, true); - else - return locate_edge(p, lt,li,false); -} - +{ + Face_handle f = all_edges_begin()->first; + // check if p is coplanar with existing points + + // first three points of triangulation + Vertex_handle v1 = f->vertex(0); + Vertex_handle v2 = f->vertex(1); + Vertex_handle v3 = f->neighbor(0)->vertex(1); + + Orientation orient = orientation(v1->point(), v2->point(), v3->point(), p); + if(orient !=ON_ORIENTED_BOUNDARY) + { + lt = OUTSIDE_AFFINE_HULL; + li = 4; + test_distance(p, f, lt, li); + return f; + } + + // check if p is coradial with one existing point + All_vertices_iterator vi; + for(vi=vertices_begin(); vi!=vertices_end(); ++vi) + { + if(xy_equal(vi->point(), p)) + { + lt = VERTEX; + li = 1; + return f; + } + } + + // ***find conflicting edge*** + lt = EDGE; + li = 2; + Orientation pqr = orientation(v1->point(), v2->point(), v3->point()); + if(pqr == ON_ORIENTED_BOUNDARY) + return locate_edge(p, lt, li, true); + else + return locate_edge(p, lt, li, false); +} - template typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: -march_locate_2D(Face_handle c,const Point& t,Locate_type& lt,int& li) const +march_locate_2D(Face_handle c, const Point& t,Locate_type& lt, int& li) const { - - CGAL_triangulation_assertion(!c->is_ghost()); - Face_handle prev = Face_handle(); - bool first=true; - while (1) { - if ( c->is_ghost() ) { - if(orientation(c, t)==ON_POSITIVE_SIDE){ //conflict with the corresponding face - lt = OUTSIDE_CONVEX_HULL; - li = 4; - test_distance(t,c, lt, li); - return c; - } - else {//one of the neighbour face has to be in conflict with - Face_handle next = Face_handle(); - for(int i=0; i<=2 ; i++){ - next=c->neighbor(i); - //Orientation orient =orientation(next, t); - if(orientation(next, t)==ON_POSITIVE_SIDE){ - lt = CONTOUR; - li = 4; - test_distance(t, next, lt, li); - return next; - } - } -CGAL_triangulation_precondition(false); - - } - }// end if ghost - - - - const Point & p0 = c->vertex( 0 )->point(); - const Point & p1 = c->vertex( 1 )->point(); - const Point & p2 = c->vertex( 2 )->point(); - - // Instead of testing c's edges in a random order we do the following + CGAL_triangulation_assertion(!c->is_ghost()); + + Face_handle prev = Face_handle(); + bool first = true; + + while(1) + { + if(c->is_ghost()) + { + if(orientation(c, t) == ON_POSITIVE_SIDE) //conflict with the corresponding face + { + lt = OUTSIDE_CONVEX_HULL; + li = 4; + test_distance(t, c, lt, li); + return c; + } + else //one of the neighbour face has to be in conflict with + { + Face_handle next = Face_handle(); + for(int i=0; i<=2 ; ++i) + { + next = c->neighbor(i); + // Orientation orient =orientation(next, t); + if(orientation(next, t) == ON_POSITIVE_SIDE) + { + lt = CONTOUR; + li = 4; + test_distance(t, next, lt, li); + return next; + } + } + + CGAL_triangulation_precondition(false); + } + } + + const Point& p0 = c->vertex(0)->point(); + const Point& p1 = c->vertex(1)->point(); + const Point& p2 = c->vertex(2)->point(); + + // Instead of testing c's edges in a random order we do the following // until we find a neighbor to go further: - // As we come from prev we do not have to check the edge leading to prev - // Now we flip a coin in order to decide if we start checking the - // edge before or the edge after the edge leading to prev + // As we come from 'prev', we do not have to check the edge leading to 'prev' + // Now, we flip a coin in order to decide if we start checking the + // edge before or the edge after the edge leading to 'prev' // We do loop unrolling in order to find out if this is faster. - // In the very beginning we do not have a prev, but for the first step + // In the very beginning we do not have a prev, but for the first step // we do not need randomness - int left_first =rng.template get_bits<1>(); + int left_first = rng.template get_bits<1>(); Orientation o0, o1, o2; - + /************************FIRST*************************/ - if(first){ + if(first) + { prev = c; first = false; - o0 = orientation(p0,p1,t);//classic march locate - if ( o0 == NEGATIVE ) { - c = c->neighbor( 2 ); - continue; + o0 = orientation(p0, p1, t);//classic march locate + if(o0 == NEGATIVE) + { + c = c->neighbor(2); + continue; } - o1 = orientation(p1,p2,t); - if ( o1 == NEGATIVE ) { - c = c->neighbor( 0 ); - continue; + + o1 = orientation(p1, p2, t); + if(o1 == NEGATIVE) + { + c = c->neighbor(0); + continue; } - o2 = orientation(p2,p0,t); - if ( o2 == NEGATIVE ) { - c = c->neighbor( 1 ); - continue; + + o2 = orientation(p2, p0, t); + if(o2 == NEGATIVE) + { + c = c->neighbor(1); + continue; } - } /***********************END FIRST*****************/ - + } //****LEFT****// + else if(left_first) + { + if(c->neighbor(0) == prev) + { + prev = c; + o0 = orientation(p0, p1, t); + if(o0 == NEGATIVE) + { + c = c->neighbor(2); + continue; + } - else if(left_first){ - if(c->neighbor(0) == prev){ - prev = c; - o0 = orientation(p0,p1,t); - if ( o0 == NEGATIVE ) { - c = c->neighbor( 2 ); - continue; - } - o2 = orientation(p2,p0,t); - if ( o2 == NEGATIVE ) { - c = c->neighbor( 1 ); - continue; - } - o1 = orientation(p1,p2,t); - } else if(c->neighbor(1) == prev){ - prev = c; - o1 = orientation(p1,p2,t); - if ( o1 == NEGATIVE ) { - c = c->neighbor( 0 ); - continue; - } - o0 = orientation(p0,p1,t); - if ( o0 == NEGATIVE ) { - c = c->neighbor( 2 ); - continue; - } - o2 = orientation(p2,p0,t); - } else { - prev = c; - o2 = orientation(p2,p0,t); - if ( o2 == NEGATIVE ) { - c = c->neighbor( 1 ); - continue; - } - o1 = orientation(p1,p2,t); - if ( o1 == NEGATIVE ) { - c = c->neighbor( 0 ); - continue; - } - o0 = orientation(p0,p1,t); + o2 = orientation(p2, p0, t); + if(o2 == NEGATIVE) + { + c = c->neighbor(1); + continue; + } + o1 = orientation(p1, p2, t); + } + else if(c->neighbor(1) == prev) + { + prev = c; + o1 = orientation(p1, p2, t); + if(o1 == NEGATIVE) + { + c = c->neighbor(0); + continue; + } + + o0 = orientation(p0, p1, t); + if(o0 == NEGATIVE) + { + c = c->neighbor(2); + continue; + } + + o2 = orientation(p2, p0, t); + } + else + { + prev = c; + o2 = orientation(p2, p0, t); + if(o2 == NEGATIVE) + { + c = c->neighbor(1); + continue; + } + + o1 = orientation(p1, p2, t); + if(o1 == NEGATIVE) + { + c = c->neighbor(0); + continue; + } + + o0 = orientation(p0, p1, t); } } - - else { - if(c->neighbor(0) == prev){ - prev = c; - o2 = orientation(p2,p0,t); - if ( o2 == NEGATIVE ) { - c = c->neighbor( 1 ); - continue; - } - o0 = orientation(p0,p1,t); - if ( o0 == NEGATIVE ) { - c = c->neighbor( 2 ); - continue; - } - o1 = orientation(p1,p2,t); - } else if(c->neighbor(1) == prev){ - prev = c; - o0 = orientation(p0,p1,t); - if ( o0 == NEGATIVE ) { - c = c->neighbor( 2 ); - continue; - } - o1 = orientation(p1,p2,t); - if ( o1 == NEGATIVE ) { - c = c->neighbor( 0 ); - continue; - } - o2 = orientation(p2,p0,t); - } else { - prev = c; - o1 = orientation(p1,p2,t); - if ( o1 == NEGATIVE ) { - c = c->neighbor( 0 ); - continue; - } - o2 = orientation(p2,p0,t); - if ( o2 == NEGATIVE ) { - c = c->neighbor( 1 ); - continue; - } - o0 = orientation(p0,p1,t); + else + { + if(c->neighbor(0) == prev) + { + prev = c; + o2 = orientation(p2, p0, t); + if(o2 == NEGATIVE) + { + c = c->neighbor(1); + continue; + } + + o0 = orientation(p0, p1, t); + if(o0 == NEGATIVE) + { + c = c->neighbor(2); + continue; + } + o1 = orientation(p1, p2, t); + } + else if(c->neighbor(1) == prev) + { + prev = c; + o0 = orientation(p0, p1, t); + if(o0 == NEGATIVE) + { + c = c->neighbor(2); + continue; + } + + o1 = orientation(p1, p2, t); + if(o1 == NEGATIVE) + { + c = c->neighbor(0); + continue; + } + + o2 = orientation(p2, p0, t); + } + else + { + prev = c; + o1 = orientation(p1, p2, t); + if(o1 == NEGATIVE) + { + c = c->neighbor(0); + continue; + } + + o2 = orientation(p2, p0, t); + if(o2 == NEGATIVE) + { + c = c->neighbor(1); + continue; + } + + o0 = orientation(p0, p1, t); } } - - + //********FACE LOCATED************/ + int sum = (o0 == COLLINEAR) + (o1 == COLLINEAR) + (o2 == COLLINEAR); - int sum = ( o0 == COLLINEAR ) - + ( o1 == COLLINEAR ) - + ( o2 == COLLINEAR ); - - switch (sum) { - case 0: - case -1: - case -2:{ - lt = FACE; - li = 4; - break;} - case 1:{ - lt = EDGE; - li = ( o0 == COLLINEAR ) ? 2 : - ( o1 == COLLINEAR ) ? 0 : 1; - break; - } - case 2: + switch (sum) + { + case 0: + case -1: + case -2: { - lt = VERTEX; - li = ( o0 != COLLINEAR ) ? 2 : - ( o1 != COLLINEAR ) ? 0 : - 1; - break; + lt = FACE; + li = 4; + break; } - case 3: + case 1: { - lt=FACE; - li=4; + lt = EDGE; + li = (o0 == COLLINEAR) ? 2 : (o1 == COLLINEAR) ? 0 : 1; + break; + } + case 2: + { + lt = VERTEX; + li = (o0 != COLLINEAR) ? 2 : (o1 != COLLINEAR) ? 0 : 1; + break; + } + case 3: + { + lt=FACE; + li=4; } } - test_distance(t,c,lt,li); - return c; - + + test_distance(t, c, lt, li); + return c; } -} - +} + template typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: -locate(const Point& p,Locate_type& lt,int& li, Face_handle start) const +locate(const Point& p,Locate_type& lt, int& li, Face_handle start) const { - is_on_sphere( typename Gt::requires_test(), p, lt); - - if(lt == NOT_ON_SPHERE) - return Face_handle(); - - switch (dimension()){ - case-2 : { //empty triangulation + is_on_sphere(typename Gt::requires_test(), p, lt); + + if(lt == NOT_ON_SPHERE) + return Face_handle(); + + switch (dimension()) + { + case -2 : // empty triangulation + { lt = OUTSIDE_AFFINE_HULL; li = 4; // li should not be used in this case return start; } - - case -1: { //1 vertex - Point q=vertices_begin()->point(); - if(xy_equal(q,p)){ - lt=VERTEX; - li=0; - } else{ - lt=OUTSIDE_AFFINE_HULL; - li=4; - test_distance(p, all_faces_begin(), lt, li); + case -1 : // 1 vertex + { + Point q=vertices_begin()->point(); + if(xy_equal(q, p)) + { + lt = VERTEX; + li = 0; + } + else + { + lt = OUTSIDE_AFFINE_HULL; + li = 4; + test_distance(p, all_faces_begin(), lt, li); + } + // test_distance(p, all_faces_begin(), lt, li); + return Face_handle(); + // return start; } - //test_distance(p, all_faces_begin(), lt, li); - return Face_handle(); - //return start; - } - - case 0: { - Vertex_handle v=vertices_begin(); - Face_handle f=v->face(); - if(xy_equal(p,v->point())){ - lt=VERTEX; - li=0; - return f; - }else if(xy_equal(p,f->neighbor(0)->vertex(0)->point())){ - lt=VERTEX; - li=0; - return f->neighbor(0); - }else{ - lt=OUTSIDE_AFFINE_HULL; - li=4; + case 0 : + { + Vertex_handle v = vertices_begin(); + Face_handle f = v->face(); + if(xy_equal(p, v->point())) + { + lt=VERTEX; + li=0; + return f; + } + else if(xy_equal(p, f->neighbor(0)->vertex(0)->point())) + { + lt = VERTEX; + li = 0; + return f->neighbor(0); + } + else + { + lt = OUTSIDE_AFFINE_HULL; + li = 4; + } + + test_distance(p, f, lt, li); + return Face_handle(); + } + case 1 : + { + return march_locate_1D(p, lt, li); } - test_distance(p, f, lt, li); - return Face_handle(); } - - case 1:{ - return march_locate_1D(p, lt, li); - } + + if(start == Face_handle()) + start = all_faces_begin(); + + if(start->is_ghost()) + { + for(All_faces_iterator it = this->_tds.face_iterator_base_begin(); it !=all_faces_end(); it++) + { + if(!it->is_ghost()) + { + start = it; + break; + } + } } - - if(start==Face_handle()){ - start=all_faces_begin(); - } - - if(start->is_ghost()){ - for (All_faces_iterator it = this->_tds.face_iterator_base_begin(); it !=all_faces_end(); it++) { - if(!it->is_ghost()){ - start = it; - break; - } - } - } - -#if ( ! defined(CGAL_ZIG_ZAG_WALK)) && ( ! defined(CGAL_LFC_WALK)) -#define CGAL_ZIG_ZAG_WALK + +#if(! defined(CGAL_ZIG_ZAG_WALK)) && (! defined(CGAL_LFC_WALK)) + #define CGAL_ZIG_ZAG_WALK #endif #ifdef CGAL_ZIG_ZAG_WALK Face_handle res1; - res1 = march_locate_2D(start, p, lt, li); - - - + res1 = march_locate_2D(start, p, lt, li); #endif #ifdef CGAL_LFC_WALK @@ -982,10 +1030,7 @@ locate(const Point& p,Locate_type& lt,int& li, Face_handle start) const #endif #if defined(CGAL_ZIG_ZAG_WALK) && defined(CGAL_LFC_WALK) - compare_walks(p, - res1, res2, - lt, lt2, - li, li2); + compare_walks(p, res1, res2, lt, lt2, li, li2); #endif #ifdef CGAL_ZIG_ZAG_WALK @@ -997,13 +1042,12 @@ locate(const Point& p,Locate_type& lt,int& li, Face_handle start) const li = li2; return res2; #endif - } template typename Triangulation_sphere_2:: Face_handle Triangulation_sphere_2:: -locate(const Point &p, +locate(const Point& p, Face_handle start) const { Locate_type lt; @@ -1011,80 +1055,74 @@ locate(const Point &p, return locate(p, lt, li, start); } - - -//------------------------------------------------------------------------------PREDICATES----------------------------------------------------------------- +//---------------------- PREDICATES ------------------------------- template Comparison_result Triangulation_sphere_2< Gt, Tds>:: -compare_xyz(const Point &p, const Point &q) const +compare_xyz(const Point& p, const Point& q) const { - return geom_traits().compare_xyz_3_object()(p, q); + return geom_traits().compare_xyz_3_object()(p, q); } - -template +template bool Triangulation_sphere_2:: -equal(const Point &p, const Point &q) const +equal(const Point& p, const Point& q) const { - return compare_xyz(p, q) == EQUAL; -} - - -template -inline -Orientation -Triangulation_sphere_2:: -coplanar_orientation(const Point& p, const Point& q,const Point& r, const Point &s ) const -{ - return geom_traits().orientation_1_object()(p,q,r,s); -} - - -template -inline -Orientation -Triangulation_sphere_2:: -orientation(const Point& p, const Point& q,const Point& r ) const -{ - return geom_traits().orientation_2_object()(p,q,r); + return compare_xyz(p, q) == EQUAL; } template inline Orientation Triangulation_sphere_2:: -orientation(const Face_handle fh,const Point& r ) const +coplanar_orientation(const Point& p, const Point& q, const Point& r, const Point& s) const { - return orientation(fh->vertex(0)->point(), fh->vertex(1)->point(), fh->vertex(2)->point(),r); -} - + return geom_traits().orientation_1_object()(p, q, r, s); +} + +template +inline +Orientation +Triangulation_sphere_2:: +orientation(const Point& p, const Point& q, const Point& r) const +{ + return geom_traits().orientation_2_object()(p, q, r); +} + +template +inline +Orientation +Triangulation_sphere_2:: +orientation(const Face_handle fh, const Point& r) const +{ + return orientation(fh->vertex(0)->point(), fh->vertex(1)->point(), fh->vertex(2)->point(), r); +} template Orientation Triangulation_sphere_2:: orientation(const Face_handle f) const { - return orientation(f->vertex(0)->point(),f->vertex(1)->point(),f->vertex(2)->point()); + return orientation(f->vertex(0)->point(), f->vertex(1)->point(), f->vertex(2)->point()); } template Orientation Triangulation_sphere_2:: -orientation(const Point&p, const Point &q, const Point &r, const Point & s)const +orientation(const Point&p, const Point& q, const Point& r, const Point& s) const { - return geom_traits().orientation_2_object()(p,q,r,s); + return geom_traits().orientation_2_object()(p, q, r, s); } - -//returns true if p,q, and O (center of the sphere) are aligned and if p (q) is located in the segment Oq (Op) + +// returns true if p, q, and O (center of the sphere) are aligned and if p (q) is located in the segment Oq (Op) template bool Triangulation_sphere_2:: xy_equal(const Point& p, const Point& q) const { - return geom_traits().coradial_sphere_2_object()(p,q); + return geom_traits().coradial_sphere_2_object()(p, q); } // return true if r lies inside the cone defined by trait.sphere, p and q @@ -1092,8 +1130,8 @@ template bool Triangulation_sphere_2:: collinear_between(const Point& p, const Point& q, const Point& r) const -{ - return geom_traits().inside_cone_2_object()(p,q,r); +{ + return geom_traits().inside_cone_2_object()(p, q, r); } //------------------------------------------------------------------------------DEBUG------------------------------------------------- @@ -1102,55 +1140,62 @@ void Triangulation_sphere_2:: show_all() const { - //Triangulation_2::show_all(); - std::cerr<< "AFFICHE TOUTE LA TRIANGULATION :"< "<< this; - std::cerr << " dimension " << dimension() << std::endl; + //Triangulation_2::show_all(); + std::cerr << "AFFICHE TOUTE LA TRIANGULATION :" << std::endl; + std::cerr << std::endl<< "====> " << this; + std::cerr << " dimension " << dimension() << std::endl; std::cerr << "nb of vertices " << number_of_vertices() << std::endl; - - if (dimension() < 1) return; - if(dimension() == 1) { - std::cerr<<" all edges dim 1 "<first); - std::cerr<<" ------------ " <first); + std::cerr << " ------------ " << std::endl; } + return; } - - std::cerr<<" faces "<1) { - std::cerr << "affichage des sommets de la triangulation" - < 1) + { + std::cerr << "affichage des sommets de la triangulation" << std::endl; All_vertices_iterator vi; - for( vi = vertices_begin(); vi != vertices_end(); vi++){ + for(vi=vertices_begin(); vi!=vertices_end(); ++vi) + { show_vertex(vi); - std::cerr << " / face associee : " - << (void*)(&(*(vi->face())))<< std::endl;; - } - std::cerr<face()))) << std::endl;; + } + + std::cerr << std::endl; } return; } - -//returns the number of ghost_faces + +// returns the number of ghost_faces template int Triangulation_sphere_2:: -number_of_ghost_faces() +number_of_ghost_faces() { - int nb=0; - for(All_faces_iterator it=all_faces_begin();it!=all_faces_end();++it) + int nb = 0; + for(All_faces_iterator it=all_faces_begin(); it!=all_faces_end(); ++it) if(it->is_ghost()) - nb++; + ++nb; + return nb; } @@ -1159,7 +1204,6 @@ void Triangulation_sphere_2:: show_vertex(Vertex_handle vh) const { - std::cerr << vh->point() << "\t"; return; } @@ -1169,73 +1213,69 @@ void Triangulation_sphere_2:: show_face(Face_handle fh) const { - std::cerr << "face : "<<(void*)&(*fh)<<" => "<is_ghost()) std::cerr << "ghost "<dimension(); - switch(i){ - case 0: - std::cerr <<"point :" ; show_vertex(fh->vertex(0)); - std::cerr <<" / voisin " << &(*(fh->neighbor(0))); - std::cerr <<"[" ; show_vertex(fh->neighbor(0)->vertex(0)); - std::cerr <<"]" << std::endl; - break; - case 1: - std::cerr <<"point :" ; show_vertex(fh->vertex(0)); - std::cerr <<" / voisin " << &(*(fh->neighbor(0))); - std::cerr <<"[" ; show_vertex(fh->neighbor(0)->vertex(0)); - std::cerr <<"/" ; show_vertex(fh->neighbor(0)->vertex(1)); - std::cerr <<"]" < " << std::endl; + if(fh->is_ghost()) std::cerr << "ghost " << std::endl; - std::cerr <<"point :" ; show_vertex(fh->vertex(1)); - std::cerr <<" / voisin " << &(*(fh->neighbor(1))); - std::cerr <<"[" ; show_vertex(fh->neighbor(1)->vertex(0)); - std::cerr <<"/" ; show_vertex(fh->neighbor(1)->vertex(1)); - std::cerr <<"]" <vertex(0)); - std::cerr <<" / voisin " << &(*(fh->neighbor(0))); - std::cerr <<"[" ; show_vertex(fh->neighbor(0)->vertex(0)); - std::cerr <<"/" ; show_vertex(fh->neighbor(0)->vertex(1)); - std::cerr <<"/" ; show_vertex(fh->neighbor(0)->vertex(2)); - std::cerr <<"]" <dimension(); + switch(i) + { + case 0: + std::cerr << "point :" ; show_vertex(fh->vertex(0)); + std::cerr << " / voisin " << &(*(fh->neighbor(0))); + std::cerr << "[" ; show_vertex(fh->neighbor(0)->vertex(0)); + std::cerr << "]" << std::endl; + break; - std::cerr <<"point :" ; show_vertex(fh->vertex(1)); - std::cerr <<" / voisin " << &(*(fh->neighbor(1))); - std::cerr <<"[" ; show_vertex(fh->neighbor(1)->vertex(0)); - std::cerr <<"/" ; show_vertex(fh->neighbor(1)->vertex(1)); - std::cerr <<"/" ; show_vertex(fh->neighbor(1)->vertex(2)); - std::cerr <<"]" <vertex(0)); + std::cerr << " / voisin " << &(*(fh->neighbor(0))); + std::cerr << "[" ; show_vertex(fh->neighbor(0)->vertex(0)); + std::cerr << "/" ; show_vertex(fh->neighbor(0)->vertex(1)); + std::cerr << "]" << std::endl; - std::cerr <<"point :" ; show_vertex(fh->vertex(2)); - std::cerr <<" / voisin " << &(*(fh->neighbor(2))); - std::cerr <<"[" ; show_vertex(fh->neighbor(2)->vertex(0)); - std::cerr <<"/" ; show_vertex(fh->neighbor(2)->vertex(1)); - std::cerr <<"/" ; show_vertex(fh->neighbor(2)->vertex(2)); - std::cerr <<"]" <vertex(1)); + std::cerr << " / voisin " << &(*(fh->neighbor(1))); + std::cerr << "[" ; show_vertex(fh->neighbor(1)->vertex(0)); + std::cerr << "/" ; show_vertex(fh->neighbor(1)->vertex(1)); + std::cerr << "]" << std::endl; + break; + + case 2: + std::cerr << "point :" ; show_vertex(fh->vertex(0)); + std::cerr << " / voisin " << &(*(fh->neighbor(0))); + std::cerr << "[" ; show_vertex(fh->neighbor(0)->vertex(0)); + std::cerr << "/" ; show_vertex(fh->neighbor(0)->vertex(1)); + std::cerr << "/" ; show_vertex(fh->neighbor(0)->vertex(2)); + std::cerr << "]" << std::endl; + + std::cerr << "point :" ; show_vertex(fh->vertex(1)); + std::cerr << " / voisin " << &(*(fh->neighbor(1))); + std::cerr << "[" ; show_vertex(fh->neighbor(1)->vertex(0)); + std::cerr << "/" ; show_vertex(fh->neighbor(1)->vertex(1)); + std::cerr << "/" ; show_vertex(fh->neighbor(1)->vertex(2)); + std::cerr << "]" << std::endl; + + std::cerr << "point :" ; show_vertex(fh->vertex(2)); + std::cerr << " / voisin " << &(*(fh->neighbor(2))); + std::cerr << "[" ; show_vertex(fh->neighbor(2)->vertex(0)); + std::cerr << "/" ; show_vertex(fh->neighbor(2)->vertex(1)); + std::cerr << "/" ; show_vertex(fh->neighbor(2)->vertex(2)); + std::cerr << "]" << std::endl; + break; } - return; - - - - - } - - /*---------------------------------------------------------------------PUBLIC REMOVE-------------------------------------*/ +/*----------------------PUBLIC REMOVE---------------------------*/ template void Triangulation_sphere_2:: -make_hole ( Vertex_handle v, std::list & hole) -{ - return this->_tds.make_hole(v, hole); +make_hole (Vertex_handle v, std::list& hole) +{ + return this->_tds.make_hole(v, hole); } - -template + +template inline void Triangulation_sphere_2:: @@ -1244,7 +1284,7 @@ delete_face(Face_handle f) _tds.delete_face(f); } -template +template inline void Triangulation_sphere_2:: @@ -1253,29 +1293,28 @@ delete_vertex(Vertex_handle v) _tds.delete_vertex(v); } -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: create_face(Face_handle f1, int i1, - Face_handle f2, int i2, - Face_handle f3, int i3) + Face_handle f2, int i2, + Face_handle f3, int i3) { return _tds.create_face(f1, i1, f2, i2, f3, i3); } - -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: create_face(Face_handle f1, int i1, - Face_handle f2, int i2) + Face_handle f2, int i2) { return _tds.create_face(f1, i1, f2, i2); -} +} -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: @@ -1284,7 +1323,7 @@ create_face() return _tds.create_face(); } -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: @@ -1293,7 +1332,7 @@ create_face(Face_handle f, int i, Vertex_handle v) return _tds.create_face(f, i, v); } -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: @@ -1302,17 +1341,17 @@ create_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3) return _tds.create_face(v1, v2, v3); } -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: create_face(Vertex_handle v1, Vertex_handle v2, Vertex_handle v3, - Face_handle f1, Face_handle f2, Face_handle f3) + Face_handle f1, Face_handle f2, Face_handle f3) { return _tds.create_face(v1, v2, v3, f1, f2, f3); } -template +template inline typename Triangulation_sphere_2::Face_handle Triangulation_sphere_2:: @@ -1320,39 +1359,36 @@ create_face(Face_handle fh) { return _tds.create_face(fh); } - -//----------------CONSTRUCTION----------------------------------- - +// ---------------- CONSTRUCTION ------------------------ template inline typename Triangulation_sphere_2::Point Triangulation_sphere_2:: -circumcenter (const Point& p0, const Point& p1, const Point& p2) const +circumcenter (const Point& p0, const Point& p1, const Point& p2) const { - return - geom_traits().construct_circumcenter_2_object()(p0,p1,p2); + return geom_traits().construct_circumcenter_2_object()(p0, p1, p2); } - - + template typename Triangulation_sphere_2::Point Triangulation_sphere_2:: -circumcenter(Face_handle f) const +circumcenter(Face_handle f) const { - return circumcenter((f->vertex(0))->point(), - (f->vertex(1))->point(), - (f->vertex(2))->point()); + return circumcenter((f->vertex(0))->point(), + (f->vertex(1))->point(), + (f->vertex(2))->point()); } - + template double Triangulation_sphere_2 :: -squared_distance(const Point& p, const Point& q)const -{return geom_traits().compute_squared_distance_3_object()(p,q);} - +squared_distance(const Point& p, const Point& q) const +{ + return geom_traits().compute_squared_distance_3_object()(p, q); +} -//----------------------------------------------------------------I/O----------------------------------------------------------------// +// ---------------------------------I/O--------------------------- // template void @@ -1374,24 +1410,21 @@ file_input(std::istream& is) template std::ostream& -operator<<(std::ostream& os, const Triangulation_sphere_2 &tr) +operator<< (std::ostream& os, const Triangulation_sphere_2& tr) { tr.file_output(os); return os ; } - template < class Gt, class Tds > std::istream& -operator>>(std::istream& is, Triangulation_sphere_2 &tr) +operator>>(std::istream& is, Triangulation_sphere_2& tr) { tr.file_input(is); CGAL_triangulation_assertion(tr.is_valid()); return is; } - -} //namespace CGAL - + +} // namespace CGAL #endif //CGAL_TRIANGULATION_ON_SPHERE_2_H - diff --git a/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_line_face_circulator_2.h b/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_line_face_circulator_2.h index 6759192cddf..04ec164d482 100644 --- a/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_line_face_circulator_2.h +++ b/Triangulation_on_sphere_2/include/CGAL/Triangulation_sphere_line_face_circulator_2.h @@ -1,4 +1,4 @@ -// Copyright (c) 1997 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997, 2O12, 2019 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). @@ -14,7 +14,7 @@ // // $URL$ // $Id$ -// +// SPDX-License-Identifier: GPL-3.0+ // // Author(s) : Claudia Werner, Mariette Yvinec @@ -23,344 +23,346 @@ namespace CGAL{ template class Triangulation_sphere_line_face_circulator_2 - :public Bidirectional_circulator_base, - public Triangulation_cw_ccw_2 + : public Bidirectional_circulator_base< + typename Triangulation_::Triangulation_data_structure::Face, + std::size_t>, + public Triangulation_cw_ccw_2 { public: - typedef Triangulation_sphere_line_face_circulator_2 Line_face_circulator; - typedef Triangulation_ Triangulation; - typedef typename Triangulation::Geom_traits Gt; - typedef typename Triangulation_::Triangulation_data_structure Tds; - typedef typename Tds::Vertex Vertex; - typedef typename Tds::Face Face; - typedef typename Tds::Edge Edge; - typedef typename Tds::Vertex_handle Vertex_handle; - typedef typename Tds::Face_handle Face_handle; - typedef typename Tds::Face_circulator Face_circulator; - - typedef typename Gt::Point_2 Point; - typedef typename Triangulation::Locate_type Locate_type; - - - enum State {undefined = -1, - vertex_vertex, - vertex_edge, - edge_vertex, - edge_edge}; - + typedef Triangulation_sphere_line_face_circulator_2 Line_face_circulator; + typedef Triangulation_ Triangulation; + typedef typename Triangulation::Geom_traits Gt; + typedef typename Triangulation_::Triangulation_data_structure Tds; + + typedef typename Tds::Vertex Vertex; + typedef typename Tds::Face Face; + typedef typename Tds::Edge Edge; + typedef typename Tds::Vertex_handle Vertex_handle; + typedef typename Tds::Face_handle Face_handle; + typedef typename Tds::Face_circulator Face_circulator; + + typedef typename Gt::Point_2 Point; + typedef typename Triangulation::Locate_type Locate_type; + + enum State {undefined = -1, + vertex_vertex, + vertex_edge, + edge_vertex, + edge_edge}; + private: - Face_handle pos; - const Triangulation* _tr; - State s; - int i; - Point p, q; - + Face_handle pos; + const Triangulation* _tr; + State s; + int i; + Point p, q; + public: - Triangulation_sphere_line_face_circulator_2() + Triangulation_sphere_line_face_circulator_2() : pos(), _tr(NULL), s(undefined), i(-1) - {} - - Triangulation_sphere_line_face_circulator_2(Vertex_handle v, - const Triangulation* tr, - const Point& dir); - - - Line_face_circulator& operator++() ; - Line_face_circulator& operator--() ; - Line_face_circulator operator++(int); - Line_face_circulator operator--(int); - Face* operator->() {return &*pos;} - Face& operator*() { return *pos;} - Face_handle handle() {return pos;} - operator const Face_handle() const {return pos;} - bool operator==(const Line_face_circulator& lfc) const; - bool operator!=(const Line_face_circulator& lfc) const; - - bool operator==(const Face_handle& fh) const { return fh == pos; } - bool operator!=(const Face_handle& fh) const { return fh != pos; } - - bool operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const; - bool operator!=(Nullptr_t n) const; - bool is_empty() const; - bool locate(const Point& t, Locate_type <, int &li); - - //private: - Triangulation_sphere_line_face_circulator_2(const Face_handle& face, - int index, - State state, - const Triangulation * t, - const Point& pp, - const Point& qq); + { } + + Triangulation_sphere_line_face_circulator_2(Vertex_handle v, + const Triangulation* tr, + const Point& dir); + + Line_face_circulator& operator++() ; + Line_face_circulator& operator--() ; + Line_face_circulator operator++(int); + Line_face_circulator operator--(int); + Face* operator->() { return &*pos; } + Face& operator*() { return *pos; } + Face_handle handle() { return pos; } + + operator const Face_handle() const { return pos; } + bool operator==(const Line_face_circulator& lfc) const; + bool operator!=(const Line_face_circulator& lfc) const; + + bool operator==(const Face_handle& fh) const { return fh == pos; } + bool operator!=(const Face_handle& fh) const { return fh != pos; } + + bool operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const; + bool operator!=(Nullptr_t n) const; + bool is_empty() const; + bool locate(const Point& t, Locate_type <, int &li); + + //private: + Triangulation_sphere_line_face_circulator_2(const Face_handle& face, + int index, + State state, + const Triangulation * t, + const Point& pp, + const Point& qq); private: - void increment(); - void decrement(); + void increment(); + void decrement(); }; - - template < class Triangulation > - inline - bool - operator==(typename Triangulation::Triangulation_data_structure::Face_handle fh, - Triangulation_sphere_line_face_circulator_2 fc) - { - return (fc==fh); - } - - template < class Triangulation > - inline - bool - operator!=(typename Triangulation::Triangulation_data_structure::Face_handle fh, - Triangulation_sphere_line_face_circulator_2 fc) - { - return (fc!=fh); - } - - - - template < class Triangulation > - Triangulation_sphere_line_face_circulator_2:: - Triangulation_sphere_line_face_circulator_2(Vertex_handle v, - const Triangulation* tr, - const Point& dir) - :pos(), _tr(tr), s(undefined) - // begin at the face incident to v, traversed by the ray from v to dir - // or null iterator - { - CGAL_triangulation_precondition((_tr->dimension() == 2) && - (! _tr->xy_equal(v->point(),dir))); - p=v->point(); - q=dir; - - // find a vertex to the left of pq - // if there is no, the line_face_circulator is null - Face_circulator fc = _tr->incident_faces(v); - Face_circulator done(fc); - int ic = fc->index(v); - Vertex_handle vt= fc->vertex(cw(ic)); - //Orientation o = _tr->orientation(p, q, vt->point()); - while( _tr->orientation(p, q, vt->point()) != LEFT_TURN) { - ++fc; - ic = fc->index(v); - vt= fc->vertex(cw(ic)); - if (fc == done) { *this = Line_face_circulator(); return;} - } - - Vertex_handle vr = fc-> vertex(ccw(ic)); - Orientation pqr = RIGHT_TURN; // warning "pqr might be used uninitialized" - while ( (pqr = _tr->orientation(p, q, vr->point()))== LEFT_TURN ) { - --fc; - ic = fc->index(v); - vr = fc-> vertex(ccw(ic)); - } - - - - // first intersected face found - // [pqr] is COLLINEAR or RIGHT_TURN - ic = fc->index(v); - vt= fc->vertex(cw(ic)); - CGAL_triangulation_assertion (_tr->orientation(p,q, vt->point())== - LEFT_TURN ); - - if (pqr == COLLINEAR) { - pos = fc; - s = vertex_vertex; - i = ccw(ic); - } - else { // pqr==RIGHT_TURN - pos = fc; - s = vertex_edge; - i = ic ; - } - return; - } - - - - - template < class Triangulation > - inline - void - Triangulation_sphere_line_face_circulator_2:: - increment() - { - CGAL_triangulation_precondition(pos != Face_handle()); - if(s == vertex_vertex || s == edge_vertex) { - Orientation o; - do{ - Face_handle n = pos->neighbor(cw(i)); - i = n->index(pos); - pos = n; - - o = _tr->orientation(p, q, pos->vertex(i)->point()); - i = cw(i); - }while(o == LEFT_TURN); - - if(o == COLLINEAR) { - s = vertex_vertex; - i = ccw(i); - } - else { - s = vertex_edge; - } - } - else { - Face_handle n = pos->neighbor(i); - int ni = n->index(pos); - pos = n ; - Orientation o = _tr->orientation(p,q,pos->vertex(ni)->point()); - - switch(o){ - case LEFT_TURN: - s = edge_edge; - i = ccw(ni); - break; - case RIGHT_TURN: - s = edge_edge; - i = cw(ni); - break; - default: - s = edge_vertex; - i = ni; - } - } - } - - template < class Triangulation > - void - Triangulation_sphere_line_face_circulator_2:: - decrement() - { - CGAL_triangulation_precondition(pos != Face_handle()); - if(s == vertex_vertex || s == vertex_edge) { - if(s == vertex_vertex){ - i = cw(i); - } - Orientation o; - do{ - Face_handle n = pos->neighbor(ccw(i)); - i = n->index(pos); - pos = n; - - o = _tr->orientation(p, q, pos->vertex(i)->point()); - i = ccw(i); - }while(o == LEFT_TURN); - - s = (o == COLLINEAR) ? vertex_vertex : edge_vertex; - - } - else { // s == edge_edge || s == edge_vertex - // the following is not nice. A better solution is to say - // that index i is at the vertex that is alone on one side of l(p,q) - if(s == edge_edge){ - i = (_tr->orientation - (p, q, - pos->vertex(i)->point()) == - LEFT_TURN) - ? cw(i) : ccw(i); - } - Face_handle n = pos->neighbor(i); - i = n->index(pos); - pos = n; - Orientation o = _tr->orientation(p, q, pos->vertex(i)->point()); - - s = (o == COLLINEAR) ? vertex_edge : edge_edge; - } - } - - - - template < class Triangulation > - inline - Triangulation_sphere_line_face_circulator_2& - Triangulation_sphere_line_face_circulator_2:: - operator++() - { - CGAL_triangulation_precondition( pos != Face_handle()) ; - increment(); - return *this; - } - - template < class Triangulation > - inline - Triangulation_sphere_line_face_circulator_2& - Triangulation_sphere_line_face_circulator_2:: - operator--() - { - CGAL_triangulation_precondition(pos != Face_handle()) ; - decrement(); - return *this; - } - - template < class Triangulation > - inline - Triangulation_sphere_line_face_circulator_2 - Triangulation_sphere_line_face_circulator_2:: - operator++(int) - { - Line_face_circulator tmp(*this); - ++(*this); - return tmp; - } - - template < class Triangulation > - inline - Triangulation_sphere_line_face_circulator_2 - Triangulation_sphere_line_face_circulator_2:: - operator--(int) - { - Line_face_circulator tmp(*this); - --(*this); - return tmp; - } - - template < class Triangulation > - inline bool - Triangulation_sphere_line_face_circulator_2:: - operator==(const Line_face_circulator& lfc) const - { - CGAL_triangulation_precondition( pos != Face_handle() && - lfc.pos != Face_handle()); - return ( pos == lfc.pos && _tr == lfc._tr && - s== lfc.s && p==lfc.p && q==lfc.q); - } - - template < class Triangulation > - inline bool - Triangulation_sphere_line_face_circulator_2:: - operator!=(const Line_face_circulator& lfc) const - { - return !(*this == lfc); - } - - template < class Triangulation > - inline bool - Triangulation_sphere_line_face_circulator_2:: - is_empty() const - { - return pos == Face_handle(); - } - - template < class Triangulation > - inline bool - Triangulation_sphere_line_face_circulator_2:: - operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const - { - CGAL_triangulation_assertion( n == NULL); - return pos == Face_handle(); - } - - template < class Triangulation > - inline bool - Triangulation_sphere_line_face_circulator_2:: - operator!=(Nullptr_t n) const - { - CGAL_triangulation_assertion( n == NULL); - return !(*this == n); - } - - -}//namespace +template < class Triangulation > +inline +bool +operator==(typename Triangulation::Triangulation_data_structure::Face_handle fh, + Triangulation_sphere_line_face_circulator_2 fc) +{ + return (fc == fh); +} + +template < class Triangulation > +inline +bool +operator!=(typename Triangulation::Triangulation_data_structure::Face_handle fh, + Triangulation_sphere_line_face_circulator_2 fc) +{ + return (fc != fh); +} + +template < class Triangulation > +Triangulation_sphere_line_face_circulator_2:: +Triangulation_sphere_line_face_circulator_2(Vertex_handle v, + const Triangulation* tr, + const Point& dir) + :pos(), _tr(tr), s(undefined) + // begin at the face incident to v, traversed by the ray from v to dir + // or null iterator +{ + CGAL_triangulation_precondition((_tr->dimension() == 2) && + (! _tr->xy_equal(v->point(), dir))); + p = v->point(); + q = dir; + + // find a vertex to the left of pq + // if there is no, the line_face_circulator is null + Face_circulator fc = _tr->incident_faces(v); + Face_circulator done(fc); + int ic = fc->index(v); + Vertex_handle vt = fc->vertex(cw(ic)); + //Orientation o = _tr->orientation(p, q, vt->point()); + while( _tr->orientation(p, q, vt->point()) != LEFT_TURN) + { + ++fc; + ic = fc->index(v); + vt= fc->vertex(cw(ic)); + + if(fc == done) + { + *this = Line_face_circulator(); + return; + } + } + + Vertex_handle vr = fc-> vertex(ccw(ic)); + Orientation pqr = RIGHT_TURN; // warning "pqr might be used uninitialized" + while((pqr = _tr->orientation(p, q, vr->point())) == LEFT_TURN) + { + --fc; + ic = fc->index(v); + vr = fc-> vertex(ccw(ic)); + } + + // first intersected face found + // [pqr] is COLLINEAR or RIGHT_TURN + ic = fc->index(v); + vt= fc->vertex(cw(ic)); + CGAL_triangulation_assertion (_tr->orientation(p, q, vt->point()) == LEFT_TURN); + + if(pqr == COLLINEAR) + { + pos = fc; + s = vertex_vertex; + i = ccw(ic); + } + else // pqr == RIGHT_TURN + { + pos = fc; + s = vertex_edge; + i = ic ; + } +} + +template < class Triangulation > +inline +void +Triangulation_sphere_line_face_circulator_2:: +increment() +{ + CGAL_triangulation_precondition(pos != Face_handle()); + if(s == vertex_vertex || s == edge_vertex) + { + Orientation o; + do + { + Face_handle n = pos->neighbor(cw(i)); + i = n->index(pos); + pos = n; + + o = _tr->orientation(p, q, pos->vertex(i)->point()); + i = cw(i); + } while(o == LEFT_TURN); + + if(o == COLLINEAR) + { + s = vertex_vertex; + i = ccw(i); + } + else + { + s = vertex_edge; + } + } + else + { + Face_handle n = pos->neighbor(i); + int ni = n->index(pos); + pos = n ; + Orientation o = _tr->orientation(p, q, pos->vertex(ni)->point()); + + switch(o) + { + case LEFT_TURN: + s = edge_edge; + i = ccw(ni); + break; + case RIGHT_TURN: + s = edge_edge; + i = cw(ni); + break; + default: + s = edge_vertex; + i = ni; + } + } +} + +template < class Triangulation > +void +Triangulation_sphere_line_face_circulator_2:: +decrement() +{ + CGAL_triangulation_precondition(pos != Face_handle()); + if(s == vertex_vertex || s == vertex_edge) + { + if(s == vertex_vertex) + i = cw(i); + + Orientation o; + do + { + Face_handle n = pos->neighbor(ccw(i)); + i = n->index(pos); + pos = n; + + o = _tr->orientation(p, q, pos->vertex(i)->point()); + i = ccw(i); + } + while(o == LEFT_TURN); + + s = (o == COLLINEAR) ? vertex_vertex : edge_vertex; + + } + else // s == edge_edge || s == edge_vertex + { + // the following is not nice. A better solution is to say + // that index i is at the vertex that is alone on one side of l(p, q) + if(s == edge_edge) + i = (_tr->orientation(p, q, pos->vertex(i)->point()) == LEFT_TURN) ? cw(i) : ccw(i); + + Face_handle n = pos->neighbor(i); + i = n->index(pos); + pos = n; + Orientation o = _tr->orientation(p, q, pos->vertex(i)->point()); + + s = (o == COLLINEAR) ? vertex_edge : edge_edge; + } +} + +template < class Triangulation > +inline +Triangulation_sphere_line_face_circulator_2& +Triangulation_sphere_line_face_circulator_2:: +operator++() +{ + CGAL_triangulation_precondition(pos != Face_handle()) ; + increment(); + return *this; +} + +template < class Triangulation > +inline +Triangulation_sphere_line_face_circulator_2& +Triangulation_sphere_line_face_circulator_2:: +operator--() +{ + CGAL_triangulation_precondition(pos != Face_handle()) ; + decrement(); + return *this; +} + +template < class Triangulation > +inline +Triangulation_sphere_line_face_circulator_2 +Triangulation_sphere_line_face_circulator_2:: +operator++(int) +{ + Line_face_circulator tmp(*this); + ++(*this); + return tmp; +} + +template < class Triangulation > +inline +Triangulation_sphere_line_face_circulator_2 +Triangulation_sphere_line_face_circulator_2:: +operator--(int) +{ + Line_face_circulator tmp(*this); + --(*this); + return tmp; +} + +template < class Triangulation > +inline bool +Triangulation_sphere_line_face_circulator_2:: +operator==(const Line_face_circulator& lfc) const +{ + CGAL_triangulation_precondition(pos != Face_handle() && lfc.pos != Face_handle()); + return (pos == lfc.pos && _tr == lfc._tr && + s == lfc.s && p==lfc.p && q==lfc.q); +} + +template < class Triangulation > +inline bool +Triangulation_sphere_line_face_circulator_2:: +operator!=(const Line_face_circulator& lfc) const +{ + return !(*this == lfc); +} + +template < class Triangulation > +inline bool +Triangulation_sphere_line_face_circulator_2:: +is_empty() const +{ + return pos == Face_handle(); +} + +template < class Triangulation > +inline bool +Triangulation_sphere_line_face_circulator_2:: +operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const +{ + CGAL_triangulation_assertion(n == NULL); + return pos == Face_handle(); +} + +template < class Triangulation > +inline bool +Triangulation_sphere_line_face_circulator_2:: +operator!=(Nullptr_t n) const +{ + CGAL_triangulation_assertion(n == NULL); + return !(*this == n); +} + +} // end namespace CGAL + #endif -