MultiRegCamStr.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 
00031 #ifndef __MULTI_REG_CAM_STR_H
00032 #define __MULTI_REG_CAM_STR_H
00033 
00034 #include <MIPMatrix.h>
00035 #include "time.h"
00036 #include <fstream>
00037 #include <stdlib.h>
00038 #include <stdio.h>
00039 #include <vector>
00040 #include <iostream>
00041 #include <R2.h>
00042 #include <S1.h>
00043 #include <SE2.h>
00044 
00045 namespace MipBaselib {
00046 
00047     class TriaMatrix : public MIPMatrix {
00048     public:
00049 
00051 
00052         TriaMatrix(int rows, int cols) : MIPMatrix(rows, cols) {
00053         };
00054 
00056 
00057         TriaMatrix() : MIPMatrix() {
00058         };
00059         /*
00061         TriaMatrix growDim(TriaMatrix &matrix){
00062              TriaMatrix _matrixRis(matrix.rows+1,matrix.cols+1);
00063              for(int i=0;i<matrix.rows;i++)
00064                  for(int j=0;j<matrix.cols;j++)
00065                     _matrixRis.elms[i][j]=matrix.elms[i][j];
00066              return _matrixRis;
00067          }
00068          */
00070 
00071         void growDim(TriaMatrix* &matrix);
00072     };
00073 
00074 }
00075 
00076 namespace MipAlgorithms {
00077 
00078 template <class T>
00079     class ObjId {
00080     private:
00081         vector<T> _obj;
00082         int _id;
00083     public:
00084 
00086 
00087         ObjId() {
00088             _id = -1;
00089             _obj.clear();
00090         }
00091 
00093 
00094         ObjId(T obj, int id) {
00095             _id = id;
00096             _obj.push_back(obj);
00097         }
00098 
00100 
00101         ObjId(vector<T> obj, int id) {
00102             _id = id;
00103             _obj.clear();
00104             _obj = obj;
00105         }
00106 
00108 
00109         ~ObjId() {
00110 
00111            _id = -1;
00112            _obj.clear();
00113             /*delete &_id;
00114             delete &_obj;*/
00115         }
00116 
00118 
00119         ObjId & operator=(const ObjId& rhs) {
00120             if (this != &rhs) { // Not necessary in this case but it is useful to don't forget it
00121                 _id = rhs._id;
00122                 _obj = rhs._obj;
00123             }
00124             return (*this);
00125         }
00126 
00128 
00129         vector<T> getObj() {
00130             return _obj;
00131         }
00132 
00134 
00135         int getId() {
00136             return _id;
00137         }
00138 
00140 
00141         void setObj(T obj) {
00142             _obj.push_back(obj);
00143         }
00144 
00146 
00147         void setObj(vector<T> obj, int id) {
00148             _obj = obj;
00149             _id = id;
00150         }
00151 
00153         void setObj(vector<T> obj) {
00154             _obj = obj;
00155         }
00156 
00158 
00159         void setObj(T obj, int id) {
00160             _obj.push_back(obj);
00161             _id = id;
00162         }
00163 
00165 
00166         void setId(int id) {
00167             _id = id;
00168         }
00169 
00170     };
00171     //Creating three classes based on the template
00172     typedef PosiFeature PosId;
00173 
00174     /*class PosId : public PosiFeature{
00175         private: Angle _ori;
00176         public: PosId() : PosiFeature() {
00177                 };
00178 
00179                 PosId(Position pos, int id) : PosiFeature(pos,id) {
00180                 };
00181 
00182                 void setOri(Decimal ori){
00183                     _ori = ori;
00184                 }
00185 
00186                 Angle getOri(){
00187                     return _ori;
00188                 }
00189 
00190     };*/
00191 
00192     //typedef Pose BearId;
00193 
00194     typedef ObjId<Angle> AngleId;
00195 
00196     class AngleIdTime : public AngleId {
00197         private:
00198             long int _ttSec;
00199             long int _ttUSec;
00200         public:
00202             AngleIdTime(){};
00203 
00205             AngleIdTime(Angle angle,int id,long int ttSec, long int ttUSec);
00206 
00208             ~AngleIdTime();
00209 
00211             void setTimeSec(long int sec);
00212 
00214             void setTimeUSec(long int usec);
00215 
00217             void setTime(long int sec, long int usec);
00218 
00220             long int getTimeSec();
00221 
00222             long int getTimeUSec();
00223 
00224             // Check if the time in input is before or later the actual one
00225             bool overTime(long int sec, long int usec);
00226 
00227             bool underTime(long int sec, long int usec);
00228 
00229             Decimal getTime();
00230 
00231             bool underTime(Decimal sec);
00232 
00233             bool overTime(Decimal sec);
00234 
00235     };
00236 
00237     class InterPoints {
00238     private:
00240         vector<Position> _xy;
00241 
00243         //int _nPoints;
00244 
00245     public:
00247         InterPoints();
00248 
00250         InterPoints(Position xy);
00251 
00253         InterPoints(vector<Position> xy);
00254 
00256         InterPoints(Decimal x, Decimal y);
00257 
00259         ~InterPoints();
00260 
00262         int getSize();
00263 
00265         InterPoints& operator=(const InterPoints& rhs);
00266 
00268         void insertPoint(Position xy);
00269 
00271         void deletePoint(int pos);
00272 
00273         void deleteLastPoint();
00274 
00276         void insertPoints(vector<Position> xy);
00277 
00279         void insertPoint(Position ip,int pos);
00280 
00282         Position getPoint(int pos);
00283 
00285         Position getLastPoint();
00286 
00288         string print();
00289 
00290     };
00291 
00292     class Triangle {
00293     private:
00294 
00295         PosId *_firstVertex;
00296         PosId *_secondVertex;
00297         PosId *_thirdVertex;
00298         InterPoints *_interPoints3;
00299         InterPoints *_interPoints2;
00300         Angle _oriTwo;
00301         Angle _oriThree;
00302         Angle _oriTwoOne;
00303         Angle _oriTwoThree;
00304         Angle _oriThreeOne;
00305         Angle _oriThreeTwo;
00306     Angle _ori2;
00307     Angle _ori3;
00308     
00309         //bool _meIn;
00310 
00311     public:
00312 
00314         Triangle();
00315 
00317         Triangle(Position xy1, int id1, Position xy2, int id2, Position xy3, int id3);
00318 
00320 
00321         ~Triangle();
00322 
00324 
00325         vector<PosId> getVertex();
00326 
00328         PosId* getFirstVertex();
00329 
00331         PosId* getSecondVertex();
00332 
00334         PosId* getThirdVertex();
00335 
00337         PosId* getVertexByPos(int pos);
00338 
00339         PosId* getVertexByID(int id);
00340 
00342         // Pay attention: it could be a rototranslation, not only translation!
00343         void setMyIdVertex(int myId, Decimal &aSide, Decimal &bSide, Decimal &cSide);
00344 
00346         bool isAVertex(Position pos, Decimal thr);
00347 
00349         void getIds(vector<int> &ris);
00350 
00352         // To give it side-effect, type a & after InterPoints
00353         InterPoints getInter3();
00354 
00355         // / \brief Returns the intersection by three vector in edit mode
00356         InterPoints* setInter3();
00357 
00359         Position getInter3At(int i);
00360 
00362 
00363         int getInter3Size();
00364 
00366 
00367         InterPoints getInter2();
00368 
00370 
00371         int getInter2Size();
00372 
00374 
00375         void deleteDupPoint2(int pos);
00376 
00378 
00379         void deleteDupPoint3(int pos);
00380 
00382 
00383         void insertPoints3(vector<Position> iPoints);
00384 
00386 
00387         void insertPoint3(Position iPoint);
00388 
00390 
00391         void insertPoints2(vector<Position> iPoints);
00392 
00394 
00395         void insertPoint2(Position iPoint);
00396         /*
00398         void setPos(PosId posId,int pos){
00399                 if(pos==0)
00400                     (*_firstVertex).setObj(posId.getObj(),posId.getId());
00401                 if(pos==1)
00402                     (*_secondVertex).setObj(posId.getObj(),posId.getId());
00403                 if(pos==2)
00404                     (*_thirdVertex).setObj(posId.getObj(),posId.getId());
00405                 (*_firstVertex).
00406         }
00407          */
00409 
00410         bool checkId(int myId);
00411 
00413         bool sameIds(Triangle* tria);
00414 
00416 
00417         bool setOri(Angle oriTwo, Angle oriThree, Angle oriTwoF, Angle oriTwoS, Angle oriThreeF, Angle oriThreeS, Decimal projToll);
00418 
00420         bool setOriOpt(Angle oriTwo, Angle oriThree, Angle oriTwoF, Angle oriTwoS, Angle oriThreeF, Angle oriThreeS, Decimal projToll, Decimal noise=0.0);
00421 
00423 
00424         Angle getOriTwo();
00425 
00427 
00428         Angle getOriThree();
00429 
00431 
00432         Angle getOriTwoThree();
00433 
00435 
00436         Angle getOriTwoOne();
00437 
00439 
00440         Angle getOriThreeOne();
00441 
00443 
00444         Angle getOriThreeTwo();
00445 
00446         Angle getOriByPos(int pos);
00447 
00448 
00450 
00451         string print();
00452 
00454         Triangle& operator=(Triangle &A);
00455 
00456         bool operator==(Triangle &A) const;
00457 
00458         /*Triangle & operator=(const Triangle& rhs) {
00459             if (this != &rhs) { // Not necessary in this case but it is useful to don't forget it
00460                 _firstVertex = rhs._firstVertex;
00461                 _secondVertex = rhs._secondVertex;
00462                 _thirdVertex = rhs._thirdVertex;
00463                 _interPoints2 = rhs._interPoints2;
00464                 _interPoints3 = rhs._interPoints3;
00465             }
00466             return (*this);
00467         }*/
00468 
00469     };
00470 
00471     class PolFusion {
00472     private:
00473         vector<Triangle*> _triangles;
00474         //TriaMatrix* _polMatrix;
00475         vector<PosId> _vertex;
00476         vector<Angle> _ori;
00477         InterPoints _intThree;
00478         vector<Triangle*> _triangleQueue;
00479         vector<MIPMatrix> _rotoTrasl;
00480         vector<Decimal> _scaleF;
00481 
00482     public:
00484         PolFusion();
00485 
00487         PolFusion(Triangle* tria);
00488 
00490         ~PolFusion();
00491 
00493         Triangle* getTriangle(int pos);
00494 
00496         void setTriangle(int pos,Triangle* tria);
00497 
00499         void deleteTriangle(int pos);
00500 
00501         void deleteLastTriangle();
00502 
00504         void deleteBifConflicts(int pos,int posAt, int idNew);
00505 
00507 
00508         //void setMatrix(int id1, int id2, int pos);
00509 
00510 
00512         int getSize();
00513 
00515         void insertVertex(PosId vertex);
00516 
00518         PosId getVertex(int pos);
00519 
00520         void setVertex(int pos,PosId vertex);
00521 
00523         void setQueue(Triangle* queue);
00524 
00526         int queueSize();
00527 
00529         void deleteQueueTriangle(int pos);
00530 
00531         void deleteQueueLastTriangle();
00532 
00534         void setScale(int i, Decimal scale);
00535 
00537         void setScale(Decimal scale);
00538 
00540         Decimal getScale(int i);
00541 
00543         void deleteScaleF(int pos);
00544 
00545         void deleteLastScaleF();
00546 
00548         void setRotoTrasl(int pos, MIPMatrix rt);
00549 
00551         void deleteRotoTrasl(int pos);
00552 
00553         void deleteLastRotoTrasl();
00554 
00556         void insertOri(Decimal ori);
00557 
00559         Decimal getOri(int pos);
00560 
00562         void setOri(int pos,Angle ori);
00563 
00565         void deleteOri(int pos);
00566 
00567         void deleteLastOri();
00568 
00570         void insertTriangle(Triangle *tria, int myId, int id1, int id2);
00571 
00573         PosId* searchVertex(int id);
00574 
00575         PosId* searchVertex(int id,int &posAt);
00576 
00578         void deleteVertex(int pos);
00579 
00580         void deleteLastVertex();
00581 
00583         int searchBif(PosId vertex,int &posAt,Decimal thr);
00584 
00586         void insertPoints(Triangle* tria);
00587 
00589         int getNInThree(int pos);
00590 
00592         Position getIntThree(int pos);
00593 
00595         Position getLastIntThree();
00596 
00598         void deleteIntThree(int pos);
00599 
00600         void deleteLastIntThree();
00601 
00603         void insertPointIntThree(Position ip,int pos);
00604 
00605         bool expandPol(int myId, vector<PolFusion*> actualSol, vector<PolFusion*> &bifPolFusion,Decimal linThr);
00606 
00608         //bool checkBif(MultiRegCamSol* &mrcsols,PosId vertex,Decimal thr,int myId){
00609         bool checkBif(PosId vertex,Decimal thr,int myId);
00610 
00612         string print(int opt=0);
00613 
00615         PolFusion& operator=(PolFusion &A);
00616 
00617     };
00618 
00619 }
00620 
00621 #endif

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