S3.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
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 //BOOST SERIALIZATION
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 #include <R3.h>
00064 // #include <LogTrace.h>
00065 
00066 using namespace std;
00067 
00072 class Orientation3D /*: public MIPObject*/{
00073  
00074  private:
00075 #ifdef FOUND_BOOST_SER
00076   friend class boost::serialization::access;
00077   template<class Archive>
00078     void serialize(Archive & ar, const unsigned int version){
00079    ar & _roll; 
00080    ar & _pitch;
00081    ar & _yaw;
00082     }
00083 #endif
00084  
00085  protected:
00086   Angle _roll;
00087   Angle _pitch;
00088   Angle _yaw;
00089 
00090  public:
00092   Orientation3D() {_roll=0.0; _pitch=0.0; _yaw=0.0;}
00094   Orientation3D(Angle roll_in,Angle pitch_in, Angle yaw_in) {_roll=roll_in; _pitch=pitch_in; _yaw=yaw_in;}
00095   
00096   Orientation3D(Position3D vQuat,Decimal sQuat);
00097   
00099   Orientation3D(const Orientation3D& p) { _roll  = p._roll; _pitch = p._pitch; _yaw   = p._yaw;}
00101   Orientation3D& operator=(const Orientation3D& rhs){
00102    if (this != &rhs){      // Not necessary in this case but it is useful to don't forget it
00103     _roll  = rhs._roll;
00104     _pitch = rhs._pitch;
00105     _yaw   = rhs._yaw;
00106    }
00107    return *this;
00108   }
00110   Orientation3D& operator+=(const Orientation3D& a) {
00111    _roll  = _roll  + a._roll;
00112    _pitch = _pitch + a._pitch;
00113    _yaw   = _yaw   + a._yaw;
00114    return *this;
00115   }
00117   Orientation3D& operator-=(const Orientation3D& a) {
00118    _roll  = _roll  - a._roll;
00119    _pitch = _pitch - a._pitch;
00120    _yaw   = _yaw   - a._yaw;
00121    return *this;
00122   }
00124   Orientation3D& operator*=(const Decimal scalar) {
00125    _roll  = _roll*scalar;
00126    _pitch = _pitch*scalar;
00127    _yaw   = _yaw*scalar;
00128    return *this;;
00129   }
00131   Orientation3D& operator/=(const Decimal scalar) {
00132    _roll  = _roll.dCast2Pi()/scalar;
00133    _pitch = _pitch.dCast2Pi()/scalar;
00134    _yaw   = _yaw.dCast2Pi()/scalar;
00135    return *this;;
00136   }
00137   
00139   Orientation3D operator+(const Orientation3D &other) const {
00140    return Orientation3D(*this) += other;
00141   }
00143   Orientation3D operator-(const Orientation3D &other) const {
00144    return Orientation3D(*this) -= other;
00145   }
00146   
00150   Orientation3D operator*(const Decimal scalar) const {
00151    return Orientation3D(*this) *= scalar;
00152   }
00156   Orientation3D operator/(const Decimal scalar) const {
00157    return Orientation3D(*this) /= scalar;
00158   }
00160   bool operator==(const Orientation3D &other) const {
00161    if( (_roll == other._roll) && (_pitch == other._pitch) && (_yaw == other._yaw) )
00162     return true;
00163    else return false;
00164   }
00166   bool operator!=(const Orientation3D &other) const {
00167    return !(*this == other);
00168   }
00170   Orientation3D minimum(const Orientation3D& p) const {
00171    return Orientation3D(min(_roll.dCast2Pi(),p._roll.dCast2Pi()),min(_pitch.dCast2Pi(),p._pitch.dCast2Pi()),min(_yaw.dCast2Pi(),p._yaw.dCast2Pi()));
00172   }
00174   Orientation3D maximum(const Orientation3D& p) const {
00175    return Orientation3D(max(_roll.dCast2Pi(),p._roll.dCast2Pi()),max(_pitch.dCast2Pi(),p._pitch.dCast2Pi()),max(_yaw.dCast2Pi(),p._yaw.dCast2Pi()));
00176   }
00178   Angle roll() const {
00179    return _roll;
00180   }
00181   Angle pitch() const {
00182    return _pitch;
00183   }
00184   Angle yaw() const {
00185    return _yaw;
00186   }
00187   
00189   void unitQuat(Position3D& vQuat, Decimal& sQuat) const;
00190   
00192   void setRoll(const Angle& roll){
00193    _roll = roll;
00194   }
00195       
00197   void setPitch(const Angle& pitch){
00198    _pitch = pitch;
00199   }
00200     
00202   void setYaw(const Angle& yaw){
00203    _yaw = yaw;
00204   }
00205   
00207   vector<Decimal> vectPi() const;
00208 
00210   vector<Decimal> vectDeg180() const;
00211 
00213   vector<Decimal> vect2Pi() const;
00214 
00216   vector<Decimal> vectDeg360() const;
00217   
00219   string print(PrintTypes type = PRINT_TYPE_WITH_UNITS) const{
00220 //    stringstream s;
00221 //    s.precision(9);
00222 //    s.setf(ios::fixed,ios::floatfield);
00223 //    s << "(" << _roll.print() << ", " << _pitch.print() << ", " << _yaw.print() << ")" ;
00224 //    return s.str();
00225    stringstream s;
00226    s.precision(9);
00227    s.setf(ios::fixed,ios::floatfield);
00228    switch (type){
00229     case PRINT_TYPE_PLAIN:
00230      s << _roll.dCast2Pi() << " " << _pitch.dCast2Pi() << " " << _yaw.dCast2Pi() << " " ;
00231      break;
00232     case PRINT_TYPE_WITH_UNITS:
00233     default:
00234      s << "(" << _roll.print() << ", " << _pitch.print() << ", " << _yaw.print() << ")" ;
00235      break;
00236    }
00237    return s.str();
00238   }
00239   
00240   string toString() const{
00241    stringstream ss;
00242    ss << _roll.dCast2Pi() << "," << _pitch.dCast2Pi() << "," << _yaw.dCast2Pi();
00243    return ss.str();
00244   }
00245   /*
00246   string getObjectName() const {return string("Orientation3D");};*/
00247 };
00248 
00249 
00250 #endif
00251 
00252 
00253 
00254 /* @} */

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6