-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport.js
More file actions
33 lines (28 loc) · 885 Bytes
/
Copy pathexport.js
File metadata and controls
33 lines (28 loc) · 885 Bytes
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
export function saveNRRD(nv) {
if (!nv.drawBitmap) return;
const dx = nv.back.dims[1];
const dy = nv.back.dims[2];
const dz = nv.back.dims[3];
const vol = nv.volumes[0];
const sx = vol.hdr.pixDims[1] || 1;
const sy = vol.hdr.pixDims[2] || 1;
const sz = vol.hdr.pixDims[3] || 1;
const header = [
'NRRD0004',
'type: uint8',
'dimension: 3',
`sizes: ${dx} ${dy} ${dz}`,
'encoding: raw',
'endian: little',
`space directions: (${sx},0,0) (0,${sy},0) (0,0,${sz})`,
'space origin: (0,0,0)',
'',
].join('\n');
const headerBytes = new TextEncoder().encode(header + '\n');
const blob = new Blob([headerBytes, nv.drawBitmap], { type: 'application/octet-stream' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'mask.nrrd';
link.click();
URL.revokeObjectURL(link.href);
}