core/vgl/algo/vgl_h_matrix_2d.h

Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_2d.h
00002 #ifndef vgl_h_matrix_2d_h_
00003 #define vgl_h_matrix_2d_h_
00004 //:
00005 // \file
00006 // \brief 3x3 plane-to-plane projectivity
00007 //
00008 // A class to hold a plane-to-plane projective transformation matrix
00009 // and to perform common operations using it e.g. transfer point.
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface
00014 //   23 Oct 2002 - Peter Vanroose - using fixed 3x3 matrices throughout
00015 //   22 Mar 2003 - J.L. Mundy - preparing for upgrade to vgl
00016 //   24 Jun 2003 - Peter Vanroose - added projective_basis() from 4 lines
00017 // \endverbatim
00018 
00019 #include <vcl_vector.h>
00020 #include <vnl/vnl_matrix_fixed.h>
00021 #include <vgl/vgl_homg_point_2d.h>
00022 #include <vgl/vgl_homg_line_2d.h>
00023 #include <vgl/vgl_conic.h>
00024 #include <vcl_iosfwd.h>
00025 
00026 //:
00027 // A class to hold a plane-to-plane projective transformation matrix
00028 // and to perform common operations using it e.g. transfer point.
00029 template <class T>
00030 class vgl_h_matrix_2d
00031 {
00032   // Data Members--------------------------------------------------------------
00033  protected:
00034   vnl_matrix_fixed<T,3,3> t12_matrix_;
00035 
00036  public:
00037 
00038   // Constructors/Initializers/Destructors-------------------------------------
00039 
00040   vgl_h_matrix_2d();
00041   vgl_h_matrix_2d(const vgl_h_matrix_2d<T>& M);
00042   vgl_h_matrix_2d(vnl_matrix_fixed<T,3,3> const& M);
00043   vgl_h_matrix_2d(const T* t_matrix);
00044   vgl_h_matrix_2d(vcl_istream& s);
00045   vgl_h_matrix_2d(char const* filename);
00046 
00047  ~vgl_h_matrix_2d();
00048 
00049   // Operations----------------------------------------------------------------
00050 
00051   vgl_homg_point_2d<T> operator()(vgl_homg_point_2d<T> const& p) const;
00052   vgl_homg_point_2d<T> operator*(vgl_homg_point_2d<T> const& p) const { return (*this)(p);}
00053   bool operator==(vgl_h_matrix_2d<T> const& M) { return t12_matrix_ == M.get_matrix(); }
00054 
00055   vgl_homg_line_2d<T> preimage(vgl_homg_line_2d<T> const& l) const;
00056   vgl_homg_line_2d<T> correlation(vgl_homg_point_2d<T> const& p) const;
00057   vgl_homg_point_2d<T> correlation(vgl_homg_line_2d<T> const& l) const;
00058 
00059   //: assumed to be a point conic
00060   vgl_conic<T> operator() (vgl_conic<T> const& C) const;
00061 
00062   // these operations require taking an inverse
00063   vgl_homg_point_2d<T> preimage(vgl_homg_point_2d<T> const& p) const;
00064   vgl_conic<T> preimage(vgl_conic<T> const& C) const;
00065   vgl_homg_line_2d<T> operator()(vgl_homg_line_2d<T> const& l) const;
00066   vgl_homg_line_2d<T> operator*(vgl_homg_line_2d<T> const& l) const { return (*this)(l);}
00067 
00068   //: Composition
00069   vgl_h_matrix_2d operator*(const vgl_h_matrix_2d& h2) const { return vgl_h_matrix_2d<T>(t12_matrix_ * h2.t12_matrix_); }
00070 
00071   // Data Access---------------------------------------------------------------
00072 
00073   T get(unsigned int row_index, unsigned int col_index) const;
00074   void get(T *t_matrix) const;
00075   void get(vnl_matrix<T>* t_matrix) const;
00076   const vnl_matrix_fixed<T,3,3>& get_matrix() const { return t12_matrix_; }
00077   const vgl_h_matrix_2d get_inverse () const;
00078 
00079   void set(const T *t_matrix);
00080   void set(vnl_matrix_fixed<T,3,3> const& t_matrix);
00081 
00082   // various affine transformations that set the corresponding parts of the matrix
00083 
00084   //:initialize the transformation to identity
00085   void set_identity();
00086 
00087   //: set T[0][2] = tx and T[1][2] = ty, other elements unaltered
00088   void set_translation(const T tx, const T ty);
00089 
00090   //: the upper 2x2 part of the matrix is replaced by a rotation matrix.
00091   // theta is in radians
00092   void set_rotation(const T theta);
00093 
00094   //: initialize the transform to a scaling transform.
00095   // $S = \left[ \begin{array}{ccc}
00096   //                                s & 0 & 0 \\%
00097   //                                0 & s & 0 \\%
00098   //                                0 & 0 & 1
00099   // \end{array}\right]$                         , Ts = S*T.
00100   void set_scale(const T scale);
00101 
00102   //: initialize the transform to a diagonal aspect transform.
00103   // $A = \left[ \begin{array}{ccc}
00104   //                                1 & 0 & 0 \\%
00105   //                                0 & a & 0 \\%
00106   //                                0 & 0 & 1
00107   // \end{array}\right]$                         , Ta = A*T.
00108   void set_aspect_ratio(const T aspect_ratio);
00109 
00110   //: transformation to projective basis (canonical frame)
00111   // Compute the homography that takes the input set of points to the
00112   // canonical frame.  The points act as the projective basis for
00113   // the canonical coordinate system.  In the canonical frame the points
00114   // have coordinates:
00115   // $\begin{array}{cccc}
00116   //   p[0] & p[1] & p[2] & p[3] \\%
00117   //     1  &   0  &   0  &   1  \\%
00118   //     0  &   1  &   0  &   1  \\%
00119   //     0  &   0  &   1  &   1
00120   // \end{array}$
00121   bool projective_basis(vcl_vector<vgl_homg_point_2d<T> > const& four_points);
00122 
00123   //: transformation to projective basis (canonical frame)
00124   // Compute the homography that takes the input set of lines to the canonical
00125   // frame.  The lines act as the dual projective basis for the canonical
00126   // coordinate system.  In the canonical frame the lines have equations:
00127   // x=0; y=0; w=0; x+y+w=0.  (The third line is the line at infinity.)
00128   bool projective_basis(vcl_vector<vgl_homg_line_2d<T> > const& four_lines
00129 #ifdef VCL_VC_6
00130                        , int dummy=0 // parameter to help useless compiler disambiguate different functions
00131 #endif
00132                        );
00133 
00134   bool read(vcl_istream& s);
00135   bool read(char const* filename);
00136 };
00137 
00138 template <class T> vcl_ostream& operator<<(vcl_ostream& s, const vgl_h_matrix_2d<T>& h);
00139 template <class T> vcl_istream& operator>>(vcl_istream& s, vgl_h_matrix_2d<T>& h);
00140 
00141 #define VGL_H_MATRIX_2D_INSTANTIATE(T) extern "please include vgl/algo/vgl_h_matrix_2d.txx first"
00142 
00143 #endif // vgl_h_matrix_2d_h_

Generated on Mon Mar 8 05:07:49 2010 for core/vgl by  doxygen 1.5.1