UNPKG

dicomweb-proxy

Version:

A proxy to translate between dicomweb and dimse

1 lines 82.9 kB
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[2914],{97181:(t,e,n)=>{n.d(e,{A:()=>o});const o=function(t,e,n){return`${t}::${e}::${n}`}},76910:(t,e,n)=>{n.d(e,{A:()=>a});var o=n(99737);const a=t=>t.shiftKey?t.ctrlKey?o.KeyboardBindings.ShiftCtrl:t.altKey?o.KeyboardBindings.ShiftAlt:t.metaKey?o.KeyboardBindings.ShiftMeta:o.KeyboardBindings.Shift:t.ctrlKey?t.altKey?o.KeyboardBindings.CtrlAlt:t.metaKey?o.KeyboardBindings.CtrlMeta:o.KeyboardBindings.Ctrl:t.altKey?t.metaKey&&o.KeyboardBindings.AltMeta||o.KeyboardBindings.Alt:t.metaKey?o.KeyboardBindings.Meta:void 0},97:(t,e,n)=>{n.d(e,{c:()=>l});var o=n(2076),a=n(29601),i=n(67013),s=n(82056);const r=i.H;function l(){(0,s.setAnnotationManager)(r)}r.setPreprocessingFn((t=>{const e=(t=(t=>(t.data||(t.data={}),t.data.cachedStats||(t.data.cachedStats={}),t))(t=(t=>(t.data||(t.data={}),t.data.handles||(t.data.handles={}),t.data.handles.textBox||(t.data.handles.textBox={}),t))(t))).annotationUID,n=(0,o.checkAndSetAnnotationLocked)(e);t.isLocked=n;const i=(0,a.checkAndSetAnnotationVisibility)(e);return t.isVisible=i,t})),(0,s.setAnnotationManager)(r)},75419:(t,e,n)=>{n.d(e,{R:()=>i});var o=n(15327),a=n(99737);function i(t){const e={segmentationId:t};(0,o.triggerEvent)(o.eventTarget,a.Events.SEGMENTATION_ADDED,e)}},9726:(t,e,n)=>{n.d(e,{G:()=>i});var o=n(15327),a=n(99737);function i(t){const e={segmentationId:t};(0,o.triggerEvent)(o.eventTarget,a.Events.SEGMENTATION_MODIFIED,e)}},1485:(t,e,n)=>{n.d(e,{B:()=>i});var o=n(15327),a=n(99737);function i(t){const e={segmentationId:t};(0,o.triggerEvent)(o.eventTarget,a.Events.SEGMENTATION_REMOVED,e)}},44951:(t,e,n)=>{n.d(e,{r:()=>i});var o=n(15327),a=n(99737);function i(t,e,n){const i={segmentationId:e,type:n,viewportId:t};(0,o.triggerEvent)(o.eventTarget,a.Events.SEGMENTATION_REPRESENTATION_MODIFIED,i)}},65290:(t,e,n)=>{n.d(e,{O:()=>i});var o=n(15327),a=n(99737);function i(t,e,n){const i={viewportId:t,segmentationId:e,type:n};(0,o.triggerEvent)(o.eventTarget,a.Events.SEGMENTATION_REPRESENTATION_REMOVED,i)}},47098:(t,e,n)=>{n.d(e,{s:()=>a});var o=n(93210);function a(t,e){const n=(0,o.Ut)(t,e);if(!n)return new Set;return Object.entries(n.segments).reduce(((t,[e,n])=>(n.visible||t.add(Number(e)),t)),new Set)}},9711:(t,e,n)=>{n(99737),n(21345)},88029:(t,e,n)=>{n.d(e,{A:()=>s});var o=n(85204),a=n(99737);const i=[a.ToolModes.Active,a.ToolModes.Passive,a.ToolModes.Enabled];const s=function(t){return o.wk.toolGroups.filter((({toolOptions:e})=>{const n=Object.keys(e);for(let o=0;o<n.length;o++)if(t===n[o]&&e[t]&&i.includes(e[t].mode))return!0;return!1}))}},57999:(t,e,n)=>{n.d(e,{A:()=>S});var o=n(3823),a=n(15327),i=n(85204),s=n(99737),r=n(7001),l=n(95527),d=n(93126),c=n(42797),u=n(58640),g=n(72967),m=n(44049);const{getSubPixelSpacingAndXYDirections:h,addCanvasPointsToArray:p,getArea:f}=l.polyline;function v(t,e,n){this.isEditingClosed=!0;const o=t.detail,{currentPoints:l,element:d}=o,c=l.canvas,u=(0,a.getEnabledElement)(d);if(!u)return;const{viewport:g}=u,m=e.data.contour.polyline.map(g.worldToCanvas),{spacing:p,xDir:f,yDir:v}=h(g,this.configuration.subPixelResolution);this.editData={prevCanvasPoints:m,editCanvasPoints:[c],startCrossingIndex:void 0,editIndex:0,annotation:e},this.commonData={annotation:e,viewportIdsToRender:n,spacing:p,xDir:f,yDir:v,movingTextBox:!1},i.wk.isInteractingWithTool=!0,d.addEventListener(s.Events.MOUSE_UP,this.mouseUpClosedContourEditCallback),d.addEventListener(s.Events.MOUSE_DRAG,this.mouseDragClosedContourEditCallback),d.addEventListener(s.Events.MOUSE_CLICK,this.mouseUpClosedContourEditCallback),d.addEventListener(s.Events.TOUCH_END,this.mouseUpClosedContourEditCallback),d.addEventListener(s.Events.TOUCH_DRAG,this.mouseDragClosedContourEditCallback),d.addEventListener(s.Events.TOUCH_TAP,this.mouseUpClosedContourEditCallback),(0,r.hideElementCursor)(d)}function I(t){i.wk.isInteractingWithTool=!1,t.removeEventListener(s.Events.MOUSE_UP,this.mouseUpClosedContourEditCallback),t.removeEventListener(s.Events.MOUSE_DRAG,this.mouseDragClosedContourEditCallback),t.removeEventListener(s.Events.MOUSE_CLICK,this.mouseUpClosedContourEditCallback),t.removeEventListener(s.Events.TOUCH_END,this.mouseUpClosedContourEditCallback),t.removeEventListener(s.Events.TOUCH_DRAG,this.mouseDragClosedContourEditCallback),t.removeEventListener(s.Events.TOUCH_TAP,this.mouseUpClosedContourEditCallback),(0,r.resetElementCursor)(t)}function C(t){const e=t.detail,{currentPoints:n,element:i}=e,s=n.world,r=n.canvas,l=(0,a.getEnabledElement)(i),{viewport:d}=l,{viewportIdsToRender:c,xDir:g,yDir:m,spacing:h}=this.commonData,{editIndex:f,editCanvasPoints:v,startCrossingIndex:I,annotation:C}=this.editData;this.createMemo(i,C);const E=v[v.length-1],D=d.canvasToWorld(E),A=o.eR.create();o.eR.subtract(A,s,D);const w=Math.abs(o.eR.dot(A,g)),x=Math.abs(o.eR.dot(A,m));if(w<=h[0]&&x<=h[1])return;void 0!==I&&this.checkAndRemoveCrossesOnEditLine(t);const S=f+p(i,v,r,this.commonData);this.editData.editIndex=S,void 0===I&&v.length>1&&this.checkForFirstCrossing(t,!0),this.editData.snapIndex=this.findSnapIndex(),-1!==this.editData.snapIndex?(this.editData.fusedCanvasPoints=this.fuseEditPointsWithClosedContour(t),void 0!==I&&this.checkForSecondCrossing(t,!0)&&(this.removePointsAfterSecondCrossing(!0),this.finishEditAndStartNewEdit(t)),(0,u.A)(c)):this.finishEditAndStartNewEdit(t)}function E(t){const e=t.detail,{element:n}=e,o=(0,a.getEnabledElement)(n),{viewport:i,renderingEngine:s}=o,{annotation:r,viewportIdsToRender:l}=this.commonData,{fusedCanvasPoints:c,editCanvasPoints:h}=this.editData;(0,g.A)(r,{points:c,closed:!0,targetWindingDirection:d.W.Clockwise},i),r.autoGenerated&&(r.autoGenerated=!1),(0,m.triggerAnnotationModified)(r,n);const p=h.pop();this.editData={prevCanvasPoints:c,editCanvasPoints:[p],startCrossingIndex:void 0,editIndex:0,snapIndex:void 0,annotation:r},(0,u.A)(l)}function D(t){const{prevCanvasPoints:e,editCanvasPoints:n,startCrossingIndex:a,snapIndex:i}=this.editData;if(void 0===a||void 0===i)return;const s=t.detail,{element:r}=s,l=[...n];let d,c;p(r,l,e[i],this.commonData),l.length>n.length&&l.pop(),a>i?(d=i,c=a):(d=a,c=i);const u=o.Zc.distance(e[d],l[0]),g=o.Zc.distance(e[d],l[l.length-1]),m=o.Zc.distance(e[c],l[0]),h=o.Zc.distance(e[c],l[l.length-1]),v=[];for(let t=0;t<d;t++){const n=e[t];v.push([n[0],n[1]])}let I=u+h,C=g+m;if(I<C)for(let t=0;t<l.length;t++){const e=l[t];v.push([e[0],e[1]])}else for(let t=l.length-1;t>=0;t--){const e=l[t];v.push([e[0],e[1]])}for(let t=c;t<e.length;t++){const n=e[t];v.push([n[0],n[1]])}const E=[];for(let t=d;t<c;t++){const n=e[t];E.push([n[0],n[1]])}if(I=m+g,C=h+u,I<C)for(let t=0;t<l.length;t++){const e=l[t];E.push([e[0],e[1]])}else for(let t=l.length-1;t>=0;t--){const e=l[t];E.push([e[0],e[1]])}return f(v)>f(E)?v:E}function A(t){const e=t.detail,{element:n}=e;this.completeClosedContourEdit(n)}function w(t){const e=(0,a.getEnabledElement)(t),{viewport:n}=e,{annotation:o,viewportIdsToRender:i}=this.commonData;this.doneEditMemo();const{fusedCanvasPoints:s,prevCanvasPoints:r}=this.editData;if(s){const e=(0,c.Q)(this.configuration,o)?(0,c.p)(this.configuration,s,r):s,a=this.configuration?.decimate||{};(0,g.A)(o,{points:e,closed:!0,targetWindingDirection:d.W.Clockwise},n,{decimate:{enabled:!!a.enabled,epsilon:a.epsilon}}),o.autoGenerated&&(o.autoGenerated=!1),(0,m.triggerAnnotationModified)(o,t)}this.isEditingClosed=!1,this.editData=void 0,this.commonData=void 0,(0,u.A)(i),this.deactivateClosedContourEdit(t)}function x(t){this.completeClosedContourEdit(t)}const S=function(t){t.activateClosedContourEdit=v.bind(t),t.deactivateClosedContourEdit=I.bind(t),t.mouseDragClosedContourEditCallback=C.bind(t),t.mouseUpClosedContourEditCallback=A.bind(t),t.finishEditAndStartNewEdit=E.bind(t),t.fuseEditPointsWithClosedContour=D.bind(t),t.cancelClosedContourEdit=x.bind(t),t.completeClosedContourEdit=w.bind(t)}},55927:(t,e,n)=>{n.d(e,{A:()=>T});var o=n(15327),a=n(7001),i=n(99737),s=n(85204),r=n(3823),l=n(42797),d=n(76910),c=n(58640),u=n(44049),g=n(5403),m=n(95527),h=n(82056),p=n(93126);const{addCanvasPointsToArray:f,pointsAreWithinCloseContourProximity:v,getFirstLineSegmentIntersectionIndexes:I,getSubPixelSpacingAndXYDirections:C}=m.polyline;function E(t,e,n){this.isDrawing=!0;const r=t.detail,{currentPoints:l,element:c}=r,u=l.canvas,g=(0,o.getEnabledElement)(c),{viewport:m}=g,h=(0,d.A)(t.detail.event)===this.configuration.contourHoleAdditionModifierKey,{spacing:p,xDir:f,yDir:v}=C(m,this.configuration.subPixelResolution)||{};p&&f&&v&&(this.drawData={canvasPoints:[u],polylineIndex:0,contourHoleProcessingEnabled:h,newAnnotation:!0},this.commonData={annotation:e,viewportIdsToRender:n,spacing:p,xDir:f,yDir:v,movingTextBox:!1},s.wk.isInteractingWithTool=!0,c.addEventListener(i.Events.MOUSE_UP,this.mouseUpDrawCallback),c.addEventListener(i.Events.MOUSE_DRAG,this.mouseDragDrawCallback),c.addEventListener(i.Events.MOUSE_CLICK,this.mouseUpDrawCallback),c.addEventListener(i.Events.TOUCH_END,this.mouseUpDrawCallback),c.addEventListener(i.Events.TOUCH_DRAG,this.mouseDragDrawCallback),c.addEventListener(i.Events.TOUCH_TAP,this.mouseUpDrawCallback),(0,a.hideElementCursor)(c))}function D(t){s.wk.isInteractingWithTool=!1,t.removeEventListener(i.Events.MOUSE_UP,this.mouseUpDrawCallback),t.removeEventListener(i.Events.MOUSE_DRAG,this.mouseDragDrawCallback),t.removeEventListener(i.Events.MOUSE_CLICK,this.mouseUpDrawCallback),t.removeEventListener(i.Events.TOUCH_END,this.mouseUpDrawCallback),t.removeEventListener(i.Events.TOUCH_DRAG,this.mouseDragDrawCallback),t.removeEventListener(i.Events.TOUCH_TAP,this.mouseUpDrawCallback),(0,a.resetElementCursor)(t)}function A(t){const e=t.detail,{currentPoints:n,element:a}=e,s=n.world,l=n.canvas,d=(0,o.getEnabledElement)(a),{viewport:g}=d,{annotation:m,viewportIdsToRender:h,xDir:p,yDir:v,spacing:I,movingTextBox:C}=this.commonData,{polylineIndex:E,canvasPoints:D,newAnnotation:A}=this.drawData;this.createMemo(a,m,{newAnnotation:A});const w=D[D.length-1],x=g.canvasToWorld(w),S=r.eR.create();r.eR.subtract(S,s,x);const b=Math.abs(r.eR.dot(S,p)),y=Math.abs(r.eR.dot(S,v));if(!(b<=I[0]&&y<=I[1])){if(C){this.isDrawing=!1;const{deltaPoints:t}=e,n=t.world,{textBox:o}=m.data.handles,{worldPosition:a}=o;a[0]+=n[0],a[1]+=n[1],a[2]+=n[2],o.hasMoved=!0}else{const e=this.findCrossingIndexDuringCreate(t);if(void 0!==e)this.applyCreateOnCross(t,e);else{const t=f(a,D,l,this.commonData);this.drawData.polylineIndex=E+t}m.invalidated=!0}(0,c.A)(h),m.invalidated&&(0,u.triggerAnnotationModified)(m,a,i.ChangeTypes.HandlesUpdated)}}function w(t){const{allowOpenContours:e}=this.configuration,{canvasPoints:n,contourHoleProcessingEnabled:o}=this.drawData,a=n[0],i=n[n.length-1],s=t.detail,{element:r}=s;this.doneEditMemo(),this.drawData.newAnnotation=!1,e&&!v(a,i,this.configuration.closeContourProximity)?this.completeDrawOpenContour(r,{contourHoleProcessingEnabled:o}):this.completeDrawClosedContour(r,{contourHoleProcessingEnabled:o})}function x(t,e){this.removeCrossedLinesOnCompleteDraw();const{canvasPoints:n}=this.drawData,{contourHoleProcessingEnabled:a,minPointsToSave:i}=e??{};if(i&&n.length<i)return!1;if(this.haltDrawing(t,n))return!1;const{annotation:s,viewportIdsToRender:r}=this.commonData,d=(0,o.getEnabledElement)(t),{viewport:g,renderingEngine:m}=d;f(t,n,n[0],this.commonData),n.pop();const h=(0,l.Q)(this.configuration,s)?(0,l.p)(this.configuration,n):n;this.updateContourPolyline(s,{points:h,closed:!0,targetWindingDirection:p.W.Clockwise},g);const{textBox:v}=s.data.handles;return v?.hasMoved||(0,u.triggerContourAnnotationCompleted)(s,a),this.isDrawing=!1,this.drawData=void 0,this.commonData=void 0,(0,c.A)(r),this.deactivateDraw(t),!0}function S(){const{canvasPoints:t}=this.drawData,e=t.length,n=[t[0],t[e-1]],o=t.slice(0,-1).slice(1),a=I(o,n[0],n[1],!1);if(a){const e=a[1];this.drawData.canvasPoints=1===e?t.splice(1):t.splice(0,e)}}function b(t,e){const{canvasPoints:n}=this.drawData,{contourHoleProcessingEnabled:a}=e??{};if(this.haltDrawing(t,n))return!1;const{annotation:i,viewportIdsToRender:s}=this.commonData,r=(0,o.getEnabledElement)(t),{viewport:d,renderingEngine:m}=r,h=(0,l.Q)(this.configuration,i)?(0,l.p)(this.configuration,n):n;this.updateContourPolyline(i,{points:h,closed:!1},d);const{textBox:p}=i.data.handles,f=i.data.contour.polyline;return i.data.handles.points=[f[0],f[f.length-1]],i.data.isOpenUShapeContour&&(i.data.openUShapeContourVectorToPeak=(0,g.A)(n,d)),p.hasMoved||(0,u.triggerContourAnnotationCompleted)(i,a),this.isDrawing=!1,this.drawData=void 0,this.commonData=void 0,(0,c.A)(s),this.deactivateDraw(t),!0}function y(t){const e=t.detail,{currentPoints:n,lastPoints:o}=e,a=n.canvas,i=o.canvas,{canvasPoints:s}=this.drawData,r=s.slice(0,-1),l=I(r,a,i,!1);if(void 0===l)return;return l[0]}function P(t,e){const n=t.detail,{element:a}=n,{canvasPoints:i,contourHoleProcessingEnabled:s}=this.drawData,{annotation:r,viewportIdsToRender:l}=this.commonData;f(a,i,i[e],this.commonData),i.pop();const d=i.slice(e),c=m.polyline.getArea(d);if(o.utilities.isEqual(c,0))return void i.splice(e+1);i.splice(0,e);const u={contourHoleProcessingEnabled:s,minPointsToSave:3};this.completeDrawClosedContour(a,u)&&this.activateClosedContourEdit(t,r,l)}function M(t){const{allowOpenContours:e}=this.configuration,{canvasPoints:n,contourHoleProcessingEnabled:o}=this.drawData,a=n[0],i=n[n.length-1];e&&!v(a,i,this.configuration.closeContourProximity)?this.completeDrawOpenContour(t,{contourHoleProcessingEnabled:o}):this.completeDrawClosedContour(t,{contourHoleProcessingEnabled:o})}function O(t,e){const{subPixelResolution:n}=this.configuration;if(function(t,e){const n=Math.max(3*e,3);return t.length<n}(e,n)){const{annotation:e,viewportIdsToRender:n}=this.commonData,a=(0,o.getEnabledElement)(t),{renderingEngine:i}=a;return(0,h.removeAnnotation)(e.annotationUID),this.isDrawing=!1,this.drawData=void 0,this.commonData=void 0,(0,c.A)(n),this.deactivateDraw(t),!0}return!1}const T=function(t){t.activateDraw=E.bind(t),t.deactivateDraw=D.bind(t),t.applyCreateOnCross=P.bind(t),t.findCrossingIndexDuringCreate=y.bind(t),t.completeDrawOpenContour=b.bind(t),t.removeCrossedLinesOnCompleteDraw=S.bind(t),t.mouseDragDrawCallback=A.bind(t),t.mouseUpDrawCallback=w.bind(t),t.completeDrawClosedContour=x.bind(t),t.cancelDrawing=M.bind(t),t.haltDrawing=O.bind(t)}},92400:(t,e,n)=>{n.d(e,{A:()=>m});var o=n(3823),a=n(95527);const{addCanvasPointsToArray:i,getFirstLineSegmentIntersectionIndexes:s}=a.polyline;function r(t,e){const n=t.detail,{element:a,currentPoints:r,lastPoints:l}=n,d=r.canvas,c=l.canvas,{editCanvasPoints:u,prevCanvasPoints:g}=this.editData,m=s(g,d,c,e);if(m)this.editData.startCrossingIndex=m[0],this.removePointsUpUntilFirstCrossing(e);else if(g.length>=2)if(u.length>this.configuration.checkCanvasEditFallbackProximity){const t=u[0],e=[];for(let n=0;n<g.length;n++){const a=g[n],i=o.Zc.distance(a,t);e.push({distance:i,index:n})}e.sort(((t,e)=>t.distance-e.distance));const n=[e[0],e[1]],a=Math.min(n[0].index,n[1].index);this.editData.startCrossingIndex=a}else{const t=o.Zc.create();o.Zc.subtract(t,u[1],u[0]),o.Zc.normalize(t,t);const n=6,r=[u[0][0]-t[0]*n,u[0][1]-t[1]*n],l=s(g,r,u[0],e);if(l){const t=[r];i(a,t,u[0],this.commonData),u.unshift(...t),this.removePointsUpUntilFirstCrossing(e),this.editData.editIndex=u.length-1,this.editData.startCrossingIndex=l[0]}}}function l(t){const{editCanvasPoints:e,prevCanvasPoints:n}=this.editData;let o=0;for(let a=0;a<e.length-1;a++){const i=[e[a],e[a+1]];if(o++,!!s(n,i[0],i[1],t))break}e.splice(0,o),this.editData.editIndex=e.length-1}function d(t,e){const n=t.detail,{currentPoints:o,lastPoints:a}=n,i=o.canvas,r=a.canvas,{prevCanvasPoints:l}=this.editData;return!!s(l,i,r,e)}function c(t){const{prevCanvasPoints:e,editCanvasPoints:n}=this.editData;for(let o=n.length-1;o>0;o--){const a=[n[o],n[o-1]],i=!!s(e,a[0],a[1],t);if(n.pop(),i)break}}function u(){const{editCanvasPoints:t,prevCanvasPoints:e,startCrossingIndex:n}=this.editData;if(void 0===n)return;const a=t[t.length-1],i=[];for(let t=0;t<e.length;t++){const n=e[t],s=o.Zc.distance(n,a);i.push({distance:s,index:t})}i.sort(((t,e)=>t.distance-e.distance));const r=t.slice(0,-1);for(let n=0;n<i.length;n++){const{index:o}=i[n],a=e[o],l=t[t.length-1];if(!s(r,a,l,!1))return o}return-1}function g(t){const e=t.detail,{currentPoints:n,lastPoints:o}=e,a=n.canvas,i=o.canvas,{editCanvasPoints:r}=this.editData,l=r.slice(0,-2),d=s(l,a,i,!1);if(!d)return;const c=d[0],u=r.length-c;for(let t=0;t<u;t++)r.pop()}const m=function(t){t.checkForFirstCrossing=r.bind(t),t.removePointsUpUntilFirstCrossing=l.bind(t),t.checkForSecondCrossing=d.bind(t),t.findSnapIndex=u.bind(t),t.removePointsAfterSecondCrossing=c.bind(t),t.checkAndRemoveCrossesOnEditLine=g.bind(t)}},5403:(t,e,n)=>{n.d(e,{A:()=>a,h:()=>i});var o=n(3823);function a(t,e){const n=t[0],a=t[t.length-1],i=o.Zc.create();o.Zc.set(i,a[0]-n[0],a[1]-n[1]),o.Zc.normalize(i,i);const s=o.Zc.create(),r=o.Zc.create();o.Zc.set(s,-i[1],i[0]),o.Zc.set(r,i[1],-i[0]);const l=[(n[0]+a[0])/2,(n[1]+a[1])/2],d={dist:0,index:null};for(let e=0;e<t.length;e++){const n=t[e],a=o.Zc.dist(n,l);a>d.dist&&(d.dist=a,d.index=e)}return[t[d.index],l].map(e.canvasToWorld)}function i(t,e){const{viewport:n}=t;return a(e.data.contour.polyline.map(n.worldToCanvas),n)}},69855:(t,e,n)=>{n.d(e,{A:()=>y});var o=n(3823),a=n(15327),i=n(85204),s=n(99737),r=n(7001),l=n(95527),d=n(42797),c=n(58640),u=n(72967),g=n(5403),m=n(44049);const{addCanvasPointsToArray:h,getSubPixelSpacingAndXYDirections:p}=l.polyline;function f(t,e,n){this.isEditingOpen=!0;const o=t.detail,{currentPoints:l,element:d}=o,c=l.canvas,u=(0,a.getEnabledElement)(d),{viewport:g}=u;this.doneEditMemo();const m=e.data.contour.polyline.map(g.worldToCanvas),{spacing:h,xDir:f,yDir:v}=p(g,this.configuration.subPixelResolution);this.editData={prevCanvasPoints:m,editCanvasPoints:[c],startCrossingIndex:void 0,editIndex:0},this.commonData={annotation:e,viewportIdsToRender:n,spacing:h,xDir:f,yDir:v,movingTextBox:!1},i.wk.isInteractingWithTool=!0,d.addEventListener(s.Events.MOUSE_UP,this.mouseUpOpenContourEditCallback),d.addEventListener(s.Events.MOUSE_DRAG,this.mouseDragOpenContourEditCallback),d.addEventListener(s.Events.MOUSE_CLICK,this.mouseUpOpenContourEditCallback),d.addEventListener(s.Events.TOUCH_END,this.mouseUpOpenContourEditCallback),d.addEventListener(s.Events.TOUCH_DRAG,this.mouseDragOpenContourEditCallback),d.addEventListener(s.Events.TOUCH_TAP,this.mouseUpOpenContourEditCallback),(0,r.hideElementCursor)(d)}function v(t){i.wk.isInteractingWithTool=!1,t.removeEventListener(s.Events.MOUSE_UP,this.mouseUpOpenContourEditCallback),t.removeEventListener(s.Events.MOUSE_DRAG,this.mouseDragOpenContourEditCallback),t.removeEventListener(s.Events.MOUSE_CLICK,this.mouseUpOpenContourEditCallback),t.removeEventListener(s.Events.TOUCH_END,this.mouseUpOpenContourEditCallback),t.removeEventListener(s.Events.TOUCH_DRAG,this.mouseDragOpenContourEditCallback),t.removeEventListener(s.Events.TOUCH_TAP,this.mouseUpOpenContourEditCallback),(0,r.resetElementCursor)(t)}function I(t){const e=t.detail,{currentPoints:n,element:i}=e,s=n.world,r=n.canvas,l=(0,a.getEnabledElement)(i),{viewport:d}=l,{viewportIdsToRender:u,xDir:g,yDir:m,spacing:p}=this.commonData,{editIndex:f,editCanvasPoints:v,startCrossingIndex:I}=this.editData,C=v[v.length-1],E=d.canvasToWorld(C),D=o.eR.create();this.createMemo(i,this.commonData.annotation),o.eR.subtract(D,s,E);const A=Math.abs(o.eR.dot(D,g)),w=Math.abs(o.eR.dot(D,m));if(A<=p[0]&&w<=p[1])return;void 0!==I&&this.checkAndRemoveCrossesOnEditLine(t);const x=f+h(i,v,r,this.commonData);this.editData.editIndex=x,void 0===I&&v.length>1&&this.checkForFirstCrossing(t,!1),this.editData.snapIndex=this.findSnapIndex(),this.editData.fusedCanvasPoints=this.fuseEditPointsWithOpenContour(t),void 0!==I&&this.checkForSecondCrossing(t,!1)?(this.removePointsAfterSecondCrossing(!1),this.finishEditOpenOnSecondCrossing(t)):this.checkIfShouldOverwriteAnEnd(t)&&this.openContourEditOverwriteEnd(t),(0,c.A)(u)}function C(t){const e=t.detail,{element:n}=e,o=(0,a.getEnabledElement)(n),{viewport:i}=o,{annotation:s,viewportIdsToRender:r}=this.commonData,l=this.fuseEditPointsForOpenContourEndEdit();(0,u.A)(s,{points:l,closed:!1},i);const d=s.data.contour.polyline;s.data.handles.points=[d[0],d[d.length-1]],s.data.handles.activeHandleIndex=1,(0,m.triggerAnnotationModified)(s,n),this.isEditingOpen=!1,this.editData=void 0,this.commonData=void 0,this.doneEditMemo(),this.deactivateOpenContourEdit(n),this.activateOpenContourEndEdit(t,s,r,null)}function E(t){const e=t.detail,{currentPoints:n,lastPoints:a}=e,i=n.canvas,s=a.canvas,{snapIndex:r,prevCanvasPoints:l,startCrossingIndex:d}=this.editData;if(void 0===d||void 0===r)return!1;if(-1===r)return!0;if(0!==r&&r!==l.length-1)return!1;const c=i,u=s,g=l[r],m=o.Zc.create(),h=o.Zc.create();o.Zc.set(m,c[0]-u[0],c[1]-u[1]),o.Zc.set(h,c[0]-g[0],c[1]-g[1]);const p=o.Zc.dot(m,h),f=Math.sqrt(m[0]*m[0]+m[1]*m[1]),v=Math.sqrt(h[0]*h[0]+h[1]*h[1]);return Math.acos(p/(f*v))<Math.PI/2}function D(){const{snapIndex:t,prevCanvasPoints:e,editCanvasPoints:n,startCrossingIndex:a}=this.editData,i=[];if(0===t)for(let t=e.length-1;t>=a;t--){const n=e[t];i.push([n[0],n[1]])}else for(let t=0;t<a;t++){const n=e[t];i.push([n[0],n[1]])}if(o.Zc.distance(e[a],n[0])<o.Zc.distance(e[a],n[n.length-1]))for(let t=0;t<n.length;t++){const e=n[t];i.push([e[0],e[1]])}else for(let t=n.length-1;t>=0;t--){const e=n[t];i.push([e[0],e[1]])}return i}function A(t){const{prevCanvasPoints:e,editCanvasPoints:n,startCrossingIndex:a,snapIndex:i}=this.editData;if(void 0===a||void 0===i)return;const s=t.detail,{element:r}=s,l=[...n];let d,c;h(r,l,e[i],this.commonData),l.length>n.length&&l.pop(),a>i?(d=i,c=a):(d=a,c=i);const u=o.Zc.distance(e[d],l[0]),g=o.Zc.distance(e[d],l[l.length-1]),m=o.Zc.distance(e[c],l[0]),p=o.Zc.distance(e[c],l[l.length-1]),f=[];for(let t=0;t<d;t++){const n=e[t];f.push([n[0],n[1]])}if(u+p<g+m)for(let t=0;t<l.length;t++){const e=l[t];f.push([e[0],e[1]])}else for(let t=l.length-1;t>=0;t--){const e=l[t];f.push([e[0],e[1]])}for(let t=c;t<e.length;t++){const n=e[t];f.push([n[0],n[1]])}return f}function w(t){const e=t.detail,{element:n}=e,o=(0,a.getEnabledElement)(n),{viewport:i,renderingEngine:s}=o,{annotation:r,viewportIdsToRender:l}=this.commonData,{fusedCanvasPoints:d,editCanvasPoints:g}=this.editData;(0,u.A)(r,{points:d,closed:!1},i);const h=r.data.contour.polyline;r.data.handles.points=[h[0],h[h.length-1]],(0,m.triggerAnnotationModified)(r,n);const p=g.pop();this.editData={prevCanvasPoints:d,editCanvasPoints:[p],startCrossingIndex:void 0,editIndex:0},(0,c.A)(l)}function x(t){const e=t.detail,{element:n}=e;this.completeOpenContourEdit(n)}function S(t){const e=(0,a.getEnabledElement)(t),{viewport:n}=e,{annotation:o,viewportIdsToRender:i}=this.commonData;this.doneEditMemo();const{fusedCanvasPoints:s,prevCanvasPoints:r}=this.editData;if(s){const e=(0,d.Q)(this.configuration)?(0,d.p)(this.configuration,s,r):s,a=this.configuration?.decimate||{};(0,u.A)(o,{points:e,closed:!1},n,{decimate:{enabled:!!a.enabled,epsilon:a.epsilon}});const i=o.data.contour.polyline;o.data.handles.points=[i[0],i[i.length-1]],o.data.isOpenUShapeContour&&(o.data.openUShapeContourVectorToPeak=(0,g.A)(s,n)),(0,m.triggerAnnotationModified)(o,t)}this.isEditingOpen=!1,this.editData=void 0,this.commonData=void 0,(0,c.A)(i),this.deactivateOpenContourEdit(t)}function b(t){this.completeOpenContourEdit(t)}const y=function(t){t.activateOpenContourEdit=f.bind(t),t.deactivateOpenContourEdit=v.bind(t),t.mouseDragOpenContourEditCallback=I.bind(t),t.mouseUpOpenContourEditCallback=x.bind(t),t.fuseEditPointsWithOpenContour=A.bind(t),t.finishEditOpenOnSecondCrossing=w.bind(t),t.checkIfShouldOverwriteAnEnd=E.bind(t),t.fuseEditPointsForOpenContourEndEdit=D.bind(t),t.openContourEditOverwriteEnd=C.bind(t),t.cancelOpenContourEdit=b.bind(t),t.completeOpenContourEdit=S.bind(t)}},70734:(t,e,n)=>{n.d(e,{A:()=>c});var o=n(15327),a=n(85204),i=n(99737),s=n(7001),r=n(95527);const{getSubPixelSpacingAndXYDirections:l}=r.polyline;function d(t,e,n,r){this.isDrawing=!0;const d=t.detail,{element:c}=d,u=(0,o.getEnabledElement)(c),{viewport:g}=u,{spacing:m,xDir:h,yDir:p}=l(g,this.configuration.subPixelResolution),f=e.data.contour.polyline.map(g.worldToCanvas);0===e.data.handles.activeHandleIndex&&f.reverse();let v=!1;r?.worldPosition&&(v=!0),this.drawData={canvasPoints:f,polylineIndex:f.length-1},this.commonData={annotation:e,viewportIdsToRender:n,spacing:m,xDir:h,yDir:p,movingTextBox:v},a.wk.isInteractingWithTool=!0,c.addEventListener(i.Events.MOUSE_UP,this.mouseUpDrawCallback),c.addEventListener(i.Events.MOUSE_DRAG,this.mouseDragDrawCallback),c.addEventListener(i.Events.MOUSE_CLICK,this.mouseUpDrawCallback),c.addEventListener(i.Events.TOUCH_END,this.mouseUpDrawCallback),c.addEventListener(i.Events.TOUCH_DRAG,this.mouseDragDrawCallback),c.addEventListener(i.Events.TOUCH_TAP,this.mouseUpDrawCallback),(0,s.hideElementCursor)(c)}const c=function(t){t.activateOpenContourEndEdit=d.bind(t)}},58161:(t,e,n)=>{n.d(e,{A:()=>v});var o=n(17328),a=n(95527),i=n(5403),s=n(15451);const{pointsAreWithinCloseContourProximity:r}=a.polyline;function l(t,e){const n={toolGroupId:this.toolGroupId,toolName:this.getToolName(),viewportId:t.viewport.id,annotationUID:e.annotationUID},{lineWidth:o,lineDash:a,color:i,fillColor:s,fillOpacity:r}=this.getAnnotationStyle({annotation:e,styleSpecifier:n}),{closed:l}=e.data.contour;return{color:i,width:o,lineDash:a,fillColor:s,fillOpacity:r,closePath:l}}function d(t,e,n){t?.viewport?.getImageData()&&(n.data.contour.closed?this.renderClosedContour(t,e,n):n.data.isOpenUShapeContour?(!function(t,e){e.data.openUShapeContourVectorToPeak||(e.data.openUShapeContourVectorToPeak=(0,i.h)(t,e))}(t,n),this.renderOpenUShapedContour(t,e,n)):this.renderOpenContour(t,e,n))}function c(t,e,n){if(n.parentAnnotationUID)return;const{viewport:a}=t,i=this._getRenderingOptions(t,n),r=[n.data.contour.polyline.map((t=>a.worldToCanvas(t))),...(0,s.A)(n,a)];(0,o.drawPath)(e,n.annotationUID,"1",r,i)}function u(t,e,n){const{viewport:a}=t,i=this._getRenderingOptions(t,n),s=n.data.contour.polyline.map((t=>a.worldToCanvas(t)));(0,o.drawPolyline)(e,n.annotationUID,"1",s,i);const r=n.data.handles.activeHandleIndex;if(!0===this.configuration.alwaysRenderOpenContourHandles?.enabled){const t=this.configuration.alwaysRenderOpenContourHandles.radius,a="0",l=[s[0],s[s.length-1]];0===r?l.shift():1===r&&l.pop(),(0,o.drawHandles)(e,n.annotationUID,a,l,{color:i.color,handleRadius:t})}if(null!==r){const t="1",a=s[0===r?0:s.length-1];(0,o.drawHandles)(e,n.annotationUID,t,[a],{color:i.color})}}function g(t,e,n){const{viewport:a}=t,{openUShapeContourVectorToPeak:i}=n.data,{polyline:s}=n.data.contour;if(this.renderOpenContour(t,e,n),!i)return;const r=a.worldToCanvas(s[0]),l=a.worldToCanvas(s[s.length-1]),d=[a.worldToCanvas(i[0]),a.worldToCanvas(i[1])],c=this._getRenderingOptions(t,n);(0,o.drawPolyline)(e,n.annotationUID,"first-to-last",[r,l],{color:c.color,width:c.width,closePath:!1,lineDash:"2,2"}),(0,o.drawPolyline)(e,n.annotationUID,"midpoint-to-open-contour",[d[0],d[1]],{color:c.color,width:c.width,closePath:!1,lineDash:"2,2"})}function m(t,e,n){const a=this._getRenderingOptions(t,n),{allowOpenContours:i}=this.configuration,{canvasPoints:s}=this.drawData;if(a.closePath=!1,(0,o.drawPolyline)(e,n.annotationUID,"1",s,a),i){const t=s[0],i=s[s.length-1];if(r(t,i,this.configuration.closeContourProximity))(0,o.drawPolyline)(e,n.annotationUID,"2",[i,t],a);else{const i="0";(0,o.drawHandles)(e,n.annotationUID,i,[t],{color:a.color,handleRadius:2})}}}function h(t,e,n){const{viewport:a}=t,{fusedCanvasPoints:i}=this.editData;if(void 0===i)return void this.renderClosedContour(t,e,n);const r=[i,...(0,s.A)(n,a)],l=this._getRenderingOptions(t,n);n.parentAnnotationUID&&l.fillOpacity&&(l.fillOpacity=0),(0,o.drawPath)(e,n.annotationUID,"preview-1",r,l)}function p(t,e,n){const{fusedCanvasPoints:a}=this.editData;if(void 0===a)return void this.renderOpenContour(t,e,n);const i=this._getRenderingOptions(t,n);(0,o.drawPolyline)(e,n.annotationUID,"preview-1",a,i)}function f(t,e,n){if(n.parentAnnotationUID)return;const{viewport:a}=t,i=this._getRenderingOptions(t,n),r=n.data.contour.polyline.map((t=>a.worldToCanvas(t))),l=(0,s.A)(n,a),d=r[0],c=[];for(let t=0;t<100;t++){const e=t/100*2*Math.PI,n=d[0]+6*Math.cos(e),o=d[1]+6*Math.sin(e);c.push([n,o])}const u=[[d[0]-12,d[1]],[d[0]+12,d[1]],[d[0],d[1]-12],[d[0],d[1]+12]];(0,o.drawPath)(e,n.annotationUID,"1-crosshair_v",[u[0],u[1]],i),(0,o.drawPath)(e,n.annotationUID,"1-crosshair_h",[u[2],u[3]],i);const g=[c,...l];(0,o.drawPath)(e,n.annotationUID,"1",g,i)}const v=function(t){t.renderContour=d.bind(t),t.renderClosedContour=c.bind(t),t.renderOpenContour=u.bind(t),t.renderPointContourWithMarker=f.bind(t),t.renderOpenUShapedContour=g.bind(t),t.renderContourBeingDrawn=m.bind(t),t.renderClosedContourBeingEdited=h.bind(t),t.renderOpenContourBeingEdited=p.bind(t),t._getRenderingOptions=l.bind(t)}},91350:(t,e,n)=>{n.d(e,{A:()=>f});var o=n(15327),a=n(3823),i=n(6030),s=n(2076),r=n(29601),l=n(82056),d=n(44049),c=n(75183),u=n(17343),g=n(64843);const{DefaultHistoryMemo:m}=o.utilities.HistoryMemo,{PointsManager:h}=o.utilities;class p extends i.A{static createAnnotation(...t){let e={annotationUID:null,highlighted:!0,invalidated:!0,metadata:{toolName:this.toolName},data:{text:"",handles:{points:new Array,textBox:{hasMoved:!1,worldPosition:[0,0,0],worldBoundingBox:{topLeft:[0,0,0],topRight:[0,0,0],bottomLeft:[0,0,0],bottomRight:[0,0,0]}}},label:""}};for(const n of t)e=o.utilities.deepMerge(e,n);return e}static createAnnotationForViewport(t,...e){return this.createAnnotation({metadata:t.getViewReference()},...e)}static createAndAddAnnotation(t,...e){const n=this.createAnnotationForViewport(t,...e);(0,l.addAnnotation)(n,t.element),(0,d.triggerAnnotationModified)(n,t.element)}constructor(t,e){super(t,e),this.mouseMoveCallback=(t,e)=>{if(!e)return!1;const{element:n,currentPoints:o}=t.detail,a=o.canvas;let i=!1;for(const t of e){if((0,s.isAnnotationLocked)(t.annotationUID)||!(0,r.isAnnotationVisible)(t.annotationUID))continue;const{data:e}=t,o=e.handles?e.handles.activeHandleIndex:void 0,l=this._imagePointNearToolOrHandle(n,t,a,6),d=l&&!t.highlighted,c=!l&&t.highlighted;d||c?(t.highlighted=!t.highlighted,i=!0):e.handles&&e.handles.activeHandleIndex!==o&&(i=!0)}return i},this.isSuvScaled=p.isSuvScaled,t.configuration?.getTextLines&&(this.configuration.getTextLines=t.configuration.getTextLines),t.configuration?.statsCalculator&&(this.configuration.statsCalculator=t.configuration.statsCalculator)}getHandleNearImagePoint(t,e,n,i){const s=(0,o.getEnabledElement)(t),{viewport:r}=s,{data:l}=e,{isCanvasAnnotation:d}=l,{points:c,textBox:u}=l.handles;if(u){const{worldBoundingBox:t}=u;if(t){const e={topLeft:r.worldToCanvas(t.topLeft),topRight:r.worldToCanvas(t.topRight),bottomLeft:r.worldToCanvas(t.bottomLeft),bottomRight:r.worldToCanvas(t.bottomRight)};if(n[0]>=e.topLeft[0]&&n[0]<=e.bottomRight[0]&&n[1]>=e.topLeft[1]&&n[1]<=e.bottomRight[1])return l.handles.activeHandleIndex=null,u}}for(let t=0;t<c?.length;t++){const e=c[t],o=d?e.slice(0,2):r.worldToCanvas(e);if(!0===a.Zc.distance(n,o)<i)return l.handles.activeHandleIndex=t,e}l.handles.activeHandleIndex=null}getLinkedTextBoxStyle(t,e){return{visibility:this.getStyle("textBoxVisibility",t,e),fontFamily:this.getStyle("textBoxFontFamily",t,e),fontSize:this.getStyle("textBoxFontSize",t,e),color:this.getStyle("textBoxColor",t,e),shadow:this.getStyle("textBoxShadow",t,e),background:this.getStyle("textBoxBackground",t,e),lineWidth:this.getStyle("textBoxLinkLineWidth",t,e),lineDash:this.getStyle("textBoxLinkLineDash",t,e)}}static isSuvScaled(t,e,n){if(t instanceof o.BaseVolumeViewport){const t=o.utilities.getVolumeId(e),n=o.cache.getVolume(t);return void 0!==n?.scaling?.PT}const a=n&&o.metaData.get("scalingModule",n);return"number"==typeof a?.suvbw}getAnnotationStyle(t){const{annotation:e,styleSpecifier:n}=t,o=t=>this.getStyle(t,n,e),{annotationUID:a}=e,i=(0,r.isAnnotationVisible)(a),l=(0,s.isAnnotationLocked)(a),d=o("lineWidth"),c=o("lineDash"),u=o("color"),g=o("markerSize");return{visibility:i,locked:l,color:u,lineWidth:d,lineDash:c,lineOpacity:1,fillColor:u,fillOpacity:0,shadow:o("shadow"),textbox:this.getLinkedTextBoxStyle(n,e),markerSize:g}}_imagePointNearToolOrHandle(t,e,n,o){if(this.getHandleNearImagePoint(t,e,n,o))return!0;return!!this.isPointNearTool(t,e,n,o,"mouse")||void 0}static createAnnotationState(t,e){const{data:n,annotationUID:o}=t,a={...n,cachedStats:{}};delete a.contour,delete a.spline;const i={annotationUID:o,data:structuredClone(a),deleting:e},s=n.contour;return s&&(i.data.contour={...s,polyline:null,pointsManager:h.create3(s.polyline.length,s.polyline)}),i}static createAnnotationMemo(t,e,n){if(!e)return;const{newAnnotation:a,deleting:i=!a&&void 0}=n||{},{annotationUID:s}=e,r=p.createAnnotationState(e,i),h={restoreMemo:()=>{const n=p.createAnnotationState(e,i),{viewport:a}=(0,o.getEnabledElement)(t)||{};if(a?.setViewReference(e.metadata),!0===r.deleting){if(r.deleting=!1,Object.assign(e.data,r.data),e.data.contour){const t=e.data;t.contour.polyline=r.data.contour.pointsManager.points,delete r.data.contour.pointsManager,t.segmentation&&(0,g.addContourSegmentationAnnotation)(e)}return r.data=n.data,(0,l.addAnnotation)(e,t),(0,u.setAnnotationSelected)(e.annotationUID,!0),void a?.render()}if(!1===r.deleting)return r.deleting=!0,r.data=n.data,(0,u.setAnnotationSelected)(e.annotationUID),(0,l.removeAnnotation)(e.annotationUID),void a?.render();const m=(0,l.getAnnotation)(s);m?(Object.assign(m.data,r.data),m.data.contour&&(m.data.contour.polyline=r.data.contour.pointsManager.points),r.data=n.data,m.invalidated=!0,(0,d.triggerAnnotationModified)(m,t,c.A.History)):console.warn("No current annotation")},id:s,operationType:"annotation"};return m.push(h),h}createMemo(t,e,n){this.memo||=p.createAnnotationMemo(t,e,n)}static hydrateBase(t,e,n,a={}){if(!e)return null;const{viewport:i}=e,s=i.getFrameOfReferenceUID(),r=i.getCamera(),l=a.viewplaneNormal??r.viewPlaneNormal,d=a.viewUp??r.viewUp,c=a.toolInstance||new t;let u,g=l,m=d;if(a.referencedImageId)u=a.referencedImageId,g=void 0,m=void 0;else if(i instanceof o.StackViewport){const t=o.utilities.getClosestStackImageIndexForPoint(n[0],i);void 0!==t&&(u=i.getImageIds()[t])}else{if(!(i instanceof o.BaseVolumeViewport))throw new Error("Unsupported viewport type");u=c.getReferencedImageId(i,n[0],l,d)}return{FrameOfReferenceUID:s,referencedImageId:u,viewPlaneNormal:g,viewUp:m,instance:c,viewport:i}}}p.toolName="AnnotationTool";const f=p},36320:(t,e,n)=>{n.d(e,{A:()=>A});var o=n(15327),a=n(99737),i=n(82056),s=n(17328),r=n(91350),l=n(72967),d=n(15451);class c extends r.A{constructor(t,e){super(t,e)}renderAnnotation(t,e){let n=!1;const{viewport:o}=t,{element:a}=o;if(!o.getRenderingEngine())return console.warn("Rendering Engine has been destroyed"),n;let s=(0,i.getAnnotations)(this.getToolName(),a);if(!s?.length)return n;if(s=this.filterInteractableAnnotationsForElement(a,s),!s?.length)return n;const r=this.getTargetId(o),l={toolGroupId:this.toolGroupId,toolName:this.getToolName(),viewportId:t.viewport.id};for(let o=0;o<s.length;o++){const a=s[o];l.annotationUID=a.annotationUID;const i=this.getAnnotationStyle({annotation:a,styleSpecifier:l});if(!i.visibility)continue;const d=this.renderAnnotationInstance({enabledElement:t,targetId:r,annotation:a,annotationStyle:i,svgDrawingHelper:e});n||=d,a.invalidated=!1}return n}createAnnotation(t){const e=super.createAnnotation(t);return Object.assign(e.data,{contour:{polyline:[],closed:!1}}),Object.assign(e,{interpolationUID:"",autoGenerated:!1}),e}addAnnotation(t,e){return(0,i.addAnnotation)(t,e)}cancelAnnotation(t){}moveAnnotation(t,e){const{points:n}=t.data.handles;for(let t=0,o=n.length;t<o;t++){const o=n[t];o[0]+=e[0],o[1]+=e[1],o[2]+=e[2]}t.invalidated=!0,(0,i.getChildAnnotations)(t).forEach((t=>this.moveAnnotation(t,e)))}updateContourPolyline(t,e,n,o){const a=this.configuration?.decimate||{};(0,l.A)(t,e,n,{decimate:{enabled:!!a.enabled,epsilon:a.epsilon},updateWindingDirection:o?.updateWindingDirection})}getPolylinePoints(t){return t.data.contour?.polyline??t.data.polyline}renderAnnotationInstance(t){const{enabledElement:e,annotationStyle:n,svgDrawingHelper:o}=t,a=t.annotation;if(a.parentAnnotationUID)return;const{annotationUID:i}=a,{viewport:r}=e,{worldToCanvas:l}=r,c=this.getPolylinePoints(a).map((t=>l(t))),{lineWidth:u,lineDash:g,color:m,fillColor:h,fillOpacity:p}=n,f=[c,...(0,d.A)(a,r)];return(0,s.drawPath)(o,i,"contourPolyline",f,{color:m,lineDash:g,lineWidth:Math.max(.1,u),fillColor:h,fillOpacity:p}),!0}}var u=n(49906),g=n(27740),m=n(64843),h=n(94779),p=n(77609),f=n(93210),v=n(67165),I=n(58859),C=n(60740),E=n(26795),D=n(86644);class A extends c{static{this.PreviewSegmentIndex=255}constructor(t,e){super(t,e),this.configuration.interpolation?.enabled&&g.A.addTool(this.getToolName())}isContourSegmentationTool(){return!0}createAnnotation(t){const e=t.detail,{element:n}=e,a=(0,o.getEnabledElement)(n);if(!a)return;const{viewport:i}=a,s=super.createAnnotation(t);if(!this.isContourSegmentationTool())return s;const r=(0,v.T)(i.id);if(!r)throw new Error("No active segmentation detected, create one before using scissors tool");if(!r.representationData.Contour)throw new Error("A contour segmentation must be active");const{segmentationId:l}=r,d=(0,C.Q)(l);return o.utilities.deepMerge(s,{data:{segmentation:{segmentationId:l,segmentIndex:d}}})}addAnnotation(t,e){const n=super.addAnnotation(t,e);if(this.isContourSegmentationTool()){const e=t;(0,m.addContourSegmentationAnnotation)(e)}return n}cancelAnnotation(t){this.isContourSegmentationTool()&&(0,m.removeContourSegmentationAnnotation)(t),super.cancelAnnotation(t)}getAnnotationStyle(t){const e=super.getAnnotationStyle(t);if(!this.isContourSegmentationTool())return e;const n=this._getContourSegmentationStyle(t);return o.utilities.deepMerge(e,n)}renderAnnotationInstance(t){const{annotation:e}=t,{invalidated:n}=e,o=super.renderAnnotationInstance(t);if(n&&this.isContourSegmentationTool()){const{segmentationId:t}=e.data.segmentation;(0,u.triggerSegmentationDataModified)(t);const n=(0,I.P)(t).map((t=>(0,p.getToolGroupForViewport)(t).id));(0,h._)(n)}return o}_getContourSegmentationStyle(t){const e=t.annotation,{segmentationId:n,segmentIndex:o}=e.data.segmentation,{viewportId:i}=t.styleSpecifier,s=(0,f.r$)(i,{segmentationId:n});if(!s?.length)return{};let r;r=s.length>1?s.find((t=>t.segmentationId===n&&t.type===a.SegmentationRepresentations.Contour)):s[0];const{autoGenerated:l}=e,d=(0,E.getLockedSegmentIndices)(n).includes(o),{color:c,fillColor:u,lineWidth:g,fillOpacity:m,lineDash:h,visibility:p}=(0,D.u)({segmentationId:n,segmentIndex:o,viewportId:i,autoGenerated:l});return{color:c,fillColor:u,lineWidth:g,fillOpacity:m,lineDash:h,textbox:{color:c},visibility:p,locked:d}}}},67772:(t,e,n)=>{n.d(e,{A:()=>a});const o={renderOutline:!0,outlineWidthAutoGenerated:3,outlineWidth:1,outlineWidthInactive:1,outlineOpacity:1,outlineOpacityInactive:.85,outlineDash:void 0,outlineDashInactive:void 0,outlineDashAutoGenerated:"5,3",activeSegmentOutlineWidthDelta:0,renderFill:!0,fillAlpha:.5,fillAlphaInactive:.3,fillAlphaAutoGenerated:.3};const a=function(){return o}},22384:(t,e,n)=>{n.d(e,{d:()=>d});var o=n(82056),a=n(15327),i=n(64485),s=n(64843);n(35056),n(74966),n(87275);var r=n(99737),l=n(92686);function d(t,e,n,d){n.size?t.render():function(t,e,n){const{segmentationId:d}=n,c=new Map;e.forEach((e=>{const n=a.cache.getGeometry(e);if(!n)return void console.warn(`No geometry found for geometryId ${e}. Skipping render.`);const u=n.data.segmentIndex;!function(t){if(!t)throw new Error(`No contours found for geometryId ${t.id}`);const e=t.id;if(t.type!==a.Enums.GeometryType.CONTOUR)throw new Error(`Geometry type ${t.type} not supported for rendering.`);t.data||console.warn(`No contours found for geometryId ${e}. Skipping render.`)}(n);const g=l.Y.getStyle({viewportId:t.id,segmentationId:d,type:r.SegmentationRepresentations.Contour,segmentIndex:u}),m=n.data,h=t.getCamera().viewPlaneNormal;m.contours.forEach((e=>{const{points:n,color:r,id:l}=e,c=(0,i.x)(t,n[0],h),g={annotationUID:a.utilities.uuidv4(),data:{contour:{closed:!0,polyline:n},segmentation:{segmentationId:d,segmentIndex:u,color:r,id:l},handles:{}},handles:{},highlighted:!1,autoGenerated:!1,invalidated:!1,isLocked:!0,isVisible:!0,metadata:{referencedImageId:c,toolName:"PlanarFreehandContourSegmentationTool",FrameOfReferenceUID:t.getFrameOfReferenceUID(),viewPlaneNormal:t.getCamera().viewPlaneNormal}},m=t.element;(0,o.addAnnotation)(g,m),(0,s.addContourSegmentationAnnotation)(g)})),g&&c.set(u,g)})),t.resetCamera(),t.render()}(t,e,d)}},87420:(t,e,n)=>{n.d(e,{A:()=>i});var o=n(33283),a=n(6802);const i=function(t,e,n=!1){const i=(0,o.T)(e),{annotationUIDsMap:s}=i.representationData.Contour;s.forEach((t=>{t.forEach((t=>{(0,a.O8)(t)}))}))}},63597:(t,e,n)=>{n.d(e,{A:()=>u});var o=n(15327),a=n(97577),i=n(33283),s=n(49906),r=n(99737);const l=new Map,d=({cfun:t,ofun:e,actor:n})=>{n.getProperty().setRGBTransferFunction(1,t),n.getProperty().setScalarOpacity(1,e)};const{uuidv4:c}=o.utilities;const u=async function(t,e,n,u){const g=(0,o.getEnabledElement)(t),{renderingEngine:m,viewport:h}=g,{id:p}=h;if(h instanceof o.BaseVolumeViewport){const t=function(t,e){let{volumeId:n}=t;if(!n){n=c();const o=(0,i.T)(e);o.representationData.Labelmap={...o.representationData.Labelmap,volumeId:n},t.volumeId=n,(0,s.triggerSegmentationModified)(e)}return n}(e,n);o.cache.getVolume(t)||await async function(t){const e=t;if(!(e.imageIds.length>0))throw new Error("cannot create labelmap, no imageIds found for the volume labelmap");const n=await o.volumeLoader.createAndCacheVolumeFromImages(t.volumeId||c(),e.imageIds);return n}(e);let a=u?.blendMode??o.Enums.BlendModes.MAXIMUM_INTENSITY_BLEND,g=a===o.Enums.BlendModes.LABELMAP_EDGE_PROJECTION_BLEND;if(g){const e=h.getVolumeId(),n=o.cache.getVolume(e),i=o.cache.getVolume(t).dimensions,s=n.dimensions;i[0]===s[0]&&i[1]===s[1]&&i[2]===s[2]||(g=!1,a=o.Enums.BlendModes.MAXIMUM_INTENSITY_BLEND,console.debug("Dimensions mismatch - falling back to regular volume addition"))}const f=[{volumeId:t,visibility:true,representationUID:`${n}-${r.SegmentationRepresentations.Labelmap}`,useIndependentComponents:g,blendMode:a}];if(f[0].useIndependentComponents){const t=await async function({viewport:t,volumeInputs:e,segmentationId:n}){const a=t.getDefaultActor(),{actor:s}=a,{uid:c,callback:u}=a,g=t.getVolumeId();if(l.get(c)?.added)return{uid:c,actor:s};const m=e,h=o.cache.getVolume(m[0].volumeId);if(!h)throw new Error(`imageVolume with id: ${h.volumeId} does not exist`);const{volumeId:p}=m[0],f=await o.volumeLoader.loadVolume(p);if(!f)throw new Error(`segImageVolume with id: ${f.volumeId} does not exist`);const v=f.voxelManager.getCompleteScalarDataArray(),{imageData:I}=f,C=o.cache.getVolume(g),E=C.voxelManager.getCompleteScalarDataArray(),D=new Float32Array(2*C.voxelManager.getScalarDataLength()),A=I.getDimensions();for(let t=0;t<A[2];++t)for(let e=0;e<A[1];++e)for(let n=0;n<A[0];++n){const o=n+A[0]*(e+A[1]*t);D[2*o+0]=E[o],D[2*o+1]=v[o]}t.removeActors([c]);const w=s.getMapper(),x=(0,o.convertMapperToNotSharedMapper)(w);s.setMapper(x),x.setBlendMode(o.Enums.BlendModes.LABELMAP_EDGE_PROJECTION_BLEND);const S=x.getInputData().getPointData().getArray(0);function b(e){const{segmentationId:n}=e.detail,{representationData:a}=(0,i.T)(n),{volumeId:s}=a.Labelmap;if(s!==f.volumeId)return;const r=o.cache.getVolume(s).voxelManager,l=x.getInputData(),d=l.getPointData().getArray(0),c=d.getData(),u=I.getDimensions(),g=Array.from({length:u[2]},((t,e)=>e));for(const t of g)for(let e=0;e<u[1];++e)for(let n=0;n<u[0];++n){const o=n+u[0]*(e+u[1]*t);c[2*o+1]=r.getAtIndex(o)}d.setData(c),l.modified(),t.render()}return S.setData(D),S.setNumberOfComponents(2),s.getProperty().setColorMixPreset(1),s.getProperty().setForceNearestInterpolation(1,!0),s.getProperty().setIndependentComponents(!0),t.addActor({actor:s,uid:c,callback:u,referencedId:g,representationUID:`${n}-${r.SegmentationRepresentations.Labelmap}`}),l.set(c,{added:!0,segmentationRepresentationUID:`${n}`,originalBlendMode:t.getBlendMode()}),s.set({preLoad:d}),o.eventTarget.addEventListenerDebounced(r.Events.SEGMENTATION_DATA_MODIFIED,b,200),o.eventTarget.addEventListener(r.Events.SEGMENTATION_REPRESENTATION_REMOVED,(async e=>{o.eventTarget.removeEventListener(r.Events.SEGMENTATION_DATA_MODIFIED,b);const n=t.getActor(c),{element:a,id:i}=t;t.removeActors([c]);const s=await(0,o.createVolumeActor)({volumeId:c,blendMode:o.Enums.BlendModes.MAXIMUM_INTENSITY_BLEND,callback:({volumeActor:t})=>{n.callback&&n.callback({volumeActor:t,volumeId:p})}},a,i);t.addActor({actor:s,uid:c}),t.render()})),{uid:c,actor:s}}({viewport:h,volumeInputs:f,segmentationId:n});return t}await(0,o.addVolumesToViewports)(m,f,[p],false,true)}else{const t=(0,a.aF)(h.id,n).map((t=>({imageId:t,representationUID:`${n}-${r.SegmentationRepresentations.Labelmap}-${t}`})));(0,o.addImageSlicesToViewports)(m,t,[p])}(0,s.triggerSegmentationDataModified)(n)}},53486:(t,e,n)=>{n.d(e,{A:()=>a});const o={renderOutline:!0,renderOutlineInactive:!0,outlineWidth:3,outlineWidthInactive:2,activeSegmentOutlineWidthDelta:0,renderFill:!0,renderFillInactive:!0,fillAlpha:.5,fillAlphaInactive:.4,outlineOpacity:1,outlineOpacityInactive:.85};const a=function(){return o}},88234:(t,e,n)=>{n.d(e,{A:()=>i});var o=n(15327),a=n(59452);const i=function(t,e){const n=(0,o.getEnabledElement)(t),{viewport:i}=n;i.removeActors([(0,a.Qe)(i.id,e)])}},18796:(t,e,n)=>{n.d(e,{A:()=>d});var o=n(15327),a=n(82409),i=n(7019),s=n(87275),r=n(35056),l=n(59452);const d=function(t,e,n){const d=(0,o.getEnabledElement)(t),{viewport:c}=d,u=(0,l.Th)(c.id,n,e.segmentIndex),g=u?.actor,m=e.visible;if(g){if(g.setVisibility(m),!m)return;const t=g.getMapper(),n=t.getInputData(),o=e.points,a=e.polys,i=n.getPoints().getData(),l=n.getPolys().getData();if(o.length===i.length&&a.length===l.length)return;const d=s.Ay.newInstance();d.getPoints().setData(o,3);const u=r.Ay.newInstance({values:Float32Array.from(a)});return d.setPolys(u),t.setInputData(d),t.modified(),void c.getRenderer().resetCameraClippingRange()}const h=e.points,p=e.polys,f=e.color,v=s.Ay.newInstance();v.getPoints().setData(h,3);const I=r.Ay.newInstance({values:Float32Array.from(p)});v.setPolys(I);const C=a.Ay.newInstance({});C.setInputData(v);const E=i.Ay.newInstance();E.setMapper(C),E.getProperty().setColor(f[0]/255,f[1]/255,f[2]/255),E.getProperty().setLineWidth(2);const D=(0,l.DU)(n,e.segmentIndex);c.addActor({uid:o.utilities.uuidv4(),actor:E,clippingFilter:undefined,representationUID:D}),c.resetCamera(),c.getRenderer().resetCameraClippingRange(),c.render()}},20552:(t,e,n)=>{n.d(e,{A:()=>a});var o=n(15327);const a=function(t,e){const n=(0,o.getEnabledElement)(t),{viewport:a}=n,i=a.getActors().filter((t=>t.representationUID&&"string"==typeof t.representationUID&&t.representationUID.startsWith(e)));a.removeActors(i.map((t=>t.uid)))}},55887:(t,e,n)=>{n.d(e,{A:()=>r});n(15327);var o=n(49906),a=n(11990),i=n(40905),s=n(99737);class r{static{this.COMPOSITIONS=a.A}static{this.childFunctions={[s.StrategyCallbacks.OnInteractionStart]:l(s.StrategyCallbacks.OnInteractionStart,s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.OnInteractionEnd]:l(s.StrategyCallbacks.OnInteractionEnd,s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.Fill]:l(s.StrategyCallbacks.Fill),[s.StrategyCallbacks.Initialize]:l(s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.CreateIsInThreshold]:d(s.StrategyCallbacks.CreateIsInThreshold),[s.StrategyCallbacks.Interpolate]:l(s.StrategyCallbacks.Interpolate,s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.AcceptPreview]:l(s.StrategyCallbacks.AcceptPreview,s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.RejectPreview]:l(s.StrategyCallbacks.RejectPreview,s.StrategyCallbacks.Initialize),[s.StrategyCallbacks.INTERNAL_setValue]:d(s.StrategyCallbacks.INTERNAL_setValue),[s.StrategyCallbacks.Preview]:d(s.StrategyCallbacks.Preview,!1),[s.StrategyCallbacks.ComputeInnerCircleRadius]:l(s.StrategyCallbacks.ComputeInnerCircleRadius),[s.StrategyCallbacks.EnsureSegmentationVolumeFor3DManipulation]:l(s.StrategyCallbacks.EnsureSegmentationVolumeFor3DManipulation),[s.StrategyCallbacks.EnsureImageVolumeFor3DManipulation]:l(s.StrategyCallbacks.EnsureImageVolumeFor3DManipulation),[s.StrategyCallbacks.AddPreview]:l(s.StrategyCallbacks.AddPreview),[s.StrategyCallbacks.GetStatistics]:d(s.StrategyCallbacks.GetStatistics),compositions:null}}constructor(t,...e){this._initialize=[],this._fill=[],this._onInteractionStart=[],this.fill=(t,e)=>{const n=this.initialize(t,e,s.StrategyCallbacks.Fill);if(!n)return;this._fill.forEach((t=>t(n)));const{segmentationVoxelManager:a,segmentIndex:i}=n;return(0,o.triggerSegmentationDataModified)(n.segmentationId,a.getArrayOfModifiedSlices(),i),n},this.onInteractionStart=(t,e)=>{const n=this.initialize(t,e);n&&this._onInteractionStart.forEach((t=>t.call(this,n)))},this.addPreview=(t,e)=>{const n=this.initialize(t,e,s.StrategyCallbacks.AddPreview);if(n)return n},this.configurationName=t,this.compositions=e,e.forEach((t=>{const e="function"==typeof t?t():t;if(e)for(const t in e){if(!r.childFunctions[t])throw new Error(`Didn't find ${t} as a brush strategy`);r.childFunctions[t](this,e[t])}})),this.strategyFunction=(t,e)=>this.fill(t,e);for(const t of Object.keys(r.childFunctions))this.strategyFunction[t]=this[t]}initialize(t,e,n){const{viewport:o}=t,a=(0,i.S)({operationData:e,viewport:o,strategy:this});if(!a)return null;const{imageVoxelManager:s,segmentationVoxelManager:r,segmentationImageData:l}=a,d=e.createMemo(e.segmentationId,r),c={operationName:n,...e,segmentIndex:e.segmentIndex,enabledElement:t,imageVoxelManager:s,segmentationVoxelManager:r,segmentationImageData:l,viewport:o,centerWorld:null,isInObject:null,isInObjectBoundsIJK:null,brushStrategy:this,memo:d};return this._initialize.forEach((t=>t(c))),c}}function l(t,e){const n=`_${t}`;return(o,a)=>{o[n]||=[],o[