EMODnet Quantized Mesh Generator for Cesium
corner_vertices_are_constrained_vertex_map.h
1 // Copyright (c) 2018 Coronis Computing S.L. (Spain)
2 // All rights reserved.
3 //
4 // This file is part of EMODnet Quantized Mesh Generator for Cesium.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 //
19 // Author: Ricard Campos (ricardcd@gmail.com)
20 
21 #ifndef EMODNET_QMGC_CORNER_VERTICES_ARE_CONSTRAINED_VERTEX_MAP_H
22 #define EMODNET_QMGC_CORNER_VERTICES_ARE_CONSTRAINED_VERTEX_MAP_H
23 
24 #include "tin_creation/tin_creation_cgal_types.h"
25 #include "cgal_utils.h"
26 #include <iostream>
27 
28 
36 template <class Polyhedron>
38 {
39  typedef typename boost::graph_traits<Polyhedron>::vertex_descriptor key_type;
40  typedef typename boost::graph_traits<Polyhedron>::halfedge_descriptor HalfedgeDescriptor;
41  typedef bool value_type;
42  typedef value_type reference;
43  typedef typename Polyhedron::Point_3 Point_3;
44 
45  const Polyhedron *m_pPolyPtr;
46 
47  CornerVerticesAreConstrainedVertexMap( const Polyhedron &sm ) : m_pPolyPtr(&sm) {}
48 
49  friend bool get(CornerVerticesAreConstrainedVertexMap m, const key_type &vertex)
50  {
51  // The vertex must be on the border
52  boost::optional<HalfedgeDescriptor> he = CGAL::is_border( vertex, *m.m_pPolyPtr ) ;
53 
54  if (he) {
55  // Next edge on the border (since we are in a border halfedge, the next operator should point to the next halfedge around the "hole")
56  if ( (*he)->next()->is_border() ) {
57  // Check the differences in X and Y to discern if this is a corner vertex
58 
59  // Relevant geometric info of the current edge
60  Point_3 p0 = vertex->point() ;
61  Point_3 p1 = (*he)->opposite()->vertex()->point() ; // This is the previous vertex, with which p0 forms an edge
62 
63  // Differences between the points in the edge
64  double diffX = fabs( p1.x() - p0.x() ) ;
65  double diffY = fabs( p1.y() - p0.y() ) ;
66 
67  Point_3 p2 = (*he)->next()->vertex()->point() ;
68 
69  double diffXNext = fabs( p2.x() - p0.x() ) ;
70  double diffYNext = fabs( p2.y() - p0.y() ) ;
71 
72  return ( ( diffX < diffY ) && ( diffXNext > diffYNext ) ) ||
73  ( ( diffX > diffY ) && ( diffXNext < diffYNext ) ) ;
74  }
75  else {
76  return false ;
77  }
78  }
79  else {
80  return false ;
81  }
82  }
83 };
84 
85 #endif // EMODNET_QMGC_CORNER_VERTICES_ARE_CONSTRAINED_VERTEX_MAP_H
BGL property map indicating whether a given vertex is one of the 4 corners of the tile...
Definition: corner_vertices_are_constrained_vertex_map.h:37
Set of miscellaneous functions extending the functionality of the CGAL library.