SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAlgo.cpp
Go to the documentation of this file.
1 /**
2  * \file math/SLAlgo.cpp
3  * \brief Container for general algorithm functions
4  * \date November
5  * \remarks Please use clangformat to format the code. See more code style on
6  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
7  * \authors Michael Goettlicher, Marcus Hudritsch
8  * \copyright http://opensource.org/licenses/GPL-3.0
9 */
10 
11 #include <SLAlgo.h>
12 #include <cassert>
13 
14 namespace SLAlgo
15 {
16 
17 bool estimateHorizon(const SLMat3f& enuRs, const SLMat3f& sRc, SLVec3f& horizon)
18 {
19  SLMat3f cRenu = (enuRs * sRc).transposed();
20  //estimate horizon in camera frame:
21  //-normal vector of camera x-y-plane in enu frame definition: this is the camera z-axis epressed in enu frame
22  SLVec3f normalCamXYPlane = SLVec3f(0, 0, 1);
23  //-normal vector of enu x-y-plane in camera frame: this is the enu z-axis rotated into camera coord. frame
24  SLVec3f normalEnuXYPlane = cRenu * SLVec3f(0, 0, 1);
25  //-Estimation of intersetion line (horizon):
26  //Then the crossproduct of both vectors defines the direction of the intersection line. In our special case we know that the origin is a point that lies on both planes.
27  //Then origin together with the direction vector define the horizon.
28  horizon.cross(normalEnuXYPlane, normalCamXYPlane);
29 
30  //check that vectors are not parallel
31  float l = horizon.length();
32  if (l < 0.01f)
33  {
34  horizon = {1.f, 0.f, 0.f};
35  return false;
36  }
37  else
38  {
39  horizon /= l;
40  return true;
41  }
42 }
43 
44 template<typename T>
45 T geoDegMinSec2Decimal(int degrees, int minutes, T seconds)
46 {
47  return (T)degrees + ((T)(minutes * 60) + seconds) / ((T)3600);
48 }
49 //explicit template instantiation for float and double (only these make sense)
50 template float geoDegMinSec2Decimal(int degrees, int minutes, float seconds);
51 template double geoDegMinSec2Decimal(int degrees, int minutes, double seconds);
52 
53 // clang-format off
54 template<typename T>
55 SLVec3<T> geoDegMinSec2Decimal(int degreesLat, int minutesLat, T secondsLat,
56  int degreesLon, int minutesLon, T secondsLon,
57  T altM)
58 {
59  //https://www.koordinaten-umrechner.de/
60  assert(degreesLat > -90 && degreesLat < 90);
61  assert(degreesLon > -180 && degreesLon < 180);
62  assert(minutesLat > 0 && minutesLat < 60);
63  assert(minutesLon > 0 && minutesLon < 60);
64  assert(secondsLat >= (T)0 && secondsLat < (T)60);
65  assert(secondsLon >= (T)0 && secondsLon < (T)60);
66 
67  SLVec3<T> vec;
68  vec.x = geoDegMinSec2Decimal<T>(degreesLat, minutesLat, secondsLat);
69  vec.y = geoDegMinSec2Decimal<T>(degreesLon, minutesLon, secondsLon);
70  vec.z = altM;
71 
72  return vec;
73 }
74 //explicit template instantiation for float and double (only these make sense)
75 template SLVec3f geoDegMinSec2Decimal(int degreesLat, int minutesLat, float secondsLat,
76  int degreesLon, int minutesLon, float secondsLon,
77  float altM);
78 template SLVec3d geoDegMinSec2Decimal(int degreesLat, int minutesLat, double secondsLat,
79  int degreesLon, int minutesLon, double secondsLon,
80  double altM);
81 // clang-format on
82 };
Container for general algorithm functions.
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
T y
Definition: SLVec3.h:43
void cross(const SLVec3 &a, const SLVec3 &b)
Definition: SLVec3.h:118
T x
Definition: SLVec3.h:43
T length() const
Definition: SLVec3.h:122
T z
Definition: SLVec3.h:43
Collection of algorithms that may should be integrated into other namespaces.
Definition: SLAlgo.cpp:15
bool estimateHorizon(const SLMat3f &enuRs, const SLMat3f &sRc, SLVec3f &horizon)
Definition: SLAlgo.cpp:17
T geoDegMinSec2Decimal(int degrees, int minutes, T seconds)
convert geodetic datum defined in degrees, minutes and seconds to decimal
Definition: SLAlgo.cpp:45