mirror of
https://github.com/jlblancoc/nanoflann.git
synced 2026-01-16 21:01:17 +01:00
first commit: a performance test for FLANN and kd-trees with 3D point clouds
This commit is contained in:
29
COPYING
Normal file
29
COPYING
Normal file
@@ -0,0 +1,29 @@
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
|
||||
Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
|
||||
Copyright 2011 Jose L. Blanco (joseluisblancoc@gmail.com). All rights reserved.
|
||||
|
||||
THE BSD LICENSE
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
27
perf-tests/flann/Makefile
Normal file
27
perf-tests/flann/Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
# Set up basic variables:
|
||||
CC = g++
|
||||
CFLAGS = -c -Wall -O2
|
||||
LDFLAGS =
|
||||
|
||||
# List of sources:
|
||||
SOURCES = test_flann.cpp
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
# Name of executable target:
|
||||
EXECUTABLE = test_flann
|
||||
|
||||
CFLAGS += `pkg-config --cflags flann`
|
||||
#LDFLAGS += `pkg-config --libs flann`
|
||||
LDFLAGS += -lflann_cpp
|
||||
|
||||
all: $(SOURCES) $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
|
||||
|
||||
.cpp.o:
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm $(OBJECTS) $(EXECUTABLE)
|
||||
|
||||
131
perf-tests/flann/test_flann.cpp
Normal file
131
perf-tests/flann/test_flann.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/***********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright 2011 Jose Luis Blanco (joseluisblancoc@gmail.com).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*************************************************************************/
|
||||
|
||||
#include <flann/flann.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <sys/time.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace flann;
|
||||
|
||||
template <typename T>
|
||||
struct PointCloud
|
||||
{
|
||||
struct Point
|
||||
{
|
||||
T x,y,z;
|
||||
};
|
||||
|
||||
std::vector<Point> pts;
|
||||
};
|
||||
|
||||
double get_time()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
return tv.tv_sec+tv.tv_usec/1000000.0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void generateRandomPointCloud(PointCloud<T> &point, const size_t N, const T max_range = 10)
|
||||
{
|
||||
cout << "Generating "<< N << " point cloud...";cout.flush();
|
||||
const double t0=get_time();
|
||||
|
||||
point.pts.resize(N);
|
||||
for (size_t i=0;i<N;i++)
|
||||
{
|
||||
point.pts[i].x = max_range * (rand() % 1000) / T(1000);
|
||||
point.pts[i].y = max_range * (rand() % 1000) / T(1000);
|
||||
point.pts[i].z = max_range * (rand() % 1000) / T(1000);
|
||||
}
|
||||
|
||||
const double t1=get_time();
|
||||
cout << "done in "<< (t1-t0)*1e3 << " ms\n";
|
||||
}
|
||||
|
||||
template <typename num_t>
|
||||
void perf_test(const size_t N)
|
||||
{
|
||||
PointCloud<num_t> cloud;
|
||||
|
||||
// Generate points:
|
||||
generateRandomPointCloud(cloud, N);
|
||||
|
||||
// Convert to Matrix<>:
|
||||
double t0=get_time();
|
||||
num_t *cloud_pts = new num_t[N*3];
|
||||
{
|
||||
num_t *ptr = cloud_pts;
|
||||
for (size_t i=0;i<N;i++)
|
||||
{
|
||||
*ptr++ = cloud.pts[i].x;
|
||||
*ptr++ = cloud.pts[i].y;
|
||||
*ptr++ = cloud.pts[i].z;
|
||||
}
|
||||
}
|
||||
Matrix<float> dataset(cloud_pts,cloud.pts.size(),3);
|
||||
double t1=get_time();
|
||||
cout << "Convert to Matrix<>: " << (t1-t0)*1e3 << " ms\n";
|
||||
|
||||
num_t query_pt[3] = { 0.5, 0.5, 0.5};
|
||||
Matrix<num_t> query(query_pt,1,3);
|
||||
|
||||
const size_t num_results = 1;
|
||||
|
||||
Matrix<int> indices(new int[query.rows*num_results], query.rows, num_results);
|
||||
Matrix<float> dists(new float[query.rows*num_results], query.rows, num_results);
|
||||
|
||||
// construct an randomized kd-tree index using 4 kd-trees
|
||||
t0=get_time();
|
||||
Index<L2<float> > index(dataset, flann::KDTreeIndexParams(4));
|
||||
index.buildIndex();
|
||||
t1=get_time();
|
||||
cout << "Build Index<>: " << (t1-t0)*1e3 << " ms\n";
|
||||
|
||||
// do a knn search
|
||||
t0=get_time();
|
||||
index.knnSearch(query, indices, dists, num_results, flann::SearchParams(10));
|
||||
t1=get_time();
|
||||
cout << "knnSearch(nn="<<num_results<<"): " << (t1-t0)*1e3 << " ms\n";
|
||||
|
||||
dataset.free();
|
||||
indices.free();
|
||||
dists.free();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
perf_test<float>(100000);
|
||||
perf_test<float>(1000000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
perf-tests/nanoflann/Makefile
Normal file
31
perf-tests/nanoflann/Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Set up basic variables:
|
||||
CC = g++
|
||||
CFLAGS = -c -Wall
|
||||
LDFLAGS =
|
||||
|
||||
# List of sources:
|
||||
SOURCES = test_flann.cpp
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
# Name of executable target:
|
||||
EXECUTABLE = test_flann
|
||||
|
||||
# MRPT specific flags:
|
||||
# Here we invoke "pkg-config" passing it as argument the list of the
|
||||
# MRPT libraries needed by our program (see available libs
|
||||
# with "pkg-config --list-all | grep mrpt").
|
||||
#
|
||||
CFLAGS += `pkg-config --cflags mrpt-base`
|
||||
LDFLAGS += `pkg-config --libs mrpt-base`
|
||||
|
||||
|
||||
all: $(SOURCES) $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
|
||||
|
||||
.cpp.o:
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm $(OBJECTS) $(EXECUTABLE)
|
||||
0
perf-tests/nanoflann/test_nanoflann.cpp
Normal file
0
perf-tests/nanoflann/test_nanoflann.cpp
Normal file
Reference in New Issue
Block a user