SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSSimHelper Class Reference

#include <SENSSimHelper.h>

Public Member Functions

 SENSSimHelper (SENSGps *&gps, SENSOrientation *&orientation, SENSCamera *&camera, const std::string &simDataDir, std::function< void(void)> cameraParametersChangedCB)
 
 ~SENSSimHelper ()
 
bool startRecording ()
 
void stopRecording ()
 
void updateGpsRecording ()
 
void updateOrientationRecording ()
 
void updateCameraRecording ()
 
bool recorderIsRunning ()
 
void resetRecorder ()
 
bool getRecorderErrors (std::vector< std::string > &errorMsgs)
 
bool canSimGps ()
 
bool canSimOrientation ()
 
bool canSimCamera ()
 
void initSimulator (const std::string &simDataSet)
 
bool simIsRunning ()
 
void updateGpsSim ()
 
void updateOrientationSim ()
 
void updateCameraSim ()
 
bool getSimulatorErrors (std::vector< std::string > &errorMsgs)
 
void stopSim ()
 
void startSim ()
 
bool isPausedSim ()
 
void pauseSim ()
 
void resumeSim ()
 
SENSTimePt simTime ()
 
SENSMicroseconds passedSimTime ()
 
SENSGpsgps () const
 
SENSOrientationorientation () const
 
SENSCameracamera () const
 
const std::string & simDataDir () const
 

Public Attributes

bool recordGps = false
 
bool recordOrientation = false
 
bool recordCamera = false
 
bool simulateGps = false
 
bool simulateOrientation = false
 
bool simulateCamera = false
 

Private Member Functions

void restoreInputSensors ()
 
SENSRecorderrecorder ()
 

Private Attributes

std::unique_ptr< SENSSimulator_simulator
 
std::unique_ptr< SENSRecorder_recorder
 
SENSGps_gpsIn
 
SENSOrientation_orientationIn
 
SENSCamera_cameraIn
 
SENSGps *& _gpsRef
 
SENSOrientation *& _orientationRef
 
SENSCamera *& _cameraRef
 
std::string _simDataDir
 
std::function< void(void)> _cameraParametersChangedCB
 

Detailed Description

Definition at line 7 of file SENSSimHelper.h.

Constructor & Destructor Documentation

◆ SENSSimHelper()

SENSSimHelper::SENSSimHelper ( SENSGps *&  gps,
SENSOrientation *&  orientation,
SENSCamera *&  camera,
const std::string &  simDataDir,
std::function< void(void)>  cameraParametersChangedCB 
)

Definition at line 3 of file SENSSimHelper.cpp.

8  : _gpsIn(gps),
11  _gpsRef(gps),
15  _cameraParametersChangedCB(cameraParametersChangedCB)
16 {
20  Utils::log("SENSSimHelper", "Could not create simDataDir!");
21 }
SENSCamera * _cameraIn
Definition: SENSSimHelper.h:68
SENSOrientation *& _orientationRef
Definition: SENSSimHelper.h:71
SENSGps * _gpsIn
Definition: SENSSimHelper.h:66
SENSOrientation * orientation() const
Definition: SENSSimHelper.h:47
SENSGps * gps() const
Definition: SENSSimHelper.h:46
SENSCamera *& _cameraRef
Definition: SENSSimHelper.h:72
std::string _simDataDir
Definition: SENSSimHelper.h:74
SENSGps *& _gpsRef
Definition: SENSSimHelper.h:70
SENSCamera * camera() const
Definition: SENSSimHelper.h:48
SENSOrientation * _orientationIn
Definition: SENSSimHelper.h:67
std::function< void(void)> _cameraParametersChangedCB
Definition: SENSSimHelper.h:77
const std::string & simDataDir() const
Definition: SENSSimHelper.h:49
string unifySlashes(const string &inputDir, bool withTrailingSlash)
Returns the inputDir string with unified forward slashes, e.g.: "dirA/dirB/".
Definition: Utils.cpp:367
bool dirExists(const string &path)
Returns true if a directory exists.
Definition: Utils.cpp:789
bool makeDir(const string &path)
Creates a directory with given path.
Definition: Utils.cpp:809
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1100

◆ ~SENSSimHelper()

SENSSimHelper::~SENSSimHelper ( )

Definition at line 23 of file SENSSimHelper.cpp.

24 {
25  resetRecorder();
27 }
void restoreInputSensors()

Member Function Documentation

◆ camera()

SENSCamera* SENSSimHelper::camera ( ) const
inline

Definition at line 48 of file SENSSimHelper.h.

