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 #include <vnl/vnl_fwd.h>
00020 #include <vgl/vgl_fwd.h>
00021 #include <vgl/vgl_point_3d.h>
00022 #include <vgl/vgl_homg_point_3d.h>
00023 #include <vgl/algo/vgl_rotation_3d.h>
00024 #include <vcl_iosfwd.h>
00025
00026 #include "vpgl_proj_camera.h"
00027 #include "vpgl_calibration_matrix.h"
00028 #include <vsl/vsl_binary_io.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 template <class T>
00053 class vpgl_perspective_camera : public vpgl_proj_camera<T>
00054 {
00055 public:
00056
00057
00058 vpgl_perspective_camera();
00059
00060
00061 vpgl_perspective_camera( const vpgl_calibration_matrix<T>& K,
00062 const vgl_point_3d<T>& camera_center,
00063 const vgl_rotation_3d<T>& R );
00064
00065
00066 vpgl_perspective_camera( const vpgl_calibration_matrix<T>& K,
00067 const vgl_rotation_3d<T>& R,
00068 const vgl_vector_3d<T>& t);
00069
00070
00071
00072 vpgl_perspective_camera( const vpgl_perspective_camera& cam );
00073
00074
00075 virtual ~vpgl_perspective_camera(){}
00076
00077 virtual vcl_string type_name() const { return "vpgl_perspective_camera"; }
00078
00079
00080
00081 virtual vpgl_proj_camera<T>* clone(void) const;
00082
00083
00084 vgl_line_3d_2_points<T> backproject( const vgl_point_2d<T>& image_point ) const;
00085
00086
00087
00088 vgl_vector_3d<T> principal_axis() const;
00089
00090
00091 bool is_behind_camera( const vgl_homg_point_3d<T>& world_point ) const;
00092
00093
00094 void set_calibration( const vpgl_calibration_matrix<T>& K );
00095 void set_camera_center( const vgl_point_3d<T>& camera_center );
00096 void set_translation(const vgl_vector_3d<T>& t);
00097 void set_rotation( const vgl_rotation_3d<T>& R );
00098 const vpgl_calibration_matrix<T>& get_calibration() const{ return K_; }
00099 const vgl_point_3d<T>& get_camera_center() const { return camera_center_; }
00100 vgl_vector_3d<T> get_translation() const;
00101 const vgl_rotation_3d<T>& get_rotation() const{ return R_; }
00102
00103
00104
00105
00106 void look_at(const vgl_homg_point_3d<T>& point,
00107 const vgl_vector_3d<T>& up = vgl_vector_3d<T>(0,0,1));
00108
00109
00110
00111
00112 virtual vgl_homg_point_3d<T> camera_center() const
00113 { return vgl_homg_point_3d<T>(camera_center_); }
00114
00115
00116
00117
00118 static vpgl_perspective_camera<T>
00119 postmultiply( const vpgl_perspective_camera<T>& in_cam,
00120 const vgl_h_matrix_3d<T>& euclid_trans);
00121
00122
00123 inline bool operator==(vpgl_perspective_camera<T> const &that) const
00124 { return this == &that ||
00125 (K_ == that.K_ && this->get_matrix()== that.get_matrix() &&
00126 camera_center_ == that.camera_center_ && this->R_.as_matrix() == that.R_.as_matrix()); }
00127
00128
00129
00130
00131 virtual void b_write(vsl_b_ostream &os) const;
00132
00133
00134 virtual void b_read(vsl_b_istream &is);
00135
00136
00137 short version() const {return 2;}
00138
00139
00140 void print_summary(vcl_ostream &os) const { os << *this; }
00141
00142
00143
00144 virtual vcl_string is_a() const { return vcl_string("vpgl_perspective_camera"); }
00145
00146
00147 virtual bool is_class(vcl_string const& cls) const
00148 { return cls==is_a() || vpgl_proj_camera<double>::is_class(cls); }
00149
00150
00151
00152
00153 virtual vpgl_perspective_camera<T> *cast_to_perspective_camera() {return this;}
00154 virtual const vpgl_perspective_camera<T> *cast_to_perspective_camera() const {return this;}
00155
00156 protected:
00157
00158 void recompute_matrix();
00159
00160 vpgl_calibration_matrix<T> K_;
00161 vgl_point_3d<T> camera_center_;
00162 vgl_rotation_3d<T> R_;
00163 };
00164
00165
00166
00167
00168 template <class Type>
00169 vcl_ostream& operator<<(vcl_ostream& s, vpgl_perspective_camera<Type> const& p);
00170
00171
00172 template <class Type>
00173 vcl_istream& operator>>(vcl_istream& s, vpgl_perspective_camera<Type>& p);
00174
00175
00176
00177
00178
00179
00180 template <class T>
00181 bool vpgl_perspective_decomposition( const vnl_matrix_fixed<T,3,4>& camera_matrix,
00182 vpgl_perspective_camera<T>& p_camera );
00183
00184
00185 template <class T>
00186 vpgl_perspective_camera<T> vpgl_align_down( const vpgl_perspective_camera<T>& p0,
00187 const vpgl_perspective_camera<T>& p1 );
00188
00189
00190 template <class T>
00191 vpgl_perspective_camera<T> vpgl_align_up( const vpgl_perspective_camera<T>& p0,
00192 const vpgl_perspective_camera<T>& p1 );
00193
00194 template <class T>
00195 vpgl_perspective_camera<T>
00196 postmultiply( const vpgl_perspective_camera<T>& in_cam,
00197 const vgl_h_matrix_3d<T>& euclid_trans);
00198
00199
00200 template <class T>
00201 void vsl_b_write(vsl_b_ostream &os, const vpgl_perspective_camera<T>* p);
00202
00203
00204
00205 template <class T>
00206 void vsl_b_read(vsl_b_istream &is, vpgl_perspective_camera<T>* &p);
00207
00208
00209 #endif // vpgl_perspective_camera_h_