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.
492 lines
15 KiB
C++
492 lines
15 KiB
C++
#include "pch.h"
|
|
|
|
#include "DrawModel\BaseLib.h"
|
|
#include "DrawOperator\DrawLib.h"
|
|
|
|
#include "MLPline.h"
|
|
#include "MLMicroStructure.h"
|
|
#include "MLPlineList.h"
|
|
#include "StructureCalculateParameter.h"
|
|
|
|
bool OpenFile(LPCTSTR lpszFileName, CXy* pXy);
|
|
void Serialize(CArchive& ar, CXy* pXy);
|
|
bool AddLine2List(MLPlineList* pLineList, CCurveEx* pCurve);
|
|
void WriteStyle2String(QString& data)
|
|
{
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 13395711 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\鼻状\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 6724095 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\断鼻\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 16763904 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\断沟\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 16776960 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\沟槽\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 16751052 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\低点\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n";
|
|
data += "Property 0 559607 65568 0 0 0.000000 0.000000 0\n";
|
|
data += "Solid\n";
|
|
data += "NoDraw\n\n";
|
|
|
|
data += QString::fromLocal8Bit("Layer M 构造\\高点\n");
|
|
data += "Layer HowToViewCurve\n";
|
|
data += "HowToViewCurve\n\n";
|
|
}
|
|
void ParseLineStatistic(CXy* pXy,const QString& structureType,const MLPlineList& lines, QString& data)
|
|
{
|
|
int nCount = lines.getCount();
|
|
for (int i = 0; i < nCount; i++)
|
|
{
|
|
MLPline* pLine = lines.getPline(i);
|
|
const char* chName = pLine->getName();
|
|
|
|
QString strName(chName);
|
|
strName=strName.replace(QString("="), QString(""));
|
|
// size_t index = strName.indexOf(',');
|
|
//QByteArray ba = strName.left(index).toLatin1();
|
|
//pLine->setName(ba.data());
|
|
|
|
//CCurveEx curve;
|
|
//int nLineCount = pLine->getCount();
|
|
//curve.Create(nLineCount);
|
|
//for (int j = 0; j < nLineCount; j++)
|
|
//{
|
|
// MLPlNode node = pLine->getAtPt(j);
|
|
// curve.x[j] = node.getX();
|
|
// curve.y[j] = node.getY();
|
|
//}
|
|
//double dAngle = pXy->GetSurfaceAngle(curve);
|
|
|
|
//data += QString("%1,%2,%3\n").arg(structureType).arg(strName).arg(dAngle);
|
|
data += QString("%1,%2\n").arg(structureType).arg(strName);
|
|
}
|
|
}
|
|
void WriteLine2String(const MLPlineList& lines, QString& data)
|
|
{
|
|
int nCount = lines.getCount();
|
|
for (int i = 0; i < nCount; i++)
|
|
{
|
|
MLPline* pLine = lines.getPline(i);
|
|
QString strName(pLine->getName());
|
|
strName = strName.replace(QString("="), QString(""));
|
|
size_t index = strName.indexOf(',');
|
|
strName = strName.left(index);
|
|
data += "Pline.";
|
|
data += strName;
|
|
data += "\n";
|
|
int nLineCount = pLine->getCount();
|
|
for (int j = 0; j < nLineCount; j++)
|
|
{
|
|
MLPlNode node = pLine->getAtPt(j);
|
|
double dX = node.getX();
|
|
double dY = node.getY();
|
|
data += QString("%1,%2\n").arg(dX, 0, 'f', 3).arg(dY, 0, 'f', 3);
|
|
}
|
|
data += "\n";
|
|
}
|
|
return;
|
|
}
|
|
int SplitCString(const CString& source, const char seperator, vector<CString>& result)
|
|
{
|
|
CString strSource = source;
|
|
result.clear();
|
|
while (TRUE) {
|
|
int nFind = strSource.Find(seperator);
|
|
if (nFind == -1) {
|
|
result.push_back(strSource.Trim());
|
|
return result.size();
|
|
}
|
|
CString strSep = strSource.Left(nFind);
|
|
result.push_back(strSep.Trim());
|
|
strSource = strSource.Right(strSource.GetLength() - nFind - 1);
|
|
}
|
|
}
|
|
extern "C" __declspec(dllexport)
|
|
void CreateMicroStructure(LPCTSTR intputFile, LPCTSTR resultFile, LPCTSTR statisticFile
|
|
, StructureCalculateParameter& par
|
|
, LPCTSTR faultLayerName, LPCTSTR contourLayerName)
|
|
{
|
|
// 打开输入文件
|
|
CXy* pXy = new CXy;
|
|
//pXy->m_bRealTimeDraw = false;
|
|
if (pXy->OpenFile(intputFile, false) == false) {
|
|
pXy->Clear();
|
|
delete pXy;
|
|
pXy = nullptr;
|
|
return;
|
|
}
|
|
CString strContourLayer(par.m_curveLayer);
|
|
//CString strContourLayer(contourLayerName);
|
|
if (strContourLayer.IsEmpty()) {
|
|
strContourLayer = "等值线";
|
|
}
|
|
vector<CString> vecControurLayers;
|
|
SplitCString(strContourLayer, ',', vecControurLayers);
|
|
|
|
CString strFaultLayer(par.m_faultageLayer);
|
|
//CString strFaultLayer(faultLayerName);
|
|
if (strFaultLayer.IsEmpty()) {
|
|
strFaultLayer = "断层";
|
|
}
|
|
vector<CString> vecFaultLayers;
|
|
SplitCString(strFaultLayer, ',', vecFaultLayers);
|
|
|
|
MLMicroStructure * m_pMicroStructure = new MLMicroStructure;
|
|
MLPlineList contourList;
|
|
MLPlineList faultList;
|
|
|
|
CPtrList* pDataAll = pXy->GetValueList();
|
|
POSITION pos = pDataAll->GetHeadPosition();
|
|
CString strLayerName;
|
|
int nEleType = 0;
|
|
COne *pOne;
|
|
CMesh* pMesh = nullptr;
|
|
int i = 0;
|
|
while (pos)
|
|
{
|
|
//TRACE("%d\r\n", i++);
|
|
pOne = (COne *)(pDataAll->GetNext(pos));
|
|
strLayerName = pOne->GetLayer()->GetName();
|
|
nEleType = pOne->GetType();
|
|
// 等值线
|
|
if (nEleType == DOUBLEFOX_CURVE)
|
|
{
|
|
bool bFind = false;
|
|
for each(CString layer in vecControurLayers) {
|
|
if (strLayerName.Find(layer)==0) {
|
|
AddLine2List(&contourList, (CCurveEx*)pOne->value);
|
|
bFind = true;
|
|
break;
|
|
}
|
|
}
|
|
if (bFind == false) {
|
|
for each(CString layer in vecFaultLayers) {
|
|
if (strLayerName.Find(layer) == 0) {
|
|
AddLine2List(&faultList, (CCurveEx*)pOne->value);
|
|
bFind = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//else if (nEleType == DOUBLEFOX_CURVE && strLayerName.Find(strFaultLayer) == 0)
|
|
//{
|
|
// AddLine2List(&faultList, (CCurveEx*)pOne->value);
|
|
//}
|
|
else if (nEleType == DOUBLEFOX_MESH)
|
|
{
|
|
pMesh = (CMesh*)pOne->value;
|
|
}
|
|
}
|
|
if (pMesh == nullptr) {
|
|
pXy->Clear();
|
|
delete pXy;
|
|
pXy = nullptr;
|
|
return;
|
|
}
|
|
int nHigh = par.m_nShapeType & StructureType::High;
|
|
int nLow = par.m_nShapeType & StructureType::Low;
|
|
int nFaultHigh = par.m_nShapeType & StructureType::FaultHigh;
|
|
int nFaultLow = par.m_nShapeType & StructureType::FaultLow;
|
|
int nNoseHigh = par.m_nShapeType & StructureType::NoseHigh;
|
|
int nNoseLow = par.m_nShapeType & StructureType::NoseLow;
|
|
|
|
// 设置参数
|
|
m_pMicroStructure->m_extendDis = par.m_dExtendDis;
|
|
m_pMicroStructure->m_closeDis = par.m_dCloseDistance;
|
|
m_pMicroStructure->m_minArea = par.m_dMinimumArea;
|
|
m_pMicroStructure->m_offsetDis = par.m_dOffsetDis;
|
|
m_pMicroStructure->m_minAngle = par.m_dMiniAngle;
|
|
m_pMicroStructure->m_redundant = par.m_dRedundant;
|
|
m_pMicroStructure->m_radius = par.m_dRadius;
|
|
m_pMicroStructure->m_limitNum = par.m_nLimitNum;
|
|
m_pMicroStructure->m_faultCloseDis = par.m_dFaultCloseDis;
|
|
|
|
m_pMicroStructure->m_bCloseShape = nHigh | nLow; // par.m_bCloseShape;
|
|
m_pMicroStructure->m_bFaultShape = nFaultHigh | nFaultLow; // par.m_bFaultShap;
|
|
m_pMicroStructure->m_bNoseShape = nNoseHigh | nNoseLow; // par.m_bNoseShape;
|
|
m_pMicroStructure->m_smooth = par.m_bSmooth; // 是否光滑半径
|
|
m_pMicroStructure->m_zoomin = par.m_dZoomin; // 放大系数
|
|
m_pMicroStructure->m_unitSacle = par.m_dUnitSacle; // 鼻状隆起和沟槽重合比
|
|
|
|
m_pMicroStructure->m_minDepth = par.m_minDepth; // 最小幅度
|
|
m_pMicroStructure->m_maxDepth = par.m_maxDepth; // 最大幅度
|
|
|
|
// 设置数据
|
|
m_pMicroStructure->setContourList(contourList);
|
|
m_pMicroStructure->setFaultList(faultList);
|
|
//m_pMicroStructure->readDfgBinary(gridFile);
|
|
CGrid* pGrid = pMesh->GetMesh();
|
|
|
|
int nIndexZ = 0;
|
|
|
|
double range[4];
|
|
range[0] = pGrid->xmin();
|
|
range[1] = pGrid->xmax();
|
|
range[2] = pGrid->ymin();
|
|
range[3] = pGrid->ymax();
|
|
int num[2];
|
|
num[0] = pGrid->xnum();
|
|
num[1] = pGrid->ynum();
|
|
int nValueNum = num[0] * num[1];
|
|
float* pValues = new float[nValueNum];
|
|
switch (pMesh->GetMeshType())
|
|
{
|
|
case MESH_TEXT:
|
|
case MESH_DFG:
|
|
case MESH_FXY:
|
|
{
|
|
for (int i = 0; i < nValueNum; i++)
|
|
{
|
|
pValues[i] = ((CDimension3D*)pGrid)->u[i];
|
|
}
|
|
}
|
|
break;
|
|
case MESH_FUN_2D:
|
|
{
|
|
double dIJ = 0;
|
|
for (int j = 0; j < num[1]; j++)
|
|
{
|
|
for (int i = 0; i < num[0]; i++)
|
|
{
|
|
dIJ = ((CFunction2D*)pGrid)->Value(i, j);
|
|
pValues[i + j * num[0]] = dIJ;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
m_pMicroStructure->setGridInfo(range, num, pGrid->delt, pGrid->range);
|
|
m_pMicroStructure->setZData(num[0]* num[1], pValues);
|
|
|
|
// 执行计算
|
|
m_pMicroStructure->run();
|
|
|
|
// 输出结果
|
|
QString strData, strStatistic;
|
|
//WriteStyle2String(strData);
|
|
if (nFaultHigh)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("断鼻"),m_pMicroStructure->m_faultObjPosiAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\断鼻\n");
|
|
WriteLine2String(m_pMicroStructure->m_faultObjPosiAry, strData);
|
|
}
|
|
if (nFaultLow)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("断沟"), m_pMicroStructure->m_faultObjNegaAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\断沟\n");
|
|
WriteLine2String(m_pMicroStructure->m_faultObjNegaAry, strData);
|
|
}
|
|
if (nNoseHigh)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("鼻状"), m_pMicroStructure->m_noseObjPosiAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\鼻状\n");
|
|
WriteLine2String(m_pMicroStructure->m_noseObjPosiAry, strData);
|
|
}
|
|
if (nNoseLow)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("沟槽"), m_pMicroStructure->m_noseObjNegaAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\沟槽\n");
|
|
WriteLine2String(m_pMicroStructure->m_noseObjNegaAry, strData);
|
|
}
|
|
if (nHigh)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("高点"), m_pMicroStructure->m_closeObjPosiAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\高点\n");
|
|
WriteLine2String(m_pMicroStructure->m_closeObjPosiAry, strData);
|
|
}
|
|
if (nLow)
|
|
{
|
|
ParseLineStatistic(pXy, QString::fromLocal8Bit("低点"), m_pMicroStructure->m_closeObjNegaAry, strStatistic);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\低点\n");
|
|
WriteLine2String(m_pMicroStructure->m_closeObjNegaAry, strData);
|
|
}
|
|
|
|
QString qstrResultFile = QString::fromLocal8Bit(resultFile);
|
|
QFile file(qstrResultFile);
|
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
QTextStream stream(&file);
|
|
stream << strData;
|
|
file.close();
|
|
|
|
QString strHeader = QString::fromLocal8Bit("构造类型,构造名称,面积,构造幅度,长轴,短轴\n");
|
|
strStatistic.insert(0, strHeader);
|
|
|
|
QString qstrStatisticFile = QString::fromLocal8Bit(statisticFile);
|
|
QFile fileStatistic(qstrStatisticFile);
|
|
fileStatistic.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
QTextStream streamStatistic(&fileStatistic);
|
|
streamStatistic << strStatistic;
|
|
fileStatistic.close();
|
|
|
|
m_pMicroStructure->clearMemory();
|
|
delete m_pMicroStructure;
|
|
pXy->Clear();
|
|
delete pXy;
|
|
pXy = nullptr;
|
|
delete[] pValues;
|
|
}
|
|
extern "C" __declspec(dllexport)
|
|
void CreateMicroStructureOld(LPCTSTR curveFile, LPCTSTR faultFile
|
|
, LPCTSTR gridFile, LPCTSTR ResultFile
|
|
, StructureCalculateParameter& par)
|
|
{
|
|
int nHigh = par.m_nShapeType & StructureType::High;
|
|
int nLow = par.m_nShapeType & StructureType::Low;
|
|
int nFaultHigh = par.m_nShapeType & StructureType::FaultHigh;
|
|
int nFaultLow = par.m_nShapeType & StructureType::FaultLow;
|
|
int nNoseHigh = par.m_nShapeType & StructureType::NoseHigh;
|
|
int nNoseLow = par.m_nShapeType & StructureType::NoseLow;
|
|
|
|
QString resultFile = QString::fromLocal8Bit(ResultFile);
|
|
MLMicroStructure * m_pMicroStructure = new MLMicroStructure;
|
|
|
|
MLPlineList contourList;
|
|
QString polylineFile = QString::fromLocal8Bit(curveFile);
|
|
contourList.readPline(polylineFile);
|
|
|
|
QString faultFileQ = QString::fromLocal8Bit(faultFile);
|
|
MLPlineList faultList;
|
|
faultList.readPline(faultFileQ);
|
|
|
|
m_pMicroStructure->m_extendDis = par.m_dExtendDis;
|
|
m_pMicroStructure->m_closeDis = par.m_dCloseDistance;
|
|
m_pMicroStructure->m_minArea = par.m_dMinimumArea;
|
|
m_pMicroStructure->m_offsetDis = par.m_dOffsetDis;
|
|
m_pMicroStructure->m_minAngle = par.m_dMiniAngle;
|
|
m_pMicroStructure->m_redundant = par.m_dRedundant;
|
|
m_pMicroStructure->m_radius = par.m_dRadius;
|
|
m_pMicroStructure->m_limitNum = par.m_nLimitNum;
|
|
m_pMicroStructure->m_faultCloseDis = par.m_dFaultCloseDis;
|
|
|
|
m_pMicroStructure->m_bCloseShape = nHigh | nLow; // par.m_bCloseShape;
|
|
m_pMicroStructure->m_bFaultShape = nFaultHigh | nFaultLow; // par.m_bFaultShap;
|
|
m_pMicroStructure->m_bNoseShape = nNoseHigh | nNoseLow; // par.m_bNoseShape;
|
|
m_pMicroStructure->m_smooth = par.m_bSmooth; // 是否光滑半径
|
|
m_pMicroStructure->m_zoomin = par.m_dZoomin; // 放大系数
|
|
m_pMicroStructure->m_unitSacle = par.m_dUnitSacle; // 鼻状隆起和沟槽重合比
|
|
|
|
m_pMicroStructure->setContourList(contourList);
|
|
m_pMicroStructure->setFaultList(faultList);
|
|
m_pMicroStructure->readDfgBinary(gridFile);
|
|
|
|
m_pMicroStructure->run();
|
|
QString strData;
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\断鼻\n");
|
|
WriteLine2String(m_pMicroStructure->m_faultObjPosiAry, strData);
|
|
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\断沟\n");
|
|
WriteLine2String(m_pMicroStructure->m_faultObjNegaAry, strData);
|
|
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\鼻状\n");
|
|
WriteLine2String(m_pMicroStructure->m_noseObjPosiAry, strData);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\沟槽\n");
|
|
WriteLine2String(m_pMicroStructure->m_noseObjNegaAry, strData);
|
|
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\高点\n");
|
|
WriteLine2String(m_pMicroStructure->m_closeObjNegaAry, strData);
|
|
strData += QString::fromLocal8Bit("Layer M 构造\\低点\n");
|
|
WriteLine2String(m_pMicroStructure->m_closeObjPosiAry, strData);
|
|
|
|
QFile file(resultFile);
|
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
QTextStream stream(&file);
|
|
stream << strData;
|
|
file.close();
|
|
|
|
m_pMicroStructure->clearMemory();
|
|
|
|
delete m_pMicroStructure;
|
|
}
|
|
bool AddLine2List(MLPlineList* pLineList, CCurveEx* pCurve)
|
|
{
|
|
MLPline* pline = new MLPline();
|
|
if (pCurve->name != nullptr)
|
|
{
|
|
pline->setName(pCurve->name);
|
|
}
|
|
for (int i = 0; i < pCurve->num; ++i)
|
|
{
|
|
pline->addTailPt(pCurve->x[i], pCurve->y[i], pCurve->z[i]);
|
|
}
|
|
pLineList->addPline(pline);
|
|
return true;
|
|
}
|
|
|
|
bool OpenFile(LPCTSTR lpszFileName, CXy* pXy)
|
|
{
|
|
if (pXy->ReadOtherWithExtension(lpszFileName))
|
|
{
|
|
return true;
|
|
}
|
|
CFile file;
|
|
if (file.Open(lpszFileName, CFile::modeRead))
|
|
{
|
|
// m_FileName = lpszFileName;
|
|
CArchive ar(&file, CArchive::load);
|
|
Serialize(ar, pXy);
|
|
ar.Close();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
file.Close();
|
|
return true;
|
|
}
|
|
|
|
void Serialize(CArchive& ar, CXy* pXy)
|
|
{
|
|
if (ar.IsStoring()) {}
|
|
else
|
|
{
|
|
if (pXy == nullptr) pXy = new CXy;
|
|
pXy->m_bRealTimeDraw = false;
|
|
CString name = ar.GetFile()->GetFileName();
|
|
name.MakeLower();
|
|
CSplitPath sp(name);
|
|
|
|
CString ext = sp.GetExtension();
|
|
//ar.m_pDocument = this; // set back-pointer in archive
|
|
if (ext == _T(".dfb") || ext == _T(".dft"))
|
|
{
|
|
pXy->m_version = pXy->DFB_ReadVersion(ar);
|
|
pXy->DFB_ReadEncrypt(ar, pXy->m_version);
|
|
if (pXy->IsEncrypted()) {
|
|
}
|
|
pXy->DFB_Serialize(ar, pXy->m_version);
|
|
}
|
|
else if (ext == ".dml" || ext == ".xml")
|
|
pXy->DML_Read2(*(ar.GetFile()));
|
|
else if (ext == ".pcg")
|
|
pXy->PCG_Read2(*(ar.GetFile()));
|
|
else
|
|
pXy->DFD_Read2(*(ar.GetFile()));
|
|
}
|
|
} |