Helios++
Helios software for LiDAR simulations
PyHeliosSimulation.h
1 #pragma once
2 #ifdef PYTHON_BINDING
3 
4 #include <string>
5 #include <Leg.h>
6 #include <SurveyPlayback.h>
7 #include <memory>
8 #include <noise/RandomnessGenerator.h>
9 #include <PyPlatformWrapper.h>
10 #include <PySceneWrapper.h>
11 #include <PyHeliosOutputWrapper.h>
12 #include <PyHeliosException.h>
13 #include <XmlSurveyLoader.h>
14 #include <PyScannerWrapper.h>
15 
16 namespace pyhelios{
17 
25 private:
26  // *** ATTRIBUTES *** //
27  // ******************** //
28  std::shared_ptr<XmlSurveyLoader> xmlreader = nullptr;
29  bool started = false;
30  bool paused = false;
31  bool stopped = false;
32  bool finished = false;
33  size_t numThreads = 0;
34  size_t callbackFrequency = 0;
35  std::string surveyPath = "NULL";
36  std::string assetsPath = "NULL";
37  std::string outputPath = "NULL";
38  std::shared_ptr<Survey> survey = nullptr;
39  std::shared_ptr<SurveyPlayback> playback = nullptr;
40  boost::thread * thread = nullptr;
41  std::shared_ptr<PySimulationCycleCallback> callback = nullptr;
42  std::string fixedGpsTimeStart = "";
43  bool lasOutput = false;
44  bool las10 = false;
45  bool zipOutput = false;
46  bool splitByChannel = false;
47  double lasScale = 0.0001;
48  std::shared_ptr<PulseThreadPoolInterface> pulseThreadPool;
49  int kdtFactory = 4;
50  size_t kdtJobs = 0;
51  size_t kdtSAHLossNodes = 32;
52  int parallelizationStrategy = 1;
53  int chunkSize = 32;
54  int warehouseFactor = 1;
55 public:
56  bool finalOutput = true;
57  bool exportToFile = true;
58 
59  // *** CONSTRUCTION / DESTRUCTION *** //
60  // ************************************ //
61  PyHeliosSimulation() = default;
72  std::string surveyPath,
73  std::string assetsPath = "assets/",
74  std::string outputPath = "output/",
75  size_t numThreads = 0,
76  bool lasOutput = false,
77  bool las10 = false,
78  bool zipOutput = false,
79  bool splitByChannel = false,
80  int kdtFactory = 4,
81  size_t kdtJobs = 0,
82  size_t kdtSAHLossNodes = 32,
83  int parallelizationStrategy = 1,
84  int chunkSize = 32,
85  int warehouseFactor = 1
86  );
87  virtual ~PyHeliosSimulation();
88 
89  // *** GETTERS and SETTERS *** //
90  // ***************************** //
96  bool isStarted() {return started;}
102  bool isPaused() {return paused;}
108  bool isStopped() {return stopped;}
114  bool isFinished();
120  bool isRunning();
126  std::string getSurveyPath() {return surveyPath;}
132  std::string getAssetsPath() {return assetsPath;}
133 
139  Survey & getSurvey() {return *survey;}
146  {return new PyScannerWrapper(*survey->scanner);}
153  {return new PyPlatformWrapper(*survey->scanner->platform);}
154  PySceneWrapper * getScene()
155  {return new PySceneWrapper(*survey->scanner->platform->scene);}
161  int getNumLegs() {return survey->legs.size();}
167  Leg & getLeg(int index) {return *(survey->legs[index]);}
173  void removeLeg(int index)
174  {survey->legs.erase(survey->legs.begin() + index);}
181  Leg & newLeg(int index);
187  PyScanningStripWrapper * newScanningStrip(std::string const &stripId);
202  size_t getCallbackFrequency() {return callbackFrequency;}
207  size_t getSimFrequency() {return playback->getSimFrequency();}
213  {return _getDynScene()->getStepInterval();}
219  size_t getNumThreads() {return this->numThreads;}
223  void setNumThreads(size_t numThreads) {this->numThreads = numThreads;}
227  void setCallbackFrequency(size_t const callbackFrequency)
228  {this->callbackFrequency = callbackFrequency;}
232  void setSimFrequency(size_t const simFrequency)
233  {playback->setSimFrequency(simFrequency);}
238  void setDynSceneStep(size_t const stepInterval)
239  {return _getDynScene()->setStepInterval(stepInterval);}
243  void setCallback(PyObject * pyCallback);
248  playback->callback = nullptr;
249  survey->scanner->cycleMeasurements = nullptr;
250  survey->scanner->cycleMeasurementsMutex = nullptr;
251  }
252  std::string getFixedGpsTimeStart(){return fixedGpsTimeStart;}
253  void setFixedGpsTimeStart(std::string const fixedGpsTimeStart)
254  {this->fixedGpsTimeStart = fixedGpsTimeStart;}
255  bool getLasOutput(){return lasOutput;}
256  void setLasOutput(double lasOutput_){
257  if(started) throw PyHeliosException(
258  "Cannot modify LAS output flag for already started simulations."
259  );
260  this->lasOutput = lasOutput_;
261  }
262 
263  bool getLas10(){return las10;}
264  void setLas10(double las10_){
265  if(started) throw PyHeliosException(
266  "Cannot modify LAS v1.0 output flag for already started "
267  "simulations."
268  );
269  this->las10 = las10_;
270  }
271 
272  bool getZipOutput(){return zipOutput;}
273  void setZipOutput(bool zipOutput_){
274  if(started) throw PyHeliosException(
275  "Cannot modify ZIP output flag for already started simulations."
276  );
277  this->zipOutput = zipOutput_;
278  }
279  bool getSplitByChannel(){return splitByChannel;}
280  void setSplitByChannel(bool splitByChannel_){
281  if(started) throw PyHeliosException(
282  "Cannot modify splitByChannel flag for already started "
283  "simulations."
284  );
285  this->splitByChannel = splitByChannel_;
286  }
287 
288  double getLasScale(){return lasScale;}
289  void setLasScale(double const lasScale){
290  if(started) throw PyHeliosException(
291  "Cannot modify LAS scale for already started simulations."
292  );
293  this->lasScale = lasScale;
294  }
295 
296  int getKDTFactory(){return kdtFactory;}
297  void setKDTFactory(int kdtFactory){
298  if(started) throw PyHeliosException(
299  "Cannot modify KDT factory for already started simulations."
300  );
301  this->kdtFactory = kdtFactory;
302  }
303 
304  size_t getKDTJobs(){return kdtJobs;}
305  void setKDTJobs(size_t kdtJobs){
306  if(started) throw PyHeliosException(
307  "Cannot modify KDT jobs for already started simulations."
308  );
309  this->kdtJobs = kdtJobs;
310  }
311 
312  size_t getKDTSAHLossNodes(){return kdtSAHLossNodes;}
313  void setKDTSAHLossNodes(size_t kdtSAHLossNodes){
314  if(started) throw PyHeliosException(
315  "Cannot modify KDT SAH loss nodes for already started simulations."
316  );
317  this->kdtSAHLossNodes = kdtSAHLossNodes;
318  }
319 
320  int getParallelizationStrategy(){return parallelizationStrategy;}
321  void setParallelizationStrategy(int parallelizationStrategy){
322  if(started) throw PyHeliosException(
323  "Cannot modify parallelization strategy for already started "
324  "simulations."
325  );
326  this->parallelizationStrategy = parallelizationStrategy;
327  }
328 
329  int getChunkSize(){return chunkSize;}
330  void setChunkSize(int chunkSize){
331  if(started) throw PyHeliosException(
332  "Cannot modify chunk size for already started simulations."
333  );
334  this->chunkSize = chunkSize;
335  }
336 
337  int getWarehouseFactor(){return warehouseFactor;}
338  void setWarehouseFactor(int warehouseFactor){
339  if(started) throw PyHeliosException(
340  "Cannot modify warehouse factor for already started simulations."
341  );
342  this->warehouseFactor = warehouseFactor;
343  }
344 
345 
346 
347  // *** CONTROL FUNCTIONS *** //
348  // *************************** //
353  void start();
358  void pause();
363  void stop();
368  void resume();
372  PyHeliosOutputWrapper * join();
373 
374  // *** SIMULATION CONFIGURATION FUNCTIONS *** //
375  // ******************************************** //
385  void loadSurvey(
386  bool legNoiseDisabled = false,
387  bool rebuildScene = false,
388  bool writeWaveform = false,
389  bool calcEchowidth = false,
390  bool fullWaveNoise = false,
391  bool platformNoiseDisabled = true
392  );
393  void addRotateFilter(
394  double q0,
395  double q1,
396  double q2,
397  double q3,
398  std::string partId
399  );
400  void addScaleFilter(double scaleFactor, std::string partId);
401  void addTranslateFilter(double x, double y, double z, std::string partId);
407  void buildPulseThreadPool();
408 
409  // *** SIMULATION COPY *** //
410  // ************************* //
411  PyHeliosSimulation * copy();
412 
413  // *** INTERNAL USE *** //
414  // ********************** //
418  std::shared_ptr<DynScene> _getDynScene();
419 };
420 
421 }
422 
423 #endif
Class representing a survey leg.
Definition: Leg.h:17
Class representing a Helios++ survey.
Definition: Survey.h:13
Definition: PyHeliosSimulation.h:24
std::string getAssetsPath()
Obtain the path to assets directory used by the simulation.
Definition: PyHeliosSimulation.h:132
PyScannerWrapper * getScanner()
Obtain the scanner used by the simulation.
Definition: PyHeliosSimulation.h:145
PyScanningStripWrapper * newScanningStrip(std::string const &stripId)
Create a new empty scanning strip (with no legs)
Definition: PyHeliosSimulation.cpp:79
Leg & getLeg(int index)
Obtain leg at given index.
Definition: PyHeliosSimulation.h:167
int getNumLegs()
Obtain the number of legs.
Definition: PyHeliosSimulation.h:161
bool isStarted()
Check if the simulation has been started or not.
Definition: PyHeliosSimulation.h:96
void resume()
Resume the simulation if possible. Otherwise, PyHeliosException will be thrown.
Definition: PyHeliosSimulation.cpp:189
bool isStopped()
Check if the simulation has been stopped or not.
Definition: PyHeliosSimulation.h:108
void loadSurvey(bool legNoiseDisabled=false, bool rebuildScene=false, bool writeWaveform=false, bool calcEchowidth=false, bool fullWaveNoise=false, bool platformNoiseDisabled=true)
Load a survey XML file.
Definition: PyHeliosSimulation.cpp:273
PyPlatformWrapper * getPlatform()
Obtain the platform used by the simulation.
Definition: PyHeliosSimulation.h:152
std::string getSurveyPath()
Obtain the survey path used by the simulation.
Definition: PyHeliosSimulation.h:126
void setSimFrequency(size_t const simFrequency)
Set the simulation frequency.
Definition: PyHeliosSimulation.h:232
bool isFinished()
Check if the simulation has finished or not.
Definition: PyHeliosSimulation.cpp:209
bool isRunning()
Check if the simulation is running or not.
Definition: PyHeliosSimulation.cpp:213
size_t getDynSceneStep()
Get the step interval for the dynamic scene. Notice this method will throw an exception if the scene ...
Definition: PyHeliosSimulation.h:212
void setDynSceneStep(size_t const stepInterval)
Set the step interval for the dynamic scene. Notice this method will throw an exception if the scene ...
Definition: PyHeliosSimulation.h:238
Leg & newLeg(int index)
Create a new empty leg.
Definition: PyHeliosSimulation.cpp:67
void buildPulseThreadPool()
Build the pulse thread pool to be used by the simulation.
Definition: PyHeliosSimulation.cpp:325
bool assocLegWithScanningStrip(Leg &leg, PyScanningStripWrapper *strip)
Associate given leg with given strip.
Definition: PyHeliosSimulation.cpp:87
PyHeliosOutputWrapper * join()
Cause caller thread to wait until simulation has finished.
Definition: PyHeliosSimulation.cpp:218
bool isPaused()
Check if the simulation has been paused or not.
Definition: PyHeliosSimulation.h:102
size_t getNumThreads()
Obtain the number of threads.
Definition: PyHeliosSimulation.h:219
void start()
Start the simulation if possible. Otherwise, PyHeliosException will be thrown.
Definition: PyHeliosSimulation.cpp:110
void removeLeg(int index)
Remove leg at given index.
Definition: PyHeliosSimulation.h:173
void clearCallback()
Clear simulation callback so it will no longer be invoked.
Definition: PyHeliosSimulation.h:247
std::shared_ptr< DynScene > _getDynScene()
Obtain scene as DynScene if possible.
Definition: PyHeliosSimulation.cpp:387
Survey & getSurvey()
Obtain the survey used by the simulation.
Definition: PyHeliosSimulation.h:139
void setCallbackFrequency(size_t const callbackFrequency)
Set the callback frequency.
Definition: PyHeliosSimulation.h:227
void stop()
Stop the simulation if possible. Otherwise, PyHeliosException will be thrown.
Definition: PyHeliosSimulation.cpp:174
size_t getSimFrequency()
Obtain simulation frequency.
Definition: PyHeliosSimulation.h:207
void setNumThreads(size_t numThreads)
Set the number of threads.
Definition: PyHeliosSimulation.h:223
size_t getCallbackFrequency()
Obtain callback frequency.
Definition: PyHeliosSimulation.h:202
void pause()
Pause the simulation if possible. Otherwise, PyHeliosException will be thrown.
Definition: PyHeliosSimulation.cpp:159
void setCallback(PyObject *pyCallback)
Set the simulation callback to specified python object functor.
Definition: PyHeliosSimulation.cpp:362
Wrapper for Platform class.
Definition: PyPlatformWrapper.h:14
Wrapper for Scanner class.
Definition: PyScannerWrapper.h:28
Wrapper for ScanningStrip class.
Definition: PyScanningStripWrapper.h:17
Wrapper for Scene.
Definition: PySceneWrapper.h:26