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

Encapsulation of a mobile device location set by the device's GPS sensor. More...

#include <SLDeviceLocation.h>

Public Member Functions

 SLDeviceLocation ()
 
void init ()
 
void onLocationLatLonAlt (SLdouble latDEG, SLdouble lonDEG, SLdouble altM, SLfloat accuracyM)
 Event handler for mobile device location update. More...
 
SLbool calculateSolarAngles (SLVec3d locationLatLonAlt, std::time_t time)
 Calculates the solar angles at origin at local time. More...
 
SLVec3d convertLatLonAlt2ENU (SLVec3d locLatLonAlt) const
 Converter method: the transferred wgs84 coordinate is converted to ENU frame and returned (does not change SLDeviceLocation) More...
 
void isUsed (SLbool isUsed)
 Setter that turns on the device rotation sensor. More...
 
void useOriginAltitude (SLbool useGLA)
 
void improveOrigin (SLbool impO)
 
void hasOrigin (SLbool hasOL)
 
void originLatLonAlt (int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
 Origin coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds. More...
 
void originLatLonAlt (SLdouble latDEG, SLdouble lonDEG, SLdouble altM)
 Set global origin in latitude, longitude and altitude at the ground level. More...
 
void originLatLonAlt (SLVec3d lla)
 
void defaultLatLonAlt (int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
 Default coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds. More...
 
void defaultLatLonAlt (SLdouble latDEG, SLdouble lonDEG, SLdouble altM)
 Sets the default location in latitude, longitude and altitude. More...
 
void defaultLatLonAlt (SLVec3d lla)
 
void locMaxDistanceM (SLfloat maxDist)
 
void sunLightNode (SLLightDirect *sln)
 
void loadGeoTiff (const SLstring &geoTiffFile)
 Loads a GeoTiff DEM (Digital Elevation Model) Image. More...
 
bool geoTiffIsAvailableAndValid () const
 
bool posIsOnGeoTiff (SLdouble latDEG, SLdouble lonDEG) const
 Return true if the current GPS location is within the GeoTiff boundaries. More...
 
void cameraHeightM (float camHeightM)
 
void offsetMode (SLLocOffsetMode lom)
 
void offsetENU (SLVec3d offsetENU)
 
void activeNamedLocation (SLint locIndex)
 
SLbool isUsed () const
 
SLVec3d locLatLonAlt () const
 
SLVec3d locECEF () const
 
SLVec3d locENU () const
 
SLfloat locAccuracyM () const
 
SLfloat locMaxDistanceM () const
 
SLVec3d defaultENU () const
 
SLVec3d originLatLonAlt () const
 
SLVec3d defaultLatLonAlt () const
 
SLVec3d originENU () const
 
SLVec3d offsetENU () const
 
SLbool hasOrigin () const
 
SLbool useOriginAltitude () const
 
SLMat3d wRecef () const
 
SLfloat improveTime ()
 
SLfloat originSolarZenit () const
 
SLfloat originSolarAzimut () const
 
SLfloat originSolarSunrise () const
 
SLfloat originSolarSunset () const
 
SLNodesunLightNode () const
 
SLfloat altDemM () const
 
SLfloat altGpsM () const
 
SLfloat cameraHeightM () const
 
SLLocOffsetMode offsetMode ()
 
SLstring offsetModeStr () const
 Returns the device location offset mode as string. More...
 
SLVLocationnameLocations ()
 
SLint activeNamedLocation () const
 

Private Attributes

SLbool _isUsed
 Flag if the devices GPS Sensor is used. More...
 
SLbool _isFirstSensorValue
 Flag for the first sensor values. More...
 
SLVec3d _locLatLonAlt
 Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid. More...
 
SLVec3d _locECEF
 Cartesian location in ECEF. More...
 
SLVec3d _locENU
 Cartesian location in ENU frame. More...
 
SLfloat _locAccuracyM
 Horizontal accuracy radius in m with 68% probability. More...
 
SLfloat _locMaxDistanceM
 Max. allowed distance from origin. If higher it is ignored. More...
 
SLVec3d _defaultLatLonAlt
 Default location of scene in LatLonAlt. More...
 
SLVec3d _defaultENU
 Default location in ENU frame used if real location is too far away from origin. More...
 
SLVec3d _originLatLonAlt
 Global origin location of scene in LatLonAlt. More...
 
SLVec3d _originENU
 Origin location in ENU frame. More...
 
SLVec3d _offsetENU
 Offset vector in ENU frame. More...
 
SLfloat _originAccuracyM
 Accuracy radius of origin point. More...
 
SLfloat _originSolarZenith
 Zenith angle of the sun in deg. (from up dir.) at origin at local time. More...
 
SLfloat _originSolarAzimuth
 Azimuth angle of the sun in deg. (eastward from north) at origin at local time. More...
 
SLfloat _originSolarSunrise
 Sunrise local time at origin. More...
 
SLfloat _originSolarSunset
 Sunset local time at origin. More...
 
SLbool _hasOrigin
 Flag if this scene has a global reference location. More...
 
SLbool _useOriginAltitude
 Flag if global reference altitude should be used. More...
 
SLfloat _altDemM
 Altitude in m from Digital Elevation Model. More...
 
SLfloat _altGpsM
 Altitude in m from GPS. More...
 
SLfloat _cameraHeightM
 Height from ground to the mobile camera in m. More...
 
SLbool _improveOrigin
 Flag if origin should be improved over time & accuracy. More...
 
SLfloat _improveTimeSEC
 Max. time in seconds for the origin improvement. More...
 
HighResTimer _improveTimer
 Timer to measure the improve time. More...
 
SLMat3d _wRecef
 ECEF frame to world frame rotation: rotates a point defined in ecef. More...
 
SLNode_sunLightNode
 Pointer to directional light node to be changed if solar angles are calculated. More...
 
CVImageGeoTiff _demGeoTiff
 Digital Elevation Model from a Geo Tiff image. More...
 
SLLocOffsetMode _offsetMode
 Location offset mode. More...
 
SLVLocation _nameLocations
 Vector of fix locations for default view points. More...
 
SLint _activeNamedLocation
 Index of the active named location as defaultENU;. More...
 

Detailed Description

Encapsulation of a mobile device location set by the device's GPS sensor.

This class is only used if SLProject runs on a mobile device. Check out the app-demo/android and app_demo_slproject/ios how the sensor data is generated and passed to this object hold by AppCommon. The class stores the devices location that it gets from its GPS (global positioning system) sensor. The device location can be used in the active camera to apply it to the scene camera (s. SLCamera::setView).

  • LatLonAlt: The device location from GPS comes as a latitude (deg. north-south), longitude (deg. east-west) and altitude (m) LatLonAlt-tripple. These two angles are a position and height on the WGS84 ellipsoid (World Geodetic System 1984).
  • ECEF (Earth Centered Earth Fixed) are right-handed cartesian world coordinates with the z-axis at the north pole the x-axis at the prime meridian (0 deg. longitude) and the y-axis at 90 deg. longitude. x- and y-axis form the equator plane.
  • ENU (East North Up) is the local frame (= right-handed coordinate system) on the surface of the ellipsoid with the E=East tangential vector, the N=North tangential vector and U=Up as the ellipsoid's normal vector. Be aware that the up vector is normal to the ellipsoid and not to the terrain above. This normal does not point the center of the ellipsoid.
    If we want to show a local scene on the earth, we do this always in the ENU frame because in the ECEF frame with have not enough precision for float coordinates. Therefore we have define a local origin in the ENU frame and convert all locations from LatLonAlt to ECEF and the with the wRecef rotation matrix to the ENU frame.

Definition at line 86 of file SLDeviceLocation.h.

Constructor & Destructor Documentation

◆ SLDeviceLocation()

SLDeviceLocation::SLDeviceLocation ( )
inline

Definition at line 89 of file SLDeviceLocation.h.

89 { init(); }

Member Function Documentation

◆ activeNamedLocation() [1/2]

SLint SLDeviceLocation::activeNamedLocation ( ) const
inline

Definition at line 169 of file SLDeviceLocation.h.

169 { return _activeNamedLocation; }
SLint _activeNamedLocation
Index of the active named location as defaultENU;.

◆ activeNamedLocation() [2/2]

void SLDeviceLocation::activeNamedLocation ( SLint  locIndex)
inline

Definition at line 135 of file SLDeviceLocation.h.

136  {
137  _activeNamedLocation = locIndex;
138  _isUsed = false;
139  defaultLatLonAlt(_nameLocations[locIndex].posWGS84LatLonAlt);
140  }
SLVLocation _nameLocations
Vector of fix locations for default view points.
SLVec3d defaultLatLonAlt() const
SLbool _isUsed
Flag if the devices GPS Sensor is used.

◆ altDemM()

SLfloat SLDeviceLocation::altDemM ( ) const
inline

Definition at line 163 of file SLDeviceLocation.h.

163 { return _altDemM; }
SLfloat _altDemM
Altitude in m from Digital Elevation Model.

◆ altGpsM()

SLfloat SLDeviceLocation::altGpsM ( ) const
inline

Definition at line 164 of file SLDeviceLocation.h.

164 { return _altGpsM; }
SLfloat _altGpsM
Altitude in m from GPS.

◆ calculateSolarAngles()

SLbool SLDeviceLocation::calculateSolarAngles ( SLVec3d  locationLatLonAlt,
std::time_t  time 
)

Calculates the solar angles at origin at local time.

Calculates the zenith and azimuth angle in deg. of the sun at the origin at the local time using the Solar Position Algorithm from: https://midcdmz.nrel.gov/spa/ that is part of libsl_external.

Definition at line 265 of file SLDeviceLocation.cpp.

267 {
268  // leave default angles if origin has not been set
269  if (!_hasOrigin) return false;
270 
271  // transform time
272  tm ut{}, lt{};
273  memcpy(&ut, std::gmtime(&time), sizeof(tm));
274  memcpy(&lt, std::localtime(&time), sizeof(tm));
275 
276  ut.tm_year += 1900;
277  lt.tm_year += 1900;
278  ut.tm_mon++;
279  lt.tm_mon++;
280 
281  SL_LOG_DEBUG("Universal time : %02d.%02d.%02d %02d:%02d:%02d",
282  ut.tm_mday,
283  ut.tm_mon,
284  ut.tm_year,
285  ut.tm_hour,
286  ut.tm_min,
287  ut.tm_sec);
288  SL_LOG_DEBUG("Local time : %02d.%02d.%02d %02d:%02d:%02d",
289  lt.tm_mday,
290  lt.tm_mon,
291  lt.tm_year,
292  lt.tm_hour,
293  lt.tm_min,
294  lt.tm_sec);
295  SL_LOG_DEBUG("Timezone : %d", lt.tm_hour - ut.tm_hour);
296 
297  spa_data spa; // declare the SPA structure
298  SLint result;
299 
300  // enter required input values into SPA structure
301  spa.year = lt.tm_year;
302  spa.month = lt.tm_mon;
303  spa.day = lt.tm_mday;
304  spa.hour = lt.tm_hour;
305  spa.minute = lt.tm_min;
306  spa.second = lt.tm_sec;
307  spa.timezone = lt.tm_hour - ut.tm_hour;
308  spa.delta_ut1 = 0;
309  spa.delta_t = 0;
310  spa.longitude = locationLatLonAlt.lon;
311  spa.latitude = locationLatLonAlt.lat;
312  spa.elevation = locationLatLonAlt.alt;
313  // http://systemdesign.ch/wiki/Barometrische_Hoehenformel
314  spa.pressure = 1013.25 * pow((1.0 - 0.0065 * locationLatLonAlt.alt / 288.15), 5.255);
315  spa.temperature = 15.0;
316  spa.slope = 0;
317  spa.azm_rotation = 0;
318  spa.atmos_refract = 0.5667;
319  spa.function = SPA_ALL;
320 
321  /////////////////////////////
322  result = spa_calculate(&spa);
323  /////////////////////////////
324 
325  if (result == 0) // check for SPA errors
326  {
327  _originSolarZenith = (SLfloat)spa.zenith;
328  _originSolarAzimuth = (SLfloat)spa.azimuth;
329  _originSolarSunrise = (SLfloat)spa.sunrise;
330  _originSolarSunset = (SLfloat)spa.sunset;
331 
333  SLfloat SRm = (SLfloat)(60.0f * (SRh - (int)(SRh)));
334  SLfloat SRs = (SLfloat)(60.0 * (SRm - floor(SRm)));
336  SLfloat SSm = (SLfloat)(60.0f * (SSh - (int)(SSh)));
337  SLfloat SSs = (SLfloat)(60.0f * (SSm - floor(SSm)));
338 
339  SL_LOG_DEBUG("Zenith : %.6f degrees", _originSolarZenith);
340  SL_LOG_DEBUG("Azimuth : %.6f degrees", _originSolarAzimuth);
341  SL_LOG_DEBUG("Sunrise : %02d:%02d:%02d Local Time", (int)(SRh), (int)SRm, (int)SRs);
342  SL_LOG_DEBUG("Sunset : %02d:%02d:%02d Local Time", (int)(SSh), (int)SSm, (int)SSs);
343  }
344  else
345  SL_LOG_DEBUG("SPA Error Code: %d", result);
346 
347  if (_sunLightNode)
348  {
349  // The azimuth is from north eastwards
351 
352  // The zenith angle is from up downwards
354  }
355 
356  return (result == 0);
357 }
float SLfloat
Definition: SL.h:173
#define SL_LOG_DEBUG(...)
Definition: SL.h:237
int SLint
Definition: SL.h:170
SLfloat _originSolarAzimuth
Azimuth angle of the sun in deg. (eastward from north) at origin at local time.
SLfloat _originSolarSunset
Sunset local time at origin.
SLNode * _sunLightNode
Pointer to directional light node to be changed if solar angles are calculated.
SLfloat _originSolarZenith
Zenith angle of the sun in deg. (from up dir.) at origin at local time.
SLbool _hasOrigin
Flag if this scene has a global reference location.
SLfloat _originSolarSunrise
Sunrise local time at origin.
void rotation(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:846
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
T lat
Definition: SLVec3.h:45
static SLVec3 AXISY
Definition: SLVec3.h:298
T alt
Definition: SLVec3.h:45
static SLVec3 AXISX
Definition: SLVec3.h:297
T lon
Definition: SLVec3.h:45
T floor(T a)
Definition: Utils.h:246

◆ cameraHeightM() [1/2]

SLfloat SLDeviceLocation::cameraHeightM ( ) const
inline

Definition at line 165 of file SLDeviceLocation.h.

165 { return _cameraHeightM; };
SLfloat _cameraHeightM
Height from ground to the mobile camera in m.

◆ cameraHeightM() [2/2]

void SLDeviceLocation::cameraHeightM ( float  camHeightM)
inline

Definition at line 132 of file SLDeviceLocation.h.

132 { _cameraHeightM = camHeightM; }

◆ convertLatLonAlt2ENU()

SLVec3d SLDeviceLocation::convertLatLonAlt2ENU ( SLVec3d  locLatLonAlt) const

Converter method: the transferred wgs84 coordinate is converted to ENU frame and returned (does not change SLDeviceLocation)

Definition at line 360 of file SLDeviceLocation.cpp.

361 {
364 
365  // Convert to cartesian ECEF coordinates
368 
369  // Transform to local east-north-up frame
371 
372  return locENU;
373 }
float getAltitudeAtLatLon(double lat, double lon) const
Returns the altitude in m at the given position in WGS84 latitude-longitude.
SLVec3d locLatLonAlt() const
bool posIsOnGeoTiff(SLdouble latDEG, SLdouble lonDEG) const
Return true if the current GPS location is within the GeoTiff boundaries.
CVImageGeoTiff _demGeoTiff
Digital Elevation Model from a Geo Tiff image.
bool geoTiffIsAvailableAndValid() const
SLVec3d locECEF() const
SLMat3d _wRecef
ECEF frame to world frame rotation: rotates a point defined in ecef.
SLVec3d locENU() const
void latlonAlt2ecef(const SLVec3 &latDegLonDegAltM)
Latitude Longitude Altitude (LatLonAlt) to Earth Centered Earth Fixed (ecef) using the WGS84 model.
Definition: SLVec3.h:269
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

◆ defaultENU()

SLVec3d SLDeviceLocation::defaultENU ( ) const
inline

Definition at line 149 of file SLDeviceLocation.h.

149 { return _defaultENU; }
SLVec3d _defaultENU
Default location in ENU frame used if real location is too far away from origin.

◆ defaultLatLonAlt() [1/4]

SLVec3d SLDeviceLocation::defaultLatLonAlt ( ) const
inline

Definition at line 151 of file SLDeviceLocation.h.

151 { return _defaultLatLonAlt; }
SLVec3d _defaultLatLonAlt
Default location of scene in LatLonAlt.

◆ defaultLatLonAlt() [2/4]

void SLDeviceLocation::defaultLatLonAlt ( int  degreesLat,
int  minutesLat,
double  secondsLat,
int  degreesLon,
int  minutesLon,
double  secondsLon,
double  altitudeM 
)

Default coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.

Definition at line 204 of file SLDeviceLocation.cpp.

211 {
212  SLVec3d defaultWGS84Decimal = SLAlgo::geoDegMinSec2Decimal(degreesLat,
213  minutesLat,
214  secondsLat,
215  degreesLon,
216  minutesLon,
217  secondsLon,
218  altitudeM);
219  defaultLatLonAlt(defaultWGS84Decimal.lat,
220  defaultWGS84Decimal.lon,
221  defaultWGS84Decimal.alt);
222 }
T geoDegMinSec2Decimal(int degrees, int minutes, T seconds)
convert geodetic datum defined in degrees, minutes and seconds to decimal
Definition: SLAlgo.cpp:45

◆ defaultLatLonAlt() [3/4]

void SLDeviceLocation::defaultLatLonAlt ( SLdouble  latDEG,
SLdouble  lonDEG,
SLdouble  altM 
)

Sets the default location in latitude, longitude and altitude.

It must be called after setting the origin. If no origin is set with it will be automatically set in onLocationLatLonAlt. The default location is used by the camera in SLCamera::setView if the current distance between _locENU and _originENU is greater than _locMaxDistanceM. Witch means that you are in real not near the location. /param latDEG Latitude (vertical) on WGS84 geoid in degrees /param lonDEG Longitude (horizontal) on WGS84 geoid in degrees /param altM Altitude over WGS84 geoid in meters

Definition at line 234 of file SLDeviceLocation.cpp.

237 {
238  _defaultLatLonAlt.set(latDEG,
239  lonDEG,
242 
243  // Convert to cartesian ECEF coordinates
244  SLVec3d defaultECEF;
245  defaultECEF.latlonAlt2ecef(_defaultLatLonAlt);
246 
247  // Transform to local east-north-up frame
248  _defaultENU = _wRecef * defaultECEF;
249 }
SLVec3d _locLatLonAlt
Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid.
SLVec3d _originLatLonAlt
Global origin location of scene in LatLonAlt.
SLbool _useOriginAltitude
Flag if global reference altitude should be used.
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59

◆ defaultLatLonAlt() [4/4]

void SLDeviceLocation::defaultLatLonAlt ( SLVec3d  lla)
inline

Definition at line 126 of file SLDeviceLocation.h.

126 { defaultLatLonAlt(lla.lat, lla.lon, lla.alt); }

◆ geoTiffIsAvailableAndValid()

bool SLDeviceLocation::geoTiffIsAvailableAndValid ( ) const

◆ hasOrigin() [1/2]

SLbool SLDeviceLocation::hasOrigin ( ) const
inline

Definition at line 154 of file SLDeviceLocation.h.

154 { return _hasOrigin; }

◆ hasOrigin() [2/2]

void SLDeviceLocation::hasOrigin ( SLbool  hasOL)

Definition at line 52 of file SLDeviceLocation.cpp.

53 {
54  if (!hasOrigin)
55  {
57  _originAccuracyM = FLT_MAX;
58  }
60 }
void start()
Definition: HighResTimer.h:35
SLfloat _originAccuracyM
Accuracy radius of origin point.
SLbool hasOrigin() const
HighResTimer _improveTimer
Timer to measure the improve time.

◆ improveOrigin()

void SLDeviceLocation::improveOrigin ( SLbool  impO)
inline

Definition at line 103 of file SLDeviceLocation.h.

103 { _improveOrigin = impO; }
SLbool _improveOrigin
Flag if origin should be improved over time & accuracy.

◆ improveTime()

SLfloat SLDeviceLocation::improveTime ( )
inline

Definition at line 157 of file SLDeviceLocation.h.

157 { return std::max(_improveTimeSEC - _improveTimer.elapsedTimeInSec(), 0.0f); }
float elapsedTimeInSec()
Definition: HighResTimer.h:37
SLfloat _improveTimeSEC
Max. time in seconds for the origin improvement.

◆ init()

void SLDeviceLocation::init ( )

Definition at line 18 of file SLDeviceLocation.cpp.

19 {
20  _isUsed = false;
21  _isFirstSensorValue = false;
22  _locLatLonAlt.set(0, 0, 0);
23  _locECEF.set(0, 0, 0);
24  _locENU.set(0, 0, 0);
25  _locAccuracyM = 0.0f;
26  _locMaxDistanceM = 1000.0f;
27  _defaultLatLonAlt.set(0, 0, 0);
28  _defaultENU.set(0, 0, 0);
29  _originLatLonAlt.set(0, 0, 0);
30  _originENU.set(0, 0, 0);
31  _offsetENU.set(0, 0, 0);
32  _originAccuracyM = FLT_MAX;
33  _originSolarZenith = 45.0f;
34  _originSolarAzimuth = 0.0f;
35  _originSolarSunrise = 0.0f;
36  _originSolarSunset = 0.0f;
37  _wRecef.identity();
38  _hasOrigin = false;
39  _useOriginAltitude = true;
40  _improveOrigin = true;
41  _improveTimeSEC = 10.0f;
42  _sunLightNode = nullptr;
43  _altDemM = 0.0f;
44  _altGpsM = 0.0f;
45  _cameraHeightM = 1.6f;
47  _nameLocations.clear();
49 }
@ LOM_none
SLbool _isFirstSensorValue
Flag for the first sensor values.
SLLocOffsetMode _offsetMode
Location offset mode.
SLfloat _locMaxDistanceM
Max. allowed distance from origin. If higher it is ignored.
SLVec3d _locECEF
Cartesian location in ECEF.
SLVec3d _offsetENU
Offset vector in ENU frame.
SLfloat _locAccuracyM
Horizontal accuracy radius in m with 68% probability.
SLVec3d _locENU
Cartesian location in ENU frame.
SLVec3d _originENU
Origin location in ENU frame.
void identity()
Definition: SLMat3.h:329

◆ isUsed() [1/2]

SLbool SLDeviceLocation::isUsed ( ) const
inline

Definition at line 143 of file SLDeviceLocation.h.

143 { return _isUsed; }

◆ isUsed() [2/2]

void SLDeviceLocation::isUsed ( SLbool  isUsed)

Setter that turns on the device rotation sensor.

Definition at line 252 of file SLDeviceLocation.cpp.

253 {
254  if (!_isUsed && use)
255  _isFirstSensorValue = true;
256 
257  _isUsed = use;
258 }

◆ loadGeoTiff()

void SLDeviceLocation::loadGeoTiff ( const SLstring geoTiffFile)

Loads a GeoTiff DEM (Digital Elevation Model) Image.

Definition at line 381 of file SLDeviceLocation.cpp.

382 {
383  try
384  {
385  assert(!_defaultLatLonAlt.isZero() &&
387  "Set first defaultLatLonAlt and originLatLonAlt before you add a GeoTiff.");
388 
389  _demGeoTiff.loadGeoTiff(geoTiffFile);
390 
391  // Check that default and origin location is withing the GeoTiff extends
393  {
394  // Overwrite the altitudes of origin
399  altOriginM);
400 
401  // Overwrite the altitudes of default with the additional camera height
406  altDefaultM + _cameraHeightM);
407  }
408  else
409  {
410  string msg = "SLDeviceLocation::loadGeoTiff: Either the geotiff file ";
411  msg += "could not be loaded or the origin or default position lies ";
412  msg += "not within the extends of the geotiff file.";
413  throw std::runtime_error(msg.c_str());
414  }
415  }
416  catch (std::exception& e)
417  {
418  SL_WARN_MSG(e.what());
419  }
420  catch (...)
421  {
422  SL_WARN_MSG("SLDeviceLocation::loadGeoTiff: Unknown exception catched.");
423  }
424 }
#define SL_WARN_MSG(message)
Definition: SL.h:241
void loadGeoTiff(const string &filename)
Loads a GEOTiff file into the OpenCV image matrix.
SLVec3d originLatLonAlt() const
SLbool isZero()
Definition: SLVec3.h:165

◆ locAccuracyM()

SLfloat SLDeviceLocation::locAccuracyM ( ) const
inline

Definition at line 147 of file SLDeviceLocation.h.

147 { return _locAccuracyM; }

◆ locECEF()

SLVec3d SLDeviceLocation::locECEF ( ) const
inline

Definition at line 145 of file SLDeviceLocation.h.

145 { return _locECEF; }

◆ locENU()

SLVec3d SLDeviceLocation::locENU ( ) const
inline

Definition at line 146 of file SLDeviceLocation.h.

146 { return _locENU; }

◆ locLatLonAlt()

SLVec3d SLDeviceLocation::locLatLonAlt ( ) const
inline

Definition at line 144 of file SLDeviceLocation.h.

144 { return _locLatLonAlt; }

◆ locMaxDistanceM() [1/2]

SLfloat SLDeviceLocation::locMaxDistanceM ( ) const
inline

Definition at line 148 of file SLDeviceLocation.h.

148 { return _locMaxDistanceM; }

◆ locMaxDistanceM() [2/2]

void SLDeviceLocation::locMaxDistanceM ( SLfloat  maxDist)
inline

Definition at line 127 of file SLDeviceLocation.h.

127 { _locMaxDistanceM = maxDist; }

◆ nameLocations()

SLVLocation& SLDeviceLocation::nameLocations ( )
inline

Definition at line 168 of file SLDeviceLocation.h.

168 { return _nameLocations; }

◆ offsetENU() [1/2]

SLVec3d SLDeviceLocation::offsetENU ( ) const
inline

Definition at line 153 of file SLDeviceLocation.h.

153 { return _offsetENU; }

◆ offsetENU() [2/2]

void SLDeviceLocation::offsetENU ( SLVec3d  offsetENU)
inline

Definition at line 134 of file SLDeviceLocation.h.

134 { _offsetENU = offsetENU; }
SLVec3d offsetENU() const

◆ offsetMode() [1/2]

SLLocOffsetMode SLDeviceLocation::offsetMode ( )
inline

Definition at line 166 of file SLDeviceLocation.h.

166 { return _offsetMode; }

◆ offsetMode() [2/2]

void SLDeviceLocation::offsetMode ( SLLocOffsetMode  lom)
inline

Definition at line 133 of file SLDeviceLocation.h.

133 { _offsetMode = lom; }

◆ offsetModeStr()

SLstring SLDeviceLocation::offsetModeStr ( ) const

Returns the device location offset mode as string.

Definition at line 453 of file SLDeviceLocation.cpp.

454 {
455  switch (_offsetMode)
456  {
457  case LOM_none: return "None";
458  case LOM_twoFingerY: return "TwoFingerY";
459  default: return "Unknown";
460  }
461 }
@ LOM_twoFingerY

◆ onLocationLatLonAlt()

void SLDeviceLocation::onLocationLatLonAlt ( SLdouble  latDEG,
SLdouble  lonDEG,
SLdouble  altM,
SLfloat  accuracyM 
)

Event handler for mobile device location update.

Global event handler for device GPS location with longitude and latitude in degrees and altitude in meters. This location uses the World Geodetic System 1984 (WGS84). The accuracy in meters is a radius in which the location is with a probability of 68% (2 sigma). The altitude in m is the most inaccurate information. The option _useOriginAltitude allows to overwrite the current altitude with the origins altitude. If a geoTiff is available the altitude is is take from it. /param latDEG Latitude (vertical) on WGS84 geoid in degrees /param lonDEG Longitude (horizontal) on WGS84 geoid in degrees /param altM Altitude over WGS84 geoid in meters /param accuracyM Accuracy in meters is a radius

Definition at line 75 of file SLDeviceLocation.cpp.

79 {
80  // Use altitude either from DEM (best), origin (static) or GPS (worst)
81  _altGpsM = (float)altM;
82  float altToUse = (float)altM;
83  if (geoTiffIsAvailableAndValid() && posIsOnGeoTiff(latDEG, lonDEG))
84  {
86  lonDEG);
87  altToUse = _altDemM + _cameraHeightM;
88  }
89  else
90  {
91  altToUse = _useOriginAltitude ? (float)_originLatLonAlt.alt : _altGpsM;
92  }
93 
94  // Init origin if it is not set yet or if the origin should be improved
95  if (!_hasOrigin || _improveOrigin)
96  {
97  // The first sensor value can appear after a few seconds.
99  {
101  _isFirstSensorValue = false;
102  }
103 
104  // Only improve if accuracy is higher and the improve time has not elapsed
105  if (accuracyM < _originAccuracyM ||
107  {
108  _originAccuracyM = accuracyM;
109  originLatLonAlt(latDEG, lonDEG, altToUse);
110  defaultLatLonAlt(latDEG, lonDEG, altToUse);
111  }
112  }
113 
114  _locLatLonAlt.set(latDEG, lonDEG, altToUse);
115 
116  _locAccuracyM = accuracyM;
117 
118  // Convert to cartesian ECEF coordinates
120 
121  // Transform to local east-north-up frame
123 }

◆ originENU()

SLVec3d SLDeviceLocation::originENU ( ) const
inline

Definition at line 152 of file SLDeviceLocation.h.

152 { return _originENU; }

◆ originLatLonAlt() [1/4]

SLVec3d SLDeviceLocation::originLatLonAlt ( ) const
inline

Definition at line 150 of file SLDeviceLocation.h.

150 { return _originLatLonAlt; }

◆ originLatLonAlt() [2/4]

void SLDeviceLocation::originLatLonAlt ( int  degreesLat,
int  minutesLat,
double  secondsLat,
int  degreesLon,
int  minutesLon,
double  secondsLon,
double  altitudeM 
)

Origin coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.

Definition at line 129 of file SLDeviceLocation.cpp.

136 {
137  SLVec3d originWGS84Decimal = SLAlgo::geoDegMinSec2Decimal(degreesLat,
138  minutesLat,
139  secondsLat,
140  degreesLon,
141  minutesLon,
142  secondsLon,
143  altitudeM);
144  originLatLonAlt(originWGS84Decimal.lat,
145  originWGS84Decimal.lon,
146  originWGS84Decimal.alt);
147 }

◆ originLatLonAlt() [3/4]

void SLDeviceLocation::originLatLonAlt ( SLdouble  latDEG,
SLdouble  lonDEG,
SLdouble  altM 
)

Set global origin in latitude, longitude and altitude at the ground level.

The calculated values can be used for global camera positioning via GPS sensor. The origin is the zero point of the model. The origin should be defined in the model on the ground. /param latDEG Latitude (vertical) on WGS84 geoid in decimal degrees /param lonDEG Longitude (horizontal) on WGS84 geoid in decimal degrees /param altM Altitude over WGS84 geoid in meters

Definition at line 157 of file SLDeviceLocation.cpp.

160 {
161  _originLatLonAlt = SLVec3d(latDEG, lonDEG, altM);
162  SLVec3d originECEF;
163  originECEF.latlonAlt2ecef(_originLatLonAlt);
164 
165  // calculation of ECEF to world (scene) rotation matrix
166  // definition of rotation matrix for ECEF to world frame rotation:
167  // world frame (scene) w.r.t. ENU frame
168  double phiRad = latDEG * Utils::DEG2RAD; // phi == latitude
169  double lamRad = lonDEG * Utils::DEG2RAD; // lambda == longitude
170  double sinPhi = sin(phiRad);
171  double cosPhi = cos(phiRad);
172  double sinLam = sin(lamRad);
173  double cosLam = cos(lamRad);
174 
175  SLMat3d enuRecef(-sinLam,
176  cosLam,
177  0,
178  -cosLam * sinPhi,
179  -sinLam * sinPhi,
180  cosPhi,
181  cosLam * cosPhi,
182  sinLam * cosPhi,
183  sinPhi);
184 
185  // ENU frame w.r.t. world frame (scene)
186  SLMat3d wRenu; // same as before
187  wRenu.rotation(-90, 1, 0, 0);
188 
189  // ECEF w.r.t. world frame (scene)
190  _wRecef = wRenu * enuRecef;
191  _originENU = _wRecef * originECEF;
192 
193  // Indicate that origin is set. Otherwise it would be reset on each update
194  _hasOrigin = true;
195 
197  std::time(nullptr));
198 }
SLVec3< double > SLVec3d
Definition: SLVec3.h:323
SLbool calculateSolarAngles(SLVec3d locationLatLonAlt, std::time_t time)
Calculates the solar angles at origin at local time.
void rotation(const T angleDEG, const SLVec3< T > &axis)
Sets the rotation components
Definition: SLMat3.h:392
static const float DEG2RAD
Definition: Utils.h:239

◆ originLatLonAlt() [4/4]

void SLDeviceLocation::originLatLonAlt ( SLVec3d  lla)
inline

Definition at line 115 of file SLDeviceLocation.h.

115 { originLatLonAlt(lla.lat, lla.lon, lla.alt); }

◆ originSolarAzimut()

SLfloat SLDeviceLocation::originSolarAzimut ( ) const
inline

Definition at line 159 of file SLDeviceLocation.h.

159 { return _originSolarAzimuth; }

◆ originSolarSunrise()

SLfloat SLDeviceLocation::originSolarSunrise ( ) const
inline

Definition at line 160 of file SLDeviceLocation.h.

160 { return _originSolarSunrise; }

◆ originSolarSunset()

SLfloat SLDeviceLocation::originSolarSunset ( ) const
inline

Definition at line 161 of file SLDeviceLocation.h.

161 { return _originSolarSunset; }

◆ originSolarZenit()

SLfloat SLDeviceLocation::originSolarZenit ( ) const
inline

Definition at line 158 of file SLDeviceLocation.h.

158 { return _originSolarZenith; }

◆ posIsOnGeoTiff()

bool SLDeviceLocation::posIsOnGeoTiff ( SLdouble  latDEG,
SLdouble  lonDEG 
) const

Return true if the current GPS location is within the GeoTiff boundaries.

Definition at line 443 of file SLDeviceLocation.cpp.

444 {
445  return (!_demGeoTiff.empty() &&
446  latDEG < _demGeoTiff.upperLeftLatLonAlt()[0] &&
447  latDEG > _demGeoTiff.lowerRightLatLonAlt()[0] &&
448  lonDEG > _demGeoTiff.upperLeftLatLonAlt()[1] &&
449  lonDEG < _demGeoTiff.lowerRightLatLonAlt()[1]);
450 }
bool empty() const
Definition: CVImage.h:124

◆ sunLightNode() [1/2]

SLNode* SLDeviceLocation::sunLightNode ( ) const
inline

Definition at line 162 of file SLDeviceLocation.h.

162 { return _sunLightNode; }

◆ sunLightNode() [2/2]

void SLDeviceLocation::sunLightNode ( SLLightDirect sln)
inline

Definition at line 128 of file SLDeviceLocation.h.

128 { _sunLightNode = sln; }

◆ useOriginAltitude() [1/2]

SLbool SLDeviceLocation::useOriginAltitude ( ) const
inline

Definition at line 155 of file SLDeviceLocation.h.

155 { return _useOriginAltitude; }

◆ useOriginAltitude() [2/2]

void SLDeviceLocation::useOriginAltitude ( SLbool  useGLA)
inline

Definition at line 102 of file SLDeviceLocation.h.

102 { _useOriginAltitude = useGLA; }

◆ wRecef()

SLMat3d SLDeviceLocation::wRecef ( ) const
inline

Definition at line 156 of file SLDeviceLocation.h.

156 { return _wRecef; }

Member Data Documentation

◆ _activeNamedLocation

SLint SLDeviceLocation::_activeNamedLocation
private

Index of the active named location as defaultENU;.

Definition at line 202 of file SLDeviceLocation.h.

◆ _altDemM

SLfloat SLDeviceLocation::_altDemM
private

Altitude in m from Digital Elevation Model.

Definition at line 191 of file SLDeviceLocation.h.

◆ _altGpsM

SLfloat SLDeviceLocation::_altGpsM
private

Altitude in m from GPS.

Definition at line 192 of file SLDeviceLocation.h.

◆ _cameraHeightM

SLfloat SLDeviceLocation::_cameraHeightM
private

Height from ground to the mobile camera in m.

Definition at line 193 of file SLDeviceLocation.h.

◆ _defaultENU

SLVec3d SLDeviceLocation::_defaultENU
private

Default location in ENU frame used if real location is too far away from origin.

Definition at line 180 of file SLDeviceLocation.h.

◆ _defaultLatLonAlt

SLVec3d SLDeviceLocation::_defaultLatLonAlt
private

Default location of scene in LatLonAlt.

Definition at line 179 of file SLDeviceLocation.h.

◆ _demGeoTiff

CVImageGeoTiff SLDeviceLocation::_demGeoTiff
private

Digital Elevation Model from a Geo Tiff image.

Definition at line 199 of file SLDeviceLocation.h.

◆ _hasOrigin

SLbool SLDeviceLocation::_hasOrigin
private

Flag if this scene has a global reference location.

Definition at line 189 of file SLDeviceLocation.h.

◆ _improveOrigin

SLbool SLDeviceLocation::_improveOrigin
private

Flag if origin should be improved over time & accuracy.

Definition at line 194 of file SLDeviceLocation.h.

◆ _improveTimer

HighResTimer SLDeviceLocation::_improveTimer
private

Timer to measure the improve time.

Definition at line 196 of file SLDeviceLocation.h.

◆ _improveTimeSEC

SLfloat SLDeviceLocation::_improveTimeSEC
private

Max. time in seconds for the origin improvement.

Definition at line 195 of file SLDeviceLocation.h.

◆ _isFirstSensorValue

SLbool SLDeviceLocation::_isFirstSensorValue
private

Flag for the first sensor values.

Definition at line 173 of file SLDeviceLocation.h.

◆ _isUsed

SLbool SLDeviceLocation::_isUsed
private

Flag if the devices GPS Sensor is used.

Definition at line 172 of file SLDeviceLocation.h.

◆ _locAccuracyM

SLfloat SLDeviceLocation::_locAccuracyM
private

Horizontal accuracy radius in m with 68% probability.

Definition at line 177 of file SLDeviceLocation.h.

◆ _locECEF

SLVec3d SLDeviceLocation::_locECEF
private

Cartesian location in ECEF.

Definition at line 175 of file SLDeviceLocation.h.

◆ _locENU

SLVec3d SLDeviceLocation::_locENU
private

Cartesian location in ENU frame.

Definition at line 176 of file SLDeviceLocation.h.

◆ _locLatLonAlt

SLVec3d SLDeviceLocation::_locLatLonAlt
private

Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid.

Definition at line 174 of file SLDeviceLocation.h.

◆ _locMaxDistanceM

SLfloat SLDeviceLocation::_locMaxDistanceM
private

Max. allowed distance from origin. If higher it is ignored.

Definition at line 178 of file SLDeviceLocation.h.

◆ _nameLocations

SLVLocation SLDeviceLocation::_nameLocations
private

Vector of fix locations for default view points.

Definition at line 201 of file SLDeviceLocation.h.

◆ _offsetENU

SLVec3d SLDeviceLocation::_offsetENU
private

Offset vector in ENU frame.

Definition at line 183 of file SLDeviceLocation.h.

◆ _offsetMode

SLLocOffsetMode SLDeviceLocation::_offsetMode
private

Location offset mode.

Definition at line 200 of file SLDeviceLocation.h.

◆ _originAccuracyM

SLfloat SLDeviceLocation::_originAccuracyM
private

Accuracy radius of origin point.

Definition at line 184 of file SLDeviceLocation.h.

◆ _originENU

SLVec3d SLDeviceLocation::_originENU
private

Origin location in ENU frame.

Definition at line 182 of file SLDeviceLocation.h.

◆ _originLatLonAlt

SLVec3d SLDeviceLocation::_originLatLonAlt
private

Global origin location of scene in LatLonAlt.

Definition at line 181 of file SLDeviceLocation.h.

◆ _originSolarAzimuth

SLfloat SLDeviceLocation::_originSolarAzimuth
private

Azimuth angle of the sun in deg. (eastward from north) at origin at local time.

Definition at line 186 of file SLDeviceLocation.h.

◆ _originSolarSunrise

SLfloat SLDeviceLocation::_originSolarSunrise
private

Sunrise local time at origin.

Definition at line 187 of file SLDeviceLocation.h.

◆ _originSolarSunset

SLfloat SLDeviceLocation::_originSolarSunset
private

Sunset local time at origin.

Definition at line 188 of file SLDeviceLocation.h.

◆ _originSolarZenith

SLfloat SLDeviceLocation::_originSolarZenith
private

Zenith angle of the sun in deg. (from up dir.) at origin at local time.

Definition at line 185 of file SLDeviceLocation.h.

◆ _sunLightNode

SLNode* SLDeviceLocation::_sunLightNode
private

Pointer to directional light node to be changed if solar angles are calculated.

Definition at line 198 of file SLDeviceLocation.h.

◆ _useOriginAltitude

SLbool SLDeviceLocation::_useOriginAltitude
private

Flag if global reference altitude should be used.

Definition at line 190 of file SLDeviceLocation.h.

◆ _wRecef

SLMat3d SLDeviceLocation::_wRecef
private

ECEF frame to world frame rotation: rotates a point defined in ecef.

Definition at line 197 of file SLDeviceLocation.h.


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