Helios++
Helios software for LiDAR simulations
DynScene.h
1 #pragma once
2 
3 #include <vector>
4 #include <memory>
5 
6 #include <scene/Scene.h>
7 #include <scene/StaticScene.h>
8 #include <scene/dynamic/DynObject.h>
9 #include <sim/tools/NonVoidStepLoop.h>
10 
11 using std::vector;
12 using std::shared_ptr;
13 
29 class DynScene : public StaticScene{
30 private:
31  // *** SERIALIZATION *** //
32  // *********************** //
33  friend class boost::serialization::access;
42  template <class Archive>
43  void serialize(Archive &ar, const unsigned int version){
44  boost::serialization::split_member(ar, *this, version);
45  }
51  template <class Archive>
52  void save(Archive &ar, const unsigned int version) const {
53  boost::serialization::void_cast_register<DynScene, StaticScene>();
54  ar &boost::serialization::base_object<StaticScene>(*this);
55  ar &dynObjs;
56  ar &updated;
58  }
64  template <class Archive>
65  void load(Archive &ar, const unsigned int version){
66  boost::serialization::void_cast_register<DynScene, StaticScene>();
67  ar &boost::serialization::base_object<StaticScene>(*this);
68  ar &dynObjs;
69  ar &updated;
70  int stepInterval;
71  ar &stepInterval;
72  stepLoop.setStepInterval(stepInterval);
73  }
74 
75 protected:
76  // *** ATTRIBUTES *** //
77  // ******************** //
81  vector<shared_ptr<DynObject>> dynObjs;
90  vector<bool> updated;
96 
97 public:
98  // *** CONSTRUCTION / DESTRUCTION *** //
99  // ************************************ //
103  DynScene(int const stepInterval=1) :
104  stepLoop(stepInterval, [&] () -> bool{return doStep();})
105  {}
106  ~DynScene() override {}
111  DynScene(DynScene &ds);
116  DynScene(Scene &s, int const stepInterval=1) :
117  StaticScene(s),
118  stepLoop(stepInterval, [&] () -> bool{return doStep();})
119  {}
124  DynScene(StaticScene &ss, int const stepInterval=1) :
125  StaticScene(ss),
126  stepLoop(stepInterval, [&] () -> bool{return doStep();})
127  {}
128 
129  // *** SIMULATION STEP *** //
130  // ************************* //
152  bool doSimStep() override;
161  bool doStep();
168  virtual void makeStepLoop(int const stepInterval);
169 
170  // *** GETTERs and SETTERs *** //
171  // ***************************** //
177  inline void appendDynObject(shared_ptr<DynObject> dynobj) {
178  dynObjs.push_back(dynobj);
179  updated.push_back(true);
180  }
186  inline shared_ptr<DynObject> getDynObject(size_t const index)
187  {return dynObjs[index];}
193  inline void setDynObject(size_t const index, shared_ptr<DynObject> dynobj){
194  dynObjs[index] = dynobj;
195  updated[index] = true;
196  }
201  inline void removeDynObject(size_t const index){
202  dynObjs.erase(dynObjs.begin()+index);
203  updated.erase(updated.begin()+index);
204  }
208  inline void clearDynObjects(){dynObjs.clear();}
213  inline size_t numDynObjects() {return dynObjs.size();}
221  inline bool isDynObjectUpdated(size_t const index) const
222  {return updated[index];}
228  inline int getStepInterval() const
229  {return stepLoop.getStepInterval();}
235  inline void setStepInterval(int const stepInterval)
236  {stepLoop.setStepInterval(stepInterval);}
237 
238 
239 
240 
241  // *** READ/WRITE *** //
242  // ********************* //
248  void writeObject(std::string path) override;
254  static DynScene *readObject(std::string path);
255 };
Dynamic scene base implementation.
Definition: DynScene.h:29
void clearDynObjects()
Remove all dynamic objects from the dynamic scene.
Definition: DynScene.h:208
void removeDynObject(size_t const index)
Remove dynamic object at given index.
Definition: DynScene.h:201
void setDynObject(size_t const index, shared_ptr< DynObject > dynobj)
Set dynamic object at given index.
Definition: DynScene.h:193
void setStepInterval(int const stepInterval)
Set the step interval for the dynamic scene.
Definition: DynScene.h:235
int getStepInterval() const
Obtain the current step interval for the dynamic scene.
Definition: DynScene.h:228
DynScene(Scene &s, int const stepInterval=1)
Build a dynamic scene using given scene as basis.
Definition: DynScene.h:116
void save(Archive &ar, const unsigned int version) const
Save a serialized DynScene to a stream of bytes.
Definition: DynScene.h:52
DynScene(int const stepInterval=1)
Dynamic scene default constructor.
Definition: DynScene.h:103
shared_ptr< DynObject > getDynObject(size_t const index)
Obtain dynamic object at given index.
Definition: DynScene.h:186
void appendDynObject(shared_ptr< DynObject > dynobj)
Append given dynamic object to the scene.
Definition: DynScene.h:177
void load(Archive &ar, const unsigned int version)
Load a serialized DynScene from a stream of bytes.
Definition: DynScene.h:65
vector< bool > updated
Vector of flags controlling whether a dynamic object has been updated after last step (true) or not.
Definition: DynScene.h:90
vector< shared_ptr< DynObject > > dynObjs
Dynamic objects composing the scene.
Definition: DynScene.h:81
size_t numDynObjects()
Obtain the number of dynamic objects in the scene.
Definition: DynScene.h:213
bool doStep()
Dynamic behavior computation itself.
Definition: DynScene.cpp:25
DynScene(StaticScene &ss, int const stepInterval=1)
Build a dynamic scene using given static scene as basis.
Definition: DynScene.h:124
void serialize(Archive &ar, const unsigned int version)
Serialize a DynScene to a stream of bytes.
Definition: DynScene.h:43
NonVoidStepLoop< bool > stepLoop
The step loop for the dynamic scene.
Definition: DynScene.h:95
bool isDynObjectUpdated(size_t const index) const
Check whether the dynamic object at given index has been updated on last step (true) or not (false)
Definition: DynScene.h:221
Class representing a scene asset.
Definition: Scene.h:28
Static scene basic implementation.
Definition: StaticScene.h:24
virtual int getStepInterval() const
Obtain the step interval.
Definition: StepLoop.h:108
virtual void setStepInterval(int const stepInterval)
Set the step interval.
Definition: StepLoop.h:114