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.
kev/Drawer/Module/GeoSigmaDraw/InterfaceVoronoi.cpp

240 lines
5.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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<CItemSelect *>(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<CCurveEx*> CollectFlts(CXy* pXy, CCurveEx *pBlock)
{
std::list<CCurveEx*> 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;
}
/**
* <20><><EFBFBD>ɹ걳ͼ
* Points<74><73>ʽ name1,x,y name2,x,y ...
**/
extern "C" __declspec(dllexport)
BSTR CreateVoronoi(CXy* pXy, LPCTSTR borderLine, LPCTSTR points) {
if (pXy == NULL) { return 0; }
vector<CString> 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;
}
// <20><><EFBFBD>ɱ߽<C9B1><DFBD><EFBFBD>
CCurveEx* pBlock = new CCurveEx();
pBlock->SetPoints(pts, 2);
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
std::vector<CWellPoint> wells;
vector<CString> 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;
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ڵĶϲ<C4B6> --Ŀǰ<C4BF>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>Ƕϲ<C7B6>
std::list<CCurveEx*> flts = CollectFlts(pXy, pBlock);
std::list<CPolyline> 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);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DZպ϶ϲ<CFB6>
if (dDist > dLength*0.1)
{
CPolyline plyFault = CurveExToPolyline(pCurveCur);
lstFaultLine.push_back(plyFault);
}
else
{ // <20>պ϶ϲ<CFB6>
CPolyline plyFault = CurveExToPolyline(pCurveCur);
lstFaultLine.push_back(plyFault);
// ɾ<><C9BE><EFBFBD>ϲ<EFBFBD><CFB2>ڵľ<DAB5>
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<CPolyline> results;
auto voronoiMap = std::make_unique<CVoronoiMap>();
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();
// <20><><EFBFBD><EFBFBD><EFBFBD>ǹ걳ͼ<EAB1B3><CDBC><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3 <20><><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>պϵĶ<CFB5><C4B6><EFBFBD><EFBFBD>ν
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();
}