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

#include <gr_camera.h>

Inheritance diagram for kjb::Parametric_camera_gl_interface:
kjb::Base_gl_interface kjb::Rigid_object kjb::Transformable kjb::Cloneable

Public Member Functions

 Parametric_camera_gl_interface (double inear=10, double ifar=10000)
 
 Parametric_camera_gl_interface (const Parametric_camera_gl_interface &)
 
virtual
Parametric_camera_gl_interface
operator= (const Parametric_camera_gl_interface &src)
 
virtual
Parametric_camera_gl_interface
clone () const
 
virtual ~Parametric_camera_gl_interface ()
 
virtual void swap (Self &other)
 
void set_focal_length (double focal_length, double skew, double aspect_ratio)
 sets the focal length More...
 
void set_aspect_ratio (double aspect_ratio, double focal_length, double skew)
 sets the aspect ratio More...
 
void set_skew (double skew, double aspect_ratio, double focal_length)
 sets the skew More...
 
void set_principal_point_x (double px)
 sets the x coordinate of the principal point More...
 
void set_principal_point_y (double py)
 sets the y coordinate of the principal point More...
 
void set_principal_point (double px, double py)
 sets both coordinates of the principal point More...
 
void set_focal_no_skew (double focal_length, double aspect_ratio)
 sets the focal length assuming no skew More...
 
void set_focal_no_aspect_ratio (double focal_length, double skew)
 sets the focal length assuming aspect_ratio=1 More...
 
void set_focal_no_aspect_ratio_no_skew (double focal_length)
 sets the focal length assuming aspect_ratio=1 and no skew More...
 
void set_intrinsic_parameters (double focal_length, double aspect_ratio, double skew, double px, double py)
 sets all the intrinsic parameters of the camera More...
 
void set_camera_center (const kjb::Vector &center)
 Sets the position of the camera center. More...
 
void set_world_origin (const kjb::Vector &center)
 Sets the world origin in camera coordinates (the "t" vector in Forsyth) More...
 
void set_world_scale (double xscale, double yscale, double zscale)
 Sets the world scale along the three major axes using glScaled. More...
 
void set_rotation_angles (double pitch, double yaw, double roll)
 Sets the rotation angles of this camera. More...
 
void transform_point_to_camera_frame (kjb::Vector &point) const
 Transform a point from the world coordinate system to the camera coordinate system. More...
 
void rotate_point_to_camera_frame (kjb::Vector &point) const
 Rotates a point from the world coordinate system to 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
 Transforms a point in camera coordinates to world coordinates. More...
 
bool Polygon_visibility_test (const kjb::Polygon &p, double epsilon=0) const
 
bool is_point_in_camera_frustum (const kjb::Vector &point_in_world_coordinates, double &ox, double &oy, unsigned int num_rows, unsigned int num_cols) const
 Given a point in world coordinates, it returns true if the point is in the viewing frustum, false otherwise. More...
 
- Public Member Functions inherited from kjb::Base_gl_interface
 Base_gl_interface (double inear=10, double ifar=10000)
 
 Base_gl_interface (const Base_gl_interface &)
 bgl the Base_gl_interface to copy into this one More...
 
virtual Base_gl_interfaceoperator= (const Base_gl_interface &src)
 bgl the Base_gl_interface to assign to this one More...
 
virtual ~Base_gl_interface ()
 
virtual void set_gl_modelview () const
 Sets the gl modelview matrix based on the current camera parameters. More...
 
virtual void set_gl_projection () const
 Sets the gl projection matrix based on the current camera parameters. More...
 
virtual void mult_gl_projection () const
 Multiplies the current gl projection matrix with this camera's matrix. More...
 
void prepare_for_rendering (bool clean_buffers) const
 Prepares the opengl for rendering by setting the gl modelview and projection matrix based on the current camera parameters It also clears the depth and the color buffers, and sets the background color to black. More...
 
void set_near_clipping_plane (double inear)
 sets the near clipping plane distance from the camera More...
 
void set_far_clipping_plane (double ifar)
 sets the far clipping plane distance from the camera More...
 
