145 lines
4.2 KiB
C++
145 lines
4.2 KiB
C++
#include "ptxformatfactory.h"
|
|
#include "workermanager.h"
|
|
#include "QDir"
|
|
#include "QCoreApplication"
|
|
#include "Monitor.h"
|
|
#include "sstream"
|
|
|
|
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];
|
|
}
|
|
|
|
// Вывод результата
|
|
// for (const auto& pair : outputMap) {
|
|
// std::cout << pair.first << " -> " << pair.second << std::endl;
|
|
// }
|
|
}
|
|
|
|
// Каждый файл обрабатывается по одному
|
|
void PtsFormatFactory::process(const QStringList &files, const QString &pathSave) {
|
|
QString app = "txt2las64.exe";
|
|
|
|
QDir dir(pathSave);
|
|
WorkerManager& workersManager = WorkerManager::get();
|
|
|
|
QStringList listArgs;
|
|
QString outputFilePath;
|
|
|
|
|
|
// QString filePath = fileInfo.path();//absoluteFilePath();
|
|
// filePath = removeFilePrefix(filePath);
|
|
// QString fileName = fileInfo.fileName();
|
|
// QString fileP = filePath + "/" + fileName;
|
|
|
|
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("xyzRGBI");
|
|
|
|
listArgs.append("-o");
|
|
listArgs.append(outputFilePath);
|
|
|
|
auto it = monitorList.insert({fileName}, new Monitor());
|
|
Monitor *monitor = *it;
|
|
monitor->messageCallbackHandling = [](const std::string& inputStr){
|
|
std::unordered_map<std::string, std::string> map;
|
|
parseStrMessage(inputStr,map);
|
|
if(map.empty()) return;
|
|
};
|
|
|
|
workersManager.prepareWorker(app, listArgs, monitor);
|
|
}
|
|
}
|
|
|
|
void LasFormatFactory::process(const QStringList &files, const QString &pathSave) {
|
|
|
|
#if _DEBUG
|
|
QString app = "D:/projects/Qt/Pretvorenit/build/Qt_6_8_1_MSVC2022_64bit_VS22_ninja-Debug/PotreeConverter/PotreeConverter.exe";
|
|
#else
|
|
QDir dirApp(QCoreApplication::applicationDirPath());
|
|
QString app = dirApp.filePath("PotreeConverter.exe");
|
|
#endif
|
|
|
|
QDir dir(pathSave);
|
|
WorkerManager& workersManager = WorkerManager::get();
|
|
|
|
QStringList listArgs;
|
|
QString outputFilePath;
|
|
|
|
listArgs.append("-i");
|
|
|
|
for(const QString& filePath : files) {
|
|
QFileInfo file(filePath);
|
|
auto fileName = removeExtension(file.fileName());
|
|
fileName += ".las";
|
|
|
|
outputFilePath = dir.filePath(fileName);
|
|
listArgs.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->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);
|
|
}
|