diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a112e7e8..a7b5d9ac 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,5 @@ nanoflann 1.3.0: (Unreleased) + * Eigen::Matrix datasets: now uses std::cref() to store a reference to matrix. * GSOC2017 contributions by Pranjal Kumar Rai: * Support for dynamic datasets. * Support for non-Euclidean spaces: SO(2), SO(3) diff --git a/examples/matrix_example.cpp b/examples/matrix_example.cpp index 4b2de973..b32d8e03 100644 --- a/examples/matrix_example.cpp +++ b/examples/matrix_example.cpp @@ -28,8 +28,8 @@ #include -#include #include +#include #include #include @@ -41,77 +41,85 @@ using namespace nanoflann; const int SAMPLES_DIM = 15; template -void generateRandomPointCloud(Eigen::MatrixBase &mat, const size_t N, const size_t dim, const typename Der::Scalar max_range = 10) -{ - std::cout << "Generating "<< N << " random points..."; - mat.resize(N,dim); - for (size_t i = 0; i < N; i++) - for (size_t d = 0; d < dim; d++) - mat(i,d) = max_range * (rand() % 1000) / typename Der::Scalar(1000); - std::cout << "done\n"; +void generateRandomPointCloud(Eigen::MatrixBase &mat, const size_t N, + const size_t dim, + const typename Der::Scalar max_range = 10) { + std::cout << "Generating " << N << " random points..."; + mat.resize(N, dim); + for (size_t i = 0; i < N; i++) + for (size_t d = 0; d < dim; d++) + mat(i, d) = max_range * (rand() % 1000) / typename Der::Scalar(1000); + std::cout << "done\n"; } template -void kdtree_demo(const size_t nSamples, const size_t dim) -{ - Eigen::Matrix mat(nSamples, dim); - - const num_t max_range = 20; - - // Generate points: - generateRandomPointCloud(mat, nSamples, dim, max_range); - -// cout << mat << endl; - - // Query point: - std::vector query_pt(dim); - for (size_t d = 0; d < dim; d++) - query_pt[d] = max_range * (rand() % 1000) / num_t(1000); - - - // ------------------------------------------------------------ - // construct a kd-tree index: - // Some of the different possibilities (uncomment just one) - // ------------------------------------------------------------ - // Dimensionality set at run-time (default: L2) - typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix > my_kd_tree_t; - - // Dimensionality set at compile-time -// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix > my_kd_tree_t; - - // Dimensionality set at compile-time: Explicit selection of the distance metric: L2 -// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix,nanoflann::metric_L2> my_kd_tree_t; - - // Dimensionality set at compile-time: Explicit selection of the distance metric: L2_simple -// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix,nanoflann::metric_L2_Simple> my_kd_tree_t; - - // Dimensionality set at compile-time: Explicit selection of the distance metric: L1 -// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix,nanoflann::metric_L1> my_kd_tree_t; - - my_kd_tree_t mat_index(mat, 10 /* max leaf */ ); - mat_index.index->buildIndex(); - - // do a knn search - const size_t num_results = 3; - vector ret_indexes(num_results); - vector out_dists_sqr(num_results); - - nanoflann::KNNResultSet resultSet(num_results); - - resultSet.init(&ret_indexes[0], &out_dists_sqr[0] ); - mat_index.index->findNeighbors(resultSet, &query_pt[0], nanoflann::SearchParams(10)); - - std::cout << "knnSearch(nn="<