Go to the documentation of this file.00001
00002 #ifndef vpgl_perspective_camera_h_
00003 #define vpgl_perspective_camera_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <vnl/vnl_fwd.h>
00021 #include <vgl/vgl_fwd.h>
00022 #include <vgl/vgl_point_3d.h>
00023 #include <vgl/vgl_homg_point_3d.h>
00024 #include <vgl/algo/vgl_rotation_3d.h>
00025 #include <vgl/vgl_ray_3d.h>
00026 #include <vcl_iosfwd.h>
00027
00028 #include "vpgl_proj_camera.h"
00029 #include "vpgl_calibration_matrix.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 template <class T>
00055 class vpgl_perspective_camera : public vpgl_proj_camera<T>
00056 {
00057 public:
00058
00059
00060 vpgl_perspective_camera();
00061
00062
00063 vpgl_perspective_camera( const vpgl_calibration_matrix<T>& K,
00064 const vgl_point_3d<T>& camera_center,
00065 const vgl_rotation_3d<T>& R );
00066
00067
00068 vpgl_perspective_camera( const vpgl_calibration_matrix<T>& K,
00069 const vgl_rotation_3d<T>& R,
00070 const vgl_vector_3d<T>& t);
00071
00072
00073
00074 vpgl_perspective_camera( const vpgl_perspective_camera& cam );
00075
00076
00077 virtual ~vpgl_perspective_camera() {}
00078
00079 virtual vcl_string type_name() const { return "vpgl_perspective_camera"; }
00080
00081
00082
00083 virtual vpgl_proj_camera<T>* clone(void) const;
00084
00085
00086
00087 vgl_homg_line_3d_2_points<T> backproject(const vgl_homg_point_2d<T>& image_point ) const;
00088
00089 vgl_line_3d_2_points<T> backproject( const vgl_point_2d<T>& image_point ) const;
00090
00091 vgl_line_3d_2_points<T> backproject(T u, T v) const
00092 {return backproject(vgl_point_2d<T>(u, v));}
00093
00094
00095 vgl_ray_3d<T> backproject_ray( const vgl_point_2d<T>& image_point ) const;
00096
00097
00098 vgl_ray_3d<T> backproject_ray(T u, T v) const
00099 {return backproject_ray(vgl_point_2d<T>(u, v));}
00100
00101
00102
00103 vgl_vector_3d<T> principal_axis() const;
00104
00105
00106 bool is_behind_camera( const vgl_homg_point_3d<T>& world_point ) const;
00107
00108
00109 void set_calibration( const vpgl_calibration_matrix<T>& K );
00110 void set_camera_center( const vgl_point_3d<T>& camera_center );
00111 void set_translation(const vgl_vector_3d<T>& t);
00112 void set_rotation( const vgl_rotation_3d<T>& R );
00113 const vpgl_calibration_matrix<T>& get_calibration() const{ return K_; }
00114 const vgl_point_3d<T>& get_camera_center() const { return camera_center_; }
00115 vgl_vector_3d<T> get_translation() const;
00116 const vgl_rotation_3d<T>& get_rotation() const{ return R_; }
00117
00118
00119
00120
00121 void look_at(const vgl_homg_point_3d<T>& point,
00122 const vgl_vector_3d<T>& up = vgl_vector_3d<T>(0,0,1));
00123
00124
00125
00126
00127 virtual vgl_homg_point_3d<T> camera_center() const
00128 { return vgl_homg_point_3d<T>(camera_center_); }
00129
00130
00131
00132
00133
00134
00135 static vpgl_perspective_camera<T>
00136 postmultiply( const vpgl_perspective_camera<T>& in_cam,
00137 const vgl_h_matrix_3d<T>& euclid_trans);
00138
00139 static vpgl_perspective_camera<T>
00140 postmultiply(const vpgl_perspective_camera<T>& camera,
00141 const vgl_rotation_3d<T>& rot, const vgl_vector_3d<T>& trans);
00142
00143
00144 inline bool operator==(vpgl_perspective_camera<T> const &that) const
00145 { return this == &that ||
00146 (K_ == that.K_ && this->get_matrix()== that.get_matrix() &&
00147 camera_center_ == that.camera_center_ && this->R_.as_matrix() == that.R_.as_matrix()); }
00148
00149
00150
00151
00152 virtual void save(vcl_string cam_path);
00153
00154
00155
00156
00157
00158 virtual vpgl_perspective_camera<T> *cast_to_perspective_camera() {return this;}
00159 virtual const vpgl_perspective_camera<T> *cast_to_perspective_camera() const {return this;}
00160
00161 protected:
00162
00163 void recompute_matrix();
00164
00165 vpgl_calibration_matrix<T> K_;
00166 vgl_point_3d<T> camera_center_;
00167 vgl_rotation_3d<T> R_;
00168 };
00169
00170
00171
00172
00173 template <class Type>
00174 vcl_ostream& operator<<(vcl_ostream& s, vpgl_perspective_camera<Type> const& p);
00175
00176
00177 template <class Type>
00178 vcl_istream& operator>>(vcl_istream& s, vpgl_perspective_camera<Type>& p);
00179
00180
00181 template <class Type>
00182 void vrml_write(vcl_ostream& s, vpgl_perspective_camera<Type> const& p, double rad);
00183
00184
00185
00186
00187
00188 template <class T>
00189 bool vpgl_perspective_decomposition( const vnl_matrix_fixed<T,3,4>& camera_matrix,
00190 vpgl_perspective_camera<T>& p_camera );
00191
00192
00193 template <class T>
00194 vpgl_perspective_camera<T> vpgl_align_down( const vpgl_perspective_camera<T>& p0,
00195 const vpgl_perspective_camera<T>& p1 );
00196
00197
00198 template <class T>
00199 vpgl_perspective_camera<T> vpgl_align_up( const vpgl_perspective_camera<T>& p0,
00200 const vpgl_perspective_camera<T>& p1 );
00201
00202 template <class T>
00203 double vpgl_persp_cam_distance( const vpgl_perspective_camera<T>& cam1, const vpgl_perspective_camera<T>& cam2);
00204
00205 template <class T>
00206 vpgl_perspective_camera<T>
00207 postmultiply( const vpgl_perspective_camera<T>& in_cam,
00208 const vgl_h_matrix_3d<T>& euclid_trans)
00209 {
00210 return vpgl_perspective_camera<T>::postmultiply(in_cam, euclid_trans);
00211 }
00212
00213
00214 template <class T>
00215 vcl_vector<vpgl_perspective_camera<T> > cameras_from_directory(vcl_string dir, T);
00216
00217
00218
00219 #endif // vpgl_perspective_camera_h_