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.
vbase.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 
33 namespace Internal{
34 template<int Size, class Precision, int Stride, class Mem> struct GenericVBase;
35 
37 //
38 // Slice holding class
39 //
40 struct Default{};
41 
42 template<int Stride, class Ptr=Default, class CPtr=Default, class Ref=Default, class CRef=Default>
43 struct SliceVBase {
44 
45  // this class is really just a typedef
46  template<int Size, typename Precision>
47  struct VLayout
48  : public GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> > {
50 
51  VLayout(PointerType d, int length, int stride)
52  :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> >(d, length, stride){
53  }
54 
55  template<class Op>
56  VLayout(const Operator<Op>& op)
57  :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(op) {}
58  };
59 
60 };
61 
62 template<int Stride>
64 
65  // this class is really just a typedef
66  template<int Size, typename Precision>
67  struct VLayout
68  : public GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> > {
69 
71 
72  VLayout(PointerType d, int length, int stride)
73  :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(d, length, stride){
74  }
75 
76  template<class Op>
77  VLayout(const Operator<Op>& op)
78  :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(op) {}
79  };
80 
81 };
82 
84 //
85 // Classes for Vectors owning memory
86 //
87 
88 struct VBase {
89 
90  // this class is really just a typedef
91  template<int Size, class Precision>
92  struct VLayout
93  : public GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> > {
94 
95  VLayout(){}
96 
97  VLayout(int s)
98  :GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> >(s)
99  {}
100 
101  template<class Op>
103  :GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> >(op) {}
104  };
105 };
106 
108 //
109 // Generic implementation
110 //
111 
112 template<int Size, typename Precision, int Stride, typename Mem> struct GenericVBase: public Mem, public StrideHolder<Stride>
113 {
114  int stride() const{
116  }
117 
118  //Optional constuctors
120 
122  :Mem(s)
123  {}
124 
125  typedef typename Mem::PointerType PointerType;
126  typedef typename Mem::ConstPointerType ConstPointerType;
127  typedef typename Mem::ReferenceType ReferenceType;
128  typedef typename Mem::ConstReferenceType ConstReferenceType;
129 
130  GenericVBase(PointerType d, int length, int stride)
131  :Mem(d, length),StrideHolder<Stride>(stride){
132  }
133 
134  template<class Op>
135  GenericVBase(const Operator<Op> & op) : Mem(op), StrideHolder<Stride>(op) {}
136 
137  using Mem::data;
138  using Mem::size;
139 
140  ReferenceType operator[](int i) {
141  Internal::check_index(size(), i);
142  return data()[i * stride()];
143  }
144 
145  ConstReferenceType operator[](int i) const {
146  Internal::check_index(size(), i);
147  return data()[i * stride()];
148  }
149 
152 
153 
154  //Completely generic Vector slice operations below:
155  template<int Start, int Length>
157  Internal::CheckSlice<Size, Start, Length>::check(size(), start, length);
158  return Vector<Length, Precision, SliceBase>(data() + stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length, stride(), Slicing());
159  }
160 
161  template<int Start, int Length>
162  const Vector<Length, const Precision, ConstSliceBase> slice(int start, int length) const{
163  Internal::CheckSlice<Size, Start, Length>::check(size(), start, length);
164  return Vector<Length, const Precision, ConstSliceBase>(data() + stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length, stride(), Slicing());
165  }
166 
167 
168 
169  //Special case slice operations
170  template<int Start, int Length> Vector<Length, Precision, SliceBase> slice(){
172  return slice<Start, Length>(Start, Length);
173  }
174 
175  template<int Start, int Length> const Vector<Length, const Precision, ConstSliceBase> slice() const {
177  return slice<Start, Length>(Start, Length);
178  }
179 
181  return slice<Dynamic, Dynamic>(start, length);
182  }
183 
184  const Vector<Dynamic, const Precision, ConstSliceBase> slice(int start, int length) const{
185  return slice<Dynamic, Dynamic>(start, length);
186  }
187 
188  //Other slices below
190  return Matrix<1, Size, const Precision, Slice<1,Stride> >(data(), 1, size(), 1, stride(), Slicing());
191  }
192 
194  return Matrix<1, Size, Precision, Slice<1,Stride> >(data(), 1, size(), 1, stride(), Slicing());
195  }
196 
198  return Matrix<Size, 1, const Precision, Slice<Stride,1> >(data(), size(), 1, stride(), 1, Slicing());
199  }
200 
202  return Matrix<Size, 1, Precision, Slice<Stride,1> >(data(), size(), 1, stride(), 1, Slicing());
203  }
204 
206 
208  return Vector<Size, Precision, SliceBase>(data(), size(), stride(), Slicing());
209  }
210 
212  return Vector<Size, const Precision, ConstSliceBase>(data(), size(), stride(), Slicing());
213  }
214 
216  return DiagonalMatrix<Size, Precision, SliceBase> (data(), size(), stride(), Slicing());
217  }
218 
221  }
222 
223 };
224 
225 }
226 
227 }
VLayout(const Operator< Op > &op)
Definition: vbase.hh:102
Vector< Length, Precision, SliceBase > slice(int start, int length)
Definition: vbase.hh:156
SliceVBase< Stride, PointerType, ConstPointerType, ReferenceType, ConstReferenceType > SliceBase
Definition: vbase.hh:150
Matrix< 1, Size, Precision, Slice< 1, Stride > > as_row()
Definition: vbase.hh:193
Vector< Length, Precision, SliceBase > slice()
Definition: vbase.hh:170
Vector< Dynamic, Precision, SliceBase > slice(int start, int length)
Definition: vbase.hh:180
ConstReferenceType operator[](int i) const
Definition: vbase.hh:145
const Vector< Size, const Precision, ConstSliceBase > as_slice() const
Definition: vbase.hh:211
const Matrix< 1, Size, const Precision, Slice< 1, Stride > > as_row() const
Definition: vbase.hh:189
VLayout(PointerType d, int length, int stride)
Definition: vbase.hh:51
Everything lives inside this namespace.
Definition: allocator.hh:48
VLayout(const Operator< Op > &op)
Definition: vbase.hh:56
static const int Dynamic
Template size value used to indicate dynamically sized vectors and matrices.
Definition: TooN.h:272
Vector< Size, Precision, SliceBase > as_slice()
Definition: vbase.hh:207
Vector< Size, Precision, SliceBase > as_slice_type
Definition: vbase.hh:205
VectorSlice< Size, Precision, Ptr, CPtr, Ref, CRef >::PointerType PointerType
Definition: vbase.hh:49
Matrix< Size, 1, Precision, Slice< Stride, 1 > > as_col()
Definition: vbase.hh:201
const DiagonalMatrix< Size, const Precision, ConstSliceBase > as_diagonal() const
Definition: vbase.hh:219
GenericVBase(const Operator< Op > &op)
Definition: vbase.hh:135
const Vector< Length, const Precision, ConstSliceBase > slice(int start, int length) const
Definition: vbase.hh:162
Mem::PointerType PointerType
Definition: vbase.hh:125
const Vector< Dynamic, const Precision, ConstSliceBase > slice(int start, int length) const
Definition: vbase.hh:184
static void check_index(int, int)
Definition: debug.hh:28
const Matrix< Size, 1, const Precision, Slice< Stride, 1 > > as_col() const
Definition: vbase.hh:197
ReferenceType operator[](int i)
Definition: vbase.hh:140
Mem::ConstReferenceType ConstReferenceType
Definition: vbase.hh:128
GenericVBase(PointerType d, int length, int stride)
Definition: vbase.hh:130
const Vector< Length, const Precision, ConstSliceBase > slice() const
Definition: vbase.hh:175
Mem::ReferenceType ReferenceType
Definition: vbase.hh:127
SliceVBase< Stride, ConstPointerType, ConstPointerType, ConstReferenceType, ConstReferenceType > ConstSliceBase
Definition: vbase.hh:151
Mem::ConstPointerType ConstPointerType
Definition: vbase.hh:126
DiagonalMatrix< Size, Precision, SliceBase > as_diagonal()
Definition: vbase.hh:215