astra-vision / MonoScene

[CVPR 2022] "MonoScene: Monocular 3D Semantic Scene Completion": 3D Semantic Occupancy Prediction from a single image
https://astra-vision.github.io/MonoScene/
Apache License 2.0
698 stars 69 forks source link

How to fixed the grid size in the mayavi? #37

Closed rockywind closed 1 year ago

rockywind commented 1 year ago

Dear, author, I found that if only one object is in the scene, the grid size is larger than the two objects in the scene. My code is below.

    # Compute the voxels coordinates
    grid_coords = get_grid_coords(
        [voxels.shape[0], voxels.shape[1], voxels.shape[2]], voxel_size
    )

    # Attach the predicted class to every voxel

    grid_coords = np.vstack([grid_coords.T, voxels.reshape(-1)]).T

    # Remove empty and unknown voxels
    occupied_voxels = grid_coords[(grid_coords[:, 3] > 0) & (grid_coords[:, 3] < 255)]

    # Draw occupied voxels
    plt_plot = mlab.points3d(
        occupied_voxels[:, 0],
        occupied_voxels[:, 1],
        occupied_voxels[:, 2],
        occupied_voxels[:, 3],
        colormap="viridis",
        scale_factor=voxel_size - 0.5 * voxel_size,
        mode="cube",
        opacity=1.0,
        vmin=0,
        vmax=12,
    )

    colors = np.array(
        [
            [100, 150, 245, 255],
            [100, 230, 245, 255],
            [30, 60, 150, 255],
            [80, 30, 180, 255],
            [100, 80, 250, 255],
            [255, 30, 30, 255],
            [255, 40, 200, 255],
            [150, 30, 90, 255],
            [255, 0, 255, 255],
            [255, 150, 255, 255],
            [75, 0, 75, 255],
            [175, 0, 75, 255],
            [255, 200, 0, 255],
            [255, 120, 50, 255],
            [0, 175, 0, 255],
            [135, 60, 0, 255],
            [150, 240, 80, 255],
            [255, 240, 150, 255],
            [255, 0, 0, 255],
        ]
    ).astype(np.uint8)

    plt_plot.glyph.scale_mode = "scale_by_vector"

    plt_plot.module_manager.scalar_lut_manager.lut.table = colors

    mlab.show()
    mlab.savefig(filename=save_path)

image image

anhquancao commented 1 year ago

Hi @rockywind, I don't understand your problem? The grid_size is defined here:

# Compute the voxels coordinates
  grid_coords = get_grid_coords(
      [voxels.shape[0], voxels.shape[1], voxels.shape[2]], voxel_size
  )

It doesn't depend on the objects.

rockywind commented 1 year ago

Dear author, The grid size is 0.25. But some objects grid size drawed in the picture is larger than anthor. I am confused.

rockywind commented 1 year ago

Dear author, Just like the two pictures below. Their grid size is 0.25. But the first picture's grid size looked larger the the second one. image image

anhquancao commented 1 year ago

Do you have the same voxels.shape? I think the scene will be scaled according to it

rockywind commented 1 year ago

The voxel's shape is 400 400 25 in all scenes, and the voxel size is 0.25. I can't find any scale factor in the code. I found that the grid size is smaller with the object's number increase. image image

anhquancao commented 1 year ago

Did you set the viewpoint? I think the problem is that the viewpoint was not set. You can follow this post to set the mayavi viewpoint https://anhquancao.github.io/blog/2022/how-to-define-viewpoint-programmatically-in-mayavi/