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>
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>
130  typename enable_if<valid_combination<Index,Distance,T>::value,void>::type* = 0)
131 {
132  return new Index<Distance>(data, params, distance);
133 }
134 
135 template <template<typename> class Index, typename Distance, typename T>
137  typename disable_if<valid_combination<Index,Distance,T>::value,void>::type* = 0)
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 
170  case FLANN_INDEX_KMEANS:
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_ */
#define NULL
std::map< std::string, any > IndexParams
Definition: params.h:51
#define HAS_MEMBER(member)
Definition: all_indices.h:79
ResultType accum_dist(const U &a, const V &b, int) const
Definition: all_indices.h:106
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=-1) const
Definition: all_indices.h:100
GLM_FUNC_DECL genType::value_type distance(genType const &p0, genType const &p1)
#define true
Definition: ConvertUTF.c:57
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:144
flann_algorithm_t
Definition: defines.h:79
struct Index Index
Definition: sqlite3.c:8577
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:129


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:58