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 contructor with WGS84 position in deg, min. & sec.
27  SLLocation(string locName,
28  int degreesLat,
29  int minutesLat,
30  double secondsLat,
31  int degreesLon,
32  int minutesLon,
33  double secondsLon,
34  double altitudeM)
35  {
36  name = std::move(locName);
37  SLVec3d posWGS84 = SLAlgo::geoDegMinSec2Decimal(degreesLat,
38  minutesLat,
39  secondsLat,
40  degreesLon,
41  minutesLon,
42  secondsLon,
43  altitudeM);
44  posWGS84LatLonAlt.set(posWGS84.lat,
45  posWGS84.lon,
46  posWGS84.alt);
47  }
48 
49  //! SLLocation contructor with decimal pos in WGS84
50  SLLocation(string locName, SLVec3d posWGS84)
51  {
52  name = std::move(locName);
53  posWGS84LatLonAlt.set(posWGS84.lat,
54  posWGS84.lon,
55  posWGS84.alt);
56  }
57 
58  string name;
60 };
61 typedef vector<SLLocation> SLVLocation;
62 //-----------------------------------------------------------------------------
63 //! Device location offset mode
65 {
66  LOM_none = 0,
68 };
69 //-----------------------------------------------------------------------------
70 //! Encapsulation of a mobile device location set by the device's GPS sensor
71 /*! This class is only used if SLProject runs on a mobile device. Check out the
72  app-demo/android and app_demo_slproject/ios how the sensor data is generated
73  and passed to this object hold by AppCommon. The class stores the devices location
74  that it gets from its GPS (global positioning system) sensor. The device location can
75  be used in the active camera to apply it to the scene camera
76  (s. SLCamera::setView).\n
77  - LatLonAlt: The device location from GPS comes as a latitude (deg. north-south),
78  longitude (deg. east-west) and altitude (m) LatLonAlt-tripple.
79  These two angles are a position and height on the WGS84 ellipsoid
80  (World Geodetic System 1984).\n
81  - ECEF (Earth Centered Earth Fixed) are right-handed cartesian world
82  coordinates with the z-axis at the north pole the x-axis at the prime meridian
83  (0 deg. longitude) and the y-axis at 90 deg. longitude. x- and y-axis form the
84  equator plane.\n
85  - ENU (East North Up) is the local frame (= right-handed coordinate system)
86  on the surface of the ellipsoid with the E=East tangential vector, the N=North
87  tangential vector and U=Up as the ellipsoid's normal vector. Be aware that the
88  up vector is normal to the ellipsoid and not to the terrain above. This normal
89  does not point the center of the ellipsoid.\n
90  If we want to show a local scene on the earth, we do this always in the ENU
91  frame because in the ECEF frame with have not enough precision for float
92  coordinates. Therefore we have define a local origin in the ENU frame and
93  convert all locations from LatLonAlt to ECEF and the with the wRecef rotation
94  matrix to the ENU frame.
95 */
97 {
98 public:
100  void init();
101  void onLocationLatLonAlt(SLdouble latDEG,
102  SLdouble lonDEG,
103  SLdouble altM,
104  SLfloat accuracyM);
105 
106  SLbool calculateSolarAngles(SLVec3d locationLatLonAlt, std::time_t time);
107 
109 
110  // Setters
111  void isUsed(SLbool isUsed);
112  void useOriginAltitude(SLbool useGLA) { _useOriginAltitude = useGLA; }
113  void improveOrigin(SLbool impO) { _improveOrigin = impO; }
114  void hasOrigin(SLbool hasOL);
115  void originLatLonAlt(int degreesLat,
116  int minutesLat,
117  double secondsLat,
118  int degreesLon,
119  int minutesLon,
120  double secondsLon,
121  double altitudeM);
122  void originLatLonAlt(SLdouble latDEG,
123  SLdouble lonDEG,
124  SLdouble altM);
125  void originLatLonAlt(SLVec3d lla) { originLatLonAlt(lla.lat, lla.lon, lla.alt); }
126  void defaultLatLonAlt(int degreesLat,
127  int minutesLat,
128  double secondsLat,
129  int degreesLon,
130  int minutesLon,
131  double secondsLon,
132  double altitudeM);
133  void defaultLatLonAlt(SLdouble latDEG,
134  SLdouble lonDEG,
135  SLdouble altM);
136  void defaultLatLonAlt(SLVec3d lla) { defaultLatLonAlt(lla.lat, lla.lon, lla.alt); }
137  void locMaxDistanceM(SLfloat maxDist) { _locMaxDistanceM = maxDist; }
139  void loadGeoTiff(const SLstring& geoTiffFile);
140  bool geoTiffIsAvailableAndValid() const;
141  bool posIsOnGeoTiff(SLdouble latDEG, SLdouble lonDEG) const;
142  void cameraHeightM(float camHeightM) { _cameraHeightM = camHeightM; }
145  void activeNamedLocation(SLint locIndex)
146  {
147  _activeNamedLocation = locIndex;
148  _isUsed = false;
149  defaultLatLonAlt(_nameLocations[locIndex].posWGS84LatLonAlt);
150  }
151 
152  // Getters
153  SLbool isUsed() const { return _isUsed; }
154  SLVec3d locLatLonAlt() const { return _locLatLonAlt; }
155  SLVec3d locECEF() const { return _locECEF; }
156  SLVec3d locENU() const { return _locENU; }
157  SLfloat locAccuracyM() const { return _locAccuracyM; }
159  SLVec3d defaultENU() const { return _defaultENU; }
162  SLVec3d originENU() const { return _originENU; }
163  SLVec3d offsetENU() const { return _offsetENU; }
164  SLbool hasOrigin() const { return _hasOrigin; }
166  SLMat3d wRecef() const { return _wRecef; }
172  SLNode* sunLightNode() const { return _sunLightNode; }
173  SLfloat altDemM() const { return _altDemM; }
174  SLfloat altGpsM() const { return _altGpsM; }
175  SLfloat cameraHeightM() const { return _cameraHeightM; };
177  SLstring offsetModeStr() const;
180 
181 private:
182  SLbool _isUsed; //!< Flag if the devices GPS Sensor is used
183  SLbool _isFirstSensorValue; //!< Flag for the first sensor values
184  SLVec3d _locLatLonAlt; //!< Earth location in latitudeDEG, longitudeDEG & AltitudeM on WGS84 geoid
185  SLVec3d _locECEF; //!< Cartesian location in ECEF
186  SLVec3d _locENU; //!< Cartesian location in ENU frame
187  SLfloat _locAccuracyM; //!< Horizontal accuracy radius in m with 68% probability
188  SLfloat _locMaxDistanceM; //!< Max. allowed distance from origin. If higher it is ignored.
189  SLVec3d _defaultLatLonAlt; //!< Default location of scene in LatLonAlt.
190  SLVec3d _defaultENU; //!< Default location in ENU frame used if real location is too far away from origin
191  SLVec3d _originLatLonAlt; //!< Global origin location of scene in LatLonAlt
192  SLVec3d _originENU; //!< Origin location in ENU frame
193  SLVec3d _offsetENU; //!< Offset vector in ENU frame
194  SLfloat _originAccuracyM; //!< Accuracy radius of origin point
195  SLfloat _originSolarZenith; //!< Zenith angle of the sun in deg. (from up dir.) at origin at local time
196  SLfloat _originSolarAzimuth; //!< Azimuth angle of the sun in deg. (eastward from north) at origin at local time
197  SLfloat _originSolarSunrise; //!< Sunrise local time at origin
198  SLfloat _originSolarSunset; //!< Sunset local time at origin
199  SLbool _hasOrigin; //!< Flag if this scene has a global reference location
200  SLbool _useOriginAltitude; //!< Flag if global reference altitude should be used
201  SLfloat _altDemM; //!< Altitude in m from Digital Elevation Model
202  SLfloat _altGpsM; //!< Altitude in m from GPS
203  SLfloat _cameraHeightM; //!< Height from ground to the mobile camera in m
204  SLbool _improveOrigin; //!< Flag if origin should be improved over time & accuracy
205  SLfloat _improveTimeSEC; //!< Max. time in seconds for the origin improvement.
206  HighResTimer _improveTimer; //!< Timer to measure the improve time.
207  SLMat3d _wRecef; //!< ECEF frame to world frame rotation: rotates a point defined in ecef
208  SLNode* _sunLightNode; //!< Pointer to directional light node to be changed if solar angles are calculated
209  CVImageGeoTiff _demGeoTiff; //!< Digital Elevation Model from a Geo Tiff image
210  SLLocOffsetMode _offsetMode; //!< Location offset mode
211  SLVLocation _nameLocations; //!< Vector of fix locations for default view points
212  SLint _activeNamedLocation; //!< Index of the active named location as defaultENU;
213 };
214 //-----------------------------------------------------------------------------
215 #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, SLVec3d posWGS84)
SLLocation contructor with decimal pos in WGS84.
SLLocation(string locName, int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
SLLocation contructor with WGS84 position in deg, min. & sec.
SLVec3d posWGS84LatLonAlt
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:148
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