18 #ifndef _SDF_TYPES_HH_ 
   19 #define _SDF_TYPES_HH_ 
   25 #define SDF_DEPRECATED(version) __attribute__((deprecated)) 
   26 #define SDF_FORCEINLINE __attribute__((always_inline)) 
   28 #define SDF_DEPRECATED(version) 
   29 #define SDF_FORCEINLINE __forceinline 
   31 #define SDF_DEPRECATED(version) 
   32 #define SDF_FORCEINLINE 
   42   inline bool equal(
const T &_a, 
const T &_b,
 
   43                     const T &_epsilon = 1e-6)
 
   45     return std::fabs(_a - _b) <= _epsilon;
 
   56     public: 
Color(
double _r = 0.0, 
double _g = 0.0,
 
   57                 double _b = 0.0, 
double _a = 1.0)
 
   58             : 
r(_r), 
g(_g), 
b(_b), 
a(_a) {}
 
   64     public: 
friend std::ostream &
operator<< (std::ostream &_out,
 
   67               _out << _pt.
r << 
" " << _pt.
g << 
" " << _pt.
b << 
" " << _pt.
a;
 
   77       _in.setf(std::ios_base::skipws);
 
   78       _in >> _pt.
r >> _pt.
g >> _pt.
b >> _pt.
a;
 
   87               return equal(this->
r, _clr.
r) &&
 
  122       _out << _pt.
x << 
" " << _pt.
y;
 
  134       _in.setf(std::ios_base::skipws);
 
  135       _in >> _pt.
x >> _pt.
y;
 
  144               return this->
x == _pt.
x && this->
y == _pt.
y;
 
  170       _out << _pt.
x << 
" " << _pt.
y;
 
  182       _in.setf(std::ios_base::skipws);
 
  183       _in >> _pt.
x >> _pt.
y;
 
  212             : 
x(_v.
x), 
y(_v.
y), 
z(_v.
z) {}
 
  218     public: 
Vector3(
double _x = 0.0, 
double _y = 0.0, 
double _z = 0.0)
 
  219             : 
x(_x), 
y(_y), 
z(_z) {}
 
  226       return Vector3(this->
x + _v.
x, this->y + _v.
y, this->z + _v.
z);
 
  235               c.
x = this->
y * _pt.
z - this->
z * _pt.
y;
 
  236               c.
y = this->
z * _pt.
x - this->
x * _pt.
z;
 
  237               c.
z = this->
x * _pt.
y - this->
y * _pt.
x;
 
  247               return Vector3(this->
x * _v, this->
y * _v, this->
z * _v);
 
  257       _out << _pt.
x << 
" " << _pt.
y << 
" " << _pt.
z;
 
  279               return equal(this->
x, _pt.
x, 0.001) &&
 
  280                      equal(this->
y, _pt.
y, 0.001) &&
 
  292       _in.setf(std::ios_base::skipws);
 
  293       _in >> _pt.
x >> _pt.
y >> _pt.
z;
 
  317             : 
x(_q.
x), 
y(_q.
y), 
z(_q.
z), 
w(_q.
w) {}
 
  319     public: 
Quaternion(
const double &_roll, 
const double &_pitch,
 
  330     public: 
Quaternion(
double _w, 
double _x, 
double _y, 
double _z)
 
  331             : 
x(_x), 
y(_y), 
z(_z), 
w(_w) {}
 
  369                   this->
w*_q.
w - this->x*_q.
x - this->y*_q.
y - this->z*_q.
z,
 
  370                   this->w*_q.
x + this->x*_q.
w + this->y*_q.
z - this->z*_q.
y,
 
  371                   this->w*_q.
y - this->x*_q.
z + this->y*_q.
w + this->z*_q.
x,
 
  372                   this->w*_q.
z + this->x*_q.
y - this->y*_q.
x + this->z*_q.
w);
 
  383               s = q.
w * q.
w + q.
x * q.
x + q.
y * q.
y + q.
z * q.
z;
 
  418               squ = copy.
w * copy.
w;
 
  419               sqx = copy.
x * copy.
x;
 
  420               sqy = copy.
y * copy.
y;
 
  421               sqz = copy.
z * copy.
z;
 
  424               vec.
x = atan2(2 * (copy.
y*copy.
z + copy.
w*copy.
x),
 
  425                   squ - sqx - sqy + sqz);
 
  428               double sarg = -2 * (copy.
x*copy.
z - copy.
w * copy.
y);
 
  429               vec.
y = sarg <= -1.0 ? -0.5*M_PI :
 
  430                 (sarg >= 1.0 ? 0.5*M_PI : asin(sarg));
 
  433               vec.
z = atan2(2 * (copy.
x*copy.
y + copy.
w*copy.
z),
 
  434                   squ + sqx - sqy - sqz);
 
  443               double phi, the, psi;
 
  449               this->
w = cos(phi) * cos(the) * cos(psi) + sin(phi) *
 
  451               this->
x = sin(phi) * cos(the) * cos(psi) - cos(phi) *
 
  453               this->
y = cos(phi) * sin(the) * cos(psi) + sin(phi) *
 
  455               this->
z = cos(phi) * cos(the) * sin(psi) - sin(phi) *
 
  466               s = sqrt(this->
w * this->
w + this->
x * this->
x +
 
  504       _out << v.
x << 
" " << v.y << 
" " << v.z;
 
  515               uuv = qvec.
Cross(uv);
 
  516               uv *= (2.0f * this->
w);
 
  519               return _v + uv + uuv;
 
  529       double roll, pitch, yaw;
 
  532       _in.setf(std::ios_base::skipws);
 
  533       _in >> roll >> pitch >> yaw;
 
  550               if (!std::isfinite(this->
x))
 
  552               if (!std::isfinite(this->
y))
 
  554               if (!std::isfinite(this->
z))
 
  556               if (!std::isfinite(this->
w))
 
  584             :
pos(0, 0, 0), 
rot(1, 0, 0, 0)
 
  600     public: 
Pose(
double _x, 
double _y, 
double _z,
 
  601                  double _roll, 
double _pitch, 
double _yaw)
 
  602             : 
pos(_x, _y, _z), 
rot(_roll, _pitch, _yaw)
 
  614               _out << _pose.
pos << 
" " << _pose.
rot;
 
  626             _in.setf(std::ios_base::skipws);
 
  627             _in >> _pose.
pos >> _pose.
rot;
 
  655               result.
x = _pose.
pos.
x + tmp.
x;
 
  656               result.
y = _pose.
pos.
y + tmp.
y;
 
  657               result.
z = _pose.
pos.
z + tmp.
z;
 
  667               return this->
pos == _pose.
pos && this->
rot == _pose.
rot;
 
  690     public: 
Time(int32_t _sec, int32_t _nsec)
 
  702               _out << _time.
sec << 
" " << _time.
nsec;
 
  714               _in.setf(std::ios_base::skipws);
 
  715               _in >> _time.
sec >> _time.
nsec;
 
Generic double x, y vector. 
Definition: Types.hh:155
Quaternion operator*(const Quaternion &_q) const 
Multiplication operator. 
Definition: Types.hh:366
friend std::istream & operator>>(std::istream &_in, Pose &_pose)
Stream extraction operator. 
Definition: Types.hh:622
friend std::ostream & operator<<(std::ostream &_out, const Quaternion &_q)
Stream insertion operator. 
Definition: Types.hh:500
bool operator==(const sdf::Vector3 &_pt) const 
Equal to operator. 
Definition: Types.hh:277
bool operator==(const Vector2i &_pt) const 
Equality operator. 
Definition: Types.hh:142
friend std::istream & operator>>(std::istream &_in, Quaternion &_q)
Stream extraction operator. 
Definition: Types.hh:526
Vector3 RotateVector(const Vector3 &_vec) const 
Rotate a vector using the quaternion. 
Definition: Types.hh:489
Quaternion()
Default Constructor. 
Definition: Types.hh:311
Quaternion(double _w, double _x, double _y, double _z)
Constructor. 
Definition: Types.hh:330
Quaternion & operator=(const Quaternion &_qt)
Equal operator. 
Definition: Types.hh:353
double z
z data 
Definition: Types.hh:573
float b
Blue value. 
Definition: Types.hh:100
int32_t sec
Seconds. 
Definition: Types.hh:728
double y
y Data 
Definition: Types.hh:301
friend std::istream & operator>>(std::istream &_in, Vector3 &_pt)
Stream extraction operator. 
Definition: Types.hh:288
void Normalize()
Normalize the quaternion. 
Definition: Types.hh:462
Vector2i(int _x=0, int _y=0)
Constructor. 
Definition: Types.hh:112
int x
x data 
Definition: Types.hh:148
Vector3 operator*(double _v) const 
Multiplication operator. 
Definition: Types.hh:245
Vector3 GetAsEuler() const 
Return the rotation in Euler angles. 
Definition: Types.hh:406
double x
x Data 
Definition: Types.hh:298
bool operator==(const Vector2d &_pt) const 
Equal to operator. 
Definition: Types.hh:191
A quaternion class. 
Definition: Types.hh:308
double x
x data 
Definition: Types.hh:567
friend std::istream & operator>>(std::istream &_in, Vector2d &_pt)
Stream extraction operator. 
Definition: Types.hh:178
bool operator==(const Pose &_pose) const 
Equality operator. 
Definition: Types.hh:665
double z
z Data 
Definition: Types.hh:304
Vector3 pos
Position data. 
Definition: Types.hh:671
double x
x data 
Definition: Types.hh:198
static Quaternion EulerToQuaternion(const Vector3 &_vec)
Convert euler angles to quatern. 
Definition: Types.hh:344
Generic integer x, y vector. 
Definition: Types.hh:107
Pose(Vector3 _pos, Quaternion _rot)
Constructor. 
Definition: Types.hh:590
double mass
Definition: Types.hh:737
Vector3(double _x=0.0, double _y=0.0, double _z=0.0)
Constructor. 
Definition: Types.hh:218
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:42
Pose()
Constructor. 
Definition: Types.hh:583
Vector3 CoordPositionAdd(const Pose &_pose) const 
Add one point to another: result = this + pose. 
Definition: Types.hh:642
Pose(double _x, double _y, double _z, double _roll, double _pitch, double _yaw)
Constructor. 
Definition: Types.hh:600
Time()
Constructor. 
Definition: Types.hh:682
Vector3 operator*(const Vector3 &_v) const 
Vector3 multiplication operator. 
Definition: Types.hh:510
bool operator==(const Quaternion &_qt) const 
Equal to operator. 
Definition: Types.hh:543
Vector3(const Vector3 &_v)
Copy constructor. 
Definition: Types.hh:211
int y
y data 
Definition: Types.hh:151
const Vector3 & operator*=(double _v)
Multiplication by a double. 
Definition: Types.hh:264
Time(int32_t _sec, int32_t _nsec)
Constructor. 
Definition: Types.hh:690
friend std::istream & operator>>(std::istream &_in, Vector2i &_pt)
Stream extraction operator. 
Definition: Types.hh:130
Defines a color. 
Definition: Types.hh:49
Quaternion rot
Orientation data. 
Definition: Types.hh:674
float r
Red value. 
Definition: Types.hh:94
double y
y data 
Definition: Types.hh:570
double w
w data 
Definition: Types.hh:576
friend std::ostream & operator<<(std::ostream &_out, const Vector3 &_pt)
Stream insertion operator. 
Definition: Types.hh:254
bool operator==(const Time &_time) const 
Equal to operator. 
Definition: Types.hh:722
bool operator==(const Color &_clr) const 
Equality operator. 
Definition: Types.hh:85
A class for inertial information about a link. 
Definition: Types.hh:735
void Correct()
Definition: Types.hh:548
friend std::ostream & operator<<(std::ostream &_out, const Color &_pt)
Stream insertion operator. 
Definition: Types.hh:64
Quaternion(const Quaternion &_q)
Copy constructor. 
Definition: Types.hh:316
Quaternion(const double &_roll, const double &_pitch, const double &_yaw)
Definition: Types.hh:319
Vector3 Cross(const Vector3 &_pt) const 
Return the cross product of this vector and pt. 
Definition: Types.hh:231
Color(double _r=0.0, double _g=0.0, double _b=0.0, double _a=1.0)
Constructor. 
Definition: Types.hh:56
A Time class, can be used to hold wall- or sim-time. 
Definition: Types.hh:679
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator. 
Definition: Types.hh:699
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator. 
Definition: Types.hh:710
friend std::ostream & operator<<(std::ostream &_out, const Vector2d &_pt)
Stream extraction operator. 
Definition: Types.hh:167
void SetFromEuler(const Vector3 &_vec)
Set the quaternion from Euler angles. 
Definition: Types.hh:441
Encapsulates a position and rotation in three space. 
Definition: Types.hh:580
friend std::istream & operator>>(std::istream &_in, Color &_pt)
Stream insertion operator. 
Definition: Types.hh:74
friend std::ostream & operator<<(std::ostream &_out, const Vector2i &_pt)
Stream insertion operator. 
Definition: Types.hh:119
The Vector3 class represents the generic vector containing 3 elements. 
Definition: Types.hh:207
friend std::ostream & operator<<(std::ostream &_out, const Pose &_pose)
Stream insertion operator. 
Definition: Types.hh:611
static Quaternion EulerToQuaternion(double _x, double _y, double _z)
Convert euler angles to quatern. 
Definition: Types.hh:337
float g
Green value. 
Definition: Types.hh:97
Pose operator*(const Pose &pose)
Multiplication operator. 
Definition: Types.hh:634
Quaternion GetInverse() const 
Get the inverse of this quaternion. 
Definition: Types.hh:377
double y
y data 
Definition: Types.hh:201
Vector2d(double _x=0.0, double _y=0.0)
Constructor. 
Definition: Types.hh:160
float a
Alpha value. 
Definition: Types.hh:103
Vector3 operator+(const Vector3 &_v) const 
Addition operator. 
Definition: Types.hh:224
int32_t nsec
Nanoseconds. 
Definition: Types.hh:731