8 #ifndef META_OCEAN_GEOMETRY_UTILITIES_H
9 #define META_OCEAN_GEOMETRY_UTILITIES_H
331 static inline Scalar computePolygonArea(
const Vector2* vertices,
size_t size);
339 static inline Scalar computePolygonArea(
const Vectors2& vertices);
357 static inline Scalar computePolygonAreaSigned(
const Vectors2& vertices);
378 static inline bool isInsideConvexPolygon(
const Vectors2& vertices,
const Vector2& point);
398 static inline bool intersectConvexPolygons(
const Vectors2& vertices0,
const Vectors2& vertices1,
Vectors2& intersectedPolygon);
406 template <
typename TAccessor>
407 static inline ImagePoint meanImagePoint(
const TAccessor& imagePointAccessor);
415 template <
typename TAccessor>
416 static inline ObjectPoint meanObjectPoint(
const TAccessor& objectPointAccessor);
425 template <
typename TAccessor>
426 static inline ImagePoint medianImagePoint(
const TAccessor& imagePointAccessor);
435 template <
typename TAccessor>
436 static inline ObjectPoint medianObjectPoint(
const TAccessor& objectPointAccessor);
445 template <
typename TAccessor>
446 static inline Scalar medianDistance(
const ImagePoint& imagePoint,
const TAccessor& imagePointAccessor);
455 template <
typename TAccessor>
456 static inline Scalar medianDistance(
const ObjectPoint& objectPoint,
const TAccessor& objectPointAccessor);
537 return intersectConvexPolygons(vertices0.data(), vertices0.size(), vertices1.data(), vertices1.size(), intersectedPolygon);
540 template <
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());
554 template <
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());
568 template <
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 ImagePoint& imagePoint = imagePointAccessor[n];
585 xValues[n] = imagePoint.
x();
586 yValues[n] = imagePoint.
y();
595 template <
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();
625 template <
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]));
639 template <
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]));
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
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
This class implements a (possibly truncated) 3D cone.
Definition: Cone3.h:59
This class implements an accessor providing direct access to a constant array of elements.
Definition: Accessor.h:600
This class implements a 3D cylinder defined by its origin, axis, radius, and (signed) starting and st...
Definition: Cylinder3.h:80
This class implements utilities function for the tracking library.
Definition: geometry/Utilities.h:36
static ObjectPoints backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Plane3 &plane, const ImagePoint *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 ObjectPoints backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Cylinder3 &cylinder, const ImagePoint *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 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 ObjectPoints backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Cone3 &cone, const ImagePoint *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 &intersectingPointIndices)
Deprecated.
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 SquareMatrix2 covarianceMatrix(const ImagePoint *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 size_t countFrontObjectPoints(const PinholeCamera &cameraFirst, const PinholeCamera &cameraSecond, const HomogenousMatrix4 &poseFirst, const HomogenousMatrix4 &poseSecond, const ImagePoint *imagePointsFirst, const ImagePoint *imagePointsSecond, const size_t correspondences)
Counts the number of object points that are visible in two individual camera frames and are located i...
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 ImagePoint meanImagePoint(const TAccessor &imagePointAccessor)
Returns the mean position of a set of given 2D points.
Definition: geometry/Utilities.h:541
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 ObjectPoints backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const ImagePoint *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 *frontObjectPointIndices=nullptr)
Deprecated.
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 ObjectPoints backProjectImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Cylinder3 &cylinder, const ImagePoint *imagePoints, const size_t numberImagePoints, const bool useDistortionParameters, Indices32 &intersectingPointIndices)
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 ImagePoint medianImagePoint(const TAccessor &imagePointAccessor)
Returns the median position of a set of given 2D points.
Definition: geometry/Utilities.h:569
static ObjectPoint medianObjectPoint(const TAccessor &objectPointAccessor)
Returns the median position of a set of given 3D points.
Definition: geometry/Utilities.h:596
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 Scalar medianDistance(const ImagePoint &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 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 ImagePoint *imagePoints, const size_t number, const ImagePoint &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 SquareMatrix2 covarianceMatrix(const ImagePoint *imagePoints, const unsigned int *indices, const size_t numberIndices, const Scalar minimalSigma, ImagePoint &meanPoint)
Creates the covariance matrix for a given set of image points.
static ObjectPoints createObjectPoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const ConstIndexedAccessor< ImagePoint > &imagePoints, const bool useDistortionParameters, const Scalar distance)
Deprecated.
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 ObjectPoints backProjectImagePoints(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const Cone3 &cone, const ImagePoint *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 SquareMatrix2 covarianceMatrix(const Vector2 &direction0, const Vector2 &direction1)
Creates a covariance matrix by two given orthogonal vectors.
static ObjectPoint backProjectImagePoint(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const ImagePoint &imagePoint, const bool useDistortionParameters, bool *frontObjectPoint=nullptr)
Projects one image points onto a 3D plane and returns the resulting 3D object point.
static ObjectPoints backProjectImagePointsDamped(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Plane3 &plane, const ImagePoint *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 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 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.
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
This class implements an infinite line in 3D space.
Definition: Line3.h:70
static T abs(const T value)
Returns the absolute value of a given value.
Definition: Numeric.h:1220
static T sqrt(const T value)
Returns the square root of a given value.
Definition: Numeric.h:1533
This class implements a 2x2 square matrix.
Definition: SquareMatrix2.h:73
This class implements a 2D triangle with Cartesian coordinates.
Definition: Triangle2.h:81
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
T sqrDistance(const VectorT2< T > &right) const
Returns the square distance between this 2D position and a second 2D position.
Definition: Vector2.h:633
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
T sqrDistance(const VectorT3< T > &right) const
Returns the square distance between this 3D position and a second 3D position.
Definition: Vector3.h:682
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::vector< ObjectPoint > ObjectPoints
Definition of a vector holding 3D object points.
Definition: geometry/Geometry.h:129
Vector3 ObjectPoint
Definition of a 3D object point.
Definition: geometry/Geometry.h:117
Vector2 ImagePoint
Definition of a 2D image point.
Definition: geometry/Geometry.h:111
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition: Math.h:144
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition: Triangle3.h:57
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15