forked from chafey/cornerstoneDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cornerstoneTools.min.js
2 lines (2 loc) · 29.6 KB
/
cornerstoneTools.min.js
1
2
/*! cornerstoneTools - v0.2.2 - 2014-05-08 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstoneTools */
var cornerstoneTools=function(a,b,c){"use strict";function d(a){if(!("mousewheel"===a.originalEvent.type&&0===a.originalEvent.wheelDeltaY||"DOMMouseScroll"===a.originalEvent.type&&1===a.originalEvent.axis)){var c=a.currentTarget,d=b.pageToPixel(c,a.pageX,a.pageY);a=window.event||a;var e=a.wheelDelta||-a.detail||-a.originalEvent.detail,f=Math.max(-1,Math.min(1,e)),g=({element:c,viewport:b.getViewport(c),image:b.getEnabledElement(c).image,direction:f,pageX:a.pageX,pageY:a.pageY,imageX:d.x,imageY:d.y},new CustomEvent("CornerstoneToolsMouseWheel",{detail:{event:a,direction:f,viewport:b.getViewport(c),image:b.getEnabledElement(c).image,element:c},bubbles:!1,cancelable:!1}));c.dispatchEvent(g)}}function e(b){a(b).on(g,d)}function f(b){a(b).unbind(g,d)}void 0===c&&(c={});var g="mousewheel DOMMouseScroll";return c.mouseWheelInput={enable:e,disable:f},c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a){var b=new CustomEvent("CornerstoneToolsMouseDownActivate",{detail:a,bubbles:!1,cancelable:!0});a.element.dispatchEvent(b)}function f(f){function g(a){var e={page:c.point.pageToPoint(a),image:b.pageToPixel(i,a.pageX,a.pageY)},f={page:c.point.subtract(e.page,k.page),image:c.point.subtract(e.image,k.image)},g=new CustomEvent("CornerstoneToolsMouseDrag",{detail:{event:a,which:n,viewport:b.getViewport(i),image:b.getEnabledElement(i).image,element:i,startPoints:j,lastPoints:k,currentPoints:e,deltaPoints:f},bubbles:!1,cancelable:!0});return i.dispatchEvent(g),k=d.copyPoints(e),d.pauseEvent(a)}function h(d){var e={page:c.point.pageToPoint(d),image:b.pageToPixel(i,d.pageX,d.pageY)},f={page:c.point.subtract(e.page,k.page),image:c.point.subtract(e.image,k.image)},l=new CustomEvent("CornerstoneToolsMouseUp",{detail:{event:d,which:n,viewport:b.getViewport(i),image:b.getEnabledElement(i).image,element:i,startPoints:j,lastPoints:k,currentPoints:e,deltaPoints:f},bubbles:!1,cancelable:!1});i.dispatchEvent(l),a(document).off("mousemove",g),a(document).off("mouseup",h)}var i=(f.data,f.currentTarget),j={page:c.point.pageToPoint(f),image:b.pageToPixel(i,f.pageX,f.pageY)},k=d.copyPoints(j),l={event:f,which:f.which,viewport:b.getViewport(i),image:b.getEnabledElement(i).image,element:i,startPoints:j,lastPoints:k,currentPoints:j,deltaPoints:{x:0,y:0}},m=new CustomEvent("CornerstoneToolsMouseDown",{detail:l,bubbles:!1,cancelable:!0});if(i.dispatchEvent(m)===!0&&e(l)===!0)return d.pauseEvent(f);var n=f.which;return a(document).on("mousemove",g),a(document).on("mouseup",h),d.pauseEvent(f)}function g(a){var e=(a.data,a.currentTarget),f={page:c.point.pageToPoint(a),image:b.pageToPixel(e,a.pageX,a.pageY)},g=d.copyPoints(f),h=a.which,i={page:c.point.pageToPoint(a),image:b.pageToPixel(e,a.pageX,a.pageY)},j={page:c.point.subtract(i.page,g.page),image:c.point.subtract(i.image,g.image)},k=new CustomEvent("CornerstoneToolsMouseMove",{detail:{event:a,which:h,viewport:b.getViewport(e),image:b.getEnabledElement(e).image,element:e,startPoints:f,lastPoints:g,currentPoints:i,deltaPoints:j},bubbles:!1,cancelable:!1});e.dispatchEvent(k),g=d.copyPoints(i)}function h(b){a(b).on("mousedown",f),a(b).on("mousemove",g)}function i(b){a(b).off("mousedown",f),a(b).off("mousemove",g)}return void 0===d&&(d={}),d.mouseInput={enable:h,disable:i},d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c={activate:function(c,d){a(c).off("CornerstoneToolsMouseDownActivate",b);var e={mouseButtonMask:d};a(c).on("CornerstoneToolsMouseDownActivate",e,b)},disable:function(c){a(c).off("CornerstoneToolsMouseDownActivate",b)},enable:function(c){a(c).off("CornerstoneToolsMouseDownActivate",b)},deactivate:function(c){a(c).off("CornerstoneToolsMouseDownActivate",b)}};return c}return void 0===c&&(c={}),c.simpleMouseButtonTool=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(e){function f(b){var c=e.createNewMeasurement(b);d.addToolState(b.element,e.toolType,c),a(b.element).off("CornerstoneToolsMouseMove",h),d.moveHandle(b,c.handles.end,function(){d.anyHandlesOutsideImage(b,c.handles)&&d.removeToolState(b.element,e.toolType,c),a(b.element).on("CornerstoneToolsMouseMove",h)})}function g(a){var b=a.originalEvent.detail,c=a.data;return d.isMouseButtonEnabled(b.which,c.mouseButtonMask)?(f(b),!1):void 0}function h(a){var c=a.originalEvent.detail;if(0===c.which){var f=d.getToolState(c.element,e.toolType);if(void 0!==f){for(var g=!1,h=0;h<f.data.length;h++){var i=f.data[h];d.handleActivator(i.handles,c.currentPoints.image,c.viewport.scale)===!0&&(g=!0)}g===!0&&b.updateImage(c.element)}}}function i(a,b){for(var d in a.handles){var e=c.point.distanceSquared(a.handles[d],b);if(25>e)return a.handles[d]}}function j(b){function c(){d.anyHandlesOutsideImage(j,f.handles)&&d.removeToolState(j.element,e.toolType,f),a(j.element).on("CornerstoneToolsMouseMove",h)}var f,g=b.data,j=b.originalEvent.detail;if(d.isMouseButtonEnabled(j.which,g.mouseButtonMask)){var k,l=j.startPoints.image,m=d.getToolState(b.currentTarget,e.toolType);if(void 0!==m)for(k=0;k<m.data.length;k++){f=m.data[k];var n=i(f,l);if(void 0!==n)return a(j.element).off("CornerstoneToolsMouseMove",h),d.moveHandle(j,n,c),!1}if(void 0!==m&&void 0!==e.pointNearTool)for(k=0;k<m.data.length;k++)if(f=m.data[k],e.pointNearTool(f,l))return a(j.element).off("CornerstoneToolsMouseMove",h),d.moveAllHandles(b,f,m,!0),!1}}function k(c){a(c).off("CornerstoneImageRendered",e.onImageRendered),a(c).off("CornerstoneToolsMouseMove",h),a(c).off("CornerstoneToolsMouseDown",j),a(c).off("CornerstoneToolsMouseDownActivate",g),b.updateImage(c)}function l(c){a(c).off("CornerstoneImageRendered",e.onImageRendered),a(c).off("CornerstoneToolsMouseMove",h),a(c).off("CornerstoneToolsMouseDown",j),a(c).off("CornerstoneToolsMouseDownActivate",g),a(c).on("CornerstoneImageRendered",e.onImageRendered),b.updateImage(c)}function m(c,d){var f={mouseButtonMask:d};a(c).off("CornerstoneImageRendered",e.onImageRendered),a(c).off("CornerstoneToolsMouseMove",h),a(c).off("CornerstoneToolsMouseDown",j),a(c).off("CornerstoneToolsMouseDownActivate",g),a(c).on("CornerstoneImageRendered",e.onImageRendered),a(c).on("CornerstoneToolsMouseMove",f,h),a(c).on("CornerstoneToolsMouseDown",f,j),a(c).on("CornerstoneToolsMouseDownActivate",f,g),b.updateImage(c)}function n(c,d){var f={mouseButtonMask:d};a(c).off("CornerstoneImageRendered",e.onImageRendered),a(c).off("CornerstoneToolsMouseMove",h),a(c).off("CornerstoneToolsMouseDown",j),a(c).off("CornerstoneToolsMouseDownActivate",g),a(c).on("CornerstoneImageRendered",e.onImageRendered),a(c).on("CornerstoneToolsMouseMove",f,h),a(c).on("CornerstoneToolsMouseDown",f,j),b.updateImage(c)}var o={enable:l,disable:k,activate:m,deactivate:n};return o}return void 0===d&&(d={}),d.mouseButtonTool=e,d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c={activate:function(c){a(c).off("CornerstoneToolsMouseWheel",b);var d={};a(c).on("CornerstoneToolsMouseWheel",d,b)},disable:function(c){a(c).off("CornerstoneToolsMouseWheel",b)},enable:function(c){a(c).off("CornerstoneToolsMouseWheel",b)},deactivate:function(c){a(c).off("CornerstoneToolsMouseWheel",b)}};return c}return void 0===c&&(c={}),c.mouseWheelTool=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c={activate:function(c){a(c).off("CornerstoneToolsTouchDrag",b);var d={};a(c).on("CornerstoneToolsTouchDrag",d,b)},disable:function(c){a(c).off("CornerstoneToolsTouchDrag",b)},enable:function(c){a(c).off("CornerstoneToolsTouchDrag",b)},deactivate:function(c){a(c).off("CornerstoneToolsTouchDrag",b)}};return c}return void 0===c&&(c={}),c.touchDragTool=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c={activate:function(c){a(c).off("CornerstoneToolsTouchPinch",b);var d={};a(c).on("CornerstoneToolsTouchPinch",d,b)},disable:function(c){a(c).off("CornerstoneToolsTouchPinch",b)},enable:function(c){a(c).off("CornerstoneToolsTouchPinch",b)},deactivate:function(c){a(c).off("CornerstoneToolsTouchPinch",b)}};return c}return void 0===c&&(c={}),c.touchPinchTool=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a){var b={visible:!0,handles:{start:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!1},end:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!0}}};return b}function f(a,b){var d={left:Math.min(a.handles.start.x,a.handles.end.x),top:Math.min(a.handles.start.y,a.handles.end.y),width:Math.abs(a.handles.start.x-a.handles.end.x),height:Math.abs(a.handles.start.y-a.handles.end.y)},e=c.rect.distanceToPoint(d,b);return 5>e}function g(a,b){var c=a.width/2,d=a.height/2;if(0>=c||0>=d)return!1;var e={x:a.left+c,y:a.top+d},f={x:b.x-e.x,y:b.y-e.y},g=f.x*f.y/(c*c)+f.y*f.y/(d*d)<=1;return g}function h(a,b){for(var c=0,d=0,e=0,f=0,h=b.top;h<b.top+b.height;h++)for(var i=b.left;i<b.left+b.width;i++)g(b,{x:i,y:h})===!0&&(c+=a[f],d+=a[f]*a[f],e++),f++;if(0===e)return{count:e,mean:0,variance:0,stdDev:0};var j=c/e,k=d/e-j*j;return{count:e,mean:j,variance:k,stdDev:Math.sqrt(k)}}function i(a){var c=d.getToolState(a.currentTarget,j);if(void 0!==c){var e=a.originalEvent.detail,f=e.canvasContext.canvas.getContext("2d");b.setToPixelCoordinateSystem(e.enabledElement,f);for(var g=0;g<c.data.length;g++){f.save();var i=c.data[g],k=Math.abs(i.handles.start.x-i.handles.end.x),l=Math.abs(i.handles.start.y-i.handles.end.y),m=Math.min(i.handles.start.x,i.handles.end.x),n=Math.min(i.handles.start.y,i.handles.end.y),o=(i.handles.start.x+i.handles.end.x)/2,p=(i.handles.start.y+i.handles.end.y)/2;f.beginPath(),f.strokeStyle="white",f.lineWidth=1/e.viewport.scale,d.drawEllipse(f,m,n,k,l),f.closePath(),f.beginPath(),d.drawHandles(f,e,i.handles),f.stroke();var q=b.getStoredPixels(e.element,m,n,k,l),r={left:m,top:n,width:k,height:l},s=h(q,r),t=Math.PI*(k*e.image.columnPixelSpacing/2)*(l*e.image.rowPixelSpacing/2),u="Area: "+t.toFixed(2)+" mm^2",v=d.setContextToDisplayFontSize(e.enabledElement,e.canvasContext,15);f.font=""+v.fontSize+"px Arial";var w=f.measureText(t),x=v.lineHeight,y=o<e.image.columns/2?o+k/2:o-k/2-w.width*v.fontScale,z=p<e.image.rows/2?p+l/2:p-l/2;y/=v.fontScale,z/=v.fontScale,f.fillStyle="white",f.fillText("Mean: "+s.mean.toFixed(2),y,z-x),f.fillText("StdDev: "+s.stdDev.toFixed(2),y,z),f.fillText(u,y,z+x),f.restore()}}}void 0===d&&(d={});var j="ellipticalRoi";return d.ellipticalRoi=d.mouseButtonTool({createNewMeasurement:e,onImageRendered:i,pointNearTool:f,toolType:j}),d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a){var b={visible:!0,handles:{start:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!1},end:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!0}}};return b}function f(a,b){var d={start:a.handles.start,end:a.handles.end},e=c.lineSegment.distanceToPoint(d,b);return 5>e}function g(a){var c=d.getToolState(a.currentTarget,h);if(void 0!==c){var e=a.originalEvent.detail,f=e.canvasContext.canvas.getContext("2d");b.setToPixelCoordinateSystem(e.enabledElement,f);for(var g=0;g<c.data.length;g++){f.save();var i=c.data[g];f.beginPath(),f.strokeStyle="white",f.lineWidth=1/e.viewport.scale,f.moveTo(i.handles.start.x,i.handles.start.y),f.lineTo(i.handles.end.x,i.handles.end.y),f.stroke(),f.beginPath(),d.drawHandles(f,e,i.handles),f.stroke(),f.fillStyle="white";var j=i.handles.start.x-i.handles.end.x*e.image.columnPixelSpacing,k=i.handles.start.y-i.handles.end.y*e.image.rowPixelSpacing,l=Math.sqrt(j*j+k*k),m=""+l.toFixed(2)+" mm",n=d.setContextToDisplayFontSize(e.enabledElement,e.canvasContext,15);f.font=""+n.fontSize+"px Arial";var o=(i.handles.start.x+i.handles.end.x)/2/n.fontScale,p=(i.handles.start.y+i.handles.end.y)/2/n.fontScale;f.fillText(m,o,p),f.restore()}}}void 0===d&&(d={});var h="length";return d.length=d.mouseButtonTool({createNewMeasurement:e,onImageRendered:g,pointNearTool:f,toolType:h}),d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c=b.originalEvent.detail;a(c.element).off("CornerstoneToolsMouseDrag",f),a(c.element).off("CornerstoneToolsMouseUp",d)}function e(b){var e=b.originalEvent.detail;return c.isMouseButtonEnabled(e.which,b.data.mouseButtonMask)?(a(e.element).on("CornerstoneToolsMouseDrag",f),a(e.element).on("CornerstoneToolsMouseUp",d),!1):void 0}function f(a){var c=a.originalEvent.detail;return c.viewport.translation.x+=c.deltaPoints.page.x/c.viewport.scale,c.viewport.translation.y+=c.deltaPoints.page.y/c.viewport.scale,b.setViewport(c.element,c.viewport),!1}function g(a){var c=a.originalEvent.detail;return c.viewport.translation.x+=c.deltaPoints.page.x/c.viewport.scale,c.viewport.translation.y+=c.deltaPoints.page.y/c.viewport.scale,b.setViewport(c.element,c.viewport),!1}return void 0===c&&(c={}),c.pan=c.simpleMouseButtonTool(e),c.panTouchDrag=c.touchDragTool(g),c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a){var b={visible:!0,handles:{end:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!0}}};return b}function e(a){var d=c.getToolState(a.currentTarget,f);if(void 0!==d){var e=a.originalEvent.detail,g=e.canvasContext.canvas.getContext("2d");b.setToPixelCoordinateSystem(e.enabledElement,g);for(var h=0;h<d.data.length;h++){g.save();var i=d.data[h];g.beginPath(),c.drawHandles(g,e,i.handles),g.stroke();var j=c.setContextToDisplayFontSize(e.enabledElement,e.canvasContext,15);g.font=""+j.fontSize+"px Arial";var k=Math.round(i.handles.end.x),l=Math.round(i.handles.end.y);m=i.handles.end.x+3,n=i.handles.end.y-3;var m=m/j.fontScale,n=n/j.fontScale;g.fillStyle="white";var o=b.getStoredPixels(e.element,k,l,1,1),p=o[0],q=p*e.image.slope+e.image.intercept;g.fillText(""+k+","+l,m,n),g.fillText("SP: "+p+" MO: "+q,m,n+j.lineHeight),g.restore()}}}void 0===c&&(c={});var f="probe";return c.probe=c.mouseButtonTool({createNewMeasurement:d,onImageRendered:e,toolType:f}),c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a){var b={visible:!0,handles:{start:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!1},end:{x:a.currentPoints.image.x,y:a.currentPoints.image.y,highlight:!0,active:!0}}};return b}function f(a,b){var d={left:Math.min(a.handles.start.x,a.handles.end.x),top:Math.min(a.handles.start.y,a.handles.end.y),width:Math.abs(a.handles.start.x-a.handles.end.x),height:Math.abs(a.handles.start.y-a.handles.end.y)},e=c.rect.distanceToPoint(d,b);return 5>e}function g(a,b){for(var c=0,d=0,e=0,f=0,g=b.top;g<b.top+b.height;g++)for(var h=b.left;h<b.left+b.width;h++)c+=a[f],d+=a[f]*a[f],e++,f++;if(0===e)return{count:e,mean:0,variance:0,stdDev:0};var i=c/e,j=d/e-i*i;return{count:e,mean:i,variance:j,stdDev:Math.sqrt(j)}}function h(a){var c=d.getToolState(a.currentTarget,i);if(void 0!==c){var e=a.originalEvent.detail,f=e.canvasContext.canvas.getContext("2d");b.setToPixelCoordinateSystem(e.enabledElement,f);for(var h=0;h<c.data.length;h++){f.save();var j=c.data[h],k=Math.abs(j.handles.start.x-j.handles.end.x),l=Math.abs(j.handles.start.y-j.handles.end.y),m=Math.min(j.handles.start.x,j.handles.end.x),n=Math.min(j.handles.start.y,j.handles.end.y),o=(j.handles.start.x+j.handles.end.x)/2,p=(j.handles.start.y+j.handles.end.y)/2;f.beginPath(),f.strokeStyle="white",f.lineWidth=1/e.viewport.scale,f.rect(m,n,k,l),f.stroke(),f.beginPath(),d.drawHandles(f,e,j.handles),f.stroke();var q=b.getStoredPixels(e.element,m,n,k,l),r={left:m,top:n,width:k,height:l},s=g(q,r),t=k*e.image.columnPixelSpacing*l*e.image.rowPixelSpacing,u="Area: "+t.toFixed(2)+" mm^2",v=d.setContextToDisplayFontSize(e.enabledElement,e.canvasContext,15);f.font=""+v.fontSize+"px Arial";var w=f.measureText(t),x=v.lineHeight,y=o<e.image.columns/2?o+k/2:o-k/2-w.width*v.fontScale,z=p<e.image.rows/2?p+l/2:p-l/2;y/=v.fontScale,z/=v.fontScale,f.fillStyle="white",f.fillText("Mean: "+s.mean.toFixed(2),y,z-x),f.fillText("StdDev: "+s.stdDev.toFixed(2),y,z),f.fillText(u,y,z+x),f.restore()}}}void 0===d&&(d={});var i="rectangleRoi";return d.rectangleRoi=d.mouseButtonTool({createNewMeasurement:e,onImageRendered:h,pointNearTool:f,toolType:i}),d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(b){var c=b.originalEvent.detail;a(c.element).off("CornerstoneToolsMouseDrag",f),a(c.element).off("CornerstoneToolsMouseUp",d)}function e(b){var e=b.originalEvent.detail;return c.isMouseButtonEnabled(e.which,b.data.mouseButtonMask)?(a(e.element).on("CornerstoneToolsMouseDrag",f),a(e.element).on("CornerstoneToolsMouseUp",d),!1):void 0}function f(a){var c=a.originalEvent.detail,d=c.image.maxPixelValue-c.image.minPixelValue,e=d/1024;return c.viewport.voi.windowWidth+=c.deltaPoints.page.x*e,c.viewport.voi.windowCenter+=c.deltaPoints.page.y*e,b.setViewport(c.element,c.viewport),!1}function g(a){var c=a.originalEvent.detail,d=c.image.maxPixelValue-c.image.minPixelValue,e=d/1024;c.viewport.voi.windowWidth+=c.deltaPoints.page.x*e,c.viewport.voi.windowCenter+=c.deltaPoints.page.y*e,b.setViewport(c.element,c.viewport)}return void 0===c&&(c={}),c.wwwc=c.simpleMouseButtonTool(e),c.wwwcTouchDrag=c.touchDragTool(g),c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,c,d){var e=1.7,f=Math.log(c.scale)/Math.log(e),g=f+d,h=Math.pow(e,g);c.scale=h,b.setViewport(a,c)}function e(b){var c=b.originalEvent.detail;a(c.element).off("CornerstoneToolsMouseDrag",g),a(c.element).off("CornerstoneToolsMouseUp",e)}function f(b){var d=b.originalEvent.detail;return c.isMouseButtonEnabled(d.which,b.data.mouseButtonMask)?(a(d.element).on("CornerstoneToolsMouseDrag",g),a(d.element).on("CornerstoneToolsMouseUp",e),!1):void 0}function g(a){var c=a.originalEvent.detail,e=c.deltaPoints.page.y/100;d(c.element,c.viewport,e);var f=b.pageToPixel(c.element,c.startPoints.page.x,c.startPoints.page.y);return c.viewport.translation.x-=c.startPoints.image.x-f.x,c.viewport.translation.y-=c.startPoints.image.y-f.y,b.setViewport(c.element,c.viewport),!1}function h(a){var b=a.originalEvent.detail,c=-b.direction/4;d(b.element,b.viewport,c)}function i(a){var b=a.originalEvent.detail;d(b.element,b.viewport,b.direction/4)}function j(a){var c=a.originalEvent.detail,e=c.deltaPoints.page.y/100;d(c.element,c.viewport,e);var f=b.pageToPixel(c.element,c.startPoints.page.x,c.startPoints.page.y);return c.viewport.translation.x-=c.startPoints.image.x-f.x,c.viewport.translation.y-=c.startPoints.image.y-f.y,b.setViewport(c.element,c.viewport),!1}return void 0===c&&(c={}),c.zoom=c.simpleMouseButtonTool(f),c.zoomWheel=c.mouseWheelTool(h),c.zoomTouchPinch=c.touchPinchTool(i),c.zoomTouchDrag=c.touchDragTool(j),c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(e){if(e.gesture.preventDefault(),e.gesture.stopPropagation(),k!==!0){var f,g=e.currentTarget;if("transform"===e.type){var l=j-e.gesture.scale;j=e.gesture.scale,f=new CustomEvent("CornerstoneToolsTouchPinch",{detail:{event:e,viewport:b.getViewport(g),image:b.getEnabledElement(g).image,element:g,direction:0>l?1:-1},bubbles:!1,cancelable:!1})}else{if("dragstart"===e.type)return h={page:c.point.pageToPoint(e.gesture.touches[0]),image:b.pageToPixel(g,e.gesture.touches[0].pageX,e.gesture.touches[0].pageY)},void(i=d.copyPoints(h));if("drag"!==e.type)return;var m={page:c.point.pageToPoint(e.gesture.touches[0]),image:b.pageToPixel(g,e.gesture.touches[0].pageX,e.gesture.touches[0].pageY)},n={page:c.point.subtract(m.page,i.page),image:c.point.subtract(m.image,i.image)};f=new CustomEvent("CornerstoneToolsTouchDrag",{detail:{event:e,viewport:b.getViewport(g),image:b.getEnabledElement(g).image,element:g,startPoints:h,lastPoints:i,currentPoints:m,deltaPoints:n},bubbles:!1,cancelable:!1}),i=a.extend({},m)}k=!0,setTimeout(function(){g.dispatchEvent(f),k=!1},1)}}function f(b){var c={transform_always_block:!0,transform_min_scale:.01,drag_block_horizontal:!0,drag_block_vertical:!0,drag_min_distance:0};a(b).hammer(c).on("touch drag transform dragstart",e)}function g(b){a(b).hammer().off("touch drag transform dragstart",e)}void 0===d&&(d={});var h,i,j=1,k=!1;return d.touchInput={enable:f,disable:g},d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a,b){var d=a.image,e={left:0,top:0,width:d.width,height:d.height},f=!1;for(var g in b){var h=b[g];c.point.insideRect(h,e)===!1&&(f=!0)}return f}return void 0===d&&(d={}),d.anyHandlesOutsideImage=e,d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,b,c){a.strokeStyle="white";var d=e/b.viewport.scale;for(var f in c){var g=c[f];(g.active||g.highlight)&&(a.beginPath(),a.lineWidth=g.active?2/b.viewport.scale:.5/b.viewport.scale,a.arc(g.x,g.y,d,0,2*Math.PI),a.stroke())}}void 0===c&&(c={});var e=6;return c.drawHandles=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a,b,d){var e=h/d;for(var f in a){var g=a[f],i=c.point.distance(b,g);if(e>=i)return g}return void 0}function f(a){for(var b in a){var c=a[b];if(c.active===!0)return c}return void 0}function g(a,b,c){var d=f(a),g=e(a,b,c);return d!==g?(void 0!==g&&(g.active=!0),void 0!==d&&(d.active=!1),!0):!1}void 0===d&&(d={});var h=6;return d.handleActivator=g,d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(c,d,e){function f(a){var c=a.originalEvent.detail;d.x=c.currentPoints.image.x,d.y=c.currentPoints.image.y,b.updateImage(h)}function g(){d.eactive=!1,a(h).off("CornerstoneToolsMouseDrag",f),a(h).off("CornerstoneToolsMouseUp",g),b.updateImage(h),e()}var h=c.element;a(h).on("CornerstoneToolsMouseDrag",f),a(h).on("CornerstoneToolsMouseUp",g)}return void 0===c&&(c={}),c.moveHandle=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(d,e,f,g){function h(a){var c=a.originalEvent.detail;for(var d in e.handles){var f=e.handles[d];f.x+=c.deltaPoints.image.x,f.y+=c.deltaPoints.image.y}return b.updateImage(k),!1}function i(d){e.moving=!1;var j=d.originalEvent.detail;if(a(k).off("CornerstoneToolsMouseDrag",h),a(k).off("CornerstoneToolsMouseUp",i),g===!0){var l=j.image,m=!1,n={top:0,left:0,width:l.width,height:l.height};for(var o in e.handles){var p=e.handles[o];c.point.insideRect(p,n)===!1&&(m=!0)}if(m){for(var q=-1,r=0;r<f.data.length;r++)f.data[r]===e&&(q=r);-1!==q&&f.data.splice(q,1)}}b.updateImage(k)}var j=d.originalEvent.detail,k=j.element;return a(k).on("CornerstoneToolsMouseDrag",h),a(k).on("CornerstoneToolsMouseUp",i),!0}return void 0===d&&(d={}),d.moveAllHandles=e,d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,d){if(void 0===a)throw"playClip: element must not be undefined";void 0===d&&(d=30);var e=c.getToolState(a,"stack");if(void 0!==e&&void 0!==e.data&&0!==e.data.length){var g,h=e.data[0],i=c.getToolState(a,f);void 0===i||0===i.data.length?(g={intervalId:void 0,framesPerSecond:d,lastFrameTimeStamp:void 0,frameRate:0},c.addToolState(a,f,g)):(g=i.data[0],g.framesPerSecond=d),g.intervalId=setInterval(function(){var c=h.currentImageIdIndex;if(g.framesPerSecond>0?c++:c--,c>=h.imageIds.length&&(c=0),0>c&&(c=h.imageIds.length-1),c!==h.currentImageIdIndex){var d=b.getViewport(a);b.loadAndCacheImage(h.imageIds[c]).then(function(e){h.currentImageIdIndex=c,b.displayImage(a,e,d)})}},1e3/Math.abs(g.framesPerSecond))}}function e(a){var b,d=c.getToolState(a,f);void 0!==d&&0!==d.data.length&&(b=d.data[0],clearInterval(b.intervalId),b.intervalId=void 0)}void 0===c&&(c={});var f="playClip";return c.playClip=d,c.stopClip=e,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a){var e=c.getToolState(a,"stack");if(void 0!==e&&void 0!==e.data&&0!==e.data.length){var f=c.getToolState(a,g);if(void 0!==f){var h=f.data[0],i=e.data[0],j=h.prefetchImageIdIndex+1;if(j=Math.min(i.imageIds.length-1,j),j=Math.max(0,j),j===h.prefetchImageIdIndex)return void(h.enabled=!1);h.prefetchImageIdIndex=j;var k=i.imageIds[j],l=b.loadAndCacheImage(k);l.done(function(){setTimeout(function(){d(a)},1)})}}}function e(a){var b=c.getToolState(a,g);void 0===b&&(b={prefetchImageIdIndex:0,enabled:!0},c.addToolState(a,g,b)),d(a)}function f(a){var b=c.getToolState(a,g);void 0===b?(b={prefetchImageIdIndex:0,enabled:!1},c.addToolState(a,g,b)):b.enabled=!1}void 0===c&&(c={});var g="stackPrefetch";return c.stackPrefetch={enable:e,disable:f},c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,d){var e=c.getToolState(a,"stack");if(void 0!==e&&void 0!==e.data&&0!==e.data.length){var f=e.data[0],g=f.currentImageIdIndex+d;if(g=Math.min(f.imageIds.length-1,g),g=Math.max(0,g),g!==f.currentImageIdIndex){var h=b.getViewport(a);b.loadAndCacheImage(f.imageIds[g]).then(function(c){f.currentImageIdIndex=g,b.displayImage(a,c,h)})}}}function e(b){var c=b.originalEvent.detail;a(c.element).off("CornerstoneToolsMouseDrag",g),a(c.element).off("CornerstoneToolsMouseUp",e)}function f(b){var d=b.originalEvent.detail;if(c.isMouseButtonEnabled(d.which,b.data.mouseButtonMask)){var f={deltaY:0};return a(d.element).on("CornerstoneToolsMouseDrag",f,g),a(d.element).on("CornerstoneToolsMouseUp",e),!1}}function g(a){var d=a.originalEvent.detail,e=a.data;e.deltaY+=d.deltaPoints.page.y;var f=c.getToolState(d.element,"stack");if(void 0!==f&&void 0!==f.data&&0!==f.data.length){var g=f.data[0];if(e.deltaY>=3||e.deltaY<=-3){var h=e.deltaY/3,i=e.deltaY%3,j=Math.round(h);e.deltaY=i;var k=g.currentImageIdIndex+j;if(k=Math.min(g.imageIds.length-1,k),k=Math.max(0,k),k!==g.currentImageIdIndex){g.currentImageIdIndex=k;var l=b.getViewport(d.element);b.loadAndCacheImage(g.imageIds[k]).then(function(a){b.displayImage(d.element,a,l)})}}return!1}}function h(a){var b=a.originalEvent.detail,c=-b.direction;d(b.element,c)}function i(a){var d=a.originalEvent.detail,e={deltaY:0};e.deltaY+=d.deltaPoints.page.y;var f=c.getToolState(d.element,"stack");if(void 0!==f&&void 0!==f.data&&0!==f.data.length){var g=f.data[0];if(e.deltaY>=3||e.deltaY<=-3){var h=e.deltaY/3,i=e.deltaY%3,j=Math.round(h);e.deltaY=i;var k=g.currentImageIdIndex+j;if(k=Math.min(g.imageIds.length-1,k),k=Math.max(0,k),k!==g.currentImageIdIndex){g.currentImageIdIndex=k;var l=b.getViewport(d.element);b.loadAndCacheImage(g.imageIds[k]).then(function(a){b.displayImage(d.element,a,l)})}}return!1}}void 0===c&&(c={});return c.stackScroll=c.simpleMouseButtonTool(f),c.stackScrollWheel=c.mouseWheelTool(h),c.stackScrollTouchDrag=c.touchDragTool(i),c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(){function a(a,c,e){var f=b.getEnabledElement(a);d.hasOwnProperty(f.image.imageId)===!1&&(d[f.image.imageId]={});var g=d[f.image.imageId];g.hasOwnProperty(c)===!1&&(g[c]={data:[]});var h=g[c];h.data.push(e)}function c(a,c){var e=b.getEnabledElement(a);if(d.hasOwnProperty(e.image.imageId)===!1)return void 0;var f=d[e.image.imageId];if(f.hasOwnProperty(c)===!1)return void 0;var g=f[c];return g}var d={},e={get:c,add:a};return e}void 0===c&&(c={});var e=d();return c.newImageIdSpecificToolStateManager=d,c.globalImageIdSpecificToolStateManager=e,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,c){function d(d,e,g){if(!(a.indexOf(e)>=0))return c.add(d,e,g);b.getEnabledElement(d);f.hasOwnProperty(e)===!1&&(f[e]={data:[]});var h=f[e];h.data.push(g)}function e(b,d){if(a.indexOf(d)>=0){f.hasOwnProperty(d)===!1&&(f[d]={data:[]});var e=f[d];return e}return c.get(b,d)}var f={},g={get:e,add:d};return g}function e(a){var b=c.getElementToolStateManager(a);void 0===b&&(b=c.globalImageIdSpecificToolStateManager);var d=["stack","stackScroll","playClip","volume","slab"],e=c.newStackSpecificToolStateManager(d,b);f.push(e),c.setElementToolStateManager(a,e)}void 0===c&&(c={});var f=[];return c.newStackSpecificToolStateManager=d,c.addStackStateManager=e,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a){var d=b.getEnabledElement(a);return void 0===d.toolStateManager&&(d.toolStateManager=c.globalImageIdSpecificToolStateManager),d.toolStateManager}function e(a,b,c){var e=d(a);e.add(a,b,c)}function f(a,b){var c=d(a);return c.get(a,b)}function g(a,b,c){for(var e=d(a),f=e.get(a,b),g=-1,h=0;h<f.data.length;h++)f.data[h]===c&&(g=h);-1!==g&&f.data.splice(g,1)}function h(a,c){var d=b.getEnabledElement(a);d.toolStateManager=c}return void 0===c&&(c={}),c.addToolState=e,c.getToolState=f,c.removeToolState=g,c.setElementToolStateManager=h,c.getElementToolStateManager=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c,d){"use strict";function e(a){var b=c.point.copy(a.page),d=c.point.copy(a.image);return{page:b,image:d}}return void 0===d&&(d={}),d.copyPoints=e,d}($,cornerstone,cornerstoneMath,cornerstoneTools),cornerstoneTools=function(a){"use strict";function b(a,b,c,d,e){var f=.5522848,g=d/2*f,h=e/2*f,i=b+d,j=c+e,k=b+d/2,l=c+e/2;a.beginPath(),a.moveTo(b,l),a.bezierCurveTo(b,l-h,k-g,c,k,c),a.bezierCurveTo(k+g,c,i,l-h,i,l),a.bezierCurveTo(i,l+h,k+g,j,k,j),a.bezierCurveTo(k-g,j,b,l+h,b,l),a.closePath(),a.stroke()}return void 0===a&&(a={}),a.drawEllipse=b,a}(cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a,b){var c=1<<a-1;return 0!==(b&c)}return void 0===c&&(c={}),c.isMouseButtonEnabled=d,c}($,cornerstone,cornerstoneTools),cornerstoneTools=function(a,b,c){"use strict";function d(a){return a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.cancelBubble=!0,a.returnValue=!1,!1}return void 0===c&&(c={}),c.pauseEvent=d,c}($,cornerstone,cornerstoneTools),cornerstone=function(a){"use strict";function b(b,c,d){var e=.1;a.setToPixelCoordinateSystem(b,c,e);var f=d/b.viewport.scale/e,g=d/b.viewport.scale/e;return{fontSize:f,lineHeight:g,fontScale:e}}return void 0===a&&(a={}),cornerstoneTools.setContextToDisplayFontSize=b,a}(cornerstone);