Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EParametrization.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __EParametrization_hh__
27 #define __EParametrization_hh__
28 
29 #include <Base/Math/Vector.hh>
30 #include <Base/Math/Vector3.hh>
31 #include <Base/Math/Matrix.hh>
32 #include <Base/Math/Matrix4x4.hh>
33 #include <Base/Geometry/Quaternion.hh>
34 
35 #include <Base/Common/CompareFloatingPoint.hh>
36 
37 #include <fstream>
38 
39 namespace BIAS {
40 
41 #define EP_TYPE double
42 
43  /** @class EParametrization
44  @brief Slim class bundling essential matrix parameterization and
45  associated covariance matrix.
46 
47  The essential is parameterized as vector of dimension 7 where the first 3
48  entries represent the epipole and the last 4 entries represent the
49  quaternion orientation.
50 
51  \author woelk 07/2006 */
52  class BIASGeometryBase_EXPORT EParametrization
53  {
54  public:
56 
57  EParametrization(const Vector<EP_TYPE>& EQvec,
58  const Matrix<EP_TYPE>& covariance);
59 
60  EParametrization(const Vector3<EP_TYPE>& epipole,
61  const Quaternion<EP_TYPE>& orientation,
62  const Matrix<EP_TYPE>& covariance);
63 
64  /** Set this from E parametrization. Zeros associated
65  covariance matrix */
66  void SetEQ(const Vector<EP_TYPE>& EQvec);
67 
68  /** Set this from epipole and orientation. Zeros associated
69  covariance matrix */
70  void SetEQ(const Vector3<EP_TYPE>& epipole,
71  const Quaternion<EP_TYPE>& orientation);
72 
73  /** Set this from epipole, orientation and covariance */
74  void Set(const Vector3<EP_TYPE>& epipole,
75  const Quaternion<EP_TYPE>& orientation,
76  const Matrix<EP_TYPE>& covariance);
77 
78  inline void Set(const Vector<EP_TYPE>& EQvec, const Matrix<EP_TYPE>& Cov)
79  { SetEQ(EQvec); SetCovarianceMatrix(Cov); }
80 
81  /** Sets covariance matrix from Cov. Cov must be a 7x7 symmetric positive
82  definite matrix (i.e. a covariance matrix) */
83  void SetCovarianceMatrix(const Matrix<EP_TYPE>& Cov);
84 
85  /** Returns a vector of dimension 7 where first 3 entries are
86  the epipole and the last 4 entries are the quaternion orientation */
87  inline const Vector<EP_TYPE>& GetEQ7() const
88  { return E_; }
89 
90  /** returns the covariance matrix associated with the EQ vector */
91  inline const Matrix<EP_TYPE>& GetCov() const
92  { return Cov_; }
93 
94  /** set epipole part of vector and zero covariance matrix */
95  void SetEpipole(const Vector3<EP_TYPE>& epipole);
96 
97  /** set orientation part of vector and zero covariance matrix */
98  void SetOrientation(const Quaternion<EP_TYPE>& q);
99 
100  /** returns the epipole (first 3 entries) part of the essential matrix
101  parametrization vector */
102  Vector3<EP_TYPE> GetEpipole3() const;
103 
104  /** returns the epipole (first 3 entries) part of the essential matrix
105  parametrization vector */
106  void GetEpipole(Vector3<EP_TYPE>& epipole) const;
107 
108  /** returns the essential matrix computed from parametrization */
109  Matrix3x3<EP_TYPE> GetEssentialMatrix() const;
110 
111  /** returns the essential matrix computed from parametrization */
112  void GetEssentialMatrix(Matrix3x3<EP_TYPE>& E) const;
113 
114  /** returns the quaternion (last 4 entries) part of the essential matrix
115  parametrization vector */
116  Quaternion<EP_TYPE> GetOrientation() const;
117 
118  /** covariance to GetOrientation()
119  @author woelk 09/2006 */
120  Matrix4x4<EP_TYPE> GetOrientationCov() const;
121 
122  /** return whole (with orientation and epipole) covariance matrix */
123  Matrix<EP_TYPE> GetCovarianceMatrix() const;
124 
125  /** covariance to GetEpipole(),
126  @author woelk 09/2006 */
127  //Matrix3x3<EP_TYPE> GetEpipoleCov() const;
128 
129  /** covariance to GetEpipole(Vector3<double>))
130  @author woelk 09/2006 */
131  void GetEpipoleCov(Matrix3x3<EP_TYPE>& cov) const;
132 
133  bool Load(const std::string& file);
134 
135  bool Save(const std::string& file) const;
136 
137  /** inverts the direction, */
138  void Invert();
139 
140  /* normalizes the epipole and the quaternion */
141  void Normalize(const bool update_covariance = true);
142 
143  protected:
144  /** first 3 entries relate to the epipole, the last four to the quaternion
145  orientation */
147  /** first 3 columns relate to epipole, the last four columns relate to
148  the orientation */
150 
151  inline void E2EQ_(const Vector<EP_TYPE>& E,
152  Vector3<EP_TYPE>& epipole,
153  Quaternion<EP_TYPE>& orientation) const{
154  epipole[0] = E[0];
155  epipole[1] = E[1];
156  epipole[2] = E[2];
157  orientation[0] = E[3];
158  orientation[1] = E[4];
159  orientation[2] = E[5];
160  orientation[3] = E[6];
161  };
162 
163  inline void EQ2E_(const Vector3<EP_TYPE>& epipole,
164  const Quaternion<EP_TYPE>& orientation,
165  Vector<EP_TYPE>& E) const{
166  E[0] = epipole[0];
167  E[1] = epipole[1];
168  E[2] = epipole[2];
169  E[3] = orientation[0];
170  E[4] = orientation[1];
171  E[5] = orientation[2];
172  E[6] = orientation[3];
173  };
174 
175  };
176 
177  BIASGeometryBase_EXPORT std::ostream&
178  operator<<(std::ostream &os, const EParametrization& p);
179 
180  BIASGeometryBase_EXPORT std::istream&
181  operator>>(std::istream &is, EParametrization& p);
182 
183 }
184 
185 #endif
void E2EQ_(const Vector< EP_TYPE > &E, Vector3< EP_TYPE > &epipole, Quaternion< EP_TYPE > &orientation) const
Slim class bundling essential matrix parameterization and associated covariance matrix.
void EQ2E_(const Vector3< EP_TYPE > &epipole, const Quaternion< EP_TYPE > &orientation, Vector< EP_TYPE > &E) const
Vector< EP_TYPE > E_
first 3 entries relate to the epipole, the last four to the quaternion orientation ...
Matrix< EP_TYPE > Cov_
first 3 columns relate to epipole, the last four columns relate to the orientation ...
const Matrix< EP_TYPE > & GetCov() const
returns the covariance matrix associated with the EQ vector
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
class Vector3 contains a Vector of fixed dim.
Definition: Matrix.hh:53
const Vector< EP_TYPE > & GetEQ7() const
Returns a vector of dimension 7 where first 3 entries are the epipole and the last 4 entries are the ...
void Set(const Vector< EP_TYPE > &EQvec, const Matrix< EP_TYPE > &Cov)
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
class for rotation with axis and angle
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157