OpenCV 2.4.8 components for OpenCVgrabber.
[mmanager-3rdparty.git] / OpenCV2.4.8 / build / include / opencv2 / flann / all_indices.h
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"
41 #include "hierarchical_clustering_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>
50 struct index_creator
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;
61         case FLANN_INDEX_KDTREE_SINGLE:
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;
70         case FLANN_INDEX_COMPOSITE:
71             nnIndex = new CompositeIndex<Distance>(dataset, params, distance);
72             break;
73         case FLANN_INDEX_AUTOTUNED:
74             nnIndex = new AutotunedIndex<Distance>(dataset, params, distance);
75             break;
76         case FLANN_INDEX_HIERARCHICAL:
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;
105         case FLANN_INDEX_HIERARCHICAL:
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;
131         case FLANN_INDEX_HIERARCHICAL:
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>
146 NNIndex<Distance>* create_index_by_type(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& 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_ */