Interactive 3D Visualization using Mayavi

About

Mayavi is a scientific visualization library that is quite well equipped to to visualize point cloud data.

Getting Mayavi

Under construction.... In the mean time you can check out this gist to get it set up on your machine if you are using Ubuntu.

  • TLDR; mayavi is a pain in the ass to install.

Visualizing

Under construction.... in the mean time I have put together this following function to visualize the point cloud data. This will be explained in more detail later.

# ==============================================================================
#                                                                     VIZ_MAYAVI
# ==============================================================================
def viz_mayavi(points, vals="distance"):
    x = points[:, 0]  # x position of point
    y = points[:, 1]  # y position of point
    z = points[:, 2]  # z position of point
    # r = lidar[:, 3]  # reflectance value of point
    d = np.sqrt(x ** 2 + y ** 2)  # Map Distance from sensor

    # Plot using mayavi -Much faster and smoother than matplotlib
    import mayavi.mlab

    if vals == "height":
        col = z
    else:
        col = d

    fig = mayavi.mlab.figure(bgcolor=(0, 0, 0), size=(640, 360))
    mayavi.mlab.points3d(x, y, z,
                         col,          # Values used for Color
                         mode="point",
                         colormap='spectral', # 'bone', 'copper', 'gnuplot'
                         # color=(0, 1, 0),   # Used a fixed (r,g,b) instead
                         figure=fig,
                         )
    mayavi.mlab.show()

Using this function gives interactive 3D visualisations such as the one in the following video.