Open3d.geometry.VoxelGrid.get_voxel() 返回负值?

问题描述 投票:0回答:0

我使用

open3d.geometry.VoxelGrid
格式的点云创建一个
numpy.array
对象。

然后给定一个3D位置,我想查询点所在体素的网格索引

但是当我使用函数时我得到了负数

get_voxel()
.

get_voxel()
返回的“体素指数”和“网格指数”一样吗?如果是,返回值应该是 >= 0.

重现bug的文件在这里

重现错误的步骤

import numpy as np
import msgpack
import msgpack_numpy
msgpack_numpy.patch()
import zstandard as zstd
import open3d as o3d
import torch
from pytorch3d.ops import knn_points

N = 100 

### read particle positions

datapath = 'datasets/ours_default_data/train/sim_0001_00.msgpack.zst'
decompressor = zstd.ZstdDecompressor()

# read all data from file
with open(datapath, 'rb') as f:
    data = msgpack.unpackb(decompressor.decompress(f.read()), raw=False)
pos = data[0]['pos']

### pcd2voxel

pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(pos)

# fit to unit cube
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()), center=pcd.get_center())
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))
# o3d.visualization.draw_geometries([pcd])

voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=0.05)
voxels = voxel_grid.get_voxels()
voxel_index = np.array([voxels[i].grid_index for i in range(len(voxels))])
print(voxel_index.max(),voxel_index.min()) # [20, 0]

#  create a hash table to map the voxel grid_index to the voxel number in the voxels list
voxel_hash = {}
for i in range(len(voxels)):
    voxel_hash[tuple(voxels[i].grid_index)] = i
    
pos_grid_index = []
for i in range (len(pos)):
    pos_grid_index.append(voxel_grid.get_voxel(pos[i]))
pos_grid_index = np.array(pos_grid_index)
print(pos_grid_index.shape)
print(pos_grid_index.max(), pos_grid_index.min()) # [26, -6]

我期望

get_voxel()
函数返回数字 >= 0 的 3D 列表。

grid_index 好像和voxel index 不一样。谁能说说两者之间的关系?非常感谢! XD

python voxel open3d
© www.soinside.com 2019 - 2024. All rights reserved.