1

I am trying to find the exact number of neighbour nodes in a big 3D points dataset. The goal is for each point of the dataset to retrieve all the possible neighbours in a region with a given radius. FLANN ensures that for lower dimensional data can retrieve the exact neighbors while comparing with brute force search it seems to not be the case. The neighbors are essential for further calculations and therefore I need the exact number. I tested increasing the radius a little bit but doesn't seem to be this the problem. Is anyone aware how to calculate the exact neighbors with FLANN or other C++ library?

The code:

// All nodes to be tested for inclusion in support domain.
flann::Matrix<double> query_nodes = flann::Matrix<double>(&nodes_pos[0].x, nodes_pos.size(), 3);

// Set default search parameters
flann::SearchParams search_parameters = flann::SearchParams();
search_parameters.checks = -1;
search_parameters.sorted = false;
search_parameters.use_heap = flann::FLANN_True;

flann::KDTreeSingleIndexParams index_parameters = flann::KDTreeSingleIndexParams();
flann::KDTreeSingleIndex<flann::L2_3D<double> > index(query_nodes, index_parameters);
index.buildIndex();

//FLANN uses L2 for radius search.
double l2_radius = (this->support_layer_*grid.spacing)*(this->support_layer_*grid.spacing);
double extension = l2_radius/10.;
l2_radius+= extension;

index.radiusSearch(query_nodes, indices, dists, l2_radius, search_parameters);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

Try nanoflann. It is designed for low dimensional spaces and gives exact nearest neighbors. Furthermore, it is just one header file that you can either "install" or just copy to your project.

0

You should check page 6+ from the flann-manual, to fine-tune your search parameters, such as target_precision, which should be set to 1, for "maximum" accuracy.

That parameter is often found as epsilon (ε) in Approximate Nearest Neighbor Search (ANNS), which is used in high dimensional spaces, in order to (try) to beat the curse of dimensionality. FLANN is usually used in 128 dimensions, not 3, as far as I can tell, which may explain the bad performance you are experiencing.

A library that works well in 3 dimensions is CGAL. However, it's much larger than FLANN, because it is a library for computational geometry, thus it provides functionality for many problems, not just NNS.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • Thank you gsamaras for your reply. I discovered a bug in how my data "strored in vector" is copied in the flann matrices to be tested. I search through the web and this problem was previously mentioned without any good replies. Do you know how i could properly initialize the querry_points flann matrix. It contains wrong values in the current state. I am trying to deal with it but unfortunately without success. – Constantino Mood Oct 31 '16 at 17:34
  • I am not sure @ConstantinoMood. Which variable exactly has the problem in your code? I haven't used FLANN for ages. Did you check the examples in the manual? I remember building my code upon these examples back then... – gsamaras Oct 31 '16 at 17:49
  • the flann matrix querry_nodes was bad initialized but I fixed it. However the error in the neighbors consists. I use the optimized ksingletreeindex for low dimensional data and doesnt give option to set the precision. I guess i should try out cgal for possible better accuracy. I saw you have experience with cgal too. Do you know if it is possible to retrieve exact points? – Constantino Mood Nov 01 '16 at 13:04
  • Yes it is @ConstantinoMood, but be aware that CGAL is not adviced for high dimensional spaces, it is good for 2D and 3D! ;) BTW, if you find the answer useful, you can *accept* it if you want. – gsamaras Nov 01 '16 at 13:25
  • that would be no problem since i am interested only in 2d and 3d points. I am newbie here, how i can accept the answer? Was helpful! :p – Constantino Mood Nov 01 '16 at 16:51