Ocean
Loading...
Searching...
No Matches
GravityConstraints.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
9#define META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
10
12
14
17#include "ocean/math/Numeric.h"
19#include "ocean/math/Vector3.h"
20
21namespace Ocean
22{
23
24namespace Geometry
25{
26
27// Forward declaration.
28template <typename T>
29class GravityConstraintsT;
30
31/**
32 * Definition of the GravityConstraints object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single or double precision float data type.
33 * @see GravityConstraintsT
34 * @ingroup geometry
35 */
37
38/**
39 * Definition of the GravityConstraints object, using double floating point precision.
40 * @see GravityConstraintsT
41 * @ingroup geometry
42 */
44
45/**
46 * Definition of the GravityConstraints object, using single floating point precision.
47 * @see GravityConstraintsT
48 * @ingroup geometry
49 */
51
52/**
53 * This class implements a container allowing to define gravity constraints during e.g., camera poses estimation or optimization.
54 * The constraint is defined by a gravity vector defined in the world coordinate system (e.g., VectorT3<T>(0, -1, 0) for a gravity vector pointing towards the earth, in case the y-axis is pointing towards the sky).<br>
55 * Further, the constraints define a gravity vector for each camera, defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.<br>
56 * The camera gravity vector(s) may be provided by a IMU sensor.<br>
57 * All gravity vectors must be normalized (must be unit vectors).
58 * @tparam T The data type of a scalar, either 'float' or 'double'
59 * @ingroup geometry
60 */
61template <typename T>
63{
64 protected:
65
66 /**
67 * Definition of a vector holding gravity vectors.
68 */
70
71 public:
72
73 /**
74 * Creates a default constraint object with invalid parameters.
75 */
77
78 /**
79 * Creates a new gravity constraints object for one camera for which the gravity vector is known (in the camera coordinate system).
80 * @param cameraGravityInCamera The camera gravity vector (which is known for a camera pose), defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.
81 * @param worldGravityInWorld The world gravity vector in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity
82 * @param weightFactor The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a normal/default gravity correction, larger values to apply a stronger gravity correction, with range [0, infinity)
83 * @param maximalAngle The maximal angle between world and camera gravity vector (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm, basically specifying how accurate the gravity vector is, in radian, with range [0, PI/2)
84 */
86
87 /**
88 * Creates a new gravity constraints object for several cameras for which the gravity vectors are known (in the camera coordinate system).
89 * @param cameraGravityInCameras The camera gravity vectors (which are known for several camera poses), defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.
90 * @param worldGravityInWorld The world gravity vector in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity
91 * @param weightFactor The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a normal/default gravity correction, larger values to apply a stronger gravity correction, with range [0, infinity)
92 * @param maximalAngle The maximal angle between world and camera gravity vectors (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm, basically specifying how accurate the gravity vector is, in radian, with range [0, PI/2)
93 */
94 explicit inline GravityConstraintsT(VectorsT3<T>&& cameraGravityInCameras, const VectorT3<T>& worldGravityInWorld = VectorT3<T>(0, -1, 0), const T weightFactor = T(1), const T maximalAngle = NumericT<T>::deg2rad(5));
95
96 /**
97 * Creates a new gravity constraints object for one camera for which the precise camera pose is known.
98 * The camera gravity vector is determined from the precise camera pose.
99 * @param world_T_camera The transformation transforming camera to world, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
100 * @param worldGravityInWorld The world gravity vector in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity
101 * @param weightFactor The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a normal/default gravity correction, larger values to apply a stronger gravity correction, with range [0, infinity)
102 * @param maximalAngle The maximal angle between world and camera gravity vector (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm, basically specifying how accurate the gravity vector is, in radian, with range [0, PI/2)
103 */
104 explicit inline GravityConstraintsT(const HomogenousMatrixT4<T>& world_T_camera, const VectorT3<T>& worldGravityInWorld = VectorT3<T>(0, -1, 0), const T weightFactor = T(1), const T maximalAngle = NumericT<T>::deg2rad(5));
105
106 /**
107 * Creates a new gravity constraints object for several cameras for which the precise camera poses are known.
108 * The camera gravity vectors are determined from the precise camera poses.
109 * @param world_T_cameras The transformations transforming camera to world, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
110 * @param worldGravityInWorld The world gravity vector in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity
111 * @param weightFactor The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a normal/default gravity correction, larger values to apply a stronger gravity correction, with range [0, infinity)
112 * @param maximalAngle The maximal angle between world and camera gravity vectors (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm, basically specifying how accurate the gravity vector is, in radian, with range [0, PI/2)
113 */
114 explicit inline GravityConstraintsT(const HomogenousMatricesT4<T>& world_T_cameras, const VectorT3<T>& worldGravityInWorld = VectorT3<T>(0, -1, 0), const T weightFactor = T(1), const T maximalAngle = NumericT<T>::deg2rad(5));
115
116 /**
117 * Creates a new gravity constraints object for a single camera from a given constraints object with several cameras.
118 * @param constraints The constraints object with several cameras, must be valid
119 * @param cameraIndex The index of the camera for which the gravity constraint will be extracted, with range [0, constraints.numberCameras() - 1]
120 */
121 inline GravityConstraintsT(const GravityConstraintsT<T>& constraints, const size_t cameraIndex);
122
123 /**
124 * Creates a new gravity constraints object for a single camera from a given constraints object with several cameras.
125 * The constructor will create an invalid object if the given constraints object is nullptr.
126 * @param constraints The constraints object with several cameras, nullptr to create an invalid constraint object, must be valid if not nullptr
127 * @param cameraIndex The index of the camera for which the gravity constraint will be extracted, with range [0, constraints.numberCameras() - 1]
128 */
129 inline GravityConstraintsT(const GravityConstraintsT<T>* constraints, const size_t cameraIndex);
130
131 /**
132 * Returns the camera gravity vector (which is known for a camera pose), defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.
133 * @param cameraIndex The index of the camera for which the gravity vector is requested, with range [0, numberCameras() - 1]
134 * @return The known gravity vector for a specified camera, defined in the camera coordinate system
135 */
136 inline const VectorT3<T>& cameraGravityInCamera(const size_t cameraIndex = 0) const;
137
138 /**
139 * Returns the camera gravity vector (which is known for a camera pose), defined in the flipped camera coordinate system, with default flipped camera pointing towards the positive z-axis and y-axis pointing downwards.
140 * @param cameraIndex The index of the camera for which the gravity vector is requested, with range [0, numberCameras() - 1]
141 * @return The known gravity vector for a specified camera, defined in the flipped camera coordinate system
142 */
143 inline VectorT3<T> cameraGravityInFlippedCamera(const size_t cameraIndex = 0) const;
144
145 /**
146 * Returns the camera gravity vector (which is known for a camera pose), defined in the world coordinate system.
147 * @param world_Q_camera The rotation rotating camera to world, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
148 * @param cameraIndex The index of the camera for which the gravity vector is requested, with range [0, numberCameras() - 1]
149 * @return The known gravity vector for a specified camera, defined in the world coordinate system
150 */
151 inline VectorT3<T> cameraGravityInWorld(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex = 0) const;
152
153 /**
154 * Returns the camera gravity vector (which is known for a camera pose), defined in the world coordinate system.
155 * @param world_T_camera The transformation transforming camera to world, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
156 * @param cameraIndex The index of the camera for which the gravity vector is requested, with range [0, numberCameras() - 1]
157 * @return The known gravity vector for a specified camera, defined in the world coordinate system
158 */
159 inline VectorT3<T> cameraGravityInWorld(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
160
161 /**
162 * Returns the camera gravity vectors (which are known for one or several camera poses) defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.
163 * @return The known gravity vectors for one or several cameras
164 */
165 inline const Gravities& cameraGravitiesInCamera() const;
166
167 /**
168 * Returns the world gravity vector defined in the world coordinate system.
169 * @return The world's gravity vector in world
170 */
171 inline const VectorT3<T>& worldGravityInWorld() const;
172
173 /**
174 * Returns the world gravity vector defined in the flipped camera coordinate system, with default flipped camera pointing towards the positive z-axis and y-axis pointing downwards.
175 * @param flippedCamera_Q_world The rotation rotating world to flipped camera, must be valid
176 * @return The world's gravity vector in flipped camera
177 */
178 inline VectorT3<T> worldGravityInFlippedCameraIF(const QuaternionT<T>& flippedCamera_Q_world) const;
179
180 /**
181 * Returns the world gravity vector defined in the flipped camera coordinate system, with default flipped camera pointing towards the positive z-axis and y-axis pointing downwards.
182 * @param flippedCamera_T_world The transformation transforming world to flipped camera, must be valid
183 * @return The world's gravity vector in flipped camera
184 */
185 inline VectorT3<T> worldGravityInFlippedCameraIF(const HomogenousMatrixT4<T>& flippedCamera_T_world) const;
186
187 /**
188 * Returns one possible rotation between camera and world.
189 * The resulting rotation contains a remaining degree of freedom as the rotation is only based on the corresponding gravity vectors.<br>
190 * Any rotation around the gravity vector would be a valid rotation as well.
191 * @param cameraIndex The index of the camera for which the rotation will be returned, with range [0, numberCameras() - 1]
192 * @return The requested rotation, with default camera pointing towards the negative z-space and y-axis pointing upwards
193 */
194 inline QuaternionT<T> world_R_camera(const size_t cameraIndex) const;
195
196 /**
197 * Returns one possible rotation between world and camera.
198 * The resulting rotation contains a remaining degree of freedom as the rotation is only based on the corresponding gravity vectors.<br>
199 * Any rotation around the gravity vector would be a valid rotation as well.
200 * @param cameraIndex The index of the camera for which the rotation will be returned, with range [0, numberCameras() - 1]
201 * @return The requested rotation, with default camera pointing towards the negative z-space and y-axis pointing upwards
202 */
203 inline QuaternionT<T> camera_R_world(const size_t cameraIndex) const;
204
205 /**
206 * Returns one possible rotation between world and the flipped camera.
207 * The resulting rotation contains a remaining degree of freedom as the rotation is only based on the corresponding gravity vectors.<br>
208 * Any rotation around the gravity vector would be a valid rotation as well.
209 * @param cameraIndex The index of the camera for which the rotation will be returned, with range [0, numberCameras() - 1]
210 * @return The requested rotation, with default flipped camera pointing towards the positive z-axis and y-axis pointing downwards
211 */
212 inline QuaternionT<T> flippedCamera_R_world(const size_t cameraIndex) const;
213
214 /**
215 * Returns the weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a normal/default gravity correction, larger values to apply a stronger gravity correction.
216 * @return The object's weight factor, with range [0, infinity)
217 */
218 inline T weightFactor() const;
219
220 /**
221 * Returns the maximal angle between world and camera gravity vectors (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm.
222 * @return The object's maximal angle, in radian, with range [0, PI/2)
223 */
224 inline T maximalAngle() const;
225
226 /**
227 * Returns the cosine value of maximalAngle().
228 * @return The object's minimal angle cosine, with range [0, 1]
229 */
230 inline T minimalAngleCos() const;
231
232 /**
233 * Returns the number of cameras for which gravity constraints are defined.
234 * @return The number of cameras, with range [1, infinity)
235 */
236 inline size_t numberCameras() const;
237
238 /**
239 * Returns the cosine between the world gravity vector and the camera gravity vector (after converting into the same coordinate system).
240 * @param world_Q_camera The rotation rotating camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
241 * @param cameraIndex The index of the camera for which the cosine will be returned, with range [0, numberCameras() - 1]
242 * @return The cosine of the angle between the world gravity vector and the camera gravity vector, with range [-1, 1]
243 */
244 inline T alignmentCosine(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex = 0) const;
245
246 /**
247 * Returns the cosine between the world gravity vector and the camera gravity vector (after converting into the same coordinate system).
248 * @param world_T_camera The transformation transforming camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
249 * @param cameraIndex The index of the camera for which the cosine will be returned, with range [0, numberCameras() - 1]
250 * @return The cosine of the angle between the world gravity vector and the camera gravity vector, with range [-1, 1]
251 */
252 inline T alignmentCosine(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
253
254 /**
255 * Returns the cosine between the world gravity vector and the camera gravity vector (after converting into the same coordinate system).
256 * @param flippedCamera_Q_world The rotation rotating world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
257 * @param cameraIndex The index of the camera for which the cosine will be returned, with range [0, numberCameras() - 1]
258 * @return The cosine of the angle between the world gravity vector and the camera gravity vector, with range [-1, 1]
259 */
260 inline T alignmentCosineIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex = 0) const;
261
262 /**
263 * Returns the cosine between the world gravity vector and the camera gravity vector (after converting into the same coordinate system).
264 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
265 * @param cameraIndex The index of the camera for which the cosine will be returned, with range [0, numberCameras() - 1]
266 * @return The cosine of the angle between the world gravity vector and the camera gravity vector, with range [-1, 1]
267 */
268 inline T alignmentCosineIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
269
270 /**
271 * Returns the angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian
272 * @param world_Q_camera The rotation rotating camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
273 * @param cameraIndex The index of the camera for which the angle will be returned, with range [0, numberCameras() - 1]
274 * @return The angle between the world gravity vector and the camera gravity vector, in radian, with range [0, PI]
275 */
276 inline T alignmentAngle(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex = 0) const;
277
278 /**
279 * Returns the angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian
280 * @param world_T_camera The transformation transforming camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
281 * @param cameraIndex The index of the camera for which the angle will be returned, with range [0, numberCameras() - 1]
282 * @return The angle between the world gravity vector and the camera gravity vector, in radian, with range [0, PI]
283 */
284 inline T alignmentAngle(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
285
286 /**
287 * Returns the angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian
288 * @param flippedCamera_Q_world The rotation rotating world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
289 * @param cameraIndex The index of the camera for which the angle will be returned, with range [0, numberCameras() - 1]
290 * @return The angle between the world gravity vector and the camera gravity vector, in radian, with range [0, PI]
291 */
292 inline T alignmentAngleIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex = 0) const;
293
294 /**
295 * Returns the angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian
296 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
297 * @param cameraIndex The index of the camera for which the angle will be returned, with range [0, numberCameras() - 1]
298 * @return The angle between the world gravity vector and the camera gravity vector, in radian, with range [0, PI]
299 */
300 inline T alignmentAngleIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
301
302 /**
303 * Returns whether a camera pose is aligned with the gravity constraints using the specified angle threshold.
304 * @param world_Q_camera The rotation rotating camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
305 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
306 * @return True, if so
307 */
308 bool isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex = 0) const;
309
310 /**
311 * Returns whether a camera pose is aligned with the gravity constraints using the specified angle threshold.
312 * @param world_T_camera The transformation transforming camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
313 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
314 * @return True, if so
315 */
316 inline bool isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
317
318 /**
319 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using the specified angle threshold.
320 * @param flippedCamera_Q_world The rotation rotating world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
321 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
322 * @return True, if so
323 */
324 bool isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex = 0) const;
325
326 /**
327 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using the specified angle threshold.
328 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
329 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
330 * @return True, if so
331 */
332 inline bool isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
333
334 /**
335 * Returns whether a camera pose is aligned with the gravity constraints using a custom angle threshold.
336 * @param world_Q_camera The rotation rotating camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
337 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
338 * @param maxAngle The maximal angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian, with range [0, PI/2)
339 * @return True, if so
340 */
341 bool isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex, const T maxAngle) const;
342
343 /**
344 * Returns whether a camera pose is aligned with the gravity constraints using a custom angle threshold.
345 * @param world_T_camera The transformation transforming camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
346 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
347 * @param maxAngle The maximal angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian, with range [0, PI/2)
348 * @return True, if so
349 */
350 inline bool isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex, const T maxAngle) const;
351
352 /**
353 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using a custom angle threshold.
354 * @param flippedCamera_Q_world The rotation rotating world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
355 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
356 * @param maxAngle The maximal angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian, with range [0, PI/2)
357 * @return True, if so
358 */
359 bool isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex, const T maxAngle) const;
360
361 /**
362 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using a custom angle threshold.
363 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
364 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
365 * @param maxAngle The maximal angle between the world gravity vector and the camera gravity vector (after converting into the same coordinate system), in radian, with range [0, PI/2)
366 * @return True, if so
367 */
368 inline bool isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex, const T maxAngle) const;
369
370 /**
371 * Rotates a camera pose so that the camera is aligned with the gravity constraints.
372 * @param world_T_camera The transformation transforming camera to world, with a default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
373 * @param cameraIndex The index of the camera for which the alignment will be performed, with range [0, numberCameras() - 1]
374 * @return The camera pose aligned with the gravity constraints (world_T_alignedCamera)
375 */
376 HomogenousMatrixT4<T> alignCameraWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
377
378 /**
379 * Rotates an inverted and flipped camera pose so that the flipped camera is aligned with the gravity constraints.
380 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with a default flipped camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
381 * @param cameraIndex The index of the camera for which the alignment will be performed, with range [0, numberCameras() - 1]
382 * @return The inverted and flipped camera pose aligned with the gravity constraints (alignedFlippedCamera_T_world)
383 */
384 HomogenousMatrixT4<T> alignCameraWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
385
386 /**
387 * Returns the pointer to this gravity constraints object if it is valid.
388 * @param pointerIfValid True, to return a pointer to this object if this object is valid; False, to always return a null pointer
389 * @return The pointer to this object if the object holds valid constraints and if 'pointerIfValid == true', nullptr if this object does not hold valid constraints or if 'pointerIfValid == false'
390 */
391 inline const GravityConstraintsT<T>* conditionalPointer(const bool pointerIfValid = true) const;
392
393 /**
394 * Returns whether this constraint object holds valid parameters.
395 * @return True, if so
396 */
397 inline bool isValid() const;
398
399 /**
400 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
401 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.
402 * @param camera_Q_world The rotation rotating world to camera, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
403 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
404 * @return The camera gravity vector in the camera coordinate system
405 */
407
408 /**
409 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
410 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.
411 * @param camera_T_world The transformation transforming world to camera, with default camera pointing towards the negative z-space and y-axis pointing upwards, must be valid
412 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
413 * @return The camera gravity vector in the camera coordinate system
414 */
416
417 /**
418 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
419 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.<br>
420 * This function return the same gravity vector as cameraGravityInCamera(), but uses the flipped camera pose as input parameter.
421 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with default camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
422 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
423 * @return The camera gravity vector in the standard camera coordinate system (not in the flipped camera coordinate system)
424 * @see cameraGravityInCamera(), cameraGravityInFlippedCameraIF().
425 */
427
428 /**
429 * Helper function returning the camera gravity vector in the flipped camera coordinate system based on a given camera pose and the world gravity vector.
430 * The resulting camera gravity vector is obtained by converting the world gravity vector into the flipped camera coordinate system.
431 * @param flippedCamera_T_world The transformation transforming world to flipped camera, with default camera pointing towards the positive z-space and y-axis pointing downwards, must be valid
432 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
433 * @return The camera gravity vector in the flipped camera coordinate system
434 */
436
437 protected:
438
439 /// The gravity vectors which are known for one or more camera poses, defined in the camera coordinate system, with default camera pointing towards the negative z-space and y-axis pointing upwards.
441
442 /// The world gravity vector defined in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity.
444
445 /// The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity correction, 1 to apply a full gravity correction; with range [0, infinity).
446 T weightFactor_ = T(-1);
447
448 /// The maximal angle between world and camera gravity vectors (when converted into the same coordinate system), can be used e.g., when the camera pose is determined e.g., with RANSAC or a PnP algorithm, in radian, with range [0, PI/2).
449 T maximalAngle_ = T(-1);
450
451 /// The cosine value of maximalAngle(), with range [0, 1]
453};
454
455template <typename T>
456inline GravityConstraintsT<T>::GravityConstraintsT(const VectorT3<T>& cameraGravityInCamera, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
457 cameraGravityInCameras_(1, cameraGravityInCamera),
458 worldGravityInWorld_(worldGravityInWorld),
459 weightFactor_(weightFactor),
460 maximalAngle_(maximalAngle)
461{
463 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
464
465 ocean_assert(isValid());
466}
467
468template <typename T>
469inline GravityConstraintsT<T>::GravityConstraintsT(VectorsT3<T>&& cameraGravityInCameras, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
470 cameraGravityInCameras_(std::move(cameraGravityInCameras)),
471 worldGravityInWorld_(worldGravityInWorld),
472 weightFactor_(weightFactor),
473 maximalAngle_(maximalAngle)
474{
476 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
477
478 ocean_assert(isValid());
479}
480
481template <typename T>
482inline GravityConstraintsT<T>::GravityConstraintsT(const HomogenousMatrixT4<T>& world_T_camera, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
483 GravityConstraintsT<T>(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld), worldGravityInWorld, weightFactor, maximalAngle)
484{
485 ocean_assert(isValid());
486
487 ocean_assert(isCameraAlignedWithGravity(world_T_camera, 0, NumericT<T>::deg2rad(1)));
488}
489
490template <typename T>
491inline GravityConstraintsT<T>::GravityConstraintsT(const HomogenousMatricesT4<T>& world_T_cameras, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle)
492{
493 cameraGravityInCameras_.reserve(world_T_cameras.size());
494
495 for (const HomogenousMatrixT4<T>& world_T_camera : world_T_cameras)
496 {
497 cameraGravityInCameras_.emplaceBack(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld));
498 }
499
500 worldGravityInWorld_ = worldGravityInWorld;
501 weightFactor_ = weightFactor;
502 maximalAngle_ = maximalAngle;
503
504 minimalAngleCos_ = NumericT<T>::cos(maximalAngle_);
505 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
506
507#ifdef OCEAN_DEBUG
508 for (size_t nCamera = 0; nCamera < world_T_cameras.size(); ++nCamera)
509 {
510 const HomogenousMatrixT4<T>& world_T_camera = world_T_cameras[nCamera];
511
512 ocean_assert(isCameraAlignedWithGravity(world_T_camera, nCamera, NumericT<T>::deg2rad(1)));
513 }
514#endif
515
516 ocean_assert(isValid());
517}
518
519template <typename T>
520inline GravityConstraintsT<T>::GravityConstraintsT(const GravityConstraintsT<T>& constraints, const size_t cameraIndex) :
521 GravityConstraintsT<T>(constraints.cameraGravityInCamera(cameraIndex), constraints.worldGravityInWorld_, constraints.weightFactor_, constraints.maximalAngle_)
522{
523 ocean_assert(isValid());
524 ocean_assert(numberCameras() == 1);
525}
526
527template <typename T>
528inline GravityConstraintsT<T>::GravityConstraintsT(const GravityConstraintsT<T>* constraints, const size_t cameraIndex)
529{
530 if (constraints != nullptr)
531 {
532 *this = GravityConstraintsT<T>(*constraints, cameraIndex);
533
534 ocean_assert(isValid());
535 ocean_assert(numberCameras() == 1);
536 }
537 else
538 {
539 ocean_assert(!isValid());
540 }
541}
542
543template <typename T>
544inline const VectorT3<T>& GravityConstraintsT<T>::cameraGravityInCamera(const size_t cameraIndex) const
545{
546 ocean_assert(isValid());
547 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
548
549 return cameraGravityInCameras_[cameraIndex];
550}
551
552template <typename T>
554{
555 ocean_assert(isValid());
556 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
557
558 const VectorT3<T>& cameraGravityInCamera = cameraGravityInCameras_[cameraIndex];
559
560 // the flipped camera is pointing towards the positive z-space and y-axis pointing downwards
561
562 return VectorT3<T>(cameraGravityInCamera.x(), -cameraGravityInCamera.y(), -cameraGravityInCamera.z()); // Camera::standard2InvertedFlipped(QuaternionT<T>(true)) * targetGravityInCamera;
563}
564
565template <typename T>
566inline VectorT3<T> GravityConstraintsT<T>::cameraGravityInWorld(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
567{
568 ocean_assert(isValid());
569 ocean_assert(world_Q_camera.isValid());
570
571 return world_Q_camera * cameraGravityInCamera(cameraIndex);
572}
573
574template <typename T>
575inline VectorT3<T> GravityConstraintsT<T>::cameraGravityInWorld(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
576{
577 ocean_assert(isValid());
578 ocean_assert(world_T_camera.isValid());
579
580 return cameraGravityInWorld(world_T_camera.rotation(), cameraIndex);
581}
582
583template <typename T>
585{
586 ocean_assert(isValid());
587
588 return cameraGravityInCameras_;
589}
590
591template <typename T>
593{
594 ocean_assert(isValid());
595
596 return worldGravityInWorld_;
597}
598
599template <typename T>
601{
602 ocean_assert(isValid());
603 ocean_assert(flippedCamera_Q_world.isValid());
604
605 return flippedCamera_Q_world * worldGravityInWorld_;
606}
607
608template <typename T>
610{
611 ocean_assert(isValid());
612 ocean_assert(flippedCamera_T_world.isValid());
613
614 return worldGravityInFlippedCameraIF(flippedCamera_T_world.rotation());
615}
616
617template <typename T>
618inline QuaternionT<T> GravityConstraintsT<T>::world_R_camera(const size_t cameraIndex) const
619{
620 ocean_assert(isValid());
621
622 return QuaternionT<T>(cameraGravityInCamera(cameraIndex), worldGravityInWorld_);
623}
624
625template <typename T>
626inline QuaternionT<T> GravityConstraintsT<T>::camera_R_world(const size_t cameraIndex) const
627{
628 ocean_assert(isValid());
629
630 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInCamera(cameraIndex));
631}
632
633template <typename T>
635{
636 ocean_assert(isValid());
637
638 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInFlippedCamera(cameraIndex));
639}
640
641template <typename T>
643{
644 ocean_assert(isValid());
645
646 return weightFactor_;
647}
648
649template <typename T>
651{
652 ocean_assert(isValid());
653
654 return maximalAngle_;
655}
656
657template <typename T>
659{
660 ocean_assert(isValid());
661
662 return minimalAngleCos_;
663}
664
665template <typename T>
667{
668 ocean_assert(isValid());
669
670 return cameraGravityInCameras_.size();
671}
672
673template <typename T>
674inline T GravityConstraintsT<T>::alignmentCosine(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
675{
676 ocean_assert(isValid());
677 ocean_assert(world_Q_camera.isValid());
678
679 const VectorT3<T> knownCameraGravityInWorld = cameraGravityInWorld(world_Q_camera, cameraIndex);
680
681 ocean_assert(worldGravityInWorld_.isUnit());
682 ocean_assert(knownCameraGravityInWorld.isUnit());
683
684 const T cosine = worldGravityInWorld_ * knownCameraGravityInWorld;
685 ocean_assert(NumericT<T>::isInsideRange(-1, cosine, 1));
686
687 return cosine;
688}
689
690template <typename T>
691inline T GravityConstraintsT<T>::alignmentCosine(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
692{
693 ocean_assert(world_T_camera.isValid());
694
695 return alignmentCosine(world_T_camera.rotation(), cameraIndex);
696}
697
698template <typename T>
699inline T GravityConstraintsT<T>::alignmentCosineIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
700{
701 ocean_assert(isValid());
702 ocean_assert(flippedCamera_Q_world.isValid());
703
704 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_Q_world);
705 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
706
707 ocean_assert(worldGravityInFlippedCamera.isUnit());
708 ocean_assert(knownCameraGravityInFlippedCamera.isUnit());
709
710 const T cosine = worldGravityInFlippedCamera * knownCameraGravityInFlippedCamera;
711 ocean_assert(NumericT<T>::isInsideRange(-1, cosine, 1));
712
713 return cosine;
714}
715
716template <typename T>
717inline T GravityConstraintsT<T>::alignmentCosineIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
718{
719 ocean_assert(flippedCamera_T_world.isValid());
720
721 return alignmentCosineIF(flippedCamera_T_world.rotation(), cameraIndex);
722}
723
724
725template <typename T>
726inline T GravityConstraintsT<T>::alignmentAngle(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
727{
728 return NumericT<T>::acos(alignmentCosine(world_Q_camera, cameraIndex));
729}
730
731template <typename T>
732inline T GravityConstraintsT<T>::alignmentAngle(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
733{
734 ocean_assert(world_T_camera.isValid());
735
736 return alignmentAngle(world_T_camera.rotation(), cameraIndex);
737}
738
739template <typename T>
740inline T GravityConstraintsT<T>::alignmentAngleIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
741{
742 return NumericT<T>::acos(alignmentCosineIF(flippedCamera_Q_world, cameraIndex));
743}
744
745template <typename T>
746inline T GravityConstraintsT<T>::alignmentAngleIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
747{
748 ocean_assert(flippedCamera_T_world.isValid());
749
750 return alignmentAngleIF(flippedCamera_T_world.rotation(), cameraIndex);
751}
752
753template <typename T>
754bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
755{
756 ocean_assert(isValid());
757
758 return alignmentCosine(world_Q_camera, cameraIndex) >= minimalAngleCos_;
759}
760
761template <typename T>
762inline bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
763{
764 ocean_assert(world_T_camera.isValid());
765
766 return isCameraAlignedWithGravity(world_T_camera.rotation(), cameraIndex);
767}
768
769template <typename T>
770bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
771{
772 ocean_assert(isValid());
773
774 return alignmentCosineIF(flippedCamera_Q_world, cameraIndex) >= minimalAngleCos_;
775}
776
777template <typename T>
778inline bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
779{
780 ocean_assert(flippedCamera_T_world.isValid());
781 return isCameraAlignedWithGravityIF(flippedCamera_T_world.rotation(), cameraIndex);
782}
783
784template <typename T>
785bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex, const T maxAngle) const
786{
787 ocean_assert(maxAngle >= 0 && maxAngle < NumericT<T>::deg2rad(90));
788
789 const T angle = alignmentAngle(world_Q_camera, cameraIndex);
790
791 return angle <= maxAngle;
792}
793
794template <typename T>
795inline bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex, const T maxAngle) const
796{
797 ocean_assert(world_T_camera.isValid());
798
799 return isCameraAlignedWithGravity(world_T_camera.rotation(), cameraIndex, maxAngle);
800}
801
802template <typename T>
803bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex, const T maxAngle) const
804{
805 ocean_assert(maxAngle >= 0 && maxAngle < NumericT<T>::deg2rad(90));
806
807 const T angle = alignmentAngleIF(flippedCamera_Q_world, cameraIndex);
808
809 return angle <= maxAngle;
810}
811
812template <typename T>
813inline bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex, const T maxAngle) const
814{
815 ocean_assert(flippedCamera_T_world.isValid());
816
817 return isCameraAlignedWithGravityIF(flippedCamera_T_world.rotation(), cameraIndex, maxAngle);
818}
819
820template <typename T>
822{
823 ocean_assert(isValid());
824 ocean_assert(world_T_camera.isValid());
825
826 const VectorT3<T> knownCameraGravityInCamera = cameraGravityInCamera(cameraIndex);
827
828 const QuaternionT<T> camera_Q_world = world_T_camera.rotation().inverted();
829
830 const VectorT3<T> worldGravityInCamera = camera_Q_world * worldGravityInWorld_;
831
832 const QuaternionT<T> camera_Q_aligned(knownCameraGravityInCamera, worldGravityInCamera);
833
834 const HomogenousMatrixT4<T> world_T_alignedCamera = world_T_camera * HomogenousMatrixT4<T>(camera_Q_aligned);
835
836 ocean_assert(isCameraAlignedWithGravity(world_T_alignedCamera, cameraIndex, NumericT<T>::deg2rad(1)));
837
838 return world_T_alignedCamera;
839}
840
841template <typename T>
842HomogenousMatrixT4<T> GravityConstraintsT<T>::alignCameraWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
843{
844 ocean_assert(isValid());
845 ocean_assert(flippedCamera_T_world.isValid());
846
847 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
848 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_T_world);
849
850 const QuaternionT<T> aligned_Q_flippedCamera(worldGravityInFlippedCamera, knownCameraGravityInFlippedCamera);
851
852 const HomogenousMatrixT4<T> alignedFlippedCamera_T_world = HomogenousMatrixT4<T>(aligned_Q_flippedCamera) * flippedCamera_T_world;
853
854 ocean_assert(isCameraAlignedWithGravityIF(alignedFlippedCamera_T_world, cameraIndex, NumericT<T>::deg2rad(1)));
855
856 return alignedFlippedCamera_T_world;
857}
858
859template <typename T>
860inline const GravityConstraintsT<T>* GravityConstraintsT<T>::conditionalPointer(const bool pointerIfValid) const
861{
862 if (pointerIfValid && isValid())
863 {
864 return this;
865 }
866
867 return nullptr;
868}
869
870template <typename T>
872{
873 const bool valid = weightFactor_ >= T(0)
874 && maximalAngle_ >= NumericT<T>::deg2rad(0) && maximalAngle_ <= NumericT<T>::deg2rad(90)
875 && !cameraGravityInCameras_.isEmpty() && !worldGravityInWorld_.isNull();
876
877#ifdef OCEAN_DEBUG
878 if (valid)
879 {
880 for (const VectorT3<T>& cameraGravityInCamera : cameraGravityInCameras_)
881 {
882 ocean_assert(cameraGravityInCamera.isUnit());
883 }
884
885 ocean_assert(worldGravityInWorld_.isUnit());
886 }
887#endif
888
889 return valid;
890}
891
892template <typename T>
894{
895 ocean_assert(camera_Q_world.isValid());
896 ocean_assert(worldGravityInWorld.isUnit());
897
898 return camera_Q_world * worldGravityInWorld;
899}
900
901template <typename T>
903{
904 ocean_assert(camera_T_world.isValid());
905 ocean_assert(worldGravityInWorld.isUnit());
906
907 const SquareMatrixT3<T> camera_R_world(camera_T_world.rotationMatrix());
908 ocean_assert(camera_R_world.isOrthonormal(NumericT<T>::weakEps()));
909
910 return camera_R_world * worldGravityInWorld;
911}
912
913template <typename T>
915{
916 ocean_assert(flippedCamera_T_world.isValid());
917 ocean_assert(worldGravityInWorld.isUnit());
918
919 const VectorT3<T> cameraGravityInFlippedCamera = cameraGravityInFlippedCameraIF(flippedCamera_T_world, worldGravityInWorld);
920
921 return VectorT3<T>(cameraGravityInFlippedCamera.x(), -cameraGravityInFlippedCamera.y(), -cameraGravityInFlippedCamera.z());
922}
923
924template <typename T>
926{
927 ocean_assert(flippedCamera_T_world.isValid());
928 ocean_assert(worldGravityInWorld.isUnit());
929
930 const SquareMatrixT3<T> flippedCamera_R_world(flippedCamera_T_world.rotationMatrix());
931 ocean_assert(flippedCamera_R_world.isOrthonormal(NumericT<T>::weakEps()));
932
933 return flippedCamera_R_world * worldGravityInWorld;
934}
935
936}
937
938}
939
940#endif // META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
This class implements a container allowing to define gravity constraints during e....
Definition GravityConstraints.h:63
VectorT3< T > cameraGravityInFlippedCamera(const size_t cameraIndex=0) const
Returns the camera gravity vector (which is known for a camera pose), defined in the flipped camera c...
Definition GravityConstraints.h:553
T alignmentAngleIF(const QuaternionT< T > &flippedCamera_Q_world, const size_t cameraIndex=0) const
Returns the angle between the world gravity vector and the camera gravity vector (after converting in...
Definition GravityConstraints.h:740
const VectorT3< T > & worldGravityInWorld() const
Returns the world gravity vector defined in the world coordinate system.
Definition GravityConstraints.h:592
VectorT3< T > worldGravityInFlippedCameraIF(const QuaternionT< T > &flippedCamera_Q_world) const
Returns the world gravity vector defined in the flipped camera coordinate system, with default flippe...
Definition GravityConstraints.h:600
Gravities cameraGravityInCameras_
The gravity vectors which are known for one or more camera poses, defined in the camera coordinate sy...
Definition GravityConstraints.h:440
T weightFactor() const
Returns the weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any...
Definition GravityConstraints.h:642
size_t numberCameras() const
Returns the number of cameras for which gravity constraints are defined.
Definition GravityConstraints.h:666
static VectorT3< T > cameraGravityInCameraIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &worldGravityInWorld)
Helper function returning the camera gravity vector in the camera coordinate system based on a given ...
Definition GravityConstraints.h:914
T alignmentCosine(const QuaternionT< T > &world_Q_camera, const size_t cameraIndex=0) const
Returns the cosine between the world gravity vector and the camera gravity vector (after converting i...
Definition GravityConstraints.h:674
T alignmentAngle(const QuaternionT< T > &world_Q_camera, const size_t cameraIndex=0) const
Returns the angle between the world gravity vector and the camera gravity vector (after converting in...
Definition GravityConstraints.h:726
T minimalAngleCos() const
Returns the cosine value of maximalAngle().
Definition GravityConstraints.h:658
GravityConstraintsT()=default
Creates a default constraint object with invalid parameters.
VectorT3< T > cameraGravityInWorld(const QuaternionT< T > &world_Q_camera, const size_t cameraIndex=0) const
Returns the camera gravity vector (which is known for a camera pose), defined in the world coordinate...
Definition GravityConstraints.h:566
bool isValid() const
Returns whether this constraint object holds valid parameters.
Definition GravityConstraints.h:871
QuaternionT< T > flippedCamera_R_world(const size_t cameraIndex) const
Returns one possible rotation between world and the flipped camera.
Definition GravityConstraints.h:634
VectorT3< T > worldGravityInWorld_
The world gravity vector defined in the world coordinate system, mainly defining how the world coordi...
Definition GravityConstraints.h:443
const VectorT3< T > & cameraGravityInCamera(const size_t cameraIndex=0) const
Returns the camera gravity vector (which is known for a camera pose), defined in the camera coordinat...
Definition GravityConstraints.h:544
HomogenousMatrixT4< T > alignCameraWithGravity(const HomogenousMatrixT4< T > &world_T_camera, const size_t cameraIndex=0) const
Rotates a camera pose so that the camera is aligned with the gravity constraints.
Definition GravityConstraints.h:821
HomogenousMatrixT4< T > alignCameraWithGravityIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const size_t cameraIndex=0) const
Rotates an inverted and flipped camera pose so that the flipped camera is aligned with the gravity co...
Definition GravityConstraints.h:842
T maximalAngle_
The maximal angle between world and camera gravity vectors (when converted into the same coordinate s...
Definition GravityConstraints.h:449
const GravityConstraintsT< T > * conditionalPointer(const bool pointerIfValid=true) const
Returns the pointer to this gravity constraints object if it is valid.
Definition GravityConstraints.h:860
bool isCameraAlignedWithGravity(const QuaternionT< T > &world_Q_camera, const size_t cameraIndex=0) const
Returns whether a camera pose is aligned with the gravity constraints using the specified angle thres...
Definition GravityConstraints.h:754
T maximalAngle() const
Returns the maximal angle between world and camera gravity vectors (when converted into the same coor...
Definition GravityConstraints.h:650
QuaternionT< T > camera_R_world(const size_t cameraIndex) const
Returns one possible rotation between world and camera.
Definition GravityConstraints.h:626
QuaternionT< T > world_R_camera(const size_t cameraIndex) const
Returns one possible rotation between camera and world.
Definition GravityConstraints.h:618
const Gravities & cameraGravitiesInCamera() const
Returns the camera gravity vectors (which are known for one or several camera poses) defined in the c...
Definition GravityConstraints.h:584
T weightFactor_
The weight factor to be used during a non-linear optimization of a camera pose; 0 to skip any gravity...
Definition GravityConstraints.h:446
bool isCameraAlignedWithGravityIF(const QuaternionT< T > &flippedCamera_Q_world, const size_t cameraIndex=0) const
Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints u...
Definition GravityConstraints.h:770
T minimalAngleCos_
The cosine value of maximalAngle(), with range [0, 1].
Definition GravityConstraints.h:452
T alignmentCosineIF(const QuaternionT< T > &flippedCamera_Q_world, const size_t cameraIndex=0) const
Returns the cosine between the world gravity vector and the camera gravity vector (after converting i...
Definition GravityConstraints.h:699
static VectorT3< T > cameraGravityInFlippedCameraIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &worldGravityInWorld)
Helper function returning the camera gravity vector in the flipped camera coordinate system based on ...
Definition GravityConstraints.h:925
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition HomogenousMatrix4.h:110
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition HomogenousMatrix4.h:1493
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
QuaternionT< T > rotation() const
Returns the rotation of the transformation as quaternion.
Definition HomogenousMatrix4.h:1388
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T deg2rad(const T deg)
Converts deg to rad.
Definition Numeric.h:3241
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1588
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2916
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:882
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
bool isOrthonormal(const T epsilon=NumericT< T >::eps()) const
Returns whether this matrix is an orthonormal matrix.
Definition SquareMatrix3.h:1366
This class implements a vector with three elements.
Definition Vector3.h:97
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector3.h:873
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
std::vector< HomogenousMatrixT4< T > > HomogenousMatricesT4
Definition of a typename alias for vectors with HomogenousMatrixT4 objects.
Definition HomogenousMatrix4.h:66
std::vector< VectorT3< T > > VectorsT3
Definition of a typename alias for vectors with VectorT3 objects.
Definition Vector3.h:58
The namespace covering the entire Ocean framework.
Definition Accessor.h:15