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

#include <gr_camera.h>

Inheritance diagram for kjb::Base_gl_interface:
kjb::Parametric_camera_gl_interface

Public Member Functions

 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 swap (Self &other)
 
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
 
virtual bool Polygon_visibility_test (const kjb::Polygon &p, double epsilon=0) const
 checks whether a given polygon is visible under the given camera parameters More...
 
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...
 

Static Public Member Functions

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

 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

the base interface between opengl and a camera parametrized in terms of modelview matrix, projection matrix, and near and far clipping planes. This class manipulates the modelview and the projection matrices by accessing them directly without calling glFrustum od gluPerspective. Please use it only if you know what you are doing. The clipping planes are handled by setting projection_matrix(2,2) = near + far; projection_matrix(2,3) = near*far; projection_matrix(3,2) = -1 and then by using applying the glOrtho transformation with parameters (-viewport_width/2, viewport_width/2, -viewport_height/2, viewport_height/2, near, far) This will clip stuff outside the viewing frustum and normalize the frustum itself to the normalized device coordinates opengl expects.

If you want to see the math, please go to http://sightations.wordpress.com/2010/08/03/simulating-calibrated-cameras-in-opengl

Constructor & Destructor Documentation

Base_gl_interface::Base_gl_interface ( double  inear = 10,
double  ifar = 10000 
)
Parameters
inearDistance of the near clipping plane from the camera
ifarDistance of the far clipping plane from the camera
Base_gl_interface::Base_gl_interface ( const Base_gl_interface bgl)

bgl the Base_gl_interface to copy into this one

virtual kjb::Base_gl_interface::~Base_gl_interface ( )
inlinevirtual
Base_gl_interface::Base_gl_interface ( const Matrix mv,
const Matrix pj,
double  inear,
double  ifar 
)
protected

constructs a Base_gl_interface from a modelview and a projection matrix

Parameters
mvinput modelview matrix
pjinput projection matrix
inearDistance of the near clipping plane from the camera
ifarDistance of the far clipping plane from the camera

Member Function Documentation

void Base_gl_interface::capture_gl_view ( kjb_c::KJB_image **  img_out)
static

captures the gl view and stores it into a KJB_image

Parameters
img_outResult parameter. If *img_out is 0, an image is allocated; otherwise its space is re-used.
Exceptions
kjb::IO_error
void Base_gl_interface::capture_gl_view ( const char *  fname)
static

captures the gl view and saves into a file

Parameters
fnameFile name to write the captured view image to.
Exceptions
kjb::IO_error
void Base_gl_interface::capture_gl_view ( const char *  fname_fmt,
uint32_t  N 
)
static

captures the gl view and saves into a file, by appending N to the filename

An example for fname_fmt is

image-%04d.tiff
Parameters
fname_fmtFormat for the file name with one printf style integer conversion for the file number.
NNumber of the captured image.
Exceptions
kjb::IO_error
void Base_gl_interface::capture_gl_view ( kjb::Int_matrix matrix)
static

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.

Parameters
matrixResult parameter. The gl view will be stored into this int matrix. The four bytes used by GL to represent the four channels (R,G,B,A) are packaged into a single integer.
Exceptions
kjb::IO_error
void Base_gl_interface::capture_gl_view ( Image img_out)
static

captures the gl view and stores it into a c++ image

Captures the gl view and stores it into a c++ image

Parameters
img_outResult parameter. The content of the GL frame buffer will be copied into this image, freeing the previous memory area pointed by this image
Exceptions
kjb::IO_error
void Base_gl_interface::construct_image_from_int_matrix ( kjb::Image im,
kjb::Int_matrix m 
)
static

Constructs an image from an int matrix. Each integer consists of four bytes, and each of them is interpreted as one of the GL channels (RGBA, or ABGR if the architecture is little endian). This is MOSTLY (if not only) used for DEBUGGING

Constructs an image from an int matrix. Each integer consists of four bytes, and each of them is interpreted as one of the GL channels (RGBA, or ABGR if the architecture is little endian). This is MOSTLY (if not only) used for DEBUGGING

Parameters
imthe image to be initialized from the matrix
mthe matrix to create the image from
double kjb::Base_gl_interface::get_far ( ) const
inline

gets the far clipping plane distance from the camera

kjb::Matrix Base_gl_interface::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.

void Base_gl_interface::get_gl_viewport ( double *  x,
double *  y,
double *  w,
double *  h 
)
static

gets all the g; viewport parameters (x,y,width,height)

Parameters
xit will contain the x parameter of the gl viewport
yit will contain the y parameter of the gl viewport
wit will contain the width of the gl viewport
hit will contain the height of the gl viewport
double Base_gl_interface::get_gl_viewport_aspect ( )
static

