Skip to content

Commit

Permalink
Removed duplicate code by including utils.h
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjal-rai committed Aug 22, 2017
1 parent ea9eda2 commit 2f21a51
Showing 1 changed file with 1 addition and 48 deletions.
49 changes: 1 addition & 48 deletions examples/example_with_pkgconfig/pointcloud_example.cpp
Expand Up @@ -27,60 +27,13 @@
*************************************************************************/

#include <nanoflann.hpp>

#include "../utils.h"
#include <cstdlib>
#include <iostream>

using namespace std;
using namespace nanoflann;

// This is an exampleof a custom data set class
template <typename T>
struct PointCloud
{
struct Point
{
T x,y,z;
};

std::vector<Point> pts;

// Must return the number of data points
inline size_t kdtree_get_point_count() const { return pts.size(); }

// Returns the dim'th component of the idx'th point in the class:
// Since this is inlined and the "dim" argument is typically an immediate value, the
// "if/else's" are actually solved at compile time.
inline float kdtree_get_pt(const size_t idx, int dim) const
{
if (dim==0) return pts[idx].x;
else if (dim==1) return pts[idx].y;
else return pts[idx].z;
}

// Optional bounding-box computation: return false to default to a standard bbox computation loop.
// Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
// Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
template <class BBOX>
bool kdtree_get_bbox(BBOX &bb) const { return false; }

};

template <typename T>
void generateRandomPointCloud(PointCloud<T> &point, const size_t N, const T max_range = 10)
{
std::cout << "Generating "<< N << " point cloud...";
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);
}

std::cout << "done\n";
}

template <typename num_t>
void kdtree_demo(const size_t N)
{
Expand Down

0 comments on commit 2f21a51

Please sign in to comment.