Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LGLPursuitViewer.hpp
Go to the documentation of this file.
00001 
00013 /* $Id: lglViewer.hpp 4094 2009-09-04 09:32:58Z hcao $ */
00014 
00015 #ifdef HAVE_MODULE_QDISPLAY // lgl viewer is on if HAVE_MODULE_QDISPLAY is defined
00016 
00017 #ifndef LGL_DISPLAY_PURSUIT_HPP
00018 #define LGL_DISPLAY_PURSUIT_HPP
00019 
00020 #include <qdisplay/init.hpp>
00021 #include <qdisplay/Viewer.hpp>
00022 #include <qdisplay/ImageView.hpp>
00023 #include <qdisplay/Shape.hpp>
00024 
00025 #include <lgl/PursuitGraph.hpp>
00026 #include <lgl/PursuitStats.hpp>
00027 
00028 #include <ostream>
00029 #include <string>
00030 #include <vector>
00031 
00032 namespace jafar {
00033   namespace lgl {
00034 
00035 
00036     class LGLPursuitViewer ;
00037 
00038     /*  specific viewer, herited from qdisplay */
00039     class PursuitController : public jafar::qdisplay::Viewer 
00040     {
00041       
00042       private :
00043         LGLPursuitViewer *master ;
00044       
00045       protected : 
00046         void setMaster( LGLPursuitViewer &_master);
00047 
00048       signals:
00049         void keyPressEvent(QKeyEvent *event);
00050 
00051       friend class LGLPursuitViewer ;
00052 
00053     };
00054 
00055     class PursuitViewer : public jafar::qdisplay::Viewer 
00056     {
00057 
00058       private :
00059         double scale ;
00060       
00061       public :
00062         PursuitViewer(double _scale) :
00063           scale(_scale)
00064         { }
00065       
00066       protected :
00067         void mouseMoveEvent ( QMouseEvent * event );
00068 
00069       friend class LGLPursuitViewer ;
00070 
00071     };
00072 
00073     struct Protagonist
00074     {
00075       //position
00076       int x ;
00077       int y ;
00078 
00079       //display
00080       jafar::qdisplay::Shape *shape1;
00081       jafar::qdisplay::Shape *shape2;
00082       jafar::qdisplay::Shape *shape3;
00083     };
00084 
00085     
00086     class LGLPursuitViewer 
00087     {
00088       public:
00089         
00090         // Constructors and Destructor 
00091         LGLPursuitViewer( PursuitGraph &_PG);
00092         
00093         ~LGLPursuitViewer();
00094 
00095         // Set functions
00096         void setRobotAccess ( std::string _robotAccessPath  );
00097         void setTargetAccess( std::string _targetAccessPath );
00098         void setRobotVisib  ( std::string _robotVisibPath );
00099 
00100         void setRobotPosition ( int _x, int _y);
00101         void setTargetPosition  ( int _x, int _y);
00102 
00103         void setHorizon ( unsigned int _horizon );
00104         
00105         /* start the game 
00106          *
00107          * return false if encounter any problem while launching the game.
00108          **/
00109         bool start () ;
00110 
00111         /* Reaction to target Movement (+ _x, + _y )
00112          */
00113         void move ( int _x, int _y) ;
00114 
00115         /* Display a given Path on the robot accessibility window 
00116          */
00117         void displayPath( const std::vector<Cell_ID> &path ) ;
00118 
00119         /* Display a given Path to a given set on the robot accessibility window
00120          */
00121         void displayPath2Set( const std::vector<Cell_ID> &path , const std::set < Cell_ID> &set) ;
00122 
00123 
00124       private:
00125 
00128         PursuitGraph *myPG ;
00129 
00130         /* Controler */
00131         jafar::lgl::PursuitController* ctrl ;
00132 
00134         PursuitViewer* viewer1;
00135         PursuitViewer* viewer2;
00136         PursuitViewer* viewer3;
00137 
00140         std::string robotAccessPath   ;
00141         std::string targetAccessPath  ;
00142         std::string robotVisibPath  ;
00143 
00144         /* Position of the robot and the target */
00145         Protagonist robot ;
00146         Protagonist target ;
00147 
00148         /* temporal horizon used in the PursuitGraph */
00149         unsigned int horizon;
00150 
00151         /* Scale for display */
00152         double scale ;
00153 
00154         /* risk view */
00155         std::vector< jafar::qdisplay::Shape *> risks ;
00156 
00157         /* past positions view */
00158         std::vector< jafar::qdisplay::Shape *> viewTargetPastPositions ;
00159         std::vector< jafar::qdisplay::Shape *> viewRobotPastPositions ;
00160 
00161         /* enable / disable the display of the risks
00162          */
00163         bool visibleRisks;
00164 
00165         /* enable / disable the display of the past positions
00166          */
00167         bool visiblePastPositions;
00168 
00169         /* statistics 
00170          */
00171         PursuitStats stats ;
00172         
00173         /* Target and Robot past positions
00174          */
00175         std::vector< std::pair<int, int > > targetPastPositions ;
00176         std::vector< std::pair<int, int > > robotPastPositions ;
00177 
00178         /* start the display 
00179          *
00180          * return false if data (file path) are missing, true otherwise.
00181          **/
00182         bool startDisplay () ;
00183 
00184         /* Refresh the display (especially the protagonist position )
00185          */
00186         bool refresh();
00187 
00188         /* Display the risk positions
00189          */
00190         void displayrisks();
00191 
00192         /* Hide the risk positions
00193          */
00194         void hiderisks();
00195 
00196         /* Display the target and robot past positions
00197          */
00198         void displaypastpositions();
00199 
00200         /* Hide the target and robot past positions
00201          */
00202         void hidepastpositions();
00203 
00204         /* Display the statistics
00205          */
00206         void displaystats();
00207 
00208         /* Display the "help"
00209          */
00210         void displayhelp();
00211 
00212       friend class PursuitController ;
00213 
00214     };
00215 
00216   }
00217 }
00218 
00219 #endif // LGL_DISPLAY_PURSUIT_HPP
00220 #endif // QDisplay enabled 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:24 for Jafar by doxygen 1.7.6.1
LAAS-CNRS