Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PoseParametrization.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 __PoseParametrization_hh__
27 #define __PoseParametrization_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 <fstream>
36 
37 namespace BIAS {
38 
39 #define PP_TYPE double
40 
41  /** @class PoseParametrization
42  @brief Slim class bundeling pose parametrization and associated
43  covariance matrix.
44 
45  The pose is parametrized as vector of dimension 7 where the first 3
46  entries represent the position (euclidean vector of dimension 3) and the
47  last 4 entries represent the quaternion orientation.
48 
49  \author bartczak/woelk e.a. 04/2006 */
50  class BIASGeometryBase_EXPORT PoseParametrization
51  {
52  public:
54 
56  const Matrix<PP_TYPE>& covariance);
57 
58  PoseParametrization(const Vector3<PP_TYPE>& position,
59  const Quaternion<PP_TYPE>& orientation,
60  const Matrix<PP_TYPE>& covariance);
61 
62  /** Set this from pose parametrization. Zeros associated
63  covarinace matrix */
64  void SetCQ(const Vector<PP_TYPE>& CQvec);
65 
66  /** Set this from position and orientation. Zeros associated
67  covarinace matrix */
68  void SetCQ(const Vector3<PP_TYPE>& position,
69  const Quaternion<PP_TYPE>& orientation);
70 
71  /** Set this from position, orientation and covariance */
72  void Set(const Vector3<PP_TYPE>& position,
73  const Quaternion<PP_TYPE>& orientation,
74  const Matrix<PP_TYPE>& covariance=Matrix<double>(7,7,MatrixZero));
75 
76  inline void Set(const Vector<PP_TYPE>& CQvec, const Matrix<PP_TYPE>& Cov)
77  { SetCQ(CQvec); SetCovarianceMatrix(Cov); }
78 
79  /** Sets covariance matrix from Cov. Cov must be a 7x7 symmetric positiv
80  definit matrix (i.e. a covariance matrix) */
81  void SetCovarianceMatrix(const Matrix<PP_TYPE>& Cov);
82 
83  /** returns a vector of dimension 7 where first 3 entries are
84  the position and the last 4 entries are the quaternion orientation */
85  inline const Vector<PP_TYPE>& GetCQ() const
86  { return Pose_; }
87 
88  /** returns the covariance matrix associated with the CQ vector */
89  inline const Matrix<PP_TYPE>& GetCovarianceMatrix() const
90  { return Cov_; }
91 
92  /** set position part of vector and zero covariance matrix */
93  void SetPosition(const Vector3<PP_TYPE>& C);
94 
95  /** set orientation part of vector and zero covariance matrix */
96  void SetOrientation(const Quaternion<PP_TYPE>& q);
97 
98  /** returns the position (first 3 entries) part of the pose
99  parametrization vector */
100  Vector3<PP_TYPE> GetPosition() const;
101 
102  /** returns the quaternion (last 4 entries) part of the pose
103  parametrization vector */
104  Quaternion<PP_TYPE> GetOrientation() const;
105 
106  bool Load(const std::string& file);
107 
108  bool Save(const std::string& file) const;
109 
110  /** Transforms the pose and associated covariance according to
111  the point transformation parametrized as translation T and rotation Q
112  @author woelk 05/2006 (untested) */
113  void Transform(const Vector3<double>& T, const Quaternion<double>& q);
114 
115  /** Transforms the pose and associated covariance according to
116  the point transformation parametrized as translation T, rotation Q
117  and scale s
118  @author bartczak 05/2006 (untested) */
119  void Transform(const Vector3<double>& T,
120  const Quaternion<double>& q,
121  const double s);
122 
123  protected:
124  /** first 3 entries relate to the position */
126  /** first columns relate to position */
128 
129  inline void Pose2CQ_(const Vector<PP_TYPE>& pose,
130  Vector3<PP_TYPE>& position,
131  Quaternion<PP_TYPE>& orientation) const{
132  position[0] = pose[0];
133  position[1] = pose[1];
134  position[2] = pose[2];
135  orientation[0] = pose[3];
136  orientation[1] = pose[4];
137  orientation[2] = pose[5];
138  orientation[3] = pose[6];
139  };
140 
141  inline void CQ2Pose_(const Vector3<PP_TYPE>& position,
142  const Quaternion<PP_TYPE>& orientation,
143  Vector<PP_TYPE>& pose) const{
144  pose[0] = position[0];
145  pose[1] = position[1];
146  pose[2] = position[2];
147  pose[3] = orientation[0];
148  pose[4] = orientation[1];
149  pose[5] = orientation[2];
150  pose[6] = orientation[3];
151  };
152 
153  };
154 
155  BIASGeometryBase_EXPORT std::ostream&
156  operator<<(std::ostream &os, const PoseParametrization& p);
157 
158  BIASGeometryBase_EXPORT std::istream&
159  operator>>(std::istream &is, PoseParametrization& p);
160 
161 }
162 
163 
164 #endif
void Pose2CQ_(const Vector< PP_TYPE > &pose, Vector3< PP_TYPE > &position, Quaternion< PP_TYPE > &orientation) const
void Set(const Vector< PP_TYPE > &CQvec, const Matrix< PP_TYPE > &Cov)
Slim class bundeling pose parametrization and associated covariance matrix.
Vector< PP_TYPE > Pose_
first 3 entries relate to the position
const Matrix< PP_TYPE > & GetCovarianceMatrix() const
returns the covariance matrix associated with the CQ vector
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< PP_TYPE > & GetCQ() const
returns a vector of dimension 7 where first 3 entries are the position and the last 4 entries are the...
Matrix< PP_TYPE > Cov_
first columns relate to position
class for rotation with axis and angle
void CQ2Pose_(const Vector3< PP_TYPE > &position, const Quaternion< PP_TYPE > &orientation, Vector< PP_TYPE > &pose) const
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157