#include "stdafx.h" #include "SigmaView.h" #include "ItemSelect.h" #include "VoronoiMap/InterfaceElements.h" #include "VoronoiMap/voronoimap.h" #include "../VoronoiMap/contourfillmap.h" static CPolyline CurveExToPolyline(CCurveEx * pCurve) { CPolyline polyline; polyline.SetName(pCurve->GetName()); for (int i = 0; i < pCurve->num; i++) { polyline.AddPoint(pCurve->x[i], pCurve->y[i], pCurve->z[i]); } return polyline; } static CItemSelect *getCItemSelectPtr(CSigmaView *pView) { CXy* pXy = pView->m_pDoc->GetDraw(); if (pXy == nullptr) { return nullptr; } CItem* pItem = pView->GetItem(); if (pItem == nullptr) { return nullptr; } return dynamic_cast(pItem); } extern "C" __declspec(dllexport) int VoronoiCreateMap(CSigmaView* pView) { CItemSelect * itemSelect = getCItemSelectPtr(pView); if (itemSelect == nullptr) { return 0; } return itemSelect->CreateVoronoiMap(); } extern "C" __declspec(dllexport) int DelaunayCreateMap(CSigmaView* pView) { CItemSelect * itemSelect = getCItemSelectPtr(pView); if (itemSelect == nullptr) { return 0; } return itemSelect->CreateDelaunayMap(); } extern "C" __declspec(dllexport) int SimplifySelectPoints(CSigmaView* pView, double minSpacing) { CItemSelect * itemSelect = getCItemSelectPtr(pView); if (itemSelect == nullptr) { return 0; } return itemSelect->SimplifySelectPoints(minSpacing); } std::list CollectFlts(CXy* pXy, CCurveEx *pBlock) { std::list result; CString faultLayer = pXy->GetFaultLayer(); if (faultLayer.IsEmpty()) { return result; } NBase::CPositionList select; CXyElementFilter filter; filter.addLayer(faultLayer, true) .addType(DOUBLEFOX_CURVE); pXy->GetElement(filter, select); for (POSITION pos = (select).GetHeadPosition(); pos != nullptr; (select).GetNext(pos)) { POSITION onePos = select.GetAt(pos); COne *pOne = pXy->GetAt(onePos); CCurveEx* pCurve = (CCurveEx*)(pOne->GetValue()); int inside = pBlock->IsInside(*pCurve); if (inside == 0) { continue; } else if (inside == -1) { } if (IsEqual(pCurve, pBlock)) { continue; } result.push_back(pCurve); } return result; } /** * 生成龟背图 * Points格式 name1,x,y name2,x,y ... **/ extern "C" __declspec(dllexport) BSTR CreateVoronoi(CXy* pXy, LPCTSTR borderLine, LPCTSTR points) { if (pXy == NULL) { return 0; } vector vecString; CString strTmp; int iPos = 0; while (AfxExtractSubString(strTmp, borderLine, iPos, ' ')) { iPos++; vecString.push_back(strTmp); } NBase::CPointList pts; double dX, dY; for (auto iter = vecString.begin(); iter != vecString.end(); ++iter) { CString strLine = *iter; int nCount = sscanf(strLine, "%lf,%lf", &dX, &dY); if (nCount >= 2) { NBase::dfPoint dp; dp.x0 = dX; dp.y0 = dY; pts.AddTail(dp); } } if (pts.GetSize() == 0) { return 0; } // 生成边界线 CCurveEx* pBlock = new CCurveEx(); pBlock->SetPoints(pts, 2); // 区域内点 std::vector wells; vector vecPointData; iPos = 0; while (AfxExtractSubString(strTmp, points, iPos, ' ')) { vecPointData.push_back(strTmp); iPos++; } char s[100]; memset(s, 0, sizeof(char) * 100); CString strPointName; for (auto iter = vecPointData.begin(); iter != vecPointData.end(); ++iter) { CString strLine = *iter; int nCount = sscanf(strLine, "%99[^,],%lf,%lf", s, &dX, &dY); if (nCount >= 3) { CWellPoint dp; dp.x0 = dX; dp.y0 = dY; strPointName = s; dp.SetName(strPointName); wells.push_back(dp); } } if (wells.size() == 0) { return 0; } // 获取区域内的断层 --目前先不考虑断层 std::list flts = CollectFlts(pXy, pBlock); std::list lstFaultLine; for (auto it = flts.begin(); it != flts.end();) { CCurveEx* pCurveCur = *it; double dLength = pCurveCur->Length(); if (dLength < 0.001) { it = flts.erase(it); continue; } NBase::dfPoint ptStart, ptEnd; pCurveCur->GetPoint(0, ptStart); pCurveCur->GetPoint(pCurveCur->num - 1, ptEnd); double dDist = ptStart.Distance(ptEnd); // 如果不是闭合断层 if (dDist > dLength*0.1) { CPolyline plyFault = CurveExToPolyline(pCurveCur); lstFaultLine.push_back(plyFault); } else { // 闭合断层 CPolyline plyFault = CurveExToPolyline(pCurveCur); lstFaultLine.push_back(plyFault); // 删除断层内的井 for (auto itWell = wells.begin(); itWell != wells.end();) { CWellPoint ptWell = *itWell; if (pCurveCur->IsInside(ptWell.x0, ptWell.y0)) { itWell = wells.erase(itWell); } else { ++itWell; } } } it++; } CPolyline border = CurveExToPolyline(pBlock); std::list results; auto voronoiMap = std::make_unique(); voronoiMap->SetFltClosingFraction(0.1); voronoiMap->ReadWellData(wells); voronoiMap->CreateMap(lstFaultLine, border); int nResult = voronoiMap->OutputResult(results); if (pBlock) { delete pBlock; } CString strResultData; for (auto polyLine : results) { int iCount = polyLine.GetSize(); // 如果是龟背图的折线,每个折线至少有 3 条边形成一个闭合的多边形结构 if (iCount <= 2) { continue; } CString strPolyName = polyLine.GetName(); strResultData.Append("Pline."); strResultData.Append(strPolyName); strResultData.Append("\r\n"); CString strCoord(""); for (int i = 0; i < iCount; i++) { CPointXYZ &xyz = polyLine.GetPoint(i); strCoord.Format("%lf,%lf ", xyz.x0, xyz.y0); strResultData.Append(strCoord); } strResultData.Append("\r\n"); } return strResultData.AllocSysString(); }