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.
vector.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 
32 
33 namespace TooN {
34 
35 
127 template<int Size=Dynamic, typename Precision=DefaultPrecision, typename Base=Internal::VBase>
128 struct Vector : public Base::template VLayout<Size, Precision> {
129 protected:
130 public:
131  typedef typename Base::template VLayout<Size, Precision>::PointerType PointerType;
132  // sneaky hack: only one of these constructors will work with any given base
133  // class but they don't generate errors unless the user tries to use one of them
134  // although the error message may be less than helpful - maybe this can be changed?
135 
137 
138 
144  inline Vector(){}
145 
149  explicit inline Vector(int size_in) : Base::template VLayout<Size, Precision>(size_in) {}
150 
157  explicit inline Vector(PointerType data) : Base::template VLayout<Size, Precision> (data) {}
158 
159 
166  inline Vector(PointerType data, int size_in) : Base::template VLayout<Size, Precision> (data, size_in) {}
167 
169  inline Vector(PointerType data_in, int size_in, int stride_in, Internal::Slicing)
170  : Base::template VLayout<Size, Precision>(data_in, size_in, stride_in) {}
171 
172  using Base::template VLayout<Size, Precision>::size;
173 
179  template <class Op>
180  inline Vector(const Operator<Op>& op)
181  : Base::template VLayout<Size, Precision> (op)
182  {
183  op.eval(*this);
184  }
185 
186  // Copy construction is a very special case. Copy construction goes all the
187  // way down to the bottom. GenericVBase has no idea how to copy itself.
188  // However, the underlying allocator objects do. In the case of static sized
189  // objects, C++ automatically copies the data. For slice objects, C++ copies
190  // all parts (pointer and size), which is correct. For dynamically sized
191  // non-slice objects the copying has to be done by hand.
192 
193  // inline Vector(const Vector&from);
194 
196  template<int Size2, typename Precision2, typename Base2>
198  Base::template VLayout<Size, Precision>(from.size()) {
199  operator=(from);
200  }
201 
203 
204 #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
205 
208 
219  Precision& operator[] (int i);
220 
224  const Precision& operator[] (int i) const;
225 
227 
228 #endif
229 
232 
236  inline Vector& operator= (const Vector& from){
237  this->try_destructive_resize(from.size());
238  SizeMismatch<Size,Size>::test(size(), from.size());
239  const int s=size();
240  for(int i=0; i<s; i++){
241  (*this)[i]=from[i];
242  }
243  return *this;
244  }
245 
249  template<int Size2, typename Precision2, typename Base2>
251  this->try_destructive_resize(from.size());
252  SizeMismatch<Size,Size2>::test(size(), from.size());
253  const int s=size();
254  for(int i=0; i<s; i++){
255  (*this)[i]=from[i];
256  }
257  return *this;
258  }
259 
264  template <class Op>
265  inline Vector & operator=(const Operator<Op>& op){
266  this->try_destructive_resize(op);
267  op.eval(*this);
268  return *this;
269  }
271 
274 
276  Vector& operator/=(const Precision& rhs) {
277  for(int i=0; i<size(); i++)
278  (*this)[i]/=rhs;
279  return *this;
280  }
281 
283  Vector& operator*=(const Precision& rhs) {
284  for(int i=0; i<size(); i++)
285  (*this)[i]*=rhs;
286  return *this;
287  }
288 
290  template<int Size2, class Precision2, class Base2>
292  SizeMismatch<Size,Size2>::test(size(),rhs.size());
293  for(int i=0; i<size(); i++)
294  (*this)[i]+=rhs[i];
295  return *this;
296  }
297 
305  template<class Op>
307  {
308  op.plusequals(*this);
309  return *this;
310  }
311 
312  template<class Op>
314  {
315  op.minusequals(*this);
316  return *this;
317  }
318 
320  template<int Size2, class Precision2, class Base2>
322  SizeMismatch<Size,Size2>::test(size(),rhs.size());
323  for(int i=0; i<size(); i++)
324  (*this)[i]-=rhs[i];
325  return *this;
326  }
327 
329 
332 
334  template<int Size2, class Precision2, class Base2>
336  SizeMismatch<Size,Size2>::test(size(),rhs.size());
337  for(int i=0; i<size(); i++)
338  if((*this)[i]!=rhs[i])
339  return 0;
340  return 1;
341  }
342 
344  template<int Size2, class Precision2, class Base2>
346  SizeMismatch<Size,Size2>::test(size(),rhs.size());
347  for(int i=0; i<size(); i++)
348  if((*this)[i]!=rhs[i])
349  return 1;
350  return 0;
351  }
352 
354 
357 
360  {
361  return *this;
362  }
363 
364 #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
365 
367  int size() const;
368 
377  void resize(int s);
378 
385  Precision* get_data_ptr();
386 
387 
388 
390 
392 
393 
404 
416 
428  DiagonalMatrix<Size,Precision> as_diagonal();
429 
441  template<Start, Length>
442  const Vector<Length,Precision>& slice() const;
443 
457  template<Start, Length>
458  Vector<Length,Precision>& slice();
459 
472  template<Start, Length>
473  const Vector<Length,Precision>& slice() const;
474 
488  template<Start, Length>
489  Vector<Length,Precision>& slice();
491 
492 #endif
493 
494 };
495 
496 }
Vector & operator*=(const Precision &rhs)
multiply this vector by a constant
Definition: vector.hh:283
Vector(PointerType data_in, int size_in, int stride_in, Internal::Slicing)
internal constructor
Definition: vector.hh:169
Vector(const Vector< Size2, Precision2, Base2 > &from)
constructor from arbitrary vector
Definition: vector.hh:197
Base::template VLayout< Size, Precision >::PointerType PointerType
Definition: vector.hh:131
Everything lives inside this namespace.
Definition: allocator.hh:48
static void test(int s1, int s2)
Vector & operator=(const Vector &from)
Definition: vector.hh:236
Vector & operator+=(const Vector< Size2, Precision2, Base2 > &rhs)
add another vector onto this one
Definition: vector.hh:291
bool operator==(const Vector< Size2, Precision2, Base2 > &rhs) const
Test for equality with another vector.
Definition: vector.hh:335
Vector(int size_in)
Definition: vector.hh:149
bool operator!=(const Vector< Size2, Precision2, Base2 > &rhs) const
Test for inequality with another vector.
Definition: vector.hh:345
Vector(const Operator< Op > &op)
Definition: vector.hh:180
Vector(PointerType data)
Definition: vector.hh:157
Vector & operator-=(const Operator< Op > &op)
Definition: vector.hh:313
Vector & ref()
return me as a non const reference - useful for temporaries
Definition: vector.hh:359
Vector(PointerType data, int size_in)
Definition: vector.hh:166
Vector & operator+=(const Operator< Op > &op)
Definition: vector.hh:306
Vector & operator=(const Operator< Op > &op)
Definition: vector.hh:265
Vector & operator/=(const Precision &rhs)
divide this vector by a constant
Definition: vector.hh:276
Vector & operator-=(const Vector< Size2, Precision2, Base2 > &rhs)
subtract another vector from this one
Definition: vector.hh:321