You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

971 lines
26 KiB
C++

1 month ago
#include "pch.h"
#include "IDWCreator.h"
#include <array>
#include "IDWCalculation.h"
#include <ppl.h>
#include <time.h>
int StepProgress::stepCount = 0;
int StepProgress::progress = 0;
int StepProgress::lastProgress = 0;
CPPCallback StepProgress::DoProgress = nullptr;
using namespace concurrency;
//int StepProgress::stepCount = 0;
//int StepProgress::progress = 0;
CIDWCreator::CIDWCreator()
{
//DoProgress = nullptr;
}
CIDWCreator::~CIDWCreator()
{
}
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
//inline double ConvertX2D(int64_t source, DPoint3& ptOrigin) {
// return source / 100.0 + ptOrigin.x;
//}
//inline double ConvertY2D(int64_t source, DPoint3& ptOrigin) {
// return source / 100.0 + ptOrigin.y;
//}
inline int64_t ConvertX2Int(double source, DPoint3& ptOrigin) {
return (source - ptOrigin.x) * 100;
}
inline int64_t ConvertY2Int(double source, DPoint3& ptOrigin) {
return (source - ptOrigin.y) * 100;
}
//void CALLBACK EXPORT TimerProc(
// HWND hWnd, // handle of CWnd that called SetTimer
// UINT nMsg, // WM_TIMER
// UINT_PTR nIDEvent, // timer identification
// DWORD dwTime // system time
//)
//{
// if (StepProgress::DoProgress != nullptr) {
// StepProgress::DoProgress(_T("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), (int)(((double)StepProgress::progress / StepProgress::stepCount)*100.0));
// }
//}
//************************************
// Method: Create
// FullName: CIDWCreator::Create
// Access: public
// Returns: void
// Qualifier:
// Parameter: CString xyzFile
// Parameter: CString borderFile
// Parameter: int XCount
// Parameter: int insertTimes
//************************************
void CIDWCreator::Create(CString xyzFile, CString borderFile, CString faultFile, CString resultFile,
int XCount, double smoothFactor, int smoothTimes, CPPCallback callBack,
int insertTimes, double contourStep, int contourMarkStep
, double xMin/* = -1*/, double yMin/* = -1*/, double xMax, double yMax) // double dSearchDistance,
{
StepProgress::DoProgress = callBack;
// <20><>ȡɢ<C8A1><C9A2>
vector<array<double, 3>> dataXyz;
std::string strXyzFile = string(xyzFile);
ReadInToMatrix(strXyzFile, dataXyz);
size_t len = dataXyz.size();
if (len < 5) {
return;
}
ptO.x = dataXyz[0][0];
ptO.y = dataXyz[0][1];
double dZMin = 1E100;
double dZMax = -1E100;
vector<DPoint3>* pPts = new vector<DPoint3>();
for (int i = 0; i < len; i++)
{
DPoint3 pt;
//pt.x = ConvertX2Int(dataXyz[i][0], ptO);
//pt.y = ConvertY2Int(dataXyz[i][1], ptO);
pt.x = dataXyz[i][0];
pt.y = dataXyz[i][1];
pt.z = dataXyz[i][2];
pPts->push_back(pt);
if (pt.z > dZMax) {
dZMax = pt.z;
}
if (pt.z < dZMin) {
dZMin = pt.z;
}
}
parallel_sort(pPts->begin(), pPts->end(), IDWCalculation::PointSort);
// <20><>ȡ<EFBFBD>߽<EFBFBD><DFBD>ļ<EFBFBD>
CCurveEx* pCurveBorder = nullptr;
CPositionList list;
CXy* pXyBorder = new CXy;
if (!borderFile.IsEmpty() && borderFile != "NULL")
{
OpenFile(borderFile, pXyBorder);
}
POSITION posBorder = NULL;
if (pXyBorder->GetElement(DOUBLEFOX_CURVE, list) > 0)
{
posBorder = list.GetHead();
pCurveBorder = (CCurveEx*)(pXyBorder->GetAtValue(posBorder));
//for (int i = 0; i < pCurveBorder->num; i++) {
// pCurveBorder->x[i] = ConvertX2Int(pCurveBorder->x[i], ptO);
// pCurveBorder->y[i] = ConvertY2Int(pCurveBorder->y[i], ptO);
//}
}
// <20>ϲ<EFBFBD><CFB2><EFBFBD>ȡ
CXy* pXyFaults = new CXy;
if (!faultFile.IsEmpty() && faultFile != "NULL") {
OpenFile(faultFile, pXyFaults);
}
//PathD lineClip;
//lineClip.push_back(PointD(5461.995, 7790.803));
//lineClip.push_back(PointD(5572.185351, 7918.825292));
//PathsD clip, solutionClosed, solutionOpen;
//clip.push_back(lineClip);
//ClipperD clipperD;
//clipperD.AddOpenSubject(clip);
//clipperD.AddClip(faultages);
//clipperD.Execute(ClipType::Intersection, FillRule::NonZero, solutionClosed, solutionOpen);
//if (solutionOpen.size() > 0) {
// for (int i = 0; i < solutionOpen.size(); i++) {
// TRACE("Pline\r\n");
// for (int j = 0; j < solutionOpen[i].size(); j++) {
// TRACE("%lf,%lf\r\n", solutionOpen[i][j].x, solutionOpen[i][j].y);
// }
// TRACE("\r\n");
// }
//}
//if (solutionClosed.size() > 0) {
// for (int i = 0; i < solutionClosed.size(); i++) {
// TRACE("Pline\r\n");
// for (int j = 0; j < solutionClosed[i].size(); j++) {
// TRACE("%lf,%lf\r\n", solutionClosed[i][j].x, solutionClosed[i][j].y);
// }
// TRACE("\r\n");
// }
//}
//return;
m_XMin = 1E100;
m_YMin = 1E100;
m_XMax = -1E100;
m_YMax = -1E100;
if (pCurveBorder != nullptr&&pCurveBorder->num >= 3)
{
CRect8 range;
range.SetRect(1e100, -1e100, -1e100, 1e100);
pCurveBorder->GetRange(range);
m_XMin = range.left;
m_XMax = range.right;
m_YMin = range.bottom;
m_YMax = range.top;
//m_XMin = ConvertX2Int(m_XMin, ptO);
//m_XMax = ConvertX2Int(m_XMax, ptO);
//m_YMin = ConvertY2Int(m_YMin, ptO);
//m_YMax = ConvertY2Int(m_YMax, ptO);
}
else
{
if (xMin > 0 && yMin > 0)
{ // ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>Χ
m_XMin = xMin;
m_YMin = yMin;
m_XMax = xMax;
m_YMax = yMax;
}
else {
for (auto& v : dataXyz) {
if (v[0] < m_XMin)
{
m_XMin = v[0];
}
if (v[0] > m_XMax)
{
m_XMax = v[0];
}
if (v[1] < m_YMin)
{
m_YMin = v[1];
}
if (v[1] > m_YMax)
{
m_YMax = v[1];
}
}
}
//m_XMin = ConvertX2Int(m_XMin, ptO);
//m_XMax = ConvertX2Int(m_XMax, ptO);
//m_YMin = ConvertY2Int(m_YMin, ptO);
//m_YMax = ConvertY2Int(m_YMax, ptO);
pCurveBorder = new CCurveEx;
CPointList bp;
dfPoint point;
point.x0 = m_XMin;
point.y0 = m_YMin;
bp.AddTail(point);
point.x0 = m_XMin;
point.y0 = m_YMax;
bp.AddTail(point);
point.x0 = m_XMax;
point.y0 = m_YMax;
bp.AddTail(point);
point.x0 = m_XMax;
point.y0 = m_YMin;
bp.AddTail(point);
point.x0 = m_XMin;
point.y0 = m_YMin;
bp.AddTail(point);
pCurveBorder->SetPoints(bp, 2);
pXyBorder->AddElement(pCurveBorder, DOUBLEFOX_CURVE);
}
ptO.x = m_XMin;
ptO.y = m_YMin;
// ɢ<><C9A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < len; i++)
{
pPts->at(i).x = ConvertX2Int(pPts->at(i).x, ptO);
pPts->at(i).y = ConvertY2Int(pPts->at(i).y, ptO);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
Paths64 faultages;
if (pXyFaults != nullptr) {
COne* pOne;
CPtrList* pl = pXyFaults->GetValueList();
POSITION pos = pl->GetHeadPosition();
while (pos)
{
pOne = pXyFaults->GetAt(pos);
if (pOne->GetType() == DOUBLEFOX_CURVE) {
CCurveEx* pCurve = (CCurveEx*)(pOne->GetValue());
Path64 path;
for (int i = 0; i < pCurve->num; i++) {
int64_t x = ConvertX2Int(pCurve->x[i], ptO);
int64_t y = ConvertY2Int(pCurve->y[i], ptO);
path.push_back(Point64(x, y));
}
faultages.push_back(path);
}
pl->GetNext(pos);
}
}
// <20><><EFBFBD><EFBFBD><E3B2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//int nInsertCount = pow(2, insertTimes); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->m_XCount = XCount;
this->m_dX = (m_XMax - m_XMin) / (this->m_XCount);
//double dDxInsert = this->m_dX / nInsertCount;
//int nXCountInsert = (m_XMax - m_XMin) / dDxInsert;
this->m_dY = this->m_dX;
//double dDyInsert = dDxInsert;
this->m_YCount = (m_YMax - m_YMin) / this->m_dY;
if (this->m_YCount*this->m_dY < m_YMax - m_YMin)
{
//this->m_YCount++;
}
this->m_XCount = (this->m_XCount + 1);
this->m_YCount = (this->m_YCount + 1);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CXy* pXy = new CXy;
CMesh* pMeshNew = new CMesh();
CLayer* pLayer = pXy->FindAddLayer("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
POSITION posNew = pXy->AddElement(pMeshNew, DOUBLEFOX_MESH);
pXy->SetElementLayer(posNew, pLayer);
CDimension2D* pDfg = new CDimension2D;
pDfg->Create(this->m_XCount, this->m_YCount, m_XMin, m_YMin, this->m_dX, this->m_dY);
//double valueNull = -1E301;
double dStepHalf = this->m_dX*0.5;
double dArea = 1;
if (pCurveBorder != nullptr&&pCurveBorder->num >= 3)
{
dArea = pCurveBorder->Area();
}
else {
dArea = abs((m_XMax - m_XMin)*(m_YMax - m_YMin));
}
IDWCalculation idw;
idw.SetArea(dArea);
idw.SetSortedData(pPts);
//idw.SetFaultages(&faultages); // <20><><EFBFBD>öϲ<C3B6>
double dSearchR = idw.TestR(ConvertX2Int((m_XMax + m_XMin) / 2.0, ptO), ConvertY2Int((m_YMax + m_YMin) / 2, ptO));
//DWORD start_time = GetTickCount64();
int nYCount = this->m_YCount;
StepProgress::stepCount = this->m_XCount;
StepProgress::progress = 0;
SetTimer(NULL, 0, 50, (TIMERPROC)CIDWCreator::TimerProc);
double valueNull = -1E301;
Path64 pathBorder;
int nCount = pCurveBorder->num;
for (int i = 0; i < nCount; i++)
{
pathBorder.push_back(Point64(
ConvertX2Int(pCurveBorder->x[i], ptO)
, ConvertY2Int(pCurveBorder->y[i], ptO)));
}
DPoint3 ptOO = ptO;
CIntersectionUtil m_IntersectHelp;
if (faultages.size() > 0)
{
m_IntersectHelp.SetSourceLines(&faultages);
}
parallel_for(0, this->m_XCount, [&pDfg, pathBorder, faultages,
&m_IntersectHelp, dStepHalf, &ptOO, dArea, pPts, dSearchR, nYCount, valueNull](int i)
//for (int i = 0; i < this->m_XCount; i++)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD>
IDWCalculation idw;
idw.SetArea(dArea);
idw.SetSortedData(pPts);
idw.SetSearchR(dSearchR);
if (faultages.size() > 0)
{
idw.SetFaultageHelp(&m_IntersectHelp); // <20><><EFBFBD>öϲ<C3B6>
}
double x = ConvertX2Int(pDfg->x(i), ptOO);// +dStepHalf;
for (int j = 0; j < nYCount; j++)
{
double z;
double y = ConvertY2Int(pDfg->y(j), ptOO);// +dStepHalf;
Point64 pt(x, y);
//if (!IsPointInPolygon(x, y, pCurveBorder))
if (Clipper2Lib::PointInPolygon(pt, pathBorder) == PointInPolygonResult::IsOutside)
{
pDfg->SetValue(i, j, valueNull);
continue;
}
z = idw.GetValue(x, y);
pDfg->SetValue(i, j, z);
//TRACE("i:%d, j:%d, %lf\r\n", i, j, z);
}
StepProgress::progress++;
//if (StepProgress::DoProgress != nullptr) {
// int nProg = (int)(((double)StepProgress::progress / StepProgress::stepCount)*100.0);
// if (nProg != StepProgress::lastProgress)
// {
// StepProgress::lastProgress = nProg;
// StepProgress::DoProgress(_T("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), nProg);
// }
//}
MSG msg;
if (PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE))
// if (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
);//
pDfg->range[0] = dZMin;
pDfg->range[1] = dZMax;
StepProgress::progress = StepProgress::stepCount;
// <20><><EFBFBD>й⻬
int nSmoothTimes = 1; // <20><EFBFBD><E2BBAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>3
if (smoothTimes > nSmoothTimes) {
nSmoothTimes = smoothTimes;
}
double nSmoothCoe = smoothFactor; // <20>⻬ϵ<E2BBAC><CFB5>
for (int i = 0; i < nSmoothTimes; i++)
{
SmoothMesh(pDfg, &m_IntersectHelp, nSmoothCoe);
//pDfg->Smooth(nSmoothCoe);
}
//DWORD end_time = GetTickCount64();
//CString strMsg;
//strMsg.Format("Time:%ld\t\n", end_time - start_time);
//TRACE(strMsg);
//::AfxMessageBox(strMsg);
//pDfg->range[0] = dZMin;
//pDfg->range[1] = dZMax;
//pDfg->GetRange();
pMeshNew->SetMesh(pDfg, MESH_DFG, FALSE);
pMeshNew->m_nTimes = insertTimes;// pow(2, insertTimes);
// <20><><EFBFBD>ɵ<EFBFBD>ֵ<EFBFBD><D6B5>
if (abs(contourStep) > 1E-5) {
CString strLayerMark = _T("Layer:\\<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD>ע");
CString strLayerOther = _T("Layer:\\<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>\\<EFBFBD>ޱ<EFBFBD>ע");
CString curLayerName = pXy->GetCurrentLayer()->GetPathName();
CLayer* pMarkLayer = pXy->FindLayer(strLayerMark);
CLayer* pOtherLayer = pXy->FindLayer(strLayerOther);
if (pMarkLayer == NULL)
{
pMarkLayer = pXy->FindAddLayer(strLayerMark);
pMarkLayer->HowToViewCurve = new CHowToViewCurve();
pMarkLayer->HowToViewCurve->EnableDrawSourceCurve(FALSE);
CCurveInName* pInName = new CCurveInName();
CRect8 rect = pMeshNew->GetRect();
pInName->text_h = rect.Width() / 300;
pInName->m_size.cx = pInName->text_h*0.06;
pInName->color = RGB(0, 0, 0);
pMarkLayer->HowToViewCurve->Add(pInName);
}
if (pOtherLayer == NULL)
{
pOtherLayer = pXy->FindAddLayer(strLayerOther);
pOtherLayer->HowToViewCurve = new CHowToViewCurve();
pOtherLayer->HowToViewCurve->EnableDrawSourceCurve(FALSE);
CCurveProperties* pview = new CCurveProperties();
pview->color = RGB(0, 0, 0);
pOtherLayer->HowToViewCurve->Add(pview);
}
// <20><><EFBFBD>öϲ<C3B6>
pDfg->CDimensionBase::EmptyLink();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶϲ<C4B6><CFB2><EFBFBD>Ϣ
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>öϲ<C3B6>
COne* pOne;
CPtrList* pl = pXyFaults->GetValueList();
POSITION pos = pl->GetHeadPosition();
CLayer* pLayerFault = pXy->FindAddLayer("<EFBFBD>ϲ<EFBFBD>");
while (pos)
{
pOne = pXyFaults->GetAt(pos);
if (pOne->GetType() == DOUBLEFOX_CURVE) {
CCurveEx* pCurveFault = (CCurveEx*)(pOne->GetValue());
CCurveEx* pCurveNew = new CCurveEx;
(*pCurveNew) = (*pCurveFault);
POSITION posNew = pXy->AddElement(pCurveNew, DOUBLEFOX_CURVE);
pXy->SetElementLayer(posNew, pLayerFault);
pDfg->Faultage(*(CCurve*)pCurveNew);
}
pl->GetNext(pos);
}
//CCurveEx* pCurve;
//COne* pOne;
//CPositionList select;
//if (pXy->GetElement("<22>ϲ<EFBFBD>", select, FALSE) > 0)
//{
// POSITION pt;
// POSITION pos = select.GetHeadPosition();
// while (pos)
// {
// pt = select.GetNext(pos);
// pOne = pXy->GetAt(pt);
// if (pOne->GetType() != DOUBLEFOX_CURVE) continue;
// pCurve = (CCurveEx*)pOne->GetValue();
// pDfg->Faultage(*(CCurve*)pCurve);
// }
//}
// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//pDfg->P0[0] = ConvertX2D(pDfg->P0[0], ptO);
//pDfg->P0[1] = ConvertY2D(pDfg->P0[1], ptO);
//m_XMin = ConvertX2D(m_XMin, ptO);
//m_YMin = ConvertY2D(m_YMin, ptO);
//m_XMax = ConvertX2D(m_XMax, ptO);
//m_YMax = ConvertY2D(m_YMax, ptO);
//this->m_dX = (m_XMax - m_XMin) / (this->m_XCount);
//this->m_dY = this->m_dX;
//pDfg->delt[0]= pDfg->delt[0]/100.0;
//pDfg->delt[1] = pDfg->delt[1]/100.0;
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ<EFBFBD><D6B5>
vector<CCurve*>* pCurves = new std::vector<CCurve *>();
vector<CString*>* pLayers = new std::vector<CString *>();
pMeshNew->ContourCreate(pCurves, pLayers, contourStep, contourMarkStep,
strLayerMark, strLayerOther, dZMin, dZMax);
//// <20>ָ<EFBFBD><D6B8><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//for (size_t i = 0; i < pCurves->size(); i++)
//{
// CCurve* pCurve = pCurves->at(i);
// if (pCurve == NULL) continue;
// for (int j = 0; j < pCurve->num; j++) {
// pCurve->x[j] = ConvertX2D(pCurve->x[j], ptO);
// pCurve->y[j] = ConvertY2D(pCurve->y[j], ptO);
// }
//}
AddContourCurve(pXy, pCurves, pLayers);
vector<CCurve *>::iterator it = pCurves->begin();
while (it != pCurves->end())
{
delete *it;
it = pCurves->erase(it);
}
vector<CString *>::iterator itL = pLayers->begin();
while (itL != pLayers->end())
{
delete *itL;
itL = pLayers->erase(itL);
}
delete pCurves;
delete pLayers;
}
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD>
pMeshNew->EnableUpdateRuler(TRUE);
pMeshNew->UpdateColorRuler();
pXy->SaveAsWithExtension(resultFile);
//MSG msg;
//BOOL bRet;
//clock_t start = clock();
//while(TRUE)
//{
// if (PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE) == TRUE)
// {
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// break;
// }
// clock_t finish = clock();
// if ((double)(finish - start) / CLK_TCK> 0.1)
// {
// break;
// }
//}
delete pPts;
pXyFaults->Clear();
delete pXyFaults;
delete pXyBorder;
delete pXy;
}
inline bool isPointFaultage(double ptX, double ptY, double otherX, double otherY, Paths64* faultages) {
Path64 lineSub;
lineSub.push_back(Point64(ptX, ptY));
lineSub.push_back(Point64(otherX, otherY));
Paths64 clip, solutionClosed, solutionOpen;
clip.push_back(lineSub);
Clipper64 clipperD;
clipperD.AddOpenSubject(clip);
clipperD.AddClip(*faultages);
clipperD.Execute(ClipType::Intersection, FillRule::NonZero, solutionClosed, solutionOpen);
if (solutionOpen.size() > 0) {
clipperD.Clear();
return true;
}
clipperD.Clear();
return false;
}
void CIDWCreator::SmoothMesh(CGrid* pGrid, CIntersectionUtil* intersectHelp, double smoothFactor /*= 1*/) {
if (smoothFactor < 1e-10) {
return;
}
int numx = pGrid->xnum();
int numy = pGrid->ynum();
double dZMin = pGrid->range[0] - 0.001;
double dZMax = pGrid->range[1] + 0.001;
DPoint3 ptOO = ptO;
//double dValueCur = 0, dValueTmp = 0;
//parallel_for(1, numx - 1, [&pGrid, intersectHelp, smoothFactor, &ptOO, dZMin, dZMax, numy](int i)
for (int i = 1; i < numx - 1; i++)
{
double dSigma = 0;
double dPtX = 0, dPtY = 0, dOtherX = 0, dOtherY = 0;
for (int j = 1; j < numy - 1; j++) {
double dValueCur = pGrid->Value(i, j);
if (dValueCur< dZMin || dValueCur>dZMax) {
continue;
}
dPtX = ConvertX2Int(pGrid->x(i), ptOO);
dPtY = ConvertY2Int(pGrid->y(j), ptOO);
dSigma = 0;
int nCount = 0;
double dValueTmp = pGrid->Value(i - 1, j - 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i - 1), ptOO), ConvertY2Int(pGrid->y(j - 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i, j - 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
//if (!isPointFaultage(dPtX, dPtY, pGrid->x(i), pGrid->y(j - 1), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i), ptOO), ConvertY2Int(pGrid->y(j - 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i + 1, j - 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
//if (!isPointFaultage(dPtX, dPtY, pGrid->x(i + 1), pGrid->y(j - 1), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i + 1), ptOO), ConvertY2Int(pGrid->y(j - 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i - 1, j);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
//if (!isPointFaultage(dPtX, dPtY, pGrid->x(i - 1), pGrid->y(j), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i - 1), ptOO), ConvertY2Int(pGrid->y(j), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i + 1, j);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
//if (!isPointFaultage(dPtX, dPtY, pGrid->x(i + 1), pGrid->y(j), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i + 1), ptOO), ConvertY2Int(pGrid->y(j), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i - 1, j + 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
// if (!isPointFaultage(dPtX, dPtY, pGrid->x(i - 1), pGrid->y(j + 1), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i - 1), ptOO), ConvertY2Int(pGrid->y(j + 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i, j + 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
// if (!isPointFaultage(dPtX, dPtY, pGrid->x(i), pGrid->y(j + 1), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i), ptOO), ConvertY2Int(pGrid->y(j + 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
dValueTmp = pGrid->Value(i + 1, j + 1);
if (dValueTmp >= dZMin && dValueTmp <= dZMax) {
//if (!isPointFaultage(dPtX, dPtY, pGrid->x(i + 1), pGrid->y(j + 1), &faultages))
if (!intersectHelp->Intersects(LineSegment(Point64(dPtX, dPtY)
, Point64(ConvertX2Int(pGrid->x(i + 1), ptOO), ConvertY2Int(pGrid->y(j + 1), ptOO)))))
{
dSigma += dValueTmp;
nCount++;
}
}
if (nCount == 0) {
return;
}
double dAverage = dSigma / nCount;
double dValueNew = (dValueCur + dAverage * smoothFactor) / (1.0 + smoothFactor);
pGrid->SetValue(i, j, dValueNew);
//TRACE("i:%d, j:%d, %lf\r\n", i, j, dValueNew);
}
}
//);
}
double precision = 1e-10;
bool CIDWCreator::IsPointInPolygon(double ptX, double ptY, CCurve* pCurve)
{
bool isIn = false;
int nCount = pCurve->num;
double dX1 = 0, dX2 = 0, dY1 = 0, dY2 = 0;
for (int i = 0; i < nCount - 1; i++)
{
dX1 = pCurve->x[i];
dY1 = pCurve->y[i];
dX2 = pCurve->x[i + 1];
dY2 = pCurve->y[i + 1];
// <20>жϵ<D0B6><CFB5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><CEB6><EFBFBD><EFBFBD>غ<EFBFBD>
if ((abs(dX1 - ptX) < precision && abs(dY1 - ptY) < precision)
|| (abs(dX2 - ptX) < precision && abs(dY2 - ptY) < precision))
{
return true;
}
// <20>жϵ<D0B6><CFB5>Ƿ<EFBFBD><C7B7><EFBFBD>ˮƽֱ<C6BD><D6B1><EFBFBD><EFBFBD>
if (abs(dY1 - dY2) < precision)
{
if (ptX >= min(dX1, dX2) - precision && ptX <= max(dX1, dX2) + precision)
{
return true;
}
continue;
}
// <20>ж<EFBFBD><D0B6>߶<EFBFBD><DFB6><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ((ptY >= dY1 - precision && ptY < dY2 + precision)
|| (ptY < dY1 + precision && ptY >= dY2 - precision))
{
// б<><D0B1>
double dK = (dX2 - dX1) / (dY2 - dY1);
// <20><EFBFBD><E0BDBB><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>
double dX = dX1 + dK * (ptY - dY1);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ݲ<EFBFBD>
if (abs(dX - ptX) < 1e-10) {
return true;
}
// <20><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>x<EFBFBD><EFBFBD><E1A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>εı<CEB5>
if (dX > ptX) {
isIn = !isIn;
}
}
}
return isIn;
}
void CALLBACK CIDWCreator::TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
int nProg = (int)(((double)StepProgress::progress / StepProgress::stepCount)*100.0);
if (StepProgress::DoProgress != nullptr) {
if (nProg != StepProgress::lastProgress)
{
StepProgress::lastProgress = nProg;
StepProgress::DoProgress(_T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), nProg);
}
}
StepProgress::lastProgress = nProg;
if (nProg == 100) {
KillTimer(nullptr, idEvent);
//::AfxMessageBox("Killed");
StepProgress::lastProgress = 0;
}
}
// <20><><EFBFBD><EFBFBD>
//{
//CDimension2D* pDfgInsert = new CDimension2D;
//pDfgInsert->Create(nXCountInsert, nYCountInsert, m_XMin, m_YMin, dDxInsert, dDyInsert);
//for (int i = 0; i < nXCountInsert; i++)
//{
// for (int j = 0; j < nYCountInsert; j++) {
// pDfgInsert->SetValue(i, j, valueNull);
// }
//}
//int nL, nR, nB, nT;
//double dF11, dF21, dF12, dF22;
//BOOL bz1, bz2, bz3, bz4;
//double zmin, zmax;
//for (long j = 0; j < m_YCount - 1; ++j)
//{
// for (long i = 0; i < m_XCount - 1; ++i)
// {
// dF11 = pDfg->Value(i, j);
// dF12 = pDfg->Value(i, j + 1);
// dF22 = pDfg->Value(i + 1, j + 1);
// dF21 = pDfg->Value(i + 1, j);
//
// for (int m = 0; m < nInsertCount; ++m)
// for (int n = 0; n < nInsertCount; ++n)
// {
// double dF = (dF11*(nInsertCount - m)*n +
// dF12 * (nInsertCount - m)*(nInsertCount - n) +
// dF22 * m*(nInsertCount - n) +
// dF21 * m*n) / nInsertCount / nInsertCount;
// pDfgInsert->SetValue(i*nInsertCount + m, j*nInsertCount + n, dF);
// }
// }
//}
//for (int i = 0; i < this->m_XCount; i++)
//{
// for (int j = 0; j < m_YCount; j++)
// {
// double dZCenter = pDfg->Value(i*nInsertCount, j*nInsertCount);
// //TRACE("dZCenter: %ld,%ld,%lf\r\n", i*nInsertCount, j*nInsertCount, z);
// if (i == 0) {
// nL = i;
// }
// else {
// nL = i - 1;
// }
// if (i == m_XCount - 1) {
// nR = m_XCount - 1;
// }
// else {
// nR = i + 1;
// }
// if (j == 0) {
// nB = j;
// }
// else {
// nB = j - 1;
// }
// if (j == m_YCount - 1) {
// nT = m_YCount - 1;
// }
// else {
// nT = j + 1;
// }
// double dF11 = pDfg->Value(nL, nB); // <20><><EFBFBD><EFBFBD>
// double dF21 = pDfg->Value(nR, nB); // <20><><EFBFBD><EFBFBD>
// double dF12 = pDfg->Value(nL, nT); // <20><><EFBFBD><EFBFBD>
// double dF22 = pDfg->Value(nR, nT); // <20><><EFBFBD><EFBFBD>
// //TRACE("%ld,%ld,%ld,%ld %lf,%lf,%lf,%lf\r\n", nL, nB, nR, nT, dF11, dF21, dF12, dF22);
// for (int m = 0; m < nInsertCount; m++)
// {
// for (int n = 0; n < nInsertCount; n++)
// {
// double dX = m + 0.5;
// double dY = n + 0.5;
// double dF = (dF11 * (nInsertCount - dX)*(nInsertCount - dY)
// + dF21 * (dX)*(nInsertCount - dY)
// + dF12 * (nInsertCount - dX)*(dY)
// +dF22 * dX*dY) / (nInsertCount * nInsertCount);
// pDfgInsert->SetValue(i*nInsertCount + m, j*nInsertCount + n, dF);
// //TRACE("%ld,%ld,%lf\r\n", i*nInsertCount + m, j*nInsertCount + n, dF);
// }
// }
// }
//}
//}
void CIDWCreator::AddContourCurve(CXy* pXy, vector<CCurve*>* curves, vector<CString*>* layer)
{
for (size_t i = 0; i < curves->size(); i++)
{
CCurve* pCurve = curves->at(i);
if (pCurve == NULL) continue;
CString* pName = layer->at(i);
CCurveEx *ce = new CCurveEx(pCurve->num);
for (int i = 0; i < ce->num; i++)
{
ce->x[i] = pCurve->x[i];
ce->y[i] = pCurve->y[i];
ce->z[i] = pCurve->z[i];
}
ce->nPoint = pCurve->nPoint;
ce->GetLocation();
POSITION pos = NULL;
if (pCurve->name)
ce->SetName(pCurve->name);
pos = pXy->AddElement(ce, DOUBLEFOX_CURVE);
pXy->SetElementLayer(pos, *pName);
}
}
bool CIDWCreator::Calculate()
{
return true;
}
void CIDWCreator::ReadInToMatrix(string FilePath, vector<array<double, 3>>& data)
{
ifstream in;
in.open(FilePath, ios::in);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>file
if (!in.is_open()) {
//cout << "Can not find " << FilePath << endl;
system("pause");
}
int nDim = 3;
// <20>ԡ<EFBFBD>,<2C><>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char seps[] = " ,\t\n";
string buff;
while (getline(in, buff)) {
array<double, 3> nums = { 0 };
// string->char *
char *s_input = (char *)buff.c_str();
char *token = strtok(s_input, seps);
double a;
int i = 0;//<2F><><EFBFBD><EFBFBD>i
while (token != NULL) {
a = atof(token);
nums[i] = a;
i++;
if (i > 2) break;
token = strtok(NULL, seps);
} // end while
// <20><><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
if (i < 3) continue;
data.push_back(nums);
}//end while
in.close();
//cout << "get data" << endl;
}
bool CIDWCreator::OpenFile(LPCTSTR lpszFileName, CXy* pXy)
{
if (pXy->ReadOtherWithExtension(lpszFileName))
{
return true;
}
CFile file;
if (file.Open(lpszFileName, CFile::modeRead))
{
// m_FileName = lpszFileName;
CArchive ar(&file, CArchive::load);
Serialize(ar, pXy);
ar.Close();
}
else
{
return false;
}
file.Close();
return true;
}
void CIDWCreator::Serialize(CArchive& ar, CXy* pXy)
{
if (ar.IsStoring()) {}
else
{
if (pXy == nullptr) pXy = new CXy;
pXy->m_bRealTimeDraw = false;
CString name = ar.GetFile()->GetFileName();
name.MakeLower();
CSplitPath sp(name);
CString ext = sp.GetExtension();
//ar.m_pDocument = this; // set back-pointer in archive
if (ext == _T(".dfb") ||
ext == _T(".dft"))
{
pXy->m_version = pXy->DFB_ReadVersion(ar);
pXy->DFB_ReadEncrypt(ar, pXy->m_version);
if (pXy->IsEncrypted()) {
}
pXy->DFB_Serialize(ar, pXy->m_version);
}
else if (ext == ".dml" || ext == ".xml")
pXy->DML_Read2(*(ar.GetFile()));
else if (ext == ".pcg")
pXy->PCG_Read2(*(ar.GetFile()));
else
pXy->DFD_Read2(*(ar.GetFile()));
}
}