1, const CSiteD& d0, const CSiteD& d1) :
m_mtx(s1 - s0, (s1 - s0).rot90 (), d1 - d0, (d1 - d0).rot90 ()),
m_stdSrc (s0),
m_stdDst (d0)
{
}
CAffine2D::CAffine2D (
const CSiteD& s, const CVector2D& sv0, const CVector2D& sv1,
const CSiteD& d, const CVector2D& dv0, const CVector2D& dv1) :
m_mtx(sv0, sv1, dv0, dv1), m_stdSrc (s), m_stdDst (d)
{
}
CAffine2D::CAffine2D (const CSiteD source [3], const CSiteD dest [3]) :
m_mtx (
source [1] - source [0],
source [2] - source [0],
dest [1] - dest [0],
dest [2] - dest [0]
),
m_stdSrc (source [0]),
m_stdDst (dest [0])
{
}
CAffine2D::CAffine2D (const CoordD params [6]) :
m_mtx (CVector2D (params [0], params [3]), CVector2D (params [1], params [4])),
m_stdSrc (0, 0),
m_stdDst (params [2], params [5])
{
}
CAffine2D CAffine2D::inverse () const
{
CAffine2D affInv;
affInv.m_mtx= m_mtx.inverse ();
affInv.m_stdSrc = m_stdDst;
affInv.m_stdDst = m_stdSrc;
return affInv;
}
CAffine2D CAffine2D::setOrigin (const CSiteD& std) const
{
CAffine2D r;
CVector2D vec;
r.m_mtx = m_mtx;
vec = m_mtx.apply (std - m_stdDst);
r.m_stdDst.x = std.x - vec.x;
r.m_stdDst.y = std.y - vec.y;
r.m_stdSrc = m_stdSrc;
return r;
}
Void CAffine2D::getParams (CoordD params [6]) const
{
params [0] = m_mtx.element (0, 0);
params [1] = m_mtx.element (0, 1);
params [3] = m_mtx.element (1, 0);
params [4] = m_mtx.element (1, 1);
params [2] = m_stdDst.x - params [0] * m_stdSrc.x - params [1] * m_stdSrc.y;
params [5] = m_stdDst.y - params [3] * m_stdSrc.x - params [4] * m_stdSrc.y;
}
CPerspective2D::~CPerspective2D ()
{
delete [] m_rgCoeff;
}
CPerspective2D::CPerspective2D ()
{
m_rgCoeff = NULL;
}
CPerspective2D::CPerspective2D (const UInt pntNum, const CSiteD source [4], const CSiteD dest [4], const UInt accuracy) : m_rgCoeff (NULL)
{
UInt uiScale = 1 << (accuracy + 1);
m_x0 = source [0].x;
m_y0 = source [0].y;
m_rgCoeff = new Double [9];
Double x [4], dx [4], y [4], dy [4], a[4][4];
for (UInt k = 0; k < pntNum; k++) {
m_rgstdSrc [k] = source [k];
m_rgstdDst [k] = dest [k] * uiScale;
x [k] = m_rgstdDst [k].x;
y [k] = m_rgstdDst [k].y;
}
Int width = (Int) (m_rgstdSrc [1].x - m_rgstdSrc [0].x);
Int height = (Int) (m_rgstdSrc [2].y - m_rgstdSrc [0].y);
if (pntNum == 1) {
a[1][1] = (Double) uiScale;
a[2][1] = 0;
a[3][1] = x [0];
a[1][2] = 0;
a[2][2] = (Double) uiScale;
a[3][2] = y [0];
a[1][3] = 0;
a[2][3] = 0;
a[3][3] = 1.0;
} else if (pntNum == 2) {
a[1][1] = (x [1] - x [0]) ;
a[2][1] = (y [0] - y [1]) ;
a[3][1] = x [0] * width;
a[1][2] = (y [1] - y [0]) ;
a[2][2] = (x [1] - x [0]) ;
a[3][2] = y [0] * width;
a[1][3] = 0;
a[2][3] = 0;
a[3][3] = width;
} else if (pntNum == 3) {
a[1][1] = (x [1] - x [0]) * height;
a[2][1] = (x [2] - x [0]) * width;
a[3][1] = x [0] * height * width;
a[1][2] = (y [1] - y [0]) * height;
a[2][2] = (y [2] - y [0]) * width;
a[3][2] = y [0] * height * width;
a[1][3] = 0;
a[2][3] = 0;
a[3][3] = height * width;
} else if (pntNum == 4) {
dx [1] = x [1] - x [3]; dx [2] = x [2] - x [3]; dx [3] = x [0] - x [1] + x [3] - x [2];
dy [1] = y [1] - y [3]; dy [2] = y [2] - y [3]; dy [3] = y [0] - y [1] + y [3] - y [2];
if ((dx [3] == 0 && dy [3] == 0) || pntNum == 3) {
a[1][1] = (x [1] - x [0]) * height;
a[2][1] = (x [2] - x [0]) * width;
a[3][1] = x [0] * height * width;
a[1][2] = (y [1] - y [0]) * height;
a[2][2] = (y [2] - y [0]) * w