From 3d2205afe247f23cbe69b98845569708b4263f02 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 13:35:38 +0000 Subject: Spatial_tree_data_structure => Kd_tree_search git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1538 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 095b038d0e4c1c6d78e9aa9efe73447b65dab2b1 --- .../example/example_spatial_searching.cpp | 4 +- .../include/gudhi/Kd_tree_search.h | 276 +++++++++++++++++++++ .../include/gudhi/Spatial_tree_data_structure.h | 276 --------------------- src/Spatial_searching/test/CMakeLists.txt | 4 +- src/Spatial_searching/test/test_Kd_tree_search.cpp | 118 +++++++++ .../test/test_Spatial_tree_data_structure.cpp | 118 --------- .../include/gudhi/choose_n_farthest_points.h | 2 +- src/Subsampling/include/gudhi/sparsify_point_set.h | 4 +- 8 files changed, 401 insertions(+), 401 deletions(-) create mode 100644 src/Spatial_searching/include/gudhi/Kd_tree_search.h delete mode 100644 src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h create mode 100644 src/Spatial_searching/test/test_Kd_tree_search.cpp delete mode 100644 src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp (limited to 'src') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index ba2ea25f..7b48d055 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -14,7 +14,7 @@ int main (void) typedef typename K::Point_d Point; typedef std::vector Points; - typedef gss::Spatial_tree_data_structure Points_ds; + typedef gss::Kd_tree_search Points_ds; CGAL::Random rd; diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h new file mode 100644 index 00000000..af85915a --- /dev/null +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -0,0 +1,276 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clement Jamin + * + * Copyright (C) 2016 INRIA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUDHI_SPATIAL_TREE_DS_H_ +#define GUDHI_SPATIAL_TREE_DS_H_ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace Gudhi { +namespace spatial_searching { + + + /** + * \class Kd_tree_search Kd_tree_search.h gudhi/Kd_tree_search.h + * \brief Spatial tree data structure to perform (approximate) nearest neighbor search. + * + * \ingroup spatial_searching + * + * \details + * The class Kd_tree_search is a tree-based data structure, based on + * CGAL dD spatial searching data structures. + * It provides a simplified API to perform (approximate) nearest neighbor searches. Contrary to CGAL default behavior, the tree + * does not store the points themselves, but stores indices. + * + * There are two types of queries: the k-nearest neighbor query, where k is fixed and the k nearest points are + * computed right away, + * and the incremental nearest neighbor query, where no number of neighbors is provided during the call, as the + * neighbors will be computed incrementally when the iterator on the range is incremented. + * + * \tparam K must be a model of the SearchTraits + * concept, such as the CGAL::Epick_d class, which + * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. + * \tparam Point_range is the type of the range that provides the points. + * It must be a range whose iterator type is a `RandomAccessIterator`. + */ +template +class Kd_tree_search +{ + typedef boost::iterator_property_map< + typename Point_range::const_iterator, + CGAL::Identity_property_map > Point_property_map; + +public: + /// The kernel. + typedef K Kernel; + /// Number type used for distances. + typedef typename Kernel::FT FT; + /// The point type. + typedef typename Point_range::value_type Point; + + typedef CGAL::Search_traits< + FT, Point, + typename Kernel::Cartesian_const_iterator_d, + typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; + + typedef CGAL::Search_traits_adapter< + std::ptrdiff_t, + Point_property_map, + Traits_base> STraits; + + typedef CGAL::Orthogonal_k_neighbor_search K_neighbor_search; + typedef typename K_neighbor_search::Tree Tree; + typedef typename K_neighbor_search::Distance Distance; + /// \brief The range returned by a k-nearest neighbor search. + /// Its value type is `std::pair` where `first` is the index + /// of a point P and `second` is the squared distance between P and the query point. + typedef K_neighbor_search KNS_range; + + typedef CGAL::Orthogonal_incremental_neighbor_search< + STraits, Distance, CGAL::Sliding_midpoint, Tree> + Incremental_neighbor_search; + /// \brief The range returned by an incremental nearest neighbor search. + /// Its value type is `std::pair` where `first` is the index + /// of a point P and `second` is the squared distance between P and the query point. + typedef Incremental_neighbor_search INS_range; + + /// \brief Constructor + /// @param[in] points Const reference to the point range. This range + /// is not copied, so it should not be destroyed or modified afterwards. + Kd_tree_search(Point_range const& points) + : m_points(points), + m_tree(boost::counting_iterator(0), + boost::counting_iterator(points.size()), + typename Tree::Splitter(), + STraits(std::begin(points)) ) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + /// \brief Constructor + /// @param[in] points Const reference to the point range. This range + /// is not copied, so it should not be destroyed or modified afterwards. + /// @param[in] only_these_points Specifies the indices of the points that + /// should be actually inserted into the tree. The other points are ignored. + template + Kd_tree_search( + Point_range const& points, + Point_indices_range const& only_these_points) + : m_points(points), + m_tree( + only_these_points.begin(), only_these_points.end(), + typename Tree::Splitter(), + STraits(std::begin(points))) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + /// \brief Constructor + /// @param[in] points Const reference to the point range. This range + /// is not copied, so it should not be destroyed or modified afterwards. + /// @param[in] begin_idx, past_the_end_idx Define the subset of the points that + /// should be actually inserted into the tree. The other points are ignored. + Kd_tree_search( + Point_range const& points, + std::size_t begin_idx, std::size_t past_the_end_idx) + : m_points(points), + m_tree( + boost::counting_iterator(begin_idx), + boost::counting_iterator(past_the_end_idx), + typename Tree::Splitter(), + STraits(std::begin(point)) ) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + // Be careful, this function invalidates the tree, + // which will be recomputed at the next query + void insert(std::ptrdiff_t point_idx) + { + m_tree.insert(point_idx); + } + + /// \brief Search for the k-nearest neighbors from a query point. + /// @param[in] p The query point. + /// @param[in] k Number of nearest points to search. + /// @param[in] sorted Indicates if the computed sequence of k-nearest neighbors needs to be sorted. + /// @param[in] eps Approximation factor. + /// @return A range containing the k-nearest neighbors. + KNS_range query_k_nearest_neighbors(const + Point &p, + unsigned int k, + bool sorted = true, + FT eps = FT(0)) const + { + // Initialize the search structure, and search all N points + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + K_neighbor_search search( + m_tree, + p, + k, + eps, + true, + CGAL::Distance_adapter >( + std::begin(m_points)), + sorted); + + return search; + } + + /// \brief Search incrementally for the nearest neighbors from a query point. + /// @param[in] p The query point. + /// @param[in] eps Approximation factor. + /// @return A range containing the neighbors sorted by their distance to p. + /// All the neighbors are not computed by this function, but they will be + /// computed incrementally when the iterator on the range is incremented. + INS_range query_incremental_nearest_neighbors(const Point &p, FT eps = FT(0)) const + { + // Initialize the search structure, and search all N points + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + Incremental_neighbor_search search( + m_tree, + p, + eps, + true, + CGAL::Distance_adapter >( + std::begin(m_points)) ); + + return search; + } + + /// \brief Search for the k-farthest points from a query point. + /// @param[in] p The query point. + /// @param[in] k Number of farthest points to search. + /// @param[in] sorted Indicates if the computed sequence of k-farthest neighbors needs to be sorted. + /// @param[in] eps Approximation factor. + /// @return A range containing the k-farthest neighbors. + KNS_range query_k_farthest_neighbors(const + Point &p, + unsigned int k, + bool sorted = true, + FT eps = FT(0)) const + { + // Initialize the search structure, and search all N points + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + K_neighbor_search search( + m_tree, + p, + k, + eps, + false, + CGAL::Distance_adapter >( + std::begin(m_points)), + sorted); + + return search; + } + + /// \brief Search incrementally for the farthest neighbors from a query point. + /// @param[in] p The query point. + /// @param[in] eps Approximation factor. + /// @return A range containing the neighbors sorted by their distance to p. + /// All the neighbors are not computed by this function, but they will be + /// computed incrementally when the iterator on the range is incremented. + INS_range query_incremental_farthest_neighbors(const Point &p, FT eps = FT(0)) const + { + // Initialize the search structure, and search all N points + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + Incremental_neighbor_search search( + m_tree, + p, + eps, + false, + CGAL::Distance_adapter >( + std::begin(m_points)) ); + + return search; + } + + +private: + Point_range const& m_points; + Tree m_tree; +}; + +} // namespace spatial_searching +} // namespace Gudhi + +#endif // GUDHI_SPATIAL_TREE_DS_H_ diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h deleted file mode 100644 index 68702b22..00000000 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ /dev/null @@ -1,276 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clement Jamin - * - * Copyright (C) 2016 INRIA - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef GUDHI_SPATIAL_TREE_DS_H_ -#define GUDHI_SPATIAL_TREE_DS_H_ - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace Gudhi { -namespace spatial_searching { - - - /** - * \class Spatial_tree_data_structure Spatial_tree_data_structure.h gudhi/Spatial_tree_data_structure.h - * \brief Spatial tree data structure to perform (approximate) nearest neighbor search. - * - * \ingroup spatial_searching - * - * \details - * The class Spatial_tree_data_structure is a tree-based data structure, based on - * CGAL dD spatial searching data structures. - * It provides a simplified API to perform (approximate) nearest neighbor searches. Contrary to CGAL default behavior, the tree - * does not store the points themselves, but stores indices. - * - * There are two types of queries: the k-nearest neighbor query, where k is fixed and the k nearest points are - * computed right away, - * and the incremental nearest neighbor query, where no number of neighbors is provided during the call, as the - * neighbors will be computed incrementally when the iterator on the range is incremented. - * - * \tparam K must be a model of the SearchTraits - * concept, such as the CGAL::Epick_d class, which - * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. - * \tparam Point_range is the type of the range that provides the points. - * It must be a range whose iterator type is a `RandomAccessIterator`. - */ -template -class Spatial_tree_data_structure -{ - typedef boost::iterator_property_map< - typename Point_range::const_iterator, - CGAL::Identity_property_map > Point_property_map; - -public: - /// The kernel. - typedef K Kernel; - /// Number type used for distances. - typedef typename Kernel::FT FT; - /// The point type. - typedef typename Point_range::value_type Point; - - typedef CGAL::Search_traits< - FT, Point, - typename Kernel::Cartesian_const_iterator_d, - typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; - - typedef CGAL::Search_traits_adapter< - std::ptrdiff_t, - Point_property_map, - Traits_base> STraits; - - typedef CGAL::Orthogonal_k_neighbor_search K_neighbor_search; - typedef typename K_neighbor_search::Tree Tree; - typedef typename K_neighbor_search::Distance Distance; - /// \brief The range returned by a k-nearest neighbor search. - /// Its value type is `std::pair` where `first` is the index - /// of a point P and `second` is the squared distance between P and the query point. - typedef K_neighbor_search KNS_range; - - typedef CGAL::Orthogonal_incremental_neighbor_search< - STraits, Distance, CGAL::Sliding_midpoint, Tree> - Incremental_neighbor_search; - /// \brief The range returned by an incremental nearest neighbor search. - /// Its value type is `std::pair` where `first` is the index - /// of a point P and `second` is the squared distance between P and the query point. - typedef Incremental_neighbor_search INS_range; - - /// \brief Constructor - /// @param[in] points Const reference to the point range. This range - /// is not copied, so it should not be destroyed or modified afterwards. - Spatial_tree_data_structure(Point_range const& points) - : m_points(points), - m_tree(boost::counting_iterator(0), - boost::counting_iterator(points.size()), - typename Tree::Splitter(), - STraits(std::begin(points)) ) - { - // Build the tree now (we don't want to wait for the first query) - m_tree.build(); - } - - /// \brief Constructor - /// @param[in] points Const reference to the point range. This range - /// is not copied, so it should not be destroyed or modified afterwards. - /// @param[in] only_these_points Specifies the indices of the points that - /// should be actually inserted into the tree. The other points are ignored. - template - Spatial_tree_data_structure( - Point_range const& points, - Point_indices_range const& only_these_points) - : m_points(points), - m_tree( - only_these_points.begin(), only_these_points.end(), - typename Tree::Splitter(), - STraits(std::begin(points))) - { - // Build the tree now (we don't want to wait for the first query) - m_tree.build(); - } - - /// \brief Constructor - /// @param[in] points Const reference to the point range. This range - /// is not copied, so it should not be destroyed or modified afterwards. - /// @param[in] begin_idx, past_the_end_idx Define the subset of the points that - /// should be actually inserted into the tree. The other points are ignored. - Spatial_tree_data_structure( - Point_range const& points, - std::size_t begin_idx, std::size_t past_the_end_idx) - : m_points(points), - m_tree( - boost::counting_iterator(begin_idx), - boost::counting_iterator(past_the_end_idx), - typename Tree::Splitter(), - STraits(std::begin(point)) ) - { - // Build the tree now (we don't want to wait for the first query) - m_tree.build(); - } - - // Be careful, this function invalidates the tree, - // which will be recomputed at the next query - void insert(std::ptrdiff_t point_idx) - { - m_tree.insert(point_idx); - } - - /// \brief Search for the k-nearest neighbors from a query point. - /// @param[in] p The query point. - /// @param[in] k Number of nearest points to search. - /// @param[in] sorted Indicates if the computed sequence of k-nearest neighbors needs to be sorted. - /// @param[in] eps Approximation factor. - /// @return A range containing the k-nearest neighbors. - KNS_range query_k_nearest_neighbors(const - Point &p, - unsigned int k, - bool sorted = true, - FT eps = FT(0)) const - { - // Initialize the search structure, and search all N points - // Note that we need to pass the Distance explicitly since it needs to - // know the property map - K_neighbor_search search( - m_tree, - p, - k, - eps, - true, - CGAL::Distance_adapter >( - std::begin(m_points)), - sorted); - - return search; - } - - /// \brief Search incrementally for the nearest neighbors from a query point. - /// @param[in] p The query point. - /// @param[in] eps Approximation factor. - /// @return A range containing the neighbors sorted by their distance to p. - /// All the neighbors are not computed by this function, but they will be - /// computed incrementally when the iterator on the range is incremented. - INS_range query_incremental_nearest_neighbors(const Point &p, FT eps = FT(0)) const - { - // Initialize the search structure, and search all N points - // Note that we need to pass the Distance explicitly since it needs to - // know the property map - Incremental_neighbor_search search( - m_tree, - p, - eps, - true, - CGAL::Distance_adapter >( - std::begin(m_points)) ); - - return search; - } - - /// \brief Search for the k-farthest points from a query point. - /// @param[in] p The query point. - /// @param[in] k Number of farthest points to search. - /// @param[in] sorted Indicates if the computed sequence of k-farthest neighbors needs to be sorted. - /// @param[in] eps Approximation factor. - /// @return A range containing the k-farthest neighbors. - KNS_range query_k_farthest_neighbors(const - Point &p, - unsigned int k, - bool sorted = true, - FT eps = FT(0)) const - { - // Initialize the search structure, and search all N points - // Note that we need to pass the Distance explicitly since it needs to - // know the property map - K_neighbor_search search( - m_tree, - p, - k, - eps, - false, - CGAL::Distance_adapter >( - std::begin(m_points)), - sorted); - - return search; - } - - /// \brief Search incrementally for the farthest neighbors from a query point. - /// @param[in] p The query point. - /// @param[in] eps Approximation factor. - /// @return A range containing the neighbors sorted by their distance to p. - /// All the neighbors are not computed by this function, but they will be - /// computed incrementally when the iterator on the range is incremented. - INS_range query_incremental_farthest_neighbors(const Point &p, FT eps = FT(0)) const - { - // Initialize the search structure, and search all N points - // Note that we need to pass the Distance explicitly since it needs to - // know the property map - Incremental_neighbor_search search( - m_tree, - p, - eps, - false, - CGAL::Distance_adapter >( - std::begin(m_points)) ); - - return search; - } - - -private: - Point_range const& m_points; - Tree m_tree; -}; - -} // namespace spatial_searching -} // namespace Gudhi - -#endif // GUDHI_SPATIAL_TREE_DS_H_ diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 82c38ca5..ed61cc64 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -20,8 +20,8 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( Spatial_searching_test_Spatial_tree_data_structure test_Spatial_tree_data_structure.cpp ) - target_link_libraries(Spatial_searching_test_Spatial_tree_data_structure + add_executable( Spatial_searching_test_Kd_tree_search test_Kd_tree_search.cpp ) + target_link_libraries(Spatial_searching_test_Kd_tree_search ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Spatial_searching tests.") diff --git a/src/Spatial_searching/test/test_Kd_tree_search.cpp b/src/Spatial_searching/test/test_Kd_tree_search.cpp new file mode 100644 index 00000000..6f99b288 --- /dev/null +++ b/src/Spatial_searching/test/test_Kd_tree_search.cpp @@ -0,0 +1,118 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clement Jamin + * + * Copyright (C) 2016 INRIA Sophia-Antipolis (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Spatial_searching - test Kd_tree_search +#include + +#include + +#include +#include + +#include +#include + +BOOST_AUTO_TEST_CASE(test_Kd_tree_search) +{ + typedef CGAL::Epick_d > K; + typedef K::FT FT; + typedef K::Point_d Point; + typedef std::vector Points; + + typedef Gudhi::spatial_searching::Kd_tree_search< + K, Points> Points_ds; + + CGAL::Random rd; + + Points points; + for (int i = 0 ; i < 500 ; ++i) + points.push_back(Point(rd.get_double(-1.,1), rd.get_double(-1.,1), rd.get_double(-1.,1), rd.get_double(-1.,1))); + + Points_ds points_ds(points); + + // Test query_k_nearest_neighbors + std::size_t closest_pt_index = + points_ds.query_k_nearest_neighbors(points[10], 1, false).begin()->first; + BOOST_CHECK(closest_pt_index == 10); + + auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); + + std::vector knn_result; + FT last_dist = -1.; + for (auto const& nghb : kns_range) + { + BOOST_CHECK(nghb.second > last_dist); + knn_result.push_back(nghb.second); + last_dist = nghb.second; + } + + // Test query_incremental_nearest_neighbors + closest_pt_index = + points_ds.query_incremental_nearest_neighbors(points[10]).begin()->first; + BOOST_CHECK(closest_pt_index == 10); + + auto ins_range = points_ds.query_incremental_nearest_neighbors(points[20]); + + std::vector inn_result; + last_dist = -1.; + auto ins_it = ins_range.begin(); + for (int i = 0 ; i < 10 ; ++ins_it, ++i) + { + auto const& nghb = *ins_it; + BOOST_CHECK(nghb.second > last_dist); + inn_result.push_back(nghb.second); + last_dist = nghb.second; + } + + // Same result for KNN and INN? + BOOST_CHECK(knn_result == inn_result); + + // Test query_k_farthest_neighbors + auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); + + std::vector kfn_result; + last_dist = kfs_range.begin()->second; + for (auto const& nghb : kfs_range) + { + BOOST_CHECK(nghb.second <= last_dist); + kfn_result.push_back(nghb.second); + last_dist = nghb.second; + } + + // Test query_k_farthest_neighbors + auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[20]); + + std::vector ifn_result; + last_dist = ifs_range.begin()->second; + auto ifs_it = ifs_range.begin(); + for (int i = 0; i < 10; ++ifs_it, ++i) + { + auto const& nghb = *ifs_it; + BOOST_CHECK(nghb.second <= last_dist); + ifn_result.push_back(nghb.second); + last_dist = nghb.second; + } + + // Same result for KFN and IFN? + BOOST_CHECK(kfn_result == ifn_result); +} diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp deleted file mode 100644 index af321919..00000000 --- a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clement Jamin - * - * Copyright (C) 2016 INRIA Sophia-Antipolis (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE Spatial_searching - test Spatial_tree_data_structure -#include - -#include - -#include -#include - -#include -#include - -BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) -{ - typedef CGAL::Epick_d > K; - typedef K::FT FT; - typedef K::Point_d Point; - typedef std::vector Points; - - typedef Gudhi::spatial_searching::Spatial_tree_data_structure< - K, Points> Points_ds; - - CGAL::Random rd; - - Points points; - for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point(rd.get_double(-1.,1), rd.get_double(-1.,1), rd.get_double(-1.,1), rd.get_double(-1.,1))); - - Points_ds points_ds(points); - - // Test query_k_nearest_neighbors - std::size_t closest_pt_index = - points_ds.query_k_nearest_neighbors(points[10], 1, false).begin()->first; - BOOST_CHECK(closest_pt_index == 10); - - auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); - - std::vector knn_result; - FT last_dist = -1.; - for (auto const& nghb : kns_range) - { - BOOST_CHECK(nghb.second > last_dist); - knn_result.push_back(nghb.second); - last_dist = nghb.second; - } - - // Test query_incremental_nearest_neighbors - closest_pt_index = - points_ds.query_incremental_nearest_neighbors(points[10]).begin()->first; - BOOST_CHECK(closest_pt_index == 10); - - auto ins_range = points_ds.query_incremental_nearest_neighbors(points[20]); - - std::vector inn_result; - last_dist = -1.; - auto ins_it = ins_range.begin(); - for (int i = 0 ; i < 10 ; ++ins_it, ++i) - { - auto const& nghb = *ins_it; - BOOST_CHECK(nghb.second > last_dist); - inn_result.push_back(nghb.second); - last_dist = nghb.second; - } - - // Same result for KNN and INN? - BOOST_CHECK(knn_result == inn_result); - - // Test query_k_farthest_neighbors - auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); - - std::vector kfn_result; - last_dist = kfs_range.begin()->second; - for (auto const& nghb : kfs_range) - { - BOOST_CHECK(nghb.second <= last_dist); - kfn_result.push_back(nghb.second); - last_dist = nghb.second; - } - - // Test query_k_farthest_neighbors - auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[20]); - - std::vector ifn_result; - last_dist = ifs_range.begin()->second; - auto ifs_it = ifs_range.begin(); - for (int i = 0; i < 10; ++ifs_it, ++i) - { - auto const& nghb = *ifs_it; - BOOST_CHECK(nghb.second <= last_dist); - ifn_result.push_back(nghb.second); - last_dist = nghb.second; - } - - // Same result for KFN and IFN? - BOOST_CHECK(kfn_result == ifn_result); -} diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index b999213e..8bfb38a4 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -25,7 +25,7 @@ #include -#include +#include #include diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index ca31098b..607555b4 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -23,7 +23,7 @@ #ifndef GUDHI_SPARSIFY_POINT_SET_H #define GUDHI_SPARSIFY_POINT_SET_H -#include +#include #ifdef GUDHI_SUBSAMPLING_PROFILING #include #endif @@ -62,7 +62,7 @@ sparsify_point_set( typename Kernel::FT min_squared_dist, OutputIterator output_it) { - typedef typename Gudhi::spatial_searching::Spatial_tree_data_structure< + typedef typename Gudhi::spatial_searching::Kd_tree_search< Kernel, Point_range> Points_ds; typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); -- cgit v1.2.3