mirror of
https://github.com/dgirardeau/q3DMASC.git
synced 2026-08-29 16:40:49 +08:00
Bug fix + parallel computation of features
This commit is contained in:
+29
-5
@@ -33,6 +33,9 @@
|
|||||||
//system
|
//system
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
//Qt
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
static const char* s_echoRatioSFName = "EchoRat";
|
static const char* s_echoRatioSFName = "EchoRat";
|
||||||
static const char* s_NIRSFName = "NIR";
|
static const char* s_NIRSFName = "NIR";
|
||||||
static const char* s_M3C2SFName = "M3C2 distance";
|
static const char* s_M3C2SFName = "M3C2 distance";
|
||||||
@@ -583,10 +586,11 @@ static CCLib::ScalarField* ExtractStat( const CorePoints& corePoints,
|
|||||||
resultSF->computeMinAndMax();
|
resultSF->computeMinAndMax();
|
||||||
int newSFIdx = corePoints.cloud->addScalarField(static_cast<ccScalarField*>(resultSF));
|
int newSFIdx = corePoints.cloud->addScalarField(static_cast<ccScalarField*>(resultSF));
|
||||||
//update display
|
//update display
|
||||||
if (corePoints.cloud->getDisplay())
|
//if (corePoints.cloud->getDisplay())
|
||||||
{
|
{
|
||||||
corePoints.cloud->setCurrentDisplayedScalarField(newSFIdx);
|
corePoints.cloud->setCurrentDisplayedScalarField(newSFIdx);
|
||||||
corePoints.cloud->getDisplay()->redraw();
|
//corePoints.cloud->getDisplay()->redraw();
|
||||||
|
//QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultSF;
|
return resultSF;
|
||||||
@@ -698,7 +702,7 @@ bool PointFeature::prepare( const CorePoints& corePoints,
|
|||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//and the scalar fielda
|
//and the scalar field
|
||||||
assert(!statSF1);
|
assert(!statSF1);
|
||||||
statSF1 = PrepareSF(corePoints, qPrintable(resultSFName));
|
statSF1 = PrepareSF(corePoints, qPrintable(resultSFName));
|
||||||
//CCLib::ScalarField* statSF1 = ExtractStat(corePoints, cloud1, field1.data(), scale, stat, qPrintable(resultSFName), progressCb);
|
//CCLib::ScalarField* statSF1 = ExtractStat(corePoints, cloud1, field1.data(), scale, stat, qPrintable(resultSFName), progressCb);
|
||||||
@@ -802,10 +806,11 @@ bool PointFeature::prepare( const CorePoints& corePoints,
|
|||||||
resultSF->computeMinAndMax();
|
resultSF->computeMinAndMax();
|
||||||
int newSFIdx = corePoints.cloud->addScalarField(static_cast<ccScalarField*>(resultSF));
|
int newSFIdx = corePoints.cloud->addScalarField(static_cast<ccScalarField*>(resultSF));
|
||||||
//update display
|
//update display
|
||||||
if (corePoints.cloud->getDisplay())
|
//if (corePoints.cloud->getDisplay())
|
||||||
{
|
{
|
||||||
corePoints.cloud->setCurrentDisplayedScalarField(newSFIdx);
|
corePoints.cloud->setCurrentDisplayedScalarField(newSFIdx);
|
||||||
corePoints.cloud->getDisplay()->redraw();
|
//corePoints.cloud->getDisplay()->redraw();
|
||||||
|
//QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,6 +976,15 @@ bool PointFeature::finish(const CorePoints& corePoints, QString& error)
|
|||||||
if (statSF1)
|
if (statSF1)
|
||||||
{
|
{
|
||||||
statSF1->computeMinAndMax();
|
statSF1->computeMinAndMax();
|
||||||
|
|
||||||
|
//update display
|
||||||
|
//if (corePoints.cloud->getDisplay())
|
||||||
|
{
|
||||||
|
int sfIndex1 = corePoints.cloud->getScalarFieldIndexByName(statSF1->getName());
|
||||||
|
corePoints.cloud->setCurrentDisplayedScalarField(sfIndex1);
|
||||||
|
//corePoints.cloud->getDisplay()->redraw();
|
||||||
|
//QCoreApplication::processEvents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statSF2)
|
if (statSF2)
|
||||||
@@ -1031,6 +1045,16 @@ QString PointFeature::toString() const
|
|||||||
|
|
||||||
description += "_" + cloud1Label;
|
description += "_" + cloud1Label;
|
||||||
|
|
||||||
|
if (cloud2 && !cloud2Label.isEmpty())
|
||||||
|
{
|
||||||
|
description += "_" + cloud2Label;
|
||||||
|
|
||||||
|
if (op != NO_OPERATION)
|
||||||
|
{
|
||||||
|
description += "_" + OpToString(op);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Point features always have a scale equal to 0 by definition
|
//Point features always have a scale equal to 0 by definition
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ void q3DMASCPlugin::doTrainAction()
|
|||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
pDlg.setAutoClose(true); //restore the default behavior of the progress dialog
|
pDlg.setAutoClose(true); //restore the default behavior of the progress dialog
|
||||||
|
|
||||||
|
m_app->redrawAll();
|
||||||
|
|
||||||
//randomly select the training points
|
//randomly select the training points
|
||||||
QScopedPointer<CCLib::ReferenceCloud> trainSubset(new CCLib::ReferenceCloud(corePoints.cloud));
|
QScopedPointer<CCLib::ReferenceCloud> trainSubset(new CCLib::ReferenceCloud(corePoints.cloud));
|
||||||
QScopedPointer<CCLib::ReferenceCloud> testSubset(new CCLib::ReferenceCloud(corePoints.cloud));
|
QScopedPointer<CCLib::ReferenceCloud> testSubset(new CCLib::ReferenceCloud(corePoints.cloud));
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ bool Classifier::classify(const Feature::Set& features, ccPointCloud* cloud, QSt
|
|||||||
{
|
{
|
||||||
classificationSF = cloud->getScalarField(classifSFIdx);
|
classificationSF = cloud->getScalarField(classifSFIdx);
|
||||||
}
|
}
|
||||||
cloud->setCurrentDisplayedScalarField(classifSFIdx);
|
|
||||||
assert(classificationSF);
|
assert(classificationSF);
|
||||||
classificationSF->fill(0); //0 = no classification?
|
classificationSF->fill(0); //0 = no classification?
|
||||||
|
|
||||||
@@ -549,12 +548,13 @@ bool Classifier::toFile(QString filename, QWidget* parentWidget/*=nullptr*/) con
|
|||||||
pDlg.show();
|
pDlg.show();
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
m_rtrees->save(filename.toStdString());
|
cv::String cvFilename = filename.toStdString();
|
||||||
|
m_rtrees->save(cvFilename);
|
||||||
|
|
||||||
pDlg.close();
|
pDlg.close();
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
ccLog::Print("Classifier file saved to: " + filename);
|
ccLog::Print("Classifier file saved to: " + QString::fromStdString(cvFilename));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-6
@@ -35,6 +35,7 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
//system
|
//system
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -900,7 +901,11 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features
|
|||||||
ccLog::Print(QString("Computing fields for cloud %1 (core points: %2)").arg(sourceCloud->getName()).arg(pointCount));
|
ccLog::Print(QString("Computing fields for cloud %1 (core points: %2)").arg(sourceCloud->getName()).arg(pointCount));
|
||||||
CCLib::NormalizedProgress nProgress(progressCb, pointCount);
|
CCLib::NormalizedProgress nProgress(progressCb, pointCount);
|
||||||
|
|
||||||
for (unsigned i = 0; i < pointCount; ++i)
|
QMutex mutex;
|
||||||
|
#if defined(_OPENMP)
|
||||||
|
#pragma omp parallel for
|
||||||
|
#endif
|
||||||
|
for (int i = 0; i < static_cast<int>(pointCount); ++i)
|
||||||
{
|
{
|
||||||
//spherical neighborhood extraction structure
|
//spherical neighborhood extraction structure
|
||||||
CCLib::DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
|
CCLib::DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
|
||||||
@@ -948,6 +953,12 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features
|
|||||||
double outputValue = 0;
|
double outputValue = 0;
|
||||||
for (PointFeature::Shared& feature : fas.features)
|
for (PointFeature::Shared& feature : fas.features)
|
||||||
{
|
{
|
||||||
|
if (feature->scale != fas.scales[scaleIndex])
|
||||||
|
{
|
||||||
|
//we use the current neighborhood only for the features with the corresponding scales!
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (feature->cloud1 == sourceCloud && feature->statSF1 && feature->field1)
|
if (feature->cloud1 == sourceCloud && feature->statSF1 && feature->field1)
|
||||||
{
|
{
|
||||||
if (!feature->computeStat(nNSS.pointsInNeighbourhood, feature->field1, outputValue))
|
if (!feature->computeStat(nNSS.pointsInNeighbourhood, feature->field1, outputValue))
|
||||||
@@ -983,12 +994,18 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features
|
|||||||
|
|
||||||
} //for each scale
|
} //for each scale
|
||||||
|
|
||||||
if (progressCb && !nProgress.oneStep())
|
if (progressCb)
|
||||||
{
|
{
|
||||||
//process cancelled by the user
|
mutex.lock();
|
||||||
ccLog::Warning("Process cancelled");
|
bool cancelled = !nProgress.oneStep();
|
||||||
error = true;
|
mutex.unlock();
|
||||||
break;
|
if (cancelled)
|
||||||
|
{
|
||||||
|
//process cancelled by the user
|
||||||
|
ccLog::Warning("Process cancelled");
|
||||||
|
error = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} //for each point
|
} //for each point
|
||||||
|
|||||||
Reference in New Issue
Block a user