Go to the documentation of this file.00001
00002 #ifndef vgl_p_matrix_h_
00003 #define vgl_p_matrix_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <vcl_iosfwd.h>
00031
00032 #include <vnl/algo/vnl_algo_fwd.h>
00033 #include <vnl/vnl_matrix.h>
00034 #include <vnl/vnl_vector.h>
00035 #include <vnl/vnl_matrix_fixed.h>
00036 #include <vnl/vnl_vector_fixed.h>
00037 #include <vgl/vgl_homg_point_2d.h>
00038 #include <vgl/vgl_homg_point_3d.h>
00039 #include <vgl/vgl_homg_line_2d.h>
00040 #include <vgl/vgl_homg_line_3d_2_points.h>
00041 #include <vgl/vgl_line_segment_2d.h>
00042 #include <vgl/vgl_line_segment_3d.h>
00043 #include <vgl/algo/vgl_homg_operators_3d.h>
00044 #include <vgl/algo/vgl_h_matrix_3d.h>
00045
00046 template <class T>
00047 class vgl_p_matrix
00048 {
00049 public:
00050
00051
00052
00053
00054 vgl_p_matrix();
00055
00056
00057
00058
00059 vgl_p_matrix(vcl_istream&);
00060
00061 vgl_p_matrix(const T *c_matrix);
00062
00063 explicit vgl_p_matrix(vnl_matrix_fixed<T, 3, 4> const& P);
00064
00065 vgl_p_matrix(const vnl_matrix<T>& A, const vnl_vector<T>& a);
00066 vgl_p_matrix(const vgl_p_matrix& P);
00067 ~vgl_p_matrix();
00068
00069
00070
00071
00072
00073
00074 static vgl_p_matrix read(const char* filename);
00075
00076 static vgl_p_matrix read(vcl_istream&);
00077
00078
00079
00080
00081 vgl_homg_point_2d<T> operator()(vgl_homg_point_3d<T> const& X) const { return p_matrix_ * X; }
00082
00083 vgl_homg_point_2d<T> operator*(vgl_homg_point_3d<T> const& X) const { return (*this)(X); }
00084
00085 vgl_homg_line_2d<T> operator()(vgl_homg_line_3d_2_points<T> const& L) const;
00086
00087 vgl_homg_line_2d<T> operator*(vgl_homg_line_3d_2_points<T> const& L) const { return (*this)(L);}
00088
00089 vgl_line_segment_2d<T> operator()(vgl_line_segment_3d<T> const& L) const;
00090
00091 vgl_line_segment_2d<T> operator*(vgl_line_segment_3d<T> const& L) const{return (*this)(L);}
00092
00093
00094
00095 vgl_homg_point_3d<T> backproject_pseudoinverse(vgl_homg_point_2d<T> const& x) const;
00096
00097
00098
00099 vgl_homg_line_3d_2_points<T> backproject(vgl_homg_point_2d<T> const& x) const;
00100
00101 vgl_homg_plane_3d<T> backproject(vgl_homg_line_2d<T> const& l) const;
00102
00103
00104 vgl_p_matrix<T> postmultiply(vnl_matrix_fixed<T,4,4> const& H) const;
00105
00106
00107 vgl_p_matrix<T> premultiply(vnl_matrix_fixed<T,3,3> const& H) const;
00108
00109 vgl_p_matrix<T> operator*(vnl_matrix_fixed<T, 3,3> const& C)const{return vgl_p_matrix(C * p_matrix_);}
00110
00111
00112 vnl_svd<T>* svd() const;
00113
00114
00115 void clear_svd() const;
00116
00117
00118
00119 vgl_homg_point_3d<T> get_focal() const;
00120
00121
00122
00123 vgl_h_matrix_3d<T> get_canonical_H() const;
00124
00125
00126 bool is_canonical(T tol = 0) const;
00127
00128
00129
00130
00131 bool is_behind_camera(vgl_homg_point_3d<T> const&);
00132
00133 void flip_sign();
00134
00135 bool looks_conditioned();
00136
00137 void fix_cheirality();
00138
00139
00140
00141 vgl_p_matrix& operator=(const vgl_p_matrix&);
00142
00143 bool operator==(vgl_p_matrix const& p) const { return p_matrix_ == p.get_matrix(); }
00144
00145
00146 void get(vnl_matrix<T>* A, vnl_vector<T>* a) const;
00147
00148 void get(vnl_matrix_fixed<T,3,3>* A, vnl_vector_fixed<T,3>* a) const;
00149
00150
00151 void get_rows(vnl_vector<T>* a, vnl_vector<T>* b, vnl_vector<T>* c) const;
00152
00153 void get_rows(vnl_vector_fixed<T,4>* a, vnl_vector_fixed<T,4>* b, vnl_vector_fixed<T,4>* c) const;
00154
00155 void set_rows(const vnl_vector_fixed<T,4>& a, const vnl_vector_fixed<T,4>& b, const vnl_vector_fixed<T,4>& c);
00156
00157
00158 T get(unsigned int row_index, unsigned int col_index) const;
00159
00160 void get(T *c_matrix) const;
00161
00162 void get(vnl_matrix<T>& p_matrix) const { p_matrix = p_matrix_; }
00163
00164 void get(vnl_matrix_fixed<T, 3, 4>& p_matrix) const { p_matrix = p_matrix_; }
00165
00166
00167 void set(const T* p_matrix);
00168
00169 void set(const T p_matrix [3][4]);
00170
00171 void set(const vnl_matrix<T>& p_matrix) { p_matrix_ = p_matrix; clear_svd(); }
00172
00173 void set(vnl_matrix_fixed<T, 3, 4> const& p_matrix) { p_matrix_ = p_matrix; clear_svd(); }
00174
00175 void set(const vnl_matrix<T>& A, const vnl_vector<T>& a);
00176
00177 const vnl_matrix_fixed<T, 3, 4>& get_matrix() const { return p_matrix_; }
00178
00179
00180 void set_identity();
00181
00182
00183
00184
00185
00186
00187
00188 bool read_ascii(vcl_istream& f);
00189
00190
00191 protected:
00192 vnl_matrix_fixed<T, 3,4> p_matrix_;
00193 mutable vnl_svd<T>* svd_;
00194 };
00195
00196
00197 template <class T>
00198 vgl_p_matrix<T> operator*(const vgl_p_matrix<T>& P, const vgl_h_matrix_3d<T>& H);
00199
00200
00201 template <class T> vcl_ostream& operator<<(vcl_ostream& s, const vgl_p_matrix<T>& p);
00202
00203 template <class T> vcl_istream& operator>>(vcl_istream& i, vgl_p_matrix<T>& p);
00204
00205 #define VGL_P_MATRIX_INSTANTIATE(T) extern "please include vgl/algo/vgl_p_matrix.txx first"
00206
00207 #endif // vgl_p_matrix_h_