evorobotviewer.h
1 /********************************************************************************
2  * FARSA Experiments Library *
3  * Copyright (C) 2007-2012 *
4  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
5  * Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it> *
6  * Gianluca Massera <emmegian@yahoo.it> *
7  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the Free Software *
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
22  ********************************************************************************/
23 
24 #ifndef EVOROBOTVIEWER_H
25 #define EVOROBOTVIEWER_H
26 
27 #include "evorobotcomponent.h"
28 #include "parametersettableui.h"
29 #include "evoga.h"
30 #include "renderworld.h"
31 #include "evodataviewer.h"
32 
33 #include <QWidget>
34 #include <QMenu>
35 #include <QAction>
36 #include <QMenuBar>
37 #include <QFileDialog>
38 #include <QLabel>
39 #include <QList>
40 #include <QString>
41 #include <QWidget>
42 #include <QMenuBar>
43 #include <QVBoxLayout>
44 #include <QComboBox>
45 #include <QObject>
46 
47 namespace farsa {
48 
49 class PhyiCub;
50 // class VisionMapSensorGui;
51 class EvoRobotExperiment;
52 class TestIndividual;
53 class RenderWorldWrapperWidget;
54 
55 class FARSA_EXPERIMENTS_API EvoRobotViewer : public QObject, public ParameterSettableUI, public ConcurrentResourcesUser {
56  Q_OBJECT
57 public:
61  EvoRobotViewer( EvoRobotComponent* component );
63  ~EvoRobotViewer();
69  void fillActionsMenu( QMenu* actionsMenu );
75  QList<ParameterSettableUIViewer> getViewers( QWidget* parent, Qt::WindowFlags flags );
79  void addAdditionalMenus( QMenuBar* menuBar );
80 
81 private:
89  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
90 
91  ParameterSettableUIViewer evogaControls( QWidget* parent, Qt::WindowFlags flags );
92 // ParameterSettableUIViewer icubview( QWidget* parent, Qt::WindowFlags flags );
93  ParameterSettableUIViewer fitview( QWidget* parent, Qt::WindowFlags flags );
94  ParameterSettableUIViewer statview( QWidget* parent, Qt::WindowFlags flags );
95  ParameterSettableUIViewer renderWorld( QWidget* parent, Qt::WindowFlags flags );
96  ParameterSettableUIViewer testIndividualUI( TestIndividual* test, QWidget* parent, Qt::WindowFlags flags );
97 
98  EvoRobotComponent* evorobot;
99  Evoga* ga;
101  QWidget* statViewer;
102  FitViewer* ftv;
103 // VisionMapSensorGui *m_icubview; //! widget that visualize icub's camera content
104  RenderWorldWrapperWidget* renderworldwrapper;
105 
106  QLabel* infoEvoga;
107 
108 private slots:
110  void onWorldAdvance();
114  void onEvogaStartingReplication( int replication );
118  void onEvogaRecoveredInterruptedEvolution( QString statfile );
125  void onEvogaEndGeneration( int generation, int fmax, int faverage, int fmin );
126 
128  void onActionFinished();
129 
131  void evogaNextTrial();
132 
134  void loadStat();
136  void loadAllStat();
137 };
138 
147 class FARSA_EXPERIMENTS_API RenderWorldWrapperWidget : public QWidget, public ConcurrentResourcesUser
148 {
149 public:
156  RenderWorldWrapperWidget(QWidget* parent = NULL, Qt::WindowFlags flags = 0);
157 
161  virtual ~RenderWorldWrapperWidget();
162 
166  void updateRenderWorld();
167 
178  virtual void shareResourcesWith(ResourcesUser* buddy);
179 
180 private:
188  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
189 
198  virtual void customEvent(QEvent* event);
199 
203  void lookAtRobot();
204 
208  RenderWorld* const m_renderWorld;
209 
213  QVBoxLayout* const m_layout;
214 
221  bool m_renderWorldStateRestored;
222 
226  bool m_setCameraToLookAtRobot;
227 
233  wMatrix m_robotTm;
234 };
235 
236 // namespace VisionMapSensorGuiInternal {
237 // class ImageDisplayer;
238 // }
239 //
240 // /**
241 // * \brief A gui visualizing the camera and the projection of objects on the
242 // * retina
243 // *
244 // * This keeps the current image and adds marks on it. If you set a new image
245 // * all previous marks are lost
246 // */
247 // class FARSA_EXPERIMENTS_API VisionMapSensorGui : public QWidget
248 // {
249 // Q_OBJECT
250 //
251 // public:
252 // /**
253 // * \brief Constructor
254 // *
255 // * \param mapWidth the width of the neural map
256 // * \param mapHeight the height of the neural map
257 // * \param parent the parent of this widget
258 // */
259 // VisionMapSensorGui(QWidget* parent=0, Qt::WindowFlags flags=0);
260 //
261 // /**
262 // * \brief Destructor
263 // */
264 // virtual ~VisionMapSensorGui();
265 //
266 // /**
267 // * \brief Sets the new image to display
268 // *
269 // * This resets the old image and also changes the dimension of the
270 // * widget to match that of the image
271 // * \param image the new image
272 // */
273 // void setImage(PhyiCub *icub, bool useRightCamera=true);
274 //
275 // /**
276 // * \brief Adds a mark on the image at the given position
277 // *
278 // * x and y are normalized (i.e. within 0 and 1) coordinates. They are
279 // * converted to the actual image coordinates by this function
280 // * \param x the x coordinate of the mark (must be between 0 and 1)
281 // * \param y the y coordinate of the mark (must be between 0 and 1)
282 // * \param markCenter the color of the central part of the mark
283 // * \param markSurrounding the color of the surrounding part of the mark
284 // */
285 // void addMark(double x, double y, QColor markCenter = Qt::black, QColor markSurrounding = Qt::white);
286 //
287 // private:
288 // /**
289 // * \brief The image with marks
290 // */
291 // QImage m_image;
292 //
293 // /**
294 // * \brief The helper widget displaying the image
295 // */
296 // VisionMapSensorGuiInternal::ImageDisplayer* m_imageDisplayer;
297 // };
298 
302 class FARSA_EXPERIMENTS_API TestIndividualGUI : public QWidget
303 {
304  Q_OBJECT
305 private:
306  TestIndividual* test;
307  QStringList fileList;
308  QComboBox* combo;
309  QListWidget* list;
310 public:
311  TestIndividualGUI(TestIndividual* tb, QWidget *parent = NULL, Qt::WindowFlags flags=0);
312 private slots:
313  void agentClicked();
314  void populateCombo();
315  void seedWasChosen();
316 };
317 
318 } //end namespace farsa
319 
320 #endif
321