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.
so2.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 #ifndef TOON_INCLUDE_SO2_H
32 #define TOON_INCLUDE_SO2_H
33 
34 #include "TooN.h"
35 #include "helpers.h"
36 
37 namespace TooN {
38 
39 template<typename Precision> class SO2;
40 template <typename Precision> class SE2;
41 
42 template<typename Precision> inline std::istream & operator>>(std::istream &, SO2<Precision> & );
43 template<typename Precision> inline std::istream & operator>>(std::istream &, SE2<Precision> & );
44 
49 template<typename Precision = double>
50 class SO2 {
51  friend std::istream& operator>> <Precision>(std::istream&, SO2& );
52  friend std::istream& operator>> <Precision>(std::istream&, SE2<Precision>& );
53 
54 public:
57 
59  SO2(const Matrix<2,2,Precision>& rhs) {
60  *this = rhs;
61  coerce();
62  }
63 
65  SO2(const Precision l) { *this = exp(l); }
66 
69  template <int R, int C, typename P, typename A>
71  my_matrix = rhs;
72  coerce();
73  return *this;
74  }
75 
77  void coerce(){
78  my_matrix[0] = unit(my_matrix[0]);
79  my_matrix[1] -= my_matrix[0] * (my_matrix[0]*my_matrix[1]);
80  my_matrix[1] = unit(my_matrix[1]);
81  }
82 
84  inline static SO2 exp(const Precision & d){
85  SO2<Precision> result;
86  result.my_matrix[0][0] = result.my_matrix[1][1] = cos(d);
87  result.my_matrix[1][0] = sin(d);
88  result.my_matrix[0][1] = -result.my_matrix[1][0];
89  return result;
90  }
91 
93  Precision ln() const { return atan2(my_matrix[1][0], my_matrix[0][0]); }
94 
96  SO2 inverse() const { return SO2(*this, Invert()); }
97 
99  template <typename P>
100  SO2& operator *=(const SO2<P>& rhs){
102  return *this;
103  }
104 
106  template <typename P>
109  }
110 
112  const Matrix<2,2,Precision>& get_matrix() const {return my_matrix;}
113 
116  Matrix<2,2,Precision> result;
117  result[0] = makeVector(0,-1);
118  result[1] = makeVector(1,0);
119  return result;
120  }
121 
122 private:
123  struct Invert {};
124  inline SO2(const SO2& so2, const Invert&) : my_matrix(so2.my_matrix.T()) {}
125  template <typename PA, typename PB>
126  inline SO2(const SO2<PA>& a, const SO2<PB>& b) : my_matrix(a.get_matrix()*b.get_matrix()) {}
127 
129 };
130 
133 template <typename Precision>
134 inline std::ostream& operator<< (std::ostream& os, const SO2<Precision> & rhs){
135  return os << rhs.get_matrix();
136 }
137 
140 template <typename Precision>
141 inline std::istream& operator>>(std::istream& is, SO2<Precision>& rhs){
142  return is >> rhs.my_matrix;
143  rhs.coerce();
144 }
145 
148 template<int D, typename P1, typename PV, typename Accessor>
150  return lhs.get_matrix() * rhs;
151 }
152 
155 template<int D, typename P1, typename PV, typename Accessor>
157  return lhs * rhs.get_matrix();
158 }
159 
162 template <int R, int C, typename P1, typename P2, typename Accessor>
164  return lhs.get_matrix() * rhs;
165 }
166 
169 template <int R, int C, typename P1, typename P2, typename Accessor>
171  return lhs * rhs.get_matrix();
172 }
173 
174 }
175 
176 #endif
Precision ln() const
extracts the rotation angle from the SO2
Definition: so2.h:93
Matrix< R, 2, typename Internal::MultiplyType< P1, P2 >::type > operator*(const Matrix< R, C, P1, Accessor > &lhs, const SO2< P2 > &rhs)
Definition: so2.h:170
static Operator< Internal::Identity< Internal::One > > Identity
Definition: objects.h:748
SO2< typename Internal::MultiplyType< Precision, P >::type > operator*(const SO2< P > &rhs) const
Right-multiply by another rotation matrix.
Definition: so2.h:107
Vector< 2, typename Internal::MultiplyType< P1, PV >::type > operator*(const SO2< P1 > &lhs, const Vector< D, PV, Accessor > &rhs)
Definition: so2.h:149
Everything lives inside this namespace.
Definition: allocator.hh:48
SO2 & operator*=(const SO2< P > &rhs)
Self right-multiply by another rotation matrix.
Definition: so2.h:100
Definition: se2.h:52
SO2(const SO2< PA > &a, const SO2< PB > &b)
Definition: so2.h:126
Matrix< 2, 2, Precision > my_matrix
Definition: so2.h:128
SO2 & operator=(const Matrix< R, C, P, A > &rhs)
Definition: so2.h:70
SO2(const Matrix< 2, 2, Precision > &rhs)
Construct from a rotation matrix.
Definition: so2.h:59
void coerce()
Modifies the matrix to make sure it is a valid rotation matrix.
Definition: so2.h:77
Vector< 2, typename Internal::MultiplyType< PV, P1 >::type > operator*(const Vector< D, PV, Accessor > &lhs, const SO2< P1 > &rhs)
Definition: so2.h:156
static Matrix< 2, 2, Precision > generator()
returns generator matrix
Definition: so2.h:115
std::istream & operator>>(std::istream &is, SO2< Precision > &rhs)
Definition: so2.h:141
SO2(const Precision l)
Construct from an angle.
Definition: so2.h:65
Vector< 1 > makeVector(double x1)
Definition: make_vector.hh:4
SO2()
Default constructor. Initialises the matrix to the identity (no rotation)
Definition: so2.h:56
Vector< Size, Precision > unit(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:126
std::istream & operator>>(std::istream &is, Vector< Size, Precision, Base > &v)
Definition: operators.hh:657
SO2(const SO2 &so2, const Invert &)
Definition: so2.h:124
SO2 inverse() const
Returns the inverse of this matrix (=the transpose, so this is a fast operation)
Definition: so2.h:96
Definition: so2.h:39
Matrix< 2, C, typename Internal::MultiplyType< P1, P2 >::type > operator*(const SO2< P1 > &lhs, const Matrix< R, C, P2, Accessor > &rhs)
Definition: so2.h:163
static SO2 exp(const Precision &d)
Exponentiate an angle in the Lie algebra to generate a new SO2.
Definition: so2.h:84
const Matrix< 2, 2, Precision > & get_matrix() const
Returns the SO2 as a Matrix<2>
Definition: so2.h:112