-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphPicker.h
284 lines (221 loc) · 5.69 KB
/
GraphPicker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/**
\file
\author Javier Gonzalez
\version $Id: TEMPLATE.h.tpl,v 1.5 2003/09/25 14:38:19 lukas Exp $
\date 29 Aug 2011
TODO:
- logarithmic scale
- errors (both symmetric and asymetric)
- Clear
- undo
*/
#ifndef __imageviewer_h_
#define __imageviewer_h_
static const char CVSId__imageviewer[] =
"$Id$";
#include <QMainWindow>
#include <QScrollArea>
#include <vector>
#include <QPointF>
#include <QtGui>
#include <QGenericMatrix>
#include <ostream>
class QAction;
class QLabel;
class QMenu;
class QScrollBar;
class QMouseEvent;
namespace picker {
typedef QGenericMatrix<2,2, qreal> Matrix;
class Vector: public QGenericMatrix<1,2, qreal> {
public:
Vector(const QGenericMatrix<1,2, qreal>& values)
{
this->data()[0] = values.data()[0];
this->data()[1] = values.data()[1];
}
Vector(const qreal* values):
QGenericMatrix<1,2, qreal>(values)
{}
Vector()
{
this->data()[0] = 0.;
this->data()[1] = 0.;
}
Vector(qreal sx, qreal sy)
{
this->data()[0] = sx;
this->data()[1] = sy;
}
Vector(QPointF p)
{
this->data()[0] = p.x();
this->data()[1] = p.y();
}
Vector& operator=(const Vector& other)
{
this->data()[0] = other.data()[0];
this->data()[1] = other.data()[1];
return *this;
}
qreal x() const {return (*this)(0,0);}
qreal y() const {return (*this)(1,0);}
};
class Point {
public:
// Point(QPointF p):
// pos(p)
// {}
Point(Vector p):
pos(p)
{}
Vector pos;
Vector dxPlus;
Vector dxMinus;
Vector dyPlus;
Vector dyMinus;
};
class TopLayer;
class PointCollection {
public:
PointCollection(TopLayer* parent);
~PointCollection(){}
void AddPoint(double x, double y)
{
AddPoint(Vector(x,y));
}
void AddPoint(Vector pos);
Point& GetPoint(unsigned int i)
{return fPoints[i];}
const Point& GetPoint(unsigned int i) const
{return fPoints[i];}
void Paint(QPainter& painter);
template<class PointType>
bool Intersects(PointType pos) const;
template<class PointType>
Point& GetPoint(PointType pos);
template<class PointType>
const Point& GetPoint(PointType pos) const;
unsigned int GetSize() const
{ return fPoints.size(); }
void Clear()
{ fPoints.clear(); }
private:
template<class PointType>
int IntersectingIndex(PointType pos) const;
std::vector<Point> fPoints;
int fMarkerSize;
QBrush fBrush;
QPen fPen;
TopLayer* fParent;
};
class TopLayer: public QWidget {
Q_OBJECT
public:
TopLayer(QWidget * parent = 0);
~TopLayer(){}
const PointCollection& GetPoints() const
{ return fPoints; }
Vector FromPixelToTarget(const Vector& point) const;
Vector FromTargetToPixel(const Vector& point) const;
const Matrix& SizeMatrix() const;
const Matrix& InvSizeMatrix() const;
const Matrix& PixelToTargetMatrix()
{ return fPixelToTarget; }
const Matrix& TargetToPixelMatrix()
{ return fTargetToPixel; }
public slots:
void SetLogX(bool v)
{ fLogX=v; Calibrate(); }
void SetLogY(bool v)
{ fLogY=v; Calibrate(); }
//void SetCalibrated(bool c);
void Reset();
void Clear();
void ShowCrosshairs(bool show);
void ResetCrosshairs();
protected:
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void mouseDoubleClickEvent(QMouseEvent* event);
virtual void paintEvent(QPaintEvent* event);
private:
void Calibrate();
bool fIsCalibrated;
public:
bool fLogX;
bool fLogY;
bool fShowCrosshairs;
private:
QPointF fMousePos;
Vector fXaxis;
Vector fYaxis;
bool fCustomXaxis;
bool fCustomYaxis;
bool fSettingAxis;
bool fMousePressed;
Vector fEnd;
Vector fStart;
PointCollection fPoints;
std::vector<Vector> fTargetBase;
std::vector<Vector> fPixelBase;
std::vector<Vector> fCalibrationPointsImage;
std::vector<Vector> fCalibrationPointsTarget;
Matrix fPixelToTarget;
Matrix fTargetToPixel;
Matrix fCalibToPixel;
Matrix fPixelToCalib;
};
class GraphPicker : public QMainWindow
{
Q_OBJECT
public:
GraphPicker(std::string filename = "");
private slots:
void open(std::string filename = "");
void save();
void about();
//void ToggleCalibrate();
void Clear();
void SetLogX();
void SetLogY();
private:
void createActions();
void createMenus();
void createToolbar();
void updateActions();
void adjustScrollBar(QScrollBar *scrollBar, double factor);
QLabel* fImageLabel;
TopLayer* fTopWidget;
QScrollArea* fScrollArea;
QAction *openAct;
QAction *saveAct;
QAction *exitAct;
QAction *aboutAct;
QAction *aboutQtAct;
QAction *clearAct;
QAction *calibrateAct;
QAction *logYAct;
QAction *logXAct;
QAction *crossAct;
QAction *resetCrossAct;
QToolBar* fToolbar;
QMenu *fFileMenu;
QMenu *fHelpMenu;
};
template<int M, int N, typename T>
std::string ToString(const QGenericMatrix<M,N,T>& in);
std::ostream& operator<<(std::ostream& out, QGenericMatrix<2,2,qreal> m);
// 1-column, 2-rows (column vector)
std::ostream& operator<<(std::ostream& out, QGenericMatrix<1,2,qreal> m);
// 2-column, 1-rows (row vector)
std::ostream& operator<<(std::ostream& out, QGenericMatrix<2,1,qreal> m);
} // viewer
#endif // __imageviewer_h_
// Configure (x)emacs for this file ...
// Local Variables:
// mode:c++
// compile-command: "make -C .. -k"
// End: