core/vpgl/vpgl_calibration_matrix.h
Go to the documentation of this file.
00001 // This is core/vpgl/vpgl_calibration_matrix.h
00002 #ifndef vpgl_calibration_matrix_h_
00003 #define vpgl_calibration_matrix_h_
00004 //:
00005 // \file
00006 // \brief A class for the calibration matrix component of a perspective camera matrix.
00007 // \author Thomas Pollard
00008 // \date January 28, 2005
00009 // \author Joseph Mundy, Matt Leotta, Vishal Jain
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   May 08, 2004  Ricardo Fabbri  Added binary I/O support
00014 //   May 08, 2004  Ricardo Fabbri  Added == operator
00015 // \endverbatim
00016 //
00017 
00018 #include <vgl/vgl_fwd.h>
00019 #include <vnl/vnl_fwd.h>
00020 #include <vnl/vnl_matrix_fixed.h>
00021 #include <vgl/vgl_point_2d.h>
00022 
00023 // not used? #include <vcl_iostream.h>
00024 
00025 //:  A class representing the "K" matrix of a perspective camera matrix as described in
00026 //   Hartley and Zisserman, "Multiple View Geometry".
00027 template <class T>
00028 class vpgl_calibration_matrix
00029 {
00030  public:
00031   //: Default constructor makes an identity matrix.
00032   vpgl_calibration_matrix();
00033 
00034   //: Destructor
00035   virtual ~vpgl_calibration_matrix() {}
00036 
00037   //: Construct using all of the camera parameters.
00038   // Must satisfy the following requirements: x,y_scales must be > 0, focal_length must be not equal to 0.
00039   vpgl_calibration_matrix( T focal_length, const vgl_point_2d<T>& principal_point,
00040                            T x_scale = (T)1, T y_scale = (T)1, T skew = (T)0 );
00041 
00042   //: Construct from a right upper triangular matrix whose decomposition into the calibration components makes sense.
00043   //  The supplied matrix can be a scalar multiple of such a matrix.
00044   vpgl_calibration_matrix( const vnl_matrix_fixed<T,3,3>& K );
00045 
00046   //: Get the calibration matrix.
00047   vnl_matrix_fixed<T,3,3> get_matrix() const;
00048 
00049   //: Getters and setters for all of the parameters.
00050   void set_focal_length( T new_focal_length );
00051   void set_principal_point( const vgl_point_2d<T>& new_principal_point );
00052   void set_x_scale( T new_x_scale );
00053   void set_y_scale( T new_y_scale );
00054   void set_skew( T new_skew );
00055 
00056   T focal_length() const { return focal_length_; }
00057   vgl_point_2d<T> principal_point() const { return principal_point_; }
00058   T x_scale() const { return x_scale_; }
00059   T y_scale() const { return y_scale_; }
00060   T skew() const { return skew_; }
00061 
00062   //: Equality tests
00063   bool operator==(vpgl_calibration_matrix<T> const &that) const;
00064   bool operator!=(vpgl_calibration_matrix<T> const &that) const
00065     {return !(*this==that);}
00066 
00067   //: Maps to and from the focal plane
00068   vgl_point_2d<T> map_to_focal_plane(vgl_point_2d<T> const& p_image) const;
00069 
00070   vgl_point_2d<T> map_to_image(vgl_point_2d<T> const& p_focal_plane) const;
00071 
00072  protected:
00073   //: The following is a list of the parameters in the calibration matrix.
00074   T focal_length_;
00075   vgl_point_2d<T> principal_point_;
00076   T x_scale_, y_scale_, skew_;
00077 };
00078 
00079 
00080 
00081 #endif // vpgl_calibration_matrix_h_