cost.cpp
Go to the documentation of this file.
1 
4 #include "cost.h"
5 #include "debug.h"
6 
7 namespace librealsense {
8 namespace algo {
9 namespace depth_to_rgb_calibration {
10 
11 
12  std::vector< double > calc_cost_per_vertex(
13  std::vector<double> const & d_vals,
14  z_frame_data const & z_data,
15  yuy2_frame_data const & yuy_data,
16  std::function< void( size_t i, double d_val, double weight, double vertex_cost ) > fn
17  )
18  {
19  double cost = 0;
20  std::vector< double > cost_per_vertex(d_vals.size());
21 
22  for (size_t i = 0; i < z_data.weights.size(); i++)
23  {
24  double d_val = d_vals[i]; // may be std::numeric_limits<double>::max()?
25  double weight = z_data.weights[i];
26  double cost = d_val;
27  if (d_val != std::numeric_limits<double>::max())
28  cost = d_val * weight;
29 
30  cost_per_vertex[i] = cost;
31  fn(i, d_val, weight, cost);
32 
33  }
34  return cost_per_vertex;
35  }
36 
37  double calc_cost_per_vertex_diff(z_frame_data const & z_data, yuy2_frame_data const & yuy_data, const uvmap_t & uvmap_old, const uvmap_t & uvmap_new)
38  {
39  //old
40  auto d_vals_old = biliniar_interp(yuy_data.edges_IDT, yuy_data.width, yuy_data.height, uvmap_old);
41 
42  auto cost_per_vertex_old = calc_cost_per_vertex(d_vals_old, z_data, yuy_data,
43  [&](size_t i, double d_val, double weight, double vertex_cost) {});
44 
45  //new
46  auto d_vals_new = biliniar_interp(yuy_data.edges_IDT, yuy_data.width, yuy_data.height, uvmap_new);
47 
48  auto cost_per_vertex_new = calc_cost_per_vertex(d_vals_new, z_data, yuy_data,
49  [&](size_t i, double d_val, double weight, double vertex_cost) {});
50 
51  double diff = 0;
52  auto num = 0;
53  for (auto i = 0; i < cost_per_vertex_new.size(); i++)
54  {
55  if (cost_per_vertex_old[i] != std::numeric_limits<double>::max() &&
56  cost_per_vertex_new[i] != std::numeric_limits<double>::max())
57  {
58  diff += cost_per_vertex_old[i] - cost_per_vertex_new[i];
59  num++;
60  }
61  }
62  return diff / num;
63  }
64 
65  std::vector<double> calc_cost_per_vertex(z_frame_data const & z_data, yuy2_frame_data const & yuy_data,
66  const uvmap_t & uvmap)
67  {
68  auto d_vals = biliniar_interp(yuy_data.edges_IDT, yuy_data.width, yuy_data.height, uvmap);
69 
70  return calc_cost_per_vertex(d_vals, z_data, yuy_data,
71  [&](size_t i, double d_val, double weight, double vertex_cost)
72  {});
73  }
74 
75  double calc_cost(
76  const z_frame_data & z_data,
77  const yuy2_frame_data & yuy_data,
78  const std::vector< double2 > & uv,
79  std::vector< double > * p_interpolated_edges // = nullptr
80  )
81  {
82  double cost = 0;
83  size_t N = 0;
84 
85  auto d_vals = biliniar_interp(yuy_data.edges_IDT, yuy_data.width, yuy_data.height, uv);
86 
87  auto cost_per_vertex = calc_cost_per_vertex(d_vals, z_data, yuy_data,
88  [&]( size_t i, double d_val, double weight, double vertex_cost )
89  {
90  if( d_val != std::numeric_limits<double>::max() )
91  {
92  cost += vertex_cost;
93  ++N;
94  }
95  } );
96  if( p_interpolated_edges )
97  *p_interpolated_edges = d_vals;
98  return N ? cost / N : 0.;
99  }
100 
101 
102 }
103 }
104 }
std::vector< double2 > uvmap_t
Definition: uvmap.h:22
std::vector< double > calc_cost_per_vertex(std::vector< double > const &d_vals, z_frame_data const &z_data, yuy2_frame_data const &yuy_data, std::function< void(size_t i, double d_val, double weight, double vertex_cost) > fn)
Definition: cost.cpp:12
GLuint GLuint GLfloat weight
Definition: glext.h:10534
GLuint num
Definition: glext.h:5648
std::vector< double > biliniar_interp(std::vector< double > const &vals, size_t width, size_t height, uvmap_t const &uv)
Definition: uvmap.cpp:76
double calc_cost_per_vertex_diff(z_frame_data const &z_data, yuy2_frame_data const &yuy_data, const uvmap_t &uvmap_old, const uvmap_t &uvmap_new)
Definition: cost.cpp:37
double calc_cost(const z_frame_data &z_data, const yuy2_frame_data &yuy_data, const std::vector< double2 > &uv, std::vector< double > *p_interpolated_edges)
Definition: cost.cpp:75
int i


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12