diff --git a/q3DMASC.cpp b/q3DMASC.cpp index 0a0a63a..d8ac038 100644 --- a/q3DMASC.cpp +++ b/q3DMASC.cpp @@ -133,6 +133,7 @@ void q3DMASCPlugin::doClassifyAction() //now show a dialog where the user will be able to set the cloud roles Classify3DMASCDialog classifDlg(m_app); classifDlg.setCloudRoles(cloudLabels); + classifDlg.classifierFileLineEdit->setText(inputFilename); if (!classifDlg.exec()) { //process cancelled by the user diff --git a/q3DMASCClassifier.cpp b/q3DMASCClassifier.cpp index d46cae2..e6a8ece 100644 --- a/q3DMASCClassifier.cpp +++ b/q3DMASCClassifier.cpp @@ -132,12 +132,12 @@ bool Classifier::classify(const Feature::Set& features, ccPointCloud* cloud, QSt } classifSFIdx = cloud->addScalarField(_classificationSF); classificationSF = _classificationSF; - cloud->setCurrentDisplayedScalarField(classifSFIdx); } else { classificationSF = cloud->getScalarField(classifSFIdx); } + cloud->setCurrentDisplayedScalarField(classifSFIdx); assert(classificationSF); classificationSF->fill(0); //0 = no classification? @@ -552,16 +552,32 @@ bool Classifier::toFile(QString filename, QWidget* parentWidget/*=nullptr*/) con bool Classifier::fromFile(QString filename, QWidget* parentWidget/*=nullptr*/) { //load the classifier - QProgressDialog pDlg(parentWidget); - pDlg.setRange(0, 0); //infinite loop - pDlg.setLabelText(QObject::tr("Loading classifier")); - pDlg.show(); - QCoreApplication::processEvents(); + QScopedPointer pDlg; + if (parentWidget) + { + pDlg.reset(new QProgressDialog(parentWidget)); + pDlg->setRange(0, 0); //infinite loop + pDlg->setLabelText(QObject::tr("Loading classifier")); + pDlg->show(); + QCoreApplication::processEvents(); + } + + try + { + m_rtrees = cv::ml::RTrees::load(filename.toStdString()); + } + catch (const cv::Exception& cvex) + { + ccLog::Warning(cvex.msg.c_str()); + ccLog::Error("Failed to load file: " + filename); + return false; + } - m_rtrees = cv::ml::RTrees::load(filename.toStdString()); - - pDlg.close(); - QCoreApplication::processEvents(); + if (pDlg) + { + pDlg->close(); + QCoreApplication::processEvents(); + } if (!m_rtrees->isTrained()) { diff --git a/q3DMASCTools.cpp b/q3DMASCTools.cpp index fa315dc..c85c9a5 100644 --- a/q3DMASCTools.cpp +++ b/q3DMASCTools.cpp @@ -45,8 +45,9 @@ bool Tools::SaveClassifier(QString filename, const Feature::Set& features, const { //first save the classifier data (same base filename but with the ymal extension) QFileInfo fi(filename); - QString yamlFilename = fi.completeBaseName() + ".yaml"; - if (!classifier.toFile(fi.absoluteFilePath() + "/" + yamlFilename, parent)) + QString yamlFilename = fi.baseName() + ".yaml"; + QString yamlAbsoluteFilename = fi.absoluteDir().absoluteFilePath(yamlFilename); + if (!classifier.toFile(yamlAbsoluteFilename, parent)) { ccLog::Error("Failed to save the classifier data"); return false; @@ -109,6 +110,7 @@ bool Tools::LoadClassifierCloudLabels(QString filename, QSet& labels) } ++lineNumber; + line = line.toUpper(); if (line.startsWith("CLOUD:")) { QString command = line.mid(6).trimmed(); @@ -633,12 +635,13 @@ static bool LoadFileCommon( const QString& filename, return false; } QString yamlFilename = line.mid(11).trimmed(); - if (!classifier->fromFile(fi.absolutePath() + "/" + yamlFilename, parent)) + QString yamlAbsoluteFilename = fi.absoluteDir().absoluteFilePath(yamlFilename); + if (!classifier->fromFile(yamlAbsoluteFilename, parent)) { - ccLog::Warning("Failed to load the classifier file from " + yamlFilename); + ccLog::Warning("Failed to load the classifier file from " + yamlAbsoluteFilename); return false; } - ccLog::Print("[3DMASC] Classifier data loaded from " + yamlFilename); + ccLog::Print("[3DMASC] Classifier data loaded from " + yamlAbsoluteFilename); } else if (upperLine.startsWith("CLOUD:")) //clouds { diff --git a/qClassify3DMASCDialog.cpp b/qClassify3DMASCDialog.cpp index fc65a8d..90c4f69 100644 --- a/qClassify3DMASCDialog.cpp +++ b/qClassify3DMASCDialog.cpp @@ -99,13 +99,6 @@ Classify3DMASCDialog::Classify3DMASCDialog(ccMainAppInterface* app) } } - cloud1RadioButton->setEnabled(false); - cloud2RadioButton->setEnabled(false); - cloud3RadioButton->setEnabled(false); - cloud1ComboBox->setEnabled(false); - cloud2ComboBox->setEnabled(false); - cloud3ComboBox->setEnabled(false); - onCloudChanged(0); } @@ -118,28 +111,37 @@ void Classify3DMASCDialog::setCloudRoles(const QSet& roles) { case 0: cloud1RadioButton->setText(role); - - cloud1RadioButton->setEnabled(true); - cloud1ComboBox->setEnabled(false); - cloud1RadioButton->setChecked(true); break; case 1: cloud2RadioButton->setText(role); - - cloud2RadioButton->setEnabled(true); - cloud2ComboBox->setEnabled(false); break; case 2: cloud3RadioButton->setText(role); - - cloud3RadioButton->setEnabled(true); - cloud3ComboBox->setEnabled(false); break; default: //this dialog can't handle more than 3 roles! break; } + ++index; + } + + if (index < 1) + { + cloud1RadioButton->setEnabled(false); + cloud1ComboBox->setEnabled(false); + } + if (index < 2) + { + cloud2RadioButton->setEnabled(false); + cloud2RadioButton->setVisible(false); + cloud2ComboBox->setVisible(false); + } + if (index < 3) + { + cloud3RadioButton->setEnabled(false); + cloud3RadioButton->setVisible(false); + cloud3ComboBox->setVisible(false); } }