| 1 |
from typing import Optional |
| 2 |
|
| 3 |
import torch |
| 4 |
|
| 5 |
|
| 6 |
def grid_cluster( |
| 7 |
pos: torch.Tensor, |
| 8 |
size: torch.Tensor, |
| 9 |
start: Optional[torch.Tensor] = None, |
| 10 |
end: Optional[torch.Tensor] = None, |
| 11 |
) -> torch.Tensor: |
| 12 |
"""A clustering algorithm, which overlays a regular grid of user-defined |
| 13 |
size over a point cloud and clusters all points within a voxel. |
| 14 |
|
| 15 |
Args: |
| 16 |
pos (Tensor): D-dimensional position of points. |
| 17 |
size (Tensor): Size of a voxel in each dimension. |
| 18 |
start (Tensor, optional): Start position of the grid (in each |
| 19 |
dimension). (default: :obj:`None`) |
| 20 |
end (Tensor, optional): End position of the grid (in each |
| 21 |
dimension). (default: :obj:`None`) |
| 22 |
|
| 23 |
:rtype: :class:`LongTensor` |
| 24 |
|
| 25 |
.. code-block:: python |
| 26 |
|
| 27 |
import torch |
| 28 |
from torch_cluster import grid_cluster |
| 29 |
|
| 30 |
pos = torch.Tensor([[0, 0], [11, 9], [2, 8], [2, 2], [8, 3]]) |
| 31 |
size = torch.Tensor([5, 5]) |
| 32 |
cluster = grid_cluster(pos, size) |
| 33 |
""" |
| 34 |
return torch.ops.torch_cluster.grid(pos, size, start, end) |