Quaternion.cpp
Go to the documentation of this file.
1 
18 #include "Quaternion.hpp"
19 
20 #include <gtest/internal/gtest-internal.h>
21 
22 namespace ISM {
23  std::ostream& operator<<(std::ostream &strm, const ISM::Quaternion &q) {
24  return strm<<"quaternion: ["<<q.eigen.w() << ";" << q.eigen.x() <<";" <<q.eigen.y() << ";" << q.eigen.z() << "]";
25  }
26 
27  std::ostream& operator<<(std::ostream &strm, const ISM::QuaternionPtr &q) {
28  return strm<<(*q);
29  }
30 
31  void Quaternion::serialize(std::ostream& strm) const {
32  strm<<"{\"w\": "<<this->eigen.w()<<", \"x\": "<<this->eigen.x()<<", \"y\": "<<this->eigen.y()<<", \"z\": "<<this->eigen.z()<<"}";
33  }
34 
35  bool operator==(const QuaternionPtr& q1, const QuaternionPtr& q2)
36  {
37  return *q1 == *q2;
38  }
39 
40  bool operator==(const Quaternion& q1, const Quaternion& q2)
41  {
42  /*
43  * this would be the correct way to do it but since pose from vote has inaccuracy
44  * use threshold
45 
46  testing::internal::FloatingPoint<double> w1(q.eigen.w()), w2(eigen.w());
47  testing::internal::FloatingPoint<double> x1(q.eigen.x()), x2(eigen.x());
48  testing::internal::FloatingPoint<double> y1(q.eigen.y()), y2(eigen.y());
49  testing::internal::FloatingPoint<double> z1(q.eigen.z()), z2(eigen.z());
50  return w1.AlmostEquals(w2) && x1.AlmostEquals(x2) && y1.AlmostEquals(y2) && z1.AlmostEquals(z2);
51  */
52 
53  //threshold determined statistically
54  const double threshold = 1e-15;
55  double diffW = fabs(q1.eigen.w() - q2.eigen.w());
56  double diffX = fabs(q1.eigen.x() - q2.eigen.x());
57  double diffY = fabs(q1.eigen.y() - q2.eigen.y());
58  double diffZ = fabs(q1.eigen.z() - q2.eigen.z());
59  return diffW < threshold && diffX < threshold && diffY < threshold && diffZ < threshold;
60  }
61 
62  Eigen::Quaternion<double> Quaternion::getEigen() {
63  return this->eigen;
64  }
65 }
boost::shared_ptr< Quaternion > QuaternionPtr
Definition: Quaternion.hpp:39
virtual void serialize(std::ostream &strm) const
Definition: Quaternion.cpp:31
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Quaternion< double > eigen
Definition: Quaternion.hpp:30
std::ostream & operator<<(std::ostream &strm, const ISM::ObjectRelation &r)
bool operator==(const PointPtr &p1, const PointPtr &p2)
Definition: Point.cpp:39
this namespace contains all generally usable classes.
Eigen::Quaternion< double > getEigen()
Definition: Quaternion.cpp:62


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40