SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLDeviceLocation.h
Go to the documentation of this file.
1 /**
2  * \file SLDeviceLocation.h
3  * \brief Mobile device location class declaration
4  * \authors Marcus Hudritsch
5  * \date November 2017
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9  */
10 
11 #ifndef SLDEVICELOCATION_H
12 #define SLDEVICELOCATION_H
13 
14 #include <SLLightDirect.h>
15 #include <SLAlgo.h>
16 #include <HighResTimer.h>
17 #include <CVImageGeoTiff.h>
18 
19 class SLNode;
20 
21 //-----------------------------------------------------------------------------
22 //! class for a named location with lat-lon-Alt WGS84 position
24 {
25 public:
26  SLLocation(string locName,
27  int degreesLat,
28  int minutesLat,
29  double secondsLat,
30  int degreesLon,
31  int minutesLon,
32  double secondsLon,
33  double altitudeM)
34  {
35  name = std::move(locName);
36  SLVec3d posWGS84 = SLAlgo::geoDegMinSec2Decimal(degreesLat,
37  minutesLat,
38  secondsLat,
39  degreesLon,
40  minutesLon,
41  secondsLon,
42  altitudeM);
43  posWGS84LatLonAlt.set(posWGS84.lat,
44  posWGS84.lon,
45  posWGS84.alt);
46  }
47 
48  string name;
50 };
51 typedef vector<SLLocation> SLVLocation;
52 //-----------------------------------------------------------------------------
53 //! Device location offset mode
55 {
56  LOM_none = 0,
58 };
59 //-----------------------------------------------------------------------------
60 //! Encapsulation of a mobile device location set by the device's GPS sensor
61 /*! This class is only used if SLProject runs on a mobile device. Check out the
62  app-demo/android and app_demo_slproject/ios how the sensor data is generated
63  and passed to this object hold by AppCommon. The class stores the devices location
64  that it gets from its GPS (global positioning system) sensor. The device location can
65  be used in the active camera to apply it to the scene camera
66  (s. SLCamera::setView).\n
67  - LatLonAlt: The device location from GPS comes as a latitude (deg. north-south),
68  longitude (deg. east-west) and altitude (m) LatLonAlt-tripple.
69  These two angles are a position and height on the WGS84 ellipsoid
70  (World Geodetic System 1984).\n
71  - ECEF (Earth Centered Earth Fixed) are right-handed cartesian world
72  coordinates with the z-axis at the north pole the x-axis at the prime meridian
73  (0 deg. longitude) and the y-axis at 90 deg. longitude. x- and y-axis form the
74  equator plane.\n
75  - ENU (East North Up) is the local frame (= right-handed coordinate system)
76  on the surface of the ellipsoid with the E=East tangential vector, the N=North
77  tangential vector and U=Up as the ellipsoid's normal vector. Be aware that the
78  up vector is normal to the ellipsoid and not to the terrain above. This normal
79  does not point the center of the ellipsoid.\n
80  If we want to show a local scene on the earth, we do this always in the ENU
81  frame because in the ECEF frame with have not enough precision for float
82  coordinates. Therefore we have define a local origin in the ENU frame and
83  convert all locations from LatLonAlt to ECEF and the with the wRecef rotation
84  matrix to the ENU frame.
85 */
87 {
88 public:
90  void init();
91  void onLocationLatLonAlt(SLdouble latDEG,
92  SLdouble lonDEG,
93  SLdouble altM,
94  SLfloat accuracyM);
95 
96  SLbool calculateSolarAngles(SLVec3d locationLatLonAlt, std::time_t time);
97 
99 
100  // Setters
101  void isUsed(SLbool isUsed);
102  void useOriginAltitude(SLbool useGLA) { _useOriginAltitude = useGLA; }
103  void improveOrigin(SLbool impO) { _improveOrigin = impO; }
104  void hasOrigin(SLbool hasOL);
105  void originLatLonAlt(int degreesLat,
106  int minutesLat,
107  double secondsLat,
108  int degreesLon,
109  int minutesLon,
110  double secondsLon,
111  double altitudeM);
112  void originLatLonAlt(SLdouble latDEG,
113  SLdouble lonDEG,
114  SLdouble altM);
115  void originLatLonAlt(SLVec3d lla) { originLatLonAlt(lla.lat, lla.lon, lla.alt); }
116  void defaultLatLonAlt(int degreesLat,
117  int minutesLat,
118  double secondsLat,
119  int degreesLon,
120  int minutesLon,
121  double secondsLon,
122  double altitudeM);
123  void defaultLatLonAlt(SLdouble latDEG,
124  SLdouble lonDEG,
125  SLdouble altM);
126  void defaultLatLonAlt(SLVec3d lla) { defaultLatLonAlt(lla.lat, lla.lon, lla.alt); }
127  void locMaxDistanceM(SLfloat maxDist) { _locMaxDistanceM = maxDist; }
129  void loadGeoTiff(const SLstring& geoTiffFile);
130  bool geoTiffIsAvailableAndValid() const;
131  bool posIsOnGeoTiff(SLdouble latDEG, SLdouble lonDEG) const;
132  void cameraHeightM(float camHeightM) { _cameraHeightM = camHeightM; }
135  void activeNamedLocation(SLint locIndex)
136  {
137  _activeNamedLocation = locIndex;
138  _isUsed = false;
139  defaultLatLonAlt(_nameLocations[locIndex].posWGS84LatLonAlt);
140  }
141 
142  // Getters
143  SLbool isUsed() const { return _isUsed; }
144  SLVec3d locLatLonAlt() const { return _locLatLonAlt; }
145  SLVec3d locECEF() const { return _locECEF; }
146  SLVec3d locENU() const { return _locENU; }
147  SLfloat locAccuracyM() const { return _locAccuracyM; }
149  SLVec3d defaultENU() const { return _defaultENU; }
152  SLVec3d originENU() const { return _originENU; }
153  SLVec3d offsetENU() const { return _offsetENU; }
154  SLbool hasOrigin() const { return _hasOrigin; }
156  SLMat3d wRecef() const { return _wRecef; }
162  SLNode* sunLightNode() const { return _sunLightNode; }
163  SLfloat altDemM() const { return _altDemM; }
164  SLfloat altGpsM() const { return _altGpsM; }
165  SLfloat cameraHeightM() const { return _cameraHeightM; };
167  SLstring offsetModeStr() const;
170 
171 private:
172  SLbool _isUsed; //!< Flag if the devices GPS Sensor is used
173  SLbool _isFirstSensorValue; //!< Flag for the first sensor values
174  SLVec3d _locLatLonAlt; //!< Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid
175  SLVec3d _locECEF; //!< Cartesian location in ECEF
176  SLVec3d _locENU; //!< Cartesian location in ENU frame
177  SLfloat _locAccuracyM; //!< Horizontal accuracy radius in m with 68% probability
178  SLfloat _locMaxDistanceM; //!< Max. allowed distance from origin. If higher it is ignored.
179  SLVec3d _defaultLatLonAlt; //!< Default location of scene in LatLonAlt.
180  SLVec3d _defaultENU; //!< Default location in ENU frame used if real location is too far away from origin
181  SLVec3d _originLatLonAlt; //!< Global origin location of scene in LatLonAlt
182  SLVec3d _originENU; //!< Origin location in ENU frame
183  SLVec3d _offsetENU; //!< Offset vector in ENU frame
184  SLfloat _originAccuracyM; //!< Accuracy radius of origin point
185  SLfloat _originSolarZenith; //!< Zenith angle of the sun in deg. (from up dir.) at origin at local time
186  SLfloat _originSolarAzimuth; //!< Azimuth angle of the sun in deg. (eastward from north) at origin at local time
187  SLfloat _originSolarSunrise; //!< Sunrise local time at origin
188  SLfloat _originSolarSunset; //!< Sunset local time at origin
189  SLbool _hasOrigin; //!< Flag if this scene has a global reference location
190  SLbool _useOriginAltitude; //!< Flag if global reference altitude should be used
191  SLfloat _altDemM; //!< Altitude in m from Digital Elevation Model
192  SLfloat _altGpsM; //!< Altitude in m from GPS
193  SLfloat _cameraHeightM; //!< Height from ground to the mobile camera in m
194  SLbool _improveOrigin; //!< Flag if origin should be improved over time & accuracy
195  SLfloat _improveTimeSEC; //!< Max. time in seconds for the origin improvement.
196  HighResTimer _improveTimer; //!< Timer to measure the improve time.
197  SLMat3d _wRecef; //!< ECEF frame to world frame rotation: rotates a point defined in ecef
198  SLNode* _sunLightNode; //!< Pointer to directional light node to be changed if solar angles are calculated
199  CVImageGeoTiff _demGeoTiff; //!< Digital Elevation Model from a Geo Tiff image
200  SLLocOffsetMode _offsetMode; //!< Location offset mode
201  SLVLocation _nameLocations; //!< Vector of fix locations for default view points
202  SLint _activeNamedLocation; //!< Index of the active named location as defaultENU;
203 };
204 //-----------------------------------------------------------------------------
205 #endif
float SLfloat
Definition: SL.h:173
double SLdouble
Definition: SL.h:174
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
Container for general algorithm functions.
SLLocOffsetMode
Device location offset mode.
@ LOM_none
@ LOM_twoFingerY
vector< SLLocation > SLVLocation
Encapsulates a GEOTiff images with geo referenced meta information.
High Resolution Timer class using C++11.
Definition: HighResTimer.h:31
float elapsedTimeInSec()
Definition: HighResTimer.h:37
Encapsulation of a mobile device location set by the device's GPS sensor.
SLfloat _originSolarAzimuth
Azimuth angle of the sun in deg. (eastward from north) at origin at local time.
SLfloat _originSolarSunset
Sunset local time at origin.
void loadGeoTiff(const SLstring &geoTiffFile)
Loads a GeoTiff DEM (Digital Elevation Model) Image.
SLfloat originSolarZenit() const
void useOriginAltitude(SLbool useGLA)
SLVec3d locLatLonAlt() const
bool posIsOnGeoTiff(SLdouble latDEG, SLdouble lonDEG) const
Return true if the current GPS location is within the GeoTiff boundaries.
void improveOrigin(SLbool impO)
SLbool isUsed() const
SLstring offsetModeStr() const
Returns the device location offset mode as string.
SLbool calculateSolarAngles(SLVec3d locationLatLonAlt, std::time_t time)
Calculates the solar angles at origin at local time.
SLfloat originSolarSunset() const
SLfloat altGpsM() const
SLVec3d defaultENU() const
SLVec3d _locLatLonAlt
Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid.
SLfloat _originAccuracyM
Accuracy radius of origin point.
SLVLocation _nameLocations
Vector of fix locations for default view points.
SLVec3d _defaultLatLonAlt
Default location of scene in LatLonAlt.
SLVec3d convertLatLonAlt2ENU(SLVec3d locLatLonAlt) const
Converter method: the transferred wgs84 coordinate is converted to ENU frame and returned (does not c...
SLbool hasOrigin() const
SLbool _isFirstSensorValue
Flag for the first sensor values.
SLint _activeNamedLocation
Index of the active named location as defaultENU;.
void activeNamedLocation(SLint locIndex)
SLVec3d originLatLonAlt() const
void sunLightNode(SLLightDirect *sln)
void offsetENU(SLVec3d offsetENU)
void cameraHeightM(float camHeightM)
SLLocOffsetMode _offsetMode
Location offset mode.
void defaultLatLonAlt(SLVec3d lla)
SLfloat _locMaxDistanceM
Max. allowed distance from origin. If higher it is ignored.
SLVec3d _locECEF
Cartesian location in ECEF.
CVImageGeoTiff _demGeoTiff
Digital Elevation Model from a Geo Tiff image.
SLVec3d _defaultENU
Default location in ENU frame used if real location is too far away from origin.
SLVec3d originENU() const
HighResTimer _improveTimer
Timer to measure the improve time.
SLNode * _sunLightNode
Pointer to directional light node to be changed if solar angles are calculated.
SLMat3d wRecef() const
SLLocOffsetMode offsetMode()
SLVec3d _offsetENU
Offset vector in ENU frame.
bool geoTiffIsAvailableAndValid() const
SLfloat _locAccuracyM
Horizontal accuracy radius in m with 68% probability.
SLVec3d offsetENU() const
SLVec3d _originLatLonAlt
Global origin location of scene in LatLonAlt.
void onLocationLatLonAlt(SLdouble latDEG, SLdouble lonDEG, SLdouble altM, SLfloat accuracyM)
Event handler for mobile device location update.
SLbool _useOriginAltitude
Flag if global reference altitude should be used.
SLbool useOriginAltitude() const
SLVLocation & nameLocations()
SLVec3d locECEF() const
SLfloat _originSolarZenith
Zenith angle of the sun in deg. (from up dir.) at origin at local time.
SLfloat locMaxDistanceM() const
SLNode * sunLightNode() const
SLMat3d _wRecef
ECEF frame to world frame rotation: rotates a point defined in ecef.
SLVec3d _locENU
Cartesian location in ENU frame.
void locMaxDistanceM(SLfloat maxDist)
SLbool _hasOrigin
Flag if this scene has a global reference location.
SLfloat _altDemM
Altitude in m from Digital Elevation Model.
SLfloat altDemM() const
SLbool _improveOrigin
Flag if origin should be improved over time & accuracy.
SLVec3d defaultLatLonAlt() const
SLfloat _improveTimeSEC
Max. time in seconds for the origin improvement.
void offsetMode(SLLocOffsetMode lom)
SLfloat _altGpsM
Altitude in m from GPS.
SLfloat cameraHeightM() const
SLfloat locAccuracyM() const
SLfloat originSolarAzimut() const
SLfloat originSolarSunrise() const
SLbool _isUsed
Flag if the devices GPS Sensor is used.
SLint activeNamedLocation() const
void originLatLonAlt(SLVec3d lla)
SLfloat _cameraHeightM
Height from ground to the mobile camera in m.
SLVec3d locENU() const
SLVec3d _originENU
Origin location in ENU frame.
SLfloat _originSolarSunrise
Sunrise local time at origin.
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
class for a named location with lat-lon-Alt WGS84 position
SLLocation(string locName, int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
SLVec3d posWGS84LatLonAlt
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
T lat
Definition: SLVec3.h:45
T alt
Definition: SLVec3.h:45
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
T lon
Definition: SLVec3.h:45
T geoDegMinSec2Decimal(int degrees, int minutes, T seconds)
convert geodetic datum defined in degrees, minutes and seconds to decimal
Definition: SLAlgo.cpp:45