|
|
#include "pch.h"
|
|
|
#include "ViewOperator.h"
|
|
|
#include "ImageUtils.h"
|
|
|
#include "ContourUtils.h"
|
|
|
|
|
|
ViewOperator::ViewOperator(ViewWidget * view)
|
|
|
{
|
|
|
this->m_faciesZMin = 2000;
|
|
|
this->m_faciesZMax = 10000;
|
|
|
this->m_areaMin = 0.0;
|
|
|
this->viewWidget = view;
|
|
|
this->m_smoothTimes = 5;
|
|
|
|
|
|
m_detector = new COutlineDetector;
|
|
|
}
|
|
|
|
|
|
ViewOperator::~ViewOperator()
|
|
|
{
|
|
|
if (m_pSurface)
|
|
|
delete m_pSurface;
|
|
|
|
|
|
if (m_detector)
|
|
|
delete m_detector;
|
|
|
}
|
|
|
|
|
|
bool ViewOperator::GetSurfaceZRange(double & zMin, double & zMax)
|
|
|
{
|
|
|
if (!m_pSurface)
|
|
|
return false;
|
|
|
double* range = m_pSurface->GetRange();
|
|
|
zMin = range[0];
|
|
|
zMax = range[1];
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool ViewOperator::GetSurfaceParameter(int & xNum, int & yNum, double & deltaX, double & deltaY, double & zMin, double & zMax)
|
|
|
{
|
|
|
if (!m_pSurface)
|
|
|
return false;
|
|
|
xNum = m_pSurface->XNum();
|
|
|
yNum = m_pSurface->YNum();
|
|
|
deltaX = m_pSurface->DeltX();
|
|
|
deltaY = m_pSurface->DeltY();
|
|
|
|
|
|
double* range = m_pSurface->GetRange();
|
|
|
zMin = range[0];
|
|
|
zMax = range[1];
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool ViewOperator::GetDilateMax(int& diLateMax)
|
|
|
{
|
|
|
if (!m_pSurface)
|
|
|
return false;
|
|
|
int xnum = m_pSurface->XNum();
|
|
|
int ynum = m_pSurface->YNum();
|
|
|
diLateMax = min(xnum, ynum) / 4;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void ViewOperator::updateParameter()
|
|
|
{
|
|
|
if (!m_pSurface)
|
|
|
return;
|
|
|
int xnum = m_pSurface->XNum();
|
|
|
int ynum = m_pSurface->YNum();
|
|
|
float deltx = m_pSurface->DeltX();
|
|
|
float delty = m_pSurface->DeltY();
|
|
|
double* range = m_pSurface->GetRange();
|
|
|
float zmin = range[0];
|
|
|
float zmax = range[1];
|
|
|
|
|
|
this->m_faciesZMin = (zmin + zmax) / 2;
|
|
|
this->m_faciesZMax = zmax;
|
|
|
|
|
|
this->m_dilate = 2;
|
|
|
}
|
|
|
bool ViewOperator::LoadGrid(int numx, int numy, double x0, double y0, double dx, double dy, double* values, double zMin, double zMax)
|
|
|
{
|
|
|
this->viewWidget->resetAxisRect();
|
|
|
|
|
|
if (m_pSurface)
|
|
|
delete m_pSurface;
|
|
|
m_pSurface = new GSurface;
|
|
|
|
|
|
qApp->setOverrideCursor(Qt::BusyCursor);
|
|
|
|
|
|
if (!m_pSurface->Create(numx, numy, x0,y0, dx,dy, values, zMin, zMax))
|
|
|
{
|
|
|
qApp->restoreOverrideCursor();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
m_detector->clear();
|
|
|
m_detector->setSurface(m_pSurface);
|
|
|
|
|
|
viewWidget->resetColorScaleRange();
|
|
|
updateParameter();
|
|
|
viewWidget->m_bTransparentColormap = true;
|
|
|
viewWidget->setType(ViewWidget::colorfulmap);
|
|
|
if (m_pSurface)
|
|
|
{
|
|
|
viewWidget->setGrid(m_pSurface, true);
|
|
|
}
|
|
|
viewWidget->m_bTransparentColormap = false;
|
|
|
|
|
|
QTimer::singleShot(5, [this] {
|
|
|
if (m_pSurface)
|
|
|
{
|
|
|
viewWidget->setGrid(m_pSurface, true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
return true;
|
|
|
}
|
|
|
bool ViewOperator::LoadDfg(QString strDfg)
|
|
|
{
|
|
|
this->viewWidget->resetAxisRect();
|
|
|
|
|
|
if (m_pSurface)
|
|
|
delete m_pSurface;
|
|
|
m_pSurface = new GSurface;
|
|
|
|
|
|
QTextCodec *gbk = QTextCodec::codecForName("GBK");
|
|
|
QByteArray arr = gbk->fromUnicode(strDfg);
|
|
|
qApp->setOverrideCursor(Qt::BusyCursor);
|
|
|
|
|
|
if (!m_pSurface->ReadDfg(arr.data()))
|
|
|
{
|
|
|
delete m_pSurface;
|
|
|
m_pSurface = nullptr;
|
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
m_detector->clear();
|
|
|
m_detector->setSurface(m_pSurface);
|
|
|
|
|
|
viewWidget->resetColorScaleRange();
|
|
|
updateParameter();
|
|
|
viewWidget->m_bTransparentColormap = true;
|
|
|
viewWidget->setType(ViewWidget::colorfulmap);
|
|
|
if (m_pSurface)
|
|
|
{
|
|
|
viewWidget->setGrid(m_pSurface, true);
|
|
|
}
|
|
|
viewWidget->m_bTransparentColormap = false;
|
|
|
|
|
|
QTimer::singleShot(5, [this] {
|
|
|
if (m_pSurface)
|
|
|
{
|
|
|
viewWidget->setGrid(m_pSurface, true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void ViewOperator::ViewBlackWhite()
|
|
|
{
|
|
|
this->viewWidget->saveCurrentAxisRect();
|
|
|
|
|
|
cv::Mat mat;
|
|
|
float zupper = this->m_faciesZMax;
|
|
|
float zlower = this->m_faciesZMin;
|
|
|
ImageUtils::convertSurfaceToMat(m_pSurface, zlower, zupper, mat);
|
|
|
|
|
|
qApp->setOverrideCursor(Qt::BusyCursor);
|
|
|
GSurface& surf = m_surfBlackWhite;
|
|
|
if (nullptr == m_pSurface || !ImageUtils::convertMatToSurface(mat, m_pSurface->X(0),
|
|
|
m_pSurface->Y(0), m_pSurface->DeltX(), m_pSurface->DeltY(), &surf))
|
|
|
{
|
|
|
qApp->restoreOverrideCursor();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this->viewWidget->setType(ViewWidget::graymap);
|
|
|
this->viewWidget->setGrid(&surf, true);
|
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
}
|
|
|
/// <20><>ɫ<EFBFBD><C9AB>ʾ
|
|
|
void ViewOperator::ViewColorFul()
|
|
|
{
|
|
|
this->viewWidget->saveCurrentAxisRect();
|
|
|
if (m_pSurface)
|
|
|
{
|
|
|
this->viewWidget->setType(ViewWidget::colorfulmap);
|
|
|
this->viewWidget->setGrid(m_pSurface, true);
|
|
|
}
|
|
|
}
|
|
|
void ViewOperator::processImageAndCreateOriginalContours() {
|
|
|
float zupper = this->m_faciesZMax;
|
|
|
float zlower = this->m_faciesZMin;
|
|
|
// int nIters = ceil(ui->edit_dilateDist_2->text().toFloat() / std::min(m_pSurface->DeltX(),m_pSurface->DeltY()));
|
|
|
int nIters = this->m_dilate;
|
|
|
|
|
|
// qDebug() << "iters = " << nIters;
|
|
|
|
|
|
COutlineDetector* detector = m_detector;
|
|
|
detector->setSurface(m_pSurface, zlower, zupper, nIters);
|
|
|
|
|
|
m_detector->setContourMinArea((float)m_areaMin);
|
|
|
m_detector->setContourSmoothTimes(this->m_smoothTimes);
|
|
|
|
|
|
detector->ProcessImage();
|
|
|
}
|
|
|
void ViewOperator::showOriginalContours()
|
|
|
{
|
|
|
viewWidget->setType(ViewWidget::colorfulmap_contours);
|
|
|
viewWidget->setGrid(m_pSurface, false);
|
|
|
|
|
|
float minArea = this->m_areaMin;
|
|
|
if (minArea < 1e-4)
|
|
|
minArea = (float)1e-4;
|
|
|
|
|
|
Contours tmpContours;//= m_detector->GetOriginalContours();
|
|
|
|
|
|
m_detector->multiContourToRealCoords(m_detector->GetOriginalContours(), tmpContours, 0);
|
|
|
// ʹ<><CAB9> std::remove_if + erase
|
|
|
tmpContours.erase(
|
|
|
remove_if(tmpContours.begin(), tmpContours.end(), [](const Contour& contour) {
|
|
|
return contour.size() < 3;
|
|
|
}),
|
|
|
tmpContours.end()
|
|
|
);
|
|
|
|
|
|
Contours drawingcontours;
|
|
|
drawingcontours.reserve(tmpContours.size());
|
|
|
|
|
|
for (auto& p : tmpContours)
|
|
|
{
|
|
|
if (contourArea(p) < minArea)
|
|
|
continue;
|
|
|
drawingcontours.push_back(p);
|
|
|
}
|
|
|
viewWidget->setContours(drawingcontours);
|
|
|
viewWidget->updateDraw();
|
|
|
}
|
|
|
void ViewOperator::CreateLines()
|
|
|
{
|
|
|
if (nullptr == m_pSurface)
|
|
|
return;
|
|
|
qApp->setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
|
viewWidget->saveCurrentAxisRect();
|
|
|
|
|
|
// <20><>̬ѧ<CCAC><D1A7><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳ<EFBFBD>ʼ<EFBFBD><CABC>ֵ<EFBFBD><D6B5>
|
|
|
processImageAndCreateOriginalContours();
|
|
|
showOriginalContours();
|
|
|
|
|
|
qApp->restoreOverrideCursor();
|
|
|
}
|
|
|
CPolygonTreeInterface* ViewOperator::GetContourPtr()
|
|
|
{
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
m_detector->CreateFaciesContours();
|
|
|
//m_detector->multiContourToRealCoords(m_detector->GetFaciesContours(), dstvec, 0);
|
|
|
CPolygonTreeInterface* plyTree = m_detector->GetFaciesContours();
|
|
|
if (plyTree->GetResultPolygons().size() == 0)
|
|
|
{
|
|
|
return nullptr;
|
|
|
}
|
|
|
return plyTree;
|
|
|
}
|
|
|
char * ViewOperator::WriteContours()
|
|
|
{
|
|
|
//<2F><><EFBFBD>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
int nCount = m_detector->CreateFaciesContours();
|
|
|
|
|
|
auto dstVec = m_detector->GetRealContours();
|
|
|
if (dstVec->size() == 0) {
|
|
|
return nullptr;
|
|
|
}
|
|
|
char* pData = ContourUtils::WriteContours(*dstVec);
|
|
|
return pData;
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
|