core/vpgl/vpgl_affine_camera.h
Go to the documentation of this file.
00001 // This is core/vpgl/vpgl_affine_camera.h
00002 #ifndef vpgl_affine_camera_h_
00003 #define vpgl_affine_camera_h_
00004 //:
00005 // \file
00006 // \brief A class for the affine camera model.
00007 // \author Thomas Pollard
00008 // \date January 28, 2005
00009 // \author Joseph Mundy, Matt Leotta, Vishal Jain
00010 // \verbatim
00011 //  Modifications
00012 //  March 14, 2010 J.L. Mundy brought in virtual functions of proj_camera
00013 //  that require special treatment for the affine case. Added a default
00014 //  viewing distance to allow these methods to construct finite objects when
00015 //  the camera center is infinity.
00016 //  at infinity.
00017 // \endverbatim
00018 
00019 #include <vnl/vnl_fwd.h>
00020 #include <vgl/vgl_fwd.h>
00021 #include "vpgl_proj_camera.h"
00022 
00023 template <class T>
00024 class vpgl_affine_camera : public vpgl_proj_camera<T>
00025 {
00026  public:
00027 
00028   //: Default constructor creates the canonical affine camera.
00029   vpgl_affine_camera();
00030 
00031   //: Construct from the first two rows.
00032   vpgl_affine_camera( const vnl_vector_fixed<T,4>& row1,
00033                       const vnl_vector_fixed<T,4>& row2 );
00034 
00035   //: Construct from a 3x4 matrix, sets the last row to 0001.
00036   // The bottom right entry had better not be 0.
00037   vpgl_affine_camera( const vnl_matrix_fixed<T,3,4>& camera_matrix );
00038 
00039   //: Construct from a ray direction, up vector, 3-d stare point: vgl interface
00040   // \a p projects to (\a u0, \a v0), \a su and \a sv are calibration scale factors
00041   vpgl_affine_camera(vgl_vector_3d<T> ray, vgl_vector_3d<T> up,
00042                      vgl_point_3d<T> stare_pt, T u0, T v0, T su, T sv);
00043 
00044   //: Construct from a ray direction, up vector, 3-d stare point: vnl interface
00045   // \a p projects to (\a u0, \a v0), \a su and \a sv are calibration scale factors
00046   vpgl_affine_camera(vnl_vector_fixed<T, 3> ray, vnl_vector_fixed<T, 3> up,
00047                      vnl_vector_fixed<T, 3> stare_pt, T u0, T v0, T su, T sv) {
00048     vgl_vector_3d<T> ry(ray[0], ray[1], ray[2]), u(up[0], up[1], up[2]);
00049     vgl_point_3d<T> pt(stare_pt[0], stare_pt[1], stare_pt[2]);
00050     (*this) = vpgl_affine_camera<T>(ry, u, pt, u0, v0, su, sv);
00051   }
00052 
00053   virtual vcl_string type_name() const { return "vpgl_affine_camera"; }
00054 
00055   //: Set the top two rows.
00056   void set_rows( const vnl_vector_fixed<T,4>& row1,
00057                  const vnl_vector_fixed<T,4>& row2 );
00058 
00059   // === The following virtual functions require special treatment for the affine camera ===
00060 
00061   //: set a finite viewing distance to allow the methods below to return finite objects
00062   void set_viewing_distance(T dist) {view_distance_ = dist;}
00063   T viewing_distance() const {return view_distance_;}
00064 
00065   //: Equality test
00066   inline bool operator==(vpgl_affine_camera<T> const &that) const
00067   { return this == &that ||
00068            (this->get_matrix()==that.get_matrix() &&
00069             this->viewing_distance() == that.viewing_distance() );
00070   }
00071 
00072 //: Find the 3d coordinates of the center of the camera. Will be an ideal point with the sense of the ray direction.
00073   virtual vgl_homg_point_3d<T> camera_center() const;
00074 
00075   //: Find the 3d ray that goes through the camera center.
00076   // The finite point of the ray is at the viewing distance from the origin
00077   virtual  vgl_homg_line_3d_2_points<T> backproject( const vgl_homg_point_2d<T>& image_point ) const;
00078 
00079   //: Find the world plane perpendicular to the camera rays at viewing distance from the origin
00080   virtual  vgl_homg_plane_3d<T> principal_plane() const;
00081 
00082  private:
00083   T view_distance_; // distance from origin along rays
00084   vgl_vector_3d<T> ray_dir_;//needed to assign a consistent sense to the ray
00085 };
00086 
00087 #endif // vpgl_affine_camera_h_