dwv
Version:
DICOM Web Viewer.
2 lines • 7.91 kB
JavaScript
class t{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}toString(){return"("+this.#t+", "+this.#e+", "+this.#r+")"}norm(){return Math.sqrt(this.#t*this.#t+this.#e*this.#e+this.#r*this.#r)}crossProduct(e){return new t(this.#e*e.getZ()-e.getY()*this.#r,this.#r*e.getX()-e.getZ()*this.#t,this.#t*e.getY()-e.getX()*this.#e)}dotProduct(t){return this.#t*t.getX()+this.#e*t.getY()+this.#r*t.getZ()}isCodirectional(t){return this.dotProduct(t)>0}}class e{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}getValues(){return[this.#t,this.#e,this.#r]}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}isSimilar(t,e){return null!==t&&i(this.#t,t.getX(),e)&&i(this.#e,t.getY(),e)&&i(this.#r,t.getZ(),e)}toString(){return"("+this.#t+", "+this.#e+", "+this.#r+")"}getDistance(t){return Math.sqrt(this.#s(t))}#s(t){const e=this.#t-t.getX(),r=this.#e-t.getY(),s=this.#r-t.getZ();return e*e+r*r+s*s}getClosest(t){let e=0,r=this.#s(t[e]);for(let s=0;s<t.length;++s){const n=this.#s(t[s]);n<r&&(e=s,r=n)}return e}minus(e){return new t(this.#t-e.getX(),this.#e-e.getY(),this.#r-e.getZ())}}class r{#n;constructor(t){if(!t||void 0===t)throw new Error("Cannot create index with no values.");if(0===t.length)throw new Error("Cannot create index with empty values.");if(!t.every((function(t){return!isNaN(t)})))throw new Error("Cannot create index with non number values.");this.#n=t}get(t){return this.#n[t]}length(){return this.#n.length}toString(){return"("+this.#n.toString()+")"}getValues(){return this.#n.slice()}canCompare(t){return!!t&&this.length()===t.length()}equals(t){if(!this.canCompare(t))return!1;for(let e=0,r=this.length();e<r;++e)if(this.get(e)!==t.get(e))return!1;return!0}compare(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)this.get(r)!==t.get(r)&&e.push(r);return e}add(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)e.push(this.get(r)+t.get(r));return new r(e)}#i(t,e){const s=this.#n.slice();return t<s.length?s[t]+=e:console.warn("Cannot add to given dimension: ",t,s.length),new r(s)}next(t){return this.#i(t,1)}previous(t){return this.#i(t,-1)}getWithNew2D(t,e){const s=[t,e];for(let t=2,e=this.length();t<e;++t)s.push(this.get(t));return new r(s)}}const s={levels:{TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4},level:3,trace:function(t){this.level<=this.levels.TRACE&&console.trace(t)},debug:function(t){this.level<=this.levels.DEBUG&&console.debug(t)},info:function(t){this.level<=this.levels.INFO&&console.info(t)},warn:function(t){this.level<=this.levels.WARN&&console.warn(t)},error:function(t){this.level<=this.levels.ERROR&&console.error(t)}},n=1e4*Number.EPSILON;function i(t,e,r){return void 0===r&&(r=Number.EPSILON),Math.abs(t-e)<r}class a{#n;#a;constructor(t){this.#n=t}get(t,e){return this.#n[3*t+e]}getInverse(){return void 0===this.#a&&(this.#a=function(t){const e=t.get(0,0),r=t.get(0,1),n=t.get(0,2),i=t.get(1,0),l=t.get(1,1),h=t.get(1,2),o=t.get(2,0),u=t.get(2,1),g=t.get(2,2),c=l*g-h*u,f=h*o-i*g,v=i*u-l*o;let d=e*c+r*f+n*v;if(0!==d)return d=1/d,new a([d*c,d*(n*u-r*g),d*(r*h-n*l),d*f,d*(e*g-n*o),d*(n*i-e*h),d*v,d*(r*o-e*u),d*(e*l-r*i)]);s.warn("Cannot invert 3*3 matrix with zero determinant.")}(this)),this.#a}equals(t){for(let e=0;e<3;++e)for(let r=0;r<3;++r)if(this.get(e,r)!==t.get(e,r))return!1;return!0}isSimilar(t,e){for(let r=0;r<3;++r)for(let s=0;s<3;++s)if(!i(this.get(r,s),t.get(r,s),e))return!1;return!0}toString(){let t="[";for(let e=0;e<3;++e){0!==e&&(t+=", \n ");for(let r=0;r<3;++r)0!==r&&(t+=", "),t+=this.get(e,r)}return t+="]",t}multiply(t){const e=[];for(let r=0;r<3;++r)for(let s=0;s<3;++s){let n=0;for(let e=0;e<3;++e)n+=this.get(r,e)*t.get(e,s);e.push(n)}return new a(e)}getAbs(){const t=[];for(let e=0;e<3;++e)for(let r=0;r<3;++r)t.push(Math.abs(this.get(e,r)));return new a(t)}multiplyArray3D(t){if(3!==t.length)throw new Error("Cannot multiply 3x3 matrix with non 3D array: "+t.length);const e=t[0],r=t[1],s=t[2],n=new Array(3);return n[0]=this.#n[0]*e+this.#n[1]*r+this.#n[2]*s,n[1]=this.#n[3]*e+this.#n[4]*r+this.#n[5]*s,n[2]=this.#n[6]*e+this.#n[7]*r+this.#n[8]*s,n}multiplyTypedArray3D(t,e){const r=t[0],s=t[1],n=t[2];e[0]=this.#n[0]*r+this.#n[1]*s+this.#n[2]*n,e[1]=this.#n[3]*r+this.#n[4]*s+this.#n[5]*n,e[2]=this.#n[6]*r+this.#n[7]*s+this.#n[8]*n}multiplyVector3D(e){const r=this.multiplyArray3D([e.getX(),e.getY(),e.getZ()]);return new t(r[0],r[1],r[2])}multiplyPoint3D(t){const r=this.multiplyArray3D([t.getX(),t.getY(),t.getZ()]);return new e(r[0],r[1],r[2])}multiplyIndex3D(t){const e=this.multiplyArray3D(t.getValues());return new r(e)}getRowAbsMax(t){const e=[Math.abs(this.get(t,0)),Math.abs(this.get(t,1)),Math.abs(this.get(t,2))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(t,s),index:s}}getColAbsMax(t){const e=[Math.abs(this.get(0,t)),Math.abs(this.get(1,t)),Math.abs(this.get(2,t))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(s,t),index:s}}asOneAndZeros(){const t=[];for(let e=0;e<3;++e){const r=this.getRowAbsMax(e),s=r.value>0?1:-1;for(let e=0;e<3;++e)e===r.index?t.push(1*s):t.push(0)}return new a(t)}getThirdColMajorDirection(){return this.getColAbsMax(2).index}getValues(){return this.#n.slice()}}String.fromCharCode("u200B");class l{#l(t,e,r,s,n){const i=Math.floor(t[0]),a=Math.floor(t[1]),l=Math.floor(t[2]),h=i<0?0:i,o=i+1>=r[0]?i:i+1,u=a<0?0:a,g=a+1>=r[1]?a:a+1,c=l<0?0:l,f=l+1>=r[2]?l:l+1,v=h*s[0],d=o*s[0],y=u*s[1],w=g*s[1],m=c*s[2],p=f*s[2],x=v+y+m+n,M=v+y+p+n,A=v+w+m+n,b=v+w+p+n,z=d+y+m+n,S=d+y+p+n,D=d+w+m+n,C=d+w+p+n,R=h>=0&&h<r[0],E=o>=0&&o<r[0],I=u>=0&&u<r[1],O=g>=0&&g<r[1],Y=c>=0&&c<r[2],Z=f>=0&&f<r[2],N=R&&I&&Y?e[x]:0,X=R&&I&&Z?e[M]:0,q=R&&O&&Y?e[A]:0,T=R&&O&&Z?e[b]:0,B=E&&I&&Y?e[z]:0,P=E&&I&&Z?e[S]:0,U=E&&O&&Y?e[D]:0,V=E&&O&&Z?e[C]:0,L=Math.abs(t[0]-i),j=Math.abs(t[1]-a),W=Math.abs(t[2]-l),F=1-L,G=1-j,_=1-W;return N*(F*G*_)+X*(F*G*W)+q*(F*j*_)+T*(F*j*W)+B*(L*G*_)+P*(L*G*W)+U*(L*j*_)+V*(L*j*W)}#h(t){const e=Math.round(t);return Math.abs(t-e)<n?e:t}#o(t,e,r,n){const i=n[2]*r[2],a=function(t,e,r){let n=null;try{1===t||8===t?n=0===e?new Uint8Array(r):new Int8Array(r):16===t?n=0===e?new Uint16Array(r):new Int16Array(r):32===t&&(n=0===e?new Uint32Array(r):new Int32Array(r))}catch(t){if(t instanceof RangeError){const t=Math.floor(Math.log(r)/Math.log(2));s.error("Cannot allocate array of size: "+r+" (>2^"+t+").")}}return n}(8*t.BYTES_PER_ELEMENT,e,i);if(null===a)throw new Error("Cannot reallocate data for image resampling.");return a.fill(0),a}run(t){const e=t.sourceSize,r=t.targetSize,s=t.sourceUnitVectors,n=t.targetUnitVectors,i=t.sourceSpacing,l=t.targetSpacing,h=t.sourceImageBuffer,o=t.pixelRepresentation,u=this.#o(h,o,r,n),g=t.sourceStartOffset,c=t.targetStartOffset,f=t.interpolate,v=t.jobId,d=t.frame,y=new a(t.sourceOrientation),w=new a(t.targetOrientation),m=y.getInverse(),p=w.multiply(m),x=[(r[0]-1)/2,(r[1]-1)/2,(r[2]-1)/2],M=[(e[0]-1)/2,(e[1]-1)/2,(e[2]-1)/2],A=new Array(3),b=new Array(3),z=new Array(3);let S,D,C;for(let a=0;a<r[0];a++){A[0]=(a-x[0])*l[0],S=n[0]*a;for(let a=0;a<r[1];a++){A[1]=(a-x[1])*l[1],D=S+n[1]*a;for(let a=0;a<r[2];a++)if(A[2]=(a-x[2])*l[2],p.multiplyTypedArray3D(A,b),z[0]=this.#h(b[0]/i[0]+M[0]),z[1]=this.#h(b[1]/i[1]+M[1]),z[2]=this.#h(b[2]/i[2]+M[2]),z[0]>=0&&z[0]<e[0]&&z[1]>=0&&z[1]<e[1]&&z[2]>=0&&z[2]<e[2])if(C=D+n[2]*a,f){const t=this.#l(z,h,e,s,g);u[C]=t}else{const e=s[0]*Math.round(z[0])+s[1]*Math.round(z[1])+s[2]*Math.round(z[2])+g;u[C]=t.sourceImageBuffer[e]}}}return{targetImageBuffer:u,startOffset:c,jobId:v,frame:d}}}self.addEventListener("message",(function(t){const e=(new l).run(t.data);self.postMessage(e)}),!1);
//# sourceMappingURL=resampling.worker.min.js.map