Joe Verbout
/
main
opencv on mbed
Embed:
(wiki syntax)
Show/hide line numbers
all_indices.h
00001 /*********************************************************************** 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. 00005 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 *************************************************************************/ 00028 00029 00030 #ifndef OPENCV_FLANN_ALL_INDICES_H_ 00031 #define OPENCV_FLANN_ALL_INDICES_H_ 00032 00033 #include "general.h" 00034 00035 #include "nn_index.h" 00036 #include "kdtree_index.h" 00037 #include "kdtree_single_index.h" 00038 #include "kmeans_index.h" 00039 #include "composite_index.h" 00040 #include "linear_index.h" 00041 #include "hierarchical_clustering_index.h" 00042 #include "lsh_index.h" 00043 #include "autotuned_index.h" 00044 00045 00046 namespace cvflann 00047 { 00048 00049 template<typename KDTreeCapability, typename VectorSpace, typename Distance> 00050 struct index_creator 00051 { 00052 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) 00053 { 00054 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); 00055 00056 NNIndex<Distance>* nnIndex; 00057 switch (index_type) { 00058 case FLANN_INDEX_LINEAR: 00059 nnIndex = new LinearIndex<Distance>(dataset, params, distance); 00060 break; 00061 case FLANN_INDEX_KDTREE_SINGLE: 00062 nnIndex = new KDTreeSingleIndex<Distance>(dataset, params, distance); 00063 break; 00064 case FLANN_INDEX_KDTREE: 00065 nnIndex = new KDTreeIndex<Distance>(dataset, params, distance); 00066 break; 00067 case FLANN_INDEX_KMEANS: 00068 nnIndex = new KMeansIndex<Distance>(dataset, params, distance); 00069 break; 00070 case FLANN_INDEX_COMPOSITE: 00071 nnIndex = new CompositeIndex<Distance>(dataset, params, distance); 00072 break; 00073 case FLANN_INDEX_AUTOTUNED: 00074 nnIndex = new AutotunedIndex<Distance>(dataset, params, distance); 00075 break; 00076 case FLANN_INDEX_HIERARCHICAL: 00077 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); 00078 break; 00079 case FLANN_INDEX_LSH: 00080 nnIndex = new LshIndex<Distance>(dataset, params, distance); 00081 break; 00082 default: 00083 throw FLANNException("Unknown index type"); 00084 } 00085 00086 return nnIndex; 00087 } 00088 }; 00089 00090 template<typename VectorSpace, typename Distance> 00091 struct index_creator<False,VectorSpace,Distance> 00092 { 00093 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) 00094 { 00095 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); 00096 00097 NNIndex<Distance>* nnIndex; 00098 switch (index_type) { 00099 case FLANN_INDEX_LINEAR: 00100 nnIndex = new LinearIndex<Distance>(dataset, params, distance); 00101 break; 00102 case FLANN_INDEX_KMEANS: 00103 nnIndex = new KMeansIndex<Distance>(dataset, params, distance); 00104 break; 00105 case FLANN_INDEX_HIERARCHICAL: 00106 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); 00107 break; 00108 case FLANN_INDEX_LSH: 00109 nnIndex = new LshIndex<Distance>(dataset, params, distance); 00110 break; 00111 default: 00112 throw FLANNException("Unknown index type"); 00113 } 00114 00115 return nnIndex; 00116 } 00117 }; 00118 00119 template<typename Distance> 00120 struct index_creator<False,False,Distance> 00121 { 00122 static NNIndex<Distance>* create(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) 00123 { 00124 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params, "algorithm"); 00125 00126 NNIndex<Distance>* nnIndex; 00127 switch (index_type) { 00128 case FLANN_INDEX_LINEAR: 00129 nnIndex = new LinearIndex<Distance>(dataset, params, distance); 00130 break; 00131 case FLANN_INDEX_HIERARCHICAL: 00132 nnIndex = new HierarchicalClusteringIndex<Distance>(dataset, params, distance); 00133 break; 00134 case FLANN_INDEX_LSH: 00135 nnIndex = new LshIndex<Distance>(dataset, params, distance); 00136 break; 00137 default: 00138 throw FLANNException("Unknown index type"); 00139 } 00140 00141 return nnIndex; 00142 } 00143 }; 00144 00145 template<typename Distance> 00146 NNIndex<Distance>* create_index_by_type(const Matrix<typename Distance::ElementType>& dataset, const IndexParams& params, const Distance& distance) 00147 { 00148 return index_creator<typename Distance::is_kdtree_distance, 00149 typename Distance::is_vector_space_distance, 00150 Distance>::create(dataset, params,distance); 00151 } 00152 00153 } 00154 00155 #endif /* OPENCV_FLANN_ALL_INDICES_H_ */ 00156
Generated on Tue Jul 12 2022 16:42:37 by 1.7.2