8#ifndef META_OCEAN_GEOMETRY_UTILITIES_H
9#define META_OCEAN_GEOMETRY_UTILITIES_H
406 template <
typename TAccessor>
415 template <
typename TAccessor>
425 template <
typename TAccessor>
435 template <
typename TAccessor>
445 template <
typename TAccessor>
455 template <
typename TAccessor>
537 return intersectConvexPolygons(vertices0.data(), vertices0.size(), vertices1.data(), vertices1.size(), intersectedPolygon);
540template <
typename TAccessor>
543 ocean_assert(imagePointAccessor.size() > 0);
546 for (
size_t n = 0; n < imagePointAccessor.size(); ++n)
548 meanPosition += imagePointAccessor[n];
551 return meanPosition /
Scalar(imagePointAccessor.size());
554template <
typename TAccessor>
557 ocean_assert(objectPointAccessor.size() > 0);
560 for (
size_t n = 0; n < objectPointAccessor.size(); ++n)
562 meanPosition += objectPointAccessor[n];
565 return meanPosition /
Scalar(objectPointAccessor.size());
568template <
typename TAccessor>
571 ocean_assert(!imagePointAccessor.isEmpty());
573 if (imagePointAccessor.size() == 1)
575 return imagePointAccessor[0];
578 Scalars xValues(imagePointAccessor.size());
579 Scalars yValues(imagePointAccessor.size());
581 for (
size_t n = 0; n < imagePointAccessor.size(); ++n)
583 const Vector2& imagePoint = imagePointAccessor[n];
585 xValues[n] = imagePoint.
x();
586 yValues[n] = imagePoint.
y();
592 return Vector2(xMedian, yMedian);
595template <
typename TAccessor>
598 ocean_assert(!objectPointAccessor.isEmpty());
600 if (objectPointAccessor.size() == 1)
602 return objectPointAccessor[0];
605 Scalars xValues(objectPointAccessor.size());
606 Scalars yValues(objectPointAccessor.size());
607 Scalars zValues(objectPointAccessor.size());
609 for (
size_t n = 0; n < objectPointAccessor.size(); ++n)
611 const ObjectPoint& objectPoint = objectPointAccessor[n];
613 xValues[n] = objectPoint.
x();
614 yValues[n] = objectPoint.
y();
615 zValues[n] = objectPoint.
z();
625template <
typename TAccessor>
629 sqrDistances.reserve(imagePointAccessor.size());
631 for (
size_t n = 0; n < imagePointAccessor.size(); ++n)
633 sqrDistances.push_back(imagePoint.
sqrDistance(imagePointAccessor[n]));
639template <
typename TAccessor>
643 sqrDistances.reserve(objectPointAccessor.size());
645 for (
size_t n = 0; n < objectPointAccessor.size(); ++n)
647 sqrDistances.push_back(objectPoint.
sqrDistance(objectPointAccessor[n]));
static HomogenousMatrixT4< U > standard2InvertedFlipped(const HomogenousMatrixT4< U > &world_T_camera)
This class implements a base class for all indexed-based accessors allowing a constant reference acce...
Definition Accessor.h:241
This class implements an accessor providing direct access to a constant array of elements.
Definition Accessor.h:600
This class implements utilities function for the tracking library.
Definition geometry/Utilities.h:36
static Vector2 medianImagePoint(const TAccessor &imagePointAccessor)
Returns the median position of a set of given 2D points.
Definition geometry/Utilities.h:569
static bool isPolygonConvex(const Vector2 *vertices, const size_t size, const bool strict=true)
Returns whether a polygon of given 2D points is convex.
static bool decomposeCovarianceMatrix(const SquareMatrix2 &covarianceMatrix, Vector2 &direction0, Vector2 &direction1)
Decomposes a covariance matrix.
static bool intersectConvexPolygons(const Vector2 *vertices0, const size_t size0, const Vector2 *vertices1, const size_t size1, Vectors2 &intersectedPolygon)
Computation of the intersection of two convex polygons.
static Triangles3 backProjectTriangles(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const Triangle2 *triangles, const size_t numberTriangles, const bool useDistortionParameters)
Projects a set of given 2D image triangles onto a 3D plane and returns the resulting 3D object triang...
static Scalar medianDistance(const Vector2 &imagePoint, const TAccessor &imagePointAccessor)
Returns the median distance between a given 2D object point and a set of given 2D points.
Definition geometry/Utilities.h:626
static Vectors3 createObjectPoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const ConstIndexedAccessor< Vector2 > &imagePoints, const bool useDistortionParameters, const Scalar distance)
Deprecated.
static SquareMatrix2 covarianceMatrix(const Vector2 *imagePoints, const unsigned int *indices, const size_t numberIndices, const Scalar minimalSigma, Vector2 &meanPoint)
Creates the covariance matrix for a given set of image points.
static SquareMatrix3 createRandomHomography(const unsigned int width, const unsigned height, const Scalar maxTranslation)
Create a random homography transformation The homography is created in such a way that points in an o...
static void triangulateObjectPoints(const AnyCamera &camera0, const AnyCamera &camera1, const HomogenousMatrix4 &world_T_camera0, const HomogenousMatrix4 &world_T_camera1, const ConstIndexedAccessor< Vector2 > &imagePoints0, const ConstIndexedAccessor< Vector2 > &imagePoints1, Vectors3 &objectPoints, Indices32 &validIndices, const bool onlyFrontPoints=true, const Scalar maximalSqrError=Scalar(3 *3))
Determines 3D object points by triangulating two sets of 2D image points from different camera poses.
static Scalar computePolygonAreaSigned(const Vector2 *vertices, size_t size)
Compute the signed area of a polygon The value of the area will be positive if the vertices are in co...
static Vectors3 createObjectPoints(const AnyCamera &camera, const HomogenousMatrix4 &world_T_camera, const ConstIndexedAccessor< Vector2 > &imagePoints, const Scalar distance)
Creates a set of 3D object points for a set of given 2D image points.
static Vectors3 backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const Vector2 *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 *frontObjectPointIndices=nullptr)
Deprecated.
static size_t countFrontObjectPoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const ObjectPoint *objectPoints, const size_t numberObjectPoints)
Counts the number of object points that are in front of a given camera.
Definition geometry/Utilities.h:503
static Vectors3 backProjectImagePointsDamped(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const Vector2 *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 *frontObjectPointIndices=nullptr)
Projects a set of given image points onto a 3D plane and returns the resulting 3D object points.
static SquareMatrix2 covarianceMatrix(const Vector2 *imagePoints, const size_t number, const Scalar minimalSigma=0)
Creates the covariance matrix for a given set of image points.
Definition geometry/Utilities.h:510
static ObjectPoint medianObjectPoint(const TAccessor &objectPointAccessor)
Returns the median position of a set of given 3D points.
Definition geometry/Utilities.h:596
static Vectors3 backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Plane3 &plane, const Vector2 *imagePoints, const size_t numberImagePoints, Indices32 *frontObjectPointIndices=nullptr)
Projects a set of given image points onto a 3D plane and returns the resulting 3D object points.
static ObjectPoint backProjectImagePoint(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const Vector2 &imagePoint, const bool useDistortionParameters, bool *frontObjectPoint=nullptr)
Projects one image points onto a 3D plane and returns the resulting 3D object point.
static HomogenousMatrix4 randomCameraPose(const AnyCamera &anyCamera, const Line3 &worldObjectPointRay, const Vector2 &distortedImagePoint, const Scalar distance)
Returns a random 6-DOF camera pose for any camera which observes a given 3D object point at a specifi...
static HomogenousMatrix4 randomCameraPose(const FisheyeCamera &fisheyeCamera, const Line3 &worldObjectPointRay, const Vector2 &distortedImagePoint, const Scalar distance)
Deprecated.
static ObjectPoint meanObjectPoint(const TAccessor &objectPointAccessor)
Returns the mean position of a set of given 3D points.
Definition geometry/Utilities.h:555
static bool isInsideConvexPolygon(const Vector2 *vertices, size_t size, const Vector2 &point)
Returns whether a given point lies inside a convex polygon.
static SquareMatrix2 covarianceMatrix(const Vector2 *imagePoints, const size_t number, const Vector2 &meanPoint, const Scalar minimalSigma=0)
Creates the covariance matrix for a given set of image points.
static SquareMatrix2 covarianceMatrix(const Vector2 &majorDirection, const Scalar minimalSigma=1, const Scalar minorFactor=Scalar(0.01))
Creates a covariance matrix by one given vector representing the major axis.
static Vector2 meanImagePoint(const TAccessor &imagePointAccessor)
Returns the mean position of a set of given 2D points.
Definition geometry/Utilities.h:541
static Vectors3 backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Cylinder3 &cylinder, const Vector2 *imagePoints, const size_t numberImagePoints, Indices32 &intersectingPointIndices)
Projects a set of given image points onto a 3D cylinder and returns only the resulting 3D object poin...
static SquareMatrix2 covarianceMatrix(const Vector2 &direction0, const Scalar sigma0, const Vector2 &direction1, const Scalar sigma1)
Creates a covariance matrix by two given orthogonal vectors.
static SquareMatrix2 covarianceMatrix(const Vector2 &direction0, const Vector2 &direction1)
Creates a covariance matrix by two given orthogonal vectors.
static Vectors3 backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Cone3 &cone, const Vector2 *imagePoints, const size_t numberImagePoints, Indices32 &intersectingPointIndices)
Projects a set of given image points onto a 3D cone and returns only the resulting 3D object points f...
static size_t countFrontObjectPointsIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &invertedFlippedPose, const ObjectPoint *objectPoints, const size_t numberObjectPoints)
Counts the number of object points that are in front of a given camera.
static Vectors3 backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Cylinder3 &cylinder, const Vector2 *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 &intersectingPointIndices)
Deprecated.
static size_t countFrontObjectPoints(const PinholeCamera &cameraFirst, const PinholeCamera &cameraSecond, const HomogenousMatrix4 &poseFirst, const HomogenousMatrix4 &poseSecond, const Vector2 *imagePointsFirst, const Vector2 *imagePointsSecond, const size_t correspondences)
Counts the number of object points that are visible in two individual camera frames and are located i...
static Scalar computePolygonArea(const Vector2 *vertices, size_t size)
Compute the area of a polygon.
Definition geometry/Utilities.h:515
static HomogenousMatrix4 randomCameraPose(const PinholeCamera &pinholeCamera, const Line3 &worldObjectPointRay, const Vector2 &distortedImagePoint, const Scalar distance)
Deprecated.
static Vectors3 backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Cone3 &cone, const Vector2 *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 &intersectingPointIndices)
Deprecated.
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
static Scalar abs(const Scalar value)
static Scalar sqrt(const Scalar value)
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
T sqrDistance(const VectorT2< T > &right) const
Returns the square distance between this 2D position and a second 2D position.
Definition Vector2.h:638
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
T sqrDistance(const VectorT3< T > &right) const
Returns the square distance between this 3D position and a second 3D position.
Definition Vector3.h:686
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
Vector3 ObjectPoint
Definition of a 3D object point.
Definition geometry/Geometry.h:117
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
PlaneT3< Scalar > Plane3
Definition of the Plane3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition Plane3.h:31
PinholeCameraT< Scalar > PinholeCamera
Definition of an pinhole camera object with Scalar precision.
Definition PinholeCamera.h:39
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
AnyCameraT< Scalar > AnyCamera
Definition of an AnyCamera object with Scalar precision.
Definition AnyCamera.h:31
CylinderT3< Scalar > Cylinder3
Definition of the Cylinder3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Cylinder3.h:30
SquareMatrixT2< Scalar > SquareMatrix2
Definition of the SquareMatrix2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition SquareMatrix2.h:29
ConeT3< Scalar > Cone3
Definition of the Cone3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Cone3.h:30
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition SquareMatrix3.h:43
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
LineT3< Scalar > Line3
Definition of the Line3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Line3.h:27
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition Triangle3.h:57
FisheyeCameraT< Scalar > FisheyeCamera
Definition of a FisheyeCamera object using Scalar as data type.
Definition FisheyeCamera.h:31
TriangleT2< Scalar > Triangle2
Definition of the Triangle2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Triangle2.h:28
float Scalar
Definition of a scalar type.
Definition Math.h:129
Namespace of the Geometry library.
Definition AbsoluteTransformation.h:20
The namespace covering the entire Ocean framework.
Definition Accessor.h:15