Helios++
Helios software for LiDAR simulations
PlatformSettings.h
1 #pragma once
2 
3 #include <Asset.h>
4 
5 #include <glm/glm.hpp>
6 
7 #include <sstream>
8 #include <memory>
9 #include <unordered_set>
10 #include <functional>
11 
12 
16 class PlatformSettings : public Asset {
17 public:
18  // *** ATTRIBUTES *** //
19  // ******************** //
25  std::string id = "#nullid#";
30  std::shared_ptr<PlatformSettings> baseTemplate = nullptr;
34  double x = 0;
38  double y = 0;
42  double z = 0;
50  double yawAtDeparture = 0.0;
51 
56  bool onGround = false;
61  bool stopAndTurn = true;
66  bool smoothTurn = false;
71  bool slowdownEnabled = true;
72 
73  // 100 meter per sec are 360 km/h:
77  double movePerSec_m = 70;
78 
79  // *** CONSTRUCTION / DESTRUCTION *** //
80  // ************************************ //
84  PlatformSettings() = default;
85 
91  if(other == nullptr) return;
92 
93  this->id = other->id;
94  this->baseTemplate = other->baseTemplate;
95  this->x = other->x;
96  this->y = other->y;
97  this->z = other->z;
98  this->yawAtDepartureSpecified = other->yawAtDepartureSpecified;
99  this->yawAtDeparture = other->yawAtDeparture;
100  this->onGround = other->onGround;
101  this->stopAndTurn = other->stopAndTurn;
102  this->smoothTurn = other->smoothTurn;
103  this->slowdownEnabled = other->slowdownEnabled;
104  this->movePerSec_m = other->movePerSec_m;
105  }
106 
107  // *** CHERRY PICKING *** //
108  // ************************ //
119  std::shared_ptr<PlatformSettings> cherryPick(
120  std::shared_ptr<PlatformSettings> cherries,
121  std::unordered_set<std::string> const &fields,
122  std::unordered_set<std::string> const *templateFields=nullptr
123  ){
124  // Prepare for cherry picking
125  std::shared_ptr<PlatformSettings> settings = \
126  std::make_shared<PlatformSettings>(this);
127  std::function<bool(std::string const&)> hasCherry = [&](
128  std::string const &fieldName
129  ) -> bool{
130  return fields.find(fieldName) != fields.end();
131  };
132  // The cherry picking itself
133  if(hasCherry("baseTemplate") && cherries->baseTemplate != nullptr){
134  std::shared_ptr<PlatformSettings> tmpTemplate = \
135  cherries->baseTemplate->baseTemplate;
136  cherries->baseTemplate->baseTemplate = nullptr;
137  settings = cherryPick(cherries->baseTemplate, *templateFields);
138  cherries->baseTemplate->baseTemplate = tmpTemplate;
139  settings->baseTemplate = cherries->baseTemplate;
140  }
141  if(hasCherry("x")) settings->x = cherries->x;
142  if(hasCherry("y")) settings->y = cherries->y;
143  if(hasCherry("z")) settings->z = cherries->z;
144  if(hasCherry("yawAtDepartureSpecified"))
145  settings->yawAtDepartureSpecified = \
146  cherries->yawAtDepartureSpecified;
147  if(hasCherry("yawAtDeparture"))
148  settings->yawAtDeparture = cherries->yawAtDeparture;
149  if(hasCherry("onGround")) settings->onGround = cherries->onGround;
150  if(hasCherry("stopAndTurn"))
151  settings->stopAndTurn = cherries->stopAndTurn;
152  if(hasCherry("smoothTurn"))
153  settings->smoothTurn = cherries->smoothTurn;
154  if(hasCherry("slowdownEnabled"))
155  settings->slowdownEnabled = cherries->slowdownEnabled;
156  if(hasCherry("movePerSec_m"))
157  settings->movePerSec_m = cherries->movePerSec_m;
158  // Return settings from cherry picking
159  return settings;
160  }
161 
162  // *** GETTERS and SETTERS *** //
163  // ***************************** //
168  glm::dvec3 getPosition() {
169  return glm::dvec3(x, y, z);
170  }
171 
176  void setPosition(glm::dvec3 dest) {
177  x = dest.x;
178  y = dest.y;
179  z = dest.z;
180  }
181  void setPosition(double const x, double const y, double const z){
182  this->x = x;
183  this->y = y;
184  this->z = z;
185  }
186 
194  bool hasTemplate() {return this->baseTemplate != nullptr;}
202 
203  // *** TO STRING *** //
204  // ******************* //
209  virtual inline std::string toString() const{
210  std::stringstream ss;
211  ss << "PlatformSettings \"" << id << "\":\n";
212  if(baseTemplate != nullptr){
213  ss << "\ttemplate.id = \"" << baseTemplate->id << "\"\n"
214  << "\ttemplate.x = " << baseTemplate->x << "\n"
215  << "\ttemplate.y = " << baseTemplate->y << "\n"
216  << "\ttemplate.z = " << baseTemplate->z << "\n"
217  << "\ttemplate.yawAtDepartureSpecified = "
218  << baseTemplate->yawAtDepartureSpecified << "\n"
219  << "\ttemplate.yawAtDeparture = "
220  << baseTemplate->yawAtDeparture << "\n"
221  << "\ttemplate.onGround = " << baseTemplate->onGround << "\n"
222  << "\ttemplate.stopAndTurn = " << baseTemplate->stopAndTurn
223  << "\n"
224  << "\ttemplate.smoothTurn = " << baseTemplate->smoothTurn
225  << "\n"
226  << "\ttemplate.slowdownEnabled = "
227  << baseTemplate->slowdownEnabled << "\n"
228  << "\ttemplate.movePerSec_m = " << baseTemplate->movePerSec_m
229  << "\n"
230  ;
231  }
232  ss << "x = " << x << "\n"
233  << "y = " << y << "\n"
234  << "z = " << z << "\n"
235  << "yawAtDepartureSpecified = " << yawAtDepartureSpecified << "\n"
236  << "yawAtDeparture = " << yawAtDeparture << "\n"
237  << "onGround = " << onGround << "\n"
238  << "stopAndTurn = " << stopAndTurn << "\n"
239  << "smoothTurn = " << smoothTurn << "\n"
240  << "slowdownEnabled = " << slowdownEnabled << "\n"
241  << "movePerSec_m = " << movePerSec_m << "\n"
242  ;
243  return ss.str();
244  }
248  friend std::ostream& operator<< (
249  std::ostream &out,
250  PlatformSettings const &settings
251  ){
252  out << settings.toString();
253  return out;
254  }
255 };
Base class for all assets.
Definition: Asset.h:10
Class representing platform settings.
Definition: PlatformSettings.h:16
bool slowdownEnabled
Slowdown enabled flag.
Definition: PlatformSettings.h:71
double movePerSec_m
Movement per seconds (in meters)
Definition: PlatformSettings.h:77
double z
Position z coordinate.
Definition: PlatformSettings.h:42
std::string id
The ID for this platform settings. It does not make sense for all platform settings,...
Definition: PlatformSettings.h:25
bool smoothTurn
Smooth turn.
Definition: PlatformSettings.h:66
PlatformSettings(PlatformSettings *other)
Copy from pointer constructor.
Definition: PlatformSettings.h:90
virtual std::string toString() const
Obtain the string representation of the scanner settings.
Definition: PlatformSettings.h:209
friend std::ostream & operator<<(std::ostream &out, PlatformSettings const &settings)
Overload of << operator for output streams.
Definition: PlatformSettings.h:248
double y
Position y coordinate.
Definition: PlatformSettings.h:38
PlatformSettings()=default
Platform settings default constructor.
bool stopAndTurn
Stop and turn flag.
Definition: PlatformSettings.h:61
void setPosition(glm::dvec3 dest)
Set position from 3D vector.
Definition: PlatformSettings.h:176
bool hasTemplate()
Check if this PlatformSettings has an associated template (true) or not (false)
Definition: PlatformSettings.h:194
std::shared_ptr< PlatformSettings > baseTemplate
Template defining default values which were used to build the PlatformSettings object.
Definition: PlatformSettings.h:30
double x
Position x coordinate.
Definition: PlatformSettings.h:34
PlatformSettings & getTemplate()
Obtain template by reference.
Definition: PlatformSettings.h:201
glm::dvec3 getPosition()
Obtain position as 3D vector.
Definition: PlatformSettings.h:168
bool yawAtDepartureSpecified
Flag.
Definition: PlatformSettings.h:46
std::shared_ptr< PlatformSettings > cherryPick(std::shared_ptr< PlatformSettings > cherries, std::unordered_set< std::string > const &fields, std::unordered_set< std::string > const *templateFields=nullptr)
Build a new platform settings which by default has the same values than caller platform settings (thi...
Definition: PlatformSettings.h:119
bool onGround
On ground flag.
Definition: PlatformSettings.h:56
double yawAtDeparture
Yaw angle (in radians) at platform departure.
Definition: PlatformSettings.h:50