EMODnet Quantized Mesh Generator for Cesium
detect_sharp_edges_without_borders.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_DETECT_SHARP_EDGES_WITHOUT_BORDERS_H
22 #define EMODNET_QMGC_DETECT_SHARP_EDGES_WITHOUT_BORDERS_H
23 
24 #include <CGAL/Surface_mesh.h>
25 #include <CGAL/Polygon_mesh_processing/compute_normal.h>
26 
37 template<typename PolygonMesh,
38  typename FT,
39  typename EdgeIsSharpMap,
40  typename GT>
41 void detect_sharp_edges_without_borders(PolygonMesh &pmesh,
42  FT angle_in_deg,
43  EdgeIsSharpMap &edge_is_sharp_map) {
44  FT cos_angle(std::cos(CGAL::to_double(angle_in_deg) * CGAL_PI / 180.));
45 
46  // Detect sharp edges
47  BOOST_FOREACH(typename boost::graph_traits<PolygonMesh>::edge_descriptor ed, edges(pmesh)) {
48  typename boost::graph_traits<PolygonMesh>::halfedge_descriptor he = halfedge(ed, pmesh);
49  typedef typename boost::graph_traits<PolygonMesh>::face_descriptor face_descriptor;
50 
51  // We skip border edges
52  if (is_border_edge(he, pmesh))
53  continue;
54  else {
55  // Get the faces incident to this edge
56  face_descriptor f1 = face(he, pmesh);
57  face_descriptor f2 = face(opposite(he, pmesh), pmesh);
58 
59  // Compute their normal
60  const typename GT::Vector_3 &n1 = CGAL::Polygon_mesh_processing::compute_face_normal(f1, pmesh);
61  const typename GT::Vector_3 &n2 = CGAL::Polygon_mesh_processing::compute_face_normal(f2, pmesh);
62 
63  // Check the dihedral angle between them, and mark it as a sharp edge if it is larger than the threshold
64  if (n1 * n2 <= cos_angle) {
65  put(edge_is_sharp_map, edge(he, pmesh), true);
66  }
67  }
68  }
69 }
70 
71 #endif //EMODNET_QMGC_DETECT_SHARP_EDGES_WITHOUT_BORDERS_H