Skip to content

How to set min max for colormap when rendering a pointcloud?

AlexZakIntel edited this page Jan 27, 2022 · 2 revisions

Q: How to set the range of the colormap when rendering a pointcloud?

I only want a color gradient from ~z=0 to z=1 although there are points above and below that region. Is this currently possible? If yes, how?

A:

Please use the latest Open3D package (0.14+). Here is sample code for using the color gradient with the new API:

import open3d as o3d
from open3d.core import Tensor, concatenate
from open3d.visualization import rendering, draw
from open3d.ml.vis import Colormap

# Create a helix point cloud. We will use the Z values to assign colors.
values = Tensor.arange(start=0.0, stop=1.0, step=0.001,
                       dtype=o3d.core.float32).reshape((-1, 1))
period = 0.2
xyz = concatenate(
    ((6.28 / period * values).sin(), (6.28 / period * values).cos(), values), 1)
pcd = o3d.t.geometry.PointCloud(xyz)
# Use a special point property to specify colormap lookup values for the point
# cloud.
pcd.point['__visualization_scalar'] = values
# Use a default rainbow colormap
colormap = Colormap.make_rainbow()
# Add alpha channel and convert to Gradient Points
colormap = list(
    rendering.Gradient.Point(pt.value, pt.color + [1.0])
    for pt in colormap.points)
# Now create the material
material = rendering.MaterialRecord()
material.shader = "unlitGradient"
material.gradient = rendering.Gradient(colormap)
material.gradient.mode = rendering.Gradient.GRADIENT
material.scalar_min = 0.0
material.scalar_max = 1.0

draw(
     {
       'name': 'helix',
       'geometry': pcd,
       'material': material
     },
     point_size=3,
     show_skybox=False)

PCD Helix

For more detailed information, please see our Issues page at: https://github.com/isl-org/Open3D/issues/2545#issuecomment-987119956