ProbMultiRegCam3DStr.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010  Antonio Franchi
00006 //
00007 // This file is part of TeleKyb.
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
00023 //
00024 // ----------------------------------------------------------------------------
00025  
00029  
00030 #ifndef __PROB_MULTI_REG_CAM_STR3D_H
00031 #define __PROB_MULTI_REG_CAM_STR3D_H
00032  
00033 //Include libraries
00034 #include "time.h"
00035 #include <fstream>
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <vector>
00039 #include <iostream>
00040 #include <vector>
00041 #include <map>
00042 #include <baselib.h>
00043  
00044 namespace MipBaselib {
00045  
00049  class PosId3D : public Association<Position3D,int>{
00050   public:
00051    
00054    PosId3D() : Association<Position3D,int>(){}
00055    
00059    PosId3D (Position3D p) : Association<Position3D,int>(p){}
00060    
00065    PosId3D (Position3D p, int i) : Association<Position3D,int>(p,i){}
00066    
00068    PosId3D (const PosId3D& f) : Association<Position3D,int>(f){};
00069    
00071    using Association<Position3D,int>::operator=;
00072    
00075    Position3D getPosition(void){
00076      return getObj();
00077    }
00080    int getId(void){
00081      return getAsso();
00082    }
00085    void setId(int a){
00086      associate(a);
00087    }
00088    
00090    string print(){
00091      stringstream s;
00092      if(associated()){
00093       s << "[" << getPosition().print()  << "," << getId() << "]";
00094      }else{
00095       s << "[" << getPosition().print()  << ",na]";
00096      }
00097      return s.str();
00098    }
00099    
00101    bool notEqual(PosId3D &A, Decimal toll){
00102      if ( fabs(getPosition().x() - A.getPosition().x()) > toll ) return true;
00103      if ( fabs(getPosition().y() - A.getPosition().y()) > toll ) return true;
00104      if ( fabs(getPosition().z() - A.getPosition().z()) > toll ) return true;
00105      /*if ( !DoubleUtilities::equal(getPosition().x(), A.getPosition().x(), toll) ) return true;
00106      if ( !DoubleUtilities::equal(getPosition().y(), A.getPosition().y(), toll) ) return true;
00107      if ( !DoubleUtilities::equal(getPosition().z(), A.getPosition().z(), toll) ) return true;*/
00108      if ( getId() != A.getId() )           return true;
00109      return false;
00110    }
00111  };
00112  
00113 } // end of namespace MipBaselib
00114  
00115 using namespace MipBaselib;
00116  
00117 namespace kybalg{
00121  class bearStr{
00122   public:
00123    Angle azimuth;
00124    Angle zenith;
00125    
00127    bearStr();
00128    
00130    bearStr(Angle az,Angle zn);
00131    
00133    bearStr(Decimal az,Decimal zn);
00134    
00136    ~bearStr();
00137    
00139    bearStr& operator= (const bearStr &A);
00140    
00142    bool operator==(const bearStr &other) const;
00143    
00145    string print();
00146  };
00147  
00151  template <class T>
00152   class ObjId {
00153    private:
00154     vector<T> _obj;
00155     int _id;
00156    public:
00157     
00159     ObjId() {
00160      _id = -1;
00161      _obj.clear();
00162     }
00163     
00165     ObjId(T obj, int id) {
00166      _id = id;
00167      _obj.push_back(obj);
00168     }
00169     
00171     ObjId(vector<T> obj, int id) {
00172      _id = id;
00173      _obj.clear();
00174      _obj = obj;
00175     }
00176     
00178     ~ObjId() {
00179      _id = -1;
00180      _obj.clear();
00181     }
00182     
00184     ObjId & operator=(const ObjId& rhs) {
00185      if (this != &rhs) { // Not necessary in this case but it is useful to don't forget it
00186      _id = rhs._id;
00187      _obj = rhs._obj;
00188      }
00189      return (*this);
00190     }
00191     
00193     vector<T> getObj() {
00194      return _obj;
00195     }
00196     
00198     int getId() {
00199      return _id;
00200     }
00201     
00203     void setObj(T obj) {
00204      _obj.push_back(obj);
00205     }
00206     
00208     void setObj(vector<T> obj, int id) {
00209      _obj = obj;
00210      _id = id;
00211     }
00212     
00214     void setObj(vector<T> obj) {
00215      _obj = obj;
00216     }
00217     
00219     void setObj(T obj, int id) {
00220      _obj.push_back(obj);
00221      _id = id;
00222     }
00223     
00225     void setSubObj(T obj, int pos){
00226      if(pos>=0&&pos<_obj.size())
00227      _obj.at(pos) = obj;
00228     }
00229     
00231     void setId(int id) {
00232      _id = id;
00233     }
00234     
00236     void clearObj() {
00237      _obj.clear();
00238     }
00239    
00240   };
00241  
00242  // Create typedef structures
00243  // AngleBearId: feature set of a robot
00244  // PosId: renaming posifeature
00245  typedef ObjId<bearStr> AngleBearId;
00246  typedef PosiFeature PosId;
00247  
00251  class BearIdTime : public AngleBearId {
00252   private:
00253    long int _ttSec;
00254    long int _ttUSec;
00255   public:
00257    BearIdTime(){};
00258 
00260    BearIdTime(Angle az,Angle zn,int id,long int ttSec, long int ttUSec);
00261    
00263    BearIdTime(bearStr bs, int id,long int ttSec, long int ttUSec);
00264 
00266    ~BearIdTime();
00267 
00269    void setTimeSec(long int sec);
00270 
00272    void setTimeUSec(long int usec);
00273 
00275    void setTime(long int sec, long int usec);
00276 
00278    long int getTimeSec();
00279    
00281    long int getTimeUSec();
00282 
00284    bool overTime(long int sec, long int usec);
00285    
00287    bool underTime(long int sec, long int usec);
00288    
00290    Decimal getTime();
00291    
00293    bool underTime(Decimal sec);
00294    
00296    bool overTime(Decimal sec);
00297    
00299    string print();
00300  }; 
00301  
00305  class Pose3DIdTime : public Pose3D {
00306   private:
00307    long int _ttSec;
00308    long int _ttUSec;
00309    int _id;
00310    
00311   public:
00313    Pose3DIdTime(){};
00314 
00316    Pose3DIdTime(Position3D pos,Orientation3D ori,int id,long int ttSec, long int ttUSec);
00317    
00319    ~Pose3DIdTime();
00320 
00322    void setTimeSec(long int sec);
00323 
00325    void setTimeUSec(long int usec);
00326 
00328    void setTime(long int sec, long int usec);
00329 
00331    long int getTimeSec();
00332    
00334    long int getTimeUSec();
00335    
00337    bool overTime(long int sec, long int usec);
00338    
00340    bool underTime(long int sec, long int usec);
00341    
00343    Decimal getTime();
00344    
00346    bool underTime(Decimal sec);
00347    
00349    bool overTime(Decimal sec);
00350    
00352    int getId();
00353    
00355    void setId(int id);
00356    
00358    string print();
00359  };
00360  
00364  class InterPoints {
00365  private:
00367   vector<Position3D> _xy;
00368   
00369 // /// \brief Number of points stored
00370 // int _nPoints;
00371   
00372  public:
00374   InterPoints();
00375   
00377   InterPoints(Position3D xy);
00378   
00380   InterPoints(vector<Position3D> xy);
00381   
00383   InterPoints(Decimal x, Decimal y,Decimal z);
00384   
00386   ~InterPoints();
00387   
00389   int getSize();
00390   
00392   InterPoints& operator=(const InterPoints& rhs);
00393   
00395   void insertPoint(Position3D xy);
00396   
00398   void deletePoint(int pos);
00399   
00401   void deleteLastPoint();
00402   
00404   void insertPoints(vector<Position3D> xy);
00405   
00407   void insertPoint(Position3D ip,int pos);
00408   
00410   Position3D getPoint(int pos);
00411   
00413   Position3D getLastPoint();
00414   
00416   string print();
00417  };
00418  
00423  class Triangle : public MIPObject {
00424  private:
00425   
00426  PosId3D    *_firstVertex;
00427  PosId3D    *_secondVertex;
00428  PosId3D    *_thirdVertex;
00429  InterPoints  *_interPoints3;
00430  InterPoints  *_interPoints2;
00431  bearStr    _oriTwo;
00432  bearStr    _oriThree;
00433  bearStr    _oriTwoOne;
00434  bearStr    _oriTwoThree;
00435  bearStr    _oriThreeOne;
00436  bearStr    _oriThreeTwo;
00437     bearStr _ori2;
00438     bearStr _ori3;
00439  
00440  private:
00441   string printSetOriResult();
00442  public:
00443 
00445   Triangle();
00446 
00448   Triangle(Position3D xy1, int id1, Position3D xy2, int id2, Position3D xy3, int id3);
00449   
00451   ~Triangle();
00452   
00454   vector<PosId3D> getVertex();
00455   
00457   PosId3D* getFirstVertex();
00458   
00460   PosId3D* getSecondVertex();
00461   
00463   PosId3D* getThirdVertex();
00464   
00466   PosId3D* getVertexByPos(int pos);
00467   
00468   PosId3D* getVertexByID(int id);
00469   
00471   void setMyIdVertex(int myId, Decimal &aSide, Decimal &bSide, Decimal &cSide);
00472   
00474   bool isAVertex(Position3D pos, Decimal thr);
00475   
00477   void getIds(vector<int> &ris);
00478   
00480   vector<int> getIds();
00481   
00483   InterPoints* getInter3();
00484   
00486   InterPoints* setInter3();
00487   
00489   Position3D getInter3At(int i);
00490   
00492   int getInter3Size();
00493   
00495   InterPoints* getInter2();
00496   
00498   int getInter2Size();
00499   
00501   void deleteDupPoint2(int pos);
00502   
00504   void deleteDupPoint3(int pos);
00505   
00507   void insertPoints3(vector<Position3D> iPoints);
00508   
00510   void insertPoint3(Position3D iPoint);
00511   
00513   void insertPoints2(vector<Position3D> iPoints);
00514   
00516   void insertPoint2(Position3D iPoint);
00517   
00519   bool checkId(int myId);
00520   
00522   bool sameIds(Triangle* tria);
00523   
00525   bool setOri(bearStr oriTwo, bearStr oriThree, bearStr oriTwoF, bearStr oriTwoS, bearStr oriThreeF, bearStr oriThreeS, Decimal projToll);
00526   
00528   bool setOriOpt(bearStr oriTwo, bearStr oriThree, bearStr oriTwoF, bearStr oriTwoS, bearStr oriThreeF, bearStr oriThreeS, Decimal projToll,Decimal angToll);
00529   
00531   bool setOriSing(bearStr oriTwo, bearStr oriThree, bearStr oriTwoF, bearStr oriTwoS, bearStr oriThreeF, bearStr oriThreeS, Decimal projToll,Decimal angToll);
00532   
00534   bearStr getOriTwo();
00535   
00537   bearStr getOriThree();
00538   
00540   bearStr getOriTwoThree();
00541   
00543   bearStr getOriTwoOne();
00544 
00546   bearStr getOriThreeOne();
00547   
00549   bearStr getOriThreeTwo();
00550   
00552   Angle getOriByPos(int pos);
00553   
00555   string print();
00556   
00558   Triangle& operator=(Triangle &A);
00559   
00561   bool operator==(Triangle &A) const;
00562   
00564   string getObjectName() const{
00565    return "Triangle";
00566   }
00567   /*Triangle & operator=(const Triangle& rhs) {
00568   if (this != &rhs) { // Not necessary in this case but it is useful to don't forget it
00569    _firstVertex = rhs._firstVertex;
00570    _secondVertex = rhs._secondVertex;
00571    _thirdVertex = rhs._thirdVertex;
00572    _interPoints2 = rhs._interPoints2;
00573    _interPoints3 = rhs._interPoints3;
00574   }
00575   return (*this);
00576   }*/
00577  };
00578  
00583  class PolFusion {
00584  private:
00585   vector<Triangle*> _triangles;
00586   vector<PosId3D>  _vertex;
00587   vector<Angle>   _ori;
00588   InterPoints    _intThree;
00589   vector<Triangle*> _triangleQueue;
00590   vector<MIPMatrix> _rotoTrasl;
00591   vector<Decimal>  _scaleF;
00592  
00593  public:
00595   PolFusion();
00596   
00598   PolFusion(Triangle* tria);
00599   
00601   ~PolFusion();
00602   
00604   Triangle* getTriangle(int pos);
00605   
00607   void setTriangle(int pos,Triangle* tria);
00608   
00610   void deleteTriangle(int pos);
00611   
00612   void deleteLastTriangle();
00613   
00615   void deleteBifConflicts(int pos,int posAt, int idNew);
00616   
00618   int getSize();
00619   
00621   void insertVertex(PosId3D vertex);
00622   
00624   PosId3D getVertex(int pos);
00625   
00627   void setVertex(int pos,PosId3D vertex);
00628   
00630   void setQueue(Triangle* queue);
00631   
00633   int queueSize();
00634   
00636   void deleteQueueTriangle(int pos);
00637   
00639   void deleteQueueLastTriangle();
00640   
00642   void setScale(int i, Decimal scale);
00643   
00645   void setScale(Decimal scale);
00646   
00648   Decimal getScale(int i);
00649   
00651   void deleteScaleF(int pos);
00652   
00654   void deleteLastScaleF();
00655   
00657   void setRotoTrasl(int pos, MIPMatrix rt);
00658   
00660   void deleteRotoTrasl(int pos);
00661   
00663   void deleteLastRotoTrasl();
00664   
00666   void insertOri(Decimal ori);
00667   
00669   Decimal getOri(int pos);
00670   
00672   void setOri(int pos,Angle ori);
00673   
00675   void deleteOri(int pos);
00676   
00678   void deleteLastOri();
00679   
00681   void insertTriangle(Triangle *tria, int myId, int id1, int id2);
00682   
00684   PosId3D* searchVertex(int id);
00685   
00687   PosId3D* searchVertex(int id,int &posAt);
00688   
00690   void deleteVertex(int pos);
00691   
00693   void deleteLastVertex();
00694   
00696   int searchBif(PosId3D vertex,int &posAt,Decimal thr);
00697   
00699   void insertPoints(Triangle* tria);
00700   
00702   int getNInThree(int pos);
00703   
00705   Position3D getIntThree(int pos);
00706   
00708   Position3D getLastIntThree();
00709   
00711   void deleteIntThree(int pos);
00712   
00714   void deleteLastIntThree();
00715   
00717   void insertPointIntThree(Position3D ip,int pos);
00718   
00720   bool expandPol(int myId, vector<PolFusion*> actualSol, vector<PolFusion*> &bifPolFusion,Decimal linThr);
00721   
00723   bool checkBif(PosId3D vertex,Decimal thr,int myId);
00724   
00726   string print(int opt=0);
00727   
00729   PolFusion& operator=(PolFusion &A);
00730   
00731  };
00732  
00737  class ProbPolFusion : public MIPObject{
00738   private:
00739    // Pointers to the triangles that compose the polimorph
00740    vector<Triangle*>  _triangles;
00741    // List of vertex
00742    vector<PosId3D>   _vertex;
00743    // Orientation of the robots 
00744    vector<Angle>    _ori;
00745    // Intersection by three
00746    InterPoints     _intThree;
00747    // List of triangle candidates to enter in the polimorph
00748    vector<Triangle*>  _triangleQueue;
00749    // Rototranslation
00750    vector<MIPMatrix>  _rotoTrasl;
00751    // Scale factor
00752    vector<Decimal>   _scaleF;
00753    // Rating based on the number of verteces 
00754    int         _ratingVertex;
00755    // Rating based on the number of triple intersections
00756    int         _ratingInThree;
00757    // Number of intersection by four ordered by the triangle index inserted 
00758    vector<int>     _numIntFour;
00759    // Kind of expansion method used
00760    int         _expandMethod;
00761   
00762   public:
00764    ProbPolFusion();
00765    
00767    ProbPolFusion(Triangle* tria, int expMth);
00768    
00770    ~ProbPolFusion();
00771    
00773    Triangle* getTriangle(int pos);
00774    
00776    void setTriangle(int pos,Triangle* tria);
00777    
00779    void deleteTriangle(int pos);
00780    
00782    void deleteLastTriangle();
00783    
00785    void deleteBifConflicts(int pos,int posAt, int idNew);
00786    
00788    void deleteBifConflictsOpt(int pos, int idNew);
00789    
00791    int getSize();
00792    
00794    int getQueueSize();
00795    
00797    void getIds(vector<int> &ids);
00798    
00800    void insertVertex(PosId3D vertex);
00801    
00803    PosId3D getVertex(int pos);
00804    
00806    void setVertex(int pos,PosId3D vertex);
00807    
00809    void setQueue(Triangle* queue);
00810    
00812    int queueSize();
00813    
00815    void deleteQueueTriangle(int pos);
00816    
00817    void deleteQueueLastTriangle();
00818    
00820    void setScale(int i, Decimal scale);
00821    
00823    void setScale(Decimal scale);
00824    
00826    Decimal getScale(int i);
00827    
00829    void deleteScaleF(int pos);
00830    
00831    void deleteLastScaleF();
00832    
00834    void setRotoTrasl(int pos, MIPMatrix rt);
00835    
00837    MIPMatrix getRotoTrasl(int pos);
00838    
00840    void deleteRotoTrasl(int pos);
00841    
00842    void deleteLastRotoTrasl();
00843    
00845    void insertOri(Decimal ori);
00846    
00848    Decimal getOri(int pos);
00849    
00851    void setOri(int pos,Angle ori);
00852    
00854    void deleteOri(int pos);
00855    
00857    void deleteLastOri();
00858    
00860    void insertTriangle(Triangle *tria, int myId, int id1, int id2);
00861    
00863    PosId3D* searchVertex(int id);
00864    
00866    PosId3D* searchVertex(int id,int &posAt);
00867    
00869    void deleteVertex(int pos);
00870    
00872    void deleteLastVertex();
00873    
00875    int searchBif(PosId3D vertex,int &posAt,Decimal thr);
00876    
00878    void insertPoints(Triangle* tria, int &numInt4);
00879    
00881    void insertPointsNoIn(Triangle* tria, int &numInt4, MIPMatrix* &matrixPointer, Decimal actualScale, vector<Position3D> &intToInsert, int &incrRatInThree);
00882    
00884    int getNInThree(int pos);
00885    
00887    Position3D getIntThree(int pos);
00888    
00890    Position3D getLastIntThree();
00891    
00893    void deleteIntThree(int pos);
00894    
00896    void deleteLastIntThree();
00897    
00899    void insertPointIntThree(Position3D ip,int pos);
00900    
00902    bool expandPol(int myId, vector<ProbPolFusion*> actualSol, vector<ProbPolFusion*> &bifProbPolFusion,Decimal linThr, map <int, vector<Pose3D> > *likelihood, vector <int> activeLikelihoods);
00903    
00905    bool expandPolOpt(int myId, vector<ProbPolFusion*> actualSol, vector<ProbPolFusion*> &bifProbPolFusion,Decimal linThr, map <int, vector<Pose3D> > *likelihood, vector <int> activeLikelihoods,int &maxBifSize);
00906    
00908    bool expandPolNoIn(int myId, vector<ProbPolFusion*> actualSol, vector<ProbPolFusion*> &bifProbPolFusion,Decimal linThr, map <int, vector<Pose3D> > *likelihood, vector <int> activeLikelihoods,int &maxBifSize);
00909    
00911    bool checkBif(PosId3D vertex,Decimal thr,int myId);
00912    
00914    string print(int opt=0);
00915    
00917    ProbPolFusion& operator=(ProbPolFusion &A);
00918    
00920    Decimal computeProbability(Pose3D measure, int id, map <int, vector<Pose3D> > * &likelihood);
00921    
00923    void setRatingVertex(int rating);
00924    
00926    int getRatingVertex();
00927    
00929    void growRatingVertex();
00930    
00932    void decreaseRatingVertex();
00933    
00935    void setRatingInThree(int rating);
00936    
00938    int getRatingInThree();
00939    
00941    void growRatingInThree();
00942    
00944    void decreaseRatingInThree();
00945    
00947    void setIntFourNum(int pos, int val);
00948    
00950    int getIntFourNum(int pos);
00951    
00953    int getLastIntFourNum();
00954    
00956    void deleteLastIntFourNum();
00957    
00959    void selectScale(Decimal &bestScale, Decimal &bestProb, map <int, vector<Pose3D> > * &likelihood, vector <int> &activeLikelihoods,vector<int> &idsV);
00960    
00962    void setExpandMethod(int expMth);
00963    
00965    string getObjectName() const{
00966     return "ProbPolFusion";
00967    }
00968  };
00969 } // End of namespace
00970 
00971 #endif

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