From 61bc0a0443e610b851a8c1ee8bad8514ef0c894b Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 11 May 2016 15:14:27 +0000 Subject: Add Spatial_tree_data_structure git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1168 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8849698237c375d68d37dbe36f97b7b5252f5ff8 --- .../include/gudhi/Spatial_tree_data_structure.h | 169 +++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h new file mode 100644 index 00000000..48f9590b --- /dev/null +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -0,0 +1,169 @@ +/* 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 . + */ + +#ifndef GUDHI_POINT_CLOUD_H +#define GUDHI_POINT_CLOUD_H + +#include +#include +#include +#include + +#include + +#include +#include + +namespace Gudhi { + +template +class Spatial_tree_data_structure +{ +public: + typedef typename Point_container_::value_type Point; + typedef K Kernel; + typedef typename Kernel::FT FT; + + typedef CGAL::Search_traits< + FT, Point, + typename Kernel::Cartesian_const_iterator_d, + typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; + // using a pointer as a special property map type + typedef CGAL::Search_traits_adapter< + std::ptrdiff_t, Point*, 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; + typedef typename K_neighbor_search::iterator KNS_iterator; + typedef K_neighbor_search KNS_range; + + typedef CGAL::Orthogonal_incremental_neighbor_search< + STraits, Distance, CGAL::Sliding_midpoint, Tree> + Incremental_neighbor_search; + typedef typename Incremental_neighbor_search::iterator INS_iterator; + typedef Incremental_neighbor_search INS_range; + + /// Constructor + Point_cloud_data_structure(Point_container_ const& points) + : m_points(points), + m_tree(boost::counting_iterator(0), + boost::counting_iterator(points.size()), + typename Tree::Splitter(), + STraits((Point*)&(points[0])) ) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + /// Constructor + template + Point_cloud_data_structure( + Point_container_ 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((Point*)&(points[0]))) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + /// Constructor + Point_cloud_data_structure( + Point_container_ 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((Point*)&(points[0])) ) + { + // Build the tree now (we don't want to wait for the first query) + m_tree.build(); + } + + /*Point_container_ &points() + { + return m_points; + } + + const Point_container_ &points() const + { + return m_points; + }*/ + + // 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); + } + + KNS_range query_ANN(const + Point &sp, + unsigned int k, + bool sorted = true) 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, + sp, + k, + FT(0), + true, + CGAL::Distance_adapter >( + (Point*)&(m_points[0])), + sorted); + + return search; + } + + INS_range query_incremental_ANN(const Point &sp) 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, + sp, + FT(0), + true, + CGAL::Distance_adapter >( + (Point*)&(m_points[0])) ); + + return search; + } + +protected: + Point_container_ const& m_points; + Tree m_tree; +}; + +} //namespace Gudhi + +#endif // GUDHI_POINT_CLOUD_H -- cgit v1.2.3 From 571e895cf82cd28f62a42de22bfc76e17ba1cb6b Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 11 May 2016 15:41:29 +0000 Subject: Fix constructors name git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1170 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9f427883eab193b0f03f2bf63d0663a9c52f295e --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 48f9590b..b4dbbba1 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -64,7 +64,7 @@ public: typedef Incremental_neighbor_search INS_range; /// Constructor - Point_cloud_data_structure(Point_container_ const& points) + Spatial_tree_data_structure(Point_container_ const& points) : m_points(points), m_tree(boost::counting_iterator(0), boost::counting_iterator(points.size()), @@ -77,7 +77,7 @@ public: /// Constructor template - Point_cloud_data_structure( + Spatial_tree_data_structure( Point_container_ const& points, Point_indices_range const& only_these_points) : m_points(points), @@ -91,7 +91,7 @@ public: } /// Constructor - Point_cloud_data_structure( + Spatial_tree_data_structure( Point_container_ const& points, std::size_t begin_idx, std::size_t past_the_end_idx) : m_points(points), -- cgit v1.2.3 From dbe46f1faf07b6cd074881f92dfea4eb5dde38c7 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 14:01:45 +0000 Subject: Fix/add copyright git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1324 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dc76efeb44b94b3a3fc1669d8b6636759ab92383 --- .../include/gudhi/Spatial_tree_data_structure.h | 2 +- src/Subsampling/include/gudhi/Pick_random_points.h | 2 +- .../include/gudhi/choose_by_farthest_point.h | 2 +- src/Subsampling/include/gudhi/sparsify_point_set.h | 40 +++++++++++----------- .../test/test_choose_farthest_point.cpp | 22 ++++++++++++ src/Subsampling/test/test_pick_random_points.cpp | 22 ++++++++++++ src/Subsampling/test/test_sparsify_point_set.cpp | 24 +++++++++++-- 7 files changed, 88 insertions(+), 26 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index b4dbbba1..27418445 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -4,7 +4,7 @@ * * Author(s): Clement Jamin * - * Copyright (C) 2016 INRIA Sophia-Antipolis (France) + * 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 diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h index 1bc1474b..98902264 100644 --- a/src/Subsampling/include/gudhi/Pick_random_points.h +++ b/src/Subsampling/include/gudhi/Pick_random_points.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 434b5f7d..2918983f 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index d04deb60..bd7f4c56 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -1,24 +1,24 @@ /* 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 . -*/ + * (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_SPARSIFY_POINT_SET_H #define GUDHI_SPARSIFY_POINT_SET_H diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 2f83fac9..991fcbfe 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -1,3 +1,25 @@ +/* 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): Siargey Kachanovich + * + * 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 . + */ + // #ifdef _DEBUG // # define TBB_USE_THREADING_TOOL // #endif diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index a7466c9e..81c7ffdb 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -1,3 +1,25 @@ +/* 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): Siargey Kachanovich + * + * 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 . + */ + // #ifdef _DEBUG // # define TBB_USE_THREADING_TOOL // #endif diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 8e89f81a..61f6fa18 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -1,6 +1,24 @@ -// #ifdef _DEBUG -// # define TBB_USE_THREADING_TOOL -// #endif +/* 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 . + */ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE Subsampling - test sparsify_point_set -- cgit v1.2.3 From 771ed07022c60a3070439f31b60e3c964fdaba87 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 15:14:41 +0000 Subject: Add namespace git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1325 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ff3990902b381c2c2760cf6cc8c299287328e8f5 --- .../include/gudhi/Spatial_tree_data_structure.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 27418445..e633bfc0 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef GUDHI_POINT_CLOUD_H -#define GUDHI_POINT_CLOUD_H +#ifndef GUDHI_SPATIAL_TREE_DS_H_ +#define GUDHI_SPATIAL_TREE_DS_H_ #include #include @@ -34,6 +34,7 @@ #include namespace Gudhi { +namespace spatial_searching { template class Spatial_tree_data_structure @@ -164,6 +165,7 @@ protected: Tree m_tree; }; -} //namespace Gudhi +} // namespace spatial_searching +} // namespace Gudhi -#endif // GUDHI_POINT_CLOUD_H +#endif // GUDHI_SPATIAL_TREE_DS_H_ -- cgit v1.2.3 From 4ef423a7a1140f1fe1a2ce1f1bbee03990638be1 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 15:16:13 +0000 Subject: Add spatial searching test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1327 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ec003d65063981af9c6fa0dce7324d1fa879d57a --- src/Spatial_searching/test/CMakeLists.txt | 27 ++++++++ .../test/test_Spatial_tree_data_structure.cpp | 71 ++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/Spatial_searching/test/CMakeLists.txt create mode 100644 src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt new file mode 100644 index 00000000..297b6749 --- /dev/null +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 2.6) +project(Spatial_searching_tests) + +if (GCOVR_PATH) + # for gcovr to make coverage reports - Corbera Jenkins plugin + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") +endif() +if (GPROF_PATH) + # for gprof to make coverage reports - Jenkins + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") +endif() + +if(CGAL_FOUND) + find_package(Eigen3 3.1.0) + if (EIGEN3_FOUND) + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + 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 ${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.") + endif() +else() + message(WARNING "CGAL not found. It is required for the Spatial_searching tests.") +endif() diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp new file mode 100644 index 00000000..e2bb1f87 --- /dev/null +++ b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp @@ -0,0 +1,71 @@ +/* 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 +#include + +BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) +{ + typedef CGAL::Epick_d > K; + typedef K::FT FT; + typedef K::Point_d Point_d; + typedef std::vector Point_container; + + typedef Gudhi::spatial_searching::Spatial_tree_data_structure< + K, Point_container> Points_ds; + typedef typename Points_ds::KNS_range KNS_range; + typedef typename Points_ds::KNS_iterator KNS_iterator; + typedef typename Points_ds::INS_range INS_range; + typedef typename Points_ds::INS_iterator INS_iterator; + + CGAL::Random rd; + + std::vector points; + for (int i = 0 ; i < 500 ; ++i) + points.push_back(Point_d(std::array({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); + + std::size_t closest_pt_index = + points_ds.query_ANN(points[10], 1, false).begin()->first; + BOOST_CHECK(closest_pt_index == 10); + + KNS_range kns_range = points_ds.query_ANN(points[20], 10, true); + + KNS_iterator nn_it = kns_range.begin(); + FT last_dist = -1.; + for (auto const& nghb : kns_range) + { + BOOST_CHECK(nghb.second > last_dist); + last_dist = nghb.second; + } +} -- cgit v1.2.3 From e42f150700da50741b1e0d616a24a35574c1f76a Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 28 Jun 2016 16:23:14 +0000 Subject: Improve test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1350 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e1274b2283f270b10d6ee261ffe6a48f098fa7c9 --- .../test/test_Spatial_tree_data_structure.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp index e2bb1f87..916710ef 100644 --- a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp +++ b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp @@ -31,27 +31,22 @@ #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_d; - typedef std::vector Point_container; + typedef K::Point_d Point; + typedef std::vector Points; typedef Gudhi::spatial_searching::Spatial_tree_data_structure< - K, Point_container> Points_ds; - typedef typename Points_ds::KNS_range KNS_range; - typedef typename Points_ds::KNS_iterator KNS_iterator; - typedef typename Points_ds::INS_range INS_range; - typedef typename Points_ds::INS_iterator INS_iterator; + K, Points> Points_ds; CGAL::Random rd; - std::vector points; + Points points; for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point_d(std::array({rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1)}))); + points.push_back(Point(std::array({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); @@ -59,9 +54,8 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) points_ds.query_ANN(points[10], 1, false).begin()->first; BOOST_CHECK(closest_pt_index == 10); - KNS_range kns_range = points_ds.query_ANN(points[20], 10, true); + auto kns_range = points_ds.query_ANN(points[20], 10, true); - KNS_iterator nn_it = kns_range.begin(); FT last_dist = -1.; for (auto const& nghb : kns_range) { -- cgit v1.2.3 From 58bcd511da7d3c00b7a1f8ca130ba437ae6665c8 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 28 Jun 2016 16:23:35 +0000 Subject: Add example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1351 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2b99baa9a43854119a46ec8ce11b93f00ef74835 --- src/Spatial_searching/example/CMakeLists.txt | 18 +++++++++++ .../example/example_spatial_searching.cpp | 37 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/Spatial_searching/example/CMakeLists.txt create mode 100644 src/Spatial_searching/example/example_spatial_searching.cpp (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt new file mode 100644 index 00000000..0846c232 --- /dev/null +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.6) +project(Spatial_searching_examples) + +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + message(STATUS "CGAL version: ${CGAL_VERSION}.") + + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + include( ${EIGEN3_USE_FILE} ) + include_directories (BEFORE "../../include") + + add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) + else() + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.0 is required.") + endif () +else() + message(WARNING "CGAL not found. It is required for the Spatial_searching examples.") +endif() diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp new file mode 100644 index 00000000..ba387b71 --- /dev/null +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -0,0 +1,37 @@ +#include + +#include +#include + +#include +#include + +namespace gss = Gudhi::spatial_searching; + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point; + typedef std::vector Points; + + typedef gss::Spatial_tree_data_structure Points_ds; + typedef typename Points_ds::KNS_range KNS_range; + typedef typename Points_ds::KNS_iterator KNS_iterator; + typedef typename Points_ds::INS_range INS_range; + typedef typename Points_ds::INS_iterator INS_iterator; + + CGAL::Random rd; + + Points points; + for (int i = 0; i < 500; ++i) + points.push_back(Point(std::array({ 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); + + auto kns_range = points_ds.query_ANN(points[20], 10, true); + for (auto const& nghb : kns_range) + std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; + + return 0; +} -- cgit v1.2.3 From b50f6cf3469880a807554fc08695fa4d55c47758 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 29 Jun 2016 14:45:52 +0000 Subject: Intro spatial searching git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1354 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c4ec2190237102b08502ef2f07fdd6d41aed1ee7 --- .../doc/Intro_spatial_searching.h | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Spatial_searching/doc/Intro_spatial_searching.h (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/doc/Intro_spatial_searching.h b/src/Spatial_searching/doc/Intro_spatial_searching.h new file mode 100644 index 00000000..d79d6e98 --- /dev/null +++ b/src/Spatial_searching/doc/Intro_spatial_searching.h @@ -0,0 +1,58 @@ +/* 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 DOC_SPATIAL_SEARCHING_INTRO_SPATIAL_SEARCHING_H_ +#define DOC_SPATIAL_SEARCHING_INTRO_SPATIAL_SEARCHING_H_ + +// needs namespaces for Doxygen to link on classes +namespace Gudhi { +namespace spatial_searching { + +/** \defgroup spatial_searching Spatial_searching + * + * \author Clément Jamin + * + * @{ + * + * \section introduction Introduction + * + * This Gudhi component is a wrapper around + * CGAL dD spatial searching algorithms. + * 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. + * + * \section spatial_searching_examples Example + * + * This example generates 500 random points, then queries the 10 nearest points to the 20th point. + * + * \include Spatial_searching/example_spatial_searching.cpp + * + * \copyright GNU General Public License v3. + * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim + */ +/** @} */ // end defgroup spatial_searching + +} // namespace spatial_searching + +} // namespace Gudhi + +#endif // DOC_SPATIAL_SEARCHING_INTRO_SPATIAL_SEARCHING_H_ -- cgit v1.2.3 From 0a2844e38d40bebb0825f7833f14f434635628ae Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 29 Jun 2016 16:11:49 +0000 Subject: Doc + new param (epsilon) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1355 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b2e70ef17cac8ca0f9dfaab430349468b59a60f5 --- .../include/gudhi/Spatial_tree_data_structure.h | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index e633bfc0..5153720b 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -36,6 +36,26 @@ 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 represents 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. + * + * \tparam K requires a 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_container_ is the type of the container where points are stored (on the user side). + * It must provide random-access via `operator[]` and the points should be stored contiguously in memory. + * `std::vector` is a good candidate. + */ template class Spatial_tree_data_structure { @@ -126,7 +146,8 @@ public: KNS_range query_ANN(const Point &sp, unsigned int k, - bool sorted = true) const + 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 @@ -135,7 +156,7 @@ public: m_tree, sp, k, - FT(0), + eps, true, CGAL::Distance_adapter >( (Point*)&(m_points[0])), @@ -144,7 +165,7 @@ public: return search; } - INS_range query_incremental_ANN(const Point &sp) const + INS_range query_incremental_ANN(const Point &sp, 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 @@ -152,7 +173,7 @@ public: Incremental_neighbor_search search( m_tree, sp, - FT(0), + eps, true, CGAL::Distance_adapter >( (Point*)&(m_points[0])) ); -- cgit v1.2.3 From dfc61b827ae2aa7f99e2ae8401f19f6f0d219af3 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 13:31:23 +0000 Subject: Improved example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1363 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0b6e59f5c3c7c93eaed74c93f8b0284143574cd3 --- src/Spatial_searching/example/example_spatial_searching.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index ba387b71..1a807b90 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -16,10 +16,6 @@ int main (void) typedef std::vector Points; typedef gss::Spatial_tree_data_structure Points_ds; - typedef typename Points_ds::KNS_range KNS_range; - typedef typename Points_ds::KNS_iterator KNS_iterator; - typedef typename Points_ds::INS_range INS_range; - typedef typename Points_ds::INS_iterator INS_iterator; CGAL::Random rd; @@ -29,9 +25,18 @@ int main (void) Points_ds points_ds(points); + // 20-nearest neighbor query + std::cout << "20 nearest neighbors:\n"; auto kns_range = points_ds.query_ANN(points[20], 10, true); for (auto const& nghb : kns_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; + // Incremental nearest neighbor query + std::cout << "Incremental nearest neighbors:\n"; + auto ins_range = points_ds.query_incremental_ANN(points[45]); + // Get all the neighbors that are closer than 0.5 + for (auto ins_iterator = ins_range.begin(); ins_iterator->second < 0.5*0.5 ; ++ins_iterator) + std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; + return 0; } -- cgit v1.2.3 From 511c3c3d8d059d13616adfc62993a6dd8d65b26f Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 13:31:43 +0000 Subject: Doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1364 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 64b1417a243d5e36a37e29ee65182f92809f5e35 --- .../include/gudhi/Spatial_tree_data_structure.h | 50 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 5153720b..740c7861 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -44,11 +44,16 @@ namespace spatial_searching { * \ingroup spatial_searching * * \details - * The class Spatial_tree_data_structure represents 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 + * 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, and the + * neighbors will be computed incrementally when the iterator on the range is incremented. + * * \tparam K requires a CGAL::Epick_d class, which * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. @@ -62,6 +67,7 @@ class Spatial_tree_data_structure public: typedef typename Point_container_::value_type Point; typedef K Kernel; + /// Number type used for distances. typedef typename Kernel::FT FT; typedef CGAL::Search_traits< @@ -75,16 +81,22 @@ public: typedef CGAL::Orthogonal_k_neighbor_search K_neighbor_search; typedef typename K_neighbor_search::Tree Tree; typedef typename K_neighbor_search::Distance Distance; - typedef typename K_neighbor_search::iterator KNS_iterator; + /// 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; - typedef typename Incremental_neighbor_search::iterator INS_iterator; + /// 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; /// Constructor + /// @param[in] points Const reference to the point container. This container + /// is not copied, so it should not be destroyed or modified afterwards. Spatial_tree_data_structure(Point_container_ const& points) : m_points(points), m_tree(boost::counting_iterator(0), @@ -97,21 +109,29 @@ public: } /// Constructor + /// @param[in] points Const reference to the point container. This container + /// 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_container_ 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((Point*)&(points[0]))) + m_tree( + only_these_points.begin(), only_these_points.end(), + typename Tree::Splitter(), + STraits((Point*)&(points[0]))) { // Build the tree now (we don't want to wait for the first query) m_tree.build(); } /// Constructor + /// @param[in] points Const reference to the point container. This container + /// 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_container_ const& points, std::size_t begin_idx, std::size_t past_the_end_idx) @@ -143,6 +163,12 @@ public: m_tree.insert(point_idx); } + /// 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_ANN(const Point &sp, unsigned int k, @@ -165,6 +191,12 @@ public: return search; } + /// 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_ANN(const Point &sp, FT eps = FT(0)) const { // Initialize the search structure, and search all N points -- cgit v1.2.3 From cb1a6a1925f9cbcf8a82e5e1669d56d99f25b176 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 15:05:36 +0000 Subject: Update comment about example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1366 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8d5d208e36d886bd1ee76e34e6457464afccdad7 --- src/Spatial_searching/doc/Intro_spatial_searching.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/doc/Intro_spatial_searching.h b/src/Spatial_searching/doc/Intro_spatial_searching.h index d79d6e98..0a857221 100644 --- a/src/Spatial_searching/doc/Intro_spatial_searching.h +++ b/src/Spatial_searching/doc/Intro_spatial_searching.h @@ -42,7 +42,7 @@ namespace spatial_searching { * * \section spatial_searching_examples Example * - * This example generates 500 random points, then queries the 10 nearest points to the 20th point. + * This example generates 500 random points, then performs queries for nearest points using different methods. * * \include Spatial_searching/example_spatial_searching.cpp * -- cgit v1.2.3 From bb0c62817f0c253c0931214180d75d3bf5f9ac43 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 15:16:16 +0000 Subject: Doc improvements git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1367 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 70ac18899d0aaab9241ab8626a75e88906f6f843 --- .../include/gudhi/Spatial_tree_data_structure.h | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 740c7861..18fb864a 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -49,9 +49,9 @@ namespace spatial_searching { * 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 + * 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, and the + * 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 requires a Spatial_tree_data_structure( @@ -127,7 +127,7 @@ public: m_tree.build(); } - /// Constructor + /// \brief Constructor /// @param[in] points Const reference to the point container. This container /// 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 @@ -163,14 +163,14 @@ public: m_tree.insert(point_idx); } - /// Search for the k-nearest neighbors from a query point. + /// \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_ANN(const - Point &sp, + Point &p, unsigned int k, bool sorted = true, FT eps = FT(0)) const @@ -180,7 +180,7 @@ public: // know the property map K_neighbor_search search( m_tree, - sp, + p, k, eps, true, @@ -191,20 +191,20 @@ public: return search; } - /// Search incrementally for the nearest neighbors from a query point. + /// \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_ANN(const Point &sp, FT eps = FT(0)) const + INS_range query_incremental_ANN(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, - sp, + p, eps, true, CGAL::Distance_adapter >( -- cgit v1.2.3 From b2efeb519cdb43e407be5d1c0834c5cb39cc216a Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 15:48:13 +0000 Subject: Doc improvements git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1368 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a55a3d2b3c378a5a6347963b40976e50a8ee7816 --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 18fb864a..016975b8 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -81,7 +81,7 @@ public: typedef CGAL::Orthogonal_k_neighbor_search K_neighbor_search; typedef typename K_neighbor_search::Tree Tree; typedef typename K_neighbor_search::Distance Distance; - /// The range returned by a k-nearest neighbor search. + /// \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; @@ -89,7 +89,7 @@ public: typedef CGAL::Orthogonal_incremental_neighbor_search< STraits, Distance, CGAL::Sliding_midpoint, Tree> Incremental_neighbor_search; - /// The range returned by an incremental nearest 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; -- cgit v1.2.3 From 30e801f3916d62084e92828f480a0531c7995383 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 30 Jun 2016 16:17:07 +0000 Subject: More doc improvements git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1371 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4ffe114b4e56b69fccc885ea2fbb9ad883f54761 --- .../include/gudhi/Spatial_tree_data_structure.h | 4 +++- src/Subsampling/include/gudhi/sparsify_point_set.h | 25 ++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 016975b8..ca05af57 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -54,7 +54,9 @@ namespace spatial_searching { * 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 requires a 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_container_ is the type of the container where points are stored (on the user side). diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index b4536ec8..3923bf74 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -35,12 +35,25 @@ namespace Gudhi { namespace subsampling { /** -* \ingroup subsampling -* \brief Outputs a subset of the input points so that the -* squared distance between any two points -* is greater than or equal to `min_squared_dist`. -* -*/ + * \ingroup subsampling + * \brief Outputs a subset of the input points so that the + * squared distance between any two points + * is greater than or equal to `min_squared_dist`. + * + * \tparam Kernel 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 Range whose value type is Kernel::Point_d. It must provide random-access + * via `operator[]` and the points should be stored contiguously in memory. + * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d. + * + * @param[in] k A kernel object. + * @param[in] input_pts Const reference to the input points. + * @param[in] min_squared_dist Minimum squared distance separating the output points. + * @param[out] output_it The output iterator. + */ template void -- cgit v1.2.3 From 85ab3ce5b0e6d1cb066d8ca526e9fe532fe75f4f Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 6 Jul 2016 14:42:58 +0000 Subject: Missing find_package git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1383 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 04b500ba8cb7c4ade9f0b7378bc39ee8a558b260 --- src/Spatial_searching/example/CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 0846c232..c1190d1b 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -5,11 +5,16 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") + find_package(Eigen3 3.1.0) + if (EIGEN3_FOUND) + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + include( ${EIGEN3_USE_FILE} ) + include_directories (BEFORE "../../include") - add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) + add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) + else() + message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") + endif() else() message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.0 is required.") endif () -- cgit v1.2.3 From 8587109e64af7ce1f17d8e7756e078a025a37bcb Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 6 Jul 2016 16:05:39 +0000 Subject: Fix CMake scripts git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1389 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b97e07531b300c47ddefd056cc574d89c71a4400 --- src/Spatial_searching/example/CMakeLists.txt | 1 + src/Spatial_searching/test/CMakeLists.txt | 3 ++- src/Subsampling/example/CMakeLists.txt | 2 +- src/Subsampling/test/CMakeLists.txt | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index c1190d1b..0885c24c 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -12,6 +12,7 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) + target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") endif() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 297b6749..41059286 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -18,7 +18,8 @@ if(CGAL_FOUND) 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 ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Spatial_searching_test_Spatial_tree_data_structure + ${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.") endif() diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index e1e7cc71..532440eb 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -17,7 +17,7 @@ if(CGAL_FOUND) #target_link_libraries(Subsampling_example_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 80b0ccbb..18fc84f4 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -21,12 +21,13 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( Subsampling_test_pick_random_points test_pick_random_points.cpp ) + target_link_libraries(Subsampling_test_pick_random_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable( Subsampling_test_choose_farthest_point test_choose_farthest_point.cpp ) - target_link_libraries(Subsampling_test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_test_choose_farthest_point ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) - target_link_libraries(Subsampling_test_sparsify_point_set ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() -- cgit v1.2.3 From ded061ad26b38155e9136a0e7c01d9c0e81a36be Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 6 Jul 2016 16:06:27 +0000 Subject: Doc fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1390 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2fe62f8ab51da843e434b942d5c00e31fdc36225 --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index ca05af57..5a29b153 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -54,7 +54,7 @@ namespace spatial_searching { * 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 requires a model of the SearchTraits * concept, such as the CGAL::Epick_d class, which -- cgit v1.2.3 From 5bc90cf2f92f07a45a7104bd771d52bd0985fb9a Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 5 Aug 2016 14:22:57 +0000 Subject: Added farthest/nearest neighbor division in the functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1424 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b42ad020d144ea4c0b4d726764fc0d4234f5b0b3 --- .../example/example_spatial_searching.cpp | 17 ++++++- .../include/gudhi/Spatial_tree_data_structure.h | 56 +++++++++++++++++++++- .../test/test_Spatial_tree_data_structure.cpp | 13 ++++- 3 files changed, 80 insertions(+), 6 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 1a807b90..0b1e25f5 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -27,16 +27,29 @@ int main (void) // 20-nearest neighbor query std::cout << "20 nearest neighbors:\n"; - auto kns_range = points_ds.query_ANN(points[20], 10, true); + auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); for (auto const& nghb : kns_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; // Incremental nearest neighbor query std::cout << "Incremental nearest neighbors:\n"; - auto ins_range = points_ds.query_incremental_ANN(points[45]); + auto ins_range = points_ds.query_incremental_nearest_neighbors(points[45]); // Get all the neighbors that are closer than 0.5 for (auto ins_iterator = ins_range.begin(); ins_iterator->second < 0.5*0.5 ; ++ins_iterator) std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; + // 20-farthest neighbor query + std::cout << "20 farthest neighbors:\n"; + auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); + for (auto const& nghb : kfs_range) + std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; + + // Incremental farthest neighbor query + std::cout << "Incremental farthest neighbors:\n"; + auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[45]); + // Get all the neighbors that are farthest than 2.3 + for (auto ifs_iterator = ifs_range.begin(); ifs_iterator->second > 2.3*2.3 ; ++ifs_iterator) + std::cout << ifs_iterator->first << " (sq. dist. = " << ifs_iterator->second << ")\n"; + return 0; } diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 5a29b153..99f67fed 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -171,7 +171,7 @@ public: /// @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_ANN(const + KNS_range query_k_nearest_neighbors(const Point &p, unsigned int k, bool sorted = true, @@ -199,7 +199,7 @@ public: /// @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_ANN(const Point &p, FT eps = FT(0)) const + 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 @@ -215,6 +215,58 @@ public: 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 >( + (Point*)&(m_points[0])), + 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 >( + (Point*)&(m_points[0])) ); + + return search; + } + + + protected: Point_container_ const& m_points; Tree m_tree; diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp index 916710ef..0ca35bc6 100644 --- a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp +++ b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp @@ -51,10 +51,10 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) Points_ds points_ds(points); std::size_t closest_pt_index = - points_ds.query_ANN(points[10], 1, false).begin()->first; + points_ds.query_k_nearest_neighbors(points[10], 1, false).begin()->first; BOOST_CHECK(closest_pt_index == 10); - auto kns_range = points_ds.query_ANN(points[20], 10, true); + auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); FT last_dist = -1.; for (auto const& nghb : kns_range) @@ -62,4 +62,13 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) BOOST_CHECK(nghb.second > last_dist); last_dist = nghb.second; } + + auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); + + last_dist = kfs_range.begin()->second; + for (auto const& nghb : kfs_range) + { + BOOST_CHECK(nghb.second <= last_dist); + last_dist = nghb.second; + } } -- cgit v1.2.3 From 1d1a5701ae2f544e04916f5e8b998b8de2b87275 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 5 Aug 2016 17:12:07 +0000 Subject: Update the user manual with farthest points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1426 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8cefe8f8db75edcd22582659248a69df734aa4fb --- src/Spatial_searching/doc/Intro_spatial_searching.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/doc/Intro_spatial_searching.h b/src/Spatial_searching/doc/Intro_spatial_searching.h index 0a857221..20b262d9 100644 --- a/src/Spatial_searching/doc/Intro_spatial_searching.h +++ b/src/Spatial_searching/doc/Intro_spatial_searching.h @@ -42,7 +42,7 @@ namespace spatial_searching { * * \section spatial_searching_examples Example * - * This example generates 500 random points, then performs queries for nearest points using different methods. + * This example generates 500 random points, then performs queries for nearest and farthest points using different methods. * * \include Spatial_searching/example_spatial_searching.cpp * -- cgit v1.2.3 From f4a89213f0a66b6aff58ab4a39d53e43592bde7f Mon Sep 17 00:00:00 2001 From: cjamin Date: Sat, 27 Aug 2016 08:03:05 +0000 Subject: Merge from trunk + minor fix in doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1457 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 961641cb06e1d694f5e733b1677133e8fef25d22 --- src/Persistent_cohomology/example/CMakeLists.txt | 10 +++++----- .../include/gudhi/Persistent_cohomology.h | 6 +++--- src/Spatial_searching/doc/Intro_spatial_searching.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index d6bc60be..d97d1b63 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -37,11 +37,11 @@ add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_f if(GMP_FOUND) if(GMPXX_FOUND) - add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) - target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) - add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) - target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) - if (TBB_FOUND) + add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) + target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) + target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + if (TBB_FOUND) target_link_libraries(rips_multifield_persistence ${TBB_LIBRARIES}) target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES}) endif(TBB_FOUND) diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index b6cef611..a7d1e463 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -308,14 +308,14 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - annotations_in_boundary.emplace_back(curr_col, sign); + annotations_in_boundary.emplace_back(curr_col, sign); } } sign = -sign; } // Place identical annotations consecutively so we can easily sum their multiplicities. std::sort(annotations_in_boundary.begin(), annotations_in_boundary.end(), - [](annotation_t const& a, annotation_t const& b) { return a.first < b.first; }); + [](annotation_t const& a, annotation_t const& b) { return a.first < b.first; }); // Sum the annotations with multiplicity, using a map // to represent a sparse vector. @@ -325,7 +325,7 @@ class Persistent_cohomology { Column* col = ann_it->first; int mult = ann_it->second; while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { - mult += ann_it->second; + mult += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. if (mult != coeff_field_.additive_identity()) { // For all columns in the boundary, diff --git a/src/Spatial_searching/doc/Intro_spatial_searching.h b/src/Spatial_searching/doc/Intro_spatial_searching.h index 20b262d9..2406c931 100644 --- a/src/Spatial_searching/doc/Intro_spatial_searching.h +++ b/src/Spatial_searching/doc/Intro_spatial_searching.h @@ -37,7 +37,7 @@ namespace spatial_searching { * * This Gudhi component is a wrapper around * CGAL dD spatial searching algorithms. - * It provides a simplified API to perform (approximate) nearest neighbor searches. Contrary to CGAL default behavior, the tree + * It provides a simplified API to perform (approximate) neighbor searches. Contrary to CGAL default behavior, the tree * does not store the points themselves, but stores indices. * * \section spatial_searching_examples Example -- cgit v1.2.3 From a935df397bba093848cfe5905aca1a158294825c Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 1 Sep 2016 14:50:04 +0000 Subject: Fix sentence git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1469 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d66e96bd7638ec76b9136b84695691af4c6a5691 --- src/Spatial_searching/example/example_spatial_searching.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 0b1e25f5..4afeccee 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -25,8 +25,8 @@ int main (void) Points_ds points_ds(points); - // 20-nearest neighbor query - std::cout << "20 nearest neighbors:\n"; + // 10-nearest neighbor query + std::cout << "10 nearest neighbors from points[20]:\n"; auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); for (auto const& nghb : kns_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; @@ -38,8 +38,8 @@ int main (void) for (auto ins_iterator = ins_range.begin(); ins_iterator->second < 0.5*0.5 ; ++ins_iterator) std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; - // 20-farthest neighbor query - std::cout << "20 farthest neighbors:\n"; + // 10-farthest neighbor query + std::cout << "10 farthest neighbors from points[20]:\n"; auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); for (auto const& nghb : kfs_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; -- cgit v1.2.3 From a98aa40ed1231e97eb2d1a531035fc8295133f68 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 1 Sep 2016 14:55:36 +0000 Subject: Document Kernel and Point types git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1470 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ce852f241ab92d40b6f32e70aa85d8cb8515b394 --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 99f67fed..9f7503eb 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -67,10 +67,12 @@ template class Spatial_tree_data_structure { public: - typedef typename Point_container_::value_type Point; + /// The kernel. typedef K Kernel; /// Number type used for distances. typedef typename Kernel::FT FT; + /// The point type. + typedef typename Point_container_::value_type Point; typedef CGAL::Search_traits< FT, Point, -- cgit v1.2.3 From d583e4451f548f024d7dc8e17c3ae852a28814fa Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 2 Sep 2016 13:52:00 +0000 Subject: Remove commented functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1473 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 046de1927ed4acf0273df72744607f3bd3300a40 --- .../include/gudhi/Spatial_tree_data_structure.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 9f7503eb..88629a05 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -150,16 +150,6 @@ public: m_tree.build(); } - /*Point_container_ &points() - { - return m_points; - } - - const Point_container_ &points() const - { - return m_points; - }*/ - // Be careful, this function invalidates the tree, // which will be recomputed at the next query void insert(std::ptrdiff_t point_idx) -- cgit v1.2.3 From 5567bfd646d04a1a3fe64f92fcddf126c3f8a1e2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 2 Sep 2016 13:58:07 +0000 Subject: Make member variables private instead of protected git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1474 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 31aa6d4fcb13c1700fc081064135ebf449203464 --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 88629a05..8fde5e14 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -257,9 +257,8 @@ public: return search; } - - -protected: + +private: Point_container_ const& m_points; Tree m_tree; }; -- cgit v1.2.3 From 255061a7f2846cb7bf25032887e7d411bbd9476f Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 2 Sep 2016 14:14:24 +0000 Subject: Test incremental functions + compare results between fixed and incremental git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1475 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4e0136ebdb774dffe7d0840bd1544e1dbc991336 --- .../test/test_Spatial_tree_data_structure.cpp | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp index 0ca35bc6..207b047f 100644 --- a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp +++ b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp @@ -50,25 +50,69 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) 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); } -- cgit v1.2.3 From e9173e5465ba9cb3562789cb7707c54ff75a0366 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 2 Sep 2016 14:15:34 +0000 Subject: Fix doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1476 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5b3c3b464629ce121429374865144789d30febc6 --- src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 8fde5e14..538d4209 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -115,7 +115,7 @@ public: /// \brief Constructor /// @param[in] points Const reference to the point container. This container /// is not copied, so it should not be destroyed or modified afterwards. - /// @param[in] Only_these_points Specifies the indices of the points that + /// @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( -- cgit v1.2.3 From 4ba3903fab4f46e075296c391594551a93afeb6f Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 14 Sep 2016 13:53:45 +0000 Subject: Fix construction of points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1496 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 19a074947a803f359af2be2026d9c4135743fb49 --- src/Spatial_searching/example/example_spatial_searching.cpp | 3 +-- src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 4afeccee..ba2ea25f 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -3,7 +3,6 @@ #include #include -#include #include namespace gss = Gudhi::spatial_searching; @@ -21,7 +20,7 @@ int main (void) Points points; for (int i = 0; i < 500; ++i) - points.push_back(Point(std::array({ rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1) }))); + 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); diff --git a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp index 207b047f..af321919 100644 --- a/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp +++ b/src/Spatial_searching/test/test_Spatial_tree_data_structure.cpp @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) Points points; for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point(std::array({rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1)}))); + 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); -- cgit v1.2.3 From c9d1a58d1f1433546c44ebee538957174d520671 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 20 Sep 2016 16:29:04 +0000 Subject: Use boost::iterator_property_map instead of the pointer trick git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1518 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c1a1fc717ef32087617cff6f8bfa73836365b481 --- .../include/gudhi/Spatial_tree_data_structure.h | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index 538d4209..68702b22 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -27,7 +27,9 @@ #include #include #include +#include +#include #include #include @@ -59,28 +61,33 @@ namespace spatial_searching { * 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_container_ is the type of the container where points are stored (on the user side). - * It must provide random-access via `operator[]` and the points should be stored contiguously in memory. - * `std::vector` is a good candidate. + * \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 +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_container_::value_type Point; + 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; - // using a pointer as a special property map type + typedef CGAL::Search_traits_adapter< - std::ptrdiff_t, Point*, Traits_base> STraits; + 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; @@ -99,52 +106,52 @@ public: typedef Incremental_neighbor_search INS_range; /// \brief Constructor - /// @param[in] points Const reference to the point container. This container + /// @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_container_ const& points) + 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((Point*)&(points[0])) ) + 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 container. This container + /// @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_container_ const& points, + 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((Point*)&(points[0]))) + 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 container. This container + /// @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_container_ const& points, + 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((Point*)&(points[0])) ) + STraits(std::begin(point)) ) { // Build the tree now (we don't want to wait for the first query) m_tree.build(); @@ -178,8 +185,8 @@ public: k, eps, true, - CGAL::Distance_adapter >( - (Point*)&(m_points[0])), + CGAL::Distance_adapter >( + std::begin(m_points)), sorted); return search; @@ -201,8 +208,8 @@ public: p, eps, true, - CGAL::Distance_adapter >( - (Point*)&(m_points[0])) ); + CGAL::Distance_adapter >( + std::begin(m_points)) ); return search; } @@ -228,8 +235,8 @@ public: k, eps, false, - CGAL::Distance_adapter >( - (Point*)&(m_points[0])), + CGAL::Distance_adapter >( + std::begin(m_points)), sorted); return search; @@ -251,15 +258,15 @@ public: p, eps, false, - CGAL::Distance_adapter >( - (Point*)&(m_points[0])) ); + CGAL::Distance_adapter >( + std::begin(m_points)) ); return search; } private: - Point_container_ const& m_points; + Point_range const& m_points; Tree m_tree; }; -- cgit v1.2.3 From 227f58f39835ea33381ddb28f05ce43fcfa058b2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 20 Sep 2016 16:29:57 +0000 Subject: Fix CMakeLists git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1519 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a4a5956802d6c22370367180a2ab70aaff3d3cf9 --- src/Spatial_searching/test/CMakeLists.txt | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 41059286..571c730a 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -11,18 +11,24 @@ if (GPROF_PATH) endif() if(CGAL_FOUND) - find_package(Eigen3 3.1.0) - if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") + if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + message(STATUS "CGAL version: ${CGAL_VERSION}.") - 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 - ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + find_package(Eigen3 3.1.0) + if (EIGEN3_FOUND) + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + 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 + ${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.") + endif() else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Spatial_searching tests.") - endif() + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.0 is required.") + endif () else() message(WARNING "CGAL not found. It is required for the Spatial_searching tests.") endif() -- cgit v1.2.3 From 0d9312c183e5f50ed1c71724fd77990fabb085b4 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 11:53:21 +0000 Subject: Require CGAL 4.8.1 (furthest neighbor is bugged before) See https://github.com/CGAL/cgal/pull/1105 git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1535 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: da97775398bd24c7c1bd431686abd66cdf24005b --- src/Spatial_searching/example/CMakeLists.txt | 4 ++-- src/Spatial_searching/test/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 0885c24c..0c41d56c 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(Spatial_searching_examples) if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") find_package(Eigen3 3.1.0) @@ -17,7 +17,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.1 is required.") endif () else() message(WARNING "CGAL not found. It is required for the Spatial_searching examples.") diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 571c730a..82c38ca5 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -11,7 +11,7 @@ if (GPROF_PATH) endif() if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") find_package(Eigen3 3.1.0) @@ -27,7 +27,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Spatial_searching tests.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () else() message(WARNING "CGAL not found. It is required for the Spatial_searching tests.") -- cgit v1.2.3 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/Spatial_searching') 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 From 39a0577d06d7d5349a08a64e4a73d0eaf67e6d1c Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 15:27:44 +0000 Subject: Clean-up CMakeLists.txt git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1541 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3204fef66b8a8358820531f8d6d2494c96a7226e --- src/Spatial_searching/example/CMakeLists.txt | 5 ----- src/Spatial_searching/test/CMakeLists.txt | 4 ---- src/Subsampling/example/CMakeLists.txt | 15 ++++----------- src/Subsampling/test/CMakeLists.txt | 9 ++------- 4 files changed, 6 insertions(+), 27 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 0c41d56c..3c3970d8 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -5,12 +5,7 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) else() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index ed61cc64..0f2c5ae4 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -14,11 +14,7 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") add_executable( Spatial_searching_test_Kd_tree_search test_Kd_tree_search.cpp ) target_link_libraries(Spatial_searching_test_Kd_tree_search diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 6bf717f7..81b39d6e 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -5,19 +5,12 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - add_executable( Subsampling_example_pick_n_random_points example_pick_n_random_points.cpp ) - - add_executable( Subsampling_example_choose_n_farthest_points example_choose_n_farthest_points.cpp ) - #target_link_libraries(Subsampling_example_choose_n_farthest_points ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - - add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable(Subsampling_example_pick_n_random_points example_pick_n_random_points.cpp) + add_executable(Subsampling_example_choose_n_farthest_points example_choose_n_farthest_points.cpp) + add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 72de5ac7..91d4ed8f 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -14,18 +14,13 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - add_executable( Subsampling_test_pick_n_random_points test_pick_n_random_points.cpp ) target_link_libraries(Subsampling_test_pick_n_random_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable( Subsampling_test_choose_n_farthest_points test_choose_n_farthest_points.cpp ) - target_link_libraries(Subsampling_test_choose_n_farthest_points ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - + target_link_libraries(Subsampling_test_choose_n_farthest_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() -- cgit v1.2.3 From 853bd71a57e36773a422698992527570587ec999 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 15:31:13 +0000 Subject: Fix typo git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1542 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b09cd3fd1ea7940d8787b0d9cd23d4d7e69d0925 --- src/Spatial_searching/include/gudhi/Kd_tree_search.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index af85915a..ff630e9d 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -151,7 +151,7 @@ public: boost::counting_iterator(begin_idx), boost::counting_iterator(past_the_end_idx), typename Tree::Splitter(), - STraits(std::begin(point)) ) + STraits(std::begin(points)) ) { // Build the tree now (we don't want to wait for the first query) m_tree.build(); -- cgit v1.2.3 From edf73bdb311f14187323a7df0a5815a60651526a Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 28 Sep 2016 16:14:43 +0000 Subject: Unused typedef git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1584 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1b8fa44e98da75619a411c1d6058ccebff9ac350 --- src/Spatial_searching/example/example_spatial_searching.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 7b48d055..54e3eb13 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -10,7 +10,6 @@ namespace gss = Gudhi::spatial_searching; int main (void) { typedef CGAL::Epick_d > K; - typedef typename K::FT FT; typedef typename K::Point_d Point; typedef std::vector Points; -- cgit v1.2.3 From 9908fa4d77e579293e2c2def13cb1dc4c6773e9d Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:12:18 +0000 Subject: Modify the example to avoid misleading the user git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1618 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fa4a318f59e6d6dea46694bd71d0a6a2baf1aaff --- src/Spatial_searching/example/example_spatial_searching.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 54e3eb13..46aa48b3 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -32,8 +32,8 @@ int main (void) // Incremental nearest neighbor query std::cout << "Incremental nearest neighbors:\n"; auto ins_range = points_ds.query_incremental_nearest_neighbors(points[45]); - // Get all the neighbors that are closer than 0.5 - for (auto ins_iterator = ins_range.begin(); ins_iterator->second < 0.5*0.5 ; ++ins_iterator) + // Get the neighbors in distance order until we hit the first point + for (auto ins_iterator = ins_range.begin(); ins_iterator->first != 0 ; ++ins_iterator) std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; // 10-farthest neighbor query @@ -45,8 +45,8 @@ int main (void) // Incremental farthest neighbor query std::cout << "Incremental farthest neighbors:\n"; auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[45]); - // Get all the neighbors that are farthest than 2.3 - for (auto ifs_iterator = ifs_range.begin(); ifs_iterator->second > 2.3*2.3 ; ++ifs_iterator) + // Get the neighbors in distance reverse order until we hit the first point + for (auto ifs_iterator = ifs_range.begin(); ifs_iterator->first != 0 ; ++ifs_iterator) std::cout << ifs_iterator->first << " (sq. dist. = " << ifs_iterator->second << ")\n"; return 0; -- cgit v1.2.3 From 9004fc92b2db1cf793374be0f4842c871786d623 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:26:32 +0000 Subject: Recommend the user to read CGAL doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1619 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a4c42c45551039c634b60cc9fa21b12bb4c907ba --- src/Spatial_searching/doc/Intro_spatial_searching.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/doc/Intro_spatial_searching.h b/src/Spatial_searching/doc/Intro_spatial_searching.h index 2406c931..23705378 100644 --- a/src/Spatial_searching/doc/Intro_spatial_searching.h +++ b/src/Spatial_searching/doc/Intro_spatial_searching.h @@ -39,6 +39,10 @@ namespace spatial_searching { * CGAL dD spatial searching algorithms. * It provides a simplified API to perform (approximate) neighbor searches. Contrary to CGAL default behavior, the tree * does not store the points themselves, but stores indices. + * + * For more details about the data structure or the algorithms, or for more advanced usages, reading + * CGAL documentation + * is highly recommended. * * \section spatial_searching_examples Example * -- cgit v1.2.3 From db337a2536eb8a4c7dda384b42abe407ef53487f Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:27:11 +0000 Subject: kns, kfs... => knn, kfn... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1620 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4965c110b94a8ff1e919464a1f55ec3e62fd8bbf --- .../example/example_spatial_searching.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 46aa48b3..528ec029 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -25,28 +25,28 @@ int main (void) // 10-nearest neighbor query std::cout << "10 nearest neighbors from points[20]:\n"; - auto kns_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); - for (auto const& nghb : kns_range) + auto knn_range = points_ds.query_k_nearest_neighbors(points[20], 10, true); + for (auto const& nghb : knn_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; // Incremental nearest neighbor query std::cout << "Incremental nearest neighbors:\n"; - auto ins_range = points_ds.query_incremental_nearest_neighbors(points[45]); + auto inn_range = points_ds.query_incremental_nearest_neighbors(points[45]); // Get the neighbors in distance order until we hit the first point - for (auto ins_iterator = ins_range.begin(); ins_iterator->first != 0 ; ++ins_iterator) + for (auto ins_iterator = inn_range.begin(); ins_iterator->first != 0 ; ++ins_iterator) std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; // 10-farthest neighbor query std::cout << "10 farthest neighbors from points[20]:\n"; - auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); - for (auto const& nghb : kfs_range) + auto kfn_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); + for (auto const& nghb : kfn_range) std::cout << nghb.first << " (sq. dist. = " << nghb.second << ")\n"; // Incremental farthest neighbor query std::cout << "Incremental farthest neighbors:\n"; - auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[45]); + auto ifn_range = points_ds.query_incremental_farthest_neighbors(points[45]); // Get the neighbors in distance reverse order until we hit the first point - for (auto ifs_iterator = ifs_range.begin(); ifs_iterator->first != 0 ; ++ifs_iterator) + for (auto ifs_iterator = ifn_range.begin(); ifs_iterator->first != 0 ; ++ifs_iterator) std::cout << ifs_iterator->first << " (sq. dist. = " << ifs_iterator->second << ")\n"; return 0; -- cgit v1.2.3 From 2c13449f27cff9b2630f8a548df08f1aa1410213 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:27:32 +0000 Subject: Mention farthest search option everywhere git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1621 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 098ada4430780a45eb01a2b25be275752370a08e --- src/Spatial_searching/include/gudhi/Kd_tree_search.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index ff630e9d..314342b6 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -41,19 +41,19 @@ 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. + * \brief Spatial tree data structure to perform (approximate) nearest and farthest 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 + * It provides a simplified API to perform (approximate) nearest and farthest 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 + * There are two types of queries: the k-nearest or k-farthest neighbor query, where k is fixed and the k nearest + * or farthest points are computed right away, + * and the incremental nearest or farthest 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 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. + /// \brief The range returned by a k-nearest or k-farthest 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; @@ -100,7 +100,7 @@ public: 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. + /// \brief The range returned by an incremental nearest or farthest 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; -- cgit v1.2.3 From b7f3439fefcf1c4a1c28ca47652d7e4844f1abf2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:32:02 +0000 Subject: Kernel => Search_traits git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1622 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 72ecfe733a43c52ab82e3377e22fe47655b77b1f --- src/Spatial_searching/include/gudhi/Kd_tree_search.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index 314342b6..76b99d94 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -56,7 +56,7 @@ namespace spatial_searching { * and the incremental nearest or farthest 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 @@ -64,7 +64,7 @@ namespace spatial_searching { * \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 +template class Kd_tree_search { typedef boost::iterator_property_map< @@ -72,17 +72,17 @@ class Kd_tree_search CGAL::Identity_property_map > Point_property_map; public: - /// The kernel. - typedef K Kernel; + /// The Traits. + typedef Search_traits Traits; /// Number type used for distances. - typedef typename Kernel::FT FT; + typedef typename Traits::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; + typename Traits::Cartesian_const_iterator_d, + typename Traits::Construct_cartesian_const_iterator_d> Traits_base; typedef CGAL::Search_traits_adapter< std::ptrdiff_t, -- cgit v1.2.3 From f70230dfe91ec9ac87f234c27184dd7d719e9e69 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:32:23 +0000 Subject: Test: kns, kfs... => knn, kfn... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1623 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 91343f21d81ab127ba6efbf472d153cb4be3f040 --- src/Spatial_searching/test/test_Kd_tree_search.cpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/test_Kd_tree_search.cpp b/src/Spatial_searching/test/test_Kd_tree_search.cpp index 6f99b288..df00d2b9 100644 --- a/src/Spatial_searching/test/test_Kd_tree_search.cpp +++ b/src/Spatial_searching/test/test_Kd_tree_search.cpp @@ -71,14 +71,14 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) 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]); + auto inn_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 inn_it = inn_range.begin(); + for (int i = 0 ; i < 10 ; ++inn_it, ++i) { - auto const& nghb = *ins_it; + auto const& nghb = *inn_it; BOOST_CHECK(nghb.second > last_dist); inn_result.push_back(nghb.second); last_dist = nghb.second; @@ -88,11 +88,11 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) BOOST_CHECK(knn_result == inn_result); // Test query_k_farthest_neighbors - auto kfs_range = points_ds.query_k_farthest_neighbors(points[20], 10, true); + auto kfn_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) + last_dist = kfn_range.begin()->second; + for (auto const& nghb : kfn_range) { BOOST_CHECK(nghb.second <= last_dist); kfn_result.push_back(nghb.second); @@ -100,14 +100,14 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) } // Test query_k_farthest_neighbors - auto ifs_range = points_ds.query_incremental_farthest_neighbors(points[20]); + auto ifn_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) + last_dist = ifn_range.begin()->second; + auto ifn_it = ifn_range.begin(); + for (int i = 0; i < 10; ++ifn_it, ++i) { - auto const& nghb = *ifs_it; + auto const& nghb = *ifn_it; BOOST_CHECK(nghb.second <= last_dist); ifn_result.push_back(nghb.second); last_dist = nghb.second; -- cgit v1.2.3 From fb71b41cb649e0c2242bd1997cb5e7285c1633a6 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 6 Oct 2016 07:38:18 +0000 Subject: is not used anymore git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1651 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 20e9d24cb091c436d951b8a396b684a849231bc4 --- src/Spatial_searching/test/test_Kd_tree_search.cpp | 1 - src/Subsampling/example/example_sparsify_point_set.cpp | 1 - src/Subsampling/test/test_sparsify_point_set.cpp | 1 - 3 files changed, 3 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/test/test_Kd_tree_search.cpp b/src/Spatial_searching/test/test_Kd_tree_search.cpp index df00d2b9..16b72c68 100644 --- a/src/Spatial_searching/test/test_Kd_tree_search.cpp +++ b/src/Spatial_searching/test/test_Kd_tree_search.cpp @@ -29,7 +29,6 @@ #include #include -#include #include BOOST_AUTO_TEST_CASE(test_Kd_tree_search) diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index 7c8cf8b0..ccf83bc0 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 9eebbcc8..04a055ff 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include -- cgit v1.2.3 From a1d8a8b08002d7d2067b76b7109cae4c20618540 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 10:50:47 +0000 Subject: Add unitary tests in make test target Fix doxygen warning fix compilation warning (typedef not used) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1652 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d080543ea90aa089e2f09933a44156f07ae82eb4 --- src/Spatial_searching/example/CMakeLists.txt | 12 +++--------- src/Spatial_searching/test/CMakeLists.txt | 13 ++++--------- src/Subsampling/doc/Intro_subsampling.h | 2 +- src/Subsampling/example/CMakeLists.txt | 22 ++++++++++------------ .../example/example_sparsify_point_set.cpp | 1 - src/Subsampling/test/CMakeLists.txt | 20 ++++++++++++-------- src/Subsampling/test/test_sparsify_point_set.cpp | 1 - 7 files changed, 30 insertions(+), 41 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 3c3970d8..6238a0ec 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -3,17 +3,11 @@ project(Spatial_searching_examples) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") + add_test(Spatial_searching_example_spatial_searching + ${CMAKE_CURRENT_BINARY_DIR}/Spatial_searching_example_spatial_searching) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.1 is required.") - endif () -else() - message(WARNING "CGAL not found. It is required for the Spatial_searching examples.") + endif() endif() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 0f2c5ae4..2c685c72 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -12,19 +12,14 @@ endif() if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) - 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.") + + add_test(Spatial_searching_test_Kd_tree_search ${CMAKE_CURRENT_BINARY_DIR}/Spatial_searching_test_Kd_tree_search + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Spatial_searching_UT.xml --log_level=test_suite --report_level=no) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Spatial_searching tests.") endif() diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index f8eb2fdd..c84616dd 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -34,7 +34,7 @@ namespace subsampling { * * @{ * - * \section introduction Introduction + * \section subsamplingintroduction Introduction * * This Gudhi component offers methods to subsample a set of points. * diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 81b39d6e..54349f0c 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -3,20 +3,18 @@ project(Subsampling_examples) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) + add_executable(Subsampling_example_pick_n_random_points example_pick_n_random_points.cpp) + add_executable(Subsampling_example_choose_n_farthest_points example_choose_n_farthest_points.cpp) + add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) - add_executable(Subsampling_example_pick_n_random_points example_pick_n_random_points.cpp) - add_executable(Subsampling_example_choose_n_farthest_points example_choose_n_farthest_points.cpp) - add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") + add_test(Subsampling_example_pick_n_random_points + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_pick_n_random_points) + add_test(Subsampling_example_choose_n_farthest_points + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_choose_n_farthest_points) + add_test(Subsampling_example_sparsify_point_set + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_sparsify_point_set) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Subsampling examples.") endif() diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index ccf83bc0..ad68b4c1 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -9,7 +9,6 @@ int main (void) { typedef CGAL::Epick_d > K; - typedef typename K::FT FT; typedef typename K::Point_d Point_d; CGAL::Random rd; diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 91d4ed8f..3a2fb649 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -12,8 +12,6 @@ endif() if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) add_executable( Subsampling_test_pick_n_random_points test_pick_n_random_points.cpp ) target_link_libraries(Subsampling_test_pick_n_random_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) @@ -23,12 +21,18 @@ if(CGAL_FOUND) add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") + + add_test(Subsampling_test_pick_n_random_points ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_pick_n_random_points + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_pick_n_random_points_UT.xml --log_level=test_suite --report_level=no) + + add_test(Subsampling_test_choose_n_farthest_points ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_choose_n_farthest_points + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_choose_n_farthest_points_UT.xml --log_level=test_suite --report_level=no) + + add_test(Subsampling_test_sparsify_point_set ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_sparsify_point_set + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_sparsify_point_set_UT.xml --log_level=test_suite --report_level=no) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Subsampling tests.") endif() diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 04a055ff..f993d6d6 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -35,7 +35,6 @@ BOOST_AUTO_TEST_CASE(test_sparsify_point_set) { typedef CGAL::Epick_d > K; - typedef typename K::FT FT; typedef typename K::Point_d Point_d; CGAL::Random rd; -- cgit v1.2.3 From 2a0a8a03e256b8899eee9b73d5f783ef450e61fc Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 14:54:20 +0000 Subject: Fix cpplint issues git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1659 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 498d5b8a5c70e2ab78d96f5dad82386a07dad017 --- .../include/gudhi/Kd_tree_search.h | 60 +++++++++------------- 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index 76b99d94..ab266161 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef GUDHI_SPATIAL_TREE_DS_H_ -#define GUDHI_SPATIAL_TREE_DS_H_ +#ifndef KD_TREE_SEARCH_H_ +#define KD_TREE_SEARCH_H_ #include #include @@ -65,13 +65,12 @@ namespace spatial_searching { * It must be a range whose iterator type is a `RandomAccessIterator`. */ template -class Kd_tree_search -{ +class Kd_tree_search { typedef boost::iterator_property_map< typename Point_range::const_iterator, CGAL::Identity_property_map > Point_property_map; -public: + public: /// The Traits. typedef Search_traits Traits; /// Number type used for distances. @@ -81,14 +80,14 @@ public: typedef CGAL::Search_traits< FT, Point, - typename Traits::Cartesian_const_iterator_d, + typename Traits::Cartesian_const_iterator_d, typename Traits::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; @@ -113,8 +112,7 @@ public: m_tree(boost::counting_iterator(0), boost::counting_iterator(points.size()), typename Tree::Splitter(), - STraits(std::begin(points)) ) - { + STraits(std::begin(points))) { // Build the tree now (we don't want to wait for the first query) m_tree.build(); } @@ -132,8 +130,7 @@ public: m_tree( only_these_points.begin(), only_these_points.end(), typename Tree::Splitter(), - STraits(std::begin(points))) - { + STraits(std::begin(points))) { // Build the tree now (we don't want to wait for the first query) m_tree.build(); } @@ -151,16 +148,14 @@ public: boost::counting_iterator(begin_idx), boost::counting_iterator(past_the_end_idx), typename Tree::Splitter(), - STraits(std::begin(points)) ) - { + STraits(std::begin(points))) { // 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) - { + void insert(std::ptrdiff_t point_idx) { m_tree.insert(point_idx); } @@ -174,8 +169,7 @@ public: Point &p, unsigned int k, bool sorted = true, - FT eps = FT(0)) const - { + 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 @@ -185,9 +179,8 @@ public: k, eps, true, - CGAL::Distance_adapter >( - std::begin(m_points)), - sorted); + CGAL::Distance_adapter >( + std::begin(m_points)), sorted); return search; } @@ -195,11 +188,10 @@ public: /// \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. + /// @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 - { + 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 @@ -224,8 +216,7 @@ public: Point &p, unsigned int k, bool sorted = true, - FT eps = FT(0)) const - { + 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 @@ -235,9 +226,8 @@ public: k, eps, false, - CGAL::Distance_adapter >( - std::begin(m_points)), - sorted); + CGAL::Distance_adapter >( + std::begin(m_points)), sorted); return search; } @@ -248,8 +238,7 @@ public: /// @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 - { + 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 @@ -264,13 +253,12 @@ public: return search; } - -private: + private: Point_range const& m_points; Tree m_tree; }; -} // namespace spatial_searching -} // namespace Gudhi +} // namespace spatial_searching +} // namespace Gudhi -#endif // GUDHI_SPATIAL_TREE_DS_H_ +#endif // KD_TREE_SEARCH_H_ -- cgit v1.2.3 From f7eb2c8060b7a429f360846ce4fcd51490564ce0 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 17:06:40 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1662 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 876f5fe1a6a5ecf281837dc86613dff85db65f27 --- .../example/example_spatial_searching.cpp | 17 +++++----- src/Spatial_searching/test/test_Kd_tree_search.cpp | 37 ++++++++++------------ 2 files changed, 24 insertions(+), 30 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/example_spatial_searching.cpp b/src/Spatial_searching/example/example_spatial_searching.cpp index 528ec029..14b324ae 100644 --- a/src/Spatial_searching/example/example_spatial_searching.cpp +++ b/src/Spatial_searching/example/example_spatial_searching.cpp @@ -7,11 +7,10 @@ namespace gss = Gudhi::spatial_searching; -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point; - typedef std::vector Points; +int main(void) { + typedef CGAL::Epick_d > K; + typedef typename K::Point_d Point; + typedef std::vector Points; typedef gss::Kd_tree_search Points_ds; @@ -19,7 +18,7 @@ int main (void) 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.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); @@ -33,7 +32,7 @@ int main (void) std::cout << "Incremental nearest neighbors:\n"; auto inn_range = points_ds.query_incremental_nearest_neighbors(points[45]); // Get the neighbors in distance order until we hit the first point - for (auto ins_iterator = inn_range.begin(); ins_iterator->first != 0 ; ++ins_iterator) + for (auto ins_iterator = inn_range.begin(); ins_iterator->first != 0; ++ins_iterator) std::cout << ins_iterator->first << " (sq. dist. = " << ins_iterator->second << ")\n"; // 10-farthest neighbor query @@ -46,8 +45,8 @@ int main (void) std::cout << "Incremental farthest neighbors:\n"; auto ifn_range = points_ds.query_incremental_farthest_neighbors(points[45]); // Get the neighbors in distance reverse order until we hit the first point - for (auto ifs_iterator = ifn_range.begin(); ifs_iterator->first != 0 ; ++ifs_iterator) + for (auto ifs_iterator = ifn_range.begin(); ifs_iterator->first != 0; ++ifs_iterator) std::cout << ifs_iterator->first << " (sq. dist. = " << ifs_iterator->second << ")\n"; - + return 0; } diff --git a/src/Spatial_searching/test/test_Kd_tree_search.cpp b/src/Spatial_searching/test/test_Kd_tree_search.cpp index 16b72c68..0ef22023 100644 --- a/src/Spatial_searching/test/test_Kd_tree_search.cpp +++ b/src/Spatial_searching/test/test_Kd_tree_search.cpp @@ -4,7 +4,7 @@ * * Author(s): Clement Jamin * - * Copyright (C) 2016 INRIA Sophia-Antipolis (France) + * 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 @@ -31,35 +31,33 @@ #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; +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; - + 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))); + 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; + 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) - { + for (auto const& nghb : kns_range) { BOOST_CHECK(nghb.second > last_dist); knn_result.push_back(nghb.second); last_dist = nghb.second; @@ -67,7 +65,7 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) // Test query_incremental_nearest_neighbors closest_pt_index = - points_ds.query_incremental_nearest_neighbors(points[10]).begin()->first; + points_ds.query_incremental_nearest_neighbors(points[10]).begin()->first; BOOST_CHECK(closest_pt_index == 10); auto inn_range = points_ds.query_incremental_nearest_neighbors(points[20]); @@ -75,8 +73,7 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) std::vector inn_result; last_dist = -1.; auto inn_it = inn_range.begin(); - for (int i = 0 ; i < 10 ; ++inn_it, ++i) - { + for (int i = 0; i < 10; ++inn_it, ++i) { auto const& nghb = *inn_it; BOOST_CHECK(nghb.second > last_dist); inn_result.push_back(nghb.second); @@ -91,8 +88,7 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) std::vector kfn_result; last_dist = kfn_range.begin()->second; - for (auto const& nghb : kfn_range) - { + for (auto const& nghb : kfn_range) { BOOST_CHECK(nghb.second <= last_dist); kfn_result.push_back(nghb.second); last_dist = nghb.second; @@ -104,8 +100,7 @@ BOOST_AUTO_TEST_CASE(test_Kd_tree_search) std::vector ifn_result; last_dist = ifn_range.begin()->second; auto ifn_it = ifn_range.begin(); - for (int i = 0; i < 10; ++ifn_it, ++i) - { + for (int i = 0; i < 10; ++ifn_it, ++i) { auto const& nghb = *ifn_it; BOOST_CHECK(nghb.second <= last_dist); ifn_result.push_back(nghb.second); -- cgit v1.2.3 From 6af3c873fadc3eae10aa964dd0105ef095201911 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 17:40:50 +0000 Subject: cpplint fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1668 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b24e2b03fc9a8898f5c3d6bf1cf36a2e60442673 --- src/Spatial_searching/include/gudhi/Kd_tree_search.h | 4 ++-- src/Subsampling/include/gudhi/choose_n_farthest_points.h | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index ab266161..6728d56e 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -235,7 +235,7 @@ class Kd_tree_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. + /// @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 { @@ -261,4 +261,4 @@ class Kd_tree_search { } // namespace spatial_searching } // namespace Gudhi -#endif // KD_TREE_SEARCH_H_ +#endif // KD_TREE_SEARCH_H_ diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index 60816a29..40c7808d 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -66,7 +66,6 @@ void choose_n_farthest_points(Kernel const &k, assert(nb_points >= final_size); std::size_t current_number_of_landmarks = 0; // counter for landmarks - double curr_max_dist = 0; // used for defining the furhest point from L const double infty = std::numeric_limits::infinity(); // infinity (see next entry) std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from input_pts @@ -75,7 +74,6 @@ void choose_n_farthest_points(Kernel const &k, for (current_number_of_landmarks = 0; current_number_of_landmarks != final_size; current_number_of_landmarks++) { // curr_max_w at this point is the next landmark *output_it++ = input_pts[curr_max_w]; - // std::cout << curr_max_w << "\n"; std::size_t i = 0; for (auto& p : input_pts) { double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); @@ -84,7 +82,7 @@ void choose_n_farthest_points(Kernel const &k, ++i; } // choose the next curr_max_w - curr_max_dist = 0; + double curr_max_dist = 0; // used for defining the furhest point from L for (i = 0; i < dist_to_L.size(); i++) if (dist_to_L[i] > curr_max_dist) { curr_max_dist = dist_to_L[i]; @@ -109,7 +107,7 @@ void choose_n_farthest_points(Kernel const& k, Point_container const &input_pts, unsigned final_size, OutputIterator output_it) { - // Choose randomly the first landmark + // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1, 6); -- cgit v1.2.3 From 6c9380e336455169a93cd384168f00c737a5ec27 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Sat, 8 Oct 2016 20:52:40 +0000 Subject: Spatial searcing requires CGAL 4.8.1 at least but cmake can only detect CGAL 4.8 or 4.9 (ecause of a CGAL configuration bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1680 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 83b9c75e9fa977a5fbc452a2cc8762f4a1ca32ef --- src/Spatial_searching/example/CMakeLists.txt | 2 +- src/Spatial_searching/test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Spatial_searching') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 6238a0ec..e73b201c 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(Spatial_searching_examples) if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.1) + if (NOT CGAL_VERSION VERSION_LESS 4.9.0) if (EIGEN3_FOUND) add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 2c685c72..7f443b79 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -11,7 +11,7 @@ if (GPROF_PATH) endif() if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.1) + if (NOT CGAL_VERSION VERSION_LESS 4.9.0) if (EIGEN3_FOUND) add_executable( Spatial_searching_test_Kd_tree_search test_Kd_tree_search.cpp ) target_link_libraries(Spatial_searching_test_Kd_tree_search -- cgit v1.2.3