ndm  0.1.1
 All Classes Functions Variables Enumerations Pages
Space.cc
1 #include <vector>
2 #include "ndm.hh"
3 #include "Point.pb.h"
4 #include "Space.hh"
5 #include "Utils.hh"
6 namespace NDM {
9 {
10 }
13 
15 {
19 }
20 
21 void Space::print() const
22 {
26  for (auto a : mAxes) {
27  a.print();
28  }
29 }
30 
32 {
36  mAxes.push_back(axis);
37 }
38 
39 Axis & Space::axis(int id)
40 {
44  return mAxes.at(id);
45 }
46 
47 std::string Space::get_full_path(std::vector<std::string> & paths)
48 {
52  std::string fullPath, blank = "_";
53  int maxLength = 0;
54  for (auto a : paths) {
55  if (a.length() > maxLength) {
56  maxLength = a.length();
57  }
58  }
59  for (int iPathLevel = 0; iPathLevel < maxLength; iPathLevel++) {
60  for (int iPathAxis = 0; iPathAxis < paths.size(); iPathAxis++) {
61  paths.at(iPathAxis).resize(maxLength);
62  if (!paths.at(iPathAxis).at(iPathLevel)) {
63  fullPath += blank;
64  }
65  else
66  fullPath += paths.at(iPathAxis).at(iPathLevel);
67  if (iPathAxis == (mAxes.size() - 1)) fullPath += "/";
68  }
69  if (fullPath.back() != '/') fullPath += "/";
70  }
71  return std::move(fullPath);
72 }
73 
74 void Space::points(std::vector<int> levels, std::vector<NDM::Point> & point, int idAxis)
75 {
80  if (idAxis >= mAxes.size()) {
81  spdlog::error("idAxis cannot be more than total number of axes in space!!!");
82  }
83 
84  if (idAxis == 0 && mTmpMins.size() == 0) {
85  spdlog::trace("Space::points -> Init");
86  mTmpMins.resize(mAxes.size());
87  mTmpPaths.resize(mAxes.size());
88 
89  if (levels.size() != mAxes.size()) {
90  spdlog::error("Total number of levels must be equal to total number of axes!!!");
91  return;
92  }
93 
94  for (int iAxes = 0; iAxes < mAxes.size(); iAxes++) {
95  axis(iAxes).split(mTmpMins.at(iAxes), levels[iAxes]);
96  mTmpPoint.add_coordinates();
97  }
98  }
99 
100  NDM::Coordinate * c;
101  double min;
102  double max;
103  std::string path;
104 
105  for (auto m : mTmpMins[idAxis]) {
106  c = mTmpPoint.mutable_coordinates(idAxis);
107  mAxes[idAxis].find(m, min, max, path, levels.at(idAxis));
108  spdlog::trace("v[{}][{}] size[{}] min[{}], max[{}], path[{}]", idAxis, m, mTmpMins[idAxis].size(), min, max,
109  path);
110  // mAxes[idAxis].print();
111 
112  c->set_min(min);
113  c->set_max(max);
114  c->set_isbin(mAxes[idAxis].is_bin());
115  c->set_info(mAxes[idAxis].info());
116  mTmpPaths[idAxis] = path;
117  if (idAxis < (mAxes.size() - 1)) {
118  points(levels, point, idAxis + 1);
119  }
120  else if (idAxis == (mAxes.size() - 1)) {
121 
122  // fill point
123  mTmpPoint.set_path(get_full_path(mTmpPaths));
124  point.push_back(mTmpPoint);
125  // mTmpPoint.PrintDebugString();
126  }
127  else {
128  spdlog::error("Space::points -> idAxis[{}] is higher then number of axis '{}' !!!", idAxis, mAxes.size());
129  }
130  }
131 }
132 
133 void Space::find_point(std::vector<int> & coordinates, std::vector<int> & levels, NDM::Point & point)
134 {
138 
139  if (mTmpPaths.size() != coordinates.size()) {
140  mTmpPaths.resize(coordinates.size());
141  mTmpMins.resize(coordinates.size());
142  }
143 
144  double min, max;
145  NDM::Coordinate * c;
146  std::string path;
147  for (int iCoord = 0; iCoord < coordinates.size(); iCoord++) {
148 
149  mAxes[iCoord].split(mTmpMins.at(iCoord), levels[iCoord]);
150  if (point.coordinates_size() < coordinates.size()) {
151  c = point.add_coordinates();
152  }
153  c = point.mutable_coordinates(iCoord);
154 
155  mAxes[iCoord].find(mTmpMins[iCoord][coordinates[iCoord] - 1], min, max, path, levels.at(iCoord));
156  spdlog::trace("v[{}][{}] size[{}] min[{}], max[{}], path[{}]", iCoord,
157  mTmpMins[iCoord][coordinates[iCoord] - 1], mTmpMins[iCoord].size(), min, max, path);
158 
159  c->set_min(min);
160  c->set_max(max);
161  c->set_info(mAxes[iCoord].info());
162  mTmpPaths[iCoord] = path;
163  }
164  point.set_path(get_full_path(mTmpPaths));
165 
166 } // namespace NDM
167 
168 } // namespace NDM
void print() const
Definition: Space.cc:21
void split(std::vector< double > &mins, int level)
Definition: Axis.cc:266
void add(NDM::Axis a)
Definition: Space.cc:31
void points(std::vector< int > levels, std::vector< NDM::Point > &point, int idAxis=0)
Definition: Space.cc:74
Axis object in n-dimensional space.
Definition: Axis.hh:12
std::vector< std::string > mTmpPaths
Temporary vector storing generated paths for points.
Definition: Space.hh:39
virtual ~Space()
Default Destructor.
Definition: Space.cc:14
Point mTmpPoint
Temporary Point Object.
Definition: Space.hh:38
void find_point(std::vector< int > &coordinates, std::vector< int > &levels, NDM::Point &point)
Definition: Space.cc:133
Axis & axis(int id)
Definition: Space.cc:39
std::string get_full_path(std::vector< std::string > &paths)
Definition: Space.cc:47
std::vector< std::vector< double > > mTmpMins
Temporary vector storing value of minimums of axes.
Definition: Space.hh:37
Space()
Default Constructor.
Definition: Space.cc:8
std::vector< NDM::Axis > mAxes
Vector of axis to be used for space.
Definition: Space.hh:36