Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2886_SymRegGrammarEnumeration/ExpressionClustering/flann/include/flann/algorithms/linear_index.h @ 15840

Last change on this file since 15840 was 15840, checked in by gkronber, 6 years ago

#2886 added utility console program for clustering of expressions

File size: 3.6 KB
Line 
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 FLANN_LINEAR_INDEX_H_
32#define FLANN_LINEAR_INDEX_H_
33
34#include "flann/general.h"
35#include "flann/algorithms/nn_index.h"
36
37namespace flann
38{
39
40struct LinearIndexParams : public IndexParams
41{
42    LinearIndexParams()
43    {
44        (* this)["algorithm"] = FLANN_INDEX_LINEAR;
45    }
46};
47
48template <typename Distance>
49class LinearIndex : public NNIndex<Distance>
50{
51public:
52
53    typedef typename Distance::ElementType ElementType;
54    typedef typename Distance::ResultType DistanceType;
55
56
57    LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(),
58                Distance d = Distance()) :
59        dataset_(inputData), index_params_(params), distance_(d)
60    {
61    }
62
63    LinearIndex(const LinearIndex&);
64    LinearIndex& operator=(const LinearIndex&);
65
66    flann_algorithm_t getType() const
67    {
68        return FLANN_INDEX_LINEAR;
69    }
70
71
72    size_t size() const
73    {
74        return dataset_.rows;
75    }
76
77    size_t veclen() const
78    {
79        return dataset_.cols;
80    }
81
82
83    int usedMemory() const
84    {
85        return 0;
86    }
87
88    void buildIndex()
89    {
90        /* nothing to do here for linear search */
91    }
92
93    void saveIndex(FILE*)
94    {
95        /* nothing to do here for linear search */
96    }
97
98
99    void loadIndex(FILE*)
100    {
101        /* nothing to do here for linear search */
102
103        index_params_["algorithm"] = getType();
104    }
105
106    void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/)
107    {
108        for (size_t i = 0; i < dataset_.rows; ++i) {
109            DistanceType dist = distance_(dataset_[i], vec, dataset_.cols);
110            resultSet.addPoint(dist, i);
111        }
112    }
113
114    IndexParams getParameters() const
115    {
116        return index_params_;
117    }
118
119private:
120    /** The dataset */
121    const Matrix<ElementType> dataset_;
122    /** Index parameters */
123    IndexParams index_params_;
124    /** Index distance */
125    Distance distance_;
126
127};
128
129}
130
131#endif // FLANN_LINEAR_INDEX_H_
Note: See TracBrowser for help on using the repository browser.