isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.28k stars 2.29k forks source link

Use o3d.geometry.KDTreeFlann with o3d.t.geometry.PointCloud #6314

Open Buglakova opened 1 year ago

Buglakova commented 1 year ago

Checklist

My Question

Hello,

I register two point clouds and then I'd like to find several nearest neighbors in the moving point cloud for each point in the fixed point cloud. I handle point clouds using o3d.t.geometry.PointCloud, especially because I have additional custom attributes of the points that I need to read and write. I try to use o3d.geometry.KDTreeFlann like this:

pcd1 = o3d.t.io.read_point_cloud("point_cloud_1.pcd")
pcd2 = o3d.t.io.read_point_cloud("point_cloud_2.pcd")
pcd1_tree = o3d.geometry.KDTreeFlann(pcd1.point.positions.numpy())
example_point = pcd2.point.positions.numpy()[0]
n, idx, d = pcd1_tree.search_hybrid_vector_3d(example_point, 10, 1)

which gives RuntimeError: search_hybrid_vector_3d() error! I assume that the data type of the point is wrong (it's float64 numpy array) but not sure how to fix it. Is there a way to do the same without going back to the legacy geometry classes?

theNded commented 1 year ago

First of all, there is a new nns engine for t point clouds (https://github.com/isl-org/Open3D/blob/master/cpp/open3d/core/nns/KnnIndex.h), but the python binding is not there AFAIK. I will assign myself to follow up this item. Regarding the legacy search engine you are using, it lacks proper boundary condition check and may be related to #6235, I will have to follow up as well. For the workaround itself, using o3d.geometry.KDTreeFlann(pcd1.point.positions.numpy().T) will fix the problem. It sounds weird but there is a transpose between the raw input (e.g. numpy) and the geometry (e.g. point cloud).

Buglakova commented 1 year ago

That's right, I missed the .T bit, thank you!

Looking forward to see the new engine available for Python users too

yuecideng commented 1 year ago

Hi @theNded @Buglakova , I think the pybind for new nns engine is already supported (see o3d.core.nns). But the related documentation is missing.

saurabheights commented 1 year ago

If true, please leave docs tag here. I wont be able to work asap, but I am keeping track of all issues labelled docs.