8 #ifndef META_OCEAN_MATH_FRUSTUM_H
9 #define META_OCEAN_MATH_FRUSTUM_H
23 template <
typename T>
class FrustumT;
133 FrustumT(
const T width,
const T height,
const T focalLengthX,
const T focalLengthY,
const T principalPointX,
const T principalPointY,
const T nearDistance,
const T farDistance);
163 FrustumT(
const HomogenousMatrixT4<T>& world_T_camera,
const T width,
const T height,
const T focalLengthX,
const T focalLengthY,
const T principalPointX,
const T principalPointY,
const T nearDistance,
const T farDistance);
273 template <
typename T>
274 FrustumT<T>::FrustumT(
const T width,
const T height,
const T focalLengthX,
const T focalLengthY,
const T principalPointX,
const T principalPointY,
const T nearDistance,
const T farDistance)
280 ocean_assert(principalPointX > 0 && principalPointX < width);
281 ocean_assert(principalPointY > 0 && principalPointY < height);
283 ocean_assert(nearDistance >= 0 && nearDistance < farDistance);
288 const T& leftPx = principalPointX;
289 const T rightPx = width - principalPointX;
294 const T& topPy = principalPointY;
295 const T bottomPy = height - principalPointY;
300 ocean_assert(isValid());
303 template <
typename T>
305 FrustumT<T>(T(pinholeCamera.width()), T(pinholeCamera.height()), T(pinholeCamera.focalLengthX()), T(pinholeCamera.focalLengthY()), T(pinholeCamera.principalPointX()), T(pinholeCamera.principalPointY()), nearDistance, farDistance)
307 ocean_assert(pinholeCamera.
isValid());
310 template <
typename T>
312 FrustumT<T>(T(pinholeCamera.width()), T(pinholeCamera.height()), T(pinholeCamera.focalLengthX()), T(pinholeCamera.focalLengthY()), T(pinholeCamera.principalPointX()), T(pinholeCamera.principalPointY()), nearDistance, farDistance)
314 ocean_assert(pinholeCamera.
isValid());
318 template <
typename T>
319 FrustumT<T>::FrustumT(
const HomogenousMatrixT4<T>& world_T_camera,
const T width,
const T height,
const T focalLengthX,
const T focalLengthY,
const T principalPointX,
const T principalPointY,
const T nearDistance,
const T farDistance)
327 ocean_assert(principalPointX > 0 && principalPointX < width);
328 ocean_assert(principalPointY > 0 && principalPointY < height);
330 ocean_assert(nearDistance >= 0 && nearDistance < farDistance);
334 const VectorT3<T> zAxisNormalized = world_T_camera.
zAxis().normalizedOrZero();
339 const T& leftPx = principalPointX;
340 const T rightPx = width - principalPointX;
342 const VectorT3<T> leftNormal = (world_T_camera *
VectorT3<T>(focalLengthX, 0, -leftPx) - translation).normalizedOrZero();
343 const VectorT3<T> rightNormal = (world_T_camera *
VectorT3<T>(-focalLengthX, 0, -rightPx) - translation).normalizedOrZero();
345 planes_[PI_LEFT] =
PlaneT3<T>(translation, leftNormal);
346 planes_[PI_RIGHT] =
PlaneT3<T>(translation, rightNormal);
348 const T& topPy = principalPointY;
349 const T bottomPy = height - principalPointY;
351 const VectorT3<T> topNormal = (world_T_camera *
VectorT3<T>(0, -focalLengthY, -topPy) - translation).normalizedOrZero();
352 const VectorT3<T> bottomNormal = (world_T_camera *
VectorT3<T>(0, focalLengthY, -bottomPy) - translation).normalizedOrZero();
354 planes_[PI_TOP] =
PlaneT3<T>(translation, topNormal);
355 planes_[PI_BOTTOM] =
PlaneT3<T>(translation, bottomNormal);
357 ocean_assert(isValid());
360 template <
typename T>
362 FrustumT(world_T_camera, T(pinholeCamera.width()), T(pinholeCamera.height()), T(pinholeCamera.focalLengthX()), T(pinholeCamera.focalLengthY()), T(pinholeCamera.principalPointX()), T(pinholeCamera.principalPointY()), nearDistance, farDistance)
364 ocean_assert(pinholeCamera.
isValid());
367 template <
typename T>
369 FrustumT(world_T_camera, T(pinholeCamera.width()), T(pinholeCamera.height()), T(pinholeCamera.focalLengthX()), T(pinholeCamera.focalLengthY()), T(pinholeCamera.principalPointX()), T(pinholeCamera.principalPointY()), nearDistance, farDistance)
371 ocean_assert(pinholeCamera.
isValid());
375 template <
typename T>
381 template <
typename T>
384 ocean_assert(isValid());
388 for (
unsigned int n = 0u; n < PI_END; ++n)
390 if (planes_[n].signedDistance(objectPoint) < T(0))
399 template <
typename T>
402 ocean_assert(isValid());
403 ocean_assert(sphere.
isValid());
407 for (
unsigned int n = 0u; n < PI_END; ++n)
409 if (planes_[n].signedDistance(sphere.
center()) < sphere.
radius())
418 template <
typename T>
421 ocean_assert(isValid());
426 for (
unsigned int n = 0u; n < PI_END; ++n)
446 template <
typename T>
449 ocean_assert(isValid());
450 ocean_assert(vertices !=
nullptr && size != 0);
454 for (
unsigned int n = 0u; n < PI_END; ++n)
458 for (
size_t nVertex = 0; nVertex < size; ++nVertex)
470 template <
typename T>
473 ocean_assert(isValid());
474 ocean_assert(sphere.
isValid());
478 for (
unsigned int n = 0u; n < PI_END; ++n)
480 if (planes_[n].signedDistance(sphere.
center()) < -sphere.
radius())
489 template <
typename T>
492 ocean_assert(isValid());
497 for (
unsigned int n = 0u; n < PI_END; ++n)
517 template <
typename T>
520 ocean_assert(isValid());
521 ocean_assert(vertices !=
nullptr && size != 0);
525 for (
unsigned int n = 0u; n < PI_END; ++n)
529 bool allOutside =
true;
531 for (
size_t nVertex = 0; allOutside && nVertex < size; ++nVertex)
545 template <
typename T>
548 return planes_[PI_FRONT].isValid();
551 template <
typename T>
554 for (
unsigned int n = 0u; n < PI_END; ++n)
556 if (!planes_[n].isEqual(frustum.
planes_[n], eps))
565 template <
typename T>
568 return isEqual(frustum);
571 template <
typename T>
574 return !isEqual(frustum);
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
virtual bool isValid() const =0
Returns whether this camera is valid.
virtual AnyCameraType anyCameraType() const =0
Returns the type of this camera.
bool isValid() const
Returns whether the bounding box is valid.
const VectorT3< T > & lower() const
Returns the lower corner of the box.
const VectorT3< T > & higher() const
Returns the higher corner of the box.
This class implements a viewing frustum.
Definition: Frustum.h:84
const PlaneT3< T > * planes() const
Returns the six planes of the frustum, with order as defined in PlaneIds.
Definition: Frustum.h:376
bool isValid() const
Returns whether this frustum object is valid.
Definition: Frustum.h:546
PlaneT3< T > planes_[PI_END]
The six planes of the frustum.
Definition: Frustum.h:270
bool isEqual(const FrustumT< T > &frustum, const T eps=NumericT< T >::eps()) const
Returns whether two frustum objects are equal up to a small epsilon.
Definition: Frustum.h:552
bool operator!=(const FrustumT< T > &frustum) const
Returns whether two frustum objects are not identical.
Definition: Frustum.h:572
bool operator==(const FrustumT< T > &frustum) const
Returns whether two frustum objects are identical.
Definition: Frustum.h:566
T Type
Definition of the used data type.
Definition: Frustum.h:113
FrustumT()=default
Default constructor creating an invalid frustum.
bool isInside(const VectorT3< T > &objectPoint) const
Returns whether a 3D object point is inside this frustum.
Definition: Frustum.h:382
PlaneIds
Definition of ids for the individual planes of the frustum.
Definition: Frustum.h:91
@ PI_END
The number of planes.
Definition: Frustum.h:105
@ PI_FRONT
The front plane, with normal pointing into the frustum.
Definition: Frustum.h:93
@ PI_BOTTOM
The bottom plane, with normal pointing into the frustum.
Definition: Frustum.h:103
@ PI_LEFT
The left plane, with normal pointing into the frustum.
Definition: Frustum.h:97
@ PI_RIGHT
The right plane, with normal pointing into the frustum.
Definition: Frustum.h:99
@ PI_TOP
The top plane, with normal pointing into the frustum.
Definition: Frustum.h:101
@ PI_BACK
The back plane, with normal pointing into the frustum.
Definition: Frustum.h:95
bool hasIntersection(const SphereT3< T > &sphere) const
Returns whether a 3D sphere has an interaction with this frustum or is entirely inside this frustum.
Definition: Frustum.h:471
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition: HomogenousMatrix4.h:110
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition: HomogenousMatrix4.h:1493
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition: HomogenousMatrix4.h:1381
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
VectorT3< T > zAxis() const
Returns the z-axis of the transformation which is the first vector of the upper left 3x3 rotation mat...
Definition: HomogenousMatrix4.h:1374
This class provides basic numeric functionalities.
Definition: Numeric.h:57
bool isValid() const
Returns whether this camera is valid.
Definition: PinholeCamera.h:1572
This class implements a plane in 3D space.
Definition: Plane3.h:73
T signedDistance(const VectorT3< T > &point) const
Returns the distance between a given point and this plane.
Definition: Plane3.h:441
This class implements a 3D sphere.
Definition: Sphere3.h:57
bool isValid() const
Returns whether this radius of this sphere is not negative and thus the sphere is valid.
Definition: Sphere3.h:281
const T & radius() const
Returns the radius of the sphere.
Definition: Sphere3.h:209
const VectorT3< T > & center() const
Returns the center of the sphere.
Definition: Sphere3.h:203
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< FrustumD > FrustumsD
Definition of a vector holding FrustumD objects.
Definition: Frustum.h:66
FrustumT< float > FrustumF
Definition of a frustum vector with float values.
Definition: Frustum.h:44
FrustumT< double > FrustumD
Definition of a frustum with double values.
Definition: Frustum.h:37
std::vector< FrustumF > FrustumsF
Definition of a vector holding FrustumF objects.
Definition: Frustum.h:73
std::vector< Frustum > Frustums
Definition of a vector holding Frustum objects.
Definition: Frustum.h:59
FrustumT< Scalar > Frustum
Definition of a frustum.
Definition: Frustum.h:23
std::vector< FrustumT< T > > FrustumsT
Definition of a typename alias for vectors with FrustumT objects.
Definition: Frustum.h:52
@ PINHOLE
A pinhole camera.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15