contrib/gel/mrc/vpgl/vpgl_calibration_matrix.h
Go to the documentation of this file.
00001 // This is gel/mrc/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 <vsl/vsl_binary_io.h>
00022 #include <vgl/vgl_point_2d.h>
00023 
00024 // not used? #include <vcl_iostream.h>
00025 
00026 //:  A class representing the "K" matrix of a perspective camera matrix as described in
00027 //   Hartley and Zisserman, "Multiple View Geometry".
00028 template <class T>
00029 class vpgl_calibration_matrix
00030 {
00031  public:
00032   //: Default constructor makes an identity matrix.
00033   vpgl_calibration_matrix();
00034 
00035   //: Destructor
00036   virtual ~vpgl_calibration_matrix(){}
00037 
00038   //: Construct using all of the camera parameters.
00039   // Must satisfy the following requirements: x,y_scales must be > 0, focal_length must be not equal to 0.
00040   vpgl_calibration_matrix( T focal_length, const vgl_point_2d<T>& principal_point,
00041                            T x_scale = (T)1, T y_scale = (T)1, T skew = (T)0 );
00042 
00043   //: Construct from a right upper triangular matrix whose decomposition into the calibration components makes sense.
00044   //  The supplied matrix can be a scalar multiple of such a matrix.
00045   vpgl_calibration_matrix( const vnl_matrix_fixed<T,3,3>& K );
00046 
00047   //: Get the calibration matrix.
00048   vnl_matrix_fixed<T,3,3> get_matrix() const;
00049 
00050   //: Getters and setters for all of the parameters.
00051   void set_focal_length( T new_focal_length );
00052   void set_principal_point( const vgl_point_2d<T>& new_principal_point );
00053   void set_x_scale( T new_x_scale );
00054   void set_y_scale( T new_y_scale );
00055   void set_skew( T new_skew );
00056 
00057   T focal_length() const { return focal_length_; }
00058   vgl_point_2d<T> principal_point() const { return principal_point_; }
00059   T x_scale() const { return x_scale_; }
00060   T y_scale() const { return y_scale_; }
00061   T skew() const { return skew_; }
00062 
00063   //: Equality tests
00064   bool operator==(vpgl_calibration_matrix<T> const &that) const;
00065   bool operator!=(vpgl_calibration_matrix<T> const &that) const
00066     {return !(*this==that);}
00067 
00068   //: Maps to and from the focal plane
00069   vgl_point_2d<T> map_to_focal_plane(vgl_point_2d<T> const& p_image) const;
00070 
00071   vgl_point_2d<T> map_to_image(vgl_point_2d<T> const& p_focal_plane) const;
00072 
00073   // I/O :---------------------
00074 
00075   //: Binary save self to stream.
00076   virtual void b_write(vsl_b_ostream &os) const;
00077 
00078   //: Binary load self from stream.
00079   virtual void b_read(vsl_b_istream &is);
00080 
00081   //: IO version number
00082   short version() const {return 1;}
00083 
00084  protected:
00085   //: The following is a list of the parameters in the calibration matrix.
00086   T focal_length_;
00087   vgl_point_2d<T> principal_point_;
00088   T x_scale_, y_scale_, skew_;
00089 };
00090 
00091 // Non-member Functions:-------------------------------------------------------------
00092 
00093 //: Binary save
00094 template <class T>
00095 void vsl_b_write(vsl_b_ostream &os, const vpgl_calibration_matrix<T>* p);
00096 
00097 
00098 //: Binary read
00099 template <class T>
00100 void vsl_b_read(vsl_b_istream &is, vpgl_calibration_matrix<T>* &p);
00101 
00102 
00103 #endif // vpgl_calibration_matrix_h_