Copiste  0.1
 All Classes Functions Variables Enumerations Friends Pages
view2D.h
1 /*
2  * This file is part of Copiste.
3  *
4  * Copiste is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Copiste is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Copiste. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #ifndef INCLUDED_VIEW2DH
20 #define INCLUDED_VIEW2DH
21 
22 class View2D;
23 
24 #include "algo/neuralnetwork.h"
25 #include "algo/corpus.h"
26 #include "gui/viewport.h"
27 
28 #include <QWidget>
29 #include <QPainter>
30 #include <QPaintEvent>
31 #include <QTime>
32 
33 #include <iostream>
34 #include <stack>
35 
36 const int VIEW_OUTPUT_WIDTH = 700;
37 const int VIEW_OUTPUT_HEIGHT = 500;
38 const char POINT_0_PATH[16] = "img/point-0.png";
39 const char POINT_1_PATH[16] = "img/point-1.png";
40 const float CORPUS_EPSILON = 0.0001;
41 const int MAX_WIDTH_HISTORY = 2000;
42 const int TIME_BETWEEN_TWO_LABEL_UPDATES = 500; // in milliseconds
43 
44 void plotHistory(double* history, int size, int corpusSize);
45 
47 class View2D : public QWidget
48 {
49  Q_OBJECT
50  public:
52  View2D(QWidget *parent = 0);
53 
55  void renderToImage(std::string fileName, std::string format = "PNG",
56  int w = VIEW_OUTPUT_WIDTH, int h = VIEW_OUTPUT_HEIGHT);
57 
59  void setCorpus(Corpus *corpus);
61  void setNet(NeuralNetwork *net);
63  void updateQuadtree();
64 
66  void renderScene();
67 
69  Corpus* corpus();
71  NeuralNetwork* net();
72 
74  void handleKeyReleaseEvent(QKeyEvent *event);
75 
77  void setCurrentPoint(bool point);
78 
79  signals:
81  void rendering();
83  void rendered();
85  void hoveringElement(std::string);
86 
87  protected:
89  void paintEvent(QPaintEvent *event);
90 
92  void mouseMoveEvent(QMouseEvent *event);
94  void mousePressEvent(QMouseEvent *event);
96  void mouseReleaseEvent(QMouseEvent *event);
98  void keyReleaseEvent(QKeyEvent *event);
99 
101  void emitHoveringElement(std::string name);
102 
103  private:
104  Corpus *mCorpus;
105  NeuralNetwork *mNet;
106 
107  QPixmap mPoint0;
108  QPixmap mPoint1;
109 
110  // Viewport managing
111  Viewport mViewport;
112 
114  QTime mLastUpdate;
115 
116  // Dynamic zoom
117  bool mZooming;
118  int mStartX;
119  int mStartY;
120  int mCurrentX;
121  int mCurrentY;
122 
123  // Corpus editing
124  bool mCurrentPoint;
125 
126  // Zoom history
127  std::stack<Viewport> mZoomHistory;
128 };
129 
130 #endif
131