S1m.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 
00035 #ifndef __S1M_H_
00036 #define __S1M_H_
00037 
00038 #ifdef MIP_HOST_APPLE
00039 #include <applePatch.h>
00040 #endif
00041 
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <vector>
00045 #include <iostream>
00046 #include <string>
00047 #include <sstream>
00048 #include <sys/time.h>
00049 #include <sys/select.h>
00050 #include <assert.h>
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 #include <Types.h>
00059 #include <numTools.h>
00060 
00061 
00062 #define MPIm  18000
00063 // #define M2PIm 36000
00064 
00065 // inline UCoordmm fmod(UCoordmm a, UCoordmm b){
00066 //  return (UCoordmm)fmod((double)a, (double)b);
00067 // }
00068 
00069 inline double cos(UCoordmm a){
00070  return cos((double)a*M_PI/MPIm);
00071 }
00072 
00073 inline double sin(UCoordmm a){
00074  return sin((double)a*M_PI/MPIm);
00075 }
00076 
00077 using namespace std;
00078 
00079 
00080 
00084 class Anglem{
00085  private:
00086 #ifdef FOUND_BOOST_SER
00087   friend class boost::serialization::access;
00088   template<class Archive>
00089   void serialize(Archive & ar, const unsigned int version){
00090    ar & theta; 
00091   }
00092 #endif
00093   
00094   UCoordmm theta;
00095   static const UCoordmm M2PIm=2*MPIm; /*for efficency*/
00096 
00098   UCoordmm norm2Pi(UCoordmm a){
00099    if (a >= M2PIm){
00100     a-=M2PIm;
00101    }
00102    return a;
00103   }
00105   UCoordmm norm2Pi(Coordmm a){
00106    if (a >= 0){
00107     return a;
00108    } else {
00109     // TEMP not used
00110 //     int b = ((int)a) + M2PIm;
00111     return (UCoordmm)a;
00112    }
00113   }
00115   UCoordmm norm2Pi(int a){
00116    a = a%M2PIm;
00117    if (a < 0){
00118     a+=M2PIm;
00119    }
00120    return a;
00121   }
00123   Coordmm normPi(Coordmm a){
00124    if (a<=-MPIm) {
00125     a+=MPIm;
00126     a+=MPIm;
00127    }
00128    if (a>MPIm) {
00129     a-=MPIm;
00130     a-=MPIm;
00131    }
00132    return a;
00133   }
00135   Coordmm normPi(UCoordmm a){
00136    UCoordmm b = norm2Pi(a);
00137    if (b>MPIm){ // in questo caso b è tra MPIm e M2PIm
00138     UCoordmm c = b - MPIm; // c è certamente compreso tra 1 e 17999
00139     return -MPIm + c;
00140    } else { // in questo caso b è certamente compreso tra 0 e 18000
00141     return b;
00142    }
00143   }
00145   Coordmm normPi(int a){
00146    a = norm2Pi(a);
00147    if (a > MPIm){
00148     a-=MPIm;
00149    }
00150    return a;
00151   }
00152  public:
00154   Anglem() {
00155    theta = 0;
00156   };
00158   Anglem(UCoordmm t) {
00159    theta = norm2Pi(t);
00160   };
00162   Anglem(const Anglem& rhs) {
00163    theta = norm2Pi(rhs.dCast());
00164   };
00166   Anglem& operator=(const Anglem& rhs){
00167    if (this != &rhs){      // Not necessary in this case but it is useful to don't forget it
00168     theta = norm2Pi(rhs.dCast());
00169    }
00170    return *this;
00171   }
00173   Anglem& operator+=(const Anglem& a) {
00174    theta = norm2Pi( (int)theta + (int)(a.theta) );
00175    return *this;
00176   }
00178   Anglem& operator-=(const Anglem& a) {
00179    if (theta >= a.theta){
00180     theta = theta - a.theta;
00181    } else {
00182     int th = (int)theta - (int)(a.theta);
00183     theta = th + M2PIm;
00184    }
00185 /*   Coordmm myTheta = theta >= other.theta ? theta : theta + 2.0*MPIm;
00186    theta = norm2Pi(myTheta - other.theta);*/
00187    return *this;
00188   }
00189 //  /**compound assignment operator *= */
00190 //   Anglem& operator*=(const Anglem& a) {
00191 //    theta = norm2Pi( (int)theta * (int)(a.theta) );
00192 //    return *this;
00193 //   }
00195   Anglem& operator*=(const Coordmm& d) {
00196    theta = norm2Pi( (int)theta*(int)d );
00197    return *this;
00198   }
00200   Anglem& operator*=(const UCoordmm& d) {
00201    theta = norm2Pi( (int)theta*(int)d );
00202    return *this;
00203   }
00205   Anglem& operator*=(const int& d) {
00206    theta = norm2Pi( (int)theta * d);
00207    return *this;
00208   }
00210   const Anglem operator+(const Anglem &other) const {
00211    return Anglem(*this) += other;
00212   }
00214   const Anglem operator-(const Anglem &other) const {
00215    return Anglem(*this) -= other;
00216   }
00217 //  /** binary arithmetic operator * */
00218 //   const Anglem operator*(const Anglem &other) const {
00219 //    return Anglem(*this) *= other;
00220 //   }
00222   const Anglem operator*(const Coordmm& d) const {
00223    return (Anglem(*this) *= d);
00224   }
00226   const Anglem operator*(const UCoordmm& d) const {
00227    return (Anglem(*this) *= d);
00228   }
00230   const Anglem operator*(const int& d) const {
00231    return (Anglem(*this) *= d);
00232   }
00234   bool operator==(const Anglem &other) const {
00235    if( (other.dCast()) == theta) return true;
00236    else return false;
00237   }
00239   bool operator!=(const Anglem &other) const {
00240    return !(*this == other);
00241   }
00243   UCoordmm dCast() const {
00244    return theta;
00245   }
00247   Coordmm dCastPi() {
00248    return normPi(theta);
00249   }
00251   Coordmm dCastDeg() {
00252    return ((int)theta*180)/MPIm;
00253   }
00255   Decimal dCastPiDecimal() {
00256    return ((Decimal)theta)/100.0;
00257   }
00258   
00263   Coordmm alDiff(const Anglem &other); 
00264   
00269   Coordmm ccwDiff(const Anglem &other);
00270   
00275   Coordmm cwDiff(const Anglem &other);
00276   
00281   bool almostEqual(Anglem A, Coordmm toll);
00282   
00286    Anglem mean(const Anglem &other);
00287   
00292   Anglem ccwMean(const Anglem &other);
00293   
00298   Anglem cwMean(const Anglem &other);
00299   
00302   string print();
00303 };
00304 
00305 
00306 
00307 #endif
00308 
00309 
00310 
00311 /* @} */

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