ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
KdTree.cpp
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 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <CVKdTree.h>
14 
15 namespace py = pybind11;
16 using namespace pybind11::literals;
17 
18 #include "cccorelib.h"
19 
20 void define_KdTree(py::module &cccorelib)
21 {
22 
23  py::class_<cloudViewer::KDTree> a(cccorelib, "KDTree");
24  py::bind_vector<std::vector<unsigned>>(a, "IndicesVector", py::module_local(true));
25 
26  a.def(py::init<>())
27  .def("buildFromCloud", &cloudViewer::KDTree::buildFromCloud, "cloud"_a, "progressCb"_a = nullptr)
28  .def("getAssociatedCloud",
30  py::return_value_policy::reference)
31  .def(
32  "findNearestNeighbour",
33  [](cloudViewer::KDTree &self, py::sequence &queryPoint, ScalarType maxDist)
34  {
36  point[0] = queryPoint[0].cast<PointCoordinateType>();
37  point[1] = queryPoint[1].cast<PointCoordinateType>();
38  point[2] = queryPoint[2].cast<PointCoordinateType>();
39 
40  unsigned nearestIndex{0};
41  py::object ret = py::none();
42  if (self.findNearestNeighbour(point, nearestIndex, maxDist))
43  {
44  ret = py::cast(nearestIndex);
45  }
46  return ret;
47  },
48  "queryPoint"_a,
49  "maxDist"_a)
50  .def(
51  "findNearestNeighbourWithMaxDist",
52  [](cloudViewer::KDTree &self, py::sequence &queryPoint, ScalarType maxDist)
53  {
55  point[0] = queryPoint[0].cast<PointCoordinateType>();
56  point[1] = queryPoint[1].cast<PointCoordinateType>();
57  point[2] = queryPoint[2].cast<PointCoordinateType>();
58  return self.findNearestNeighbourWithMaxDist(point, maxDist);
59  },
60  "queryPoint"_a,
61  "maxDist"_a)
62  .def(
63  "radiusSearch",
64  [](cloudViewer::KDTree &self,
65  py::sequence &queryPoint,
66  ScalarType distance,
67  ScalarType tolerance,
68  std::vector<unsigned> &points)
69  {
71  point[0] = queryPoint[0].cast<PointCoordinateType>();
72  point[1] = queryPoint[1].cast<PointCoordinateType>();
73  point[2] = queryPoint[2].cast<PointCoordinateType>();
74  return self.radiusSearch(point, distance, tolerance, points);
75  },
76  "queryPoint"_a,
77  "distance"_a,
78  "tolerance"_a,
79  "points"_a);
80 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
int points
void define_KdTree(py::module &cccorelib)
Definition: KdTree.cpp:20
GenericIndexedCloud * getAssociatedCloud() const
Gets the point cloud from which the tree has been build.
Definition: CVKdTree.h:40
bool buildFromCloud(GenericIndexedCloud *cloud, GenericProgressCallback *progressCb=nullptr)
Builds the KD-tree.
Definition: CVKdTree.cpp:23
Definition: lsd.c:149