our-medical
Version:
medical image vue component
34 lines (33 loc) • 1.12 kB
JavaScript
self.onmessage = function({ data: x }) {
const { refDimensions: a, segDimensions: o, origin: r, spacing: c, scalarData: d, segmentationId: M } = x, [l, f, h] = o, n = [1 / 0, -1 / 0, 1 / 0, -1 / 0, 1 / 0, -1 / 0];
let m = 0;
const I = l * f;
for (let s = 0; s < h; s++) {
const i = s * I;
for (let t = 0; t < f; t++) {
const p = t * l;
for (let e = 0; e < l; e++) {
const D = i + p + e;
d[D] > 0 && (m++, n[0] = Math.min(e, n[0]), n[1] = Math.max(e, n[1]), n[2] = Math.min(t, n[2]), n[3] = Math.max(t, n[3]), n[4] = Math.min(s, n[4]), n[5] = Math.max(s, n[5]));
}
}
}
const u = c.reduce((s, i) => s * i, 1) * m, y = n.map((s, i) => {
const t = i >> 1;
return r[t] + c[t] * s;
}), g = [
Math.max(o[0] - a[0] >> 1, 1),
Math.max(o[1] - a[1] >> 1, 1),
Math.max(o[2] - a[2] >> 1, 1)
];
for (let s = 0; s < 6; s++) {
const i = s >> 1;
n[s] -= g[i];
}
const V = [
n[1] - n[0] + 1,
n[3] - n[2] + 1,
n[5] - n[4] + 1
];
self.postMessage({ bounds: y, boundsIJK: n, dimensions: V, segmentationId: M, volumeValue: u });
};