From e6c5dde140fa8f8de23fcf86c62d4c69bee9b16e Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 11 May 2016 09:47:08 +0000 Subject: Create 2 new packages: Subsampling & Spatial_searching git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1167 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e7053d379e936bb6c3f82bd323837285decba5d2 --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e55e4395..f4d15b64 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,6 +92,8 @@ else() add_subdirectory(example/Bitmap_cubical_complex) add_subdirectory(example/Witness_complex) add_subdirectory(example/Alpha_complex) + add_subdirectory(example/Spatial_searching) + add_subdirectory(example/Subsampling) # data points generator add_subdirectory(data/points/generator) -- cgit v1.2.3 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') 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') 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 d48e75a5095c48da3bfaf87df5135c209dab58eb Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 13 May 2016 16:36:46 +0000 Subject: Add sparsify_point_set git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1176 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 21e3b8d9ef41a750436fff3b8b077399cfd3e48b --- src/Subsampling/include/gudhi/sparsify_point_set.h | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/Subsampling/include/gudhi/sparsify_point_set.h (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h new file mode 100644 index 00000000..89770886 --- /dev/null +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -0,0 +1,99 @@ +/* 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_SPARSIFY_POINT_SET_H +#define GUDHI_SPARSIFY_POINT_SET_H + +#include +#ifdef GUDHI_TC_PROFILING +#include +#endif + +#include +#include + +namespace Gudhi { + + template + bool + sparsify_point_set( + const Kernel &k, Point_container const& input_pts, + typename Kernel::FT min_squared_dist, + OutputIterator output_it) + { + typedef typename Gudhi::Spatial_tree_data_structure< + Kernel, Point_container> Points_ds; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + +#ifdef GUDHI_TC_PROFILING + Gudhi::Clock t; +#endif + + Points_ds points_ds(input_pts); + + std::vector dropped_points(input_pts.size(), false); + + // Parse the input points, and add them if they are not too close to + // the other points + std::size_t pt_idx = 0; + for (typename Point_container::const_iterator it_pt = input_pts.begin() ; + it_pt != input_pts.end(); + ++it_pt, ++pt_idx) + { + if (dropped_points[pt_idx]) + continue; + + *output_it++ = *it_pt; + + auto ins_range = points_ds.query_incremental_ANN(*it_pt); + + // If another point Q is closer that min_squared_dist, mark Q to be dropped + for (auto const& neighbor : ins_range) + { + std::size_t neighbor_point_idx = neighbor.first; + // If the neighbor is too close, we drop the neighbor + if (neighbor.second < min_squared_dist) + //if (neighbor.second < 0.2*((*it_pt)[0] + 1.)*0.5 + 0.00005) + //if (neighbor.second < ((*it_pt)[0] < 0 ? 0.2 : 0.00001)) + { + // N.B.: If neighbor_point_idx < pt_idx, + // dropped_points[neighbor_point_idx] is already true but adding a + // test doesn't make things faster, so why bother? + dropped_points[neighbor_point_idx] = true; + } + else + break; + } + } + +#ifdef GUDHI_TC_PROFILING + t.end(); + std::cerr << "Point set sparsified in " << t.num_seconds() + << " seconds." << std::endl; +#endif + } + + +} //namespace Gudhi + +#endif // GUDHI_POINT_CLOUD_H -- cgit v1.2.3 From 29cf10daf5e6f2674ccb1491716754a4e5f98cc2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 31 May 2016 16:03:05 +0000 Subject: Fix identation git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1229 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 90afa5dc86416baa5716cdbd7157f96149165dc0 --- src/Subsampling/include/gudhi/sparsify_point_set.h | 97 +++++++++++----------- 1 file changed, 48 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 89770886..a6844919 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -33,66 +33,65 @@ namespace Gudhi { - template - bool - sparsify_point_set( - const Kernel &k, Point_container const& input_pts, - typename Kernel::FT min_squared_dist, - OutputIterator output_it) - { - typedef typename Gudhi::Spatial_tree_data_structure< - Kernel, Point_container> Points_ds; - - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); +template +bool +sparsify_point_set( + const Kernel &k, Point_container const& input_pts, + typename Kernel::FT min_squared_dist, + OutputIterator output_it) +{ + typedef typename Gudhi::Spatial_tree_data_structure< + Kernel, Point_container> Points_ds; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); #ifdef GUDHI_TC_PROFILING - Gudhi::Clock t; + Gudhi::Clock t; #endif - Points_ds points_ds(input_pts); + Points_ds points_ds(input_pts); + + std::vector dropped_points(input_pts.size(), false); + + // Parse the input points, and add them if they are not too close to + // the other points + std::size_t pt_idx = 0; + for (typename Point_container::const_iterator it_pt = input_pts.begin() ; + it_pt != input_pts.end(); + ++it_pt, ++pt_idx) + { + if (dropped_points[pt_idx]) + continue; - std::vector dropped_points(input_pts.size(), false); + *output_it++ = *it_pt; - // Parse the input points, and add them if they are not too close to - // the other points - std::size_t pt_idx = 0; - for (typename Point_container::const_iterator it_pt = input_pts.begin() ; - it_pt != input_pts.end(); - ++it_pt, ++pt_idx) + auto ins_range = points_ds.query_incremental_ANN(*it_pt); + + // If another point Q is closer that min_squared_dist, mark Q to be dropped + for (auto const& neighbor : ins_range) + { + std::size_t neighbor_point_idx = neighbor.first; + // If the neighbor is too close, we drop the neighbor + if (neighbor.second < min_squared_dist) + //if (neighbor.second < 0.2*((*it_pt)[0] + 1.)*0.5 + 0.00005) + //if (neighbor.second < ((*it_pt)[0] < 0 ? 0.2 : 0.00001)) { - if (dropped_points[pt_idx]) - continue; - - *output_it++ = *it_pt; - - auto ins_range = points_ds.query_incremental_ANN(*it_pt); - - // If another point Q is closer that min_squared_dist, mark Q to be dropped - for (auto const& neighbor : ins_range) - { - std::size_t neighbor_point_idx = neighbor.first; - // If the neighbor is too close, we drop the neighbor - if (neighbor.second < min_squared_dist) - //if (neighbor.second < 0.2*((*it_pt)[0] + 1.)*0.5 + 0.00005) - //if (neighbor.second < ((*it_pt)[0] < 0 ? 0.2 : 0.00001)) - { - // N.B.: If neighbor_point_idx < pt_idx, - // dropped_points[neighbor_point_idx] is already true but adding a - // test doesn't make things faster, so why bother? - dropped_points[neighbor_point_idx] = true; - } - else - break; - } + // N.B.: If neighbor_point_idx < pt_idx, + // dropped_points[neighbor_point_idx] is already true but adding a + // test doesn't make things faster, so why bother? + dropped_points[neighbor_point_idx] = true; } + else + break; + } + } #ifdef GUDHI_TC_PROFILING - t.end(); - std::cerr << "Point set sparsified in " << t.num_seconds() - << " seconds." << std::endl; + t.end(); + std::cerr << "Point set sparsified in " << t.num_seconds() + << " seconds." << std::endl; #endif - } - +} } //namespace Gudhi -- cgit v1.2.3 From bb56631552ff8cf431d2286470223f7394cb2846 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 31 May 2016 16:09:46 +0000 Subject: Farthest points (from Siargey) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1230 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3093bfd41948fecf5f6ccb2d1d77546c12e628f4 --- .../gudhi/Landmark_choice_by_farthest_point.h | 158 +++++++++++++++++++++ .../gudhi/Landmark_choice_by_random_point.h | 80 +++++++++++ src/Subsampling/test/CMakeLists.txt | 22 +++ src/Subsampling/test/landmarking.cpp | 47 ++++++ 4 files changed, 307 insertions(+) create mode 100644 src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h create mode 100644 src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h create mode 100644 src/Subsampling/test/CMakeLists.txt create mode 100644 src/Subsampling/test/landmarking.cpp (limited to 'src') diff --git a/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h b/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h new file mode 100644 index 00000000..198c9f9f --- /dev/null +++ b/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h @@ -0,0 +1,158 @@ +/* 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) 2015 INRIA Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ +#define LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ + +#include + +#include +#include // for sort +#include +#include +#include + +namespace Gudhi { + + + template < typename Point_d, + typename Heap, + typename Tree, + typename Presence_table > + void update_heap( Point_d &l, + unsigned nbL, + Heap &heap, + Tree &tree, + Presence_table &table) + { + auto search = tree.query_incremental_ANN(l); + for (auto w: search) { + if (table[w.first].first) + if (w.second < table[w.first].second->second) { + heap.update(table[w.first].second, w); + } + } + } + + /** + * \ingroup witness_complex + * \brief Landmark choice strategy by iteratively adding the farthest witness from the + * current landmark set as the new landmark. + * \details It chooses nbL landmarks from a random access range `points` and + * writes {witness}*{closest landmarks} matrix in `knn`. + * + * The type KNearestNeighbors can be seen as + * Witness_range>, where + * Witness_range and Closest_landmark_range are random access ranges + * + */ + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void landmark_choice_by_farthest_point( Kernel& k, + Point_container const &points, + int nbL, + OutputIterator output_it) + { + + // typedef typename Kernel::FT FT; + // typedef std::pair Heap_node; + + // struct R_max_compare + // { + // bool operator()(const Heap_node &rmh1, const Heap_node &rmh2) const + // { + // return rmh1.second < rmh2.second; + // } + // }; + + // typedef boost::heap::fibonacci_heap> Heap; + // typedef Spatial_tree_data_structure Tree; + // typedef std::vector< std::pair > Presence_table; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + // Tree tree(points); + // Heap heap; + // Presence_table table(points.size()); + // for (auto p: table) + // std::cout << p.first << "\n"; + // int number_landmarks = 0; // number of treated 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(points.size(), infty); // vector of current distances to L from points + + // // Choose randomly the first landmark + // std::random_device rd; + // std::mt19937 gen(rd()); + // std::uniform_int_distribution<> dis(1, 6); + // int curr_landmark = dis(gen); + + // do { + // *output_landmarks++ = points[curr_landmark]; + // std::cout << curr_landmark << "\n"; + // number_landmarks++; + // } + // while (number_landmarks < nbL); + // } + + int nb_points = boost::size(points); + assert(nb_points >= nbL); + + int 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 points + + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int curr_max_w = dis(gen); + + + for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { + // curr_max_w at this point is the next landmark + *output_it++ = points[curr_max_w]; + std::cout << curr_max_w << "\n"; + unsigned i = 0; + for (auto& p : points) { + double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + ++i; + } + // choose the next curr_max_w + curr_max_dist = 0; + for (i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } + } + } + +} // namespace Gudhi + +#endif // LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ diff --git a/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h b/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h new file mode 100644 index 00000000..daa05d1a --- /dev/null +++ b/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h @@ -0,0 +1,80 @@ +/* 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 Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_RANDOM_POINT_H_ +#define LANDMARK_CHOICE_BY_RANDOM_POINT_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + + /** + * \ingroup witness_complex + * \brief Landmark choice strategy by taking random vertices for landmarks. + * + * \details It chooses nbL distinct landmarks from a random access range `points` + * and outputs them to an output iterator. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void landmark_choice_by_random_point(Point_container const &points, + unsigned nbL, + OutputIterator output_it) { +#ifdef GUDHI_LM_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= nbL); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(nbL); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_LM_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + + + } + +} // namespace Gudhi + +#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt new file mode 100644 index 00000000..3a45c685 --- /dev/null +++ b/src/Subsampling/test/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.6) +project(GUDHILandmarkingTest) + +# Landmarking test +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + 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( landmarking_UT landmarking.cpp ) + else() + message(WARNING "Eigen3 not found. Version 3.1.0 is required for Landmarking feature.") + endif() + else() + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") + endif () +endif() diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp new file mode 100644 index 00000000..3131c798 --- /dev/null +++ b/src/Subsampling/test/landmarking.cpp @@ -0,0 +1,47 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include +#include +#include +#include + +#include + + +int main() { + typedef CGAL::Epick_d K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + std::vector vect; + vect.push_back(Point_d(std::vector({0,0,0,0}))); + vect.push_back(Point_d(std::vector({0,0,0,1}))); + vect.push_back(Point_d(std::vector({0,0,1,0}))); + vect.push_back(Point_d(std::vector({0,0,1,1}))); + vect.push_back(Point_d(std::vector({0,1,0,0}))); + vect.push_back(Point_d(std::vector({0,1,0,1}))); + vect.push_back(Point_d(std::vector({0,1,1,0}))); + vect.push_back(Point_d(std::vector({0,1,1,1}))); + vect.push_back(Point_d(std::vector({1,0,0,0}))); + vect.push_back(Point_d(std::vector({1,0,0,1}))); + vect.push_back(Point_d(std::vector({1,0,1,0}))); + vect.push_back(Point_d(std::vector({1,0,1,1}))); + vect.push_back(Point_d(std::vector({1,1,0,0}))); + vect.push_back(Point_d(std::vector({1,1,0,1}))); + vect.push_back(Point_d(std::vector({1,1,1,0}))); + vect.push_back(Point_d(std::vector({1,1,1,1}))); + + + std::vector landmarks; + Gudhi::landmark_choice_by_random_point(vect, 5, std::back_inserter(landmarks)); + std::cout << "landmark vector contains: "; + for (auto l: landmarks) + std::cout << l << "\n"; + + landmarks.clear(); + K k; + Gudhi::landmark_choice_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); + +} -- cgit v1.2.3 From d40d646eefb3460f64ca0dac56da47ae863bf37d Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 1 Jun 2016 12:11:48 +0000 Subject: Clean-up git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1237 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6d60dce225c8705c8f441ec454c425f663a899d8 --- src/Subsampling/include/gudhi/sparsify_point_set.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index a6844919..859f2295 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -73,8 +73,6 @@ sparsify_point_set( std::size_t neighbor_point_idx = neighbor.first; // If the neighbor is too close, we drop the neighbor if (neighbor.second < min_squared_dist) - //if (neighbor.second < 0.2*((*it_pt)[0] + 1.)*0.5 + 0.00005) - //if (neighbor.second < ((*it_pt)[0] < 0 ? 0.2 : 0.00001)) { // N.B.: If neighbor_point_idx < pt_idx, // dropped_points[neighbor_point_idx] is already true but adding a -- cgit v1.2.3 From ead71ec7ab6f5b1d23a0102289530d5f99572fe0 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Jun 2016 14:59:04 +0000 Subject: Deleted Landmark choices from witness complex, modified the test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1238 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f3072037b5e931a4e8fcfeadaae3499074377f01 --- src/Witness_complex/test/witness_complex_points.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index bd3df604..c0006142 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -27,8 +27,9 @@ #include #include +#include #include -#include +#include #include #include @@ -40,7 +41,7 @@ typedef Gudhi::witness_complex::Witness_complex WitnessComplex; BOOST_AUTO_TEST_CASE(witness_complex_points) { std::vector< typeVectorVertex > knn; - std::vector< Point > points; + std::vector< Point > points, landmarks; // Add grid points as witnesses for (double i = 0; i < 10; i += 1.0) for (double j = 0; j < 10; j += 1.0) @@ -50,15 +51,9 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::witness_complex::landmark_choice_by_random_point(points, 100, knn); + Gudhi::landmark_choice_by_random_point(points, 100, std::back_inserter(landmarks)); + Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); assert(!knn.empty()); WitnessComplex witnessComplex1(knn, 100, 3, complex1); BOOST_CHECK(witnessComplex1.is_witness_complex(knn, b_print_output)); - - // Second test: furthest choice - knn.clear(); - Simplex_tree complex2; - Gudhi::witness_complex::landmark_choice_by_furthest_point(points, 100, knn); - WitnessComplex witnessComplex2(knn, 100, 3, complex2); - BOOST_CHECK(witnessComplex2.is_witness_complex(knn, b_print_output)); } -- cgit v1.2.3 From 1f07634127072d447b22c4d5edaec95577f792e4 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Jun 2016 15:14:17 +0000 Subject: Changed the examples in witness complex package git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1239 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1ab3b8e4b99d52e749fe5ec67d41283be4258e81 --- src/Witness_complex/example/witness_complex_from_file.cpp | 6 ++++-- src/Witness_complex/example/witness_complex_sphere.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 53207ad2..fbc3cf1d 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -78,7 +79,7 @@ int main(int argc, char * const argv[]) { Gudhi::Simplex_tree<> simplex_tree; // Read the point file - Point_Vector point_vector; + Point_Vector point_vector, landmarks; read_points_cust(file_name, point_vector); std::cout << "Successfully read " << point_vector.size() << " points.\n"; std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n"; @@ -86,7 +87,8 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::witness_complex::landmark_choice_by_random_point(point_vector, nbL, knn); + Gudhi::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); end = clock(); std::cout << "Landmark choice for " << nbL << " landmarks took " << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index b26c9f36..9cf2f119 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -67,7 +68,7 @@ int main(int argc, char * const argv[]) { // Read the point file for (int nbP = 500; nbP < 10000; nbP += 500) { - Point_Vector point_vector; + Point_Vector point_vector, landmarks; generate_points_sphere(point_vector, nbP, 4); std::cout << "Successfully generated " << point_vector.size() << " points.\n"; std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n"; @@ -75,7 +76,8 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::witness_complex::landmark_choice_by_random_point(point_vector, number_of_landmarks, knn); + Gudhi::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); // Compute witness complex Gudhi::witness_complex::witness_complex(knn, number_of_landmarks, point_vector[0].size(), simplex_tree); -- cgit v1.2.3 From 9469df0b1d91e133ee246229fb5df597c9d18e5b Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 15 Jun 2016 08:33:59 +0000 Subject: Added the forgotten Construct_closest_landmark_table.h git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1280 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ec56f3a9da0fc63a96fb9f7075bc533bfd18393 --- .../gudhi/Construct_closest_landmark_table.h | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h (limited to 'src') diff --git a/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h b/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h new file mode 100644 index 00000000..ef711c34 --- /dev/null +++ b/src/Witness_complex/include/gudhi/Construct_closest_landmark_table.h @@ -0,0 +1,90 @@ +/* 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) 2015 INRIA Sophia Antipolis-Méditerranée (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 CONSTRUCT_CLOSEST_LANDMARK_TABLE_H_ +#define CONSTRUCT_CLOSEST_LANDMARK_TABLE_H_ + +#include + +#include // for priority_queue<> +#include // for pair<> +#include +#include +#include + +namespace Gudhi { + +namespace witness_complex { + + /** + * \ingroup witness_complex + * \brief Construct the closest landmark tables for all witnesses. + * \details Output a table 'knn', each line of which represents a witness and + * consists of landmarks sorted by + * euclidean distance from the corresponding witness. + * + * The type WitnessContainer is a random access range and + * the type LandmarkContainer is a range. + * The type KNearestNeighbors can be seen as + * Witness_range>, where + * Witness_range and Closest_landmark_range are random access ranges and + * Vertex_handle is the label type of a vertex in a simplicial complex. + * Closest_landmark_range needs to have push_back operation. + */ + + template + void construct_closest_landmark_table(WitnessContainer const &points, + LandmarkContainer const &landmarks, + KNearestNeighbours &knn) { + int nbP = boost::size(points); + assert(nbP >= boost::size(landmarks)); + + int dim = boost::size(*std::begin(points)); + typedef std::pair dist_i; + typedef bool (*comp)(dist_i, dist_i); + knn = KNearestNeighbours(nbP); + for (int points_i = 0; points_i < nbP; points_i++) { + std::priority_queue, comp> l_heap([](dist_i j1, dist_i j2) { + return j1.first > j2.first; + }); + typename LandmarkContainer::const_iterator landmarks_it; + int landmarks_i = 0; + for (landmarks_it = landmarks.begin(), landmarks_i = 0; landmarks_it != landmarks.end(); + ++landmarks_it, landmarks_i++) { + dist_i dist = std::make_pair(euclidean_distance(points[points_i], *landmarks_it), landmarks_i); + l_heap.push(dist); + } + for (int i = 0; i < dim + 1; i++) { + dist_i dist = l_heap.top(); + knn[points_i].push_back(dist.second); + l_heap.pop(); + } + } + } + +} // namespace witness_complex + +} // namespace Gudhi + +#endif // CONSTRUCT_CLOSEST_LANDMARK_TABLE_H_ -- cgit v1.2.3 From 730b337735ae0ce0ee8f849910e637ca479a93b5 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 17 Jun 2016 12:54:38 +0000 Subject: Fix return type git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1311 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 33798172ecb1d19bcb080cd6b6a38102ac975304 --- src/Subsampling/include/gudhi/sparsify_point_set.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 3784e583..d04deb60 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -35,7 +35,7 @@ namespace Gudhi { namespace subsampling { template -bool +void sparsify_point_set( const Kernel &k, Point_container const& input_pts, typename Kernel::FT min_squared_dist, -- cgit v1.2.3 From 3c65ebebc4bfc32ec1b436c3d99a1f97a94b60d7 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 20 Jun 2016 13:24:52 +0000 Subject: Renamed the two landmarking functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1314 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5025e0aff02306d61fa809eac10b7db27947b120 --- src/Subsampling/test/landmarking.cpp | 8 +- .../example/witness_complex_from_file.cpp | 4 +- .../example/witness_complex_sphere.cpp | 4 +- .../gudhi/Landmark_choice_by_furthest_point.h | 105 --------------------- .../gudhi/Landmark_choice_by_random_point.h | 96 ------------------- .../test/witness_complex_points.cpp | 5 +- 6 files changed, 10 insertions(+), 212 deletions(-) delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h (limited to 'src') diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp index 3131c798..a2c85349 100644 --- a/src/Subsampling/test/landmarking.cpp +++ b/src/Subsampling/test/landmarking.cpp @@ -2,8 +2,8 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include -#include +#include +#include #include #include @@ -35,13 +35,13 @@ int main() { std::vector landmarks; - Gudhi::landmark_choice_by_random_point(vect, 5, std::back_inserter(landmarks)); + Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); std::cout << "landmark vector contains: "; for (auto l: landmarks) std::cout << l << "\n"; landmarks.clear(); K k; - Gudhi::landmark_choice_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); + Gudhi::choose_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); } diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index fbc3cf1d..17b63dcf 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); end = clock(); std::cout << "Landmark choice for " << nbL << " landmarks took " diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 9cf2f119..495a5895 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); // Compute witness complex diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h deleted file mode 100644 index df93155b..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h +++ /dev/null @@ -1,105 +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): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ -#define LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ - -#include - -#include // for numeric_limits<> -#include -#include // for sort -#include - -namespace Gudhi { - -namespace witness_complex { - - typedef std::vector typeVectorVertex; - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the furthest witness from the - * current landmark set as the new landmark. - * \details It chooses nbL landmarks from a random access range `points` and - * writes {witness}*{closest landmarks} matrix in `knn`. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges - * - */ - - template - void landmark_choice_by_furthest_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nb_points = boost::size(points); - assert(nb_points >= nbL); - // distance matrix witness x landmarks - std::vector> wit_land_dist(nb_points, std::vector()); - // landmark list - typeVectorVertex chosen_landmarks; - - knn = KNearestNeighbours(nb_points, std::vector()); - int 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 points - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - // or better yet std::uniform_int_distribution - int rand_int = rand() % nb_points; - int curr_max_w = rand_int; // For testing purposes a pseudo-random number is used here - - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - // curr_max_w at this point is the next landmark - chosen_landmarks.push_back(curr_max_w); - unsigned i = 0; - for (auto& p : points) { - double curr_dist = euclidean_distance(p, *(std::begin(points) + chosen_landmarks[current_number_of_landmarks])); - wit_land_dist[i].push_back(curr_dist); - knn[i].push_back(current_number_of_landmarks); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - curr_max_dist = 0; - for (i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - for (int i = 0; i < nb_points; ++i) - std::sort(std::begin(knn[i]), - std::end(knn[i]), - [&wit_land_dist, i](int a, int b) { - return wit_land_dist[i][a] < wit_land_dist[i][b]; }); - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h deleted file mode 100644 index ebf6aad1..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h +++ /dev/null @@ -1,96 +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): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_RANDOM_POINT_H_ -#define LANDMARK_CHOICE_BY_RANDOM_POINT_H_ - -#include - -#include // for priority_queue<> -#include // for pair<> -#include -#include -#include - -namespace Gudhi { - -namespace witness_complex { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs a matrix {witness}*{closest landmarks} in knn. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges and - * Vertex_handle is the label type of a vertex in a simplicial complex. - * Closest_landmark_range needs to have push_back operation. - */ - - template - void landmark_choice_by_random_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nbP = boost::size(points); - assert(nbP >= nbL); - std::set landmarks; - int current_number_of_landmarks = 0; // counter for landmarks - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - int chosen_landmark = rand() % nbP; - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - while (landmarks.find(chosen_landmark) != landmarks.end()) - chosen_landmark = rand() % nbP; - landmarks.insert(chosen_landmark); - } - - int dim = boost::size(*std::begin(points)); - typedef std::pair dist_i; - typedef bool (*comp)(dist_i, dist_i); - knn = KNearestNeighbours(nbP); - for (int points_i = 0; points_i < nbP; points_i++) { - std::priority_queue, comp> l_heap([](dist_i j1, dist_i j2) { - return j1.first > j2.first; - }); - std::set::iterator landmarks_it; - int landmarks_i = 0; - for (landmarks_it = landmarks.begin(), landmarks_i = 0; landmarks_it != landmarks.end(); - ++landmarks_it, landmarks_i++) { - dist_i dist = std::make_pair(euclidean_distance(points[points_i], points[*landmarks_it]), landmarks_i); - l_heap.push(dist); - } - for (int i = 0; i < dim + 1; i++) { - dist_i dist = l_heap.top(); - knn[points_i].push_back(dist.second); - l_heap.pop(); - } - } - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index c0006142..596152f4 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -28,8 +28,7 @@ #include #include #include -#include -#include +#include #include #include @@ -51,7 +50,7 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::landmark_choice_by_random_point(points, 100, std::back_inserter(landmarks)); + Gudhi::pick_random_points(points, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); assert(!knn.empty()); WitnessComplex witnessComplex1(knn, 100, 3, complex1); -- cgit v1.2.3 From a3b6dbe9223bc71ebbb763066a1cd9f3359322a8 Mon Sep 17 00:00:00 2001 From: cjamin Date: Mon, 20 Jun 2016 16:54:13 +0000 Subject: Add test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1316 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a597203ec80289750b8faa2d6e5293211125dd3c --- src/Subsampling/test/CMakeLists.txt | 6 ++--- src/Subsampling/test/test_sparsify_point_set.cpp | 34 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/Subsampling/test/test_sparsify_point_set.cpp (limited to 'src') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 3a45c685..1785b86d 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 2.6) -project(GUDHILandmarkingTest) +project(Subsampling_tests) -# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -13,8 +12,9 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( landmarking_UT landmarking.cpp ) + add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Landmarking feature.") + message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp new file mode 100644 index 00000000..e9d2a8f6 --- /dev/null +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -0,0 +1,34 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include + +#include +#include + +#include +#include +#include + +int main() { + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::sparsify_point_set(k, points, 0.5, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + //for (auto p : results) + // std::cout << p << "\n"; + + return 0; +} -- cgit v1.2.3 From 80c45e3f6a8a1f823840b3ae9e924362d7e376b7 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 20 Jun 2016 21:49:38 +0000 Subject: Added the forgotten files git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1317 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5fe0bce1c55e62c87bf0da9be915f081a90e9e7 --- .../gudhi/Landmark_choice_by_farthest_point.h | 158 --------------------- .../gudhi/Landmark_choice_by_random_point.h | 80 ----------- .../include/gudhi/choose_by_farthest_point.h | 96 +++++++++++++ src/Subsampling/include/gudhi/pick_random_points.h | 80 +++++++++++ 4 files changed, 176 insertions(+), 238 deletions(-) delete mode 100644 src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h delete mode 100644 src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h create mode 100644 src/Subsampling/include/gudhi/choose_by_farthest_point.h create mode 100644 src/Subsampling/include/gudhi/pick_random_points.h (limited to 'src') diff --git a/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h b/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h deleted file mode 100644 index 198c9f9f..00000000 --- a/src/Subsampling/include/gudhi/Landmark_choice_by_farthest_point.h +++ /dev/null @@ -1,158 +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): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ -#define LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ - -#include - -#include -#include // for sort -#include -#include -#include - -namespace Gudhi { - - - template < typename Point_d, - typename Heap, - typename Tree, - typename Presence_table > - void update_heap( Point_d &l, - unsigned nbL, - Heap &heap, - Tree &tree, - Presence_table &table) - { - auto search = tree.query_incremental_ANN(l); - for (auto w: search) { - if (table[w.first].first) - if (w.second < table[w.first].second->second) { - heap.update(table[w.first].second, w); - } - } - } - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the farthest witness from the - * current landmark set as the new landmark. - * \details It chooses nbL landmarks from a random access range `points` and - * writes {witness}*{closest landmarks} matrix in `knn`. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges - * - */ - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void landmark_choice_by_farthest_point( Kernel& k, - Point_container const &points, - int nbL, - OutputIterator output_it) - { - - // typedef typename Kernel::FT FT; - // typedef std::pair Heap_node; - - // struct R_max_compare - // { - // bool operator()(const Heap_node &rmh1, const Heap_node &rmh2) const - // { - // return rmh1.second < rmh2.second; - // } - // }; - - // typedef boost::heap::fibonacci_heap> Heap; - // typedef Spatial_tree_data_structure Tree; - // typedef std::vector< std::pair > Presence_table; - - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - // Tree tree(points); - // Heap heap; - // Presence_table table(points.size()); - // for (auto p: table) - // std::cout << p.first << "\n"; - // int number_landmarks = 0; // number of treated 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(points.size(), infty); // vector of current distances to L from points - - // // Choose randomly the first landmark - // std::random_device rd; - // std::mt19937 gen(rd()); - // std::uniform_int_distribution<> dis(1, 6); - // int curr_landmark = dis(gen); - - // do { - // *output_landmarks++ = points[curr_landmark]; - // std::cout << curr_landmark << "\n"; - // number_landmarks++; - // } - // while (number_landmarks < nbL); - // } - - int nb_points = boost::size(points); - assert(nb_points >= nbL); - - int 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 points - - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int curr_max_w = dis(gen); - - - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - // curr_max_w at this point is the next landmark - *output_it++ = points[curr_max_w]; - std::cout << curr_max_w << "\n"; - unsigned i = 0; - for (auto& p : points) { - double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - // choose the next curr_max_w - curr_max_dist = 0; - for (i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - } - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_FARTHEST_POINT_H_ diff --git a/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h b/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h deleted file mode 100644 index daa05d1a..00000000 --- a/src/Subsampling/include/gudhi/Landmark_choice_by_random_point.h +++ /dev/null @@ -1,80 +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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (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 LANDMARK_CHOICE_BY_RANDOM_POINT_H_ -#define LANDMARK_CHOICE_BY_RANDOM_POINT_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs them to an output iterator. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void landmark_choice_by_random_point(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { -#ifdef GUDHI_LM_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= nbL); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); - - std::random_device rd; - std::mt19937 g(rd()); - - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(nbL); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - - - } - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h new file mode 100644 index 00000000..61a21f44 --- /dev/null +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -0,0 +1,96 @@ +/* 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) 2015 INRIA Sophia Antipolis-Méditerranée (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 CHOOSE_BY_FARTHEST_POINT_H_ +#define CHOOSE_BY_FARTHEST_POINT_H_ + +#include + +#include +#include // for sort +#include +#include + +namespace Gudhi { + + /** + * \ingroup witness_complex + * \brief Landmark choice strategy by iteratively adding the farthest witness from the + * current landmark set as the new landmark. + * \details It chooses nbL landmarks from a random access range `points` and + * writes {witness}*{closest landmarks} matrix in `knn`. + * + * The type KNearestNeighbors can be seen as + * Witness_range>, where + * Witness_range and Closest_landmark_range are random access ranges + * + */ + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int nbL, + OutputIterator output_it) + { + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + int nb_points = boost::size(points); + assert(nb_points >= nbL); + + int 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 points + + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int curr_max_w = dis(gen); + + + for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { + // curr_max_w at this point is the next landmark + *output_it++ = points[curr_max_w]; + std::cout << curr_max_w << "\n"; + unsigned i = 0; + for (auto& p : points) { + double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + ++i; + } + // choose the next curr_max_w + curr_max_dist = 0; + for (i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } + } + } + +} // namespace Gudhi + +#endif // CHOOSE_BY_FARTHEST_POINT_H_ diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h new file mode 100644 index 00000000..9a436ee3 --- /dev/null +++ b/src/Subsampling/include/gudhi/pick_random_points.h @@ -0,0 +1,80 @@ +/* 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 Sophia Antipolis-Méditerranée (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 PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + + /** + * \ingroup witness_complex + * \brief Landmark choice strategy by taking random vertices for landmarks. + * + * \details It chooses nbL distinct landmarks from a random access range `points` + * and outputs them to an output iterator. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_random_points(Point_container const &points, + unsigned nbL, + OutputIterator output_it) { +#ifdef GUDHI_LM_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= nbL); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(nbL); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_LM_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + + + } + +} // namespace Gudhi + +#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ -- cgit v1.2.3 From 1539aa803375bbb562559ab632d8ce22c6ce940b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:20:44 +0000 Subject: Merged the CMakeLists and added test_choose_by_farthest_point git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1318 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 534a2ac30a2177a780d1f483add2c472d4cedac3 --- .../include/gudhi/choose_by_farthest_point.h | 4 ++- src/Subsampling/test/CMakeLists.txt | 14 ++++++++- .../test/test_choose_farthest_point.cpp | 35 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/Subsampling/test/test_choose_farthest_point.cpp (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 61a21f44..9877d5eb 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -25,6 +25,8 @@ #include +#include + #include #include // for sort #include @@ -73,7 +75,7 @@ namespace Gudhi { for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { // curr_max_w at this point is the next landmark *output_it++ = points[curr_max_w]; - std::cout << curr_max_w << "\n"; + // std::cout << curr_max_w << "\n"; unsigned i = 0; for (auto& p : points) { double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 1785b86d..3a7fc092 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -1,6 +1,16 @@ cmake_minimum_required(VERSION 2.6) project(Subsampling_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() + +# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -11,7 +21,9 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( landmarking_UT landmarking.cpp ) + add_executable( test_choose_farthest_point test_choose_farthest_point.cpp ) + target_link_libraries(test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp new file mode 100644 index 00000000..2f83fac9 --- /dev/null +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -0,0 +1,35 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "witness_complex_points" +#include +#include + +#include +#include +#include + +#include + +typedef CGAL::Epick_d K; +typedef typename K::FT FT; +typedef typename K::Point_d Point_d; + + +BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { + std::vector< Point_d > points, landmarks; + // Add grid points (625 points) + for (FT i = 0; i < 5; i += 1.0) + for (FT j = 0; j < 5; j += 1.0) + for (FT k = 0; k < 5; k += 1.0) + for (FT l = 0; l < 5; l += 1.0) + points.push_back(Point_d(std::vector({i, j, k, l}))); + + landmarks.clear(); + K k; + Gudhi::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); + + assert(landmarks.size() == 100); +} -- cgit v1.2.3 From 3113edccca8b0ecf1bc3a942abd03f62c7bb0bcb Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:29:59 +0000 Subject: Renamed the test for pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1319 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2210767dc829ba596409170200ba8fce5d39fdf1 --- src/Subsampling/test/CMakeLists.txt | 6 ++- src/Subsampling/test/landmarking.cpp | 47 ------------------------ src/Subsampling/test/test_pick_random_points.cpp | 44 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 src/Subsampling/test/landmarking.cpp create mode 100644 src/Subsampling/test/test_pick_random_points.cpp (limited to 'src') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 3a7fc092..0c591e8b 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -21,8 +21,10 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( test_choose_farthest_point test_choose_farthest_point.cpp ) - target_link_libraries(test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable( Subsampling_test_pick_random_points test_pick_random_points.cpp ) + + 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}) add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp deleted file mode 100644 index a2c85349..00000000 --- a/src/Subsampling/test/landmarking.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// #ifdef _DEBUG -// # define TBB_USE_THREADING_TOOL -// #endif - -#include -#include -#include -#include - -#include - - -int main() { - typedef CGAL::Epick_d K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - std::vector vect; - vect.push_back(Point_d(std::vector({0,0,0,0}))); - vect.push_back(Point_d(std::vector({0,0,0,1}))); - vect.push_back(Point_d(std::vector({0,0,1,0}))); - vect.push_back(Point_d(std::vector({0,0,1,1}))); - vect.push_back(Point_d(std::vector({0,1,0,0}))); - vect.push_back(Point_d(std::vector({0,1,0,1}))); - vect.push_back(Point_d(std::vector({0,1,1,0}))); - vect.push_back(Point_d(std::vector({0,1,1,1}))); - vect.push_back(Point_d(std::vector({1,0,0,0}))); - vect.push_back(Point_d(std::vector({1,0,0,1}))); - vect.push_back(Point_d(std::vector({1,0,1,0}))); - vect.push_back(Point_d(std::vector({1,0,1,1}))); - vect.push_back(Point_d(std::vector({1,1,0,0}))); - vect.push_back(Point_d(std::vector({1,1,0,1}))); - vect.push_back(Point_d(std::vector({1,1,1,0}))); - vect.push_back(Point_d(std::vector({1,1,1,1}))); - - - std::vector landmarks; - Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); - std::cout << "landmark vector contains: "; - for (auto l: landmarks) - std::cout << l << "\n"; - - landmarks.clear(); - K k; - Gudhi::choose_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); - -} diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp new file mode 100644 index 00000000..13c7dcad --- /dev/null +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -0,0 +1,44 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include +#include +#include +#include + +#include + + +int main() { + typedef CGAL::Epick_d K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + std::vector vect; + vect.push_back(Point_d(std::vector({0,0,0,0}))); + vect.push_back(Point_d(std::vector({0,0,0,1}))); + vect.push_back(Point_d(std::vector({0,0,1,0}))); + vect.push_back(Point_d(std::vector({0,0,1,1}))); + vect.push_back(Point_d(std::vector({0,1,0,0}))); + vect.push_back(Point_d(std::vector({0,1,0,1}))); + vect.push_back(Point_d(std::vector({0,1,1,0}))); + vect.push_back(Point_d(std::vector({0,1,1,1}))); + vect.push_back(Point_d(std::vector({1,0,0,0}))); + vect.push_back(Point_d(std::vector({1,0,0,1}))); + vect.push_back(Point_d(std::vector({1,0,1,0}))); + vect.push_back(Point_d(std::vector({1,0,1,1}))); + vect.push_back(Point_d(std::vector({1,1,0,0}))); + vect.push_back(Point_d(std::vector({1,1,0,1}))); + vect.push_back(Point_d(std::vector({1,1,1,0}))); + vect.push_back(Point_d(std::vector({1,1,1,1}))); + + + std::vector landmarks; + Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); + std::cout << "landmark vector contains: "; + for (auto l: landmarks) + std::cout << l << "\n"; + assert(landmarks_size() == 5); + +} -- cgit v1.2.3 From c4bad9f4dcdefb44bb91b80afc06bf3f2039efe2 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:34:22 +0000 Subject: Capitalized Pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1320 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24995238315de68a9bd93e88d56581e2451ea68e --- src/Subsampling/include/gudhi/Pick_random_points.h | 80 ++++++++++++++++++++++ src/Subsampling/include/gudhi/pick_random_points.h | 80 ---------------------- src/Subsampling/test/test_pick_random_points.cpp | 3 +- .../example/witness_complex_from_file.cpp | 2 +- .../example/witness_complex_sphere.cpp | 2 +- 5 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 src/Subsampling/include/gudhi/Pick_random_points.h delete mode 100644 src/Subsampling/include/gudhi/pick_random_points.h (limited to 'src') diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h new file mode 100644 index 00000000..9a436ee3 --- /dev/null +++ b/src/Subsampling/include/gudhi/Pick_random_points.h @@ -0,0 +1,80 @@ +/* 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 Sophia Antipolis-Méditerranée (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 PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + + /** + * \ingroup witness_complex + * \brief Landmark choice strategy by taking random vertices for landmarks. + * + * \details It chooses nbL distinct landmarks from a random access range `points` + * and outputs them to an output iterator. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_random_points(Point_container const &points, + unsigned nbL, + OutputIterator output_it) { +#ifdef GUDHI_LM_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= nbL); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(nbL); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_LM_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + + + } + +} // namespace Gudhi + +#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h deleted file mode 100644 index 9a436ee3..00000000 --- a/src/Subsampling/include/gudhi/pick_random_points.h +++ /dev/null @@ -1,80 +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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (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 PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs them to an output iterator. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { -#ifdef GUDHI_LM_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= nbL); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); - - std::random_device rd; - std::mt19937 g(rd()); - - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(nbL); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - - - } - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 13c7dcad..a7466c9e 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -2,8 +2,7 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include -#include +#include #include #include diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 17b63dcf..ba348f9b 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 495a5895..2ea7376f 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From ffcfe6014704dc2b2e5121d64ba42a832f4bbc34 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 13:09:35 +0000 Subject: Minor fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1321 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 74e20cad580a15a344c969a39dcd0bc30efe07a8 --- src/Subsampling/include/gudhi/Pick_random_points.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h index 9a436ee3..1bc1474b 100644 --- a/src/Subsampling/include/gudhi/Pick_random_points.h +++ b/src/Subsampling/include/gudhi/Pick_random_points.h @@ -46,8 +46,8 @@ namespace Gudhi { template void pick_random_points(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { + unsigned nbL, + OutputIterator output_it) { #ifdef GUDHI_LM_PROFILING Gudhi::Clock t; #endif @@ -67,14 +67,12 @@ namespace Gudhi { *output_it++ = points[l]; #ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; #endif - - } } // namespace Gudhi -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ +#endif // PICK_RANDOM_POINTS_H_ -- cgit v1.2.3 From 4fcd44cbaf631e764e7cd7a9b1e23d209685bba5 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 13:11:24 +0000 Subject: Minor fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1322 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1be827933417d190d01c7ec56c6b14283c2deb51 --- src/Subsampling/include/gudhi/choose_by_farthest_point.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 9877d5eb..434b5f7d 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -23,8 +23,6 @@ #ifndef CHOOSE_BY_FARTHEST_POINT_H_ #define CHOOSE_BY_FARTHEST_POINT_H_ -#include - #include #include @@ -50,10 +48,10 @@ namespace Gudhi { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &points, - int nbL, - OutputIterator output_it) + void choose_by_farthest_point(Kernel& k, + Point_container const &points, + int nbL, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -71,7 +69,6 @@ namespace Gudhi { std::uniform_int_distribution<> dis(1, 6); int curr_max_w = dis(gen); - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { // curr_max_w at this point is the next landmark *output_it++ = points[curr_max_w]; -- cgit v1.2.3 From 1ed4039613bee6d3cd85b312e88af71acdbdc163 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 13:53:51 +0000 Subject: Boostify the test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1323 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 58b2cfba030198debf2831809e430e3bf3251346 --- src/Subsampling/test/CMakeLists.txt | 3 ++- src/Subsampling/test/test_sparsify_point_set.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 0c591e8b..6fd70e39 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -26,7 +26,8 @@ if(CGAL_FOUND) 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}) - add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) + 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}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index e9d2a8f6..8e89f81a 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -2,6 +2,10 @@ // # define TBB_USE_THREADING_TOOL // #endif +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test sparsify_point_set +#include + #include #include @@ -11,7 +15,8 @@ #include #include -int main() { +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; @@ -30,5 +35,5 @@ int main() { //for (auto p : results) // std::cout << p << "\n"; - return 0; + BOOST_CHECK(points.size() > results.size()); } -- 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') 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') 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 091796c9be3ac7ddaa96bacc71842a2808da14e4 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 15:15:25 +0000 Subject: Use namespace + improve CMakeLists.txt git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1326 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7481553ea143479fa48b3722370b3d031ad8175a --- src/Subsampling/include/gudhi/sparsify_point_set.h | 6 +++--- src/Subsampling/test/CMakeLists.txt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index bd7f4c56..62b1b4b6 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -40,9 +40,9 @@ sparsify_point_set( const Kernel &k, Point_container const& input_pts, typename Kernel::FT min_squared_dist, OutputIterator output_it) -{ - typedef typename Gudhi::Spatial_tree_data_structure< - Kernel, Point_container> Points_ds; +{ + typedef typename Gudhi::spatial_searching::Spatial_tree_data_structure< + Kernel, Point_container> Points_ds; typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 6fd70e39..80b0ccbb 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -10,7 +10,6 @@ if (GPROF_PATH) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") endif() -# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -32,6 +31,8 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") + 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 Subsampling tests.") endif() -- 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') 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 83dd60a38920cdf85e4c1108404cfa7c294f98e2 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 22 Jun 2016 09:42:57 +0000 Subject: Took into account Clément's remarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1328 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6f1db13d0e8cec8e64c5bb30da53b72b00446de3 --- src/Subsampling/include/gudhi/Pick_random_points.h | 78 -------------------- .../include/gudhi/choose_by_farthest_point.h | 31 ++++---- src/Subsampling/include/gudhi/pick_random_points.h | 82 ++++++++++++++++++++++ .../test/test_choose_farthest_point.cpp | 8 +-- src/Subsampling/test/test_pick_random_points.cpp | 10 +-- 5 files changed, 106 insertions(+), 103 deletions(-) delete mode 100644 src/Subsampling/include/gudhi/Pick_random_points.h create mode 100644 src/Subsampling/include/gudhi/pick_random_points.h (limited to 'src') diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h deleted file mode 100644 index 98902264..00000000 --- a/src/Subsampling/include/gudhi/Pick_random_points.h +++ /dev/null @@ -1,78 +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): 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 . - */ - -#ifndef PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs them to an output iterator. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { -#ifdef GUDHI_LM_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= nbL); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); - - std::random_device rd; - std::mt19937 g(rd()); - - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(nbL); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - } - -} // namespace Gudhi - -#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 2918983f..52647c16 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -31,32 +31,29 @@ #include namespace Gudhi { - + +namespace subsampling { /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the farthest witness from the - * current landmark set as the new landmark. - * \details It chooses nbL landmarks from a random access range `points` and - * writes {witness}*{closest landmarks} matrix in `knn`. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * \details It chooses `final_size` points from a random access range `points` and + * outputs it in the output iterator `output_it`. * */ template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point(Kernel& k, - Point_container const &points, - int nbL, - OutputIterator output_it) + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); int nb_points = boost::size(points); - assert(nb_points >= nbL); + assert(nb_points >= final_size); int current_number_of_landmarks = 0; // counter for landmarks double curr_max_dist = 0; // used for defining the furhest point from L @@ -69,7 +66,7 @@ namespace Gudhi { std::uniform_int_distribution<> dis(1, 6); int curr_max_w = dis(gen); - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { + 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++ = points[curr_max_w]; // std::cout << curr_max_w << "\n"; @@ -89,6 +86,8 @@ namespace Gudhi { } } } + +} // namespace subsampling } // namespace Gudhi diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h new file mode 100644 index 00000000..732ae3f7 --- /dev/null +++ b/src/Subsampling/include/gudhi/pick_random_points.h @@ -0,0 +1,82 @@ +/* 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 . + */ + +#ifndef PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + +namespace subsampling { + + /** + * \ingroup subsampling + * \brief Subsample a point set by picking random vertices. + * + * \details It chooses `final_size` distinct points from a random access range `points` + * and outputs them to the output iterator `output_it`. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_random_points(Point_container const &points, + unsigned final_size, + OutputIterator output_it) { +#ifdef GUDHI_SUBS_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= final_size); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(final_size); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_SUBS_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + } + +} // namesapce subsampling + +} // namespace Gudhi + +#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 991fcbfe..87c2c38d 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -41,7 +41,7 @@ typedef typename K::Point_d Point_d; BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { - std::vector< Point_d > points, landmarks; + std::vector< Point_d > points, results; // Add grid points (625 points) for (FT i = 0; i < 5; i += 1.0) for (FT j = 0; j < 5; j += 1.0) @@ -49,9 +49,9 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { for (FT l = 0; l < 5; l += 1.0) points.push_back(Point_d(std::vector({i, j, k, l}))); - landmarks.clear(); + results.clear(); K k; - Gudhi::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); - assert(landmarks.size() == 100); + assert(results.size() == 100); } diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 81c7ffdb..8156160e 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -24,7 +24,7 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include +#include #include #include @@ -55,11 +55,11 @@ int main() { vect.push_back(Point_d(std::vector({1,1,1,1}))); - std::vector landmarks; - Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); + std::vector results; + Gudhi::subsampling::pick_random_points(vect, 5, std::back_inserter(results)); std::cout << "landmark vector contains: "; - for (auto l: landmarks) + for (auto l: results) std::cout << l << "\n"; - assert(landmarks_size() == 5); + assert(results.size() == 5); } -- cgit v1.2.3 From a288227ce65517493c73ae9ae09b44d50c6c325d Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 22 Jun 2016 14:22:08 +0000 Subject: Fix macro name git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1329 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 54f4b2503173286f4ca1f0186cafc8a195776c7a --- src/Subsampling/include/gudhi/sparsify_point_set.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 62b1b4b6..31ca40be 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -24,7 +24,7 @@ #define GUDHI_SPARSIFY_POINT_SET_H #include -#ifdef GUDHI_TC_PROFILING +#ifdef GUDHI_SUBSAMPLING_PROFILING #include #endif @@ -46,7 +46,7 @@ sparsify_point_set( typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); -#ifdef GUDHI_TC_PROFILING +#ifdef GUDHI_SUBSAMPLING_PROFILING Gudhi::Clock t; #endif @@ -85,7 +85,7 @@ sparsify_point_set( } } -#ifdef GUDHI_TC_PROFILING +#ifdef GUDHI_SUBSAMPLING_PROFILING t.end(); std::cerr << "Point set sparsified in " << t.num_seconds() << " seconds." << std::endl; -- cgit v1.2.3 From c90bcb4438cd23467ece39eb9815fe66cee04740 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 22 Jun 2016 14:40:26 +0000 Subject: Doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1330 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a0ceaad859180b088662288aab7ff321171b985e --- src/Subsampling/include/gudhi/sparsify_point_set.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 31ca40be..09c4af13 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -34,6 +34,14 @@ 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`. +* +*/ + template void sparsify_point_set( -- cgit v1.2.3 From 8e78adfc0f09f128a541cb96dad7a547dd6a9d0c Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:23:40 +0000 Subject: Add an example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1334 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: df8ee96b7cbfcc4380e49956b2495ec8bf12895e --- src/Subsampling/example/CMakeLists.txt | 29 ++++++++++++ .../example/example_sparsify_point_set.cpp | 51 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/Subsampling/example/CMakeLists.txt create mode 100644 src/Subsampling/example/example_sparsify_point_set.cpp (limited to 'src') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt new file mode 100644 index 00000000..e7a8a9f7 --- /dev/null +++ b/src/Subsampling/example/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 2.6) +project(Subsampling_examples) + +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + 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_random_points example_pick_random_points.cpp ) + + #add_executable( Subsampling_example_choose_farthest_point example_choose_farthest_point.cpp ) + #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}) + else() + message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") + endif() + else() + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.0 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 new file mode 100644 index 00000000..57171082 --- /dev/null +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -0,0 +1,51 @@ +/* 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 . + */ + +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::sparsify_point_set(k, points, 0.4, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} -- cgit v1.2.3 From 37fab7af9e25e4a6eb20542bd591d680f5e363b2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:25:52 +0000 Subject: Doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1335 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 67d3d81e429cf62b0fd0755cd3f8c3d81ad2c1b6 --- src/Subsampling/doc/Intro_subsampling.h | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Subsampling/doc/Intro_subsampling.h (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h new file mode 100644 index 00000000..658a45ed --- /dev/null +++ b/src/Subsampling/doc/Intro_subsampling.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_SUBSAMPLING_INTRO_SUBSAMPLING_H_ +#define DOC_SUBSAMPLING_INTRO_SUBSAMPLING_H_ + +// needs namespace for Doxygen to link on classes +namespace Gudhi { +// needs namespace for Doxygen to link on classes +namespace subsampling { + +/** \defgroup subsampling Subsampling + * + * \author Clément Jamin, Siargey Kachanovich + * + * @{ + * + * \section introduction Introduction + * + * This Gudhi component offers methods to subsample a set of points. + * + * \section sparsifyexamples Example: `sparsify_point_set` + * + * This example Outputs a subset of the input points so that the + * squared distance between any two points + * is greater than or equal to 0.4. + * + * \include Subsampling/example_sparsify_point_set.cpp + * + * \copyright GNU General Public License v3. + * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim + */ +/** @} */ // end defgroup subsampling + +} // namespace subsampling + +} // namespace Gudhi + +#endif // DOC_SUBSAMPLING_INTRO_SUBSAMPLING_H_ -- cgit v1.2.3 From 1857deb15fbf20cfec66175d5309299c0012cf55 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:32:04 +0000 Subject: Add paths to IMAGE_PATH git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1336 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3f75a756d642ffb54561065539c79db3b3e47858 --- src/Doxyfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Doxyfile b/src/Doxyfile index 6ddfb55d..40648f29 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -843,7 +843,9 @@ IMAGE_PATH = doc/Skeleton_blocker/ \ doc/Simplex_tree/ \ doc/Persistent_cohomology/ \ doc/Witness_complex/ \ - doc/Bitmap_cubical_complex/ + doc/Bitmap_cubical_complex/ \ + doc/Subsampling/ \ + doc/Spatial_searching/ # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program -- cgit v1.2.3 From 9eaa65136751ab3362c13455163187bd60e7a1aa Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:42:11 +0000 Subject: Fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1337 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e2b4d4c10b9daacab7841cc6c1c85473ec15c979 --- src/Subsampling/doc/Intro_subsampling.h | 6 +++--- .../example/example_sparsify_point_set.cpp | 22 ---------------------- 2 files changed, 3 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 658a45ed..e62ebc61 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -30,7 +30,7 @@ namespace subsampling { /** \defgroup subsampling Subsampling * - * \author Clément Jamin, Siargey Kachanovich + * \author Clément Jamin, Siargey Kachanovich * * @{ * @@ -38,9 +38,9 @@ namespace subsampling { * * This Gudhi component offers methods to subsample a set of points. * - * \section sparsifyexamples Example: `sparsify_point_set` + * \section sparsifyexamples Example: sparsify_point_set * - * This example Outputs a subset of the input points so that the + * This example outputs a subset of the input points so that the * squared distance between any two points * is greater than or equal to 0.4. * diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index 57171082..cb5ccf0b 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -1,25 +1,3 @@ -/* 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 . - */ - #include #include -- cgit v1.2.3 From 7928209595af6f7559fde36fa06c031cd47e7179 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 24 Jun 2016 13:42:39 +0000 Subject: Copied Clément's example for 2 functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1338 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 42f29038057980965bfead2c73cbc013448493fb --- src/Subsampling/example/CMakeLists.txt | 4 +- .../example/example_choose_by_farthest_point.cpp | 52 +++++++++ .../example/example_pick_random_points.cpp | 52 +++++++++ .../include/gudhi/choose_by_farthest_point.h | 119 +++++++++++++++++++-- .../test/test_choose_farthest_point.cpp | 65 ++++++++--- 5 files changed, 266 insertions(+), 26 deletions(-) create mode 100644 src/Subsampling/example/example_choose_by_farthest_point.cpp create mode 100644 src/Subsampling/example/example_pick_random_points.cpp (limited to 'src') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index e7a8a9f7..e1e7cc71 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -11,9 +11,9 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - #add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) + add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) - #add_executable( Subsampling_example_choose_farthest_point example_choose_farthest_point.cpp ) + add_executable( Subsampling_example_choose_by_farthest_point example_choose_by_farthest_point.cpp ) #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) diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp new file mode 100644 index 00000000..5b81bc9d --- /dev/null +++ b/src/Subsampling/example/example_choose_by_farthest_point.cpp @@ -0,0 +1,52 @@ +/* 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 . + */ + + +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} diff --git a/src/Subsampling/example/example_pick_random_points.cpp b/src/Subsampling/example/example_pick_random_points.cpp new file mode 100644 index 00000000..49a027a4 --- /dev/null +++ b/src/Subsampling/example/example_pick_random_points.cpp @@ -0,0 +1,52 @@ +/* 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 . + */ + + +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::pick_random_points(points, 100, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 52647c16..d1db0d1a 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -25,6 +25,14 @@ #include +#include + +#include + +#include +#include +#include + #include #include // for sort #include @@ -45,10 +53,11 @@ namespace subsampling { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &points, - int final_size, - OutputIterator output_it) + void choose_by_farthest_point_old( Kernel& k, + Point_container const &points, + int final_size, + int starting_point, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -60,11 +69,7 @@ namespace subsampling { 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 points - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int curr_max_w = dis(gen); + int curr_max_w = starting_point; 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 @@ -86,7 +91,103 @@ namespace subsampling { } } } + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_by_farthest_point_old( Kernel& k, + Point_container const &points, + int final_size, + OutputIterator output_it) + { + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int starting_point = dis(gen); + choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); + } + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + int starting_point, + OutputIterator output_it) + { + // typedef typename Kernel::Point_d Point_d; + // typedef typename Kernel::FT FT; + // typedef CGAL::Search_traits< + // FT, Point_d, + // typename Kernel::Cartesian_const_iterator_d, + // typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; + // typedef CGAL::Search_traits_adapter< std::ptrdiff_t, Point_d*, Traits_base > STraits; + // typedef CGAL::Fuzzy_sphere< STraits > Fuzzy_sphere; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + int nb_points = boost::size(points); + assert(nb_points >= final_size); + + Clock t; + Gudhi::spatial_searching::Spatial_tree_data_structure< Kernel, Point_container> tree(points); + t.end(); + //std::cout << "Constructed the Kd tree: " << t.num_seconds() << " s." << std::endl; + + //CGAL::Fuzzy_sphere< CGAL::Search_trai> + + int current_number_of_landmarks = 0; // counter for landmarks + const double infty = std::numeric_limits::infinity(); // infinity (see next entry) + double curr_max_dist = infty; // used for defining the furhest point from L + std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from points + + // Choose randomly the first landmark + int curr_max_w = starting_point; + + 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++ = points[curr_max_w]; + // std::cout << curr_max_w << "\n"; + //for (auto& p : points) { + auto search = tree.query_incremental_ANN(points[curr_max_w]); + auto search_it = search.begin(); + while (search_it != search.end() && search_it->second <= curr_max_dist ) { + //std::cout << search_it->second << " " << curr_max_dist << "\n"; + if (dist_to_L[search_it->first] > search_it->second) + dist_to_L[search_it->first] = search_it->second; + search_it++; + } + // choose the next curr_max_w + curr_max_dist = 0; + for (unsigned i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } + } + } + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + OutputIterator output_it) + { + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int starting_point = dis(gen); + + choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); + } + + } // namespace subsampling } // namespace Gudhi diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 87c2c38d..dff2cd4e 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -24,14 +24,15 @@ // # define TBB_USE_THREADING_TOOL // #endif -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "witness_complex_points" -#include -#include +// #define BOOST_TEST_DYN_LINK +// #define BOOST_TEST_MODULE "test_choose_farthest_point" +//#include +//#include #include #include #include +#include #include @@ -40,18 +41,52 @@ typedef typename K::FT FT; typedef typename K::Point_d Point_d; -BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { - std::vector< Point_d > points, results; - // Add grid points (625 points) - for (FT i = 0; i < 5; i += 1.0) - for (FT j = 0; j < 5; j += 1.0) - for (FT k = 0; k < 5; k += 1.0) - for (FT l = 0; l < 5; l += 1.0) +//BOOST_AUTO_TEST_CASE(test_choose_farthest_point) +int main() { + std::vector< Point_d > points, results, results2; + K k; + Clock t; + // Add grid points (810000 points) + for (FT i = 0; i < 30; i += 1.0) + for (FT j = 0; j < 30; j += 1.0) + for (FT k = 0; k < 30; k += 1.0) + for (FT l = 0; l < 30; l += 1.0) points.push_back(Point_d(std::vector({i, j, k, l}))); - results.clear(); - K k; - Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); + unsigned final_size = 100, numeral = 1; + std::cout << "Test New Old\n"; + while (final_size < 100001) { + std::cout << final_size << ": "; + results.clear(); + t.begin(); + Gudhi::subsampling::choose_by_farthest_point(k, points, final_size, 0, std::back_inserter(results)); + t.end(); + std::cout << t.num_seconds() << " s, "; - assert(results.size() == 100); + // std::cout << "New algorithm result:\n"; + // for (auto p: results) + // std::cout << p << std::endl; + + results2.clear(); + t.begin(); + Gudhi::subsampling::choose_by_farthest_point_old(k, points, final_size, 0, std::back_inserter(results2)); + t.end(); + std::cout << t.num_seconds() << " s" << std::endl; + + + // std::cout << "Old algorithm result:\n"; + // for (auto p: results2) + // std::cout << p << std::endl; + + assert(results.size() == final_size); + assert(results2.size() == final_size); + assert(results == results2); + + switch (numeral) { + case 1: numeral = 2; final_size *= 2; break; + case 2: numeral = 5; final_size = final_size/2*5; break; + case 5: numeral = 1; final_size *= 2; break; + default: assert(false); + } + } } -- cgit v1.2.3 From 96b7e2ec76b94aa8d609c816f3adab63f0b6caa9 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 24 Jun 2016 14:08:26 +0000 Subject: Removed headers in the examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1339 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 835003033dc15ce8fd2d8efdc7bfdf3e0be7760d --- src/Subsampling/doc/Intro_subsampling.h | 7 ++ .../example/example_choose_by_farthest_point.cpp | 23 ----- .../example/example_pick_random_points.cpp | 23 ----- .../include/gudhi/choose_by_farthest_point.h | 102 ++++----------------- .../test/test_choose_farthest_point.cpp | 65 +++---------- 5 files changed, 38 insertions(+), 182 deletions(-) (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index e62ebc61..5ccab3af 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -46,6 +46,13 @@ namespace subsampling { * * \include Subsampling/example_sparsify_point_set.cpp * + * \section farthestpointexamples Example: choose_by_farthest_point + * + * This example outputs a subset of 100 points obtained by González algorithm, + * starting with a random point. + * + * \include Subsampling/example_choose_by_farthest_point.cpp + * * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp index 5b81bc9d..29ecbf9b 100644 --- a/src/Subsampling/example/example_choose_by_farthest_point.cpp +++ b/src/Subsampling/example/example_choose_by_farthest_point.cpp @@ -1,26 +1,3 @@ -/* 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 . - */ - - #include #include diff --git a/src/Subsampling/example/example_pick_random_points.cpp b/src/Subsampling/example/example_pick_random_points.cpp index 49a027a4..348b1b81 100644 --- a/src/Subsampling/example/example_pick_random_points.cpp +++ b/src/Subsampling/example/example_pick_random_points.cpp @@ -1,26 +1,3 @@ -/* 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 . - */ - - #include #include diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index d1db0d1a..8dea19be 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -45,6 +45,7 @@ namespace subsampling { * \ingroup subsampling * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the * current chosen point set to the subsampling. + * The iteration starts with the landmark `starting point`. * \details It chooses `final_size` points from a random access range `points` and * outputs it in the output iterator `output_it`. * @@ -53,11 +54,11 @@ namespace subsampling { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point_old( Kernel& k, - Point_container const &points, - int final_size, - int starting_point, - OutputIterator output_it) + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + int starting_point, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -92,101 +93,30 @@ namespace subsampling { } } - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point_old( Kernel& k, - Point_container const &points, - int final_size, - OutputIterator output_it) - { - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int starting_point = dis(gen); - choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); - } - + /** + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * The iteration starts with a random landmark. + * \details It chooses `final_size` points from a random access range `points` and + * outputs it in the output iterator `output_it`. + * + */ template < typename Kernel, typename Point_container, typename OutputIterator> void choose_by_farthest_point( Kernel& k, Point_container const &points, int final_size, - int starting_point, OutputIterator output_it) { - // typedef typename Kernel::Point_d Point_d; - // typedef typename Kernel::FT FT; - // typedef CGAL::Search_traits< - // FT, Point_d, - // typename Kernel::Cartesian_const_iterator_d, - // typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; - - // typedef CGAL::Search_traits_adapter< std::ptrdiff_t, Point_d*, Traits_base > STraits; - // typedef CGAL::Fuzzy_sphere< STraits > Fuzzy_sphere; - - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - int nb_points = boost::size(points); - assert(nb_points >= final_size); - - Clock t; - Gudhi::spatial_searching::Spatial_tree_data_structure< Kernel, Point_container> tree(points); - t.end(); - //std::cout << "Constructed the Kd tree: " << t.num_seconds() << " s." << std::endl; - - //CGAL::Fuzzy_sphere< CGAL::Search_trai> - - int current_number_of_landmarks = 0; // counter for landmarks - const double infty = std::numeric_limits::infinity(); // infinity (see next entry) - double curr_max_dist = infty; // used for defining the furhest point from L - std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from points - - // Choose randomly the first landmark - int curr_max_w = starting_point; - - 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++ = points[curr_max_w]; - // std::cout << curr_max_w << "\n"; - //for (auto& p : points) { - auto search = tree.query_incremental_ANN(points[curr_max_w]); - auto search_it = search.begin(); - while (search_it != search.end() && search_it->second <= curr_max_dist ) { - //std::cout << search_it->second << " " << curr_max_dist << "\n"; - if (dist_to_L[search_it->first] > search_it->second) - dist_to_L[search_it->first] = search_it->second; - search_it++; - } - // choose the next curr_max_w - curr_max_dist = 0; - for (unsigned i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - } - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &points, - int final_size, - OutputIterator output_it) - { // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1, 6); int starting_point = dis(gen); - - choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); + choose_by_farthest_point(k, points, final_size, starting_point, output_it); } - } // namespace subsampling diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index dff2cd4e..5f705de6 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -24,15 +24,14 @@ // # define TBB_USE_THREADING_TOOL // #endif -// #define BOOST_TEST_DYN_LINK -// #define BOOST_TEST_MODULE "test_choose_farthest_point" -//#include -//#include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "witness_complex_points" +#include +#include #include #include #include -#include #include @@ -41,52 +40,18 @@ typedef typename K::FT FT; typedef typename K::Point_d Point_d; -//BOOST_AUTO_TEST_CASE(test_choose_farthest_point) -int main() { - std::vector< Point_d > points, results, results2; - K k; - Clock t; - // Add grid points (810000 points) - for (FT i = 0; i < 30; i += 1.0) - for (FT j = 0; j < 30; j += 1.0) - for (FT k = 0; k < 30; k += 1.0) - for (FT l = 0; l < 30; l += 1.0) +BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { + std::vector< Point_d > points, landmarks; + // Add grid points (625 points) + for (FT i = 0; i < 5; i += 1.0) + for (FT j = 0; j < 5; j += 1.0) + for (FT k = 0; k < 5; k += 1.0) + for (FT l = 0; l < 5; l += 1.0) points.push_back(Point_d(std::vector({i, j, k, l}))); - unsigned final_size = 100, numeral = 1; - std::cout << "Test New Old\n"; - while (final_size < 100001) { - std::cout << final_size << ": "; - results.clear(); - t.begin(); - Gudhi::subsampling::choose_by_farthest_point(k, points, final_size, 0, std::back_inserter(results)); - t.end(); - std::cout << t.num_seconds() << " s, "; - - // std::cout << "New algorithm result:\n"; - // for (auto p: results) - // std::cout << p << std::endl; - - results2.clear(); - t.begin(); - Gudhi::subsampling::choose_by_farthest_point_old(k, points, final_size, 0, std::back_inserter(results2)); - t.end(); - std::cout << t.num_seconds() << " s" << std::endl; - - - // std::cout << "Old algorithm result:\n"; - // for (auto p: results2) - // std::cout << p << std::endl; + landmarks.clear(); + K k; + Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - assert(results.size() == final_size); - assert(results2.size() == final_size); - assert(results == results2); - - switch (numeral) { - case 1: numeral = 2; final_size *= 2; break; - case 2: numeral = 5; final_size = final_size/2*5; break; - case 5: numeral = 1; final_size *= 2; break; - default: assert(false); - } - } + assert(landmarks.size() == 100); } -- cgit v1.2.3 From cbc50d7ad49ae57461a42935e9c3d4b848fa9b24 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 14:26:59 +0000 Subject: Fix #include git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1344 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e95475a01b2717bfbbe980554d0882e30996e5ad --- src/Witness_complex/example/witness_complex_from_file.cpp | 2 +- src/Witness_complex/example/witness_complex_sphere.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index ba348f9b..17b63dcf 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 2ea7376f..495a5895 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From 9eaeb5892014e6c516a90a17016cf135123fcbb3 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 14:27:15 +0000 Subject: Point_container => Point_range git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1345 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 11cabe4d1928341da570b3eab465c3bb9ee0e46d --- src/Subsampling/include/gudhi/sparsify_point_set.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 09c4af13..b4536ec8 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -42,15 +42,15 @@ namespace subsampling { * */ -template +template void sparsify_point_set( - const Kernel &k, Point_container const& input_pts, + const Kernel &k, Point_range const& input_pts, typename Kernel::FT min_squared_dist, OutputIterator output_it) { typedef typename Gudhi::spatial_searching::Spatial_tree_data_structure< - Kernel, Point_container> Points_ds; + Kernel, Point_range> Points_ds; typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -65,7 +65,7 @@ sparsify_point_set( // Parse the input points, and add them if they are not too close to // the other points std::size_t pt_idx = 0; - for (typename Point_container::const_iterator it_pt = input_pts.begin() ; + for (typename Point_range::const_iterator it_pt = input_pts.begin() ; it_pt != input_pts.end(); ++it_pt, ++pt_idx) { -- 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 2455525b1583b7a7b4c38d0637a1e0507cf5181d Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 4 Aug 2016 13:38:18 +0000 Subject: Use BOOST_CHECK instead of assert git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1401 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6822fcbda4e9fdaa8a5850b4042a79800c8c019a --- src/Subsampling/test/test_choose_farthest_point.cpp | 2 +- src/Subsampling/test/test_pick_random_points.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 5f705de6..a1929924 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -53,5 +53,5 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { K k; Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - assert(landmarks.size() == 100); + BOOST_CHECK(landmarks.size() == 100); } diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 8156160e..d74f992f 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -60,6 +60,6 @@ int main() { std::cout << "landmark vector contains: "; for (auto l: results) std::cout << l << "\n"; - assert(results.size() == 5); + BOOST_CHECK(results.size() == 5); } -- cgit v1.2.3 From 6cdf1246015e1ce8c87a938f7fb2ccde787e5d4c Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 5 Aug 2016 08:30:29 +0000 Subject: Added the random_pick_example to the doc intro git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1417 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 19f7562d5c499f2967e371610067ba0e1c74306c --- src/Subsampling/doc/Intro_subsampling.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 5ccab3af..aed41430 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -53,6 +53,11 @@ namespace subsampling { * * \include Subsampling/example_choose_by_farthest_point.cpp * + * \section randompointexamples Example: pick_random_points + * + * This example outputs a subset of 100 points picked randomly. + * + * \include Subsampling/example_pick_random_points.cpp * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ -- 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') 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') 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') 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 4da47219339ce8bee2a42d1ffcf6e5c9d0d61e0b Mon Sep 17 00:00:00 2001 From: cjamin Date: Sat, 27 Aug 2016 08:13:46 +0000 Subject: Fix test of pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1459 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6963479b6c53c668542313aff2392b8449cb0cc3 --- src/Subsampling/test/test_pick_random_points.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index d74f992f..16841eff 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -24,6 +24,10 @@ // # define TBB_USE_THREADING_TOOL // #endif +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test pick_random_points +#include + #include #include #include @@ -31,7 +35,8 @@ #include -int main() { +BOOST_AUTO_TEST_CASE(test_pick_random_points) +{ typedef CGAL::Epick_d K; typedef typename K::FT FT; typedef typename K::Point_d Point_d; @@ -53,8 +58,7 @@ int main() { vect.push_back(Point_d(std::vector({1,1,0,1}))); vect.push_back(Point_d(std::vector({1,1,1,0}))); vect.push_back(Point_d(std::vector({1,1,1,1}))); - - + std::vector results; Gudhi::subsampling::pick_random_points(vect, 5, std::back_inserter(results)); std::cout << "landmark vector contains: "; -- cgit v1.2.3 From 6d54bc010287d731f5d9a054491beb229c972ba3 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 30 Aug 2016 14:58:51 +0000 Subject: Fix function name git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1462 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f11c5f25649eae2e85dffe02d78675ff4bc3db8c --- src/Subsampling/include/gudhi/sparsify_point_set.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 3923bf74..ca31098b 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -87,7 +87,7 @@ sparsify_point_set( *output_it++ = *it_pt; - auto ins_range = points_ds.query_incremental_ANN(*it_pt); + auto ins_range = points_ds.query_incremental_nearest_neighbors(*it_pt); // If another point Q is closer that min_squared_dist, mark Q to be dropped for (auto const& neighbor : ins_range) -- 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') 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') 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 661df189e5a0c5cdfa12607d03da4cd59c51018f Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 2 Sep 2016 13:15:33 +0000 Subject: Mark comment #1 + Vincent comment #1 git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1472 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e9a2fb8d8f9e11c60326203c7e0e46cdb2b12435 --- .../include/gudhi/choose_by_farthest_point.h | 28 +++++++++++----------- .../example/witness_complex_from_file.cpp | 2 +- .../example/witness_complex_sphere.cpp | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 8dea19be..b09192d9 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -46,7 +46,7 @@ namespace subsampling { * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the * current chosen point set to the subsampling. * The iteration starts with the landmark `starting point`. - * \details It chooses `final_size` points from a random access range `points` and + * \details It chooses `final_size` points from a random access range `input_pts` and * outputs it in the output iterator `output_it`. * */ @@ -54,31 +54,31 @@ namespace subsampling { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &points, - int final_size, - int starting_point, + void choose_by_farthest_point( Kernel const &k, + Point_container const &input_pts, + unsigned final_size, + unsigned starting_point, OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - int nb_points = boost::size(points); + int nb_points = boost::size(input_pts); assert(nb_points >= final_size); - int current_number_of_landmarks = 0; // counter for landmarks + unsigned 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 points + std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from input_pts int curr_max_w = starting_point; 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++ = points[curr_max_w]; + *output_it++ = input_pts[curr_max_w]; // std::cout << curr_max_w << "\n"; unsigned i = 0; - for (auto& p : points) { - double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); + for (auto& p : input_pts) { + double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); if (curr_dist < dist_to_L[i]) dist_to_L[i] = curr_dist; ++i; @@ -98,7 +98,7 @@ namespace subsampling { * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the * current chosen point set to the subsampling. * The iteration starts with a random landmark. - * \details It chooses `final_size` points from a random access range `points` and + * \details It chooses `final_size` points from a random access range `input_pts` and * outputs it in the output iterator `output_it`. * */ @@ -106,7 +106,7 @@ namespace subsampling { typename Point_container, typename OutputIterator> void choose_by_farthest_point( Kernel& k, - Point_container const &points, + Point_container const &input_pts, int final_size, OutputIterator output_it) { @@ -115,7 +115,7 @@ namespace subsampling { std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1, 6); int starting_point = dis(gen); - choose_by_farthest_point(k, points, final_size, starting_point, output_it); + choose_by_farthest_point(k, input_pts, final_size, starting_point, output_it); } } // namespace subsampling diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 17b63dcf..0d82ee38 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -87,7 +87,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); end = clock(); std::cout << "Landmark choice for " << nbL << " landmarks took " diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 495a5895..d0c4b4c4 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -76,7 +76,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); // Compute witness complex -- 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') 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') 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') 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') 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') 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 d38ddb2d2b6943e1e9b26694ac624f85263ad24b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 09:45:31 +0000 Subject: Changed choose_by_farthest_point -> choose_n_farthest_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1513 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 287ef6f3be6e4db4616ad92ff7369cd7722a1f2d --- src/Subsampling/example/CMakeLists.txt | 4 ++-- src/Subsampling/test/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 532440eb..b6d71dac 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -13,8 +13,8 @@ if(CGAL_FOUND) add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) - add_executable( Subsampling_example_choose_by_farthest_point example_choose_by_farthest_point.cpp ) - #target_link_libraries(Subsampling_example_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + 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}) diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 18fc84f4..95241cd2 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -23,8 +23,8 @@ if(CGAL_FOUND) 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 ${CGAL_LIBRARY} ${Boost_SYSTEM_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}) 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}) -- cgit v1.2.3 From e8183d76c99eac5458d8f72cb4479cc680c6a6c4 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 09:59:15 +0000 Subject: Changed the names of files as well git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1514 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: df3b82dc1d07b5d51b1c1bed4b5abd823129d4a8 --- .../example/example_choose_by_farthest_point.cpp | 29 ----- .../example/example_choose_n_farthest_points.cpp | 29 +++++ .../include/gudhi/choose_by_farthest_point.h | 125 --------------------- .../include/gudhi/choose_n_farthest_points.h | 125 +++++++++++++++++++++ .../test/test_choose_farthest_point.cpp | 57 ---------- .../test/test_choose_n_farthest_points.cpp | 57 ++++++++++ 6 files changed, 211 insertions(+), 211 deletions(-) delete mode 100644 src/Subsampling/example/example_choose_by_farthest_point.cpp create mode 100644 src/Subsampling/example/example_choose_n_farthest_points.cpp delete mode 100644 src/Subsampling/include/gudhi/choose_by_farthest_point.h create mode 100644 src/Subsampling/include/gudhi/choose_n_farthest_points.h delete mode 100644 src/Subsampling/test/test_choose_farthest_point.cpp create mode 100644 src/Subsampling/test/test_choose_n_farthest_points.cpp (limited to 'src') diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp deleted file mode 100644 index 29ecbf9b..00000000 --- a/src/Subsampling/example/example_choose_by_farthest_point.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include -#include - -#include -#include -#include - -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - 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)}))); - - K k; - std::vector results; - Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); - std::cout << "Before sparsification: " << points.size() << " points.\n"; - std::cout << "After sparsification: " << results.size() << " points.\n"; - - return 0; -} diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp new file mode 100644 index 00000000..9955d0ec --- /dev/null +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -0,0 +1,29 @@ +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h deleted file mode 100644 index b09192d9..00000000 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ /dev/null @@ -1,125 +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): 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 . - */ - -#ifndef CHOOSE_BY_FARTHEST_POINT_H_ -#define CHOOSE_BY_FARTHEST_POINT_H_ - -#include - -#include - -#include - -#include -#include -#include - -#include -#include // for sort -#include -#include - -namespace Gudhi { - -namespace subsampling { - /** - * \ingroup subsampling - * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the - * current chosen point set to the subsampling. - * The iteration starts with the landmark `starting point`. - * \details It chooses `final_size` points from a random access range `input_pts` and - * outputs it in the output iterator `output_it`. - * - */ - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point( Kernel const &k, - Point_container const &input_pts, - unsigned final_size, - unsigned starting_point, - OutputIterator output_it) - { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - int nb_points = boost::size(input_pts); - assert(nb_points >= final_size); - - unsigned 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 - - int curr_max_w = starting_point; - - 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"; - unsigned i = 0; - for (auto& p : input_pts) { - double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - // choose the next curr_max_w - curr_max_dist = 0; - for (i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - } - - /** - * \ingroup subsampling - * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the - * current chosen point set to the subsampling. - * The iteration starts with a random landmark. - * \details It chooses `final_size` points from a random access range `input_pts` and - * outputs it in the output iterator `output_it`. - * - */ - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &input_pts, - int final_size, - OutputIterator output_it) - { - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int starting_point = dis(gen); - choose_by_farthest_point(k, input_pts, final_size, starting_point, output_it); - } - -} // namespace subsampling - -} // namespace Gudhi - -#endif // CHOOSE_BY_FARTHEST_POINT_H_ diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h new file mode 100644 index 00000000..b999213e --- /dev/null +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -0,0 +1,125 @@ +/* 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 . + */ + +#ifndef CHOOSE_N_FARTHEST_POINTS_H_ +#define CHOOSE_N_FARTHEST_POINTS_H_ + +#include + +#include + +#include + +#include +#include +#include + +#include +#include // for sort +#include +#include + +namespace Gudhi { + +namespace subsampling { + /** + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * The iteration starts with the landmark `starting point`. + * \details It chooses `final_size` points from a random access range `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_n_farthest_points( Kernel const &k, + Point_container const &input_pts, + unsigned final_size, + unsigned starting_point, + OutputIterator output_it) + { + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + int nb_points = boost::size(input_pts); + assert(nb_points >= final_size); + + unsigned 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 + + int curr_max_w = starting_point; + + 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"; + unsigned i = 0; + for (auto& p : input_pts) { + double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + ++i; + } + // choose the next curr_max_w + curr_max_dist = 0; + for (i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } + } + } + + /** + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * The iteration starts with a random landmark. + * \details It chooses `final_size` points from a random access range `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_n_farthest_points( Kernel& k, + Point_container const &input_pts, + int final_size, + OutputIterator output_it) + { + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int starting_point = dis(gen); + choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); + } + +} // namespace subsampling + +} // namespace Gudhi + +#endif // CHOOSE_N_FARTHEST_POINTS_H_ diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp deleted file mode 100644 index a1929924..00000000 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ /dev/null @@ -1,57 +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): 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 - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "witness_complex_points" -#include -#include - -#include -#include -#include - -#include - -typedef CGAL::Epick_d K; -typedef typename K::FT FT; -typedef typename K::Point_d Point_d; - - -BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { - std::vector< Point_d > points, landmarks; - // Add grid points (625 points) - for (FT i = 0; i < 5; i += 1.0) - for (FT j = 0; j < 5; j += 1.0) - for (FT k = 0; k < 5; k += 1.0) - for (FT l = 0; l < 5; l += 1.0) - points.push_back(Point_d(std::vector({i, j, k, l}))); - - landmarks.clear(); - K k; - Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - - BOOST_CHECK(landmarks.size() == 100); -} diff --git a/src/Subsampling/test/test_choose_n_farthest_points.cpp b/src/Subsampling/test/test_choose_n_farthest_points.cpp new file mode 100644 index 00000000..f79a4dfb --- /dev/null +++ b/src/Subsampling/test/test_choose_n_farthest_points.cpp @@ -0,0 +1,57 @@ +/* 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 + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "witness_complex_points" +#include +#include + +#include +#include +#include + +#include + +typedef CGAL::Epick_d K; +typedef typename K::FT FT; +typedef typename K::Point_d Point_d; + + +BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { + std::vector< Point_d > points, landmarks; + // Add grid points (625 points) + for (FT i = 0; i < 5; i += 1.0) + for (FT j = 0; j < 5; j += 1.0) + for (FT k = 0; k < 5; k += 1.0) + for (FT l = 0; l < 5; l += 1.0) + points.push_back(Point_d(std::vector({i, j, k, l}))); + + landmarks.clear(); + K k; + Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(landmarks)); + + BOOST_CHECK(landmarks.size() == 100); +} -- cgit v1.2.3 From 6ad5ac6794ebc46638cd1f0862a553f40d2557d7 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 16:14:38 +0000 Subject: Renamed pick_random_points -> pick_n_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1516 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 45cc8cca9debf56dd0d21762e537649dd92d9a4d --- src/Subsampling/doc/Intro_subsampling.h | 4 +- src/Subsampling/example/CMakeLists.txt | 2 +- .../example/example_pick_n_random_points.cpp | 29 ++++++++ .../example/example_pick_random_points.cpp | 29 -------- .../include/gudhi/pick_n_random_points.h | 82 ++++++++++++++++++++++ src/Subsampling/include/gudhi/pick_random_points.h | 82 ---------------------- src/Subsampling/test/CMakeLists.txt | 4 +- src/Subsampling/test/test_pick_n_random_points.cpp | 69 ++++++++++++++++++ src/Subsampling/test/test_pick_random_points.cpp | 69 ------------------ .../example/witness_complex_from_file.cpp | 4 +- .../example/witness_complex_sphere.cpp | 4 +- .../test/witness_complex_points.cpp | 4 +- 12 files changed, 191 insertions(+), 191 deletions(-) create mode 100644 src/Subsampling/example/example_pick_n_random_points.cpp delete mode 100644 src/Subsampling/example/example_pick_random_points.cpp create mode 100644 src/Subsampling/include/gudhi/pick_n_random_points.h delete mode 100644 src/Subsampling/include/gudhi/pick_random_points.h create mode 100644 src/Subsampling/test/test_pick_n_random_points.cpp delete mode 100644 src/Subsampling/test/test_pick_random_points.cpp (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index aed41430..06aee2fc 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -53,11 +53,11 @@ namespace subsampling { * * \include Subsampling/example_choose_by_farthest_point.cpp * - * \section randompointexamples Example: pick_random_points + * \section randompointexamples Example: pick_n_random_points * * This example outputs a subset of 100 points picked randomly. * - * \include Subsampling/example_pick_random_points.cpp + * \include Subsampling/example_pick_n_random_points.cpp * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index b6d71dac..4710cf00 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -11,7 +11,7 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) + 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}) diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp new file mode 100644 index 00000000..d2f063ba --- /dev/null +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -0,0 +1,29 @@ +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + 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)}))); + + K k; + std::vector results; + Gudhi::subsampling::pick_n_random_points(points, 100, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} diff --git a/src/Subsampling/example/example_pick_random_points.cpp b/src/Subsampling/example/example_pick_random_points.cpp deleted file mode 100644 index 348b1b81..00000000 --- a/src/Subsampling/example/example_pick_random_points.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include -#include - -#include -#include -#include - -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - 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)}))); - - K k; - std::vector results; - Gudhi::subsampling::pick_random_points(points, 100, std::back_inserter(results)); - std::cout << "Before sparsification: " << points.size() << " points.\n"; - std::cout << "After sparsification: " << results.size() << " points.\n"; - - return 0; -} diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h new file mode 100644 index 00000000..4ca1fafc --- /dev/null +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -0,0 +1,82 @@ +/* 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 . + */ + +#ifndef PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + +namespace subsampling { + + /** + * \ingroup subsampling + * \brief Subsample a point set by picking random vertices. + * + * \details It chooses `final_size` distinct points from a random access range `points` + * and outputs them to the output iterator `output_it`. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_n_random_points(Point_container const &points, + unsigned final_size, + OutputIterator output_it) { +#ifdef GUDHI_SUBS_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= final_size); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(final_size); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_SUBS_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + } + +} // namesapce subsampling + +} // namespace Gudhi + +#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h deleted file mode 100644 index 732ae3f7..00000000 --- a/src/Subsampling/include/gudhi/pick_random_points.h +++ /dev/null @@ -1,82 +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): 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 . - */ - -#ifndef PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - -namespace subsampling { - - /** - * \ingroup subsampling - * \brief Subsample a point set by picking random vertices. - * - * \details It chooses `final_size` distinct points from a random access range `points` - * and outputs them to the output iterator `output_it`. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned final_size, - OutputIterator output_it) { -#ifdef GUDHI_SUBS_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= final_size); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); - - std::random_device rd; - std::mt19937 g(rd()); - - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(final_size); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_SUBS_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - } - -} // namesapce subsampling - -} // namespace Gudhi - -#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 95241cd2..c9e48416 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -20,8 +20,8 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) 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_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}) diff --git a/src/Subsampling/test/test_pick_n_random_points.cpp b/src/Subsampling/test/test_pick_n_random_points.cpp new file mode 100644 index 00000000..6c8dbea2 --- /dev/null +++ b/src/Subsampling/test/test_pick_n_random_points.cpp @@ -0,0 +1,69 @@ +/* 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 + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test pick_n_random_points +#include + +#include +#include +#include + +#include + + +BOOST_AUTO_TEST_CASE(test_pick_n_random_points) +{ + typedef CGAL::Epick_d K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + std::vector vect; + vect.push_back(Point_d(std::vector({0,0,0,0}))); + vect.push_back(Point_d(std::vector({0,0,0,1}))); + vect.push_back(Point_d(std::vector({0,0,1,0}))); + vect.push_back(Point_d(std::vector({0,0,1,1}))); + vect.push_back(Point_d(std::vector({0,1,0,0}))); + vect.push_back(Point_d(std::vector({0,1,0,1}))); + vect.push_back(Point_d(std::vector({0,1,1,0}))); + vect.push_back(Point_d(std::vector({0,1,1,1}))); + vect.push_back(Point_d(std::vector({1,0,0,0}))); + vect.push_back(Point_d(std::vector({1,0,0,1}))); + vect.push_back(Point_d(std::vector({1,0,1,0}))); + vect.push_back(Point_d(std::vector({1,0,1,1}))); + vect.push_back(Point_d(std::vector({1,1,0,0}))); + vect.push_back(Point_d(std::vector({1,1,0,1}))); + vect.push_back(Point_d(std::vector({1,1,1,0}))); + vect.push_back(Point_d(std::vector({1,1,1,1}))); + + std::vector results; + Gudhi::subsampling::pick_n_random_points(vect, 5, std::back_inserter(results)); + std::cout << "landmark vector contains: "; + for (auto l: results) + std::cout << l << "\n"; + + BOOST_CHECK(results.size() == 5); +} diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp deleted file mode 100644 index 16841eff..00000000 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ /dev/null @@ -1,69 +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): 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 - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE Subsampling - test pick_random_points -#include - -#include -#include -#include - -#include - - -BOOST_AUTO_TEST_CASE(test_pick_random_points) -{ - typedef CGAL::Epick_d K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - std::vector vect; - vect.push_back(Point_d(std::vector({0,0,0,0}))); - vect.push_back(Point_d(std::vector({0,0,0,1}))); - vect.push_back(Point_d(std::vector({0,0,1,0}))); - vect.push_back(Point_d(std::vector({0,0,1,1}))); - vect.push_back(Point_d(std::vector({0,1,0,0}))); - vect.push_back(Point_d(std::vector({0,1,0,1}))); - vect.push_back(Point_d(std::vector({0,1,1,0}))); - vect.push_back(Point_d(std::vector({0,1,1,1}))); - vect.push_back(Point_d(std::vector({1,0,0,0}))); - vect.push_back(Point_d(std::vector({1,0,0,1}))); - vect.push_back(Point_d(std::vector({1,0,1,0}))); - vect.push_back(Point_d(std::vector({1,0,1,1}))); - vect.push_back(Point_d(std::vector({1,1,0,0}))); - vect.push_back(Point_d(std::vector({1,1,0,1}))); - vect.push_back(Point_d(std::vector({1,1,1,0}))); - vect.push_back(Point_d(std::vector({1,1,1,1}))); - - std::vector results; - Gudhi::subsampling::pick_random_points(vect, 5, std::back_inserter(results)); - std::cout << "landmark vector contains: "; - for (auto l: results) - std::cout << l << "\n"; - - BOOST_CHECK(results.size() == 5); -} diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 0d82ee38..5e9f0e81 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); end = clock(); std::cout << "Landmark choice for " << nbL << " landmarks took " diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index d0c4b4c4..e6f88274 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); // Compute witness complex diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index 596152f4..d40bbf14 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::pick_random_points(points, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(points, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); assert(!knn.empty()); WitnessComplex witnessComplex1(knn, 100, 3, complex1); -- cgit v1.2.3 From a79e15a3581a26cd09fd22fe589ae9ee2315ea0b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 16:20:32 +0000 Subject: Changed the name of farthest point in intro doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1517 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 83ad658d6fa02e8a1524bf0f363c8bac522c9406 --- src/Subsampling/doc/Intro_subsampling.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 06aee2fc..f8eb2fdd 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -46,12 +46,12 @@ namespace subsampling { * * \include Subsampling/example_sparsify_point_set.cpp * - * \section farthestpointexamples Example: choose_by_farthest_point + * \section farthestpointexamples Example: choose_n_farthest_points * * This example outputs a subset of 100 points obtained by González algorithm, * starting with a random point. * - * \include Subsampling/example_choose_by_farthest_point.cpp + * \include Subsampling/example_choose_n_farthest_points.cpp * * \section randompointexamples Example: pick_n_random_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') 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') 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 731ebae307759cb1fa05254c7ba8cd922e9eda25 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 21 Sep 2016 09:50:55 +0000 Subject: Add packages in GUDHI_MODULES git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1522 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fa1d4b4f1e0f6c437817e7bf6453d9fb1ca09df6 --- src/cmake/modules/GUDHI_user_version_target.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cmake/modules/GUDHI_user_version_target.txt b/src/cmake/modules/GUDHI_user_version_target.txt index 805f0a83..0ab36cfc 100644 --- a/src/cmake/modules/GUDHI_user_version_target.txt +++ b/src/cmake/modules/GUDHI_user_version_target.txt @@ -48,7 +48,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11) add_custom_command(TARGET user_version PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/GudhUI ${GUDHI_USER_VERSION_DIR}/GudhUI) - set(GUDHI_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Contraction;Hasse_complex;Persistent_cohomology;Simplex_tree;Skeleton_blocker;Witness_complex") + set(GUDHI_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Contraction;Hasse_complex;Persistent_cohomology;Simplex_tree;Skeleton_blocker;Spatial_searching;Subsampling;Witness_complex") foreach(GUDHI_MODULE ${GUDHI_MODULES}) # doc files -- 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') 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 aa994dbd8dadfd4be416f13b13721e7e13c3623a Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 11:58:31 +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@1536 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc980f30c107b39f8a47e18deb23820b411a9201 --- src/Subsampling/example/CMakeLists.txt | 4 ++-- src/Subsampling/test/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 4710cf00..6bf717f7 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(Subsampling_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) @@ -22,7 +22,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.0 is required.") + 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.") diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index c9e48416..72de5ac7 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/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) @@ -32,7 +32,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") 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 Subsampling 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') 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') 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') 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') 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 d68d79f7274ecc01ec539f74e04e9e4f940751ba Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 4 Oct 2016 09:07:21 +0000 Subject: Changed the second choose_n_farthest_points' incostistencies git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1614 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 285b607d598b0f50efd6d4f1f3d4e38dfc2d097a --- src/Subsampling/include/gudhi/choose_n_farthest_points.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index 8bfb38a4..d0f7377a 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -105,9 +105,9 @@ namespace subsampling { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_n_farthest_points( Kernel& k, + void choose_n_farthest_points( Kernel const& k, Point_container const &input_pts, - int final_size, + unsigned final_size, OutputIterator output_it) { // Choose randomly the first landmark -- 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') 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') 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') 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') 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') 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') 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 9356208327a9784b570b96ce5007f785c2abebef Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:55:48 +0000 Subject: Don't use Point_d(std::array... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1624 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b91315785cc6fbab1843b8f0e2d1778e920998b9 --- src/Subsampling/example/example_choose_n_farthest_points.cpp | 2 +- src/Subsampling/example/example_pick_n_random_points.cpp | 2 +- src/Subsampling/example/example_sparsify_point_set.cpp | 2 +- src/Subsampling/test/test_sparsify_point_set.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp index 9955d0ec..7afc8033 100644 --- a/src/Subsampling/example/example_choose_n_farthest_points.cpp +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -17,7 +17,7 @@ int main (void) 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.push_back(Point_d(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); K k; std::vector results; diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp index d2f063ba..e0d3b789 100644 --- a/src/Subsampling/example/example_pick_n_random_points.cpp +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -17,7 +17,7 @@ int main (void) 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.push_back(Point_d(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); K k; std::vector results; diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index cb5ccf0b..7c8cf8b0 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -17,7 +17,7 @@ int main (void) 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.push_back(Point_d(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); K k; std::vector results; diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 61f6fa18..9eebbcc8 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(test_sparsify_point_set) 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.push_back(Point_d(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); K k; std::vector results; -- cgit v1.2.3 From e7edd8a70065e882da088de12aba86d3a8d82bb7 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:56:12 +0000 Subject: Use std::size_t instead of unsigned git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1625 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: cfc0013c1247512eb4899809975266a971d57c34 --- src/Subsampling/include/gudhi/pick_n_random_points.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h index 4ca1fafc..b8f4900a 100644 --- a/src/Subsampling/include/gudhi/pick_n_random_points.h +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -25,6 +25,7 @@ #include +#include #include // random_device, mt19937 #include // shuffle #include // iota @@ -48,13 +49,13 @@ namespace subsampling { template void pick_n_random_points(Point_container const &points, - unsigned final_size, + std::size_t final_size, OutputIterator output_it) { #ifdef GUDHI_SUBS_PROFILING Gudhi::Clock t; #endif - unsigned nbP = boost::size(points); + std::size_t nbP = boost::size(points); assert(nbP >= final_size); std::vector landmarks(nbP); std::iota(landmarks.begin(), landmarks.end(), 0); -- cgit v1.2.3 From 404297f53b222f34a436638117ffb1affca18e7b Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 5 Oct 2016 09:36:37 +0000 Subject: Warning FT and include array in 2 files git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1642 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f25797a941de0f814b2bb1d16a0a3b31cd848282 --- src/Subsampling/example/example_choose_n_farthest_points.cpp | 2 -- src/Subsampling/example/example_pick_n_random_points.cpp | 2 -- 2 files changed, 4 deletions(-) (limited to 'src') diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp index 7afc8033..4bcb0eb9 100644 --- a/src/Subsampling/example/example_choose_n_farthest_points.cpp +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -3,14 +3,12 @@ #include #include -#include #include #include 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/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp index e0d3b789..7b4379e4 100644 --- a/src/Subsampling/example/example_pick_n_random_points.cpp +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -3,14 +3,12 @@ #include #include -#include #include #include int main (void) { 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 9f0861b57c2479ffece89e2e4e949a66ef9b47ed Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 5 Oct 2016 09:56:06 +0000 Subject: Changed unsigned to std::size_t git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1643 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7282a69d4d3bde59727b42b309ddb6b7e1a5a548 --- src/Subsampling/include/gudhi/choose_n_farthest_points.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index d0f7377a..a4719f56 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -56,27 +56,27 @@ namespace subsampling { typename OutputIterator> void choose_n_farthest_points( Kernel const &k, Point_container const &input_pts, - unsigned final_size, - unsigned starting_point, + std::size_t final_size, + std::size_t starting_point, OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - int nb_points = boost::size(input_pts); + std::size_t nb_points = boost::size(input_pts); assert(nb_points >= final_size); - unsigned current_number_of_landmarks = 0; // counter for landmarks + 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 - int curr_max_w = starting_point; + std::size_t curr_max_w = starting_point; 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"; - unsigned i = 0; + std::size_t i = 0; for (auto& p : input_pts) { double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); if (curr_dist < dist_to_L[i]) -- 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') 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') 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') 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 ad4a82843c8268a9e9d12e607a13ee323831b597 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 15:13:10 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1660 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8a8a944168adfddbf848c122fb9d9cf78b75d36c --- src/Subsampling/include/gudhi/pick_n_random_points.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h index b8f4900a..52842a54 100644 --- a/src/Subsampling/include/gudhi/pick_n_random_points.h +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -20,8 +20,10 @@ * along with this program. If not, see . */ -#ifndef PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ +#ifndef PICK_N_RANDOM_POINTS_H_ +#define PICK_N_RANDOM_POINTS_H_ + +#include #include @@ -30,7 +32,7 @@ #include // shuffle #include // iota #include -#include +#include namespace Gudhi { @@ -62,13 +64,13 @@ namespace subsampling { std::random_device rd; std::mt19937 g(rd()); - + std::shuffle(landmarks.begin(), landmarks.end(), g); landmarks.resize(final_size); for (int l: landmarks) *output_it++ = points[l]; - + #ifdef GUDHI_SUBS_PROFILING t.end(); std::cerr << "Random landmark choice took " << t.num_seconds() @@ -76,8 +78,8 @@ namespace subsampling { #endif } -} // namesapce subsampling - +} // namespace subsampling + } // namespace Gudhi -#endif // PICK_RANDOM_POINTS_H_ +#endif // PICK_N_RANDOM_POINTS_H_ -- cgit v1.2.3 From 3ed1e6ab9d5c122427e0a7308bd5b5a2d49d7557 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 15:23:28 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1661 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 880ca1a8686938b8ce5f0498848583fa258df4a0 --- src/Subsampling/include/gudhi/sparsify_point_set.h | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 607555b4..edb9869b 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef GUDHI_SPARSIFY_POINT_SET_H -#define GUDHI_SPARSIFY_POINT_SET_H +#ifndef SPARSIFY_POINT_SET_H_ +#define SPARSIFY_POINT_SET_H_ #include #ifdef GUDHI_SUBSAMPLING_PROFILING @@ -60,8 +60,7 @@ void sparsify_point_set( const Kernel &k, Point_range const& input_pts, typename Kernel::FT min_squared_dist, - OutputIterator output_it) -{ + OutputIterator output_it) { typedef typename Gudhi::spatial_searching::Kd_tree_search< Kernel, Point_range> Points_ds; @@ -80,8 +79,7 @@ sparsify_point_set( std::size_t pt_idx = 0; for (typename Point_range::const_iterator it_pt = input_pts.begin() ; it_pt != input_pts.end(); - ++it_pt, ++pt_idx) - { + ++it_pt, ++pt_idx) { if (dropped_points[pt_idx]) continue; @@ -90,19 +88,17 @@ sparsify_point_set( auto ins_range = points_ds.query_incremental_nearest_neighbors(*it_pt); // If another point Q is closer that min_squared_dist, mark Q to be dropped - for (auto const& neighbor : ins_range) - { + for (auto const& neighbor : ins_range) { std::size_t neighbor_point_idx = neighbor.first; // If the neighbor is too close, we drop the neighbor - if (neighbor.second < min_squared_dist) - { - // N.B.: If neighbor_point_idx < pt_idx, + if (neighbor.second < min_squared_dist) { + // N.B.: If neighbor_point_idx < pt_idx, // dropped_points[neighbor_point_idx] is already true but adding a // test doesn't make things faster, so why bother? dropped_points[neighbor_point_idx] = true; - } - else + } else { break; + } } } @@ -113,7 +109,7 @@ sparsify_point_set( #endif } -} // namespace subsampling -} // namespace Gudhi +} // namespace subsampling +} // namespace Gudhi -#endif // GUDHI_POINT_CLOUD_H +#endif // SPARSIFY_POINT_SET_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') 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 7e417a80188b8ed4051f73f26e9899f94c33dc1e Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 17:13:24 +0000 Subject: fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1663 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 78cab9749df2feaf6d47bf253d4449b043e026e7 --- .../example/example_choose_n_farthest_points.cpp | 14 +++++++------- src/Subsampling/example/example_pick_n_random_points.cpp | 14 +++++++------- src/Subsampling/example/example_sparsify_point_set.cpp | 14 +++++++------- src/Subsampling/test/test_choose_n_farthest_points.cpp | 9 ++++----- 4 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp index 4bcb0eb9..533aba74 100644 --- a/src/Subsampling/example/example_choose_n_farthest_points.cpp +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + typedef typename K::Point_d Point_d; + CGAL::Random rd; std::vector points; - for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point_d(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_d(rd.get_double(-1., 1), rd.get_double(-1., 1), + rd.get_double(-1., 1), rd.get_double(-1., 1))); K k; std::vector results; diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp index 7b4379e4..1e38e405 100644 --- a/src/Subsampling/example/example_pick_n_random_points.cpp +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + typedef typename K::Point_d Point_d; + CGAL::Random rd; std::vector points; - for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point_d(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_d(rd.get_double(-1., 1), rd.get_double(-1., 1), + rd.get_double(-1., 1), rd.get_double(-1., 1))); K k; std::vector results; diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index ad68b4c1..b35a18d9 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + typedef typename K::Point_d Point_d; + CGAL::Random rd; std::vector points; - for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point_d(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_d(rd.get_double(-1., 1), rd.get_double(-1., 1), + rd.get_double(-1., 1), rd.get_double(-1., 1))); K k; std::vector results; diff --git a/src/Subsampling/test/test_choose_n_farthest_points.cpp b/src/Subsampling/test/test_choose_n_farthest_points.cpp index f79a4dfb..d064899a 100644 --- a/src/Subsampling/test/test_choose_n_farthest_points.cpp +++ b/src/Subsampling/test/test_choose_n_farthest_points.cpp @@ -35,10 +35,9 @@ #include -typedef CGAL::Epick_d K; -typedef typename K::FT FT; -typedef typename K::Point_d Point_d; - +typedef CGAL::Epick_d K; +typedef typename K::FT FT; +typedef typename K::Point_d Point_d; BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { std::vector< Point_d > points, landmarks; @@ -52,6 +51,6 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { landmarks.clear(); K k; Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(landmarks)); - + BOOST_CHECK(landmarks.size() == 100); } -- cgit v1.2.3 From 5592d57180bee4cdedbe2e99ffd873184e889559 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 17:19:44 +0000 Subject: fixcpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1667 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c6974fc881cae681326777d1e6f8bd7f475f235e --- .../include/gudhi/choose_n_farthest_points.h | 153 ++++++++++----------- .../include/gudhi/pick_n_random_points.h | 53 ++++--- src/Subsampling/include/gudhi/sparsify_point_set.h | 18 +-- 3 files changed, 111 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index a4719f56..60816a29 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -37,89 +37,88 @@ #include // for sort #include #include +#include // for numeric_limits<> namespace Gudhi { namespace subsampling { - /** - * \ingroup subsampling - * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the - * current chosen point set to the subsampling. - * The iteration starts with the landmark `starting point`. - * \details It chooses `final_size` points from a random access range `input_pts` and - * outputs it in the output iterator `output_it`. - * - */ - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_n_farthest_points( Kernel const &k, - Point_container const &input_pts, - std::size_t final_size, - std::size_t starting_point, - OutputIterator output_it) - { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - std::size_t nb_points = boost::size(input_pts); - 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 - - std::size_t curr_max_w = starting_point; - - 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)); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - // choose the next curr_max_w - curr_max_dist = 0; - for (i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } + +/** + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * The iteration starts with the landmark `starting point`. + * \details It chooses `final_size` points from a random access range `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ +template < typename Kernel, +typename Point_container, +typename OutputIterator> +void choose_n_farthest_points(Kernel const &k, + Point_container const &input_pts, + std::size_t final_size, + std::size_t starting_point, + OutputIterator output_it) { + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + std::size_t nb_points = boost::size(input_pts); + 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 + + std::size_t curr_max_w = starting_point; + + 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)); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + ++i; } + // choose the next curr_max_w + curr_max_dist = 0; + for (i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } } - - /** - * \ingroup subsampling - * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the - * current chosen point set to the subsampling. - * The iteration starts with a random landmark. - * \details It chooses `final_size` points from a random access range `input_pts` and - * outputs it in the output iterator `output_it`. - * - */ - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_n_farthest_points( Kernel const& k, - Point_container const &input_pts, - unsigned final_size, - OutputIterator output_it) - { - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int starting_point = dis(gen); - choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); - } - -} // namespace subsampling - +} + +/** + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * The iteration starts with a random landmark. + * \details It chooses `final_size` points from a random access range `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ +template < typename Kernel, +typename Point_container, +typename OutputIterator> +void choose_n_farthest_points(Kernel const& k, + Point_container const &input_pts, + unsigned final_size, + OutputIterator output_it) { + // Choose randomly the first landmark + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 6); + int starting_point = dis(gen); + choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); +} + +} // namespace subsampling + } // namespace Gudhi #endif // CHOOSE_N_FARTHEST_POINTS_H_ diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h index 52842a54..e89b2b2d 100644 --- a/src/Subsampling/include/gudhi/pick_n_random_points.h +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -38,45 +38,44 @@ namespace Gudhi { namespace subsampling { - - /** - * \ingroup subsampling - * \brief Subsample a point set by picking random vertices. - * - * \details It chooses `final_size` distinct points from a random access range `points` - * and outputs them to the output iterator `output_it`. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_n_random_points(Point_container const &points, + +/** + * \ingroup subsampling + * \brief Subsample a point set by picking random vertices. + * + * \details It chooses `final_size` distinct points from a random access range `points` + * and outputs them to the output iterator `output_it`. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ +template +void pick_n_random_points(Point_container const &points, std::size_t final_size, OutputIterator output_it) { #ifdef GUDHI_SUBS_PROFILING - Gudhi::Clock t; + Gudhi::Clock t; #endif - std::size_t nbP = boost::size(points); - assert(nbP >= final_size); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); + std::size_t nbP = boost::size(points); + assert(nbP >= final_size); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); - std::random_device rd; - std::mt19937 g(rd()); + std::random_device rd; + std::mt19937 g(rd()); - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(final_size); + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(final_size); - for (int l: landmarks) - *output_it++ = points[l]; + for (int l : landmarks) + *output_it++ = points[l]; #ifdef GUDHI_SUBS_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() << " seconds." << std::endl; #endif - } +} } // namespace subsampling diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index edb9869b..7ff11b4c 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -32,6 +32,7 @@ #include namespace Gudhi { + namespace subsampling { /** @@ -54,15 +55,14 @@ namespace subsampling { * @param[in] min_squared_dist Minimum squared distance separating the output points. * @param[out] output_it The output iterator. */ - template void sparsify_point_set( - const Kernel &k, Point_range const& input_pts, - typename Kernel::FT min_squared_dist, - OutputIterator output_it) { + const Kernel &k, Point_range const& input_pts, + typename Kernel::FT min_squared_dist, + OutputIterator output_it) { typedef typename Gudhi::spatial_searching::Kd_tree_search< - Kernel, Point_range> Points_ds; + Kernel, Point_range> Points_ds; typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -77,9 +77,9 @@ sparsify_point_set( // Parse the input points, and add them if they are not too close to // the other points std::size_t pt_idx = 0; - for (typename Point_range::const_iterator it_pt = input_pts.begin() ; - it_pt != input_pts.end(); - ++it_pt, ++pt_idx) { + for (typename Point_range::const_iterator it_pt = input_pts.begin(); + it_pt != input_pts.end(); + ++it_pt, ++pt_idx) { if (dropped_points[pt_idx]) continue; @@ -105,7 +105,7 @@ sparsify_point_set( #ifdef GUDHI_SUBSAMPLING_PROFILING t.end(); std::cerr << "Point set sparsified in " << t.num_seconds() - << " seconds." << std::endl; + << " seconds." << std::endl; #endif } -- 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') 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