18 #ifndef _SDF_TYPES_HH_
19 #define _SDF_TYPES_HH_
27 #define SDF_DEPRECATED(version) __attribute__((deprecated))
28 #define SDF_FORCEINLINE __attribute__((always_inline))
30 #define SDF_DEPRECATED(version)
31 #define SDF_FORCEINLINE __forceinline
33 #define SDF_DEPRECATED(version)
34 #define SDF_FORCEINLINE
44 inline bool equal(
const T &_a,
const T &_b,
45 const T &_epsilon = 1e-6)
47 return std::fabs(_a - _b) <= _epsilon;
58 public:
Color(
double _r = 0.0,
double _g = 0.0,
59 double _b = 0.0,
double _a = 1.0)
60 : r(_r), g(_g), b(_b), a(_a) {}
66 public:
friend std::ostream &operator<< (std::ostream &_out,
69 _out << _pt.
r <<
" " << _pt.
g <<
" " << _pt.
b <<
" " << _pt.
a;
76 public:
friend std::istream &operator>> (std::istream &_in,
Color &_pt)
79 _in.setf(std::ios_base::skipws);
80 _in >> _pt.
r >> _pt.
g >> _pt.
b >> _pt.
a;
87 public:
bool operator ==(
const Color &_clr)
const
89 return equal(this->r, _clr.
r) &&
124 _out << _pt.
x <<
" " << _pt.
y;
136 _in.setf(std::ios_base::skipws);
137 _in >> _pt.
x >> _pt.
y;
144 public:
bool operator ==(
const Vector2i &_pt)
const
146 return this->x == _pt.
x && this->y == _pt.
y;
172 _out << _pt.
x <<
" " << _pt.
y;
184 _in.setf(std::ios_base::skipws);
185 _in >> _pt.
x >> _pt.
y;
193 public:
bool operator ==(
const Vector2d &_pt)
const
214 : x(_v.x), y(_v.y), z(_v.z) {}
220 public:
Vector3(
double _x = 0.0,
double _y = 0.0,
double _z = 0.0)
221 : x(_x), y(_y), z(_z) {}
228 return Vector3(this->x + _v.
x, this->y + _v.
y, this->z + _v.
z);
237 c.
x = this->y * _pt.
z - this->z * _pt.
y;
238 c.
y = this->z * _pt.
x - this->x * _pt.
z;
239 c.
z = this->x * _pt.
y - this->y * _pt.
x;
249 return Vector3(this->x * _v, this->y * _v, this->z * _v);
259 _out << _pt.
x <<
" " << _pt.
y <<
" " << _pt.
z;
281 return equal(this->x, _pt.
x, 0.001) &&
282 equal(this->y, _pt.
y, 0.001) &&
283 equal(this->z, _pt.
z, 0.001);
294 _in.setf(std::ios_base::skipws);
295 _in >> _pt.
x >> _pt.
y >> _pt.
z;
319 : x(_q.x), y(_q.y), z(_q.z), w(_q.w) {}
321 public:
Quaternion(
const double &_roll,
const double &_pitch,
324 this->SetFromEuler(
Vector3(_roll, _pitch, _yaw));
332 public:
Quaternion(
double _w,
double _x,
double _y,
double _z)
333 : x(_x), y(_y), z(_z), w(_w) {}
341 return EulerToQuaternion(
Vector3(_x, _y, _z));
371 this->w*_q.
w - this->x*_q.
x - this->y*_q.
y - this->z*_q.
z,
372 this->w*_q.
x + this->x*_q.
w + this->y*_q.
z - this->z*_q.
y,
373 this->w*_q.
y - this->x*_q.
z + this->y*_q.
w + this->z*_q.
x,
374 this->w*_q.
z + this->x*_q.
y - this->y*_q.
x + this->z*_q.
w);
382 Quaternion q(this->w, this->x, this->y, this->z);
385 s = q.
w * q.
w + q.
x * q.
x + q.
y * q.
y + q.
z * q.
z;
420 squ = copy.
w * copy.
w;
421 sqx = copy.
x * copy.
x;
422 sqy = copy.
y * copy.
y;
423 sqz = copy.
z * copy.
z;
426 vec.
x = atan2(2 * (copy.
y*copy.
z + copy.
w*copy.
x),
427 squ - sqx - sqy + sqz);
430 double sarg = -2 * (copy.
x*copy.
z - copy.
w * copy.
y);
431 vec.
y = sarg <= -1.0 ? -0.5*M_PI :
432 (sarg >= 1.0 ? 0.5*M_PI : asin(sarg));
435 vec.
z = atan2(2 * (copy.
x*copy.
y + copy.
w*copy.
z),
436 squ + sqx - sqy - sqz);
445 double phi, the, psi;
451 this->w = cos(phi) * cos(the) * cos(psi) + sin(phi) *
453 this->x = sin(phi) * cos(the) * cos(psi) - cos(phi) *
455 this->y = cos(phi) * sin(the) * cos(psi) + sin(phi) *
457 this->z = cos(phi) * cos(the) * sin(psi) - sin(phi) *
468 s = sqrt(this->w * this->w + this->x * this->x +
494 tmp = (*this) * (tmp * this->GetInverse());
506 _out << v.
x <<
" " << v.y <<
" " << v.z;
515 Vector3 qvec(this->x, this->y, this->z);
517 uuv = qvec.
Cross(uv);
518 uv *= (2.0f * this->w);
521 return _v + uv + uuv;
531 double roll, pitch, yaw;
534 _in.setf(std::ios_base::skipws);
535 _in >> roll >> pitch >> yaw;
547 return this->GetAsEuler() == _qt.
GetAsEuler();
552 if (!std::isfinite(this->x))
554 if (!std::isfinite(this->y))
556 if (!std::isfinite(this->z))
558 if (!std::isfinite(this->w))
561 if (
equal(this->w, 0.0) &&
equal(this->x, 0.0) &&
586 :pos(0, 0, 0), rot(1, 0, 0, 0)
593 : pos(_pos), rot(_rot) {}
602 public:
Pose(
double _x,
double _y,
double _z,
603 double _roll,
double _pitch,
double _yaw)
604 : pos(_x, _y, _z), rot(_roll, _pitch, _yaw)
616 _out << _pose.
pos <<
" " << _pose.
rot;
628 _in.setf(std::ios_base::skipws);
629 _in >> _pose.
pos >> _pose.
rot;
638 return Pose(this->CoordPositionAdd(pose), pose.
rot * this->rot);
657 result.
x = _pose.
pos.
x + tmp.
x;
658 result.
y = _pose.
pos.
y + tmp.
y;
659 result.
z = _pose.
pos.
z + tmp.
z;
667 public:
bool operator ==(
const Pose &_pose)
const
669 return this->pos == _pose.
pos && this->rot == _pose.
rot;
692 public:
Time(int32_t _sec, int32_t _nsec)
693 : sec(_sec), nsec(_nsec)
704 _out << _time.
sec <<
" " << _time.
nsec;
716 _in.setf(std::ios_base::skipws);
717 _in >> _time.
sec >> _time.
nsec;
724 public:
bool operator ==(
const Time &_time)
const
726 return this->sec == _time.
sec && this->nsec == _time.
nsec;
Generic double x, y vector.
Definition: Types.hh:157
Quaternion operator*(const Quaternion &_q) const
Multiplication operator.
Definition: Types.hh:368
friend std::istream & operator>>(std::istream &_in, Pose &_pose)
Stream extraction operator.
Definition: Types.hh:624
friend std::ostream & operator<<(std::ostream &_out, const Quaternion &_q)
Stream insertion operator.
Definition: Types.hh:502
bool operator==(const sdf::Vector3 &_pt) const
Equal to operator.
Definition: Types.hh:279
friend std::istream & operator>>(std::istream &_in, Quaternion &_q)
Stream extraction operator.
Definition: Types.hh:528
Vector3 RotateVector(const Vector3 &_vec) const
Rotate a vector using the quaternion.
Definition: Types.hh:491
Quaternion()
Default Constructor.
Definition: Types.hh:313
Quaternion(double _w, double _x, double _y, double _z)
Constructor.
Definition: Types.hh:332
double z
z data
Definition: Types.hh:575
float b
Blue value.
Definition: Types.hh:102
int32_t sec
Seconds.
Definition: Types.hh:730
double y
y Data
Definition: Types.hh:303
friend std::istream & operator>>(std::istream &_in, Vector3 &_pt)
Stream extraction operator.
Definition: Types.hh:290
void Normalize()
Normalize the quaternion.
Definition: Types.hh:464
Vector2i(int _x=0, int _y=0)
Constructor.
Definition: Types.hh:114
int x
x data
Definition: Types.hh:150
Vector3 operator*(double _v) const
Multiplication operator.
Definition: Types.hh:247
Vector3 GetAsEuler() const
Return the rotation in Euler angles.
Definition: Types.hh:408
double x
x Data
Definition: Types.hh:300
A quaternion class.
Definition: Types.hh:310
double x
x data
Definition: Types.hh:569
friend std::istream & operator>>(std::istream &_in, Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:180
double z
z Data
Definition: Types.hh:306
Vector3 pos
Position data.
Definition: Types.hh:673
double x
x data
Definition: Types.hh:200
static Quaternion EulerToQuaternion(const Vector3 &_vec)
Convert euler angles to quatern.
Definition: Types.hh:346
Generic integer x, y vector.
Definition: Types.hh:109
Pose(Vector3 _pos, Quaternion _rot)
Constructor.
Definition: Types.hh:592
double mass
Definition: Types.hh:739
Vector3(double _x=0.0, double _y=0.0, double _z=0.0)
Constructor.
Definition: Types.hh:220
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:44
Pose()
Constructor.
Definition: Types.hh:585
Vector3 CoordPositionAdd(const Pose &_pose) const
Add one point to another: result = this + pose.
Definition: Types.hh:644
#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:602
Time()
Constructor.
Definition: Types.hh:684
Vector3 operator*(const Vector3 &_v) const
Vector3 multiplication operator.
Definition: Types.hh:512
Vector3(const Vector3 &_v)
Copy constructor.
Definition: Types.hh:213
int y
y data
Definition: Types.hh:153
const Vector3 & operator*=(double _v)
Multiplication by a double.
Definition: Types.hh:266
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:692
friend std::istream & operator>>(std::istream &_in, Vector2i &_pt)
Stream extraction operator.
Definition: Types.hh:132
Defines a color.
Definition: Types.hh:51
Quaternion rot
Orientation data.
Definition: Types.hh:676
float r
Red value.
Definition: Types.hh:96
double y
y data
Definition: Types.hh:572
double w
w data
Definition: Types.hh:578
friend std::ostream & operator<<(std::ostream &_out, const Vector3 &_pt)
Stream insertion operator.
Definition: Types.hh:256
A class for inertial information about a link.
Definition: Types.hh:737
void Correct()
Definition: Types.hh:550
namespace for Simulation Description Format parser
Definition: Console.hh:29
Quaternion(const Quaternion &_q)
Copy constructor.
Definition: Types.hh:318
Quaternion(const double &_roll, const double &_pitch, const double &_yaw)
Definition: Types.hh:321
Vector3 Cross(const Vector3 &_pt) const
Return the cross product of this vector and pt.
Definition: Types.hh:233
Color(double _r=0.0, double _g=0.0, double _b=0.0, double _a=1.0)
Constructor.
Definition: Types.hh:58
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:681
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:701
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:712
friend std::ostream & operator<<(std::ostream &_out, const Vector2d &_pt)
Stream extraction operator.
Definition: Types.hh:169
void SetFromEuler(const Vector3 &_vec)
Set the quaternion from Euler angles.
Definition: Types.hh:443
Encapsulates a position and rotation in three space.
Definition: Types.hh:582
friend std::ostream & operator<<(std::ostream &_out, const Vector2i &_pt)
Stream insertion operator.
Definition: Types.hh:121
The Vector3 class represents the generic vector containing 3 elements.
Definition: Types.hh:209
friend std::ostream & operator<<(std::ostream &_out, const Pose &_pose)
Stream insertion operator.
Definition: Types.hh:613
static Quaternion EulerToQuaternion(double _x, double _y, double _z)
Convert euler angles to quatern.
Definition: Types.hh:339
float g
Green value.
Definition: Types.hh:99
Pose operator*(const Pose &pose)
Multiplication operator.
Definition: Types.hh:636
Quaternion GetInverse() const
Get the inverse of this quaternion.
Definition: Types.hh:379
double y
y data
Definition: Types.hh:203
Vector2d(double _x=0.0, double _y=0.0)
Constructor.
Definition: Types.hh:162
float a
Alpha value.
Definition: Types.hh:105
Vector3 operator+(const Vector3 &_v) const
Addition operator.
Definition: Types.hh:226
int32_t nsec
Nanoseconds.
Definition: Types.hh:733