5 #define NULL_QTRANSFORM 0,0,0,0,0,0,0,0,0
7 void Transform::simple(const ReferencePoint
&p1
, const ReferencePoint
&p2
)
9 if (p1
.xy().x() == p2
.xy().x() || p1
.xy().y() == p2
.xy().y()) {
10 _errorString
= "Invalid reference points tuple";
14 double sX
= (p1
.xy().x() - p2
.xy().x()) / (p1
.pp().x() - p2
.pp().x());
15 double sY
= (p2
.xy().y() - p1
.xy().y()) / (p2
.pp().y() - p1
.pp().y());
16 double dX
= p2
.xy().x() - p2
.pp().x() * sX
;
17 double dY
= p1
.xy().y() - p1
.pp().y() * sY
;
19 _proj2img
= QTransform(sX
, 0, 0, sY
, dX
, dY
);
20 _img2proj
= _proj2img
.inverted();
23 void Transform::affine(const QList
<ReferencePoint
> &points
)
26 for (size_t i
= 0; i
< c
.h(); i
++) {
27 for (size_t j
= 0; j
< c
.w(); j
++) {
28 for (int k
= 0; k
< points
.size(); k
++) {
31 f
[0] = points
.at(k
).pp().x();
32 f
[1] = points
.at(k
).pp().y();
34 t
[0] = points
.at(k
).xy().x();
35 t
[1] = points
.at(k
).xy().y();
36 c
.m(i
,j
) += f
[i
] * t
[j
];
42 for (int qi
= 0; qi
< points
.size(); qi
++) {
45 v
[0] = points
.at(qi
).pp().x();
46 v
[1] = points
.at(qi
).pp().y();
48 for (size_t i
= 0; i
< Q
.h(); i
++)
49 for (size_t j
= 0; j
< Q
.w(); j
++)
50 Q
.m(i
,j
) += v
[i
] * v
[j
];
53 Matrix
M(Q
.augemented(c
));
55 _errorString
= "Singular transformation matrix";
59 _proj2img
= QTransform(M
.m(0,3), M
.m(0,4), M
.m(1,3), M
.m(1,4), M
.m(2,3),
61 _img2proj
= _proj2img
.inverted();
64 Transform::Transform()
65 : _proj2img(NULL_QTRANSFORM
), _img2proj(NULL_QTRANSFORM
)
69 Transform::Transform(const QList
<ReferencePoint
> &points
)
70 : _proj2img(NULL_QTRANSFORM
), _img2proj(NULL_QTRANSFORM
)
72 if (points
.count() < 2)
73 _errorString
= "Insufficient number of reference points";
74 else if (points
.size() == 2)
75 simple(points
.at(0), points
.at(1));
80 Transform::Transform(const ReferencePoint
&p1
, const ReferencePoint
&p2
)
81 : _proj2img(NULL_QTRANSFORM
), _img2proj(NULL_QTRANSFORM
)
86 Transform::Transform(const ReferencePoint
&p
, const PointD
&scale
)
87 : _proj2img(NULL_QTRANSFORM
), _img2proj(NULL_QTRANSFORM
)
89 if (scale
.x() == 0.0 || scale
.y() == 0.0) {
90 _errorString
= "Invalid scale factor";
94 _img2proj
= QTransform(scale
.x(), 0, 0, -scale
.y(), p
.pp().x() - p
.xy().x()
95 / scale
.x(), p
.pp().y() + p
.xy().x() / scale
.y());
96 _proj2img
= _img2proj
.inverted();
99 Transform::Transform(double matrix
[16])
100 : _proj2img(NULL_QTRANSFORM
), _img2proj(NULL_QTRANSFORM
)
102 _img2proj
= QTransform(matrix
[0], matrix
[1], matrix
[4], matrix
[5],
103 matrix
[3], matrix
[7]);
104 if (!_img2proj
.isInvertible())
105 _errorString
= "Singular transformation matrix";
107 _proj2img
= _img2proj
.inverted();
111 QDebug
operator<<(QDebug dbg
, const ReferencePoint
&p
)
113 dbg
.nospace() << "ReferencePoint(" << p
.xy() << ", " << p
.pp() << ")";
116 #endif // QT_NO_DEBUG