jlblancoc / nanoflann

nanoflann: a C++11 header-only library for Nearest Neighbor (NN) search with KD-trees
Other
2.26k stars 491 forks source link

How to add KDTree into a hashset/hashmap? #204

Closed JiayingGaoo closed 1 year ago

JiayingGaoo commented 1 year ago

Hi there, Thanks for your great and impressive work! I am new to nanoflann. I want to add some kdtree into a hashset, just like below:

` using KDTree = KDTreeSingleIndexAdaptor<L2_Simple_Adaptor<double, Point2D>, Point2D, 2/ dim />; KDTree kd0 = KDTree(2, cloud0); KDTree kd1 = KDTree(2, cloud1); KDTree kd2 = KDTree(2, cloud2);

unordered_set trees = {kd0, kd1, kd2}; `

Then, a mistake is encountered: error C2440: 'initializing': cannot convert from 'initializer list' to 'std::unordered_set<KDTRee,std::hash,std::equal_to,std::allocator>'

What can i do to fix it, thanks a lot!

JiayingGaoo commented 1 year ago

Maybe I need to construct the hashset by the pointers, such like: unordered_set<KDTree*>?

JiayingGaoo commented 1 year ago

Thanks, I solve it.

jlblancoc commented 1 year ago

Cool! Yeah, using pointers is a possible solution. Another is creating your own overload of hash. Read, for example, this SO thread.