EstervQrCode 1.1.1
Library for qr code manipulation
linear_index.h
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  * THE BSD LICENSE
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *************************************************************************/
30 
31 #ifndef OPENCV_FLANN_LINEAR_INDEX_H_
32 #define OPENCV_FLANN_LINEAR_INDEX_H_
33 
35 
36 #include "nn_index.h"
37 
38 namespace cvflann
39 {
40 
41 struct LinearIndexParams : public IndexParams
42 {
43  LinearIndexParams()
44  {
45  (* this)["algorithm"] = FLANN_INDEX_LINEAR;
46  }
47 };
48 
49 template <typename Distance>
50 class LinearIndex : public NNIndex<Distance>
51 {
52 public:
53 
54  typedef typename Distance::ElementType ElementType;
55  typedef typename Distance::ResultType DistanceType;
56 
57 
58  LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(),
59  Distance d = Distance()) :
60  dataset_(inputData), index_params_(params), distance_(d)
61  {
62  }
63 
64  LinearIndex(const LinearIndex&);
65  LinearIndex& operator=(const LinearIndex&);
66 
67  flann_algorithm_t getType() const CV_OVERRIDE
68  {
69  return FLANN_INDEX_LINEAR;
70  }
71 
72 
73  size_t size() const CV_OVERRIDE
74  {
75  return dataset_.rows;
76  }
77 
78  size_t veclen() const CV_OVERRIDE
79  {
80  return dataset_.cols;
81  }
82 
83 
84  int usedMemory() const CV_OVERRIDE
85  {
86  return 0;
87  }
88 
89  void buildIndex() CV_OVERRIDE
90  {
91  /* nothing to do here for linear search */
92  }
93 
94  void saveIndex(FILE*) CV_OVERRIDE
95  {
96  /* nothing to do here for linear search */
97  }
98 
99 
100  void loadIndex(FILE*) CV_OVERRIDE
101  {
102  /* nothing to do here for linear search */
103 
104  index_params_["algorithm"] = getType();
105  }
106 
107  void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/) CV_OVERRIDE
108  {
109  ElementType* data = dataset_.data;
110  for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) {
111  DistanceType dist = distance_(data, vec, dataset_.cols);
112  resultSet.addPoint(dist, (int)i);
113  }
114  }
115 
116  IndexParams getParameters() const CV_OVERRIDE
117  {
118  return index_params_;
119  }
120 
121 private:
123  const Matrix<ElementType> dataset_;
125  IndexParams index_params_;
127  Distance distance_;
128 
129 };
130 
131 }
132 
134 
135 #endif // OPENCV_FLANN_LINEAR_INDEX_H_
CvSize size
Definition: core_c.h:112
void * data
Definition: core_c.h:427
#define CV_OVERRIDE
Definition: cvdef.h:792
Definition: flann.hpp:60