core/vgl/algo/vgl_h_matrix_1d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_1d.h
00002 #ifndef vgl_h_matrix_1d_h_
00003 #define vgl_h_matrix_1d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief 2x2 line-to-line projectivity
00010 //
00011 // A class to hold a line-to-line projective transformation matrix
00012 // and to perform common operations using it e.g. transfer point.
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface
00017 //   23 Oct 2002 - Peter Vanroose - using fixed 3x3 matrices throughout
00018 //   22 Mar 2003 - J.L. Mundy - preparing for upgrade to vgl
00019 //   13 Jun 2004 - Peter Vanroose - added set_identity() and projective_basis()
00020 // \endverbatim
00021 
00022 #include <vnl/vnl_matrix_fixed.h>
00023 #include <vgl/vgl_homg_point_1d.h>
00024 #include <vcl_iosfwd.h>
00025 
00026 template <class T>
00027 class vgl_h_matrix_1d
00028 {
00029   // Data Members--------------------------------------------------------------
00030  protected:
00031   vnl_matrix_fixed<T,2,2> t12_matrix_;
00032 
00033  public:
00034 
00035   // Constructors/Initializers/Destructors-------------------------------------
00036 
00037   vgl_h_matrix_1d();
00038   vgl_h_matrix_1d(const vgl_h_matrix_1d<T>& M);
00039   // product of two vgl_h_matrix_1ds
00040   vgl_h_matrix_1d(const vgl_h_matrix_1d<T>&,const vgl_h_matrix_1d<T>&);
00041   vgl_h_matrix_1d(vnl_matrix_fixed<T,2,2> const& M);
00042   vgl_h_matrix_1d(const T* t_matrix);
00043   vgl_h_matrix_1d(vcl_istream& s);
00044  ~vgl_h_matrix_1d();
00045 
00046   // Operations----------------------------------------------------------------
00047 
00048   vgl_homg_point_1d<T> operator()(const vgl_homg_point_1d<T>& x1) const;
00049   vgl_homg_point_1d<T> preimage(const vgl_homg_point_1d<T>& x2) const;
00050   vgl_homg_point_1d<T> operator* (const vgl_homg_point_1d<T>& x1) const;
00051   bool operator==(vgl_h_matrix_1d<T> const& M) { return t12_matrix_ == M.get_matrix(); }
00052 
00053   // Data Access---------------------------------------------------------------
00054 
00055   T get (unsigned int row_index, unsigned int col_index) const;
00056   void get (T *t_matrix) const;
00057   void get (vnl_matrix<T>* t_matrix) const;
00058   const vnl_matrix_fixed<T,2,2>& get_matrix () const { return t12_matrix_; }
00059   const vgl_h_matrix_1d get_inverse () const;
00060 
00061   //: transformation to projective basis (canonical frame)
00062   // Compute the homography that takes the input set of points to the
00063   // canonical frame.  The points act as the projective basis for
00064   // the canonical coordinate system.  In the canonical frame the points
00065   // have coordinates:
00066   // \verbatim
00067   //   p[0]p[1]p[2]
00068   //     1   0   1
00069   //     0   1   1
00070   // \endverbatim
00071   bool projective_basis(vcl_vector<vgl_homg_point_1d<T> > const& three_points);
00072 
00073   void set_identity() { t12_matrix_.set_identity(); }
00074   void set(const T *t_matrix);
00075   void set(vnl_matrix_fixed<T,2,2> const& t_matrix);
00076 
00077   static vgl_h_matrix_1d<T> read(char const* filename);
00078   static vgl_h_matrix_1d<T> read(vcl_istream&);
00079 };
00080 
00081 template <class T> vcl_ostream& operator<<(vcl_ostream& s, const vgl_h_matrix_1d<T>& h);
00082 template <class T> vcl_istream& operator>>(vcl_istream& s, vgl_h_matrix_1d<T>& h);
00083 
00084 
00085 #define VGL_H_MATRIX_1D_INSTANTIATE(T) extern "please include vgl/algo/vgl_h_matrix_1d.txx first"
00086 
00087 #endif // vgl_h_matrix_1d_h_