Obtaining a vector of coordinates from a vector of indexes from a point cloud

Question:

I was tinkering around with open3d and I got to the point where I found myself having a vector made from the index of each point I got from a radius search and it looks somewhat like this:

[1500, 1497, 1509, 1503, 1499, 1555, 1557, ... , 1565]

I would like to create another vector made with the coordinates of each point in that list, knowing that I can obtain a points coordinate by doing this:

pcd.points[index]

The final result would I want to achieve would look somewhat like this:

[[0.65234375 0.84686458 2.37890625],
 [0.65234375 0.83984375 2.38430572],
 [0.66737998 0.83984375 2.37890625],
 ...
 [2.00839925 2.39453125 1.88671875],
 [2.00390625 2.39488506 1.88671875],
 [2.00390625 2.39453125 1.88793314]]

I know this might be a basic question but I have been trying to get my head around this for a couple hours and I found myself to be blocked.

Now, if someone wants to get more context this is the code I am using right now

mesh = o3d.io.read_triangle_mesh("ModelNet10/chair/test/chair_0890.off")
pcd = o3d.geometry.TriangleMesh.sample_points_uniformly(mesh,5000)
pcd_tree = o3d.geometry.KDTreeFlann(pcd)
[k, idx, _] = pcd_tree.search_radius_vector_3d(pcd.points[1500], 2)

I would like being able to grab that vector that comes from the radius search and have the coordinate of each point from that radius search in a vector so I can work with it.

Answers:

After banging my head against my monitor I found out that my answer was in front of my eyes but I was so stubborn in solving it a way I wasn’t even able to think about I couldn’t tell.

The only thing I needed to do is just

points = o3d.np.asarray(pcd.points)[idx[1:], :]

Just as I did for coloring each point.

Although I managed to get what I wanted I’d like to see any other useful answers or an actual optimal answer to keep learning. Thanks!

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.