-
Notifications
You must be signed in to change notification settings - Fork 1
/
distortion.h
118 lines (100 loc) · 2.7 KB
/
distortion.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
#ifndef DISTRORTION_H
#define DISTRORTION_H
#include <QtCore>
#include <vector>
#include <utility>
/**
* @brief Distortion of image
* Distortion is presented by two polynomial who correct respectively
* the X and Y coordinate of pixels in a image.
* For a pixel (x, y) in image, after correction, it moves to (X, Y),
* and we have:
*
* X = polyX(x,y) = a0*x^0*y^0 + a1*x^1*y^0 + a2*x^0*y^1+ ...
* Y = polyY(x,y) = b0*x^0*y^0 + b1*x^1*y^0 + b2*x^0*y^1+ ...
*
* For example, when maxOrder=3:
* QList<QPair<double,double> >:
* xParam yParam
*
* a0 * x^0*y^0 b0 * x^0*y^0
*
* a1 * x^1*y^0 b1 * x^1*y^0
* a2 * x^0*y^1 b2 * x^0*y^1
*
* a3 * x^2*y^0 b3 * x^2*y^0
* a4 * x^1*y^1 b4 * x^1*y^1
* a5 * x^0*y^2 b5 * x^0*y^2
*
* a6 * x^3*y^0 b6 * x^3*y^0
* a7 * x^2*y^1 b7 * x^2*y^1
* a8 * x^1*y^2 b8 * x^1*y^2
* a9 * x^0*y^3 b9 * x^0*y^3
* size = 10 = (2+maxOrder) * (1+maxOrder) / 2
* maxOrder = -1 if the distortion is empty
*
*/
struct DistortionValue
{
DistortionValue();
std::vector<std::pair<double, double> > _XYData;
int _maxOrder;
int _size;
void setMaxOrder(int maxOrder);
bool isValid()const;
int sizeFromMaxOrder(int maxOrder)const
{
return maxOrder >= 0 ? (2+maxOrder)*(1+maxOrder)/2 : 0;
}
};
/**
* @brief The Distortion class
*
* @note All public functions of this class are thread-safe
*/
class Distortion : public QObject
{
Q_OBJECT
public:
Distortion(QObject *parent = 0);
bool isEmpty() const;
int maxOrder() const;
void setMaxOrder(int maxOrder);
int size() const;
/**
* @brief XYfromIdx
* @param idx index in array
* @param degX integer powers of X
* @param degY integer powers of Y
* X 0 1 2 3
* Y
* 0 0 1 3 6
* 1 2 4 7
* 2 5 8 <--idx
* 3 9
*
* e.g. idx=6, a6 -> x^3*y^0, so x=3 y=0
*/
static void XYfromIdx(int idx, int °X, int °Y);
static int idxFromXY(int degX, int degY);
DistortionValue getValue() const;
bool setValue(const DistortionValue &value);
bool setXParamVector(const std::vector<double> &xVector);
bool setYParamVector(const std::vector<double> &yVector);
void setXParam(double value, int degX, int degY);
void setYParam(double value, int degX, int degY);
void setXParam(double value, int idx);
void setYParam(double value, int idx);
int xParam(int degX, int degY) const;
int yParam(int degX, int degY) const;
double xParam(int idx) const;
double yParam(int idx) const;
void clear();
signals:
void dataChanged();
protected:
mutable QReadWriteLock rwLock;
private:
DistortionValue value;
};
#endif // DISTRORTION_H