117 lines
3.3 KiB
C++
117 lines
3.3 KiB
C++
|
#include <QProcess>
|
|||
|
#include <QDir>
|
|||
|
#include <QApplication>
|
|||
|
#include <QDebug>
|
|||
|
#include <QTimer>
|
|||
|
|
|||
|
#include <windows.h>
|
|||
|
|
|||
|
#include "DEM_GeneRas.h"
|
|||
|
#include "ThreadObject.h"
|
|||
|
|
|||
|
#include "im2shp.h"
|
|||
|
|
|||
|
using namespace std;
|
|||
|
|
|||
|
WorkThreadObject::WorkThreadObject(QObject* parent) :QObject(parent)
|
|||
|
{
|
|||
|
qRegisterMetaType<std::function<void(int)> >("std::function<void(int)>");
|
|||
|
}
|
|||
|
|
|||
|
WorkThreadObject::~WorkThreadObject()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void WorkThreadObject::runPredictWork(QString Moudle, QString DOM, QString DSM, QString PRE)//, std::function<void(int)>func
|
|||
|
{
|
|||
|
QString str = QString("%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId());
|
|||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|||
|
qDebug() << str << "----" << pluginsDir.currentPath();
|
|||
|
if (!pluginsDir.cd("models\\envs"))
|
|||
|
{
|
|||
|
qDebug() << "no folder models\\envs";
|
|||
|
return;
|
|||
|
}
|
|||
|
QString exeDirName = pluginsDir.absoluteFilePath("predict_4c_vegetation.exe");
|
|||
|
qDebug() << "----" << exeDirName;
|
|||
|
|
|||
|
QString model = " --model_path " + Moudle;
|
|||
|
QString dom_path = " --dom_path " + DOM + "/";
|
|||
|
QString dsm_path = " --dsm_path " + DSM + "/";
|
|||
|
QString pre_dir = " --pre_path " + PRE + "/";
|
|||
|
QString ss = exeDirName + model + dom_path + dsm_path + pre_dir;
|
|||
|
qDebug() << ss;
|
|||
|
QProcess* pProces = new QProcess(this);
|
|||
|
connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(on_read()));
|
|||
|
|
|||
|
pProces->start(ss);
|
|||
|
emit process(2);
|
|||
|
}
|
|||
|
|
|||
|
void WorkThreadObject::on_read()
|
|||
|
{
|
|||
|
mProces = (QProcess*)sender();
|
|||
|
QString output = QString::fromLocal8Bit(mProces->readAllStandardOutput());
|
|||
|
if (output.toFloat() > 0)
|
|||
|
{
|
|||
|
qDebug() << "exe out:" << output.toFloat();
|
|||
|
emit process(output.toFloat());
|
|||
|
if (output.toFloat() == 100.0)
|
|||
|
emit addDataToMap();
|
|||
|
}
|
|||
|
else
|
|||
|
qDebug() << "Unresolved exe out:" << output;
|
|||
|
}
|
|||
|
|
|||
|
void WorkThreadObject::runFormatConvert(QString pre_path, QString DSM)
|
|||
|
{
|
|||
|
QDir dir(pre_path);
|
|||
|
QStringList nameFilters;
|
|||
|
nameFilters << "*.tif" << "*.tiff";
|
|||
|
QStringList pre_tiff_files = dir.entryList(nameFilters, QDir::Files | QDir::Readable, QDir::Name);
|
|||
|
int list_len = pre_tiff_files.size();
|
|||
|
for (int i = 0; i < list_len; i++)
|
|||
|
{
|
|||
|
emit process(float(i) / float(list_len) * 95);
|
|||
|
qDebug() << "TiffToShp progress:" << float(i) / float(list_len) * 100;
|
|||
|
QString file_path = pre_path + "\\" + pre_tiff_files[i];
|
|||
|
QString dsm_path = DSM + "\\" + pre_tiff_files[i];
|
|||
|
string path_preTiff = file_path.toStdString();
|
|||
|
string pathPureName = path_preTiff.substr(0, path_preTiff.rfind("."));
|
|||
|
string shp_path = pathPureName + ".shp";
|
|||
|
//<2F><><EFBFBD><EFBFBD>դ<EFBFBD><D5A4>תʸ<D7AA><CAB8>
|
|||
|
img2shp cc;
|
|||
|
QtGDALProcessBar* gb = new QtGDALProcessBar();
|
|||
|
bool returnval = cc.ImagePolygonize(path_preTiff.c_str(), shp_path.c_str(), "ESRI Shapefile", 1, gb, gb);
|
|||
|
if (returnval == true)
|
|||
|
{
|
|||
|
QStringList list;
|
|||
|
list << dsm_path << QString::fromStdString(shp_path);
|
|||
|
emit addShpDataToMap(list);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("<22><><EFBFBD><EFBFBD>"), QString::fromLocal8Bit("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|||
|
//mess.setWindowFlags(Qt::Drawer);
|
|||
|
//int result = mess.exec();
|
|||
|
//return;
|
|||
|
}
|
|||
|
}
|
|||
|
emit process(100);
|
|||
|
}
|
|||
|
|
|||
|
void WorkThreadObject::on_cancel()
|
|||
|
{
|
|||
|
if (mProces == nullptr)
|
|||
|
{
|
|||
|
qDebug() << "--mProces null";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//py<70><79><EFBFBD><EFBFBD>exe<78>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
QString KillStr = "taskkill /f /im predict_4c_vegetation.exe";
|
|||
|
mProces->startDetached(KillStr);
|
|||
|
qDebug() << "--kill Proces";
|
|||
|
}
|
|||
|
}
|