21 #ifndef EMODNET_QMGC_CGAL_UTILS_H 22 #define EMODNET_QMGC_CGAL_UTILS_H 24 #include "tin_creation/tin_creation_cgal_types.h" 26 #include <CGAL/Polyhedron_incremental_builder_3.h> 27 #include <CGAL/Polyhedron_3.h> 28 #include <CGAL/Delaunay_triangulation_2.h> 29 #include <CGAL/Triangulation_2.h> 40 template<
class Polyhedron>
41 bool isTileCorner(
typename Polyhedron::Halfedge_const_handle e ) {
42 typedef typename Polyhedron::Point_3 Point_3 ;
45 Point_3 p0 = e->vertex()->point() ;
46 Point_3 p1 = e->prev()->vertex()->point() ;
49 double diffX = fabs( p1.x() - p0.x() ) ;
50 double diffY = fabs( p1.y() - p0.y() ) ;
53 Point_3 p2 = e->next()->vertex()->point() ;
56 double diffXNext = fabs( p2.x() - p0.x() ) ;
57 double diffYNext = fabs( p2.y() - p0.y() ) ;
60 return ( ( diffX < diffY ) && ( diffXNext > diffYNext ) ) ||
61 ( ( diffX > diffY ) && ( diffXNext < diffYNext ) ) ;
71 template <
class Delaunay>
72 void delaunayToOFF(
const std::string &outFilePath,
const Delaunay &dt )
74 std::ofstream ofs( outFilePath.c_str() );
75 ofs <<
"OFF\n" << dt.number_of_vertices()
76 <<
" " << dt.number_of_faces() <<
" 0" << std::endl;
78 std::map<typename Delaunay::Vertex_handle,int> indices;
81 for(
typename Delaunay::Finite_vertices_iterator it = dt.finite_vertices_begin(); it != dt.finite_vertices_end(); ++it)
83 ofs << it->point() << std::endl;
84 indices.insert(std::pair<typename Delaunay::Vertex_handle,int>(it, counter++));
87 for(
typename Delaunay::Finite_faces_iterator it = dt.finite_faces_begin(); it != dt.finite_faces_end(); ++it)
89 ofs <<
"3 " << indices[it->vertex(0)]
90 <<
" " << indices[it->vertex(1)]
91 <<
" " << indices[it->vertex(2)] << std::endl;
100 template <
class Polyhedron>
101 bool isBorder(
typename Polyhedron::Vertex_handle& v)
103 typename Polyhedron::Halfedge_around_vertex_const_circulator hv = v->vertex_begin();
109 }
while (++hv != v->vertex_begin());
115 template <
class Polyhedron>
116 bool isBorder(
typename Polyhedron::Vertex_const_handle& v)
118 typename Polyhedron::Halfedge_around_vertex_const_circulator hv = v->vertex_begin();
124 }
while (++hv != v->vertex_begin());
133 const typename K::Point_2& center,
134 const typename K::Point_2& p0,
135 const typename K::Point_2& p1 )
137 typedef typename K::Vector_2 Vector_2;
139 Vector_2 a = p0 - center ;
140 Vector_2 b = query - center ;
141 Vector_2 c = p1 - center ;
143 double AxB = a.x()*b.y() - a.y()*b.x() ;
144 double AxC = a.x()*c.y() - a.y()*c.x() ;
145 double CxB = c.x()*b.y() - c.y()*b.x() ;
146 double CxA = c.x()*a.y() - c.y()*a.x() ;
148 return ( AxB*AxC >= 0. && CxB*CxA >= 0. ) ;
151 #endif //EMODNET_QMGC_CGAL_UTILS_H bool isPointInArc(const typename K::Point_2 &query, const typename K::Point_2 ¢er, const typename K::Point_2 &p0, const typename K::Point_2 &p1)
Computes if a point query falls within the arc defined by the vectors p0 - center and p1 - center...
Definition: cgal_utils.h:132
void delaunayToOFF(const std::string &outFilePath, const Delaunay &dt)
Exports a 2D Delaunay on a 3D point set (i.e., using the Projection_traits_xy_3) to an OFF file...
Definition: cgal_utils.h:72
bool isBorder(typename Polyhedron::Vertex_handle &v)
Checks if a vertex in the polyhedron is in the border.
Definition: cgal_utils.h:101
bool isTileCorner(typename Polyhedron::Halfedge_const_handle e)
Definition: cgal_utils.h:41