Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::math::FieldOfView< T > Class Template Reference

Encapsulates a generalized, asymmetric field of view with four half angles. More...

#include "fieldofview.h"

Public Member Functions

 FieldOfView ()
 The default constructor sets an angle of 0 (in any unit) for all four half-angles. More...
 
 FieldOfView (const Angle< T > &left, const Angle< T > &right, const Angle< T > &bottom, const Angle< T > &top)
 Constructs a FieldOfView from four angles. More...
 
template<typename U >
 FieldOfView (const FieldOfView< U > &fov)
 Copy constructor from an instance of the same Dimension and any value type that is compatible (via static_cast) with this instance's type. More...
 
bool SetFromTotalFovAndOpticalCenter (const Angle< T > fov_x, const Angle< T > fov_y, const Point< 2, T > &optical_center_ndc)
 Resets the FieldOfView based on a total field of view in both dimensions, and an optical center for the projection. More...
 
Point< 2, TGetOpticalCenter () const
 Returns the optical center of a projection that is created using this FieldOfView. More...
 
Matrix< 4, TGetProjectionMatrix (T near_p, T far_p) const
 Computes the projection matrix corresponding to the frustum defined by the four half angles and the two planes near_p and far_p. More...
 
Angle< TGetLeft () const
 Accessors for all four half-angles. More...
 
Angle< TGetRight () const
 
Angle< TGetBottom () const
 
Angle< TGetTop () const
 
void SetLeft (const Angle< T > &left)
 Setters for all four half-angles. More...
 
void SetRight (const Angle< T > &right)
 
void SetBottom (const Angle< T > &bottom)
 
void SetTop (const Angle< T > &top)
 
Angle< TGetCenteredFovX () const
 Gets the centered FOV in each dimension. More...
 
Angle< TGetCenteredFovY () const
 
void Print (std::ostream &out) const
 This is used for printing FOV objects to a stream. More...
 
void Read (std::istream &in)
 This is used for reading FOV objects from a stream. More...
 
bool IsZero () const
 Returns true iff all four angles are zero (which is the case after using the default constructor). More...
 

Static Public Member Functions

static FieldOfView< TFromProjectionMatrix (const Matrix< 4, T > &matrix)
 Constructs a FieldOfView by extracting the four frustum planes from the projection matrix. More...
 
static FieldOfView< TFromTangents (const T &left, const T &right, const T &bottom, const T &top)
 Constructs a FieldOfView from four values tan(alpha) for each half-angle alpha. More...
 
p_ndc **static FieldOfView< TFromCenteredFovAndOpticalCenter (const Angle< T > centered_fov_x, const Angle< T > centered_fov_y, const Point< 2, T > &optical_center_ndc)
 Constructs a FieldOfView based on a centered field of view and an optical center for the projection. More...
 

Friends

bool operator== (const FieldOfView &fov0, const FieldOfView &fov1)
 Exact equality and inequality comparisons. More...
 
bool operator!= (const FieldOfView &fov0, const FieldOfView &fov1)
 

Detailed Description

template<typename T>
class ion::math::FieldOfView< T >

Encapsulates a generalized, asymmetric field of view with four half angles.

Each half angle denotes the angle between the corresponding frustum plane. Together with a near and far plane, a FieldOfView forms the frustum of an off-axis perspective projection.

Definition at line 36 of file fieldofview.h.

Constructor & Destructor Documentation

template<typename T >
ion::math::FieldOfView< T >::FieldOfView ( )
inline

The default constructor sets an angle of 0 (in any unit) for all four half-angles.

Definition at line 183 of file fieldofview.h.

template<typename T >
ion::math::FieldOfView< T >::FieldOfView ( const Angle< T > &  left,
const Angle< T > &  right,
const Angle< T > &  bottom,
const Angle< T > &  top 
)
inline

Constructs a FieldOfView from four angles.

Definition at line 186 of file fieldofview.h.

template<typename T >
template<typename U >
ion::math::FieldOfView< T >::FieldOfView ( const FieldOfView< U > &  fov)
explicit

Copy constructor from an instance of the same Dimension and any value type that is compatible (via static_cast) with this instance's type.

Definition at line 229 of file fieldofview.h.

Member Function Documentation

template<typename T >
FieldOfView< T > ion::math::FieldOfView< T >::FromCenteredFovAndOpticalCenter ( const Angle< T centered_fov_x,
const Angle< T centered_fov_y,
const Point< 2, T > &  optical_center_ndc 
)
inlinestatic

Constructs a FieldOfView based on a centered field of view and an optical center for the projection.

The optical center is defined as the intersection of the optical axis with the image plane. Note that the optical center is invariant in world space. This method sets left/right/up/down so that the optical center appears at the given optical_center_ndc with respect to the window defined by those bounds.

The centered FOV is not necessarily the actual FOV. It is defined as what the fov would be if the camera were kept the same perpendicular distance from the viewing plane but the optical center were the center of the screen.+–—*——*------——+ \ \ | | / \ | | ///< \ |\ | / / \ | \ |/ / | / |/ eye eye_centered

In the diagram above, the centered_fov is the angle at eye_centered. The centered FOV allows us to maintain the size of objects on the map.

