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:
82 
83  ParameterSettableUIViewer evogaControls( QWidget* parent, Qt::WindowFlags flags );
84 // ParameterSettableUIViewer icubview( QWidget* parent, Qt::WindowFlags flags );
85  ParameterSettableUIViewer fitview( QWidget* parent, Qt::WindowFlags flags );
86  ParameterSettableUIViewer statview( QWidget* parent, Qt::WindowFlags flags );
87  ParameterSettableUIViewer renderWorld( QWidget* parent, Qt::WindowFlags flags );
88  ParameterSettableUIViewer testIndividualUI( TestIndividual* test, QWidget* parent, Qt::WindowFlags flags );
89 
90  EvoRobotComponent* evorobot;
91  Evoga* ga;
93  QWidget* statViewer;
94  FitViewer* ftv;
95 // VisionMapSensorGui *m_icubview; //! widget that visualize icub's camera content
96  RenderWorldWrapperWidget* renderworldwrapper;
97 
98  QLabel* infoEvoga;
100  QSlider* simulationThrottle;
102  QLabel* simulationSpeed;
103 
104 private slots:
106  void onWorldAdvance();
110  void onEvogaStartingReplication( int replication );
114  void onEvogaRecoveredInterruptedEvolution( QString statfile );
121  void onEvogaEndGeneration( int generation, double fmax, double faverage, double fmin );
122 
124  void onActionFinished();
125 
127  void evogaNextTrial();
128 
130  void onSimulationThrottleChanges( int newvalue );
131 
133  void loadStat();
135  void loadAllStat();
136 };
137 
146 class FARSA_EXPERIMENTS_API RenderWorldWrapperWidget : public QWidget, public ConcurrentResourcesUser
147 {
148 public:
155  RenderWorldWrapperWidget(QWidget* parent = NULL, Qt::WindowFlags flags = 0);
156 
160  virtual ~RenderWorldWrapperWidget();
161 
165  void updateRenderWorld();
166 
177  virtual void shareResourcesWith(ResourcesUser* buddy);
178 
179 private:
187  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
188 
197  virtual void customEvent(QEvent* event);
198 
202  void lookAtRobot();
203 
207  RenderWorld* const m_renderWorld;
208 
212  QVBoxLayout* const m_layout;
213 
220  bool m_renderWorldStateRestored;
221 
225  bool m_setCameraToLookAtRobot;
226 
232  wMatrix m_robotTm;
233 };
234 
235 // namespace VisionMapSensorGuiInternal {
236 // class ImageDisplayer;
237 // }
238 //
239 // /**
240 // * \brief A gui visualizing the camera and the projection of objects on the
241 // * retina
242 // *
243 // * This keeps the current image and adds marks on it. If you set a new image
244 // * all previous marks are lost
245 // */
246 // class FARSA_EXPERIMENTS_API VisionMapSensorGui : public QWidget
247 // {
248 // Q_OBJECT
249 //
250 // public:
251 // /**
252 // * \brief Constructor
253 // *
254 // * \param mapWidth the width of the neural map
255 // * \param mapHeight the height of the neural map
256 // * \param parent the parent of this widget
257 // */
258 // VisionMapSensorGui(QWidget* parent=0, Qt::WindowFlags flags=0);
259 //
260 // /**
261 // * \brief Destructor
262 // */
263 // virtual ~VisionMapSensorGui();
264 //
265 // /**
266 // * \brief Sets the new image to display
267 // *
268 // * This resets the old image and also changes the dimension of the
269 // * widget to match that of the image
270 // * \param image the new image
271 // */
272 // void setImage(PhyiCub *icub, bool useRightCamera=true);
273 //
274 // /**
275 // * \brief Adds a mark on the image at the given position
276 // *
277 // * x and y are normalized (i.e. within 0 and 1) coordinates. They are
278 // * converted to the actual image coordinates by this function
279 // * \param x the x coordinate of the mark (must be between 0 and 1)
280 // * \param y the y coordinate of the mark (must be between 0 and 1)
281 // * \param markCenter the color of the central part of the mark
282 // * \param markSurrounding the color of the surrounding part of the mark
283 // */
284 // void addMark(double x, double y, QColor markCenter = Qt::black, QColor markSurrounding = Qt::white);
285 //
286 // private:
287 // /**
288 // * \brief The image with marks
289 // */
290 // QImage m_image;
291 //
292 // /**
293 // * \brief The helper widget displaying the image
294 // */
295 // VisionMapSensorGuiInternal::ImageDisplayer* m_imageDisplayer;
296 // };
297 
301 class FARSA_EXPERIMENTS_API TestIndividualGUI : public QWidget
302 {
303  Q_OBJECT
304 private:
305  TestIndividual* test;
306  QStringList fileList;
307  QComboBox* combo;
308  QListWidget* list;
309 public:
310  TestIndividualGUI(TestIndividual* tb, QWidget *parent = NULL, Qt::WindowFlags flags=0);
311 private slots:
312  void agentClicked();
313  void populateCombo();
314  void seedWasChosen();
315 };
316 
317 } //end namespace farsa
318 
319 #endif
320