examples/homography/TooN/mclasses.hh

00001 
00002 /*                       
00003          Copyright (C) 2005 Tom Drummond
00004 
00005      This library is free software; you can redistribute it and/or
00006      modify it under the terms of the GNU Lesser General Public
00007      License as published by the Free Software Foundation; either
00008      version 2.1 of the License, or (at your option) any later version.
00009 
00010      This library is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013      Lesser General Public License for more details.
00014 
00015      You should have received a copy of the GNU Lesser General Public
00016      License along with this library; if not, write to the Free Software
00017      Foundation, Inc.
00018      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019 */
00020 #ifndef __MCLASSES_HH
00021 #define __MCLASSES_HH
00022 
00023 
00024 
00025 template <int Rows, int Cols, class Layout>
00026 class Matrix : public FixedMatrix<Rows, Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> > {
00027   public:
00028   inline Matrix(){}
00029 
00030   // construction from 1 and 2 dimensional c-style arrays
00031   inline Matrix(const double d[Rows*Cols]){*this = (reinterpret_cast<const FixedMatrix<Rows,Cols,FixedMAccessor<Rows,Cols,RowMajor,Stack<Rows*Cols> > >&>(*d));}
00032   inline Matrix(const double d[Rows][Cols]){*this = (reinterpret_cast<const FixedMatrix<Rows,Cols,FixedMAccessor<Rows,Cols,RowMajor,Stack<Rows*Cols> > >&>(*d));}
00033 
00034   // construction from a fixed Matrix
00035   template <class Accessor>
00036   inline Matrix(const FixedMatrix<Rows,Cols,Accessor>& m){
00037     FixedMatrix<Rows,Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> >::operator=(m);
00038   }
00039 
00040   // construction from a dynamic Matrix
00041   template <class Accessor>
00042   inline Matrix(const DynamicMatrix<Accessor>& m){
00043     assert(m.num_rows()==Rows && m.num_cols() == Cols);
00044     FixedMatrix<Rows,Cols, FixedMAccessor<Rows, Cols, Layout, typename SizeTraits<Rows*Cols>::get_zone> >::operator=(m);
00045   }
00046 
00047   // constructor from 1-ary operator
00048   template <class Arg, class Op>
00049   Matrix(const Arg& arg, const Operator<Op>&){Op::eval(*this,arg);}
00050 
00051   // constructor from 2-ary operator
00052   template <class LHS, class RHS, class Op>
00053   Matrix(const LHS& lhs, const RHS& rhs, const Operator<Op>&){Op::eval(*this,lhs,rhs);}
00054 
00055 
00056 
00057 };
00058 
00059 template <class Layout>
00060 class Matrix<General, General, Layout> : public DynamicMatrix<DynamicMAccessor<Layout> > {
00061   friend class MSizer;
00062  public:
00063   inline Matrix(){
00064     this->my_num_rows = 0;
00065     this->my_num_cols = 0;
00066     this->my_values = NULL;
00067   }
00068 
00069   inline Matrix(int num_rows, int num_cols){
00070     this->my_num_rows = num_rows;
00071     this->my_num_cols = num_cols;
00072     this->my_values = new double[num_rows*num_cols];
00073   }
00074 
00075   inline ~Matrix(){
00076     delete[] this->my_values;}
00077 
00078   // construction from a double*
00079   inline Matrix(int num_rows, int num_cols, const double* data){
00080     this->my_num_rows=num_rows;
00081     this->my_num_cols = num_cols;
00082     this->my_values = new double[num_rows*num_cols];
00083     RefMatrix<RowMajor> temp (num_rows,num_cols,data);
00084     DynamicMatrix<DynamicMAccessor<Layout> >::operator=(temp);
00085   }
00086 
00087   // construction from a general Matrix
00088   template <class Accessor>
00089   inline Matrix(const MatrixBase<Accessor>& from){
00090     this->my_num_rows = from.num_rows();
00091     this->my_num_cols = from.num_cols();
00092     this->my_values = new double [this->my_num_rows*this->my_num_cols];
00093     DynamicMatrix<DynamicMAccessor<Layout> >::operator=(from);
00094   }
00095 
00096   inline void resize(int rows, int cols)
00097   {
00098         if(rows != this->my_num_rows || cols != this->my_num_cols)
00099         {
00100                 delete[] this->my_values;
00101                 this->my_num_rows = rows;
00102                 this->my_num_cols = cols;
00103                 this->my_values = new double[this->my_num_rows*this->my_num_cols];
00104         }
00105   }
00106     
00107     template <class Accessor> inline void assign(const MatrixBase<Accessor>& m) {
00108         resize(m.num_rows(),m.num_cols());
00109         DynamicMatrix<DynamicMAccessor<Layout> >::operator=(m); 
00110     }
00111     
00112   // copy construction
00113   inline Matrix(const Matrix<General,General,Layout>& from){
00114     this->my_num_rows = from.my_num_rows;
00115     this->my_num_cols = from.my_num_cols;
00116     this->my_values = new double[this->my_num_rows*this->my_num_cols];
00117     DynamicMatrix<DynamicMAccessor<Layout> >::operator=(from);
00118   }
00119 
00120   // constructor from 1-ary operator
00121   template <class Arg, class Op>
00122   Matrix(const Arg& arg, const Operator<Op>&){
00123     Op::eval(*this,arg);
00124   }
00125 
00126   // constructor from 2-ary operator
00127   template <class LHS, class RHS, class Op>
00128   Matrix(const LHS& lhs, const RHS& rhs, const Operator<Op>&){
00129     Op::eval(*this,lhs,rhs);
00130   }
00131 };
00132 
00133 
00134 
00135 struct MSizer {
00136   template<class Layout>
00137   static inline void set_size(Matrix<General,General,Layout>& ret, int rows, int cols){
00138     ret.my_num_rows=rows;
00139     ret.my_num_cols=cols;
00140     ret.my_values = new double[rows*cols];
00141   }
00142 };
00143 
00144 
00145 #endif

Generated on Fri Feb 22 18:26:54 2008 for QVision by  doxygen 1.5.3