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 #include <vnl/vnl_fwd.h>
00040 #include <vgl/vgl_fwd.h>
00041 #include <vnl/vnl_matrix_fixed.h>
00042 #include <vnl/algo/vnl_svd.h>
00043 #include <vgl/vgl_homg_point_3d.h>
00044 #include <vgl/vgl_homg_point_2d.h>
00045 #include <vgl/vgl_line_segment_2d.h>
00046 #include <vgl/vgl_line_segment_3d.h>
00047 #include <vgl/vgl_infinite_line_3d.h>
00048 #include <vgl/vgl_homg_line_2d.h>
00049 #include <vgl/vgl_line_2d.h>
00050 #include <vgl/vgl_homg_line_3d_2_points.h>
00051 #include <vgl/vgl_homg_plane_3d.h>
00052 #include <vgl/algo/vgl_h_matrix_2d.h>
00053 #include <vgl/algo/vgl_h_matrix_3d.h>
00054 #include <vcl_iosfwd.h>
00055 #include <vsl/vsl_binary_io.h>
00056
00057
00058 #include "vpgl_camera.h"
00059
00060 template <class T>
00061 class vpgl_perspective_camera;
00062
00063
00064 template <class T>
00065 class vpgl_proj_camera : public vpgl_camera<T>
00066 {
00067 public:
00068
00069
00070
00071 vpgl_proj_camera();
00072
00073
00074 vpgl_proj_camera( const vnl_matrix_fixed<T,3,4>& camera_matrix );
00075
00076
00077 vpgl_proj_camera( const T* camera_matrix );
00078
00079
00080 vpgl_proj_camera( const vpgl_proj_camera& cam );
00081
00082 virtual vcl_string type_name() const { return "vpgl_proj_camera"; }
00083
00084
00085
00086 virtual vpgl_proj_camera<T>* clone(void) const;
00087
00088
00089 const vpgl_proj_camera<T>& operator=( const vpgl_proj_camera& cam );
00090
00091 virtual ~vpgl_proj_camera();
00092
00093
00094
00095
00096 virtual void project(const T x, const T y, const T z, T& u, T& v) const;
00097
00098
00099 virtual vgl_homg_point_2d<T> project( const vgl_homg_point_3d<T>& world_point ) const;
00100
00101
00102 vgl_homg_point_2d<T> project( const vgl_point_3d<T>& world_point ) const {
00103 return project( vgl_homg_point_3d<T>( world_point ) ); }
00104
00105
00106 vgl_homg_point_2d<T> operator()( const vgl_homg_point_3d<T>& world_point ) const {
00107 return this->project( world_point ); }
00108
00109
00110 vgl_line_segment_2d<T> project( const vgl_line_segment_3d<T>& world_line ) const;
00111
00112
00113 vgl_line_segment_2d<T> operator()( const vgl_line_segment_3d<T>& world_line ) const
00114 { return project( world_line ); }
00115
00116
00117 vgl_line_2d<T> project( const vgl_infinite_line_3d<T>& world_line ) const;
00118
00119
00120 vgl_line_2d<T> operator()( const vgl_infinite_line_3d<T>& world_line ) const
00121 { return project( world_line ); }
00122
00123
00124 vgl_homg_line_3d_2_points<T> backproject( const vgl_homg_point_2d<T>& image_point ) const;
00125
00126
00127
00128 vgl_homg_plane_3d<T> backproject( const vgl_homg_line_2d<T>& image_line ) const;
00129
00130
00131
00132
00133
00134 virtual vgl_homg_point_3d<T> camera_center() const;
00135
00136
00137 vgl_homg_plane_3d<T> principal_plane() const{
00138 return vgl_homg_plane_3d<T>( P_[2] ); }
00139
00140
00141 vgl_homg_point_2d<T> x_vanishing_point() const{
00142 return vgl_homg_point_2d<T>( P_(0,0), P_(1,0), P_(2,0) ); }
00143 vgl_homg_point_2d<T> y_vanishing_point() const{
00144 return vgl_homg_point_2d<T>( P_(0,1), P_(1,1), P_(2,1) ); }
00145 vgl_homg_point_2d<T> z_vanishing_point() const{
00146 return vgl_homg_point_2d<T>( P_(0,2), P_(1,2), P_(2,2) ); }
00147
00148
00149
00150
00151
00152 const vnl_matrix_fixed<T,3,4>& get_matrix() const{ return P_; }
00153
00154
00155
00156 vnl_svd<T>* svd() const;
00157
00158
00159
00160
00161 virtual bool set_matrix( const vnl_matrix_fixed<T,3,4>& new_camera_matrix );
00162 virtual bool set_matrix( const T* new_camera_matrix );
00163
00164
00165
00166
00167
00168 virtual void b_write(vsl_b_ostream &os) const;
00169
00170
00171 virtual void b_read(vsl_b_istream &is);
00172
00173
00174 short version() const {return 1;}
00175
00176
00177 void print_summary(vcl_ostream &os) const { os << *this; }
00178
00179
00180 virtual vcl_string is_a() const { return vcl_string("vpgl_proj_camera"); }
00181
00182
00183 virtual bool is_class(vcl_string const& cls) const
00184 { return cls==is_a() || cls==vcl_string("vpgl_camera"); }
00185
00186
00187
00188 virtual vpgl_proj_camera<T> *cast_to_proj_camera() {return this;}
00189 virtual const vpgl_proj_camera<T> *cast_to_proj_camera() const {return this;}
00190
00191
00192
00193
00194 virtual vpgl_perspective_camera<T> *cast_to_perspective_camera() {return 0;}
00195 virtual const vpgl_perspective_camera<T> *cast_to_perspective_camera() const {return 0;}
00196
00197 private:
00198
00199
00200 vnl_matrix_fixed<T,3,4> P_;
00201
00202 mutable vnl_svd<T>* cached_svd_;
00203 };
00204
00205
00206
00207
00208
00209 template <class T>
00210 vgl_h_matrix_3d<T> get_canonical_h( vpgl_proj_camera<T>& camera );
00211
00212
00213 template <class T>
00214 void fix_cheirality( vpgl_proj_camera<T>& camera );
00215
00216
00217 template <class T>
00218 void make_cannonical( vpgl_proj_camera<T>& camera );
00219
00220
00221 template <class T>
00222 vpgl_proj_camera<T> premultiply( const vpgl_proj_camera<T>& in_camera,
00223 const vnl_matrix_fixed<T,3,3>& transform );
00224
00225
00226 template <class T>
00227 vpgl_proj_camera<T> premultiply( const vpgl_proj_camera<T>& in_camera,
00228 const vgl_h_matrix_2d<T>& transform )
00229 {
00230 return premultiply(in_camera, transform.get_matrix());
00231 }
00232
00233
00234
00235 template <class T>
00236 vpgl_proj_camera<T> postmultiply( const vpgl_proj_camera<T>& in_camera,
00237 const vnl_matrix_fixed<T,4,4>& transform );
00238
00239
00240 template <class T>
00241 vpgl_proj_camera<T> postmultiply( const vpgl_proj_camera<T>& in_camera,
00242 const vgl_h_matrix_3d<T>& transform )
00243 {
00244 return postmultiply(in_camera, transform.get_matrix());
00245 }
00246
00247 template <class T>
00248 vgl_point_3d<T> triangulate_3d_point(const vpgl_proj_camera<T>& c1,
00249 const vgl_point_2d<T>& x1,
00250 const vpgl_proj_camera<T>& c2,
00251 const vgl_point_2d<T>& x2);
00252
00253
00254
00255
00256 template <class T>
00257 vcl_vector<vnl_matrix_fixed<T,2,3> >
00258 image_jacobians(const vpgl_proj_camera<T>& camera,
00259 const vcl_vector<vgl_point_3d<T> >& pts);
00260
00261
00262
00263
00264
00265
00266 template <class Type>
00267 vcl_ostream& operator<<(vcl_ostream& s, vpgl_proj_camera<Type> const& p);
00268
00269
00270 template <class Type>
00271 vcl_istream& operator>>(vcl_istream& s, vpgl_proj_camera<Type>& p);
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 template <class T>
00284 void vsl_add_to_binary_loader(vpgl_proj_camera<T> const& b);
00285
00286
00287 #endif // vpgl_proj_camera_h_