📄 testtrianglenetwork.cpp
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement. The various license agreements may be found at
// the Magic Software web site. This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License.html/free.pdf
#include <MgcCore.pkg>
#include <MgcInterpolation.pkg>
#include <images.h>
//----------------------------------------------------------------------------
void TestLinearInterpolator ()
{
const int iQuantity = 6;
MgcVector2* akVertex = new MgcVector2[iQuantity];
akVertex[0] = MgcVector2(-2.0,0.5);
akVertex[1] = MgcVector2(-1.0,0.0);
akVertex[2] = MgcVector2(0.0,1.0);
akVertex[3] = MgcVector2(1.0,0.0);
akVertex[4] = MgcVector2(3.0,1.0);
akVertex[5] = MgcVector2(0.0,-3.0);
MgcReal* afF0 = new MgcReal[iQuantity];
afF0[0] = 0.62;
afF0[1] = 0.73;
afF0[2] = 0.58;
afF0[3] = 0.79;
afF0[4] = 0.34;
afF0[5] = 0.11;
MgcLinearNetwork kNet0(iQuantity,akVertex,afF0);
// compute interpolated values on a grid
mgcImageFloat kImage(2,256);
MgcVector2 kP;
MgcReal fF;
int iX, iY;
for (iY = 0; iY < kImage.Bound(1); iY++)
{
kP.y = kNet0.GetYMin()+kNet0.GetYRange()*iY/kImage.Bound(1);
for (iX = 0; iX < kImage.Bound(0); iX++)
{
kP.x = kNet0.GetXMin()+kNet0.GetXRange()*iX/kImage.Bound(0);
if ( kNet0.Evaluate(kP,fF) )
kImage(iX,iY) = fF;
}
}
kImage.Save("lin0.im");
MgcReal* afF1 = new MgcReal[iQuantity];
afF1[0] = 0.11;
afF1[1] = 0.34;
afF1[2] = 0.79;
afF1[3] = 0.58;
afF1[4] = 0.73;
afF1[5] = 0.62;
MgcLinearNetwork kNet1(kNet0,afF1);
for (iY = 0; iY < kImage.Bound(1); iY++)
{
kP.y = kNet1.GetYMin()+kNet1.GetYRange()*iY/kImage.Bound(1);
for (iX = 0; iX < kImage.Bound(0); iX++)
{
kP.x = kNet1.GetXMin()+kNet1.GetXRange()*iX/kImage.Bound(0);
if ( kNet1.Evaluate(kP,fF) )
kImage(iX,iY) = fF;
}
}
kImage.Save("lin1.im");
}
//----------------------------------------------------------------------------
void TestQuadraticInterpolator ()
{
const int iQuantity = 6;
MgcVector2* akVertex = new MgcVector2[iQuantity];
akVertex[0] = MgcVector2(-2.0,0.5);
akVertex[1] = MgcVector2(-1.0,0.0);
akVertex[2] = MgcVector2(0.0,1.0);
akVertex[3] = MgcVector2(1.0,0.0);
akVertex[4] = MgcVector2(3.0,1.0);
akVertex[5] = MgcVector2(0.0,-3.0);
MgcReal* afF0 = new MgcReal[iQuantity];
afF0[0] = 0.62;
afF0[1] = 0.73;
afF0[2] = 0.58;
afF0[3] = 0.79;
afF0[4] = 0.34;
afF0[5] = 0.11;
// let interpolator estimate derivatives at samples
MgcQuadraticNetwork kNet0(iQuantity,akVertex,afF0);
// compute interpolated values on grid
mgcImageFloat kImF(2,256), kImFx(2,256), kImFy(2,256);
kImF = 0.0f;
MgcVector2 kP;
MgcReal fF, fFx, fFy;
int iX, iY;
for (iY = 0; iY < kImF.Bound(1); iY++)
{
kP.y = kNet0.GetYMin()+kNet0.GetYRange()*iY/kImF.Bound(1);
for (iX = 0; iX < kImF.Bound(0); iX++)
{
kP.x = kNet0.GetXMin()+kNet0.GetXRange()*iX/kImF.Bound(0);
if ( kNet0.Evaluate(kP,fF,fFx,fFy) )
{
kImF(iX,iY) = fF;
kImFx(iX,iY) = fFx;
kImFy(iX,iY) = fFy;
}
}
}
kImF.Save("quad0.im");
kImFx.Save("quadx0.im");
kImFy.Save("quady0.im");
// specify zero derivatives at the sample points
MgcReal* afF1x = new MgcReal[iQuantity];
MgcReal* afF1y = new MgcReal[iQuantity];
memset(afF1x,0,iQuantity*sizeof(MgcReal));
memset(afF1y,0,iQuantity*sizeof(MgcReal));
MgcReal* afF1 = new MgcReal[iQuantity];
afF1[0] = 0.62;
afF1[1] = 0.73;
afF1[2] = 0.58;
afF1[3] = 0.79;
afF1[4] = 0.34;
afF1[5] = 0.11;
// let interpolator estimate derivatives at samples
MgcQuadraticNetwork kNet1(kNet0,afF1,afF1x,afF1y);
for (iY = 0; iY < kImF.Bound(1); iY++)
{
kP.y = kNet1.GetYMin()+kNet1.GetYRange()*iY/kImF.Bound(1);
for (iX = 0; iX < kImF.Bound(0); iX++)
{
kP.x = kNet1.GetXMin()+kNet1.GetXRange()*iX/kImF.Bound(0);
if ( kNet1.Evaluate(kP,fF,fFx,fFy) )
{
kImF(iX,iY) = fF;
kImFx(iX,iY) = fFx;
kImFy(iX,iY) = fFy;
}
}
}
kImF.Save("quad1.im");
kImFx.Save("quadx1.im");
kImFy.Save("quady1.im");
}
//----------------------------------------------------------------------------
int main ()
{
TestLinearInterpolator();
TestQuadraticInterpolator();
return 0;
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -