Mesh colormaps¶

This is a Python port for the mesh colormaps live demo

In [1]:
from ipyniivue import NiiVue
import ipywidgets as widgets
from IPython.display import display

nv = NiiVue(back_color=(0.9, 0.9, 1.0, 1))

meshLHLayersList1 = [
    {
        "path": "../images/BrainMesh_ICBM152.lh.curv",
        "colormap": "gray",
        "cal_min": 0.3,
        "cal_max": 0.5,
        "opacity": 0.7,
    }
]

nv.load_meshes(
    [
        {
            "path": "../images/BrainMesh_ICBM152.lh.mz3",
            "layers": meshLHLayersList1,
        }
    ]
)

## Create interactive widgets

# Curvature Slider
curve_slider = widgets.IntSlider(
    value=7,
    min=0,
    max=10,
    step=1,
    description="Curvature",
    readout=False
)


def on_curve_slider_change(change):
    """Set mesh layer 0 opacity."""
    nv.set_mesh_layer_property(nv.meshes[0].id, 0, "opacity", change["new"] * 0.1)


curve_slider.observe(on_curve_slider_change, names="value")


## Create the shader header buttons



# Get available shaders
shader_options = nv.mesh_shader_names()

shader_dropdown = widgets.Dropdown(
    options=shader_options,
    value="Phong",  # Default shader
    description="Shader:"
)


def on_shader_change(change):
    """Set mesh layer shader."""
    nv.set_mesh_shader(nv.meshes[0].id, change["new"])


shader_dropdown.observe(on_shader_change, names="value")


## Display

# Display header controls
header_controls = widgets.HBox(
    [
        curve_slider, shader_dropdown
    ]
)

display(header_controls)
display(nv)
In [ ]:
 
In [ ]: