daavoo / pyntcloud

pyntcloud is a Python library for working with 3D point clouds.
http://pyntcloud.readthedocs.io
MIT License
1.39k stars 221 forks source link

kdtree radius search not working #344

Open tholzmann opened 1 year ago

tholzmann commented 1 year ago

Describe the bug When running radius search on my point cloud, I get an error:

File "D:\repos\scripts\venv\lib\site-packages\pyntcloud\core_class.py", line 590, in get_neighbors return r_neighbors(kdtree, r) File "D:\repos\scripts\venv\lib\site-packages\pyntcloud\neighbors\r_neighbors.py", line 21, in r_neighbors return np.array(kdtree.query_ball_tree(kdtree, r)) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5342,) + inhomogeneous part.`

k-neighbor search works as expected.

To Reproduce My code to reproduce the bug:

cloud = PyntCloud.from_file(pc_path) kdtree_id = cloud.add_structure("kdtree") r_neighbors = cloud.get_neighbors( r=5, kdtree=kdtree_id)

Desktop (please complete the following information):

tholzmann commented 1 year ago

When reading some comments from this stackoverflow thread [1], I actually found out that it seems to be a Python 3.9 issue. The line 21 in neighbors/r_neighbors.py needs to be changed to:

return np.array(kdtree.query_ball_tree(kdtree, r), dtype=object)

so the argument dtype=object needs to be added.

[1] https://stackoverflow.com/questions/10346336/list-of-lists-into-numpy-array/26224619#26224619