8#ifndef META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
9#define META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
29class GravityConstraintsT;
459 cameraGravityInCameras_(1, cameraGravityInCamera),
460 worldGravityInWorld_(worldGravityInWorld),
461 weightFactor_(weightFactor),
462 maximalAngle_(maximalAngle)
472 cameraGravityInCameras_(std::move(cameraGravityInCameras)),
473 worldGravityInWorld_(worldGravityInWorld),
474 weightFactor_(weightFactor),
475 maximalAngle_(maximalAngle)
485 GravityConstraintsT<T>(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld), worldGravityInWorld, weightFactor, maximalAngle)
495 cameraGravityInCameras_.reserve(world_T_cameras.size());
499 cameraGravityInCameras_.emplaceBack(cameraGravityInCamera(world_T_camera.
rotation().inverted(), worldGravityInWorld));
502 worldGravityInWorld_ = worldGravityInWorld;
503 weightFactor_ = weightFactor;
504 maximalAngle_ = maximalAngle;
507 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
510 for (
size_t nCamera = 0; nCamera < world_T_cameras.size(); ++nCamera)
518 ocean_assert(isValid());
523 GravityConstraintsT<T>(constraints.cameraGravityInCamera(cameraIndex), constraints.worldGravityInWorld_, constraints.weightFactor_, constraints.maximalAngle_)
532 if (constraints !=
nullptr)
536 ocean_assert(isValid());
537 ocean_assert(numberCameras() == 1);
541 ocean_assert(!isValid());
548 ocean_assert(isValid());
549 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
551 return cameraGravityInCameras_[cameraIndex];
557 ocean_assert(isValid());
558 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
560 const VectorT3<T>& cameraGravityInCamera = cameraGravityInCameras_[cameraIndex];
564 return VectorT3<T>(cameraGravityInCamera.
x(), -cameraGravityInCamera.
y(), -cameraGravityInCamera.
z());
570 ocean_assert(isValid());
571 ocean_assert(world_Q_camera.
isValid());
573 return world_Q_camera * cameraGravityInCamera(cameraIndex);
579 ocean_assert(isValid());
580 ocean_assert(world_T_camera.
isValid());
582 return cameraGravityInWorld(world_T_camera.
rotation(), cameraIndex);
588 ocean_assert(isValid());
590 return cameraGravityInCameras_;
596 ocean_assert(isValid());
598 return worldGravityInWorld_;
604 ocean_assert(isValid());
605 ocean_assert(flippedCamera_Q_world.
isValid());
607 return flippedCamera_Q_world * worldGravityInWorld_;
613 ocean_assert(isValid());
614 ocean_assert(flippedCamera_T_world.
isValid());
616 return worldGravityInFlippedCameraIF(flippedCamera_T_world.
rotation());
622 ocean_assert(isValid());
624 return QuaternionT<T>(cameraGravityInCamera(cameraIndex), worldGravityInWorld_);
630 ocean_assert(isValid());
632 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInCamera(cameraIndex));
638 ocean_assert(isValid());
640 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInFlippedCamera(cameraIndex));
646 ocean_assert(isValid());
648 return weightFactor_;
654 ocean_assert(isValid());
656 return maximalAngle_;
662 ocean_assert(isValid());
664 return minimalAngleCos_;
670 ocean_assert(isValid());
672 return cameraGravityInCameras_.size();
678 ocean_assert(isValid());
679 ocean_assert(world_Q_camera.
isValid());
681 const VectorT3<T> knownCameraGravityInWorld = cameraGravityInWorld(world_Q_camera, cameraIndex);
683 ocean_assert(worldGravityInWorld_.isUnit());
684 ocean_assert(knownCameraGravityInWorld.
isUnit());
686 const T cosine = worldGravityInWorld_ * knownCameraGravityInWorld;
695 ocean_assert(world_T_camera.
isValid());
697 return alignmentCosine(world_T_camera.
rotation(), cameraIndex);
703 ocean_assert(isValid());
704 ocean_assert(flippedCamera_Q_world.
isValid());
706 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_Q_world);
707 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
709 ocean_assert(worldGravityInFlippedCamera.
isUnit());
710 ocean_assert(knownCameraGravityInFlippedCamera.
isUnit());
712 const T cosine = worldGravityInFlippedCamera * knownCameraGravityInFlippedCamera;
721 ocean_assert(flippedCamera_T_world.
isValid());
723 return alignmentCosineIF(flippedCamera_T_world.
rotation(), cameraIndex);
736 ocean_assert(world_T_camera.
isValid());
738 return alignmentAngle(world_T_camera.
rotation(), cameraIndex);
750 ocean_assert(flippedCamera_T_world.
isValid());
752 return alignmentAngleIF(flippedCamera_T_world.
rotation(), cameraIndex);
758 ocean_assert(isValid());
760 return alignmentCosine(world_Q_camera, cameraIndex) >= minimalAngleCos_;
766 ocean_assert(world_T_camera.
isValid());
768 return isCameraAlignedWithGravity(world_T_camera.
rotation(), cameraIndex);
774 ocean_assert(isValid());
776 return isCameraAlignedWithGravityIF(flippedCamera_Q_world, cameraIndex) >= minimalAngleCos_;
782 ocean_assert(flippedCamera_T_world.
isValid());
783 return isCameraAlignedWithGravityIF(flippedCamera_T_world.
rotation(), cameraIndex);
791 const T angle = alignmentAngle(world_Q_camera, cameraIndex);
793 return angle <= maxAngle;
799 ocean_assert(world_T_camera.
isValid());
801 return isCameraAlignedWithGravity(world_T_camera.
rotation(), cameraIndex, maxAngle);
809 const T angle = alignmentAngleIF(flippedCamera_Q_world, cameraIndex);
811 return angle <= maxAngle;
817 ocean_assert(flippedCamera_T_world.
isValid());
819 return isCameraAlignedWithGravityIF(flippedCamera_T_world.
rotation(), cameraIndex, maxAngle);
825 ocean_assert(isValid());
826 ocean_assert(world_T_camera.
isValid());
828 const VectorT3<T> knownCameraGravityInCamera = cameraGravityInCamera(cameraIndex);
832 const VectorT3<T> worldGravityInCamera = camera_Q_world * worldGravityInWorld_;
834 const QuaternionT<T> camera_Q_aligned(knownCameraGravityInCamera, worldGravityInCamera);
838 ocean_assert(isCameraAlignedWithGravity(world_T_alignedCamera, cameraIndex,
NumericT<T>::deg2rad(1)));
840 return world_T_alignedCamera;
846 ocean_assert(isValid());
847 ocean_assert(flippedCamera_T_world.
isValid());
849 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
850 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_T_world);
852 const QuaternionT<T> aligned_Q_flippedCamera(worldGravityInFlippedCamera, knownCameraGravityInFlippedCamera);
856 ocean_assert(isCameraAlignedWithGravityIF(alignedFlippedCamera_T_world, cameraIndex,
NumericT<T>::deg2rad(1)));
858 return alignedFlippedCamera_T_world;
864 if (pointerIfValid && isValid())
875 const bool valid = weightFactor_ >= T(0)
877 && !cameraGravityInCameras_.isEmpty() && !worldGravityInWorld_.isNull();
882 for (
const VectorT3<T>& cameraGravityInCamera : cameraGravityInCameras_)
884 ocean_assert(cameraGravityInCamera.
isUnit());
887 ocean_assert(worldGravityInWorld_.isUnit());
897 ocean_assert(camera_Q_world.
isValid());
898 ocean_assert(worldGravityInWorld.
isUnit());
900 return camera_Q_world * worldGravityInWorld;
906 ocean_assert(camera_T_world.
isValid());
907 ocean_assert(worldGravityInWorld.
isUnit());
912 return camera_R_world * worldGravityInWorld;
918 ocean_assert(flippedCamera_T_world.
isValid());
919 ocean_assert(worldGravityInWorld.
isUnit());
921 const VectorT3<T> cameraGravityInFlippedCamera = cameraGravityInFlippedCameraIF(flippedCamera_T_world, worldGravityInWorld);
923 return VectorT3<T>(cameraGravityInFlippedCamera.
x(), -cameraGravityInFlippedCamera.
y(), -cameraGravityInFlippedCamera.
z());
929 ocean_assert(flippedCamera_T_world.
isValid());
930 ocean_assert(worldGravityInWorld.
isUnit());
935 return flippedCamera_R_world * worldGravityInWorld;
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