Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RParametrization.cpp
1 #include "RParametrization.hh"
2 #include <Base/Common/W32Compat.hh>
3 
4 #include <Base/Debug/Exception.hh>
5 #include <Base/Common/CompareFloatingPoint.hh>
6 #include <Base/Geometry/HomgPoint2D.hh>
7 #include <Base/Geometry/HomgPoint2DCov.hh>
8 #include <Base/Geometry/RMatrixBase.hh>
9 #include <Base/Geometry/Quaternion.hh>
10 
11 #include <fstream>
12 
13 using namespace BIAS;
14 using namespace std;
15 
18  : Q_(4, 0.0), Cov_(4, 4, MatrixZero)
19 {
20  Q_[3] = 1.0;
21 }
22 
23 
26  const Matrix<Q_TYPE>& covariance)
27 {
28  Set(Qvec, covariance);
29 }
30 
31 
33 Set(const Vector<Q_TYPE>& Qvec)
34 {
35  if (Qvec.size() != 4){
36  BEXCEPTION("invalid vector size, must be 4");
37  }
38  Q_ = Qvec;
39  Cov_.SetZero();
40 }
41 
42 
45 {
46  if(Cov.num_rows() != 4 || Cov.num_cols() != 4) {
47  BEXCEPTION("dimension of argument covariance matrix does not match!\n");
48  }
49  // todo: check symmetry and positiv definitness of cov
50  Cov_ = Cov;
51 }
52 
53 
55 GetQ() const
56 {
57  Vector4<double> vec = GetVec();
58  Quaternion<Q_TYPE> Q(vec);
59  return Q;
60 }
61 
62 
65 {
66  const Quaternion<Q_TYPE> Q = GetQ();
67  RMatrixBase R;
68  R.SetFromQuaternion(Q);
69 
70  return R;
71 }
72 
73 
75 Load(const std::string& file)
76 {
77  std::ifstream ifs(file.c_str());
78  if(!ifs)
79  return false;
80  ifs>>*this;
81  if(!ifs) {
82  ifs.close();
83  return false;
84  }
85  ifs.close();
86  return true;
87 }
88 
89 
91 Save(const std::string& file) const
92 {
93  std::ofstream ofs(file.c_str());
94  if(!ofs)
95  return false;
96  ofs<<*this;
97  if(!ofs) {
98  ofs.close();
99  return false;
100  }
101  ofs.close();
102  return true;
103 }
104 
105 
106 std::ostream& BIAS::
107 operator<<(std::ostream &os, const RParametrization& p)
108 {
109  os<< "orientation= "<<p.GetVec();
110  os<< " cov= "<<p.GetCovarianceMatrix();
111  return os;
112 }
113 
114 
115 std::istream& BIAS::
116 operator>>(std::istream &is, RParametrization& p)
117 {
118  std::string temp;
119  Vector<Q_TYPE> orientation;
120  Matrix<Q_TYPE> cov;
121  is>>temp>>temp>>orientation>>temp>>cov;
122  p.Set(orientation, cov);
123  return is;
124 }
125 
RMatrixBase GetRotationMatrix() const
returns the rotation matrix computed from parametrization
Subscript num_cols() const
Definition: cmat.h:320
void Set(const Vector< Q_TYPE > &Qvec)
Set this from R parametrization.
const Vector< Q_TYPE > & GetVec() const
returns a vector of dimension 6 where first 2 entries are the epipole and the last 4 entries are the ...
Quaternion< Q_TYPE > GetQ() const
returns the quaternion
const Matrix< Q_TYPE > & GetCovarianceMatrix() const
returns the covariance matrix associated with the EQ vector
Slim class bundeling rotation matrix parametrization and associated covariance matrix.
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
void SetZero()
Sets all values to zero.
Definition: Matrix.hh:856
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
bool Save(const std::string &file) const
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
Subscript num_rows() const
Definition: cmat.h:319
bool Load(const std::string &file)
void SetCovarianceMatrix(const Matrix< Q_TYPE > &Cov)
Sets covariance matrix from Cov.
class for rotation with axis and angle
Subscript size() const
Definition: vec.h:262
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157