30
#ifndef OPENCV_FLANN_ALL_INDICES_H_
31
#define OPENCV_FLANN_ALL_INDICES_H_
38
#include "kdtree_index.h"
39
#include "kdtree_single_index.h"
40
#include "kmeans_index.h"
41
#include "composite_index.h"
42
#include "linear_index.h"
43
#include "hierarchical_clustering_index.h"
44
#include "lsh_index.h"
45
#include "autotuned_index.h"
51
template<
typename
KDTreeCapability,
typename
VectorSpace,
typename
Distance>
54
static
NNIndex<Distance>* create(
const
Matrix<typename Distance::ElementType>& dataset,
const
IndexParams& params,
const
Distance& distance)
56
flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,
"algorithm");
58
NNIndex<Distance>* nnIndex;
60
case
FLANN_INDEX_LINEAR:
61
nnIndex =
new
LinearIndex<Distance>(dataset, params, distance);
63
case
FLANN_INDEX_KDTREE_SINGLE:
64
nnIndex =
new
KDTreeSingleIndex<Distance>(dataset, params, distance);
66
case
FLANN_INDEX_KDTREE:
67
nnIndex =
new
KDTreeIndex<Distance>(dataset, params, distance);
69
case
FLANN_INDEX_KMEANS:
70
nnIndex =
new
KMeansIndex<Distance>(dataset, params, distance);
72
case
FLANN_INDEX_COMPOSITE:
73
nnIndex =
new
CompositeIndex<Distance>(dataset, params, distance);
75
case
FLANN_INDEX_AUTOTUNED:
76
nnIndex =
new
AutotunedIndex<Distance>(dataset, params, distance);
78
case
FLANN_INDEX_HIERARCHICAL:
79
nnIndex =
new
HierarchicalClusteringIndex<Distance>(dataset, params, distance);
82
nnIndex =
new
LshIndex<Distance>(dataset, params, distance);
85
FLANN_THROW(cv::Error::StsBadArg,
"Unknown index type");
92
template<
typename
VectorSpace,
typename
Distance>
93
struct
index_creator<False,VectorSpace,Distance>
95
static
NNIndex<Distance>* create(
const
Matrix<typename Distance::ElementType>& dataset,
const
IndexParams& params,
const
Distance& distance)
97
flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,
"algorithm");
99
NNIndex<Distance>* nnIndex;
100
switch
(index_type) {
101
case
FLANN_INDEX_LINEAR:
102
nnIndex =
new
LinearIndex<Distance>(dataset, params, distance);
104
case
FLANN_INDEX_KMEANS:
105
nnIndex =
new
KMeansIndex<Distance>(dataset, params, distance);
107
case
FLANN_INDEX_HIERARCHICAL:
108
nnIndex =
new
HierarchicalClusteringIndex<Distance>(dataset, params, distance);
110
case
FLANN_INDEX_LSH:
111
nnIndex =
new
LshIndex<Distance>(dataset, params, distance);
114
FLANN_THROW(cv::Error::StsBadArg,
"Unknown index type");
121
template<
typename
Distance>
122
struct
index_creator<False,False,Distance>
124
static
NNIndex<Distance>* create(
const
Matrix<typename Distance::ElementType>& dataset,
const
IndexParams& params,
const
Distance& distance)
126
flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,
"algorithm");
128
NNIndex<Distance>* nnIndex;
129
switch
(index_type) {
130
case
FLANN_INDEX_LINEAR:
131
nnIndex =
new
LinearIndex<Distance>(dataset, params, distance);
133
case
FLANN_INDEX_KMEANS:
134
nnIndex =
new
KMeansIndex<Distance>(dataset, params, distance);
136
case
FLANN_INDEX_HIERARCHICAL:
137
nnIndex =
new
HierarchicalClusteringIndex<Distance>(dataset, params, distance);
139
case
FLANN_INDEX_LSH:
140
nnIndex =
new
LshIndex<Distance>(dataset, params, distance);
143
FLANN_THROW(cv::Error::StsBadArg,
"Unknown index type");
150
template<
typename
Distance>
151NNIndex<Distance>* create_index_by_type(
const
Matrix<typename Distance::ElementType>& dataset,
const
IndexParams& params,
const
Distance& distance)
153
return
index_creator<
typename
Distance::is_kdtree_distance,
154
typename
Distance::is_vector_space_distance,
155
Distance>::create(dataset, params,distance);