core/vgl/algo/vgl_h_matrix_3d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_3d.h
00002 #ifndef vgl_h_matrix_3d_h_
00003 #define vgl_h_matrix_3d_h_
00004 //:
00005 // \file
00006 // \brief 4x4 3D-to-3D projectivity
00007 //
00008 // A class to hold a 3D 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  - prep for moving to vgl
00016 // \endverbatim
00017 
00018 #include <vcl_vector.h>
00019 #include <vcl_iosfwd.h>
00020 #include <vnl/vnl_fwd.h> // for vnl_vector_fixed<T,3>
00021 #include <vnl/vnl_matrix_fixed.h>
00022 #include <vgl/vgl_homg_point_3d.h>
00023 #include <vgl/vgl_homg_plane_3d.h>
00024 
00025 //:
00026 // A class to hold a 3-d projective transformation matrix
00027 // and to perform common operations using it e.g. transform point.
00028 template <class T>
00029 class vgl_h_matrix_3d
00030 {
00031  protected:
00032   vnl_matrix_fixed<T,4,4> t12_matrix_;
00033  public:
00034   vgl_h_matrix_3d() {}
00035  ~vgl_h_matrix_3d() {}
00036   vgl_h_matrix_3d(const vgl_h_matrix_3d& M);
00037   vgl_h_matrix_3d(vnl_matrix_fixed<T,4,4> const& M);
00038   vgl_h_matrix_3d(vnl_matrix_fixed<T,3,3> const& M,
00039                   vnl_vector_fixed<T,3> const& m);
00040   vgl_h_matrix_3d(const T* t_matrix);
00041   vgl_h_matrix_3d(vcl_istream&);
00042   vgl_h_matrix_3d(char const* filename);
00043   vgl_h_matrix_3d(vcl_vector<vgl_homg_point_3d<T> > const &points1,
00044                   vcl_vector<vgl_homg_point_3d<T> > const &points2);
00045 
00046   // Operations----------------------------------------------------------------
00047 
00048   vgl_homg_point_3d<T> operator()(vgl_homg_point_3d<T> const& x) const;
00049   vgl_homg_point_3d<T> operator* (vgl_homg_point_3d<T> const& x) const {return (*this)(x);}
00050   bool operator==(vgl_h_matrix_3d<T> const& M) { return t12_matrix_ == M.get_matrix(); }
00051 
00052   vgl_homg_plane_3d<T> preimage(vgl_homg_plane_3d<T> const& p);
00053 
00054   //the following require forming an inverse
00055   vgl_homg_point_3d<T> preimage(vgl_homg_point_3d<T> const& x) const;
00056   vgl_homg_plane_3d<T> operator()(vgl_homg_plane_3d<T> const& x) const;
00057 
00058   //:composition (*this) * H
00059   vgl_h_matrix_3d<T> operator * (vgl_h_matrix_3d<T> const& H) const
00060     {return t12_matrix_* H.t12_matrix_;}
00061 
00062   bool read(vcl_istream&);
00063 
00064   // Data Access---------------------------------------------------------------
00065 
00066   T get (unsigned int row_index, unsigned int col_index) const;
00067   void get (T* t_matrix) const;
00068   void get (vnl_matrix_fixed<T, 4, 4>* t_matrix) const;
00069   const vnl_matrix_fixed<T,4,4>& get_matrix() const { return t12_matrix_; }
00070   vgl_h_matrix_3d get_inverse() const;
00071 
00072   void set (unsigned int row_index, unsigned int col_index, const T value)
00073     {t12_matrix_[row_index][col_index]=value;}
00074 
00075   void set(const T *t_matrix);
00076   void set(vnl_matrix_fixed<T,4,4> const& t_matrix);
00077   bool projective_basis(vcl_vector<vgl_homg_point_3d<T> > const & five_points);
00078   void set_identity();
00079   void set_translation(T tx, T ty, T tz);
00080   //: rotation angle is in radians
00081   void set_rotation_about_axis(const vnl_vector_fixed<T,3>& axis, T angle);
00082   void set_rotation_roll_pitch_yaw(T yaw, T pitch, T roll);
00083   void set_rotation_euler(T rz1, T ry, T rz2);
00084   void set_rotation_matrix(vnl_matrix_fixed<T, 3, 3> const& R);
00085 
00086   bool is_rotation() const;
00087   bool is_euclidean() const;
00088 
00089   // ---------- extract components as transformations ----------
00090 
00091   //: corresponds to rotation for Euclidan transformations
00092   vgl_h_matrix_3d<T> get_upper_3x3() const;
00093   vnl_matrix_fixed<T, 3,3> get_upper_3x3_matrix() const;
00094 
00095   //: corresponds to translation for affine transformations
00096   vgl_homg_point_3d<T> get_translation() const;
00097   vnl_vector_fixed<T, 3> get_translation_vector() const;
00098 };
00099 
00100 // stream I/O
00101 template <class T> vcl_ostream& operator<<(vcl_ostream& s, vgl_h_matrix_3d<T> const& h);
00102 template <class T> vcl_istream& operator>>(vcl_istream& s, vgl_h_matrix_3d<T>&       h);
00103 
00104 #define VGL_H_MATRIX_3D_INSTANTIATE(T) extern "please include vgl/algo/vgl_h_matrix_3d.txx first"
00105 
00106 #endif // vgl_h_matrix_3d_h_