@niivue/nv-ext-drawing 1.0.0-rc.22 → 1.0.0-rc.220
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.ts +3 -1
- package/dist/nv-ext-drawing.js +125 -185
- package/dist/processing/magicWand.d.ts +10 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Drawing interpolation and segmentation tools for [NiiVue](https://github.com/niivue).
|
|
4
4
|
|
|
5
|
+
Documentation: https://niivue.github.io/mono/docs/packages/nv-ext-drawing/
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -46,6 +48,7 @@ dr.update(filled)
|
|
|
46
48
|
```bash
|
|
47
49
|
bunx nx build nv-ext-drawing # Build
|
|
48
50
|
bunx nx typecheck nv-ext-drawing # Type-check
|
|
51
|
+
bunx nx test nv-ext-drawing # Test
|
|
49
52
|
```
|
|
50
53
|
|
|
51
54
|
## Part of the [NiiVue](https://github.com/niivue) ecosystem
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ export declare function findDrawingBoundarySlices(sliceType: SliceType, drawBitm
|
|
|
14
14
|
* Runs in a Web Worker. Returns a new Uint8Array with the interpolated bitmap.
|
|
15
15
|
*
|
|
16
16
|
* Image data (`imageData`) must be in RAS voxel order. Use
|
|
17
|
-
* `ctx.backgroundVolume.imgRAS` from the extension context.
|
|
17
|
+
* `ctx.backgroundVolume.imgRAS` from the extension context. `maxVal` is a
|
|
18
|
+
* positive scale in the same raw units, normally its largest absolute value
|
|
19
|
+
* (`globalMin`/`globalMax` are scaled by scl_slope/scl_inter).
|
|
18
20
|
*/
|
|
19
21
|
export declare function interpolateMaskSlices(drawBitmap: Uint8Array, dims: DrawingDims, imageData: ArrayLike<number> | null, maxVal: number, sliceIndexLow: number | undefined, sliceIndexHigh: number | undefined, options?: InterpolationOptions): Promise<Uint8Array>;
|
|
20
22
|
/**
|
package/dist/nv-ext-drawing.js
CHANGED
|
@@ -1,193 +1,133 @@
|
|
|
1
|
-
import { NVWorker as
|
|
2
|
-
|
|
3
|
-
function w(e) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(g),
|
|
16
|
-
{
|
|
17
|
-
name: e == null ? void 0 : e.name
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
} finally {
|
|
21
|
-
t && (self.URL || self.webkitURL).revokeObjectURL(t);
|
|
22
|
-
}
|
|
1
|
+
import { NVWorker as e } from "@niivue/niivue";
|
|
2
|
+
// src/worker.ts?worker&inline
|
|
3
|
+
var t = "(function(){let e={AXIAL:0,CORONAL:1,SAGITTAL:2};function t(t,n){let{dimX:r,dimY:i,dimZ:a}=n;return t===e.AXIAL?{w:r,h:i,depth:a}:t===e.CORONAL?{w:r,h:a,depth:i}:{w:i,h:a,depth:r}}function n(e,t,n,r){return e+t*r.dimX+n*r.dimX*r.dimY}function r(e,t,r,i,a){if(!a)return n(e,t,r,i);let{img2RASstep:o,img2RASstart:s}=a;return s[0]+e*o[0]+s[1]+t*o[1]+s[2]+r*o[2]}function i(t,r,i,a){let{dimX:o,dimY:s,dimZ:c}=a;if(r===e.AXIAL){let e=new Float32Array(o*s),n=t*o*s;for(let t=0;t<e.length;t++)e[t]=i[n+t];return e}if(r===e.CORONAL){let e=new Float32Array(o*c);for(let r=0;r<c;r++)for(let s=0;s<o;s++)e[s+r*o]=i[n(s,t,r,a)];return e}let l=new Float32Array(s*c);for(let e=0;e<c;e++)for(let r=0;r<s;r++)l[r+e*s]=i[n(t,r,e,a)];return l}function a(t,n,i,a,o,s){let{dimX:c,dimY:l,dimZ:u}=a,d=1/o;if(n===e.AXIAL){let e=new Float32Array(c*l);for(let n=0;n<l;n++)for(let o=0;o<c;o++)e[o+n*c]=i[r(o,n,t,a,s)]*d;return e}if(n===e.CORONAL){let e=new Float32Array(c*u);for(let n=0;n<u;n++)for(let o=0;o<c;o++)e[o+n*c]=i[r(o,t,n,a,s)]*d;return e}let f=new Float32Array(l*u);for(let e=0;e<u;e++)for(let n=0;n<l;n++)f[n+e*l]=i[r(t,n,e,a,s)]*d;return f}function o(t,r,i,a,o,s,c){let{dimX:l,dimY:u,dimZ:d}=o;if(i===e.AXIAL){let e=r*l*u;for(let n=0;n<t.length;n++)t[n]>=s&&(a[e+n]=c)}else if(i===e.CORONAL)for(let e=0;e<d;e++)for(let i=0;i<l;i++)t[i+e*l]>=s&&(a[n(i,r,e,o)]=c);else for(let e=0;e<d;e++)for(let i=0;i<u;i++)t[i+e*u]>=s&&(a[n(r,i,e,o)]=c)}function s(e,t,n){if(t<3||n<3)return;let r=new Float32Array(e.length);for(let i=0;i<n;i++)for(let n=0;n<t;n++){let a=n+i*t;r[a]=n===0||n===t-1?e[a]:(e[a-1]+2*e[a]+e[a+1])*.25}for(let i=0;i<n;i++)for(let a=0;a<t;a++){let o=a+i*t;e[o]=i===0||i===n-1?r[o]:(r[o-t]+2*r[o]+r[o+t])*.25}}function c(e,t,n,r){let i=Math.abs(n-e),a=Math.abs(n-t),o=Math.exp(-i*i/(2*r*r)),s=o+Math.exp(-a*a/(2*r*r));return s<1e-6?.5:o/s}function l(e,n,r){let{depth:a}=t(e,r),o=-1,s=-1;for(let t=0;t<a;t++){let a=i(t,e,n,r),c=!1;for(let e=0;e<a.length;e++)if(a[e]>0){c=!0;break}c&&(o===-1&&(o=t),s=t)}return o===-1?null:{first:o,last:s}}function u(n,r,l,u,d,f,p,m){let h=p.sliceType??e.AXIAL,{w:g,h:_,depth:v}=t(h,r),y=v-1,b={intensityWeight:p.intensityWeight??.7,binaryThreshold:p.binaryThreshold??.375,intensitySigma:p.intensitySigma??.1,applySmoothingToSlices:p.applySmoothingToSlices??!0,useIntensityGuided:p.useIntensityGuided??!1};if(d!==void 0&&f!==void 0){if(d>=f)throw Error(`Low slice index must be less than high slice index`);if(d<0||f>y)throw Error(`Slice indices out of bounds [0, ${y}]`)}let x=/* @__PURE__ */ new Map;for(let e=0;e<=y;e++){let t=i(e,h,n,r);for(let n=0;n<t.length;n++){let r=t[n];if(r>0){let t=x.get(r);t?(t.min=Math.min(t.min,e),t.max=Math.max(t.max,e)):x.set(r,{min:e,max:e})}}}for(let[e,t]of x){let p=d===void 0?t.min:Math.max(d,t.min),v=f===void 0?t.max:Math.min(f,t.max);if(p>=v||v-p<2)continue;let y=i(p,h,n,r),x=i(v,h,n,r),S=new Float32Array(y.length),C=new Float32Array(x.length);for(let t=0;t<y.length;t++)S[t]=+(y[t]===e),C[t]=+(x[t]===e);b.applySmoothingToSlices&&(s(S,g,_),s(C,g,_));let w=b.useIntensityGuided&&l,T=w?a(p,h,l,r,u,m):null,E=w?a(v,h,l,r,u,m):null;for(let t=p+1;t<v;t++){let i=new Float32Array(g*_),s=(t-p)/(v-p),d=1-s;if(T&&E&&l){let e=a(t,h,l,r,u,m),n=b.intensityWeight;for(let t=0;t<S.length;t++)if(S[t]>0||C[t]>0){let r=n*c(T[t],E[t],e[t],b.intensitySigma)+(1-n)*d,a=1-r;i[t]=S[t]*r+C[t]*a}else i[t]=S[t]*d+C[t]*s}else for(let e=0;e<S.length;e++)i[e]=S[e]*d+C[e]*s;o(i,t,h,n,r,b.binaryThreshold,e)}}return n}function d(e,t,n,r){return e+t*r.dimX+n*r.dimX*r.dimY}function f(e,t,n,r,i){if(!i)return d(e,t,n,r);let{img2RASstep:a,img2RASstart:o}=i;return o[0]+e*a[0]+o[1]+t*a[1]+o[2]+n*a[2]}let p=[[-1,0,0],[1,0,0],[0,-1,0],[0,1,0],[0,0,-1],[0,0,1]],m=[[-1,-1,0],[1,-1,0],[-1,1,0],[1,1,0],[0,-1,-1],[0,1,-1],[-1,0,-1],[1,0,-1],[0,-1,1],[0,1,1],[-1,0,1],[1,0,1]],h=[[-1,-1,-1],[1,-1,-1],[-1,1,-1],[1,1,-1],[-1,-1,1],[1,-1,1],[-1,1,1],[1,1,1]];function g(e){return e>=26?[...p,...m,...h]:e>=18?[...p,...m]:[...p]}function _(e,t){return Math.abs(e===0?.01:e)*t}function v(e,t,n,r,i={},a,o){let{tolerance:s=0,thresholdMode:c=`symmetric`,percent:l=0,calMin:u=0,calMax:p=1,connectivity:m=6,maxDistanceMM:h=1/0,is2D:v=!1,sliceAxis:y=0,penValue:b=1}=i,{dimX:x,dimY:S,dimZ:C}=n,w=x*S*C,[T,E,D]=e;if(T<0||E<0||D<0||T>=x||E>=S||D>=C)return{filledCount:0,seedIntensity:0,intensityMin:0,intensityMax:0};let O=f(T,E,D,n,a),k=Number(r[O]),A,j,M;if(i.intensityMin!==void 0&&i.intensityMax!==void 0)A=i.intensityMin,j=i.intensityMax;else{let e=c===`auto`?`symmetric`:c;switch(c===`auto`&&(M=k>(u+p)*.5,e=M?`bright`:`dark`),e){case`percent`:{let e=_(k,l);A=k-e,j=k+e;break}case`bright`:l>0?(A=k,j=k+_(k,l)):s>0?(A=k,j=k+s):(A=k,j=1/0);break;case`dark`:l>0?(A=k-_(k,l),j=k):s>0?(A=k-s,j=k):(A=-1/0,j=k);break;default:A=k-s,j=k+s}}let N=g(m),P=o?o[0]:1,F=o?o[1]:1,I=o?o[2]:1,L=h*h;function R(e,t,n){if(!Number.isFinite(L))return!0;let r=(e-T)*P,i=(t-E)*F,a=(n-D)*I;return r*r+i*i+a*a<=L}let z=-1,B=-1;v&&(y===0?(z=2,B=D):y===1?(z=1,B=E):y===2&&(z=0,B=T));let V=new Uint8Array(w),H=d(T,E,D,n);if(k<A||k>j)return{filledCount:0,seedIntensity:k,intensityMin:A,intensityMax:j,isBright:M};let U=[H];V[H]=1;let W=0;for(;U.length>0;){let e=U.shift(),i=Math.floor(e/(x*S)),o=Math.floor((e-i*x*S)/x),s=e-i*x*S-o*x;t[e]=b,W++;for(let[e,t,c]of N){let l=s+e,u=o+t,p=i+c;if(l<0||u<0||p<0||l>=x||u>=S||p>=C||z>=0&&(z===0?l:z===1?u:p)!==B)continue;let m=d(l,u,p,n);if(V[m]||(V[m]=1,!R(l,u,p)))continue;let h=Number(r[f(l,u,p,n,a)]);h<A||h>j||U.push(m)}}return{filledCount:W,seedIntensity:k,intensityMin:A,intensityMax:j,isBright:M}}function y(e,t,n,r,i=6){let{dimX:a,dimY:o,dimZ:s}=n,[c,l,u]=e;if(c<0||l<0||u<0||c>=a||l>=o||u>=s)return 0;let f=d(c,l,u,n),p=t[f];if(p===r||p===0)return 0;let m=a*o*s,h=new Uint8Array(m),_=g(i),v=[f];h[f]=1;let y=0;for(;v.length>0;){let e=v.shift();t[e]=r,y++;let i=Math.floor(e/(a*o)),c=Math.floor((e-i*a*o)/a),l=e-i*a*o-c*a;for(let[e,r,u]of _){let f=l+e,m=c+r,g=i+u;if(f<0||m<0||g<0||f>=a||m>=o||g>=s)continue;let _=d(f,m,g,n);h[_]||(h[_]=1,t[_]===p&&v.push(_))}}return y}let b=self.postMessage.bind(self),x={findBoundarySlices(e){let t=e.sliceType,n=new Uint8Array(e.drawBitmap),r=e.dims;return{result:l(t,n,r)}},interpolateMaskSlices(e){let t=new Uint8Array(e.drawBitmap),n=e.dims,r=e.imageData?new Float32Array(e.imageData):null,i=e.maxVal??1,a=e.sliceIndexLow,o=e.sliceIndexHigh;return{drawBitmap:u(t,n,r,i,a,o,e.options??{},e.rasMap??void 0).buffer}},magicWand(e){let t=e.seed,n=new Uint8Array(e.drawBitmap),r=e.dims,i=v(t,n,r,new Float32Array(e.imageData),e.options??{},e.rasMap??void 0,e.voxelSizeMM??void 0);return{drawBitmap:n.buffer,result:i}},magicWandFromBitmap(e){let t=e.seed,n=new Uint8Array(e.drawBitmap),r=e.dims,i=y(t,n,r,e.newColor??0,e.connectivity??6);return{drawBitmap:n.buffer,count:i}}},S=null,C=null,w=null,T=null,E,D;self.onmessage=e=>{let t=e.data;if(t.type===`initShared`){S=new Uint8Array(t.workingBuffer),C=new Float32Array(t.imageBuffer),w=new Uint8Array(t.committedBuffer),T=t.dims,E=t.rasMap??void 0,D=t.voxelSizeMM??void 0,b({type:`initSharedDone`});return}if(t.type===`updateCommitted`){w=new Uint8Array(t.committed);return}if(t.type===`magicWandShared`){if(!S||!C||!w||!T){b({type:`magicWandSharedResult`,error:`Not initialized`,gen:t.gen});return}S.set(w);let e=v(t.seed,S,T,C,t.options??{},E,D);b({type:`magicWandSharedResult`,result:e,gen:t.gen});return}let{_wbId:n,name:r,...i}=t,a=x[r];if(!a)b({_wbId:n,_wbError:`Unknown operation: ${r}`});else try{let e=a(i),t=[];for(let n of Object.values(e))n instanceof ArrayBuffer&&t.push(n);b({_wbId:n,...e},t)}catch(e){b({_wbId:n,_wbError:e instanceof Error?e.message:String(e)})}}})();", n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", t], { type: "text/javascript;charset=utf-8" });
|
|
4
|
+
function r(e) {
|
|
5
|
+
let r;
|
|
6
|
+
try {
|
|
7
|
+
if (r = n && (self.URL || self.webkitURL).createObjectURL(n), !r) throw "";
|
|
8
|
+
let t = new Worker(r, { name: e?.name });
|
|
9
|
+
return t.addEventListener("error", () => {
|
|
10
|
+
(self.URL || self.webkitURL).revokeObjectURL(r);
|
|
11
|
+
}), t;
|
|
12
|
+
} catch {
|
|
13
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(t), { name: e?.name });
|
|
14
|
+
}
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
// src/index.ts
|
|
17
|
+
function i(e) {
|
|
18
|
+
if (e instanceof Float32Array) return e;
|
|
19
|
+
let t = new Float32Array(e.length);
|
|
20
|
+
for (let n = 0; n < e.length; n++) t[n] = e[n];
|
|
21
|
+
return t;
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
function
|
|
32
|
-
|
|
23
|
+
var a = null;
|
|
24
|
+
function o() {
|
|
25
|
+
return a ||= new e(() => new r()), a;
|
|
33
26
|
}
|
|
34
|
-
async function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sliceType: e,
|
|
43
|
-
drawBitmap: r,
|
|
44
|
-
dims: n
|
|
45
|
-
},
|
|
46
|
-
[r]
|
|
47
|
-
)).result;
|
|
27
|
+
async function s(e, t, n) {
|
|
28
|
+
let r = t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
|
|
29
|
+
return (await o().execute({
|
|
30
|
+
name: "findBoundarySlices",
|
|
31
|
+
sliceType: e,
|
|
32
|
+
drawBitmap: r,
|
|
33
|
+
dims: n
|
|
34
|
+
}, [r])).result;
|
|
48
35
|
}
|
|
49
|
-
async function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
imageData: f,
|
|
68
|
-
maxVal: r,
|
|
69
|
-
sliceIndexLow: o,
|
|
70
|
-
sliceIndexHigh: s,
|
|
71
|
-
options: i ?? {},
|
|
72
|
-
rasMap: null
|
|
73
|
-
},
|
|
74
|
-
c
|
|
75
|
-
);
|
|
76
|
-
return new Uint8Array(u.drawBitmap);
|
|
36
|
+
async function c(e, t, n, r, a, s, c) {
|
|
37
|
+
let l = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), u = [l], d = null;
|
|
38
|
+
if (n) {
|
|
39
|
+
let e = i(n);
|
|
40
|
+
d = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength), u.push(d);
|
|
41
|
+
}
|
|
42
|
+
let f = await o().execute({
|
|
43
|
+
name: "interpolateMaskSlices",
|
|
44
|
+
drawBitmap: l,
|
|
45
|
+
dims: t,
|
|
46
|
+
imageData: d,
|
|
47
|
+
maxVal: r,
|
|
48
|
+
sliceIndexLow: a,
|
|
49
|
+
sliceIndexHigh: s,
|
|
50
|
+
options: c ?? {},
|
|
51
|
+
rasMap: null
|
|
52
|
+
}, u);
|
|
53
|
+
return new Uint8Array(f.drawBitmap);
|
|
77
54
|
}
|
|
78
|
-
async function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
rasMap: null,
|
|
94
|
-
voxelSizeMM: s ?? null
|
|
95
|
-
},
|
|
96
|
-
f
|
|
97
|
-
);
|
|
98
|
-
return { bitmap: new Uint8Array(u.drawBitmap), result: u.result };
|
|
55
|
+
async function l(e, t, n, r, a, s) {
|
|
56
|
+
let c = t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), l = i(r), u = l.buffer.slice(l.byteOffset, l.byteOffset + l.byteLength), d = [c, u], f = await o().execute({
|
|
57
|
+
name: "magicWand",
|
|
58
|
+
seed: e,
|
|
59
|
+
drawBitmap: c,
|
|
60
|
+
dims: n,
|
|
61
|
+
imageData: u,
|
|
62
|
+
options: a ?? {},
|
|
63
|
+
rasMap: null,
|
|
64
|
+
voxelSizeMM: s ?? null
|
|
65
|
+
}, d);
|
|
66
|
+
return {
|
|
67
|
+
bitmap: new Uint8Array(f.drawBitmap),
|
|
68
|
+
result: f.result
|
|
69
|
+
};
|
|
99
70
|
}
|
|
100
|
-
async function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
[s]
|
|
114
|
-
);
|
|
115
|
-
return { bitmap: new Uint8Array(i.drawBitmap), count: i.count };
|
|
71
|
+
async function u(e, t, n, r, i = 6) {
|
|
72
|
+
let a = t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), s = await o().execute({
|
|
73
|
+
name: "magicWandFromBitmap",
|
|
74
|
+
seed: e,
|
|
75
|
+
drawBitmap: a,
|
|
76
|
+
dims: n,
|
|
77
|
+
newColor: r,
|
|
78
|
+
connectivity: i
|
|
79
|
+
}, [a]);
|
|
80
|
+
return {
|
|
81
|
+
bitmap: new Uint8Array(s.drawBitmap),
|
|
82
|
+
count: s.count
|
|
83
|
+
};
|
|
116
84
|
}
|
|
117
|
-
class
|
|
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
|
-
return new Promise((o) => {
|
|
165
|
-
const s = (i) => {
|
|
166
|
-
if (i.data.type === "magicWandSharedResult") {
|
|
167
|
-
if (this._worker.removeEventListener("message", s), i.data.gen !== r) {
|
|
168
|
-
o(null);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
o(i.data.result);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
this._worker.addEventListener("message", s), this._worker.postMessage({
|
|
175
|
-
type: "magicWandShared",
|
|
176
|
-
seed: t,
|
|
177
|
-
options: n ?? {},
|
|
178
|
-
gen: r
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/** Terminate the worker and release resources. */
|
|
183
|
-
dispose() {
|
|
184
|
-
this._worker.terminate();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
export {
|
|
188
|
-
L as MagicWandShared,
|
|
189
|
-
M as findDrawingBoundarySlices,
|
|
190
|
-
S as interpolateMaskSlices,
|
|
191
|
-
x as magicWand,
|
|
192
|
-
I as magicWandFromBitmap
|
|
85
|
+
var d = class {
|
|
86
|
+
constructor(e, t, n, a) {
|
|
87
|
+
this._gen = 0;
|
|
88
|
+
let o = e.dimX * e.dimY * e.dimZ, s = new SharedArrayBuffer(o);
|
|
89
|
+
this.bitmap = new Uint8Array(s), this.bitmap.set(n);
|
|
90
|
+
let c = i(t), l = new SharedArrayBuffer(c.byteLength);
|
|
91
|
+
new Float32Array(l).set(c);
|
|
92
|
+
let u = n.slice();
|
|
93
|
+
this._worker = new r(), this.ready = new Promise((e) => {
|
|
94
|
+
let t = (n) => {
|
|
95
|
+
n.data.type === "initSharedDone" && (this._worker.removeEventListener("message", t), e());
|
|
96
|
+
};
|
|
97
|
+
this._worker.addEventListener("message", t);
|
|
98
|
+
}), this._worker.postMessage({
|
|
99
|
+
type: "initShared",
|
|
100
|
+
workingBuffer: s,
|
|
101
|
+
imageBuffer: l,
|
|
102
|
+
committedBuffer: u.buffer,
|
|
103
|
+
dims: e,
|
|
104
|
+
rasMap: null,
|
|
105
|
+
voxelSizeMM: a ?? null
|
|
106
|
+
}, [u.buffer]);
|
|
107
|
+
}
|
|
108
|
+
updateCommitted(e) {
|
|
109
|
+
let t = e.slice();
|
|
110
|
+
this._worker.postMessage({
|
|
111
|
+
type: "updateCommitted",
|
|
112
|
+
committed: t.buffer
|
|
113
|
+
}, [t.buffer]);
|
|
114
|
+
}
|
|
115
|
+
preview(e, t) {
|
|
116
|
+
let n = ++this._gen;
|
|
117
|
+
return new Promise((r) => {
|
|
118
|
+
let i = (e) => {
|
|
119
|
+
e.data.type === "magicWandSharedResult" && (this._worker.removeEventListener("message", i), e.data.gen === n ? r(e.data.result) : r(null));
|
|
120
|
+
};
|
|
121
|
+
this._worker.addEventListener("message", i), this._worker.postMessage({
|
|
122
|
+
type: "magicWandShared",
|
|
123
|
+
seed: e,
|
|
124
|
+
options: t ?? {},
|
|
125
|
+
gen: n
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
dispose() {
|
|
130
|
+
this._worker.terminate();
|
|
131
|
+
}
|
|
193
132
|
};
|
|
133
|
+
export { d as MagicWandShared, s as findDrawingBoundarySlices, c as interpolateMaskSlices, l as magicWand, u as magicWandFromBitmap };
|
|
@@ -5,7 +5,7 @@ export type Connectivity = 6 | 18 | 26;
|
|
|
5
5
|
* Threshold mode controls how the intensity range is computed from the seed.
|
|
6
6
|
*
|
|
7
7
|
* - `"symmetric"` (default) — range = `[seed - tolerance, seed + tolerance]`.
|
|
8
|
-
* - `"percent"` — range = `
|
|
8
|
+
* - `"percent"` — range = `seed ± |seed| * percent` (a zero seed uses 0.01).
|
|
9
9
|
* Requires {@link MagicWandOptions.percent}.
|
|
10
10
|
* - `"bright"` — only voxels **≥** seed are included:
|
|
11
11
|
* range = `[seed, seed + tolerance]` (or `[seed, Infinity]` when tolerance is 0).
|
|
@@ -37,19 +37,22 @@ export interface MagicWandOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
thresholdMode?: ThresholdMode;
|
|
39
39
|
/**
|
|
40
|
-
* Percentage threshold (0–1) used when `thresholdMode` is `"percent"`
|
|
41
|
-
*
|
|
40
|
+
* Percentage threshold (0–1) used when `thresholdMode` is `"percent"`
|
|
41
|
+
* (range `seed ± |seed|*pct`), or `"bright"`, `"dark"` or
|
|
42
|
+
* `"auto"` (one side only: `[seed, seed + |seed|*pct]` or `[seed - |seed|*pct, seed]`).
|
|
42
43
|
* Equivalent to `clickToSegmentPercent` in the old niivue API.
|
|
43
44
|
*/
|
|
44
45
|
percent?: number;
|
|
45
46
|
/**
|
|
46
47
|
* Volume calibration minimum — needed for `thresholdMode: "auto"` to
|
|
47
|
-
* determine bright vs dark.
|
|
48
|
+
* determine bright vs dark. In the image data's raw units, so
|
|
49
|
+
* `back.cal_min` (scaled by scl_slope/scl_inter) must be converted back.
|
|
48
50
|
*/
|
|
49
51
|
calMin?: number;
|
|
50
52
|
/**
|
|
51
53
|
* Volume calibration maximum — needed for `thresholdMode: "auto"` to
|
|
52
|
-
* determine bright vs dark.
|
|
54
|
+
* determine bright vs dark. In the image data's raw units, so
|
|
55
|
+
* `back.cal_max` (scaled by scl_slope/scl_inter) must be converted back.
|
|
53
56
|
*/
|
|
54
57
|
calMax?: number;
|
|
55
58
|
/** Neighbour connectivity (default 6). */
|
|
@@ -75,7 +78,8 @@ export interface MagicWandResult {
|
|
|
75
78
|
intensityMax: number;
|
|
76
79
|
/**
|
|
77
80
|
* Whether the auto-detect resolved to "bright" (`true`) or "dark" (`false`).
|
|
78
|
-
* Only meaningful when `thresholdMode` was `"auto"`.
|
|
81
|
+
* Only meaningful when `thresholdMode` was `"auto"`. In raw units: with a
|
|
82
|
+
* negative scl_slope, raw "bright" is the calibrated dark side.
|
|
79
83
|
*/
|
|
80
84
|
isBright?: boolean;
|
|
81
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niivue/nv-ext-drawing",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.220",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Drawing interpolation and segmentation tools for NiiVue",
|
|
6
6
|
"main": "./dist/nv-ext-drawing.js",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@niivue/niivue": "1.0.0-rc.
|
|
19
|
+
"@niivue/niivue": "1.0.0-rc.218"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@niivue/niivue": "1.0.0-rc.
|
|
23
|
-
"typescript": "
|
|
24
|
-
"vite": "^
|
|
22
|
+
"@niivue/niivue": "1.0.0-rc.218",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"vite": "^8.3.8",
|
|
25
25
|
"vite-plugin-dts": "^4.5.4"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|