@niivue/nv-ext-drawing 1.0.0-rc.14 → 1.0.0-rc.140
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 +1 -0
- package/dist/nv-ext-drawing.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/nv-ext-drawing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NVWorker as p } from "@niivue/niivue";
|
|
2
|
-
const g = '(function(){"use strict";const X={AXIAL:0,CORONAL:1};function ct(t,e){const{dimX:o,dimY:r,dimZ:s}=e;return t===X.AXIAL?{w:o,h:r,depth:s}:t===X.CORONAL?{w:o,h:s,depth:r}:{w:r,h:s,depth:o}}function
|
|
2
|
+
const g = '(function(){"use strict";const X={AXIAL:0,CORONAL:1};function ct(t,e){const{dimX:o,dimY:r,dimZ:s}=e;return t===X.AXIAL?{w:o,h:r,depth:s}:t===X.CORONAL?{w:o,h:s,depth:r}:{w:r,h:s,depth:o}}function k(t,e,o,r){return t+e*r.dimX+o*r.dimX*r.dimY}function Q(t,e,o,r,s){if(!s)return k(t,e,o,r);const{img2RASstep:i,img2RASstart:n}=s;return n[0]+t*i[0]+n[1]+e*i[1]+n[2]+o*i[2]}function _(t,e,o,r){const{dimX:s,dimY:i,dimZ:n}=r;if(e===X.AXIAL){const c=new Float32Array(s*i),f=t*s*i;for(let a=0;a<c.length;a++)c[a]=o[f+a];return c}if(e===X.CORONAL){const c=new Float32Array(s*n);for(let f=0;f<n;f++)for(let a=0;a<s;a++)c[a+f*s]=o[k(a,t,f,r)];return c}const l=new Float32Array(i*n);for(let c=0;c<n;c++)for(let f=0;f<i;f++)l[f+c*i]=o[k(t,f,c,r)];return l}function tt(t,e,o,r,s,i){const{dimX:n,dimY:l,dimZ:c}=r,f=1/s;if(e===X.AXIAL){const u=new Float32Array(n*l);for(let h=0;h<l;h++)for(let w=0;w<n;w++)u[w+h*n]=o[Q(w,h,t,r,i)]*f;return u}if(e===X.CORONAL){const u=new Float32Array(n*c);for(let h=0;h<c;h++)for(let w=0;w<n;w++)u[w+h*n]=o[Q(w,t,h,r,i)]*f;return u}const a=new Float32Array(l*c);for(let u=0;u<c;u++)for(let h=0;h<l;h++)a[h+u*l]=o[Q(t,h,u,r,i)]*f;return a}function wt(t,e,o,r,s,i,n){const{dimX:l,dimY:c,dimZ:f}=s;if(o===X.AXIAL){const a=e*l*c;for(let u=0;u<t.length;u++)t[u]>=i&&(r[a+u]=n)}else if(o===X.CORONAL)for(let a=0;a<f;a++)for(let u=0;u<l;u++)t[u+a*l]>=i&&(r[k(u,e,a,s)]=n);else for(let a=0;a<f;a++)for(let u=0;u<c;u++)t[u+a*c]>=i&&(r[k(e,u,a,s)]=n)}function ft(t,e,o){if(e<3||o<3)return;const r=new Float32Array(t.length);for(let s=0;s<o;s++)for(let i=0;i<e;i++){const n=i+s*e;r[n]=i===0||i===e-1?t[n]:(t[n-1]+2*t[n]+t[n+1])*.25}for(let s=0;s<o;s++)for(let i=0;i<e;i++){const n=i+s*e;t[n]=s===0||s===o-1?r[n]:(r[n-e]+2*r[n]+r[n+e])*.25}}function pt(t,e,o,r){const s=Math.abs(o-t),i=Math.abs(o-e),n=Math.exp(-s*s/(2*r*r)),l=Math.exp(-i*i/(2*r*r)),c=n+l;return c<1e-6?.5:n/c}function bt(t,e,o){const{depth:r}=ct(t,o);let s=-1,i=-1;for(let n=0;n<r;n++){const l=_(n,t,e,o);let c=!1;for(let f=0;f<l.length;f++)if(l[f]>0){c=!0;break}c&&(s===-1&&(s=n),i=n)}return s===-1?null:{first:s,last:i}}function xt(t,e,o,r,s,i,n,l){const c=n.sliceType??X.AXIAL,{w:f,h:a,depth:u}=ct(c,e),h=u-1,w={intensityWeight:n.intensityWeight??.7,binaryThreshold:n.binaryThreshold??.375,intensitySigma:n.intensitySigma??.1,applySmoothingToSlices:n.applySmoothingToSlices??!0,useIntensityGuided:n.useIntensityGuided??!1};if(s!==void 0&&i!==void 0){if(s>=i)throw new Error("Low slice index must be less than high slice index");if(s<0||i>h)throw new Error(`Slice indices out of bounds [0, ${h}]`)}const C=new Map;for(let p=0;p<=h;p++){const S=_(p,c,t,e);for(let y=0;y<S.length;y++){const g=S[y];if(g>0){const b=C.get(g);b?(b.min=Math.min(b.min,p),b.max=Math.max(b.max,p)):C.set(g,{min:p,max:p})}}}for(const[p,S]of C){const y=s!==void 0?Math.max(s,S.min):S.min,g=i!==void 0?Math.min(i,S.max):S.max;if(y>=g||g-y<2)continue;const b=_(y,c,t,e),R=_(g,c,t,e),x=new Float32Array(b.length),M=new Float32Array(R.length);for(let d=0;d<b.length;d++)x[d]=b[d]===p?1:0,M[d]=R[d]===p?1:0;w.applySmoothingToSlices&&(ft(x,f,a),ft(M,f,a));const v=w.useIntensityGuided&&o,B=v?tt(y,c,o,e,r,l):null,m=v?tt(g,c,o,e,r,l):null;for(let d=y+1;d<g;d++){const A=new Float32Array(f*a),N=(d-y)/(g-y),V=1-N;if(B&&m&&o){const L=tt(d,c,o,e,r,l),G=w.intensityWeight;for(let I=0;I<x.length;I++)if(x[I]>0||M[I]>0){const H=pt(B[I],m[I],L[I],w.intensitySigma),P=G*H+(1-G)*V,O=1-P;A[I]=x[I]*P+M[I]*O}else A[I]=x[I]*V+M[I]*N}else for(let L=0;L<x.length;L++)A[L]=x[L]*V+M[L]*N;wt(A,d,c,t,e,w.binaryThreshold,p)}}return t}function U(t,e,o,r){return t+e*r.dimX+o*r.dimX*r.dimY}function lt(t,e,o,r,s){if(!s)return U(t,e,o,r);const{img2RASstep:i,img2RASstart:n}=s;return n[0]+t*i[0]+n[1]+e*i[1]+n[2]+o*i[2]}const nt=[[-1,0,0],[1,0,0],[0,-1,0],[0,1,0],[0,0,-1],[0,0,1]],at=[[-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]],Mt=[[-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 ut(t){return t>=26?[...nt,...at,...Mt]:t>=18?[...nt,...at]:[...nt]}function dt(t,e,o,r,s={},i,n){const{tolerance:l=0,thresholdMode:c="symmetric",percent:f=0,calMin:a=0,calMax:u=1,connectivity:h=6,maxDistanceMM:w=Number.POSITIVE_INFINITY,is2D:C=!1,sliceAxis:p=0,penValue:S=1}=s,{dimX:y,dimY:g,dimZ:b}=o,R=y*g*b,[x,M,v]=t;if(x<0||M<0||v<0||x>=y||M>=g||v>=b)return{filledCount:0,seedIntensity:0,intensityMin:0,intensityMax:0};const B=lt(x,M,v,o,i),m=Number(r[B]);let d,A,N;if(s.intensityMin!==void 0&&s.intensityMax!==void 0)d=s.intensityMin,A=s.intensityMax;else{let E=c==="auto"?"symmetric":c;switch(c==="auto"&&(N=m>(a+u)*.5,E=N?"bright":"dark"),E){case"percent":{const F=m===0?.01:m;d=F*(1-f),A=F*(1+f);break}case"bright":if(f>0){const F=m===0?.01:m;d=F*(1-f),A=F*(1+f)}else l>0?(d=m,A=m+l):(d=m,A=Number.POSITIVE_INFINITY);break;case"dark":if(f>0){const F=m===0?.01:m;d=F*(1-f),A=F*(1+f)}else l>0?(d=m-l,A=m):(d=Number.NEGATIVE_INFINITY,A=m);break;default:d=m-l,A=m+l;break}}const V=ut(h),L=n?n[0]:1,G=n?n[1]:1,I=n?n[2]:1,H=w*w;function P(E,F,$){if(!Number.isFinite(H))return!0;const j=(E-x)*L,J=(F-M)*G,K=($-v)*I;return j*j+J*J+K*K<=H}let O=-1,q=-1;C&&(p===0?(O=2,q=v):p===1?(O=1,q=M):p===2&&(O=0,q=x));const it=new Uint8Array(R),yt=U(x,M,v,o);if(m<d||m>A)return{filledCount:0,seedIntensity:m,intensityMin:d,intensityMax:A,isBright:N};const rt=[yt];it[yt]=1;let gt=0;for(;rt.length>0;){const E=rt.shift(),F=Math.floor(E/(y*g)),$=Math.floor((E-F*y*g)/y),j=E-F*y*g-$*y;e[E]=S,gt++;for(const[J,K,St]of V){const W=j+J,T=$+K,Y=F+St;if(W<0||T<0||Y<0||W>=y||T>=g||Y>=b||O>=0&&(O===0?W:O===1?T:Y)!==q)continue;const st=U(W,T,Y,o);if(it[st]||(it[st]=1,!P(W,T,Y)))continue;const At=Number(r[lt(W,T,Y,o,i)]);At<d||At>A||rt.push(st)}}return{filledCount:gt,seedIntensity:m,intensityMin:d,intensityMax:A,isBright:N}}function It(t,e,o,r,s=6){const{dimX:i,dimY:n,dimZ:l}=o,[c,f,a]=t;if(c<0||f<0||a<0||c>=i||f>=n||a>=l)return 0;const u=U(c,f,a,o),h=e[u];if(h===r||h===0)return 0;const w=i*n*l,C=new Uint8Array(w),p=ut(s),S=[u];C[u]=1;let y=0;for(;S.length>0;){const g=S.shift();e[g]=r,y++;const b=Math.floor(g/(i*n)),R=Math.floor((g-b*i*n)/i),x=g-b*i*n-R*i;for(const[M,v,B]of p){const m=x+M,d=R+v,A=b+B;if(m<0||d<0||A<0||m>=i||d>=n||A>=l)continue;const N=U(m,d,A,o);C[N]||(C[N]=1,e[N]===h&&S.push(N))}}return y}const z=self.postMessage.bind(self),Ft={findBoundarySlices(t){const e=t.sliceType,o=new Uint8Array(t.drawBitmap),r=t.dims;return{result:bt(e,o,r)}},interpolateMaskSlices(t){const e=new Uint8Array(t.drawBitmap),o=t.dims,r=t.imageData?new Float32Array(t.imageData):null,s=t.maxVal??1,i=t.sliceIndexLow,n=t.sliceIndexHigh,l=t.options??{},c=t.rasMap??void 0;return{drawBitmap:xt(e,o,r,s,i,n,l,c).buffer}},magicWand(t){const e=t.seed,o=new Uint8Array(t.drawBitmap),r=t.dims,s=new Float32Array(t.imageData),i=t.options??{},n=t.rasMap??void 0,l=t.voxelSizeMM??void 0,c=dt(e,o,r,s,i,n,l);return{drawBitmap:o.buffer,result:c}},magicWandFromBitmap(t){const e=t.seed,o=new Uint8Array(t.drawBitmap),r=t.dims,s=t.newColor??0,i=t.connectivity??6,n=It(e,o,r,s,i);return{drawBitmap:o.buffer,count:n}}};let D=null,et=null,Z=null,ot=null,mt,ht;self.onmessage=t=>{const e=t.data;if(e.type==="initShared"){D=new Uint8Array(e.workingBuffer),et=new Float32Array(e.imageBuffer),Z=new Uint8Array(e.committedBuffer),ot=e.dims,mt=e.rasMap??void 0,ht=e.voxelSizeMM??void 0,z({type:"initSharedDone"});return}if(e.type==="updateCommitted"){Z=new Uint8Array(e.committed);return}if(e.type==="magicWandShared"){if(!D||!et||!Z||!ot){z({type:"magicWandSharedResult",error:"Not initialized",gen:e.gen});return}D.set(Z);const n=dt(e.seed,D,ot,et,e.options??{},mt,ht);z({type:"magicWandSharedResult",result:n,gen:e.gen});return}const{_wbId:o,name:r,...s}=e,i=Ft[r];if(!i){z({_wbId:o,_wbError:`Unknown operation: ${r}`});return}try{const n=i(s),l=[];for(const c of Object.values(n))c instanceof ArrayBuffer&&l.push(c);z({_wbId:o,...n},l)}catch(n){z({_wbId:o,_wbError:n instanceof Error?n.message:String(n)})}}})();\n', h = typeof self < "u" && self.Blob && new Blob([g], { type: "text/javascript;charset=utf-8" });
|
|
3
3
|
function w(e) {
|
|
4
4
|
let t;
|
|
5
5
|
try {
|
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.140",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Drawing interpolation and segmentation tools for NiiVue",
|
|
6
6
|
"main": "./dist/nv-ext-drawing.js",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@niivue/niivue": "1.0.0-rc.
|
|
19
|
+
"@niivue/niivue": "1.0.0-rc.139"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@niivue/niivue": "1.0.0-rc.
|
|
22
|
+
"@niivue/niivue": "1.0.0-rc.139",
|
|
23
23
|
"typescript": "~5.8.3",
|
|
24
24
|
"vite": "^6.3.2",
|
|
25
25
|
"vite-plugin-dts": "^4.5.4"
|