MEPP2 Project
Edge_length_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 "Error_metric.h"
15 #include <iostream>
16 
17 namespace FEVV {
18 namespace Filters {
19 
22 template<
23  typename HalfedgeGraph,
24  typename PointMap >
25 class Edge_length_metric : public Error_metric< HalfedgeGraph, PointMap >
26 {
27 
28 public:
29  using edge_iterator =
30  typename boost::graph_traits< HalfedgeGraph >::edge_iterator;
32  typename boost::graph_traits< HalfedgeGraph >::edge_descriptor;
36 
38  Edge_length_metric(HalfedgeGraph &g,
39  PointMap &pm,
42  : Super_class(g, pm, vkept, dequantiz)
43  {
44  Super_class::_operator = FEVV::Filters::VKEPT_POSITION::MIDPOINT;
45  }
46 
48 
49  void compute_error() override
50  {
51  if(!Super_class::_queue.empty())
52  {
53  typename Super_class::priority_queue_edges empty2;
54  std::swap(Super_class::_queue, empty2);
55  }
57  typename Super_class::edge2cost_map empty;
58  std::swap(Super_class::_edges_cost, empty);
59  if(Super_class::_edges_cost.empty())
60  {
61  auto edge_iterator_pair = edges(Super_class::_g);
62  auto edge_ite = edge_iterator_pair.first;
63  int count = 0;
65  for( ; edge_ite != edge_iterator_pair.second; ++edge_ite)
66  {
67  Point collapsePos = Super_class::_vkept->compute_position(*edge_ite);
68 
69  double weight = compute_cost_edge(*edge_ite,collapsePos);
70 
71  Super_class::_threshold += weight;
72  count++;
73 
75  std::make_tuple(*edge_ite, weight, collapsePos));
76  Super_class::_edges_cost.emplace(*edge_ite,
77  std::make_pair(weight,collapsePos));
78  }
79 
80  Super_class::_threshold /= count;
81  }
82  }
83 
84  double compute_cost_edge(edge_descriptor e, const Point &/*collapsePos*/) override
85  {
88  return Super_class::_gt.length(Super_class::_gt.sub_p(P1, P0));
89  }
90 
91  std::string get_as_string() const override { return "edgelength";}
92 };
93 
94 
95 } // namespace Filters
96 } // namespace FEVV
FEVV::Filters::Error_metric::_queue
priority_queue_edges _queue
Definition: Error_metric.h:208
FEVV::Filters::Edge_length_metric::get_as_string
std::string get_as_string() const override
Definition: Edge_length_metric.h:91
FEVV::Filters::Error_metric::_threshold
double _threshold
Definition: Error_metric.h:214
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::_pm
PointMap & _pm
Definition: Error_metric.h:206
FEVV::DataStructures::AIF::edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator > edges(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the edges of the mesh.
Definition: Graph_traits_aif.h:238
FEVV::Filters::Edge_length_metric::Vector
typename FEVV::Geometry_traits< HalfedgeGraph >::Vector Vector
Definition: Edge_length_metric.h:33
Error_metric.h
FEVV::GeometryTraits::sub_p
GeometryTraits::Vector sub_p(const typename GeometryTraits::Point &p1, const typename GeometryTraits::Point &p2)
Returns point P1 minus point P2.
Definition: Geometry_traits_operators.h:62
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::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
FEVV::Filters::Error_metric::_g
HalfedgeGraph & _g
Definition: Error_metric.h:204
FEVV::Filters::Edge_length_metric::~Edge_length_metric
~Edge_length_metric()
Definition: Edge_length_metric.h:47
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::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::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV::Filters::Kept_position::compute_position
virtual Point compute_position(typename boost::graph_traits< HalfedgeGraph >::edge_descriptor edge)=0
Compute the kept vertex position of an edge.
FEVV::Filters::Kept_position< HalfedgeGraph, PointMap >
FEVV::Filters::Edge_length_metric::edge_iterator
typename boost::graph_traits< HalfedgeGraph >::edge_iterator edge_iterator
Definition: Edge_length_metric.h:30
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
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
FEVV::Filters::Edge_length_metric::Super_class
Error_metric< HalfedgeGraph, PointMap > Super_class
Definition: Edge_length_metric.h:37
FEVV::Filters::Edge_length_metric
Concrete class to compute the collapse cost of each edge in a mesh as the edge length (L2).
Definition: Edge_length_metric.h:26
FEVV::Filters::Error_metric::edge2cost_map
std::map< edge_descriptor, std::pair< double, Point > > edge2cost_map
Definition: Error_metric.h:85
FEVV::Filters::Edge_length_metric::Point
typename FEVV::Geometry_traits< HalfedgeGraph >::Point Point
Definition: Edge_length_metric.h:34
FEVV::Filters::Edge_length_metric::Edge_length_metric
Edge_length_metric(HalfedgeGraph &g, PointMap &pm, Kept_position< HalfedgeGraph, PointMap > *vkept, FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap > &dequantiz)
Definition: Edge_length_metric.h:38
FEVV::Filters::Error_metric::_operator
FEVV::Filters::VKEPT_POSITION _operator
Definition: Error_metric.h:211
FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap >
FEVV::Filters::Edge_length_metric::edge_descriptor
typename boost::graph_traits< HalfedgeGraph >::edge_descriptor edge_descriptor
Definition: Edge_length_metric.h:32
FEVV::Filters::Edge_length_metric::compute_error
void compute_error() override
Definition: Edge_length_metric.h:49
FEVV::Filters::Error_metric::_gt
const Geometry _gt
Definition: Error_metric.h:205
FEVV::Filters::Edge_length_metric::Geometry
typename FEVV::Geometry_traits< HalfedgeGraph > Geometry
Definition: Edge_length_metric.h:35
FEVV::Filters::Edge_length_metric::compute_cost_edge
double compute_cost_edge(edge_descriptor e, const Point &) override
Definition: Edge_length_metric.h:84