forked from Irev-Dev/MRI-Volume-Slice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
47 lines (38 loc) · 1.33 KB
/
script.js
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
import 'babel-polyfill';
import nifti from 'nifti-js';
import MRISlice from './MRI-Volume-Slice';
import niftiData from './data/sub-study002_ses-after_anat_sub-study002_ses-after_T1w.nii';
const mRISlice = new MRISlice();
const xDiv = document.getElementById('z-view-wrapper');
const yDiv = document.getElementById('y-view-wrapper');
const zDiv = document.getElementById('x-view-wrapper');
loadDefaultData(niftiData);
appendCanvasesToHTML();
function appendCanvasesToHTML() {
xDiv.appendChild(mRISlice.canvases.z);
yDiv.appendChild(mRISlice.canvases.y);
zDiv.appendChild(mRISlice.canvases.x);
}
document.getElementById('file-input').onchange = function (event) {
const fr = new FileReader();
fr.onload = setupNifti;
fr.readAsArrayBuffer(event.target.files[0]);
};
document.getElementById('toggle-cross-hairs').onchange = function (event) {
if(event.target.checked) {
mRISlice.showCrosshairs();
}else{
mRISlice.hideCrossHairs();
}
};
function setupNifti(event) {
mRISlice.loadNewNifti(nifti.parse(event.target.result));
mRISlice.mouseNavigationEnabled('enable please')
}
async function loadDefaultData(niftiData) {
const response = await fetch(niftiData);
const blob = await response.blob();
const fr = new FileReader();
fr.onload = setupNifti;
fr.readAsArrayBuffer(blob);
}