SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
matrix.hh
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 // Copyright (C) 2009 Tom Drummond (twd20@cam.ac.uk),
4 // Ed Rosten (er258@cam.ac.uk)
5 //
6 // This file is part of the TooN Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21 
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30 
31 namespace TooN {
32 
109 template <int Rows=-1, int Cols=Rows, class Precision=DefaultPrecision, class Layout = RowMajor>
110 struct Matrix : public Layout::template MLayout<Rows, Cols, Precision>
111 {
112 public:
113 
114  using Layout::template MLayout<Rows, Cols, Precision>::my_data;
115  using Layout::template MLayout<Rows, Cols, Precision>::num_rows;
116  using Layout::template MLayout<Rows, Cols, Precision>::num_cols;
117 
118  //Use Tom's sneaky constructor hack...
119 
122 
124  Matrix(){}
125 
127  Matrix(int rows, int cols) :
128  Layout::template MLayout<Rows,Cols,Precision>(rows, cols)
129  {}
130 
132  Matrix(Precision* p) :
133  Layout::template MLayout<Rows, Cols, Precision>(p)
134  {}
135 
137  Matrix(Precision* p, int r, int c) :
138  Layout::template MLayout<Rows, Cols, Precision>(p, r, c)
139  {}
140 
143  Matrix(Precision* data, int rows, int cols, int rowstride, int colstride, Internal::Slicing)
144  :Layout::template MLayout<Rows, Cols, Precision>(data, rows, cols, rowstride, colstride){}
145 
146 
147  //See vector.hh and allocator.hh for details about why the
148  //copy constructor should be default.
150  template <class Op>
151  inline Matrix(const Operator<Op>& op)
152  :Layout::template MLayout<Rows,Cols,Precision>(op)
153  {
154  op.eval(*this);
155  }
156 
158  template<int Rows2, int Cols2, typename Precision2, typename Base2>
160  :Layout::template MLayout<Rows,Cols,Precision>(from.num_rows(), from.num_cols())
161  {
162  operator=(from);
163  }
165 
169  inline Matrix& operator= (const Matrix& from)
170  {
171  SizeMismatch<Rows, Rows>::test(num_rows(), from.num_rows());
172  SizeMismatch<Cols, Cols>::test(num_cols(), from.num_cols());
173 
174  for(int r=0; r < num_rows(); r++)
175  for(int c=0; c < num_cols(); c++)
176  (*this)[r][c] = from[r][c];
177 
178  return *this;
179  }
180 
181  // operator = 0-ary operator
182  template<class Op> inline Matrix& operator= (const Operator<Op>& op)
183  {
184  op.eval(*this);
185  return *this;
186  }
187 
188  // operator =
189  template<int Rows2, int Cols2, typename Precision2, typename Base2>
191  {
192  SizeMismatch<Rows, Rows2>::test(num_rows(), from.num_rows());
193  SizeMismatch<Cols, Cols2>::test(num_cols(), from.num_cols());
194 
195  for(int r=0; r < num_rows(); r++)
196  for(int c=0; c < num_cols(); c++)
197  (*this)[r][c] = from[r][c];
198 
199  return *this;
200  }
202 
205 
206  Matrix& operator*=(const Precision& rhs)
207  {
208  for(int r=0; r < num_rows(); r++)
209  for(int c=0; c < num_cols(); c++)
210  (*this)[r][c] *= rhs;
211 
212  return *this;
213  }
214 
215  Matrix& operator/=(const Precision& rhs)
216  {
217  for(int r=0; r < num_rows(); r++)
218  for(int c=0; c < num_cols(); c++)
219  (*this)[r][c] /= rhs;
220 
221  return *this;
222  }
223 
224  template<int Rows2, int Cols2, typename Precision2, typename Base2>
226  {
227  SizeMismatch<Rows, Rows2>::test(num_rows(), from.num_rows());
228  SizeMismatch<Cols, Cols2>::test(num_cols(), from.num_cols());
229 
230  for(int r=0; r < num_rows(); r++)
231  for(int c=0; c < num_cols(); c++)
232  (*this)[r][c] += from[r][c];
233 
234  return *this;
235  }
236 
237  template<class Op>
239  {
240  op.plusequals(*this);
241  return *this;
242  }
243 
244  template<class Op>
246  {
247  op.minusequals(*this);
248  return *this;
249  }
250 
251  template<int Rows2, int Cols2, typename Precision2, typename Base2>
253  {
254  SizeMismatch<Rows, Rows2>::test(num_rows(), from.num_rows());
255  SizeMismatch<Cols, Cols2>::test(num_cols(), from.num_cols());
256 
257  for(int r=0; r < num_rows(); r++)
258  for(int c=0; c < num_cols(); c++)
259  (*this)[r][c] -= from[r][c];
260 
261  return *this;
262  }
263 
264  template<int Rows2, int Cols2, typename Precision2, typename Base2>
266  {
267  SizeMismatch<Rows, Rows2>::test(num_rows(), rhs.num_rows());
268  SizeMismatch<Cols, Cols2>::test(num_cols(), rhs.num_cols());
269 
270  for(int r=0; r < num_rows(); r++)
271  for(int c=0; c < num_cols(); c++)
272  if((*this)[r][c] != rhs[r][c])
273  return 0;
274  return 1;
275  }
276 
277  template<int Rows2, int Cols2, typename Precision2, typename Base2>
279  {
280  SizeMismatch<Rows, Rows2>::test(num_rows(), rhs.num_rows());
281  SizeMismatch<Cols, Cols2>::test(num_cols(), rhs.num_cols());
282 
283  for(int r=0; r < num_rows(); r++)
284  for(int c=0; c < num_cols(); c++)
285  if((*this)[r][c] != rhs[r][c])
286  return 1;
287  return 0;
288  }
289 
291 
294 
297  {
298  return *this;
299  }
301 
302  #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
303 
315  const double& operator() (int r, int c) const;
316 
323  const double& operator[](const std::pair<int,int>& row_col) const;
327  double& operator[](const std::pair<int,int>& row_col);
328 
342  double& operator() (int r, int c);
343 
360  const Vector& operator[] (int r) const;
361 
380  Vector& operator[] (int r);
381 
385  int num_rows() const;
386 
390  int num_cols() const;
391 
393 
394 
409  const Matrix<Cols, Rows>& T() const;
410 
430  Matrix<Cols, Rows>& T();
431 
445  template<Rstart, Cstart, Rsize, Csize>
446  const Matrix<Rsize, Csize>& slice() const;
447 
461  template<Rstart, Cstart, Rsize, Csize>
462  Matrix<Rsize, Csize>& slice();
463 
476  const Matrix<>& slice(int rstart, int cstart, int rsize, int csize) const;
477 
489  Matrix<>& slice(int rstart, int cstart, int rsize, int csize);
490 
492 
493 
494  #endif
495 };
496 
497 }
Matrix & operator=(const Matrix &from)
Definition: matrix.hh:169
Matrix & ref()
return me as a non const reference - useful for temporaries
Definition: matrix.hh:296
Matrix & operator*=(const Precision &rhs)
Definition: matrix.hh:206
Everything lives inside this namespace.
Definition: allocator.hh:48
bool operator==(const Matrix< Rows2, Cols2, Precision2, Base2 > &rhs) const
Definition: matrix.hh:265
static void test(int s1, int s2)
bool operator!=(const Matrix< Rows2, Cols2, Precision2, Base2 > &rhs) const
Definition: matrix.hh:278
Matrix()
Construction of static matrices. Values are not initialized.
Definition: matrix.hh:124
double DefaultPrecision
All TooN classes default to using this precision for computations and storage.
Definition: TooN.h:301
Matrix(int rows, int cols)
Construction of dynamic matrices. Values are not initialized.
Definition: matrix.hh:127
Matrix & operator/=(const Precision &rhs)
Definition: matrix.hh:215
Matrix & operator-=(const Operator< Op > &op)
Definition: matrix.hh:245
Matrix & operator+=(const Matrix< Rows2, Cols2, Precision2, Base2 > &from)
Definition: matrix.hh:225
Matrix(Precision *data, int rows, int cols, int rowstride, int colstride, Internal::Slicing)
Definition: matrix.hh:143
Matrix & operator+=(const Operator< Op > &op)
Definition: matrix.hh:238
Matrix(const Operator< Op > &op)
Construction from an operator.
Definition: matrix.hh:151
Matrix(const Matrix< Rows2, Cols2, Precision2, Base2 > &from)
constructor from arbitrary matrix
Definition: matrix.hh:159
Matrix(Precision *p, int r, int c)
Construction of dynamically sized slice matrices.
Definition: matrix.hh:137
Matrix(Precision *p)
Construction of statically sized slice matrices.
Definition: matrix.hh:132