Questions tagged [kdtree]

A k-d-tree (k-dimensional tree) is a data structure for storing points in multidimensional space. They can be used to efficiently query for whether a point exists, as well as to do Euclidean nearest-neighbor searches and searches inside of hyperdimensional rectangular regions.

457 questions
6
votes
1 answer

python point indices in KDTree

Given a list of points, how can I get their indices in a KDTree? from scipy import spatial import numpy as np #some data x, y = np.mgrid[0:3, 0:3] data = zip(x.ravel(), y.ravel()) points = [[0,1], [2,2]] #KDTree tree = spatial.cKDTree(data) #…
a.smiet
  • 1,727
  • 3
  • 21
  • 36
6
votes
1 answer

KD-Tree in GLSL

after one day of trying to figure out how to implement a kd-tree in OpenGL/GLSL i am pretty frustrated ... I declare my KD-Nodes like this in GLSL: layout(std140) uniform node{ ivec4 splitPoint; int dataPtr; } nodes[1024]; SplitPoint holds the…
fho
  • 6,787
  • 26
  • 71
6
votes
1 answer

Partition large amount of 3D point data

I need to partition a large set of 3D points (using C++). The points are stored on the HDD as binary float array, and the files are usually larger than 10GB. I need to divide the set into smaller subsets that have a size less than 1GB. The points…
blasalat
  • 91
  • 4
6
votes
2 answers

Something faster than std::nth_element

I'm working on a kd-tree implementation and I'm currently using std::nth_element for partition a vector of elements by their median. However std::nth_element takes 90% of the time of tree construction. Can anyone suggest a more efficient…
plasmacel
  • 8,183
  • 7
  • 53
  • 101
6
votes
1 answer

Nanoflann radius search

I have a doubt regarding the parameter search_radius in nanoflann's radiusSearch function. My code is this: #include #include #include #include "nanoflann.hpp" #include "Eigen/Dense" int main() { Eigen::MatrixXf…
BRabbit27
  • 6,333
  • 17
  • 90
  • 161
6
votes
1 answer

MemoryError in Python while using cKDTree().query_ball_tree

I have large 2D arrays with unsorted (X,Y) points, for which I need to know which points are in close proximity to each other (nearest-neighbor lookup). I have used cKDTree and query_ball_tree with succes for arrays with around 500,000 (X,Y) points.…
6
votes
3 answers

Balancing KD-Tree: Which approach is more efficient?

I'm trying to balance a set of (Million +) 3D points using a KD-tree and I have two ways of doing it. Way 1: Use an O(n) algorithm to find the arraysize/2-th largest element along a given axis and store it at the current node Iterate over all the…
user1782677
  • 1,963
  • 5
  • 26
  • 48
6
votes
3 answers

Is kd-Tree an alternative to K-means clustering?

I'm working with BOW object detection and I'm working on the encoding stage. I have seen some implementations that use kd-Tree in the encoding stage, but most writings suggest that K-means clustering is the way to go. What is the difference between…
mugetsu
  • 4,228
  • 9
  • 50
  • 79
6
votes
2 answers

QuadTree or Octree templatized implementation in C++

I'm going to write a templatized implementation of a KDTree, which for now should only work as Quadtree or Octree for a BarnesHut implementation. The crucial point here is the design, I would like to specify the number of dimension where the tree is…
linello
  • 8,451
  • 18
  • 63
  • 109
5
votes
2 answers

Which spatial data structure (algorithm) is best for (searching in) a set of regions (spacial data)?

I have a set of regions (geo-fences) which are polygons. This set of data is fixed; so there is no need for insertion and deletion of data. Which data structure can be used for searching for regions that a query point (longitude, latitude) is in…
Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139
5
votes
3 answers

Sort coordinates of pointcloud by distance to previous point

Pointcloud of rope with desired start and end point I have a pointcloud of a rope-like object with about 300 points. I'd like to sort the 3D coordinates of that pointcloud, so that one end of the rope has index 0 and the other end has index 300 like…
Xaagas
  • 51
  • 1
5
votes
0 answers

Why scipy 'cKDTree' is slower than 'cdist' for finding the nearest point?

I've been told throughout many references that KDTree is a fast way to find nearest neighbors for large data. My current issue is to find the nearest points in X for a given data A. To elaborate, currently, X has 1,000,000 numerical data and A…
Cody Chung
  • 629
  • 1
  • 6
  • 15
5
votes
1 answer

Scipy: how to convert KD-Tree distance from query to kilometers (Python/Pandas)

This post builds upon this one. I got a Pandas dataframe containing cities with their geo-coordinates (geodetic) as longitude and latitude. import pandas as pd df = pd.DataFrame([{'city':"Berlin", 'lat':52.5243700, 'lng':13.4105300}, …
Matthias
  • 5,574
  • 8
  • 61
  • 121
5
votes
2 answers

python sklearn KDTree with haversine distance

I try to create a KD tree of WGS84 coordinates and find neighbors within a certain radius from sklearn.neighbors.dist_metrics import DistanceMetric from sklearn.neighbors.kd_tree import KDTree T = KDTree([[47.8665, 8.90123]],…
user307380
  • 55
  • 1
  • 4
5
votes
1 answer

Ray Tracing F# - Missing triangles creates holes in figure: Hit properly?

I have worked on this quite a while and is stuck with this bug. We have build a ray-tracer in F# for a school project. (Link explaining Ray tracer: https://blog.frogslayer.com/kd-trees-for-faster-ray-tracing-with-triangles/) We have a made hit…
em0605
  • 197
  • 2
  • 9