Definition at line 352 of file fieldofview.h.

template<typename T >
FieldOfView< T > ion::math::FieldOfView< T >::FromProjectionMatrix ( const Matrix< 4, T > &  matrix)
inlinestatic

Constructs a FieldOfView by extracting the four frustum planes from the projection matrix.

Definition at line 212 of file fieldofview.h.

template<typename T >
FieldOfView< T > ion::math::FieldOfView< T >::FromTangents ( const T left,
const T right,
const T bottom,
const T top 
)
inlinestatic

Constructs a FieldOfView from four values tan(alpha) for each half-angle alpha.

Definition at line 201 of file fieldofview.h.

References ion::math::Angle< T >::FromRadians().

template<typename T>
Angle<T> ion::math::FieldOfView< T >::GetBottom ( ) const
inline

Definition at line 117 of file fieldofview.h.

template<typename T>
Angle<T> ion::math::FieldOfView< T >::GetCenteredFovX ( ) const

Gets the centered FOV in each dimension.

It is defined as what the FOV would be if the camera were kept the same perpendicular distance from the viewing plane but the optical center were the center of the screen.

template<typename T >
Angle< T > ion::math::FieldOfView< T >::GetCenteredFovY ( ) const
inline

Definition at line 422 of file fieldofview.h.

References ion::math::Angle< T >::FromRadians().

template<typename T>
Angle<T> ion::math::FieldOfView< T >::GetLeft ( ) const
inline

Accessors for all four half-angles.

Definition at line 115 of file fieldofview.h.

template<typename T >
Point< 2, T > ion::math::FieldOfView< T >::GetOpticalCenter ( ) const
inline

Returns the optical center of a projection that is created using this FieldOfView.

Definition at line 236 of file fieldofview.h.

template<typename T >
Matrix< 4, T > ion::math::FieldOfView< T >::GetProjectionMatrix ( T  near_p,
T  far_p 
) const
inline

Computes the projection matrix corresponding to the frustum defined by the four half angles and the two planes near_p and far_p.

Todo:
(user): Cache this.

Definition at line 191 of file fieldofview.h.

References ion::math::PerspectiveMatrixFromFrustum().

template<typename T>
Angle<T> ion::math::FieldOfView< T >::GetRight ( ) const
inline

Definition at line 116 of file fieldofview.h.

template<typename T>
Angle<T> ion::math::FieldOfView< T >::GetTop ( ) const
inline

Definition at line 118 of file fieldofview.h.

template<typename T >
bool ion::math::FieldOfView< T >::IsZero ( ) const
inline

Returns true iff all four angles are zero (which is the case after using the default constructor).

Definition at line 478 of file fieldofview.h.

template<typename T >
void ion::math::FieldOfView< T >::Print ( std::ostream &  out) const
inline

This is used for printing FOV objects to a stream.

Definition at line 431 of file fieldofview.h.

Referenced by ion::math::operator<<().

template<typename T >
void ion::math::FieldOfView< T >::Read ( std::istream &  in)
inline

This is used for reading FOV objects from a stream.

Definition at line 437 of file fieldofview.h.

References ion::base::GetExpectedChar(), and ion::base::GetExpectedString().

Referenced by ion::math::operator>>().

template<typename T>
void ion::math::FieldOfView< T >::SetBottom ( const Angle< T > &  bottom)
inline

Definition at line 123 of file fieldofview.h.

template<typename T >
bool ion::math::FieldOfView< T >::SetFromTotalFovAndOpticalCenter ( const Angle< T fov_x,
const Angle< T fov_y,
const Point< 2, T > &  optical_center_ndc 
)
inline

Resets the FieldOfView based on a total field of view in both dimensions, and an optical center for the projection.

The optical center is defined as the intersection of the optical axis with the image plane. Note that the optical center is invariant in world space. This method sets left/right/up/down so that the optical center appears at the given optical_center_ndc with respect to the window defined by those bounds.

Returns true if a valid configuration was provided. If the provided configuration was invalid, the FieldOfView object remains unchanged and this method returns false.

Note
the aspect ratio implied by the requested fov_x and fov_y will not necessarily be preserved.

Definition at line 249 of file fieldofview.h.

template<typename T>
void ion::math::FieldOfView< T >::SetLeft ( const Angle< T > &  left)
inline

Setters for all four half-angles.

Definition at line 121 of file fieldofview.h.

template<typename T>
void ion::math::FieldOfView< T >::SetRight ( const Angle< T > &  right)
inline

Definition at line 122 of file fieldofview.h.

template<typename T>
void ion::math::FieldOfView< T >::SetTop ( const Angle< T > &  top)
inline

Definition at line 124 of file fieldofview.h.

Friends And Related Function Documentation

template<typename T>
bool operator!= ( const FieldOfView< T > &  fov0,
const FieldOfView< T > &  fov1 
)
friend

Definition at line 148 of file fieldofview.h.

template<typename T>
bool operator== ( const FieldOfView< T > &  fov0,
const FieldOfView< T > &  fov1 
)
friend

Exact equality and inequality comparisons.

Definition at line 144 of file fieldofview.h.


The documentation for this class was generated from the following file: