KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | List of all members
kjb::Perspective_camera Class Reference

#include <perspective_camera.h>

Inheritance diagram for kjb::Perspective_camera:
kjb::Cloneable kjb::Readable kjb::Writeable kjb::Calibrated_camera

Public Member Functions

 Perspective_camera (double inear=10, double ifar=10000)
 
 Perspective_camera (double icentre_x, double icentre_y, double icentre_z, double ipitch, double iyaw, double iroll, double ifocal_length, double iprincipal_point_x, double iprincipal_point_y, double iskew, double iaspect_ratio, double world_scale=1.0, double inear=10, double ifar=10000)
 
 Perspective_camera (const kjb::Vector &icamera_centre, double ipitch, double iyaw, double iroll, double ifocal_length, double iprincipal_point_x, double iprincipal_point_y, double iskew, double iaspect_ratio, double world_scale=1.0, double inear=10, double ifar=10000)
 
 Perspective_camera (const char *fname)
 Reads a camera from an input file. More...
 
 Perspective_camera (std::istream &in)
 Reads a camera from an input stream. More...
 
 Perspective_camera (const Perspective_camera &pc)
 
virtual Perspective_cameraoperator= (const Perspective_camera &pc)
 
virtual Perspective_cameraclone () const
 
virtual void swap (Perspective_camera &other)
 
virtual ~Perspective_camera ()
 
virtual void read (std::istream &in)
 Reads this camera from an input stream. More...
 
virtual void read (const char *fname)
 Reads this camera from a file. More...
 
virtual void write (std::ostream &out) const
 Writes this camera to an output stream. More...
 
virtual void write (const char *fname) const
 Writes this camera to an output stream. More...
 
virtual void update_rendering_interface () const
 This funcation makes sure that the rendering interface is consistent with the camera parameters stored in this class. More...
 
double get_near () const
 get near plane z-distance from camera center (always positive) More...
 
void set_near (double near)
 
double get_far () const
 get farplane z-distance from camera center (always positive) More...
 
void set_far (double far)
 
Vector get_world_origin () const
 returns the world origin in camera coordinates More...
 
const kjb::Vectorget_camera_centre () const
 returns the camera centre More...
 
double get_camera_centre_x () const
 returns the x-coordinate of the camera centre More...
 
double get_camera_centre_y () const
 returns the y-coordinate of the camera centre More...
 
double get_camera_centre_z () const
 returns the y-coordinate of the camera centre More...
 
double get_pitch () const
 returns the pitch angle in radian More...
 
double get_yaw () const
 returns the yaw angle in radian More...
 
double get_roll () const
 returns the roll angle in radian More...
 
const Vectorget_rotation_angles () const
 returns the rotation angles [pitch, yaw, roll] More...
 
double get_focal_length () const
 returns the focal length More...
 
const kjb::Vectorget_principal_point () const
 returns the principal point More...
 
double get_principal_point (unsigned int index) const
 returns the coordinate of the principal point specified by the input index More...
 
double get_principal_point_x () const
 returns the x-coordinate of the principal point More...
 
double get_principal_point_y () const
 returns the y-coordinate of the principal point More...
 
double get_skew () const
 returns the skew in radian More...
 
double get_aspect_ratio () const
 returns the aspect ratio More...
 
double get_world_scale () const
 returns the world scale More...
 
void set_world_origin (const kjb::Vector &origin)
 This returns a 3X4 camera matrix, built from the intrinsic and extrinsic parameters. More...
 
virtual void set_camera_centre (const kjb::Vector &icentre)
 sets the camera centre More...
 
virtual void set_camera_centre (unsigned int index, double ivalue)
 sets the coordinate of the camera centre specified by the input index More...
 
virtual void set_camera_centre_x (double ix)
 sets the x-coordinate of the camera centre More...
 
virtual void set_camera_centre_y (double iy)
 sets the y-coordinate of the camera centre More...
 
virtual void set_camera_centre_z (double iz)
 sets the y-coordinate of the camera centre More...
 
virtual void set_pitch (double ipitch)
 sets the pitch angle in radian More...
 
virtual void set_yaw (double iyaw)
 sets the yaw angle in radian More...
 
