8#ifndef META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
9#define META_OCEAN_GEOMETRY_GRAVITY_CONSTRAINTS_H
29class GravityConstraintsT;
457 cameraGravityInCameras_(1, cameraGravityInCamera),
458 worldGravityInWorld_(worldGravityInWorld),
459 weightFactor_(weightFactor),
460 maximalAngle_(maximalAngle)
470 cameraGravityInCameras_(std::move(cameraGravityInCameras)),
471 worldGravityInWorld_(worldGravityInWorld),
472 weightFactor_(weightFactor),
473 maximalAngle_(maximalAngle)
483 GravityConstraintsT<T>(cameraGravityInCamera(world_T_camera.rotation().inverted(), worldGravityInWorld), worldGravityInWorld, weightFactor, maximalAngle)
493 cameraGravityInCameras_.reserve(world_T_cameras.size());
497 cameraGravityInCameras_.emplaceBack(cameraGravityInCamera(world_T_camera.
rotation().inverted(), worldGravityInWorld));
500 worldGravityInWorld_ = worldGravityInWorld;
501 weightFactor_ = weightFactor;
502 maximalAngle_ = maximalAngle;
505 ocean_assert(minimalAngleCos_ >= T(0) && minimalAngleCos_ <= T(1));
508 for (
size_t nCamera = 0; nCamera < world_T_cameras.size(); ++nCamera)
516 ocean_assert(isValid());
521 GravityConstraintsT<T>(constraints.cameraGravityInCamera(cameraIndex), constraints.worldGravityInWorld_, constraints.weightFactor_, constraints.maximalAngle_)
530 if (constraints !=
nullptr)
534 ocean_assert(isValid());
535 ocean_assert(numberCameras() == 1);
539 ocean_assert(!isValid());
546 ocean_assert(isValid());
547 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
549 return cameraGravityInCameras_[cameraIndex];
555 ocean_assert(isValid());
556 ocean_assert(cameraIndex < cameraGravityInCameras_.size());
558 const VectorT3<T>& cameraGravityInCamera = cameraGravityInCameras_[cameraIndex];
562 return VectorT3<T>(cameraGravityInCamera.
x(), -cameraGravityInCamera.
y(), -cameraGravityInCamera.
z());
568 ocean_assert(isValid());
569 ocean_assert(world_Q_camera.
isValid());
571 return world_Q_camera * cameraGravityInCamera(cameraIndex);
577 ocean_assert(isValid());
578 ocean_assert(world_T_camera.
isValid());
580 return cameraGravityInWorld(world_T_camera.
rotation(), cameraIndex);
586 ocean_assert(isValid());
588 return cameraGravityInCameras_;
594 ocean_assert(isValid());
596 return worldGravityInWorld_;
602 ocean_assert(isValid());
603 ocean_assert(flippedCamera_Q_world.
isValid());
605 return flippedCamera_Q_world * worldGravityInWorld_;
611 ocean_assert(isValid());
612 ocean_assert(flippedCamera_T_world.
isValid());
614 return worldGravityInFlippedCameraIF(flippedCamera_T_world.
rotation());
620 ocean_assert(isValid());
622 return QuaternionT<T>(cameraGravityInCamera(cameraIndex), worldGravityInWorld_);
628 ocean_assert(isValid());
630 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInCamera(cameraIndex));
636 ocean_assert(isValid());
638 return QuaternionT<T>(worldGravityInWorld_, cameraGravityInFlippedCamera(cameraIndex));
644 ocean_assert(isValid());
646 return weightFactor_;
652 ocean_assert(isValid());
654 return maximalAngle_;
660 ocean_assert(isValid());
662 return minimalAngleCos_;
668 ocean_assert(isValid());
670 return cameraGravityInCameras_.size();
676 ocean_assert(isValid());
677 ocean_assert(world_Q_camera.
isValid());
679 const VectorT3<T> knownCameraGravityInWorld = cameraGravityInWorld(world_Q_camera, cameraIndex);
681 ocean_assert(worldGravityInWorld_.isUnit());
682 ocean_assert(knownCameraGravityInWorld.
isUnit());
684 const T cosine = worldGravityInWorld_ * knownCameraGravityInWorld;
693 ocean_assert(world_T_camera.
isValid());
695 return alignmentCosine(world_T_camera.
rotation(), cameraIndex);
701 ocean_assert(isValid());
702 ocean_assert(flippedCamera_Q_world.
isValid());
704 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_Q_world);
705 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
707 ocean_assert(worldGravityInFlippedCamera.
isUnit());
708 ocean_assert(knownCameraGravityInFlippedCamera.
isUnit());
710 const T cosine = worldGravityInFlippedCamera * knownCameraGravityInFlippedCamera;
719 ocean_assert(flippedCamera_T_world.
isValid());
721 return alignmentCosineIF(flippedCamera_T_world.
rotation(), cameraIndex);
734 ocean_assert(world_T_camera.
isValid());
736 return alignmentAngle(world_T_camera.
rotation(), cameraIndex);
748 ocean_assert(flippedCamera_T_world.
isValid());
750 return alignmentAngleIF(flippedCamera_T_world.
rotation(), cameraIndex);
756 ocean_assert(isValid());
758 return alignmentCosine(world_Q_camera, cameraIndex) >= minimalAngleCos_;
764 ocean_assert(world_T_camera.
isValid());
766 return isCameraAlignedWithGravity(world_T_camera.
rotation(), cameraIndex);
772 ocean_assert(isValid());
774 return alignmentCosineIF(flippedCamera_Q_world, cameraIndex) >= minimalAngleCos_;
780 ocean_assert(flippedCamera_T_world.
isValid());
781 return isCameraAlignedWithGravityIF(flippedCamera_T_world.
rotation(), cameraIndex);
789 const T angle = alignmentAngle(world_Q_camera, cameraIndex);
791 return angle <= maxAngle;
797 ocean_assert(world_T_camera.
isValid());
799 return isCameraAlignedWithGravity(world_T_camera.
rotation(), cameraIndex, maxAngle);
807 const T angle = alignmentAngleIF(flippedCamera_Q_world, cameraIndex);
809 return angle <= maxAngle;
815 ocean_assert(flippedCamera_T_world.
isValid());
817 return isCameraAlignedWithGravityIF(flippedCamera_T_world.
rotation(), cameraIndex, maxAngle);
823 ocean_assert(isValid());
824 ocean_assert(world_T_camera.
isValid());
826 const VectorT3<T> knownCameraGravityInCamera = cameraGravityInCamera(cameraIndex);
830 const VectorT3<T> worldGravityInCamera = camera_Q_world * worldGravityInWorld_;
832 const QuaternionT<T> camera_Q_aligned(knownCameraGravityInCamera, worldGravityInCamera);
836 ocean_assert(isCameraAlignedWithGravity(world_T_alignedCamera, cameraIndex,
NumericT<T>::deg2rad(1)));
838 return world_T_alignedCamera;
844 ocean_assert(isValid());
845 ocean_assert(flippedCamera_T_world.
isValid());
847 const VectorT3<T> knownCameraGravityInFlippedCamera = cameraGravityInFlippedCamera(cameraIndex);
848 const VectorT3<T> worldGravityInFlippedCamera = worldGravityInFlippedCameraIF(flippedCamera_T_world);
850 const QuaternionT<T> aligned_Q_flippedCamera(worldGravityInFlippedCamera, knownCameraGravityInFlippedCamera);
854 ocean_assert(isCameraAlignedWithGravityIF(alignedFlippedCamera_T_world, cameraIndex,
NumericT<T>::deg2rad(1)));
856 return alignedFlippedCamera_T_world;
862 if (pointerIfValid && isValid())
873 const bool valid = weightFactor_ >= T(0)
875 && !cameraGravityInCameras_.isEmpty() && !worldGravityInWorld_.isNull();
880 for (
const VectorT3<T>& cameraGravityInCamera : cameraGravityInCameras_)
882 ocean_assert(cameraGravityInCamera.
isUnit());
885 ocean_assert(worldGravityInWorld_.isUnit());
895 ocean_assert(camera_Q_world.
isValid());
896 ocean_assert(worldGravityInWorld.
isUnit());
898 return camera_Q_world * worldGravityInWorld;
904 ocean_assert(camera_T_world.
isValid());
905 ocean_assert(worldGravityInWorld.
isUnit());
910 return camera_R_world * worldGravityInWorld;
916 ocean_assert(flippedCamera_T_world.
isValid());
917 ocean_assert(worldGravityInWorld.
isUnit());
919 const VectorT3<T> cameraGravityInFlippedCamera = cameraGravityInFlippedCameraIF(flippedCamera_T_world, worldGravityInWorld);
921 return VectorT3<T>(cameraGravityInFlippedCamera.
x(), -cameraGravityInFlippedCamera.
y(), -cameraGravityInFlippedCamera.
z());
927 ocean_assert(flippedCamera_T_world.
isValid());
928 ocean_assert(worldGravityInWorld.
isUnit());
933 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: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