31 #ifndef RTABMAP_FLANN_INDEX_TESTING_H_
32 #define RTABMAP_FLANN_INDEX_TESTING_H_
51 for (
int i=0;
i<
n; ++
i) {
52 for (
int k=0; k<
n; ++k) {
53 if (neighbors[i]==groundTruth[k]) {
63 template <
typename Distance>
65 size_t* neighbors,
size_t* groundTruth,
int veclen,
int n,
const Distance& distance)
67 typedef typename Distance::ResultType DistanceType;
70 for (
int i=0;
i<
n; ++
i) {
71 DistanceType den =
distance(inputData[groundTruth[i]], target, veclen);
72 DistanceType num =
distance(inputData[neighbors[i]], target, veclen);
74 if ((den==0)&&(num==0)) {
85 template <
typename Index,
typename Distance>
88 float& time,
typename Distance::ResultType& dist,
const Distance& distance,
int skipMatches)
90 typedef typename Distance::ElementType ElementType;
91 typedef typename Distance::ResultType DistanceType;
94 Logger::info(
"matches.cols=%d, nn=%d\n",
matches.cols,
nn);
95 throw FLANNException(
"Ground truth is not computed for as many neighbors as requested");
98 SearchParams searchParams(checks);
100 size_t*
indices =
new size_t[
nn+skipMatches];
101 DistanceType* dists =
new DistanceType[
nn+skipMatches];
106 size_t* neighbors =
indices + skipMatches;
109 DistanceType
distR = 0;
112 while (
t.value<0.2) {
117 for (
size_t i = 0;
i < testData.
rows;
i++) {
130 float precicion = (
float)correct/(nn*testData.
rows);
134 Logger::info(
"%8d %10.4g %10.5g %10.5g %10.5g\n",
135 checks, precicion, time, 1000.0 * time / testData.
rows, dist);
141 template <
typename Index,
typename Distance>
144 int checks,
float&
precision,
const Distance& distance,
int nn = 1,
int skipMatches = 0)
146 typedef typename Distance::ResultType DistanceType;
148 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
149 Logger::info(
"---------------------------------------------------------\n");
152 DistanceType
dist = 0;
158 template <
typename Index,
typename Distance>
161 float precision,
int& checks,
const Distance& distance,
int nn = 1,
int skipMatches = 0)
163 typedef typename Distance::ResultType DistanceType;
164 const float SEARCH_EPS = 0.001f;
166 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
167 Logger::info(
"---------------------------------------------------------\n");
179 Logger::info(
"Got as close as I can\n");
194 Logger::info(
"Start linear estimation\n");
199 realPrecision =
search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
210 Logger::info(
"Got as close as I can\n");
213 realPrecision =
search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
221 Logger::info(
"No need for linear estimation\n");
231 template <
typename Index,
typename Distance>
234 float* precisions,
int precisions_length,
const Distance& distance,
int nn = 1,
int skipMatches = 0,
float maxTime = 0)
236 typedef typename Distance::ResultType DistanceType;
238 const float SEARCH_EPS = 0.001;
241 std::sort(precisions, precisions+precisions_length);
246 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
247 Logger::info(
"---------------------------------------------------------\n");
263 while (precisions[pindex]<p2 && pindex<precisions_length) {
267 if (pindex==precisions_length) {
268 Logger::info(
"Got as close as I can\n");
272 for (
int i=pindex;
i<precisions_length; ++
i) {
280 if ((maxTime> 0)&&(time > maxTime)&&(p2<
precision))
return;
286 Logger::info(
"Start linear estimation\n");
291 realPrecision =
search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
302 Logger::info(
"Got as close as I can\n");
305 realPrecision =
search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches);
313 Logger::info(
"No need for linear estimation\n");
323 #endif //FLANN_INDEX_TESTING_H_