48 { return _cameraRef; }

◆ canSimCamera()

bool SENSSimHelper::canSimCamera ( )

Definition at line 172 of file SENSSimHelper.cpp.

173 {
174  if (_simulator && _simulator->getCameraSensorPtr())
175  return true;
176  else
177  return false;
178 }
std::unique_ptr< SENSSimulator > _simulator
Definition: SENSSimHelper.h:63

◆ canSimGps()

bool SENSSimHelper::canSimGps ( )

Definition at line 156 of file SENSSimHelper.cpp.

157 {
158  if (_simulator && _simulator->getGpsSensorPtr())
159  return true;
160  else
161  return false;
162 }

◆ canSimOrientation()

bool SENSSimHelper::canSimOrientation ( )

Definition at line 164 of file SENSSimHelper.cpp.

165 {
166  if (_simulator && _simulator->getOrientationSensorPtr())
167  return true;
168  else
169  return false;
170 }

◆ getRecorderErrors()

bool SENSSimHelper::getRecorderErrors ( std::vector< std::string > &  errorMsgs)

Definition at line 136 of file SENSSimHelper.cpp.

137 {
138  if (_recorder)
139  {
140  std::string gpsError;
141  if (_recorder->getGpsHandlerError(gpsError))
142  errorMsgs.emplace_back(gpsError);
143  std::string orientationError;
144  if (_recorder->getOrientationHandlerError(orientationError))
145  errorMsgs.emplace_back(orientationError);
146  std::string cameraError;
147  if (_recorder->getCameraHandlerError(cameraError))
148  errorMsgs.emplace_back(cameraError);
149 
150  return errorMsgs.size() != 0;
151  }
152  else
153  return false;
154 }
std::unique_ptr< SENSRecorder > _recorder
Definition: SENSSimHelper.h:64

◆ getSimulatorErrors()

bool SENSSimHelper::getSimulatorErrors ( std::vector< std::string > &  errorMsgs)

Definition at line 248 of file SENSSimHelper.cpp.

249 {
250  if (_simulator)
251  return _simulator->getSimulatorErrors(errorMsgs);
252  else
253  return false;
254 }

◆ gps()

SENSGps* SENSSimHelper::gps ( ) const
inline

Definition at line 46 of file SENSSimHelper.h.

46 { return _gpsRef; }

◆ initSimulator()

void SENSSimHelper::initSimulator ( const std::string &  simDataSet)

Definition at line 180 of file SENSSimHelper.cpp.

181 {
182  resetRecorder();
183  //stop running simulations
184  if (canSimGps() && simulateGps)
185  _simulator->getGpsSensorPtr()->stop();
187  _simulator->getOrientationSensorPtr()->stop();
188  if (canSimCamera() && simulateCamera)
189  _simulator->getCameraSensorPtr()->stop();
190 
191  simulateGps = false;
192  simulateOrientation = false;
193  simulateCamera = false;
197 
198  if (_simulator)
199  _simulator.reset();
200 
201  _simulator = std::make_unique<SENSSimulator>(_simDataDir + simDataSet);
202 }
bool canSimOrientation()
bool simulateOrientation
Definition: SENSSimHelper.h:56

◆ isPausedSim()

bool SENSSimHelper::isPausedSim ( )

Definition at line 306 of file SENSSimHelper.cpp.

307 {
308  if (_simulator && _simulator->isPaused())
309  return true;
310  else
311  return false;
312 }

◆ orientation()

SENSOrientation* SENSSimHelper::orientation ( ) const
inline

Definition at line 47 of file SENSSimHelper.h.

47 { return _orientationRef; }

◆ passedSimTime()

SENSMicroseconds SENSSimHelper::passedSimTime ( )

Definition at line 333 of file SENSSimHelper.cpp.

334 {
335  if (_simulator)
336  return _simulator->passedTime();
337  else
338  return SENSMicroseconds(0);
339 }
std::chrono::microseconds SENSMicroseconds
Definition: SENS.h:58

◆ pauseSim()

void SENSSimHelper::pauseSim ( )

Definition at line 314 of file SENSSimHelper.cpp.

315 {
316  if (_simulator)
317  _simulator->pause();
318 }

◆ recorder()

SENSRecorder * SENSSimHelper::recorder ( )
private

Definition at line 111 of file SENSSimHelper.cpp.

112 {
113  if (!_recorder)
114  _recorder = std::make_unique<SENSRecorder>(_simDataDir);
115  return _recorder.get();
116 }

◆ recorderIsRunning()

bool SENSSimHelper::recorderIsRunning ( )

Definition at line 118 of file SENSSimHelper.cpp.

119 {
120  if (_recorder)
121  return _recorder->isRunning();
122  else
123  return false;
124 }

◆ resetRecorder()

void SENSSimHelper::resetRecorder ( )

Definition at line 126 of file SENSSimHelper.cpp.

127 {
128  if (_recorder)
129  _recorder.reset();
130 
131  recordGps = false;
132  recordOrientation = false;
133  recordCamera = false;
134 }
bool recordOrientation
Definition: SENSSimHelper.h:52

◆ restoreInputSensors()

void SENSSimHelper::restoreInputSensors ( )
private

Definition at line 29 of file SENSSimHelper.cpp.

30 {
31  //restore input sensors and state
32  if (_gpsRef != _gpsIn)
33  {
34  if (_gpsRef && _gpsRef->isRunning())
35  _gpsRef->stop();
36  _gpsRef = _gpsIn;
37  }
38 
40  {
44  }
45 
46  if (_cameraRef != _cameraIn)
47  {
48  if (_cameraRef && _cameraRef->started())
49  _cameraRef->stop();
51  }
52 }
virtual bool started() const =0
virtual void stop()=0
Stop a started camera device.
bool isRunning()
Definition: SENSGps.h:32
virtual void stop()=0
virtual void stop()=0

◆ resumeSim()

void SENSSimHelper::resumeSim ( )

Definition at line 320 of file SENSSimHelper.cpp.

321 {
322  if (_simulator)
323  _simulator->resume();
324 }

◆ simDataDir()

const std::string& SENSSimHelper::simDataDir ( ) const
inline

Definition at line 49 of file SENSSimHelper.h.

49 { return _simDataDir; }

◆ simIsRunning()

bool SENSSimHelper::simIsRunning ( )

Definition at line 204 of file SENSSimHelper.cpp.

205 {
206  if (_simulator && _simulator->isRunning())
207  return true;
208  else
209  return false;
210 }

◆ simTime()

SENSTimePt SENSSimHelper::simTime ( )

Definition at line 326 of file SENSSimHelper.cpp.

327 {
328  if (_simulator)
329  return _simulator->now();
330  else
331  return SENSClock::now();
332 }

◆ startRecording()

bool SENSSimHelper::startRecording ( )

Definition at line 54 of file SENSSimHelper.cpp.

55 {
56  if (!_recorder)
57  return false;
58 
59  //sensors should have been activated before
60  return _recorder->start();
61 }

◆ startSim()

void SENSSimHelper::startSim ( )

Definition at line 269 of file SENSSimHelper.cpp.

270 {
271  //stop running sensors
272  stopSim();
273 
274  //start possible simulated sensors
275  if (canSimGps() && simulateGps)
276  {
277  _gpsRef = _simulator->getGpsSensorPtr();
278  _gpsRef->start();
279  }
280 
282  {
283  _orientationRef = _simulator->getOrientationSensorPtr();
285  }
286 
287  if (canSimCamera() && simulateCamera)
288  {
289  _cameraRef = _simulator->getCameraSensorPtr();
290  //there is only one prop:
291  const SENSCaptureProps& capProps = _cameraRef->captureProperties();
292  if (capProps.size())
293  {
294  const SENSCameraDeviceProps* currCamProps = &capProps.front();
295  auto streamConfig = currCamProps->streamConfigs().front();
296  //first start the camera, the intrinsic is valid afterwards
297  _cameraRef->start(currCamProps->deviceId(),
298  streamConfig,
299  true);
302  }
303  }
304 }
const std::string & deviceId() const
Definition: SENSCamera.h:85
const std::vector< SENSCameraStreamConfig > & streamConfigs() const
Definition: SENSCamera.h:84
virtual const SENSCameraConfig & start(std::string deviceId, const SENSCameraStreamConfig &streamConfig, bool provideIntrinsics=true)=0
virtual const SENSCaptureProps & captureProperties()=0
Get SENSCaptureProps which contains necessary information about all available camera devices and thei...
virtual bool start()=0
virtual bool start()=0

◆ stopRecording()

void SENSSimHelper::stopRecording ( )

Definition at line 63 of file SENSSimHelper.cpp.

64 {
65  if (_recorder)
66  _recorder->stop();
67 }

◆ stopSim()

void SENSSimHelper::stopSim ( )

Definition at line 256 of file SENSSimHelper.cpp.

257 {
258  //stop running sensors
259  if (_gpsRef && _gpsRef->isRunning())
260  _gpsRef->stop();
261 
264 
265  if (_cameraRef && _cameraRef->started())
266  _cameraRef->stop();
267 }

◆ updateCameraRecording()

void SENSSimHelper::updateCameraRecording ( )

Definition at line 97 of file SENSSimHelper.cpp.

98 {
99  if (recordCamera)
100  {
101  if (!recorder()->activateCamera(_cameraRef))
103  }
104  else
105  {
106  if (!recorder()->deactivateOrientation())
108  }
109 }
SENSRecorder * recorder()

◆ updateCameraSim()

void SENSSimHelper::updateCameraSim ( )

Definition at line 234 of file SENSSimHelper.cpp.

235 {
236  if (_cameraRef && _cameraRef->started())
237  _cameraRef->stop();
238 
239  if (canSimCamera() && simulateCamera)
240  _cameraRef = _simulator->getCameraSensorPtr();
241  else
243 
246 }

◆ updateGpsRecording()

void SENSSimHelper::updateGpsRecording ( )

Definition at line 69 of file SENSSimHelper.cpp.

70 {
71  if (recordGps)
72  {
73  if (!recorder()->activateGps(_gpsRef))
75  }
76  else
77  {
78  if (!recorder()->deactivateGps())
80  }
81 }

◆ updateGpsSim()

void SENSSimHelper::updateGpsSim ( )

Definition at line 212 of file SENSSimHelper.cpp.

213 {
214  if (_gpsRef && _gpsRef->isRunning())
215  _gpsRef->stop();
216 
217  if (canSimGps() && simulateGps)
218  _gpsRef = _simulator->getGpsSensorPtr();
219  else
220  _gpsRef = _gpsIn;
221 }

◆ updateOrientationRecording()

void SENSSimHelper::updateOrientationRecording ( )

Definition at line 83 of file SENSSimHelper.cpp.

84 {
86  {
87  if (!recorder()->activateOrientation(_orientationRef))
89  }
90  else
91  {
92  if (!recorder()->deactivateOrientation())
94  }
95 }

◆ updateOrientationSim()

void SENSSimHelper::updateOrientationSim ( )

Definition at line 223 of file SENSSimHelper.cpp.

224 {
227 
229  _orientationRef = _simulator->getOrientationSensorPtr();
230  else
232 }

Member Data Documentation

◆ _cameraIn

SENSCamera* SENSSimHelper::_cameraIn
private

Definition at line 68 of file SENSSimHelper.h.

◆ _cameraParametersChangedCB

std::function<void(void)> SENSSimHelper::_cameraParametersChangedCB
private

Definition at line 77 of file SENSSimHelper.h.

◆ _cameraRef

SENSCamera*& SENSSimHelper::_cameraRef
private

Definition at line 72 of file SENSSimHelper.h.

◆ _gpsIn

SENSGps* SENSSimHelper::_gpsIn
private

Definition at line 66 of file SENSSimHelper.h.

◆ _gpsRef

SENSGps*& SENSSimHelper::_gpsRef
private

Definition at line 70 of file SENSSimHelper.h.

◆ _orientationIn

SENSOrientation* SENSSimHelper::_orientationIn
private

Definition at line 67 of file SENSSimHelper.h.

◆ _orientationRef

SENSOrientation*& SENSSimHelper::_orientationRef
private

Definition at line 71 of file SENSSimHelper.h.

◆ _recorder

std::unique_ptr<SENSRecorder> SENSSimHelper::_recorder
private

Definition at line 64 of file SENSSimHelper.h.

◆ _simDataDir

std::string SENSSimHelper::_simDataDir
private

Definition at line 74 of file SENSSimHelper.h.

◆ _simulator

std::unique_ptr<SENSSimulator> SENSSimHelper::_simulator
private

Definition at line 63 of file SENSSimHelper.h.

◆ recordCamera

bool SENSSimHelper::recordCamera = false

Definition at line 53 of file SENSSimHelper.h.

◆ recordGps

bool SENSSimHelper::recordGps = false

Definition at line 51 of file SENSSimHelper.h.

◆ recordOrientation

bool SENSSimHelper::recordOrientation = false

Definition at line 52 of file SENSSimHelper.h.

◆ simulateCamera

bool SENSSimHelper::simulateCamera = false

Definition at line 57 of file SENSSimHelper.h.

◆ simulateGps

bool SENSSimHelper::simulateGps = false

Definition at line 55 of file SENSSimHelper.h.

◆ simulateOrientation

bool SENSSimHelper::simulateOrientation = false

Definition at line 56 of file SENSSimHelper.h.


The documentation for this class was generated from the following files: