diff options
author | cjamin <cjamin@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-28 16:23:35 +0000 |
---|---|---|
committer | cjamin <cjamin@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-28 16:23:35 +0000 |
commit | 58bcd511da7d3c00b7a1f8ca130ba437ae6665c8 (patch) | |
tree | 74098568251a899732887e72aea019926974dc40 /src/Spatial_searching/example | |
parent | e42f150700da50741b1e0d616a24a35574c1f76a (diff) |
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
Diffstat (limited to 'src/Spatial_searching/example')
-rw-r--r-- | src/Spatial_searching/example/CMakeLists.txt | 18 | ||||
-rw-r--r-- | src/Spatial_searching/example/example_spatial_searching.cpp | 37 |
2 files changed, 55 insertions, 0 deletions
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 <gudhi/Spatial_tree_data_structure.h> + +#include <CGAL/Epick_d.h> +#include <CGAL/Random.h> + +#include <array> +#include <vector> + +namespace gss = Gudhi::spatial_searching; + +int main (void) +{ + typedef CGAL::Epick_d<CGAL::Dimension_tag<4> > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point; + typedef std::vector<Point> Points; + + typedef gss::Spatial_tree_data_structure<K, Points> 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<FT, 4>({ 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; +} |