Skip to content

Commit 025cfd6

Browse files
committed
Add Cloud2CloudDistance
1 parent 214ff25 commit 025cfd6

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

wrapper/cccorelib/src/DistanceComputationTools.cpp

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <pybind11/pybind11.h>
1919

2020
#include <DistanceComputationTools.h>
21+
#include <ReferenceCloud.h>
22+
#include <ScalarField.h>
2123

2224
namespace py = pybind11;
2325
using namespace pybind11::literals;
@@ -27,6 +29,150 @@ void define_DistanceComputationTools(py::module &cccorelib)
2729
py::class_<CCCoreLib::DistanceComputationTools> DistanceComputationTools(cccorelib,
2830
"DistanceComputationTools");
2931

32+
py::class_<CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams>(
33+
DistanceComputationTools, "Cloud2CloudDistancesComputationParams")
34+
.def(py::init<>())
35+
.def_readwrite(
36+
"octreeLevel",
37+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::octreeLevel,
38+
R"doc(
39+
Level of subdivision of the octree at witch to apply the distance computation algorithm
40+
If set to 0 (default) the algorithm will try to guess the best level automatically.
41+
)doc")
42+
.def_readwrite(
43+
"maxSearchDist",
44+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::maxSearchDist,
45+
R"doc(
46+
Maximum search distance (true distance won't be computed if greater)
47+
Set to -1 to deactivate (default).
48+
49+
Not compatible with closest point set determination (see CPSet)
50+
)doc")
51+
.def_readwrite(
52+
"multiThread",
53+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::multiThread,
54+
R"doc(
55+
Whether to use multi-thread or single thread mode
56+
57+
If maxSearchDist > 0, single thread mode will be forced.
58+
)doc")
59+
.def_readwrite(
60+
"maxThreadCount",
61+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::maxThreadCount,
62+
R"doc(
63+
Maximum number of threads to use (0 = max)
64+
)doc")
65+
.def_readwrite(
66+
"localModel",
67+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::localModel,
68+
R"doc(
69+
Type of local 3D modeling to use
70+
71+
Default: NO_MODEL. Otherwise see CC_LOCAL_MODEL_TYPES.
72+
)doc")
73+
.def_readwrite("useSphericalSearchForLocalModel",
74+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::
75+
useSphericalSearchForLocalModel,
76+
R"doc(
77+
Whether to use a fixed number of neighbors or a (sphere) radius for nearest neighbors search
78+
79+
For local models only (i.e. ignored if localModel = NO_MODEL).
80+
)doc")
81+
.def_readwrite(
82+
"kNNForLocalModel",
83+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::kNNForLocalModel,
84+
R"doc(
85+
Number of neighbors for nearest neighbors search (local model)
86+
87+
For local models only (i.e. ignored if localModel = NO_MODEL).
88+
Ignored if useSphericalSearchForLocalModel is true.
89+
)doc")
90+
.def_readwrite(
91+
"radiusForLocalModel",
92+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::radiusForLocalModel,
93+
R"doc(
94+
Radius for nearest neighbors search (local model)
95+
96+
For local models only (i.e. ignored if localModel = NO_MODEL).
97+
Ignored if useSphericalSearchForLocalModel is true.
98+
)doc")
99+
.def_readwrite("reuseExistingLocalModels",
100+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::
101+
reuseExistingLocalModels,
102+
R"doc(
103+
Whether to use an approximation for local model computation
104+
105+
For local models only (i.e. ignored if localModel = NO_MODEL).
106+
Ignored if useSphericalSearchForLocalModel is true.
107+
)doc")
108+
.def_readwrite("CPSet",
109+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::CPSet,
110+
R"doc(
111+
Container of (references to) points to store the "Closest Point Set"
112+
113+
The Closest Point Set corresponds to (the reference to) each compared point's closest neighbor.
114+
Not compatible with max search distance (see maxSearchDist)
115+
)doc")
116+
.def_property(
117+
"splitDistances",
118+
[](CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams &self) {
119+
return py::make_tuple(self.splitDistances[0], self.splitDistances[1], self.splitDistances[2]);
120+
},
121+
[](CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams &self,
122+
const py::sequence &list)
123+
{
124+
self.splitDistances[0] = list[0].cast<CCCoreLib::ScalarField *>();
125+
self.splitDistances[1] = list[1].cast<CCCoreLib::ScalarField *>();
126+
self.splitDistances[2] = list[2].cast<CCCoreLib::ScalarField *>();
127+
},
128+
R"doc(Split distances (one scalar field per dimension: X, Y and Z))doc")
129+
.def_readwrite(
130+
"resetFormerDistances",
131+
&CCCoreLib::DistanceComputationTools::Cloud2CloudDistancesComputationParams::resetFormerDistances,
132+
R"doc(
133+
Whether to keep the existing distances as is (if any) or not
134+
135+
By default, any previous distances/scalar values stored in the 'enabled' scalar field will be
136+
reset before computing them again.
137+
)doc");
138+
139+
DistanceComputationTools.def_static("computeCloud2CloudDistances",
140+
&CCCoreLib::DistanceComputationTools::computeCloud2CloudDistances,
141+
"compareCloud"_a,
142+
"referenceCloud"_a,
143+
"params"_a,
144+
"progressCb"_a = nullptr,
145+
"compOctree"_a = nullptr,
146+
"refOctree"_a = nullptr,
147+
R"doc(
148+
Computes the 'nearest neighbor' distances between two point clouds (formerly named "Hausdorff distance")
149+
150+
The main algorithm and its different versions (with or without local modeling) are described in
151+
Daniel Girardeau-Montaut's PhD manuscript (Chapter 2, section 2.3). It is the standard way to compare
152+
directly two dense point clouds.
153+
154+
The current scalar field of the compared cloud should be enabled. By default it will be reset to
155+
NAN_VALUE but one can avoid this by defining the Cloud2CloudDistancesComputationParams::resetFormerDistances
156+
parameters to false. But even in this case, only values above Cloud2CloudDistancesComputationParams::maxSearchDist
157+
will remain untouched.
158+
159+
Max search distance (Cloud2CloudDistancesComputationParams::maxSearchDist > 0) is not compatible with the
160+
determination of the Closest Point Set (Cloud2CloudDistancesComputationParams::CPSet)
161+
162+
Parameters
163+
----------
164+
comparedCloud:the compared cloud (the distances will be computed for each point of this cloud)
165+
referenceCloud: the reference cloud (the nearest neigbhor will be determined among these points)
166+
params: distance computation parameters
167+
progressCb:the client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback)
168+
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)
169+
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)
170+
171+
Returns
172+
-------
173+
0 if ok, a negative value otherwise
174+
)doc");
175+
30176
py::enum_<CCCoreLib::DistanceComputationTools::ERROR_MEASURES>(DistanceComputationTools,
31177
"ERRPOR_MEASURES")
32178
.value("RMS", CCCoreLib::DistanceComputationTools::ERROR_MEASURES::RMS)

0 commit comments

Comments
 (0)