ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ContextBasedFeature.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 
30 namespace masc {
32 struct ContextBasedFeature : public Feature {
33 public: // ContextBasedFeatureType
34  typedef QSharedPointer<ContextBasedFeature> Shared;
35 
37 
39  switch (type) {
40  case Invalid:
41  return "Invalid";
42  case DZ:
43  return "DZ";
44  case DH:
45  return "DH";
46  default:
47  assert(false);
48  break;
49  }
50  return "Invalid";
51  }
52 
53  static inline ContextBasedFeatureType FromString(const QString& token) {
54  return FromUpperString(token.toUpper());
55  }
56  static ContextBasedFeatureType FromUpperString(const QString& token) {
57  if (token.startsWith("DZ"))
58  return DZ;
59  else if (token.startsWith("DH"))
60  return DH;
61 
62  return Invalid;
63  }
64 
65 public: // methods
69  int p_kNN = 1,
70  double p_scale = std::numeric_limits<double>::quiet_NaN(),
71  int p_ctxClassLabel = 0)
72  : type(p_type),
73  kNN(p_kNN),
74  ctxClassLabel(p_ctxClassLabel),
75  sf(nullptr) {
76  scale = p_scale;
77  }
78 
79  // inherited from Feature
80  virtual Type getType() const override { return Type::ContextBasedFeature; }
81  virtual Feature::Shared clone() const override {
82  return Feature::Shared(new ContextBasedFeature(*this));
83  }
84  virtual bool prepare(
85  const CorePoints& corePoints,
86  QString& error,
87  cloudViewer::GenericProgressCallback* progressCb = nullptr,
88  SFCollector* generatedScalarFields = nullptr) override;
89  virtual bool finish(const CorePoints& corePoints, QString& error) override;
90  virtual bool checkValidity(QString corePointRole,
91  QString& error) const override;
92  virtual QString toString() const override;
93 
95  bool computeValue(
96  cloudViewer::DgmOctree::NeighboursSet& pointsInNeighbourhood,
97  const CCVector3& queryPoint,
98  ScalarType& outputValue) const;
99 
100 public: // members
102 
105 
106  // Number of neighbors
107  int kNN;
112 };
113 } // namespace masc
ccGenericPointCloud::computeOctree
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
Definition: ecvGenericPointCloud.cpp:124
masc::ContextBasedFeature::type
ContextBasedFeatureType type
Neighborhood feature type.
Definition: ContextBasedFeature.h:104
masc::Feature::Shared
QSharedPointer< Feature > Shared
Shared type.
Definition: FeaturesInterface.h:49
masc::ContextBasedFeature::checkValidity
virtual bool checkValidity(QString corePointRole, QString &error) const override
Checks the feature definition validity.
Definition: ContextBasedFeature.cpp:25
octreeLevel
unsigned char octreeLevel
Definition: qCanupoTools.cpp:38
cloudViewer::NormalizedProgress::oneStep
bool oneStep()
Increments total progress value of a single unit.
Definition: NormalizedProgress.cpp:99
masc
3DMASC classifier
Definition: ContextBasedFeature.h:30
Tuple3Tpl::x
Type x
Definition: CVGeom.h:137
FeaturesInterface.h
cloudViewer::GenericCloud::size
virtual unsigned size() const =0
Returns the number of points.
cloudViewer::ScalarField::computeMinAndMax
virtual void computeMinAndMax()
Determines the min and max values.
Definition: ScalarField.h:123
masc::ContextBasedFeature::DH
@ DH
Definition: ContextBasedFeature.h:36
cloudViewer::ScalarField::getValue
ScalarType & getValue(std::size_t index)
Definition: ScalarField.h:92
masc::ContextBasedFeature::FromString
static ContextBasedFeatureType FromString(const QString &token)
Definition: ContextBasedFeature.h:53
masc::Feature::source
Source source
Definition: FeaturesInterface.h:235
nProgress
cloudViewer::NormalizedProgress * nProgress
Definition: qCanupoTools.cpp:42
cloudViewer::PointCloudTpl::setCurrentOutScalarField
void setCurrentOutScalarField(int index)
Sets the OUTPUT scalar field.
Definition: PointCloudTpl.h:421
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
cloudViewer::PointCloudTpl::getPoint
const CCVector3 * getPoint(unsigned index) const override
Definition: PointCloudTpl.h:143
cloudViewer::ReferenceCloud::getPoint
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
Definition: ReferenceCloud.h:79
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
cloudViewer::ScalarField
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
cloudViewer::GenericProgressCallback::stop
virtual void stop()=0
Notifies the fact that the process has ended.
cloudViewer::GenericProgressCallback::setMethodTitle
virtual void setMethodTitle(const char *methodTitle)=0
Notifies the algorithm title.
masc::ContextBasedFeature::computeValue
bool computeValue(cloudViewer::DgmOctree::NeighboursSet &pointsInNeighbourhood, const CCVector3 &queryPoint, ScalarType &outputValue) const
Compute the feature value on a set of points.
Definition: ContextBasedFeature.cpp:284
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::ContextBasedFeature::ContextBasedFeatureType
ContextBasedFeatureType
Definition: ContextBasedFeature.h:36
cloudViewer::DgmOctree::MAX_OCTREE_LEVEL
static const int MAX_OCTREE_LEVEL
Max octree subdivision level.
Definition: DgmOctree.h:67
ccOctree::Shared
QSharedPointer< ccOctree > Shared
Shared pointer.
Definition: ecvOctree.h:32
masc::ContextBasedFeature::DZ
@ DZ
Definition: ContextBasedFeature.h:36
masc::ContextBasedFeature::ctxClassLabel
int ctxClassLabel
Context class (label)
Definition: ContextBasedFeature.h:109
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
SFCollector::CAN_REMOVE
@ CAN_REMOVE
Definition: ScalarFieldCollector.h:44
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
Vector3Tpl< PointCoordinateType >
masc::Feature::PrepareSF
static cloudViewer::ScalarField * PrepareSF(ccPointCloud *cloud, const char *resultSFName, SFCollector *generatedScalarFields, SFCollector::Behavior behavior)
Definition: FeaturesInterface.cpp:29
cloudViewer::ScalarField::getName
const char * getName() const
Returns scalar field name.
Definition: ScalarField.h:43
ccPointCloud::reserve
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
Definition: ecvPointCloud.cpp:1452
masc::Feature::scale
double scale
Scale (diameter)
Definition: FeaturesInterface.h:230
masc::ContextBasedFeature::ContextBasedFeature
ContextBasedFeature(ContextBasedFeatureType p_type, int p_kNN=1, double p_scale=std::numeric_limits< double >::quiet_NaN(), int p_ctxClassLabel=0)
Default constructor.
Definition: ContextBasedFeature.h:67
masc::Feature::Source::name
QString name
Definition: FeaturesInterface.h:124
ecvScalarField.h
masc::ContextBasedFeature::getType
virtual Type getType() const override
Returns the type (must be reimplemented by child struct)
Definition: ContextBasedFeature.h:80
masc::Feature
Generic feature descriptor.
Definition: FeaturesInterface.h:46
masc::Feature::CheckSFExistence
static bool CheckSFExistence(ccPointCloud *cloud, const char *resultSFName)
Definition: FeaturesInterface.cpp:19
cloudViewer::PointCloudTpl::getPointScalarValue
ScalarType getPointScalarValue(unsigned pointIndex) const override
Definition: PointCloudTpl.h:134
masc::Feature::Type
Type
Feature type.
Definition: FeaturesInterface.h:56
ContextBasedFeature.h
masc::ContextBasedFeature::FromUpperString
static ContextBasedFeatureType FromUpperString(const QString &token)
Definition: ContextBasedFeature.h:56
masc::ContextBasedFeature::prepare
virtual bool prepare(const CorePoints &corePoints, QString &error, cloudViewer::GenericProgressCallback *progressCb=nullptr, SFCollector *generatedScalarFields=nullptr) override
Prepares the feature (compute the scalar field, etc.)
Definition: ContextBasedFeature.cpp:65
Tuple3Tpl::z
Type z
Definition: CVGeom.h:137
masc::ContextBasedFeature::Invalid
@ Invalid
Definition: ContextBasedFeature.h:36
masc::Feature::cloud1
ccPointCloud * cloud1
Definition: FeaturesInterface.h:232
masc::ContextBasedFeature::kNN
int kNN
Definition: ContextBasedFeature.h:107
cloudViewer::GenericIndexedCloud::getPoint
virtual const CCVector3 * getPoint(unsigned index) const =0
Returns the ith point.
cloudViewer::DgmOctree::NeighboursSet
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
Definition: DgmOctree.h:133
masc::ContextBasedFeature::sf
cloudViewer::ScalarField * sf
The computed scalar.
Definition: ContextBasedFeature.h:111
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::Type::ContextBasedFeature
@ ContextBasedFeature
masc::ContextBasedFeature::clone
virtual Feature::Shared clone() const override
Clones this feature.
Definition: ContextBasedFeature.h:81
SFCollector
SF collector.
Definition: ScalarFieldCollector.h:42
NAN_VALUE
constexpr ScalarType NAN_VALUE
NaN as a ScalarType value.
Definition: CVConst.h:76
q3DMASCTools.h
Tuple3Tpl::y
Type y
Definition: CVGeom.h:137
masc::Feature::cloud1Label
QString cloud1Label
Definition: FeaturesInterface.h:233
cloudViewer::ScalarField::setValue
void setValue(std::size_t index, ScalarType value)
Definition: ScalarField.h:96
masc::ContextBasedFeature
Context-based feature.
Definition: ContextBasedFeature.h:32
cloudViewer::PointCloudTpl::addPoint
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
Definition: PointCloudTpl.h:246
masc::ContextBasedFeature::ToString
static QString ToString(ContextBasedFeatureType type)
Definition: ContextBasedFeature.h:38
cloudViewer::NormalizedProgress
Definition: GenericProgressCallback.h:78
Tuple3Tpl::u
Type u[3]
Definition: CVGeom.h:139
masc::ContextBasedFeature::Shared
QSharedPointer< ContextBasedFeature > Shared
Definition: ContextBasedFeature.h:34
masc::Feature::checkValidity
virtual bool checkValidity(QString corePointRole, QString &error) const
Checks the feature definition validity.
Definition: FeaturesInterface.h:179
masc::Feature::sf1WasAlreadyExisting
bool sf1WasAlreadyExisting
Definition: FeaturesInterface.h:240
corePoints
cloudViewer::GenericIndexedCloud * corePoints
Definition: qCanupoTools.cpp:35
Vector3Tpl< double >::fromArray
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
masc::ContextBasedFeature::finish
virtual bool finish(const CorePoints &corePoints, QString &error) override
Finishes the feature preparation (update the scalar field, etc.)
Definition: ContextBasedFeature.cpp:323
masc::ContextBasedFeature::toString
virtual QString toString() const override
Returns the formatted description.
Definition: ContextBasedFeature.cpp:350
cloudViewer::DgmOctree::PointDescriptor
Structure used during nearest neighbour search.
Definition: DgmOctree.h:101
masc::Feature::scaled
bool scaled() const
Returns whether the feature has an associated scale.
Definition: FeaturesInterface.h:176