18 #ifndef _SDF_TYPES_HH_
19 #define _SDF_TYPES_HH_
26 #include <boost/shared_ptr.hpp>
31 #define SDF_DEPRECATED(version) __attribute__((deprecated))
32 #define SDF_FORCEINLINE __attribute__((always_inline))
34 #define SDF_DEPRECATED(version)
35 #define SDF_FORCEINLINE __forceinline
37 #define SDF_DEPRECATED(version)
38 #define SDF_FORCEINLINE
55 inline bool equal(
const T &_a,
const T &_b,
56 const T &_epsilon = 1e-6)
58 return std::fabs(_a - _b) <= _epsilon;
69 public:
Color(
float _r = 0.0f,
float _g = 0.0f,
70 float _b = 0.0f,
float _a = 1.0f)
71 : r(_r), g(_g), b(_b), a(_a) {}
77 public:
friend std::ostream &operator<< (std::ostream &_out,
80 _out << _pt.
r <<
" " << _pt.
g <<
" " << _pt.
b <<
" " << _pt.
a;
87 public:
friend std::istream &operator>> (std::istream &_in,
Color &_pt)
90 _in.setf(std::ios_base::skipws);
91 _in >> _pt.
r >> _pt.
g >> _pt.
b >> _pt.
a;
98 public:
bool operator ==(
const Color &_clr)
const
100 return equal(this->r, _clr.
r) &&
136 _out << _pt.
x <<
" " << _pt.
y;
148 _in.setf(std::ios_base::skipws);
149 _in >> _pt.
x >> _pt.
y;
156 public:
bool operator ==(
const Vector2i &_pt)
const
158 return this->x == _pt.
x && this->y == _pt.
y;
185 _out << _pt.
x <<
" " << _pt.
y;
197 _in.setf(std::ios_base::skipws);
198 _in >> _pt.
x >> _pt.
y;
206 public:
bool operator ==(
const Vector2d &_pt)
const
228 : x(_v.x), y(_v.y), z(_v.z) {}
234 public:
Vector3(
double _x = 0.0,
double _y = 0.0,
double _z = 0.0)
235 : x(_x), y(_y), z(_z) {}
242 return Vector3(this->x + _v.
x, this->y + _v.
y, this->z + _v.
z);
251 c.
x = this->y * _pt.
z - this->z * _pt.
y;
252 c.
y = this->z * _pt.
x - this->x * _pt.
z;
253 c.
z = this->x * _pt.
y - this->y * _pt.
x;
263 return Vector3(this->x * _v, this->y * _v, this->z * _v);
273 _out << _pt.
x <<
" " << _pt.
y <<
" " << _pt.
z;
295 return equal(this->x, _pt.
x, 0.001) &&
296 equal(this->y, _pt.
y, 0.001) &&
297 equal(this->z, _pt.
z, 0.001);
308 _in.setf(std::ios_base::skipws);
309 _in >> _pt.
x >> _pt.
y >> _pt.
z;
334 : x(_q.x), y(_q.y), z(_q.z), w(_q.w) {}
336 public:
Quaternion(
const double &_roll,
const double &_pitch,
339 this->SetFromEuler(
Vector3(_roll, _pitch, _yaw));
347 public:
Quaternion(
double _w,
double _x,
double _y,
double _z)
348 : x(_x), y(_y), z(_z), w(_w) {}
356 return EulerToQuaternion(
Vector3(_x, _y, _z));
386 this->w*_q.
w - this->x*_q.
x - this->y*_q.
y - this->z*_q.
z,
387 this->w*_q.
x + this->x*_q.
w + this->y*_q.
z - this->z*_q.
y,
388 this->w*_q.
y - this->x*_q.
z + this->y*_q.
w + this->z*_q.
x,
389 this->w*_q.
z + this->x*_q.
y - this->y*_q.
x + this->z*_q.
w);
397 Quaternion q(this->w, this->x, this->y, this->z);
400 s = q.
w * q.
w + q.
x * q.
x + q.
y * q.
y + q.
z * q.
z;
435 squ = copy.
w * copy.
w;
436 sqx = copy.
x * copy.
x;
437 sqy = copy.
y * copy.
y;
438 sqz = copy.
z * copy.
z;
441 vec.
x = atan2(2 * (copy.
y*copy.
z + copy.
w*copy.
x),
442 squ - sqx - sqy + sqz);
445 double sarg = -2 * (copy.
x*copy.
z - copy.
w * copy.
y);
446 vec.
y = sarg <= -1.0 ? -0.5*M_PI :
447 (sarg >= 1.0 ? 0.5*M_PI : asin(sarg));
450 vec.
z = atan2(2 * (copy.
x*copy.
y + copy.
w*copy.
z),
451 squ + sqx - sqy - sqz);
460 double phi, the, psi;
466 this->w = cos(phi) * cos(the) * cos(psi) + sin(phi) *
468 this->x = sin(phi) * cos(the) * cos(psi) - cos(phi) *
470 this->y = cos(phi) * sin(the) * cos(psi) + sin(phi) *
472 this->z = cos(phi) * cos(the) * sin(psi) - sin(phi) *
483 s = sqrt(this->w * this->w + this->x * this->x +
509 tmp = (*this) * (tmp * this->GetInverse());
521 _out << v.
x <<
" " << v.y <<
" " << v.z;
530 Vector3 qvec(this->x, this->y, this->z);
532 uuv = qvec.
Cross(uv);
533 uv *= (2.0f * this->w);
536 return _v + uv + uuv;
546 double roll, pitch, yaw;
549 _in.setf(std::ios_base::skipws);
550 _in >> roll >> pitch >> yaw;
562 return this->GetAsEuler() == _qt.
GetAsEuler();
567 if (!std::isfinite(this->x))
569 if (!std::isfinite(this->y))
571 if (!std::isfinite(this->z))
573 if (!std::isfinite(this->w))
576 if (
equal(this->w, 0.0) &&
equal(this->x, 0.0) &&
602 :pos(0, 0, 0), rot(1, 0, 0, 0)
609 : pos(_pos), rot(_rot) {}
618 public:
Pose(
double _x,
double _y,
double _z,
619 double _roll,
double _pitch,
double _yaw)
620 : pos(_x, _y, _z), rot(_roll, _pitch, _yaw)
632 _out << _pose.
pos <<
" " << _pose.
rot;
644 _in.setf(std::ios_base::skipws);
645 _in >> _pose.
pos >> _pose.
rot;
654 return Pose(this->CoordPositionAdd(pose), pose.
rot * this->rot);
673 result.
x = _pose.
pos.
x + tmp.
x;
674 result.
y = _pose.
pos.
y + tmp.
y;
675 result.
z = _pose.
pos.
z + tmp.
z;
683 public:
bool operator ==(
const Pose &_pose)
const
685 return this->pos == _pose.
pos && this->rot == _pose.
rot;
708 public:
Time(int32_t _sec, int32_t _nsec)
709 : sec(_sec), nsec(_nsec)
720 _out << _time.
sec <<
" " << _time.
nsec;
732 _in.setf(std::ios_base::skipws);
733 _in >> _time.
sec >> _time.
nsec;
740 public:
bool operator ==(
const Time &_time)
const
742 return this->sec == _time.
sec && this->nsec == _time.
nsec;
Generic double x, y vector.
Definition: Types.hh:170
Quaternion operator*(const Quaternion &_q) const
Multiplication operator.
Definition: Types.hh:383
friend std::istream & operator>>(std::istream &_in, Pose &_pose)
Stream extraction operator.
Definition: Types.hh:640
friend std::ostream & operator<<(std::ostream &_out, const Quaternion &_q)
Stream insertion operator.
Definition: Types.hh:517
bool operator==(const sdf::Vector3 &_pt) const
Equal to operator.
Definition: Types.hh:293
friend std::istream & operator>>(std::istream &_in, Quaternion &_q)
Stream extraction operator.
Definition: Types.hh:543
Vector3 RotateVector(const Vector3 &_vec) const
Rotate a vector using the quaternion.
Definition: Types.hh:506
Quaternion()
Default Constructor.
Definition: Types.hh:328
Quaternion(double _w, double _x, double _y, double _z)
Constructor.
Definition: Types.hh:347
double z
z data
Definition: Types.hh:590
float b
Blue value.
Definition: Types.hh:113
int32_t sec
Seconds.
Definition: Types.hh:746
double y
y Data
Definition: Types.hh:317
friend std::istream & operator>>(std::istream &_in, Vector3 &_pt)
Stream extraction operator.
Definition: Types.hh:304
void Normalize()
Normalize the quaternion.
Definition: Types.hh:479
Vector2i(int _x=0, int _y=0)
Constructor.
Definition: Types.hh:126
int x
x data
Definition: Types.hh:162
Vector3 operator*(double _v) const
Multiplication operator.
Definition: Types.hh:261
Vector3 GetAsEuler() const
Return the rotation in Euler angles.
Definition: Types.hh:423
double x
x Data
Definition: Types.hh:314
A quaternion class.
Definition: Types.hh:325
double x
x data
Definition: Types.hh:584
friend std::istream & operator>>(std::istream &_in, Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:193
double z
z Data
Definition: Types.hh:320
Vector3 pos
Position data.
Definition: Types.hh:689
double x
x data
Definition: Types.hh:213
static Quaternion EulerToQuaternion(const Vector3 &_vec)
Convert euler angles to quatern.
Definition: Types.hh:361
Generic integer x, y vector.
Definition: Types.hh:121
Pose(Vector3 _pos, Quaternion _rot)
Constructor.
Definition: Types.hh:608
double mass
Definition: Types.hh:755
Vector3(double _x=0.0, double _y=0.0, double _z=0.0)
Constructor.
Definition: Types.hh:234
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6)
check if two values are equal, within a tolerance
Definition: Types.hh:55
Pose()
Constructor.
Definition: Types.hh:601
Vector3 CoordPositionAdd(const Pose &_pose) const
Add one point to another: result = this + pose.
Definition: Types.hh:660
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
Pose(double _x, double _y, double _z, double _roll, double _pitch, double _yaw)
Constructor.
Definition: Types.hh:618
Time()
Constructor.
Definition: Types.hh:700
Vector3 operator*(const Vector3 &_v) const
Vector3 multiplication operator.
Definition: Types.hh:527
SDFORMAT_VISIBLE const char * winGetEnv(const char *_name)
Windows equivalent of getEnv.
Vector3(const Vector3 &_v)
Copy constructor.
Definition: Types.hh:227
int y
y data
Definition: Types.hh:165
const Vector3 & operator*=(double _v)
Multiplication by a double.
Definition: Types.hh:280
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:708
friend std::istream & operator>>(std::istream &_in, Vector2i &_pt)
Stream extraction operator.
Definition: Types.hh:144
Defines a color.
Definition: Types.hh:62
Quaternion rot
Orientation data.
Definition: Types.hh:692
float r
Red value.
Definition: Types.hh:107
double y
y data
Definition: Types.hh:587
double w
w data
Definition: Types.hh:593
friend std::ostream & operator<<(std::ostream &_out, const Vector3 &_pt)
Stream insertion operator.
Definition: Types.hh:270
A class for inertial information about a link.
Definition: Types.hh:753
void Correct()
Definition: Types.hh:565
Quaternion(const Quaternion &_q)
Copy constructor.
Definition: Types.hh:333
Quaternion(const double &_roll, const double &_pitch, const double &_yaw)
Definition: Types.hh:336
Vector3 Cross(const Vector3 &_pt) const
Return the cross product of this vector and pt.
Definition: Types.hh:247
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:697
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:717
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:728
friend std::ostream & operator<<(std::ostream &_out, const Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:182
void SetFromEuler(const Vector3 &_vec)
Set the quaternion from Euler angles.
Definition: Types.hh:458
Encapsulates a position and rotation in three space.
Definition: Types.hh:598
#define SDF_DEPRECATED(version)
Definition: Types.hh:37
friend std::ostream & operator<<(std::ostream &_out, const Vector2i &_pt)
Stream insertion operator.
Definition: Types.hh:133
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition: Types.hh:69
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Types.hh:223
friend std::ostream & operator<<(std::ostream &_out, const Pose &_pose)
Stream insertion operator.
Definition: Types.hh:629
static Quaternion EulerToQuaternion(double _x, double _y, double _z)
Convert euler angles to quatern.
Definition: Types.hh:354
float g
Green value.
Definition: Types.hh:110
Pose operator*(const Pose &pose)
Multiplication operator.
Definition: Types.hh:652
Quaternion GetInverse() const
Get the inverse of this quaternion.
Definition: Types.hh:394
double y
y data
Definition: Types.hh:216
Vector2d(double _x=0.0, double _y=0.0)
Constructor.
Definition: Types.hh:175
float a
Alpha value.
Definition: Types.hh:116
Vector3 operator+(const Vector3 &_v) const
Addition operator.
Definition: Types.hh:240
int32_t nsec
Nanoseconds.
Definition: Types.hh:749