MEPP2 Project
Error_metric.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 
12 #pragma once
13 
14 #include <boost/graph/graph_traits.hpp>
15 #include <boost/graph/properties.hpp>
16 #include <CGAL/boost/graph/iterator.h>
18 
22 
23 #include <iostream>
24 #include <vector>
25 #include <map>
26 #include <queue>
27 #include <utility>
28 
29 namespace FEVV {
30 namespace Filters {
34 template<
35  typename HalfedgeGraph,
36  typename edge_descriptor =
37  typename boost::graph_traits< HalfedgeGraph >::edge_descriptor,
41 {
42 public:
43  bool operator()(const std::tuple< edge_descriptor, double, Point > &e1,
44  const std::tuple< edge_descriptor, double, Point > &e2) const
45  {
46  double w1 = std::get< 1 >(e1);
47  double w2 = std::get< 1 >(e2);
48 
49  if(w1 > w2)
50  return true;
51  else
52  return false;
53  }
54 };
55 
58 template<
59  typename HalfedgeGraph,
60  typename PointMap>
62 {
63 public:
67  typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor;
68  using edge_iterator =
69  typename boost::graph_traits< HalfedgeGraph >::edge_iterator;
71  typename boost::graph_traits< HalfedgeGraph >::edge_descriptor;
75 
76 
77  typedef std::priority_queue<
78  std::tuple< edge_descriptor, double, Point >,
79  std::vector< std::tuple< edge_descriptor, double, Point > >,
82 
85  typedef std::map< edge_descriptor, std::pair< double, Point > > edge2cost_map;
86 
88  HalfedgeGraph &g,
89  PointMap &pm,
92  : _g(g), _gt(Geometry(g)), _pm(pm),
93  _dequantiz(dequantiz)
94  {
95  _vkept = vkept;
96  _threshold = 0;
97  }
98  virtual ~Error_metric(){}
99 
103  virtual void compute_error() = 0;
104 
108  virtual double compute_cost_edge(edge_descriptor e, const Point &collapsePos) = 0;
109 
110  bool is_queue_empty() { return _queue.empty(); }
111  std::tuple< typename boost::graph_traits< HalfedgeGraph >::edge_descriptor,
112  double,
113  typename Geometry::Point >
114  get_top_queue() const { return _queue.top(); }
115  void pop_queue() { _queue.pop(); }
116 
117  double get_top_cost() const { return std::get< 1 >(_queue.top()); }
118 
119  double get_mean_threshold() const { return _threshold; }
120 
122 
124  {
126  halfedge_descriptor h_opp = opposite(h, _g);
127  bool is_normal_present = !(_edges_cost.find(edge(h, _g)) == _edges_cost.end());
128  if(is_normal_present)
129  return true;
130  bool is_opposite_present = !(_edges_cost.find(edge(h_opp, _g)) == _edges_cost.end());
131 
132  return is_opposite_present; // for most data structure (except LCC) is_normal_present <=> is_opposite_present
133  }
135  {
136  boost::iterator_range<
137  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
138  iterator_range = CGAL::halfedges_around_target(vs, _g);
139 
140  for(auto h_around : iterator_range)
141  {
142  edge_descriptor e = edge(h_around, _g);
143 
144  typename std::map< edge_descriptor, std::pair< double, Point > >::iterator
145  it = _edges_cost.find(e);
146  if(it != _edges_cost.end())
147  _edges_cost.erase(it);
148 
149  else
150  {
151  edge_descriptor h_around_2 = edge(opposite(h_around, _g), _g);
152  it = _edges_cost.find(h_around_2);
153  if(it != _edges_cost.end())
154  _edges_cost.erase(it);
155  else
156  std::cerr << "remove_old_edges: edge not found " << std::endl;
157  }
158  }
159 
160 
161  // for vt
162  iterator_range = CGAL::halfedges_around_target(vt, _g);
163 
164  for(auto h_around : iterator_range)
165  {
166  // skip the edge to collapse
167  if((source(h_around, _g) == vs && target(h_around, _g) == vt) ||
168  (source(h_around, _g) == vt && target(h_around, _g) == vs))
169  continue;
170  else
171  {
172  edge_descriptor e = edge(h_around, _g);
173 
174  typename std::map< edge_descriptor,
175  std::pair< double, Point > >::iterator it =
176  _edges_cost.find(e);
177  if(it != _edges_cost.end())
178  _edges_cost.erase(it);
179  else
180  {
181  halfedge_descriptor h2 = opposite(h_around, _g);
182  edge_descriptor h_around_2 = edge(h2, _g);
183  it = _edges_cost.find(h_around_2);
184  if(it != _edges_cost.end())
185  _edges_cost.erase(it);
186  else
187  std::cerr << "remove_old_edges: edge not found " << std::endl;
188  }
189  }
190  }
191  }
192 
193  size_t get_size_queue() const { return _queue.size(); }
194 
197  {
198  return _vkept;
199  }
200 
201  virtual std::string get_as_string() const = 0;
202 
203 protected:
204  HalfedgeGraph &_g;
205  const Geometry _gt;
206  PointMap &_pm;
207 
210 
214  double _threshold;
216 };
217 } // namespace Filters
218 } // namespace FEVV
FEVV::Filters::Error_metric::_queue
priority_queue_edges _queue
Definition: Error_metric.h:208
FEVV::Filters::Error_metric::_threshold
double _threshold
Definition: Error_metric.h:214
FEVV::Filters::Compare_weights2
Definition: Error_metric.h:41
FEVV::Filters::Error_metric::halfedge_descriptor
typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor halfedge_descriptor
Definition: Error_metric.h:67
FEVV::Filters::Error_metric::is_present_in_map
bool is_present_in_map(edge_descriptor e) const
Definition: Error_metric.h:123
FEVV::Filters::Error_metric::_edges_cost
edge2cost_map _edges_cost
queue with the cost/weight as the key
Definition: Error_metric.h:209
FEVV::Filters::Error_metric::vertex_descriptor
typename boost::graph_traits< HalfedgeGraph >::vertex_descriptor vertex_descriptor
Definition: Error_metric.h:65
FEVV::Filters::Error_metric::_pm
PointMap & _pm
Definition: Error_metric.h:206
FEVV::Filters::Error_metric::Point
typename FEVV::Geometry_traits< HalfedgeGraph >::Point Point
Definition: Error_metric.h:73
FEVV::Filters::Error_metric::pop_queue
void pop_queue()
Definition: Error_metric.h:115
FEVV::Filters::Error_metric::get_as_string
virtual std::string get_as_string() const =0
FEVV::Filters::Error_metric::is_queue_empty
bool is_queue_empty()
Definition: Error_metric.h:110
FEVV::Filters::Error_metric::priority_queue_edges
std::priority_queue< std::tuple< edge_descriptor, double, Point >, std::vector< std::tuple< edge_descriptor, double, Point > >, Compare_weights2< HalfedgeGraph > > priority_queue_edges
Definition: Error_metric.h:81
FEVV::Filters::Error_metric::get_size_queue
size_t get_size_queue() const
Definition: Error_metric.h:193
FEVV::DataStructures::AIF::opposite
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor opposite(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the halfedge with source and target swapped.
Definition: Graph_traits_aif.h:625
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Uniform_dequantization.h
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Filters::Error_metric::remove_old_edges
void remove_old_edges(vertex_descriptor vs, vertex_descriptor vt)
Definition: Error_metric.h:134
FEVV::Filters::Error_metric::_g
HalfedgeGraph & _g
Definition: Error_metric.h:204
Midpoint.h
FEVV::Filters::Error_metric::delete_from_descriptors
void delete_from_descriptors(edge_descriptor e)
Definition: Error_metric.h:121
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
FEVV::DataStructures::AIF::edge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor edge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the edge corresponding to h and opposite(h).
Definition: Graph_traits_aif.h:345
FEVV::Filters::Error_metric
Abstract class to compute the collapse cost of each edge in a mesh. It also manages a priority queue ...
Definition: Error_metric.h:62
FEVV::Filters::Error_metric::compute_error
virtual void compute_error()=0
FEVV::Filters::Error_metric::Error_metric
Error_metric(HalfedgeGraph &g, PointMap &pm, Kept_position< HalfedgeGraph, PointMap > *vkept, FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap > &dequantiz)
Definition: Error_metric.h:87
FEVV::Filters::Error_metric::compute_cost_edge
virtual double compute_cost_edge(edge_descriptor e, const Point &collapsePos)=0
FEVV::Filters::Error_metric::Vector
typename FEVV::Geometry_traits< HalfedgeGraph >::Vector Vector
Definition: Error_metric.h:72
Halfedge.h
FEVV::Filters::Kept_position< HalfedgeGraph, PointMap >
FEVV::Filters::Error_metric::Geometry
typename FEVV::Geometry_traits< HalfedgeGraph > Geometry
Definition: Error_metric.h:74
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Filters::Error_metric::get_top_cost
double get_top_cost() const
Definition: Error_metric.h:117
FEVV::Filters::Error_metric::~Error_metric
virtual ~Error_metric()
Definition: Error_metric.h:98
FEVV::Filters::Error_metric::get_mean_threshold
double get_mean_threshold() const
Definition: Error_metric.h:119
FEVV::DataStructures::AIF::halfedge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor halfedge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns a halfedge with target v.
Definition: Graph_traits_aif.h:296
FEVV::DataStructures::AIF::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
FEVV::Filters::Error_metric::_vkept
Kept_position< HalfedgeGraph, PointMap > * _vkept
Definition: Error_metric.h:213
Geometry_traits.h
FEVV::Filters::Error_metric::get_top_queue
std::tuple< typename boost::graph_traits< HalfedgeGraph >::edge_descriptor, double, typename Geometry::Point > get_top_queue() const
Definition: Error_metric.h:114
FEVV::Filters::Error_metric::edge2cost_map
std::map< edge_descriptor, std::pair< double, Point > > edge2cost_map
Definition: Error_metric.h:85
FEVV::Filters::Error_metric::_dequantiz
FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap > & _dequantiz
Definition: Error_metric.h:215
FEVV::Filters::VKEPT_POSITION
VKEPT_POSITION
Definition: Parameters.h:28
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::Filters::Error_metric::edge_iterator
typename boost::graph_traits< HalfedgeGraph >::edge_iterator edge_iterator
Definition: Error_metric.h:69
FEVV::Filters::Error_metric::_operator
FEVV::Filters::VKEPT_POSITION _operator
Definition: Error_metric.h:211
FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap >
FEVV::Filters::Error_metric::edge_descriptor
typename boost::graph_traits< HalfedgeGraph >::edge_descriptor edge_descriptor
Definition: Error_metric.h:71
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Filters::Compare_weights2::operator()
bool operator()(const std::tuple< edge_descriptor, double, Point > &e1, const std::tuple< edge_descriptor, double, Point > &e2) const
Definition: Error_metric.h:43
FEVV::Filters::Error_metric::get_vkept
Kept_position< HalfedgeGraph, PointMap > * get_vkept()
Definition: Error_metric.h:196
FEVV::Filters::Error_metric::_gt
const Geometry _gt
Definition: Error_metric.h:205
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31