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/GVision/FaultAmplitudeLib/FaultAmplitudeCreator.cpp

1169 lines
26 KiB
C++

1 month ago
#include "stdafx.h"
#include "FaultAmplitudeCreator.h"
#include "../BaseLib/GDfdMap.h"
#include "../BaseLib/GSurface.h"
#include "../BaseLib/PublicFunctions.h"
#include<list>
#include <fstream>
#include <sstream>
#include <string>
#include <codecvt>
using namespace std;
FAmplitudeInfo::FAmplitudeInfo()
:fltName("")
, surveyName("")
, x0(0)
, y0(0)
,xMid(0)
,yMid(0)
, amplitude(0)
, angle(0)
, horizontal_dist(0.0)
{
}
FAmplitudeInfo::~FAmplitudeInfo()
{
}
CFaultAmplitudeCreator::CFaultAmplitudeCreator()
:m_dfdMap(nullptr)
, m_dfg(nullptr)
, m_strOutDfd(_T(""))
, m_strOutCsv(_T(""))
, m_strFltLayer(_T(""))
, m_strSurveyLayer(_T(""))
, m_strFltNameFile(_T(""))
, m_strFltNames(_T(""))
, m_iCalcMethod(0)
, m_pillarStep(10.0) //
, m_thresholdValue(0) //
, m_clrLow(RGB(0, 0, 255)) //С
, m_clrHigh(RGB(255, 0, 0)) //<2F><>
, m_PillarWidth(5) //<2F><>
, m_PillarHeightRatio(1.0)
, m_TextHeight(10) //<2F><><EFBFBD>ָ߶<D6B8>
,m_bLocalFltDirect(false)
, m_bWithIncline(false)
, m_inclineScale(10)
, m_clrIncline(RGB(255, 0, 0))
{
m_strLayerPillarHigh = "<EFBFBD>Ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD>ֵ";
m_strLayerPillarLow = "<EFBFBD>Ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD>ֵ";
m_strLayerPillarText = "<EFBFBD>Ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
m_strLayerPillarIncline = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
m_strLayerTextIncline = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
m_surveyAngle = PI;
}
CFaultAmplitudeCreator::~CFaultAmplitudeCreator()
{
Clear();
}
void CFaultAmplitudeCreator::Clear(void)
{
if (m_dfdMap)
delete m_dfdMap;
if (m_dfg)
delete m_dfg;
m_dfdMap = nullptr;
m_dfg = nullptr;
m_strOutDfd = (_T(""));
m_strOutCsv = (_T(""));
m_strFltLayer = (_T(""));
m_strSurveyLayer = (_T(""));
m_strFltNameFile = (_T(""));
m_tarFltNames.clear();
m_candidateFlts.clear();
m_ampResults.clear();
ErasePillarPgns();
m_strFltNames = (_T(""));
}
bool CFaultAmplitudeCreator::ReadDfdMap(const char* strFile) //<2F><>ȡdfdͼ<64><CDBC>
{
if (m_dfdMap)
delete m_dfdMap;
m_strInputDfd = strFile;
m_dfdMap = new GDfdMap();
if (!m_dfdMap->ReadFile(strFile))
{
delete m_dfdMap;
m_dfdMap = nullptr;
return false;
}
return true;
}
bool CFaultAmplitudeCreator::ReadDfg(const char* strDfg) //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (m_dfg)
delete m_dfg;
m_strInputDfg = strDfg;
m_dfg = new GSurface();
if (!m_dfg->ReadDfg(strDfg))
{
delete m_dfg;
m_dfg = nullptr;
return false;
}
//begin test
m_dfg;
//end test
return true;
}
bool CFaultAmplitudeCreator::CreateDfg(int numx, int numy, double x0, double y0, double dx, double dy, double* values) {
if (m_dfg)
delete m_dfg;
m_dfg = new GSurface();
if (!m_dfg->Create(numx, numy, x0, y0, dx, dy, values))
{
delete m_dfg;
m_dfg = nullptr;
return false;
}
return true;
}
void CFaultAmplitudeCreator::SetZRange(double zmin, double zmax)
{
if (m_dfg) {
m_dfg->SetZRange(zmin, zmax);
}
}
GDfdMap* CFaultAmplitudeCreator::GetDfd(void)
{
return m_dfdMap;
}
GSurface* CFaultAmplitudeCreator::GetDfg(void)
{
return m_dfg;
}
////begin test
//FILE* gfw = 0;
////end test
void CFaultAmplitudeCreator::CalcAmplitudeWithSurvey(void)
{
m_ampResults.clear();
GetCandidateSurveys();
GPline* pFlt = 0;
GPline* pSvy = 0;
GRect8 rtFlt, rtSvy;
FAmplitudeInfo fminfo;
////begin test
//gfw = fopen("f:/testsegs.dfd", "w");
////end test
for (int j = 0; j < m_candidateFlts.size(); j++)
{
pFlt = m_candidateFlts[j];
rtFlt = m_fltRects[j];
for (int i = 0; i < m_candidateSurveys.size(); i++)
{
pSvy = m_candidateSurveys[i];
rtSvy = m_surveyRects[i];
//<2F><><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD>
if (!rtFlt.IsIntersected(rtSvy))
continue;
if (GetFltAmplitudeInfo(pFlt, pSvy, fminfo))
{
m_ampResults.push_back(fminfo);
}
}
}
////begin test
//fclose(gfw);
////end test
}
double CFaultAmplitudeCreator::GetAmplitude(const GPoint3D& pt, const GPoint3D& ptStart, const GPoint3D& ptEnd)
{
if (nullptr == m_dfg)
return 0.0;
double dV = m_dfg->Z(pt.x0, pt.y0);
if (!m_dfg->IsInRange(dV))
{
return 0.0;
}
vector<GPoint3D> ptsClockwize, ptsCounterclockwize;
double v1 = 0.0, v2 = 0.0;
size_t nCount = m_dfg->Value(pt.x0, pt.y0, ptStart.x0, ptStart.y0, ptEnd.x0, ptEnd.y0, true, ptsClockwize);
size_t nCountCounter = m_dfg->Value(pt.x0, pt.y0, ptStart.x0, ptStart.y0, ptEnd.x0, ptEnd.y0, false, ptsCounterclockwize);
if (nCount == 0 || nCountCounter == 0) {
return 0.0;
}
for (int i = 0; i < nCount; i++) {
v1 += ptsClockwize.at(i).z0 / nCount;
}
for (int i = 0; i < nCountCounter; i++) {
v2 += ptsCounterclockwize.at(i).z0 / nCountCounter;
}
if (m_dfg->IsInRange(v1) && m_dfg->IsInRange(v2))
return fabs(v2 - v1);
return 0.0;
}
double CFaultAmplitudeCreator::GetAmplitude(const GPoint3D& pt1, const GPoint3D& pt2,
GPline* pFlt)// pt1 pt2Ϊ<32>ϵ<EFBFBD> pFltΪ<74>ϲ<EFBFBD>
{
if (nullptr == m_dfg)
return -1E100;
double v1 = 0.0, v2 = 0.0;
if (nullptr != pFlt && pFlt->IsClosed(1e-4))
{
v1 = m_dfg->Value(pt1.x0, pt1.y0, pFlt);
v2 = m_dfg->Value(pt2.x0, pt2.y0, pFlt);
}
else
{
v1 = m_dfg->Z(pt1.x0, pt1.y0);
v2 = m_dfg->Z(pt2.x0, pt2.y0);
}
if (m_dfg->IsInRange(v1) && m_dfg->IsInRange(v2))
return fabs(v2 - v1);
return -1E100;
}
//<2F><>ȡ<EFBFBD><C8A1>ֱ<EFBFBD>Ͼ࣬pt1Ϊ<31>ϲ<EFBFBD><CFB2>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>㣬angleΪ<65>Ƕȣ<C7B6>д<EFBFBD><D0B4>fmInfo
bool CFaultAmplitudeCreator::Get2rdPoint(GPline* pFlt, GPoint3D& ptScr, double angle, GPoint3D& dstPt)
{
double cosa = cos(angle);
double sina = sin(angle);
GPline* pl = CreateLine(ptScr.x0, ptScr.y0, sina, cosa, pFlt->GetLength());
if (nullptr == pl)
return false;
list<GPoint3D> cxpts;
list<int> cxpIndexs;
dstPt = ptScr;
int flag = pFlt->GetCrossPoints(*pl, cxpts, cxpIndexs);
delete pl;
if (flag < 1)
return false;
list<GPoint3D>::iterator iter = cxpts.begin();
double dist = 1e301;
double minDist = dist;
for (; iter != cxpts.end(); iter++ )
{
dist = ptScr.Distance2D(*iter);
if (fabs(dist) < 1e-6)
continue;
if (dist < minDist)
{
minDist = dist;
dstPt = *iter;
}
}
return true;
}
bool CFaultAmplitudeCreator::GetFltAmplitudeInfo(GPline* pFlt, GPline* pSvy, FAmplitudeInfo& fmInfo)
{
////begin test
//TRACE("angle = %.4g %.4g\n", pFlt->GetAverageDirection() / PI * 180,
// pSvy->GetAverageDirection() / PI * 180);
//double svyangle = pSvy->GetAverageDirection();
////end test
list<GPoint3D> cxpts;
list<int> cxpIndexs;
GPoint3D pt1;
GPoint3D pt2(0, 0, 0);
cxpts.clear();
if (pFlt->GetCrossPoints(*pSvy, cxpts, cxpIndexs) < 1)
return false;
std::list<GPoint3D>::iterator ele;
int i = 0;
for (ele = cxpts.begin(); ele != cxpts.end(); ++ele) {// list<73><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><,vector<6F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!=<3D><><
GPoint3D ptTmp = *ele;
if (i == 0) {
pt1 = ptTmp;
i++;
continue;
}
if (abs( ptTmp.x0 - pt1.x0 )<1E-5 && abs(ptTmp.y0 - pt1.y0)<1E-5) {
continue;
}
pt2 = ptTmp;
break;
}
// <20><><EFBFBD>߶ϲ<DFB6>
if (pt2.x0 == 0 && pt2.y0 == 0) {
pt2.x0 = pt1.x0;
pt2.y0 = pt1.y0;
//return false;
}
if (fabs(pt1.x0 - pt2.x0) < 1e-4 &&fabs(pt1.y0 - pt2.y0) < 1e-4)
{
int nIndex = cxpIndexs.front();
GPoint3D gpSeg0 = pFlt->GetPoint(nIndex);
GPoint3D gpSeg1 = pFlt->GetPoint(nIndex + 1);
fmInfo.amplitude = GetAmplitude(pt1, gpSeg0, gpSeg1);
}
else {
fmInfo.amplitude = GetAmplitude(pt1, pt2, pFlt);
}
if (fmInfo.amplitude <0 || fmInfo.amplitude > 1E4) {
return false;
}
//pt1 = cxpts.front();
//pt2 = cxpts.back();
fmInfo.x0 = pt1.x0;
fmInfo.y0 = pt1.y0;
fmInfo.x1 = pt2.x0;
fmInfo.y1 = pt2.y0;
fmInfo.horizontal_dist = pt1.Distance2D(pt2);
fmInfo.fltName = pFlt->GetName();
if(nullptr != pSvy)
fmInfo.surveyName = pSvy->GetName();
////<2F><><EFBFBD>߷<EFBFBD>ʽ
if (1 == m_iCalcMethod && fabs(m_surveyAngle - PI) < 1e-4) //<2F><><EFBFBD><EFBFBD>
{
fmInfo.angle = m_surveyAngle;
if (fabs(m_surveyAngle - PI) < 1e-4)
{
fmInfo.angle = PI;
if (pt1.x0 > pt2.x0)
{
fmInfo.x0 = pt2.x0;
fmInfo.y0 = pt2.y0;
fmInfo.x1 = pt1.x0;
fmInfo.y1 = pt1.y0;
}
}
else if (fabs(m_surveyAngle - PI / 2.0) < 1e-4)
{
fmInfo.angle = PI / 2.0;
if (pt1.y0 < pt2.y0)
{
fmInfo.x0 = pt2.x0;
fmInfo.y0 = pt2.y0;
fmInfo.x1 = pt1.x0;
fmInfo.y1 = pt1.y0;
}
}
else
{
double angle = atan2(pt1.y0 - pt2.y0, pt1.x0 - pt2.x0);
if(angle < 1e-4)
{
fmInfo.x0 = pt2.x0;
fmInfo.y0 = pt2.y0;
fmInfo.x1 = pt1.x0;
fmInfo.y1 = pt1.y0;
}
}
}
else {
// <20><><EFBFBD>߶ϲ<DFB6>
if (fabs(pt1.x0 - pt2.x0) < 1e-4 &&fabs(pt1.y0 - pt2.y0) < 1e-4)
{
int nIndex = cxpIndexs.front();
GPoint3D gpSeg0 = pFlt->GetPoint(nIndex);
GPoint3D gpSeg1 = pFlt->GetPoint(nIndex +1);
double angle = CPublicFunctions::GetAngle180(gpSeg0.x0, gpSeg0.y0, gpSeg1.x0, gpSeg1.y0); //atan2(gpSeg0.x0 - gpSeg1.x0, gpSeg0.y0 - gpSeg1.y0);
if (angle >= 0)
fmInfo.angle = angle;
else
{
fmInfo.angle = angle + PI;
}
}
else if (fabs(pt1.x0 - pt2.x0) < 1e-4) //<2F><><EFBFBD><EFBFBD>
{
fmInfo.y0 = max(pt1.y0, pt2.y0);
fmInfo.angle = PI / 2;
fmInfo.y1 = min(pt1.y0, pt2.y0);
}
else if (fabs(pt1.y0 - pt2.y0) < 1e-4)
{
fmInfo.x0 = min(pt1.x0, pt2.x0);
fmInfo.angle = PI;
fmInfo.x1 = max(pt1.x0, pt2.x0);
}
else
{
double angle = atan2(pt1.y0 - pt2.y0, pt1.x0 - pt2.x0);
if (angle > 0)
fmInfo.angle = angle;
else
{
fmInfo.x0 = pt2.x0;
fmInfo.y0 = pt2.y0;
fmInfo.angle = angle + PI;
fmInfo.x1 = pt1.x0;
fmInfo.y1 = pt1.y0;
}
}
}
if (0 == m_iCalcMethod && m_bLocalFltDirect)
{
double oldangle = fmInfo.angle;
double f = 0;
int istart = pFlt->GetLocation(fmInfo.x0, fmInfo.y0, f);
if (istart > -1)
{
GPline local_flt;
local_flt.AddPoint(pFlt->GetPoint(istart));
local_flt.AddPoint(pFlt->GetPoint(istart + 1));
double direct = local_flt.GetAverageDirection();
double ds = 0; //<2F><><EFBFBD>߽Ƕ<DFBD>
GRect8 rtflt = local_flt.GetRect();
rtflt.left -= 1e-6;
rtflt.right += 1e-6;
rtflt.bottom -= 1e-6;
rtflt.top += 1e-6;
double cs = 2 * (rtflt.Width() + rtflt.Height());
cs *= 2;
if (direct < PI / 2.0)
ds = direct + PI / 2.0;
else
ds = direct - PI / 2.0;
if (fabs(oldangle - ds) > PI / 2.0)
ds += PI;
fmInfo.angle = ds;
pt1.x0 = fmInfo.x0;
pt1.y0 = fmInfo.y0;
Get2rdPoint(pFlt, pt1, fmInfo.angle, pt2);
fmInfo.horizontal_dist = pt1.Distance2D(pt2);
}
}
////begin test
//fprintf(gfw, "Pline.%s\n", pSvy->GetName().c_str());
//fprintf(gfw, "%.4f,%.4f\n", pt1.x0, pt1.y0);
//fprintf(gfw, "%.4f,%.4f\n", pt2.x0, pt2.y0);
//fprintf(gfw, "\n");
// //end test
//if (fabs(pt1.x0 - pt2.x0) < 1e-4 &&fabs(pt1.y0 - pt2.y0) < 1e-4)
//{
// int nIndex = cxpIndexs.front();
// GPoint3D gpSeg0 = pFlt->GetPoint(nIndex);
// GPoint3D gpSeg1 = pFlt->GetPoint(nIndex + 1);
// fmInfo.amplitude = GetAmplitude(pt1, gpSeg0, gpSeg1);
//}
//else {
// fmInfo.amplitude = GetAmplitude(pt1, pt2, pFlt);
//}
fmInfo.xMid = (fmInfo.x0 + fmInfo.x1)*0.5;
fmInfo.yMid = (fmInfo.y0 + fmInfo.y1)*0.5;
return true;
}
void CFaultAmplitudeCreator::ReadFltNames(void)
{
m_tarFltNames.clear();
if (m_strFltNames.GetLength() > 0) {
stringstream ss;
ss << m_strFltNames;
string strLine, strName;
while (ss >> strLine)
{
stringstream ssLine;
ssLine << strLine;
while (getline(ssLine, strName, ','))
{
if (strName.size() > 0)
{
m_tarFltNames.insert(strName);
}
}
ssLine.str("");
}
ss.str("");
return;
}
ifstream ifs(m_strFltNameFile.GetBuffer());
if (!ifs)
return;
string line;
while (getline(ifs, line))
{
CPublicFunctions::Trim(line);
if (line.size() < 1)
continue;
m_tarFltNames.insert(line);
}
ifs.close();
}
void CFaultAmplitudeCreator::SetOutPaths(CString strOutDfd, CString strOutCsv)
{
m_strOutDfd = strOutDfd;
m_strOutCsv = strOutCsv;
}
void CFaultAmplitudeCreator::InsertLayer(const string& strLayer) {
if (m_dfdMap == nullptr)
{
m_dfdMap = new GDfdMap();
}
m_dfdMap->InsertLayer(strLayer);
}
void CFaultAmplitudeCreator::InsertElement(GBaseObj* pobj, const string& strLayer, COLORREF color)
{
if (m_dfdMap == nullptr)
{
m_dfdMap = new GDfdMap();
}
m_dfdMap->InsertObj(pobj, strLayer, color);
}
bool CFaultAmplitudeCreator::Execute()
{
GetCandidateFlts();
switch (m_iCalcMethod)
{
case 0:
CalcAmplitudeWithStep();
break;
case 1:
CalcAmplitudeWithSurvey();
break;
default:
return false;
}
CreatePillarPolygons();
WriteDfd();
WriteCsv();
return true;
}
////x0,y0Ϊ<30><CEAA><EFBFBD>ĵ㣬б<E3A3AC><D0B1>k <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD>Ϊlen
//GPline* CreateLine(double x0, double y0, double sina, double cosa, double len)
//{
// double x1 = x0, y1 = y0, x2 = x0, y2 = y0;
// if (fabs(sina - 1.0) < 1e-6)
// {
// y1 = y0 + len;
// y2 = y0 - len;
// }
// else
// {
// x1 = x0 - len*cosa;
// y1 = y0 - len*sina;
// x2 = x0 + len*cosa;
// y2 = y0 + len*sina;
// }
//
//
// GPline* pln = new GPline();
// pln->AddPoint(GPoint3D(x1, y1, 0));
// pln->AddPoint(GPoint3D(x2, y2, 0));
// return pln;
//
//}
//
//
////<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xs ,ys<79><73><EFBFBD>㣬 xe ye <20>յ<EFBFBD> <20>Ƕ<EFBFBD>lndirect, lenΪ<6E><CEAA>1/2<><32><EFBFBD><EFBFBD>
//int CreateLines(vector<GPline*>& dstLines, double xs, double ys, double xe, double ye,
// double dx, double dy, double lndirect, double len)
//{
// double x = xs;
// double y = ys;
//
// double tts = sqrt(dx*dx + dy*dy);
// int N = len / tts;
// int i = -1;
//
// double sina = sin(lndirect);
// double cosa = cos(lndirect);
// GPline* pln = nullptr;
// while (i < N)
// {
// i++;
//
// if (x > xe && (ye > ys && y > ys) )
// break;
// if (x > xe && ye < ys && y < ye)
// break;
//
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// pln = CreateLine(x, y, sina, cosa, len);
// dstLines.push_back(pln);
//
// x += dx;
// y += dy;
//
// }
//
// return dstLines.size();
//
//
//}
//<2F>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>
void CFaultAmplitudeCreator::CalcAmplitudeWithStep(GPline* flt, std::vector<FAmplitudeInfo>* dstFAInfo)
{
if (0 == flt || flt->GetCount() < 3)
return;
vector<GPline*> tmpSvys; //<2F><>ʱ<EFBFBD><CAB1><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>flt<6C><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ
double direct = flt->GetAverageDirection();
////begin test
//TRACE("\n%s agl = %.2g\n", flt->GetName().c_str(), direct / PI * 180.0);
////end test
double ds = 0; //<2F><><EFBFBD>߽Ƕ<DFBD>
GRect8 rtflt = flt->GetRect();
rtflt.left -= 1e-6;
rtflt.right += 1e-6;
rtflt.bottom -= 1e-6;
rtflt.top += 1e-6;
double cs = 2 * (rtflt.Width() + rtflt.Height());
cs *= 2;
if (direct < PI / 2.0)
ds = direct + PI / 2.0;
else
ds = direct - PI / 2.0;
double x0 = rtflt.left;
double y0 = rtflt.top; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double xe = rtflt.right;
double ye = rtflt.bottom;
if (ds > PI / 2.0)
{
y0 = rtflt.bottom;
ye = rtflt.top;
}
double sina = sin(direct);
double cosa = cos(direct);
double dx = m_pillarStep*cosa;
double dy = m_pillarStep*sina;
vector<GPline*> plvec;
CreateLines(plvec, x0, y0, xe, ye, dx, dy, ds, cs);
std::vector< FAmplitudeInfo> infos;
for (int i = 0; i < plvec.size(); i++)
{
GPline* pSvy = plvec[i];
FAmplitudeInfo fminfo;
if (GetFltAmplitudeInfo(flt, pSvy, fminfo))
{
infos.push_back(fminfo);
}
}
double dTotal = 0;
for (auto it = infos.begin(); it != infos.end(); ++it) {
dTotal += it->amplitude;
}
dTotal *= 0.8;
// ɸѡ<C9B8><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
auto& target = (dstFAInfo) ? *dstFAInfo : m_ampResults;
for (const auto& info : infos) {
if (info.amplitude < dTotal) { // <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> < <20>ܺ<EFBFBD>80%<25><>Ԫ<EFBFBD><D4AA>
target.push_back(info);
}
1 month ago
else if ((info.amplitude > dTotal) && (infos.size() == 1))
{
target.push_back(info);
}
1 month ago
}
////begin test
//FILE* fw = fopen("f:/testsegs.dfd", "w");
//for (int i = 0; i < plvec.size(); i++)
// plvec[i]->Write(fw);
//fclose(fw);
////end test
for (int i = 0; i < plvec.size(); i++)
delete plvec[i];
}
//<2F>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>
void CFaultAmplitudeCreator::CalcAmplitudeWithStep(void)
{
m_ampResults.clear();
GPline* pFlt = 0;
GPline* pSvy = 0;
GRect8 rtFlt, rtSvy;
FAmplitudeInfo fminfo;
////begin test
//gfw = fopen("f:/testsegs.dfd", "w");
////end test
for (int j = 0; j < m_candidateFlts.size(); j++)
{
pFlt = m_candidateFlts[j];
CalcAmplitudeWithStep(pFlt);
//rtFlt = m_fltRects[j];
//for (int i = 0; i < m_candidateSurveys.size(); i++)
//{
// pSvy = m_candidateSurveys[i];
// rtSvy = m_surveyRects[i];
// //<2F><><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD>
// if (!rtFlt.IsIntersected(rtSvy))
// continue;
// if (GetFltAmplitudeInfo(pFlt, pSvy, fminfo))
// {
// m_ampResults.push_back(fminfo);
// }
//}
}
}
void CFaultAmplitudeCreator::WriteLayers(FILE* fw)
{
fprintf(fw, "Class Layer\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M <20>Ͼ<EFBFBD><CFBE><EFBFBD><EFBFBD><EFBFBD>\n");
fprintf(fw, "Layer ViewAndEdit\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarHigh);
fprintf(fw, "Layer ViewAndEdit\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarLow);
fprintf(fw, "Layer ViewAndEdit\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarText);
fprintf(fw, "Layer ViewAndEdit\n");
fprintf(fw, "\n");
// fprintf(fw, "Layer M 0\n");
fprintf(fw, "Layer M <20>Ͼ<EFBFBD><CFBE><EFBFBD><EFBFBD><EFBFBD>\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "Property 0 %ld 65568 0 0 20000.000000 30000.000000 10\n", m_clrHigh);
fprintf(fw, "Solid\n");
fprintf(fw, "CenterName 0.0000 %lf 0.0000 0.0000 0 0 0 Times_New_Roman\n", m_TextHeight);
fprintf(fw, "NoDraw\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarHigh.GetBuffer());
fprintf(fw, "Layer HowToViewCurve\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "Property 0 %ld 65568 0 0 20000.000000 30000.000000 10\n", m_clrLow);
fprintf(fw, "Solid\n");
fprintf(fw, "CenterName 0.0000 %lf 0.0000 0.0000 0 0 0 Times_New_Roman\n", m_TextHeight);
fprintf(fw, "NoDraw\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarLow.GetBuffer());
fprintf(fw, "Layer HowToViewCurve\n");
fprintf(fw, "HowToViewPoint\n");
fprintf(fw, "Font 0 20 0 400 0 0 0 1 0 16 0 0 Times New Roman\n");
double width = m_TextHeight* 0.4;
fprintf(fw, "Text %.4f %.4f 0.0000 %.4f %.4f 76\n", m_TextHeight, m_TextHeight*0.4,
-width*0.4, -m_TextHeight);
fprintf(fw, "Color 0 16777215\n"); //<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
fprintf(fw, "Mark 0.0000 0.0000 0.0000\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarText.GetBuffer());
fprintf(fw, "Layer HowToViewPoint\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "Property 0 %ld 65568 0 0 20000.000000 30000.000000 10\n", m_clrIncline);
fprintf(fw, "Solid\n");
fprintf(fw, "CenterName 0.0000 %lf 0.0000 0.0000 0 0 0 Times_New_Roman\n", m_TextHeight);
fprintf(fw, "NoDraw\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarIncline.GetBuffer());
fprintf(fw, "Layer HowToViewCurve\n");
fprintf(fw, "HowToViewPoint\n");
fprintf(fw, "Font 0 20 0 400 0 0 0 1 0 16 0 0 Times New Roman\n");
fprintf(fw, "Text %.4f %.4f 0.0000 %.4f %.4f 76\n", m_TextHeight, m_TextHeight*0.4,
-width * 0.4, -m_TextHeight);
fprintf(fw, "Color 0 16777215\n"); //<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
fprintf(fw, "Mark 0.0000 0.0000 0.0000\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerTextIncline.GetBuffer());
fprintf(fw, "Layer HowToViewPoint\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "\n");
fprintf(fw, "HowToViewPoint\n");
fprintf(fw, "\n");
fprintf(fw, "State 10\n");
fprintf(fw, "Color 0\n");
/*
fprintf(fw, "Layer M %s\n", m_strLayerPillarHigh);
fprintf(fw, "Layer M %s\n", m_strLayerPillarLow);
fprintf(fw, "Layer M %s\n", m_strLayerPillarText);
//fprintf(fw,"State 10\n");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double height = m_TextHeight;
double width = 4 * height / 10.0;
fprintf(fw, "HowToViewPoint\n");
fprintf(fw, "Font 0 -20 0 400 0 0 0 0 3 2 1 2 Times New Roman\n");
fprintf(fw, "Text %.4f %.4f 0.0000 %.4f %.4f 76\n", height, width, -width*0.4, -height);
fprintf(fw, "Color 0 16777215\n");
fprintf(fw, "Mark 0.0000 0.0000 0.0000\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerPillarText);
fprintf(fw, "Layer HowToViewPoint\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "Property 0 %ld 65568 0 0 20000.000000 30000.000000 10\n", m_barColor);
fprintf(fw, "Solid\n");
fprintf(fw, "NoDraw\n");
fprintf(fw, "\n");
fprintf(fw, "Layer M %s\n", m_strLayerBars);
fprintf(fw, "Layer HowToViewCurve\n");
fprintf(fw, "HowToViewCurve\n");
fprintf(fw, "\n\n");
fprintf(fw, "HowToViewPoint\n");
fprintf(fw, "\n");
fprintf(fw, "State 10\n");
*/
}
void CFaultAmplitudeCreator::WritePillars(FILE* fw)
{
for (int i = 0; i < m_pillarPolygons.size(); i++)
{
if (m_ampResults[i].amplitude > m_thresholdValue)
fprintf(fw, "Layer M %s\n", m_strLayerPillarHigh.GetBuffer());
else
fprintf(fw, "Layer M %s\n", m_strLayerPillarLow.GetBuffer());
m_pillarPolygons[i]->Write(fw);
}
if (m_bWithIncline) {
for (int i = 0; i < m_pillarPolygonsInc.size(); i++)
{
fprintf(fw, "Layer M %s\n", m_strLayerPillarIncline.GetBuffer());
m_pillarPolygonsInc[i]->Write(fw);
}
}
}
void CFaultAmplitudeCreator::WriteTextPoints(FILE* fw)
{
double angle = 0;
GPoint3D pt;
for (int i = 0; i < m_pillarPolygons.size(); i++)
{
fprintf(fw, "Layer M %s\n", m_strLayerPillarText.GetBuffer());
angle = m_ampResults[i].angle;
angle -= PI / 2.0;
angle = angle / PI * 180;
pt = m_pillarTexts[m_pillarPolygons[i] ];
fprintf(fw, "3dPoint %.12g,%.12g,0 %.4g %s\n",
pt.x0,pt.y0,angle, pt.GetName().c_str() );
}
if (m_bWithIncline)
{
for (int i = 0; i < m_pillarPolygonsInc.size(); i++)
{
fprintf(fw, "Layer M %s\n", m_strLayerTextIncline.GetBuffer());
angle = m_ampResults[i].angle;
angle -= PI / 2.0;
angle = angle / PI * 180 - 180;
if (angle > 0) {
angle -= 360;
}
pt = m_pillarTextsInc[m_pillarPolygonsInc[i]];
fprintf(fw, "3dPoint %.12g,%.12g,0 %.4g %s\n",
pt.x0, pt.y0, angle, pt.GetName().c_str());
}
}
}
//д<><D0B4>dfd
bool CFaultAmplitudeCreator::WriteDfd(void)
{
::CopyFile(m_strInputDfd, m_strOutDfd, FALSE);
FILE* fw = fopen(m_strOutDfd, "a+");
if (0 == fw)
return false;
WriteLayers(fw);
WritePillars(fw);
// WriteTextPoints(fw);
////begin test
//for (int i = 0; i < m_pillarPolygons.size(); i++)
// m_pillarPolygons[i]->Write(fw);
////end test
fclose(fw);
return true;
}
//д<><D0B4>csv
bool CFaultAmplitudeCreator::WriteCsv(void)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ơ<EFBFBD>X<EFBFBD><58>Y<EFBFBD><59><EFBFBD>Ͼࡢ<CFBE><E0A1A2><EFBFBD>㴹ֱ<E3B4B9>Ͼ<EFBFBD><CFBE>IJ<EFBFBD><C4B2>ߺ<EFBFBD>
std::ofstream file(m_strOutCsv.GetString());
if (file.is_open())
{
file << u8"<EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,X,Y,<2C><>ֱ<EFBFBD>Ͼ<EFBFBD>,<2C><><EFBFBD><EFBFBD>\n";
for (int i = 0; i < m_ampResults.size(); i++)
{
char buf[512];
sprintf_s(buf, sizeof(buf), "%s,%.4lf,%.4lf,%.4f,%s\n",
m_ampResults[i].fltName.c_str(),
m_ampResults[i].xMid,
m_ampResults[i].yMid,
m_ampResults[i].amplitude,
m_ampResults[i].surveyName.c_str()
);
file << buf;
}
file.close();
return true;
}
return false;
}
void CFaultAmplitudeCreator::GetCandidateFlts(void)
{
ReadFltNames();
m_candidateFlts.clear();
m_fltRects.clear();
if (nullptr == m_dfdMap)
return;
list<GBaseObj*> objlst;
m_dfdMap->GetElements(objlst, m_strFltLayer.GetBuffer());
list<GBaseObj*>::iterator iter = objlst.begin();
GPline* pc = nullptr;
for (; iter != objlst.end(); iter++)
{
if (eLine != (*iter)->GetType())
continue;
pc = (GPline*)(*iter);
if (m_tarFltNames.size() > 0 && m_tarFltNames.count(pc->GetName()) < 1)
continue;
m_candidateFlts.push_back(pc);
m_fltRects.push_back(pc->GetRect());
}
}
double CFaultAmplitudeCreator::GetSurveyAngle(GPline* psvy)
{
if (psvy->GetCount() < 2)
return PI;
int N = psvy->GetCount();
N--;
double agl = atan2(psvy->Y(N) - psvy->Y(0), psvy->X(N) - psvy->X(0));
if (agl < 0.001)
agl += PI;
return agl;
}
void CFaultAmplitudeCreator::GetCandidateSurveys(void)
{
m_candidateSurveys.clear();
m_surveyRects.clear();
if (nullptr == m_dfdMap)
return;
list<GBaseObj*> objlst;
m_dfdMap->GetElements(objlst, m_strSurveyLayer.GetBuffer() );
list<GBaseObj*>::iterator iter = objlst.begin();
GPline* pc = nullptr;
int N = 0;
double totalAgl = 0.0;
for (; iter != objlst.end(); iter++)
{
if (eLine != (*iter)->GetType())
continue;
pc = (GPline*)(*iter);
m_candidateSurveys.push_back(pc);
m_surveyRects.push_back(pc->GetRect());
totalAgl += GetSurveyAngle(pc);
N++;
}
m_surveyAngle = totalAgl / double(N);
}
//CFaultAmplitudeCreator::FAmplitudeInfo::FAmplitudeInfo(void)
// :fltName("")
// , surveyName("")
// ,x0(0)
// ,y0(0)
// ,amplitude(0)
// ,angle(0)
// ,horizontal_dist(0.0)
//{
//}
void CFaultAmplitudeCreator::ErasePillarPgns()
{
for (int i = 0; i < m_pillarPolygons.size(); i++)
delete m_pillarPolygons[i];
m_pillarPolygons.clear();
m_pillarTexts.clear();
for (int i = 0; i < m_pillarPolygonsInc.size(); i++)
delete m_pillarPolygonsInc[i];
m_pillarPolygonsInc.clear();
m_pillarTextsInc.clear();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD>
int CFaultAmplitudeCreator::CreatePillarPolygons(void)
{
ErasePillarPgns();
m_pillarPolygons.reserve(m_ampResults.size());
if (m_bWithIncline)
{
m_pillarPolygonsInc.reserve(m_ampResults.size());
}
for (int i = 0; i < m_ampResults.size(); i++)
{
GPline* pl = new GPline();
GPline* plInc = new GPline();
CreatePillarPolygon(m_ampResults[i], pl, plInc);
if (pl->GetCount() == 0)
{
continue;
}
m_pillarPolygons.push_back(pl);
if (m_bWithIncline)
{
m_pillarPolygonsInc.push_back(plInc);
}
}
return m_pillarPolygons.size();
}
//<2F><>FAmplitudeInfo<66><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD>
void CFaultAmplitudeCreator::CreatePillarPolygon(FAmplitudeInfo& fi, GPline* pline, GPline* plineInc)
{
if (fi.amplitude > 1E20) {
return;
}
double dX0 = fi.xMid;
double dY0 = fi.yMid;
GRect8 rt(dX0, dX0 + fi.amplitude*m_PillarHeightRatio, dY0 - m_PillarWidth / 2.0,
dY0 + m_PillarWidth / 2.0);
GPline* pl = pline;
static char cname[20];
sprintf(cname, "%.1f", fi.amplitude);
pl->SetName(cname);
pl->FromRect(rt);
////begin test
//FILE* fw = fopen("f:/testout.dfd", "w");
//pl->Write(fw);
////end test
double wd = m_TextHeight*0.4;
GPoint3D pttext(rt.right+ 1.4*m_TextHeight, (rt.bottom + rt.top) / 2.0 + 5*wd, 0);
pttext.SetName(cname);
pl->Rotate(dX0, dY0, fi.angle);
pttext.Rotate(dX0, dY0, fi.angle);
m_pillarTexts[pl] = pttext;
//GRect8 rtIncline(fi.x1 - fi.amplitude*m_PillarHeightRatio, fi.x1, fi.y1 - m_PillarWidth / 2.0,
// fi.y1 + m_PillarWidth / 2.0);
if (m_bWithIncline) {
double dIncline = atan(fi.amplitude / fi.horizontal_dist) * 180 / PI;
GRect8 rtIncline(fi.x1 - dIncline* m_inclineScale, fi.x1, fi.y1 - m_PillarWidth / 2.0,
fi.y1 + m_PillarWidth / 2.0);
GPline* plIncline = plineInc;
static char cnameIncline[20];
sprintf(cnameIncline, "%.1f", dIncline);
plIncline->SetName(cnameIncline);
plIncline->FromRect(rtIncline);
plIncline->Rotate(fi.x1, fi.y1, fi.angle);
double dPtIncX = rtIncline.right + 1.3*m_TextHeight;
double dPtIncY = (rtIncline.bottom + rtIncline.top) / 2.0;// -2 * wd;
GPoint3D ptIncline(rtIncline.left - 0.2*m_TextHeight, dPtIncY, 0);
ptIncline.SetName(cnameIncline);
ptIncline.Rotate(fi.x1, fi.y1, fi.angle);
m_pillarTextsInc[plIncline] = ptIncline;
}
////begin test
//pl->Write(fw);
//fclose(fw);
////end test
//return pl;
}