ndm  0.1.2
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  if (levels.size() != mAxes.size()) {
88  spdlog::error("Total number of levels must be equal to total number of axes!!!");
89  return;
90  }
91 
92  for (int iAxes = 0; iAxes < mAxes.size(); iAxes++) {
93  axis(iAxes).split(mTmpMins.at(iAxes), levels[iAxes]);
94  mTmpPaths.push_back("");
95  mTmpPoint.add_coordinates();
96  }
97  }
98 
99  NDM::Coordinate * c;
100  double min;
101  double max;
102  std::string path;
103 
104  for (auto m : mTmpMins[idAxis]) {
105  c = mTmpPoint.mutable_coordinates(idAxis);
106  mAxes[idAxis].find(m, min, max, path, levels.at(idAxis));
107  spdlog::trace("v[{}][{}] size[{}] min[{}], max[{}], path[{}]", idAxis, m, mTmpMins[idAxis].size(), min, max, path);
108  // mAxes[idAxis].print();
109 
110  c->set_min(min);
111  c->set_max(max);
112  c->set_info(mAxes[idAxis].info());
113  mTmpPaths[idAxis] = path;
114  if (idAxis < (mAxes.size() - 1)) {
115  points(levels, point, idAxis + 1);
116  }
117  else if (idAxis == (mAxes.size() - 1)) {
118 
119  // fill point
120  mTmpPoint.set_path(get_full_path(mTmpPaths));
121  point.push_back(mTmpPoint);
122  // mTmpPoint.PrintDebugString();
123  }
124  else {
125  spdlog::error("Space::points -> idAxis[{}] is higher then number of axis '{}' !!!", idAxis, mAxes.size());
126  }
127  }
128 } // namespace NDM
129 
130 } // namespace NDM
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:37
virtual ~Space()
Default Destructor.
Definition: Space.cc:14
Point mTmpPoint
Temporary Point Object.
Definition: Space.hh:36
void print() const
Definition: Space.cc:21
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:35
Space()
Default Constructor.
Definition: Space.cc:8
std::vector< NDM::Axis > mAxes
Vector of axis to be used for space.
Definition: Space.hh:34