Joe Verbout
/
main
opencv on mbed
Embed:
(wiki syntax)
Show/hide line numbers
linear_index.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 * THE BSD LICENSE 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *************************************************************************/ 00030 00031 #ifndef OPENCV_FLANN_LINEAR_INDEX_H_ 00032 #define OPENCV_FLANN_LINEAR_INDEX_H_ 00033 00034 #include "general.h" 00035 #include "nn_index.h" 00036 00037 namespace cvflann 00038 { 00039 00040 struct LinearIndexParams : public IndexParams 00041 { 00042 LinearIndexParams() 00043 { 00044 (* this)["algorithm"] = FLANN_INDEX_LINEAR; 00045 } 00046 }; 00047 00048 template <typename Distance> 00049 class LinearIndex : public NNIndex<Distance> 00050 { 00051 public: 00052 00053 typedef typename Distance::ElementType ElementType; 00054 typedef typename Distance::ResultType DistanceType; 00055 00056 00057 LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(), 00058 Distance d = Distance()) : 00059 dataset_(inputData), index_params_(params), distance_(d) 00060 { 00061 } 00062 00063 LinearIndex(const LinearIndex&); 00064 LinearIndex& operator=(const LinearIndex&); 00065 00066 flann_algorithm_t getType() const 00067 { 00068 return FLANN_INDEX_LINEAR; 00069 } 00070 00071 00072 size_t size() const 00073 { 00074 return dataset_.rows; 00075 } 00076 00077 size_t veclen() const 00078 { 00079 return dataset_.cols; 00080 } 00081 00082 00083 int usedMemory() const 00084 { 00085 return 0; 00086 } 00087 00088 void buildIndex() 00089 { 00090 /* nothing to do here for linear search */ 00091 } 00092 00093 void saveIndex(FILE*) 00094 { 00095 /* nothing to do here for linear search */ 00096 } 00097 00098 00099 void loadIndex(FILE*) 00100 { 00101 /* nothing to do here for linear search */ 00102 00103 index_params_["algorithm"] = getType(); 00104 } 00105 00106 void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/) 00107 { 00108 ElementType* data = dataset_.data; 00109 for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) { 00110 DistanceType dist = distance_(data, vec, dataset_.cols); 00111 resultSet.addPoint(dist, (int)i); 00112 } 00113 } 00114 00115 IndexParams getParameters() const 00116 { 00117 return index_params_; 00118 } 00119 00120 private: 00121 /** The dataset */ 00122 const Matrix<ElementType> dataset_; 00123 /** Index parameters */ 00124 IndexParams index_params_; 00125 /** Index distance */ 00126 Distance distance_; 00127 00128 }; 00129 00130 } 00131 00132 #endif // OPENCV_FLANN_LINEAR_INDEX_H_ 00133
Generated on Tue Jul 12 2022 16:42:38 by 1.7.2