contrib/oxl/mvl/FDesignMatrix.cxx
Go to the documentation of this file.
00001 // This is oxl/mvl/FDesignMatrix.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 //  \file
00007 
00008 #include "FDesignMatrix.h"
00009 
00010 //: Construct a design matrix for the fundamental matrix least squares problem.
00011 // Specifically, it constructs the matrix
00012 // \f[
00013 // D = \left( \begin{array}{lllllllll}
00014 //          m_{11} m'_{11} & m_{12} m'_{11}  & m_{13} m'_{11} &
00015 //          m_{11} m'_{12} & m_{12} m'_{12}  & m_{13} m'_{12} &
00016 //          m_{11} m'_{13} & m_{12} m'_{13}  & m_{13} m'_{13}
00017 //       \\ \vdots & & & & & & & &
00018 //       \\ m_{n1} m'_{n1} & m_{n2} m'_{n1}  & m_{n3} m'_{n1} &
00019 //          m_{n1} m'_{n2} & m_{n2} m'_{n2}  & m_{n3} m'_{n2} &
00020 //          m_{n1} m'_{n3} & m_{n2} m'_{n3}  & m_{n3} m'_{n3}
00021 //     \end{array} \right)
00022 // \f]
00023 // such that $ D f = 0 $ for
00024 // $f = (F_{11} F_{12} F_{13} F_{21} F_{22} F_{23} F_{31} F_{32} F_{33}) $
00025 // where $F$ is the fundamental matrix.
00026 // }
00027 //
00028 
00029 FDesignMatrix::FDesignMatrix(vcl_vector<HomgPoint2D> const& points1,
00030                              vcl_vector<HomgPoint2D> const& points2):
00031   base(points1.size(), 9)
00032 {
00033   unsigned int n = points1.size();
00034   for (unsigned int row = 0; row < n; ++row) {
00035     const HomgPoint2D& p1 = points1[row];
00036     const HomgPoint2D& p2 = points2[row];
00037 
00038     vnl_matrix<double>& D = *this;
00039     D(row,0) = p1.x() * p2.x();
00040     D(row,1) = p1.y() * p2.x();
00041     D(row,2) = p1.w() * p2.x();
00042     D(row,3) = p1.x() * p2.y();
00043     D(row,4) = p1.y() * p2.y();
00044     D(row,5) = p1.w() * p2.y();
00045     D(row,6) = p1.x() * p2.w();
00046     D(row,7) = p1.y() * p2.w();
00047     D(row,8) = p1.w() * p2.w();
00048   }
00049 }
00050 
00051 FDesignMatrix::FDesignMatrix(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00052                              vcl_vector<vgl_homg_point_2d<double> > const& points2):
00053   base(points1.size(), 9)
00054 {
00055   unsigned int n = points1.size();
00056   for (unsigned int row = 0; row < n; ++row) {
00057     const vgl_homg_point_2d<double>& p1 = points1[row];
00058     const vgl_homg_point_2d<double>& p2 = points2[row];
00059 
00060     vnl_matrix<double>& D = *this;
00061     D(row,0) = p1.x() * p2.x();
00062     D(row,1) = p1.y() * p2.x();
00063     D(row,2) = p1.w() * p2.x();
00064     D(row,3) = p1.x() * p2.y();
00065     D(row,4) = p1.y() * p2.y();
00066     D(row,5) = p1.w() * p2.y();
00067     D(row,6) = p1.x() * p2.w();
00068     D(row,7) = p1.y() * p2.w();
00069     D(row,8) = p1.w() * p2.w();
00070   }
00071 }