Pose6D.cpp
Go to the documentation of this file.
1 /*
2  * OctoMap - An Efficient Probabilistic 3D Mapping Framework Based on Octrees
3  * http://octomap.github.com/
4  *
5  * Copyright (c) 2009-2013, K.M. Wurm and A. Hornung, University of Freiburg
6  * All rights reserved.
7  * License: New BSD
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the University of Freiburg nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <octomap/math/Pose6D.h>
35 #include <math.h>
36 
37 namespace octomath {
38 
40  }
41 
42 
44  translation(trans),
45  rotation(rot)
46  { }
47 
48 
49 
50  Pose6D::Pose6D(float x, float y, float z, double roll, double pitch, double yaw) :
51  translation(x, y, z),
52  rotation(roll, pitch, yaw)
53  { }
54 
56  }
57 
58  Pose6D& Pose6D::operator= (const Pose6D& other) {
59  translation = other.trans();
60  rotation = other.rot();
61  return *this;
62  }
63 
64 
65  Pose6D Pose6D::inv() const {
66  Pose6D result(*this);
67  result.rot() = rot().inv().normalized();
68  result.trans() = result.rot().rotate(-trans());
69  return result;
70  }
71 
72 
74  rot() = rot().inv().normalized();
75  trans() = rot().rotate(-trans());
76  return *this;
77  }
78 
79 
80  Vector3 Pose6D::transform (const Vector3 &v) const {
81  Vector3 res = this->rot().rotate(v);
82  res = res + this->trans();
83  return res;
84  }
85 
86  Pose6D Pose6D::operator* (const Pose6D& other) const {
87  Quaternion rot_new = rotation * other.rot();
88  Vector3 trans_new = rotation.rotate(other.trans()) + trans();
89  return Pose6D(trans_new, rot_new.normalized());
90  }
91 
92  const Pose6D& Pose6D::operator*= (const Pose6D& other) {
93  trans() += rotation.rotate(other.trans());
94  rot() = rot() * other.rot();
95  return *this;
96  }
97 
98  double Pose6D::distance (const Pose6D &other) const {
99  double dist_x = x() - other.x();
100  double dist_y = y() - other.y();
101  double dist_z = z() - other.z();
102  return sqrt(dist_x*dist_x + dist_y*dist_y + dist_z*dist_z);
103  }
104 
105  double Pose6D::transLength() const {
106  return sqrt(x()*x() + y()*y() + z()*z());
107  }
108 
109 
110  bool Pose6D::operator==(const Pose6D& other) const {
111  return translation == other.translation
112  && rotation == other.rotation;
113  }
114 
115  bool Pose6D::operator!=(const Pose6D& other) const {
116  return !(*this == other);
117  }
118 
119  std::istream& Pose6D::read(std::istream &s) {
120  translation.read(s);
121  rotation.read(s);
122  return s;
123  }
124 
125 
126  std::ostream& Pose6D::write(std::ostream &s) const {
127  translation.write(s);
128  s << " ";
129  rotation.write(s);
130  return s;
131  }
132 
133 
134  std::istream& Pose6D::readBinary(std::istream &s) {
136  rotation.readBinary(s);
137  return s;
138  }
139 
140 
141  std::ostream& Pose6D::writeBinary(std::ostream &s) const {
144  return s;
145  }
146 
147  std::ostream& operator<<(std::ostream& s, const Pose6D& p) {
148  s << "(" << p.x() << " " << p.y() << " " << p.z()
149  << ", " << p.rot().u() << " " << p.rot().x() << " " << p.rot().y() << " " << p.rot().z() << ")";
150  return s;
151  }
152 
153 }
std::istream & read(std::istream &s)
Input operator.
Definition: Pose6D.cpp:119
Vector3 transform(const Vector3 &v) const
Transformation of a vector.
Definition: Pose6D.cpp:80
std::ostream & writeBinary(std::ostream &s) const
Definition: Quaternion.cpp:291
std::ostream & operator<<(std::ostream &s, const Pose6D &p)
user friendly output in format (x y z, u x y z) which is (translation, rotation)
Definition: Pose6D.cpp:147
std::istream & read(std::istream &s)
Definition: Quaternion.cpp:261
Pose6D & operator=(const Pose6D &other)
Definition: Pose6D.cpp:58
std::istream & read(std::istream &s)
Definition: Vector3.cpp:69
float & x()
Definition: Pose6D.h:100
std::istream & readBinary(std::istream &s)
Binary input operator.
Definition: Pose6D.cpp:134
bool operator==(const Pose6D &other) const
Definition: Pose6D.cpp:110
std::ostream & write(std::ostream &s) const
Definition: Vector3.cpp:78
double transLength() const
Translational length.
Definition: Pose6D.cpp:105
Quaternion inv() const
Inversion.
Definition: Quaternion.h:156
float & z()
Definition: Pose6D.h:102
Quaternion normalized() const
Definition: Quaternion.cpp:241
const Pose6D & operator*=(const Pose6D &p)
In place concatenation.
Definition: Pose6D.cpp:92
std::istream & readBinary(std::istream &s)
Definition: Vector3.cpp:87
double yaw() const
Definition: Pose6D.h:109
std::ostream & writeBinary(std::ostream &s) const
Definition: Vector3.cpp:99
bool operator!=(const Pose6D &other) const
Definition: Pose6D.cpp:115
This class represents a tree-dimensional pose of an object.
Definition: Pose6D.h:49
double roll() const
Definition: Pose6D.h:107
Vector3 & trans()
Translational component.
Definition: Pose6D.h:80
This class represents a three-dimensional vector.
Definition: Vector3.h:50
std::ostream & write(std::ostream &s) const
Output operator.
Definition: Pose6D.cpp:126
Quaternion rotation
Definition: Pose6D.h:196
std::ostream & writeBinary(std::ostream &s) const
Binary output operator.
Definition: Pose6D.cpp:141
float & y()
Definition: Pose6D.h:101
Vector3 rotate(const Vector3 &v) const
Rotate a vector.
Definition: Quaternion.cpp:255
double distance(const Pose6D &other) const
Translational distance.
Definition: Pose6D.cpp:98
Pose6D operator*(const Pose6D &p) const
Concatenation.
Definition: Pose6D.cpp:86
Quaternion & rot()
Rotational component.
Definition: Pose6D.h:86
std::ostream & write(std::ostream &s) const
Definition: Quaternion.cpp:270
Vector3 translation
Definition: Pose6D.h:195
Pose6D & inv_IP()
Inversion.
Definition: Pose6D.cpp:73
double pitch() const
Definition: Pose6D.h:108
Pose6D inv() const
Inversion.
Definition: Pose6D.cpp:65
This class represents a Quaternion.
Definition: Quaternion.h:56
std::istream & readBinary(std::istream &s)
Definition: Quaternion.cpp:279


octomap
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Feb 28 2022 22:58:06