18 #ifndef _SDF_TYPES_HH_
19 #define _SDF_TYPES_HH_
30 #define SDF_DEPRECATED(version) __attribute__((deprecated))
31 #define SDF_FORCEINLINE __attribute__((always_inline))
33 #define SDF_DEPRECATED(version)
34 #define SDF_FORCEINLINE __forceinline
36 #define SDF_DEPRECATED(version)
37 #define SDF_FORCEINLINE
54 inline bool equal(
const T &_a,
const T &_b,
55 const T &_epsilon = 1e-6)
57 return std::fabs(_a - _b) <= _epsilon;
68 public:
Color(
float _r = 0.0f,
float _g = 0.0f,
69 float _b = 0.0f,
float _a = 1.0f)
70 : r(_r), g(_g), b(_b), a(_a) {}
76 public:
friend std::ostream &operator<< (std::ostream &_out,
79 _out << _pt.
r <<
" " << _pt.
g <<
" " << _pt.
b <<
" " << _pt.
a;
86 public:
friend std::istream &operator>> (std::istream &_in,
Color &_pt)
89 _in.setf(std::ios_base::skipws);
90 _in >> _pt.
r >> _pt.
g >> _pt.
b >> _pt.
a;
97 public:
bool operator ==(
const Color &_clr)
const
99 return equal(this->r, _clr.
r) &&
135 _out << _pt.
x <<
" " << _pt.
y;
147 _in.setf(std::ios_base::skipws);
148 _in >> _pt.
x >> _pt.
y;
155 public:
bool operator ==(
const Vector2i &_pt)
const
157 return this->x == _pt.
x && this->y == _pt.
y;
184 _out << _pt.
x <<
" " << _pt.
y;
196 _in.setf(std::ios_base::skipws);
197 _in >> _pt.
x >> _pt.
y;
205 public:
bool operator ==(
const Vector2d &_pt)
const
227 : x(_v.x), y(_v.y), z(_v.z) {}
233 public:
Vector3(
double _x = 0.0,
double _y = 0.0,
double _z = 0.0)
234 : x(_x), y(_y), z(_z) {}
241 return Vector3(this->x + _v.
x, this->y + _v.
y, this->z + _v.
z);
250 c.
x = this->y * _pt.
z - this->z * _pt.
y;
251 c.
y = this->z * _pt.
x - this->x * _pt.
z;
252 c.
z = this->x * _pt.
y - this->y * _pt.
x;
262 return Vector3(this->x * _v, this->y * _v, this->z * _v);
272 _out << _pt.
x <<
" " << _pt.
y <<
" " << _pt.
z;
294 return equal(this->x, _pt.
x, 0.001) &&
295 equal(this->y, _pt.
y, 0.001) &&
296 equal(this->z, _pt.
z, 0.001);
307 _in.setf(std::ios_base::skipws);
308 _in >> _pt.
x >> _pt.
y >> _pt.
z;
333 : x(_q.x), y(_q.y), z(_q.z), w(_q.w) {}
335 public:
Quaternion(
const double &_roll,
const double &_pitch,
338 this->SetFromEuler(
Vector3(_roll, _pitch, _yaw));
346 public:
Quaternion(
double _w,
double _x,
double _y,
double _z)
347 : x(_x), y(_y), z(_z), w(_w) {}
355 return EulerToQuaternion(
Vector3(_x, _y, _z));
385 this->w*_q.
w - this->x*_q.
x - this->y*_q.
y - this->z*_q.
z,
386 this->w*_q.
x + this->x*_q.
w + this->y*_q.
z - this->z*_q.
y,
387 this->w*_q.
y - this->x*_q.
z + this->y*_q.
w + this->z*_q.
x,
388 this->w*_q.
z + this->x*_q.
y - this->y*_q.
x + this->z*_q.
w);
396 Quaternion q(this->w, this->x, this->y, this->z);
399 s = q.
w * q.
w + q.
x * q.
x + q.
y * q.
y + q.
z * q.
z;
434 squ = copy.
w * copy.
w;
435 sqx = copy.
x * copy.
x;
436 sqy = copy.
y * copy.
y;
437 sqz = copy.
z * copy.
z;
440 vec.
x = atan2(2 * (copy.
y*copy.
z + copy.
w*copy.
x),
441 squ - sqx - sqy + sqz);
444 double sarg = -2 * (copy.
x*copy.
z - copy.
w * copy.
y);
445 vec.
y = sarg <= -1.0 ? -0.5*M_PI :
446 (sarg >= 1.0 ? 0.5*M_PI : asin(sarg));
449 vec.
z = atan2(2 * (copy.
x*copy.
y + copy.
w*copy.
z),
450 squ + sqx - sqy - sqz);
459 double phi, the, psi;
465 this->w = cos(phi) * cos(the) * cos(psi) + sin(phi) *
467 this->x = sin(phi) * cos(the) * cos(psi) - cos(phi) *
469 this->y = cos(phi) * sin(the) * cos(psi) + sin(phi) *
471 this->z = cos(phi) * cos(the) * sin(psi) - sin(phi) *
482 s = sqrt(this->w * this->w + this->x * this->x +
508 tmp = (*this) * (tmp * this->GetInverse());
520 _out << v.
x <<
" " << v.y <<
" " << v.z;
529 Vector3 qvec(this->x, this->y, this->z);
531 uuv = qvec.
Cross(uv);
532 uv *= (2.0f * this->w);
535 return _v + uv + uuv;
545 double roll, pitch, yaw;
548 _in.setf(std::ios_base::skipws);
549 _in >> roll >> pitch >> yaw;
561 return this->GetAsEuler() == _qt.
GetAsEuler();
566 if (!std::isfinite(this->x))
568 if (!std::isfinite(this->y))
570 if (!std::isfinite(this->z))
572 if (!std::isfinite(this->w))
575 if (
equal(this->w, 0.0) &&
equal(this->x, 0.0) &&
601 :pos(0, 0, 0), rot(1, 0, 0, 0)
608 : pos(_pos), rot(_rot) {}
617 public:
Pose(
double _x,
double _y,
double _z,
618 double _roll,
double _pitch,
double _yaw)
619 : pos(_x, _y, _z), rot(_roll, _pitch, _yaw)
631 _out << _pose.
pos <<
" " << _pose.
rot;
643 _in.setf(std::ios_base::skipws);
644 _in >> _pose.
pos >> _pose.
rot;
653 return Pose(this->CoordPositionAdd(pose), pose.
rot * this->rot);
672 result.
x = _pose.
pos.
x + tmp.
x;
673 result.
y = _pose.
pos.
y + tmp.
y;
674 result.
z = _pose.
pos.
z + tmp.
z;
682 public:
bool operator ==(
const Pose &_pose)
const
684 return this->pos == _pose.
pos && this->rot == _pose.
rot;
707 public:
Time(int32_t _sec, int32_t _nsec)
708 : sec(_sec), nsec(_nsec)
719 _out << _time.
sec <<
" " << _time.
nsec;
731 _in.setf(std::ios_base::skipws);
732 _in >> _time.
sec >> _time.
nsec;
739 public:
bool operator ==(
const Time &_time)
const
741 return this->sec == _time.
sec && this->nsec == _time.
nsec;
Generic double x, y vector.
Definition: Types.hh:169
Quaternion operator*(const Quaternion &_q) const
Multiplication operator.
Definition: Types.hh:382
friend std::istream & operator>>(std::istream &_in, Pose &_pose)
Stream extraction operator.
Definition: Types.hh:639
friend std::ostream & operator<<(std::ostream &_out, const Quaternion &_q)
Stream insertion operator.
Definition: Types.hh:516
bool operator==(const sdf::Vector3 &_pt) const
Equal to operator.
Definition: Types.hh:292
friend std::istream & operator>>(std::istream &_in, Quaternion &_q)
Stream extraction operator.
Definition: Types.hh:542
Vector3 RotateVector(const Vector3 &_vec) const
Rotate a vector using the quaternion.
Definition: Types.hh:505
Quaternion()
Default Constructor.
Definition: Types.hh:327
Quaternion(double _w, double _x, double _y, double _z)
Constructor.
Definition: Types.hh:346
double z
z data
Definition: Types.hh:589
float b
Blue value.
Definition: Types.hh:112
int32_t sec
Seconds.
Definition: Types.hh:745
double y
y Data
Definition: Types.hh:316
friend std::istream & operator>>(std::istream &_in, Vector3 &_pt)
Stream extraction operator.
Definition: Types.hh:303
void Normalize()
Normalize the quaternion.
Definition: Types.hh:478
Vector2i(int _x=0, int _y=0)
Constructor.
Definition: Types.hh:125
int x
x data
Definition: Types.hh:161
Vector3 operator*(double _v) const
Multiplication operator.
Definition: Types.hh:260
Vector3 GetAsEuler() const
Return the rotation in Euler angles.
Definition: Types.hh:422
double x
x Data
Definition: Types.hh:313
A quaternion class.
Definition: Types.hh:324
double x
x data
Definition: Types.hh:583
friend std::istream & operator>>(std::istream &_in, Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:192
double z
z Data
Definition: Types.hh:319
Vector3 pos
Position data.
Definition: Types.hh:688
double x
x data
Definition: Types.hh:212
static Quaternion EulerToQuaternion(const Vector3 &_vec)
Convert euler angles to quatern.
Definition: Types.hh:360
Generic integer x, y vector.
Definition: Types.hh:120
Pose(Vector3 _pos, Quaternion _rot)
Constructor.
Definition: Types.hh:607
double mass
Definition: Types.hh:754
Vector3(double _x=0.0, double _y=0.0, double _z=0.0)
Constructor.
Definition: Types.hh:233
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:54
Pose()
Constructor.
Definition: Types.hh:600
Vector3 CoordPositionAdd(const Pose &_pose) const
Add one point to another: result = this + pose.
Definition: Types.hh:659
#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:617
Time()
Constructor.
Definition: Types.hh:699
Vector3 operator*(const Vector3 &_v) const
Vector3 multiplication operator.
Definition: Types.hh:526
SDFORMAT_VISIBLE const char * winGetEnv(const char *_name)
Windows equivalent of getEnv.
Vector3(const Vector3 &_v)
Copy constructor.
Definition: Types.hh:226
int y
y data
Definition: Types.hh:164
const Vector3 & operator*=(double _v)
Multiplication by a double.
Definition: Types.hh:279
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:707
friend std::istream & operator>>(std::istream &_in, Vector2i &_pt)
Stream extraction operator.
Definition: Types.hh:143
Defines a color.
Definition: Types.hh:61
Quaternion rot
Orientation data.
Definition: Types.hh:691
float r
Red value.
Definition: Types.hh:106
double y
y data
Definition: Types.hh:586
double w
w data
Definition: Types.hh:592
friend std::ostream & operator<<(std::ostream &_out, const Vector3 &_pt)
Stream insertion operator.
Definition: Types.hh:269
A class for inertial information about a link.
Definition: Types.hh:752
void Correct()
Definition: Types.hh:564
Quaternion(const Quaternion &_q)
Copy constructor.
Definition: Types.hh:332
Quaternion(const double &_roll, const double &_pitch, const double &_yaw)
Definition: Types.hh:335
Vector3 Cross(const Vector3 &_pt) const
Return the cross product of this vector and pt.
Definition: Types.hh:246
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:696
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:716
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:727
friend std::ostream & operator<<(std::ostream &_out, const Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:181
void SetFromEuler(const Vector3 &_vec)
Set the quaternion from Euler angles.
Definition: Types.hh:457
Encapsulates a position and rotation in three space.
Definition: Types.hh:597
#define SDF_DEPRECATED(version)
Definition: Types.hh:36
friend std::ostream & operator<<(std::ostream &_out, const Vector2i &_pt)
Stream insertion operator.
Definition: Types.hh:132
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition: Types.hh:68
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Types.hh:222
friend std::ostream & operator<<(std::ostream &_out, const Pose &_pose)
Stream insertion operator.
Definition: Types.hh:628
static Quaternion EulerToQuaternion(double _x, double _y, double _z)
Convert euler angles to quatern.
Definition: Types.hh:353
float g
Green value.
Definition: Types.hh:109
Pose operator*(const Pose &pose)
Multiplication operator.
Definition: Types.hh:651
Quaternion GetInverse() const
Get the inverse of this quaternion.
Definition: Types.hh:393
double y
y data
Definition: Types.hh:215
Vector2d(double _x=0.0, double _y=0.0)
Constructor.
Definition: Types.hh:174
float a
Alpha value.
Definition: Types.hh:115
Vector3 operator+(const Vector3 &_v) const
Addition operator.
Definition: Types.hh:239
int32_t nsec
Nanoseconds.
Definition: Types.hh:748