21 #ifndef EMODNET_QMGC_CGAL_EXTRACT_TILE_BORDERS_FROM_POLYHEDRON_H 22 #define EMODNET_QMGC_CGAL_EXTRACT_TILE_BORDERS_FROM_POLYHEDRON_H 24 #include "tin_creation/tin_creation_cgal_types.h" 25 #include <CGAL/centroid.h> 34 template<
class Polyhedron>
35 bool extractTileBordersFromPolyhedron(
const Polyhedron& poly,
36 std::vector<typename Polyhedron::Point_3>& easternBorderPts,
37 std::vector<typename Polyhedron::Point_3>& westernBorderPts,
38 std::vector<typename Polyhedron::Point_3>& northernBorderPts,
39 std::vector<typename Polyhedron::Point_3>& southernBorderPts,
40 typename Polyhedron::Point_3& cornerPoint00,
41 typename Polyhedron::Point_3& cornerPoint01,
42 typename Polyhedron::Point_3& cornerPoint10,
43 typename Polyhedron::Point_3& cornerPoint11)
45 typedef typename Polyhedron::Point_3 Point_3;
46 typedef typename Polyhedron::Traits::FT FT;
47 typedef typename Polyhedron::Vertex_const_iterator Vertex_const_iterator;
48 typedef typename Polyhedron::Halfedge_const_iterator Halfedge_const_iterator;
50 easternBorderPts.clear();
51 westernBorderPts.clear();
52 northernBorderPts.clear();
53 southernBorderPts.clear();
57 std::vector<Point_3 > pts ;
58 for ( Vertex_const_iterator it = poly.vertices_begin(); it != poly.vertices_end(); ++it )
59 pts.push_back(it->point());
60 Point_3 c3 = CGAL::centroid(pts.begin(), pts.end(),CGAL::Dimension_tag<0>());
64 Halfedge_const_iterator e = poly.border_halfedges_begin() ;
66 while( e->is_border() )
69 Point_3 p0 = e->vertex()->point() ;
70 Point_3 p1 = e->prev()->vertex()->point() ;
73 double diffX = fabs( p1.x() - p0.x() ) ;
74 double diffY = fabs( p1.y() - p0.y() ) ;
80 Point_3 p2 = e->next()->vertex()->point() ;
82 double diffXNext = fabs( p2.x() - p0.x() ) ;
83 double diffYNext = fabs( p2.y() - p0.y() ) ;
84 bool isCorner = ( ( diffX < diffY ) && ( diffXNext > diffYNext ) ) ||
85 ( ( diffX > diffY ) && ( diffXNext < diffYNext ) ) ;
89 if ( p0.x() < midX && p0.y() < midY ) {
91 westernBorderPts.push_back(p0);
92 southernBorderPts.push_back(p0);
94 else if ( p0.x() < midX && p0.y() > midY ) {
96 westernBorderPts.push_back(p0);
97 northernBorderPts.push_back(p0);
99 else if ( p0.x() > midX && p0.y() > midY ) {
101 easternBorderPts.push_back(p0);
102 northernBorderPts.push_back(p0);
106 easternBorderPts.push_back(p0);
107 southernBorderPts.push_back(p0);
115 westernBorderPts.push_back(p0);
118 easternBorderPts.push_back(p0);
124 southernBorderPts.push_back(p0);
127 northernBorderPts.push_back(p0);
136 return numCorners == 4 ;
139 #endif //EMODNET_QMGC_CGAL_EXTRACT_TILE_BORDERS_FROM_POLYHEDRON_H