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.
QR_Lapack.h
Go to the documentation of this file.
1 #ifndef TOON_INCLUDE_QR_LAPACK_H
2 #define TOON_INCLUDE_QR_LAPACK_H
3 
4 
5 #include "TooN.h"
6 #include "lapack.h"
7 #include <utility>
8 
9 namespace TooN{
10 
30 template<int Rows=Dynamic, int Cols=Rows, class Precision=double>
31 class QR_Lapack{
32 
33  private:
34  static const int square_Size = (Rows>=0 && Cols>=0)?(Rows<Cols?Rows:Cols):Dynamic;
35 
36  public:
41  template<int R, int C, class P, class B>
42  QR_Lapack(const Matrix<R,C,P,B>& m, bool p=0)
44  {
45  //pivot is set to all zeros, which means all columns are free columns
46  //and can take part in column pivoting.
47 
48  compute();
49  }
50 
53  {
54  return copy;
55  }
56 
59  {
60  return Q;
61  }
62 
66  {
67  return pivot;
68  }
69 
70  private:
71 
72  void compute()
73  {
74  int M = copy.num_rows();
75  int N = copy.num_cols();
76 
77  int LWORK=-1;
78  int INFO;
79  int lda = M;
80 
81  Precision size;
82 
83  //Set up the pivot vector
84  if(do_pivoting)
85  pivot = Zeros;
86  else
87  for(int i=0; i < pivot.size(); i++)
88  pivot[i] = i+1;
89 
90 
91  //Compute the working space
92  geqp3_(&M, &N, copy.get_data_ptr(), &lda, pivot.get_data_ptr(), tau.get_data_ptr(), &size, &LWORK, &INFO);
93 
94  LWORK = (int) size;
95 
96  Precision* work = new Precision[LWORK];
97 
98  geqp3_(&M, &N, copy.get_data_ptr(), &lda, pivot.get_data_ptr(), tau.get_data_ptr(), work, &LWORK, &INFO);
99 
100 
101  if(INFO < 0)
102  std::cerr << "error in QR, INFO was " << INFO << std::endl;
103 
104  //The upper "triangle+" of copy is R
105  //The lower right and tau contain enough information to reconstruct Q
106 
107  //LAPACK provides a handy function to do the reconstruction
108  Q = copy.template slice<0,0,square_Size, square_Size>(0,0,square_size(), square_size());
109 
110  int K = square_size();
111  M=K;
112  N=K;
113  lda = K;
114  orgqr_(&M, &N, &K, Q.get_data_ptr(), &lda, tau.get_data_ptr(), work, &LWORK, &INFO);
115 
116  if(INFO < 0)
117  std::cerr << "error in QR, INFO was " << INFO << std::endl;
118 
119  delete [] work;
120 
121  //Now zero out the lower triangle
122  for(int r=1; r < square_size(); r++)
123  for(int c=0; c<r; c++)
124  copy[r][c] = 0;
125 
126  //Now fix the pivot matrix.
127  //We need to go from FORTRAN to C numbering.
128  for(int i=0; i < pivot.size(); i++)
129  pivot[i]--;
130  }
131 
137 
138 
140  {
141  return std::min(copy.num_rows(), copy.num_cols());
142  }
143 };
144 
145 }
146 
147 
148 #endif
Vector< Cols, int > pivot
Definition: QR_Lapack.h:136
static const int square_Size
Definition: QR_Lapack.h:34
Everything lives inside this namespace.
Definition: allocator.hh:48
void orgqr_(int *M, int *N, int *K, float *A, int *LDA, float *TAU, float *WORK, int *LWORK, int *INFO)
Definition: lapack.h:174
static const int Dynamic
Template size value used to indicate dynamically sized vectors and matrices.
Definition: TooN.h:272
Matrix< square_Size, square_Size, Precision, ColMajor > Q
Definition: QR_Lapack.h:134
Matrix< Rows, Cols, Precision, ColMajor > copy
Definition: QR_Lapack.h:132
const Matrix< square_Size, square_Size, Precision, ColMajor > & get_Q()
Return Q.
Definition: QR_Lapack.h:58
QR_Lapack(const Matrix< R, C, P, B > &m, bool p=0)
Definition: QR_Lapack.h:42
void compute()
Definition: QR_Lapack.h:72
const Vector< Cols, int > & get_P()
Definition: QR_Lapack.h:65
const Matrix< Rows, Cols, Precision, ColMajor > & get_R()
Return R.
Definition: QR_Lapack.h:52
int square_size()
Definition: QR_Lapack.h:139
static Operator< Internal::Zero > Zeros
Definition: objects.h:727
Vector< square_Size, Precision > tau
Definition: QR_Lapack.h:133
void geqp3_(int *M, int *N, float *A, int *LDA, int *JPVT, float *TAU, float *WORK, int *LWORK, int *INFO)
Definition: lapack.h:164