ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
DistanceComputationTools.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 "CVConst.h"
12 #include "CVToolbox.h"
13 #include "DgmOctree.h"
14 #include "Polyline.h"
15 #include "SquareMatrix.h"
16 
17 namespace cloudViewer {
18 
19 class GenericTriangle;
20 class GenericIndexedMesh;
21 class GenericCloud;
22 class GenericIndexedCloudPersist;
23 class ReferenceCloud;
24 class PointCloud;
25 class GenericProgressCallback;
26 struct OctreeAndMeshIntersection;
27 class ScalarField;
28 
32 public: // distance to clouds or meshes
37 
40  unsigned char octreeLevel;
41 
43 
47  ScalarType maxSearchDist;
48 
50 
53 
56 
58 
61 
64 
67 
69 
72  unsigned kNNForLocalModel;
73 
75 
78  ScalarType radiusForLocalModel;
79 
81 
85 
87 
92 
94  ScalarField* splitDistances[3];
95 
97 
101 
104  : octreeLevel(0),
105  maxSearchDist(0),
106  multiThread(true),
107  maxThreadCount(0),
108  localModel(NO_MODEL),
109  useSphericalSearchForLocalModel(false),
110  kNNForLocalModel(0),
111  radiusForLocalModel(0),
112  reuseExistingLocalModels(false),
113  CPSet(nullptr),
114  resetFormerDistances(true) {
115  splitDistances[0] = splitDistances[1] = splitDistances[2] = nullptr;
116  }
117  };
118 
121 
146  static int computeCloud2CloudDistances(
147  GenericIndexedCloudPersist* comparedCloud,
148  GenericIndexedCloudPersist* referenceCloud,
149  Cloud2CloudDistancesComputationParams& params,
150  GenericProgressCallback* progressCb = nullptr,
151  DgmOctree* compOctree = nullptr,
152  DgmOctree* refOctree = nullptr);
153 
158  unsigned char octreeLevel;
159 
161 
164  ScalarType maxSearchDist;
165 
167 
172 
174 
179 
183 
187 
190 
192 
197 
200  : octreeLevel(0),
201  maxSearchDist(0),
202  useDistanceMap(false),
203  signedDistances(false),
204  flipNormals(false),
205  multiThread(true),
206  maxThreadCount(0),
207  CPSet(nullptr) {}
208  };
209 
211 
224  static int computeCloud2MeshDistances(
225  GenericIndexedCloudPersist* pointCloud,
226  GenericIndexedMesh* mesh,
227  Cloud2MeshDistancesComputationParams& params,
228  GenericProgressCallback* progressCb = nullptr,
229  DgmOctree* cloudOctree = nullptr);
230 
231 public: // approximate distances to clouds or meshes
233 
249  static int computeApproxCloud2CloudDistance(
250  GenericIndexedCloudPersist* comparedCloud,
251  GenericIndexedCloudPersist* referenceCloud,
252  unsigned char octreeLevel,
253  PointCoordinateType maxSearchDist = 0,
254  GenericProgressCallback* progressCb = nullptr,
255  DgmOctree* compOctree = nullptr,
256  DgmOctree* refOctree = nullptr);
257 
258 public: // distance to simple entities (triangles, planes, etc.)
260 
267  static ScalarType computePoint2TriangleDistance(
268  const CCVector3* P,
269  const GenericTriangle* theTriangle,
270  bool signedDist,
271  CCVector3* nearestP = nullptr);
272 
274 
278  static ScalarType computePoint2PlaneDistance(
279  const CCVector3* P, const PointCoordinateType* planeEquation);
280 
282 
287  static ScalarType computePoint2LineSegmentDistSquared(
288  const CCVector3* point,
289  const CCVector3* start,
290  const CCVector3* end);
291 
293 
305  static int computeCloud2ConeEquation(GenericIndexedCloudPersist* cloud,
306  const CCVector3& coneP1,
307  const CCVector3& coneP2,
308  const PointCoordinateType coneR1,
309  const PointCoordinateType coneR2,
310  bool signedDistances = true,
311  bool solutionType = false,
312  double* rms = nullptr);
313 
315 
326  static int computeCloud2CylinderEquation(
328  const CCVector3& cylinderP1,
329  const CCVector3& cylinderP2,
330  const PointCoordinateType cylinderRadius,
331  bool signedDistances = true,
332  bool solutionType = false,
333  double* rms = nullptr);
334 
336 
344  static int computeCloud2SphereEquation(
346  const CCVector3& sphereCenter,
347  const PointCoordinateType sphereRadius,
348  bool signedDistances = true,
349  double* rms = nullptr);
350 
352 
361  static int computeCloud2DiscEquation(GenericIndexedCloudPersist* cloud,
362  const CCVector3& discCenter,
363  const PointCoordinateType discRadius,
364  const SquareMatrix& rotationTransform,
365  bool signedDistances = true,
366  double* rms = nullptr);
367 
369 
376  static int computeCloud2PlaneEquation(
378  const PointCoordinateType* planeEquation,
379  bool signedDistances = true,
380  double* rms = nullptr);
381 
382  static int computeCloud2RectangleEquation(
384  PointCoordinateType widthX,
385  PointCoordinateType widthY,
386  const SquareMatrix& rotationTransform,
387  const CCVector3& center,
388  bool signedDist = true,
389  double* rms = nullptr);
390 
391  static int computeCloud2BoxEquation(GenericIndexedCloudPersist* cloud,
392  const CCVector3& boxDimensions,
393  const SquareMatrix& rotationTransform,
394  const CCVector3& boxCenter,
395  bool signedDist = true,
396  double* rms = nullptr);
397 
399 
405  static int computeCloud2PolylineEquation(GenericIndexedCloudPersist* cloud,
406  const Polyline* polyline,
407  double* rms = nullptr);
408 
411  RMS,
416  };
417 
419  CANCELED_BY_USER = -1000,
462  SUCCESS = 1,
463  };
464 
467 
471  static ScalarType ComputeCloud2PlaneDistance(
473  const PointCoordinateType* planeEquation,
474  ERROR_MEASURES measureType);
475 
477 
484  static ScalarType ComputeCloud2PlaneRobustMax(
485  GenericCloud* cloud,
486  const PointCoordinateType* planeEquation,
487  float percent);
488 
490 
495  static ScalarType ComputeCloud2PlaneMaxDistance(
496  GenericCloud* cloud, const PointCoordinateType* planeEquation);
497 
499 
505  static ScalarType computeCloud2PlaneDistanceRMS(
506  GenericCloud* cloud, const PointCoordinateType* planeEquation);
507 
509 
516  static PointCoordinateType ComputeSquareDistToSegment(
517  const CCVector2& P,
518  const CCVector2& A,
519  const CCVector2& B,
520  bool onlyOrthogonal = false);
521 
522 public: // other methods
525 
537  static bool computeGeodesicDistances(
539  unsigned seedPointIndex,
540  unsigned char octreeLevel,
541  GenericProgressCallback* progressCb = nullptr);
542 
545 
558  static int diff(GenericIndexedCloudPersist* comparedCloud,
559  GenericIndexedCloudPersist* referenceCloud,
560  GenericProgressCallback* progressCb = nullptr);
561 
563  enum SOReturnCode { EMPTY_CLOUD, SYNCHRONIZED, DISJOINT, OUT_OF_MEMORY };
564 
566 
576  static SOReturnCode synchronizeOctrees(
577  GenericIndexedCloudPersist* comparedCloud,
578  GenericIndexedCloudPersist* referenceCloud,
579  DgmOctree*& comparedOctree,
580  DgmOctree*& referenceOctree,
581  PointCoordinateType maxSearchDist = 0,
582  GenericProgressCallback* progressCb = nullptr);
583 
586  static bool MultiThreadSupport();
587 
588 protected:
590 
597  static int intersectMeshWithOctree(
598  OctreeAndMeshIntersection* theIntersection,
599  unsigned char octreeLevel,
600  GenericProgressCallback* progressCb = nullptr);
601 
604 
612  static int computeCloud2MeshDistanceWithOctree(
613  OctreeAndMeshIntersection* theIntersection,
614  Cloud2MeshDistancesComputationParams& params,
615  GenericProgressCallback* progressCb = nullptr);
616 
619 
628  static int computeCloud2MeshDistancesWithOctree(
629  const DgmOctree* octree,
630  OctreeAndMeshIntersection* intersection,
631  Cloud2MeshDistancesComputationParams& params,
632  GenericProgressCallback* progressCb = nullptr);
633 
636 
647  static int computePoint2MeshDistancesWithOctree(
648  const CCVector3& P,
649  ScalarType& distance,
650  OctreeAndMeshIntersection* intersection,
651  Cloud2MeshDistancesComputationParams& params);
652 
655 
665  static bool computeCellHausdorffDistance(
666  const DgmOctree::octreeCell& cell,
667  void** additionalParameters,
668  NormalizedProgress* nProgress = nullptr);
669 
672 
683  static bool computeCellHausdorffDistanceWithLocalModel(
684  const DgmOctree::octreeCell& cell,
685  void** additionalParameters,
686  NormalizedProgress* nProgress = nullptr);
687 };
688 
689 } // namespace cloudViewer
CV_LOCAL_MODEL_TYPES
Definition: CVConst.h:121
@ NO_MODEL
Definition: CVConst.h:122
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
cmdLineReadable * params[]
Empty class - for classification purpose only.
Definition: CVToolbox.h:15
The octree structure used throughout the library.
Definition: DgmOctree.h:39
SOReturnCode
Return codes for DistanceComputationTools::synchronizeOctrees.
A generic 3D point cloud with index-based and presistent access to points.
A generic mesh with index-based vertex access.
A generic triangle interface.
A simple polyline class.
Definition: Polyline.h:20
A very simple point cloud (no point duplication)
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
::ccPointCloud PointCloud
Definition: PointCloud.h:19
Generic file read and write utility for python interface.
cloudViewer::NormalizedProgress * nProgress
cloudViewer::DgmOctree * octree
unsigned char octreeLevel
Octree cell descriptor.
Definition: DgmOctree.h:354
Cloud-to-cloud "Hausdorff" distance computation parameters.
ReferenceCloud * CPSet
Container of (references to) points to store the "Closest Point Set".
ScalarType radiusForLocalModel
Radius for nearest neighbours search (local model)
bool resetFormerDistances
Whether to keep the existing distances as is (if any) or not.
bool reuseExistingLocalModels
Whether to use an approximation for local model computation.
unsigned kNNForLocalModel
Number of neighbours for nearest neighbours search (local model)
ScalarType maxSearchDist
Maximum search distance (true distance won't be computed if greater)
Definition: lsd.c:149