ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PointFeature.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 "ScalarFieldWrappers.h"
30 
31 // Qt
32 #include <QSharedPointer>
33 
34 namespace masc {
36 struct PointFeature : public Feature {
37 public: // PointFeatureType
38  typedef QSharedPointer<PointFeature> Shared;
39 
41  Invalid = 0,
43  X,
44  Y,
45  Z,
49  R,
50  G,
51  B,
52  NIR,
53  Dip,
56  PCV,
57  SF
58  };
59 
60  static QString ToString(PointFeatureType type) {
61  switch (type) {
62  case Invalid:
63  return "Invalid";
64  case Intensity:
65  return "INT";
66  case X:
67  return "X";
68  case Y:
69  return "Y";
70  case Z:
71  return "Z";
72  case NbRet:
73  return "NbRet";
74  case RetNb:
75  return "RetNb";
76  case EchoRat:
77  return "EchoRat";
78  case R:
79  return "R";
80  case G:
81  return "G";
82  case B:
83  return "B";
84  case NIR:
85  return "NIR";
86  case Dip:
87  return "NormDip";
88  case DipDir:
89  return "NormDipDir";
90  case M3C2:
91  return "M3C2";
92  case PCV:
93  return "PCV";
94  case SF:
95  return "SF";
96  default:
97  assert(false);
98  break;
99  }
100  return "Invalid";
101  }
102 
103  static inline PointFeatureType FromString(const QString& token) {
104  return FromUpperString(token.toUpper());
105  }
106 
107  static PointFeatureType FromUpperString(const QString& token) {
108  if (token == "INT")
109  return Intensity;
110  else if (token == "X")
111  return X;
112  else if (token == "Y")
113  return Y;
114  else if (token == "Z")
115  return Z;
116  else if (token == "NBRET")
117  return NbRet;
118  else if (token == "RETNB")
119  return RetNb;
120  else if (token == "ECHORAT")
121  return EchoRat;
122  else if (token == "R")
123  return R;
124  else if (token == "G")
125  return G;
126  else if (token == "B")
127  return B;
128  else if (token == "NIR")
129  return NIR;
130  else if (token == "NORMDIP")
131  return Dip;
132  else if (token == "NORMDIPDIR")
133  return DipDir;
134  else if (token == "M3C2")
135  return M3C2;
136  else if (token == "PCV")
137  return PCV;
138  else if (token.startsWith("SF"))
139  return SF;
140 
141  return Invalid;
142  }
143 
144 public: // methods
147  : type(p_type),
148  sourceSFIndex(-1),
149  field1(nullptr),
150  field2(nullptr),
151  statSF1(nullptr),
152  statSF2(nullptr) {
153  // auomatically set the right source for specific features
154  switch (type) {
155  case X:
156  source = {Source::DimX, "X"};
157  break;
158  case Y:
159  source = {Source::DimY, "Y"};
160  break;
161  case Z:
162  source = {Source::DimZ, "Z"};
163  break;
164  case R:
165  source = {Source::Red, "Red"};
166  break;
167  case G:
168  source = {Source::Green, "Green"};
169  break;
170  case B:
171  source = {Source::Blue, "Blue"};
172  break;
173  default:
175  QString()}; // source name --> TBD later
176  break;
177  }
178  }
179 
181  ~PointFeature() override {}
182 
183  // inherited from Feature
184  virtual Type getType() const override { return Type::PointFeature; }
185  virtual Feature::Shared clone() const override {
186  return Feature::Shared(new PointFeature(*this));
187  }
188  virtual bool prepare(
189  const CorePoints& corePoints,
190  QString& error,
191  cloudViewer::GenericProgressCallback* progressCb = nullptr,
192  SFCollector* generatedScalarFields = nullptr) override;
193  virtual bool finish(const CorePoints& corePoints, QString& error) override;
194  virtual bool checkValidity(QString corePointRole,
195  QString& error) const override;
196  virtual QString toString() const override;
197 
200  bool computeStat(
201  const cloudViewer::DgmOctree::NeighboursSet& pointsInNeighbourhood,
202  const IScalarFieldWrapper::Shared& sourceField,
203  double& outputValue) const;
204 
205 protected: // methods
208  QString& error);
209 
210 public: // members
212 
215 
218 
221 
224 
228 };
229 } // namespace masc
QSharedPointer< IScalarFieldWrapper > Shared
SF collector.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
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
Core points descriptor.
Definition: CorePoints.h:39
Generic feature descriptor.
QSharedPointer< Feature > Shared
Shared type.
Type
Feature type.
Point feature.
Definition: PointFeature.h:36
bool computeStat(const cloudViewer::DgmOctree::NeighboursSet &pointsInNeighbourhood, const IScalarFieldWrapper::Shared &sourceField, double &outputValue) const
IScalarFieldWrapper::Shared field1
First cloud 'source' field.
Definition: PointFeature.h:220
static PointFeatureType FromString(const QString &token)
Definition: PointFeature.h:103
virtual Type getType() const override
Returns the type (must be reimplemented by child struct)
Definition: PointFeature.h:184
virtual bool checkValidity(QString corePointRole, QString &error) const override
Checks the feature definition validity.
static QString ToString(PointFeatureType type)
Definition: PointFeature.h:60
PointFeatureType type
Point feature type.
Definition: PointFeature.h:214
cloudViewer::ScalarField * statSF1
For scaled features.
Definition: PointFeature.h:226
cloudViewer::ScalarField * statSF2
Definition: PointFeature.h:227
~PointFeature() override
Destructor.
Definition: PointFeature.h:181
virtual bool finish(const CorePoints &corePoints, QString &error) override
Finishes the feature preparation (update the scalar field, etc.)
virtual QString toString() const override
Returns the formatted description.
virtual Feature::Shared clone() const override
Clones this feature.
Definition: PointFeature.h:185
virtual bool prepare(const CorePoints &corePoints, QString &error, cloudViewer::GenericProgressCallback *progressCb=nullptr, SFCollector *generatedScalarFields=nullptr) override
Prepares the feature (compute the scalar field, etc.)
PointFeature(PointFeatureType p_type)
Default constructor.
Definition: PointFeature.h:146
static PointFeatureType FromUpperString(const QString &token)
Definition: PointFeature.h:107
QSharedPointer< PointFeature > Shared
Definition: PointFeature.h:38
IScalarFieldWrapper::Shared retrieveField(ccPointCloud *cloud, QString &error)
Returns the 'source' field from a given cloud.
IScalarFieldWrapper::Shared field2
Second cloud 'source' field (if any)
Definition: PointFeature.h:223
int sourceSFIndex
Source scalar field index (if the feature source is 'ScalarField')
Definition: PointFeature.h:217