Atlas
Mesh Atlas
Code
import NiiVue from '@niivue/niivue'
const colorBtn = document.getElementById('colorBtn')const cullCheck = document.getElementById('cullCheck')const gl1 = document.getElementById('gl1')const legendCheck = document.getElementById('legendCheck')const shaderSelect = document.getElementById('shaderSelect')const sliceType = document.getElementById('sliceType')const webgpuCheck = document.getElementById('webgpuCheck')
sliceType.onchange = () => { nv1.sliceType = parseInt(sliceType.value, 10)}
shaderSelect.onchange = () => { const meshes = nv1.model.getMeshes() if (meshes.length < 1) return nv1.setMesh(meshes.length - 1, { shaderType: shaderSelect.value })}
colorBtn.addEventListener('input', (event) => { const input = event.target const hex = input.value const r = parseInt(hex.slice(1, 3), 16) / 255 const g = parseInt(hex.slice(3, 5), 16) / 255 const b = parseInt(hex.slice(5, 7), 16) / 255 nv1.backgroundColor = [r, g, b, 1.0]})
legendCheck.onchange = async function () { await nv1.setMesh(0, { isLegendVisible: this.checked })}
// Unticked, hidden regions show the mesh colour instead of vanishing.cullCheck.onchange = async function () { await nv1.setMeshLayerProperty(0, 0, { isHiddenLabelCulled: this.checked })}
webgpuCheck.onchange = async function () { await nv1.reinitializeView({ backend: this.checked ? 'webgpu' : 'webgl2' })}
// Click a legend colour box to hide/show that region, double-click to show only// it; the name moves the crosshair.const nv1 = new NiiVue({ backgroundColor: [0, 0, 0, 1], isLegendToggleEnabled: true,})await nv1.attachToCanvas(gl1)for (const shader of nv1.meshShaders) { const option = document.createElement('option') option.value = shader option.textContent = shader.charAt(0).toUpperCase() + shader.slice(1) shaderSelect.appendChild(option)}await nv1.loadMeshes([ { url: '/meshes/atl-Anatom_space-MNI.mz3', },])sliceType.onchange()legendCheck.onchange()