all_indices.h
Go to the documentation of this file.
1 /***********************************************************************
2  * Software License Agreement (BSD License)
3  *
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.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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.
16  *
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  *************************************************************************/
28 
29 
30 #ifndef OPENCV_FLANN_ALL_INDICES_H_
31 #define OPENCV_FLANN_ALL_INDICES_H_
32 
33 #include "general.h"
34 
35 #include "nn_index.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"
42 #include "lsh_index.h"
43 #include "autotuned_index.h"
44 
45 
46 namespace cvflann
47 {
48 
49 template<typename KDTreeCapability, typename VectorSpace, typename Distance>
51 {
52  static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
53  {
54  flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
55 
56  NNIndex<Distance>* nnIndex;
57  switch (index_type) {
58  case FLANN_INDEX_LINEAR:
59  nnIndex = new LinearIndex<Distance>(dataset, params, distance);
60  break;
62  nnIndex = new KDTreeSingleIndex<Distance>(dataset, params, distance);
63  break;
64  case FLANN_INDEX_KDTREE:
65  nnIndex = new KDTreeIndex<Distance>(dataset, params, distance);
66  break;
67  case FLANN_INDEX_KMEANS:
68  nnIndex = new KMeansIndex<Distance>(dataset, params, distance);
69  break;
71  nnIndex = new CompositeIndex<Distance>(dataset, params, distance);
72  break;
74  nnIndex = new AutotunedIndex<Distance>(dataset, params, distance);
75  break;
77  nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
78  break;
79  case FLANN_INDEX_LSH:
80  nnIndex = new LshIndex<Distance>(dataset, params, distance);
81  break;
82  default:
83  throw FLANNException("Unknown index type");
84  }
85 
86  return nnIndex;
87  }
88 };
89 
90 template<typename VectorSpace, typename Distance>
91 struct index_creator<False,VectorSpace,Distance>
92 {
93  static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
94  {
95  flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
96 
97  NNIndex<Distance>* nnIndex;
98  switch (index_type) {
99  case FLANN_INDEX_LINEAR:
100  nnIndex = new LinearIndex<Distance>(dataset, params, distance);
101  break;
102  case FLANN_INDEX_KMEANS:
103  nnIndex = new KMeansIndex<Distance>(dataset, params, distance);
104  break;
106  nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
107  break;
108  case FLANN_INDEX_LSH:
109  nnIndex = new LshIndex<Distance>(dataset, params, distance);
110  break;
111  default:
112  throw FLANNException("Unknown index type");
113  }
114 
115  return nnIndex;
116  }
117 };
118 
119 template<typename Distance>
120 struct index_creator<False,False,Distance>
121 {
122  static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
123  {
124  flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm");
125 
126  NNIndex<Distance>* nnIndex;
127  switch (index_type) {
128  case FLANN_INDEX_LINEAR:
129  nnIndex = new LinearIndex<Distance>(dataset, params, distance);
130  break;
132  nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance);
133  break;
134  case FLANN_INDEX_LSH:
135  nnIndex = new LshIndex<Distance>(dataset, params, distance);
136  break;
137  default:
138  throw FLANNException("Unknown index type");
139  }
140 
141  return nnIndex;
142  }
143 };
144 
145 template<typename Distance>
147 {
148  return index_creator<typename Distance::is_kdtree_distance,
149  typename Distance::is_vector_space_distance,
150  Distance>::create(dataset, params,distance);
151 }
152 
153 }
154 
155 #endif /* OPENCV_FLANN_ALL_INDICES_H_ */
Definition: defines.h:86
Definition: defines.h:87
Definition: hierarchical_clustering_index.h:81
const CvArr CvSeq CvSeq CvMemStorage CvSURFParams params
Definition: compat.hpp:647
flann_algorithm_t
Definition: defines.h:81
Definition: lsh_index.h:78
Definition: kmeans_index.h:81
Definition: general.h:41
Definition: matrix.h:46
Definition: defines.h:85
Definition: kdtree_single_index.h:70
Definition: defines.h:91
Definition: composite_index.h:71
Definition: dist.h:91
Definition: linear_index.h:49
Definition: autotuned_index.h:70
std::map< std::string, any > IndexParams
Definition: params.h:42
Definition: all_indices.h:50
GLenum const GLfloat * params
Definition: compat.hpp:688
Definition: defines.h:84
Definition: kdtree_index.h:70
static NNIndex< Distance > * create(const Matrix< typename Distance::ElementType > &dataset, const IndexParams &params, const Distance &distance)
Definition: all_indices.h:93
Definition: defines.h:88
Definition: defines.h:89
Definition: nn_index.h:48
static NNIndex< Distance > * create(const Matrix< typename Distance::ElementType > &dataset, const IndexParams &params, const Distance &distance)
Definition: all_indices.h:122
NNIndex< Distance > * create_index_by_type(const Matrix< typename Distance::ElementType > &dataset, const IndexParams &params, const Distance &distance)
Definition: all_indices.h:146
static NNIndex< Distance > * create(const Matrix< typename Distance::ElementType > &dataset, const IndexParams &params, const Distance &distance)
Definition: all_indices.h:52
Definition: defines.h:83