virtual void set_roll (double iroll)
 sets the roll angle in radian More...
 
virtual void rotate_around_x_axis (double theta)
 rotates the camera around its x-axis More...
 
virtual void rotate_around_y_axis (double theta)
 rotates the camera around its x-axis More...
 
virtual void rotate_around_z_axis (double theta)
 rotates the camera around its x-axis More...
 
virtual void rotate_around_camera_axes (double thetax, double thetay, double thetaz)
 rotates the camera around its x,y,z axes in this order More...
 
virtual void set_rotation_angles (double ipitch, double iyaw, double iroll)
 sets pitch, yaw and roll for this camera, in radian More...
 
virtual void set_focal_length (double ifocal)
 sets the focal length More...
 
virtual void update_focal_with_scale (double ifocal)
 
virtual void set_principal_point (const kjb::Vector &ip)
 sets the principal point More...
 
virtual void set_principal_point (unsigned int index, double ip)
 sets the coordinate of the principal point specified by the input index More...
 
virtual void set_principal_point_x (double ix)
 sets the x-coordinate of the principal point More...
 
virtual void set_principal_point_y (double iy)
 sets the y-coordinate of the principal point More...
 
virtual void set_skew (double is)
 sets the skew angle More...
 
virtual void set_aspect_ratio (double iar)
 sets the aspect ratio More...
 
virtual void set_world_scale (double iscale)
 sets the world scale More...
 
virtual void set_look_at (double deyex, double deyey, double deyez, double dlookx, double dlooky, double dlookz, double dupx, double dupy, double dupz)
 sets the position and orientation with the semantics similar to gluLookAt More...
 
virtual void set_look_at (const kjb::Vector &eye, const kjb::Vector &look, const kjb::Vector &up)
 sets the position and orientation with the semantics similar to gluLookAt in a more convenient form More...
 
virtual void translate (double dx, double dy, double dz, unsigned int frame=FRAME_CAMERA_WORLD_COORDINATES)
 
virtual void prepare_for_rendering (bool clean_buffers) const
 
const Matrixget_modelview_matrix () const
 
const Matrixget_projection_matrix () const
 
Matrix get_gl_projection_matrix () const
 
void mult_projection_matrix () const
 
void mult_modelview_matrix () const
 
virtual
Parametric_camera_gl_interface
get_rendering_interface () const
 
void set_rotation_mode (kjb::Quaternion::Euler_mode imode)
 
virtual void set_angles_from_quaternion (const kjb::Quaternion &q)
 sets the rotation angles from an input quaternion More...
 
virtual void set_orientation (const kjb::Quaternion &q)
 Alias of set_angles_from_quaternion() More...
 
const kjb::Quaternionget_rotations_as_a_quaternion () const
 returns the rotations of this camera as a quaternion More...
 
const kjb::Quaternionget_orientation () const
 Alias of get_angles_as_a_quaternion() More...
 
void rotate_point_to_camera_frame (kjb::Vector &ipoint)
 Rotates the input point into the camera coordinate system. More...
 
void get_point_in_world_coordinates (const kjb::Vector &point_in_camera_coordinates, kjb::Vector &point_in_world_coordinates) const
 Given a point in camera coordinates, it converts it to world coordinates. More...
 
bool is_point_in_camera_frustum (const kjb::Vector &point_in_world_coordinates, double &x_, double &y_, unsigned int num_image_rows, unsigned int num_image_cols) const
 Given a point in world coordinates, it returns true if the point is in the viewing frustum, false otherwise. Notice that the OpenGL context will be set in this function, since it is needed for the computation. More...
 
void get_point_in_camera_coordinates (kjb::Vector &io_point) const
 Given a point in world coordinates, it converts it to camera coordinates. More...
 
void compute_new_euler_angles_on_rotations (double dpitch, double dyaw, double droll)
 
const Matrixget_camera_matrix () const
 
const Matrixbuild_camera_matrix () const
 
Vector to_camera_coordinates (const Vector &v) const
 
- Public Member Functions inherited from kjb::Cloneable
virtual ~Cloneable ()
 Deletes this Cloneable. More...
 
