00001 // This is oxl/mvl/HMatrix2D.h 00002 #ifndef _HMatrix2D_h 00003 #define _HMatrix2D_h 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief 3x3 plane-to-plane projectivity 00010 // 00011 // A class to hold a plane-to-plane 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 // \endverbatim 00019 00020 #include <vnl/vnl_double_3x3.h> 00021 #include <vnl/vnl_double_4.h> 00022 #include <vgl/vgl_homg_point_2d.h> 00023 #include <vgl/vgl_homg_line_2d.h> 00024 #include <vgl/algo/vgl_homg_operators_2d.h> // t12_matrix_ * vgl_homg_point_2d 00025 #include <mvl/HomgPoint2D.h> 00026 #include <mvl/HomgLine2D.h> 00027 #include <mvl/HomgLineSeg2D.h> 00028 #include <vcl_iosfwd.h> 00029 00030 //: 00031 // A class to hold a plane-to-plane projective transformation matrix 00032 // and to perform common operations using it e.g. transfer point. 00033 00034 class HMatrix2D 00035 { 00036 // Data Members-------------------------------------------------------------- 00037 vnl_double_3x3 t12_matrix_; 00038 00039 public: 00040 00041 //: Flags for reduced H matrices 00042 enum Type { 00043 Euclidean, 00044 Similarity, 00045 Affine, 00046 Projective 00047 }; 00048 00049 // Constructors/Initializers/Destructors------------------------------------- 00050 00051 HMatrix2D(); 00052 HMatrix2D(const HMatrix2D& M); 00053 HMatrix2D(vnl_double_3x3 const& M); 00054 HMatrix2D(const double* t_matrix); 00055 HMatrix2D(vcl_istream& s); 00056 HMatrix2D(char const* filename); 00057 ~HMatrix2D(); 00058 00059 // Operations---------------------------------------------------------------- 00060 00061 // Deprecated Methods: 00062 HomgPoint2D transform_to_plane2(const HomgPoint2D& x1) const; 00063 vgl_homg_point_2d<double> transform_to_plane2(vgl_homg_point_2d<double> const& x1) const 00064 { return t12_matrix_ * x1; } 00065 HomgLine2D transform_to_plane1(const HomgLine2D& l2) const; 00066 vgl_homg_line_2d<double> transform_to_plane1(vgl_homg_line_2d <double> const& l2) const 00067 { return t12_matrix_.transpose() * l2; } 00068 HomgLine2D transform_to_plane2(const HomgLine2D& l1) const; 00069 // Note that this calculates the inverse of $H$ on every call. 00070 vgl_homg_line_2d<double> transform_to_plane2(vgl_homg_line_2d <double> const& l1) const 00071 { return this->get_inverse().get_matrix().transpose() * l1; } 00072 HomgPoint2D transform_to_plane1(const HomgPoint2D& x2) const; 00073 // Note that this calculates the inverse of $H$ on every call. 00074 vgl_homg_point_2d<double> transform_to_plane1(vgl_homg_point_2d<double> const& x2) const 00075 { return this->get_inverse().get_matrix() * x2; } 00076 00077 HomgPoint2D operator*(const HomgPoint2D& x1) const { return transform_to_plane2(x1); } 00078 vgl_homg_point_2d<double> operator*(vgl_homg_point_2d<double> const& x1) const { return transform_to_plane2(x1); } 00079 HomgPoint2D operator()(const HomgPoint2D& p) const { return transform_to_plane2(p); } 00080 vgl_homg_point_2d<double> operator()(vgl_homg_point_2d<double> const& p) const { return transform_to_plane2(p); } 00081 HomgLine2D preimage(const HomgLine2D& l) const { return this->transform_to_plane1(l); } 00082 vgl_homg_line_2d<double> preimage(vgl_homg_line_2d<double> const& l) const { return this->transform_to_plane1(l); } 00083 00084 // WARNING. these cost one vnl_svd<double>, so are here for convenience only : 00085 HomgPoint2D preimage(const HomgPoint2D& p) const { return this->get_inverse().transform_to_plane2(p); } 00086 vgl_homg_point_2d<double> preimage(vgl_homg_point_2d<double> const& p) const {return this->get_inverse().transform_to_plane2(p);} 00087 HomgLine2D operator()(const HomgLine2D& l) const { return this->get_inverse().transform_to_plane1(l); } 00088 vgl_homg_line_2d<double> operator()(vgl_homg_line_2d<double> const& l) const {return this->get_inverse().transform_to_plane1(l);} 00089 00090 vnl_double_4 transform_bounding_box(double x0, double y0, double x1, double y1); 00091 00092 //: Composition 00093 HMatrix2D operator*(const HMatrix2D& H2) { return HMatrix2D(t12_matrix_ * H2.t12_matrix_); } 00094 00095 // Data Access--------------------------------------------------------------- 00096 00097 double get(unsigned int row_index, unsigned int col_index) const; 00098 void get(double *t_matrix) const; 00099 void get(vnl_matrix<double>* t_matrix) const; 00100 const vnl_double_3x3& get_matrix() const { return t12_matrix_; } 00101 HMatrix2D get_inverse() const; 00102 00103 void set_identity(); 00104 void set(const double *t_matrix); 00105 void set(vnl_double_3x3 const& t_matrix); 00106 00107 bool read(vcl_istream& s); 00108 bool read(char const* filename); 00109 }; 00110 00111 vcl_ostream& operator<<(vcl_ostream& s, const HMatrix2D& H); 00112 vcl_istream& operator>>(vcl_istream& s, HMatrix2D& H); 00113 00114 #endif // _HMatrix2D_h