marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
1.98k stars 257 forks source link

Adjacent connections and distance between adjacent point clouds #1131

Closed ttsesm closed 3 weeks ago

ttsesm commented 3 weeks ago

Hi @marcomusy,

Is there any easy way to get the adjacency connection between neighboring point clouds based on their distance to each other. For example in the following point clouds: image

I should get something like that: image

which is related to whether two point clouds are neighbors which you can specify it as a threshold of the minimum distance between the two closest points of the two point clouds.

pcds.zip

marcomusy commented 3 weeks ago

You can try this:

from vedo import *

tiles = load("data/pcds/pcd_*.ply")
# tiles = load("tile_*.ply")

dists = {}
for i, tile1 in enumerate(tiles):
    tile1.subsample(0.02).write(f"tile_{i}.ply")
    for j, tile2 in enumerate(tiles):
        if i <= j:
            continue
        dist = np.min(tile1.distance_to(tile2))
        dists[(i,j)] = dist

lines = []
for i, tile1 in enumerate(tiles):
    tile1.color(i).alpha(0.25).point_size(5)
    cm1 = tile1.center_of_mass()
    for j, tile2 in enumerate(tiles):
        if i <= j:
            continue
        if dists[(i,j)] < 10:
            cm2 = tile2.center_of_mass()
            line = Line(cm1, cm2).lw(4)
            lines.append(line)

show(tiles, lines, axes=1)

image

ttsesm commented 3 weeks ago

Looks good... :heart:

One clarification though the dist = np.min(tile1.distance_to(tile2)) is computed from the center of the point clouds to each other or the it gets the distance between all points of pcd1 to all points pcd2 and keeps the minimum one based on which two points between teh two pcds are the nearest ones. Because from the description of the function is not clear... :thinking:

Computes the distance from one point cloud or mesh to another point cloud or mesh.
        This new `pointdata` array is saved with default name "Distance".

        Keywords ``signed`` and ``invert`` are used to compute signed distance,
        but the mesh in that case must have polygonal faces (not a simple point cloud),
        and normals must also be computed.

It is the second case, right?

marcomusy commented 3 weeks ago

Yes - the second: all distances are computed irrespective of the center of mass.

ttsesm commented 3 weeks ago

Thanks a lot. (It even found a connection that I have overlooked in the top four tiles :+1: )