Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2886_SymRegGrammarEnumeration/ExpressionClustering/flann/include/flann/util/params.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: 4.1 KB
Line 
1/***********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright 2008-2011  Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5 * Copyright 2008-2011  David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *************************************************************************/
28
29
30#ifndef FLANN_PARAMS_H_
31#define FLANN_PARAMS_H_
32
33#include "any.h"
34#include "flann/general.h"
35#include <iostream>
36#include <map>
37
38
39namespace flann
40{
41
42typedef std::map<std::string, any> IndexParams;
43
44
45typedef enum {
46  FLANN_False = 0,
47  FLANN_True = 1,
48  FLANN_Undefined
49} tri_type;
50
51struct SearchParams
52{
53    SearchParams(int checks_ = 32, float eps_ = 0.0, bool sorted_ = true ) :
54      checks(checks_), eps(eps_), sorted(sorted_)
55    {
56      max_neighbors = -1;
57      use_heap = FLANN_Undefined;
58      cores = 1;
59      matrices_in_gpu_ram = false;
60    }
61
62    // how many leafs to visit when searching for neighbours (-1 for unlimited)
63    int checks;
64    // search for eps-approximate neighbours (default: 0)
65    float eps;
66    // only for radius search, require neighbours sorted by distance (default: true)
67    bool sorted;
68    // maximum number of neighbors radius search should return (-1 for unlimited)
69    int max_neighbors;
70    // use a heap to manage the result set (default: FLANN_Undefined)
71    tri_type use_heap;
72    // how many cores to assign to the search
73    // this parameter will be ignored if Intel TBB isn't available on the system or no "TBB" macro is defined
74    int cores;
75    // for GPU search indicates if matrices are already in GPU ram
76    bool matrices_in_gpu_ram;
77};
78
79
80inline bool has_param(const IndexParams& params, std::string name)
81{
82  return params.find(name)!=params.end();
83}
84
85template<typename T>
86T get_param(const IndexParams& params, std::string name, const T& default_value)
87{
88    IndexParams::const_iterator it = params.find(name);
89    if (it != params.end()) {
90        return it->second.cast<T>();
91    }
92    else {
93        return default_value;
94    }
95}
96
97template<typename T>
98T get_param(const IndexParams& params, std::string name)
99{
100    IndexParams::const_iterator it = params.find(name);
101    if (it != params.end()) {
102        return it->second.cast<T>();
103    }
104    else {
105        throw FLANNException(std::string("Missing parameter '")+name+std::string("' in the parameters given"));
106    }
107}
108
109inline void print_params(const IndexParams& params)
110{
111    IndexParams::const_iterator it;
112
113    for(it=params.begin(); it!=params.end(); ++it) {
114        std::cout << it->first << " : " << it->second << std::endl;
115    }
116}
117
118inline void print_params(const SearchParams& params)
119{
120  std::cout << "checks : " << params.checks << std::endl;
121  std::cout << "eps : " << params.eps << std::endl;
122  std::cout << "sorted : " << params.sorted << std::endl;
123  std::cout << "max_neighbors : " << params.max_neighbors << std::endl;
124}
125
126
127}
128
129
130#endif /* FLANN_PARAMS_H_ */
Note: See TracBrowser for help on using the repository browser.