params.h
Go to the documentation of this file.
00001 /***********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright 2008-2011  Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
00005  * Copyright 2008-2011  David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  *************************************************************************/
00028 
00029 
00030 #ifndef RTABMAP_FLANN_PARAMS_H_
00031 #define RTABMAP_FLANN_PARAMS_H_
00032 
00033 #include "rtflann/util/any.h"
00034 #include "rtflann/general.h"
00035 #include <iostream>
00036 #include <map>
00037 
00038 
00039 namespace rtflann
00040 {
00041 
00042 namespace anyimpl
00043 {
00044 SMALL_POLICY(flann_algorithm_t);
00045 SMALL_POLICY(flann_centers_init_t);
00046 SMALL_POLICY(flann_log_level_t);
00047 SMALL_POLICY(flann_datatype_t);
00048 }
00049 
00050 
00051 typedef std::map<std::string, any> IndexParams;
00052 
00053 
00054 typedef enum {
00055         FLANN_False = 0,
00056         FLANN_True = 1,
00057         FLANN_Undefined
00058 } tri_type;
00059 
00060 
00061 struct SearchParams
00062 {
00063     SearchParams(int checks_ = 32, float eps_ = 0.0, bool sorted_ = true ) :
00064         checks(checks_), eps(eps_), sorted(sorted_)
00065     {
00066         max_neighbors = -1;
00067         use_heap = FLANN_Undefined;
00068         cores = 1;
00069         matrices_in_gpu_ram = false;
00070     }
00071 
00072     // how many leafs to visit when searching for neighbours (-1 for unlimited)
00073     int checks;
00074     // search for eps-approximate neighbours (default: 0)
00075     float eps;
00076     // only for radius search, require neighbours sorted by distance (default: true)
00077     bool sorted;
00078     // maximum number of neighbors radius search should return (-1 for unlimited)
00079     int max_neighbors;
00080     // use a heap to manage the result set (default: FLANN_Undefined)
00081     tri_type use_heap;
00082     // how many cores to assign to the search (used only if compiled with OpenMP capable compiler) (0 for auto)
00083     int cores;
00084     // for GPU search indicates if matrices are already in GPU ram
00085     bool matrices_in_gpu_ram;
00086 };
00087 
00088 
00089 inline bool has_param(const IndexParams& params, std::string name)
00090 {
00091         return params.find(name)!=params.end();
00092 }
00093 
00094 template<typename T>
00095 T get_param(const IndexParams& params, std::string name, const T& default_value)
00096 {
00097     IndexParams::const_iterator it = params.find(name);
00098     if (it != params.end()) {
00099         return it->second.cast<T>();
00100     }
00101     else {
00102         return default_value;
00103     }
00104 }
00105 
00106 template<typename T>
00107 T get_param(const IndexParams& params, std::string name)
00108 {
00109     IndexParams::const_iterator it = params.find(name);
00110     if (it != params.end()) {
00111         return it->second.cast<T>();
00112     }
00113     else {
00114         throw FLANNException(std::string("Missing parameter '")+name+std::string("' in the parameters given"));
00115     }
00116 }
00117 
00118 inline void print_params(const IndexParams& params)
00119 {
00120     IndexParams::const_iterator it;
00121 
00122     for(it=params.begin(); it!=params.end(); ++it) {
00123         std::cout << it->first << " : " << it->second << std::endl;
00124     }
00125 }
00126 
00127 inline void print_params(const SearchParams& params)
00128 {
00129         std::cout << "checks : " << params.checks << std::endl;
00130         std::cout << "eps : " << params.eps << std::endl;
00131         std::cout << "sorted : " << params.sorted << std::endl;
00132         std::cout << "max_neighbors : " << params.max_neighbors << std::endl;
00133 }
00134 
00135 
00136 }
00137 
00138 
00139 #endif /* FLANN_PARAMS_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:17