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.

199 lines
5.0 KiB
C++

#include "pch.h"
#include "GridManager.h"
CGridManager::CGridManager()
{
pDfg = nullptr;
m_insertTimes = 0;
}
CGridManager::~CGridManager()
{
Clear();
}
double valueNull = -1E301;
void CGridManager::SetGridData(double xMin, double yMin, double * pDataZ
, double nCols, int nRows, double dx, double dy
, double zMin, double zMax, int insertTimes
, double* borderData, int borderDataSize)
{
Clear();
//int nCount = nCols * nRows;
pDfg = new CDimension2D;
pDfg->Create(nCols, nRows, xMin, yMin, dx, dy);
CCurveEx* pBorder = nullptr;
if (borderDataSize > 0) {
pBorder = new CCurveEx;
CPointList ptsBorder;
int nPtCount = borderDataSize / 2;
for (int i = 0; i < nPtCount; i++) {
dfPoint dp;
dp.x0 = borderData[2 * i];
dp.y0 =borderData[2 * i + 1];
ptsBorder.AddTail(dp);
}
pBorder->SetPoints(ptsBorder, nPtCount);
}
for (int i = 0; i < nCols; i++)
{
for (int j = 0; j < nRows; j++)
{
////if (!IsPointInPolygon(x, y, pCurveBorder))
//if (Clipper2Lib::PointInPolygon(pt, pathBorder) == PointInPolygonResult::IsOutside)
//{
// pDfg->SetValue(i, j, valueNull);
// continue;
//}
if (pBorder) {
double dX = pDfg->x(i);
double dY = pDfg->y(j);
if (!pBorder->IsInside(dX, dY)) {
pDfg->SetValue(i, j, valueNull);
continue;
}
}
pDfg->SetValue(i, j, pDataZ[i*nRows + j]);
}
}
pDfg->range[0] = zMin;
pDfg->range[1] = zMax;
this->m_insertTimes = insertTimes;
if (pBorder != nullptr) {
delete pBorder;
pBorder = nullptr;
}
}
bool CGridManager::SaveFile(CString outputFile, double contourStep, int contourMarkStep)
{
if (pDfg == nullptr)
{
return false;
}
CXy* pXy = new CXy;
CMesh* pMeshNew = new CMesh();
CLayer* pLayer = pXy->FindAddLayer("背景");
POSITION posNew = pXy->AddElement(pMeshNew, DOUBLEFOX_MESH);
pXy->SetElementLayer(posNew, pLayer);
pMeshNew->SetMesh(pDfg, MESH_DFG, FALSE);
pMeshNew->m_nTimes = m_insertTimes;
// 生成等值线
CString strLayerMark = _T("Layer:\\等值线\\标注");
CString strLayerOther = _T("Layer:\\等值线\\无标注");
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);
}
/*// 等值线生成设置断层
COne* pOne;
CPtrList* pl = pXyFaults->GetValueList();
POSITION pos = pl->GetHeadPosition();
CLayer* pLayerFault = pXy->FindAddLayer("断层");
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);
}*/
if (abs(contourStep) > 1E-5)
{
vector<CCurve*>* pCurves = new std::vector<CCurve *>();
vector<CString*>* pLayers = new std::vector<CString *>();
pMeshNew->ContourCreate(pCurves, pLayers, contourStep, contourMarkStep,
strLayerMark, strLayerOther, pDfg->range[0], pDfg->range[1]);
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;
}
pMeshNew->EnableUpdateRuler(TRUE);
pMeshNew->UpdateColorRuler();
pXy->SaveAsWithExtension(outputFile);
delete pXy;
pDfg = nullptr;
return true;
}
void CGridManager::Clear()
{
m_insertTimes = 0;
if (pDfg != nullptr) {
delete pDfg;
pDfg = nullptr;
}
}
void CGridManager::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);
}
}