EMODnet Quantized Mesh Generator for Cesium
polyhedron_builder_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_POLYHEDRON_BUILDER_FROM_PROJECTED_TRIANGULATION_H
22 #define EMODNET_QMGC_POLYHEDRON_BUILDER_FROM_PROJECTED_TRIANGULATION_H
23 
29 template<class ProjectedTriangulation2, class HDS>
30 class PolyhedronBuilderFromProjectedTriangulation : public CGAL::Modifier_base<HDS> {
31 public:
32  typedef ProjectedTriangulation2 Tri;
33 
34  Tri m_dt ;
35 
36  PolyhedronBuilderFromProjectedTriangulation( const Tri &dt ) : m_dt(dt) {}
37 
38  void operator()( HDS& hds ) {
39  typedef typename HDS::Vertex Vertex;
40  typedef typename Vertex::Point Point;
41 
42  // Polyhedron_3 incremental builder
43  CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true);
44  B.begin_surface( m_dt.number_of_vertices(), m_dt.number_of_faces() );
45 
46  std::map<typename Tri::Vertex_handle,int> indices;
47  int counter = 0 ;
48  for(typename Tri::Finite_vertices_iterator it = m_dt.finite_vertices_begin();
49  it != m_dt.finite_vertices_end(); ++it)
50  {
51  B.add_vertex( it->point() );
52  indices.insert(std::pair<typename Tri::Vertex_handle,int>(it, counter++));
53  }
54 
55  for(typename Tri::Finite_faces_iterator it = m_dt.finite_faces_begin();
56  it != m_dt.finite_faces_end(); ++it)
57  {
58  B.begin_facet();
59  B.add_vertex_to_facet( indices[it->vertex(0)] );
60  B.add_vertex_to_facet( indices[it->vertex(1)] );
61  B.add_vertex_to_facet( indices[it->vertex(2)] );
62  B.end_facet();
63  }
64 
65  // End the surface
66  B.end_surface();
67  }
68 };
69 
70 
71 #endif //EMODNET_QMGC_POLYHEDRON_BUILDER_FROM_PROJECTED_TRIANGULATION_H
A modifier creating a Polyhedron_3 structure with the incremental builder from a projected triangulat...
Definition: polyhedron_builder_from_projected_triangulation.h:30