1 /***********************************************************************
2 * Software License Agreement (BSD License)
4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *************************************************************************/
30 #ifndef OPENCV_FLANN_ALL_INDICES_H_
31 #define OPENCV_FLANN_ALL_INDICES_H_
36 #include "kdtree_index.h"
37 #include "kdtree_single_index.h"
38 #include "kmeans_index.h"
39 #include "composite_index.h"
40 #include "linear_index.h"
41 #include "hierarchical_clustering_index.h"
42 #include "lsh_index.h"
43 #include "autotuned_index.h"
49 template<typename KDTreeCapability, typename VectorSpace, typename Distance>
52 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
54 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
56 NNIndex<Distance>* nnIndex;
58 case FLANN_INDEX_LINEAR:
59 nnIndex = new LinearIndex<Distance>(dataset, params, distance);
61 case FLANN_INDEX_KDTREE_SINGLE:
62 nnIndex = new KDTreeSingleIndex<Distance>(dataset, params, distance);
64 case FLANN_INDEX_KDTREE:
65 nnIndex = new KDTreeIndex<Distance>(dataset, params, distance);
67 case FLANN_INDEX_KMEANS:
68 nnIndex = new KMeansIndex<Distance>(dataset, params, distance);
70 case FLANN_INDEX_COMPOSITE:
71 nnIndex = new CompositeIndex<Distance>(dataset, params, distance);
73 case FLANN_INDEX_AUTOTUNED:
74 nnIndex = new AutotunedIndex<Distance>(dataset, params, distance);
76 case FLANN_INDEX_HIERARCHICAL:
77 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
80 nnIndex = new LshIndex<Distance>(dataset, params, distance);
83 throw FLANNException("Unknown index type");
90 template<typename VectorSpace, typename Distance>
91 struct index_creator<False,VectorSpace,Distance>
93 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
95 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
97 NNIndex<Distance>* nnIndex;
99 case FLANN_INDEX_LINEAR:
100 nnIndex = new LinearIndex<Distance>(dataset, params, distance);
102 case FLANN_INDEX_KMEANS:
103 nnIndex = new KMeansIndex<Distance>(dataset, params, distance);
105 case FLANN_INDEX_HIERARCHICAL:
106 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
108 case FLANN_INDEX_LSH:
109 nnIndex = new LshIndex<Distance>(dataset, params, distance);
112 throw FLANNException("Unknown index type");
119 template<typename Distance>
120 struct index_creator<False,False,Distance>
122 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
124 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
126 NNIndex<Distance>* nnIndex;
127 switch (index_type) {
128 case FLANN_INDEX_LINEAR:
129 nnIndex = new LinearIndex<Distance>(dataset, params, distance);
131 case FLANN_INDEX_HIERARCHICAL:
132 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
134 case FLANN_INDEX_LSH:
135 nnIndex = new LshIndex<Distance>(dataset, params, distance);
138 throw FLANNException("Unknown index type");
145 template<typename Distance>
146 NNIndex<Distance>* create_index_by_type(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
148 return index_creator<typename Distance::is_kdtree_distance,
149 typename Distance::is_vector_space_distance,
150 Distance>::create(dataset, params,distance);
155 #endif /* OPENCV_FLANN_ALL_INDICES_H_ */