From a894539cfdfe9b1b2536a41a25af4ddf4d18babd Mon Sep 17 00:00:00 2001 From: Paul Leroy Date: Thu, 1 Jun 2023 23:05:50 +0200 Subject: [PATCH] 0.10 code cleaning --- CMakeLists.txt | 2 +- ContextBasedFeature.cpp | 2 +- PointFeature.cpp | 32 ++++++++++++++++---------------- confusionmatrix.cpp | 2 +- q3DMASC.cpp | 3 +-- q3DMASCTools.cpp | 34 +++++++++++++++++++--------------- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 513a75c..3f85674 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ if (INSTALL_Q3DMASC_PLUGIN) project( Q3DMASC_PLUGIN ) AddPlugin( NAME ${PROJECT_NAME} ) - set(Q3DMASC_PLUGIN_VERSION "0.9") + set(Q3DMASC_PLUGIN_VERSION "0.9+") include( CMakePolicies NO_POLICY_SCOPE ) diff --git a/ContextBasedFeature.cpp b/ContextBasedFeature.cpp index 4102a77..0da5bf2 100644 --- a/ContextBasedFeature.cpp +++ b/ContextBasedFeature.cpp @@ -268,7 +268,7 @@ bool ContextBasedFeature::prepare( const CorePoints& corePoints, return false; } - } + } // classCount >= kNN else // classCount < kNN { //specific case: not enough points of this class in the whole cloud! diff --git a/PointFeature.cpp b/PointFeature.cpp index 8a027d5..7a269e8 100644 --- a/PointFeature.cpp +++ b/PointFeature.cpp @@ -534,10 +534,10 @@ bool PointFeature::prepare( const CorePoints& corePoints, bool isScaled = scaled(); //build the final SF name - QString resultSFName = field1->getName(); + QString resultSF1Name = field1->getName(); if (cloud2 || corePoints.role != cloud1Label) { - resultSFName += "_" + cloud1Label; + resultSF1Name += "_" + cloud1Label; } if (isScaled) @@ -549,7 +549,7 @@ bool PointFeature::prepare( const CorePoints& corePoints, error = "Scaled features (SCx) must have an associated STAT measure"; return false; } - resultSFName += QString("_") + Feature::StatToString(stat); + resultSF1Name += QString("_") + Feature::StatToString(stat); } else //not scaled { @@ -564,29 +564,29 @@ bool PointFeature::prepare( const CorePoints& corePoints, if (field2 && op != Feature::NO_OPERATION) { //include the math operation as well if necessary! - resultSFName += "_" + Feature::OpToString(op) + "_" + field2->getName() + "_" + cloud2Label; + resultSF1Name += "_" + Feature::OpToString(op) + "_" + field2->getName() + "_" + cloud2Label; if (isScaled) { assert(stat != Feature::NO_STAT); - resultSFName += QString("_") + Feature::StatToString(stat); + resultSF1Name += QString("_") + Feature::StatToString(stat); } } if (isScaled) { - resultSFName += "@" + QString::number(scale); + resultSF1Name += "@" + QString::number(scale); //prepare the corresponding scalar field - statSF1WasAlreadyExisting = CheckSFExistence(corePoints.cloud, qPrintable(resultSFName)); + statSF1WasAlreadyExisting = CheckSFExistence(corePoints.cloud, qPrintable(resultSF1Name)); if (statSF1WasAlreadyExisting) { - // if the SF is not existing, it is not added to generatedScalarFields - statSF1 = PrepareSF(corePoints.cloud, qPrintable(resultSFName), generatedScalarFields, SFCollector::ALWAYS_KEEP); + // if the SF exists, it is not added to generatedScalarFields + statSF1 = PrepareSF(corePoints.cloud, qPrintable(resultSF1Name), generatedScalarFields, SFCollector::ALWAYS_KEEP); if (generatedScalarFields->scalarFields.contains(statSF1)) // i.e. the SF is existing but was not present at the startup of the plugin generatedScalarFields->setBehavior(statSF1, SFCollector::CAN_REMOVE); } else - statSF1 = PrepareSF(corePoints.cloud, qPrintable(resultSFName), generatedScalarFields, SFCollector::CAN_REMOVE); + statSF1 = PrepareSF(corePoints.cloud, qPrintable(resultSF1Name), generatedScalarFields, SFCollector::CAN_REMOVE); if (!statSF1) { error = QString("Failed to prepare scalar field for field '%1' @ scale %2").arg(field1->getName()).arg(scale); @@ -596,15 +596,15 @@ bool PointFeature::prepare( const CorePoints& corePoints, if (field2 && op != Feature::NO_OPERATION && !statSF1WasAlreadyExisting) // nothing to do if statSF1 was already there { - QString resultSFName2 = field2->getName() + QString("_") + cloud2Label + "_" + Feature::StatToString(stat) + "@" + QString::number(scale); + QString resultSF2Name = field2->getName() + QString("_") + cloud2Label + "_" + Feature::StatToString(stat) + "@" + QString::number(scale); //keepStatSF2 = (corePoints.cloud->getScalarFieldIndexByName(qPrintable(resultSFName2)) >= 0); //we remember that the scalar field was already existing! assert(!statSF2); - statSF2WasAlreadyExisting = CheckSFExistence(corePoints.cloud, qPrintable(resultSFName2)); + statSF2WasAlreadyExisting = CheckSFExistence(corePoints.cloud, qPrintable(resultSF2Name)); if (statSF2WasAlreadyExisting) - statSF2 = PrepareSF(corePoints.cloud, qPrintable(resultSFName2), generatedScalarFields, SFCollector::ALWAYS_KEEP); + statSF2 = PrepareSF(corePoints.cloud, qPrintable(resultSF2Name), generatedScalarFields, SFCollector::ALWAYS_KEEP); else - statSF2 = PrepareSF(corePoints.cloud, qPrintable(resultSFName2), generatedScalarFields, SFCollector::ALWAYS_REMOVE); + statSF2 = PrepareSF(corePoints.cloud, qPrintable(resultSF2Name), generatedScalarFields, SFCollector::ALWAYS_REMOVE); if (!statSF2) { error = QString("Failed to prepare scalar field for field '%1' @ scale %2").arg(field2->getName()).arg(scale); @@ -619,7 +619,7 @@ bool PointFeature::prepare( const CorePoints& corePoints, assert(cloud1 == corePoints.cloud || cloud1 == corePoints.origin); //retrieve/create a SF to host the result - int sfIdx = corePoints.cloud->getScalarFieldIndexByName(qPrintable(resultSFName)); + int sfIdx = corePoints.cloud->getScalarFieldIndexByName(qPrintable(resultSF1Name)); CCCoreLib::ScalarField* resultSF = nullptr; if (sfIdx >= 0) @@ -630,7 +630,7 @@ bool PointFeature::prepare( const CorePoints& corePoints, else { //copy the SF1 field - resultSF = new ccScalarField(qPrintable(resultSFName)); + resultSF = new ccScalarField(qPrintable(resultSF1Name)); if (!resultSF->resizeSafe(corePoints.cloud->size())) { error = "Not enough memory"; diff --git a/confusionmatrix.cpp b/confusionmatrix.cpp index 8cebfff..ad9f300 100644 --- a/confusionmatrix.cpp +++ b/confusionmatrix.cpp @@ -46,7 +46,7 @@ ConfusionMatrix::ConfusionMatrix(const std::vector &actual, const st this->ui->tableWidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); QSize tableSize = this->ui->tableWidget->sizeHint(); QSize labelSize = this->ui->label->sizeHint(); - QSize widgetSize = QSize(tableSize.width() + 20, tableSize.height() + 50); + QSize widgetSize = QSize(tableSize.width() + 30, tableSize.height() + 50); this->setMinimumSize(widgetSize); } diff --git a/q3DMASC.cpp b/q3DMASC.cpp index 962dcfa..2d8422c 100644 --- a/q3DMASC.cpp +++ b/q3DMASC.cpp @@ -604,7 +604,6 @@ void q3DMASCPlugin::doTrainAction() for (size_t i = 0; i < originalFeaturesTest.size(); ++i) { originalFeaturesTest[i].selected = trainDlg.isFeatureSelected(originalFeatures[i].feature->toString()); - //if the feature is selected if (originalFeaturesTest[i].selected) { @@ -625,7 +624,7 @@ void q3DMASCPlugin::doTrainAction() masc::CorePoints corePointsTest; corePointsTest.cloud = corePointsTest.origin = testCloud; corePointsTest.role = mainCloudLabel; - if (!masc::Tools::PrepareFeatures(corePointsTest, toPrepareTest, error, &progressDlg, &generatedScalarFieldsTest)) + if (!masc::Tools::PrepareFeatures(corePointsTest, toPrepareTest, error, &progressDlg, &generatedScalarFieldsTest)) { m_app->dispToConsole(error, ccMainAppInterface::ERR_CONSOLE_MESSAGE); generatedScalarFields.releaseSFs(false); diff --git a/q3DMASCTools.cpp b/q3DMASCTools.cpp index 0493c44..d54ca82 100644 --- a/q3DMASCTools.cpp +++ b/q3DMASCTools.cpp @@ -299,7 +299,7 @@ static bool CreateFeaturesFromCommand(const QString& command, QString corePoints } else { - //read the specific scale index (is it really an index? it looks like a scale value!) + //read the specific scale value bool ok = true; feature->scale = scaleStr.mid(2).toDouble(&ok); if (!ok) @@ -427,7 +427,7 @@ static bool CreateFeaturesFromCommand(const QString& command, QString corePoints } else { - ccLog::Warning(QString("ContextBasedFeature: you are using the DEPRECATED syntax (for instance, DZ1_SC0_CTX_10 is correct)").arg(token).arg(lineNumber)); + ccLog::Warning(QString("ContextBasedFeature: you are using the DEPRECATED syntax, the feature should contain only one cloud, as in DZ1_SC0_CTX_10)").arg(token).arg(lineNumber)); qSharedPointerCast(feature)->ctxClassLabel = classLabel; ++i; } @@ -1091,11 +1091,12 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features //build the scaled feature list attached to the second cloud (if any) if (feature->cloud2 && feature->cloud2 != feature->cloud1 - && feature->op != Feature::NO_OPERATION - && !static_cast(feature.data())->statSF1WasAlreadyExisting) // nothing to compute if the scalar field was already there + && feature->op != Feature::NO_OPERATION) { - if (!static_cast(feature.data())->statSF2WasAlreadyExisting) + if(!static_cast(feature.data())->statSF1WasAlreadyExisting) // nothing to compute if the scalar field was already there { + if (!static_cast(feature.data())->statSF2WasAlreadyExisting) + { FeaturesAndScales& fas = cloudsWithScaledFeatures[feature->cloud2]; ++fas.featureCount; fas.pointFeaturesPerScale[feature->scale].push_back(qSharedPointerCast(feature)); @@ -1103,6 +1104,7 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features { fas.scales.push_back(feature->scale); } + } } } } @@ -1127,17 +1129,19 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features //build the scaled feature list attached to the second cloud (if any) if (feature->cloud2 && feature->cloud2 != feature->cloud1 - && feature->op != Feature::NO_OPERATION - && !static_cast(feature.data())->sf1WasAlreadyExisting) // nothing to compute if the scalar field was already there + && feature->op != Feature::NO_OPERATION) { - if (!static_cast(feature.data())->sf2WasAlreadyExisting) + if (!static_cast(feature.data())->sf1WasAlreadyExisting) // nothing to compute if the scalar field was already there { - FeaturesAndScales& fas = cloudsWithScaledFeatures[feature->cloud2]; - fas.neighborhoodFeaturesPerScale[feature->scale].push_back(qSharedPointerCast(feature)); - ++fas.featureCount; - if (std::find(fas.scales.begin(), fas.scales.end(), feature->scale) == fas.scales.end()) + if (!static_cast(feature.data())->sf2WasAlreadyExisting) { - fas.scales.push_back(feature->scale); + FeaturesAndScales& fas = cloudsWithScaledFeatures[feature->cloud2]; + fas.neighborhoodFeaturesPerScale[feature->scale].push_back(qSharedPointerCast(feature)); + ++fas.featureCount; + if (std::find(fas.scales.begin(), fas.scales.end(), feature->scale) == fas.scales.end()) + { + fas.scales.push_back(feature->scale); + } } } } @@ -1357,9 +1361,9 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features { break; } - } + } //for each scale - } //for each scale + } if (progressCb) {