From 26fd3a550b891ef4110fd66a865b8213e6995e27 Mon Sep 17 00:00:00 2001 From: Marius Muja Date: Tue, 6 Dec 2011 14:29:22 -0800 Subject: [PATCH] Nicer way of controling index instantiation for different distance combinations --- src/cpp/flann/algorithms/all_indices.h | 107 +----------------- src/cpp/flann/algorithms/composite_index.h | 2 + .../flann/algorithms/kdtree_cuda_3d_index.h | 1 + .../flann/algorithms/kdtree_single_index.h | 1 + test/flann_simple_test.cpp | 2 +- 5 files changed, 6 insertions(+), 107 deletions(-) diff --git a/src/cpp/flann/algorithms/all_indices.h b/src/cpp/flann/algorithms/all_indices.h index 5d4cbae..42f8586 100644 --- a/src/cpp/flann/algorithms/all_indices.h +++ b/src/cpp/flann/algorithms/all_indices.h @@ -47,111 +47,6 @@ namespace flann { -template -struct index_creator -{ - static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) - { - flann_algorithm_t index_type = get_param(params, "algorithm"); - - NNIndex* nnIndex; - switch (index_type) { - case FLANN_INDEX_LINEAR: - nnIndex = new LinearIndex(dataset, params, distance); - break; - case FLANN_INDEX_KDTREE_SINGLE: - nnIndex = new KDTreeSingleIndex(dataset, params, distance); - break; - case FLANN_INDEX_KDTREE: - nnIndex = new KDTreeIndex(dataset, params, distance); - break; - //! #define this symbol before including flann.h to enable GPU search algorithms. But you have - //! to link libflann_cuda then! - #ifdef FLANN_USE_CUDA - case FLANN_INDEX_KDTREE_CUDA: - nnIndex = new KDTreeCuda3dIndex(dataset, params, distance); - break; - #endif - - case FLANN_INDEX_KMEANS: - nnIndex = new KMeansIndex(dataset, params, distance); - break; - case FLANN_INDEX_COMPOSITE: - nnIndex = new CompositeIndex(dataset, params, distance); - break; - case FLANN_INDEX_AUTOTUNED: - nnIndex = new AutotunedIndex(dataset, params, distance); - break; - case FLANN_INDEX_HIERARCHICAL: - nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); - break; - case FLANN_INDEX_LSH: - nnIndex = new LshIndex(dataset, params, distance); - break; - default: - throw FLANNException("Unknown index type"); - } - - return nnIndex; - } -}; - -template -struct index_creator -{ - static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) - { - flann_algorithm_t index_type = get_param(params, "algorithm"); - - NNIndex* nnIndex; - switch (index_type) { - case FLANN_INDEX_LINEAR: - nnIndex = new LinearIndex(dataset, params, distance); - break; - case FLANN_INDEX_KMEANS: - nnIndex = new KMeansIndex(dataset, params, distance); - break; - case FLANN_INDEX_HIERARCHICAL: - nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); - break; - case FLANN_INDEX_LSH: - nnIndex = new LshIndex(dataset, params, distance); - break; - default: - throw FLANNException("Unknown index type"); - } - - return nnIndex; - } -}; - -template -struct index_creator -{ - static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) - { - flann_algorithm_t index_type = get_param(params, "algorithm"); - - NNIndex* nnIndex; - switch (index_type) { - case FLANN_INDEX_LINEAR: - nnIndex = new LinearIndex(dataset, params, distance); - break; - case FLANN_INDEX_HIERARCHICAL: - nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); - break; - case FLANN_INDEX_LSH: - nnIndex = new LshIndex(dataset, params, distance); - break; - default: - throw FLANNException("Unknown index type"); - } - - return nnIndex; - } -}; - - /** * enable_if sfinae helper @@ -205,7 +100,7 @@ struct valid_combination static const bool value = same_type::value && (!needs_kdtree_distance >::value || is_kdtree_distance::value) && - (!needs_vector_space_distance >::value || is_vector_space_distance::value); + (!needs_vector_space_distance >::value || is_kdtree_distance::value || is_vector_space_distance::value); }; diff --git a/src/cpp/flann/algorithms/composite_index.h b/src/cpp/flann/algorithms/composite_index.h index 83e44dc..e2fb92b 100644 --- a/src/cpp/flann/algorithms/composite_index.h +++ b/src/cpp/flann/algorithms/composite_index.h @@ -74,6 +74,8 @@ public: typedef typename Distance::ElementType ElementType; typedef typename Distance::ResultType DistanceType; + typedef bool needs_kdtree_distance; + /** * Index constructor * @param inputData dataset containing the points to index diff --git a/src/cpp/flann/algorithms/kdtree_cuda_3d_index.h b/src/cpp/flann/algorithms/kdtree_cuda_3d_index.h index 4c699c6..82c7617 100644 --- a/src/cpp/flann/algorithms/kdtree_cuda_3d_index.h +++ b/src/cpp/flann/algorithms/kdtree_cuda_3d_index.h @@ -76,6 +76,7 @@ public: int visited_leafs; + typedef bool needs_kdtree_distance; /** * KDTree constructor diff --git a/src/cpp/flann/algorithms/kdtree_single_index.h b/src/cpp/flann/algorithms/kdtree_single_index.h index 6f46936..55b9650 100644 --- a/src/cpp/flann/algorithms/kdtree_single_index.h +++ b/src/cpp/flann/algorithms/kdtree_single_index.h @@ -72,6 +72,7 @@ public: typedef typename Distance::ElementType ElementType; typedef typename Distance::ResultType DistanceType; + typedef bool needs_kdtree_distance; /** * KDTree constructor diff --git a/test/flann_simple_test.cpp b/test/flann_simple_test.cpp index 6b1ce54..caae8c6 100644 --- a/test/flann_simple_test.cpp +++ b/test/flann_simple_test.cpp @@ -620,7 +620,7 @@ TEST_F(Flann_3D, SavedTest2) class Flann_Brief100K_Test : public FLANNTestFixture { protected: - typedef flann::Hamming2 Distance; + typedef flann::Hamming Distance; typedef Distance::ElementType ElementType; typedef Distance::ResultType DistanceType; flann::Matrix data; -- GitLab