EMODnet Quantized Mesh Generator for Cesium
further_constrained_placement.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 
29 #ifndef EMODNET_QMGC_CGAL_FURTHER_CONSTRAINED_PLACEMENT_H
30 #define EMODNET_QMGC_CGAL_FURTHER_CONSTRAINED_PLACEMENT_H
31 
32 #include <CGAL/Surface_mesh_simplification/Detail/Common.h>
33 #include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Edge_profile.h>
34 #include <iostream>
35 
36 
37 
38 namespace CGAL {
39 
40  namespace Surface_mesh_simplification {
41 
48  template<class BasePlacement, class EdgeIsConstrainedMap, class VertexIsConstrainedMap>
49  class FurtherConstrainedPlacement : public BasePlacement {
50  public:
51 
52  EdgeIsConstrainedMap Edge_is_constrained_map;
53  VertexIsConstrainedMap Vertex_is_constrained_map;
54 
55  public:
57  EdgeIsConstrainedMap edgesMap = EdgeIsConstrainedMap(),
58  VertexIsConstrainedMap vertMap = VertexIsConstrainedMap(),
59  BasePlacement base = BasePlacement())
60  : BasePlacement(base), Edge_is_constrained_map(edgesMap), Vertex_is_constrained_map(vertMap) {}
61 
62  template<typename Profile>
63  optional<typename Profile::Point> operator()(Profile const &aProfile) const {
64  typedef typename Profile::ECM ECM;
65  typedef typename CGAL::Halfedge_around_target_iterator<ECM> in_edge_iterator;
66 
67  // Constrained vertices
68  bool isConstrainedV0 = get(Vertex_is_constrained_map, aProfile.v0()) ;
69  bool isConstrainedV1 = get(Vertex_is_constrained_map, aProfile.v1()) ;
70 
71  if ( isConstrainedV0 && isConstrainedV1 ) {
72  // Both vertices in the edge are constrained: the edge must remain as is, no placement possible
73  return boost::optional<typename Profile::Point>();
74  }
75  else if ( isConstrainedV0 ) {
76  // v0 is constrained, return it as the placement
77  typename Profile::Point p = get(aProfile.vertex_point_map(), aProfile.v0()) ;
78  return get(aProfile.vertex_point_map(), aProfile.v0()) ;
79  }
80  else if ( isConstrainedV1 ) {
81  // v1 is constrained, return it as the placement
82  typename Profile::Point p = get(aProfile.vertex_point_map(), aProfile.v1()) ;
83  return get(aProfile.vertex_point_map(), aProfile.v1()) ;
84  }
85 
86  // Constrained edges
87  in_edge_iterator eb, ee;
88  for (boost::tie(eb, ee) = halfedges_around_target(aProfile.v0(), aProfile.surface_mesh());
89  eb != ee; ++eb) {
90  if (get(Edge_is_constrained_map, edge(*eb, aProfile.surface_mesh())))
91  return get(aProfile.vertex_point_map(),
92  aProfile.v0());
93  }
94  for (boost::tie(eb, ee) = halfedges_around_target(aProfile.v1(), aProfile.surface_mesh());
95  eb != ee; ++eb) {
96  if (get(Edge_is_constrained_map, edge(*eb, aProfile.surface_mesh())))
97  return get(aProfile.vertex_point_map(),
98  aProfile.v1());
99  }
100 
101  return static_cast<const BasePlacement *>(this)->operator()(aProfile);
102  }
103  };
104 
105  }
106 }
107 #endif //EMODNET_QMGC_CGAL_FURTHER_CONSTRAINED_PLACEMENT_H
Constrained placement class for CGAL::Surface_mesh_simplification, extending the normal constrained p...
Definition: further_constrained_placement.h:49
Extension of CGAL&#39;s Constrained_placement class.
Definition: further_constrained_placement.h:38