R2.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 __R2_H_
00035 #define __R2_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 #include <Types.h>
00060 #include <Association.h>
00061 #include <S1.h>
00062 
00063 using namespace std;
00064 
00067 class Position {
00068  
00069  private:
00070 #ifdef FOUND_BOOST_SER
00071   friend class boost::serialization::access;
00072   template<class Archive>
00073     void serialize(Archive & ar, const unsigned int version){
00074    ar & _x; 
00075    ar & _y;
00076     }
00077 #endif
00078  
00079  protected:
00080   Decimal _x;
00081   Decimal _y;
00082 
00083  public:
00086   Position();
00087   
00092   Position(const Decimal& x_in,const Decimal& y_in);
00093   
00097   Position(const Angle& theta);
00098   
00103   Position(const Decimal &d,const Angle& theta);
00104   
00107   Position(const Position& p);
00108   
00111   void setX (const Decimal& x);
00112   
00115   void setY (const Decimal& y);
00116   
00119   Position& operator=(const Position& rhs);
00120   
00122   Position& operator+=(const Position& a);
00123   
00125   Position& operator-=(const Position& a);
00126   
00128   Position& operator*=(const Decimal& scalar);
00129   
00131   Position& operator/=(const Decimal& scalar);
00132   
00134   Position& operator+=(const Decimal& scalar);
00135   
00138   Position& operator+=(const Angle& angle);
00139   
00141   Position& operator-=(const Decimal& scalar);
00142   
00145   Position& operator-=(const Angle& angle);
00146   
00148   Position operator+(const Decimal &other) const;
00149   
00151   Position operator-(const Decimal &other) const;
00152   
00154   Position operator+(const Angle &other) const;
00155   
00157   Position operator-(const Angle &other) const;
00158   
00160   Position operator+(const Position &other) const;
00161   
00163   Position operator-(const Position &other) const;
00164   
00167   Position operator*(const Decimal& scalar) const;
00168   
00171   Position operator/(const Decimal& scalar) const;
00172   
00174   bool operator==(const Position &other) const;
00175   
00177   bool operator!=(const Position &other) const;
00178   
00180   Position minimum(const Position& p) const;
00181   
00183   Position maximum(const Position& p) const;
00184   
00186   Decimal x() const;
00187   
00189   Decimal y() const;
00190   
00193   Decimal norm() const;
00194   
00197   Decimal squareNorm() const;
00198   
00202   Decimal dist(const Position& p) const;
00203   
00206   Angle bearing() const;
00207 
00210   Decimal bearingInv() const;
00211   
00215   Decimal scalar(const Position& p) const;
00216   
00219   vector<Decimal> vectorize() const;
00220   
00222   string print(int precision=4) const;
00223   
00224   // String getter & setter (Syntax "x,y")
00225   bool fromString(const string& s);
00226   string toString() const;
00227 };
00228 
00229 
00236 class PosiFeature : public Association<Position,int> {
00237  private:
00238   
00239  public:
00240   int numInliersForThisFeature;
00241   
00244   PosiFeature() : Association<Position,int>(){
00245    numInliersForThisFeature = 1;
00246   }
00247   
00251   PosiFeature (const Position& p) : Association<Position,int>(p){
00252    numInliersForThisFeature = 1;
00253   }
00254   
00259   PosiFeature (const Position& p, const int i) : Association<Position,int>(p,i){
00260    numInliersForThisFeature = 1;
00261   }
00262   
00264   PosiFeature (const PosiFeature& f) : Association<Position,int>(f){
00265    numInliersForThisFeature = f.numInliersForThisFeature;
00266   };
00267   
00269   PosiFeature (stringstream &ss) : Association<Position,int>(){
00270    PosiFeature tpf(ss);
00271    numInliersForThisFeature = 1;
00272    (*this) = tpf;
00273   };
00274   
00276   // TODO: (Martin:) This does nothing!
00277   
00278   
00279   
00280   PosiFeature& operator=(const PosiFeature& a){
00281    if (this != &a){      // Not necessary in this case but it is useful to don't forget it
00282     this->Association<Position,int>::operator=(a);
00283 //     _obj   = a._obj;
00284 //     _assoObj = a._assoObj;
00285 //     _isAsso  = a._isAsso;
00286     numInliersForThisFeature = a.numInliersForThisFeature;
00287    }
00288    return *this;
00289   }
00290 /* using Association<Position,int>::operator=;*/
00291 
00294   Position getPosition(void) const {
00295    return getObj();
00296   }
00299   int getId(void) const {
00300    return getAsso();
00301   }
00304   void setId(int a) {
00305    associate(a);
00306   }
00307   
00310   string print() const;
00311 
00313   bool notEqual(const PosiFeature &A, const Decimal& toll) const;
00314 
00316   PosiFeature& mul(const Decimal& scalar);
00317   
00320   string exportAsString(){
00321    stringstream ss;
00322    ss << this->getId() << " " << this->getPosition().x() << " " << this->getPosition().y();
00323    return ss.str();
00324   }
00325 };
00326 
00327 
00331 // class PosiFeatures : public vector<PosiFeature> {};
00332 typedef vector<PosiFeature> PosiFeatures;
00333 
00334 
00338 class Observation : public PosiFeatures {
00339  public:
00340   
00342   int nullFeature;
00343   
00345   int id;
00346   
00349   Observation();
00350   
00354   Observation(int ID);
00355   
00361   Observation(const PosiFeatures& p, int ID);
00362   
00364   Observation (const Observation& f);
00365   
00369   Observation (stringstream& ss);
00370   
00372   Observation& operator=(const Observation& f);
00373     
00375   string print() const;
00376   
00379   int insertion(const PosiFeature& p);
00380   
00382   bool find(const PosiFeature& p, int& position);
00383   
00385   bool find(const int id, int& position);
00386   
00389   void init();
00390   
00393   string exportAsString();
00394   
00395  private:
00396 #ifdef FOUND_BOOST_SER
00397   friend class boost::serialization::access;
00398   template<class Archive>
00399     void serialize(Archive & ar, const unsigned int version){
00400    
00401    ar & nullFeature; 
00402    ar & id;
00403    ar & &((*this)[0]);
00404 //    ar & size();
00405 //    for(int i = 0; i<size(); i++){
00406 //     ar & (*this)[i];
00407 //    }
00408     }
00409 #endif
00410 
00411 };
00412 
00413 
00414 
00415 
00416 #endif
00417 
00418 
00419 
00420 /* @} */

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