69 #ifndef CAMERA_CPP_PERSPECTIVE_CAMERA_H_
70 #define CAMERA_CPP_PERSPECTIVE_CAMERA_H_
72 #define FRAME_CAMERA_WORLD_COORDINATES 0
73 #define FRAME_CAMERA_CAMERA_COORDINATES 1
75 #define CAMERA_PITCH_INDEX 0
76 #define CAMERA_YAW_INDEX 1
77 #define CAMERA_ROLL_INDEX 2
85 #ifdef KJB_HAVE_BST_SERIAL
87 #include <boost/serialization/access.hpp>
95 #ifdef KJB_HAVE_BST_SERIAL
96 friend class boost::serialization::access;
110 double ifocal_length,
111 double iprincipal_point_x,
112 double iprincipal_point_y,
114 double iaspect_ratio,
115 double world_scale = 1.0,
117 double ifar = 10000);
123 double ifocal_length,
124 double iprincipal_point_x,
125 double iprincipal_point_y,
127 double iaspect_ratio,
128 double world_scale = 1.0,
130 double ifar = 10000);
154 virtual void read(std::istream& in);
157 virtual void read(
const char * fname)
164 virtual void write(std::ostream& out)
const
168 virtual void write(
const char * fname)
const
272 virtual void set_yaw(
double iyaw);
275 virtual void set_roll(
double iroll);
320 virtual void set_look_at(
double deyex,
double deyey,
double deyez,
double dlookx,
double dlooky,
double dlookz,
321 double dupx,
double dupy,
double dupz);
436 point_in_world_coordinates(3) = 1.0;
447 unsigned int num_image_rows,
448 unsigned int num_image_cols
475 update_camera_matrix();
550 template<
class Archive>
551 void serialize(Archive &ar,
const unsigned int )
553 #ifdef KJB_HAVE_BST_SERIAL
556 if(Archive::is_saving::value ==
true)
566 ar & rotation_angles;
568 ar & principal_point;
576 if(Archive::is_loading::value ==
true)
595 void update_camera_matrix()
const;
virtual void read(const char *fname)
Reads this camera from a file.
Definition: perspective_camera.h:157
virtual void set_aspect_ratio(double iar)
sets the aspect ratio
Definition: perspective_camera.cpp:956
virtual void set_camera_centre(const kjb::Vector &icentre)
sets the camera centre
Definition: perspective_camera.cpp:695
double get_principal_point(unsigned int index) const
returns the coordinate of the principal point specified by the input index
Definition: perspective_camera.h:224
double get_skew() const
returns the skew in radian
Definition: perspective_camera.h:234
double get_yaw() const
returns the yaw angle in radian
Definition: perspective_camera.h:209
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
Matrix get_gl_projection_matrix() const
returns the exact matrix that opengl uses for its projection matrix. this is effectively glOrtho(-vp_...
Definition: gr_camera.cpp:252
void transform_point_to_camera_frame(kjb::Vector &point) const
Transform a point from the world coordinate system to the camera coordinate system.
Definition: gr_camera.cpp:1162
double get_focal_length() const
returns the focal length
Definition: perspective_camera.h:218
const Vector & get_rotation_angles() const
returns the rotation angles [pitch, yaw, roll]
Definition: perspective_camera.h:215
void mult_projection_matrix() const
Definition: perspective_camera.h:369
Definition: gr_camera.h:288
virtual ~Perspective_camera()
Definition: perspective_camera.h:151
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
virtual void read(std::istream &in)
Reads this camera from an input stream.
Definition: perspective_camera.cpp:446
virtual void set_yaw(double iyaw)
sets the yaw angle in radian
Definition: perspective_camera.cpp:781
classes to interface camera models to opengl for rendering
virtual void update_rendering_interface() const
This funcation makes sure that the rendering interface is consistent with the camera parameters store...
Definition: perspective_camera.cpp:643
virtual void swap(Perspective_camera &other)
Definition: perspective_camera.cpp:341
virtual void prepare_for_rendering(bool clean_buffers) const
Definition: perspective_camera.cpp:1103
theta
Definition: APPgetLargeConnectedEdges.m:108
virtual void set_principal_point_y(double iy)
sets the y-coordinate of the principal point
Definition: perspective_camera.cpp:936
void swap(Perspective_camera &cam1, Perspective_camera &cam2)
Swap two cameras.
Definition: perspective_camera.h:599
double get_roll() const
returns the roll angle in radian
Definition: perspective_camera.h:212
virtual void set_focal_length(double ifocal)
sets the focal length
Definition: perspective_camera.cpp:872
double get_camera_centre_x() const
returns the x-coordinate of the camera centre
Definition: perspective_camera.h:197
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.
Definition: perspective_camera.h:429
void set_world_origin(const kjb::Vector &origin)
This returns a 3X4 camera matrix, built from the intrinsic and extrinsic parameters.
Definition: perspective_camera.cpp:664
bool extrinsic_dirty
Definition: perspective_camera.h:541
virtual void set_camera_centre_y(double iy)
sets the y-coordinate of the camera centre
Definition: perspective_camera.cpp:751
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
virtual void write(std::ostream &out) const =0
Writes this Writeable to an output stream.
virtual void rotate_around_z_axis(double theta)
rotates the camera around its x-axis
Definition: perspective_camera.cpp:834
Euler_mode
Definition: g_quaternion.h:55
virtual void set_world_scale(double iscale)
sets the world scale
Definition: perspective_camera.cpp:971
double get_aspect_ratio() const
returns the aspect ratio
Definition: perspective_camera.h:237
void get_point_in_camera_coordinates(kjb::Vector &io_point) const
Given a point in world coordinates, it converts it to camera coordinates.
Definition: perspective_camera.h:459
double get_camera_centre_z() const
returns the y-coordinate of the camera centre
Definition: perspective_camera.h:203
virtual void update_focal_with_scale(double ifocal)
Definition: perspective_camera.cpp:885
virtual void set_angles_from_quaternion(const kjb::Quaternion &q)
sets the rotation angles from an input quaternion
Definition: perspective_camera.cpp:985
const Matrix & get_projection_matrix() const
returns the projection matrix; note: this needs to be preceeded by a glOrtho call with the window dim...
Definition: gr_camera.h:164
double get_far() const
get farplane z-distance from camera center (always positive)
Definition: perspective_camera.h:187
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
Definition: perspective_camera.cpp:1010
virtual void set_rotation_angles(double ipitch, double iyaw, double iroll)
sets pitch, yaw and roll for this camera, in radian
Definition: perspective_camera.cpp:862
const kjb::Quaternion & get_rotations_as_a_quaternion() const
returns the rotations of this camera as a quaternion
Definition: perspective_camera.h:408
Abstract class to clone this object.
Definition: l_cloneable.h:45
virtual void write(const char *fname) const
Writes this camera to an output stream.
Definition: perspective_camera.h:168
virtual Perspective_camera & operator=(const Perspective_camera &pc)
Definition: perspective_camera.cpp:313
double get_far() const
gets the far clipping plane distance from the camera
Definition: gr_camera.h:159
Matrix m_camera_matrix
Definition: perspective_camera.h:547
void set_far(double far)
Definition: perspective_camera.h:188
Definition: g_quaternion.h:40
void set_near(double near)
Definition: perspective_camera.h:184
const kjb::Quaternion & get_orientation() const
returns the quaternion defining this object's orientation
Definition: gr_rigid_object.h:174
Vector to_camera_coordinates(const Vector &v) const
Definition: perspective_camera.cpp:369
Definition: perspective_camera.h:93
double get_pitch() const
returns the pitch angle in radian
Definition: perspective_camera.h:206
bool intrinsic_dirty
Definition: perspective_camera.h:538
const kjb::Vector & get_principal_point() const
returns the principal point
Definition: perspective_camera.h:221
#define CAMERA_ROLL_INDEX
Definition: perspective_camera.h:77
void set_far_clipping_plane(double ifar)
sets the far clipping plane distance from the camera
Definition: gr_camera.cpp:214
double get_world_scale() const
returns the world scale
Definition: perspective_camera.h:240
double get_camera_centre_y() const
returns the y-coordinate of the camera centre
Definition: perspective_camera.h:200
double get_principal_point_x() const
returns the x-coordinate of the principal point
Definition: perspective_camera.h:228
virtual void set_skew(double is)
sets the skew angle
Definition: perspective_camera.cpp:946
bool cam_matrix_dirty
Definition: perspective_camera.h:544
virtual void set_principal_point(const kjb::Vector &ip)
sets the principal point
Definition: perspective_camera.cpp:897
virtual void set_pitch(double ipitch)
sets the pitch angle in radian
Definition: perspective_camera.cpp:771
virtual void set_camera_centre_x(double ix)
sets the x-coordinate of the camera centre
Definition: perspective_camera.cpp:741
const kjb::Vector & get_camera_centre() const
returns the camera centre
Definition: perspective_camera.h:194
Matrix get_gl_projection_matrix() const
Definition: perspective_camera.h:363
Abstract class to clone this object.
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...
Definition: perspective_camera.h:443
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
const Matrix & get_projection_matrix() const
Definition: perspective_camera.h:351
const Matrix & get_modelview_matrix() const
returns the gl modelview matrix
Definition: gr_camera.h:162
virtual void translate(double dx, double dy, double dz, unsigned int frame=FRAME_CAMERA_WORLD_COORDINATES)
Definition: perspective_camera.cpp:1078
virtual void write(std::ostream &out) const
Writes this camera to an output stream.
Definition: perspective_camera.cpp:617
virtual void set_orientation(const kjb::Quaternion &q)
Alias of set_angles_from_quaternion()
Definition: perspective_camera.h:401
virtual void set_roll(double iroll)
sets the roll angle in radian
Definition: perspective_camera.cpp:791
virtual void mult_gl_projection() const
Multiplies the current gl projection matrix with this camera's matrix.
Definition: gr_camera.cpp:687
virtual void rotate_around_x_axis(double theta)
rotates the camera around its x-axis
Definition: perspective_camera.cpp:816
Parametric_camera_gl_interface rendering_interface
Definition: perspective_camera.h:535
void mult_modelview_matrix() const
Definition: perspective_camera.cpp:359
virtual Perspective_camera * clone() const
Definition: perspective_camera.cpp:336
void rotate_point_to_camera_frame(kjb::Vector &ipoint)
Rotates the input point into the camera coordinate system.
Definition: perspective_camera.h:421
void compute_new_euler_angles_on_rotations(double dpitch, double dyaw, double droll)
Definition: perspective_camera.cpp:805
const Matrix & get_modelview_matrix() const
Definition: perspective_camera.h:340
double get_near() const
get near plane z-distance from camera center (always positive)
Definition: perspective_camera.h:183
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
#define CAMERA_PITCH_INDEX
Definition: perspective_camera.h:75
void set_near_clipping_plane(double inear)
sets the near clipping plane distance from the camera
Definition: gr_camera.cpp:192
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...
Definition: gr_camera.cpp:1244
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
const Matrix & get_camera_matrix() const
Definition: perspective_camera.h:473
Object thrown when a program lacks required resources or libraries.
Definition: l_exception.h:539
const Matrix & build_camera_matrix() const
Definition: perspective_camera.h:487
#define CAMERA_YAW_INDEX
Definition: perspective_camera.h:76
virtual void rotate_around_camera_axes(double thetax, double thetay, double thetaz)
rotates the camera around its x,y,z axes in this order
Definition: perspective_camera.cpp:849
virtual Parametric_camera_gl_interface & get_rendering_interface() const
Definition: perspective_camera.h:377
Vector get_world_origin() const
returns the world origin in camera coordinates
Definition: perspective_camera.cpp:686
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
virtual void set_principal_point_x(double ix)
sets the x-coordinate of the principal point
Definition: perspective_camera.cpp:926
#define FRAME_CAMERA_WORLD_COORDINATES
Definition: perspective_camera.h:72
double get_principal_point_y() const
returns the y-coordinate of the principal point
Definition: perspective_camera.h:231
void set_rotation_mode(kjb::Quaternion::Euler_mode imode)
Definition: gr_rigid_object.h:168
virtual void set_camera_centre_z(double iz)
sets the y-coordinate of the camera centre
Definition: perspective_camera.cpp:761
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.
Definition: gr_camera.cpp:1191
Perspective_camera(double inear=10, double ifar=10000)
Definition: perspective_camera.cpp:78
virtual void rotate_around_y_axis(double theta)
rotates the camera around its x-axis
Definition: perspective_camera.cpp:825
const kjb::Quaternion & get_orientation() const
Alias of get_angles_as_a_quaternion()
Definition: perspective_camera.h:415
void set_rotation_mode(kjb::Quaternion::Euler_mode imode)
Definition: perspective_camera.h:391
double get_near() const
gets the near clipping plane distance from the camera
Definition: gr_camera.h:156
void rotate_point_to_camera_frame(kjb::Vector &point) const
Rotates a point from the world coordinate system to the camera coordinate system. ...
Definition: gr_camera.cpp:1179