8#ifndef META_OCEAN_MATH_CAMERA_H
9#define META_OCEAN_MATH_CAMERA_H
108 static T
fovX2Y(
const T fovX,
const T aspectRatio);
116 static T
fovY2X(
const T fovY,
const T aspectRatio);
183 template <
typename U = T>
193 template <
typename U = T>
203 template <
typename U = T>
213 template <
typename U>
223 template <
typename U>
233 template <
typename U>
243 template <
typename U>
253 template <
typename U>
263 template <
typename U>
273 template <
typename U>
283 template <
typename U>
293 template <
typename U>
305 template <
typename U>
318 template <
typename U>
331 template <
typename U>
343 template <
typename U>
355 template <
typename U>
367 template <
typename U>
377 template <
typename U>
388 template <
typename U>
399 template <
typename U>
409 template <
typename U>
419 template <
typename U>
429 template <
typename U>
472 ocean_assert(width > 0u);
475 const T width_2 = T(width) * T(0.5);
483 ocean_assert(world_T_camera.
isValid());
485 return objectPoint2normalizedImagePointIF(standard2InvertedFlipped(world_T_camera), objectPoint);
491 ocean_assert(flippedCamera_T_world.
isValid());
493 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * objectPoint);
501 const T factor = T(1) / transformedObjectPoint.
z();
502 return VectorT2<T>(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
508 ocean_assert(world_T_camera.
isValid());
509 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
511 objectPoints2normalizedImagePointsIF(standard2InvertedFlipped(world_T_camera), objectPoints, numberObjectPoints, normalizedImagePoints);
517 ocean_assert(flippedCamera_T_world.
isValid());
518 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
520 for (
unsigned int n = 0u; n < numberObjectPoints; ++n)
522 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * objectPoints[n]);
528 const T factor = T(1) / transformedObjectPoint.
z();
529 normalizedImagePoints[n].
x() = transformedObjectPoint.
x() * factor;
530 normalizedImagePoints[n].
y() = transformedObjectPoint.
y() * factor;
534 normalizedImagePoints[n].
x() = 0;
535 normalizedImagePoints[n].
y() = 0;
544 ocean_assert(
SquareMatrixT3<U>(1, 0, 0, 0, -1, 0, 0, 0, -1) ==
SquareMatrixT3<U>(
RotationT<U>(1, 0, 0,
NumericT<U>::pi())));
553 const U flipValues[16] =
588 result[1] = -result[1];
589 result[2] = -result[2];
591 result[5] = -result[5];
592 result[6] = -result[6];
594 result[9] = -result[9];
595 result[10] = -result[10];
597 result[13] = -result[13];
598 result[14] = -result[14];
600 ocean_assert(result == flipMatrix4<U>() * left_T_right);
618 result[4] = -result[4];
619 result[5] = -result[5];
620 result[6] = -result[6];
622 result[8] = -result[8];
623 result[9] = -result[9];
624 result[10] = -result[10];
626 ocean_assert(result == left_T_right * flipMatrix4<U>());
644 result[1] = -result[1];
645 result[2] = -result[2];
647 result[4] = -result[4];
649 result[8] = -result[8];
651 result[13] = -result[13];
652 result[14] = -result[14];
654 ocean_assert(result == flipMatrix4<U>() * left_T_right * flipMatrix4<U>());
671 result[1] = -result[1];
672 result[2] = -result[2];
674 result[4] = -result[4];
675 result[5] = -result[5];
677 result[7] = -result[7];
678 result[8] = -result[8];
680 ocean_assert(result == left_R_right * flipMatrix3<U>());
712 result[1] = -result[1];
713 result[2] = -result[2];
715 result[3] = -result[3];
717 result[6] = -result[6];
719 ocean_assert(result == flipMatrix3<U>() * left_R_right * flipMatrix3<U>());
728 return flipQuaternion<U>() * left_Q_right;
735 return left_Q_right * flipQuaternion<U>();
742 return flipQuaternion<U>() * left_Q_right * flipQuaternion<U>();
750 flippedCameras_T_world.reserve(number);
752 for (
size_t n = 0; n < number; ++n)
754 flippedCameras_T_world.emplace_back(standard2InvertedFlipped<U>(world_T_cameras[n]));
757 return flippedCameras_T_world;
764 for (
size_t n = 0; n < number; ++n)
766 flippedCameras_T_world[n] = standard2InvertedFlipped<U>(world_T_cameras[n]);
774 return standard2InvertedFlipped<U>(world_T_cameras.data(), world_T_cameras.size());
781 ocean_assert(world_T_camera.
isValid());
783 return flippedTransformationRightSide<U>(world_T_camera).inverted();
790 return flippedTransformationRightSide<U>(world_R_camera).
inverted();
797 return flippedTransformationRightSide<U>(world_Q_camera).
inverted();
804 ocean_assert(flippedCamera_T_world.
isValid());
806 return flippedTransformationRightSide<U>(flippedCamera_T_world.
inverted());
813 return flippedTransformationRightSide<U>(flippedCamera_R_world.
inverted());
820 return flippedTransformationRightSide<U>(flippedCamera_Q_world.
inverted());
828 cameras_T_world.reserve(number);
830 for (
size_t n = 0; n < number; ++n)
832 cameras_T_world.emplace_back(invertedFlipped2Standard<U>(flippedCameras_T_world[n]));
835 return cameras_T_world;
842 for (
size_t n = 0; n < number; ++n)
844 world_T_camera[n] = invertedFlipped2Standard<U>(flippedCameras_T_world[n]);
852 return invertedFlipped2Standard<U>(flippedCameras_T_world.data(), flippedCameras_T_world.size());
858 ocean_assert(flippedCamera_T_world.
isValid());
859 ocean_assert(epsilon >= 0);
863 ocean_assert((flippedCamera_T_world[2] * objectPoint.
x() + flippedCamera_T_world[6] * objectPoint.
y() + flippedCamera_T_world[10] * objectPoint.
z() + flippedCamera_T_world[14] > epsilon) == ((flippedCamera_T_world * objectPoint).z() > epsilon));
864 return flippedCamera_T_world[2] * objectPoint.
x() + flippedCamera_T_world[6] * objectPoint.
y() + flippedCamera_T_world[10] * objectPoint.
z() + flippedCamera_T_world[14] > epsilon;
870 ocean_assert(!flippedCamera_R_world.
isNull());
871 ocean_assert(epsilon >= 0);
875 ocean_assert((flippedCamera_R_world[2] * objectPoint.
x() + flippedCamera_R_world[5] * objectPoint.
y() + flippedCamera_R_world[8] * objectPoint.
z() > epsilon) == ((flippedCamera_R_world * objectPoint).z() > epsilon));
876 return flippedCamera_R_world[2] * objectPoint.
x() + flippedCamera_R_world[5] * objectPoint.
y() + flippedCamera_R_world[8] * objectPoint.
z() > epsilon;
static HomogenousMatricesT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > *world_T_cameras, const size_t number)
Transforms standard homogenous 4x4 viewing (extrinsic camera) matrices into an inverted and flipped c...
Definition Camera.h:747
static void invertedFlipped2Standard(const HomogenousMatrixT4< U > *flippedCameras_T_world, HomogenousMatrixT4< U > *world_T_cameras, const size_t number)
Transforms inverted and flipped camera matrices into standard viewing (extrinsic camera) matrices.
Definition Camera.h:840
static void standard2InvertedFlipped(const HomogenousMatrixT4< U > *world_T_cameras, HomogenousMatrixT4< U > *flippedCameras_T_world, const size_t number)
Transforms standard homogenous 4x4 viewing (extrinsic camera) matrices into an inverted and flipped c...
Definition Camera.h:762
static QuaternionT< U > flippedTransformationLeftSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:726
static HomogenousMatricesT4< U > invertedFlipped2Standard(const HomogenousMatricesT4< U > &flippedCameras_T_world)
Transforms inverted and flipped camera matrices into standard viewing (extrinsic camera) matrices.
Definition Camera.h:850
static HomogenousMatrixT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > &world_T_camera)
Transforms a standard homogenous 4x4 viewing (extrinsic camera) matrix into an inverted and flipped c...
Definition Camera.h:779
static void objectPoints2normalizedImagePointsIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > *objectPoints, const size_t numberObjectPoints, VectorT2< T > *normalizedImagePoints)
Calculates the normalized image points (the normalized projected object points) for a set of given ob...
Definition Camera.h:515
static QuaternionT< U > flipQuaternion()
Returns the quaternion flipping a rotation around the x-axis by 180 deg.
Definition Camera.h:568
static HomogenousMatrixT4< U > flipMatrix4()
Returns the 4x4 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition Camera.h:551
static SquareMatrixT3< U > flippedTransformationLeftSide(const SquareMatrixT3< U > &left_R_right)
Flips a 3x3 rotation matrix around the x-axis by 180 degree.
Definition Camera.h:661
static QuaternionT< U > standard2InvertedFlipped(const QuaternionT< U > &world_Q_camera)
Transforms a standard rotation quaternion into an inverted and flipped rotation quaternion.
Definition Camera.h:795
static VectorT2< T > objectPoint2normalizedImagePoint(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > &objectPoint)
Calculates the normalized image point (the normalized projected object point) for a of given object p...
Definition Camera.h:481
static VectorT2< T > objectPoint2normalizedImagePointIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &objectPoint)
Calculates the normalized image point (the normalized projected object point) for a given object poin...
Definition Camera.h:489
static HomogenousMatrixT4< U > flippedTransformationRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:607
static T fieldOfViewToFocalLength(const unsigned int width, const T fovX)
Converts field of view (and width) to the corresponding focal length.
Definition Camera.h:470
static HomogenousMatrixT4< U > flippedTransformationLeftSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:577
static SquareMatrixT3< U > standard2InvertedFlipped(const SquareMatrixT3< U > &world_R_camera)
Transforms a standard 3x3 rotation matrix into an inverted and flipped rotation matrix.
Definition Camera.h:788
static QuaternionT< U > flippedTransformationLeftAndRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:740
static void objectPoints2normalizedImagePoints(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > *objectPoints, const size_t numberObjectPoints, VectorT2< T > *normalizedImagePoints)
Calculates the normalized image points (the normalized projected object points) for a set of given ob...
Definition Camera.h:506
static HomogenousMatrixT4< U > invertedFlipped2Standard(const HomogenousMatrixT4< U > &flippedCamera_T_world)
Transforms an inverted and flipped camera pose into a standard camera pose.
Definition Camera.h:802
static SquareMatrixT3< U > flipMatrix3()
Returns the 3x3 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition Camera.h:542
static SquareMatrixT3< U > flippedTransformationRightSide(const SquareMatrixT3< U > &left_R_right)
Flips a 3x3 rotation matrix around the x-axis by 180 degree.
Definition Camera.h:687
static HomogenousMatricesT4< U > standard2InvertedFlipped(const HomogenousMatricesT4< U > &world_T_cameras)
Transforms standard homogenous 4x4 viewing (extrinsic camera) matrices into an inverted and flipped c...
Definition Camera.h:772
static SquareMatrixT3< U > invertedFlipped2Standard(const SquareMatrixT3< U > &flippedCamera_R_world)
Transforms an inverted and flipped rotation matrix into a standard viewing rotation matrix.
Definition Camera.h:811
static QuaternionT< U > flippedTransformationRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:733
static bool isObjectPointInFrontIF(const SquareMatrixT3< T > &flippedCamera_R_world, const VectorT3< T > &objectPoint, const T epsilon=NumericT< T >::eps())
Determines whether a given 3D object point lies in front of a camera while the location of the camera...
Definition Camera.h:868
static HomogenousMatrixT4< U > flippedTransformationLeftAndRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:633
static T fovY2X(const T fovY, const T aspectRatio)
Calculates the horizontal FOV from the vertical FOV and the aspect ratio of the camera image.
Definition Camera.h:462
static QuaternionT< U > invertedFlipped2Standard(const QuaternionT< U > &flippedCamera_Q_world)
Transforms an inverted and flipped rotation quaternion into a standard viewing rotation quaternion.
Definition Camera.h:818
static T fovX2Y(const T fovX, const T aspectRatio)
Calculates the vertical FOV from the horizontal FOV and the aspect ratio of the camera image.
Definition Camera.h:454
static SquareMatrixT3< U > flippedTransformationLeftAndRightSide(const SquareMatrixT3< U > &left_R_right)
Flips a 3x3 rotation matrix around the x-axis by 180 degree.
Definition Camera.h:702
static bool isObjectPointInFrontIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &objectPoint, const T epsilon=NumericT< T >::eps())
Determines whether a given 3D object point lies in front of a camera while the location of the camera...
Definition Camera.h:856
static HomogenousMatricesT4< U > invertedFlipped2Standard(const HomogenousMatrixT4< U > *flippedCameras_T_world, const size_t number)
Transforms inverted and flipped camera matrices into standard viewing (extrinsic camera) matrices.
Definition Camera.h:825
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition HomogenousMatrix4.h:110
HomogenousMatrixT4< T > inverted() const noexcept
Returns the inverted of this matrix.
Definition HomogenousMatrix4.h:1575
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
This class provides basic numeric functionalities.
Definition Numeric.h:57
static T atan(const T value)
Returns the arctangent of a given value.
Definition Numeric.h:1620
static T tan(const T value)
Returns the tangent of a given value.
Definition Numeric.h:1604
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
QuaternionT< T > inverted() const
Returns the inverted quaternion.
Definition Quaternion.h:737
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:73
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
VectorT3< T > xAxis() const
Returns the x axis which is the first column of the matrix.
Definition SquareMatrix3.h:1397
bool isNull() const
Returns whether this matrix is a zero matrix.
Definition SquareMatrix3.h:1334
VectorT3< T > zAxis() const
Returns the z axis which is the last column of the matrix.
Definition SquareMatrix3.h:1409
VectorT3< T > yAxis() const
Returns the y axis which is the middle column of the matrix.
Definition SquareMatrix3.h:1403
SquareMatrixT3< T > inverted() const
Returns the inverted matrix of this matrix.
Definition SquareMatrix3.h:1177
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
This class implements a vector with three elements.
Definition Vector3.h:97
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
The namespace covering the entire Ocean framework.
Definition Accessor.h:15