commit 21d5ecac2cfd33ef7ebd94307684e9f9e60bb6fc Author: keyeslll Date: Mon Mar 13 14:13:07 2023 +0800 DemTrain 20230313 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/DEM_GeneVec/CProgressBar.cpp b/DEM_GeneVec/CProgressBar.cpp new file mode 100644 index 0000000..f568f04 --- /dev/null +++ b/DEM_GeneVec/CProgressBar.cpp @@ -0,0 +1,51 @@ +#include "CProgressBar.h" + +CProgressBar::CProgressBar(QWidget* parent) : QProgressBar(parent) +{ + //this->setStyleSheet( + // "QProgressBar {color:black;font-size:12px;font-weight:normal;font-family:'Microsoft YaHei'; text-align:center; }" + // "QProgressBar::chunk {background-color: rgb(0, 160, 244);}"); +} + +void CProgressBar::ShowTips(const QString& strTips) +{ + if (this->isHidden()) + { + this->show(); + } + + this->resetFormat(); + this->setRange(0, 100); + this->setFormat(strTips); + this->setValue(100); +} + +double CProgressBar::GetDoubleFormatValue() +{ + double dValue = 0.0; + + QString strFormat = this->format(); + if (!strFormat.isEmpty()) + { + int nIndex = strFormat.indexOf(":"); + if (nIndex != -1) + { + QString strFormatData = strFormat.mid(nIndex + 1, strFormat.length() - nIndex - 2); + dValue = strFormatData.toDouble(); + } + } + + return dValue; +} + +void CProgressBar::SetDoubleFormatValue(const QString& strFormat, double dValue) +{ + if (this->isHidden()) + { + this->show(); + } + + this->setFormat(strFormat + ":" + QString::number(dValue, 'f', 2) + "%"); + this->setValue(dValue); +} + diff --git a/DEM_GeneVec/CProgressBar.h b/DEM_GeneVec/CProgressBar.h new file mode 100644 index 0000000..ffbc76d --- /dev/null +++ b/DEM_GeneVec/CProgressBar.h @@ -0,0 +1,18 @@ +#pragma once +#include + +class CProgressBar : public QProgressBar +{ + Q_OBJECT + +public: + CProgressBar(QWidget* parent = 0); + ~CProgressBar() {} + +public: + void ShowTips(const QString& strTips); + + void SetDoubleFormatValue(const QString& strFormat, double dValue); + + double GetDoubleFormatValue(); +}; diff --git a/DEM_GeneVec/DEM_GeneVec.cpp b/DEM_GeneVec/DEM_GeneVec.cpp new file mode 100644 index 0000000..9bb9646 --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.cpp @@ -0,0 +1,425 @@ +#include "DEM_GeneVec.h" +#include +#include +#include + +#include + +TrainMoudle::TrainMoudle() +{ + //ui.setupUi(this); +} + +TrainMoudle::~TrainMoudle() +{ + +} + +QString TrainMoudle::PannelName() +{ + return QString::fromLocal8Bit(""); +} + +QString TrainMoudle::CategoryName() +{ + return QString::fromLocal8Bit("DEM模块"); +} + +QString TrainMoudle::EnglishName() +{ + return QString::fromLocal8Bit("DEM_Module"); +} + +QString TrainMoudle::ChineseName() +{ + return QString::fromLocal8Bit("模型构建"); +} + +QString TrainMoudle::Information() +{ + return QString::fromLocal8Bit("模型构建"); +} + +QString TrainMoudle::IconPath() +{ + return ":/DEM_GeneVec/resources/dem_vec.svg"; +} + +QWidget* TrainMoudle::CenterWidget() +{ + QString gdal_path = qApp->applicationDirPath().toLocal8Bit() + "/share/gdal"; + QString pro_lib_path = qApp->applicationDirPath().toLocal8Bit() + "/share/proj"; + qputenv("GDAL_DATA", gdal_path.toLocal8Bit()); + qputenv("PROJ_LIB", pro_lib_path.toLocal8Bit()); + + bool showWin = false; + if (myWidget == nullptr) + { + myWidget = new QDialog(); + showWin = true; + qDebug() << "new QDialog()"; + } + else + { + qDebug() << "already have myWidget"; + myWidget->activateWindow(); + myWidget->raise(); + return myWidget; + } + ui.setupUi(myWidget); + + myWidget->setWindowTitle(QString::fromLocal8Bit("模型构建")); + myWidget->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); + myWidget->setWindowIcon(QIcon(":/DEM_GeneVec/resources/dem_vec.svg")); + myWidget->setAttribute(Qt::WA_QuitOnClose, false); + + myWidget->setAttribute(Qt::WA_DeleteOnClose); + connect(myWidget, &QDialog::destroyed, this, [=] { + qDebug() << "----DEM train window close----"; + + QDir pluginsDir = QDir(qApp->applicationDirPath()); + if (pluginsDir.cd("srsplugins\\DemModel")) + { + QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini"); + QFile f(strConfigPath); + if (f.exists()) + { + WriteConfigPaths(strConfigPath); + f.close(); + } + } + + if (mThread != nullptr) + { + mThread->requestInterruption();//请求线程中断 + mThread->quit(); + mThread->wait();//调用wait后先调用finished信号对应的槽函数,执行完成后再往下走 + mWorkObject->on_cancel(); + mThread = nullptr;//m_objThread, &QThread::finished, m_objThread, &QObject::deleteLater,不需要delete + mWorkObject = nullptr;//m_objThread, &QThread::finished, m_obj, &QObject::deleteLater + } + myWidget->close(); + myWidget = nullptr; + }); + connect(ui.pbtInModel, &QPushButton::pressed, this, &TrainMoudle::choseInModel); + connect(ui.pbtInDom, &QPushButton::pressed, this, &TrainMoudle::choseInDom); + connect(ui.pbtInDsm, &QPushButton::pressed, this, &TrainMoudle::choseInDsm); + connect(ui.pbtInLabel, &QPushButton::pressed, this, &TrainMoudle::choseInLabel); + connect(ui.pbtOutModel, &QPushButton::pressed, this, &TrainMoudle::choseOutModel); + + connect(ui.pushButton_ok, &QPushButton::pressed, this, &TrainMoudle::readAndStart); + connect(ui.pushButton_cancel, &QPushButton::pressed, this, &TrainMoudle::pbCancel); + + connect(ui.checkBoxMid, &QCheckBox::clicked, this, [=](bool checked) { + executeMid = checked; + if (!executeMid && !executeTrain) + ui.pushButton_ok->setEnabled(false); + else + ui.pushButton_ok->setEnabled(true); + }); + connect(ui.checkBoxTrain, &QCheckBox::clicked, this, [=](bool checked) { + executeTrain = checked; + if (!executeMid && !executeTrain) + ui.pushButton_ok->setEnabled(false); + else + ui.pushButton_ok->setEnabled(true); + }); + + ui.progressBar->setTextVisible(true); + ui.progressBar->setRange(0, 100); + + ui.lineEpoch1->setValidator(new QIntValidator(0, 999, this)); + ui.lineEpoch2->setValidator(new QIntValidator(0, 999, this)); + ui.lineEpoch1->setText("100"); + ui.lineEpoch2->setText("100"); + + ui.pbtInModel->setFocus(); + + QFile qssFile(":/DEM_GeneVec/DEM_GeneVec.qss"); + qssFile.open(QFile::ReadOnly); //以只读方式打开 + if (qssFile.isOpen()) + { + QString qss = QLatin1String(qssFile.readAll()); + myWidget->setStyleSheet(qss); + qssFile.close(); + } + else + qDebug() << "无法打开文件"; + + QDir pluginsDir = QDir(qApp->applicationDirPath()); + if (pluginsDir.cd("srsplugins\\DemModel")) + { + QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini"); + QFile f(strConfigPath); + if (f.exists()) + { + ReadConfigHistoryPaths(strConfigPath); + f.close(); + } + } + + if (showWin) + myWidget->show(); + + return myWidget; +} + +void TrainMoudle::startWorkThread() +{ + if (mWorkObject != nullptr) + { + return; + } + mThread = new QThread(); + mWorkObject = new WorkThreadObject(); + mWorkObject->moveToThread(mThread); + connect(mThread, &QThread::finished, mThread, &QObject::deleteLater); + connect(mThread, &QThread::finished, mWorkObject, &QObject::deleteLater); + connect(mWorkObject, &WorkThreadObject::process, myWidget, [=](double val) {ui.progressBar->SetDoubleFormatValue(QString::fromLocal8Bit("进度"), val); }); + connect(mWorkObject, &WorkThreadObject::addDataToMap, this, &TrainMoudle::addMap); + //connect(this, &TrainMoudle::killChildThread, mWorkObject, &WorkThreadObject::on_cancel); + + connect(this, &TrainMoudle::start, mWorkObject, &WorkThreadObject::runTrainWork); + mThread->start(); +} +//pbtDataset +//pbtValName +//pbtOutModel +void TrainMoudle::choseInModel() +{ + QString inModel = QFileDialog::getOpenFileName(ui.pbtInModel, QString::fromLocal8Bit("选择输入模型文件路径"), "", "*.pth"); + if (inModel != "") + ui.lineInModel->setText(inModel); +} +void TrainMoudle::choseInDom() +{ + QString dataset = QFileDialog::getExistingDirectory(ui.pbtInDom, QString::fromLocal8Bit("选择输入DOM文件路径"), ""); + if (dataset != "") + ui.lineInDom->setText(dataset); +} +void TrainMoudle::choseInDsm() +{ + QString valName = QFileDialog::getExistingDirectory(ui.pbtInDsm, QString::fromLocal8Bit("选择输入Slope文件路径"), ""); + if (valName != "") + ui.lineInDsm->setText(valName); +} +void TrainMoudle::choseInLabel() +{ + QString valName = QFileDialog::getExistingDirectory(ui.pbtInLabel, QString::fromLocal8Bit("选择输入Label文件路径"), ""); + if (valName != "") + ui.lineInLabel->setText(valName); +} +void TrainMoudle::choseOutModel() +{ + QString outModel = QFileDialog::getExistingDirectory(ui.pbtOutModel, QString::fromLocal8Bit("选择输出模型文件路径"), ""); + if (outModel != "") + ui.lineOutModel->setText(outModel); +} + +void TrainMoudle::ReadConfigHistoryPaths(QString strPath) +{ + QSettings configIni(strPath, QSettings::IniFormat); + + //打开标题为:[DemTrain] 的组,并读取出port字段的值 + configIni.beginGroup("DemTrain"); + + ui.lineInModel->setText(configIni.value("RetrainModel").toString()); + ui.lineInDom->setText(configIni.value("SrcDom").toString()); + ui.lineInDsm->setText(configIni.value("SrcDsm").toString()); + ui.lineInLabel->setText(configIni.value("SrcLabel").toString()); + ui.lineOutModel->setText(configIni.value("TrainResult").toString()); + + configIni.endGroup();//关闭组 +} + +void TrainMoudle::WriteConfigPaths(QString strPath) +{ + QSettings configIni(strPath, QSettings::IniFormat); + configIni.setIniCodec("utf-8"); + //打开标题为:[DemTrain] 的组 + configIni.beginGroup("DemTrain"); + + //更新输入模型路径 + QString temp = ui.lineInModel->text(); + if (temp != "") + configIni.setValue("RetrainModel", temp); + //更新输入DOM路径 + temp = ui.lineInDom->text(); + if (temp != "") + configIni.setValue("SrcDom", temp); + //更新输入DSM路径 + temp = ui.lineInDsm->text(); + if (temp != "") + configIni.setValue("SrcDsm", temp); + //更新输入Label路径 + temp = ui.lineInLabel->text(); + if (temp != "") + configIni.setValue("SrcLabel", temp); + //更新输出结果路径 + temp = ui.lineOutModel->text(); + if (temp != "") + configIni.setValue("TrainResult", temp); + + configIni.endGroup();//关闭组 +} + +void TrainMoudle::addMap() +{ + QMessageBox mess(QMessageBox::NoIcon, + QString::fromLocal8Bit("运行结束"), + QString::fromLocal8Bit("结果文件生成路径\n") + ui.lineOutModel->text(), + QMessageBox::Ok, NULL); + mess.setWindowFlags(Qt::Drawer); + mess.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确认")); + int result = mess.exec(); + //switch (result) + //{ + //case QMessageBox::Ok: + // //string_list.append(ui.lineEdit_outras->text()); + // //string_list.append(ui.lineEdit_outshp->text()); + // //qDebug() << "----Yes:" << string_list; + // //openResultData(string_list); + // //emit addDataToCanvas(string_list); + // break; + //default: + // break; + //} + pbCancel(); +} + +void TrainMoudle::readAndStart() +{ + QString inModel = ui.lineInModel->text(); + QString inDOM = ui.lineInDom->text(); + QString inDSM = ui.lineInDsm->text(); + QString inLabel = ui.lineInLabel->text(); + QString outModel = ui.lineOutModel->text(); + + ui.progressBar->SetDoubleFormatValue(QString::fromLocal8Bit("进度"), 0); + + if (inModel == "" || inDOM == "" || inDSM == "" || inLabel == "" || outModel == "") + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入输出文件夹或数据")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + QDir inDOMdir(inDOM); + if (!inDOMdir.exists()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("DOM文件夹不存在")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + QDir inDSMdir(inDSM); + if (!inDSMdir.exists()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("Slope文件夹不存在")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + QDir inLabeldir(inLabel); + if (!inLabeldir.exists()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("Label文件夹不存在")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + QDir outModeldir(outModel); + if (!outModeldir.exists()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("模型输出文件夹不存在")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + + if (executeMid && executeTrain) + qDebug() << "executeMid & executeTrain"; + if (executeMid && (!executeTrain)) + qDebug() << "executeMid, not executeTrain"; + if ((!executeMid) && executeTrain) + { + //判断train文件夹下有无训练集文件夹 + QDir dirImage(outModel + "/Images"); + QDir dirLabel(outModel + "/Labels"); + if (!dirImage.exists() || !dirLabel.exists()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), + QString::fromLocal8Bit("未找到训练集文件夹\n确保Images和Labels在以下路径中: \n") + outModel); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + //判断文件是否匹配 + QStringList imgList = getAllFiles(outModel + "/Images", "tif"); + QStringList labelList = getAllFiles(outModel + "/Labels", "tif"); + if (imgList.size() == 0 || labelList.size() == 0) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), + QString::fromLocal8Bit("训练集文件夹内为空")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + if (imgList.size() != labelList.size()) + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), + QString::fromLocal8Bit("训练集Images、Labels文件夹内文件不匹配")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + } + + if (ui.lineEpoch1->text() == "" || ui.lineEpoch2->text() == "") + { + QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请输入正确的训练轮数")); + mess.setWindowFlags(Qt::Drawer); + int result = mess.exec(); + return; + } + QString epoch1 = ui.lineEpoch1->text(); + QString epoch2 = ui.lineEpoch2->text(); + + if (mThread == nullptr) + { + qDebug() << "--startThread"; + startWorkThread(); + } + + emit start(inModel, inDOM, inDSM, inLabel, outModel, executeMid, executeTrain, epoch1, epoch2); +} + +QStringList TrainMoudle::getAllFiles(QString path, QString fileType) +{ + QDir dir(path); + if (!dir.exists()) + return QStringList(); + dir.setFilter(QDir::Files | QDir::NoSymLinks); + QFileInfoList list = dir.entryInfoList(); + + int file_count = list.count(); + if (file_count <= 0) + return QStringList(); + QStringList files; + for (int i = 0; i < file_count; i++) + { + QFileInfo file_info = list.at(i); + QString suffix = file_info.suffix(); + if (QString::compare(suffix, QString(fileType), Qt::CaseInsensitive) == 0) + { + QString absolute_file_path = file_info.absoluteFilePath(); + files.append(absolute_file_path); + } + } + return files; +} + +void TrainMoudle::pbCancel() +{ + delete myWidget;//调起&QDialog::destroyed +} diff --git a/DEM_GeneVec/DEM_GeneVec.h b/DEM_GeneVec/DEM_GeneVec.h new file mode 100644 index 0000000..4d3d84a --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ui_DEM_GeneVec.h" +#include "ThreadObject.h" +#include "SrsMainPluginInterFace.h" + +#include "gdal_priv.h" +//#include "gdal_alg_priv.h" + +class TrainMoudle : public SrsMainInterface +{ + Q_OBJECT + Q_INTERFACES(SrsMainInterface) + Q_PLUGIN_METADATA(IID MainInterface_iid) + +public: + TrainMoudle(); + ~TrainMoudle(); + + virtual QString PannelName() override; + virtual QString CategoryName() override; + + virtual QString EnglishName() override; + virtual QString ChineseName() override; + virtual QString Information() override; + virtual QString IconPath() override; + virtual QWidget* CenterWidget() override; + + void startWorkThread(); + + //读json文件,获取历史存储的路径 + void ReadConfigHistoryPaths(QString strPath); + //保存本次打开的路径到json文件 + void WriteConfigPaths(QString strPath); + + QStringList getAllFiles(QString path, QString fileType); + +public slots: + void choseInModel(); + void choseInDom(); + void choseInDsm(); + void choseInLabel(); + void choseOutModel(); + + void addMap(); + //pushbutton_OK + void readAndStart(); + void pbCancel(); + +signals: + void start(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2); + void killChildThread(); + +private: + Ui::DEM_GeneVecClass ui; + + QDialog* myWidget = nullptr; + + WorkThreadObject* mWorkObject = nullptr; + + QThread* mThread = nullptr; + + bool executeMid = true; + bool executeTrain = true; + +}; diff --git a/DEM_GeneVec/DEM_GeneVec.qrc b/DEM_GeneVec/DEM_GeneVec.qrc new file mode 100644 index 0000000..3860792 --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.qrc @@ -0,0 +1,6 @@ + + + resources/dem_vec.svg + DEM_GeneVec.qss + + diff --git a/DEM_GeneVec/DEM_GeneVec.qss b/DEM_GeneVec/DEM_GeneVec.qss new file mode 100644 index 0000000..762478b --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.qss @@ -0,0 +1,98 @@ +QProgressBar#progressBar { + border:0px solid white; + text-align:center; + color:black; +} +QProgressBar#progressBar:chunk { + background-color:#3FABBA; + width:20px; +} +QProgressBar#progressBar QLineEdit { + border:none; + color:black; + padding-left:5px; + font-size:16px; + background-color:transparent; +} + +QLabel{ + color:black; + font-family:'Microsoft YaHei'; + font-size:12px; +} + +/*----QPushButton样式表*/ +#pushButton_ok, #pushButton_cancel, #pbtInModel, #pbtInDom, #pbtInDsm, #pbtInLabel, #pbtOutModel{ + font-family:'Microsoft YaHei'; + font-size:12px; + background-color: #ffffff; + border: 1px solid #dcdfe6; + padding: 2px; + border-radius: 5px; + max-height:20px; +} +#pushButton_ok, #pushButton_cancel{ + min-width:36px; +} +#pushButton_ok:hover, #pushButton_cancel:hover, #pbtInModel:hover, #pbtInDom:hover, #pbtInDsm:hover,#pbtInLabel:hover,#pbtOutModel:hover{ + background-color: #ecf5ff; + color: #409eff; +} +#pushButton_ok:pressed, #pushButton_cancel:pressed, #pbtInModel:pressed, #pbtInDom:pressed, #pbtInDsm:pressed,#pbtInLabel:pressed,#pbtOutModel:pressed{ + border: 1px solid #3a8ee6; + color: #409eff; +} +#pushButton_ok:checked, #pushButton_cancel:checked, #pbtInModel:checked, #pbtInDom:checked, #pbtInDsm:checked,#pbtInLabel:checked,#pbtOutModel:checked{ + border: 1px solid #3a8ee6; + color: #409eff; +} +#pushButton_ok:focus, #pushButton_cancel:focus, #pbtInModel:focus, #pbtInDom:focus, #pbtInDsm:focus,#pbtInLabel:focus,#pbtOutModel:focus{ + border: 1px solid #3a8ee6; + color: #409eff; + outline: none; +} + +/*----QLineEdit样式*/ +#lineInModel, #lineInDsm, #lineInDom, #lineOutModel, #lineInLabel, #lineEpoch1, #lineEpoch2{ + border:0px; + border-bottom: 1px solid #B3B3B3; + font-family:'Microsoft YaHei'; + font-size:12px; + background-color:transparent; +} +#lineInModel:hover, #lineInDsm:hover, #lineInDom:hover, #lineOutModel:hover, #lineInLabel:hover, #lineEpoch1:hover, #lineEpoch2:hover{ + border-bottom: 2px solid #66A3FF; +} +#lineInModel:focus, #lineInDsm:focus, #lineInDom:focus, #lineOutModel:focus, #lineInLabel:focus, #lineEpoch1:focus, #lineEpoch2:focus{ + border-bottom: 2px solid #7666FF; +} + +/*QCheckBox{ + background:transparent; + border:0px; + color:black; + min-height: 20px; + min-width: 60px; +} +QCheckBox::disabled{ + background:transparent; + border:0px; + color:#202020; + min-height: 20px; + min-width: 60px; +} +QCheckBox::indicator{ + margin-right:-10px; +} +QCheckBox::indicator:checked{ + image: url(:/RemoteSensingProcess/Resources/checkbox_checked.svg); + width:25px; +} +QCheckBox::indicator:unchecked{ + image: url(:/RemoteSensingProcess/Resources/checkbox_unchecked.svg); + width:25px; +} +QCheckBox::indicator:disabled{ + image: url(:/RemoteSensingProcess/Resources/checkbox_disabled.svg); + width:25px; +}*/ \ No newline at end of file diff --git a/DEM_GeneVec/DEM_GeneVec.ui b/DEM_GeneVec/DEM_GeneVec.ui new file mode 100644 index 0000000..198a817 --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.ui @@ -0,0 +1,485 @@ + + + DEM_GeneVecClass + + + + 0 + 0 + 550 + 320 + + + + + 0 + 0 + + + + + 550 + 320 + + + + + 550 + 320 + + + + + + + + + + + + + 0 + 0 + + + + + + + + 6 + + + + + + 100 + 16777215 + + + + + + + + + 0 + 0 + + + + + 110 + 16777215 + + + + 瑙e喕璁粌娆℃暟 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 100 + 16777215 + + + + + + + + + + + 0 + 0 + + + + + + + + 閫夋嫨鏂囦欢 + + + + + + + + 0 + 0 + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 閫夋嫨鏂囦欢澶 + + + + + + + + + + + 0 + 0 + + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 閫夋嫨鏂囦欢澶 + + + + + + + + 0 + 0 + + + + + 110 + 0 + + + + + 110 + 16777215 + + + + 杈撳叆DOM鏂囦欢璺緞 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 110 + 0 + + + + + 110 + 16777215 + + + + 杈撳叆DSM鏂囦欢璺緞 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 閫夋嫨鏂囦欢澶 + + + + + + + + 0 + 0 + + + + + 110 + 0 + + + + + 110 + 16777215 + + + + 杈撳叆Label鏂囦欢璺緞 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 閫夋嫨鏂囦欢澶 + + + + + + + + 0 + 0 + + + + + 110 + 0 + + + + + 110 + 16777215 + + + + 杈撳嚭妯″瀷鏂囦欢璺緞 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + 杈撳叆鍒濆妯″瀷鏂囦欢璺緞 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 110 + 16777215 + + + + 鍐荤粨璁粌娆℃暟 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + 0 + + + QLayout::SetDefaultConstraint + + + 100 + + + + + 鐢熸垚璁粌闆嗐侀獙璇侀泦 + + + true + + + + + + + 妯″瀷璁粌 + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + 纭畾 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + 鍙栨秷 + + + + + + + + + + + 0 + + + + + + + + + + + CProgressBar + QProgressBar +
CProgressBar.h
+
+
+ + lineInModel + pbtInModel + lineInDom + pbtInDom + lineInDsm + pbtInDsm + lineInLabel + pbtInLabel + lineOutModel + pbtOutModel + pushButton_ok + pushButton_cancel + + + + + +
diff --git a/DEM_GeneVec/DEM_GeneVec.vcxproj b/DEM_GeneVec/DEM_GeneVec.vcxproj new file mode 100644 index 0000000..0ffa5bd --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.vcxproj @@ -0,0 +1,89 @@ +锘 + + + + Release + x64 + + + + {858826AD-BC7C-4B9D-8E48-626392904948} + QtVS_v304 + 10.0.19041.0 + $(MSBuildProjectDirectory)\QtMsBuild + DEM_Train + + + + DynamicLibrary + v142 + + + + + + + QtQgis + core;gui;widgets + release + + + + + + + + + + + + + D:\qgis\osgeo4w\include;D:\qgis\osgeo4w\apps\Qt5\include;$(IncludePath) + D:\qgis\osgeo4w\lib;D:\qgis\osgeo4w\apps\Qt5\lib;$(LibraryPath) + dem1-$(ProjectName) + + + + gdal_i.lib;%(AdditionalDependencies) + + + + + true + true + EditAndContinue + Disabled + MultiThreadedDLL + + + Console + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DEM_GeneVec/DEM_GeneVec.vcxproj.filters b/DEM_GeneVec/DEM_GeneVec.vcxproj.filters new file mode 100644 index 0000000..fe49981 --- /dev/null +++ b/DEM_GeneVec/DEM_GeneVec.vcxproj.filters @@ -0,0 +1,76 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + {96222dac-cebd-43e4-bfdd-ebee13ab43e3} + + + + + Resource Files + + + Header Files + + + Source Files + + + + + Source Files + + + process + + + Source Files + + + + + Form Files + + + + + Form Files + + + + + process + + + Header Files + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/DEM_GeneVec/SrsMainPluginInterFace.h b/DEM_GeneVec/SrsMainPluginInterFace.h new file mode 100644 index 0000000..9130479 --- /dev/null +++ b/DEM_GeneVec/SrsMainPluginInterFace.h @@ -0,0 +1,58 @@ +#pragma once +//#if _MSC_VER >=1600 // MSVC2015>1899, msvc_ver=14.0 +//#pragma execution_character_set("utf-8") +//#endif +//#include "qtclasslibrary1_global.h" +#include +#include +#include +#include + +struct SPluginMetaData +{ + QVector qvsReturnFilePaths; + QVector qvsSendFilePaths; + bool isAdd2Map; + +}; +class SrsMainInterface : public QObject +{ + Q_OBJECT +public: + virtual ~SrsMainInterface() {} + + /// + /// 返回pannel的名字 + /// + virtual QString PannelName() = 0; + + /// + /// 返回Category名字 + /// + /// + virtual QString CategoryName() = 0; + + /// + /// 返回插件的英文名字 + /// + /// + virtual QString EnglishName() = 0; + /// + /// 返回插件的中文名字 + /// + /// + virtual QString ChineseName() = 0; + virtual QString Information() = 0; + virtual QString IconPath() = 0; + virtual QWidget* CenterWidget() = 0; + // + //public slots: + // virtual void test(QWidget* parent) = 0; + +signals: + void AddDataToMap(QStringList string_list); + //void addDataToCanvas(QStringList string_list); +}; + +#define MainInterface_iid "com.Srs.MainInterface" +Q_DECLARE_INTERFACE(SrsMainInterface, MainInterface_iid) diff --git a/DEM_GeneVec/ThreadObject.cpp b/DEM_GeneVec/ThreadObject.cpp new file mode 100644 index 0000000..0475865 --- /dev/null +++ b/DEM_GeneVec/ThreadObject.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include + +#include + +#include "DEM_GeneVec.h" +#include "ThreadObject.h" + +using namespace std; + +WorkThreadObject::WorkThreadObject(QObject* parent) :QObject(parent) +{ + qRegisterMetaType >("std::function"); +} + +WorkThreadObject::~WorkThreadObject() +{ + +} + +void WorkThreadObject::runTrainWork(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2) +{ + QString str = QString("%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId()); + qDebug() << str; + + QDir pluginsDir = QDir(qApp->applicationDirPath()); + if (!pluginsDir.cd("models\\envs")) + { + qDebug() << "no folder models\\envs"; + return; + } + QString exeDirName = pluginsDir.absoluteFilePath("train_4c_vegetaion.exe"); + + QString inDom = " --dom_path "+ dom + "/"; + QString inDsm = " --dsm_path " + dsm + "/"; + QString inLabel = " --label_path " + label + "/"; + QString trainedModel = " --retrained_model " + inModel; + QString save_model = " --save_model " + outModel + "/"; + QString strMid, strTrain; + if (mid) + strMid = " --exe_mid True "; + else + strMid = " --exe_mid False "; + if (train) + strTrain = " --exe_train True"; + else + strTrain = " --exe_train False"; + QString strEpoch1, strEpoch2; + strEpoch1 = " --epoch1 " + epoch1; + strEpoch2 = " --epoch2 " + epoch2; + + //QString CUDA = " --CUDA False"; + QString ss = exeDirName + inDom + inDsm + inLabel + trainedModel + save_model+ strMid + strTrain + strEpoch1 + strEpoch2;// + CUDA + qDebug() << ss; + QProcess* pProces = new QProcess(this); + connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(on_read())); + + pProces->start(ss); +} + +void WorkThreadObject::on_read() +{ + mProces = (QProcess*)sender(); + QString output = QString::fromLocal8Bit(mProces->readAllStandardOutput()); + //qDebug() << "out:" << output; + if (output.toDouble() > 0) + { + qDebug() << "exe out:" << output.toDouble(); + emit process(output.toDouble()); + if (output.toDouble() == 100.0) + { + emit addDataToMap(); + } + } + else + qDebug() << "Unresolved exe out:" << output; +} + +void WorkThreadObject::on_cancel() +{ + QString str = QString("--1.%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId()); + qDebug() << str; + + if (mProces == nullptr) + { + qDebug() << "--mProces null"; + } + else + { + QString KillStr = "taskkill /f /im train_4c_vegetaion.exe"; + mProces->startDetached(KillStr); + qDebug() << "--kill Proces"; + } +} \ No newline at end of file diff --git a/DEM_GeneVec/ThreadObject.h b/DEM_GeneVec/ThreadObject.h new file mode 100644 index 0000000..18570a9 --- /dev/null +++ b/DEM_GeneVec/ThreadObject.h @@ -0,0 +1,48 @@ +#ifndef THREADOBJECT_H +#define THREADOBJECT_H +#include + +#include +#include +#include +#include +#include + +#include + +//#include "MultiQProcess.h" + +//#include "qtclasslibrary1_global.h" +#include "SrsMainPluginInterFace.h" +#include "ui_DEM_GeneVec.h" +//#include "Extract.h" + +using namespace std; + +class TrainMoudle; + +class WorkThreadObject :public QObject +{ + Q_OBJECT +public: + WorkThreadObject(QObject* parent = NULL); + ~WorkThreadObject(); + + void on_cancel(); + +signals: + void process(double value); + void addDataToMap(); + +public slots: + //void RunWork(QString landsat_file, QString gf_file, QString tvdi_file); + //void RunWork(QString file1, QString file2, QString file_out, std::functionprogressCallback); + //void RunWork(QString file1, QString file2, QString file_out); + void runTrainWork(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2); + void on_read(); + +private: + QProcess* mProces = nullptr; +}; + +#endif diff --git a/DEM_GeneVec/main.cpp b/DEM_GeneVec/main.cpp new file mode 100644 index 0000000..a349a89 --- /dev/null +++ b/DEM_GeneVec/main.cpp @@ -0,0 +1,16 @@ +#include "DEM_GeneVec.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QString gdal_path = qApp->applicationDirPath().toLocal8Bit() + "/share/gdal"; + QString pro_lib_path = qApp->applicationDirPath().toLocal8Bit() + "/share/proj"; + qputenv("GDAL_DATA", gdal_path.toLocal8Bit()); + qputenv("PROJ_LIB", pro_lib_path.toLocal8Bit()); + + TrainMoudle w; + w.CenterWidget()->show(); + return a.exec(); +} diff --git a/DEM_GeneVec/resources/dem_vec.svg b/DEM_GeneVec/resources/dem_vec.svg new file mode 100644 index 0000000..e7e2365 --- /dev/null +++ b/DEM_GeneVec/resources/dem_vec.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/DEM_Train.sln b/DEM_Train.sln new file mode 100644 index 0000000..7e0294c --- /dev/null +++ b/DEM_Train.sln @@ -0,0 +1,23 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31911.196 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DEM_GeneVec", "DEM_GeneVec\DEM_GeneVec.vcxproj", "{858826AD-BC7C-4B9D-8E48-626392904948}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {858826AD-BC7C-4B9D-8E48-626392904948}.Release|x64.ActiveCfg = Release|x64 + {858826AD-BC7C-4B9D-8E48-626392904948}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + Qt5Version = qt5.14.2 + SolutionGuid = {B8F00221-FFCF-43EE-B1EC-68EEC3E5BC58} + EndGlobalSection +EndGlobal