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.
helpers.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 // Copyright (C) 2005,2009 Tom Drummond (twd20@cam.ac.uk),
4 // Ed Rosten (er258@cam.ac.uk), Gerhard Reitmayr (gr281@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 
32 #ifndef TOON_INCLUDE_HELPERS_H
33 #define TOON_INCLUDE_HELPERS_H
34 
35 #include "TooN.h"
36 #include <cmath>
37 #include <functional>
38 #include <utility>
39 
40 #ifndef M_PI
41 #define M_PI 3.14159265358979323846
42 #endif
43 
44 #ifndef M_SQRT1_2
45 #define M_SQRT1_2 0.707106781186547524401
46 #endif
47 
48 namespace TooN {
49 
52  template<int Size, class Precision, class Base> void Fill(Vector<Size, Precision, Base>& v, const Precision& p)
53  {
54  for(int i=0; i < v.size(); i++)
55  v[i]= p;
56  }
57 
60  template<int Rows, int Cols, class Precision, class Base> TOON_DEPRECATED void Fill(Matrix<Rows, Cols, Precision, Base>& m, const Precision& p)
61  {
62  for(int i=0; i < m.num_rows(); i++)
63  for(int j=0; j < m.num_cols(); j++)
64  m[i][j] = p;
65  }
66 
70  template<int Size, class Precision, class Base> inline Precision norm(const Vector<Size, Precision, Base>& v)
71  {
72  using std::sqrt;
73  return sqrt(v*v);
74  }
75 
79  template<int Size, class Precision, class Base> inline Precision norm_sq(const Vector<Size, Precision, Base>& v)
80  {
81  return v*v;
82  }
83 
87  template<int Size, class Precision, class Base> inline Precision norm_1(const Vector<Size, Precision, Base>& v)
88  {
89  using std::abs;
90  Precision n = 0;
91  for(int i=0; i < v.size(); i++)
92  n += abs(v[i]);
93  return n;
94  }
95 
99  template<int Size, class Precision, class Base> inline Precision norm_inf(const Vector<Size, Precision, Base>& v)
100  {
101  using std::abs;
102  using std::max;
103  Precision n = 0;
104  n = abs(v[0]);
105 
106  for(int i=1; i < v.size(); i++)
107  n = max(n, abs(v[i]));
108  return n;
109  }
110 
115  template<int Size, class Precision, class Base> inline Precision norm_2(const Vector<Size, Precision, Base>& v)
116  {
117  return norm(v);
118  }
119 
120 
121 
122 
126  template<int Size, class Precision, class Base> inline Vector<Size, Precision> unit(const Vector<Size, Precision, Base> & v)
127  {
128  using std::sqrt;
129  return TooN::operator*(v,(1/sqrt(v*v)));
130  }
131 
132  //Note because of the overload later, this function will ONLY receive sliced vectors. Therefore
133  //a copy can be made, which is still a slice, so operating on the copy operates on the original
134  //data.
138  template<int Size, class Precision, class Base> inline void normalize(Vector<Size, Precision, Base> v)
139  {
140  using std::sqrt;
141  v /= sqrt(v*v);
142  }
143 
144  //This overload is required to operate on non-slice vectors
148  template<int Size, class Precision> inline void normalize(Vector<Size, Precision> & v)
149  {
150  normalize(v.as_slice());
151  }
152 
153 
157  template<int Size, typename Precision, typename Base> inline Vector<(Size==Dynamic?Dynamic:Size-1), Precision> project( const Vector<Size, Precision, Base> & v){
158  static const int Len = (Size==Dynamic?Dynamic:Size-1);
159  return TooN::operator/(v.template slice<0, Len>(0, v.size()-1),v[v.size() - 1]);
160  }
161 
162  //This should probably be done with an operator to prevent an extra new[] for dynamic vectors.
166  template<int Size, typename Precision, typename Base> inline Vector<(Size==Dynamic?Dynamic:Size+1), Precision> unproject( const Vector<Size, Precision, Base> & v){
168  static const int Len = (Size==Dynamic?Dynamic:Size);
169  result.template slice<0, Len>(0, v.size()) = v;
170  result[v.size()] = 1;
171  return result;
172  }
173 
177  template<int R, int C, typename Precision, typename Base> inline Matrix<R-1, C, Precision> project( const Matrix<R,C, Precision, Base> & m){
178  Matrix<R-1, C, Precision> result = m.template slice(0,0,R-1,m.num_cols());
179  for( int c = 0; c < m.num_cols(); ++c ) {
180  result.slice(0,c,R-1,1) /= m[R-1][c];
181  }
182  return result;
183  }
184 
185  template<int C, typename Precision, typename Base> inline Matrix<-1, C, Precision> project( const Matrix<-1,C, Precision, Base> & m){
186  Matrix<-1, C, Precision> result = m.template slice(0,0,m.num_rows()-1,m.num_cols());
187  for( int c = 0; c < m.num_cols(); ++c ) {
188  result.slice(0,c,m.num_rows()-1,1) /= m[m.num_rows()-1][c];
189  }
190  return result;
191  }
192 
196  template<int R, int C, typename Precision, typename Base> inline Matrix<R+1, C, Precision> unproject( const Matrix<R, C, Precision, Base> & m){
198  result.template slice<0,0,R,C>() = m;
199  result[R] = Ones;
200  return result;
201  }
202 
203  template<int C, typename Precision, typename Base> inline Matrix<-1, C, Precision> unproject( const Matrix<-1, C, Precision, Base> & m){
204  Matrix<-1, C, Precision> result( m.num_rows()+1, m.num_cols() );
205  result.template slice(0,0,m.num_rows(),m.num_cols()) = m;
206  result[m.num_rows()] = Ones;
207  return result;
208  }
209 
213  template <int R, int C, typename P, typename B>
214  P inline norm_fro( const Matrix<R,C,P,B> & m ){
215  using std::sqrt;
216  P n = 0;
217  for(int r = 0; r < m.num_rows(); ++r)
218  for(int c = 0; c < m.num_cols(); ++c)
219  n += m[r][c] * m[r][c];
220 
221  return sqrt(n);
222  }
223 
227  template <int R, int C, typename P, typename B>
228  P inline norm_inf( const Matrix<R,C,P,B> & m ){
229  using std::abs;
230  using std::max;
231  P n = 0;
232  for(int r = 0; r < m.num_rows(); ++r){
233  P s = 0;
234  for(int c = 0; c < m.num_cols(); ++c)
235  s += abs(m(r,c));
236  n = max(n,s);
237  }
238  return n;
239  }
240 
244  template <int R, int C, typename P, typename B>
245  P inline norm_1( const Matrix<R,C,P,B> & m ){
246  using std::abs;
247  using std::max;
248  P n = 0;
249  for(int c = 0; c < m.num_cols(); ++c){
250  P s = 0;
251  for(int r = 0; r < m.num_rows(); ++r)
252  s += abs(m(r,c));
253  n = max(n,s);
254  }
255  return n;
256  }
257 
258  namespace Internal {
262  template <int R, int C, typename P, typename B>
264  TooN::SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
265  Matrix<R,C,P> result = TooN::Zeros(m.num_rows(), m.num_cols());
266  Matrix<R,C,P> f = TooN::Identity(m.num_rows());
267  P k = 1;
268  while(norm_inf((result+f)-result) > 0){
269  result += f;
270  f = (m * f) / k;
271  k += 1;
272  }
273  return result;
274  }
275  };
276 
283  template <int R, int C, typename P, typename B>
284  inline Matrix<R, C, P> exp( const Matrix<R,C,P,B> & m ){
285  using std::max;
286  SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
287  const P l = log2(norm_inf(m));
288  const int s = max(0,(int)ceil(l));
289  Matrix<R,C,P> result = Internal::exp_taylor(m/(1<<s));
290  for(int i = 0; i < s; ++i)
291  result = result * result;
292  return result;
293  }
294 
297  template<int S, class P, class B> bool isfinite(const Vector<S, P, B>& v)
298  {
299  using std::isfinite;
300  for(int i=0; i < v.size(); i++)
301  if(!isfinite(v[i]))
302  return 0;
303  return 1;
304  }
305 
308  template<int S, class P, class B> bool isnan(const Vector<S, P, B>& v)
309  {
310  using std::isnan;
311  for(int i=0; i < v.size(); i++)
312  if(isnan(v[i]))
313  return 1;
314  return 0;
315  }
316 
321  template<int Rows, int Cols, typename Precision, typename Base>
323  SizeMismatch<Rows,Cols>::test(m.num_rows(), m.num_cols());
324  for(int r=0; r<m.num_rows()-1; r++){
325  for(int c=r+1; c<m.num_cols(); c++){
326  const Precision temp=(m(r,c)+m(c,r))/2;
327  m(r,c)=temp;
328  m(c,r)=temp;
329  }
330  }
331  }
332 
335  template<int Rows, int Cols, typename Precision, typename Base>
337  SizeMismatch<Rows,Cols>::test(m.num_rows(), m.num_cols());
338  Precision tr = 0;
339  for(int i = 0; i < m.num_rows(); ++i)
340  tr += m(i,i);
341  return tr;
342  }
343 
348  template<int Size, class P, class B> inline TooN::Matrix<3, 3, P> cross_product_matrix(const Vector<Size, P, B>& vec)
349  {
350  SizeMismatch<Size,3>::test(vec.size(), 3);
351 
352  TooN::Matrix<3> result;
353 
354  result(0,0) = 0;
355  result(0,1) = -vec[2];
356  result(0,2) = vec[1];
357  result(1,0) = vec[2];
358  result(1,1) = 0;
359  result(1,2) = -vec[0];
360  result(2,0) = -vec[1];
361  result(2,1) = vec[0];
362  result(2,2) = 0;
363 
364  return result;
365  }
366 
367  namespace Internal {
368  template<int Size, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate( const Vector<Size, Precision, Base> & v ) {
369  Func func;
370  if( v.size() == 0 ) {
371  return func.null(); // What should we return, exception?
372  }
373  func.initialise( v[0], 0 );
374  for( int ii = 1; ii < v.size(); ii++ ) {
375  func( v[ii], ii );
376  }
377  return func.ret();
378  }
379 
380  template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate( const Matrix<R, C, Precision, Base> & m ) {
381  Func func;
382  if( m.num_rows() == 0 || m.num_cols() == 0) {
383  return func.null(); // What should we return, exception?
384  }
385  func.initialise( m[0][0], 0, 0 );
386  for(int r=0; r<m.num_rows(); r++){
387  for(int c=0; c<m.num_cols(); c++){
388  func( m[r][c], r, c );
389  }
390  }
391  return func.ret();
392  }
393  template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate_horizontal( const Matrix<R, C, Precision, Base> & m ) {
394  Func func( m.num_rows() );
395  if( m.num_cols() == 0 || m.num_rows() == 0 ) {
396  func.null(); // What should we return, exception?
397  }
398  for(int r=0; r<m.num_rows(); r++){
399  func.initialise( m[r][0], r, 0 );
400  for(int c=1; c<m.num_cols(); c++){
401  func( m[r][c], r, c );
402  }
403  }
404  return func.ret();
405  }
406  template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate_vertical( const Matrix<R, C, Precision, Base> & m ) {
407  Func func( m.num_cols() );
408  if( m.num_cols() == 0 || m.num_rows() == 0 ) {
409  func.null(); // What should we return, exception?
410  }
411  for(int c=0; c<m.num_cols(); c++){
412  func.initialise( m[0][c], 0, c );
413  for(int r=1; r<m.num_rows(); r++){
414  func( m[r][c], r, c );
415  }
416  }
417  return func.ret();
418  }
419 
420  template<typename Precision, typename ComparisonFunctor>
422  Precision bestVal;
423  public:
424  Precision null() {
425  return 0;
426  }
427  void initialise( Precision initialVal, int ) {
428  bestVal = initialVal;
429  }
430  void operator()( Precision curVal, int ) {
431  if( ComparisonFunctor()( curVal, bestVal ) ) {
432  bestVal = curVal;
433  }
434  }
435  Precision ret() { return bestVal; }
436  };
437  template<typename Precision, typename ComparisonFunctor>
439  Precision bestVal;
441  public:
442  std::pair<Precision,int> null() {
443  return std::pair<Precision,int>( 0, 0 );
444  }
445  void initialise( Precision initialVal, int nIndex ) {
446  bestVal = initialVal;
447  nBestIndex = nIndex;
448  }
449  void operator()( Precision curVal, int nIndex ) {
450  if( ComparisonFunctor()( curVal, bestVal ) ) {
451  bestVal = curVal;
452  nBestIndex = nIndex;
453  }
454  }
455  std::pair<Precision,int> ret() {
456  return std::pair<Precision,int>( bestVal, nBestIndex );
457  }
458  };
459  template<typename Precision, typename ComparisonFunctor>
461  Precision bestVal;
462  public:
463  Precision null() {
464  return 0;
465  }
466  void initialise( Precision initialVal, int, int ) {
467  bestVal = initialVal;
468  }
469  void operator()( Precision curVal, int, int ) {
470  if( ComparisonFunctor()( curVal, bestVal ) ) {
471  bestVal = curVal;
472  }
473  }
474  Precision ret() { return bestVal; }
475  };
476  template<typename Precision, typename ComparisonFunctor>
478  Precision bestVal;
479  int nBestRow;
480  int nBestCol;
481  public:
482  std::pair<Precision,std::pair<int,int> > null() {
483  return std::pair<Precision,std::pair<int,int> >( 0, std::pair<int,int>( 0, 0 ) );
484  }
485  void initialise( Precision initialVal, int nRow, int nCol ) {
486  bestVal = initialVal;
487  nBestRow = nRow;
488  nBestCol = nCol;
489  }
490  void operator()( Precision curVal, int nRow, int nCol ) {
491  if( ComparisonFunctor()( curVal, bestVal ) ) {
492  bestVal = curVal;
493  nBestRow = nRow;
494  nBestCol = nCol;
495  }
496  }
497  std::pair<Precision,std::pair<int,int> > ret() {
498  return std::pair<Precision,std::pair<int,int> >( bestVal,
499  std::pair<int,int>( nBestRow, nBestCol ) );
500  }
501  };
502  template<typename Precision, typename ComparisonFunctor>
505  public:
507  bestVal = NULL;
508  }
509  accumulate_vertical_functor( int nNumCols ) {
510  bestVal = new Vector<Dynamic,Precision>( nNumCols );
511  }
513  return Vector<Dynamic,Precision>( 0 );
514  }
515  void initialise( Precision initialVal, int, int nCol ) {
516  (*bestVal)[nCol] = initialVal;
517  }
518  void operator()( Precision curVal, int, int nCol ) {
519  if( ComparisonFunctor()( curVal, (*bestVal)[nCol] ) ) {
520  (*bestVal)[nCol] = curVal;
521  }
522  }
524  if( bestVal == NULL ) {
525  return null();
526  }
528  delete bestVal;
529  return vRet;
530  }
531  };
532  template<typename Precision, typename ComparisonFunctor>
536  public:
538  bestVal = NULL;
539  bestIndices = NULL;
540  }
542  bestVal = new Vector<Dynamic,Precision>( nNumCols );
543  bestIndices = new Vector<Dynamic,Precision>( nNumCols );
544  }
545  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > null() {
546  Vector<Dynamic,Precision> vEmpty( 0 );
547  return std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( vEmpty, vEmpty );
548  }
549  void initialise( Precision initialVal, int nRow, int nCol ) {
550  (*bestVal)[nCol] = initialVal;
551  (*bestIndices)[nCol] = nRow;
552  }
553  void operator()( Precision curVal, int nRow, int nCol ) {
554  if( ComparisonFunctor()( curVal, (*bestVal)[nCol] ) ) {
555  (*bestVal)[nCol] = curVal;
556  (*bestIndices)[nCol] = nRow;
557  }
558  }
559  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > ret() {
560  if( bestVal == NULL ) {
561  return null();
562  }
563  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > vRet =
564  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > (*bestVal, *bestIndices );
565  delete bestVal; bestVal = NULL;
566  delete bestIndices; bestIndices = NULL;
567  return vRet;
568  }
569  };
570  template<typename Precision, typename ComparisonFunctor>
573  public:
575  bestVal = NULL;
576  }
578  bestVal = new Vector<Dynamic,Precision>( nNumRows );
579  }
581  return Vector<Dynamic,Precision>( 0 );
582  }
583  void initialise( Precision initialVal, int nRow, int ) {
584  (*bestVal)[nRow] = initialVal;
585  }
586  void operator()( Precision curVal, int nRow, int ) {
587  if( ComparisonFunctor()( curVal, (*bestVal)[nRow] ) ) {
588  (*bestVal)[nRow] = curVal;
589  }
590  }
592  if( bestVal == NULL ) {
593  return null();
594  }
596  delete bestVal; bestVal = NULL;
597  return vRet;
598  }
599  };
600  template<typename Precision, typename ComparisonFunctor>
604  public:
606  bestVal = NULL;
607  bestIndices = NULL;
608  }
610  bestVal = new Vector<Dynamic,Precision>( nNumRows );
611  bestIndices = new Vector<Dynamic,Precision>( nNumRows );
612  }
613  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > null() {
614  Vector<Dynamic,Precision> vEmpty( 0 );
615  return std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( vEmpty, vEmpty );
616  }
617  void initialise( Precision initialVal, int nRow, int nCol ) {
618  (*bestVal)[nRow] = initialVal;
619  (*bestIndices)[nRow] = nCol;
620  }
621  void operator()( Precision curVal, int nRow, int nCol ) {
622  if( ComparisonFunctor()( curVal, (*bestVal)[nRow] ) ) {
623  (*bestVal)[nRow] = curVal;
624  (*bestIndices)[nRow] = nCol;
625  }
626  }
627  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > ret() {
628  if( bestVal == NULL ) {
629  return null();
630  }
631  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > vRet =
632  std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( *bestVal, *bestIndices );
633  delete bestVal; bestVal = NULL;
634  delete bestIndices; bestIndices = NULL;
635  return vRet;
636  }
637  };
638  }
639 
640 
644  template<int Size, typename Precision, typename Base> inline Precision min_value( const Vector<Size, Precision, Base>& v) {
646  return Internal::accumulate<Size,Precision,Base,
647  vector_accumulate_functor, Precision >( v );
648  }
652  template<int Size, typename Precision, typename Base> inline Precision max_value( const Vector<Size, Precision, Base>& v) {
654  return Internal::accumulate<Size,Precision,Base,
655  vector_accumulate_functor, Precision >( v );
656  }
657 
661  template<int R, int C, typename Precision, typename Base> inline Precision min_value( const Matrix<R, C, Precision, Base> & m) {
663  return Internal::accumulate<R,C,Precision,Base,
664  matrix_accumulate_functor, Precision>( m );
665  }
669  template<int R, int C, typename Precision, typename Base> inline Precision max_value( const Matrix<R, C, Precision, Base> & m) {
671  return Internal::accumulate<R,C,Precision,Base,
672  matrix_accumulate_functor, Precision>( m );
673  }
677  template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> min_value_vertical( const Matrix<R, C, Precision, Base> & m) {
678  typedef Internal::accumulate_vertical_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
679  return Internal::accumulate_vertical<R,C,Precision,Base,
680  matrix_accumulate_vertical_functor, Vector<Dynamic,Precision> >( m );
681  }
685  template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> max_value_vertical( const Matrix<R, C, Precision, Base> & m) {
686  typedef Internal::accumulate_vertical_functor<Precision,std::greater<Precision> > matrix_accumulate_vertical_functor;
687  return Internal::accumulate_vertical<R,C,Precision,Base,
688  matrix_accumulate_vertical_functor, Vector<Dynamic,Precision> >( m );
689  }
693  template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> min_value_horizontal( const Matrix<R, C, Precision, Base> & m) {
694  typedef Internal::accumulate_horizontal_functor<Precision,std::less<Precision> > matrix_accumulate_horizontal_functor;
695  return Internal::accumulate_horizontal<R,C,Precision,Base,
696  matrix_accumulate_horizontal_functor, Vector<Dynamic,Precision> >( m );
697  }
701  template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> max_value_horizontal( const Matrix<R, C, Precision, Base> & m) {
702  typedef Internal::accumulate_horizontal_functor<Precision,std::greater<Precision> > matrix_accumulate_horizontal_functor;
703  return Internal::accumulate_horizontal<R,C,Precision,Base,
704  matrix_accumulate_horizontal_functor, Vector<Dynamic,Precision> >( m );
705  }
709  template<int Size, typename Precision, typename Base> inline std::pair<Precision,int> min_element( const Vector<Size, Precision, Base>& v) {
711  return Internal::accumulate<Size,Precision,Base,
712  vector_accumulate_functor, std::pair<Precision,int> >( v );
713  }
717  template<int Size, typename Precision, typename Base> inline std::pair<Precision,int> max_element( const Vector<Size, Precision, Base>& v) {
719  return Internal::accumulate<Size,Precision,Base,
720  vector_accumulate_functor, std::pair<Precision,int> >( v );
721  }
726  template<int R, int C, typename Precision, typename Base> inline std::pair<Precision,std::pair<int,int> > min_element( const Matrix<R, C, Precision, Base> & m) {
728  typedef std::pair<Precision,std::pair<int,int> > Ret;
729  return Internal::accumulate<R,C,Precision,Base,
730  matrix_accumulate_functor, Ret>( m );
731  }
736  template<int R, int C, typename Precision, typename Base> inline std::pair<Precision,std::pair<int,int> > max_element( const Matrix<R, C, Precision, Base> & m) {
738  typedef std::pair<Precision,std::pair<int,int> > Ret;
739  return Internal::accumulate<R,C,Precision,Base,
740  matrix_accumulate_functor, Ret>( m );
741  }
747  template<int R, int C, typename Precision, typename Base> inline std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > min_element_vertical( const Matrix<R, C, Precision, Base> & m) {
748  typedef Internal::accumulate_element_vertical_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
749  typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
750  return Internal::accumulate_vertical<R,C,Precision,Base,
751  matrix_accumulate_vertical_functor, Ret >( m );
752  }
758  template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > max_element_vertical( const Matrix<R, C, Precision, Base> & m) {
759  typedef Internal::accumulate_element_vertical_functor<Precision,std::greater<Precision> > matrix_accumulate_vertical_functor;
760  typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
761  return Internal::accumulate_vertical<R,C,Precision,Base,
762  matrix_accumulate_vertical_functor, Ret >( m );
763  }
769  template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > min_element_horizontal( const Matrix<R, C, Precision, Base> & m) {
770  typedef Internal::accumulate_element_horizontal_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
771  typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
772  return Internal::accumulate_horizontal<R,C,Precision,Base,
773  matrix_accumulate_vertical_functor, Ret >( m );
774  }
780  template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > max_element_horizontal( const Matrix<R, C, Precision, Base> & m) {
782  typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
783  return Internal::accumulate_horizontal<R,C,Precision,Base,
784  matrix_accumulate_vertical_functor, Ret >( m );
785  }
786 }
787 #endif
std::pair< Precision, int > min_element(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:709
void normalize(Vector< Size, Precision, Base > v)
Definition: helpers.h:138
std::pair< Precision, int > ret()
Definition: helpers.h:455
void initialise(Precision initialVal, int nRow, int nCol)
Definition: helpers.h:485
Internal::MatrixStartFill< R, C, Precision, Base > Fill(Matrix< R, C, Precision, Base > &m)
Definition: comma.hh:130
Vector< Dynamic, Precision > ret()
Definition: helpers.h:591
TooN::Matrix< 3, 3, P > cross_product_matrix(const Vector< Size, P, B > &vec)
Definition: helpers.h:348
void Symmetrize(Matrix< Rows, Cols, Precision, Base > &m)
Definition: helpers.h:322
void initialise(Precision initialVal, int, int)
Definition: helpers.h:466
Precision norm_inf(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:99
void operator()(Precision curVal, int nIndex)
Definition: helpers.h:449
Operator< Op< typename Internal::DivideType< Pl, Pr >::type > > operator/(const Operator< Op< Pl > > &l, const Pr &r)
Definition: objects.h:675
Vector< Dynamic, Precision > max_value_vertical(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:685
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > null()
Definition: helpers.h:613
Vector< Dynamic, Precision > min_value_vertical(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:677
static Operator< Internal::Identity< Internal::One > > Identity
Definition: objects.h:748
std::pair< Precision, std::pair< int, int > > null()
Definition: helpers.h:482
Ret accumulate_vertical(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:406
Vector< Dynamic, Precision > * bestIndices
Definition: helpers.h:535
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > ret()
Definition: helpers.h:559
TooN::Vector< 2 > vec(const ImageRef &ir)
Everything lives inside this namespace.
Definition: allocator.hh:48
void operator()(Precision curVal, int nRow, int nCol)
Definition: helpers.h:621
Matrix< R, C, P > exp_taylor(const Matrix< R, C, P, B > &m)
Definition: helpers.h:263
static const int Dynamic
Template size value used to indicate dynamically sized vectors and matrices.
Definition: TooN.h:272
static void test(int s1, int s2)
Vector<(Size==Dynamic?Dynamic:Size+1), Precision > unproject(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:166
void operator()(Precision curVal, int, int nCol)
Definition: helpers.h:518
bool isfinite(const Vector< S, P, B > &v)
Definition: helpers.h:297
static const Operator< Internal::Scalars< Internal::One > > Ones
Definition: objects.h:713
Precision max_value(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:652
P norm_fro(const Matrix< R, C, P, B > &m)
Definition: helpers.h:214
void initialise(Precision initialVal, int nIndex)
Definition: helpers.h:445
void initialise(Precision initialVal, int nRow, int nCol)
Definition: helpers.h:617
void operator()(Precision curVal, int nRow, int nCol)
Definition: helpers.h:553
T abs(T t)
Definition: abs.h:30
Precision trace(const Matrix< Rows, Cols, Precision, Base > &m)
Definition: helpers.h:336
Precision norm(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:70
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > min_element_horizontal(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:769
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > null()
Definition: helpers.h:545
#define TOON_DEPRECATED
Definition: deprecated.hh:37
Ret accumulate_horizontal(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:393
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > max_element_horizontal(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:780
Matrix< R, C, P > exp(const Matrix< R, C, P, B > &m)
Definition: helpers.h:284
std::pair< Precision, int > null()
Definition: helpers.h:442
std::pair< Precision, int > max_element(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:717
void initialise(Precision initialVal, int nRow, int)
Definition: helpers.h:583
void initialise(Precision initialVal, int nRow, int nCol)
Definition: helpers.h:549
Vector< Dynamic, Precision > max_value_horizontal(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:701
void operator()(Precision curVal, int nRow, int)
Definition: helpers.h:586
Vector< Dynamic, Precision > null()
Definition: helpers.h:580
Vector< Dynamic, Precision > min_value_horizontal(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:693
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > ret()
Definition: helpers.h:627
Vector< Dynamic, Precision > * bestVal
Definition: helpers.h:602
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > max_element_vertical(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:758
Precision norm_sq(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:79
void initialise(Precision initialVal, int, int nCol)
Definition: helpers.h:515
Vector< Size, Precision > unit(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:126
Ret accumulate(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:368
void initialise(Precision initialVal, int)
Definition: helpers.h:427
Vector< Dynamic, Precision > * bestVal
Definition: helpers.h:504
Vector< Dynamic, Precision > * bestVal
Definition: helpers.h:572
std::pair< Vector< Dynamic, Precision >, Vector< Dynamic, Precision > > min_element_vertical(const Matrix< R, C, Precision, Base > &m)
Definition: helpers.h:747
Vector< Dynamic, Precision > null()
Definition: helpers.h:512
void operator()(Precision curVal, int, int)
Definition: helpers.h:469
Vector< Dynamic, Precision > * bestIndices
Definition: helpers.h:603
Precision min_value(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:644
void operator()(Precision curVal, int nRow, int nCol)
Definition: helpers.h:490
std::pair< Precision, std::pair< int, int > > ret()
Definition: helpers.h:497
void operator()(Precision curVal, int)
Definition: helpers.h:430
Vector< Internal::Sizer< S1, S2 >::size, typename Internal::MultiplyType< P1, P2 >::type > operator*(const DiagonalMatrix< S1, P1, B1 > &d, const Vector< S2, P2, B2 > &v)
Definition: diagmatrix.h:111
Vector< Dynamic, Precision > ret()
Definition: helpers.h:523
static Operator< Internal::Zero > Zeros
Definition: objects.h:727
Precision norm_2(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:115
Vector<(Size==Dynamic?Dynamic:Size-1), Precision > project(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:157
bool isnan(const Vector< S, P, B > &v)
Definition: helpers.h:308
Precision norm_1(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:87
Vector< Dynamic, Precision > * bestVal
Definition: helpers.h:534