nanoflann: 一款仅包含头文件的 C++11 库,用于近邻 (NN) 搜索和 KD 树
| Distro | Build dev | Build releases | Stable version |
|---|---|---|---|
| ROS 2 Humble (u22.04) | |
||
| ROS 2 Jazzy (u24.04) | |
||
| ROS 2 Kilted (u24.04) | |
||
| ROS 2 Lyrical (u26.04) | |
||
| ROS 2 Rolling (u26.04) | |
(Binary build badges are for amd64 and arm64, respectively)
nanoflann is a C++11 header-only library for building KD-Trees of datasets with different topologies: R2, R3 (point clouds), SO(2) and SO(3) (2D and 3D rotation groups). No support for approximate NN is provided. nanoflann does not require compiling or installing. You just need to #include <nanoflann.hpp> in your code.
This library is a fork of the flann library by Marius Muja and David G. Lowe, and born as a child project of MRPT. Following the original license terms, nanoflann is distributed under the BSD license. Please, for bugs use the issues button or fork and open a pull request.
Cite as:
@misc{blanco2014nanoflann,
title = {nanoflann: a {C}++ header-only fork of {FLANN}, a library for Nearest Neighbor ({NN}) with KD-trees},
author = {Blanco, Jose Luis and Rai, Pranjal Kumar},
howpublished = {\\url{https://github.com/jlblancoc/nanoflann}},
year = {2014}
}
See the release CHANGELOG for a list of project changes.
include/nanoflann.hpp file for use where you need it.$ sudo apt install libnanoflann-dev
nanoflann with Homebrew with:$ brew install brewsci/science/nanoflann
or$ brew tap brewsci/science
$ brew install nanoflann
MacPorts users can use:$ sudo port install nanoflann
brew install homebrew/science/nanoflannAlthough nanoflann itself doesn't have to be compiled, you can build some examples and tests with:
$ sudo apt-get install build-essential cmake libgtest-dev libeigen3-dev
$ mkdir build && cd build && cmake ..
$ make && make test
Browse the Doxygen documentation.
Important note: If L2 norms are used, notice that search radius and all passed and returned distances are actually squared distances.
knnSearch() and radiusSearch(): pointcloud_kdd_radius.cppEigen::Matrix<>: matrix_example.cppstd::vector<std::vector<T> > or std::vector<Eigen::VectorXd>: vector_of_vectors_example.cppMakefile for usage through pkg-config (for example, after doing a "make install" or after installing from Ubuntu repositories): example_with_pkgconfig/mrpt-gui, e.g. sudo apt install libmrpt-gui-dev):
Execution time efficiency:
flann library comes from the possibility of choosing between different ANN algorithms. The cost of this flexibility is the declaration of pure virtual methods which (in some circumstances) impose run-time penalties. In nanoflann all those virtual methods have been replaced by a combination of the Curiously Recurring Template Pattern (CRTP) and inlined methods, which are much faster.radiusSearch(), there is no need to make a call to determine the number of points within the radius and then call it again to get the data. By using STL containers for the output data, containers are automatically resized.nanoflann allows users to provide a precomputed bounding box of the data, if available, to avoid recomputation.int to size_t, which removes a limit when handling very large data sets.Memory efficiency: Instead of making a copy of the entire dataset into a custom flann-like matrix before building a KD-tree index, nanoflann allows direct access to your data via an adaptor interface which must be implemented in your class.
Refer to the examples below or to the C++ API of nanoflann::KDTreeSingleIndexAdaptor<> for more info.
::knnSearch()num_closest nearest neighbors to query_point[0:dim-1]. Their indices are stored inside the result object. See an example usage code.::radiusSearch()query_point[0:dim-1] within a maximum radius. The output is given as a vector of pairs, of which the first element is a point index and the second the corresponding distance. See an example usage code.::radiusSearchCustomCallback()::findWithinBox() [New in 1.8.0]: Optimized search within a given axis-aligned bound box._DistanceType defaults to the element type and must be signed, an
unsigned element type requires passing it explicitly, wide enough for the
distances of the actual coordinate range, e.g.
nanoflann::L2_Simple_Adaptor<uint8_t, MyCloud, int32_t>. To use it
through the nanoflann::metric_* tags, define your own tag:struct my_metric_L2 : public nanoflann::Metric
{
template <class T, class DataSource, typename IndexType = size_t>
struct traits
{
using distance_t = nanoflann::L2_Simple_Adaptor<T, DataSource, int32_t, IndexType>;
};
};
Eigen::Matrix<> classes (matrices and vectors-of-vectors).nanoflann::KDTreeSingleIndexDynamicAdaptor<>: the Bentley–Saxe "logarithmic forest" of static sub-trees.nanoflann::KDTreeSingleIndexIncrementalAdaptor<> [New]: a single self-balancing tree, recommended for sliding-window LiDAR-style maps. Supports incremental addPoints, lazy removePoint, and axis-aligned box trimming (removeBox / removeOutsideBox) with bounded memory under churn. See the design & benchmark report in nanoflann-benchmark/incrementalTests.nanoflann::KDTreeSingleIndexIncrementalAdaptorMT<> [New]: the same index with the large rebalancing rebuilds offloaded to a background thread, to bound the foreground update-latency tail (see the threading analysis). Disabled under NANOFLANN_NO_THREADS.暂无开放 Issues,或尚未同步最近议题。