licornea_tools
references_grid.cc
Go to the documentation of this file.
1 #include "references_grid.h"
2 #include <algorithm>
3 
4 namespace tlz {
5 
6 view_index references_grid::view(std::ptrdiff_t col, std::ptrdiff_t row) const {
7  return view_index(x_indices.at(col), y_indices.at(row));
8 }
9 
10 
11 bool references_grid::has_view(const view_index& idx) const {
12  return std::any_of(x_indices.cbegin(), x_indices.cend(), [idx](const int& x){ return x == idx.x; })
13  && std::any_of(y_indices.cbegin(), y_indices.cend(), [idx](const int& y){ return y == idx.y; });
14 }
15 
16 
18  json j_grid = json::object();
19  j_grid["x_indices"] = grid.x_indices;
20  j_grid["y_indices"] = grid.y_indices;
21  return j_grid;
22 }
23 
24 
26  references_grid grid;
27  for(int x : j_grid["x_indices"]) grid.x_indices.push_back(x);
28  for(int y : j_grid["y_indices"]) grid.y_indices.push_back(y);
29  return grid;
30 }
31 
32 
34  references_grid grid;
35 
36  auto ref_vws = get_reference_views_set(cors);
37 
38  std::vector<int> ref_x_positions, ref_y_positions;
39  {
40  std::set<int> ref_x_positions_set, ref_y_positions_set;
41  for(const view_index& idx : ref_vws) {
42  ref_x_positions_set.insert(idx.x);
43  ref_y_positions_set.insert(idx.y);
44  }
45  for(int x : ref_x_positions) grid.x_indices.push_back(x);
46  for(int y : ref_y_positions) grid.y_indices.push_back(y);
47  }
48 
49  for(int row = 0; row < grid.rows(); ++row)
50  for(int col = 0; col < grid.cols(); ++col) {
51  view_index ref_idx = grid.view(col, row);
52  if(ref_vws.find(ref_idx) == ref_vws.end())
53  throw std::runtime_error("reference views are not arranged in a grid");
54  }
55 
56  return grid;
57 }
58 
59 
62 }
63 
64 
65 }
references_grid decode_references_grid(const json &j_grid)
Set of features, each on set of views.
references_grid references_grid_arg()
json encode_references_grid(const references_grid &grid)
json json_arg()
Definition: json.h:34
bool has_view(const view_index &) const
std::vector< int > y_indices
std::vector< int > x_indices
view_index view(std::ptrdiff_t col, std::ptrdiff_t row) const
std::set< view_index > get_reference_views_set(const image_correspondences &cors)
std::size_t cols() const
references_grid get_references_grid(const image_correspondences &cors)
nlohmann::json json
Definition: json.h:11
std::size_t rows() const