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 math
35 */
37
38/**
39 * Definition of the GravityConstraints object, using double floating point precision.
40 * @see GravityConstraintsT
41 * @ingroup math
42 */
44
45/**
46 * Definition of the GravityConstraints object, using single floating point precision.
47 * @see GravityConstraintsT
48 * @ingroup math
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 gravityInCamera 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, 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 gravityInCameras 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, 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, 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, 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), in radian
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), in radian
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), in radian
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 * @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)
323 * @return True, if so
324 */
325 bool isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex = 0) const;
326
327 /**
328 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using the specified angle threshold.
329 * @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
330 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
331 * @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)
332 * @return True, if so
333 */
334 inline bool isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
335
336 /**
337 * Returns whether a camera pose is aligned with the gravity constraints using a custom angle threshold.
338 * @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
339 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
340 * @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)
341 * @return True, if so
342 */
343 bool isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex, const T maxAngle) const;
344
345 /**
346 * Returns whether a camera pose is aligned with the gravity constraints using a custom angle threshold.
347 * @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
348 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
349 * @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)
350 * @return True, if so
351 */
352 inline bool isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex, const T maxAngle) const;
353
354 /**
355 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using a custom angle threshold.
356 * @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
357 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
358 * @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)
359 * @return True, if so
360 */
361 bool isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex, const T maxAngle) const;
362
363 /**
364 * Returns whether a provided flipped and inverted camera pose is aligned with the gravity constraints using a custom angle threshold.
365 * @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
366 * @param cameraIndex The index of the camera for which the alignment check will be performed, with range [0, numberCameras() - 1]
367 * @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)
368 * @return True, if so
369 */
370 inline bool isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex, const T maxAngle) const;
371
372 /**
373 * Rotates a camera pose so that the camera is aligned with the gravity constraints.
374 * @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
375 * @param cameraIndex The index of the camera for which the alignment will be performed, with range [0, numberCameras() - 1]
376 * @return The camera pose aligned with the gravity constraints (world_T_alignedCamera)
377 */
378 HomogenousMatrixT4<T> alignCameraWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex = 0) const;
379
380 /**
381 * Rotates a inverted and flipped camera pose so that the flipped camera is aligned with the gravity constraints.
382 * @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
383 * @param cameraIndex The index of the camera for which the alignment will be performed, with range [0, numberCameras() - 1]
384 * @return The flipped inverted and flipped camera pose aligned with the gravity constraints (alignedFlippedCamera_T_world)
385 */
386 HomogenousMatrixT4<T> alignCameraWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex = 0) const;
387
388 /**
389 * Returns the pointer to this gravity constraints object if it is valid.
390 * @param pointerIfValid True, to return a pointer to this object if this object is valid; False, to always return a null pointer
391 * @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'
392 */
393 inline const GravityConstraintsT<T>* conditionalPointer(const bool pointerIfValid = true) const;
394
395 /**
396 * Returns whether this constraint object holds valid parameters.
397 * @return True, if so
398 */
399 inline bool isValid() const;
400
401 /**
402 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
403 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.
404 * @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
405 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
406 * @return The camera gravity vector in the camera coordinate system
407 */
409
410 /**
411 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
412 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.
413 * @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
414 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
415 * @return The camera gravity vector in the camera coordinate system
416 */
418
419 /**
420 * Helper function returning the camera gravity vector in the camera coordinate system based on a given camera pose and the world gravity vector.
421 * The resulting camera gravity vector is obtained by converting the world gravity vector into the camera coordinate system.,br>
422 * This function return the same gravity vector as cameraGravityInCamera(), but uses the flipped camera pose as input parameter.
423 * @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
424 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
425 * @return The camera gravity vector in the standard camera coordinate system (not in the flipped camera coordinate system)
426 * @see cameraGravityInCamera(), cameraGravityInFlippedCameraIF().
427 */
429
430 /**
431 * Helper function returning the camera gravity vector in the flipped camera coordinate system based on a given camera pose and the world gravity vector.
432 * The resulting camera gravity vector is obtained by converting the world gravity vector into the flipped camera coordinate system.
433 * @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
434 * @param worldGravityInWorld The world gravity vector defined in the world coordinate system, must be a unit vector
435 * @return The camera gravity vector in the flipped camera coordinate system
436 */
438
439 protected:
440
441 /// 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.
443
444 /// The world gravity vector defined in the world coordinate system, mainly defining how the world coordinate system is oriented/aligned wrt gravity.
446
447 /// 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, 1).
448 T weightFactor_ = T(-1);
449
450 /// 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).
451 T maximalAngle_ = T(-1);
452
453 /// The cosine value of maximalAngle(), with range [0, 1]
455};
456
457template <typename T>
458inline GravityConstraintsT<T>::GravityConstraintsT(const VectorT3<T>& cameraGravityInCamera, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
459 cameraGravityInCameras_(1, cameraGravityInCamera),
460 worldGravityInWorld_(worldGravityInWorld),
461 weightFactor_(weightFactor),
462 maximalAngle_(maximalAngle)
463{
465 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
466
467 ocean_assert(isValid());
468}
469
470template <typename T>
471inline GravityConstraintsT<T>::GravityConstraintsT(VectorsT3<T>&& cameraGravityInCameras, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
472 cameraGravityInCameras_(std::move(cameraGravityInCameras)),
473 worldGravityInWorld_(worldGravityInWorld),
474 weightFactor_(weightFactor),
475 maximalAngle_(maximalAngle)
476{
478 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
479
480 ocean_assert(isValid());
481}
482
483template <typename T>
484inline GravityConstraintsT<T>::GravityConstraintsT(const HomogenousMatrixT4<T>& world_T_camera, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle) :
485 GravityConstraintsT<T>(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld), worldGravityInWorld, weightFactor, maximalAngle)
486{
487 ocean_assert(isValid());
488
489 ocean_assert(isCameraAlignedWithGravity(world_T_camera, 0, NumericT<T>::deg2rad(1)));
490}
491
492template <typename T>
493inline GravityConstraintsT<T>::GravityConstraintsT(const HomogenousMatricesT4<T>& world_T_cameras, const VectorT3<T>& worldGravityInWorld, const T weightFactor, const T maximalAngle)
494{
495 cameraGravityInCameras_.reserve(world_T_cameras.size());
496
497 for (const HomogenousMatrixT4<T>& world_T_camera : world_T_cameras)
498 {
499 cameraGravityInCameras_.emplaceBack(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld));
500 }
501
502 worldGravityInWorld_ = worldGravityInWorld;
503 weightFactor_ = weightFactor;
504 maximalAngle_ = maximalAngle;
505
506 minimalAngleCos_ = NumericT<T>::cos(maximalAngle_);
507 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
508
509#ifdef OCEAN_DEBUG
510 for (size_t nCamera = 0; nCamera < world_T_cameras.size(); ++nCamera)
511 {
512 const HomogenousMatrixT4<T>& world_T_camera = world_T_cameras[nCamera];
513
514 ocean_assert(isCameraAlignedWithGravity(world_T_camera, nCamera, NumericT<T>::deg2rad(1)));
515 }
516#endif
517
518 ocean_assert(isValid());
519}
520
521template <typename T>
522inline GravityConstraintsT<T>::GravityConstraintsT(const GravityConstraintsT<T>& constraints, const size_t cameraIndex) :
523 GravityConstraintsT<T>(constraints.cameraGravityInCamera(cameraIndex), constraints.worldGravityInWorld_, constraints.weightFactor_, constraints.maximalAngle_)
524{
525 ocean_assert(isValid());
526 ocean_assert(numberCameras() == 1);
527}
528
529template <typename T>
530inline GravityConstraintsT<T>::GravityConstraintsT(const GravityConstraintsT<T>* constraints, const size_t cameraIndex)
531{
532 if (constraints != nullptr)
533 {
534 *this = GravityConstraintsT<T>(*constraints, cameraIndex);
535
536 ocean_assert(isValid());
537 ocean_assert(numberCameras() == 1);
538 }
539 else
540 {
541 ocean_assert(!isValid());
542 }
543}
544
545template <typename T>
546inline const VectorT3<T>& GravityConstraintsT<T>::cameraGravityInCamera(const size_t cameraIndex) const
547{
548 ocean_assert(isValid());
549 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
550
551 return cameraGravityInCameras_[cameraIndex];
552}
553
554template <typename T>
556{
557 ocean_assert(isValid());
558 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
559
560 const VectorT3<T>& cameraGravityInCamera = cameraGravityInCameras_[cameraIndex];
561
562 // the flipped camera is pointing towards the positive z-space and y-axis pointing downwards
563
564 return VectorT3<T>(cameraGravityInCamera.x(), -cameraGravityInCamera.y(), -cameraGravityInCamera.z()); // Camera::standard2InvertedFlipped(QuaternionT<T>(true)) * targetGravityInCamera;
565}
566
567template <typename T>
568inline VectorT3<T> GravityConstraintsT<T>::cameraGravityInWorld(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
569{
570 ocean_assert(isValid());
571 ocean_assert(world_Q_camera.isValid());
572
573 return world_Q_camera * cameraGravityInCamera(cameraIndex);
574}
575
576template <typename T>
577inline VectorT3<T> GravityConstraintsT<T>::cameraGravityInWorld(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
578{
579 ocean_assert(isValid());
580 ocean_assert(world_T_camera.isValid());
581
582 return cameraGravityInWorld(world_T_camera.rotation(), cameraIndex);
583}
584
585template <typename T>
587{
588 ocean_assert(isValid());
589
590 return cameraGravityInCameras_;
591}
592
593template <typename T>
595{
596 ocean_assert(isValid());
597
598 return worldGravityInWorld_;
599}
600
601template <typename T>
603{
604 ocean_assert(isValid());
605 ocean_assert(flippedCamera_Q_world.isValid());
606
607 return flippedCamera_Q_world * worldGravityInWorld_;
608}
609
610template <typename T>
612{
613 ocean_assert(isValid());
614 ocean_assert(flippedCamera_T_world.isValid());
615
616 return worldGravityInFlippedCameraIF(flippedCamera_T_world.rotation());
617}
618
619template <typename T>
620inline QuaternionT<T> GravityConstraintsT<T>::world_R_camera(const size_t cameraIndex) const
621{
622 ocean_assert(isValid());
623
624 return QuaternionT<T>(cameraGravityInCamera(cameraIndex), worldGravityInWorld_);
625}
626
627template <typename T>
628inline QuaternionT<T> GravityConstraintsT<T>::camera_R_world(const size_t cameraIndex) const
629{
630 ocean_assert(isValid());
631
632 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInCamera(cameraIndex));
633}
634
635template <typename T>
637{
638 ocean_assert(isValid());
639
640 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInFlippedCamera(cameraIndex));
641}
642
643template <typename T>
645{
646 ocean_assert(isValid());
647
648 return weightFactor_;
649}
650
651template <typename T>
653{
654 ocean_assert(isValid());
655
656 return maximalAngle_;
657}
658
659template <typename T>
661{
662 ocean_assert(isValid());
663
664 return minimalAngleCos_;
665}
666
667template <typename T>
669{
670 ocean_assert(isValid());
671
672 return cameraGravityInCameras_.size();
673}
674
675template <typename T>
676inline T GravityConstraintsT<T>::alignmentCosine(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
677{
678 ocean_assert(isValid());
679 ocean_assert(world_Q_camera.isValid());
680
681 const VectorT3<T> knownCameraGravityInWorld = cameraGravityInWorld(world_Q_camera, cameraIndex);
682
683 ocean_assert(worldGravityInWorld_.isUnit());
684 ocean_assert(knownCameraGravityInWorld.isUnit());
685
686 const T cosine = worldGravityInWorld_ * knownCameraGravityInWorld;
687 ocean_assert(NumericT<T>::isInsideRange(-1, cosine, 1));
688
689 return cosine;
690}
691
692template <typename T>
693inline T GravityConstraintsT<T>::alignmentCosine(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
694{
695 ocean_assert(world_T_camera.isValid());
696
697 return alignmentCosine(world_T_camera.rotation(), cameraIndex);
698}
699
700template <typename T>
701inline T GravityConstraintsT<T>::alignmentCosineIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
702{
703 ocean_assert(isValid());
704 ocean_assert(flippedCamera_Q_world.isValid());
705
706 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_Q_world);
707 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
708
709 ocean_assert(worldGravityInFlippedCamera.isUnit());
710 ocean_assert(knownCameraGravityInFlippedCamera.isUnit());
711
712 const T cosine = worldGravityInFlippedCamera * knownCameraGravityInFlippedCamera;
713 ocean_assert(NumericT<T>::isInsideRange(-1, cosine, 1));
714
715 return cosine;
716}
717
718template <typename T>
719inline T GravityConstraintsT<T>::alignmentCosineIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
720{
721 ocean_assert(flippedCamera_T_world.isValid());
722
723 return alignmentCosineIF(flippedCamera_T_world.rotation(), cameraIndex);
724}
725
726
727template <typename T>
728inline T GravityConstraintsT<T>::alignmentAngle(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
729{
730 return NumericT<T>::acos(alignmentCosine(world_Q_camera, cameraIndex));
731}
732
733template <typename T>
734inline T GravityConstraintsT<T>::alignmentAngle(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
735{
736 ocean_assert(world_T_camera.isValid());
737
738 return alignmentAngle(world_T_camera.rotation(), cameraIndex);
739}
740
741template <typename T>
742inline T GravityConstraintsT<T>::alignmentAngleIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
743{
744 return NumericT<T>::acos(alignmentCosineIF(flippedCamera_Q_world, cameraIndex));
745}
746
747template <typename T>
748inline T GravityConstraintsT<T>::alignmentAngleIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
749{
750 ocean_assert(flippedCamera_T_world.isValid());
751
752 return alignmentAngleIF(flippedCamera_T_world.rotation(), cameraIndex);
753}
754
755template <typename T>
756bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex) const
757{
758 ocean_assert(isValid());
759
760 return alignmentCosine(world_Q_camera, cameraIndex) >= minimalAngleCos_;
761}
762
763template <typename T>
764inline bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex) const
765{
766 ocean_assert(world_T_camera.isValid());
767
768 return isCameraAlignedWithGravity(world_T_camera.rotation(), cameraIndex);
769}
770
771template <typename T>
772bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex) const
773{
774 ocean_assert(isValid());
775
776 return isCameraAlignedWithGravityIF(flippedCamera_Q_world, cameraIndex) >= minimalAngleCos_;
777}
778
779template <typename T>
780inline bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
781{
782 ocean_assert(flippedCamera_T_world.isValid());
783 return isCameraAlignedWithGravityIF(flippedCamera_T_world.rotation(), cameraIndex);
784}
785
786template <typename T>
787bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const QuaternionT<T>& world_Q_camera, const size_t cameraIndex, const T maxAngle) const
788{
789 ocean_assert(maxAngle >= 0 && maxAngle < NumericT<T>::deg2rad(90));
790
791 const T angle = alignmentAngle(world_Q_camera, cameraIndex);
792
793 return angle <= maxAngle;
794}
795
796template <typename T>
797inline bool GravityConstraintsT<T>::isCameraAlignedWithGravity(const HomogenousMatrixT4<T>& world_T_camera, const size_t cameraIndex, const T maxAngle) const
798{
799 ocean_assert(world_T_camera.isValid());
800
801 return isCameraAlignedWithGravity(world_T_camera.rotation(), cameraIndex, maxAngle);
802}
803
804template <typename T>
805bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const QuaternionT<T>& flippedCamera_Q_world, const size_t cameraIndex, const T maxAngle) const
806{
807 ocean_assert(maxAngle >= 0 && maxAngle < NumericT<T>::deg2rad(90));
808
809 const T angle = alignmentAngleIF(flippedCamera_Q_world, cameraIndex);
810
811 return angle <= maxAngle;
812}
813
814template <typename T>
815inline bool GravityConstraintsT<T>::isCameraAlignedWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex, const T maxAngle) const
816{
817 ocean_assert(flippedCamera_T_world.isValid());
818
819 return isCameraAlignedWithGravityIF(flippedCamera_T_world.rotation(), cameraIndex, maxAngle);
820}
821
822template <typename T>
824{
825 ocean_assert(isValid());
826 ocean_assert(world_T_camera.isValid());
827
828 const VectorT3<T> knownCameraGravityInCamera = cameraGravityInCamera(cameraIndex);
829
830 const QuaternionT<T> camera_Q_world = world_T_camera.rotation().inverted();
831
832 const VectorT3<T> worldGravityInCamera = camera_Q_world * worldGravityInWorld_;
833
834 const QuaternionT<T> camera_Q_aligned(knownCameraGravityInCamera, worldGravityInCamera);
835
836 const HomogenousMatrixT4<T> world_T_alignedCamera = world_T_camera * HomogenousMatrixT4<T>(camera_Q_aligned);
837
838 ocean_assert(isCameraAlignedWithGravity(world_T_alignedCamera, cameraIndex, NumericT<T>::deg2rad(1)));
839
840 return world_T_alignedCamera;
841}
842
843template <typename T>
844HomogenousMatrixT4<T> GravityConstraintsT<T>::alignCameraWithGravityIF(const HomogenousMatrixT4<T>& flippedCamera_T_world, const size_t cameraIndex) const
845{
846 ocean_assert(isValid());
847 ocean_assert(flippedCamera_T_world.isValid());
848
849 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
850 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_T_world);
851
852 const QuaternionT<T> aligned_Q_flippedCamera(worldGravityInFlippedCamera, knownCameraGravityInFlippedCamera);
853
854 const HomogenousMatrixT4<T> alignedFlippedCamera_T_world = HomogenousMatrixT4<T>(aligned_Q_flippedCamera) * flippedCamera_T_world;
855
856 ocean_assert(isCameraAlignedWithGravityIF(alignedFlippedCamera_T_world, cameraIndex, NumericT<T>::deg2rad(1)));
857
858 return alignedFlippedCamera_T_world;
859}
860
861template <typename T>
862inline const GravityConstraintsT<T>* GravityConstraintsT<T>::conditionalPointer(const bool pointerIfValid) const
863{
864 if (pointerIfValid && isValid())
865 {
866 return this;
867 }
868
869 return nullptr;
870}
871
872template <typename T>
874{
875 const bool valid = weightFactor_ >= T(0)
876 && maximalAngle_ >= NumericT<T>::rad2deg(0) && maximalAngle_ <= NumericT<T>::rad2deg(90)
877 && !cameraGravityInCameras_.isEmpty() && !worldGravityInWorld_.isNull();
878
879#ifdef OCEAN_DEBUG
880 if (valid)
881 {
882 for (const VectorT3<T>& cameraGravityInCamera : cameraGravityInCameras_)
883 {
884 ocean_assert(cameraGravityInCamera.isUnit());
885 }
886
887 ocean_assert(worldGravityInWorld_.isUnit());
888 }
889#endif
890
891 return valid;
892}
893
894template <typename T>
896{
897 ocean_assert(camera_Q_world.isValid());
898 ocean_assert(worldGravityInWorld.isUnit());
899
900 return camera_Q_world * worldGravityInWorld;
901}
902
903template <typename T>
905{
906 ocean_assert(camera_T_world.isValid());
907 ocean_assert(worldGravityInWorld.isUnit());
908
909 const SquareMatrixT3<T> camera_R_world(camera_T_world.rotationMatrix());
910 ocean_assert(camera_R_world.isOrthonormal(NumericT<T>::weakEps()));
911
912 return camera_R_world * worldGravityInWorld;
913}
914
915template <typename T>
917{
918 ocean_assert(flippedCamera_T_world.isValid());
919 ocean_assert(worldGravityInWorld.isUnit());
920
921 const VectorT3<T> cameraGravityInFlippedCamera = cameraGravityInFlippedCameraIF(flippedCamera_T_world, worldGravityInWorld);
922
923 return VectorT3<T>(cameraGravityInFlippedCamera.x(), -cameraGravityInFlippedCamera.y(), -cameraGravityInFlippedCamera.z());
924}
925
926template <typename T>
928{
929 ocean_assert(flippedCamera_T_world.isValid());
930 ocean_assert(worldGravityInWorld.isUnit());
931
932 const SquareMatrixT3<T> flippedCamera_R_world(flippedCamera_T_world.rotationMatrix());
933 ocean_assert(flippedCamera_R_world.isOrthonormal(NumericT<T>::weakEps()));
934
935 return flippedCamera_R_world * worldGravityInWorld;
936}
937
938}
939
940}
941
942#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:555
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:742
const VectorT3< T > & worldGravityInWorld() const
Returns the world gravity vector defined in the world coordinate system.
Definition GravityConstraints.h:594
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:602
Gravities cameraGravityInCameras_
The gravity vectors which are known for one or more camera poses, defined in the camera coordinate sy...
Definition GravityConstraints.h:442
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:644
size_t numberCameras() const
Returns the number of cameras for which gravity constraints are defined.
Definition GravityConstraints.h:668
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:916
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:676
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:728
T minimalAngleCos() const
Returns the cosine value of maximalAngle().
Definition GravityConstraints.h:660
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:568
bool isValid() const
Returns whether this constraint object holds valid parameters.
Definition GravityConstraints.h:873
QuaternionT< T > flippedCamera_R_world(const size_t cameraIndex) const
Returns one possible rotation between world and the flipped camera.
Definition GravityConstraints.h:636
VectorT3< T > worldGravityInWorld_
The world gravity vector defined in the world coordinate system, mainly defining how the world coordi...
Definition GravityConstraints.h:445
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:546
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:823
HomogenousMatrixT4< T > alignCameraWithGravityIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const size_t cameraIndex=0) const
Rotates a inverted and flipped camera pose so that the flipped camera is aligned with the gravity con...
Definition GravityConstraints.h:844
T maximalAngle_
The maximal angle between world and camera gravity vectors (when converted into the same coordinate s...
Definition GravityConstraints.h:451
const GravityConstraintsT< T > * conditionalPointer(const bool pointerIfValid=true) const
Returns the pointer to this gravity constraints object if it is valid.
Definition GravityConstraints.h:862
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:756
T maximalAngle() const
Returns the maximal angle between world and camera gravity vectors (when converted into the same coor...
Definition GravityConstraints.h:652
QuaternionT< T > camera_R_world(const size_t cameraIndex) const
Returns one possible rotation between world and camera.
Definition GravityConstraints.h:628
QuaternionT< T > world_R_camera(const size_t cameraIndex) const
Returns one possible rotation between camera and world.
Definition GravityConstraints.h:620
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:586
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:448
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:772
T minimalAngleCos_
The cosine value of maximalAngle(), with range [0, 1].
Definition GravityConstraints.h:454
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:701
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:927
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 rad2deg(const T rad)
Converts rad to deg.
Definition Numeric.h:3241
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1584
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2910
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:901
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