S3New.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00032
00033
00034 #ifndef __S3_H_
00035 #define __S3_H_
00036
00037 #ifdef MIP_HOST_APPLE
00038 #include <applePatch.h>
00039 #endif
00040
00041 #include <stdio.h>
00042 #include <math.h>
00043 #include <vector>
00044 #include <iostream>
00045 #include <string>
00046 #include <sstream>
00047 #include <sys/time.h>
00048 #include <sys/select.h>
00049 #include <assert.h>
00050
00051
00052 #ifdef FOUND_BOOST_SER
00053 #include <boost/serialization/vector.hpp>
00054 #include <boost/archive/text_iarchive.hpp>
00055 #include <boost/archive/text_oarchive.hpp>
00056 #endif
00057
00058
00059
00060 #include <Types.h>
00061 #include <Association.h>
00062 #include <S1.h>
00063
00064 using namespace std;
00065
00070 class Orientation3D {
00071
00072 private:
00073 #ifdef FOUND_BOOST_SER
00074 friend class boost::serialization::access;
00075 template<class Archive>
00076 void serialize(Archive & ar, const unsigned int version){
00077 ar & _q0;
00078 ar & _q1;
00079 ar & _q2;
00080 ar & _q3;
00081 }
00082 #endif
00083
00084
00085
00086
00087 protected:
00088
00089
00090
00091
00092 bool _normalize();
00093
00094 Decimal _q[4];
00095
00096 public:
00098 Orientation3D();
00099
00101 Orientation3D(Position3D quatVectPart,Decimal quatScalarPart);
00102
00104 Orientation3D(Position3D axis,Angle angle);
00105
00107 Orientation3D& operator*=(const Orientation3D& a);
00108
00109
00111 const Orientation3D operator*(const Orientation3D &other) const;
00112
00114 Orientation3D(Angle roll_in,Angle pitch_in, Angle yaw_in);
00115
00117 Orientation3D(const Orientation3D& p) { _roll = p._roll; _pitch = p._pitch; _yaw = p._yaw;}
00119 Orientation3D& operator=(const Orientation3D& rhs){
00120 if (this != &rhs){
00121 _roll = rhs._roll;
00122 _pitch = rhs._pitch;
00123 _yaw = rhs._yaw;
00124 }
00125 return *this;
00126 }
00128 Orientation3D& operator+=(const Orientation3D& a) {
00129 _roll = _roll + a._roll;
00130 _pitch = _pitch + a._pitch;
00131 _yaw = _yaw + a._yaw;
00132 return *this;
00133 }
00135 Orientation3D& operator-=(const Orientation3D& a) {
00136 _roll = _roll - a._roll;
00137 _pitch = _pitch - a._pitch;
00138 _yaw = _yaw - a._yaw;
00139 return *this;
00140 }
00142 Orientation3D& operator*=(const Decimal scalar) {
00143 _roll = _roll*scalar;
00144 _pitch = _pitch*scalar;
00145 _yaw = _yaw*scalar;
00146 return *this;;
00147 }
00149 Orientation3D& operator/=(const Decimal scalar) {
00150 _roll = _roll.dCast()/scalar;
00151 _pitch = _pitch.dCast()/scalar;
00152 _yaw = _yaw.dCast()/scalar;
00153 return *this;;
00154 }
00155
00157 const Orientation3D operator+(const Orientation3D &other) const {
00158 return Orientation3D(*this) += other;
00159 }
00161 const Orientation3D operator-(const Orientation3D &other) const {
00162 return Orientation3D(*this) -= other;
00163 }
00164
00168 const Orientation3D operator*(const Decimal scalar) {
00169 return Orientation3D(*this) *= scalar;
00170 }
00174 const Orientation3D operator/(const Decimal scalar) {
00175 return Orientation3D(*this) /= scalar;
00176 }
00178 bool operator==(const Orientation3D &other) const {
00179 if( (_roll == other._roll) && (_pitch == other._pitch) && (_yaw == other._yaw) )
00180 return true;
00181 else return false;
00182 }
00184 bool operator!=(const Orientation3D &other) const {
00185 return !(*this == other);
00186 }
00188 Orientation3D minimum(const Orientation3D& p) {
00189 return Orientation3D(min(_roll.dCast(),p._roll.dCast()),min(_pitch.dCast(),p._pitch.dCast()),min(_yaw.dCast(),p._yaw.dCast()));
00190 }
00192 Orientation3D maximum(const Orientation3D& p) {
00193 return Orientation3D(max(_roll.dCast(),p._roll.dCast()),max(_pitch.dCast(),p._pitch.dCast()),max(_yaw.dCast(),p._yaw.dCast()));
00194 }
00196 Angle roll() {
00197 return _roll;
00198 }
00199 Angle pitch() {
00200 return _pitch;
00201 }
00202 Angle yaw() {
00203 return _yaw;
00204 }
00205
00207 void setRoll(Angle roll){
00208 _roll = roll;
00209 }
00210
00212 void setPitch(Angle pitch){
00213 _pitch = pitch;
00214 }
00215
00217 void setYaw(Angle yaw){
00218 _yaw = yaw;
00219 }
00220
00222 vector<Decimal> vectPi();
00223
00225 vector<Decimal> vectDeg180();
00226
00228 vector<Decimal> vect2Pi();
00229
00231 vector<Decimal> vectDeg360();
00232
00234 string print(PrintTypes type = PRINT_TYPE_WITH_UNITS){
00235
00236
00237
00238
00239
00240 stringstream s;
00241 s.precision(9);
00242 s.setf(ios::fixed,ios::floatfield);
00243 switch (type){
00244 case PRINT_TYPE_PLAIN:
00245 s << _roll.dCast() << " " << _pitch.dCast() << " " << _yaw.dCast() << " " ;
00246 break;
00247 case PRINT_TYPE_WITH_UNITS:
00248 default:
00249 s << "(" << _roll.print() << ", " << _pitch.print() << ", " << _yaw.print() << ")" ;
00250 break;
00251 }
00252 return s.str();
00253
00254 }
00255 };
00256
00257
00258 #endif
00259
00260
00261
00262