181 lines
4.6 KiB
C++
181 lines
4.6 KiB
C++
// MediumEdgeGradient.cpp: implementation of the CMediumEdgeGradient class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "geomative.h"
|
|
#include "MediumEdgeGradient.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
extern int g_iUILanguage;
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CMediumEdgeGradient::CMediumEdgeGradient(int iAR): CMedium(iAR)
|
|
{
|
|
|
|
}
|
|
|
|
CMediumEdgeGradient::~CMediumEdgeGradient()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMediumEdgeGradient::GenerateSptRecElecVal(int iEAmount, int* pMaxLevel, int* pPtAmount, CPtrArray* pSptRecArray)
|
|
{
|
|
if (iEAmount < 4)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("Edge Gradient中EA_MOUNT的个数是错误的!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("The number of EA_MOUNT in Edge Gradient is error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
if (NULL == pSptRecArray)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("pSptRecArray不能为空!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("pSptRecArray can't be NULL!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
pSptRecArray->RemoveAll();
|
|
//装置的位置顺序为AMNB
|
|
int iC1Pos = 1, iC2Pos = 4,iP1Pos = 2,iP2Pos = 3;
|
|
int iTsn = 0;
|
|
CSptRecord *pSptRec = NULL;
|
|
//此时固定A的位置不动,B点向右移动,然后M从2开始往右移动,MN的间距始终为1
|
|
while(iC2Pos <= iEAmount)
|
|
{
|
|
iP1Pos = 2;
|
|
iP2Pos = iP1Pos + 1;
|
|
while(iP2Pos <= iC2Pos-1)
|
|
{
|
|
pSptRec = new CSptRecord();
|
|
pSptRec->m_iC1 = iC1Pos;
|
|
pSptRec->m_iC2 = iC2Pos;
|
|
pSptRec->m_iP1 = iP1Pos;
|
|
pSptRec->m_iP2 = iP2Pos;
|
|
pSptRec->m_fK = CalculateCESptKVal(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
//由于不需要画剖面图,所以这里暂时对m_iPtNum赋值为0
|
|
pSptRec->m_iPtNum = 0;
|
|
// pSptRec->m_iPtNum = iC1Pos;
|
|
pSptRec->m_iLevel = GenSptRecLevel(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
pSptRec->m_colorREF = RGB(0, 255, 0);
|
|
pSptRec->m_iN = 1;
|
|
pSptRec->m_bIsSel = TRUE;
|
|
pSptRec->m_iTsn = ++iTsn;
|
|
pSptRecArray->Add(pSptRec);
|
|
iP1Pos++;
|
|
iP2Pos = iP1Pos+1;
|
|
}
|
|
iC2Pos++;
|
|
}
|
|
//此时将B不动,A开始移动
|
|
iC2Pos = iEAmount;
|
|
iC1Pos = 2;
|
|
while(TRUE)
|
|
{
|
|
iP1Pos = iC1Pos + 1;
|
|
iP2Pos = iP1Pos + 1;
|
|
if (iP2Pos >= iC2Pos)
|
|
{
|
|
break;
|
|
}
|
|
//开始将M,N循环向右移动
|
|
while(iP2Pos <= iC2Pos-1)
|
|
{
|
|
pSptRec = new CSptRecord();
|
|
pSptRec->m_iC1 = iC1Pos;
|
|
pSptRec->m_iC2 = iC2Pos;
|
|
pSptRec->m_iP1 = iP1Pos;
|
|
pSptRec->m_iP2 = iP2Pos;
|
|
pSptRec->m_fK = CalculateCESptKVal(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
//由于不需要画剖面图,所以这里暂时对m_iPtNum赋值为0
|
|
pSptRec->m_iPtNum = 0;
|
|
// pSptRec->m_iPtNum = iC1Pos;
|
|
pSptRec->m_iLevel = GenSptRecLevel(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
pSptRec->m_colorREF = RGB(0, 255, 0);
|
|
pSptRec->m_iN = 1;
|
|
pSptRec->m_bIsSel = TRUE;
|
|
pSptRec->m_iTsn = ++iTsn;
|
|
pSptRecArray->Add(pSptRec);
|
|
iP1Pos++;
|
|
iP2Pos = iP1Pos+1;
|
|
}
|
|
iC1Pos++;
|
|
}
|
|
|
|
*pPtAmount = pSptRecArray->GetSize();
|
|
*pMaxLevel = iEAmount-1;
|
|
return true;
|
|
}
|
|
|
|
float CMediumEdgeGradient::CalculateCESptKVal(float fA, float fB, float fX, float fY)
|
|
{
|
|
float fAM = fabs(fX - fA);
|
|
float fAN = fabs(fY - fA);
|
|
float fBM = fabs(fB - fX);
|
|
float fBN = fabs(fB - fY);
|
|
if (0 == fAM || 0 ==fAN || 0 == fBM || 0 == fBN)
|
|
{
|
|
return 0;
|
|
// AfxMessageBox(_T("Calcualte K value error.value = "))
|
|
}
|
|
return fabs(2*VAL_PI/(1.0/fAM - 1.0/fAN - 1.0/fBM + 1.0/fBN));
|
|
}
|
|
|
|
int CMediumEdgeGradient::GetMaxLevelByEAmount(int iEAmount)
|
|
{
|
|
if (iEAmount < 4)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("Edge Gradient中EA_MOUNT的个数是错误的!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("The number of EA_MOUNT in Edge Gradient is error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return 0;
|
|
}
|
|
int iC1Pos = 1, iC2Pos = 4,iP1Pos = 2,iP2Pos = 3;
|
|
int iCnt = 0;
|
|
|
|
//此时固定A的位置不动,B点向右移动,然后M从2开始往右移动,MN的间距始终为1
|
|
while(iC2Pos <= iEAmount)
|
|
{
|
|
iP1Pos = 2;
|
|
iP2Pos = iP1Pos + 1;
|
|
while(iP2Pos <= iC2Pos-1)
|
|
{
|
|
iCnt++;
|
|
iP1Pos++;
|
|
iP2Pos = iP1Pos+1;
|
|
}
|
|
iC2Pos++;
|
|
}
|
|
//此时将B不动,A开始移动
|
|
iC2Pos = iEAmount;
|
|
iC1Pos = 2;
|
|
while(TRUE)
|
|
{
|
|
iP1Pos = iC1Pos + 1;
|
|
iP2Pos = iP1Pos + 1;
|
|
if (iP2Pos >= iC2Pos)
|
|
{
|
|
break;
|
|
}
|
|
//开始将M,N循环向右移动
|
|
while(iP2Pos <= iC2Pos-1)
|
|
{
|
|
iCnt++;
|
|
iP1Pos++;
|
|
iP2Pos = iP1Pos+1;
|
|
}
|
|
iC1Pos++;
|
|
}
|
|
return iCnt;
|
|
} |