8 #ifndef META_OCEAN_GEOMETRY_GRID_H
9 #define META_OCEAN_GEOMETRY_GRID_H
73 class OCEAN_GEOMETRY_EXPORT
Grid
177 inline const Vector2& lowerGridCorner()
const;
183 inline const Vector2& upperGridCorner()
const;
189 inline void setPlane2worldTransformation(
const HomogenousMatrix4& newTransformation);
196 inline void setGrid2planeTransformation(
const HomogenousMatrix4& newTransformation);
213 inline void setLowerGridCorner(
const Vector2& newCorner);
220 inline void setUpperGridCorner(
const Vector2& newCorner);
290 template <
bool tVirtual>
328 template <
bool tVirtual>
366 template <
bool tVirtual>
378 template <
bool tVirtual>
390 template <
bool tVirtual>
400 template <
bool tVirtual>
410 template <
bool tVirtual>
418 inline bool operator==(
const Grid& grid)
const;
425 inline bool operator!=(
const Grid& grid)
const;
464 static inline Vector2 grid2nearestNode(
const Vector2& gridCoordinate);
472 static inline bool hasTransformationShearComponent(
const HomogenousMatrix4& transformation);
554 planeTvirtualGrid(false),
555 gridLowerCorner(1, 1),
556 gridUpperCorner(-1, -1)
562 worldTplane(plane2worldTransformation),
563 gridLowerCorner(lowerCorner),
564 gridUpperCorner(upperCorner)
607 ocean_assert(newTransformation.
isValid());
614 ocean_assert(newTransformation.
isValid());
630 template <
bool tVirtual>
637 if (!
image2plane(pinholeCamera, pose, imageCoordinate, planeCoordinate))
640 gridCoordinate = plane2grid<tVirtual>(planeCoordinate);
671 template <
bool tVirtual>
676 return plane2grid<tVirtual>(
world2plane(worldCoordinate));
702 template <
bool tVirtual>
710 return Vector2(gridCoordinate.
x(), gridCoordinate.
y());
713 template <
bool tVirtual>
719 return world2image(pinholeCamera, pose, grid2world<tVirtual>(gridCoordinate));
722 template <
bool tVirtual>
728 return world2imageIF(pinholeCamera, poseIF, grid2world<tVirtual>(gridCoordinate));
731 template <
bool tVirtual>
736 return plane2world(grid2plane<tVirtual>(gridCoordinate));
739 template <
bool tVirtual>
744 if constexpr (tVirtual)
758 return !(*
this == grid);
778 return (poseIF * worldCoordinate).z() >
Scalar(0.0001);
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 an finite line in 3D space.
Definition: FiniteLine3.h:68
This class implements the basic data of an planar grid.
Definition: Grid.h:74
Vector3 grid2plane(const Vector2 &gridCoordinate) const
Convert an point on the plane defined in a coordinate system of the grid into an point defined in the...
Definition: Grid.h:740
bool operator!=(const Grid &grid) const
Returns whether two grids are not identical.
Definition: Grid.h:756
const HomogenousMatrix4 & virtualGrid2planeTransformation() const
Returns the transformation that transform points defined in a coordinate system of the virtual grid i...
Definition: Grid.h:580
void adjustGridCornersInYDirectionByImageLines(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const FiniteLine2 &gridBoundingBoxEdgeImageCoordinate, const FiniteLine2 &imageBoundingBoxEdgeImageCoordinate)
Adjust the lower and upper grid corner in y direction by a given finite image line that is a projecte...
static bool isInFrontOfCameraIF(const HomogenousMatrix4 &poseIF, const Vector3 &worldCoordinate)
Returns whether a given world coordinate is in front of the camera.
Definition: Grid.h:776
Grid()
Creates a new invalid grid element.
Definition: Grid.h:551
Vector2 plane2grid(const Vector3 &planeCoordinate) const
Convert an point on the plane defined in a coordinate system of the plane into an point defined in th...
Definition: Grid.h:703
static Vector2 grid2nearestNode(const Vector2 &gridCoordinate)
Determine the nearest integer grid node from a given grid coordinate.
Definition: Grid.h:761
const HomogenousMatrix4 & plane2worldTransformation() const
Returns the transformation that transforms points defined in a coordinate system of the plane into po...
Definition: Grid.h:570
bool image2plane(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector2 &imageCoordinate, Vector3 &planeCoordinate) const
Convert an point defined in a coordinate system of the camera image into an point on the plane define...
void setInvalid()
Sets the grid to invalid.
static bool clipWorldLineInFrontOfCameraBinarySearchIF(const HomogenousMatrix4 &poseIF, const FiniteLine3 &lineToClip, FiniteLine3 &resultingLine)
Clips a finite line in world coordinates, that the start and end point lie in front of the camera.
Vector2 world2imageIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &poseIF, const Vector3 &worldCoordinate) const
Convert an point on the plane defined in a coordinate system of the world into an point defined in th...
Definition: Grid.h:654
Vector3 world2plane(const Vector3 &worldCoordinate) const
Convert an point on the plane defined in a coordinate system of the world into an point defined in th...
Definition: Grid.h:663
HomogenousMatrix4 virtualPlane2worldTransformation() const
Returns a transformation that transforms points defined in a coordinate system of the virtual plane i...
static bool determineTransformationWithoutShearComponent(const HomogenousMatrix4 &transformationWithShearComponent, HomogenousMatrix4 &resultTransformation)
Determines a transformation without a shear component from a given transformation with shear componen...
void setLowerGridCorner(const Vector2 &newCorner)
Sets the lower grid corner defined in the plane coordinate system of the visualization bounding box o...
Definition: Grid.h:620
Vector3 plane2world(const Vector3 &planeCoordinate) const
Convert an point on the plane defined in a coordinate system of the plane into an point defined in th...
Definition: Grid.h:695
Vector2 gridLowerCorner
Lower grid corner of the visualization bounding box of the grid defined in the grid coordinate system...
Definition: Grid.h:545
Vector2 grid2imageIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &poseIF, const Vector2 &gridCoordinate) const
Convert an point on the plane defined in a coordinate system of the grid into an point defined in the...
Definition: Grid.h:723
bool image2grid(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector2 &imageCoordinate, Vector2 &gridCoordinate) const
Convert an point defined in a coordinate system of the camera image into an point on the plane define...
Definition: Grid.h:631
bool areVirtualAndPhysicalGridIdentical() const
Returns whether the physical and virtual grid transformations are identical.
bool isValid() const
Returns whether the grid is valid.
Vector2 world2grid(const Vector3 &worldCoordinate) const
Convert an point on the plane defined in a coordinate system of the world into an point defined in th...
Definition: Grid.h:672
static bool determineVirtualGridTransformationByPlane2WorldTransformation(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vectors2 &imagePoints, const HomogenousMatrix4 &previousPlane2worldTransformation, HomogenousMatrix4 &plane2worldTransformation, HomogenousMatrix4 &virtualGrid2planeTransformation)
Determines a virtualGrid2plane transformation by a plane2world transformation and four given image po...
static bool determineVirtualGridTransformationsByFourImagePoints(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector2 *imagePoints, const Vector2 *gridCoordinates=nullptr, const HomogenousMatrix4 *previousPlane2worldTransformation=nullptr, HomogenousMatrix4 *plane2worldTransformation=nullptr, HomogenousMatrix4 *virtualGrid2planeTransformation=nullptr)
Determine the transformation that transforms points defined in a coordinate system of the plane into ...
void clipByImageBoundingBox(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Scalar borderSizeFactor=Scalar(2.0), const Vectors2 &insideGridCoordinates=Vectors2())
Clips the grid bounding box and adjusts the lower and upper grid corner by an image bounding box.
const Vector2 & lowerGridCorner() const
Returns the lower grid corner defined in the grid coordinate system of the visualization bounding box...
Definition: Grid.h:595
void adjustGridCornersInXDirectionByImageLines(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const FiniteLine2 &gridBoundingBoxEdgeImageCoordinate, const FiniteLine2 &imageBoundingBoxEdgeImageCoordinate)
Adjust the lower and upper grid corner in x direction by a given finite image line that is a projecte...
HomogenousMatrix4 virtualGrid2worldTransformation() const
Returns the transformation that transform points defined in a coordinate system of the virtual grid i...
Definition: Grid.h:590
Vector3 grid2world(const Vector2 &gridCoordinate) const
Convert an point on the plane defined in a coordinate system of the grid into an point defined in the...
Definition: Grid.h:732
bool setVirtualGrid2planeTransformation(const HomogenousMatrix4 &newTransformation)
Sets the transformation that transform points defined in a coordinate system of the virtual grid into...
static bool isInFrontOfCamera(const HomogenousMatrix4 &pose, const Vector3 &worldCoordinate)
Returns whether a given world coordinate is in front of the camera.
Definition: Grid.h:771
bool image2world(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector2 &imageCoordinate, Vector3 &worldCoordinate) const
Convert an point defined in a coordinate system of the camera image into an point on the plane define...
Vector2 world2image(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector3 &worldCoordinate) const
Convert an point on the plane defined in a coordinate system of the world into an point defined in th...
Definition: Grid.h:645
Vector2 gridUpperCorner
Upper grid corner of the visualization bounding box of the grid defined in the grid coordinate system...
Definition: Grid.h:548
void setGrid2planeTransformation(const HomogenousMatrix4 &newTransformation)
Sets the transformation that transforms points defined in a coordinate system of the grid into points...
Definition: Grid.h:612
const Vector2 & upperGridCorner() const
Returns the upper grid corner defined in the grid coordinate system of the visualization bounding box...
Definition: Grid.h:600
Grid(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const HomogenousMatrix4 &plane2worldTransformation, const Vectors2 &imagePoints, const bool clipBoundingBox=false)
Creates a new Grid by a given transformation that transforms points defined in a coordinate system of...
const HomogenousMatrix4 & grid2planeTransformation() const
Returns the transformation that transforms points defined in a coordinate system of the grid into poi...
Definition: Grid.h:575
Grid(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vectors2 &imagePoints, const HomogenousMatrix4 &plane2worldTransformation, const HomogenousMatrix4 &virtualGrid2planeTransformation=HomogenousMatrix4(true), const bool clipBoundingBox=false)
Creates a new Grid by a plane2world transformation and four image points defining a rectangle.
void setPlane2worldTransformation(const HomogenousMatrix4 &newTransformation)
Sets the transformation that transforms points defined in a coordinate system of the plane into point...
Definition: Grid.h:605
bool operator==(const Grid &grid) const
Returns whether two grids are identical.
Definition: Grid.h:750
Grid(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vectors2 &imagePoints, const Vector2 *gridCoordinates=nullptr, const HomogenousMatrix4 *previousPlane2worldTransformation=nullptr, const bool clipBoundingBox=false)
Creates a new Grid by four given image points using vanishing projection.
void setUpperGridCorner(const Vector2 &newCorner)
Sets the upper grid corner defined in the plane coordinate system of the visualization bounding box o...
Definition: Grid.h:625
HomogenousMatrix4 grid2worldTransformation() const
Returns the transformation that transform points defined in a coordinate system of the grid into poin...
Definition: Grid.h:585
static bool hasTransformationShearComponent(const HomogenousMatrix4 &transformation)
Returns whether a given transformation has shear component in x/y direction.
Definition: Grid.h:766
Vector2 plane2image(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector3 &planeCoordinate) const
Convert an point on the plane defined in a coordinate system of the plane into an point defined in th...
Definition: Grid.h:679
Vector2 plane2imageIF(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &poseIF, const Vector3 &planeCoordinate) const
Convert an point on the plane defined in a coordinate system of the plane into an point defined in th...
Definition: Grid.h:687
HomogenousMatrix4 planeTvirtualGrid
Transformation that transform points defined in a coordinate system of the virtual grid into points d...
Definition: Grid.h:542
HomogenousMatrix4 worldTplane
Transformation that transforms points defined in a coordinate system of the plane into points defined...
Definition: Grid.h:536
Vector2 grid2image(const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &pose, const Vector2 &gridCoordinate) const
Convert an point on the plane defined in a coordinate system of the grid into an point defined in the...
Definition: Grid.h:714
HomogenousMatrix4 planeTgrid
Transformation that transforms points defined in a coordinate system of the grid into points defined ...
Definition: Grid.h:539
HomogenousMatrixT4< T > inverted() const noexcept
Returns the inverted of this matrix.
Definition: HomogenousMatrix4.h:1575
VectorT3< T > yAxis() const
Returns the y-axis of the transformation which is the second vector of the upper left 3x3 rotation ma...
Definition: HomogenousMatrix4.h:1367
VectorT3< T > xAxis() const
Returns the x-axis of the transformation which is the first vector of the upper left 3x3 rotation mat...
Definition: HomogenousMatrix4.h:1360
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
static constexpr int32_t round32(const T value)
Returns the rounded 32 bit integer value of a given value.
Definition: Numeric.h:2064
static constexpr T eps()
Returns a small epsilon.
VectorT2< T > projectToImageDamped(const HomogenousMatrixT4< T > &extrinsic, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given extrinsic camera matrix.
Definition: PinholeCamera.h:2085
bool isValid() const
Returns whether this camera is valid.
Definition: PinholeCamera.h:1572
bool hasDistortionParameters() const
Returns whether this camera object has specified distortion parameters.
Definition: PinholeCamera.h:1293
VectorT2< T > projectToImageDampedIF(const HomogenousMatrixT4< T > &iFlippedExtrinsic, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T dampingFactor=T(1), const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given inverse extrinsic camera ma...
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
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
bool isOrthogonal(const VectorT3< T > &right) const
Returns whether two vectors are orthogonal.
Definition: Vector3.h:794
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
float Scalar
Definition of a scalar type.
Definition: Math.h:128
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition: Vector3.h:22
PlaneT3< Scalar > Plane3
Definition of the Plane3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition: Plane3.h:24
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15