179 lines
5.5 KiB
C++
179 lines
5.5 KiB
C++
#include "ptxformatfactory.h"
|
||
#include "workermanager.h"
|
||
#include "QDir"
|
||
#include "QCoreApplication"
|
||
#include "Monitor.h"
|
||
#include "sstream"
|
||
#include "converterdata.h"
|
||
|
||
QString removeExtension(const QString& fileName) {
|
||
QString retValue = "";
|
||
QChar ch;
|
||
for (int idx =0, idxLenght = fileName.length(); idx<idxLenght; ++idx) {
|
||
ch= fileName[idx];
|
||
if (ch=='.') break;
|
||
retValue += ch;
|
||
}
|
||
|
||
return retValue;
|
||
}
|
||
|
||
void parseStrMessage(const std::string& input, std::unordered_map<std::string, std::string>& outputMap) {
|
||
std::istringstream stream(input);
|
||
std::string token;
|
||
std::vector<std::string> tokens;
|
||
|
||
// Разбиваем строку по ';'
|
||
while (std::getline(stream, token, ';')) {
|
||
if (!token.empty()) {
|
||
tokens.push_back(token);
|
||
}
|
||
}
|
||
|
||
// Чередуем ключ-значение
|
||
for (size_t i = 0; i + 1 < tokens.size(); i += 2) {
|
||
outputMap[tokens[i]] = tokens[i + 1];
|
||
}
|
||
}
|
||
|
||
// Каждый файл обрабатывается по одному
|
||
void PtsFormatFactory::process(const QStringList &files, const QString &pathSave) {
|
||
QString app = "txt2las64.exe";
|
||
|
||
QDir dir(pathSave);
|
||
WorkerManager& workersManager = WorkerManager::get();
|
||
|
||
QStringList listArgs;
|
||
QString outputFilePath;
|
||
|
||
QMap<QString,Monitor*>& monitorList = Monitor::getMonitorList();
|
||
|
||
for (const QString& filePath : files) {
|
||
QFileInfo file(filePath);
|
||
QString fileNameSuffix = file.fileName();
|
||
auto fileName = removeExtension(fileNameSuffix);
|
||
|
||
auto fileNameLas = fileName + ".las";
|
||
|
||
outputFilePath = dir.filePath(fileNameLas);
|
||
|
||
listArgs.append("-i");
|
||
listArgs.append(filePath);
|
||
|
||
listArgs.append("-set_point_type");
|
||
listArgs.append("2");
|
||
|
||
listArgs.append("-parse");
|
||
listArgs.append("xyzIRGB");
|
||
|
||
listArgs.append("-set_scale");
|
||
listArgs.append("0.001");
|
||
listArgs.append("0.001");
|
||
listArgs.append("0.001");
|
||
|
||
listArgs.append("-o");
|
||
listArgs.append(outputFilePath);
|
||
|
||
|
||
|
||
|
||
auto it = monitorList.insert({fileName}, new Monitor());
|
||
Monitor *monitor = *it;
|
||
|
||
std::string logFileName = monitor->getLogFileName();
|
||
monitor->setListFiles({filePath});
|
||
|
||
monitor->logErrorOutput =[logFileName](const std::string&msg){
|
||
QFile logFile = ConverterData::Get().getTempFile(QString::fromStdString(logFileName));
|
||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||
QTextStream stream(&logFile);
|
||
stream << QString::fromStdString(msg) << "\n";
|
||
logFile.close();
|
||
} else {
|
||
qWarning() << "Не удалось открыть лог-файл для записи:" << logFile.errorString();
|
||
}
|
||
};
|
||
monitor->messageCallbackHandling = [monitor](const std::string& inputStr){
|
||
std::unordered_map<std::string, std::string> map;
|
||
parseStrMessage(inputStr,map);
|
||
if(map.empty()) return;
|
||
|
||
auto it = map.find("progressTotal");
|
||
if (it != map.end()) {
|
||
monitor->setPercentComplete(std::stod(it->second));
|
||
}
|
||
};
|
||
|
||
monitor->listAllowedRetCodes.push_back(1);
|
||
workersManager.prepareWorker(app, listArgs, monitor);
|
||
}
|
||
}
|
||
|
||
void LasFormatFactory::process(const QStringList &files, const QString &pathSave) {
|
||
|
||
#if _DEBUG
|
||
QString app = R"(D:\projects\Qt\install\Program Files (x86)\Qurts\bin\PotreeConverter.exe)";
|
||
#else
|
||
QDir dirApp(QCoreApplication::applicationDirPath());
|
||
QString app = dirApp.filePath("PotreeConverter.exe");
|
||
#endif
|
||
|
||
QDir dir(pathSave);
|
||
WorkerManager& workersManager = WorkerManager::get();
|
||
|
||
QStringList listArgs;
|
||
QStringList listInputFiles;
|
||
|
||
listArgs.append("-i");
|
||
|
||
for(const QString& filePath : files) {
|
||
QFileInfo file(filePath);
|
||
auto fileName = removeExtension(file.fileName());
|
||
fileName += ".las";
|
||
|
||
listArgs.append(filePath);
|
||
listInputFiles.append(filePath);
|
||
// workersManager.prepareWorker(app,listArgs);
|
||
}
|
||
|
||
listArgs.append("-o");
|
||
listArgs.append(pathSave);
|
||
|
||
QMap<QString,Monitor*>& monitorList = Monitor::getMonitorList();
|
||
|
||
// auto it = monitorList.insert("CLAS", new Monitor());
|
||
// Monitor *monitor = *it;
|
||
{
|
||
Monitor *monitor = monitorList["CLAS"];
|
||
monitor->setListFiles(listInputFiles);
|
||
std::string logFileName = monitor->getLogFileName();
|
||
|
||
|
||
monitor->logErrorOutput =[logFileName](const std::string&msg){
|
||
QFile logFile = ConverterData::Get().getTempFile(QString::fromStdString(logFileName));
|
||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||
QTextStream stream(&logFile);
|
||
stream << QString::fromStdString(msg) << "\n";
|
||
logFile.close();
|
||
} else {
|
||
qWarning() << "Не удалось открыть лог-файл для записи:" << logFile.errorString();
|
||
}
|
||
};
|
||
|
||
monitor->messageCallbackHandling = [monitor](const std::string& inputStr){
|
||
qDebug() << "Received: " << inputStr;
|
||
std::unordered_map<std::string, std::string> map;
|
||
parseStrMessage(inputStr,map);
|
||
|
||
if(map.empty()) return;
|
||
|
||
auto it = map.find("progressTotal");
|
||
if(it != map.end()) {
|
||
monitor->setPercentComplete(std::stod(it->second) / 100);
|
||
}
|
||
};
|
||
|
||
workersManager.prepareWorker(app,listArgs,monitor);
|
||
}
|
||
}
|