MEPP2 Project
Volume_preserving.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 #include "Error_metric.h"
14 
15 namespace FEVV {
16 namespace Filters {
17 
20 template<
21  typename HalfedgeGraph,
22  typename PointMap>
23 class Volume_preserving : public Error_metric< HalfedgeGraph, PointMap >
24 {
25 public:
26  using edge_iterator =
27  typename boost::graph_traits< HalfedgeGraph >::edge_iterator;
29  typename boost::graph_traits< HalfedgeGraph >::edge_descriptor;
33 
35 
36  Volume_preserving(HalfedgeGraph &g,
37  PointMap &pm,
40  : Super_class(g, pm, vkept, dequantiz){}
41 
43 
44  void compute_error() override
45  {
46  if(!Super_class::_queue.empty())
47  {
48  typename Super_class::priority_queue_edges empty2;
49  std::swap(Super_class::_queue, empty2);
50  }
52  typename Super_class::edge2cost_map empty;
53  std::swap(Super_class::_edges_cost, empty);
54  if(Super_class::_edges_cost.empty())
55  {
56  auto edge_iterator_pair = edges(Super_class::_g);
57  auto edge_ite = edge_iterator_pair.first;
58  int count = 0;
60  for( ; edge_ite != edge_iterator_pair.second;
61  ++edge_ite)
62  {
63  Point collapsePos = Super_class::_vkept->compute_position(*edge_ite);
64 
65  double weight = compute_cost_edge(*edge_ite, collapsePos);
66  Super_class::_threshold += weight;
67  ++count;
68 
70  std::make_tuple(*edge_ite, weight, collapsePos));
71  Super_class::_edges_cost.emplace(*edge_ite,
72  std::make_pair(weight, collapsePos));
73  }
74  Super_class::_threshold /= count;
75  }
76  };
77 
78  double compute_cost_edge(edge_descriptor e, const Point &collapsePos) override
79  {
80  double sum_first_vertex=0., sum_second_vertex=0.;
81  compute_volumes(e, collapsePos, sum_first_vertex, sum_second_vertex);
82 
83  return (sum_first_vertex + sum_second_vertex);
84  }
85  std::string get_as_string() const override
86  {
87  return "volumepreserving";
88  }
89  private:
90  double tetrahedron_volume(const Point &a,
91  const Point &b,
92  const Point &c,
93  const Point &d) const
94  {
97  Super_class::_gt.sub_p(d, a))) / 6.0; // this calculus has been validated onto several
98  // tetrahedra using the above commented source code
99  };
100  void compute_volumes(edge_descriptor e, const Point &collapsePos, double& sum_first_vertex, double& sum_second_vertex)
101  {
102  auto current_halfedge = halfedge(e, Super_class::_g);
103  boost::iterator_range<
104  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
105  iterator_range = CGAL::halfedges_around_target(target(current_halfedge, Super_class::_g), Super_class::_g);
106  sum_first_vertex = 0.;
107  for(auto h : iterator_range)
108  {
109  if((h == current_halfedge) ||
110  (prev(opposite(h, Super_class::_g), Super_class::_g) == current_halfedge) ||
111  CGAL::is_border(opposite(h, Super_class::_g),
112  Super_class::_g)) // when volume calculus is not possible
113  // we ignore it
114  {
115  continue;
116  }
119  const Point& c = get(Super_class::_pm, target(current_halfedge, Super_class::_g));
120 
121  sum_first_vertex += tetrahedron_volume(a, b, c, collapsePos);
122  }
123  iterator_range =
124  CGAL::halfedges_around_target(source(current_halfedge, Super_class::_g), Super_class::_g);
125  sum_second_vertex = 0.;
126  for(auto h : iterator_range)
127  {
128  if((h == opposite(current_halfedge, Super_class::_g)) ||
129  (prev(opposite(h, Super_class::_g), Super_class::_g) == opposite(current_halfedge, Super_class::_g)) ||
130  (CGAL::is_border(opposite(h, Super_class::_g), Super_class::_g)))
131  {
132  continue;
133  }
136  const Point& c = get(Super_class::_pm, source(current_halfedge, Super_class::_g));
137 
138  sum_second_vertex +=
140  b,
141  c,
142  collapsePos);
143  }
144  }
145 };
146 } // namespace Filters
147 } // namespace FEVV
FEVV::Filters::Volume_preserving::compute_volumes
void compute_volumes(edge_descriptor e, const Point &collapsePos, double &sum_first_vertex, double &sum_second_vertex)
Definition: Volume_preserving.h:100
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::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
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::Filters::Error_metric::Point
typename FEVV::Geometry_traits< HalfedgeGraph >::Point Point
Definition: Error_metric.h:73
FEVV::Filters::Volume_preserving::Super_class
Error_metric< HalfedgeGraph, PointMap > Super_class
Definition: Volume_preserving.h:34
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::Volume_preserving::Volume_preserving
Volume_preserving(HalfedgeGraph &g, PointMap &pm, Kept_position< HalfedgeGraph, PointMap > *vkept, FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap > &dequantiz)
Definition: Volume_preserving.h:36
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::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
FEVV::Filters::Error_metric::_g
HalfedgeGraph & _g
Definition: Error_metric.h:204
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::Filters::Volume_preserving::compute_error
void compute_error() override
Definition: Volume_preserving.h:44
FEVV::Math::Vector::cross_product
static std::vector< ElementType > cross_product(const ElementType v1[DIM], const ElementType v2[DIM])
Definition: MatrixOperations.hpp:460
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::Error_metric::Vector
typename FEVV::Geometry_traits< HalfedgeGraph >::Vector Vector
Definition: Error_metric.h:72
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::Volume_preserving::get_as_string
std::string get_as_string() const override
Definition: Volume_preserving.h:85
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
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::edge_iterator
typename boost::graph_traits< HalfedgeGraph >::edge_iterator edge_iterator
Definition: Error_metric.h:69
FEVV::Filters::Volume_preserving::~Volume_preserving
~Volume_preserving()
Definition: Volume_preserving.h:42
FEVV::DataStructures::AIF::prev
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor prev(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the previous halfedge around its face.
Definition: Graph_traits_aif.h:612
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
FEVV::Filters::fabs
double fabs(const v_Curv< HalfedgeGraph > &input)
Definition: curvature.hpp:54
FEVV::Filters::Volume_preserving::tetrahedron_volume
double tetrahedron_volume(const Point &a, const Point &b, const Point &c, const Point &d) const
Definition: Volume_preserving.h:90
FEVV::Filters::Volume_preserving::compute_cost_edge
double compute_cost_edge(edge_descriptor e, const Point &collapsePos) override
Definition: Volume_preserving.h:78
FEVV::Filters::Volume_preserving
Concrete class to compute the collapse cost of each edge in a mesh as the local absolute volume error...
Definition: Volume_preserving.h:24
FEVV::Filters::Error_metric::_gt
const Geometry _gt
Definition: Error_metric.h:205
FEVV::Math::Vector::dot_product
static ElementType dot_product(const ElementType v1[DIM], const ElementType v2[DIM])
Compute v1 * v2 scalar product.
Definition: MatrixOperations.hpp:421