void set_clipping_planes (double inear, double ifar)
 sets the near and far clipping plane distances from the camera More...
 
double get_near () const
 gets the near clipping plane distance from the camera More...
 
double get_far () const
 gets the far clipping plane distance from the camera More...
 
const Matrixget_modelview_matrix () const
 returns the gl modelview matrix More...
 
const Matrixget_projection_matrix () const
 returns the projection matrix; note: this needs to be preceeded by a glOrtho call with the window dimensions before sending this to opengl. More...
 
Matrix get_gl_projection_matrix () const
 returns the exact matrix that opengl uses for its projection matrix. this is effectively glOrtho(-vp_width/2, vp_width/2, -vp_height/2, vp_height/2, znear, zfar), followed by glMultMatrix(get_projection_matrix(). Note that if the viewport size changes, you'll likely need to re-call this, or understand that the pixels sizes will change. More...
 
void project_point (double &x, double &y, double &z, const kjb::Vector &point3D, double img_height) const
 
void set_modelview_entry (unsigned int row, unsigned int col, double value)
 sets an entry of the modelview matrix More...
 
void set_projection_entry (unsigned int row, unsigned int col, double value)
 sets an entry of the projection matrix More...
 
double & get_modelview_entry (unsigned int row, unsigned int col)
 returns an entry of the modelview matrix More...
 
double get_modelview_entry (unsigned int row, unsigned int col) const
 returns an entry of the modelview matrix More...
 
double & get_projection_entry (unsigned int row, unsigned int col)
 returns an entry of the projection matrix More...
 
double get_projection_entry (unsigned int row, unsigned int col) const
 returns an entry of the projection matrix More...
 
- Public Member Functions inherited from kjb::Rigid_object
 Rigid_object ()
 
 Rigid_object (const Rigid_object &ro)
 
virtual Rigid_objectoperator= (const Rigid_object &src)
 
virtual ~Rigid_object ()
 
virtual void swap (Self &other)
 
virtual void rotate (double dpitch, double dyaw, double droll)
 rotate this object around its x-axis by dpitch, the y-axis by dyaw, and its z-axis by droll (in this order, starting from the object's current position) More...
 
virtual void compute_new_euler_angles_on_rotations (double dpitch, double dyaw, double droll, kjb::Vector &angles) const
 computes the new values for the object's euler angles, after a rotation of dpitch around the object's x-axis, a rotation of dyaw around the object's y axis, and a rotation of droll around the object's z axis (in this order, starting from the object's current position). The state of this rigid object is not changed More...
 
virtual void set_rotations (double pitch, double yaw, double roll)
 rotate this object so that its pitch, yaw and roll match the input values More...
 
const Matrixget_rotations () const
 Returns the current transformation matrix, that is used to store the rotation to be applied to the object. More...
 
const Vectorget_euler_angles () const
 returns vector [pitch, yaw, roll] More...
 
void set_rotation_mode (kjb::Quaternion::Euler_mode imode)
 
const kjb::Quaternionget_orientation () const
 returns the quaternion defining this object's orientation More...
 
void set_orientation (const Quaternion &orientation)
 sets the orientation of this object from an input quaternion More...
 
- Public Member Functions inherited from kjb::Transformable
virtual ~Transformable ()
 Deletes this Transformable. More...
 
virtual ~Transformable ()
 Deletes this Transformable_d. More...
 
- Public Member Functions inherited from kjb::Cloneable
virtual ~Cloneable ()
 Deletes this Cloneable. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from kjb::Base_gl_interface
static double get_gl_viewport_aspect ()
 returns the ratio between the gl viewport width and the gl viewport height More...
 
static double get_gl_viewport_width ()
 returns the gl viewport width More...
 
static double get_gl_viewport_height ()
 returns the gl viewport height More...
 
static void get_gl_viewport_size (double *w, double *h)
 gets the gl viewport width and height More...
 
static void get_gl_viewport (double *x, double *y, double *w, double *h)
 gets all the g; viewport parameters (x,y,width,height) More...
 
static void set_gl_viewport_size (double, double)
 sets the gl viewport size More...
 
static void set_gl_viewport (double x, double y, double w, double h)
 sets all the gl viewport parameters (x,y,width,length) More...
 
static void capture_gl_view (kjb_c::KJB_image **img_out)
 captures the gl view and stores it into a KJB_image More...
 
static void capture_gl_view (const char *fname)
 captures the gl view and saves into a file More...
 
static void capture_gl_view (const char *fname_fmt, uint32_t N)
 captures the gl view and saves into a file, by appending N to the filename More...
 
static void capture_gl_view (kjb::Int_matrix &matrix)
 captures the gl view and stores it into a Int_matrix. The four bytes used by GL to represent the four channels (R,G,B,A) are packaged into a single integer. More...
 
static void capture_gl_view (Image &img_out)
 captures the gl view and stores it into a c++ image More...
 
static void set_gl_view (const kjb::Image &img_in)
 
static void construct_image_from_int_matrix (kjb::Image &im, kjb::Int_matrix &m)
 
- Protected Member Functions inherited from kjb::Base_gl_interface
 Base_gl_interface (const Matrix &, const Matrix &, double near, double far)
 constructs a Base_gl_interface from a modelview and a projection matrix More...
 
void set_modelview_matrix (const Matrix &mv)
 sets the modelview matrix More...
 
void set_projection_matrix (const Matrix &pm)
 sets the projection matrix More...
 
void scale_modelview (double xscale, double yscale, double zscale)
 scales the modelview matrix using glScale More...
 

Detailed Description

provides an interface between OpenGL and a perspective camera parametrized in terms of extrinsic parameters (three rotations and camera center) and intrinsic parameters (focal length, principal point position, aspect ratio, skew). See Forsyth and Ponce for further details (Computer Vision, a modern approach). Rotations are handled using the classic Tait-Bryan formulation with pitch, yaw and roll. Please see

Constructor & Destructor Documentation

Parametric_camera_gl_interface::Parametric_camera_gl_interface ( double  inear = 10,
double  ifar = 10000 
)
Parameters
inearDistance of the near clipping plane from the camera
farDistance of the far clipping plane from the camera
Parametric_camera_gl_interface::Parametric_camera_gl_interface ( const Parametric_camera_gl_interface pcgi)
Parameters
pcgithe parametric camera to copy into this one
virtual kjb::Parametric_camera_gl_interface::~Parametric_camera_gl_interface ( )
inlinevirtual

Member Function Documentation

Parametric_camera_gl_interface * Parametric_camera_gl_interface::clone ( ) const
virtual

Virtual copy constructor

Implements kjb::Rigid_object.

void Parametric_camera_gl_interface::get_point_in_world_coordinates ( const kjb::Vector point_in_camera_coordinates,
kjb::Vector point_in_world_coordinates 
) const

Transforms a point in camera coordinates to world coordinates.

Transforms a point in camera coordinates to world coordinates

bool Parametric_camera_gl_interface::is_point_in_camera_frustum ( const kjb::Vector point_in_world_coordinates,
double &  ox_,
double &  oy_,
unsigned int  num_rows,
unsigned int  num_cols 
) const

Given a point in world coordinates, it returns true if the point is in the viewing frustum, false otherwise.

Given a point in world coordinates, it returns true if the point is in the viewing frustum, false otherwise

Parameters
point_in_world_coordinatesThe input point in world coordinates
num_rowsThe height of the image
num_colsThe width of the image
Returns
true if the point is in the frustum, false otherwise
Parametric_camera_gl_interface & Parametric_camera_gl_interface::operator= ( const Parametric_camera_gl_interface pcgi)
virtual
Parameters
pcgithe parametric camera to assign to this one
bool Parametric_camera_gl_interface::Polygon_visibility_test ( const kjb::Polygon p,
double  epsilon = 0 
) const
virtual

Checks whether a polygon is visible under the current camera by checking that the dot product between the polygon normal and the normalized vector between the camera and the polygon center is bigger than epsilon (whose default value is zero)

Parameters
pthe polygon to test
epsilonthe constant to compare the dot product with (default = 0)

Reimplemented from kjb::Base_gl_interface.

void Parametric_camera_gl_interface::rotate_point_to_camera_frame ( kjb::Vector point) const

Rotates a point from the world coordinate system to the camera coordinate system.

void Parametric_camera_gl_interface::set_aspect_ratio ( double  aspect_ratio,
double  focal_length,
double  skew 
)

sets the aspect ratio

Parameters
aspect_ratiothe new aspect_ratio
focal_lengththe new focal length
skewthe new skew

Skew and focal length are necessary since a change in the aspect ratio impacts entries in the matrix that depend on skew and focal length as well

void Parametric_camera_gl_interface::set_camera_center ( const kjb::Vector center)

Sets the position of the camera center.

void Parametric_camera_gl_interface::set_focal_length ( double  focal_length,
double  skew,
double  aspect_ratio 
)

sets the focal length

Parameters
focal_lengththe new focal length
skewthe new skew
aspect_ratiothe new aspect_ratio

Skew and aspect ratio are necessary since a change in the focal length impacts entries in the matrix that depend on skew and aspect ratio as well

void Parametric_camera_gl_interface::set_focal_no_aspect_ratio ( double  focal_length,
double  skew 
)

sets the focal length assuming aspect_ratio=1

This function assumes aspect_ratio=1

Parameters
focal_lengththe new focal length
skewthe new skew

Aspect ratio is necessary since a change in the focal length impacts entries in the matrix that depend on skew as well

void Parametric_camera_gl_interface::set_focal_no_aspect_ratio_no_skew ( double  focal_length)

sets the focal length assuming aspect_ratio=1 and no skew

This funcation assumes no skew and aspect_ration = 1

Parameters
focal_lengthThe new focal length
void Parametric_camera_gl_interface::set_focal_no_skew ( double  focal_length,
double  aspect_ratio 
)

sets the focal length assuming no skew

This function assumes no skew

Parameters
aspect_ratiothe new aspect_ratio
focal_lengththe new focal length

Aspect ratio is necessary since a change in the skew impacts entries in the matrix that depend on aspect ratio as well

void Parametric_camera_gl_interface::set_intrinsic_parameters ( double  focal_length,
double  aspect_ratio,
double  skew,
double  px,
double  py 
)

sets all the intrinsic parameters of the camera

void kjb::Parametric_camera_gl_interface::set_principal_point ( double  px,
double  py 
)
inline

sets both coordinates of the principal point

void Parametric_camera_gl_interface::set_principal_point_x ( double  px)

sets the x coordinate of the principal point

Parameters
pxthe new x coordinate of the principal point
void Parametric_camera_gl_interface::set_principal_point_y ( double  py)

sets the y coordinate of the principal point

Parameters
pythe new y coordinate of the principal point
void Parametric_camera_gl_interface::set_rotation_angles ( double  pitch,
double  yaw,
double  roll 
)

Sets the rotation angles of this camera.

void Parametric_camera_gl_interface::set_skew ( double  skew,
double  aspect_ratio,
double  focal_length 
)

sets the skew

Parameters
skewthe new skew
aspect_ratiothe new aspect_ratio
focal_lengththe new focal length

Skew and aspect ratio are necessary since a change in the skew impacts entries in the matrix that depend on focal length and aspect ratio as well

void Parametric_camera_gl_interface::set_world_origin ( const kjb::Vector center)

Sets the world origin in camera coordinates (the "t" vector in Forsyth)

void kjb::Parametric_camera_gl_interface::set_world_scale ( double  xscale,
double  yscale,
double  zscale 
)
inline

Sets the world scale along the three major axes using glScaled.

Note
you must call this after calling prepare_for_rendering or set_gl_modelview.
virtual void kjb::Parametric_camera_gl_interface::swap ( Self other)
inlinevirtual

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

Reimplemented from kjb::Base_gl_interface.

void Parametric_camera_gl_interface::transform_point_to_camera_frame ( kjb::Vector point) const

Transform a point from the world coordinate system to the camera coordinate system.


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