ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qCanupoTools.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 // Local
11 #include "classifier.h"
12 
13 // cloudViewer
14 #include <DgmOctree.h>
15 #include <GenericIndexedCloud.h>
17 
18 // Qt
19 #include <QString>
20 
21 // system
22 #include <vector>
23 
25 class ccPointCloud;
27 class ccHObject;
28 class QComboBox;
29 class ccScalarField;
30 
32 template <unsigned Count>
33 struct CosSinTable {
34  float cosines[Count];
35  float sines[Count];
36 
38  for (int i = 0; i < Count; ++i) {
39  cosines[i] = static_cast<float>(cos(M_PI * i / Count));
40  sines[i] = static_cast<float>(sin(M_PI * i / Count));
41  }
42  }
43 };
44 
46 class qCanupoTools {
47 public:
49  template <typename T>
50  static bool Fpeq(T a, T b, T epsilon = static_cast<T>(1.0e-6)) {
51  if (b == 0) return fabs(a) < epsilon;
52 
53  return fabs(a / b - 1) <= epsilon;
54  }
55 
57 
60  static bool CompareVectors(const std::vector<float>& first,
61  const std::vector<float>& second);
62 
64 
66  static size_t TestVectorsOverlap(const std::vector<float>& first,
67  const std::vector<float>& second);
68 
70  static bool ComputeCorePointsDescriptors(
72  CorePointDescSet& corePointsDescriptors,
74  const std::vector<float>& sortedScales,
75  bool& invalidDescriptors,
76  QString& error, // if any
77  unsigned descriptorID = DESC_DIMENSIONALITY,
78  int maxThreadCount = 0,
80  cloudViewer::DgmOctree* inputOctree = 0,
81  std::vector<ccScalarField*>* roughnessSFs = 0 /*for tests*/);
82 
84  static QString GetEntityName(ccHObject* obj);
85 
88 
91  static ccPointCloud* GetCloudFromCombo(QComboBox* comboBox,
92  ccHObject* dbRoot);
93 
95  static bool TrainClassifier(
96  Classifier& classifier,
97  const CorePointDescSet& descriptors1,
98  const CorePointDescSet& descriptors2,
99  const std::vector<float>& scales,
100  ccPointCloud* mscCloud,
101  const CorePointDescSet* evaluationDescriptors = 0,
102  ecvMainAppInterface* app = 0);
103 
105 
107  struct EvalParameters {
110  : false1(0),
111  false2(0),
112  true1(0),
113  true2(0),
114  mu1(0),
115  mu2(0),
116  var1(0),
117  var2(0) {}
119  unsigned false1, false2;
121  unsigned true1, true2;
123  double ba() const {
124  unsigned n1 = true1 + false1;
125  unsigned n2 = true2 + false2;
126  double a1 =
127  (n1 ? static_cast<double>(true1) / static_cast<double>(n1)
128  : 0);
129  double a2 =
130  (n2 ? static_cast<double>(true2) / static_cast<double>(n2)
131  : 0);
132  return (a1 + a2) / 2;
133  }
134 
136  double mu1, mu2;
138  double var1, var2;
140  double fdr() const {
141  double v = var1 + var2;
142  return v != 0 ? (mu1 - mu2) * (mu1 - mu2) / v : 0;
143  }
144  };
145 
147  static bool EvaluateClassifier(const Classifier& classifier,
148  const CorePointDescSet& descriptors1,
149  const CorePointDescSet& descriptors2,
150  const std::vector<float>& scales,
151  EvalParameters& params);
152 };
constexpr double M_PI
Pi.
Definition: CVConst.h:19
cmdLineReadable * params[]
static const unsigned DESC_DIMENSIONALITY
Classifier.
Definition: classifier.h:23
Set of (core) point descriptors.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
A scalar field associated to display-related parameters.
The octree structure used throughout the library.
Definition: DgmOctree.h:39
A generic 3D point cloud with index-based point access.
Main application interface (for plugins)
CANUPO generic tools.
Definition: qCanupoTools.h:46
static ccPointCloud * GetCloudFromCombo(QComboBox *comboBox, ccHObject *dbRoot)
static bool EvaluateClassifier(const Classifier &classifier, const CorePointDescSet &descriptors1, const CorePointDescSet &descriptors2, const std::vector< float > &scales, EvalParameters &params)
Evaluates a classifier.
static size_t TestVectorsOverlap(const std::vector< float > &first, const std::vector< float > &second)
Tests whether a vector contains the values of another one (at the end!)
static bool CompareVectors(const std::vector< float > &first, const std::vector< float > &second)
Compares two vectors.
static bool ComputeCorePointsDescriptors(cloudViewer::GenericIndexedCloud *corePoints, CorePointDescSet &corePointsDescriptors, ccGenericPointCloud *sourceCloud, const std::vector< float > &sortedScales, bool &invalidDescriptors, QString &error, unsigned descriptorID=DESC_DIMENSIONALITY, int maxThreadCount=0, cloudViewer::GenericProgressCallback *progressCb=0, cloudViewer::DgmOctree *inputOctree=0, std::vector< ccScalarField * > *roughnessSFs=0)
Computes the 'descriptors' for various scales on core points only.
static bool Fpeq(T a, T b, T epsilon=static_cast< T >(1.0e-6))
Returns whether two numbers are almost equal or not.
Definition: qCanupoTools.h:50
static bool TrainClassifier(Classifier &classifier, const CorePointDescSet &descriptors1, const CorePointDescSet &descriptors2, const std::vector< float > &scales, ccPointCloud *mscCloud, const CorePointDescSet *evaluationDescriptors=0, ecvMainAppInterface *app=0)
Trains a classifier.
static QString GetEntityName(ccHObject *obj)
Returns a long description of a given entity (name + [ID])
__host__ __device__ float2 fabs(float2 v)
Definition: cutil_math.h:1254
static void error(char *msg)
Definition: lsd.c:159
std::vector< ccScalarField * > * roughnessSFs
bool invalidDescriptors
cloudViewer::GenericIndexedCloud * corePoints
ccGenericPointCloud * sourceCloud
Helper: pre-computed cos and sin values between 0 and Pi.
Definition: qCanupoTools.h:33
float sines[Count]
Definition: qCanupoTools.h:35
float cosines[Count]
Definition: qCanupoTools.h:34
Classifer evaluation parameters.
Definition: qCanupoTools.h:107
double mu1
Mean distance to boundary line.
Definition: qCanupoTools.h:136
EvalParameters()
Default constructor.
Definition: qCanupoTools.h:109
double var1
Variance to boundary line.
Definition: qCanupoTools.h:138
unsigned false1
Falsely positive.
Definition: qCanupoTools.h:119
double fdr() const
Fisher Discriminant Ratio.
Definition: qCanupoTools.h:140
double ba() const
Balanced accuracy.
Definition: qCanupoTools.h:123
unsigned true1
Truly positive.
Definition: qCanupoTools.h:121