【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了warp.cpp相关资料,希望对各位网友有所帮助!
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
Bruce Lin (blin@microsoft.com), Microsoft Corporation
Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
(date: March, 1996)
and also edited by
Yuichiro Nakaya (Hitachi, Ltd.)
Yoshinori Suzuki (Hitachi, Ltd.)
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Microsoft retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Module Name:
warp.cpp
Abstract:
Geometry transformation:
2D Affine
2D Perspective
Revision History:
Jan. 13, 1999: Code for disallowing zero demoninators in perspective
warping added by Hitachi, Ltd.
*************************************************************************/
#include <math.h>
#include "basic.hpp"
#include "svd.h"
#include "warp.hpp"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
CVector2D CMatrix2x2D::apply (const CVector2D& v) const
{
return CVector2D (
m_value [0] [0] * v.x + m_value [0] [1] * v.y,
m_value [1] [0] * v.x + m_value [1] [1] * v.y
);
}
CMatrix2x2D::CMatrix2x2D (Double d)
{
m_value [0] [0] = d;
m_value [1] [1] = d;
m_value [0] [1] = 0;
m_value [1] [0] = 0;
}
CMatrix2x2D::CMatrix2x2D (Double d00, Double d01, Double d10, Double d11)
{
m_value [0] [0] = d00;
m_value [1] [1] = d11;
m_value [0] [1] = d01;
m_value [1] [0] = d10;
}
CMatrix2x2D::CMatrix2x2D (const CVector2D& v0, const CVector2D& v1, Bool fAsColumns)
{
m_value [0] [0] = v0.x;
m_value [1] [0] = v0.y;
m_value [0] [1] = v1.x;
m_value [1] [1] = v1.y;
if (!fAsColumns) transpose ();
}
CMatrix2x2D::CMatrix2x2D (const CVector2D v [2])
{
*this = CMatrix2x2D (v [0], v [1]);
}
CMatrix2x2D CMatrix2x2D::operator * (const CMatrix2x2D& x) const
{
CMatrix2x2D r;
r.m_value [0] [0] = m_value [0] [0] * x.m_value [0] [0] + m_value [0] [1] * x.m_value [1] [0];
r.m_value [1] [0] = m_value [1] [0] * x.m_value [0] [0] + m_value [1] [1] * x.m_value [1] [0];
r.m_value [0] [1] = m_value [0] [0] * x.m_value [0] [1] + m_value [0] [1] * x.m_value [1] [1];
r.m_value [1] [1] = m_value [1] [0] * x.m_value [0] [1] + m_value [1] [1] * x.m_value [1] [1];
return r;
}
CMatrix2x2D::CMatrix2x2D (const CVector2D& s0, const CVector2D& s1, const CVector2D& d0, const CVector2D& d1)
{
*this = CMatrix2x2D (d0, d1) * CMatrix2x2D (s0, s1).inverse ();
}
CMatrix2x2D::CMatrix2x2D (const CVector2D source [2], const CVector2D dest [2])
{
*this = CMatrix2x2D (source [0], source [1], dest [0], dest [1]);
}
CMatrix2x2D CMatrix2x2D::inverse () const
{
Double det = determinant ();
if (det == 0) // ill conditioned -- make this a better test
{
return CMatrix2x2D ((Double) 0);
}
CMatrix2x2D r;
Double detInv = (Double) 1.0 / det;
r.m_value [0] [0] = m_value [1] [1] * detInv;
r.m_value [1] [1] = m_value [0] [0] * detInv;
r.m_value [0] [1] = - m_value [0] [1] * detInv;
r.m_value [1] [0] = - m_value [1] [0] * detInv;
return r;
}
Void CMatrix2x2D::transpose ()
{
Double tmp = m_value [0] [1];
m_value [0] [1] = m_value [1] [0];
m_value [1] [0] = tmp;
}
CAffine2D::CAffine2D (const CSiteD& source, const CSiteD& dest) :
m_mtx(1.), m_stdSrc (source), m_stdDst (dest)
{
// thats all folks
}
CAffine2D::CAffine2D (const CSiteD& s0, const CSiteD& s