Connectomes¶

NiiVue considers connectomes as a special class of meshes. While most meshes have fixed vertex positions (e.g. a brain is considered to have a fixed size), the radius of connectome nodes and edges can be scaled dynamically. The notebook mirrors the JavaScript connectome web page.

n.b. this requires future version of ipyniivue with load_jcon

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

nv = NiiVue(show_3d_crosshair=True, is_colorbar=True, back_color=(0.8, 0.8, 1, 1))
nv.load_volumes([{"path": "../images/mni152.nii.gz"}])
nv.volumes[0].colorbar_visible = False
nv.set_clip_plane(0.1, 0, 135)
nv.opts.mesh_xray = 0.1

@nv.on_canvas_attached
def on_canvas_attached():
    """Ensure attached to GL."""
    connectome = {
        "name": "shearConnectome",
        "nodeColormap": "viridis",
        "nodeColormapNegative": "viridis",
        "nodeMinColor": 2,
        "nodeMaxColor": 4,
        "nodeScale": 5,
        "edgeColormap": "warm",
        "edgeColormapNegative": "winter",
        "edgeMin": 2,
        "edgeMax": 4,
        "edgeScale": 1,
        "nodes": {
            "names": ["Sphere", "Pyramid", "Box", "CylinderLow"],
            "X": [0, -41, -37, -21],
            "Y": [0, -59, -6, -21],
            "Z": [0, 3, 16, -22],
            "Color": [2, 2, 3, 4],
            "Size": [2, 2, 3, 4],
        },
        "edges": [1, 4, -3, 4, 0, 1, 0, 6, 0, 0, 1, 0, 0, 0, 0, 1],
    }
    
    # 2) JSON -> bytes
    json_bytes = json.dumps(connectome).encode("utf-8")
    
    
    nv.send(
        {
            "type": "load_jcon",   # this is the mesh loader message
            "data": [json_bytes],
        },
        buffers=[json_bytes],
    )

# Create UI

# Outline width slider
outline_slider = widgets.FloatSlider(
    min=0, max=1, step=0.1, value=1, description="Outline", continuous_update=True, readout=False
)

# Display

display(widgets.VBox([nv]))
In [ ]:
 
In [ ]: