EMODnet Quantized Mesh Generator for Cesium
border_edges_are_constrained_edge_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_CGAL_SIMPLIFICATION_CONSTRAINED_BORDERS_H
22 #define EMODNET_QMGC_CGAL_SIMPLIFICATION_CONSTRAINED_BORDERS_H
23 
24 #include "tin_creation/tin_creation_cgal_types.h"
25 #include "cgal_utils.h"
26 
27 
35 template <class Polyhedron>
37 {
38  typedef typename boost::graph_traits<Polyhedron>::edge_descriptor key_type ;
39  typedef bool value_type ;
40  typedef value_type reference ;
41  typedef boost::readable_property_map_tag category;
42  typedef typename Polyhedron::Point_3 Point_3;
43 
44  const Polyhedron* m_pPolyPtr ;
45  const bool m_constrainEastBorder ;
46  const bool m_constrainWestBorder ;
47  const bool m_constrainNorthBorder ;
48  const bool m_constrainSouthBorder ;
49 
50  BorderEdgesAreConstrainedEdgeMap( const Polyhedron& sm,
51  const bool& constrainEastBorder = true,
52  const bool& constrainWestBorder = true,
53  const bool& constrainNorthBorder = true,
54  const bool& constrainSouthBorder = true )
55  : m_pPolyPtr(&sm)
56  , m_constrainEastBorder(constrainEastBorder)
57  , m_constrainWestBorder(constrainWestBorder)
58  , m_constrainNorthBorder(constrainNorthBorder)
59  , m_constrainSouthBorder(constrainSouthBorder) {}
60 
61  friend bool get(BorderEdgesAreConstrainedEdgeMap m, const key_type& edge)
62  {
63  bool isBorder = CGAL::is_border(edge, *m.m_pPolyPtr);
64  if (isBorder) {
65  Point_3 p0 = edge.halfedge()->vertex()->point() ;
66  Point_3 p1 = edge.halfedge()->opposite()->vertex()->point() ;
67 
68  double diffX = fabs( p1.x() - p0.x() ) ;
69  double diffY = fabs( p1.y() - p0.y() ) ;
70 
71  return ( m.m_constrainEastBorder && diffX < diffY && p0.x() > 0.5 ) ||
72  ( m.m_constrainWestBorder && diffX < diffY && p0.x() < 0.5 ) ||
73  ( m.m_constrainNorthBorder && diffY < diffX && p0.y() > 0.5 ) ||
74  ( m.m_constrainSouthBorder && diffY < diffX && p0.y() < 0.5 ) ;
75  }
76  else
77  return false ;
78  }
79 };
80 
81 #endif //EMODNET_QMGC_CGAL_SIMPLIFICATION_CONSTRAINED_BORDERS_H
Set of miscellaneous functions extending the functionality of the CGAL library.
bool isBorder(typename Polyhedron::Vertex_handle &v)
Checks if a vertex in the polyhedron is in the border.
Definition: cgal_utils.h:101
BGL property map indicating whether an edge is marked as non-removable.
Definition: border_edges_are_constrained_edge_map.h:36