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.
Lapack_Cholesky.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 // Copyright (C) 2009 Tom Drummond (twd20@cam.ac.uk)
4 //
5 // This file is part of the TooN Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20 
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29 
30 
31 #ifndef TOON_INCLUDE_LAPACK_CHOLESKY_H
32 #define TOON_INCLUDE_LAPACK_CHOLESKY_H
33 
34 #include "TooN.h"
35 
36 #include "lapack.h"
37 
38 #include <assert.h>
39 
40 namespace TooN {
41 
42 
71 template <int Size, typename Precision=DefaultPrecision>
73 public:
74 
76 
77  template<class P2, class B2>
80  SizeMismatch<Size,Size>::test(m.num_rows(), m.num_cols());
81  do_compute();
82  }
83 
85  Lapack_Cholesky(int size) : my_cholesky(size,size), my_cholesky_lapack(size,size) {}
86 
87  template<class P2, class B2> void compute(const Matrix<Size, Size, P2, B2>& m){
88  SizeMismatch<Size,Size>::test(m.num_rows(), m.num_cols());
89  SizeMismatch<Size,Size>::test(m.num_rows(), my_cholesky.num_rows());
91  do_compute();
92  }
93 
94 
95 
96  void do_compute(){
97  int N = my_cholesky.num_rows();
98  int info;
99  potrf_("L", &N, my_cholesky_lapack.my_data, &N, &info);
100  for (int i=0;i<N;i++) {
101  int j;
102  for (j=0;j<=i;j++) {
103  my_cholesky[i][j]=my_cholesky_lapack[j][i];
104  }
105  // LAPACK does not set upper triangle to zero,
106  // must be done here
107  for (;j<N;j++) {
108  my_cholesky[i][j]=0;
109  }
110  }
111  assert(info >= 0);
112  if (info > 0) {
113  my_rank = info-1;
114  }
115  }
116 
117  int rank() const { return my_rank; }
118 
119  template <int Size2, typename P2, typename B2>
121  SizeMismatch<Size,Size2>::test(my_cholesky.num_cols(), v.size());
122 
123  Vector<Size> result(v);
124  int N=my_cholesky.num_rows();
125  int NRHS=1;
126  int info;
127  potrs_("L", &N, &NRHS, my_cholesky_lapack.my_data, &N, result.my_data, &N, &info);
128  assert(info==0);
129  return result;
130  }
131 
132  template <int Size2, int Cols2, typename P2, typename B2>
134  SizeMismatch<Size,Size2>::test(my_cholesky.num_cols(), m.num_rows());
135 
137  int N=my_cholesky.num_rows();
138  int NRHS=m.num_cols();
139  int info;
140  potrs_("L", &N, &NRHS, my_cholesky_lapack.my_data, &N, result.my_data, &N, &info);
141  assert(info==0);
142  return result;
143  }
144 
145  template <int Size2, typename P2, typename B2>
146  Precision mahalanobis(const Vector<Size2, P2, B2>& v) const {
147  return v * backsub(v);
148  }
149 
151  return my_cholesky;
152  }
153 
154  Precision determinant() const {
155  Precision det = my_cholesky[0][0];
156  for (int i=1; i<my_cholesky.num_rows(); i++)
157  det *= my_cholesky[i][i];
158  return det*det;
159  }
160 
162  Matrix<Size> M(my_cholesky.num_rows(),my_cholesky.num_rows());
164  int N = my_cholesky.num_rows();
165  int info;
166  potri_("L", &N, M.my_data, &N, &info);
167  assert(info == 0);
168  for (int i=1;i<N;i++) {
169  for (int j=0;j<i;j++) {
170  M[i][j]=M[j][i];
171  }
172  }
173  return M;
174  }
175 
176 private:
179  int my_rank;
180 };
181 
182 
183 }
184 
185 #endif
Precision determinant() const
void potrf_(const char *UPLO, const int *N, double *A, const int *LDA, int *INFO)
Definition: lapack.h:117
void compute(const Matrix< Size, Size, P2, B2 > &m)
Lapack_Cholesky(const Matrix< Size, Size, P2, B2 > &m)
Everything lives inside this namespace.
Definition: allocator.hh:48
static void test(int s1, int s2)
void potri_(const char *UPLO, const int *N, double *A, const int *LDA, int *INFO)
Definition: lapack.h:148
Matrix< Size, Cols2, Precision, ColMajor > backsub(const Matrix< Size2, Cols2, P2, B2 > &m) const
void potrs_(const char *UPLO, const int *N, const int *NRHS, const double *A, const int *LDA, double *B, const int *LDB, int *INFO)
Definition: lapack.h:139
Vector< Size, Precision > backsub(const Vector< Size2, P2, B2 > &v) const
Precision mahalanobis(const Vector< Size2, P2, B2 > &v) const
Matrix< Size, Size, Precision > my_cholesky
Lapack_Cholesky(int size)
Constructor for Size=Dynamic.
Matrix< Size, Size, Precision > get_L() const
Matrix< Size, Size, Precision > my_cholesky_lapack
Matrix get_inverse() const