- Public Member Functions inherited from kjb::Readable
virtual ~Readable ()
 Deletes this Readable. More...
 
- Public Member Functions inherited from kjb::Writeable
virtual ~Writeable ()
 Deletes this Writeable. More...
 

Protected Attributes

Parametric_camera_gl_interface rendering_interface
 
bool intrinsic_dirty
 
bool extrinsic_dirty
 
bool cam_matrix_dirty
 
Matrix m_camera_matrix
 

Additional Inherited Members

- Static Public Member Functions inherited from kjb::Readable
static const char * read_field_value (std::istream &in, const char *field_name, char *field_buf, size_t buf_len, char separator=':')
 Reads a line off in into a buffer and returns a pointer to the field value in the buffer. More...
 
static const char * read_field_value (std::istream &in, const char *field_name, char separator=':')
 Reads a line off in into an internal buffer and returns a pointer to the field value in the buffer. More...
 

Constructor & Destructor Documentation

kjb::Perspective_camera::Perspective_camera ( double  inear = 10,
double  ifar = 10000 
)
Parameters
inearThe distance between the camera centre and the near clipping plane
ifarThe distance between the camera centre and the far clipping plane
kjb::Perspective_camera::Perspective_camera ( double  icentre_x,
double  icentre_y,
double  icentre_z,
double  ipitch,
double  iyaw,
double  iroll,
double  ifocal_length,
double  iprincipal_point_x,
double  iprincipal_point_y,
double  iskew,
double  iaspect_ratio,
double  iscale = 1.0,
double  inear = 10,
double  ifar = 10000 
)
Parameters
icentre_xThe x coordinate of the camera centre
icentre_yThe y coordinate of the camera centre
icentre_zThe z coordinate of the camera centre
ipitchThe rotation around the camera's x axis
iyawThe rotation around the camera's y axis
irollThe rotation around the camera's x axis
ifocal_lengthThe focal length
iprincipal_point_xThe x coordinate of the principal point
iprincipal_point_yThe y coordinate of the principal point
iskewThe skew angle in radian
iaspect_ratioThe camera aspect ratio
iscaleThe scale of the world
inearThe distance between the camera centre and the near clipping plane
ifarThe distance between the camera centre and the far clipping plane
kjb::Perspective_camera::Perspective_camera ( const kjb::Vector icamera_centre,
double  ipitch,
double  iyaw,
double  iroll,
double  ifocal_length,
double  iprincipal_point_x,
double  iprincipal_point_y,
double  iskew,
double  iaspect_ratio,
double  iscale = 1.0,
double  inear = 10,
double  ifar = 10000 
)
Parameters
icamera_centreThe camera centre position [x,y,z], optionally in homogeneous coordinates
ipitchThe rotation around the camera's x axis
iyawThe rotation around the camera's y axis
irollThe rotation around the camera's x axis
ifocal_lengthThe focal length
iprincipal_point_xThe x coordinate of the principal point
iprincipal_point_yThe y coordinate of the principal point
iskewThe skew angle in radian
iaspect_ratioThe camera aspect ratio
iscaleThe scale of the world
inearThe distance between the camera centre and the near clipping plane
ifarThe distance between the camera centre and the far clipping plane
kjb::Perspective_camera::Perspective_camera ( const char *  fname)

Reads a camera from an input file.

The name of the file to read this camera from

kjb::Perspective_camera::Perspective_camera ( std::istream &  in)

Reads a camera from an input stream.

The input stream to read this camera from

kjb::Perspective_camera::Perspective_camera ( const Perspective_camera pc)

The camera to copy into this one

virtual kjb::Perspective_camera::~Perspective_camera ( )
inlinevirtual

Member Function Documentation

const Matrix& kjb::Perspective_camera::build_camera_matrix ( ) const
inline

Returns the camera matrix. This is a legacy call. get_camera_matrix() is preferred.

