-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuromodulation_explainer.html
More file actions
564 lines (498 loc) · 19.2 KB
/
Copy pathneuromodulation_explainer.html
File metadata and controls
564 lines (498 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>MNI Atlas + Mesh Viewer | Remy Cohan | Neuropsis</title>
<link rel="canonical" href="https://www.neuropsis.org/tms_visualiser.html" />
<meta name="description" content="Local-only MRI viewer by Remy Cohan (Neuropsis): 3-plane, 3D, and 4-panel views with optional atlas labels. Nothing uploads." />
<meta name="keywords" content="Remy Cohan, Neuropsis, NIfTI viewer, MRI viewer, neuroimaging, brain atlas, 3D render, neuroradiology" />
<meta name="author" content="Remy Cohan" />
<meta name="robots" content="index,follow" />
<style>
:root{
--bg:#050608;
--panel:#0b0f16cc;
--stroke:#1e2a3d;
--text:#d9e2f1;
--muted:#90a2bf;
--accent:#3b82f6;
--danger:#ef4444;
--good:#22c55e;
--shadow: 0 18px 60px rgba(0,0,0,.55);
--radius: 18px;
}
html,body{height:100%; margin:0; background:radial-gradient(1200px 800px at 10% 5%, #0c1a2e 0%, transparent 55%),
radial-gradient(1200px 800px at 90% 10%, #102b22 0%, transparent 60%),
var(--bg);
color:var(--text); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;}
*{box-sizing:border-box}
header{
position:fixed; top:0; left:0; right:0; height:64px;
display:flex; align-items:center; justify-content:space-between;
padding:0 18px; z-index:50;
background:linear-gradient(to bottom, rgba(0,0,0,.55), rgba(0,0,0,0));
backdrop-filter: blur(10px);
}
.brand{display:flex; align-items:center; gap:10px; min-width: 320px;}
.dot{width:10px; height:10px; border-radius:999px; background:#ff3b3b; box-shadow:0 0 18px rgba(255,59,59,.35);}
.title{font-weight:750; letter-spacing:.2px}
.subtitle{color:var(--muted); font-size:12.5px; margin-top:2px}
.brandText{display:flex; flex-direction:column; line-height:1.05}
.nav{display:flex; align-items:center; gap:10px}
.pill{
border:1px solid rgba(255,255,255,.10);
background:rgba(12,16,24,.55);
color:var(--text);
padding:8px 12px; border-radius:999px;
font-weight:650; font-size:13px;
text-decoration:none;
box-shadow:0 10px 30px rgba(0,0,0,.25);
}
.statusPill{
border:1px solid rgba(255,255,255,.10);
background:rgba(12,16,24,.55);
padding:8px 12px; border-radius:999px;
font-weight:700; font-size:12.5px;
}
.statusPill.err{border-color: rgba(239,68,68,.45); color:#ffd3d3;}
.statusPill.ok{border-color: rgba(34,197,94,.35); color:#d9ffe7;}
.wrap{
height:100%;
padding-top:78px;
padding-left:18px;
padding-right:18px;
padding-bottom:18px;
display:grid;
grid-template-columns: 340px 1fr;
gap:16px;
}
.card{
background:var(--panel);
border:1px solid rgba(255,255,255,.08);
border-radius:var(--radius);
box-shadow: var(--shadow);
}
.controls{padding:16px;}
.controls h3{margin:2px 0 12px 0; font-size:14px; color:var(--muted); font-weight:800; letter-spacing:.2px}
.row{display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px}
button{
appearance:none; border:1px solid rgba(255,255,255,.10);
background:rgba(12,16,24,.55);
color:var(--text);
padding:10px 12px; border-radius:12px;
font-weight:750; font-size:13px;
cursor:pointer;
transition:transform .05s ease, border-color .12s ease, background .12s ease;
}
button:hover{border-color: rgba(255,255,255,.18)}
button:active{transform: translateY(1px)}
button.primary{border-color: rgba(59,130,246,.35)}
button.primary:hover{border-color: rgba(59,130,246,.55)}
button.danger{border-color: rgba(239,68,68,.35)}
button.danger:hover{border-color: rgba(239,68,68,.55)}
button.on{outline: 2px solid rgba(59,130,246,.55); outline-offset: 0px}
.sliderRow{display:flex; align-items:center; gap:10px; margin:10px 0 8px 0}
input[type="range"]{width:100%}
.labelTiny{font-size:12px; color:var(--muted); font-weight:650}
.fileRow{display:flex; flex-direction:column; gap:8px; margin-top:10px}
input[type="file"]{
width:100%;
border:1px dashed rgba(255,255,255,.14);
border-radius:12px;
padding:10px;
background:rgba(0,0,0,.15);
color:var(--muted);
}
.kv{margin-top:10px; padding-top:10px; border-top:1px solid rgba(255,255,255,.08)}
.kv .k{font-size:12px; color:var(--muted); font-weight:800; margin-bottom:6px}
.kv .v{
font-size:13px; color:var(--text);
background:rgba(0,0,0,.20);
border:1px solid rgba(255,255,255,.08);
border-radius:12px;
padding:10px 12px;
min-height:42px;
display:flex; align-items:center;
}
.foot{margin-top:10px; font-size:12px; color:var(--muted); line-height:1.35}
.viewer{position:relative; padding:14px; overflow:hidden}
.canvasShell{
height: calc(100% - 0px);
width:100%;
display:block;
border-radius:16px;
border:1px solid rgba(255,255,255,.08);
overflow:hidden;
background:#000;
}
/* single-canvas area (for 3-plane or 3D) */
#singleWrap{height: 100%;}
#singleCanvas{width:100%; height:100%; display:block;}
/* 4-panel grid */
#gridWrap{
height:100%;
display:none;
gap:10px;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
}
.panel{
border-radius:16px;
border:1px solid rgba(255,255,255,.08);
overflow:hidden;
background:#000;
min-height:0;
}
.panel canvas{width:100%; height:100%; display:block;}
</style>
<!-- Use your local UMD build (NOT ESM) -->
<script src="/assets/vendor/niivue/niivue.umd.js"></script>
</head>
<body>
<header>
<div class="brand">
<div class="dot"></div>
<div class="brandText">
<div class="title">MNI Atlas + Mesh Viewer</div>
<div class="subtitle">Remy Cohan • Neuropsis • local-only • 3-plane / 3D / 4-panel</div>
</div>
</div>
<div class="nav">
<a class="pill" href="/" rel="home">Home</a>
<a class="pill" href="javascript:history.back()">Back</a>
<div id="statusPill" class="statusPill ok">Ready</div>
</div>
</header>
<div class="wrap">
<div class="card controls">
<h3>Controls</h3>
<div class="row">
<button id="btnAtlas" class="primary">Add atlas labels</button>
<button id="btnReset" class="danger">Reset demo</button>
</div>
<div class="row">
<button id="btn3plane" class="on">3-plane</button>
<button id="btn3d">3D</button>
<button id="btn4panel">4-panel</button>
</div>
<div class="sliderRow">
<div class="labelTiny">Atlas opacity</div>
</div>
<input id="atlasOpacity" type="range" min="0" max="1" step="0.01" value="0.55" />
<div class="fileRow">
<div class="labelTiny">Load your own NIfTI (.nii / .nii.gz)</div>
<input id="fileInput" type="file" accept=".nii,.nii.gz,application/gzip" />
<div class="row">
<button id="btnLoadUser">Clear + load my NIfTI</button>
<button id="btnSkull" class="primary">MNI-Cortex 3D</button>
</div>
</div>
<div class="kv">
<div class="k">Label</div>
<div id="labelBox" class="v">—</div>
</div>
<div class="foot">
Runs entirely in your browser. Nothing uploads.<br/>
Tip: drag-and-drop also works.
</div>
</div>
<div class="card viewer">
<div class="canvasShell">
<div id="singleWrap">
<canvas id="singleCanvas"></canvas>
</div>
<div id="gridWrap">
<div class="panel"><canvas id="axCanvas"></canvas></div>
<div class="panel"><canvas id="corCanvas"></canvas></div>
<div class="panel"><canvas id="sagCanvas"></canvas></div>
<div class="panel"><canvas id="renCanvas"></canvas></div>
</div>
</div>
</div>
</div>
<script>
(() => {
// ---------- Paths ----------
const DEMO_MESH_URL = "/assets/neurop/mni152_2009.mz3";
const ATLAS_NII_URL = "/assets/neurop/MNI152_T1_1mm_desikan_adjusted.nii.gz";
const ATLAS_LUT_URL = "/assets/neurop/MNI152_T1_1mm_desikan_adjusted.txt";
// ---------- Grab Niivue class (works with both UMD globals) ----------
const NiivueClass =
(window.niivue && window.niivue.Niivue) ||
(window.Niivue && window.Niivue.Niivue) ||
window.Niivue;
// ---------- UI ----------
const statusPill = document.getElementById("statusPill");
const labelBox = document.getElementById("labelBox");
const atlasOpacity = document.getElementById("atlasOpacity");
const fileInput = document.getElementById("fileInput");
const btnAtlas = document.getElementById("btnAtlas");
const btnReset = document.getElementById("btnReset");
const btn3plane = document.getElementById("btn3plane");
const btn3d = document.getElementById("btn3d");
const btn4panel = document.getElementById("btn4panel");
const btnLoadUser= document.getElementById("btnLoadUser");
const btnSkull = document.getElementById("btnSkull");
const singleWrap = document.getElementById("singleWrap");
const gridWrap = document.getElementById("gridWrap");
function setStatusOk(msg="Ready"){ statusPill.className="statusPill ok"; statusPill.textContent=msg; }
function setStatusErr(msg="Error"){ statusPill.className="statusPill err"; statusPill.textContent=msg; }
function setModeButtons(mode){
[btn3plane, btn3d, btn4panel].forEach(b => b.classList.remove("on"));
if(mode==="3plane") btn3plane.classList.add("on");
if(mode==="3d") btn3d.classList.add("on");
if(mode==="4panel") btn4panel.classList.add("on");
}
function showSingle(){ gridWrap.style.display="none"; singleWrap.style.display="block"; }
function showGrid(){ singleWrap.style.display="none"; gridWrap.style.display="grid"; }
// ---------- NiiVue instances ----------
let nvSingle = null;
let nvAx=null, nvCor=null, nvSag=null, nvRen=null;
let currentMode = "3d";
let atlasLoaded = false;
let userVolumeObjectUrl = null;
// ---------- Helpers ----------
function draw(nv){ try { nv.drawScene && nv.drawScene(); } catch(e) {} }
function hide3DRedAxes(nv){
// This is what you’re seeing as “red axis lines” in 3D. Turn it off.
if(nv?.opts) nv.opts.showCrosshair = false;
draw(nv);
}
function show2DCrosshair(nv){
if(nv?.opts) nv.opts.showCrosshair = true;
draw(nv);
}
function safeSetSliceType(nv, sliceType){
if(!nv) return;
if(typeof nv.setSliceType === "function") nv.setSliceType(sliceType);
else nv.sliceType = sliceType;
draw(nv);
}
function safeClear(nv){
if(!nv) return;
try { nv.removeAllMeshes && nv.removeAllMeshes(); } catch(e) {}
try { nv.removeAllVolumes && nv.removeAllVolumes(); } catch(e) {}
// fallback
if(Array.isArray(nv.meshes)) nv.meshes = [];
if(Array.isArray(nv.volumes)) nv.volumes = [];
draw(nv);
}
async function safeLoadMesh(nv, url){
// Prefer loadMeshes on newer builds (your 0.66 case)
if(typeof nv.loadMeshes === "function"){
try { await nv.loadMeshes([{ url }]); draw(nv); return; } catch(e) {}
try { await nv.loadMeshes([url]); draw(nv); return; } catch(e) {}
}
if(typeof nv.addMeshFromUrl === "function"){ await nv.addMeshFromUrl(url); draw(nv); return; }
if(typeof nv.loadMesh === "function"){ await nv.loadMesh(url); draw(nv); return; }
throw new Error("No supported mesh loader in this NiiVue build.");
}
async function safeLoadVolumeUrl(nv, url){
if(typeof nv.loadVolumes === "function"){ await nv.loadVolumes([{ url }]); draw(nv); return; }
if(typeof nv.addVolumesFromUrl === "function"){ await nv.addVolumesFromUrl([{ url }]); draw(nv); return; }
if(typeof nv.loadFromUrl === "function"){ await nv.loadFromUrl(url); draw(nv); return; }
throw new Error("No supported volume loader in this NiiVue build.");
}
async function safeAddAtlas(nv){
if(typeof nv.addLabelFromUrl === "function"){
await nv.addLabelFromUrl(ATLAS_NII_URL, ATLAS_LUT_URL);
draw(nv);
return;
}
// fallback: load atlas as 2nd volume
await safeLoadVolumeUrl(nv, ATLAS_NII_URL);
}
function applyAtlasOpacity(nv, alpha){
if(!nv) return;
// if atlas is volume[1], set opacity there
if(Array.isArray(nv.volumes) && nv.volumes.length > 1){
try { nv.volumes[1].opacity = alpha; } catch(e) {}
}
draw(nv);
}
// ---------- Create viewers ----------
function createNv(canvas){
const nv = new NiivueClass({
backColor: [0,0,0,1],
isNearestInterpolation: true
});
nv.attachToCanvas(canvas);
if(nv.opts){
nv.opts.showCrosshair = true; // keep crosshair in 2D
nv.opts.crosshairColor = [1,0,0,1];
}
if(typeof nv.onLocationChange === "function"){
nv.onLocationChange = (data) => { if(data?.label) labelBox.textContent = data.label; };
}
return nv;
}
function destroy4Panel(){
[nvAx,nvCor,nvSag,nvRen].forEach(nv => { try { nv?.destroy && nv.destroy(); } catch(e){} });
nvAx=nvCor=nvSag=nvRen=null;
}
async function initSingle(){
if(nvSingle) return;
nvSingle = createNv(document.getElementById("singleCanvas"));
}
async function init4Panel(){
destroy4Panel();
nvAx = createNv(document.getElementById("axCanvas"));
nvCor = createNv(document.getElementById("corCanvas"));
nvSag = createNv(document.getElementById("sagCanvas"));
nvRen = createNv(document.getElementById("renCanvas"));
safeSetSliceType(nvAx, 0);
safeSetSliceType(nvCor, 1);
safeSetSliceType(nvSag, 2);
safeSetSliceType(nvRen, 4);
hide3DRedAxes(nvRen);
}
// ---------- Actions ----------
async function loadDemoMeshIntoCurrentView(){
setStatusOk("Loading…");
labelBox.textContent = "—";
atlasLoaded = false;
try{
if(currentMode === "4panel"){
showGrid();
await init4Panel();
safeClear(nvRen);
await safeLoadMesh(nvRen, DEMO_MESH_URL);
safeSetSliceType(nvRen, 4);
hide3DRedAxes(nvRen);
} else {
showSingle();
await initSingle();
safeClear(nvSingle);
await safeLoadMesh(nvSingle, DEMO_MESH_URL);
safeSetSliceType(nvSingle, 3);
hide3DRedAxes(nvSingle);
}
setStatusOk("Ready");
} catch(e){
console.error(e);
setStatusErr("Mesh failed");
}
}
async function loadUserNifti(){
const f = fileInput.files?.[0];
if(!f){ setStatusErr("No file selected"); return; }
setStatusOk("Loading…");
labelBox.textContent = "—";
if(userVolumeObjectUrl) URL.revokeObjectURL(userVolumeObjectUrl);
userVolumeObjectUrl = URL.createObjectURL(f);
try{
if(currentMode === "4panel"){
showGrid();
await init4Panel();
[nvAx,nvCor,nvSag,nvRen].forEach(safeClear);
await Promise.all([nvAx,nvCor,nvSag,nvRen].map(nv => safeLoadVolumeUrl(nv, userVolumeObjectUrl)));
safeSetSliceType(nvAx,0); safeSetSliceType(nvCor,1); safeSetSliceType(nvSag,2);
safeSetSliceType(nvRen,4);
hide3DRedAxes(nvRen);
if(atlasLoaded) await Promise.all([nvAx,nvCor,nvSag,nvRen].map(nv => safeAddAtlas(nv)));
[nvAx,nvCor,nvSag,nvRen].forEach(nv => applyAtlasOpacity(nv, parseFloat(atlasOpacity.value)));
} else {
showSingle();
await initSingle();
safeClear(nvSingle);
await safeLoadVolumeUrl(nvSingle, userVolumeObjectUrl);
if(currentMode === "3d"){ safeSetSliceType(nvSingle,3); hide3DRedAxes(nvSingle); }
else { safeSetSliceType(nvSingle,2); show2DCrosshair(nvSingle); }
if(atlasLoaded) await safeAddAtlas(nvSingle);
applyAtlasOpacity(nvSingle, parseFloat(atlasOpacity.value));
}
setStatusOk("Ready");
} catch(e){
console.error(e);
setStatusErr("NIfTI failed");
}
}
async function addAtlasEverywhere(){
setStatusOk("Loading…");
try{
if(currentMode === "4panel"){
await init4Panel();
await Promise.all([nvAx,nvCor,nvSag,nvRen].map(nv => safeAddAtlas(nv)));
[nvAx,nvCor,nvSag,nvRen].forEach(nv => applyAtlasOpacity(nv, parseFloat(atlasOpacity.value)));
} else {
await initSingle();
await safeAddAtlas(nvSingle);
applyAtlasOpacity(nvSingle, parseFloat(atlasOpacity.value));
}
atlasLoaded = true;
setStatusOk("Ready");
} catch(e){
console.error(e);
setStatusErr("Atlas failed");
}
}
function setMode(mode){
currentMode = mode;
setModeButtons(mode);
if(mode === "4panel"){
showGrid();
init4Panel().then(async () => {
// if we already loaded a user file, populate panels
if(userVolumeObjectUrl){
[nvAx,nvCor,nvSag,nvRen].forEach(safeClear);
await Promise.all([nvAx,nvCor,nvSag,nvRen].map(nv => safeLoadVolumeUrl(nv, userVolumeObjectUrl)));
safeSetSliceType(nvAx,0); safeSetSliceType(nvCor,1); safeSetSliceType(nvSag,2);
safeSetSliceType(nvRen,4); hide3DRedAxes(nvRen);
if(atlasLoaded) await Promise.all([nvAx,nvCor,nvSag,nvRen].map(nv => safeAddAtlas(nv)));
[nvAx,nvCor,nvSag,nvRen].forEach(nv => applyAtlasOpacity(nv, parseFloat(atlasOpacity.value)));
}
});
return;
}
showSingle();
initSingle().then(() => {
if(mode === "3d"){ safeSetSliceType(nvSingle,3); hide3DRedAxes(nvSingle); }
else { safeSetSliceType(nvSingle,2); show2DCrosshair(nvSingle); }
if(atlasLoaded) applyAtlasOpacity(nvSingle, parseFloat(atlasOpacity.value));
});
}
// ---------- Events ----------
btnSkull.addEventListener("click", loadDemoMeshIntoCurrentView); // THIS is your requested button
btnReset.addEventListener("click", async () => {
// reset = clear everything + load demo mesh again
if(userVolumeObjectUrl){ URL.revokeObjectURL(userVolumeObjectUrl); userVolumeObjectUrl = null; }
atlasLoaded = false;
labelBox.textContent = "—";
await loadDemoMeshIntoCurrentView();
});
btnAtlas.addEventListener("click", addAtlasEverywhere);
btnLoadUser.addEventListener("click", loadUserNifti);
btn3plane.addEventListener("click", () => setMode("3plane"));
btn3d.addEventListener("click", () => setMode("3d"));
btn4panel.addEventListener("click", () => setMode("4panel"));
atlasOpacity.addEventListener("input", (e) => {
const a = parseFloat(e.target.value);
if(currentMode === "4panel") [nvAx,nvCor,nvSag,nvRen].forEach(nv => applyAtlasOpacity(nv, a));
else applyAtlasOpacity(nvSingle, a);
});
// drag/drop over viewer
const viewerEl = document.querySelector(".viewer");
viewerEl.addEventListener("dragover", e => e.preventDefault());
viewerEl.addEventListener("drop", async (e) => {
e.preventDefault();
const f = e.dataTransfer?.files?.[0];
if(!f) return;
const dt = new DataTransfer();
dt.items.add(f);
fileInput.files = dt.files;
await loadUserNifti();
});
// ---------- Init ----------
if(!NiivueClass){
setStatusErr("NiiVue missing");
console.error("NiiVue class not found. Check /assets/vendor/niivue/niivue.umd.js");
return;
}
// Start: demo mesh in 3D
setMode("3d");
loadDemoMeshIntoCurrentView();
})();
</script>
</body>
</html>