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
SF collector.
std::vector< PointDescriptor > NeighboursSet
A set of neighbours.
Definition: DgmOctree.h:133
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
static void error(char *msg)
Definition: lsd.c:159
3DMASC classifier
cloudViewer::GenericIndexedCloud * corePoints
Context-based feature.
virtual QString toString() const override
Returns the formatted description.
ContextBasedFeature(ContextBasedFeatureType p_type, int p_kNN=1, double p_scale=std::numeric_limits< double >::quiet_NaN(), int p_ctxClassLabel=0)
Default constructor.
cloudViewer::ScalarField * sf
The computed scalar.
virtual bool prepare(const CorePoints &corePoints, QString &error, cloudViewer::GenericProgressCallback *progressCb=nullptr, SFCollector *generatedScalarFields=nullptr) override
Prepares the feature (compute the scalar field, etc.)
bool computeValue(cloudViewer::DgmOctree::NeighboursSet &pointsInNeighbourhood, const CCVector3 &queryPoint, ScalarType &outputValue) const
Compute the feature value on a set of points.
virtual Feature::Shared clone() const override
Clones this feature.
virtual bool finish(const CorePoints &corePoints, QString &error) override
Finishes the feature preparation (update the scalar field, etc.)
static ContextBasedFeatureType FromString(const QString &token)
static QString ToString(ContextBasedFeatureType type)
ContextBasedFeatureType type
Neighborhood feature type.
static ContextBasedFeatureType FromUpperString(const QString &token)
QSharedPointer< ContextBasedFeature > Shared
int ctxClassLabel
Context class (label)
virtual bool checkValidity(QString corePointRole, QString &error) const override
Checks the feature definition validity.
virtual Type getType() const override
Returns the type (must be reimplemented by child struct)
Core points descriptor.
Definition: CorePoints.h:39
Generic feature descriptor.
QSharedPointer< Feature > Shared
Shared type.
Type
Feature type.
double scale
Scale (diameter)