evodataviewer.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 EVODATAVIEWER_H
25 #define EVODATAVIEWER_H
26 
27 #include "experimentsconfig.h"
28 #include <QWidget>
29 #include <QPixmap>
30 #include <QTimer>
31 #include <QListWidget>
32 #include <QGridLayout>
33 #include <QPushButton>
34 #include <QFile>
35 #include <QTextStream>
36 
37 namespace farsa {
38 
39 
40 //DataChunk class
41 class FARSA_EXPERIMENTS_API DataChunk
42 {
43 
44 
45 
46 
47 private:
48  QColor color;
49  QString label;
50  int size; //actual size of the array
51  double dpratio;// dat pixel ratio data size/pixels
52  bool visible;
53  int index;
54  double min, max;//range in case we need a normalization
55  double maxValue;
56 
57 
58  int style; //different visualization style 0: full line, 1: edge
59  double* data; //to be sized on size value;
60  double zeroValue;
61  void checkMaxValue(double val);
62 
63 
64 public:
65  DataChunk(const QString& label, const QColor& color, int size, bool visible);
66  ~DataChunk();
67  void setColor(QColor color);
68  void setData(double value);
69  void setDataRaw(double value); //not ranged
70  void setDataRaw(int ind, double value); //not ranged
71 
72 
73  void setRange(double min, double max);
74  void setLabel(const QString& label);
75  void setStyle(int style);
76  void setVisible(bool vis);
77  bool isVisible();
78  const QString& getLabel();
79  QColor& getColor();
80 
81  double getValueToDraw();
82  double getValue(int ind);
83  int getIndex();
84  double linearMap( double x, double rmin, double rmax,
85  double outMin = 0, double outMax = 1 );
86 
87 
88  double getRangeMin();
89  double getRangeMax();
90  double getMaxValue();
91  double getZeroValue();
92  void setDPRatio(double val);
93  double getDPRatio();
94  //loads space separated columns from a txt file
95  bool loadRawData(const QString& filename, int column);
96 
97 
98 
99 
100 };
101 //listwindow triggered by right mouse click ---------------------------------------------------------------------------------------
102 class FARSA_EXPERIMENTS_API EvoListViewer : public QWidget
103 {
104  Q_OBJECT
105 public:
106  EvoListViewer(DataChunk** dataChunks, int n, bool *nviewChange , QWidget *parent = 0);
107  ~EvoListViewer();
108  private slots:
109  void okSelected();
110  public slots:
111  void restoreSelected();
112  void allOnOrAllOff();
113 
114 
115 private:
116  int nchunks;
117  DataChunk** dataChunks;
118  QListWidget *listwidget;
119  QGridLayout *layout;
120  QPushButton* deselectAll;
121  bool *nvchange;
122  //EvoDataViewr *edv;
123  //void resizeEvent(QResizeEvent* evt);
124 
125 
126 
127 };
128 
129 
130 // EvodataViewer ----------------------------------------------------------------------------------------------------------------
131 
132 class FARSA_EXPERIMENTS_API EvoDataViewer : public QWidget
133 {
134  Q_OBJECT
135 public:
136  //EvoDataViewer();
137  EvoDataViewer(int nchunks, int chunksize, int style=0, QWidget* parent=0, Qt::WindowFlags flags=0);
138  ~EvoDataViewer();
139 
140  void setChunkLabel(int ch, const QString& label);
141  void setChunkValue(int ch, double value); //setting value by id
142  bool setChunkValue(const QString& name, double value); //setting value by chunk name
143  void setChunkColor(int ch, QColor color);
144  void setCurrentStep(int step);
145  void setStyle(int style);
146  void setChunkRange(int ch, double mn, double mx);
147  void setChunkProperties(int ch, double rangeMin, double rangeMax, const QString& label, QColor color, bool visible);
148  int visibleChunks();
149  void listVisibleChunks();
150  void reset();
151 private slots:
152  void pickUnvisible();
153 protected:
154  void paintEvent(QPaintEvent* evt);
155  void resizeEvent(QResizeEvent* evt);
156  void mousePressEvent(QMouseEvent* evt);
157 private:
158  void updateGraphic(int ch);//draws only latest data on the pixmap. ch is the chunk to update
159  QPixmap* qpixmap;
160  int dheight;
161  int dwidth;
162  int nchunks;
163  int nvchunks; //# of visible chunks
164  int chunksize;
165  DataChunk** dataChunks;
166  DataChunk* stepChunk; //here we set the current step/cycle
167  int vertical_step;
168  int label_width; //no pixels of the label column
169  int panning_width; //width between label column and data column in which we draw 3 pixels large line
170  int style;
171  double pickValue;
172  int pickStep;
173  bool pickValueVisible;
174  int pickX, pickY;
175  QTimer *qtimer;
176  EvoListViewer *elw;
177 
178  int *vchunks; //visible chunks
179 public:
180  bool nviewChange;
181 private:
182  void evoDataPaint();
183 
184 
185 };
186 
187 // Fitviewer
188 class FARSA_EXPERIMENTS_API FitViewer : public QWidget
189 {
190 
191 private:
192  DataChunk** dataChunks;
193  int nchunks;
194  int chunksize;
195 
196  double fitVal[4000][3];
197  int currentGen;
198  int padding;
199  double zerox, zeroy;
200  double vmin;
201  double vmax;
202  double wyaxes;
203  double xstep;
204  int* sortedIndex;
205  QString gtitle;
206  QString xlabel;
207  QString ylabel;
208 
209 public:
210  void setValues(int gen, double min, double average, double max);
211  FitViewer( QWidget* parent=0, Qt::WindowFlags flags=0 );
212  FitViewer(int nchunks, int chunkSize, QWidget* parent=0, Qt::WindowFlags flags=0);
213  ~FitViewer();
214 private:
215  double getYnormValue(double val);
216  int checkGraphRange(double val);
217 
218 protected:
219 void paintEvent(QPaintEvent* evt);
220 public:
221  void setChunkLabel(int ch, const QString &label);
222  void setChunkProperties(int ch, const QString &label, QColor color, bool visible);
223  void setChunkValue(int ch,int ind, double value); //setting value by id
224  bool setChunkValue(const QString& name,int ind, double value); //setting value by chunk name
225  void diplayUntilStep(int st);
226  void setLabels(const QString &title, const QString &xlabel, const QString &ylabel);
227  bool loadRawData(int nchunk, const QString &filename, int column);
228  void checkChunkRange(int chunk);
229  void reset();
230  int getCurrentGeneration();
231  void sortchunks();
232 
233 
234 };
235 
236 } //end namespace farsa
237 
238 #endif