Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / flann / algorithms / nn_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 NNINDEX_H
32 #define NNINDEX_H
33
34 #include "flann.hpp"
35 #include "constants.h"
36 #include "common.h"
37 #include "matrix.h"
38
39 #include <string>
40 #include <string.h>
41
42 using namespace std;
43
44 namespace flann
45 {
46
47 class ResultSet;
48
49 /**
50 * Nearest-neighbor index base class
51 */
52 class NNIndex
53 {
54 public:
55
56         virtual ~NNIndex() {};
57
58         /**
59         Method responsible with building the index.
60         */
61         virtual void buildIndex() = 0;
62
63         /**
64         Saves the index to a stream
65         */
66         virtual void saveIndex(FILE* stream) = 0;
67
68         /**
69         Loads the index from a stream
70         */
71         virtual void loadIndex(FILE* stream) = 0;
72
73         /**
74         Method that searches for nearest-neighbors
75         */
76         virtual void findNeighbors(ResultSet& result, const float* vec, const SearchParams& searchParams) = 0;
77
78         /**
79         Number of features in this index.
80         */
81         virtual int size() const = 0;
82
83         /**
84         The length of each vector in this index.
85         */
86         virtual int veclen() const = 0;
87
88         /**
89         The amount of memory (in bytes) this index uses.
90         */
91         virtual int usedMemory() const = 0;
92
93         /**
94         * Algorithm name
95         */
96         virtual flann_algorithm_t getType() const = 0;
97
98         /**
99         Estimates the search parameters required in order to get a certain precision.
100         If testset is not given it uses cross-validation.
101         */
102 //      virtual Params estimateSearchParams(float precision, Matrix<float>* testset = NULL) = 0;
103
104 };
105
106
107 }
108
109 #endif //NNINDEX_H