8#ifndef META_OCEAN_MATH_CAMERA_H
9#define META_OCEAN_MATH_CAMERA_H
22template <
typename T>
class CameraT;
107 static T
fovX2Y(
const T fovX,
const T aspectRatio);
115 static T
fovY2X(
const T fovY,
const T aspectRatio);
182 template <
typename U = T>
192 template <
typename U = T>
202 template <
typename U = T>
212 template <
typename U>
222 template <
typename U>
232 template <
typename U>
242 template <
typename U>
252 template <
typename U>
262 template <
typename U>
272 template <
typename U>
282 template <
typename U>
292 template <
typename U>
304 template <
typename U>
317 template <
typename U>
330 template <
typename U>
342 template <
typename U>
354 template <
typename U>
366 template <
typename U>
376 template <
typename U>
387 template <
typename U>
398 template <
typename U>
408 template <
typename U>
418 template <
typename U>
428 template <
typename U>
455 ocean_assert(aspectRatio != 0);
463 ocean_assert(aspectRatio != 0);
471 ocean_assert(width > 0u);
474 const T width_2 = T(width) * T(0.5);
482 ocean_assert(world_T_camera.
isValid());
484 return objectPoint2normalizedImagePointIF(standard2InvertedFlipped(world_T_camera), objectPoint);
490 ocean_assert(flippedCamera_T_world.
isValid());
492 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * objectPoint);
500 const T factor = 1 / transformedObjectPoint.
z();
501 return VectorT2<T>(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
507 ocean_assert(world_T_camera.
isValid());
508 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
510 objectPoints2normalizedImagePointsIF(standard2InvertedFlipped(world_T_camera), objectPoints, numberObjectPoints, normalizedImagePoints);
516 ocean_assert(flippedCamera_T_world.
isValid());
517 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
519 for (
unsigned int n = 0u; n < numberObjectPoints; ++n)
521 const VectorT3<T> transformedObjectPoint(flippedCamera_T_world * objectPoints[n]);
527 const T factor = 1 / transformedObjectPoint.
z();
528 normalizedImagePoints[n].
x() = transformedObjectPoint.
x() * factor;
529 normalizedImagePoints[n].
y() = transformedObjectPoint.
y() * factor;
533 normalizedImagePoints[n].
x() = 0;
534 normalizedImagePoints[n].
y() = 0;
543 ocean_assert(
SquareMatrixT3<U>(1, 0, 0, 0, -1, 0, 0, 0, -1) ==
SquareMatrixT3<U>(
RotationT<U>(1, 0, 0,
NumericT<U>::pi())));
552 const U flipValues[16] =
587 result[1] = -result[1];
588 result[2] = -result[2];
590 result[5] = -result[5];
591 result[6] = -result[6];
593 result[9] = -result[9];
594 result[10] = -result[10];
596 result[13] = -result[13];
597 result[14] = -result[14];
599 ocean_assert(result == flipMatrix4<U>() * left_T_right);
617 result[4] = -result[4];
618 result[5] = -result[5];
619 result[6] = -result[6];
621 result[8] = -result[8];
622 result[9] = -result[9];
623 result[10] = -result[10];
625 ocean_assert(result == left_T_right * flipMatrix4<U>());
643 result[1] = -result[1];
644 result[2] = -result[2];
646 result[4] = -result[4];
648 result[8] = -result[8];
650 result[13] = -result[13];
651 result[14] = -result[14];
653 ocean_assert(result == flipMatrix4<U>() * left_T_right * flipMatrix4<U>());
670 result[1] = -result[1];
671 result[2] = -result[2];
673 result[4] = -result[4];
674 result[5] = -result[5];
676 result[7] = -result[7];
677 result[8] = -result[8];
679 ocean_assert(result == left_R_right * flipMatrix3<U>());
711 result[1] = -result[1];
712 result[2] = -result[2];
714 result[3] = -result[3];
716 result[6] = -result[6];
718 ocean_assert(result == flipMatrix3<U>() * left_R_right * flipMatrix3<U>());
727 return flipQuaternion<U>() * left_Q_right;
734 return left_Q_right * flipQuaternion<U>();
741 return flipQuaternion<U>() * left_Q_right * flipQuaternion<U>();
749 flippedCameras_T_world.reserve(number);
751 for (
size_t n = 0; n < number; ++n)
753 flippedCameras_T_world.emplace_back(standard2InvertedFlipped<U>(world_T_cameras[n]));
756 return flippedCameras_T_world;
763 for (
size_t n = 0; n < number; ++n)
765 flippedCameras_T_world[n] = standard2InvertedFlipped<U>(world_T_cameras[n]);
773 return standard2InvertedFlipped<U>(world_T_cameras.data(), world_T_cameras.size());
780 ocean_assert(world_T_camera.
isValid());
782 return flippedTransformationRightSide<U>(world_T_camera).inverted();
789 return flippedTransformationRightSide<U>(world_R_camera).
inverted();
796 return flippedTransformationRightSide<U>(world_Q_camera).
inverted();
803 ocean_assert(flippedCamera_T_world.
isValid());
805 return flippedTransformationRightSide<U>(flippedCamera_T_world.
inverted());
812 return flippedTransformationRightSide<U>(flippedCamera_R_world.
inverted());
819 return flippedTransformationRightSide<U>(flippedCamera_Q_world.
inverted());
827 cameras_T_world.reserve(number);
829 for (
size_t n = 0; n < number; ++n)
831 cameras_T_world.emplace_back(invertedFlipped2Standard<U>(flippedCameras_T_world[n]));
834 return cameras_T_world;
841 for (
size_t n = 0; n < number; ++n)
843 world_T_camera[n] = invertedFlipped2Standard<U>(flippedCameras_T_world[n]);
851 return invertedFlipped2Standard<U>(flippedCameras_T_world.data(), flippedCameras_T_world.size());
857 ocean_assert(flippedCamera_T_world.
isValid());
858 ocean_assert(epsilon >= 0);
862 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));
863 return flippedCamera_T_world[2] * objectPoint.
x() + flippedCamera_T_world[6] * objectPoint.
y() + flippedCamera_T_world[10] * objectPoint.
z() + flippedCamera_T_world[14] > epsilon;
869 ocean_assert(!flippedCamera_R_world.
isNull());
870 ocean_assert(epsilon >= 0);
874 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));
875 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:746
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:839
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:761
static QuaternionT< U > flippedTransformationLeftSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:725
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:849
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:778
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:514
static QuaternionT< U > flipQuaternion()
Returns the quaternion flipping a rotation around the x-axis by 180 deg.
Definition Camera.h:567
static HomogenousMatrixT4< U > flipMatrix4()
Returns the 4x4 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition Camera.h:550
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:660
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:794
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:480
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:488
static HomogenousMatrixT4< U > flippedTransformationRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:606
static T fieldOfViewToFocalLength(const unsigned int width, const T fovX)
Converts field of view (and width) to the corresponding focal length.
Definition Camera.h:469
static HomogenousMatrixT4< U > flippedTransformationLeftSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:576
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:787
static QuaternionT< U > flippedTransformationLeftAndRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:739
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:505
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:801
static SquareMatrixT3< U > flipMatrix3()
Returns the 3x3 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition Camera.h:541
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:686
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:771
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:810
static QuaternionT< U > flippedTransformationRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition Camera.h:732
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:867
static HomogenousMatrixT4< U > flippedTransformationLeftAndRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition Camera.h:632
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:461
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:817
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:453
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:701
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:855
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:824
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