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 RTABMAP_FLANN_ALL_INDICES_H_
31 #define RTABMAP_FLANN_ALL_INDICES_H_
32 
33 #include "rtflann/general.h"
34 
44 #ifdef FLANN_USE_CUDA
45 #include "rtflann/algorithms/kdtree_cuda_3d_index.h"
46 #endif
47 
48 
49 namespace rtflann
50 {
51 
55 template<bool, typename T = void> struct enable_if{};
56 template<typename T> struct enable_if<true,T> { typedef T type; };
57 
61 template<bool, typename T> struct disable_if{ typedef T type; };
62 template<typename T> struct disable_if<true,T> { };
63 
67 template <typename T, typename U>
68 struct same_type
69 {
70  enum {value = false};
71 };
72 
73 template<typename T>
74 struct same_type<T,T>
75 {
76  enum {value = true};
77 };
78 
79 #define HAS_MEMBER(member) \
80  template<typename T> \
81  struct member { \
82  typedef char No; \
83  typedef long Yes; \
84  template<typename C> static Yes test( typename C::member* ); \
85  template<typename C> static No test( ... ); \
86  enum { value = sizeof (test<T>(0))==sizeof(Yes) }; \
87  };
88 
89 HAS_MEMBER(needs_kdtree_distance)
90 HAS_MEMBER(needs_vector_space_distance)
91 HAS_MEMBER(is_kdtree_distance)
92 HAS_MEMBER(is_vector_space_distance)
93 
95 {
96  typedef float ElementType;
97  typedef float ResultType;
98 
99  template <typename Iterator1, typename Iterator2>
100  ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const
101  {
102  return ResultType(0);
103  }
104 
105  template <typename U, typename V>
106  inline ResultType accum_dist(const U& a, const V& b, int) const
107  {
108  return ResultType(0);
109  }
110 };
111 
115 template<template <typename> class Index, typename Distance, typename ElemType>
116 struct valid_combination
117 {
119  (!needs_kdtree_distance<Index<DummyDistance> >::value || is_kdtree_distance<Distance>::value) &&
120  (!needs_vector_space_distance<Index<DummyDistance> >::value || is_kdtree_distance<Distance>::value || is_vector_space_distance<Distance>::value);
121 
122 };
123 
124 
125 /*********************************************************
126  * Create index
127  **********************************************************/
128 template <template<typename> class Index, typename Distance, typename T>
129 inline NNIndex<Distance>* create_index_(rtflann::Matrix<T> data, const rtflann::IndexParams& params, const Distance& distance,
131 {
132  return new Index<Distance>(data, params, distance);
133 }
134 
135 template <template<typename> class Index, typename Distance, typename T>
136 inline NNIndex<Distance>* create_index_(rtflann::Matrix<T> data, const rtflann::IndexParams& params, const Distance& distance,
138 {
139  return NULL;
140 }
141 
142 template<typename Distance>
143 inline NNIndex<Distance>*
145  const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance)
146 {
147  typedef typename Distance::ElementType ElementType;
148 
149  NNIndex<Distance>* nnIndex;
150 
151  switch (index_type) {
152 
153  case FLANN_INDEX_LINEAR:
154  nnIndex = create_index_<LinearIndex,Distance,ElementType>(dataset, params, distance);
155  break;
157  nnIndex = create_index_<KDTreeSingleIndex,Distance,ElementType>(dataset, params, distance);
158  break;
159  case FLANN_INDEX_KDTREE:
160  nnIndex = create_index_<KDTreeIndex,Distance,ElementType>(dataset, params, distance);
161  break;
164 #ifdef FLANN_USE_CUDA
165  case FLANN_INDEX_KDTREE_CUDA:
166  nnIndex = create_index_<KDTreeCuda3dIndex,Distance,ElementType>(dataset, params, distance);
167  break;
168 #endif
169 
171  nnIndex = create_index_<KMeansIndex,Distance,ElementType>(dataset, params, distance);
172  break;
174  nnIndex = create_index_<CompositeIndex,Distance,ElementType>(dataset, params, distance);
175  break;
177  nnIndex = create_index_<AutotunedIndex,Distance,ElementType>(dataset, params, distance);
178  break;
180  nnIndex = create_index_<HierarchicalClusteringIndex,Distance,ElementType>(dataset, params, distance);
181  break;
182  case FLANN_INDEX_LSH:
183  nnIndex = create_index_<LshIndex,Distance,ElementType>(dataset, params, distance);
184  break;
185  default:
186  throw FLANNException("Unknown index type");
187  }
188 
189  if (nnIndex==NULL) {
190  throw FLANNException("Unsupported index/distance combination");
191  }
192  return nnIndex;
193 }
194 
195 }
196 
197 #endif /* RTABMAP_FLANN_ALL_INDICES_H_ */
linear_index.h
kdtree_single_index.h
general.h
rtflann::NNIndex
Definition: nn_index.h:101
rtflann::DummyDistance
Definition: all_indices.h:120
kmeans_index.h
hierarchical_clustering_index.h
rtflann::FLANNException
Definition: general.h:70
rtflann::FLANN_INDEX_KDTREE
@ FLANN_INDEX_KDTREE
Definition: defines.h:82
rtflann::valid_combination::value
static const bool value
Definition: all_indices.h:144
nn_index.h
type
true
#define true
Definition: ConvertUTF.c:57
rtflann::FLANN_INDEX_COMPOSITE
@ FLANN_INDEX_COMPOSITE
Definition: defines.h:84
autotuned_index.h
rtflann::FLANN_INDEX_KDTREE_SINGLE
@ FLANN_INDEX_KDTREE_SINGLE
Definition: defines.h:85
rtflann::same_type::value
@ value
Definition: all_indices.h:96
rtflann::disable_if
Definition: all_indices.h:87
rtflann::FLANN_INDEX_AUTOTUNED
@ FLANN_INDEX_AUTOTUNED
Definition: defines.h:92
rtflann::create_index_by_type
NNIndex< Distance > * create_index_by_type(const flann_algorithm_t index_type, const Matrix< typename Distance::ElementType > &dataset, const IndexParams &params, const Distance &distance)
Definition: all_indices.h:170
HAS_MEMBER
#define HAS_MEMBER(member)
Definition: all_indices.h:105
params
SmartProjectionParams params(gtsam::HESSIAN, gtsam::ZERO_ON_DEGENERACY)
Eigen::Triplet
rtflann::FLANN_INDEX_KMEANS
@ FLANN_INDEX_KMEANS
Definition: defines.h:83
lsh_index.h
rtflann::flann_algorithm_t
flann_algorithm_t
Definition: defines.h:79
rtflann::same_type
Definition: all_indices.h:94
rtflann::create_index_
NNIndex< Distance > * create_index_(rtflann::Matrix< T > data, const rtflann::IndexParams &params, const Distance &distance, typename enable_if< valid_combination< Index, Distance, T >::value, void >::type *=0)
Definition: all_indices.h:155
Index
struct Index Index
Definition: sqlite3.c:8577
rtflann::disable_if::type
T type
Definition: all_indices.h:87
rtflann::enable_if
Definition: all_indices.h:81
operator()
internal::enable_if< symbolic::is_symbolic< IndexType >::value, CoeffReturnType >::type operator()(const IndexType &id) EIGEN_INDEXED_VIEW_METHOD_CONST
distance
Double_ distance(const OrientedPlane3_ &p)
rtflann::valid_combination
Definition: all_indices.h:142
rtflann::FLANN_INDEX_LSH
@ FLANN_INDEX_LSH
Definition: defines.h:87
rtflann::IndexParams
std::map< std::string, any > IndexParams
Definition: params.h:77
NULL
#define NULL
rtflann::FLANN_INDEX_HIERARCHICAL
@ FLANN_INDEX_HIERARCHICAL
Definition: defines.h:86
kdtree_index.h
rtflann::FLANN_INDEX_LINEAR
@ FLANN_INDEX_LINEAR
Definition: defines.h:81
rtflann
Definition: all_indices.h:49
composite_index.h
rtflann::Matrix
Definition: matrix.h:131
rtflann::Index
Definition: flann.hpp:104


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:06