MEPP2 Project
Delta_predictor.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 "Predictor.h"
15 
16 #include <vector>
17 #include <map>
18 
19 namespace FEVV {
20 namespace Filters {
21 
22 template<
23  typename HalfedgeGraph,
24  typename PointMap >
25 class Delta_predictor : public Predictor< HalfedgeGraph,
26  PointMap >
27 {
28 public:
32  typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor;
36 
39  Delta_predictor(HalfedgeGraph &_g,
41  PointMap &pm)
42  : Super_class(_g, kp, pm)
43  {
44  Super_class::_type = PREDICTION_TYPE::DELTA;
47  std::make_tuple< bool, bool, bool, bool >(false, false, false, false);
48  }
49 
50 
51  std::vector< Vector > compute_residuals(Collapse_info< HalfedgeGraph, PointMap > &mem) override
52  {
53  Point A = mem.get_pos_vt();
54  Point B = mem.get_pos_vs();
55 
56  if(mem.get_reverse())
57  {
58  Point save = A;
59  A = B;
60  B = save;
61  }
62  Apred = A;
63  Bpred = B;
64 
65  Vector delta = Super_class::_gt.sub_p(B, A);
66 
67  std::vector< Vector > residuals;
68  if(Super_class::_kp->get_type() == VKEPT_POSITION::MIDPOINT)
69  {
70  residuals = {delta};
71  }
72  if(Super_class::_kp->get_type() == VKEPT_POSITION::HALFEDGE)
73  {
74  residuals = {delta};
75  }
76  mem.record_error_prediction(residuals);
77  return residuals;
78  }
79 
80  std::pair< Point, Point > place_points(const std::vector< Vector > &residuals,
81  vertex_descriptor vkept,
82  halfedge_descriptor /*h1*/,
83  halfedge_descriptor /*h2*/) override
84  {
85  const Point& current_point = get(Super_class::_pm, vkept);
86 
87  Point p1, p2;
88  if(residuals.size() == 2)
89  { // Case of the optimized position along the edge.
90  // Should not occur in this work.
91  p1 = Super_class::_gt.add_pv(current_point, residuals[0]);
92  p2 = Super_class::_gt.add_pv(current_point, residuals[1]);
93  }
94  else
95  {
96  if(Super_class::_kp->get_type() == VKEPT_POSITION::MIDPOINT)
97  {
98  Vector D = residuals[0];
99  Vector DA = Super_class::_gt.scalar_mult(D, -0.5f);
100  auto&& tmp = Super_class::_gt.add_pv(Super_class::_gt.ORIGIN, DA);
101  DA = Vector(std::floor(Super_class::_gt.get_x(tmp)),
102  std::floor(Super_class::_gt.get_y(tmp)),
103  std::floor(Super_class::_gt.get_z(tmp)) );
104  Vector DB = Super_class::_gt.add_v(D, DA);
105 
106  p1 = Super_class::_gt.add_pv(current_point, DA);
107 
108  p2 = Super_class::_gt.add_pv(current_point, DB);
109  }
110  else
111  {
112 
113  if(!_rev)
114  {
115  p1 = current_point;
116  p2 = Super_class::_gt.add_pv(current_point, residuals[0]);
117  }
118  else
119  {
120  p1 = Super_class::_gt.sub_pv(current_point, residuals[0]);
121  p2 = current_point;
122  }
123  }
124  }
125 
126 
127  return std::make_pair(p1, p2);
128  }
129 
130 
131 
132 
133  const std::tuple< bool, bool, bool, bool >& get_midpoint() const
134  {
135  return _round_midpoint;
136  }
137  void set_bit_info(bool b1, bool b2, bool b3, bool b4)
138  {
139  _round_midpoint = std::make_tuple(b1, b2, b3, b4);
140  }
141  void set_rev(bool b) override { _rev = b; }
142 
143  std::string get_as_string() const override { return "delta"; }
144 
146 
147 private:
151  std::tuple< bool, bool, bool, bool > _round_midpoint;
154  std::map< vertex_descriptor, Vector > _vkept_to_other_residual;
155  bool _rev;
156 };
157 
158 
159 } // namespace Filters
160 } // namespace FEVV
FEVV::Filters::Delta_predictor::set_bit_info
void set_bit_info(bool b1, bool b2, bool b3, bool b4)
Definition: Delta_predictor.h:137
FEVV::Filters::Delta_predictor::set_rev
void set_rev(bool b) override
Definition: Delta_predictor.h:141
FEVV::Filters::Delta_predictor::Vector
typename FEVV::Geometry_traits< HalfedgeGraph >::Vector Vector
Definition: Delta_predictor.h:33
FEVV::Filters::Predictor::get_type
virtual FEVV::Filters::PREDICTION_TYPE get_type() const
Definition: Predictor.h:71
FEVV::Filters::Delta_predictor::~Delta_predictor
~Delta_predictor()
Definition: Delta_predictor.h:145
FEVV::Filters::Collapse_info::record_error_prediction
void record_error_prediction(const std::vector< Vector > &pred)
Definition: Collapse_info.h:144
FEVV::Filters::Delta_predictor::get_midpoint
const std::tuple< bool, bool, bool, bool > & get_midpoint() const
Definition: Delta_predictor.h:133
FEVV::Filters::Collapse_info::get_reverse
bool get_reverse() const
Definition: Collapse_info.h:106
FEVV::Filters::Predictor::_pm
PointMap & _pm
Definition: Predictor.h:88
FEVV::Filters::Collapse_info< HalfedgeGraph, PointMap >
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
FEVV::Filters::Delta_predictor::_rev
bool _rev
Definition: Delta_predictor.h:155
FEVV::Filters::Delta_predictor::get_as_string
std::string get_as_string() const override
Definition: Delta_predictor.h:143
FEVV::Filters::Delta_predictor::compute_residuals
std::vector< Vector > compute_residuals(Collapse_info< HalfedgeGraph, PointMap > &mem) override
Definition: Delta_predictor.h:51
FEVV::Filters::Delta_predictor::place_points
std::pair< Point, Point > place_points(const std::vector< Vector > &residuals, vertex_descriptor vkept, halfedge_descriptor, halfedge_descriptor) override
Decompression side: predicts a position from encoded residuals.
Definition: Delta_predictor.h:80
FEVV::Filters::Predictor
Abstract class used to predict position.
Definition: Predictor.h:35
FEVV::Filters::Delta_predictor::_round_midpoint
std::tuple< bool, bool, bool, bool > _round_midpoint
Definition: Delta_predictor.h:151
FEVV::Filters::Collapse_info::get_pos_vs
const Point & get_pos_vs() const
Get edge source vertex position.
Definition: Collapse_info.h:99
FEVV::Filters::Collapse_info::get_pos_vt
const Point & get_pos_vt() const
Get edge target vertex position.
Definition: Collapse_info.h:97
FEVV::Filters::Delta_predictor::Dpred
Vector Dpred
Definition: Delta_predictor.h:150
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::Predictor::_type
FEVV::Filters::PREDICTION_TYPE _type
Definition: Predictor.h:91
FEVV::Filters::Kept_position< HalfedgeGraph, PointMap >
FEVV::Filters::Delta_predictor::vertex_descriptor
typename boost::graph_traits< HalfedgeGraph >::vertex_descriptor vertex_descriptor
Definition: Delta_predictor.h:30
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
Predictor.h
FEVV::Filters::Delta_predictor::halfedge_descriptor
typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor halfedge_descriptor
Definition: Delta_predictor.h:32
FEVV::Filters::Delta_predictor::DApred
Vector DApred
Definition: Delta_predictor.h:149
FEVV::Filters::Delta_predictor::Super_class
Predictor< HalfedgeGraph, PointMap > Super_class
Definition: Delta_predictor.h:38
FEVV::Filters::Delta_predictor::Bpred
Point Bpred
Definition: Delta_predictor.h:148
FEVV::Filters::Delta_predictor::_source
Point _source
Definition: Delta_predictor.h:152
FEVV::Filters::Delta_predictor::DBpred
Vector DBpred
Definition: Delta_predictor.h:149
FEVV::Filters::Delta_predictor::Delta_predictor
Delta_predictor(HalfedgeGraph &_g, Kept_position< HalfedgeGraph, PointMap > *kp, PointMap &pm)
Definition: Delta_predictor.h:39
FEVV::Filters::Predictor::_gt
const Geometry _gt
Definition: Predictor.h:87
FEVV::Filters::Delta_predictor
Definition: Delta_predictor.h:27
FEVV::Filters::Delta_predictor::Geometry
typename FEVV::Geometry_traits< HalfedgeGraph > Geometry
Definition: Delta_predictor.h:35
FEVV::Filters::Delta_predictor::Apred
Point Apred
Definition: Delta_predictor.h:148
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Filters::Delta_predictor::_vkept_to_other_residual
std::map< vertex_descriptor, Vector > _vkept_to_other_residual
Definition: Delta_predictor.h:154
FEVV::Filters::Delta_predictor::Point
typename FEVV::Geometry_traits< HalfedgeGraph >::Point Point
Definition: Delta_predictor.h:34
FEVV::Filters::Predictor::_nbResiduals
int _nbResiduals
Definition: Predictor.h:89
FEVV::Filters::Predictor::_kp
Kept_position< HalfedgeGraph, PointMap > * _kp
Definition: Predictor.h:85
FEVV::Filters::Delta_predictor::_target
Point _target
Definition: Delta_predictor.h:153
FEVV::Filters::Predictor::_g
HalfedgeGraph & _g
Definition: Predictor.h:86