I was am trying to find more efficent and faster way of unpacking a list of objects into its component parts. The approach i have currently working is this:
points_fill_v2 = o3d.geometry.VoxelGrid.create_from_point_cloud(points,
voxel_size=vox)
scrap = points_fill_v2 .get_voxels()
resize3d = np.ones((3, 64, 64, 64))
for idx in range(len(scrap)):
resize3d[0, scrap[idx].grid_index[0], scrap[idx].grid_index[1], scrap[idx].grid_index[2]] = scrap[idx].color[0]
resize3d[1, scrap[idx].grid_index[0], scrap[idx].grid_index[1], scrap[idx].grid_index[2]] = scrap[idx].color[1]
resize3d[2, scrap[idx].grid_index[0], scrap[idx].grid_index[1], scrap[idx].grid_index[2]] = scrap[idx].color[2]
scrap
is a list and looks like this:
[Voxel with grid_index: (7, 27, 30), color: (0, 0, 1), Voxel with grid_index: (32, 9, 8), color: (0, 0, 0), ......]
It has 2 properties; grid index and color, both are numpy 1,3 arrays.
The above code converts a point cloud into a voxel dataset using open3d (I have to use open3d), and then converts that into a RGB 3d numpy array.
I can split out the main list into 2 other lists (and then arrays) using:
grid = [scrap[idx].grid_index for idx in range(len(scrap))]
colour = [scrap[idx].color for idx in range(len(scrap))]
How do I transfer the data in colour into resize_3d
efficiently using the index stored in grid
?