Note: I left this class for backward-compatability. However, it is now much faster (it simply returns the matrix, updating if necessary. (Ernesto – 2013/10/23)

Perspective_camera * kjb::Perspective_camera::clone ( ) const
virtual

Virtual copy contructor

Implements kjb::Cloneable.

Reimplemented in kjb::Calibrated_camera.

void kjb::Perspective_camera::compute_new_euler_angles_on_rotations ( double  dpitch,
double  dyaw,
double  droll 
)

Given 3 rotation angles, sets the corresponding Euler angles given the current Euler convention

Parameters
dpitchThe amount of rotation arount the x-axis of this camera
dyawThe amount of rotation arount the y-axis of this camera
drollThe amount of rotation arount the z-axis of this camera
double kjb::Perspective_camera::get_aspect_ratio ( ) const
inline

returns the aspect ratio

const kjb::Vector& kjb::Perspective_camera::get_camera_centre ( ) const
inline

returns the camera centre

double kjb::Perspective_camera::get_camera_centre_x ( ) const
inline

returns the x-coordinate of the camera centre

double kjb::Perspective_camera::get_camera_centre_y ( ) const
inline

returns the y-coordinate of the camera centre

double kjb::Perspective_camera::get_camera_centre_z ( ) const
inline

returns the y-coordinate of the camera centre

const Matrix& kjb::Perspective_camera::get_camera_matrix ( ) const
inline

Get the camera matrix corresponding to this camera

double kjb::Perspective_camera::get_far ( ) const
inline

get farplane z-distance from camera center (always positive)

double kjb::Perspective_camera::get_focal_length ( ) const
inline

returns the focal length

Matrix kjb::Perspective_camera::get_gl_projection_matrix ( ) const
inline

Return opengl projection matrix, which can be passed to kjb::opengl::glMultMatrix(). This is the exact matrix that is passed to opengl; i.e. the effect of the glOrtho call is included in this matrix.

const Matrix& kjb::Perspective_camera::get_modelview_matrix ( ) const
inline

Return opengl modelview matrix, which can be passed to kjb::opengl::glMultMatrix()

double kjb::Perspective_camera::get_near ( ) const
inline

get near plane z-distance from camera center (always positive)

const kjb::Quaternion& kjb::Perspective_camera::get_orientation ( ) const
inline

Alias of get_angles_as_a_quaternion()

double kjb::Perspective_camera::get_pitch ( ) const
inline

returns the pitch angle in radian

void kjb::Perspective_camera::get_point_in_camera_coordinates ( kjb::Vector io_point) const
inline

Given a point in world coordinates, it converts it to camera coordinates.

void kjb::Perspective_camera::get_point_in_world_coordinates ( const kjb::Vector point_in_camera_coordinates,
kjb::Vector point_in_world_coordinates 
) const
inline

Given a point in camera coordinates, it converts it to world coordinates.

const kjb::Vector& kjb::Perspective_camera::get_principal_point ( ) const
inline

returns the principal point

double kjb::Perspective_camera::get_principal_point ( unsigned int  index) const
inline

returns the coordinate of the principal point specified by the input index

double kjb::Perspective_camera::get_principal_point_x ( ) const
inline

returns the x-coordinate of the principal point

double kjb::Perspective_camera::get_principal_point_y ( ) const
inline

returns the y-coordinate of the principal point

const Matrix& kjb::Perspective_camera::get_projection_matrix ( ) const
inline

Return opengl projection matrix, which can be passed to kjb::opengl::glMultMatrix(). Note that this needs to be preceeded by a call to glOrtho()

virtual Parametric_camera_gl_interface& kjb::Perspective_camera::get_rendering_interface ( ) const
inlinevirtual
double kjb::Perspective_camera::get_roll ( ) const
inline

returns the roll angle in radian

const Vector& kjb::Perspective_camera::get_rotation_angles ( ) const
inline

returns the rotation angles [pitch, yaw, roll]

const kjb::Quaternion& kjb::Perspective_camera::get_rotations_as_a_quaternion ( ) const
inline

returns the rotations of this camera as a quaternion

double kjb::Perspective_camera::get_skew ( ) const
inline

returns the skew in radian

Vector kjb::Perspective_camera::get_world_origin ( ) const

returns the world origin in camera coordinates

returns the world origin in camera coordinates as a 3-vector.

double kjb::Perspective_camera::get_world_scale ( ) const
inline

returns the world scale

double kjb::Perspective_camera::get_yaw ( ) const
inline

returns the yaw angle in radian

bool kjb::Perspective_camera::is_point_in_camera_frustum ( const kjb::Vector point_in_world_coordinates,
double &  x_,
double &  y_,
unsigned int  num_image_rows,
unsigned int  num_image_cols 
) const
inline

Given a point in world coordinates, it returns true if the point is in the viewing frustum, false otherwise. Notice that the OpenGL context will be set in this function, since it is needed for the computation.

void kjb::Perspective_camera::mult_modelview_matrix ( ) const
void kjb::Perspective_camera::mult_projection_matrix ( ) const
inline
Perspective_camera & kjb::Perspective_camera::operator= ( const Perspective_camera pc)
virtual

The camera to assign to this one

void kjb::Perspective_camera::prepare_for_rendering ( bool  clean_buffers) const
virtual

This function makes sure that the rendering mechanism (OpenGL in this case) is set properly so that anything that will be rendered will be seen through a camera having the parameters specified in this class

Parameters
clean_buffersif true, the gl buffers will be cleared
void kjb::Perspective_camera::read ( std::istream &  in)
virtual

Reads this camera from an input stream.

Parameters
inThe input stream to read from

Implements kjb::Readable.

virtual void kjb::Perspective_camera::read ( const char *  fname)
inlinevirtual

Reads this camera from a file.

Reimplemented from kjb::Readable.

void kjb::Perspective_camera::rotate_around_camera_axes ( double  thetax,
double  thetay,
double  thetaz 
)
virtual

rotates the camera around its x,y,z axes in this order

void kjb::Perspective_camera::rotate_around_x_axis ( double  theta)
virtual

rotates the camera around its x-axis

void kjb::Perspective_camera::rotate_around_y_axis ( double  theta)
virtual

rotates the camera around its x-axis

void kjb::Perspective_camera::rotate_around_z_axis ( double  theta)
virtual

rotates the camera around its x-axis

void kjb::Perspective_camera::rotate_point_to_camera_frame ( kjb::Vector ipoint)
inline

Rotates the input point into the camera coordinate system.

void kjb::Perspective_camera::set_angles_from_quaternion ( const kjb::Quaternion q)
virtual

sets the rotation angles from an input quaternion

Sets the rotation angles from an input quaternion

Parameters
qthe input quaternion
void kjb::Perspective_camera::set_aspect_ratio ( double  iar)
virtual

sets the aspect ratio

void kjb::Perspective_camera::set_camera_centre ( const kjb::Vector icentre)
virtual

sets the camera centre

void kjb::Perspective_camera::set_camera_centre ( unsigned int  index,
double  ivalue 
)
virtual

sets the coordinate of the camera centre specified by the input index

void kjb::Perspective_camera::set_camera_centre_x ( double  ix)
virtual

sets the x-coordinate of the camera centre

void kjb::Perspective_camera::set_camera_centre_y ( double  iy)
virtual

sets the y-coordinate of the camera centre

void kjb::Perspective_camera::set_camera_centre_z ( double  iz)
virtual

sets the y-coordinate of the camera centre

void kjb::Perspective_camera::set_far ( double  far)
inline
void kjb::Perspective_camera::set_focal_length ( double  ifocal)
virtual

sets the focal length

void kjb::Perspective_camera::set_look_at ( double  deyex,
double  deyey,
double  deyez,
double  dlookx,
double  dlooky,
double  dlookz,
double  dupx,
double  dupy,
double  dupz 
)
virtual

sets the position and orientation with the semantics similar to gluLookAt

Parameters
deyexSpecifies the x position of the eye point.
deyeySpecifies the y position of the eye point.
deyexSpecifies the z position of the eye point.
dlookxSpecifies the x position of the reference point.
dlookySpecifies the y position of the reference point.
dlookzSpecifies the z position of the reference point.
dupxSpecifies the x direction of the up vector.
dupySpecifies the y direction of the up vector.
dupzSpecifies the z direction of the up vector.
void kjb::Perspective_camera::set_look_at ( const kjb::Vector p_eye,
const kjb::Vector p_look,
const kjb::Vector p_up 
)
virtual

sets the position and orientation with the semantics similar to gluLookAt in a more convenient form

Parameters
eyeSpecifies the position of the eye point.
lookSpecifies the position of the reference point.
upSpecifies the direction of the up vector.
void kjb::Perspective_camera::set_near ( double  near)
inline
virtual void kjb::Perspective_camera::set_orientation ( const kjb::Quaternion q)
inlinevirtual
void kjb::Perspective_camera::set_pitch ( double  ipitch)
virtual

sets the pitch angle in radian

void kjb::Perspective_camera::set_principal_point ( const kjb::Vector ip)
virtual

sets the principal point

void kjb::Perspective_camera::set_principal_point ( unsigned int  index,
double  ip 
)
virtual

sets the coordinate of the principal point specified by the input index

void kjb::Perspective_camera::set_principal_point_x ( double  ix)
virtual

sets the x-coordinate of the principal point

void kjb::Perspective_camera::set_principal_point_y ( double  iy)
virtual

sets the y-coordinate of the principal point

void kjb::Perspective_camera::set_roll ( double  iroll)
virtual

sets the roll angle in radian

void kjb::Perspective_camera::set_rotation_angles ( double  ipitch,
double  iyaw,
double  iroll 
)
virtual

sets pitch, yaw and roll for this camera, in radian

void kjb::Perspective_camera::set_rotation_mode ( kjb::Quaternion::Euler_mode  imode)
inline

Sets the rotation mode. This will have an impact on how pitch, yaw and roll are interpreted (standard is Euler Mode XYZ with rotating axes, see class Quaternion). No matter what mode you specify here, pitch will be interpreted as Euler angle 1, yaw as Euler angle 2, and roll as Euler angle 3. This function (except for standard mode XYZR) is not adequately tested

void kjb::Perspective_camera::set_skew ( double  is)
virtual

sets the skew angle

void kjb::Perspective_camera::set_world_origin ( const kjb::Vector origin)

This returns a 3X4 camera matrix, built from the intrinsic and extrinsic parameters.

Setters sets the world origin in camera coordinates.

void kjb::Perspective_camera::set_world_scale ( double  iscale)
virtual

sets the world scale

void kjb::Perspective_camera::set_yaw ( double  iyaw)
virtual

sets the yaw angle in radian

void kjb::Perspective_camera::swap ( Perspective_camera other)
virtual

Swap contents with another Perspective_camera. This is implemented to run much more quickly than: Perspective_camera tmp = b; b = a; a = tmp;

Vector kjb::Perspective_camera::to_camera_coordinates ( const Vector v) const
void kjb::Perspective_camera::translate ( double  dx,
double  dy,
double  dz,
unsigned int  frame = FRAME_CAMERA_WORLD_COORDINATES 
)
virtual
void kjb::Perspective_camera::update_focal_with_scale ( double  ifocal)
virtual
void kjb::Perspective_camera::update_rendering_interface ( ) const
virtual

This funcation makes sure that the rendering interface is consistent with the camera parameters stored in this class.

This makes sure that the rendering interface is consistent with the camera parameters

void kjb::Perspective_camera::write ( std::ostream &  out) const
virtual

Writes this camera to an output stream.

Implements kjb::Writeable.

virtual void kjb::Perspective_camera::write ( const char *  fname) const
inlinevirtual

Writes this camera to an output stream.

Reimplemented from kjb::Writeable.

Member Data Documentation

bool kjb::Perspective_camera::cam_matrix_dirty
mutableprotected

True if the camera matrix was not updated to reflect changes.

bool kjb::Perspective_camera::extrinsic_dirty
mutableprotected

True if the gl interface was not updated to reflect the changes to an extrinsic parameter

bool kjb::Perspective_camera::intrinsic_dirty
mutableprotected

True if the gl interface was not updated to reflect the changes to an intrinsic parameter

Matrix kjb::Perspective_camera::m_camera_matrix
mutableprotected

Camera matrix

Parametric_camera_gl_interface kjb::Perspective_camera::rendering_interface
mutableprotected

Interface to opengl


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