Permalink
Browse files

Merged master into MetricAdaptor

  • Loading branch information...
pranjal-rai committed Aug 24, 2017
2 parents 25c17d0 + e13fdfb commit 9e344389f835e3966a6f7bee1f3e1fc5cf51b87a
Showing with 17 additions and 15 deletions.
  1. +5 −0 .travis.sh
  2. +5 −5 examples/matrix_example.cpp
  3. +7 −10 include/nanoflann.hpp
View
@@ -36,6 +36,11 @@ mkdir -p $OUT_DIR;
doxygen
# Only publish docs on merge to master
if [ $TRAVIS_PULL_REQUEST ]; then
return
fi
cd $OUT_DIR
git init
@@ -77,18 +77,18 @@ void kdtree_demo(const size_t nSamples, const size_t dim)
typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t, Dynamic, Dynamic> > my_kd_tree_t;
// Dimensionality set at compile-time
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>, SAMPLES_DIM> my_kd_tree_t;
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic> > my_kd_tree_t;
// Dimensionality set at compile-time: Explicit selection of the distance metric: L2
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>, SAMPLES_DIM,nanoflann::metric_L2> my_kd_tree_t;
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>,nanoflann::metric_L2> my_kd_tree_t;
// Dimensionality set at compile-time: Explicit selection of the distance metric: L2_simple
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>, SAMPLES_DIM,nanoflann::metric_L2_Simple> my_kd_tree_t;
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>,nanoflann::metric_L2_Simple> my_kd_tree_t;
// Dimensionality set at compile-time: Explicit selection of the distance metric: L1
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>, SAMPLES_DIM,nanoflann::metric_L1> my_kd_tree_t;
// typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic>,nanoflann::metric_L1> my_kd_tree_t;
my_kd_tree_t mat_index(dim /*dim*/, mat, 10 /* max leaf */ );
my_kd_tree_t mat_index(mat, 10 /* max leaf */ );
mat_index.index->buildIndex();
// do a knn search
View
@@ -1898,32 +1898,29 @@ namespace nanoflann
*
* typedef KDTreeEigenMatrixAdaptor< Eigen::Matrix<num_t,Dynamic,Dynamic> > my_kd_tree_t;
* const int max_leaf = 10;
* my_kd_tree_t mat_index(dimdim, mat, max_leaf );
* my_kd_tree_t mat_index(mat, max_leaf );
* mat_index.index->buildIndex();
* mat_index.index->...
* \endcode
*
* \tparam DIM If set to >0, it specifies a compile-time fixed dimensionality for the points in the data set, allowing more compiler optimizations.
* \tparam Distance The distance metric to use: nanoflann::metric_L1, nanoflann::metric_L2, nanoflann::metric_L2_Simple, etc.
*/
template <class MatrixType, int DIM = -1, class Distance = nanoflann::metric_L2>
template <class MatrixType, class Distance = nanoflann::metric_L2>
struct KDTreeEigenMatrixAdaptor
{
typedef KDTreeEigenMatrixAdaptor<MatrixType, DIM, Distance> self_t;
typedef typename MatrixType::Scalar num_t;
typedef KDTreeEigenMatrixAdaptor<MatrixType,Distance> self_t;
typedef typename MatrixType::Scalar num_t;
typedef typename MatrixType::Index IndexType;
typedef typename Distance::template traits<num_t, self_t>::distance_t metric_t;
typedef KDTreeSingleIndexAdaptor< metric_t, self_t, DIM, IndexType> index_t;
typedef typename Distance::template traits<num_t,self_t>::distance_t metric_t;
typedef KDTreeSingleIndexAdaptor< metric_t,self_t, MatrixType::ColsAtCompileTime,IndexType> index_t;
index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index.
/// Constructor: takes a const ref to the matrix object with the data points
KDTreeEigenMatrixAdaptor(const int dimensionality, const MatrixType &mat, const int leaf_max_size = 10) : m_data_matrix(mat)
KDTreeEigenMatrixAdaptor(const MatrixType &mat, const int leaf_max_size = 10) : m_data_matrix(mat)
{
const IndexType dims = mat.cols();
if (dims != dimensionality) throw std::runtime_error("Error: 'dimensionality' must match column count in data matrix");
if (DIM > 0 && static_cast<int>(dims) != DIM)
throw std::runtime_error("Data set dimensionality does not match the 'DIM' template argument");
index = new index_t( dims, *this /* adaptor */, nanoflann::KDTreeSingleIndexAdaptorParams(leaf_max_size ) );
index->buildIndex();
}

0 comments on commit 9e34438

Please sign in to comment.