Skip to content

Commit

Permalink
Update nanoflann to version 1.5.0 (#6216)
Browse files Browse the repository at this point in the history
Fix broken nanoflann::SearchParameters
The (ignored) checks argument has been removed
Add version restriction for Nanoflann
  • Loading branch information
roehling authored Jun 30, 2023
1 parent 47f4ee9 commit f492ff5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 5 additions & 1 deletion 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ endfunction()
# If <pkg> also defines targets, use them instead and pass them via TARGETS option.
#
function(open3d_find_package_3rdparty_library name)
cmake_parse_arguments(arg "PUBLIC;HEADER;REQUIRED;QUIET" "PACKAGE;PACKAGE_VERSION_VAR" "TARGETS;INCLUDE_DIRS;LIBRARIES" ${ARGN})
cmake_parse_arguments(arg "PUBLIC;HEADER;REQUIRED;QUIET" "PACKAGE;VERSION;PACKAGE_VERSION_VAR" "TARGETS;INCLUDE_DIRS;LIBRARIES" ${ARGN})
if(arg_UNPARSED_ARGUMENTS)
message(STATUS "Unparsed: ${arg_UNPARSED_ARGUMENTS}")
message(FATAL_ERROR "Invalid syntax: open3d_find_package_3rdparty_library(${name} ${ARGN})")
Expand All @@ -281,6 +281,9 @@ function(open3d_find_package_3rdparty_library name)
set(arg_PACKAGE_VERSION_VAR "${arg_PACKAGE}_VERSION")
endif()
set(find_package_args "")
if(arg_VERSION)
list(APPEND find_package_args "${arg_VERSION}")
endif()
if(arg_REQUIRED)
list(APPEND find_package_args "REQUIRED")
endif()
Expand Down Expand Up @@ -596,6 +599,7 @@ endif()
if(USE_SYSTEM_NANOFLANN)
open3d_find_package_3rdparty_library(3rdparty_nanoflann
PACKAGE nanoflann
VERSION 1.5.0
TARGETS nanoflann::nanoflann
)
if(NOT 3rdparty_nanoflann_FOUND)
Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/nanoflann/nanoflann.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ include(ExternalProject)
ExternalProject_Add(
ext_nanoflann
PREFIX nanoflann
URL https://github.com/jlblancoc/nanoflann/archive/refs/tags/v1.3.2.tar.gz
URL_HASH SHA256=e100b5fc8d72e9426a80312d852a62c05ddefd23f17cbb22ccd8b458b11d0bea
URL https://github.com/jlblancoc/nanoflann/archive/refs/tags/v1.5.0.tar.gz
URL_HASH SHA256=89aecfef1a956ccba7e40f24561846d064f309bc547cc184af7f4426e42f8e65
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/nanoflann"
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
Expand Down
8 changes: 4 additions & 4 deletions cpp/open3d/core/nns/NanoFlannImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ void _RadiusSearchCPU(NanoFlannIndexHolderBase *holder,
std::vector<std::vector<T>> neighbors_distances(num_queries);
std::vector<uint32_t> neighbors_count(num_queries, 0);

nanoflann::SearchParams params;
nanoflann::SearchParameters params;
params.sorted = sort;

auto holder_ =
static_cast<NanoFlannIndexHolder<METRIC, T, TIndex> *>(holder);
tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_queries),
[&](const tbb::blocked_range<size_t> &r) {
std::vector<std::pair<TIndex, T>> search_result;
std::vector<nanoflann::ResultItem<TIndex, T>> search_result;
for (size_t i = r.begin(); i != r.end(); ++i) {
T radius = radii[i];
if (METRIC == L2) {
Expand Down Expand Up @@ -346,15 +346,15 @@ void _HybridSearchCPU(NanoFlannIndexHolderBase *holder,
output_allocator.AllocDistances(&distances_ptr, num_indices);
output_allocator.AllocCounts(&counts_ptr, num_queries);

nanoflann::SearchParams params;
nanoflann::SearchParameters params;
params.sorted = true;

auto holder_ =
static_cast<NanoFlannIndexHolder<METRIC, T, TIndex> *>(holder);
tbb::parallel_for(
tbb::blocked_range<size_t>(0, num_queries),
[&](const tbb::blocked_range<size_t> &r) {
std::vector<std::pair<TIndex, T>> ret_matches;
std::vector<nanoflann::ResultItem<TIndex, T>> ret_matches;
for (size_t i = r.begin(); i != r.end(); ++i) {
size_t num_results = holder_->index_->radiusSearch(
&queries[i * dimension], radius_squared,
Expand Down
12 changes: 6 additions & 6 deletions cpp/open3d/geometry/KDTreeFlann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int KDTreeFlann::SearchKNN(const T &query,
indices.resize(knn);
distance2.resize(knn);
std::vector<Eigen::Index> indices_eigen(knn);
int k = nanoflann_index_->index->knnSearch(
int k = nanoflann_index_->index_->knnSearch(
query.data(), knn, indices_eigen.data(), distance2.data());
indices.resize(k);
distance2.resize(k);
Expand All @@ -125,10 +125,10 @@ int KDTreeFlann::SearchRadius(const T &query,
size_t(query.rows()) != dimension_) {
return -1;
}
std::vector<std::pair<Eigen::Index, double>> indices_dists;
int k = nanoflann_index_->index->radiusSearch(
std::vector<nanoflann::ResultItem<Eigen::Index, double>> indices_dists;
int k = nanoflann_index_->index_->radiusSearch(
query.data(), radius * radius, indices_dists,
nanoflann::SearchParams(-1, 0.0));
nanoflann::SearchParameters(0.0));
indices.resize(k);
distance2.resize(k);
for (int i = 0; i < k; ++i) {
Expand All @@ -154,7 +154,7 @@ int KDTreeFlann::SearchHybrid(const T &query,
}
distance2.resize(max_nn);
std::vector<Eigen::Index> indices_eigen(max_nn);
int k = nanoflann_index_->index->knnSearch(
int k = nanoflann_index_->index_->knnSearch(
query.data(), max_nn, indices_eigen.data(), distance2.data());
k = std::distance(distance2.begin(),
std::lower_bound(distance2.begin(), distance2.begin() + k,
Expand All @@ -178,7 +178,7 @@ bool KDTreeFlann::SetRawData(const Eigen::Map<const Eigen::MatrixXd> &data) {
data_interface_.reset(new Eigen::Map<const Eigen::MatrixXd>(data));
nanoflann_index_.reset(
new KDTree_t(dimension_, std::cref(*data_interface_), 15));
nanoflann_index_->index->buildIndex();
nanoflann_index_->index_->buildIndex();
return true;
}

Expand Down

0 comments on commit f492ff5

Please sign in to comment.