8 #ifndef META_OCEAN_MATH_CAMERA_H
9 #define META_OCEAN_MATH_CAMERA_H
22 template <
typename T>
class CameraT;
63 static T
fovX2Y(
const T fovX,
const T aspectRatio);
71 static T
fovY2X(
const T fovY,
const T aspectRatio);
138 template <
typename U = T>
148 template <
typename U = T>
158 template <
typename U = T>
168 template <
typename U>
178 template <
typename U>
188 template <
typename U>
198 template <
typename U>
208 template <
typename U>
218 template <
typename U>
228 template <
typename U>
238 template <
typename U>
248 template <
typename U>
260 template <
typename U>
273 template <
typename U>
286 template <
typename U>
298 template <
typename U>
310 template <
typename U>
322 template <
typename U>
332 template <
typename U>
343 template <
typename U>
354 template <
typename U>
364 template <
typename U>
374 template <
typename U>
384 template <
typename U>
408 template <
typename T>
411 ocean_assert(aspectRatio != 0);
416 template <
typename T>
419 ocean_assert(aspectRatio != 0);
424 template <
typename T>
427 ocean_assert(width > 0u);
430 const T width_2 = T(width) * T(0.5);
435 template <
typename T>
438 ocean_assert(extrinsic.
isValid());
440 return objectPoint2normalizedImagePointIF(standard2InvertedFlipped(extrinsic), objectPoint);
443 template <
typename T>
446 ocean_assert(iFlippedExtrinsic.
isValid());
448 const VectorT3<T> transformedObjectPoint(iFlippedExtrinsic * objectPoint);
456 const T factor = 1 / transformedObjectPoint.
z();
457 return VectorT2<T>(transformedObjectPoint.
x() * factor, transformedObjectPoint.
y() * factor);
460 template <
typename T>
463 ocean_assert(extrinsic.
isValid());
464 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
466 objectPoints2normalizedImagePointsIF(standard2InvertedFlipped(extrinsic), objectPoints, numberObjectPoints, normalizedImagePoints);
469 template <
typename T>
472 ocean_assert(iFlippedExtrinsic.
isValid());
473 ocean_assert(numberObjectPoints == 0u || (objectPoints && normalizedImagePoints));
475 for (
unsigned int n = 0u; n < numberObjectPoints; ++n)
477 const VectorT3<T> transformedObjectPoint(iFlippedExtrinsic * objectPoints[n]);
483 const T factor = 1 / transformedObjectPoint.
z();
484 normalizedImagePoints[n].
x() = transformedObjectPoint.
x() * factor;
485 normalizedImagePoints[n].
y() = transformedObjectPoint.
y() * factor;
489 normalizedImagePoints[n].
x() = 0;
490 normalizedImagePoints[n].
y() = 0;
495 template <
typename T>
496 template <
typename U>
499 ocean_assert(
SquareMatrixT3<U>(1, 0, 0, 0, -1, 0, 0, 0, -1) ==
SquareMatrixT3<U>(
RotationT<U>(1, 0, 0,
NumericT<U>::pi())));
504 template <
typename T>
505 template <
typename U>
508 const U flipValues[16] =
521 template <
typename T>
522 template <
typename U>
530 template <
typename T>
531 template <
typename U>
543 result[1] = -result[1];
544 result[2] = -result[2];
546 result[5] = -result[5];
547 result[6] = -result[6];
549 result[9] = -result[9];
550 result[10] = -result[10];
552 result[13] = -result[13];
553 result[14] = -result[14];
555 ocean_assert(result == flipMatrix4<U>() * left_T_right);
560 template <
typename T>
561 template <
typename U>
573 result[4] = -result[4];
574 result[5] = -result[5];
575 result[6] = -result[6];
577 result[8] = -result[8];
578 result[9] = -result[9];
579 result[10] = -result[10];
581 ocean_assert(result == left_T_right * flipMatrix4<U>());
586 template <
typename T>
587 template <
typename U>
599 result[1] = -result[1];
600 result[2] = -result[2];
602 result[4] = -result[4];
604 result[8] = -result[8];
606 result[13] = -result[13];
607 result[14] = -result[14];
609 ocean_assert(result == flipMatrix4<U>() * left_T_right * flipMatrix4<U>());
614 template <
typename T>
615 template <
typename U>
626 result[1] = -result[1];
627 result[2] = -result[2];
629 result[4] = -result[4];
630 result[5] = -result[5];
632 result[7] = -result[7];
633 result[8] = -result[8];
635 ocean_assert(result == left_R_right * flipMatrix3<U>());
640 template <
typename T>
641 template <
typename U>
655 template <
typename T>
656 template <
typename U>
667 result[1] = -result[1];
668 result[2] = -result[2];
670 result[3] = -result[4];
672 result[6] = -result[5];
674 ocean_assert(result == flipMatrix3<U>() * left_R_right * flipMatrix3<U>());
679 template <
typename T>
680 template <
typename U>
683 return flipQuaternion<U>() * left_Q_right;
686 template <
typename T>
687 template <
typename U>
690 return left_Q_right * flipQuaternion<U>();
693 template <
typename T>
694 template <
typename U>
697 return flipQuaternion<U>() * left_Q_right * flipQuaternion<U>();
700 template <
typename T>
701 template <
typename U>
705 flippedCameras_T_world.reserve(number);
707 for (
size_t n = 0; n < number; ++n)
709 flippedCameras_T_world.emplace_back(standard2InvertedFlipped<U>(world_T_cameras[n]));
712 return flippedCameras_T_world;
715 template <
typename T>
716 template <
typename U>
719 for (
size_t n = 0; n < number; ++n)
721 flippedCameras_T_world[n] = standard2InvertedFlipped<U>(world_T_cameras[n]);
725 template <
typename T>
726 template <
typename U>
729 return standard2InvertedFlipped<U>(world_T_cameras.data(), world_T_cameras.size());
732 template <
typename T>
733 template <
typename U>
736 ocean_assert(world_T_camera.
isValid());
738 return flippedTransformationRightSide<U>(world_T_camera).inverted();
741 template <
typename T>
742 template <
typename U>
745 return flippedTransformationRightSide<U>(world_R_camera).inverted();
748 template <
typename T>
749 template <
typename U>
752 return flippedTransformationRightSide<U>(world_Q_camera).inverted();
755 template <
typename T>
756 template <
typename U>
759 ocean_assert(flippedCamera_T_world.
isValid());
761 return flippedTransformationRightSide<U>(flippedCamera_T_world.
inverted());
764 template <
typename T>
765 template <
typename U>
768 return flippedTransformationRightSide<U>(flippedCamera_R_world.
inverted());
771 template <
typename T>
772 template <
typename U>
775 return flippedTransformationRightSide<U>(flippedCamera_Q_world.
inverted());
778 template <
typename T>
779 template <
typename U>
783 cameras_T_world.reserve(number);
785 for (
size_t n = 0; n < number; ++n)
787 cameras_T_world.emplace_back(invertedFlipped2Standard<U>(flippedCameras_T_world[n]));
790 return cameras_T_world;
793 template <
typename T>
794 template <
typename U>
797 for (
size_t n = 0; n < number; ++n)
799 world_T_camera[n] = invertedFlipped2Standard<U>(flippedCameras_T_world[n]);
803 template <
typename T>
804 template <
typename U>
807 return invertedFlipped2Standard<U>(flippedCameras_T_world.data(), flippedCameras_T_world.size());
810 template <
typename T>
813 ocean_assert(flippedCamera_T_world.
isValid());
814 ocean_assert(epsilon >= 0);
818 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));
819 return flippedCamera_T_world[2] * objectPoint.
x() + flippedCamera_T_world[6] * objectPoint.
y() + flippedCamera_T_world[10] * objectPoint.
z() + flippedCamera_T_world[14] > epsilon;
822 template <
typename T>
825 ocean_assert(!flippedCamera_R_world.
isNull());
826 ocean_assert(epsilon >= 0);
830 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));
831 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:702
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:795
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:717
static QuaternionT< U > flippedTransformationLeftSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition: Camera.h:681
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:805
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:734
static void objectPoints2normalizedImagePoints(const HomogenousMatrixT4< T > &extrinsic, 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:461
static QuaternionT< U > flipQuaternion()
Returns the quaternion flipping a rotation around the x-axis by 180 deg.
Definition: Camera.h:523
static HomogenousMatrixT4< U > flipMatrix4()
Returns the 4x4 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition: Camera.h:506
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:616
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:750
static VectorT2< T > objectPoint2normalizedImagePointIF(const HomogenousMatrixT4< T > &iFlippedExtrinsic, const VectorT3< T > &objectPoint)
Calculates the normalized image point (the normalized projected object point) for a given object poin...
Definition: Camera.h:444
static HomogenousMatrixT4< U > flippedTransformationRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition: Camera.h:562
static T fieldOfViewToFocalLength(const unsigned int width, const T fovX)
Converts field of view (and width) to the corresponding focal length.
Definition: Camera.h:425
static VectorT2< T > objectPoint2normalizedImagePoint(const HomogenousMatrixT4< T > &extrinsic, const VectorT3< T > &objectPoint)
Calculates the normalized image point (the normalized projected object point) for a of given object p...
Definition: Camera.h:436
static void objectPoints2normalizedImagePointsIF(const HomogenousMatrixT4< T > &iFlippedExtrinsic, 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: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:532
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:743
static QuaternionT< U > flippedTransformationLeftAndRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition: Camera.h:695
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:757
static SquareMatrixT3< U > flipMatrix3()
Returns the 3x3 transformation matrix flipping a transformation around the x-axis by 180 deg.
Definition: Camera.h:497
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:642
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:727
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:766
static QuaternionT< U > flippedTransformationRightSide(const QuaternionT< U > &left_Q_right)
Flips a quaternion around the x-axis by 180 degree.
Definition: Camera.h:688
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:823
static HomogenousMatrixT4< U > flippedTransformationLeftAndRightSide(const HomogenousMatrixT4< U > &left_T_right)
Flips a transformation matrix around the x-axis by 180 degree.
Definition: Camera.h:588
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:417
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:773
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:409
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:657
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:811
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:780
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:1616
static T tan(const T value)
Returns the tangent of a given value.
Definition: Numeric.h:1600
This class implements a unit quaternion rotation.
Definition: Quaternion.h:100
QuaternionT< T > inverted() const
Returns the inverted quaternion.
Definition: Quaternion.h:754
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
This class implements a 3x3 square matrix.
Definition: SquareMatrix3.h:88
VectorT3< T > xAxis() const
Returns the x axis which is the first column of the matrix.
Definition: SquareMatrix3.h:1396
bool isNull() const
Returns whether this matrix is a zero matrix.
Definition: SquareMatrix3.h:1333
VectorT3< T > zAxis() const
Returns the z axis which is the last column of the matrix.
Definition: SquareMatrix3.h:1408
VectorT3< T > yAxis() const
Returns the y axis which is the middle column of the matrix.
Definition: SquareMatrix3.h:1402
SquareMatrixT3< T > inverted() const
Returns the inverted matrix of this matrix.
Definition: SquareMatrix3.h:1176
This class implements a vector with two elements.
Definition: Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
This class implements a vector with three elements.
Definition: Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
std::vector< HomogenousMatrixT4< T > > HomogenousMatricesT4
Definition of a typename alias for vectors with HomogenousMatrixT4 objects.
Definition: HomogenousMatrix4.h:66
CameraT< double > CameraD
Definition of an Camera object with double precision.
Definition: Camera.h:36
CameraT< float > CameraF
Definition of an Camera object with float precision.
Definition: Camera.h:43
CameraT< Scalar > Camera
Definition of an Camera object with Scalar precision.
Definition: Camera.h:22
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15