00001
00002 #ifndef vpgl_proj_camera_h_
00003 #define vpgl_proj_camera_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <vnl/vnl_fwd.h>
00041 #include <vgl/vgl_fwd.h>
00042 #include <vnl/vnl_matrix_fixed.h>
00043 #include <vnl/algo/vnl_svd.h>
00044 #include <vgl/vgl_homg_point_3d.h>
00045 #include <vgl/vgl_homg_point_2d.h>
00046 #include <vgl/vgl_line_segment_2d.h>
00047 #include <vgl/vgl_line_segment_3d.h>
00048 #include <vgl/vgl_infinite_line_3d.h>
00049 #include <vgl/vgl_homg_line_2d.h>
00050 #include <vgl/vgl_line_2d.h>
00051 #include <vgl/vgl_homg_line_3d_2_points.h>
00052 #include <vgl/vgl_homg_plane_3d.h>
00053 #include <vgl/algo/vgl_h_matrix_2d.h>
00054 #include <vgl/algo/vgl_h_matrix_3d.h>
00055 #include <vcl_iosfwd.h>
00056
00057
00058
00059 #include "vpgl_camera.h"
00060
00061 template <class T>
00062 class vpgl_perspective_camera;
00063
00064
00065 template <class T>
00066 class vpgl_proj_camera : public vpgl_camera<T>
00067 {
00068 public:
00069
00070
00071
00072 vpgl_proj_camera();
00073
00074
00075 vpgl_proj_camera( const vnl_matrix_fixed<T,3,4>& camera_matrix );
00076
00077
00078 vpgl_proj_camera( const T* camera_matrix );
00079
00080
00081 vpgl_proj_camera( const vpgl_proj_camera& cam );
00082
00083 virtual vcl_string type_name() const { return "vpgl_proj_camera"; }
00084
00085
00086
00087 virtual vpgl_proj_camera<T>* clone(void) const;
00088
00089
00090 const vpgl_proj_camera<T>& operator=( const vpgl_proj_camera& cam );
00091
00092 virtual ~vpgl_proj_camera();
00093
00094
00095 inline bool operator==(vpgl_proj_camera<T> const &that) const
00096 { return this == &that || this->get_matrix()==that.get_matrix(); }
00097
00098
00099
00100
00101 virtual void project(const T x, const T y, const T z, T& u, T& v) const;
00102
00103
00104 virtual vgl_homg_point_2d<T> project( const vgl_homg_point_3d<T>& world_point ) const;
00105
00106
00107 vgl_homg_point_2d<T> project( const vgl_point_3d<T>& world_point ) const {
00108 return project( vgl_homg_point_3d<T>( world_point ) ); }
00109
00110
00111 vgl_homg_point_2d<T> operator()( const vgl_homg_point_3d<T>& world_point ) const {
00112 return this->project( world_point ); }
00113
00114
00115 vgl_line_segment_2d<T> project( const vgl_line_segment_3d<T>& world_line ) const;
00116
00117
00118 vgl_line_segment_2d<T> operator()( const vgl_line_segment_3d<T>& world_line ) const
00119 { return project( world_line ); }
00120
00121
00122 vgl_line_2d<T> project( const vgl_infinite_line_3d<T>& world_line ) const;
00123
00124
00125 vgl_line_2d<T> operator()( const vgl_infinite_line_3d<T>& world_line ) const
00126 { return project( world_line ); }
00127
00128
00129 virtual vgl_ray_3d<T> backproject_ray( const vgl_homg_point_2d<T>& image_point ) const;
00130
00131
00132 virtual vgl_homg_line_3d_2_points<T> backproject( const vgl_homg_point_2d<T>& image_point ) const;
00133
00134
00135 vgl_homg_plane_3d<T> backproject( const vgl_homg_line_2d<T>& image_line ) const;
00136
00137
00138
00139
00140 virtual vgl_homg_point_3d<T> camera_center() const;
00141
00142
00143 virtual vgl_homg_plane_3d<T> principal_plane() const{ return vgl_homg_plane_3d<T>( P_[2] ); }
00144
00145
00146 vgl_homg_point_2d<T> x_vanishing_point() const{ return vgl_homg_point_2d<T>( P_(0,0), P_(1,0), P_(2,0) ); }
00147 vgl_homg_point_2d<T> y_vanishing_point() const{ return vgl_homg_point_2d<T>( P_(0,1), P_(1,1), P_(2,1) ); }
00148 vgl_homg_point_2d<T> z_vanishing_point() const{ return vgl_homg_point_2d<T>( P_(0,2), P_(1,2), P_(2,2) ); }
00149
00150
00151
00152
00153 const vnl_matrix_fixed<T,3,4>& get_matrix() const{ return P_; }
00154
00155
00156
00157 vnl_svd<T>* svd() const;
00158
00159
00160
00161
00162 virtual bool set_matrix( const vnl_matrix_fixed<T,3,4>& new_camera_matrix );
00163 virtual bool set_matrix( const T* new_camera_matrix );
00164
00165
00166
00167
00168 virtual void save(vcl_string cam_path);
00169
00170 private:
00171
00172
00173 vnl_matrix_fixed<T,3,4> P_;
00174
00175 mutable vnl_svd<T>* cached_svd_;
00176 };
00177
00178
00179
00180
00181
00182 template <class T>
00183 vgl_h_matrix_3d<T> get_canonical_h( vpgl_proj_camera<T>& camera );
00184
00185
00186 template <class T>
00187 void fix_cheirality( vpgl_proj_camera<T>& camera );
00188
00189
00190 template <class T>
00191 void make_canonical( vpgl_proj_camera<T>& camera );
00192
00193
00194 template <class T>
00195 vpgl_proj_camera<T> premultiply( const vpgl_proj_camera<T>& in_camera,
00196 const vnl_matrix_fixed<T,3,3>& transform );
00197
00198
00199 template <class T>
00200 vpgl_proj_camera<T> premultiply( const vpgl_proj_camera<T>& in_camera,
00201 const vgl_h_matrix_2d<T>& transform )
00202 {
00203 return premultiply(in_camera, transform.get_matrix());
00204 }
00205
00206
00207
00208 template <class T>
00209 vpgl_proj_camera<T> postmultiply( const vpgl_proj_camera<T>& in_camera,
00210 const vnl_matrix_fixed<T,4,4>& transform );
00211
00212
00213 template <class T>
00214 vpgl_proj_camera<T> postmultiply( const vpgl_proj_camera<T>& in_camera,
00215 const vgl_h_matrix_3d<T>& transform )
00216 {
00217 return postmultiply(in_camera, transform.get_matrix());
00218 }
00219
00220 template <class T>
00221 vgl_point_3d<T> triangulate_3d_point(const vpgl_proj_camera<T>& c1,
00222 const vgl_point_2d<T>& x1,
00223 const vpgl_proj_camera<T>& c2,
00224 const vgl_point_2d<T>& x2);
00225
00226
00227
00228
00229 template <class T>
00230 vcl_vector<vnl_matrix_fixed<T,2,3> >
00231 image_jacobians(const vpgl_proj_camera<T>& camera,
00232 const vcl_vector<vgl_point_3d<T> >& pts);
00233
00234
00235
00236
00237
00238 template <class Type>
00239 vcl_ostream& operator<<(vcl_ostream& s, vpgl_proj_camera<Type> const& p);
00240
00241
00242 template <class Type>
00243 vcl_istream& operator>>(vcl_istream& s, vpgl_proj_camera<Type>& p);
00244
00245 #endif // vpgl_proj_camera_h_