forked from r03ert0/translucent-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (53 loc) · 1.6 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* globals MRI */
import TranslucentCluster from "./translucent-cluster.js";
const trc = new TranslucentCluster({
elemId: 'container',
assetsPath: './'
});
const updateStats = () => {
//Update statistics
document.querySelector('#resolution').innerText = `${
trc.cmap.dim[0]
} x ${
trc.cmap.dim[1]
} x ${
trc.cmap.dim[2]
}`;
document.querySelector('#vertcount').innerText = trc.cluster.vertices.length;
document.querySelector('#facecount').innerText = trc.cluster.faces.length;
};
const toggleBrain = () => {
if (trc.brain) {
trc.brain.visible = !trc.brain.visible;
}
};
const handleFileSelect = (evt) => {
var file = evt.target.files.item(0);
var m = new MRI();
m.init()
.then(() => m.loadMRIFromFile(file))
.then(() => {
trc.cmap.data = m.data;
trc.cmap.dim = m.dim;
trc.cmap.level = 0.06;
trc.updateMesh(trc.cmap);
trc.flagDataLoaded = true;
updateStats();
});
};
const handleLevelChange = () => {
var level = Number(document.querySelector('#level').value) / 100;
trc.cmap.level = parseFloat(level);
trc.updateMesh(trc.cmap);
document.querySelector('#levelValue').innerText = level;
updateStats();
};
trc.init().then(() => {
updateStats();
// Configure file upload
document.querySelector('#file').addEventListener('change', handleFileSelect);
document.querySelector('#level').addEventListener('input', handleLevelChange);
document.querySelector('#showBrain').addEventListener('change', toggleBrain);
document.querySelector('#level').value = `${0.06 * 100}`;
document.querySelector('#showBrain').checked = true;
});