ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RegistrationTools.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 "PointProjectionTools.h"
12 
13 namespace cloudViewer {
14 
15 class GenericProgressCallback;
16 class GenericCloud;
17 class GenericIndexedMesh;
18 class GenericIndexedCloud;
19 class KDTree;
20 class ScalarField;
21 
24 public:
27 
30  SKIP_NONE = 0,
31  SKIP_RXY = 1,
32  SKIP_RYZ = 2,
33  SKIP_RXZ = 4,
34  SKIP_ROTATION = 7,
35  SKIP_TX = 8,
36  SKIP_TY = 16,
37  SKIP_TZ = 32,
38  SKIP_TRANSLATION = 56,
39  };
40 
43 
49  static void FilterTransformation(const ScaledTransformation& inTrans,
50  int transformationFilters,
51  const CCVector3& toBeAlignedGravityCenter,
52  const CCVector3& referenceGravityCenter,
53  ScaledTransformation& outTrans);
54 
55 protected:
57 
79  static bool RegistrationProcedure(GenericCloud* P,
80  GenericCloud* X,
81  ScaledTransformation& trans,
82  bool adjustScale = false,
83  ScalarField* coupleWeights = nullptr,
84  PointCoordinateType aPrioriScale = 1.0f,
85  CCVector3* Gp = nullptr,
86  CCVector3* Gx = nullptr);
87 };
88 
90 
94 public:
97 
103  static bool FindAbsoluteOrientation(GenericCloud* lCloud,
104  GenericCloud* rCloud,
105  ScaledTransformation& trans,
106  bool fixedScale = false);
107 
109 
116  static double ComputeRMS(GenericCloud* lCloud,
117  GenericCloud* rCloud,
118  const ScaledTransformation& trans);
119 };
120 
123 public:
126  MAX_ERROR_CONVERGENCE = 0,
127  MAX_ITER_CONVERGENCE = 1,
128  };
129 
131  enum RESULT_TYPE {
132  ICP_NOTHING_TO_DO = 0,
133  ICP_APPLY_TRANSFO = 1,
134  ICP_ERROR = 100,
135  // all errors should be greater than ICP_ERROR
136  ICP_ERROR_REGISTRATION_STEP = 101,
137  ICP_ERROR_DIST_COMPUTATION = 102,
138  ICP_ERROR_NOT_ENOUGH_MEMORY = 103,
139  ICP_ERROR_CANCELED_BY_USER = 104,
140  ICP_ERROR_INVALID_INPUT = 105,
141  };
142 
145  NO_NORMAL = 0,
146  OPPOSITE_NORMALS = 1,
147  SAME_SIDE_NORMALS = 2,
148  DOUBLE_SIDED_NORMALS = 3
149  };
150 
152  struct Parameters {
154  : convType(MAX_ERROR_CONVERGENCE),
155  minRMSDecrease(1.0e-5),
156  nbMaxIterations(20),
157  adjustScale(false),
158  filterOutFarthestPoints(false),
159  samplingLimit(50000),
160  finalOverlapRatio(1.0),
161  modelWeights(nullptr),
162  dataWeights(nullptr),
163  transformationFilters(SKIP_NONE),
164  maxThreadCount(0),
165  useC2MSignedDistances(false),
166  normalsMatching(NO_NORMAL) {}
167 
170 
174 
177  unsigned nbMaxIterations;
178 
182 
186 
189  unsigned samplingLimit;
190 
194 
198 
201 
205 
208 
210 
214 
217  };
218 
220 
234  static RESULT_TYPE Register(GenericIndexedCloudPersist* modelCloud,
235  GenericIndexedMesh* modelMesh,
236  GenericIndexedCloudPersist* dataCloud,
237  const Parameters& params,
238  ScaledTransformation& totalTrans,
239  double& finalRMS,
240  unsigned& finalPointCount,
241  GenericProgressCallback* progressCb = nullptr);
242 };
243 
247 public:
249 
264  static bool RegisterClouds(GenericIndexedCloud* modelCloud,
265  GenericIndexedCloud* dataCloud,
266  ScaledTransformation& transform,
267  ScalarType delta,
268  ScalarType beta,
269  PointCoordinateType overlap,
270  unsigned nbBases,
271  unsigned nbTries,
272  GenericProgressCallback* progressCb = nullptr,
273  unsigned nbMaxCandidates = 0);
274 
275 protected:
277  struct Base {
278  unsigned a, b, c, d;
279  void init(unsigned _a, unsigned _b, unsigned _c, unsigned _d) {
280  a = _a;
281  b = _b;
282  c = _c;
283  d = _d;
284  }
285  void copy(const struct Base& b) { init(b.a, b.b, b.c, b.d); }
286  unsigned getIndex(unsigned i) {
287  if (i == 0) return a;
288  if (i == 1) return b;
289  if (i == 2) return c;
290  if (i == 3) return d;
291  return 0;
292  }
293  };
294 
296 
302  static bool FindBase(GenericIndexedCloud* cloud,
303  PointCoordinateType overlap,
304  unsigned nbTries,
305  Base& base);
306 
315  static int FindCongruentBases(KDTree* tree,
316  ScalarType delta,
317  const CCVector3* base[4],
318  std::vector<Base>& results);
319 
321 
330  static unsigned ComputeRegistrationScore(
331  KDTree* modelTree,
332  GenericIndexedCloud* dataCloud,
333  ScalarType delta,
334  const ScaledTransformation& dataToModel);
335 
337 
350  static bool LinesIntersections(const CCVector3& p0,
351  const CCVector3& p1,
352  const CCVector3& p2,
353  const CCVector3& p3,
354  CCVector3& inter,
355  PointCoordinateType& lambda,
356  PointCoordinateType& mu);
357 
372  static bool FilterCandidates(GenericIndexedCloud* modelCloud,
373  GenericIndexedCloud* dataCloud,
374  Base& reference,
375  std::vector<Base>& candidates,
376  unsigned nbMaxCandidates,
377  std::vector<ScaledTransformation>& transforms);
378 };
379 
380 } // namespace cloudViewer
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
void * X
Definition: SmallVector.cpp:45
cmdLineReadable * params[]
Empty class - for classification purpose only.
Definition: CVToolbox.h:15
A generic 3D point cloud with index-based and presistent access to points.
A generic 3D point cloud with index-based point access.
A generic mesh with index-based vertex access.
Horn point cloud registration algorithm.
ICP point cloud registration algorithm (Besl et al.).
CONVERGENCE_TYPE
Convergence control method.
NORMALS_MATCHING
Normals matching method.
Common point cloud registration algorithms.
TRANSFORMATION_FILTERS
Transformation constraints.
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
Generic file read and write utility for python interface.
flann::Index< flann::L2< float > > KDTree
void init(unsigned _a, unsigned _b, unsigned _c, unsigned _d)
CONVERGENCE_TYPE convType
Convergence type.
NORMALS_MATCHING normalsMatching
Normals matching method.
int maxThreadCount
Maximum number of threads to use (0 = max)
bool useC2MSignedDistances
Whether to compute signed C2M distances.
ScalarField * dataWeights
Weights for data points (optional)
A scaled geometrical transformation (scale + rotation + translation)