EMODnet Quantized Mesh Generator for Cesium
surface_mesh_from_projected_triangulation.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_SURFACE_MESH_FROM_PROJECTED_TRIANGULATION_H
22 #define EMODNET_QMGC_SURFACE_MESH_FROM_PROJECTED_TRIANGULATION_H
23 
24 #include <map>
25 
30 template<class ProjectedTriangulation2, class SurfaceMesh>
31 SurfaceMesh surfaceMeshFromProjectedTriangulation(const ProjectedTriangulation2& tri)
32 {
33  typedef ProjectedTriangulation2 Tri;
34  typedef typename SurfaceMesh::vertex_index VertexIndex;
35  SurfaceMesh sm;
36 
37  std::map<typename Tri::Vertex_handle, VertexIndex> indices;
38  for(typename Tri::Finite_vertices_iterator it = tri.finite_vertices_begin();
39  it != tri.finite_vertices_end(); ++it)
40  {
41  VertexIndex vi = sm.add_vertex(it->point());
42  indices.insert(std::pair<typename Tri::Vertex_handle,int>(it, vi));
43  }
44 
45  for(typename Tri::Finite_faces_iterator it = tri.finite_faces_begin();
46  it != tri.finite_faces_end(); ++it)
47  {
48  sm.add_face(indices[it->vertex(0)], indices[it->vertex(1)], indices[it->vertex(2)]);
49  }
50 
51  return sm;
52 }
53 
54 #endif //EMODNET_QMGC_SURFACE_MESH_FROM_PROJECTED_TRIANGULATION_H