experiments/evorobot/include/evorobotviewer.h

00001 /********************************************************************************
00002  *  FARSA Experiments Library                                                   *
00003  *  Copyright (C) 2007-2012                                                     *
00004  *  Stefano Nolfi <stefano.nolfi@istc.cnr.it>                                   *
00005  *  Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it>                           *
00006  *  Gianluca Massera <emmegian@yahoo.it>                                        *
00007  *  Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it>                         *
00008  *                                                                              *
00009  *  This program 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 2 of the License, or           *
00012  *  (at your option) any later version.                                         *
00013  *                                                                              *
00014  *  This program 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 this program; if not, write to the Free Software                 *
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00022  ********************************************************************************/
00023 
00024 #ifndef EVOROBOTVIEWER_H
00025 #define EVOROBOTVIEWER_H
00026 
00027 #include "evorobotcomponent.h"
00028 #include "componentui.h"
00029 #include "evoga.h"
00030 #include "renderworld.h"
00031 #include "holisticviewer.h"
00032 
00033 #include <QWidget>
00034 #include <QMenu>
00035 #include <QAction>
00036 #include <QMenuBar>
00037 #include <QFileDialog>
00038 #include <QLabel>
00039 #include <QList>
00040 #include <QString>
00041 #include <QWidget>
00042 #include <QMenuBar>
00043 #include <QVBoxLayout>
00044 #include <QObject>
00045 
00046 namespace farsa {
00047 
00048 class PhyiCub;
00049 // class VisionMapSensorGui;
00050 class EvoRobotExperiment;
00051 class NetworkDialog;
00052 class TestIndividual;
00053 class RenderWorldWrapperWidget;
00054 
00055 class FARSA_EXPERIMENTS_API EvoRobotViewer : public QObject, public ComponentUI, public ConcurrentResourcesUser {
00056     Q_OBJECT
00057 public:
00061     EvoRobotViewer( EvoRobotComponent* component );
00063     ~EvoRobotViewer();
00069     void fillActionsMenu( QMenu* actionsMenu );
00075     QList<ComponentUIViewer> getViewers( QWidget* parent, Qt::WindowFlags flags );
00079     void addAdditionalMenus( QMenuBar* menuBar );
00080 
00081 private:
00089     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00090 
00091     ComponentUIViewer evogaControls( QWidget* parent, Qt::WindowFlags flags );
00092     ComponentUIViewer networkView( QWidget* parent, Qt::WindowFlags flags );
00093     ComponentUIViewer neuroMonitorView( QWidget* parent, Qt::WindowFlags flags );
00094 //  ComponentUIViewer icubview( QWidget* parent, Qt::WindowFlags flags );
00095     ComponentUIViewer fitview( QWidget* parent, Qt::WindowFlags flags );
00096     ComponentUIViewer statview( QWidget* parent, Qt::WindowFlags flags );
00097     ComponentUIViewer holisticView( QWidget* parent, Qt::WindowFlags flags );
00098     ComponentUIViewer renderWorld( QWidget* parent, Qt::WindowFlags flags );
00099     ComponentUIViewer testIndividualUI( TestIndividual* test, QWidget* parent, Qt::WindowFlags flags );
00100 
00101     EvoRobotComponent* evorobot;
00102     Evoga* ga;
00104     QWidget* statViewer;
00105     EvoDataViewer* edv;     
00106     FitViewer* ftv;         
00107     HolisticViewer* hlv;        
00108 //  VisionMapSensorGui *m_icubview; //! widget that visualize icub's camera content
00109     RenderWorldWrapperWidget* renderworldwrapper;   
00110     NetworkDialog *networkDialog;  // The network Dialog
00112     QLabel* infoEvoga;
00113 
00114 private slots:
00118     void onEvonetUpdated();
00120     void onWorldAdvance();
00124     void onEvogaStartingReplication( int replication );
00128     void onEvogaRecoveredInterruptedEvolution( QString statfile );
00135     void onEvogaEndGeneration( int generation, int fmax, int faverage, int fmin );
00136     
00138     void onActionFinished();
00139     
00141     void evogaNextTrial();
00142 
00144     void loadStat();
00146     void loadAllStat();
00147 };
00148 
00157 class FARSA_EXPERIMENTS_API RenderWorldWrapperWidget : public QWidget, public ConcurrentResourcesUser
00158 {
00159 public:
00166     RenderWorldWrapperWidget(QWidget* parent = NULL, Qt::WindowFlags flags = 0);
00167 
00171     virtual ~RenderWorldWrapperWidget();
00172 
00176     void updateRenderWorld();
00177 
00188     virtual void shareResourcesWith(ResourcesUser* buddy);
00189 
00190 private:
00198     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00199 
00208     virtual void customEvent(QEvent* event);
00209 
00213     void lookAtRobot();
00214 
00218     RenderWorld* const m_renderWorld;
00219 
00223     QVBoxLayout* const m_layout;
00224 
00231     bool m_renderWorldStateRestored;
00232 
00236     bool m_setCameraToLookAtRobot;
00237 
00243     wMatrix m_robotTm;
00244 };
00245 
00246 // namespace VisionMapSensorGuiInternal {
00247 //  class ImageDisplayer;
00248 // }
00249 // 
00250 // /**
00251 //  * \brief A gui visualizing the camera and the projection of objects on the
00252 //  *        retina
00253 //  *
00254 //  * This keeps the current image and adds marks on it. If you set a new image
00255 //  * all previous marks are lost
00256 //  */
00257 // class FARSA_EXPERIMENTS_API VisionMapSensorGui : public QWidget
00258 // {
00259 //  Q_OBJECT
00260 // 
00261 // public:
00262 //  /**
00263 //   * \brief Constructor
00264 //   *
00265 //   * \param mapWidth the width of the neural map
00266 //   * \param mapHeight the height of the neural map
00267 //   * \param parent the parent of this widget
00268 //   */
00269 //  VisionMapSensorGui(QWidget* parent=0, Qt::WindowFlags flags=0);
00270 // 
00271 //  /**
00272 //   * \brief Destructor
00273 //   */
00274 //  virtual ~VisionMapSensorGui();
00275 // 
00276 //  /**
00277 //   * \brief Sets the new image to display
00278 //   *
00279 //   * This resets the old image and also changes the dimension of the
00280 //   * widget to match that of the image
00281 //   * \param image the new image
00282 //   */
00283 //  void setImage(PhyiCub *icub, bool useRightCamera=true);
00284 // 
00285 //  /**
00286 //   * \brief Adds a mark on the image at the given position
00287 //   *
00288 //   * x and y are normalized (i.e. within 0 and 1) coordinates. They are
00289 //   * converted to the actual image coordinates by this function
00290 //   * \param x the x coordinate of the mark (must be between 0 and 1)
00291 //   * \param y the y coordinate of the mark (must be between 0 and 1)
00292 //   * \param markCenter the color of the central part of the mark
00293 //   * \param markSurrounding the color of the surrounding part of the mark
00294 //   */
00295 //  void addMark(double x, double y, QColor markCenter = Qt::black, QColor markSurrounding = Qt::white);
00296 // 
00297 // private:
00298 //  /**
00299 //   * \brief The image with marks
00300 //   */
00301 //  QImage m_image;
00302 // 
00303 //  /**
00304 //   * \brief The helper widget displaying the image
00305 //   */
00306 //  VisionMapSensorGuiInternal::ImageDisplayer* m_imageDisplayer;
00307 // };
00308 
00312 class FARSA_EXPERIMENTS_API TestIndividualGUI : public QWidget
00313 {
00314     Q_OBJECT
00315 private:
00316     TestIndividual* test;
00317     QStringList fileList;
00318     QComboBox* combo;
00319     QListWidget* list;
00320 public:
00321     TestIndividualGUI(TestIndividual* tb, QWidget *parent = NULL, Qt::WindowFlags flags=0);
00322 private slots:
00323     void agentClicked();
00324     void populateCombo();
00325     void seedWasChosen();
00326 };
00327 
00328 } //end namespace farsa
00329 
00330 #endif
00331