CCCoreLib 31 May 2022
CloudCompare Core algorithms
|
Several entity-to-entity distances computation algorithms (cloud-cloud, cloud-mesh, point-triangle, etc.) More...
#include <DistanceComputationTools.h>
Classes | |
struct | Cloud2CloudDistancesComputationParams |
Cloud-to-cloud 'nearest neighbors' distances computation parameters. More... | |
struct | Cloud2MeshDistancesComputationParams |
Cloud-to-mesh distances computation parameters. More... | |
Public Types | |
enum | ERROR_MEASURES { RMS , MAX_DIST_68_PERCENT , MAX_DIST_95_PERCENT , MAX_DIST_99_PERCENT , MAX_DIST } |
Error estimators. More... | |
enum | DISTANCE_COMPUTATION_RESULTS { CANCELED_BY_USER = -1000 , ERROR_NULL_COMPAREDCLOUD , ERROR_NULL_COMPAREDOCTREE , ERROR_OUT_OF_MEMORY , ERROR_ENABLE_SCALAR_FIELD_FAILURE , ERROR_EMPTY_COMPAREDCLOUD , ERROR_NULL_REFERENCECLOUD , ERROR_EMPTY_REFERENCECLOUD , ERROR_NULL_REFERENCEMESH , ERROR_EMPTY_REFERENCEMESH , ERROR_NULL_REFERENCEPOLYLINE , ERROR_TOOSMALL_REFERENCEPOLYLINE , NULL_PLANE_EQUATION , ERROR_NULL_OCTREE , ERROR_INVALID_OCTREE_AND_MESH_INTERSECTION , ERROR_OCTREE_AND_MESH_INTERSECTION_MISMATCH , ERROR_CANT_USE_MAX_SEARCH_DIST_AND_CLOSEST_POINT_SET , ERROR_EXECUTE_FUNCTION_FOR_ALL_CELLS_AT_LEVEL_FAILURE , ERROR_EXECUTE_GET_POINTS_IN_CELL_BY_INDEX_FAILURE , ERROR_EXECUTE_CLOUD_MESH_DIST_CELL_FUNC_MT_FAILURE , ERROR_GET_CELL_CODES_FAILURE , ERROR_GET_CELL_CODES_AND_INDEXES_FAILURE , ERROR_GET_CELL_INDEXES_FAILURE , ERROR_PROPAGATE_DISTANCE_FAILURE , ERROR_SEED_POINT_INDEX_GREATER_THAN_COMPAREDCLOUD_SIZE , ERROR_INIT_DISTANCE_TRANSFORM_GRID_FAILURE , ERROR_INIT_PER_CELL_TRIANGLE_LIST_FAILURE , ERROR_INTERSECT_MESH_WITH_OCTREE_FAILURE , ERROR_COMPUTE_CLOUD2_MESH_DISTANCE_WITH_OCTREE_FAILURE , ERROR_COMPUTE_CLOUD2_CLOUD_DISTANCE_FAILURE , ERROR_OCTREE_LEVEL_LT_ONE , ERROR_OCTREE_LEVEL_GT_MAX_OCTREE_LEVEL , ERROR_SYNCHRONIZE_OCTREES_FAILURE , ERROR_PLANE_NORMAL_LT_ZERO , ERROR_INVALID_PRIMITIVE_DIMENSIONS , ERROR_CONE_R1_LT_CONE_R2 , ERROR_CONELENGTH_ZERO , ERROR_COULDNOT_SYNCRONIZE_OCTREES , ERROR_BUILD_OCTREE_FAILURE , ERROR_BUILD_FAST_MARCHING_FAILURE , ERROR_UNKOWN_ERRORMEASURES_TYPE , INVALID_INPUT , SUCCESS = 1 } |
Error codes returned by the distance computation methods. | |
enum | SOReturnCode { EMPTY_CLOUD , SYNCHRONIZED , DISJOINT , OUT_OF_MEMORY } |
Return codes for DistanceComputationTools::synchronizeOctrees. | |
Static Public Member Functions | |
static int | computeCloud2CloudDistances (GenericIndexedCloudPersist *comparedCloud, GenericIndexedCloudPersist *referenceCloud, Cloud2CloudDistancesComputationParams ¶ms, GenericProgressCallback *progressCb=nullptr, DgmOctree *compOctree=nullptr, DgmOctree *refOctree=nullptr) |
Computes the 'nearest neighbor' distances between two point clouds (formerly named "Hausdorff distance") More... | |
static int | computeCloud2MeshDistances (GenericIndexedCloudPersist *pointCloud, GenericIndexedMesh *mesh, Cloud2MeshDistancesComputationParams ¶ms, GenericProgressCallback *progressCb=nullptr, DgmOctree *cloudOctree=nullptr) |
Computes the distances between a point cloud and a mesh. More... | |
static int | computeCloud2MeshDistancesWithOctree (const DgmOctree *octree, const GridAndMeshIntersection &intersection, Cloud2MeshDistancesComputationParams ¶ms, GenericProgressCallback *progressCb=nullptr) |
Computes the distances between a point cloud and a mesh projected into a grid structure. More... | |
static int | computePoint2MeshDistancesWithOctree (const CCVector3 &P, ScalarType &distance, const GridAndMeshIntersection &intersection, Cloud2MeshDistancesComputationParams ¶ms) |
Computes the distances between a point and a mesh projected into a grid structure. More... | |
static int | computeApproxCloud2CloudDistance (GenericIndexedCloudPersist *comparedCloud, GenericIndexedCloudPersist *referenceCloud, unsigned char octreeLevel, PointCoordinateType maxSearchDist=0, GenericProgressCallback *progressCb=nullptr, DgmOctree *compOctree=nullptr, DgmOctree *refOctree=nullptr) |
Computes approximate distances between two point clouds. More... | |
static ScalarType | computePoint2TriangleDistance (const CCVector3 *P, const GenericTriangle *theTriangle, bool signedDistances, CCVector3 *nearestP=nullptr) |
Computes the distance between a point and a triangle. More... | |
static ScalarType | computePoint2PlaneDistance (const CCVector3 *P, const PointCoordinateType *planeEquation) |
Computes the (signed) distance between a point and a plane. More... | |
static ScalarType | computePoint2LineSegmentDistSquared (const CCVector3 *point, const CCVector3 *start, const CCVector3 *end) |
Computes the squared distance between a point and a line segment. More... | |
static int | computeCloud2ConeEquation (GenericIndexedCloudPersist *cloud, const CCVector3 &coneP1, const CCVector3 &coneP2, const PointCoordinateType coneR1, const PointCoordinateType coneR2, bool signedDistances=true, bool solutionType=false, double *rms=nullptr) |
Computes the distance between each point in a cloud and a cone. More... | |
static int | computeCloud2CylinderEquation (GenericIndexedCloudPersist *cloud, const CCVector3 &cylinderP1, const CCVector3 &cylinderP2, const PointCoordinateType cylinderRadius, bool signedDistances=true, bool solutionType=false, double *rms=nullptr) |
Computes the distance between each point in a cloud and a cylinder. More... | |
static int | computeCloud2SphereEquation (GenericIndexedCloudPersist *cloud, const CCVector3 &sphereCenter, const PointCoordinateType sphereRadius, bool signedDistances=true, double *rms=nullptr) |
Computes the distance between each point in a cloud and a sphere. More... | |
static int | computeCloud2PlaneEquation (GenericIndexedCloudPersist *cloud, const PointCoordinateType *planeEquation, bool signedDistances=true, double *rms=nullptr) |
Computes the distance between each point in a cloud and a plane. More... | |
static int | computeCloud2RectangleEquation (GenericIndexedCloudPersist *cloud, PointCoordinateType widthX, PointCoordinateType widthY, const SquareMatrix &rotationTransform, const CCVector3 ¢er, bool signedDistances=true, double *rms=nullptr) |
Computes the distance between each point in a cloud and a rectangle. More... | |
static int | computeCloud2BoxEquation (GenericIndexedCloudPersist *cloud, const CCVector3 &boxDimensions, const SquareMatrix &rotationTransform, const CCVector3 &boxCenter, bool signedDistances=true, double *rms=nullptr) |
Computes the distance between each point in a cloud and a box. More... | |
static int | computeCloud2PolylineEquation (GenericIndexedCloudPersist *cloud, const Polyline *polyline, double *rms=nullptr) |
Computes the distance between each point in a cloud and a polyline. More... | |
static ScalarType | ComputeCloud2PlaneDistance (GenericCloud *cloud, const PointCoordinateType *planeEquation, ERROR_MEASURES measureType) |
Computes the "distance" (see ERROR_MEASURES) between a point cloud and a plane. More... | |
static ScalarType | ComputeCloud2PlaneRobustMax (GenericCloud *cloud, const PointCoordinateType *planeEquation, float percent) |
Computes the maximum distance between a point cloud and a plane. More... | |
static ScalarType | ComputeCloud2PlaneMaxDistance (GenericCloud *cloud, const PointCoordinateType *planeEquation) |
Computes the maximum distance between a point cloud and a plane. More... | |
static ScalarType | computeCloud2PlaneDistanceRMS (GenericCloud *cloud, const PointCoordinateType *planeEquation) |
Computes the Root Mean Square (RMS) distance between a cloud and a plane. More... | |
static PointCoordinateType | ComputeSquareDistToSegment (const CCVector2 &P, const CCVector2 &A, const CCVector2 &B, bool onlyOrthogonal=false) |
Returns the (squared) distance from a point to a segment. More... | |
static bool | computeGeodesicDistances (GenericIndexedCloudPersist *cloud, unsigned seedPointIndex, unsigned char octreeLevel, GenericProgressCallback *progressCb=nullptr) |
Computes geodesic distances over a point cloud "surface" (starting from a seed point) More... | |
static int | diff (GenericIndexedCloudPersist *comparedCloud, GenericIndexedCloudPersist *referenceCloud, GenericProgressCallback *progressCb=nullptr) |
Computes the differences between two scalar fields associated to equivalent point clouds. More... | |
static SOReturnCode | synchronizeOctrees (GenericIndexedCloudPersist *comparedCloud, GenericIndexedCloudPersist *referenceCloud, DgmOctree *&comparedOctree, DgmOctree *&referenceOctree, PointCoordinateType maxSearchDist=0, GenericProgressCallback *progressCb=nullptr) |
Synchronizes (and re-build if necessary) two octrees. More... | |
static bool | MultiThreadSupport () |
Returns whether multi-threading (parallel) computation is supported or not. | |
Static Protected Member Functions | |
static bool | computeCellHausdorffDistance (const DgmOctree::octreeCell &cell, void **additionalParameters, NormalizedProgress *nProgress=nullptr) |
Computes the "nearest neighbor distance" without local modeling for all points of an octree cell. More... | |
static bool | computeCellHausdorffDistanceWithLocalModel (const DgmOctree::octreeCell &cell, void **additionalParameters, NormalizedProgress *nProgress=nullptr) |
Computes the "nearest neighbor distance" with local modeling for all points of an octree cell. More... | |
Several entity-to-entity distances computation algorithms (cloud-cloud, cloud-mesh, point-triangle, etc.)
|
static |
Computes approximate distances between two point clouds.
This methods uses an exact Distance Transform to approximate the real distances. Therefore, the greater the octree level is (it is used to determine the grid step), the finer the result will be (but more memory and time will be needed).
comparedCloud | the compared cloud |
referenceCloud | the reference cloud |
octreeLevel | the octree level at which to compute the Distance Transform |
maxSearchDist | max search distance (or any negative value if no max distance is defined) |
progressCb | the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
compOctree | the pre-computed octree of the compared cloud (warning: both octrees must have the same cubical bounding-box - it is automatically computed if 0) |
refOctree | the pre-computed octree of the reference cloud (warning: both octrees must have the same cubical bounding-box - it is automatically computed if 0) |
|
staticprotected |
Computes the "nearest neighbor distance" without local modeling for all points of an octree cell.
This method has the generic syntax of a "cellular function" (see DgmOctree::localFunctionPtr). Specific parameters are transmitted via the "additionalParameters" structure. There are 3 additional parameters :
cell | structure describing the cell on which processing is applied |
additionalParameters | see method description |
nProgress | optional (normalized) progress notification (per-point) |
|
staticprotected |
Computes the "nearest neighbor distance" with local modeling for all points of an octree cell.
This method has the generic syntax of a "cellular function" (see DgmOctree::localFunctionPtr). Specific parameters are transmitted via the "additionalParameters" structure. There are 4 additional parameters :
cell | structure describing the cell on which processing is applied |
additionalParameters | see method description |
nProgress | optional (normalized) progress notification (per-point) |
|
static |
Computes the distance between each point in a cloud and a box.
[in] | cloud | a 3D point cloud |
[in] | boxDimensions | box 3D dimensions |
[in] | rotationTransform | box position in space |
[in] | boxCenter | box center point |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a box (optional) |
|
static |
Computes the 'nearest neighbor' distances between two point clouds (formerly named "Hausdorff distance")
The main algorithm and its different versions (with or without local modeling) are described in Daniel Girardeau-Montaut's PhD manuscript (Chapter 2, section 2.3). It is the standard way to compare directly two dense point clouds.
comparedCloud | the compared cloud (the distances will be computed for each point of this cloud) |
referenceCloud | the reference cloud (the nearest neigbhor will be determined among these points) |
params | distance computation parameters |
progressCb | the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
compOctree | the pre-computed octree of the compared cloud (warning: both octrees must have the same cubical bounding-box - it is automatically computed if 0) |
refOctree | the pre-computed octree of the reference cloud (warning: both octrees must have the same cubical bounding-box - it is automatically computed if 0) |
|
static |
Computes the distance between each point in a cloud and a cone.
[in] | cloud | a 3D point cloud |
[in] | coneP1 | center point associated with the larger radii |
[in] | coneP2 | center point associated with the smaller radii |
[in] | coneR1 | cone radius at coneP1 (larger) |
[in] | coneR2 | cone radius at coneP2 (smaller) |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[in] | solutionType | if true the scalar field will be set to which solution was selected 1-4 (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a cylinder (optional) |
|
static |
Computes the distance between each point in a cloud and a cylinder.
[in] | cloud | a 3D point cloud |
[in] | cylinderP1 | center bottom point |
[in] | cylinderP2 | center top point |
[in] | cylinderRadius | cylinder radius |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[in] | solutionType | if true the scalar field will be set to which solution was selected 1-4 (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a cylinder (optional) |
|
static |
Computes the distances between a point cloud and a mesh.
The algorithm, inspired from METRO by Cignoni et al., is described in Daniel Girardeau-Montaut's PhD manuscript (Chapter 2, section 2.2). It is the general way to compare a point cloud with a triangular mesh.
pointCloud | the compared cloud (the distances will be computed on these points) |
mesh | the reference mesh (the distances will be computed relatively to its triangles) |
params | distance computation parameters |
progressCb | the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
cloudOctree | the pre-computed octree of the compared cloud (warning: its bounding box should be equal to the union of both point cloud and mesh bbs and it should be cubical - it is automatically computed if 0) |
|
static |
Computes the distances between a point cloud and a mesh projected into a grid structure.
This method is used by computeCloud2MeshDistances, after intersectMeshWithOctree has been called.
octree | the cloud octree |
intersection | a specific structure corresponding the intersection of the mesh with the grid |
params | parameters |
progressCb | the client method can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
|
static |
Computes the "distance" (see ERROR_MEASURES) between a point cloud and a plane.
cloud | a point cloud |
planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' |
measureType | measure type |
|
static |
Computes the Root Mean Square (RMS) distance between a cloud and a plane.
Sums the squared distances between each point of the cloud and the plane, then computes the mean value.
cloud | a point cloud |
planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' |
|
static |
Computes the distance between each point in a cloud and a plane.
[in] | cloud | a 3D point cloud |
[in] | planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' with norm(a,bc)==1 |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a plane (optional) |
|
static |
Computes the maximum distance between a point cloud and a plane.
cloud | a point cloud |
planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' |
|
static |
Computes the maximum distance between a point cloud and a plane.
cloud | a point cloud |
planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' |
percent | percentage of lowest values ignored |
|
static |
Computes the distance between each point in a cloud and a polyline.
[in] | cloud | a 3D point cloud |
[in] | polyline | the polyline to measure to |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a plane (optional) |
|
static |
Computes the distance between each point in a cloud and a rectangle.
[in] | cloud | a 3D point cloud |
[in] | widthX | rectangle width |
[in] | widthY | rectangle height |
[in] | rotationTransform | (plane) rectangle position in space |
[in] | center | (plane) rectangle center point |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a rectangle (optional) |
|
static |
Computes the distance between each point in a cloud and a sphere.
[in] | cloud | a 3D point cloud |
[in] | sphereCenter | sphere 3d center point |
[in] | sphereRadius | sphere radius |
[in] | signedDistances | whether to compute the signed or positive (absolute) distance (optional) |
[out] | rms | will be set with the Root Mean Square (RMS) distance between a cloud and a sphere (optional) |
|
static |
Computes geodesic distances over a point cloud "surface" (starting from a seed point)
This method uses the FastMarching algorithm. Thereofre it needs an octree level as input parameter in order to create the corresponding 3D grid. The greater this level is, the finer the result will be, but more memory will be required as well. Moreover to get an interesting result the cells size should not be too small (the propagation will be stoped more easily on any encountered 'hole').
cloud | the point cloud |
seedPointIndex | the index of the point from where to start the propagation |
octreeLevel | the octree at which to perform the Fast Marching propagation |
progressCb | the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
|
static |
Computes the squared distance between a point and a line segment.
point | a 3D point |
start | the start of line segment |
end | the end of line segment |
|
static |
Computes the distances between a point and a mesh projected into a grid structure.
P | the point |
distance | the output distance |
intersection | a specific structure corresponding the intersection of the mesh with the grid |
params | parameters |
|
static |
Computes the (signed) distance between a point and a plane.
P | a 3D point |
planeEquation | plane equation: [a,b,c,d] as 'ax+by+cz=d' with norm(a,bc)==1 |
|
static |
Computes the distance between a point and a triangle.
\param P a 3D point \param theTriangle a 3D triangle \param signedDistances whether to compute the signed or positive (SQUARED) distance \param nearestP optional: returns the nearest point on the triangle \return the distance between the point and the triangle
|
static |
Returns the (squared) distance from a point to a segment.
P | 3D point |
A | first point of the segment |
B | first point of the segment |
onlyOrthogonal | computes distance only if P lies 'in front' of AB (returns -1.0 otherwise) |
|
static |
Computes the differences between two scalar fields associated to equivalent point clouds.
The compared cloud should be smaller or equal to the reference cloud. Its points should be at the same position in space as points in the other cloud. The algorithm simply computes the difference between the scalar values associated to each couple of equivalent points.
comparedCloud | the compared cloud |
referenceCloud | the reference cloud |
progressCb | the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |
|
static |
Synchronizes (and re-build if necessary) two octrees.
Initializes the octrees before computing the distance between two clouds. Check if both octree have the same sizes and limits (in 3D) and rebuild them if necessary.
comparedCloud | the cloud corresponding to the first octree |
referenceCloud | the cloud corresponding to the second octree |
comparedOctree | the first octree |
referenceOctree | the second octree |
maxSearchDist | max search distance (or any negative value if no max distance is defined) |
progressCb | the client method can get some notification of the process progress through this callback mechanism (see GenericProgressCallback) |