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++

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 "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)) //大
, m_PillarWidth(5) //柱
, m_PillarHeightRatio(1.0)
, m_TextHeight(10) //文字高度
,m_bLocalFltDirect(false)
, m_bWithIncline(false)
, m_inclineScale(10)
, m_clrIncline(RGB(255, 0, 0))
{
m_strLayerPillarHigh = "断距柱子\\高值";
m_strLayerPillarLow = "断距柱子\\低值";
m_strLayerPillarText = "断距柱子\\文字";
m_strLayerPillarIncline = "断裂倾角\\柱子";
m_strLayerTextIncline = "断裂倾角\\文字";
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) //读取dfd图件
{
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) //读取背景曲面
{
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];
//快速排斥
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为断点 pFlt为断层
{
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;
}
//获取垂直断距pt1为断层上测量点angle为角度写入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不可以用<,vector可以用!=和<
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;
}
// 单线断层
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();
////测线方式
if (1 == m_iCalcMethod && fabs(m_surveyAngle - PI) < 1e-4) //横向
{
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 {
// 单线断层
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) //垂向
{
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; //测线角度
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为中心点斜率k 生成一条线长度为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;
//
//}
//
//
////生成一组测线 xs ,ys起点 xe ye 终点 角度lndirect, len为线1/2长度
//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;
//
// //生成新线
// pln = CreateLine(x, y, sina, cosa, len);
// dstLines.push_back(pln);
//
// x += dx;
// y += dy;
//
// }
//
// return dstLines.size();
//
//
//}
//由步长计算断距
void CFaultAmplitudeCreator::CalcAmplitudeWithStep(GPline* flt, std::vector<FAmplitudeInfo>* dstFAInfo)
{
if (0 == flt || flt->GetCount() < 3)
return;
vector<GPline*> tmpSvys; //临时测线方向与flt方向垂直
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; //测线角度
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; //测线起点坐标
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;
// 筛选符合条件的元素
auto& target = (dstFAInfo) ? *dstFAInfo : m_ampResults;
for (const auto& info : infos) {
if (info.amplitude < dTotal) { // 明确条件:保留振幅 < 总和80%的元素
target.push_back(info);
}
else if ((info.amplitude > dTotal) && (infos.size() == 1))
{
target.push_back(info);
}
}
////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];
}
//由步长计算断距
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];
// //快速排斥
// 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 断距柱子\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 断距柱子\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"); //黑色文字
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"); //黑色文字
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");
//曲线修饰
//点修饰
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());
}
}
}
//写出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;
}
//写出csv
bool CFaultAmplitudeCreator::WriteCsv(void)
{
//输出断层名称、X、Y、断距、计算垂直断距的测线号
std::ofstream file(m_strOutCsv.GetString());
if (file.is_open())
{
file << u8"断层名称,X,Y,垂直断距,测线\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();
}
//生成柱子多边形
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();
}
//由FAmplitudeInfo生成柱子多边形
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;
}