diff --git a/dist/dwv.d.ts b/dist/dwv.d.ts index e47939f0f6..6c8a549648 100644 --- a/dist/dwv.d.ts +++ b/dist/dwv.d.ts @@ -3937,6 +3937,14 @@ export declare class ViewConfig { * @type {number|undefined} */ opacity: number | undefined; + /** + * Optional layer window level preset name. + * If present, the preset name will be used and + * the window centre and width ignored. + * + * @type {string|undefined} + */ + wlPresetName: string | undefined; /** * Optional layer window center. * diff --git a/dist/dwv.min.js b/dist/dwv.min.js index d3a8c40d13..185147f315 100644 --- a/dist/dwv.min.js +++ b/dist/dwv.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("konva"),require("jszip"),require("magic-wand-tool")):"function"==typeof define&&define.amd?define(["konva","jszip","konmagic-wand-tool"],t):"object"==typeof exports?exports.dwv=t(require("konva"),require("jszip"),require("magic-wand-tool")):e.dwv=t(e.Konva,e.JSZip,e.MagicWand)}(this,(function(e,t,n){return function(){"use strict";var i={626:function(e){e.exports=t},436:function(t){t.exports=e},812:function(e){e.exports=n}},r={};function o(e){var t=r[e];if(void 0!==t)return t.exports;var n=r[e]={exports:{}};return i[e](n,n.exports,o),n.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return function(){o.r(a),o.d(a,{App:function(){return gi},AppOptions:function(){return hi},ColourMap:function(){return h},DataElement:function(){return ce},DicomCode:function(){return Je},DicomParser:function(){return Ae},DicomWriter:function(){return Pi},DrawController:function(){return Nt},DrawDetails:function(){return Rt},DrawLayer:function(){return Vt},DrawMeta:function(){return Ft},Geometry:function(){return Qe},Image:function(){return st},Index:function(){return e},LayerGroup:function(){return zt},MaskFactory:function(){return rt},MaskSegment:function(){return et},MaskSegmentHelper:function(){return ht},Matrix33:function(){return L},Orientation:function(){return O},OverlayData:function(){return xn},PlaneHelper:function(){return St},Point:function(){return F},Point2D:function(){return b},Point3D:function(){return x},RGB:function(){return m},RescaleSlopeAndIntercept:function(){return qe},ScrollWheel:function(){return Fn},Size:function(){return Ue},Spacing:function(){return Me},Tag:function(){return $},TagValueExtractor:function(){return Ye},ToolConfig:function(){return Si},ToolboxController:function(){return tn},Vector3D:function(){return v},View:function(){return dt},ViewConfig:function(){return di},ViewController:function(){return mt},ViewLayer:function(){return It},WindowLevel:function(){return r},WriterRule:function(){return fi},addTagsToDictionary:function(){return Y},buildMultipart:function(){return z},createImage:function(){return ot},createMaskImage:function(){return at},createView:function(){return ut},customUI:function(){return ft},decoderScripts:function(){return dn},defaultPresets:function(){return s},defaults:function(){return Wn},getDefaultDicomSegJson:function(){return Ke},getDwvVersion:function(){return ue},getElementsFromJSONTags:function(){return Ai},getEllipseIndices:function(){return ni},getLayerDetailsFromEvent:function(){return kt},getMousePoint:function(){return Ct},getOrientationName:function(){return me},getPixelDataTag:function(){return re},getReverseOrientation:function(){return ge},getTagFromKey:function(){return ee},getTouchPoints:function(){return yt},getTypedArray:function(){return Ie},getUID:function(){return Di},hasDicomPrefix:function(){return de},i18n:function(){return Rn},labToUintLab:function(){return f},logger:function(){return i},luts:function(){return g},precisionRound:function(){return B},srgbToCielab:function(){return y},toolList:function(){return li}});class e{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create index with no values.");if(0===e.length)throw new Error("Cannot create index with empty values.");if(!e.every((function(e){return!isNaN(e)})))throw new Error("Cannot create index with non number values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}canCompare(e){return!!e&&this.length()===e.length()}equals(e){if(!this.canCompare(e))return!1;for(let t=0,n=this.length();t=this.length())throw new Error("Non valid dimension for toStringId.");let t="";for(let n=0;nr&&(r=i+1);const o=new Array(r);o.fill(0);for(let e=0;ethis.#u?this.#l:e*this.#d+this.#S}}class c{#g;#m;#r;#p=0;#f=!0;constructor(e,t,n){if(this.#g=e,t){const e=this.#g.getLength();this.#p=e/2}else this.#p=0;this.#f=n}getVoiLut(){return this.#m}getModalityLut(){return this.#g}setVoiLut(e){if(this.#m=e,this.#m.setSignedOffset(this.#g.getRSI().getSlope()*this.#p),this.#f){const e=this.#g.getLength();this.#r=new Uint8ClampedArray(e);for(let t=0;t255?255:t})),green:u((function(e){const t=256/3;let n=0;return e>=t&&(n=3*(e-t),n>255)?255:n})),blue:u((function(e){const t=256/3;let n=0;return e>=2*t&&(n=3*(e-2*t),n>255)?255:n}))},hot_iron:{red:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,255],blue:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,255]},pet:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,128,126,124,122,120,118,116,114,112,110,108,106,104,102,100,98,96,94,92,90,88,86,84,82,80,78,76,74,72,70,68,66,64,63,61,59,57,55,53,51,49,47,45,43,41,39,37,35,33,31,29,27,25,23,21,19,17,15,13,11,9,7,5,3,1,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,255],blue:[0,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,252,248,244,240,236,232,228,224,220,216,212,208,204,200,196,192,188,184,180,176,172,168,164,160,156,152,148,144,140,136,132,128,124,120,116,112,108,104,100,96,92,88,84,80,76,72,68,64,60,56,52,48,44,40,36,32,28,24,20,16,12,8,4,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157,161,165,170,174,178,182,186,190,194,198,202,206,210,214,218,222,226,230,234,238,242,246,250,255]},hot_metal_blue:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,6,9,12,15,18,21,24,26,29,32,35,38,41,44,47,50,52,55,57,59,62,64,66,69,71,74,76,78,81,83,85,88,90,93,96,99,102,105,108,111,114,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,166,169,172,175,178,181,184,187,190,194,198,201,205,209,213,217,221,224,228,232,236,240,244,247,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,6,8,9,11,13,15,17,19,21,23,24,26,28,30,32,34,36,38,40,41,43,45,47,49,51,53,55,56,58,60,62,64,66,68,70,72,73,75,77,79,81,83,85,87,88,90,92,94,96,98,100,102,104,105,107,109,111,113,115,117,119,120,122,124,126,128,130,132,134,136,137,139,141,143,145,147,149,151,152,154,156,158,160,162,164,166,168,169,171,173,175,177,179,181,183,184,186,188,190,192,194,196,198,200,201,203,205,207,209,211,213,215,216,218,220,222,224,226,228,229,231,233,235,237,239,240,242,244,246,248,250,251,253,255],blue:[0,2,4,6,8,10,12,14,16,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,184,186,188,190,192,194,196,198,200,197,194,191,188,185,182,179,176,174,171,168,165,162,159,156,153,150,144,138,132,126,121,115,109,103,97,91,85,79,74,68,62,56,50,47,44,41,38,35,32,29,26,24,21,18,15,12,9,6,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,6,9,12,15,18,21,24,26,29,32,35,38,41,44,47,50,53,56,59,62,65,68,71,74,76,79,82,85,88,91,94,97,100,103,106,109,112,115,118,121,124,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,176,179,182,185,188,191,194,197,200,203,206,210,213,216,219,223,226,229,232,236,239,242,245,249,252,255]},pet_20step:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,96,96,96,96,96,96,96,96,96,96,96,96,96,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,112,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,64,64,64,64,64,64,64,64,64,64,64,64,224,224,224,224,224,224,224,224,224,224,224,224,224,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,192,192,192,192,176,176,176,176,176,176,176,176,176,176,176,176,176,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,112,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,96,96,96,96,96,96,96,96,96,96,96,96,96,144,144,144,144,144,144,144,144,144,144,144,144,144,192,192,192,192,192,192,192,192,192,192,192,192,192,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,208,208,208,208,208,208,208,208,208,208,208,208,208,176,176,176,176,176,176,176,176,176,176,176,176,176,144,144,144,144,144,144,144,144,144,144,144,144,96,96,96,96,96,96,96,96,96,96,96,96,96,48,48,48,48,48,48,48,48,48,48,48,48,48,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255],blue:[0,0,0,0,0,0,0,0,0,0,0,0,0,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,128,176,176,176,176,176,176,176,176,176,176,176,176,176,192,192,192,192,192,192,192,192,192,192,192,192,192,224,224,224,224,224,224,224,224,224,224,224,224,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,64,64,64,64,64,64,64,64,64,64,64,64,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,64,64,64,64,64,64,64,64,64,64,64,64,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255]}};class m{r;g;b;constructor(e,t,n){this.r=e,this.g=t,this.b=n}}function p(e){return function(e){return n=e,.001172549*(t={r:parseInt(n.substring(1,3),16),g:parseInt(n.substring(3,5),16),b:parseInt(n.substring(5,7),16)}).r+.002301961*t.g+447059e-9*t.b<.5;var t,n}(e)?"#fff":"#000"}function f(e){return{l:655.35*e.l,a:257*e.a+32896,b:257*e.b+32896}}const D={x:95.0489,y:100,z:108.884};function y(e){return function(e){function t(e){let t=null;return t=e>.008856452?Math.pow(e,.333333333):7.787037037*e+.137931034,t}const n=D,i=t(e.y/n.y);return{l:116*i-16,a:500*(t(e.x/n.x)-i),b:200*(i-t(e.z/n.z))}}(function(e){function t(e){let t=null;return t=e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),t}const n=t(e.r/255),i=t(e.g/255),r=t(e.b/255);return{x:100*(.4124*n+.3576*i+.1805*r),y:100*(.2126*n+.7152*i+.0722*r),z:100*(.0193*n+.1192*i+.9505*r)}}(e))}function C(e){const t={Yellow:"#ffff00",Red:"#ff0000",White:"#ffffff",Green:"#008000",Blue:"#0000ff",Lime:"#00ff00",Fuchsia:"#ff00ff",Black:"#000000"};let n="#ffff00";return void 0!==t[e]&&(n=t[e]),n}class v{#D;#y;#C;constructor(e,t,n){this.#D=e,this.#y=t,this.#C=n}getX(){return this.#D}getY(){return this.#y}getZ(){return this.#C}equals(e){return null!==e&&this.getX()===e.getX()&&this.getY()===e.getY()&&this.getZ()===e.getZ()}toString(){return"("+this.getX()+", "+this.getY()+", "+this.getZ()+")"}norm(){return Math.sqrt(this.getX()*this.getX()+this.getY()*this.getY()+this.getZ()*this.getZ())}crossProduct(e){return new v(this.getY()*e.getZ()-e.getY()*this.getZ(),this.getZ()*e.getX()-e.getZ()*this.getX(),this.getX()*e.getY()-e.getX()*this.getY())}dotProduct(e){return this.getX()*e.getX()+this.getY()*e.getY()+this.getZ()*e.getZ()}}const I=1e4*Number.EPSILON;function T(e,t,n){return void 0===n&&(n=Number.EPSILON),Math.abs(e-t)0?1:-1;for(let t=0;t<3;++t)t===n.index?e.push(1*i):e.push(0)}return new L(e)}getThirdColMajorDirection(){return this.getColAbsMax(2).index}}function P(){return new L([1,0,0,0,1,0,0,0,1])}function w(){return new L([1,0,0,0,0,1,0,-1,0])}const O={Axial:"axial",Coronal:"coronal",Sagittal:"sagittal"};function A(e){let t=new v(Math.abs(e.getX()),Math.abs(e.getY()),Math.abs(e.getZ())),n="";const i=e.getX()<0?"R":"L",r=e.getY()<0?"A":"P",o=e.getZ()<0?"I":"S",a=1e-4;for(let e=0;e<3;e++)if(t.getX()>a&&t.getX()>t.getY()&&t.getX()>t.getZ())n+=i,t=new v(0,t.getY(),t.getZ());else if(t.getY()>a&&t.getY()>t.getX()&&t.getY()>t.getZ())n+=r,t=new v(t.getX(),0,t.getZ());else{if(!(t.getZ()>a&&t.getZ()>t.getX()&&t.getZ()>t.getY()))break;n+=o,t=new v(t.getX(),t.getY(),0)}return n}class b{#D;#y;constructor(e,t){this.#D=e,this.#y=t}getX(){return this.#D}getY(){return this.#y}equals(e){return null!=e&&this.#D===e.getX()&&this.#y===e.getY()}toString(){return"("+this.#D+", "+this.#y+")"}}class x{#D;#y;#C;constructor(e,t,n){this.#D=e,this.#y=t,this.#C=n}getX(){return this.#D}getY(){return this.#y}getZ(){return this.#C}equals(e){return null!==e&&this.getX()===e.getX()&&this.getY()===e.getY()&&this.getZ()===e.getZ()}isSimilar(e,t){return null!==e&&T(this.getX(),e.getX(),t)&&T(this.getY(),e.getY(),t)&&T(this.getZ(),e.getZ(),t)}toString(){return"("+this.getX()+", "+this.getY()+", "+this.getZ()+")"}getDistance(e){return Math.sqrt((this.getX()-e.getX())*(this.getX()-e.getX())+(this.getY()-e.getY())*(this.getY()-e.getY())+(this.getZ()-e.getZ())*(this.getZ()-e.getZ()))}minus(e){return new v(this.getX()-e.getX(),this.getY()-e.getY(),this.getZ()-e.getZ())}}class F{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create point with no values.");if(0===e.length)throw new Error("Cannot create point with empty values.");if(!e.every((function(e){return!isNaN(e)})))throw new Error("Cannot create point with non number values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}canCompare(e){return!!e&&this.length()===e.length()}equals(e){if(!this.canCompare(e))return!1;for(let t=0,n=this.length();t0?0|n:0;return e.substring(i,i+t.length)===t}function E(e,t){return null!=e&&null!=t&&e.substring(e.length-t.length)===t}function q(e){const t=[];if(null==e)return t;const n=/{(\w+)}/g;let i=n.exec(e);for(;i;)t.push(i[1]),i=n.exec(e);return t}function U(e,t){let n="";if(null==e)return n;if(n=e,null==t)return n;const i=q(e);for(let e=0;e=e.length)&&(n=0),(void 0===i||i<=n||i>e.length)&&(i=e.length);for(let r=n;ro;t--,o++)r=n[o],n[o]=n[t],n[t]=r}class le{#L;#P=!0;#w=function(){return new Int8Array(new Int16Array([1]).buffer)[0]>0}();#O;#A;constructor(e,t){this.#L=e,void 0!==t&&(this.#P=t),this.#O=this.#P!==this.#w,this.#A=new DataView(e)}readUint16(e){return this.#A.getUint16(e,this.#P)}readInt16(e){return this.#A.getInt16(e,this.#P)}readUint32(e){return this.#A.getUint32(e,this.#P)}readBigUint64(e){return this.#A.getBigUint64(e,this.#P)}readInt32(e){return this.#A.getInt32(e,this.#P)}readBigInt64(e){return this.#A.getBigInt64(e,this.#P)}readFloat32(e){return this.#A.getFloat32(e,this.#P)}readFloat64(e){return this.#A.getFloat64(e,this.#P)}readBinaryArray(e,t){const n=new Uint8Array(this.#L,e,t),i=8*n.length,r=new Uint8Array(i);let o=0,a=0;for(let e=0;e2^"+e+").")}}return r}function Te(e,t){return t?8:Z(e)?12:8}const Le="00280008",Pe="00280100",we="00280103",Oe="7FE00010";class Ae{#b={};#x;#F=new he;#R=this.#F;#E(e){return this.#F.decode(e)}#q(e){return this.#R.decode(e)}getDefaultCharacterSet(){return this.#x}setDefaultCharacterSet(e){this.#x=e}setDecoderCharacterSet(e){this.#R=new TextDecoder(e)}getDicomElements(){return this.#b}#U(e,t){const n=e.readHex(t);t+=Uint16Array.BYTES_PER_ELEMENT;const i=e.readHex(t);return t+=Uint16Array.BYTES_PER_ELEMENT,{tag:new $(n,i),endOffset:t}}#M(e,t,n){const i={};let r=this.#Q(e,t,n);if(t=r.endOffset,ie(r.tag))return{data:i,endOffset:r.endOffset,isSeqDelim:!0};if(i[r.tag.getKey()]={tag:r.tag,vr:"NONE",vl:r.vl,undefinedLength:r.undefinedLength},r.undefinedLength){let o=!1;for(;!o;)r=this.#Q(e,t,n),t=r.endOffset,o="FFFEE00D"===r.tag.getKey(),o||(i[r.tag.getKey()]=r)}else{const o=t;for(t-=r.vl;t8&&"OB"===s&&(i.warn("Reading DICOM pixel data with bitsAllocated>8 and OB VR, treating as OW"),e.vr="OW"),c=[],1===r)c.push(t.readBinaryArray(l,a));else if(8===r)0===n?c.push(t.readUint8Array(l,a)):c.push(t.readInt8Array(l,a));else{if(16!==r)throw new Error("Unsupported bits allocated: "+r);0===n?c.push(t.readUint16Array(l,a)):c.push(t.readInt16Array(l,a))}else if(void 0!==u)if("Uint8"===u)c=t.readUint8Array(l,a);else if("Uint16"===u)c=t.readUint16Array(l,a),"O"!==s[0]&&(c=Array.from(c));else if("Uint32"===u)c=t.readUint32Array(l,a),"O"!==s[0]&&(c=Array.from(c));else if("Uint64"===u)c=t.readUint64Array(l,a);else if("Int16"===u)c=Array.from(t.readInt16Array(l,a));else if("Int32"===u)c=Array.from(t.readInt32Array(l,a));else if("Int64"===u)c=t.readInt64Array(l,a);else if("Float32"===u)c=Array.from(t.readFloat32Array(l,a));else if("Float64"===u)c=Array.from(t.readFloat64Array(l,a));else{if("string"!==u)throw new Error("Unknown VR type: "+u);{const e=t.readUint8Array(l,a);c=K(s)?this.#q(e):this.#E(e),c=function(e){let t=e;const n=e.length-1;return e[n]===Se&&(t=e.substring(0,n)),t=t.trim(),t}(c).split("\\")}}else if("xx"===s)c=Array.from(t.readUint16Array(l,a));else if("ox"===s)c=8===r?0===n?Array.from(t.readUint8Array(l,a)):Array.from(t.readInt8Array(l,a)):0===n?Array.from(t.readUint16Array(l,a)):Array.from(t.readInt16Array(l,a));else if("xs"===s)c=0===n?Array.from(t.readUint16Array(l,a)):Array.from(t.readInt16Array(l,a));else if("AT"===s){const e=t.readUint16Array(l,a);c=[];for(let t=0,n=e.length;t=65&&r<=90&&o>=65&&o<=90);let s=null;if(n===t)s=a?"1.2.840.10008.1.2":"1.2.840.10008.1.2.1";else{if(a)throw new Error("Not a valid DICOM file (no magic DICM word foundand implicit VR big endian detected)");s="1.2.840.10008.1.2.2"}const l=new ce("UI");return l.tag=new $("0002","0010"),l.value=[s],l.vl=l.value[0].length,l.startOffset=e.startOffset,l.endOffset=l.startOffset+l.vl,l}(r);this.#b[e.tag.getKey()]=e,n=e.value[0],t=0}if(!function(e){return"1.2.840.10008.1.2"===e||"1.2.840.10008.1.2.1"===e||"1.2.840.10008.1.2.2"===e||De(e)||ye(e)||Ce(e)||ve(e)}(n))throw new Error("Unsupported DICOM transfer syntax: '"+n+"' ("+function(e){let t="Unknown";return"1.2.840.10008.1.2"===e?t="Little Endian Implicit":"1.2.840.10008.1.2.1"===e?t="Little Endian Explicit":"1.2.840.10008.1.2.1.99"===e?t="Little Endian Deflated Explicit":"1.2.840.10008.1.2.2"===e?t="Big Endian Explicit":De(e)?t="1.2.840.10008.1.2.4.50"===e?"JPEG Baseline":"JPEG Extended, Process 2+4":ye(e)?t="1.2.840.10008.1.2.4.57"===e?"JPEG Lossless, Nonhierarchical (Processes 14)":"JPEG Lossless, Non-hierarchical, 1st Order Prediction":function(e){return null!==e.match(/1.2.840.10008.1.2.4.5/)&&!De(e)&&!ye(e)||null!==e.match(/1.2.840.10008.1.2.4.6/)}(e)?t="Retired JPEG":function(e){return null!==e.match(/1.2.840.10008.1.2.4.8/)}(e)?t="JPEG-LS":Ce(e)?t="1.2.840.10008.1.2.4.91"===e?"JPEG 2000 (Lossless or Lossy)":"JPEG 2000 (Lossless only)":"1.2.840.10008.1.2.4.100"===e?t="MPEG2":ve(e)&&(t="RLE"),t}(n)+")");let l=!1;for(pe(n)&&(l=!0),fe(n)&&(a=new le(e,!1));t1&&t.length>e){const n=t.length/e,i=[];let o=0;for(let r=0;r{if(void 0===this.#G[e.type])return;const t=this.#G[e.type].slice();for(let n=0;n2?e:0})));let c=o.indexToOffset(l);void 0===i&&(i=!1);let u=null;u=i?function(e){return t.getRescaledValueAtOffset(e)}:function(e){return t.getValueAtOffset(e)};const d=o.get(0),S=o.get(1),h=o.get(2);let g=o.getDimSize(2);const m=t.getNumberOfComponents(),p=1===t.getPlanarConfiguration(),f=function(e,t,n,i,r,o,a,s){return 1===m?xe(e,t,n,i,r,o,a,s):3===m?function(e,t,n,i,r,o,a,s,l){const c=[];return l?(c.push(xe(e,t,n,i,r,o,a,s)),c.push(xe(e,t+n*i,n,i,r,o,a,s)),c.push(xe(e,t+2*n*i,n,i,r,o,a,s))):(i*=3,o*=3,c.push(xe(e,t,n,i,r,o,a,s)),c.push(xe(e,t+1,n,i,r,o,a,s)),c.push(xe(e,t+2,n,i,r,o,a,s))),{next:function(){const e=c[0].next(),t=c[1].next(),n=c[2].next();return e.done?{done:!0,index:n.index}:{value:[e.value,t.value,n.value],done:!1,index:[e.index,t.index,n.index]}}}}(e,3*t,n,i,r,o,a,s,p):void 0};let D=null;if(r&&void 0!==r){const e=r.getColAbsMax(0),t=r.getColAbsMax(2),n=!1,i=!1;let o=null;if(2===t.index)o=d*S,D=0===e.index?f(u,c,o,1,d,d,n,i):f(u,c,o,d,S,1,n,i);else if(0===t.index)o=h*S,D=1===e.index?f(u,c,o,d,S,g,n,i):f(u,c,o,g,h,d,n,i);else{if(1!==t.index)throw new Error("Unknown direction: "+t.index);o=h*d,D=0===e.index?f(u,c,o,1,d,g,n,i):f(u,c,o,g,h,1,n,i)}}else if(1===t.getNumberOfComponents())D=function(e,t,n,i){void 0===i&&(i=1);let r=t;return{next:function(){if(r=e[i+1].index&&++i;const t={value:e[i].colour,done:!1,index:n};return++n,t}return{done:!0,index:t}}}}class qe{#d;#k;constructor(e,t){this.#d=e,this.#k=t}getSlope(){return this.#d}getIntercept(){return this.#k}apply(e){return e*this.#d+this.#k}equals(e){return null!=e&&this.getSlope()===e.getSlope()&&this.getIntercept()===e.getIntercept()}isID(){return 1===this.getSlope()&&0===this.getIntercept()}}class Ue{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create size with no values.");if(0===e.length)throw new Error("Cannot create size with empty values.");if(!e.every((function(e){return!isNaN(e)&&0!==e})))throw new Error("Cannot create size with non number or zero values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}moreThanOne(e){return this.length()>=e+1&&1!==this.get(e)}canScroll3D(e){let t=2;return void 0!==e&&(t=e.getThirdColMajorDirection()),this.moreThanOne(t)}canScroll(e){let t=this.canScroll3D(e);for(let e=3;ethis.length())return null;if(void 0===t)t=0;else if(t<0||t>e)throw new Error("Invalid start value for getDimSize");let n=1;for(let i=t;in-1)throw new Error("Wrong input dir value: "+t[e]);for(let n=0;n=0&&ithis.length()-1)throw new Error("Invalid start value for indexToOffset");let n=0;for(let i=t;i0;--e)r=this.getDimSize(e),n[e]=Math.floor(i/r),i-=n[e]*r;return n[0]=i,new e(n)}get2D(){return{x:this.get(0),y:this.get(1)}}}class Me{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create spacing with no values.");if(0===e.length)throw new Error("Cannot create spacing with empty values.");if(!e.every((function(e){return!isNaN(e)&&0!==e})))throw new Error("Cannot create spacing with non number or zero values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}equals(e){if(!e)return!1;const t=this.length();if(t!==e.length())return!1;for(let n=0;n0?i+1:i}appendOrigin(e,t,n){const i=function(t){return t.equals(e)};if(void 0!==n){if(void 0!==this.#Y[n].find(i))throw new Error("Cannot append same time origin twice");this.#Y[n].splice(t,0,e)}if(void 0===n||n===this.#X){if(void 0!==this.#H.find(i))throw new Error("Cannot append same origin twice");this.#Z=!0,this.#H.splice(t,0,e);const n=this.#z.getValues();n[2]+=1,this.#z=new Ue(n)}}appendFrame(e,t){this.#Y[t]=[e];const n=this.#z.getValues(),i=this.#W.getValues();4===n.length?n[3]+=1:(n.push(2),i.push(1)),this.#z=new Ue(n),this.#W=new Me(i)}toString(){return"Origin: "+this.getOrigin()+", Size: "+this.getSize()+", Spacing: "+this.getSpacing()+", Orientation: "+this.getOrientation()}equals(e){return null!==e&&this.getOrigin().equals(e.getOrigin())&&this.getSize().equals(e.getSize())&&this.getSpacing().equals(e.getSpacing())}isInBounds(e){return this.isIndexInBounds(this.worldToIndex(e))}isIndexInBounds(e,t){return this.getSize().isInBounds(e,t)}indexToWorld(e){const t=this.getSpacing(),n=new x(e.get(0)*t.get(0),e.get(1)*t.get(1),e.get(2)*t.get(2)),i=this.getOrientation().multiplyPoint3D(n),r=e.getValues(),o=this.getOrigin();return r[0]=o.getX()+i.getX(),r[1]=o.getY()+i.getY(),r[2]=o.getZ()+i.getZ(),new F(r)}pointToWorld(e){const t=this.getSpacing(),n=new x(e.getX()*t.get(0),e.getY()*t.get(1),e.getZ()*t.get(2)),i=this.getOrientation().multiplyPoint3D(n),r=this.getOrigin();return new x(r.getX()+i.getX(),r.getY()+i.getY(),r.getZ()+i.getZ())}worldToIndex(t){const n=this.getOrigin(),i=new x(t.get(0)-n.getX(),t.get(1)-n.getY(),t.get(2)-n.getZ()),r=this.getOrientation().getInverse().multiplyPoint3D(i),o=t.getValues(),a=this.getSpacing();return o[0]=Math.round(r.getX()/a.get(0)),o[1]=Math.round(r.getY()/a.get(1)),o[2]=Math.round(r.getZ()/a.get(2)),new e(o)}worldToPoint(e){const t=this.getOrigin(),n=new x(e.get(0)-t.getX(),e.get(1)-t.getY(),e.get(2)-t.getZ()),i=this.getOrientation().getInverse().multiplyPoint3D(n),r=e.getValues(),o=this.getSpacing();return r[0]=i.getX()/o.get(0),r[1]=i.getY()/o.get(1),r[2]=i.getZ()/o.get(2),new x(r[0],r[1],r[2])}}function Be(e,t){return t.getInverse().multiplyArray3D(e)}function Ne(e,t){return t.multiplyArray3D(e)}function Ve(e,t,n){if(void 0===n&&(n=!0),e.length<=1)return;const r=t.getInverse();let o=r.multiplyPoint3D(e[0]),a=r.multiplyPoint3D(e[1]),s=Math.abs(o.getZ()-a.getZ());const l=[];for(let t=0;t1e-4&&i.warn("Varying slice spacing, mean delta: "+t.toFixed(3)+" ("+l.length+" case(s))")}return s}function Ge(e){const t=e["00280010"];if(void 0===t)throw new Error("Missing DICOM image number of rows");if(0===t.value.length)throw new Error("Empty DICOM image number of rows");const n=e["00280011"];if(void 0===n)throw new Error("Missing DICOM image number of columns");if(0===n.value.length)throw new Error("Empty DICOM image number of columns");return[n.value[0],t.value[0]]}function ke(e){if(void 0===e)return;if(1!==e.value.length)return;const t=e.value[0];let n=4,i=6;return 10===t.length&&(n=5,i=8),{year:parseInt(t.substring(0,4),10),monthIndex:t.length>=n+2?parseInt(t.substring(n,n+2),10)-1:0,day:t.length===i+2?parseInt(t.substring(i,i+2),10):0}}function He(e){if(void 0===e)return;if(1!==e.value.length)return;const t=e.value[0],n=parseInt(t.substring(0,2),10),i=t.length>=4?parseInt(t.substring(2,4),10):0,r=t.length>=6?parseInt(t.substring(4,6),10):0,o=t.length>=8?t.substring(7,10):0;return{hours:n,minutes:i,seconds:r,milliseconds:0===o?0:parseInt(o,10)*Math.pow(10,3-o.length)}}function ze(e,t,n){let i="";if(void 0===e)i+=" "+t+" is undefined,";else if(0===e.value.length)i+=" "+t+" is empty,";else if(void 0!==n)for(let r=0;ra&&(t+=" Series date/time is after Aquisition date/time")}let o;return 0!==t.length&&(o="Cannot calculate PET SUV:"+t),o}class Ye{getTime(e){}}class Xe{checkElements(e){let t,n;Ge(e);const i=e["00080060"];return void 0!==i&&(n=i.value[0],"PT"===n&&(t=We(e))),t}create(e,t,n){const o=Ge(e),a=[o[0],o[1],1],s=e["00280008"];s&&a.push(s.value[0]);const l=new Ue(a),c=function(e){let t=1,n=1;const r=["00280030","00181164","00182010","00280034"];for(let i=0;i=9?He({value:[t.substring(8)]}):void 0}}(r);o=e.date,a=e.time}void 0===a&&(a={hours:0,minutes:0,seconds:0,milliseconds:0});const s=new Date(o.year,o.monthIndex,o.day,a.hours,a.minutes,a.seconds,a.milliseconds),l=i.value[0]["00181074"],c=i.value[0]["00181075"],u=e["00101030"],d=(new Date(t.year,t.monthIndex,t.day,n.hours,n.minutes,n.seconds,n.milliseconds).getTime()-s.getTime())/1e3,S=Math.pow(2,-d/parseFloat(c.value[0])),h=l.value[0]*S;return 1e3*u.value[0]/h}(e),i.info("Applying PET SUV calibration: "+V),E*=V,U*=V);const G=new qe(E,U);b.setRescaleSlopeAndIntercept(G);const k=function(t){let n;const i=e[t];return void 0!==i&&(n=i.value[0]),n};if(Q.TransferSyntaxUID=k("00020010"),Q.MediaStorageSOPClassUID=k("00020002"),Q.SOPClassUID=k("00080016"),Q.Modality=k("00080060"),Q.ImageType=k("00080008"),Q.SamplesPerPixel=k("00280002"),Q.PhotometricInterpretation=k("00280004"),Q.PixelRepresentation=k("00280103"),Q.BitsAllocated=k("00280100"),Q.BitsStored=k("00280101"),Q.HighBit=k("00280102"),Q.StudyDate=k("00080020"),Q.StudyTime=k("00080030"),Q.StudyInstanceUID=k("0020000D"),Q.StudyID=k("00200010"),Q.SeriesInstanceUID=k("0020000E"),Q.SeriesNumber=k("00200011"),Q.ReferringPhysicianName=k("00080090"),Q.PatientName=k("00100010"),Q.PatientID=k("00100020"),Q.PatientBirthDate=k("00100030"),Q.PatientSex=k("00100040"),Q.Manufacturer=k("00080070"),Q.ManufacturerModelName=k("00081090"),Q.DeviceSerialNumber=k("00181000"),Q.SoftwareVersions=k("00181020"),Q.FrameOfReferenceUID=k("00200052"),Q.IsSigned=1===Q.PixelRepresentation,N)Q.pixelUnit="SUV";else{const t=function(e){let t;const n=["00281054","00541001"];for(let i=0;i>8};o=t.value.map(e),a=n.value.map(e),s=r.value.map(e)}}else if(8===l.value[2]){i.info("Scaling 16bits color lut since the lut descriptor is 8.");let e=t.value.slice(0);o=Array.from(new Uint8Array(e.buffer)),e=n.value.slice(0),a=Array.from(new Uint8Array(e.buffer)),e=r.value.slice(0),s=Array.from(new Uint8Array(e.buffer))}g.palette={red:o,green:a,blue:s}}const X=e["00082144"];return void 0!==X&&(Q.RecommendedDisplayFrameRate=parseInt(X.value[0],10)),b.setMeta(Q),b}}function je(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Ze(e,t){const n=e[t.tag];if(1===t.type||2===t.type){if(void 0===n)throw new Error("Missing or empty "+t.name)}else if(void 0===n)return;let i,r=!1;if(i=1===n.value.length?n.value[0]:n.value,Array.isArray(i))for(let e=0;e.206896552?Math.pow(e,3):.128418549*e-.017712903,t}const n=D,i=(e.l+16)/116;return{x:n.x*t(i+e.a/500),y:n.y*t(i),z:n.z*t(i-e.b/200)}}(e))}({l:.001525902*(n={l:i[0],a:i[1],b:i[2]}).l,a:.003891051*n.a-128,b:.003891051*n.b-128});t.displayRGBValue=r}var n;if(void 0===e["00620003"])throw new Error("Missing Segmented Property Category Code Sequence.");if(t.propertyCategoryCode=$e(e["00620003"].value[0]),void 0===e["0062000F"])throw new Error("Missing Segmented Property Type Code Sequence.");return t.propertyTypeCode=$e(e["0062000F"].value[0]),void 0!==e["00620020"]&&(t.trackingId=e["00620020"].value[0],t.trackingUid=e["00620021"].value[0]),t}function nt(e){if(void 0===e["00280030"])return null;const t=e["00280030"],n=[parseFloat(t.value[0]),parseFloat(t.value[1])];return void 0!==e["00180050"]?n.push(parseFloat(e["00180050"].value[0])):void 0!==e["00180088"]&&n.push(parseFloat(e["00180088"].value[0])),new Me(n)}function it(e){const t=[];if(void 0!==e["00089124"]){const n=e["00089124"].value;for(let e=0;e1e-4;return t&&(t=e>.001,t?(t=e>.01,t||i.warn("Using larger+ real world epsilon in SEG pos pat adding")):i.warn("Using larger real world epsilon in SEG pos pat adding")),t},U=[];U.push(C[0]);let M=0;for(let t=1;ts)throw new Error("Test distance is increasing when adding intermediate pos pats");U.push(C[t])}const Q=U.length,B=new Qe(A[0],o,b,w),V=["0"];for(let e=1;ee.length)return!1;for(const n of t)if(!e.includes(n))return!1;return!0}(this.#J,e)}getGeometry(){return this.#K}getBuffer(){return this.#L}canQuantify(){return 1===this.getNumberOfComponents()}canWindowLevel(){return this.isMonochrome()}isMonochrome(){return null!==this.getPhotometricInterpretation().match(/MONOCHROME/)}canScroll(e){const t=this.getGeometry().getSize();let n=1;return void 0!==this.#oe.numberOfFiles&&(n=this.#oe.numberOfFiles),t.canScroll(e)||1!==n}#ue(){return this.#K.getSize().getTotalSize(2)}getSecondaryOffset(e){return this.#K.getSize().indexToOffset(e,2)}getRescaleSlopeAndIntercept(e){let t=this.#t;if(!this.isConstantRSI()){if(void 0===e)throw new Error("Cannot get non constant RSI with empty slice index.");const n=this.getSecondaryOffset(e);void 0!==this.#$[n]?t=this.#$[n]:i.warn("undefined non constant rsi at "+n)}return t}#de(e){return this.#$[e]}setRescaleSlopeAndIntercept(e,t){if(this.#ee=this.#ee&&e.isID(),this.#te){if(!this.#t.equals(e))if(void 0===t)this.#t=e;else{this.#te=!1,this.#$=[];for(let e=0,t=this.#ue();e=this.#oe.numberOfFiles?i.warn("Ignoring frame at index "+t+" (size: "+this.#oe.numberOfFiles+")"):(this.#L.set(e,r*t),this.appendFrame(t,new x(0,0,0)))}appendFrame(e,t){this.#K.appendFrame(t,e),this.#he({type:"appendframe"})}getDataRange(){return this.#ae||(this.#ae=this.calculateDataRange()),this.#ae}getRescaledDataRange(){return this.#se||(this.#se=this.calculateRescaledDataRange()),this.#se}getHistogram(){if(!this.#le){const e=this.calculateHistogram();this.#ae=e.dataRange,this.#se=e.rescaledDataRange,this.#le=e.histogram}return this.#le}addEventListener(e,t){this.#ce.add(e,t)}removeEventListener(e,t){this.#ce.remove(e,t)}#he=e=>{this.#ce.fireEvent(e)};setAtOffsets(e,t){let n,i;if("number"==typeof t){if(1!==this.#re)throw new Error("Number of components is not 1 for setting single value.");n=[t]}else if(void 0!==t.r&&void 0!==t.g&&void 0!==t.b){if(3!==this.#re)throw new Error("Number of components is not 3 for setting RGB value.");n=[t.r,t.g,t.b]}for(let t=0,r=e.length;t=3&&(r=i.getDimSize(3));for(let i=0;it&&(t=n),nn?t:n}}{let e=this.getRescaledValueAtOffset(0),t=e,n=0;const i=this.getGeometry().getSize();let r=i.getTotalSize();3===i.length()&&(r=i.getDimSize(3));for(let i=0;it&&(t=n),ni&&(i=r),ra&&(a=s),s{const t=this.getCurrentIndex();if(3===t.length()){const n=t.getValues();n.push(0),this.setCurrentIndex(new e(n))}}))}getImage(){return this.#ge}setImage(e){this.#ge=e}getOrientation(){return this.#j}setOrientation(e){this.#j=e}init(){this.setInitialIndex()}setInitialIndex(){const t=this.#ge.getGeometry().getSize(),n=new Array(t.length());n.fill(0),n[0]=Math.floor(t.get(0)/2),n[1]=Math.floor(t.get(1)/2),n[2]=Math.floor(t.get(2)/2),this.setCurrentIndex(new e(n),!0)}getPlaybackMilliseconds(e){return e||(e=10),Math.round(1e3/e)}#ve=function(e,t){return 255};getAlphaFunction(){return this.#ve}setAlphaFunction(e){this.#ve=e,this.#he({type:"alphafuncchange"})}#Ie(){let e;if(this.#fe&&void 0!==this.#pe[this.#fe]&&void 0!==this.#pe[this.#fe].perslice&&!0===this.#pe[this.#fe].perslice){this.getCurrentIndex()||this.setInitialIndex();const t=this.getCurrentIndex(),n=this.#ge.getSecondaryOffset(t);e=this.#pe[this.#fe].wl[n]}if(void 0===e&&(void 0===this.#De&&this.setWindowLevelPresetById(0,!0),e=this.#De),void 0===this.#te||this.#ge.isConstantRSI()!==this.#te){let e,t;this.#te=this.#ge.isConstantRSI(),this.#te?(e=this.#ge.getRescaleSlopeAndIntercept(),t=!0):(e=new qe(1,0),t=!1);const i=new n(e,this.#ge.getMeta().BitsStored);this.#me=new c(i,this.#ge.getMeta().IsSigned,t)}const t=this.#me.getVoiLut();let i;if(void 0!==t&&(i=t.getWindowLevel()),void 0===t||!e.equals(i)){const t=new l(e);this.#me.setVoiLut(t),this.#he({type:"wlchange",value:[e.center,e.width],wc:e.center,ww:e.width,skipGenerate:!0})}return this.#me}getWindowPresets(){return this.#pe}getWindowPresetsNames(){return Object.keys(this.#pe)}setWindowPresets(e){this.#pe=e}addWindowPresets(e){const t=Object.keys(e);let n=null;for(let i=0;i{this.#ce.fireEvent(e)};getWindowLevelMinMax(){const e=this.getImage().getRescaledDataRange(),t=e.min;let n=e.max-t;return n<1&&(i.warn("Zero or negative window width, defaulting to one."),n=1),new r(t+n/2,n)}setWindowLevelMinMax(){const e=this.getWindowLevelMinMax();this.setWindowLevel(e,"minmax")}generateImageData(e,t){void 0===t&&(this.getCurrentIndex()||this.setInitialIndex(),t=this.getCurrentIndex());const n=this.getImage(),r=!n.isConstantRSI(),o=Re(n,t,r,this.getOrientation()),a=n.getPhotometricInterpretation();switch(a){case"MONOCHROME1":case"MONOCHROME2":!function(e,t,n,i,r){let o=0,a=0,s=t.next();for(;!s.done;)a=i.getValue(s.value),e.data[o]=r.red[a],e.data[o+1]=r.green[a],e.data[o+2]=r.blue[a],e.data[o+3]=n(s.value,s.index),o+=4,s=t.next()}(e,o,this.getAlphaFunction(),this.#Ie(),this.#Te());break;case"PALETTE COLOR":!function(e,t,n,r,o){const a=function(e){return e>>8};o&&i.info("Scaling 16bits data to 8bits.");let s=0,l=0,c=t.next();for(;!c.done;)l=c.value,o?(e.data[s]=a(r.red[l]),e.data[s+1]=a(r.green[l]),e.data[s+2]=a(r.blue[l])):(e.data[s]=r.red[l],e.data[s+1]=r.green[l],e.data[s+2]=r.blue[l]),e.data[s+3]=n(l,c.index),s+=4,c=t.next()}(e,o,this.getAlphaFunction(),this.#Te(),16===n.getMeta().BitsStored);break;case"RGB":!function(e,t,n){let i=0,r=t.next();for(;!r.done;)e.data[i]=r.value[0],e.data[i+1]=r.value[1],e.data[i+2]=r.value[2],e.data[i+3]=n(r.value,r.index),i+=4,r=t.next()}(e,o,this.getAlphaFunction());break;case"YBR_FULL":!function(e,t,n){let i=0,r=null,o=t.next();for(;!o.done;)a=o.value[0],s=o.value[1],r={r:a+1.402*((l=o.value[2])-128),g:a-.34414*(s-128)-.71414*(l-128),b:a+1.772*(s-128)},e.data[i]=r.r,e.data[i+1]=r.g,e.data[i+2]=r.b,e.data[i+3]=n(o.value,o.index),i+=4,o=t.next();var a,s,l}(e,o,this.getAlphaFunction());break;default:throw new Error("Unsupported photometric interpretation: "+a)}}getScrollIndex(){let e=null;const t=this.getOrientation();return e=void 0!==t?t.getThirdColMajorDirection():2,e}}class St{#W;#Le;#Pe;#we;constructor(e,t,n){this.#W=e,this.#Le=t,this.#Pe=n,this.#we=function(e,t){let n=e.asOneAndZeros().multiply(t);return e.asOneAndZeros().getAbs().equals(w().getAbs())&&(n=n.getAbs()),n}(t,n)}getOffset3DFromPlaneOffset(e){const t=new v(e.x,e.y,0),n=this.getTargetDeOrientedVector3D(t);return new v(n.getX()*this.#W.get(0),n.getY()*this.#W.get(1),n.getZ()*this.#W.get(2))}getPlaneOffsetFromOffset3D(e){const t=new v(e.x/this.#W.get(0),e.y/this.#W.get(1),e.z/this.#W.get(2)),n=this.getTargetOrientedVector3D(t);return{x:n.getX(),y:n.getY()}}getTargetOrientedVector3D(e){let t=e;return void 0!==this.#we&&(t=this.#we.getInverse().multiplyVector3D(e)),t}getTargetDeOrientedVector3D(e){let t=e;return void 0!==this.#we&&(t=this.#we.multiplyVector3D(e)),t}getTargetDeOrientedPoint3D(e){let t=e;return void 0!==this.#we&&(t=this.#we.multiplyPoint3D(e)),t}getImageOrientedVector3D(e){let t=e;if(void 0!==this.#Pe){const n=Ne([e.getX(),e.getY(),e.getZ()],this.#Pe);t=new v(n[0],n[1],n[2])}return t}getImageOrientedPoint3D(e){let t=e;if(void 0!==this.#Pe){const n=Ne([e.getX(),e.getY(),e.getZ()],this.#Pe);t=new x(n[0],n[1],n[2])}return t}getImageDeOrientedVector3D(e){let t=e;if(void 0!==this.#Pe){const n=Be([e.getX(),e.getY(),e.getZ()],this.#Pe);t=new v(n[0],n[1],n[2])}return t}getImageDeOrientedPoint3D(e){let t=e;if(void 0!==this.#Pe){const n=Be([e.getX(),e.getY(),e.getZ()],this.#Pe);t=new x(n[0],n[1],n[2])}return t}getTargetOrientedPositiveXYZ(e){const t=Be([e.x,e.y,e.z],this.#we);return{x:t[0],y:t[1],z:t[2]}}getScrollIndex(){let e=null;return e=void 0!==this.#Pe?this.#Pe.getThirdColMajorDirection():2,e}getNativeScrollIndex(){let e=null;return e=void 0!==this.#Le?this.#Le.getThirdColMajorDirection():2,e}}class ht{#Oe;#Ae;#be=[];constructor(e){this.#Oe=e,this.#Ae=e.getMeta().custom.segments}hasSegment(e){return void 0!==this.getSegment(e)}maskHasSegments(e){const t=[],n=[];for(let r=0;r