ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
q3DMASCTools.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // ##########################################################################
11 // # #
12 // # ACLOUDVIEWER PLUGIN: q3DMASC #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 or later of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Dimitri Lague / CNRS / UEB #
24 // # #
25 // ##########################################################################
26 
27 // Local
28 #include "FeaturesInterface.h"
29 #include "q3DMASCClassifier.h"
30 
31 // CCLib
33 
34 // qCC_db
35 class ccPointCloud;
36 
37 class QWidget;
38 
40 namespace masc {
41 class Tools {
42 public:
43  typedef QMap<QString, ccPointCloud*> NamedClouds;
44 
45  static bool LoadTrainingFile(QString filename,
46  Feature::Set& rawFeatures,
47  std::vector<double>& scales,
48  NamedClouds& loadedClouds,
49  TrainParameters& parameters,
50  CorePoints* corePoints = nullptr,
51  QWidget* parent = nullptr);
52 
53  static bool LoadClassifierCloudLabels(
54  QString filename,
55  QList<QString>& labels,
56  QString& corePointsLabel,
57  bool& filenamesSpecified,
58  QMap<QString, QString>& rolesAndNames);
59 
60  static bool LoadClassifier(QString filename,
61  NamedClouds& clouds,
62  Feature::Set& rawFeatures,
63  masc::Classifier& classifier,
64  QWidget* parent = nullptr);
65 
66  static bool LoadFile(
67  const QString& filename,
68  Tools::NamedClouds* clouds,
69  bool cloudsAreProvided,
70  std::vector<Feature::Shared>* rawFeatures =
71  nullptr, // requires 'clouds'
72  std::vector<double>* rawScales = nullptr,
73  masc::CorePoints* corePoints = nullptr, // requires 'clouds'
74  masc::Classifier* classifier = nullptr,
75  TrainParameters* parameters = nullptr,
76  QWidget* parent = nullptr);
77 
78  static bool SaveClassifier(QString filename,
79  const Feature::Set& features,
80  const QString corePointsRole,
81  const masc::Classifier& classifier,
82  QWidget* parent = nullptr);
83 
84  static bool PrepareFeatures(
85  const CorePoints& corePoints,
86  Feature::Set& features,
87  QString& error,
88  cloudViewer::GenericProgressCallback* progressCb = nullptr,
89  SFCollector* generatedScalarFields = nullptr);
90 
91  static bool RandomSubset(ccPointCloud* cloud,
92  float ratio,
93  cloudViewer::ReferenceCloud* inRatioSubset,
94  cloudViewer::ReferenceCloud* outRatioSubset);
95 
97  const QString& sfName,
98  bool caseSensitive = true);
99 
102  const ccPointCloud* cloud);
103 };
104 
105 }; // namespace masc
cloudViewer::DgmOctree::NearestNeighboursSearchStruct::cellCenter
CCVector3 cellCenter
Coordinates of the center of the cell including the query point.
Definition: DgmOctree.h:189
ccGenericPointCloud::computeOctree
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
Definition: ecvGenericPointCloud.cpp:124
masc::Classifier::isValid
bool isValid() const
Returns whether the classifier is valid or not.
Definition: q3DMASCClassifier.cpp:48
masc::Feature::PLUS
@ PLUS
Definition: FeaturesInterface.h:95
FeaturesAndScales::scales
std::vector< double > scales
Definition: q3DMASCTools.cpp:1022
masc::Feature::Shared
QSharedPointer< Feature > Shared
Shared type.
Definition: FeaturesInterface.h:49
QtCompat::endl
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
FeaturesAndScales::featureCount
size_t featureCount
Definition: q3DMASCTools.cpp:1023
ccHObject::filterChildren
unsigned filterChildren(Container &filteredChildren, bool recursive=false, CV_CLASS_ENUM filter=CV_TYPES::OBJECT, bool strict=false) const
Collects the children corresponding to a certain pattern.
Definition: ecvHObject.cpp:611
ccHObject::detachChild
void detachChild(ccHObject *child)
Detaches a specific child.
Definition: ecvHObject.cpp:988
filename
std::string filename
Definition: PointCloudIO.cpp:47
cloudViewer::ReferenceCloud::reserve
virtual bool reserve(unsigned n)
Reserves some memory for hosting the point references.
Definition: ReferenceCloud.cpp:51
LAS_CLASSIFICATION
@ LAS_CLASSIFICATION
Definition: LASFields.h:44
octreeLevel
unsigned char octreeLevel
Definition: qCanupoTools.cpp:38
masc::Tools::LoadClassifier
static bool LoadClassifier(QString filename, NamedClouds &clouds, Feature::Set &rawFeatures, masc::Classifier &classifier, QWidget *parent=nullptr)
Definition: q3DMASCTools.cpp:962
cloudViewer::NormalizedProgress::oneStep
bool oneStep()
Increments total progress value of a single unit.
Definition: NormalizedProgress.cpp:99
masc
3DMASC classifier
Definition: ContextBasedFeature.h:30
masc::PointFeature::Invalid
@ Invalid
Definition: PointFeature.h:41
QtCompat.h
cloudViewer::DgmOctree::computeCellCenter
void computeCellCenter(CellCode code, unsigned char level, CCVector3 &center, bool isCodeTruncated=false) const
Definition: DgmOctree.h:862
FeaturesInterface.h
cloudViewer::ReferenceCloud::size
unsigned size() const override
Returns the number of points.
Definition: ReferenceCloud.h:41
cloudViewer::GenericCloud::size
virtual unsigned size() const =0
Returns the number of points.
PointFeature.h
ccHObject::getParent
ccHObject * getParent() const
Returns parent object.
Definition: ecvHObject.h:245
masc::Tools::LoadFile
static bool LoadFile(const QString &filename, Tools::NamedClouds *clouds, bool cloudsAreProvided, std::vector< Feature::Shared > *rawFeatures=nullptr, std::vector< double > *rawScales=nullptr, masc::CorePoints *corePoints=nullptr, masc::Classifier *classifier=nullptr, TrainParameters *parameters=nullptr, QWidget *parent=nullptr)
Definition: q3DMASCTools.cpp:745
cloudViewer::DgmOctree::NearestNeighboursSearchStruct::cellPos
Tuple3i cellPos
Position in the octree of the cell including the query point.
Definition: DgmOctree.h:184
masc::RandomTreesParams::maxTreeCount
int maxTreeCount
Definition: Parameters.h:36
cloudViewer::DgmOctree::NearestNeighboursSearchStruct::level
unsigned char level
Level of subdivision of the octree at which to start the search.
Definition: DgmOctree.h:171
nProgress
cloudViewer::NormalizedProgress * nProgress
Definition: qCanupoTools.cpp:42
ccObject::setName
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
cloudViewer::PointCloudTpl::getNumberOfScalarFields
unsigned getNumberOfScalarFields() const
Returns the number of associated (and active) scalar fields.
Definition: PointCloudTpl.h:345
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
CV_TYPES::POINT_CLOUD
@ POINT_CLOUD
Definition: CVTypes.h:104
masc::Tools::SaveClassifier
static bool SaveClassifier(QString filename, const Feature::Set &features, const QString corePointsRole, const masc::Classifier &classifier, QWidget *parent=nullptr)
Definition: q3DMASCTools.cpp:43
masc::Feature::Set
std::vector< Shared > Set
Set of features.
Definition: FeaturesInterface.h:52
GenericProgressCallback.h
cloudViewer::PointCloudTpl::size
unsigned size() const override
Definition: PointCloudTpl.h:38
ccPointCloud
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Definition: ecvPointCloud.h:146
masc::Feature::Type::PointFeature
@ PointFeature
cloudViewer::ScalarField
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
masc::Feature::MEDIAN
@ MEDIAN
Definition: FeaturesInterface.h:69
ecvMainAppInterface.h
FileIOFilter::LoadParameters::coordinatesShift
CCVector3d * coordinatesShift
If applicable, applied shift on load (optional)
Definition: FileIOFilter.h:71
masc::Tools
Definition: q3DMASCTools.h:41
cloudViewer::GenericProgressCallback::setMethodTitle
virtual void setMethodTitle(const char *methodTitle)=0
Notifies the algorithm title.
masc::PointFeature::Shared
QSharedPointer< PointFeature > Shared
Definition: PointFeature.h:38
cloudViewer::GenericProgressCallback
Definition: GenericProgressCallback.h:20
cloudViewer::PointCloudTpl::getScalarFieldIndexByName
int getScalarFieldIndexByName(const char *name) const
Returns the index of a scalar field represented by its name.
Definition: PointCloudTpl.h:375
masc::Classifier
Definition: q3DMASCClassifier.h:47
FileIOFilter::LoadParameters
Generic loading parameters.
Definition: FileIOFilter.h:51
masc::ContextBasedFeature::ContextBasedFeatureType
ContextBasedFeatureType
Definition: ContextBasedFeature.h:36
masc::PointFeature::SF
@ SF
Definition: PointFeature.h:57
ccOctree::Shared
QSharedPointer< ccOctree > Shared
Shared pointer.
Definition: ecvOctree.h:32
masc::Tools::RetrieveSF
static cloudViewer::ScalarField * RetrieveSF(const ccPointCloud *cloud, const QString &sfName, bool caseSensitive=true)
Definition: q3DMASCTools.cpp:993
CheckFeatureUnicity
bool CheckFeatureUnicity(std::vector< Feature::Shared > &rawFeatures, Feature::Shared feature)
Definition: q3DMASCTools.cpp:174
ccHObject::Container
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
FileIOFilter::LoadParameters::alwaysDisplayLoadDialog
bool alwaysDisplayLoadDialog
Definition: FileIOFilter.h:67
masc::NeighborhoodFeature::NeighborhoodFeatureType
NeighborhoodFeatureType
Definition: NeighborhoodFeature.h:36
masc::Tools::GetClassificationSF
static cloudViewer::ScalarField * GetClassificationSF(const ccPointCloud *cloud)
Helper: returns the classification SF associated to a cloud (if any)
Definition: q3DMASCTools.cpp:1591
cloudViewer::PointCloudTpl::getScalarField
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
Definition: PointCloudTpl.h:354
masc::DualCloudFeature::Invalid
@ Invalid
Definition: DualCloudFeature.h:34
ReadScales
static bool ReadScales(const QString &command, std::vector< double > &scales, int lineNumber)
Definition: q3DMASCTools.cpp:569
ccGenericPointCloud::getOctree
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
Definition: ecvGenericPointCloud.cpp:97
cloudViewer::GenericProgressCallback::setInfo
virtual void setInfo(const char *infoStr)=0
Notifies some information about the ongoing process.
masc::CorePoints
Core points descriptor.
Definition: CorePoints.h:39
masc::Tools::RandomSubset
static bool RandomSubset(ccPointCloud *cloud, float ratio, cloudViewer::ReferenceCloud *inRatioSubset, cloudViewer::ReferenceCloud *outRatioSubset)
Definition: q3DMASCTools.cpp:1512
CVLog::Error
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
FeaturesAndScales::pointFeaturesPerScale
QMap< double, std::vector< PointFeature::Shared > > pointFeaturesPerScale
Definition: q3DMASCTools.cpp:1024
cloudViewer::ReferenceCloud::addPointIndex
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
Definition: ReferenceCloud.cpp:84
NeighborhoodFeature.h
cloudViewer::DgmOctree::findNeighborsInASphereStartingFromCell
int findNeighborsInASphereStartingFromCell(NearestNeighboursSearchStruct &nNSS, double radius, bool sortValues=true) const
Advanced form of the nearest neighbours search algorithm (in a sphere)
Definition: DgmOctree.cpp:2479
size
int size
Definition: FileIOFactory.cpp:130
masc::Feature::MODE
@ MODE
Definition: FeaturesInterface.h:68
FeaturesAndScales::neighborhoodFeaturesPerScale
QMap< double, std::vector< NeighborhoodFeature::Shared > > neighborhoodFeaturesPerScale
Definition: q3DMASCTools.cpp:1026
FeaturesAndScales
Definition: q3DMASCTools.cpp:1021
masc::NeighborhoodFeature::FromUpperString
static NeighborhoodFeatureType FromUpperString(const QString &token)
Definition: NeighborhoodFeature.h:111
masc::RandomTreesParams::activeVarCount
int activeVarCount
Definition: Parameters.h:35
CreateFeaturesFromCommand
static bool CreateFeaturesFromCommand(const QString &command, QString corePointsRole, int lineNumber, const Tools::NamedClouds &clouds, std::vector< Feature::Shared > &rawFeatures, std::vector< double > &scales)
Definition: q3DMASCTools.cpp:187
Vector3Tpl< double >
cloudViewer::ScalarField::getName
const char * getName() const
Returns scalar field name.
Definition: ScalarField.h:43
FileIOFilter::LoadFromFile
static ccHObject * LoadFromFile(const QString &filename, LoadParameters &parameters, Shared filter, CC_FILE_ERROR &result)
Loads one or more entities from a file with a known filter.
Definition: FileIOFilter.cpp:253
masc::TrainParameters::rt
RandomTreesParams rt
Definition: Parameters.h:41
LAS_FIELD_NAMES
const char LAS_FIELD_NAMES[][28]
Definition: LASFields.h:63
cloudViewer::DgmOctree::NearestNeighboursSearchStruct::pointsInNeighbourhood
NeighboursSet pointsInNeighbourhood
Definition: DgmOctree.h:215
masc::NeighborhoodFeature::Invalid
@ Invalid
Definition: NeighborhoodFeature.h:37
ReadCorePoints
static bool ReadCorePoints(const QString &command, const Tools::NamedClouds &clouds, masc::CorePoints &corePoints, int lineNumber)
Definition: q3DMASCTools.cpp:633
CC_FILE_ERROR
CC_FILE_ERROR
Typical I/O filter errors.
Definition: FileIOFilter.h:20
masc::NeighborhoodFeature
Neighborhood-based feature.
Definition: NeighborhoodFeature.h:32
masc::Tools::NamedClouds
QMap< QString, ccPointCloud * > NamedClouds
Definition: q3DMASCTools.h:43
masc::Tools::LoadClassifierCloudLabels
static bool LoadClassifierCloudLabels(QString filename, QList< QString > &labels, QString &corePointsLabel, bool &filenamesSpecified, QMap< QString, QString > &rolesAndNames)
Definition: q3DMASCTools.cpp:101
masc::NeighborhoodFeature::Shared
QSharedPointer< NeighborhoodFeature > Shared
Definition: NeighborhoodFeature.h:34
ecvScalarField.h
FileIOFilter::ResetSesionCounter
static void ResetSesionCounter()
Definition: FileIOFilter.cpp:140
FileIOFilter.h
cloudViewer::DgmOctree::NearestNeighboursSearchStruct::queryPoint
CCVector3 queryPoint
Query point.
Definition: DgmOctree.h:167
masc::Feature::STD
@ STD
Definition: FeaturesInterface.h:70
masc::CorePoints::RANDOM
@ RANDOM
Definition: CorePoints.h:58
masc::PointFeature::sourceSFIndex
int sourceSFIndex
Source scalar field index (if the feature source is 'ScalarField')
Definition: PointFeature.h:217
masc::DualCloudFeature
Dual-cloud feature.
Definition: DualCloudFeature.h:32
cloudViewer::utility::floor
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
ContextBasedFeature.h
masc::ContextBasedFeature::FromUpperString
static ContextBasedFeatureType FromUpperString(const QString &token)
Definition: ContextBasedFeature.h:56
FeaturesAndScales::contextBasedFeaturesPerScale
QMap< double, std::vector< ContextBasedFeature::Shared > > contextBasedFeaturesPerScale
Definition: q3DMASCTools.cpp:1028
masc::Feature::SKEW
@ SKEW
Definition: FeaturesInterface.h:72
masc::TrainParameters
Definition: Parameters.h:40
masc::ContextBasedFeature::Invalid
@ Invalid
Definition: ContextBasedFeature.h:36
masc::Feature::DIVIDE
@ DIVIDE
Definition: FeaturesInterface.h:95
masc::DualCloudFeature::FromUpperString
static DualCloudFeatureType FromUpperString(const QString &token)
Definition: DualCloudFeature.h:52
masc::Feature::RANGE
@ RANGE
Definition: FeaturesInterface.h:71
masc::TrainParameters::testDataRatio
float testDataRatio
Definition: Parameters.h:42
FileIOFilter::LoadParameters::shiftHandlingMode
ecvGlobalShiftManager::Mode shiftHandlingMode
How to handle big coordinates.
Definition: FileIOFilter.h:64
q3DMASCClassifier.h
masc::Tools::PrepareFeatures
static bool PrepareFeatures(const CorePoints &corePoints, Feature::Set &features, QString &error, cloudViewer::GenericProgressCallback *progressCb=nullptr, SFCollector *generatedScalarFields=nullptr)
Definition: q3DMASCTools.cpp:1031
FileIOFilter::LoadParameters::parentWidget
QWidget * parentWidget
Parent widget (if any)
Definition: FileIOFilter.h:78
cloudViewer::ReferenceCloud::clear
virtual void clear(bool releaseMemory=false)
Clears the cloud.
Definition: ReferenceCloud.cpp:26
masc::PointFeature
Point feature.
Definition: PointFeature.h:36
cloudViewer::GenericIndexedCloud::getPoint
virtual const CCVector3 * getPoint(unsigned index) const =0
Returns the ith point.
octree
cloudViewer::DgmOctree * octree
Definition: qCanupoTools.cpp:37
cloudViewer::GenericProgressCallback::start
virtual void start()=0
masc::Feature::NO_OPERATION
@ NO_OPERATION
Definition: FeaturesInterface.h:95
masc::Feature::MEAN
@ MEAN
Definition: FeaturesInterface.h:67
masc::CorePoints::SPATIAL
@ SPATIAL
Definition: CorePoints.h:58
masc::Feature::Type::NeighborhoodFeature
@ NeighborhoodFeature
CVLog::Warning
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
cloudViewer::ReferenceCloud
A very simple point cloud (no point duplication)
Definition: ReferenceCloud.h:29
masc::Feature::MINUS
@ MINUS
Definition: FeaturesInterface.h:95
masc::Feature::Type::ContextBasedFeature
@ ContextBasedFeature
SFCollector
SF collector.
Definition: ScalarFieldCollector.h:42
masc::Classifier::fromFile
bool fromFile(QString filename, QWidget *parentWidget=nullptr)
Loads the classifier from file.
Definition: q3DMASCClassifier.cpp:730
ecvGlobalShiftManager::DIALOG_IF_NECESSARY
@ DIALOG_IF_NECESSARY
Definition: ecvGlobalShiftManager.h:32
masc::DualCloudFeature::DualCloudFeatureType
DualCloudFeatureType
Definition: DualCloudFeature.h:34
sourceCloud
ccGenericPointCloud * sourceCloud
Definition: qCanupoTools.cpp:36
masc::PointFeature::PointFeatureType
PointFeatureType
Definition: PointFeature.h:40
ccHObject
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
q3DMASCTools.h
ccObject::getName
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
ReadCloud
static bool ReadCloud(const QString &command, Tools::NamedClouds &clouds, const QDir &defaultDir, int lineNumber, FileIOFilter::LoadParameters &loadParameters)
Definition: q3DMASCTools.cpp:695
masc::ContextBasedFeature
Context-based feature.
Definition: ContextBasedFeature.h:32
masc::ContextBasedFeature::ToString
static QString ToString(ContextBasedFeatureType type)
Definition: ContextBasedFeature.h:38
masc::Tools::LoadTrainingFile
static bool LoadTrainingFile(QString filename, Feature::Set &rawFeatures, std::vector< double > &scales, NamedClouds &loadedClouds, TrainParameters &parameters, CorePoints *corePoints=nullptr, QWidget *parent=nullptr)
Definition: q3DMASCTools.cpp:971
masc::RandomTreesParams::minSampleCount
int minSampleCount
Definition: Parameters.h:31
cloudViewer::NormalizedProgress
Definition: GenericProgressCallback.h:78
PointCoordinateType
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
masc::Feature::MULTIPLY
@ MULTIPLY
Definition: FeaturesInterface.h:95
masc::ContextBasedFeature::Shared
QSharedPointer< ContextBasedFeature > Shared
Definition: ContextBasedFeature.h:34
masc::Classifier::toFile
bool toFile(QString filename, QWidget *parentWidget=nullptr) const
Saves the classifier to file.
Definition: q3DMASCClassifier.cpp:704
corePoints
cloudViewer::GenericIndexedCloud * corePoints
Definition: qCanupoTools.cpp:35
CC_FERR_NO_ERROR
@ CC_FERR_NO_ERROR
Definition: FileIOFilter.h:21
cloudViewer::ReferenceCloud::getAssociatedCloud
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
Definition: ReferenceCloud.h:206
ecvPointCloud.h
cloudViewer::DgmOctree::findBestLevelForAGivenNeighbourhoodSizeExtraction
unsigned char findBestLevelForAGivenNeighbourhoodSizeExtraction(PointCoordinateType radius) const
Definition: DgmOctree.cpp:2664
FileIOFilter::LoadParameters::coordinatesShiftEnabled
bool * coordinatesShiftEnabled
Whether shift on load has been applied after loading (optional)
Definition: FileIOFilter.h:69
masc::RandomTreesParams::maxDepth
int maxDepth
Definition: Parameters.h:29
DualCloudFeature.h
masc::PointFeature::FromUpperString
static PointFeatureType FromUpperString(const QString &token)
Definition: PointFeature.h:107
cloudViewer::DgmOctree::getTheCellPosWhichIncludesThePoint
void getTheCellPosWhichIncludesThePoint(const CCVector3 *thePoint, Tuple3i &cellPos) const
Definition: DgmOctree.h:779