returns the ratio between the gl viewport width and the gl viewport height

Returns
The aspect ration of width to height for the GL viewport.
double Base_gl_interface::get_gl_viewport_height ( )
static

returns the gl viewport height

Returns
The viewport height in the GL.
void Base_gl_interface::get_gl_viewport_size ( double *  w,
double *  h 
)
static

gets the gl viewport width and height

Returns
The viewport height in the GL.
double Base_gl_interface::get_gl_viewport_width ( )
static

returns the gl viewport width

Returns
The viewport width in the GL.
double& kjb::Base_gl_interface::get_modelview_entry ( unsigned int  row,
unsigned int  col 
)
inline

returns an entry of the modelview matrix

double kjb::Base_gl_interface::get_modelview_entry ( unsigned int  row,
unsigned int  col 
) const
inline

returns an entry of the modelview matrix

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

returns the gl modelview matrix

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

gets the near clipping plane distance from the camera

double& kjb::Base_gl_interface::get_projection_entry ( unsigned int  row,
unsigned int  col 
)
inline

returns an entry of the projection matrix

double kjb::Base_gl_interface::get_projection_entry ( unsigned int  row,
unsigned int  col 
) const
inline

returns an entry of the projection matrix

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

returns the projection matrix; note: this needs to be preceeded by a glOrtho call with the window dimensions before sending this to opengl.

void Base_gl_interface::mult_gl_projection ( ) const
virtual

Multiplies the current gl projection matrix with this camera's matrix.

Base_gl_interface & Base_gl_interface::operator= ( const Base_gl_interface src)
virtual

bgl the Base_gl_interface to assign to this one

bool Base_gl_interface::Polygon_visibility_test ( const kjb::Polygon p,
double  epsilon = 0 
) const
virtual

checks whether a given polygon is visible under the given camera parameters

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 in kjb::Parametric_camera_gl_interface.

void Base_gl_interface::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.

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

Parameters
clean_buffersif true, the color and the depth buffer will be cleared
void Base_gl_interface::project_point ( double &  x,
double &  y,
double &  z,
const kjb::Vector point3D,
double  img_height 
) const
void Base_gl_interface::scale_modelview ( double  xscale,
double  yscale,
double  zscale 
)
protected

scales the modelview matrix using glScale

Scales the gl modelview matrix using glScaled.

Parameters
xscalethe scale along the x axis
yscalethe scale along the y axis
zscalethe scale along the z axis
void Base_gl_interface::set_clipping_planes ( double  inear,
double  ifar 
)

sets the near and far clipping plane distances from the camera

Parameters
inearDistance of the near clipping plane from the camera
farDistance of the far clipping plane from the camera
void Base_gl_interface::set_far_clipping_plane ( double  ifar)

sets the far clipping plane distance from the camera

Parameters
ifarDistance of the far clipping plane from the camera
void Base_gl_interface::set_gl_modelview ( ) const
virtual

Sets the gl modelview matrix based on the current camera parameters.

Sets the gl modelview matrix using the current camera parameters.

void Base_gl_interface::set_gl_projection ( ) const
virtual

Sets the gl projection matrix based on the current camera parameters.

Sets the gl projection matrix using the current camera parameters. For the details on math, please see the class description

void Base_gl_interface::set_gl_view ( const kjb::Image img_in)
static

Puts the content of the input image in the GL frame buffer

Put the content of the input image in the GL frame buffer

Parameters
img_inThe input image
void Base_gl_interface::set_gl_viewport ( double  x,
double  y,
double  w,
double  h 
)
static

sets all the gl viewport parameters (x,y,width,length)

Parameters
xthe new x parameter for the gl viewport
ythe new y parameter for the gl viewport
wthe new gl viewport size
hthe new gl viewport height
void Base_gl_interface::set_gl_viewport_size ( double  w,
double  h 
)
static

sets the gl viewport size

Parameters
wthe new gl viewport size
hthe new gl viewport height
void kjb::Base_gl_interface::set_modelview_entry ( unsigned int  row,
unsigned int  col,
double  value 
)
inline

sets an entry of the modelview matrix

void kjb::Base_gl_interface::set_modelview_matrix ( const Matrix mv)
protected

sets the modelview matrix

void Base_gl_interface::set_near_clipping_plane ( double  inear)

sets the near clipping plane distance from the camera

Parameters
inearDistance of the near clipping plane from the camera
void kjb::Base_gl_interface::set_projection_entry ( unsigned int  row,
unsigned int  col,
double  value 
)
inline

sets an entry of the projection matrix

void kjb::Base_gl_interface::set_projection_matrix ( const Matrix pm)
protected

sets the projection matrix

virtual void kjb::Base_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 in kjb::Parametric_camera_gl_interface.


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