diff --git a/public/static/1.1.jpg b/public/static/1.1.jpg new file mode 100644 index 00000000..72a851b4 Binary files /dev/null and b/public/static/1.1.jpg differ diff --git a/public/static/1.2.jpg b/public/static/1.2.jpg new file mode 100644 index 00000000..a0c1d715 Binary files /dev/null and b/public/static/1.2.jpg differ diff --git a/public/static/2.1.jpg b/public/static/2.1.jpg new file mode 100644 index 00000000..1e9c5dc3 Binary files /dev/null and b/public/static/2.1.jpg differ diff --git a/public/static/2.2.jpg b/public/static/2.2.jpg new file mode 100644 index 00000000..015e4445 Binary files /dev/null and b/public/static/2.2.jpg differ diff --git a/public/static/2.3.jpg b/public/static/2.3.jpg new file mode 100644 index 00000000..598836b2 Binary files /dev/null and b/public/static/2.3.jpg differ diff --git a/public/static/3.2.jpg b/public/static/3.2.jpg new file mode 100644 index 00000000..2fae6734 Binary files /dev/null and b/public/static/3.2.jpg differ diff --git a/public/static/3.3.jpg b/public/static/3.3.jpg new file mode 100644 index 00000000..d49e57be Binary files /dev/null and b/public/static/3.3.jpg differ diff --git a/public/static/dicom/dicomViewPc1.html b/public/static/dicom/dicomViewPc1.html index c4b66c09..1cce70fb 100644 --- a/public/static/dicom/dicomViewPc1.html +++ b/public/static/dicom/dicomViewPc1.html @@ -10,7 +10,7 @@ - + @@ -56,13 +56,14 @@ } #top-menu { - background-color: black; + background-color: rgb(54, 54, 54); /*height: 180px; display: flex; flex-direction: row;*/ border: 0px solid red; - overflow-x: hidden; - overflow-y: hidden; + /* overflow-x: hidden; + overflow-y: hidden; */ + position: relative; /* 确保下拉菜单相对于这个元素定位 */ } #body-part { @@ -325,43 +326,105 @@ height:151px; } .icon-img-box > canvas { - height:149px; - width:149px; + height:149px !important; + width:149px !important; + } + /* 为图片设置过渡效果 */ +.img-checkbox { + transition: transform 0.3s ease; + cursor: pointer; +} + +/* 点击时的效果 */ +.img-checkbox:active { + transform: scale(0.95); + opacity: 0.8; +} + +.img-checkbox.active { + border: 1px solid rgb(73, 121, 243); /* 添加边框 */ +} + +/* 下拉样式 */ + + .dropdown { + position: relative; + display: inline-block; + } + .dropdown-content { + list-style-type: none; /* 去掉前面的点 */ + display: none; /* 默认隐藏 */ + position: absolute; + background-color: #f9f9f9; + min-width: 61px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1000; /* 确保在最上层 */ + padding:5px; /* 去掉内边距 */ + margin: 0; /* 去掉外边距 */ + } + .dropdown-content a { + color: black; + padding: 5px; + text-decoration: none; + display: block; + } + .dropdown-content a:hover { + background-color:rgb(196, 213, 255); + } + .dropdown:hover .dropdown-content { + display: block; /* 悬停显示下拉内容 */ + } + .dropdown:hover .dropbtn { + background-color: #3e8e41; /* 悬停时的按钮颜色 */ } -
-
- - - - - - - - - - - - - - - - - - - - - - - - - x -
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + x + +
+
@@ -369,5 +432,57 @@
+ \ No newline at end of file diff --git a/public/static/dicom/js/cornerstoneTools.js b/public/static/dicom/js/cornerstoneTools.js new file mode 100644 index 00000000..3839ba2c --- /dev/null +++ b/public/static/dicom/js/cornerstoneTools.js @@ -0,0 +1,38416 @@ + +/*! cornerstone-tools - 6.0.7 - 2022-06-13 | (c) 2017 Chris Hafey | https://github.com/cornerstonejs/cornerstoneTools */ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define("cornerstone-tools", [], factory); + else if(typeof exports === 'object') + exports["cornerstone-tools"] = factory(); + else + root["cornerstoneTools"] = factory(); +})(window, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ function hotDisposeChunk(chunkId) { +/******/ delete installedChunks[chunkId]; +/******/ } +/******/ var parentHotUpdateCallback = window["webpackHotUpdate"]; +/******/ window["webpackHotUpdate"] = // eslint-disable-next-line no-unused-vars +/******/ function webpackHotUpdateCallback(chunkId, moreModules) { +/******/ hotAddUpdateChunk(chunkId, moreModules); +/******/ if (parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules); +/******/ } ; +/******/ +/******/ // eslint-disable-next-line no-unused-vars +/******/ function hotDownloadUpdateChunk(chunkId) { +/******/ var script = document.createElement("script"); +/******/ script.charset = "utf-8"; +/******/ script.src = __webpack_require__.p + "" + chunkId + "." + hotCurrentHash + ".hot-update.js"; +/******/ if (null) script.crossOrigin = null; +/******/ document.head.appendChild(script); +/******/ } +/******/ +/******/ // eslint-disable-next-line no-unused-vars +/******/ function hotDownloadManifest(requestTimeout) { +/******/ requestTimeout = requestTimeout || 10000; +/******/ return new Promise(function(resolve, reject) { +/******/ if (typeof XMLHttpRequest === "undefined") { +/******/ return reject(new Error("No browser support")); +/******/ } +/******/ try { +/******/ var request = new XMLHttpRequest(); +/******/ var requestPath = __webpack_require__.p + "" + hotCurrentHash + ".hot-update.json"; +/******/ request.open("GET", requestPath, true); +/******/ request.timeout = requestTimeout; +/******/ request.send(null); +/******/ } catch (err) { +/******/ return reject(err); +/******/ } +/******/ request.onreadystatechange = function() { +/******/ if (request.readyState !== 4) return; +/******/ if (request.status === 0) { +/******/ // timeout +/******/ reject( +/******/ new Error("Manifest request to " + requestPath + " timed out.") +/******/ ); +/******/ } else if (request.status === 404) { +/******/ // no update available +/******/ resolve(); +/******/ } else if (request.status !== 200 && request.status !== 304) { +/******/ // other failure +/******/ reject(new Error("Manifest request to " + requestPath + " failed.")); +/******/ } else { +/******/ // success +/******/ try { +/******/ var update = JSON.parse(request.responseText); +/******/ } catch (e) { +/******/ reject(e); +/******/ return; +/******/ } +/******/ resolve(update); +/******/ } +/******/ }; +/******/ }); +/******/ } +/******/ +/******/ var hotApplyOnUpdate = true; +/******/ // eslint-disable-next-line no-unused-vars +/******/ var hotCurrentHash = "4cc6e7878d112f9012de"; +/******/ var hotRequestTimeout = 10000; +/******/ var hotCurrentModuleData = {}; +/******/ var hotCurrentChildModule; +/******/ // eslint-disable-next-line no-unused-vars +/******/ var hotCurrentParents = []; +/******/ // eslint-disable-next-line no-unused-vars +/******/ var hotCurrentParentsTemp = []; +/******/ +/******/ // eslint-disable-next-line no-unused-vars +/******/ function hotCreateRequire(moduleId) { +/******/ var me = installedModules[moduleId]; +/******/ if (!me) return __webpack_require__; +/******/ var fn = function(request) { +/******/ if (me.hot.active) { +/******/ if (installedModules[request]) { +/******/ if (installedModules[request].parents.indexOf(moduleId) === -1) { +/******/ installedModules[request].parents.push(moduleId); +/******/ } +/******/ } else { +/******/ hotCurrentParents = [moduleId]; +/******/ hotCurrentChildModule = request; +/******/ } +/******/ if (me.children.indexOf(request) === -1) { +/******/ me.children.push(request); +/******/ } +/******/ } else { +/******/ console.warn( +/******/ "[HMR] unexpected require(" + +/******/ request + +/******/ ") from disposed module " + +/******/ moduleId +/******/ ); +/******/ hotCurrentParents = []; +/******/ } +/******/ return __webpack_require__(request); +/******/ }; +/******/ var ObjectFactory = function ObjectFactory(name) { +/******/ return { +/******/ configurable: true, +/******/ enumerable: true, +/******/ get: function() { +/******/ return __webpack_require__[name]; +/******/ }, +/******/ set: function(value) { +/******/ __webpack_require__[name] = value; +/******/ } +/******/ }; +/******/ }; +/******/ for (var name in __webpack_require__) { +/******/ if ( +/******/ Object.prototype.hasOwnProperty.call(__webpack_require__, name) && +/******/ name !== "e" && +/******/ name !== "t" +/******/ ) { +/******/ Object.defineProperty(fn, name, ObjectFactory(name)); +/******/ } +/******/ } +/******/ fn.e = function(chunkId) { +/******/ if (hotStatus === "ready") hotSetStatus("prepare"); +/******/ hotChunksLoading++; +/******/ return __webpack_require__.e(chunkId).then(finishChunkLoading, function(err) { +/******/ finishChunkLoading(); +/******/ throw err; +/******/ }); +/******/ +/******/ function finishChunkLoading() { +/******/ hotChunksLoading--; +/******/ if (hotStatus === "prepare") { +/******/ if (!hotWaitingFilesMap[chunkId]) { +/******/ hotEnsureUpdateChunk(chunkId); +/******/ } +/******/ if (hotChunksLoading === 0 && hotWaitingFiles === 0) { +/******/ hotUpdateDownloaded(); +/******/ } +/******/ } +/******/ } +/******/ }; +/******/ fn.t = function(value, mode) { +/******/ if (mode & 1) value = fn(value); +/******/ return __webpack_require__.t(value, mode & ~1); +/******/ }; +/******/ return fn; +/******/ } +/******/ +/******/ // eslint-disable-next-line no-unused-vars +/******/ function hotCreateModule(moduleId) { +/******/ var hot = { +/******/ // private stuff +/******/ _acceptedDependencies: {}, +/******/ _declinedDependencies: {}, +/******/ _selfAccepted: false, +/******/ _selfDeclined: false, +/******/ _disposeHandlers: [], +/******/ _main: hotCurrentChildModule !== moduleId, +/******/ +/******/ // Module API +/******/ active: true, +/******/ accept: function(dep, callback) { +/******/ if (dep === undefined) hot._selfAccepted = true; +/******/ else if (typeof dep === "function") hot._selfAccepted = dep; +/******/ else if (typeof dep === "object") +/******/ for (var i = 0; i < dep.length; i++) +/******/ hot._acceptedDependencies[dep[i]] = callback || function() {}; +/******/ else hot._acceptedDependencies[dep] = callback || function() {}; +/******/ }, +/******/ decline: function(dep) { +/******/ if (dep === undefined) hot._selfDeclined = true; +/******/ else if (typeof dep === "object") +/******/ for (var i = 0; i < dep.length; i++) +/******/ hot._declinedDependencies[dep[i]] = true; +/******/ else hot._declinedDependencies[dep] = true; +/******/ }, +/******/ dispose: function(callback) { +/******/ hot._disposeHandlers.push(callback); +/******/ }, +/******/ addDisposeHandler: function(callback) { +/******/ hot._disposeHandlers.push(callback); +/******/ }, +/******/ removeDisposeHandler: function(callback) { +/******/ var idx = hot._disposeHandlers.indexOf(callback); +/******/ if (idx >= 0) hot._disposeHandlers.splice(idx, 1); +/******/ }, +/******/ +/******/ // Management API +/******/ check: hotCheck, +/******/ apply: hotApply, +/******/ status: function(l) { +/******/ if (!l) return hotStatus; +/******/ hotStatusHandlers.push(l); +/******/ }, +/******/ addStatusHandler: function(l) { +/******/ hotStatusHandlers.push(l); +/******/ }, +/******/ removeStatusHandler: function(l) { +/******/ var idx = hotStatusHandlers.indexOf(l); +/******/ if (idx >= 0) hotStatusHandlers.splice(idx, 1); +/******/ }, +/******/ +/******/ //inherit from previous dispose call +/******/ data: hotCurrentModuleData[moduleId] +/******/ }; +/******/ hotCurrentChildModule = undefined; +/******/ return hot; +/******/ } +/******/ +/******/ var hotStatusHandlers = []; +/******/ var hotStatus = "idle"; +/******/ +/******/ function hotSetStatus(newStatus) { +/******/ hotStatus = newStatus; +/******/ for (var i = 0; i < hotStatusHandlers.length; i++) +/******/ hotStatusHandlers[i].call(null, newStatus); +/******/ } +/******/ +/******/ // while downloading +/******/ var hotWaitingFiles = 0; +/******/ var hotChunksLoading = 0; +/******/ var hotWaitingFilesMap = {}; +/******/ var hotRequestedFilesMap = {}; +/******/ var hotAvailableFilesMap = {}; +/******/ var hotDeferred; +/******/ +/******/ // The update info +/******/ var hotUpdate, hotUpdateNewHash; +/******/ +/******/ function toModuleId(id) { +/******/ var isNumber = +id + "" === id; +/******/ return isNumber ? +id : id; +/******/ } +/******/ +/******/ function hotCheck(apply) { +/******/ if (hotStatus !== "idle") { +/******/ throw new Error("check() is only allowed in idle status"); +/******/ } +/******/ hotApplyOnUpdate = apply; +/******/ hotSetStatus("check"); +/******/ return hotDownloadManifest(hotRequestTimeout).then(function(update) { +/******/ if (!update) { +/******/ hotSetStatus("idle"); +/******/ return null; +/******/ } +/******/ hotRequestedFilesMap = {}; +/******/ hotWaitingFilesMap = {}; +/******/ hotAvailableFilesMap = update.c; +/******/ hotUpdateNewHash = update.h; +/******/ +/******/ hotSetStatus("prepare"); +/******/ var promise = new Promise(function(resolve, reject) { +/******/ hotDeferred = { +/******/ resolve: resolve, +/******/ reject: reject +/******/ }; +/******/ }); +/******/ hotUpdate = {}; +/******/ var chunkId = "cornerstoneTools"; +/******/ // eslint-disable-next-line no-lone-blocks +/******/ { +/******/ /*globals chunkId */ +/******/ hotEnsureUpdateChunk(chunkId); +/******/ } +/******/ if ( +/******/ hotStatus === "prepare" && +/******/ hotChunksLoading === 0 && +/******/ hotWaitingFiles === 0 +/******/ ) { +/******/ hotUpdateDownloaded(); +/******/ } +/******/ return promise; +/******/ }); +/******/ } +/******/ +/******/ // eslint-disable-next-line no-unused-vars +/******/ function hotAddUpdateChunk(chunkId, moreModules) { +/******/ if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId]) +/******/ return; +/******/ hotRequestedFilesMap[chunkId] = false; +/******/ for (var moduleId in moreModules) { +/******/ if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { +/******/ hotUpdate[moduleId] = moreModules[moduleId]; +/******/ } +/******/ } +/******/ if (--hotWaitingFiles === 0 && hotChunksLoading === 0) { +/******/ hotUpdateDownloaded(); +/******/ } +/******/ } +/******/ +/******/ function hotEnsureUpdateChunk(chunkId) { +/******/ if (!hotAvailableFilesMap[chunkId]) { +/******/ hotWaitingFilesMap[chunkId] = true; +/******/ } else { +/******/ hotRequestedFilesMap[chunkId] = true; +/******/ hotWaitingFiles++; +/******/ hotDownloadUpdateChunk(chunkId); +/******/ } +/******/ } +/******/ +/******/ function hotUpdateDownloaded() { +/******/ hotSetStatus("ready"); +/******/ var deferred = hotDeferred; +/******/ hotDeferred = null; +/******/ if (!deferred) return; +/******/ if (hotApplyOnUpdate) { +/******/ // Wrap deferred object in Promise to mark it as a well-handled Promise to +/******/ // avoid triggering uncaught exception warning in Chrome. +/******/ // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666 +/******/ Promise.resolve() +/******/ .then(function() { +/******/ return hotApply(hotApplyOnUpdate); +/******/ }) +/******/ .then( +/******/ function(result) { +/******/ deferred.resolve(result); +/******/ }, +/******/ function(err) { +/******/ deferred.reject(err); +/******/ } +/******/ ); +/******/ } else { +/******/ var outdatedModules = []; +/******/ for (var id in hotUpdate) { +/******/ if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) { +/******/ outdatedModules.push(toModuleId(id)); +/******/ } +/******/ } +/******/ deferred.resolve(outdatedModules); +/******/ } +/******/ } +/******/ +/******/ function hotApply(options) { +/******/ if (hotStatus !== "ready") +/******/ throw new Error("apply() is only allowed in ready status"); +/******/ options = options || {}; +/******/ +/******/ var cb; +/******/ var i; +/******/ var j; +/******/ var module; +/******/ var moduleId; +/******/ +/******/ function getAffectedStuff(updateModuleId) { +/******/ var outdatedModules = [updateModuleId]; +/******/ var outdatedDependencies = {}; +/******/ +/******/ var queue = outdatedModules.map(function(id) { +/******/ return { +/******/ chain: [id], +/******/ id: id +/******/ }; +/******/ }); +/******/ while (queue.length > 0) { +/******/ var queueItem = queue.pop(); +/******/ var moduleId = queueItem.id; +/******/ var chain = queueItem.chain; +/******/ module = installedModules[moduleId]; +/******/ if (!module || module.hot._selfAccepted) continue; +/******/ if (module.hot._selfDeclined) { +/******/ return { +/******/ type: "self-declined", +/******/ chain: chain, +/******/ moduleId: moduleId +/******/ }; +/******/ } +/******/ if (module.hot._main) { +/******/ return { +/******/ type: "unaccepted", +/******/ chain: chain, +/******/ moduleId: moduleId +/******/ }; +/******/ } +/******/ for (var i = 0; i < module.parents.length; i++) { +/******/ var parentId = module.parents[i]; +/******/ var parent = installedModules[parentId]; +/******/ if (!parent) continue; +/******/ if (parent.hot._declinedDependencies[moduleId]) { +/******/ return { +/******/ type: "declined", +/******/ chain: chain.concat([parentId]), +/******/ moduleId: moduleId, +/******/ parentId: parentId +/******/ }; +/******/ } +/******/ if (outdatedModules.indexOf(parentId) !== -1) continue; +/******/ if (parent.hot._acceptedDependencies[moduleId]) { +/******/ if (!outdatedDependencies[parentId]) +/******/ outdatedDependencies[parentId] = []; +/******/ addAllToSet(outdatedDependencies[parentId], [moduleId]); +/******/ continue; +/******/ } +/******/ delete outdatedDependencies[parentId]; +/******/ outdatedModules.push(parentId); +/******/ queue.push({ +/******/ chain: chain.concat([parentId]), +/******/ id: parentId +/******/ }); +/******/ } +/******/ } +/******/ +/******/ return { +/******/ type: "accepted", +/******/ moduleId: updateModuleId, +/******/ outdatedModules: outdatedModules, +/******/ outdatedDependencies: outdatedDependencies +/******/ }; +/******/ } +/******/ +/******/ function addAllToSet(a, b) { +/******/ for (var i = 0; i < b.length; i++) { +/******/ var item = b[i]; +/******/ if (a.indexOf(item) === -1) a.push(item); +/******/ } +/******/ } +/******/ +/******/ // at begin all updates modules are outdated +/******/ // the "outdated" status can propagate to parents if they don't accept the children +/******/ var outdatedDependencies = {}; +/******/ var outdatedModules = []; +/******/ var appliedUpdate = {}; +/******/ +/******/ var warnUnexpectedRequire = function warnUnexpectedRequire() { +/******/ console.warn( +/******/ "[HMR] unexpected require(" + result.moduleId + ") to disposed module" +/******/ ); +/******/ }; +/******/ +/******/ for (var id in hotUpdate) { +/******/ if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) { +/******/ moduleId = toModuleId(id); +/******/ /** @type {TODO} */ +/******/ var result; +/******/ if (hotUpdate[id]) { +/******/ result = getAffectedStuff(moduleId); +/******/ } else { +/******/ result = { +/******/ type: "disposed", +/******/ moduleId: id +/******/ }; +/******/ } +/******/ /** @type {Error|false} */ +/******/ var abortError = false; +/******/ var doApply = false; +/******/ var doDispose = false; +/******/ var chainInfo = ""; +/******/ if (result.chain) { +/******/ chainInfo = "\nUpdate propagation: " + result.chain.join(" -> "); +/******/ } +/******/ switch (result.type) { +/******/ case "self-declined": +/******/ if (options.onDeclined) options.onDeclined(result); +/******/ if (!options.ignoreDeclined) +/******/ abortError = new Error( +/******/ "Aborted because of self decline: " + +/******/ result.moduleId + +/******/ chainInfo +/******/ ); +/******/ break; +/******/ case "declined": +/******/ if (options.onDeclined) options.onDeclined(result); +/******/ if (!options.ignoreDeclined) +/******/ abortError = new Error( +/******/ "Aborted because of declined dependency: " + +/******/ result.moduleId + +/******/ " in " + +/******/ result.parentId + +/******/ chainInfo +/******/ ); +/******/ break; +/******/ case "unaccepted": +/******/ if (options.onUnaccepted) options.onUnaccepted(result); +/******/ if (!options.ignoreUnaccepted) +/******/ abortError = new Error( +/******/ "Aborted because " + moduleId + " is not accepted" + chainInfo +/******/ ); +/******/ break; +/******/ case "accepted": +/******/ if (options.onAccepted) options.onAccepted(result); +/******/ doApply = true; +/******/ break; +/******/ case "disposed": +/******/ if (options.onDisposed) options.onDisposed(result); +/******/ doDispose = true; +/******/ break; +/******/ default: +/******/ throw new Error("Unexception type " + result.type); +/******/ } +/******/ if (abortError) { +/******/ hotSetStatus("abort"); +/******/ return Promise.reject(abortError); +/******/ } +/******/ if (doApply) { +/******/ appliedUpdate[moduleId] = hotUpdate[moduleId]; +/******/ addAllToSet(outdatedModules, result.outdatedModules); +/******/ for (moduleId in result.outdatedDependencies) { +/******/ if ( +/******/ Object.prototype.hasOwnProperty.call( +/******/ result.outdatedDependencies, +/******/ moduleId +/******/ ) +/******/ ) { +/******/ if (!outdatedDependencies[moduleId]) +/******/ outdatedDependencies[moduleId] = []; +/******/ addAllToSet( +/******/ outdatedDependencies[moduleId], +/******/ result.outdatedDependencies[moduleId] +/******/ ); +/******/ } +/******/ } +/******/ } +/******/ if (doDispose) { +/******/ addAllToSet(outdatedModules, [result.moduleId]); +/******/ appliedUpdate[moduleId] = warnUnexpectedRequire; +/******/ } +/******/ } +/******/ } +/******/ +/******/ // Store self accepted outdated modules to require them later by the module system +/******/ var outdatedSelfAcceptedModules = []; +/******/ for (i = 0; i < outdatedModules.length; i++) { +/******/ moduleId = outdatedModules[i]; +/******/ if ( +/******/ installedModules[moduleId] && +/******/ installedModules[moduleId].hot._selfAccepted && +/******/ // removed self-accepted modules should not be required +/******/ appliedUpdate[moduleId] !== warnUnexpectedRequire +/******/ ) { +/******/ outdatedSelfAcceptedModules.push({ +/******/ module: moduleId, +/******/ errorHandler: installedModules[moduleId].hot._selfAccepted +/******/ }); +/******/ } +/******/ } +/******/ +/******/ // Now in "dispose" phase +/******/ hotSetStatus("dispose"); +/******/ Object.keys(hotAvailableFilesMap).forEach(function(chunkId) { +/******/ if (hotAvailableFilesMap[chunkId] === false) { +/******/ hotDisposeChunk(chunkId); +/******/ } +/******/ }); +/******/ +/******/ var idx; +/******/ var queue = outdatedModules.slice(); +/******/ while (queue.length > 0) { +/******/ moduleId = queue.pop(); +/******/ module = installedModules[moduleId]; +/******/ if (!module) continue; +/******/ +/******/ var data = {}; +/******/ +/******/ // Call dispose handlers +/******/ var disposeHandlers = module.hot._disposeHandlers; +/******/ for (j = 0; j < disposeHandlers.length; j++) { +/******/ cb = disposeHandlers[j]; +/******/ cb(data); +/******/ } +/******/ hotCurrentModuleData[moduleId] = data; +/******/ +/******/ // disable module (this disables requires from this module) +/******/ module.hot.active = false; +/******/ +/******/ // remove module from cache +/******/ delete installedModules[moduleId]; +/******/ +/******/ // when disposing there is no need to call dispose handler +/******/ delete outdatedDependencies[moduleId]; +/******/ +/******/ // remove "parents" references from all children +/******/ for (j = 0; j < module.children.length; j++) { +/******/ var child = installedModules[module.children[j]]; +/******/ if (!child) continue; +/******/ idx = child.parents.indexOf(moduleId); +/******/ if (idx >= 0) { +/******/ child.parents.splice(idx, 1); +/******/ } +/******/ } +/******/ } +/******/ +/******/ // remove outdated dependency from module children +/******/ var dependency; +/******/ var moduleOutdatedDependencies; +/******/ for (moduleId in outdatedDependencies) { +/******/ if ( +/******/ Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId) +/******/ ) { +/******/ module = installedModules[moduleId]; +/******/ if (module) { +/******/ moduleOutdatedDependencies = outdatedDependencies[moduleId]; +/******/ for (j = 0; j < moduleOutdatedDependencies.length; j++) { +/******/ dependency = moduleOutdatedDependencies[j]; +/******/ idx = module.children.indexOf(dependency); +/******/ if (idx >= 0) module.children.splice(idx, 1); +/******/ } +/******/ } +/******/ } +/******/ } +/******/ +/******/ // Now in "apply" phase +/******/ hotSetStatus("apply"); +/******/ +/******/ hotCurrentHash = hotUpdateNewHash; +/******/ +/******/ // insert new code +/******/ for (moduleId in appliedUpdate) { +/******/ if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) { +/******/ modules[moduleId] = appliedUpdate[moduleId]; +/******/ } +/******/ } +/******/ +/******/ // call accept handlers +/******/ var error = null; +/******/ for (moduleId in outdatedDependencies) { +/******/ if ( +/******/ Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId) +/******/ ) { +/******/ module = installedModules[moduleId]; +/******/ if (module) { +/******/ moduleOutdatedDependencies = outdatedDependencies[moduleId]; +/******/ var callbacks = []; +/******/ for (i = 0; i < moduleOutdatedDependencies.length; i++) { +/******/ dependency = moduleOutdatedDependencies[i]; +/******/ cb = module.hot._acceptedDependencies[dependency]; +/******/ if (cb) { +/******/ if (callbacks.indexOf(cb) !== -1) continue; +/******/ callbacks.push(cb); +/******/ } +/******/ } +/******/ for (i = 0; i < callbacks.length; i++) { +/******/ cb = callbacks[i]; +/******/ try { +/******/ cb(moduleOutdatedDependencies); +/******/ } catch (err) { +/******/ if (options.onErrored) { +/******/ options.onErrored({ +/******/ type: "accept-errored", +/******/ moduleId: moduleId, +/******/ dependencyId: moduleOutdatedDependencies[i], +/******/ error: err +/******/ }); +/******/ } +/******/ if (!options.ignoreErrored) { +/******/ if (!error) error = err; +/******/ } +/******/ } +/******/ } +/******/ } +/******/ } +/******/ } +/******/ +/******/ // Load self accepted modules +/******/ for (i = 0; i < outdatedSelfAcceptedModules.length; i++) { +/******/ var item = outdatedSelfAcceptedModules[i]; +/******/ moduleId = item.module; +/******/ hotCurrentParents = [moduleId]; +/******/ try { +/******/ __webpack_require__(moduleId); +/******/ } catch (err) { +/******/ if (typeof item.errorHandler === "function") { +/******/ try { +/******/ item.errorHandler(err); +/******/ } catch (err2) { +/******/ if (options.onErrored) { +/******/ options.onErrored({ +/******/ type: "self-accept-error-handler-errored", +/******/ moduleId: moduleId, +/******/ error: err2, +/******/ originalError: err +/******/ }); +/******/ } +/******/ if (!options.ignoreErrored) { +/******/ if (!error) error = err2; +/******/ } +/******/ if (!error) error = err; +/******/ } +/******/ } else { +/******/ if (options.onErrored) { +/******/ options.onErrored({ +/******/ type: "self-accept-errored", +/******/ moduleId: moduleId, +/******/ error: err +/******/ }); +/******/ } +/******/ if (!options.ignoreErrored) { +/******/ if (!error) error = err; +/******/ } +/******/ } +/******/ } +/******/ } +/******/ +/******/ // handle errors in accept handlers and self accepted module load +/******/ if (error) { +/******/ hotSetStatus("fail"); +/******/ return Promise.reject(error); +/******/ } +/******/ +/******/ hotSetStatus("idle"); +/******/ return new Promise(function(resolve) { +/******/ resolve(outdatedModules); +/******/ }); +/******/ } +/******/ +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {}, +/******/ hot: hotCreateModule(moduleId), +/******/ parents: (hotCurrentParentsTemp = hotCurrentParents, hotCurrentParents = [], hotCurrentParentsTemp), +/******/ children: [] +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // __webpack_hash__ +/******/ __webpack_require__.h = function() { return hotCurrentHash; }; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return hotCreateRequire("./index.js")(__webpack_require__.s = "./index.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "../node_modules/@babel/runtime/helpers/arrayWithHoles.js": +/*!****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/arrayWithHoles.js ***! + \****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; +} + +module.exports = _arrayWithHoles; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js": +/*!*******************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js ***! + \*******************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { + arr2[i] = arr[i]; + } + + return arr2; + } +} + +module.exports = _arrayWithoutHoles; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js": +/*!***********************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/assertThisInitialized.js ***! + \***********************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +module.exports = _assertThisInitialized; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/asyncToGenerator.js": +/*!******************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/asyncToGenerator.js ***! + \******************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} + +function _asyncToGenerator(fn) { + return function () { + var self = this, + args = arguments; + return new Promise(function (resolve, reject) { + var gen = fn.apply(self, args); + + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + + _next(undefined); + }); + }; +} + +module.exports = _asyncToGenerator; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/classCallCheck.js": +/*!****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/classCallCheck.js ***! + \****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +module.exports = _classCallCheck; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/createClass.js": +/*!*************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/createClass.js ***! + \*************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +module.exports = _createClass; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/defineProperty.js": +/*!****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/defineProperty.js ***! + \****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +module.exports = _defineProperty; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js": +/*!****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/getPrototypeOf.js ***! + \****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _getPrototypeOf(o) { + module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +module.exports = _getPrototypeOf; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/inherits.js": +/*!**********************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/inherits.js ***! + \**********************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf */ "../node_modules/@babel/runtime/helpers/setPrototypeOf.js"); + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) setPrototypeOf(subClass, superClass); +} + +module.exports = _inherits; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/iterableToArray.js": +/*!*****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/iterableToArray.js ***! + \*****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _iterableToArray(iter) { + if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); +} + +module.exports = _iterableToArray; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js": +/*!**********************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js ***! + \**********************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _iterableToArrayLimit(arr, i) { + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; +} + +module.exports = _iterableToArrayLimit; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/nonIterableRest.js": +/*!*****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/nonIterableRest.js ***! + \*****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); +} + +module.exports = _nonIterableRest; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/nonIterableSpread.js": +/*!*******************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/nonIterableSpread.js ***! + \*******************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance"); +} + +module.exports = _nonIterableSpread; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js": +/*!***************************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***! + \***************************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var _typeof = __webpack_require__(/*! ../helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); + +var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); + +function _possibleConstructorReturn(self, call) { + if (call && (_typeof(call) === "object" || typeof call === "function")) { + return call; + } + + return assertThisInitialized(self); +} + +module.exports = _possibleConstructorReturn; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/setPrototypeOf.js": +/*!****************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/setPrototypeOf.js ***! + \****************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _setPrototypeOf(o, p) { + module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +module.exports = _setPrototypeOf; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/slicedToArray.js": +/*!***************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/slicedToArray.js ***! + \***************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles */ "../node_modules/@babel/runtime/helpers/arrayWithHoles.js"); + +var iterableToArrayLimit = __webpack_require__(/*! ./iterableToArrayLimit */ "../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js"); + +var nonIterableRest = __webpack_require__(/*! ./nonIterableRest */ "../node_modules/@babel/runtime/helpers/nonIterableRest.js"); + +function _slicedToArray(arr, i) { + return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest(); +} + +module.exports = _slicedToArray; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/toConsumableArray.js": +/*!*******************************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/toConsumableArray.js ***! + \*******************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var arrayWithoutHoles = __webpack_require__(/*! ./arrayWithoutHoles */ "../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js"); + +var iterableToArray = __webpack_require__(/*! ./iterableToArray */ "../node_modules/@babel/runtime/helpers/iterableToArray.js"); + +var nonIterableSpread = __webpack_require__(/*! ./nonIterableSpread */ "../node_modules/@babel/runtime/helpers/nonIterableSpread.js"); + +function _toConsumableArray(arr) { + return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread(); +} + +module.exports = _toConsumableArray; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/helpers/typeof.js": +/*!********************************************************!*\ + !*** ../node_modules/@babel/runtime/helpers/typeof.js ***! + \********************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); } + +function _typeof(obj) { + if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { + module.exports = _typeof = function _typeof(obj) { + return _typeof2(obj); + }; + } else { + module.exports = _typeof = function _typeof(obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); + }; + } + + return _typeof(obj); +} + +module.exports = _typeof; + +/***/ }), + +/***/ "../node_modules/@babel/runtime/regenerator/index.js": +/*!***********************************************************!*\ + !*** ../node_modules/@babel/runtime/regenerator/index.js ***! + \***********************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__(/*! regenerator-runtime */ "../node_modules/regenerator-runtime/runtime-module.js"); + + +/***/ }), + +/***/ "../node_modules/ms/index.js": +/*!***********************************!*\ + !*** ../node_modules/ms/index.js ***! + \***********************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +/** + * Helpers. + */ + +var s = 1000; +var m = s * 60; +var h = m * 60; +var d = h * 24; +var w = d * 7; +var y = d * 365.25; + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} [options] + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +module.exports = function(val, options) { + options = options || {}; + var type = typeof val; + if (type === 'string' && val.length > 0) { + return parse(val); + } else if (type === 'number' && isFinite(val)) { + return options.long ? fmtLong(val) : fmtShort(val); + } + throw new Error( + 'val is not a non-empty string or a valid number. val=' + + JSON.stringify(val) + ); +}; + +/** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + +function parse(str) { + str = String(str); + if (str.length > 100) { + return; + } + var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + str + ); + if (!match) { + return; + } + var n = parseFloat(match[1]); + var type = (match[2] || 'ms').toLowerCase(); + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y; + case 'weeks': + case 'week': + case 'w': + return n * w; + case 'days': + case 'day': + case 'd': + return n * d; + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h; + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m; + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s; + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n; + default: + return undefined; + } +} + +/** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtShort(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return Math.round(ms / d) + 'd'; + } + if (msAbs >= h) { + return Math.round(ms / h) + 'h'; + } + if (msAbs >= m) { + return Math.round(ms / m) + 'm'; + } + if (msAbs >= s) { + return Math.round(ms / s) + 's'; + } + return ms + 'ms'; +} + +/** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtLong(ms) { + var msAbs = Math.abs(ms); + if (msAbs >= d) { + return plural(ms, msAbs, d, 'day'); + } + if (msAbs >= h) { + return plural(ms, msAbs, h, 'hour'); + } + if (msAbs >= m) { + return plural(ms, msAbs, m, 'minute'); + } + if (msAbs >= s) { + return plural(ms, msAbs, s, 'second'); + } + return ms + ' ms'; +} + +/** + * Pluralization helper. + */ + +function plural(ms, msAbs, n, name) { + var isPlural = msAbs >= n * 1.5; + return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); +} + + +/***/ }), + +/***/ "../node_modules/process/browser.js": +/*!******************************************!*\ + !*** ../node_modules/process/browser.js ***! + \******************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + + +/***/ }), + +/***/ "../node_modules/regenerator-runtime/runtime-module.js": +/*!*************************************************************!*\ + !*** ../node_modules/regenerator-runtime/runtime-module.js ***! + \*************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +/** + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// This method of obtaining a reference to the global object needs to be +// kept identical to the way it is obtained in runtime.js +var g = (function() { + return this || (typeof self === "object" && self); +})() || Function("return this")(); + +// Use `getOwnPropertyNames` because not all browsers support calling +// `hasOwnProperty` on the global `self` object in a worker. See #183. +var hadRuntime = g.regeneratorRuntime && + Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0; + +// Save the old regeneratorRuntime in case it needs to be restored later. +var oldRuntime = hadRuntime && g.regeneratorRuntime; + +// Force reevalutation of runtime.js. +g.regeneratorRuntime = undefined; + +module.exports = __webpack_require__(/*! ./runtime */ "../node_modules/regenerator-runtime/runtime.js"); + +if (hadRuntime) { + // Restore the original runtime. + g.regeneratorRuntime = oldRuntime; +} else { + // Remove the global property added by runtime.js. + try { + delete g.regeneratorRuntime; + } catch(e) { + g.regeneratorRuntime = undefined; + } +} + + +/***/ }), + +/***/ "../node_modules/regenerator-runtime/runtime.js": +/*!******************************************************!*\ + !*** ../node_modules/regenerator-runtime/runtime.js ***! + \******************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +/** + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +!(function(global) { + "use strict"; + + var Op = Object.prototype; + var hasOwn = Op.hasOwnProperty; + var undefined; // More compressible than void 0. + var $Symbol = typeof Symbol === "function" ? Symbol : {}; + var iteratorSymbol = $Symbol.iterator || "@@iterator"; + var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; + var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; + + var inModule = typeof module === "object"; + var runtime = global.regeneratorRuntime; + if (runtime) { + if (inModule) { + // If regeneratorRuntime is defined globally and we're in a module, + // make the exports object identical to regeneratorRuntime. + module.exports = runtime; + } + // Don't bother evaluating the rest of this file if the runtime was + // already defined globally. + return; + } + + // Define the runtime globally (as expected by generated code) as either + // module.exports (if we're in a module) or a new, empty object. + runtime = global.regeneratorRuntime = inModule ? module.exports : {}; + + function wrap(innerFn, outerFn, self, tryLocsList) { + // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. + var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; + var generator = Object.create(protoGenerator.prototype); + var context = new Context(tryLocsList || []); + + // The ._invoke method unifies the implementations of the .next, + // .throw, and .return methods. + generator._invoke = makeInvokeMethod(innerFn, self, context); + + return generator; + } + runtime.wrap = wrap; + + // Try/catch helper to minimize deoptimizations. Returns a completion + // record like context.tryEntries[i].completion. This interface could + // have been (and was previously) designed to take a closure to be + // invoked without arguments, but in all the cases we care about we + // already have an existing method we want to call, so there's no need + // to create a new function object. We can even get away with assuming + // the method takes exactly one argument, since that happens to be true + // in every case, so we don't have to touch the arguments object. The + // only additional allocation required is the completion record, which + // has a stable shape and so hopefully should be cheap to allocate. + function tryCatch(fn, obj, arg) { + try { + return { type: "normal", arg: fn.call(obj, arg) }; + } catch (err) { + return { type: "throw", arg: err }; + } + } + + var GenStateSuspendedStart = "suspendedStart"; + var GenStateSuspendedYield = "suspendedYield"; + var GenStateExecuting = "executing"; + var GenStateCompleted = "completed"; + + // Returning this object from the innerFn has the same effect as + // breaking out of the dispatch switch statement. + var ContinueSentinel = {}; + + // Dummy constructor functions that we use as the .constructor and + // .constructor.prototype properties for functions that return Generator + // objects. For full spec compliance, you may wish to configure your + // minifier not to mangle the names of these two functions. + function Generator() {} + function GeneratorFunction() {} + function GeneratorFunctionPrototype() {} + + // This is a polyfill for %IteratorPrototype% for environments that + // don't natively support it. + var IteratorPrototype = {}; + IteratorPrototype[iteratorSymbol] = function () { + return this; + }; + + var getProto = Object.getPrototypeOf; + var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); + if (NativeIteratorPrototype && + NativeIteratorPrototype !== Op && + hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { + // This environment has a native %IteratorPrototype%; use it instead + // of the polyfill. + IteratorPrototype = NativeIteratorPrototype; + } + + var Gp = GeneratorFunctionPrototype.prototype = + Generator.prototype = Object.create(IteratorPrototype); + GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; + GeneratorFunctionPrototype.constructor = GeneratorFunction; + GeneratorFunctionPrototype[toStringTagSymbol] = + GeneratorFunction.displayName = "GeneratorFunction"; + + // Helper for defining the .next, .throw, and .return methods of the + // Iterator interface in terms of a single ._invoke method. + function defineIteratorMethods(prototype) { + ["next", "throw", "return"].forEach(function(method) { + prototype[method] = function(arg) { + return this._invoke(method, arg); + }; + }); + } + + runtime.isGeneratorFunction = function(genFun) { + var ctor = typeof genFun === "function" && genFun.constructor; + return ctor + ? ctor === GeneratorFunction || + // For the native GeneratorFunction constructor, the best we can + // do is to check its .name property. + (ctor.displayName || ctor.name) === "GeneratorFunction" + : false; + }; + + runtime.mark = function(genFun) { + if (Object.setPrototypeOf) { + Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); + } else { + genFun.__proto__ = GeneratorFunctionPrototype; + if (!(toStringTagSymbol in genFun)) { + genFun[toStringTagSymbol] = "GeneratorFunction"; + } + } + genFun.prototype = Object.create(Gp); + return genFun; + }; + + // Within the body of any async function, `await x` is transformed to + // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test + // `hasOwn.call(value, "__await")` to determine if the yielded value is + // meant to be awaited. + runtime.awrap = function(arg) { + return { __await: arg }; + }; + + function AsyncIterator(generator) { + function invoke(method, arg, resolve, reject) { + var record = tryCatch(generator[method], generator, arg); + if (record.type === "throw") { + reject(record.arg); + } else { + var result = record.arg; + var value = result.value; + if (value && + typeof value === "object" && + hasOwn.call(value, "__await")) { + return Promise.resolve(value.__await).then(function(value) { + invoke("next", value, resolve, reject); + }, function(err) { + invoke("throw", err, resolve, reject); + }); + } + + return Promise.resolve(value).then(function(unwrapped) { + // When a yielded Promise is resolved, its final value becomes + // the .value of the Promise<{value,done}> result for the + // current iteration. + result.value = unwrapped; + resolve(result); + }, function(error) { + // If a rejected Promise was yielded, throw the rejection back + // into the async generator function so it can be handled there. + return invoke("throw", error, resolve, reject); + }); + } + } + + var previousPromise; + + function enqueue(method, arg) { + function callInvokeWithMethodAndArg() { + return new Promise(function(resolve, reject) { + invoke(method, arg, resolve, reject); + }); + } + + return previousPromise = + // If enqueue has been called before, then we want to wait until + // all previous Promises have been resolved before calling invoke, + // so that results are always delivered in the correct order. If + // enqueue has not been called before, then it is important to + // call invoke immediately, without waiting on a callback to fire, + // so that the async generator function has the opportunity to do + // any necessary setup in a predictable way. This predictability + // is why the Promise constructor synchronously invokes its + // executor callback, and why async functions synchronously + // execute code before the first await. Since we implement simple + // async functions in terms of async generators, it is especially + // important to get this right, even though it requires care. + previousPromise ? previousPromise.then( + callInvokeWithMethodAndArg, + // Avoid propagating failures to Promises returned by later + // invocations of the iterator. + callInvokeWithMethodAndArg + ) : callInvokeWithMethodAndArg(); + } + + // Define the unified helper method that is used to implement .next, + // .throw, and .return (see defineIteratorMethods). + this._invoke = enqueue; + } + + defineIteratorMethods(AsyncIterator.prototype); + AsyncIterator.prototype[asyncIteratorSymbol] = function () { + return this; + }; + runtime.AsyncIterator = AsyncIterator; + + // Note that simple async functions are implemented on top of + // AsyncIterator objects; they just return a Promise for the value of + // the final result produced by the iterator. + runtime.async = function(innerFn, outerFn, self, tryLocsList) { + var iter = new AsyncIterator( + wrap(innerFn, outerFn, self, tryLocsList) + ); + + return runtime.isGeneratorFunction(outerFn) + ? iter // If outerFn is a generator, return the full iterator. + : iter.next().then(function(result) { + return result.done ? result.value : iter.next(); + }); + }; + + function makeInvokeMethod(innerFn, self, context) { + var state = GenStateSuspendedStart; + + return function invoke(method, arg) { + if (state === GenStateExecuting) { + throw new Error("Generator is already running"); + } + + if (state === GenStateCompleted) { + if (method === "throw") { + throw arg; + } + + // Be forgiving, per 25.3.3.3.3 of the spec: + // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume + return doneResult(); + } + + context.method = method; + context.arg = arg; + + while (true) { + var delegate = context.delegate; + if (delegate) { + var delegateResult = maybeInvokeDelegate(delegate, context); + if (delegateResult) { + if (delegateResult === ContinueSentinel) continue; + return delegateResult; + } + } + + if (context.method === "next") { + // Setting context._sent for legacy support of Babel's + // function.sent implementation. + context.sent = context._sent = context.arg; + + } else if (context.method === "throw") { + if (state === GenStateSuspendedStart) { + state = GenStateCompleted; + throw context.arg; + } + + context.dispatchException(context.arg); + + } else if (context.method === "return") { + context.abrupt("return", context.arg); + } + + state = GenStateExecuting; + + var record = tryCatch(innerFn, self, context); + if (record.type === "normal") { + // If an exception is thrown from innerFn, we leave state === + // GenStateExecuting and loop back for another invocation. + state = context.done + ? GenStateCompleted + : GenStateSuspendedYield; + + if (record.arg === ContinueSentinel) { + continue; + } + + return { + value: record.arg, + done: context.done + }; + + } else if (record.type === "throw") { + state = GenStateCompleted; + // Dispatch the exception by looping back around to the + // context.dispatchException(context.arg) call above. + context.method = "throw"; + context.arg = record.arg; + } + } + }; + } + + // Call delegate.iterator[context.method](context.arg) and handle the + // result, either by returning a { value, done } result from the + // delegate iterator, or by modifying context.method and context.arg, + // setting context.delegate to null, and returning the ContinueSentinel. + function maybeInvokeDelegate(delegate, context) { + var method = delegate.iterator[context.method]; + if (method === undefined) { + // A .throw or .return when the delegate iterator has no .throw + // method always terminates the yield* loop. + context.delegate = null; + + if (context.method === "throw") { + if (delegate.iterator.return) { + // If the delegate iterator has a return method, give it a + // chance to clean up. + context.method = "return"; + context.arg = undefined; + maybeInvokeDelegate(delegate, context); + + if (context.method === "throw") { + // If maybeInvokeDelegate(context) changed context.method from + // "return" to "throw", let that override the TypeError below. + return ContinueSentinel; + } + } + + context.method = "throw"; + context.arg = new TypeError( + "The iterator does not provide a 'throw' method"); + } + + return ContinueSentinel; + } + + var record = tryCatch(method, delegate.iterator, context.arg); + + if (record.type === "throw") { + context.method = "throw"; + context.arg = record.arg; + context.delegate = null; + return ContinueSentinel; + } + + var info = record.arg; + + if (! info) { + context.method = "throw"; + context.arg = new TypeError("iterator result is not an object"); + context.delegate = null; + return ContinueSentinel; + } + + if (info.done) { + // Assign the result of the finished delegate to the temporary + // variable specified by delegate.resultName (see delegateYield). + context[delegate.resultName] = info.value; + + // Resume execution at the desired location (see delegateYield). + context.next = delegate.nextLoc; + + // If context.method was "throw" but the delegate handled the + // exception, let the outer generator proceed normally. If + // context.method was "next", forget context.arg since it has been + // "consumed" by the delegate iterator. If context.method was + // "return", allow the original .return call to continue in the + // outer generator. + if (context.method !== "return") { + context.method = "next"; + context.arg = undefined; + } + + } else { + // Re-yield the result returned by the delegate method. + return info; + } + + // The delegate iterator is finished, so forget it and continue with + // the outer generator. + context.delegate = null; + return ContinueSentinel; + } + + // Define Generator.prototype.{next,throw,return} in terms of the + // unified ._invoke helper method. + defineIteratorMethods(Gp); + + Gp[toStringTagSymbol] = "Generator"; + + // A Generator should always return itself as the iterator object when the + // @@iterator function is called on it. Some browsers' implementations of the + // iterator prototype chain incorrectly implement this, causing the Generator + // object to not be returned from this call. This ensures that doesn't happen. + // See https://github.com/facebook/regenerator/issues/274 for more details. + Gp[iteratorSymbol] = function() { + return this; + }; + + Gp.toString = function() { + return "[object Generator]"; + }; + + function pushTryEntry(locs) { + var entry = { tryLoc: locs[0] }; + + if (1 in locs) { + entry.catchLoc = locs[1]; + } + + if (2 in locs) { + entry.finallyLoc = locs[2]; + entry.afterLoc = locs[3]; + } + + this.tryEntries.push(entry); + } + + function resetTryEntry(entry) { + var record = entry.completion || {}; + record.type = "normal"; + delete record.arg; + entry.completion = record; + } + + function Context(tryLocsList) { + // The root entry object (effectively a try statement without a catch + // or a finally block) gives us a place to store values thrown from + // locations where there is no enclosing try statement. + this.tryEntries = [{ tryLoc: "root" }]; + tryLocsList.forEach(pushTryEntry, this); + this.reset(true); + } + + runtime.keys = function(object) { + var keys = []; + for (var key in object) { + keys.push(key); + } + keys.reverse(); + + // Rather than returning an object with a next method, we keep + // things simple and return the next function itself. + return function next() { + while (keys.length) { + var key = keys.pop(); + if (key in object) { + next.value = key; + next.done = false; + return next; + } + } + + // To avoid creating an additional object, we just hang the .value + // and .done properties off the next function object itself. This + // also ensures that the minifier will not anonymize the function. + next.done = true; + return next; + }; + }; + + function values(iterable) { + if (iterable) { + var iteratorMethod = iterable[iteratorSymbol]; + if (iteratorMethod) { + return iteratorMethod.call(iterable); + } + + if (typeof iterable.next === "function") { + return iterable; + } + + if (!isNaN(iterable.length)) { + var i = -1, next = function next() { + while (++i < iterable.length) { + if (hasOwn.call(iterable, i)) { + next.value = iterable[i]; + next.done = false; + return next; + } + } + + next.value = undefined; + next.done = true; + + return next; + }; + + return next.next = next; + } + } + + // Return an iterator with no values. + return { next: doneResult }; + } + runtime.values = values; + + function doneResult() { + return { value: undefined, done: true }; + } + + Context.prototype = { + constructor: Context, + + reset: function(skipTempReset) { + this.prev = 0; + this.next = 0; + // Resetting context._sent for legacy support of Babel's + // function.sent implementation. + this.sent = this._sent = undefined; + this.done = false; + this.delegate = null; + + this.method = "next"; + this.arg = undefined; + + this.tryEntries.forEach(resetTryEntry); + + if (!skipTempReset) { + for (var name in this) { + // Not sure about the optimal order of these conditions: + if (name.charAt(0) === "t" && + hasOwn.call(this, name) && + !isNaN(+name.slice(1))) { + this[name] = undefined; + } + } + } + }, + + stop: function() { + this.done = true; + + var rootEntry = this.tryEntries[0]; + var rootRecord = rootEntry.completion; + if (rootRecord.type === "throw") { + throw rootRecord.arg; + } + + return this.rval; + }, + + dispatchException: function(exception) { + if (this.done) { + throw exception; + } + + var context = this; + function handle(loc, caught) { + record.type = "throw"; + record.arg = exception; + context.next = loc; + + if (caught) { + // If the dispatched exception was caught by a catch block, + // then let that catch block handle the exception normally. + context.method = "next"; + context.arg = undefined; + } + + return !! caught; + } + + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + var record = entry.completion; + + if (entry.tryLoc === "root") { + // Exception thrown outside of any try block that could handle + // it, so set the completion value of the entire function to + // throw the exception. + return handle("end"); + } + + if (entry.tryLoc <= this.prev) { + var hasCatch = hasOwn.call(entry, "catchLoc"); + var hasFinally = hasOwn.call(entry, "finallyLoc"); + + if (hasCatch && hasFinally) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } else if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else if (hasCatch) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } + + } else if (hasFinally) { + if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else { + throw new Error("try statement without catch or finally"); + } + } + } + }, + + abrupt: function(type, arg) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc <= this.prev && + hasOwn.call(entry, "finallyLoc") && + this.prev < entry.finallyLoc) { + var finallyEntry = entry; + break; + } + } + + if (finallyEntry && + (type === "break" || + type === "continue") && + finallyEntry.tryLoc <= arg && + arg <= finallyEntry.finallyLoc) { + // Ignore the finally entry if control is not jumping to a + // location outside the try/catch block. + finallyEntry = null; + } + + var record = finallyEntry ? finallyEntry.completion : {}; + record.type = type; + record.arg = arg; + + if (finallyEntry) { + this.method = "next"; + this.next = finallyEntry.finallyLoc; + return ContinueSentinel; + } + + return this.complete(record); + }, + + complete: function(record, afterLoc) { + if (record.type === "throw") { + throw record.arg; + } + + if (record.type === "break" || + record.type === "continue") { + this.next = record.arg; + } else if (record.type === "return") { + this.rval = this.arg = record.arg; + this.method = "return"; + this.next = "end"; + } else if (record.type === "normal" && afterLoc) { + this.next = afterLoc; + } + + return ContinueSentinel; + }, + + finish: function(finallyLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.finallyLoc === finallyLoc) { + this.complete(entry.completion, entry.afterLoc); + resetTryEntry(entry); + return ContinueSentinel; + } + } + }, + + "catch": function(tryLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc === tryLoc) { + var record = entry.completion; + if (record.type === "throw") { + var thrown = record.arg; + resetTryEntry(entry); + } + return thrown; + } + } + + // The context.catch method must only be called with a location + // argument that corresponds to a known catch block. + throw new Error("illegal catch attempt"); + }, + + delegateYield: function(iterable, resultName, nextLoc) { + this.delegate = { + iterator: values(iterable), + resultName: resultName, + nextLoc: nextLoc + }; + + if (this.method === "next") { + // Deliberately forget the last sent value so that we don't + // accidentally pass it on to the delegate. + this.arg = undefined; + } + + return ContinueSentinel; + } + }; +})( + // In sloppy mode, unbound `this` refers to the global object, fallback to + // Function constructor if we're in global strict mode. That is sadly a form + // of indirect eval which violates Content Security Policy. + (function() { + return this || (typeof self === "object" && self); + })() || Function("return this")() +); + + +/***/ }), + +/***/ "./drawing/draw.js": +/*!*************************!*\ + !*** ./drawing/draw.js ***! + \*************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * This function manages the {@link https://www.w3.org/TR/2dcontext/#the-canvas-state|save/restore} + * pattern for working in a new context state stack. The parameter `fn` is passed the `context` and can + * execute any API calls in a clean stack. + * @public + * @method draw + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target Canvas + * @param {ContextFn} fn - A function which performs drawing operations within the given context. + * @returns {undefined} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (context, fn) { + context.save(); + fn(context); + context.restore(); +}); + +/***/ }), + +/***/ "./drawing/drawArrow.js": +/*!******************************!*\ + !*** ./drawing/drawArrow.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _drawLine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./drawLine.js */ "./drawing/drawLine.js"); +/* harmony import */ var _drawJoinedLines_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./drawJoinedLines.js */ "./drawing/drawJoinedLines.js"); + + +/** + * Draw an arrow using the drawing API. + * @public + * @method drawArrow + * @memberof Drawing + * + * @param {Object} context The canvas context. + * @param {Object} start The start position. + * @param {Object} end The end position. + * @param {string} color The color of the arrow. + * @param {number} lineWidth The width of the arrow line. + * @param {number[] | undefined} [lineDash] The optional lineDash style. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, start, end, color, lineWidth, lineDash) { + // Variables to be used when creating the arrow + var headLength = 10; + var angle = Math.atan2(end.y - start.y, end.x - start.x); // Starting path of the arrow from the start square to the end square and drawing the stroke + + var options = { + color: color, + lineWidth: lineWidth + }; + + if (lineDash) { + options.lineDash = lineDash; + } + + Object(_drawLine_js__WEBPACK_IMPORTED_MODULE_0__["default"])(context, undefined, start, end, options, 'canvas'); + options = { + color: color, + lineWidth: lineWidth, + fillStyle: color + }; + var points = [{ + x: end.x - headLength * Math.cos(angle - Math.PI / 7), + y: end.y - headLength * Math.sin(angle - Math.PI / 7) + }, { + x: end.x - headLength * Math.cos(angle + Math.PI / 7), + y: end.y - headLength * Math.sin(angle + Math.PI / 7) + }, end]; + Object(_drawJoinedLines_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, undefined, end, points, options, 'canvas'); +}); + +/***/ }), + +/***/ "./drawing/drawCircle.js": +/*!*******************************!*\ + !*** ./drawing/drawCircle.js ***! + \*******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); + + +/** + * Draw a circle with given `center` and `radius`. + * @public + * @method drawCircle + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} center - `{ x, y }` in either pixel or canvas coordinates. + * @param {number} radius - The circle's radius in canvas units. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, center, radius, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + + if (coordSystem === 'pixel') { + center = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, center); + } + + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + context.arc(center.x, center.y, radius, 0, 2 * Math.PI); + }); +}); + +/***/ }), + +/***/ "./drawing/drawEllipse.js": +/*!********************************!*\ + !*** ./drawing/drawEllipse.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); +/* harmony import */ var _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/pointProjector.js */ "./util/pointProjector.js"); + + + +/** + * Draw an ellipse within the bounding box defined by `corner1` and `corner2`. + * @public + * @method drawEllipse + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} corner1 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} corner2 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @param {Number} initialRotation - Ellipse initial rotation + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, corner1, corner2, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + var initialRotation = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0.0; + + if (coordSystem === 'pixel') { + corner1 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, corner1); + corner2 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, corner2); + } + + var viewport = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getViewport(element); // Calculate the center of the image + + var width = element.clientWidth, + height = element.clientHeight; + var scale = viewport.scale, + translation = viewport.translation; + var rotation = viewport.rotation - initialRotation; + var centerPoint = { + x: width / 2 + translation.x * scale, + y: height / 2 + translation.y * scale + }; + + if (Math.abs(rotation) > 0.05) { + corner1 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner1, centerPoint, -rotation); + corner2 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner2, centerPoint, -rotation); + } + + var w = Math.abs(corner1.x - corner2.x); + var h = Math.abs(corner1.y - corner2.y); + var xMin = Math.min(corner1.x, corner2.x); + var yMin = Math.min(corner1.y, corner2.y); + var center = { + x: xMin + w / 2, + y: yMin + h / 2 + }; + + if (Math.abs(rotation) > 0.05) { + center = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(center, centerPoint, rotation); + } + + var angle = rotation * Math.PI / 180; + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + context.ellipse(center.x, center.y, w / 2, h / 2, angle, 0, 2 * Math.PI); + context.closePath(); + }); +}); + +/***/ }), + +/***/ "./drawing/drawHandles.js": +/*!********************************!*\ + !*** ./drawing/drawHandles.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); + + + + + +/** + * Draws proivded handles to the provided context + * @public + * @method drawHandles + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {*} evtDetail - Cornerstone's 'cornerstoneimagerendered' event's `detail` + * @param {Object[]|Object} handles - An array of handle objects, or an object w/ named handle objects + * @param {Object} [options={}] - Options object + * @param {string} [options.color] + * @param {Boolean} [options.drawHandlesIfActive=false] - Whether the handles should only be drawn if Active (hovered/selected) + * @param {string} [options.fill] + * @param {Number} [options.handleRadius=6] + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, evtDetail, handles) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + var element = evtDetail.element; + var defaultColor = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__["default"].getToolColor(); + context.strokeStyle = options.color || defaultColor; + var handleKeys = Object.keys(handles); + + var _loop = function _loop(i) { + var handleKey = handleKeys[i]; + var handle = handles[handleKey]; + + if (handle.drawnIndependently === true) { + return "continue"; + } + + if (options.drawHandlesIfActive === true && !handle.active) { + return "continue"; + } + + if (options.hideHandlesIfMoving && handle.moving) { + return "continue"; + } + + var lineWidth = handle.active ? _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_1__["default"].getActiveWidth() : _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_1__["default"].getToolWidth(); + var fillStyle = options.fill; + var pathOptions = { + lineWidth: lineWidth, + fillStyle: fillStyle + }; + + if (options.lineDash) { + pathOptions.lineDash = options.lineDash; + } + + Object(_path_js__WEBPACK_IMPORTED_MODULE_3__["default"])(context, pathOptions, function (context) { + var handleCanvasCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, handle); // Handle's radisu, then tool's radius, then default radius + + var handleRadius = handle.radius || options.handleRadius || _store_index_js__WEBPACK_IMPORTED_MODULE_4__["state"].handleRadius; + context.arc(handleCanvasCoords.x, handleCanvasCoords.y, handleRadius, 0, 2 * Math.PI); + }); + }; + + for (var i = 0; i < handleKeys.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } +}); + +/***/ }), + +/***/ "./drawing/drawJoinedLines.js": +/*!************************************!*\ + !*** ./drawing/drawJoinedLines.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); + + +/** + * Draw a series of joined lines, starting at `start` and then going to each point in `points`. + * @public + * @method drawJoinedLines + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} start - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object[]} points - `[{ x, y }]` An array of points in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, start, points, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + if (coordSystem === 'pixel') { + start = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, start); + points = points.map(function (p) { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, p); + }); + } + + context.moveTo(start.x, start.y); + points.forEach(function (_ref) { + var x = _ref.x, + y = _ref.y; + context.lineTo(x, y); + }); + }); +}); + +/***/ }), + +/***/ "./drawing/drawLine.js": +/*!*****************************!*\ + !*** ./drawing/drawLine.js ***! + \*****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return drawLine; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); + + +/** + * Draw a line between `start` and `end`. + * + * @public + * @method drawLine + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} start - `{ x, y } in either pixel or canvas coordinates. + * @param {Object} end - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @returns {undefined} + */ + +function drawLine(context, element, start, end, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + if (coordSystem === 'pixel') { + start = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, start); + end = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas(element, end); + } + + context.moveTo(start.x, start.y); + context.lineTo(end.x, end.y); + }); +} + +/***/ }), + +/***/ "./drawing/drawLines.js": +/*!******************************!*\ + !*** ./drawing/drawLines.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); + + +/** + * Draw multiple lines. + * @public + * @method drawJoinedLines + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object[]} lines - `[{ start: {x, y}, end: { x, y }]` An array of `start`, `end` pairs. + * Each point is `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, lines, options) { + var coordSystem = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'pixel'; + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + lines.forEach(function (line) { + var start = line.start; + var end = line.end; + + if (coordSystem === 'pixel') { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + start = cornerstone.pixelToCanvas(element, start); + end = cornerstone.pixelToCanvas(element, end); + } + + context.moveTo(start.x, start.y); + context.lineTo(end.x, end.y); + }); + }); +}); + +/***/ }), + +/***/ "./drawing/drawLink.js": +/*!*****************************!*\ + !*** ./drawing/drawLink.js ***! + \*****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _drawLine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./drawLine.js */ "./drawing/drawLine.js"); + + +/** + * Draw a link between an annotation to a box. + * @public + * @method drawLink + * @memberof Drawing + * + * @param {Object[]} linkAnchorPoints An array of possible anchor points. + * @param {Object} refPoint A reference point to select the anchor point. + * @param {Object} boundingBox The bounding box to link. + * @param {Object} context The canvas context. + * @param {string} color The link color. + * @param {number} lineWidth The line width of the link. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (linkAnchorPoints, refPoint, boundingBox, context, color, lineWidth) { + // Draw a link from "the closest anchor point to refPoint" to "the nearest midpoint on the bounding box". + // Find the closest anchor point to RefPoint + var start = linkAnchorPoints.length > 0 ? _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.findClosestPoint(linkAnchorPoints, refPoint) : refPoint; // Calculate the midpoints of the bounding box + + var boundingBoxPoints = [{ + x: boundingBox.left + boundingBox.width / 2, + y: boundingBox.top + }, { + x: boundingBox.left, + y: boundingBox.top + boundingBox.height / 2 + }, { + x: boundingBox.left + boundingBox.width / 2, + y: boundingBox.top + boundingBox.height + }, { + x: boundingBox.left + boundingBox.width, + y: boundingBox.top + boundingBox.height / 2 + }]; // Calculate the link endpoint by identifying which midpoint of the bounding box + // Is closest to the start point. + + var end = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.findClosestPoint(boundingBoxPoints, start); // Finally we draw the dashed linking line + + var options = { + color: color, + lineWidth: lineWidth, + lineDash: [2, 3] + }; + Object(_drawLine_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, undefined, start, end, options, 'canvas'); +}); + +/***/ }), + +/***/ "./drawing/drawLinkedTextBox.js": +/*!**************************************!*\ + !*** ./drawing/drawLinkedTextBox.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _drawTextBox_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _drawLink_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./drawLink.js */ "./drawing/drawLink.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); + + + + + +/** + * Draw a link between an annotation to a textBox. + * @public + * @method drawLinkedTextBox + * @memberof Drawing + * + * @param {Object} context - The canvas context. + * @param {HTMLElement} element - The element on which to draw the link. + * @param {Object} textBox - The textBox to link. + * @param {Object} text - The text to display in the textbox. + * @param {Object[]} handles - The handles of the annotation. + * @param {Object[]} textBoxAnchorPoints - An array of possible anchor points on the textBox. + * @param {string} color - The link color. + * @param {number} lineWidth - The line width of the link. + * @param {number} xOffset - The x offset of the textbox. + * @param {boolean} yCenter - Vertically centers the text if true. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, textBox, text, handles, textBoxAnchorPoints, color, lineWidth, xOffset, yCenter) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pixelToCanvas; // Convert the textbox Image coordinates into Canvas coordinates + + var textCoords = pixelToCanvas(element, textBox); + + if (xOffset) { + textCoords.x += xOffset; + } + + var options = { + centering: { + x: false, + y: yCenter + } + }; // Clip the bounding box to the displayed area of the image + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_3__["state"].preventTextBoxOutsideDisplayedArea) { + options.displacer = function (box) { + return Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_4__["clipBoxToDisplayedArea"])(element, box); + }; + } // Draw the text box + + + textBox.boundingBox = Object(_drawTextBox_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, text, textCoords.x, textCoords.y, color, options); + + if (textBox.hasMoved) { + // Identify the possible anchor points for the tool -> text line + var linkAnchorPoints = textBoxAnchorPoints(handles).map(function (h) { + return pixelToCanvas(element, h); + }); // Draw dashed link line between tool and text + + Object(_drawLink_js__WEBPACK_IMPORTED_MODULE_2__["default"])(linkAnchorPoints, textCoords, textBox.boundingBox, context, color, lineWidth); + } +}); + +/***/ }), + +/***/ "./drawing/drawRect.js": +/*!*****************************!*\ + !*** ./drawing/drawRect.js ***! + \*****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); +/* harmony import */ var _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/pointProjector.js */ "./util/pointProjector.js"); + + + +/** + * Draw a rectangle defined by `corner1` and `corner2`. + * @public + * @method drawRect + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} corner1 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} corner2 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @param {Number} initialRotation - Rectangle initial rotation + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, corner1, corner2, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + var initialRotation = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0.0; + + if (coordSystem === 'pixel') { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + corner1 = cornerstone.pixelToCanvas(element, corner1); + corner2 = cornerstone.pixelToCanvas(element, corner2); + } + + var viewport = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getViewport(element); // Calculate the center of the image + + var width = element.clientWidth, + height = element.clientHeight; + var scale = viewport.scale, + translation = viewport.translation; + var rotation = viewport.rotation - initialRotation; + var centerPoint = { + x: width / 2 + translation.x * scale, + y: height / 2 + translation.y * scale + }; + + if (Math.abs(rotation) > 0.05) { + corner1 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner1, centerPoint, -rotation); + corner2 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner2, centerPoint, -rotation); + } + + var w = Math.abs(corner1.x - corner2.x); + var h = Math.abs(corner1.y - corner2.y); + corner1 = { + x: Math.min(corner1.x, corner2.x), + y: Math.min(corner1.y, corner2.y) + }; + corner2 = { + x: corner1.x + w, + y: corner1.y + h + }; + var corner3 = { + x: corner1.x + w, + y: corner1.y + }; + var corner4 = { + x: corner1.x, + y: corner1.y + h + }; + + if (Math.abs(rotation) > 0.05) { + corner1 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner1, centerPoint, rotation); + corner2 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner2, centerPoint, rotation); + corner3 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner3, centerPoint, rotation); + corner4 = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_2__["rotatePoint"])(corner4, centerPoint, rotation); + } + + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + context.moveTo(corner1.x, corner1.y); + context.lineTo(corner3.x, corner3.y); + context.lineTo(corner2.x, corner2.y); + context.lineTo(corner4.x, corner4.y); + context.lineTo(corner1.x, corner1.y); + }); +}); + +/***/ }), + +/***/ "./drawing/drawTextBox.js": +/*!********************************!*\ + !*** ./drawing/drawTextBox.js ***! + \********************************/ +/*! exports provided: textBoxWidth, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textBoxWidth", function() { return textBoxWidth; }); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony import */ var _draw_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./draw.js */ "./drawing/draw.js"); +/* harmony import */ var _fillTextLines_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./fillTextLines.js */ "./drawing/fillTextLines.js"); +/* harmony import */ var _fillBox_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./fillBox.js */ "./drawing/fillBox.js"); + + + + +/** + * Compute the width of the box required to display the given `text` with a given `padding`. + * @public + * @function textBoxWidth + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {String} text - The text to find the width of. + * @param {Number} padding - The padding to apply on either end of the text. + * @returns {Number} computed text box width + */ + +function textBoxWidth(context, text, padding) { + var font = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getFont(); + var origFont = context.font; + + if (font && font !== origFont) { + context.font = font; + } + + var width = context.measureText(text).width; + + if (font && font !== origFont) { + context.font = origFont; + } + + return width + 2 * padding; +} +/** + * Draws a textBox. + * @public + * @function drawTextBox + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context The canvas context. + * @param {string} textLines The text to display. + * @param {number} x The x position of the textBox. + * @param {number} y The y position of the textBox. + * @param {string} color The color of the textBox. + * @param {Object} options Options for the textBox. + * @param {boolean} options.centering Option to center the textbox. + * @param {function} options.displacer displacer function. + * @returns {Object} {top, left, width, height} - Bounding box; can be used for pointNearTool + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, textLines, x, y, color) { + var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + + if (Object.prototype.toString.call(textLines) !== '[object Array]') { + textLines = [textLines]; + } + + var padding = 5; + var fontSize = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getFontSize(); + var backgroundColor = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getBackgroundColor(); // Find the longest text width in the array of text data + + var maxWidth = 0; + textLines.forEach(function (text) { + // Get the text width in the current font + var width = textBoxWidth(context, text, padding); // Find the maximum with for all the text rows; + + maxWidth = Math.max(maxWidth, width); + }); // Calculate the bounding box for this text box + + var boundingBox = { + width: maxWidth, + height: padding + textLines.length * (fontSize + padding) + }; + Object(_draw_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, function (context) { + context.strokeStyle = color; // Draw the background box with padding + + if (options.centering) { + if (options.centering.x === true) { + x -= boundingBox.width / 2; + } + + if (options.centering.y === true) { + y -= boundingBox.height / 2; + } + } + + boundingBox.left = x; + boundingBox.top = y; // Check if a displacer function was provided + + if (typeof options.displacer === 'function') { + options.displacer(boundingBox); + } + + Object(_fillBox_js__WEBPACK_IMPORTED_MODULE_3__["default"])(context, boundingBox, backgroundColor); // Draw each of the text lines on top of the background box + + Object(_fillTextLines_js__WEBPACK_IMPORTED_MODULE_2__["default"])(context, boundingBox, textLines, color, padding); + }); // Return the bounding box so it can be used for pointNearHandle + + return boundingBox; +}); + +/***/ }), + +/***/ "./drawing/fillBox.js": +/*!****************************!*\ + !*** ./drawing/fillBox.js ***! + \****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Draw a filled rectangle defined by `boundingBox` using the style defined by `fillStyle`. + * @public + * @method fillBox + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {Object} boundingBox - `{ left, top, width, height }` in canvas coordinates. + * @param {FillStyle} fillStyle - The fillStyle to apply to the region. + * @returns {undefined} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (context, boundingBox, fillStyle) { + context.fillStyle = fillStyle; + context.fillRect(boundingBox.left, boundingBox.top, boundingBox.width, boundingBox.height); +}); + +/***/ }), + +/***/ "./drawing/fillOutsideRect.js": +/*!************************************!*\ + !*** ./drawing/fillOutsideRect.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); + + +/** + * Fill the region outside a rectangle defined by `corner1` and `corner2`. + * @public + * @method fillOutsideRect + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {HTMLElement} element - The DOM Element to draw on + * @param {Object} corner1 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} corner2 - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} options - See {@link path} + * @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate + * system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas + * is used to transform the points from pixel to canvas coordinates. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, element, corner1, corner2, options) { + var coordSystem = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'pixel'; + + if (coordSystem === 'pixel') { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + corner1 = cornerstone.pixelToCanvas(element, corner1); + corner2 = cornerstone.pixelToCanvas(element, corner2); + } + + var left = Math.min(corner1.x, corner2.x); + var top = Math.min(corner1.y, corner2.y); + var width = Math.abs(corner1.x - corner2.x); + var height = Math.abs(corner1.y - corner2.y); + Object(_path_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, options, function (context) { + context.rect(0, 0, context.canvas.clientWidth, context.canvas.clientHeight); + context.rect(left + width, top, -width, height); + }); +}); + +/***/ }), + +/***/ "./drawing/fillTextLines.js": +/*!**********************************!*\ + !*** ./drawing/fillTextLines.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); + +/** + * Draw multiple lines of text within a bounding box. + * @public + * @method fillTextLines + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Target context + * @param {Object} boundingBox - `{ left, top }` in canvas coordinates. Only the top-left corner is specified, as the text will take up as much space as it needs. + * @param {String[]} textLines - The text to be displayed. + * @param {FillStyle} fillStyle - The fillStyle to apply to the text. + * @param {Number} padding - The amount of padding above/below each line in canvas units. Note this gives an inter-line spacing of `2*padding`. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, boundingBox, textLines, fillStyle, padding) { + var fontSize = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getFontSize(); + context.font = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getFont(); + context.textBaseline = 'top'; + context.fillStyle = fillStyle; + textLines.forEach(function (text, index) { + context.fillText(text, boundingBox.left + padding, boundingBox.top + padding + index * (fontSize + padding)); + }); +}); + +/***/ }), + +/***/ "./drawing/getNewContext.js": +/*!**********************************!*\ + !*** ./drawing/getNewContext.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Create a new {@link CanvasRenderingContext2D|context} object for the given {@link HTMLCanvasElement|canvas} + * and set the transform to the {@link https://www.w3.org/TR/2dcontext/#transformations|identity transform}. + * + * @public + * @function getNewContext + * @memberof Drawing + * + * @param {HTMLCanvasElement} canvas - Canvas you would like the context for + * @returns {CanvasRenderingContext2D} - The provided canvas's 2d context + */ +/* harmony default export */ __webpack_exports__["default"] = (function (canvas) { + var context = canvas.getContext('2d'); + context.setTransform(1, 0, 0, 1, 0, 0); + return context; +}); + +/***/ }), + +/***/ "./drawing/index.js": +/*!**************************!*\ + !*** ./drawing/index.js ***! + \**************************/ +/*! exports provided: draw, drawArrow, drawCircle, drawEllipse, drawHandles, drawJoinedLines, drawLine, drawLines, drawLink, drawLinkedTextBox, drawRect, drawTextBox, fillBox, fillOutsideRect, fillTextLines, getNewContext, path, setShadow, transformCanvasContext, resetCanvasContextTransform */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _draw_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./draw.js */ "./drawing/draw.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "draw", function() { return _draw_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _drawArrow_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./drawArrow.js */ "./drawing/drawArrow.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawArrow", function() { return _drawArrow_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _drawCircle_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./drawCircle.js */ "./drawing/drawCircle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawCircle", function() { return _drawCircle_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _drawEllipse_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./drawEllipse.js */ "./drawing/drawEllipse.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawEllipse", function() { return _drawEllipse_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _drawHandles_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawHandles", function() { return _drawHandles_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony import */ var _drawJoinedLines_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./drawJoinedLines.js */ "./drawing/drawJoinedLines.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawJoinedLines", function() { return _drawJoinedLines_js__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + +/* harmony import */ var _drawLine_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./drawLine.js */ "./drawing/drawLine.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawLine", function() { return _drawLine_js__WEBPACK_IMPORTED_MODULE_6__["default"]; }); + +/* harmony import */ var _drawLines_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./drawLines.js */ "./drawing/drawLines.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawLines", function() { return _drawLines_js__WEBPACK_IMPORTED_MODULE_7__["default"]; }); + +/* harmony import */ var _drawLink_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./drawLink.js */ "./drawing/drawLink.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawLink", function() { return _drawLink_js__WEBPACK_IMPORTED_MODULE_8__["default"]; }); + +/* harmony import */ var _drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawLinkedTextBox", function() { return _drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_9__["default"]; }); + +/* harmony import */ var _drawRect_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./drawRect.js */ "./drawing/drawRect.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawRect", function() { return _drawRect_js__WEBPACK_IMPORTED_MODULE_10__["default"]; }); + +/* harmony import */ var _drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawTextBox", function() { return _drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__["default"]; }); + +/* harmony import */ var _fillBox_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./fillBox.js */ "./drawing/fillBox.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillBox", function() { return _fillBox_js__WEBPACK_IMPORTED_MODULE_12__["default"]; }); + +/* harmony import */ var _fillOutsideRect_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./fillOutsideRect.js */ "./drawing/fillOutsideRect.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideRect", function() { return _fillOutsideRect_js__WEBPACK_IMPORTED_MODULE_13__["default"]; }); + +/* harmony import */ var _fillTextLines_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./fillTextLines.js */ "./drawing/fillTextLines.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillTextLines", function() { return _fillTextLines_js__WEBPACK_IMPORTED_MODULE_14__["default"]; }); + +/* harmony import */ var _getNewContext_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./getNewContext.js */ "./drawing/getNewContext.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getNewContext", function() { return _getNewContext_js__WEBPACK_IMPORTED_MODULE_15__["default"]; }); + +/* harmony import */ var _path_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./path.js */ "./drawing/path.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "path", function() { return _path_js__WEBPACK_IMPORTED_MODULE_16__["default"]; }); + +/* harmony import */ var _setShadow_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./setShadow.js */ "./drawing/setShadow.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setShadow", function() { return _setShadow_js__WEBPACK_IMPORTED_MODULE_17__["default"]; }); + +/* harmony import */ var _transformCanvasContext_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./transformCanvasContext.js */ "./drawing/transformCanvasContext.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "transformCanvasContext", function() { return _transformCanvasContext_js__WEBPACK_IMPORTED_MODULE_18__["default"]; }); + +/* harmony import */ var _resetCanvasContextTransform_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./resetCanvasContextTransform.js */ "./drawing/resetCanvasContextTransform.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "resetCanvasContextTransform", function() { return _resetCanvasContextTransform_js__WEBPACK_IMPORTED_MODULE_19__["default"]; }); + +/** + * A {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|color, gradient or pattern} to use inside shapes. + * @typedef {(String|CanvasGradient|CanvasPattern)} FillStyle + */ + +/** + * A {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle|color, gradient or pattern} to use for the lines around shapes. + * @typedef {(String|CanvasGradient|CanvasPattern)} StrokeStyle + */ + +/** + * @callback ContextFn + * @param {CanvasRenderingContext2D} context + */ + + + + + + + + + + + + + + + + + + + + // Named exports + + + +/***/ }), + +/***/ "./drawing/path.js": +/*!*************************!*\ + !*** ./drawing/path.js ***! + \*************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); + +/** + * This function manages the beginPath/stroke pattern for working with + * {@link https://www.w3.org/TR/2dcontext/#drawing-paths-to-the-canvas|path objects}. + * + * @public + * @function path + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Context to add path to + * @param {Object} [options={}] - Drawing Options + * @param {StrokeStyle} [options.color] - The stroke style of the path. + * @param {number} [options.lineWidth] - The width of lines in the path. If null, no line width is set. + * If undefined then toolStyle.getToolWidth() is set. + * @param {FillStyle} [options.fillStyle] - The style to fill the path with. If undefined then no filling is done. + * @param {Number[]} [options.lineDash] - The {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash|dash pattern} + * to use on the lines. + * @param {boolean} [options.shouldDrawLines = true] Whether context.stroke should be evoked. + * @param {ContextFn} fn - A drawing function to execute with the provided stroke pattern. + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var fn = arguments.length > 2 ? arguments[2] : undefined; + var color = options.color, + lineWidth = options.lineWidth, + fillStyle = options.fillStyle, + lineDash = options.lineDash, + _options$shouldDrawLi = options.shouldDrawLines, + shouldDrawLines = _options$shouldDrawLi === void 0 ? true : _options$shouldDrawLi; + context.beginPath(); + context.strokeStyle = color || context.strokeStyle; + context.lineWidth = lineWidth || lineWidth === undefined && _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_0__["default"].getToolWidth() || context.lineWidth; + + if (lineDash) { + context.setLineDash(lineDash); + } + + fn(context); + + if (fillStyle) { + context.fillStyle = fillStyle; + context.fill(); + } + + if (shouldDrawLines) { + context.stroke(); + } + + if (lineDash) { + context.setLineDash([]); + } +}); + +/***/ }), + +/***/ "./drawing/resetCanvasContextTransform.js": +/*!************************************************!*\ + !*** ./drawing/resetCanvasContextTransform.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Resets the canvas {@link CanvasRenderingContext2D|context} transform to the + * {@link https://www.w3.org/TR/2dcontext/#transformations|identity transform}. + * + * @public + * @function resetCanvasContextTransform + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - context you wish to transform + * @returns {void} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (context) { + context.setTransform(1, 0, 0, 1, 0, 0); +}); + +/***/ }), + +/***/ "./drawing/setShadow.js": +/*!******************************!*\ + !*** ./drawing/setShadow.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _util_getDefault_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../util/getDefault.js */ "./util/getDefault.js"); + +/** + * Set the {@link https://www.w3.org/TR/2dcontext/#shadows|shadow} properties of the context. + * Each property is set on the context object if defined, otherwise a default value is set. + * + * @public + * @method setShadow + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Context to apply shadow options on + * @param {Object} [options={}] - Options object + * @param {Boolean} [options.shadow=undefined] - Whether to set any shadow options + * @param {String} [options.shadowColor=#000000] - Default value: #000000 + * @param {Number} [options.shadowBlur=0] - Default Value: 0 + * @param {Number} [options.shadowOffsetX=1] - Default value: 1 + * @param {Number} [options.shadowOffsetY=1] - Default value: 1 + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (options.shadow) { + context.shadowColor = Object(_util_getDefault_js__WEBPACK_IMPORTED_MODULE_0__["default"])(options.shadowColor, '#000000'); + context.shadowBlur = Object(_util_getDefault_js__WEBPACK_IMPORTED_MODULE_0__["default"])(options.shadowBlur, 0); + context.shadowOffsetX = Object(_util_getDefault_js__WEBPACK_IMPORTED_MODULE_0__["default"])(options.shadowOffsetX, 1); + context.shadowOffsetY = Object(_util_getDefault_js__WEBPACK_IMPORTED_MODULE_0__["default"])(options.shadowOffsetY, 1); + } +}); + +/***/ }), + +/***/ "./drawing/transformCanvasContext.js": +/*!*******************************************!*\ + !*** ./drawing/transformCanvasContext.js ***! + \*******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Transform the canvas {@link CanvasRenderingContext2D|context} such that it + * coincides with the orientation of the viewport. + * + * @public + * @function transformCanvasContext + * @memberof Drawing + * + * @param {CanvasRenderingContext2D} context - Context you wish to transform. + * @param {HTMLCanvasElement} canvas - Canvas the context relates to. + * @param {*} viewport - The viewport you wish to map on to. + * @returns {void} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (context, canvas, viewport) { + if (!(viewport.hflip || viewport.vflip || viewport.rotation)) { + return; + } + + var translation = { + x: canvas.width / 2 + viewport.translation.x * viewport.scale, + y: canvas.height / 2 + viewport.translation.y * viewport.scale + }; + context.translate(translation.x, translation.y); + + if (viewport.rotation) { + context.rotate(viewport.rotation * Math.PI / 180); + } + + if (viewport.vflip) { + context.scale(1, -1); + } + + if (viewport.hflip) { + context.scale(-1, 1); + } + + context.translate(-translation.x, -translation.y); +}); + +/***/ }), + +/***/ "./eventDispatchers/imageRenderedEventDispatcher.js": +/*!**********************************************************!*\ + !*** ./eventDispatchers/imageRenderedEventDispatcher.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _stateManagement_toolState__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState */ "./stateManagement/toolState.js"); +/* harmony import */ var _eventListeners_onImageRenderedBrushEventHandler_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../eventListeners/onImageRenderedBrushEventHandler.js */ "./eventListeners/onImageRenderedBrushEventHandler.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); + + + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'); + +var onImageRendered = function onImageRendered(evt) { + var eventData = evt.detail; + var element = eventData.element; // Render Annotation Tools + + var toolsToRender = _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].tools.filter(function (tool) { + return tool.element === element && (tool.mode === 'active' || tool.mode === 'passive' || tool.mode === 'enabled'); + }); // Must be using stacks in order to use segmentation tools. + + var stackToolState = Object(_stateManagement_toolState__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var segmentationConfiguration = segmentationModule.configuration; + + if (stackToolState && (segmentationConfiguration.renderFill || segmentationConfiguration.renderOutline)) { + Object(_eventListeners_onImageRenderedBrushEventHandler_js__WEBPACK_IMPORTED_MODULE_2__["default"])(evt); + } + + var context = eventData.canvasContext.canvas.getContext('2d'); + toolsToRender.forEach(function (tool) { + if (tool.renderToolData) { + context.save(); + tool.renderToolData(evt); + context.restore(); + } + }); +}; + +var enable = function enable(element) { + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.EVENTS.IMAGE_RENDERED, onImageRendered); +}; + +var disable = function disable(element) { + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.EVENTS.IMAGE_RENDERED, onImageRendered); +}; + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventDispatchers/index.js": +/*!***********************************!*\ + !*** ./eventDispatchers/index.js ***! + \***********************************/ +/*! exports provided: imageRenderedEventDispatcher, mouseToolEventDispatcher, newImageEventDispatcher, touchToolEventDispatcher */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _imageRenderedEventDispatcher_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./imageRenderedEventDispatcher.js */ "./eventDispatchers/imageRenderedEventDispatcher.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "imageRenderedEventDispatcher", function() { return _imageRenderedEventDispatcher_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _mouseToolEventDispatcher_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mouseToolEventDispatcher.js */ "./eventDispatchers/mouseToolEventDispatcher.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseToolEventDispatcher", function() { return _mouseToolEventDispatcher_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _newImageEventDispatcher_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./newImageEventDispatcher.js */ "./eventDispatchers/newImageEventDispatcher.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "newImageEventDispatcher", function() { return _newImageEventDispatcher_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _touchToolEventDispatcher_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./touchToolEventDispatcher.js */ "./eventDispatchers/touchToolEventDispatcher.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "touchToolEventDispatcher", function() { return _touchToolEventDispatcher_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + + + + + + + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/addNewMeasurement.js": +/*!******************************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/addNewMeasurement.js ***! + \******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../util/triggerEvent.js */ "./util/triggerEvent.js"); + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('eventDispatchers:mouseEventHandlers'); +/* harmony default export */ __webpack_exports__["default"] = (function (evt, tool) { + logger.log('addNewMeasurement'); + evt.preventDefault(); + evt.stopPropagation(); + var eventData = evt.detail; + var element = eventData.element; + var measurementData = tool.createNewMeasurement(eventData); + + if (!measurementData) { + return; + } + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["addToolState"])(element, tool.name, measurementData); + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + var handleMover = Object.keys(measurementData.handles).length === 1 ? _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveHandle"] : _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveNewHandle"]; + handleMover(eventData, tool.name, measurementData, measurementData.handles.end, tool.options, 'mouse', function (success) { + if (measurementData.cancelled) { + return; + } + + if (success) { + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_COMPLETED; + var _eventData = { + toolName: tool.name, + toolType: tool.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, eventType, _eventData); + } else { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["removeToolState"])(element, tool.name, measurementData); + } + }); +}); + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/index.js": +/*!******************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/index.js ***! + \******************************************************/ +/*! exports provided: mouseClick, mouseDown, mouseDownActivate, mouseDoubleClick, mouseDrag, mouseMove, mouseUp, mouseWheel */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mouseClick", function() { return mouseClick; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mouseDoubleClick", function() { return mouseDoubleClick; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mouseUp", function() { return mouseUp; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mouseWheel", function() { return mouseWheel; }); +/* harmony import */ var _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../shared/customCallbackHandler.js */ "./eventDispatchers/shared/customCallbackHandler.js"); +/* harmony import */ var _mouseDown_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mouseDown.js */ "./eventDispatchers/mouseEventHandlers/mouseDown.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseDown", function() { return _mouseDown_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _mouseDownActivate_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./mouseDownActivate.js */ "./eventDispatchers/mouseEventHandlers/mouseDownActivate.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseDownActivate", function() { return _mouseDownActivate_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _mouseDrag_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./mouseDrag.js */ "./eventDispatchers/mouseEventHandlers/mouseDrag.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseDrag", function() { return _mouseDrag_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _mouseMove_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./mouseMove.js */ "./eventDispatchers/mouseEventHandlers/mouseMove.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseMove", function() { return _mouseMove_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + + + + + + +var mouseClick = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Mouse', 'mouseClickCallback'); +var mouseDoubleClick = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Mouse', 'doubleClickCallback'); +var mouseUp = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Mouse', 'mouseUpCallback'); +var mouseWheel = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'MouseWheel', 'mouseWheelCallback'); + + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/mouseDown.js": +/*!**********************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/mouseDown.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _store_getToolsWithMoveableHandles_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/getToolsWithMoveableHandles.js */ "./store/getToolsWithMoveableHandles.js"); +/* harmony import */ var _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../util/findAndMoveHelpers.js */ "./util/findAndMoveHelpers.js"); +/* harmony import */ var _store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../store/getInteractiveToolsForElement.js */ "./store/getInteractiveToolsForElement.js"); +/* harmony import */ var _store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../store/getToolsWithDataForElement.js */ "./store/getToolsWithDataForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../store/filterToolsUsableWithMultiPartTools.js */ "./store/filterToolsUsableWithMultiPartTools.js"); +// State + + // Util + + + + + + +/** + * MouseDown is called before MouseDownActivate. If MouseDown + * finds an existing tool to interact with, it can prevent the + * event from bubbling to MouseDownActivate. + * + * @private + * @param {mousedown} evt + * @listens {CornerstoneTools.event:cornerstonetoolsmousedown} + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return; + } + + var eventData = evt.detail; + var element = evt.detail.element; + var coords = evt.detail.currentPoints.canvas; // High level filtering + + var activeAndPassiveTools = Object(_store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_0__["getters"].mouseTools()); // ACTIVE TOOL W/ PRE CALLBACK? + // Note: In theory, this should only ever be a single tool. + + var activeTools = activeAndPassiveTools.filter(function (tool) { + return tool.mode === 'active' && Array.isArray(tool.options.mouseButtonMask) && tool.options.mouseButtonMask.includes(eventData.buttons) && tool.options.isMouseActive; + }); + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + activeTools = Object(_store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_6__["default"])(activeTools); + } // If any tools are active, check if they have a special reason for dealing with the event. + + + if (activeTools.length > 0) { + // TODO: If length > 1, you could assess fitness and select the ideal tool + // TODO: But because we're locking this to 'active' tools, that should rarely be an issue + // Super-Meta-TODO: ^ I think we should just take the approach of one active tool per mouse button? + var firstActiveToolWithCallback = activeTools.find(function (tool) { + return typeof tool.preMouseDownCallback === 'function'; + }); + + if (firstActiveToolWithCallback) { + var consumedEvent = firstActiveToolWithCallback.preMouseDownCallback(evt); + + if (consumedEvent) { + return; + } + } + } + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + // Don't fire events to Annotation Tools during a multi part loop. + return; + } // Annotation tool specific + + + var annotationTools = Object(_store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, activeAndPassiveTools); // NEAR HANDLES? + + var annotationToolsWithMoveableHandles = Object(_store_getToolsWithMoveableHandles_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, annotationTools, coords, 'mouse'); + + if (annotationToolsWithMoveableHandles.length > 0) { + var firstToolWithMoveableHandles = annotationToolsWithMoveableHandles[0]; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, firstToolWithMoveableHandles.name); + + var _findHandleDataNearIm = Object(_util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_3__["findHandleDataNearImagePoint"])(element, toolState, firstToolWithMoveableHandles.name, coords), + handle = _findHandleDataNearIm.handle, + data = _findHandleDataNearIm.data; + + firstToolWithMoveableHandles.handleSelectedCallback(evt, data, handle, 'mouse'); + return; + } // NEAR TOOL? + + + var annotationToolsWithPointNearClick = activeAndPassiveTools.filter(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, tool.name); + var isNearPoint = toolState && toolState.data && tool.pointNearTool && toolState.data.some(function (data) { + return tool.pointNearTool(element, data, coords, 'mouse'); + }); + return isNearPoint; + }); + + if (annotationToolsWithPointNearClick.length > 0) { + var firstToolNearPoint = annotationToolsWithPointNearClick[0]; + + var _toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, firstToolNearPoint.name); + + var firstAnnotationNearPoint = _toolState.data.find(function (data) { + return firstToolNearPoint.pointNearTool(element, data, coords); + }); + + firstToolNearPoint.toolSelectedCallback(evt, firstAnnotationNearPoint, 'mouse'); + return; + } // ACTIVE TOOL W/ POST CALLBACK? + // If any tools are active, check if they have a special reason for dealing with the event. + + + if (activeTools.length > 0) { + // TODO: If length > 1, you could assess fitness and select the ideal tool + // TODO: But because we're locking this to 'active' tools, that should rarely be an issue + // Super-Meta-TODO: ^ I think we should just take the approach of one active tool per mouse button? + var _firstActiveToolWithCallback = activeTools.find(function (tool) { + return typeof tool.postMouseDownCallback === 'function'; + }); + + if (_firstActiveToolWithCallback) { + var _consumedEvent = _firstActiveToolWithCallback.postMouseDownCallback(evt); + + if (_consumedEvent) { + return; + } + } + } +}); + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/mouseDownActivate.js": +/*!******************************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/mouseDownActivate.js ***! + \******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./addNewMeasurement.js */ "./eventDispatchers/mouseEventHandlers/addNewMeasurement.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../tools/base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../util/getActiveTool */ "./util/getActiveTool.js"); + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked) { + return; + } + + var _evt$detail = evt.detail, + element = _evt$detail.element, + buttons = _evt$detail.buttons; + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_3__["default"])(element, buttons, 'mouse'); + + if (!activeTool) { + return; + } + + if (typeof activeTool.preMouseDownActivateCallback === 'function') { + var consumedEvent = activeTool.preMouseDownActivateCallback(evt); + + if (consumedEvent) { + return; + } + } + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isMultiPartToolActive) { + return; + } // Note: custom `addNewMeasurement` will need to prevent event bubbling + + + if (activeTool.addNewMeasurement) { + activeTool.addNewMeasurement(evt, 'mouse'); + } else if (activeTool instanceof _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_2__["default"]) { + Object(_addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_0__["default"])(evt, activeTool); + } +}); + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/mouseDrag.js": +/*!**********************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/mouseDrag.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../store/getActiveToolsForElement.js */ "./store/getActiveToolsForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../store/filterToolsUsableWithMultiPartTools.js */ "./store/filterToolsUsableWithMultiPartTools.js"); + + + // Tools like wwwc. Non-annotation tools w/ specific +// Down + mouse behavior +// TODO: I don't like filtering in drag because it's such +// A high frequency event. Anything we can do to reduce +// Repeat math here would be a big help + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return; + } + + var tools; + var eventData = evt.detail; + var element = eventData.element; // Filter out disabled, enabled, and passive + + tools = Object(_store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_0__["getters"].mouseTools()); + tools = tools.filter(function (tool) { + return Array.isArray(tool.options.mouseButtonMask) && tool.options.mouseButtonMask.includes(eventData.buttons) && tool.options.isMouseActive; + }); + tools = tools.filter(function (tool) { + return typeof tool.mouseDragCallback === 'function'; + }); + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + tools = Object(_store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__["default"])(tools); + } + + if (tools.length === 0) { + return; + } + + var activeTool = tools[0]; + activeTool.mouseDragCallback(evt); +}); + +/***/ }), + +/***/ "./eventDispatchers/mouseEventHandlers/mouseMove.js": +/*!**********************************************************!*\ + !*** ./eventDispatchers/mouseEventHandlers/mouseMove.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../store/getInteractiveToolsForElement.js */ "./store/getInteractiveToolsForElement.js"); +/* harmony import */ var _store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../store/getToolsWithDataForElement.js */ "./store/getToolsWithDataForElement.js"); + // State + + + + +/** + * This is mostly used to update the [un]hover state + * of a tool. + * + * @private + * @param {*} evt + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked || _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isMultiPartToolActive) { + return; + } + + var tools; + var _evt$detail = evt.detail, + element = _evt$detail.element, + currentPoints = _evt$detail.currentPoints; // Set the mouse position incase any tool needs it. + + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].mousePositionImage = currentPoints.image; // TODO: instead of filtering these for every interaction, we can change our + // TODO: State's structure to always know these values. + // Filter out disabled and enabled + + tools = Object(_store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_1__["getters"].mouseTools()); + var activeTools = tools.filter(function (tool) { + return tool.mode === 'active' && tool.options.isMouseActive; + }); + var imageNeedsUpdate = false; // If any tools are active, check if they have a canvas cursor, and if so update image. + + if (activeTools.length > 0) { + imageNeedsUpdate = activeTools.some(function (tool) { + return tool.updateOnMouseMove; + }); + } + + tools = Object(_store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, tools); // Iterate over each tool, and each tool's data + // Activate any handles we're hovering over, or whole tools if we're near the tool + // If we've changed the state of anything, redrawn the image + + for (var t = 0; t < tools.length; t++) { + var tool = tools[t]; + + if (typeof tool.mouseMoveCallback === 'function') { + imageNeedsUpdate = tool.mouseMoveCallback(evt) || imageNeedsUpdate; + } + } // Tool data activation status changed, redraw the image + + + if (imageNeedsUpdate === true) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + } +}); + +/***/ }), + +/***/ "./eventDispatchers/mouseToolEventDispatcher.js": +/*!******************************************************!*\ + !*** ./eventDispatchers/mouseToolEventDispatcher.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../events.js */ "./events.js"); +/* harmony import */ var _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mouseEventHandlers/index.js */ "./eventDispatchers/mouseEventHandlers/index.js"); + + +/** + * These listeners are emitted in order, and can be cancelled/prevented from bubbling + * by any previous event. + * - mouseMove: used to update the [un]hover state of a tool (highlighting) + * - mouseDown: check to see if we are close to an existing annotation, grab it + * - mouseDownActivate: createNewMeasurement (usually) + * - mouseDrag: update measurement or apply strategy (wwwc) + * - mouseDoubleClick: usually a one-time apply specialty action + * - onImageRendered: redraw visible tool data + * @private + * @param {*} element + * @returns {undefined} + */ + +var enable = function enable(element) { + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseClick"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDown"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN_ACTIVATE, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDownActivate"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOUBLE_CLICK, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDoubleClick"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDrag"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_MOVE, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseMove"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseUp"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_WHEEL, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseWheel"]); +}; + +var disable = function disable(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseClick"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDown"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN_ACTIVATE, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDownActivate"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOUBLE_CLICK, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDoubleClick"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseDrag"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_MOVE, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseMove"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseUp"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_WHEEL, _mouseEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseWheel"]); +}; + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventDispatchers/newImageEventDispatcher.js": +/*!*****************************************************!*\ + !*** ./eventDispatchers/newImageEventDispatcher.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); + + + +var onNewImage = function onNewImage(evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return false; + } + + var element = evt.detail.element; + var tools = _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].tools.filter(function (tool) { + return tool.element === element && (tool.mode === 'active' || tool.mode === 'passive' || tool.mode === 'enabled'); + }); + + if (tools.length === 0) { + return false; + } + + tools.forEach(function (tool) { + if (tool.newImageCallback) { + tool.newImageCallback(evt); + } + }); +}; + +var enable = function enable(element) { + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.EVENTS.NEW_IMAGE, onNewImage); +}; + +var disable = function disable(element) { + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.EVENTS.NEW_IMAGE, onNewImage); +}; + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventDispatchers/shared/customCallbackHandler.js": +/*!**********************************************************!*\ + !*** ./eventDispatchers/shared/customCallbackHandler.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../store/getActiveToolsForElement.js */ "./store/getActiveToolsForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../store/filterToolsUsableWithMultiPartTools.js */ "./store/filterToolsUsableWithMultiPartTools.js"); + + + +/* harmony default export */ __webpack_exports__["default"] = (function (handlerType, customFunction, evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return false; + } // TODO: We sometimes see a null detail for TOUCH_PRESS + + + var element = evt.detail.element; + var tools = _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].tools.filter(function (tool) { + return tool.supportedInteractionTypes.includes(handlerType); + }); // Tool is active, and specific callback is active + + tools = Object(_store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, tools, handlerType); // Tool has expected callback custom function + + tools = tools.filter(function (tool) { + return typeof tool[customFunction] === 'function'; + }); + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + tools = Object(_store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__["default"])(tools); + } + + if (tools.length === 0) { + return false; + } + + tools[0][customFunction](evt); +}); + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/addNewMeasurement.js": +/*!******************************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/addNewMeasurement.js ***! + \******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../manipulators/anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_7__["getLogger"])('eventDispatchers:touchEventHandlers'); +/* harmony default export */ __webpack_exports__["default"] = (function (evt, tool) { + logger.log('addNewMeasurement'); + evt.preventDefault(); + evt.stopPropagation(); + var touchEventData = evt.detail; + var element = touchEventData.element; + var measurementData = tool.createNewMeasurement(touchEventData); + + if (!measurementData) { + return; + } + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["addToolState"])(element, tool.name, measurementData); // Todo: Looks like we're handling the "up" of the tap? + + if (Object.keys(measurementData.handles).length === 1 && touchEventData.type === _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP) { + // Todo: bold assumptions about measurement data for all tools? + measurementData.active = false; + measurementData.handles.end.active = false; + measurementData.handles.end.highlight = false; + measurementData.invalidated = true; + var deleteIfHandleOutsideImage = _store_index_js__WEBPACK_IMPORTED_MODULE_2__["state"].deleteIfHandleOutsideImage || tool.options.deleteIfHandleOutsideImage; + + if (deleteIfHandleOutsideImage && Object(_manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_3__["default"])(touchEventData, measurementData.handles)) { + // Delete the measurement + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["removeToolState"])(element, tool.name, measurementData); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + return; + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_4__["moveNewHandle"])(touchEventData, tool.name, measurementData, measurementData.handles.end, tool.options, 'touch', function () { + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_COMPLETED; + var eventData = { + toolName: tool.name, + toolType: tool.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_6__["default"])(element, eventType, eventData); + }); +}); + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/index.js": +/*!******************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/index.js ***! + \******************************************************/ +/*! exports provided: doubleTap, multiTouchDrag, tap, touchDrag, touchEnd, touchPinch, touchPress, touchRotate, touchStart, touchStartActive */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doubleTap", function() { return doubleTap; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "touchDrag", function() { return touchDrag; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "touchEnd", function() { return touchEnd; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "touchPinch", function() { return touchPinch; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "touchPress", function() { return touchPress; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "touchRotate", function() { return touchRotate; }); +/* harmony import */ var _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../shared/customCallbackHandler.js */ "./eventDispatchers/shared/customCallbackHandler.js"); +/* harmony import */ var _multiTouchDrag_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./multiTouchDrag.js */ "./eventDispatchers/touchEventHandlers/multiTouchDrag.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "multiTouchDrag", function() { return _multiTouchDrag_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _tap_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tap.js */ "./eventDispatchers/touchEventHandlers/tap.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "tap", function() { return _tap_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _touchStart_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./touchStart.js */ "./eventDispatchers/touchEventHandlers/touchStart.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "touchStart", function() { return _touchStart_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _touchStartActive_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./touchStartActive.js */ "./eventDispatchers/touchEventHandlers/touchStartActive.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "touchStartActive", function() { return _touchStartActive_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + + + + + + +var doubleTap = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'DoubleTap', 'doubleTapCallback'); // TODO: some touchDrag tools don't want to fire on touchStart +// TODO: Drag tools have an option `fireOnTouchStart` used to filter +// TODO: Them out of TOUCH_START handler + +var touchDrag = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Touch', 'touchDragCallback'); +var touchEnd = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Touch', 'touchEndCallback'); +var touchPinch = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'TouchPinch', 'touchPinchCallback'); +var touchPress = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'Touch', 'touchPressCallback'); +var touchRotate = _shared_customCallbackHandler_js__WEBPACK_IMPORTED_MODULE_0__["default"].bind(null, 'TouchRotate', 'touchRotateCallback'); + + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/multiTouchDrag.js": +/*!***************************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/multiTouchDrag.js ***! + \***************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../store/getActiveToolsForElement.js */ "./store/getActiveToolsForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../store/filterToolsUsableWithMultiPartTools.js */ "./store/filterToolsUsableWithMultiPartTools.js"); + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return false; + } // TODO: We sometimes see a null detail for TOUCH_PRESS + + + var _evt$detail = evt.detail, + element = _evt$detail.element, + numPointers = _evt$detail.numPointers; + var tools = _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].tools.filter(function (tool) { + return tool.supportedInteractionTypes.includes('MultiTouch'); + }); // Tool is active, and specific callback is active + + tools = Object(_store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, tools, 'MultiTouch'); // Tool has expected callback custom function + + tools = tools.filter(function (tool) { + return typeof tool.multiTouchDragCallback === 'function' && numPointers === tool.configuration.touchPointers; + }); + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + tools = Object(_store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_2__["default"])(tools); + } + + if (tools.length === 0) { + return false; + } + + var activeTool = tools[0]; + activeTool.multiTouchDragCallback(evt); +}); + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/shared/deactivateAllToolInstances.js": +/*!**********************************************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/shared/deactivateAllToolInstances.js ***! + \**********************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony default export */ __webpack_exports__["default"] = (function (toolData) { + if (!toolData) { + return; + } + + for (var i = 0; i < toolData.data.length; i++) { + var data = toolData.data[i]; + data.active = false; + + if (!data.handles) { + continue; + } + + deactivateAllHandles(data.handles); + } +}); + +function deactivateAllHandles(handles) { + Object.keys(handles).forEach(function (name) { + var handle = handles[name]; + handle.active = false; + }); +} + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/tap.js": +/*!****************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/tap.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _touchStartActive_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./touchStartActive.js */ "./eventDispatchers/touchEventHandlers/touchStartActive.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../store/getActiveToolsForElement.js */ "./store/getActiveToolsForElement.js"); +/* harmony import */ var _store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../store/getToolsWithDataForElement.js */ "./store/getToolsWithDataForElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _shared_deactivateAllToolInstances_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./shared/deactivateAllToolInstances.js */ "./eventDispatchers/touchEventHandlers/shared/deactivateAllToolInstances.js"); + + // State + + + + + // + + + // + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_2__["state"].isToolLocked || _store_index_js__WEBPACK_IMPORTED_MODULE_2__["state"].isMultiPartToolActive) { + return; + } + + var tools; + var distanceFromHandle = 28; + var element = evt.detail.element; + var coords = evt.detail.currentPoints.canvas; + tools = Object(_store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_2__["getters"].touchTools()); + tools = Object(_store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, tools); // Deactivate everything + // DeactivateAllToolInstances(toolData); + // Find all tools w/ handles that we are near + + var toolsWithMoveableHandles = tools.filter(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["getToolState"])(element, tool.name); + + for (var i = 0; i < toolState.data.length; i++) { + if (Object(_manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_6__["default"])(element, toolState.data[i].handles, coords, distanceFromHandle) !== undefined) { + return true; + } + } + + return false; + }); // TODO: More than one? Which one was moved most recently? + // We'll just grab the first one we encounter for now + + if (toolsWithMoveableHandles.length > 0) { + // Todo: ignore: touch_start, tap + var firstToolWithMoveableHandles = toolsWithMoveableHandles[0]; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["getToolState"])(element, firstToolWithMoveableHandles.name); + var moveableHandle = toolState.data.find(function (d) { + return Object(_manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_6__["default"])(element, d.handles, coords, distanceFromHandle) !== undefined; + }); + toolState.data.active = true; + moveableHandle.active = true; // Why here, but not touchStart? + + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_7__["moveHandle"])(evt.detail, firstToolWithMoveableHandles.name, toolState.data, moveableHandle, firstToolWithMoveableHandles.options, 'touch', function () { + return Object(_shared_deactivateAllToolInstances_js__WEBPACK_IMPORTED_MODULE_8__["default"])(toolState); + }); + evt.stopImmediatePropagation(); + evt.preventDefault(); // Why no stopPropagation? + + return; + } // Find all tools near our point + + + var toolsNearPoint = tools.filter(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["getToolState"])(element, tool.name); + var isNearPoint = toolState && toolState.data && tool.pointNearTool && toolState.data.some(function (data) { + return tool.pointNearTool(element, data, coords); + }); + return isNearPoint; + }); // TODO: More than one? Which one was moved most recently? + // We'll just grab the first one we encounter for now + + if (toolsNearPoint.length > 0) { + // Todo: Ignore: TAP, START, PRESS + var firstToolNearPoint = toolsNearPoint[0]; + + var _toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_5__["getToolState"])(element, firstToolNearPoint.name); + + var firstAnnotationNearPoint = _toolState.data.find(function (data) { + return firstToolNearPoint.pointNearTool(element, data, coords); + }); // Todo: ignore: touch_start, tap + + + firstAnnotationNearPoint.active = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_7__["moveAllHandles"])(evt.detail, firstToolNearPoint.name, firstAnnotationNearPoint, null, firstToolNearPoint.options, 'touch', function () { + return Object(_shared_deactivateAllToolInstances_js__WEBPACK_IMPORTED_MODULE_8__["default"])(_toolState); + }); + evt.stopImmediatePropagation(); + evt.preventDefault(); // TODO: Why no stop propagation? + + return; + } // If there is nothing to move, add a new instance of the tool + // Need to check here to see if activation is allowed! + // TODO: What would this be? First active tool? + // Or should _always_ pass through to our larger event handler that checks + // All tools anyway? + + + var allActiveTools = Object(_store_getActiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_2__["getters"].touchTools()); + + if (allActiveTools.length > 0 && allActiveTools[0].touchStartActiveCallback) { + allActiveTools[0].touchStartActiveCallback(evt); + } else { + Object(_touchStartActive_js__WEBPACK_IMPORTED_MODULE_1__["default"])(evt); + } + + return false; +}); + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/touchStart.js": +/*!***********************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/touchStart.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../util/findAndMoveHelpers.js */ "./util/findAndMoveHelpers.js"); +/* harmony import */ var _store_getToolsWithMoveableHandles_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/getToolsWithMoveableHandles.js */ "./store/getToolsWithMoveableHandles.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../store/getInteractiveToolsForElement.js */ "./store/getInteractiveToolsForElement.js"); +/* harmony import */ var _store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../store/getToolsWithDataForElement.js */ "./store/getToolsWithDataForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../store/filterToolsUsableWithMultiPartTools.js */ "./store/filterToolsUsableWithMultiPartTools.js"); +// State + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked) { + return; + } + + var eventData = evt.detail; + var element = eventData.element; + var coords = eventData.startPoints.canvas; + var activeAndPassiveTools = Object(_store_getInteractiveToolsForElement_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _store_index_js__WEBPACK_IMPORTED_MODULE_0__["getters"].touchTools()); + var activeTools = activeAndPassiveTools.filter(function (tool) { + return tool.mode === 'active' && tool.options.isTouchActive; + }); + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + activeTools = Object(_store_filterToolsUsableWithMultiPartTools_js__WEBPACK_IMPORTED_MODULE_6__["default"])(activeTools); + } // If any tools are active, check if they have a special reason for dealing with the event. + + + if (activeTools.length > 0) { + // TODO: If length > 1, you could assess fitness and select the ideal tool + // TODO: But because we're locking this to 'active' tools, that should rarely be an issue + // Super-Meta-TODO: ^ I think we should just take the approach of one active tool per mouse button? + var firstActiveToolWithCallback = activeTools.find(function (tool) { + return typeof tool.preTouchStartCallback === 'function'; + }); + + if (firstActiveToolWithCallback) { + var consumedEvent = firstActiveToolWithCallback.preTouchStartCallback(evt); + + if (consumedEvent) { + return; + } + } + } + + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + return; + } + + var annotationTools = Object(_store_getToolsWithDataForElement_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, activeAndPassiveTools); // NEAR HANDLES? + + var annotationToolsWithMoveableHandles = Object(_store_getToolsWithMoveableHandles_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, annotationTools, coords, 'touch'); // TODO: More than one? Which one was moved most recently? + // We'll just grab the first one we encounter for now + + if (annotationToolsWithMoveableHandles.length > 0) { + // Todo: Ignore TAP, START, PRESS + var firstToolWithMoveableHandles = annotationToolsWithMoveableHandles[0]; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, firstToolWithMoveableHandles.name); + + var _findHandleDataNearIm = Object(_util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_1__["findHandleDataNearImagePoint"])(element, toolState, firstToolWithMoveableHandles.name, coords, 'touch'), + handle = _findHandleDataNearIm.handle, + data = _findHandleDataNearIm.data; + + firstToolWithMoveableHandles.handleSelectedCallback(evt, data, handle, 'touch'); + return; + } // NEAR POINT? + + + var annotationToolsWithPointNearTouch = annotationTools.filter(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, tool.name); + var isNearPoint = toolState && toolState.data && tool.pointNearTool && toolState.data.some(function (data) { + return tool.pointNearTool(element, data, coords, 'touch'); + }); + return isNearPoint; + }); // TODO: More than one? Which one was moved most recently? + // We'll just grab the first one we encounter for now + + if (annotationToolsWithPointNearTouch.length > 0) { + // Todo: Ignore: TAP, START, PRESS + var firstToolNearPoint = annotationToolsWithPointNearTouch[0]; + + var _toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, firstToolNearPoint.name); + + var firstAnnotationNearPoint = _toolState.data.find(function (data) { + return firstToolNearPoint.pointNearTool(element, data, coords); + }); + + firstToolNearPoint.toolSelectedCallback(evt, firstAnnotationNearPoint, 'touch'); + return; + } // If any tools are active, check if they have a special reason for dealing with the event. + + + if (activeTools.length > 0) { + // TODO: If length > 1, you could assess fitness and select the ideal tool + // TODO: But because we're locking this to 'active' tools, that should rarely be an issue + // Super-Meta-TODO: ^ I think we should just take the approach of one active tool per mouse button? + var _firstActiveToolWithCallback = activeTools.find(function (tool) { + return typeof tool.postTouchStartCallback === 'function'; + }); + + if (_firstActiveToolWithCallback) { + var _consumedEvent = _firstActiveToolWithCallback.postTouchStartCallback(evt); + + if (_consumedEvent) { + return; + } + } + } +}); + +/***/ }), + +/***/ "./eventDispatchers/touchEventHandlers/touchStartActive.js": +/*!*****************************************************************!*\ + !*** ./eventDispatchers/touchEventHandlers/touchStartActive.js ***! + \*****************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./addNewMeasurement.js */ "./eventDispatchers/touchEventHandlers/addNewMeasurement.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../tools/base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../util/getActiveTool */ "./util/getActiveTool.js"); +// State + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + if (_store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isToolLocked || _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + return; + } + + var element = evt.detail.element; + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_3__["default"])(element, null, 'touch'); // Note: custom `addNewMeasurement` will need to prevent event bubbling + + if (activeTool && activeTool.addNewMeasurement) { + activeTool.addNewMeasurement(evt, 'touch'); + } else if (activeTool instanceof _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_2__["default"]) { + Object(_addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, activeTool); + } +}); + +/***/ }), + +/***/ "./eventDispatchers/touchToolEventDispatcher.js": +/*!******************************************************!*\ + !*** ./eventDispatchers/touchToolEventDispatcher.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./touchEventHandlers/index.js */ "./eventDispatchers/touchEventHandlers/index.js"); + + +/** + * These listeners are emitted in order, and can be cancelled/prevented from bubbling + * by any previous event. + * - tap: + * - touchStart: check to see if we are close to an existing annotation, grab it + * - touchDrag: + * - touchStartActive: createNewMeasurement (usually) + * - touchPress: + * - touchRotate: + * - doubleTap: usually a one-time apply specialty action + * - touchPinch: + * - onImageRendered: redraw visible tool data + * @private + * @param {*} element + * @returns {void} + */ + +var enable = function enable(element) { + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["tap"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchStart"], { + passive: false + }); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchDrag"], { + passive: false + }); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchEnd"]); // Mouse equivelant is `mouse_down_activate` + // Should the naming pattern here match? + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START_ACTIVE, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchStartActive"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PRESS, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchPress"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].DOUBLE_TAP, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["doubleTap"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchPinch"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_ROTATE, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchRotate"]); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MULTI_TOUCH_DRAG, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["multiTouchDrag"]); +}; + +var disable = function disable(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["tap"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchStart"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchDrag"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchEnd"]); // Mouse equivelant is `mouse_down_activate` + // Should the naming pattern here match? + + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START_ACTIVE, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchStartActive"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PRESS, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchPress"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].DOUBLE_TAP, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["doubleTap"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchPinch"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_ROTATE, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchRotate"]); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MULTI_TOUCH_DRAG, _touchEventHandlers_index_js__WEBPACK_IMPORTED_MODULE_1__["multiTouchDrag"]); +}; + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventListeners/index.js": +/*!*********************************!*\ + !*** ./eventListeners/index.js ***! + \*********************************/ +/*! exports provided: mouseEventListeners, wheelEventListener, touchEventListeners */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _mouseEventListeners_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mouseEventListeners.js */ "./eventListeners/mouseEventListeners.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mouseEventListeners", function() { return _mouseEventListeners_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _wheelEventListener_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./wheelEventListener.js */ "./eventListeners/wheelEventListener.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "wheelEventListener", function() { return _wheelEventListener_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _touchEventListeners_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./touchEventListeners.js */ "./eventListeners/touchEventListeners.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "touchEventListeners", function() { return _touchEventListeners_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + + + + + + +/***/ }), + +/***/ "./eventListeners/internals/normalizeWheel.js": +/*!****************************************************!*\ + !*** ./eventListeners/internals/normalizeWheel.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// Reasonable defaults +var PIXEL_STEP = 10; +var LINE_HEIGHT = 40; +var PAGE_HEIGHT = 800; +/** + * Normalizes wheel events and provides properties that are more + * consistent and helpful across different browsers + * + * @private + * @function normalizeWheel + * @param {WheelEvent} event + * @returns {Object} { spinX, spinY, pixlX, pixelY } + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (event) { + var spinX = 0, + spinY = 0, + pixelX = 0, + pixelY = 0; // Legacy + + if ('detail' in event) { + spinY = event.detail; + } + + if ('wheelDelta' in event) { + spinY = -event.wheelDelta / 120; + } + + if ('wheelDeltaY' in event) { + spinY = -event.wheelDeltaY / 120; + } + + if ('wheelDeltaX' in event) { + spinX = -event.wheelDeltaX / 120; + } + + pixelX = spinX * PIXEL_STEP; + pixelY = spinY * PIXEL_STEP; + + if ('deltaY' in event) { + pixelY = event.deltaY; + } + + if ('deltaX' in event) { + pixelX = event.deltaX; + } + + if ((pixelX || pixelY) && event.deltaMode) { + if (event.deltaMode === 1) { + // Delta in LINE units + pixelX *= LINE_HEIGHT; + pixelY *= LINE_HEIGHT; + } else { + // Delta in PAGE units + pixelX *= PAGE_HEIGHT; + pixelY *= PAGE_HEIGHT; + } + } // Fall-back if spin cannot be determined + + + if (pixelX && !spinX) { + spinX = pixelX < 1 ? -1 : 1; + } + + if (pixelY && !spinY) { + spinY = pixelY < 1 ? -1 : 1; + } + + return { + spinX: spinX, + spinY: spinY, + pixelX: pixelX, + pixelY: pixelY + }; +}); + +/***/ }), + +/***/ "./eventListeners/internals/renderSegmentation.js": +/*!********************************************************!*\ + !*** ./eventListeners/internals/renderSegmentation.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return renderSegmentation; }); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _renderSegmentationFill__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./renderSegmentationFill */ "./eventListeners/internals/renderSegmentationFill.js"); +/* harmony import */ var _renderSegmentationOutline__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./renderSegmentationOutline */ "./eventListeners/internals/renderSegmentationOutline.js"); + + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'); +/** + * Renders the segmentation based on the brush configuration and + * the active status of the labelmap. + * @param {Object} evt The cornerstone event. + * @param {Labelmap3D} labelmap3D The `Labelmap3D` object. + * @param {number} labelmapIndex The index of the active label map. + * @param {Labelmap2D} labelmap2D The `Labelmap2D` object to render. + * @param {boolean} isActiveLabelMap Whether or not the labelmap is active. + * @returns {null} + */ + +function renderSegmentation(evt, labelmap3D, labelmapIndex, labelmap2D, isActiveLabelMap) { + if (shouldRenderFill(isActiveLabelMap)) { + Object(_renderSegmentationFill__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, labelmap3D, labelmap2D, labelmapIndex, isActiveLabelMap); + } + + if (shouldRenderOutline(isActiveLabelMap)) { + Object(_renderSegmentationOutline__WEBPACK_IMPORTED_MODULE_2__["default"])(evt, labelmap3D, labelmap2D, labelmapIndex, isActiveLabelMap); + } +} +/** + * ShouldRenderFill - Returns true if `configuration.renderFill` + * is true , and if the global alpha is not zero. + * + * @param {boolean} isActiveLabelMap + * @returns {boolean} True if the segmentation should be filled. + */ + +function shouldRenderFill(isActiveLabelMap) { + var configuration = segmentationModule.configuration; + return configuration.renderFill && (isActiveLabelMap && configuration.fillAlpha !== 0 || !isActiveLabelMap && configuration.fillAlphaInactive !== 0); +} +/** + * ShouldRenderOutline - Returns true if `configuration.renderOutline` + * is true , and if the global alpha is not zero. + * + * @param {boolean} isActiveLabelMap + * @returns {boolean} True if the segmentation should be outlined. + */ + + +function shouldRenderOutline(isActiveLabelMap) { + var configuration = segmentationModule.configuration; + return configuration.renderOutline && (isActiveLabelMap && configuration.outlineAlpha !== 0 || !isActiveLabelMap && configuration.outlineAlphaInactive !== 0); +} + +/***/ }), + +/***/ "./eventListeners/internals/renderSegmentationFill.js": +/*!************************************************************!*\ + !*** ./eventListeners/internals/renderSegmentationFill.js ***! + \************************************************************/ +/*! exports provided: default, getLabelmapCanvas, renderFill */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return renderSegmentationFill; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLabelmapCanvas", function() { return getLabelmapCanvas; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "renderFill", function() { return renderFill; }); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); + + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'); +function renderSegmentationFill(evt, labelmap3D, labelmap2D, labelmapIndex, isActiveLabelMap) { + var labelmapCanvas = getLabelmapCanvas(evt, labelmap3D, labelmap2D); + renderFill(evt, labelmapCanvas, isActiveLabelMap); +} +/** + * Generates a canvas of the `Labelmap2D` data with transparent background, to draw onto the + * cornerstone canvas. Reduces the number of `putImageData` calls that need to be made by + * scanning across the labelmap and painting to the canvas in chunks. + * + * @param {Object} evt The cornerstone event. + * @param {Labelmap3D} labelmap3D The `Labelmap3D` object. + * @param {Labelmap2D} labelmap2D The `Labelmap2D` object containing the pixelData to render. + * @returns {HTMLCanvasElement} + */ + +function getLabelmapCanvas(evt, labelmap3D, labelmap2D) { + var state = segmentationModule.state; + var eventData = evt.detail; + var image = eventData.image; + var cols = image.width; + var rows = image.height; + var segmentsHidden = labelmap3D.segmentsHidden; + var pixelData = labelmap2D.pixelData; + var colorLutTable = state.colorLutTables[labelmap3D.colorLUTIndex]; + var canvasElement = document.createElement('canvas'); + canvasElement.width = cols; + canvasElement.height = rows; + var ctx = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_1__["getNewContext"])(canvasElement); // Image data initialized with all transparent black. + + var imageData = new ImageData(cols, rows); + var data = imageData.data; + + for (var i = 0; i < pixelData.length; i++) { + var segmentIndex = pixelData[i]; + + if (segmentIndex !== 0 && !segmentsHidden[segmentIndex]) { + var color = colorLutTable[pixelData[i]]; // Modify ImageData. + + data[4 * i] = color[0]; // R value + + data[4 * i + 1] = color[1]; // G value + + data[4 * i + 2] = color[2]; // B value + + data[4 * i + 3] = color[3]; // A value + } + } // Put this image data onto the labelmapCanvas. + + + ctx.putImageData(imageData, 0, 0); + return canvasElement; +} +/** + * Renders the filled region of each segment in the segmentation. + * @param {Object} evt The cornerstone event. + * @param {HTMLCanvasElement} labelmapCanvas The canvas generated for the labelmap. + * @param {boolean} isActiveLabelMap Whether or not the labelmap is active. + * @returns {null} + */ + +function renderFill(evt, labelmapCanvas, isActiveLabelMap) { + var configuration = segmentationModule.configuration; + var eventData = evt.detail; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_1__["getNewContext"])(eventData.canvasContext.canvas); + var canvasTopLeft = _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone.pixelToCanvas(eventData.element, { + x: 0, + y: 0 + }); + var canvasTopRight = _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone.pixelToCanvas(eventData.element, { + x: eventData.image.width, + y: 0 + }); + var canvasBottomRight = _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone.pixelToCanvas(eventData.element, { + x: eventData.image.width, + y: eventData.image.height + }); + var cornerstoneCanvasWidth = _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstoneMath.point.distance(canvasTopLeft, canvasTopRight); + var cornerstoneCanvasHeight = _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstoneMath.point.distance(canvasTopRight, canvasBottomRight); + var canvas = eventData.canvasContext.canvas; + var viewport = eventData.viewport; + var previousImageSmoothingEnabled = context.imageSmoothingEnabled; + var previousGlobalAlpha = context.globalAlpha; + context.imageSmoothingEnabled = false; + context.globalAlpha = isActiveLabelMap ? configuration.fillAlpha : configuration.fillAlphaInactive; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_1__["transformCanvasContext"])(context, canvas, viewport); + var canvasViewportTranslation = getCanvasViewportTranslation(eventData); + context.drawImage(labelmapCanvas, canvas.width / 2 - cornerstoneCanvasWidth / 2 + canvasViewportTranslation.x, canvas.height / 2 - cornerstoneCanvasHeight / 2 + canvasViewportTranslation.y, cornerstoneCanvasWidth, cornerstoneCanvasHeight); + context.globalAlpha = previousGlobalAlpha; + context.imageSmoothingEnabled = previousImageSmoothingEnabled; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_1__["resetCanvasContextTransform"])(context); +} +/** + * GetCanvasViewportTranslation - Returns translation coordinations for + * canvas viewport with calculation of image row/column pixel spacing. + * + * @param {Object} eventData The data associated with the event. + * @returns {Object} The coordinates of the translation. + */ + +function getCanvasViewportTranslation(eventData) { + var viewport = eventData.viewport, + image = eventData.image; + var widthScale = viewport.scale; + var heightScale = viewport.scale; + + if (image.rowPixelSpacing < image.columnPixelSpacing) { + widthScale *= image.columnPixelSpacing / image.rowPixelSpacing; + } else if (image.columnPixelSpacing < image.rowPixelSpacing) { + heightScale *= image.rowPixelSpacing / image.columnPixelSpacing; + } + + return { + x: viewport.translation.x * widthScale, + y: viewport.translation.y * heightScale + }; +} + +/***/ }), + +/***/ "./eventListeners/internals/renderSegmentationOutline.js": +/*!***************************************************************!*\ + !*** ./eventListeners/internals/renderSegmentationOutline.js ***! + \***************************************************************/ +/*! exports provided: default, renderOutline, getOutline, _addTopRightCorner */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return renderSegmentationOutline; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "renderOutline", function() { return renderOutline; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getOutline", function() { return getOutline; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_addTopRightCorner", function() { return _addTopRightCorner; }); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../index.js */ "./index.js"); + + + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'); +function renderSegmentationOutline(evt, labelmap3D, labelmap2D, labelmapIndex, isActiveLabelMap) { + var configuration = segmentationModule.configuration; + var outline = getOutline(evt, labelmap3D, labelmap2D, configuration.outlineWidth); + renderOutline(evt, outline, labelmap3D.colorLUTIndex, isActiveLabelMap); +} +/** + * RenderOutline - Renders the outlines of segments to the canvas. + * + * @param {Object} evt The cornerstone event. + * @param {Object} outline The outline to render. + * @param {number} colorLUTIndex The index of the colorLUT. + * @param {number} isActiveLabelMap Whether the labelmap is active. + * @returns {null} + */ + +function renderOutline(evt, outline, colorLUTIndex) { + var isActiveLabelMap = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; + var configuration = segmentationModule.configuration, + state = segmentationModule.state; + var eventData = evt.detail; + var element = eventData.element, + canvasContext = eventData.canvasContext; + var lineWidth = configuration.outlineWidth || 1; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_2__["getNewContext"])(canvasContext.canvas); + var colorLutTable = state.colorLutTables[colorLUTIndex]; + var previousAlpha = context.globalAlpha; + context.globalAlpha = isActiveLabelMap ? configuration.outlineAlpha : configuration.outlineAlphaInactive; // Draw outlines. + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_2__["draw"])(context, function (context) { + for (var i = 1; i < outline.length; i++) { + if (outline[i]) { + var color = colorLutTable[i]; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_2__["drawLines"])(context, element, outline[i], { + color: "rgba(".concat(color[0], ", ").concat(color[1], ", ").concat(color[2], ", 1.0 )"), + lineWidth: lineWidth + }, 'canvas'); + } + } + }); + context.globalAlpha = previousAlpha; +} +/** + * GetOutline - Returns an object containing all the line segments to be + * drawn the canvas. + * + * @param {Object} evt The cornerstone event. + * @param {Labelmap3D} labelmap3D The 3D labelmap. + * @param {Labelmap2D} labelmap2D The 2D labelmap for this current image. + * @param {number} lineWidth The width of the outline in canvas pixels. + * + * @returns {Object[][]} An array of arrays of lines for each segment. + */ + +function getOutline(evt, labelmap3D, labelmap2D, lineWidth) { + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image, + viewport = eventData.viewport; + var cols = image.width; + var rows = image.height; + lineWidth = lineWidth || 1; + var segmentsHidden = labelmap3D.segmentsHidden; + var pixelData = labelmap2D.pixelData; + var activeSegmentIndex = labelmap3D.activeSegmentIndex; + var lineSegments = []; + labelmap2D.segmentsOnLabelmap.forEach(function (segmentIndex) { + var visible = !segmentsHidden[segmentIndex]; + + if (visible) { + lineSegments[segmentIndex] = []; + } + }); + + if (!lineSegments[activeSegmentIndex]) { + lineSegments[activeSegmentIndex] = []; + } + + var _getPixelCoordinateFromPixelIndex = function _getPixelCoordinateFromPixelIndex(pixelIndex) { + return { + x: pixelIndex % cols, + y: Math.floor(pixelIndex / cols) + }; + }; + + var offset = getOutlineOffset(viewport, lineWidth); + + for (var i = 0; i < pixelData.length; i++) { + var segmentIndex = pixelData[i]; + + if (segmentIndex === 0) { + continue; + } + + var visible = !segmentsHidden[segmentIndex]; + + if (!visible) { + continue; + } + + var coord = _getPixelCoordinateFromPixelIndex(i); + + var pixels = _getPixelIndiciesAroundPixel(coord, rows, cols); // Check pixel above + + + if (pixels.top === undefined || pixelData[pixels.top] !== segmentIndex) { + _addTopOutline(lineSegments[segmentIndex], element, coord, offset); + } // Check pixel below + + + if (pixels.bottom === undefined || pixelData[pixels.bottom] !== segmentIndex) { + _addBottomOutline(lineSegments[segmentIndex], element, coord, offset); + } // Check pixel to the left + + + if (pixels.left === undefined || pixelData[pixels.left] !== segmentIndex) { + _addLeftOutline(lineSegments[segmentIndex], element, coord, offset); + } // Check pixel to the right + + + if (pixels.right === undefined || pixelData[pixels.right] !== segmentIndex) { + _addRightOutline(lineSegments[segmentIndex], element, coord, offset); + } // Top left corner + + + if (pixels.topLeft !== undefined && pixelData[pixels.topLeft] !== segmentIndex && pixelData[pixels.top] === segmentIndex && pixelData[pixels.left] === segmentIndex) { + _addTopLeftCorner(lineSegments[segmentIndex], element, coord, offset); + } // Top right corner + + + if (pixels.topRight !== undefined && pixelData[pixels.topRight] !== segmentIndex && pixelData[pixels.top] === segmentIndex && pixelData[pixels.right] === segmentIndex) { + _addTopRightCorner(lineSegments[segmentIndex], element, coord, offset); + } // Bottom left corner + + + if (pixels.bottomLeft !== undefined && pixelData[pixels.bottomLeft] !== segmentIndex && pixelData[pixels.bottom] === segmentIndex && pixelData[pixels.left] === segmentIndex) { + _addBottomLeftCorner(lineSegments[segmentIndex], element, coord, offset); + } // Bottom right corner + + + if (pixels.bottomRight !== undefined && pixelData[pixels.bottomRight] !== segmentIndex && pixelData[pixels.bottom] === segmentIndex && pixelData[pixels.right] === segmentIndex) { + _addBottomRightCorner(lineSegments[segmentIndex], element, coord, offset); + } + } + + return lineSegments; +} +/** + * GetOutlineOffset - Returns the outline offset (half line width) in the + * i (column) and j (row) pixel directions in the viewport's rotated frame. + * @param {Object} viewport The cornerstone viewport. + * @param {number} lineWidth The width of the outline. + * @returns {Object} Two vectors in the i and j pixel directions, with magnitude + * lineWidth / 2 + */ + +function getOutlineOffset(viewport, lineWidth) { + var halfLineWidth = lineWidth / 2; + var theta = viewport.rotation; + theta *= Math.PI / 180; + var cosTheta = Math.cos(theta); + var sinTheta = Math.sin(theta); + var unitVectorI = [cosTheta, sinTheta]; + var unitVectorJ = [-sinTheta, cosTheta]; + var i = { + x: halfLineWidth * unitVectorI[0], + y: halfLineWidth * unitVectorI[1] + }; + var j = { + x: halfLineWidth * unitVectorJ[0], + y: halfLineWidth * unitVectorJ[1] + }; + + if (viewport.hflip) { + i.x *= -1; + i.y *= -1; + } + + if (viewport.vflip) { + j.x *= -1; + j.y *= -1; + } + + return { + i: i, + j: j + }; +} +/** + * _getPixelIndiciesAroundPixel - Returnns the coordinates for up to 8 surrounding + * pixels, if they within the bounds of the image. + * + * @param {Object} coord The coordinate to check. + * @param {number} rows The number of rows in the image. + * @param {number} cols The number of cols in the image. + * + * @returns {Object} Object containing the position of adjacent pixels. + */ + + +function _getPixelIndiciesAroundPixel(coord, rows, cols) { + var pixelIndex = coord.y * cols + coord.x; + var pixel = {}; + var hasPixelToTop = coord.y - 1 >= 0; + var hasPixelToBotoom = coord.y + 1 < rows; + var hasPixelToLeft = coord.x - 1 >= 0; + var hasPixelToRight = coord.x + 1 < cols; + + if (hasPixelToTop) { + pixel.top = pixelIndex - cols; + + if (hasPixelToRight) { + pixel.topRight = pixel.top + 1; + } + + if (hasPixelToLeft) { + pixel.topLeft = pixel.top - 1; + } + } + + if (hasPixelToBotoom) { + pixel.bottom = pixelIndex + cols; + + if (hasPixelToRight) { + pixel.bottomRight = pixel.bottom + 1; + } + + if (hasPixelToLeft) { + pixel.bottomLeft = pixel.bottom - 1; + } + } + + if (hasPixelToLeft) { + pixel.left = pixelIndex - 1; + } + + if (hasPixelToRight) { + pixel.right = pixelIndex + 1; + } + + return pixel; +} +/** + * _addTopLeftCorner - Adds an outline to the top left corner of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addTopLeftCorner(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, coord); + start.x += offset.j.x; + start.y += offset.j.y; + var end = { + x: start.x, + y: start.y + }; + end.x += offset.i.x * 2; + end.y += offset.i.y * 2; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addTopRightCorner - Adds an outline to the top right corner of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addTopRightCorner(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + }); + start.x += offset.j.x; + start.y += offset.j.y; + var end = { + x: start.x, + y: start.y + }; + end.x -= offset.i.x * 2; + end.y -= offset.i.y * 2; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addBottomLeftCorner - Adds an outline to the bottom left corner of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + +function _addBottomLeftCorner(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, { + x: coord.x, + y: coord.y + 1 + }); + start.x -= offset.j.x; + start.y -= offset.j.y; + var end = { + x: start.x, + y: start.y + }; + end.x += offset.i.x * 2; + end.y += offset.i.y * 2; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addBottomRightCorner - Adds an outline to the bottom right corner of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addBottomRightCorner(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + 1 + }); + start.x -= offset.j.x; + start.y -= offset.j.y; + var end = { + x: start.x, + y: start.y + }; + end.x -= offset.i.x * 2; + end.y -= offset.i.y * 2; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addTopOutline - adds an outline at the top of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {number} halfLineWidth - Half the line width, to place line within the pixel. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addTopOutline(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, coord); + var end = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + }); // Move the line in the y-direction. + + start.x += offset.j.x; + start.y += offset.j.y; + end.x += offset.j.x; + end.y += offset.j.y; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addBottomOutline - adds an outline at the bottom of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addBottomOutline(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, { + x: coord.x, + y: coord.y + 1 + }); + var end = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + 1 + }); // Move the line in the negative y-direction. + + start.x -= offset.j.x; + start.y -= offset.j.y; + end.x -= offset.j.x; + end.y -= offset.j.y; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addLeftOutline - adds an outline at the left side of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addLeftOutline(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, coord); + var end = pixelToCanvas(element, { + x: coord.x, + y: coord.y + 1 + }); // Move the line in the x-direction. + + start.x += offset.i.x; + start.y += offset.i.y; + end.x += offset.i.x; + end.y += offset.i.y; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} +/** + * _addRightOutline - adds an outline at the right side of the pixel. + * + * @param {Object[]} lineSegmentsForSegment - The list to append. + * @param {Object} element - The Cornerstone enabled element. + * @param {Object} coord - The pixel to add a line to. + * @param {Object} offset - The x and y offset in the rotated frame. + * + * @returns {null} + */ + + +function _addRightOutline(lineSegmentsForSegment, element, coord, offset) { + var pixelToCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas; + var start = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + }); + var end = pixelToCanvas(element, { + x: coord.x + 1, + y: coord.y + 1 + }); // Move the line in the negative x-direction. + + start.x -= offset.i.x; + start.y -= offset.i.y; + end.x -= offset.i.x; + end.y -= offset.i.y; + lineSegmentsForSegment.push({ + start: start, + end: end + }); +} + +/***/ }), + +/***/ "./eventListeners/mouseEventListeners.js": +/*!***********************************************!*\ + !*** ./eventListeners/mouseEventListeners.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/copyPoints.js */ "./util/copyPoints.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('eventListeners:mouseEventListeners'); +var isClickEvent = true; +var preventClickTimeout; +var clickDelay = 200; +var addedListeners = new Map(); + +function getEventButtons(event) { + if (typeof event.buttons === 'number') { + return event.buttons; + } + + switch (event.which) { + // No button + case 0: + return 0; + // Left + + case 1: + return 1; + // Middle + + case 2: + return 4; + // Right + + case 3: + return 2; + } + + return 0; +} + +function preventClickHandler() { + isClickEvent = false; +} + +function mouseDoubleClick(e) { + var element = e.currentTarget; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOUBLE_CLICK; + var startPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + var lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(startPoints); + logger.log('double-click: %o', getEventButtons(e)); + var eventData = { + event: e, + buttons: getEventButtons(e), + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: startPoints, + deltaPoints: { + x: 0, + y: 0 + }, + type: eventType + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, eventType, eventData); +} + +function mouseDown(e) { + var element = e.currentTarget; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + preventClickTimeout = setTimeout(preventClickHandler, clickDelay); // Prevent CornerstoneToolsMouseMove while mouse is down + + element.removeEventListener('mousemove', mouseMove); + var startPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + var lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(startPoints); + var eventData = { + event: e, + buttons: getEventButtons(e), + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: startPoints, + deltaPoints: { + x: 0, + y: 0 + }, + type: _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN + }; + var eventPropagated = Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData.element, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN, eventData); + + if (eventPropagated) { + // No tools responded to this event, create a new tool + eventData.type = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN_ACTIVATE; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData.element, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DOWN_ACTIVATE, eventData); + } + + function onMouseMove(e) { + // Calculate our current points in page and image coordinates + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG; + var currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); // Calculate delta values in page and image coordinates + + var deltaPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image), + client: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client), + canvas: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas) + }; + logger.log('mousemove: %o', getEventButtons(e)); + var eventData = { + buttons: getEventButtons(e), + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: currentPoints, + deltaPoints: deltaPoints, + type: eventType, + ctrlKey: e.ctrlKey, + metaKey: e.metaKey, + shiftKey: e.shiftKey + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData.element, eventType, eventData); // Update the last points + + lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(currentPoints); + } // Hook mouseup so we can unbind our event listeners + // When they stop dragging + + + function onMouseUp(e) { + // Cancel the timeout preventing the click event from triggering + clearTimeout(preventClickTimeout); + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP; + + if (isClickEvent) { + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK; + } // Calculate our current points in page and image coordinates + + + var currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); // Calculate delta values in page and image coordinates + + var deltaPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image), + client: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client), + canvas: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas) + }; + logger.log('mouseup: %o', getEventButtons(e)); + var eventData = { + event: e, + buttons: getEventButtons(e), + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: currentPoints, + deltaPoints: deltaPoints, + type: eventType + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData.element, eventType, eventData); + document.removeEventListener('mousemove', onMouseMove); + document.removeEventListener('mouseup', onMouseUp); + addedListeners.delete(onMouseMove); + addedListeners.delete(onMouseUp); + element.addEventListener('mousemove', mouseMove); + isClickEvent = true; + } + + document.addEventListener('mousemove', onMouseMove); + document.addEventListener('mouseup', onMouseUp); + addedListeners.set(onMouseMove, 'mousemove'); + addedListeners.set(onMouseUp, 'mouseup'); +} + +function mouseMove(e) { + var element = e.currentTarget; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_MOVE; + var startPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + var lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(startPoints); // Calculate our current points in page and image coordinates + + var currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pageX, e.pageY), + client: { + x: e.clientX, + y: e.clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); // Calculate delta values in page and image coordinates + + var deltaPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image), + client: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client), + canvas: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas) + }; + var eventData = { + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: currentPoints, + deltaPoints: deltaPoints, + type: eventType + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, eventType, eventData); // Update the last points + + lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(currentPoints); +} + +function disable(element) { + element.removeEventListener('mousedown', mouseDown); + element.removeEventListener('mousemove', mouseMove); + element.removeEventListener('dblclick', mouseDoubleClick); // Make sure we have removed any listeners that were added within the above listeners (#1337) + + addedListeners.forEach(function (event, listener) { + document.removeEventListener(event, listener); + }); + addedListeners.clear(); +} + +function enable(element) { + // Prevent handlers from being attached multiple times + disable(element); + element.addEventListener('mousedown', mouseDown); + element.addEventListener('mousemove', mouseMove); + element.addEventListener('dblclick', mouseDoubleClick); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventListeners/onImageRenderedBrushEventHandler.js": +/*!************************************************************!*\ + !*** ./eventListeners/onImageRenderedBrushEventHandler.js ***! + \************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/index.js */ "./store/index.js"); +/* harmony import */ var _internals_renderSegmentation_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./internals/renderSegmentation.js */ "./eventListeners/internals/renderSegmentation.js"); + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'); +/** + * Finds which segmentations need to be rendered based on the configuration and + * presence of `Labelmap2D` data on these frames. + * + * @param {Object} evt - The cornerstone event. + * @returns {null} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + var eventData = evt.detail; + var element = eventData.element; + var configuration = segmentationModule.configuration, + getters = segmentationModule.getters; + + var _getters$labelmaps3D = getters.labelmaps3D(element), + activeLabelmapIndex = _getters$labelmaps3D.activeLabelmapIndex, + labelmaps3D = _getters$labelmaps3D.labelmaps3D, + currentImageIdIndex = _getters$labelmaps3D.currentImageIdIndex; + + if (!labelmaps3D) { + return; + } + + if (configuration.shouldRenderInactiveLabelmaps) { + renderInactiveLabelMaps(evt, labelmaps3D, activeLabelmapIndex, currentImageIdIndex); + } + + renderActiveLabelMap(evt, labelmaps3D, activeLabelmapIndex, currentImageIdIndex); +}); +/** + * RenderActiveLabelMap - Renders the `Labelmap3D` for this element if a `Labelmap2D` + * view of the `currentImageIdIndex` exists. + * + * @param {Object} evt The cornerstone event. + * @param {Labelmap3D[]} labelmaps3D An array of `Labelmap3D` objects. + * @param {number} activeLabelmapIndex The index of the active label map. + * @param {number} currentImageIdIndex The in-stack image position. + * @returns {null} + */ + +function renderActiveLabelMap(evt, labelmaps3D, activeLabelmapIndex, currentImageIdIndex) { + var labelmap3D = labelmaps3D[activeLabelmapIndex]; + + if (!labelmap3D) { + return; + } + + var labelmap2D = labelmap3D.labelmaps2D[currentImageIdIndex]; + + if (labelmap2D) { + Object(_internals_renderSegmentation_js__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, labelmap3D, activeLabelmapIndex, labelmap2D, true); + } +} +/** + * RenderInactiveLabelMaps - Renders all the inactive `Labelmap3D`s for this element. + * + * @param {Object} evt The cornerstone event. + * @param {Labelmap3D[]} labelmaps3D An array of labelmaps. + * @param {number} activeLabelmapIndex The index of the active label map. + * @param {number} currentImageIdIndex The in-stack image position. + * @returns {null} + */ + + +function renderInactiveLabelMaps(evt, labelmaps3D, activeLabelmapIndex, currentImageIdIndex) { + for (var i = 0; i < labelmaps3D.length; i++) { + var labelmap3D = labelmaps3D[i]; + + if (i === activeLabelmapIndex || !labelmap3D) { + continue; + } + + var labelmap2D = labelmap3D.labelmaps2D[currentImageIdIndex]; + + if (labelmap2D) { + Object(_internals_renderSegmentation_js__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, labelmap3D, i, labelmap2D, false); + } + } +} + +/***/ }), + +/***/ "./eventListeners/preventGhostClick.js": +/*!*********************************************!*\ + !*** ./eventListeners/preventGhostClick.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// Functions to prevent ghost clicks following a touch +// All credit to @kosich +// https://gist.github.com/kosich/23188dd86633b6c2efb7 +var antiGhostDelay = 2000, + pointerType = { + mouse: 0, + touch: 1 +}; +var lastInteractionType, lastInteractionTime; + +function handleTap(type, e) { + var now = Date.now(); + + if (type !== lastInteractionType) { + if (now - lastInteractionTime <= antiGhostDelay) { + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + return false; + } + + lastInteractionType = type; + } + + lastInteractionTime = now; +} // Cacheing the function references +// Necessary because a new function reference is created after .bind() is called +// http://stackoverflow.com/questions/11565471/removing-event-listener-which-was-added-with-bind + + +var handleTapMouse = handleTap.bind(null, pointerType.mouse); +var handleTapTouch = handleTap.bind(null, pointerType.touch); + +function attachEvents(element, eventList, interactionType) { + var tapHandler = interactionType ? handleTapMouse : handleTapTouch; + eventList.forEach(function (eventName) { + element.addEventListener(eventName, tapHandler, { + passive: false + }); + }); +} + +function removeEvents(element, eventList, interactionType) { + var tapHandler = interactionType ? handleTapMouse : handleTapTouch; + eventList.forEach(function (eventName) { + element.removeEventListener(eventName, tapHandler); + }); +} + +var mouseEvents = ['mousedown', 'mouseup']; +var touchEvents = ['touchstart', 'touchend']; + +function disable(element) { + removeEvents(element, mouseEvents, pointerType.mouse); + removeEvents(element, touchEvents, pointerType.touch); +} + +function enable(element) { + disable(element); + attachEvents(element, mouseEvents, pointerType.mouse); + attachEvents(element, touchEvents, pointerType.touch); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventListeners/touchEventListeners.js": +/*!***********************************************!*\ + !*** ./eventListeners/touchEventListeners.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/copyPoints.js */ "./util/copyPoints.js"); +/* harmony import */ var _preventGhostClick_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./preventGhostClick.js */ "./eventListeners/preventGhostClick.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _toolOptions_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../toolOptions.js */ "./toolOptions.js"); + + + + + + +var startPoints, currentPoints, lastPoints, deltaPoints, eventData, touchStartDelay, pressTimeout, pageDistanceMoved; +var lastScale = 1.0, + lastRotation = 0.0, + preventNextPinch = false, + isPress = false, + lastDelta; +var pressDelay = 700, + pressMaxDistance = 5; +var inputName = 'touchInput'; + +function onTouch(e) { + var element = e.currentTarget || e.srcEvent.currentTarget; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + var eventType, scaleChange, delta, remainingPointers, rotation; // Prevent mouse events from occurring alongside touch events + + e.preventDefault(); // If more than one finger is placed on the element, stop the press timeout + + if (e.pointers && e.pointers.length > 1 || e.touches && e.touches.length > 1) { + isPress = false; + clearTimeout(pressTimeout); + } + + switch (e.type) { + case 'tap': + isPress = false; + clearTimeout(pressTimeout); // Calculate our current points in page and image coordinates + + currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.pointers[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pointers[0].pageX, e.pointers[0].pageY), + client: { + x: e.pointers[0].clientX, + y: e.pointers[0].clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP; + eventData = { + event: e, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + currentPoints: currentPoints, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + break; + + case 'doubletap': + isPress = false; + clearTimeout(pressTimeout); // Calculate our current points in page and image coordinates + + currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.pointers[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pointers[0].pageX, e.pointers[0].pageY), + client: { + x: e.pointers[0].clientX, + y: e.pointers[0].clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].DOUBLE_TAP; + eventData = { + event: e, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + currentPoints: currentPoints, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + break; + + case 'pinchstart': + isPress = false; + clearTimeout(pressTimeout); + lastScale = 1.0; + break; + + case 'pinchmove': + isPress = false; + clearTimeout(pressTimeout); + + if (preventNextPinch === true) { + lastScale = e.scale; + preventNextPinch = false; + break; + } + + scaleChange = (e.scale - lastScale) / lastScale; + startPoints = { + page: e.center, + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.center.x, e.center.y) + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH; + eventData = { + event: e, + startPoints: startPoints, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + direction: e.scale < 1 ? 1 : -1, + scaleChange: scaleChange, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + lastScale = e.scale; + break; + + case 'touchstart': + lastScale = 1.0; + clearTimeout(pressTimeout); + clearTimeout(touchStartDelay); + touchStartDelay = setTimeout(function () { + startPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.touches[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.touches[0].pageX, e.touches[0].pageY), + client: { + x: e.touches[0].clientX, + y: e.touches[0].clientY + } + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START; + + if (e.touches.length > 1) { + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MULTI_TOUCH_START; + } + + eventData = { + event: e, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + currentPoints: startPoints, + type: eventType, + isTouchEvent: true + }; + var eventPropagated = Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + + if (eventPropagated === true) { + // IsPress = false; + // ClearTimeout(pressTimeout); + // No current tools responded to the drag action. + // Create new tool measurement + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START_ACTIVE; + + if (e.touches.length > 1) { + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MULTI_TOUCH_START_ACTIVE; + } + + eventData.type = eventType; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + } // Console.log(eventType); + + + lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(startPoints); + }, 50); + isPress = true; + pageDistanceMoved = 0; + pressTimeout = setTimeout(function () { + if (!isPress) { + return; + } + + currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.touches[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.touches[0].pageX, e.touches[0].pageY), + client: { + x: e.touches[0].clientX, + y: e.touches[0].clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PRESS; + eventData = { + event: e, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + currentPoints: currentPoints, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); // Console.log(eventType); + }, pressDelay); + break; + + case 'touchend': + lastScale = 1.0; + isPress = false; + clearTimeout(pressTimeout); + setTimeout(function () { + startPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.changedTouches[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.changedTouches[0].pageX, e.changedTouches[0].pageY), + client: { + x: e.changedTouches[0].clientX, + y: e.changedTouches[0].clientY + } + }; + startPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, startPoints.image); + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END; + eventData = { + event: e, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + currentPoints: startPoints, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + }, 50); + break; + + case 'panmove': + // Using the delta-value of HammerJS, because it takes all pointers into account + // This is very important when using panning in combination with pinch-zooming + // But HammerJS' delta is relative to the start of the pan event + // So it needs to be converted to a per-event-delta for CornerstoneTools + delta = { + x: e.deltaX - lastDelta.x, + y: e.deltaY - lastDelta.y + }; + lastDelta = { + x: e.deltaX, + y: e.deltaY + }; // Calculate our current points in page and image coordinates + + currentPoints = { + page: { + x: lastPoints.page.x + delta.x, + y: lastPoints.page.y + delta.y + }, + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, lastPoints.page.x + delta.x, lastPoints.page.y + delta.y), + client: { + x: lastPoints.client.x + delta.x, + y: lastPoints.client.y + delta.y + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); // Calculate delta values in page and image coordinates + + deltaPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image), + client: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client), + canvas: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas) + }; + pageDistanceMoved += Math.sqrt(deltaPoints.page.x * deltaPoints.page.x + deltaPoints.page.y * deltaPoints.page.y); // Console.log("pageDistanceMoved: " + pageDistanceMoved); + + if (pageDistanceMoved > pressMaxDistance) { + // Console.log('Press event aborted due to movement'); + isPress = false; + clearTimeout(pressTimeout); + } + + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG; + + if (e.pointers.length > 1) { + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MULTI_TOUCH_DRAG; + } + + eventData = { + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: currentPoints, + deltaPoints: deltaPoints, + numPointers: e.pointers.length, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(currentPoints); + break; + + case 'panstart': + lastDelta = { + x: e.deltaX, + y: e.deltaY + }; + currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.pointers[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pointers[0].pageX, e.pointers[0].pageY), + client: { + x: e.pointers[0].clientX, + y: e.pointers[0].clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); + lastPoints = Object(_util_copyPoints_js__WEBPACK_IMPORTED_MODULE_2__["default"])(currentPoints); + break; + + case 'panend': + isPress = false; + clearTimeout(pressTimeout); // If lastPoints is not yet set, it means panend fired without panstart or pan, + // So we can ignore this event + + if (!lastPoints) { + return false; + } + + currentPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.pageToPoint(e.pointers[0]), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, e.pointers[0].pageX, e.pointers[0].pageY), + client: { + x: e.pointers[0].clientX, + y: e.pointers[0].clientY + } + }; + currentPoints.canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, currentPoints.image); // Calculate delta values in page and image coordinates + + deltaPoints = { + page: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.page, lastPoints.page), + image: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.image, lastPoints.image), + client: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.client, lastPoints.client), + canvas: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.subtract(currentPoints.canvas, lastPoints.canvas) + }; + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG_END; + eventData = { + event: e.srcEvent, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + startPoints: startPoints, + lastPoints: lastPoints, + currentPoints: currentPoints, + deltaPoints: deltaPoints, + type: eventType, + isTouchEvent: true + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + remainingPointers = e.pointers.length - e.changedPointers.length; + + if (remainingPointers === 2) { + preventNextPinch = true; + } + + break; + + case 'rotatemove': + isPress = false; + clearTimeout(pressTimeout); + rotation = e.rotation - lastRotation; + lastRotation = e.rotation; + eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_ROTATE; + eventData = { + event: e.srcEvent, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + image: enabledElement.image, + element: element, + rotation: rotation, + type: eventType + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, eventData); + break; + } + + return false; +} + +function enable(element) { + disable(element); + var Hammer = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].Hammer; + var hammerOptions = { + inputClass: Hammer.SUPPORT_POINTER_EVENTS ? Hammer.PointerEventInput : Hammer.TouchInput + }; + var mc = new Hammer.Manager(element, hammerOptions); + var panOptions = { + pointers: 0, + direction: Hammer.DIRECTION_ALL, + threshold: 0 + }; + var pan = new Hammer.Pan(panOptions); + var pinch = new Hammer.Pinch({ + threshold: 0 + }); + var rotate = new Hammer.Rotate({ + threshold: 0 + }); + pinch.recognizeWith(pan); + pinch.recognizeWith(rotate); + rotate.recognizeWith(pan); + var doubleTap = new Hammer.Tap({ + event: 'doubletap', + taps: 2, + interval: 1500, + threshold: 50, + posThreshold: 50 + }); + doubleTap.recognizeWith(pan); // Add to the Manager + + mc.add([doubleTap, pan, rotate, pinch]); + mc.on('tap doubletap panstart panmove panend pinchstart pinchmove rotatemove', onTouch); + _preventGhostClick_js__WEBPACK_IMPORTED_MODULE_3__["default"].enable(element); + var touchEvents = ['touchstart', 'touchend']; + touchEvents.forEach(function (eventType) { + element.addEventListener(eventType, onTouch, { + passive: false + }); + }); // TODO: Check why we are using tool options if it's not a tool + + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_5__["getToolOptions"])(inputName, element); + options.hammer = mc; // TODO: Check why we are using tool options if it's not a tool + + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_5__["setToolOptions"])(inputName, element, options); +} + +function disable(element) { + _preventGhostClick_js__WEBPACK_IMPORTED_MODULE_3__["default"].disable(element); + var touchEvents = ['touchstart', 'touchend']; + touchEvents.forEach(function (eventType) { + element.removeEventListener(eventType, onTouch); + }); // TODO: Check why we are using tool options if it's not a tool + + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_5__["getToolOptions"])(inputName, element); + var mc = options.hammer; + + if (mc) { + mc.off('tap doubletap panstart panmove panend pinchstart pinchmove rotatemove', onTouch); + mc.input.destroy(); + } + + options.hammer = null; + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_5__["clearToolOptions"])(inputName, element); +} // Module exports + + +var touchInput = { + enable: enable, + disable: disable +}; +/* harmony default export */ __webpack_exports__["default"] = (touchInput); + +/***/ }), + +/***/ "./eventListeners/wheelEventListener.js": +/*!**********************************************!*\ + !*** ./eventListeners/wheelEventListener.js ***! + \**********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _internals_normalizeWheel_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./internals/normalizeWheel.js */ "./eventListeners/internals/normalizeWheel.js"); +/** + * Internal module used to turn on listening, handling, and normalizing of the + * native `wheel` event + */ + + + + +/** + * + * @private + * @function wheelEventHandler + * @param {WheelEvent} evt + * @returns {undefined} + */ + +function wheelEventHandler(evt) { + var element = evt.currentTarget; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } // Prevent triggering MouseWheel events that are not real scroll events: + // E.g. when clicking the MiddleMouseWheelButton, a deltaY of 0 is emitted. + // See https://github.com/cornerstonejs/cornerstoneTools/issues/935 + + + if (evt.deltaY > -1 && evt.deltaY < 1) { + return; + } + + evt.preventDefault(); + var pageX = evt.pageX, + pageY = evt.pageY; + var startingCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pageToPixel(element, pageX, pageY); + + var _normalizeWheel = Object(_internals_normalizeWheel_js__WEBPACK_IMPORTED_MODULE_3__["default"])(evt), + spinX = _normalizeWheel.spinX, + spinY = _normalizeWheel.spinY, + pixelX = _normalizeWheel.pixelX, + pixelY = _normalizeWheel.pixelY; + + var direction = spinY < 0 ? -1 : 1; + var mouseWheelData = { + element: element, + viewport: _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getViewport(element), + detail: evt, + image: enabledElement.image, + direction: direction, + spinX: spinX, + spinY: spinY, + pixelX: pixelX, + pixelY: pixelY, + pageX: pageX, + pageY: pageY, + imageX: startingCoords.x, + imageY: startingCoords.y + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_WHEEL, mouseWheelData); +} +/** + * Listens for the wheel event, and handles it. Handled event + * will be "normalized" and re-emitted as `EVENTS.MOUSE_WHEEL` + * + * @private + * @param {HTMLElement} element + * @returns {undefined} + */ + + +function enable(element) { + disable(element); + element.addEventListener('wheel', wheelEventHandler, { + passive: false + }); +} +/** + * Removes listener and handler for wheel event. `EVENTS.MOUSE_WHEEL` + * will no longer be emitted. + * + * @private + * @param {HTMLElement} element + * @returns {undefined} + */ + + +function disable(element) { + element.removeEventListener('wheel', wheelEventHandler, { + passive: false + }); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./eventListeners/windowResizeHandler.js": +/*!***********************************************!*\ + !*** ./eventListeners/windowResizeHandler.js ***! + \***********************************************/ +/*! exports provided: forceEnabledElementResize, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "forceEnabledElementResize", function() { return forceEnabledElementResize; }); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); + + + +var enable = function enable() { + disable(); // Clean up any lingering listeners + + window.addEventListener('resize', resizeThrottler, false); +}; + +var disable = function disable() { + window.removeEventListener('resize', resizeThrottler, false); +}; + +var resizeTimeout; + +function resizeThrottler() { + // Ignore resize events as long as an actualResizeHandler execution is in the queue + if (!resizeTimeout) { + resizeTimeout = setTimeout(function () { + resizeTimeout = null; + forceEnabledElementResize(); // The actualResizeHandler will execute at a rate of 15fps + }, 66); + } +} + +var forceEnabledElementResize = function forceEnabledElementResize() { + _store_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].enabledElements.forEach(function (element) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.resize(element); + }); +}; +/* harmony default export */ __webpack_exports__["default"] = ({ + enable: enable, + disable: disable +}); + +/***/ }), + +/***/ "./events.js": +/*!*******************!*\ + !*** ./events.js ***! + \*******************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Enumerates the events for CornestoneTools. Native events are captured, + * normalized, and re-triggered with a `cornerstonetools` prefix. This allows + * us to handle events consistently across different browsers. + * + * @enum {String} + * @memberof CornerstoneTools + * @readonly + */ +var EVENTS = { + // + // MOUSE + // + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/mousedown + * @type {String} + */ + MOUSE_DOWN: 'cornerstonetoolsmousedown', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/mouseup + * @type {String} + */ + MOUSE_UP: 'cornerstonetoolsmouseup', + + /** + * Is fired if a handled `MOUSE_DOWN` event does not `stopPropagation`. The hook + * we use to create new measurement data for mouse events. + * @type {String} + */ + MOUSE_DOWN_ACTIVATE: 'cornerstonetoolsmousedownactivate', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/drag + * @type {String} + */ + MOUSE_DRAG: 'cornerstonetoolsmousedrag', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/mousemove + * @type {String} + */ + MOUSE_MOVE: 'cornerstonetoolsmousemove', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/click + * @type {String} + */ + MOUSE_CLICK: 'cornerstonetoolsmouseclick', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/dblclick + * @type {String} + */ + MOUSE_DOUBLE_CLICK: 'cornerstonetoolsmousedoubleclick', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/wheel + * @type {String} + */ + MOUSE_WHEEL: 'cornerstonetoolsmousewheel', + // + // TOUCH + // + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/touchstart + * @type {String} + */ + TOUCH_START: 'cornerstonetoolstouchstart', + + /** + * Is fired if a handled `TOUCH_START` event does not `stopPropagation`. The hook + * we use to create new measurement data for touch events. + * @type {String} + */ + TOUCH_START_ACTIVE: 'cornerstonetoolstouchstartactive', + + /** + * @type {String} + */ + TOUCH_END: 'cornerstonetoolstouchend', + + /** + * @type {String} + */ + TOUCH_DRAG: 'cornerstonetoolstouchdrag', + + /** + * @type {String} + */ + TOUCH_DRAG_END: 'cornerstonetoolstouchdragend', + + /** + * http://hammerjs.github.io/recognizer-pinch/ + * @type {String} + */ + TOUCH_PINCH: 'cornerstonetoolstouchpinch', + + /** + * http://hammerjs.github.io/recognizer-rotate/ + * @type {String} + */ + TOUCH_ROTATE: 'cornerstonetoolstouchrotate', + + /** + * http://hammerjs.github.io/recognizer-press/ + * @type {String} + */ + TOUCH_PRESS: 'cornerstonetoolstouchpress', + + /** + * http://hammerjs.github.io/recognizer-tap/ + * @type {String} + */ + TAP: 'cornerstonetoolstap', + + /** + * @type {String} + */ + DOUBLE_TAP: 'cornerstonetoolsdoubletap', + + /** + * @type {String} + */ + MULTI_TOUCH_START: 'cornerstonetoolsmultitouchstart', + + /** + * @type {String} + */ + MULTI_TOUCH_START_ACTIVE: 'cornerstonetoolsmultitouchstartactive', + + /** + * @type {String} + */ + MULTI_TOUCH_DRAG: 'cornerstonetoolsmultitouchdrag', + // + // KEYBOARD + // + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/keydown + * @type {String} + */ + KEY_DOWN: 'cornerstonetoolskeydown', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/keyup + * @type {String} + */ + KEY_UP: 'cornerstonetoolskeyup', + + /** + * https://developer.mozilla.org/en-US/docs/Web/Events/keypress + * @type {String} + */ + KEY_PRESS: 'cornerstonetoolskeypress', + // + // CUSTOM + // + + /** + * @type {String} + */ + MEASUREMENT_ADDED: 'cornerstonetoolsmeasurementadded', + + /** + * @type {String} + */ + MEASUREMENT_MODIFIED: 'cornerstonetoolsmeasurementmodified', + + /** + * @type {String} + */ + MEASUREMENT_COMPLETED: 'cornerstonetoolsmeasurementcompleted', + + /** + * @type {String} + */ + MEASUREMENT_REMOVED: 'cornerstonetoolsmeasurementremoved', + + /** + * @type {String} + */ + TOOL_DEACTIVATED: 'cornerstonetoolstooldeactivated', + + /** + * @type {String} + */ + CLIP_STOPPED: 'cornerstonetoolsclipstopped', + + /** + * @type {String} + */ + STACK_SCROLL: 'cornerstonetoolsstackscroll', + + /** + * @type {String} + */ + STACK_PREFETCH_IMAGE_LOADED: 'cornerstonetoolsstackprefetchimageloaded', + + /** + * @type {String} + */ + STACK_PREFETCH_DONE: 'cornerstonetoolsstackprefetchdone', + + /** + * @type {String} + */ + LABELMAP_MODIFIED: 'cornersontetoolslabelmapmodified' +}; +/* harmony default export */ __webpack_exports__["default"] = (EVENTS); + +/***/ }), + +/***/ "./externalModules.js": +/*!****************************!*\ + !*** ./externalModules.js ***! + \****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var cornerstone = window.cornerstone; +var cornerstoneMath = window.cornerstoneMath; +var Hammer = window.Hammer; +/* harmony default export */ __webpack_exports__["default"] = ({ + set cornerstone(cs) { + cornerstone = cs; + }, + + get cornerstone() { + return cornerstone; + }, + + set cornerstoneMath(cm) { + cornerstoneMath = cm; + }, + + get cornerstoneMath() { + return cornerstoneMath; + }, + + set Hammer(module) { + Hammer = module; + }, + + get Hammer() { + return Hammer; + } + +}); + +/***/ }), + +/***/ "./importInternal.js": +/*!***************************!*\ + !*** ./importInternal.js ***! + \***************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib.js */ "./lib.js"); + +/** + * Imports functionality from cornerstoneTools for use in external packages/plugins. + * @param {string} uri the import path for the entity to import. + * @returns {Class|Object|Function} The entity requested. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (uri) { + return _lib_js__WEBPACK_IMPORTED_MODULE_0__["lib"][uri]; +}); + +/***/ }), + +/***/ "./index.js": +/*!******************!*\ + !*** ./index.js ***! + \******************/ +/*! exports provided: AngleTool, ArrowAnnotateTool, BidirectionalTool, CircleRoiTool, CobbAngleTool, EllipticalRoiTool, FreehandRoiTool, LengthTool, ProbeTool, RectangleRoiTool, TextMarkerTool, BrushTool, SphericalBrushTool, RectangleScissorsTool, FreehandScissorsTool, CircleScissorsTool, CorrectionScissorsTool, CrosshairsTool, DoubleTapFitToWindowTool, DragProbeTool, EraserTool, FreehandRoiSculptorTool, MagnifyTool, OverlayTool, OrientationMarkersTool, PanMultiTouchTool, PanTool, ReferenceLinesTool, RotateTool, RotateTouchTool, ScaleOverlayTool, StackScrollMouseWheelTool, StackScrollMultiTouchTool, StackScrollTool, WwwcRegionTool, WwwcTool, ZoomMouseWheelTool, ZoomTool, ZoomTouchPinchTool, init, stackPrefetch, stackRenderers, playClip, stopClip, store, getModule, getToolForElement, addTool, addToolForElement, removeTool, removeToolForElement, setToolOptions, setToolOptionsForElement, isToolActiveForElement, setToolActive, setToolActiveForElement, setToolEnabled, setToolEnabledForElement, setToolDisabled, setToolDisabledForElement, setToolPassive, setToolPassiveForElement, addToolState, getToolState, removeToolState, clearToolState, setElementToolStateManager, getElementToolStateManager, textStyle, toolStyle, toolColors, toolCoordinates, stackSpecificStateManager, newStackSpecificToolStateManager, addStackStateManager, loadHandlerManager, newImageIdSpecificToolStateManager, globalImageIdSpecificToolStateManager, newFrameOfReferenceSpecificToolStateManager, globalFrameOfReferenceSpecificToolStateManager, forceEnabledElementResize, orientation, SaveAs, enableLogger, disableLogger, register, registerSome, wwwcSynchronizer, updateImageSynchronizer, Synchronizer, stackScrollSynchronizer, stackImagePositionSynchronizer, stackImagePositionOffsetSynchronizer, stackImageIndexSynchronizer, panZoomSynchronizer, importInternal, external, EVENTS, version, import, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools/annotation/index.js */ "./tools/annotation/index.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AngleTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["AngleTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrowAnnotateTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["ArrowAnnotateTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BidirectionalTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["BidirectionalTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CircleRoiTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["CircleRoiTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CobbAngleTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["CobbAngleTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EllipticalRoiTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["EllipticalRoiTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandRoiTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["FreehandRoiTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LengthTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["LengthTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ProbeTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["ProbeTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RectangleRoiTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["RectangleRoiTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TextMarkerTool", function() { return _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["TextMarkerTool"]; }); + +/* harmony import */ var _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./tools/segmentation/index.js */ "./tools/segmentation/index.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BrushTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["BrushTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SphericalBrushTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["SphericalBrushTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RectangleScissorsTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["RectangleScissorsTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandScissorsTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["FreehandScissorsTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CircleScissorsTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["CircleScissorsTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CorrectionScissorsTool", function() { return _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["CorrectionScissorsTool"]; }); + +/* harmony import */ var _tools_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tools/index.js */ "./tools/index.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CrosshairsTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["CrosshairsTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DoubleTapFitToWindowTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["DoubleTapFitToWindowTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DragProbeTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["DragProbeTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EraserTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["EraserTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandRoiSculptorTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["FreehandRoiSculptorTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MagnifyTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["MagnifyTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OverlayTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["OverlayTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OrientationMarkersTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["OrientationMarkersTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PanMultiTouchTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["PanMultiTouchTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PanTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["PanTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ReferenceLinesTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ReferenceLinesTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RotateTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["RotateTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RotateTouchTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["RotateTouchTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScaleOverlayTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ScaleOverlayTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollMouseWheelTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollMouseWheelTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollMultiTouchTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollMultiTouchTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WwwcRegionTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["WwwcRegionTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WwwcTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["WwwcTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomMouseWheelTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomMouseWheelTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomTouchPinchTool", function() { return _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomTouchPinchTool"]; }); + +/* harmony import */ var _init_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./init.js */ "./init.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "init", function() { return _init_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _stackTools_stackPrefetch_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./stackTools/stackPrefetch.js */ "./stackTools/stackPrefetch.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackPrefetch", function() { return _stackTools_stackPrefetch_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony import */ var _stackTools_stackRenderers_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./stackTools/stackRenderers.js */ "./stackTools/stackRenderers.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackRenderers", function() { return _stackTools_stackRenderers_js__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + +/* harmony import */ var _stackTools_playClip_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./stackTools/playClip.js */ "./stackTools/playClip.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "playClip", function() { return _stackTools_playClip_js__WEBPACK_IMPORTED_MODULE_6__["playClip"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stopClip", function() { return _stackTools_playClip_js__WEBPACK_IMPORTED_MODULE_6__["stopClip"]; }); + +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./store/index.js */ "./store/index.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "store", function() { return _store_index_js__WEBPACK_IMPORTED_MODULE_7__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getModule", function() { return _store_index_js__WEBPACK_IMPORTED_MODULE_7__["getModule"]; }); + +/* harmony import */ var _store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./store/getToolForElement.js */ "./store/getToolForElement.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getToolForElement", function() { return _store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_8__["default"]; }); + +/* harmony import */ var _store_addTool_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./store/addTool.js */ "./store/addTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "addTool", function() { return _store_addTool_js__WEBPACK_IMPORTED_MODULE_9__["addTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "addToolForElement", function() { return _store_addTool_js__WEBPACK_IMPORTED_MODULE_9__["addToolForElement"]; }); + +/* harmony import */ var _store_removeTool_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./store/removeTool.js */ "./store/removeTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeTool", function() { return _store_removeTool_js__WEBPACK_IMPORTED_MODULE_10__["removeTool"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeToolForElement", function() { return _store_removeTool_js__WEBPACK_IMPORTED_MODULE_10__["removeToolForElement"]; }); + +/* harmony import */ var _store_setToolOptions_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./store/setToolOptions.js */ "./store/setToolOptions.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolOptions", function() { return _store_setToolOptions_js__WEBPACK_IMPORTED_MODULE_11__["setToolOptions"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolOptionsForElement", function() { return _store_setToolOptions_js__WEBPACK_IMPORTED_MODULE_11__["setToolOptionsForElement"]; }); + +/* harmony import */ var _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./store/setToolMode.js */ "./store/setToolMode.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolActive", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolActive"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolActiveForElement", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolActiveForElement"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolEnabled", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolEnabled"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolEnabledForElement", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolEnabledForElement"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolDisabled", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolDisabled"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolDisabledForElement", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolDisabledForElement"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolPassive", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolPassive"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setToolPassiveForElement", function() { return _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolPassiveForElement"]; }); + +/* harmony import */ var _store_isToolActiveForElement__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./store/isToolActiveForElement */ "./store/isToolActiveForElement.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isToolActiveForElement", function() { return _store_isToolActiveForElement__WEBPACK_IMPORTED_MODULE_13__["default"]; }); + +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "addToolState", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["addToolState"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getToolState", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["getToolState"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "removeToolState", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["removeToolState"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "clearToolState", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["clearToolState"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "setElementToolStateManager", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["setElementToolStateManager"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getElementToolStateManager", function() { return _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["getElementToolStateManager"]; }); + +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "textStyle", function() { return _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_15__["default"]; }); + +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toolStyle", function() { return _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_16__["default"]; }); + +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toolColors", function() { return _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_17__["default"]; }); + +/* harmony import */ var _stateManagement_toolCoordinates_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./stateManagement/toolCoordinates.js */ "./stateManagement/toolCoordinates.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toolCoordinates", function() { return _stateManagement_toolCoordinates_js__WEBPACK_IMPORTED_MODULE_18__["default"]; }); + +/* harmony import */ var _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./stateManagement/stackSpecificStateManager.js */ "./stateManagement/stackSpecificStateManager.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackSpecificStateManager", function() { return _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["stackSpecificStateManager"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "newStackSpecificToolStateManager", function() { return _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["newStackSpecificToolStateManager"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "addStackStateManager", function() { return _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["addStackStateManager"]; }); + +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "loadHandlerManager", function() { return _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_20__["default"]; }); + +/* harmony import */ var _stateManagement_imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./stateManagement/imageIdSpecificStateManager.js */ "./stateManagement/imageIdSpecificStateManager.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "newImageIdSpecificToolStateManager", function() { return _stateManagement_imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_21__["newImageIdSpecificToolStateManager"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "globalImageIdSpecificToolStateManager", function() { return _stateManagement_imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_21__["globalImageIdSpecificToolStateManager"]; }); + +/* harmony import */ var _stateManagement_frameOfReferenceStateManager_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./stateManagement/frameOfReferenceStateManager.js */ "./stateManagement/frameOfReferenceStateManager.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "newFrameOfReferenceSpecificToolStateManager", function() { return _stateManagement_frameOfReferenceStateManager_js__WEBPACK_IMPORTED_MODULE_22__["newFrameOfReferenceSpecificToolStateManager"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "globalFrameOfReferenceSpecificToolStateManager", function() { return _stateManagement_frameOfReferenceStateManager_js__WEBPACK_IMPORTED_MODULE_22__["globalFrameOfReferenceSpecificToolStateManager"]; }); + +/* harmony import */ var _eventListeners_windowResizeHandler_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./eventListeners/windowResizeHandler.js */ "./eventListeners/windowResizeHandler.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "forceEnabledElementResize", function() { return _eventListeners_windowResizeHandler_js__WEBPACK_IMPORTED_MODULE_23__["forceEnabledElementResize"]; }); + +/* harmony import */ var _orientation_index_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./orientation/index.js */ "./orientation/index.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "orientation", function() { return _orientation_index_js__WEBPACK_IMPORTED_MODULE_24__["default"]; }); + +/* harmony import */ var _util_SaveAs_js__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./util/SaveAs.js */ "./util/SaveAs.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SaveAs", function() { return _util_SaveAs_js__WEBPACK_IMPORTED_MODULE_25__["default"]; }); + +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./util/logger.js */ "./util/logger.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "enableLogger", function() { return _util_logger_js__WEBPACK_IMPORTED_MODULE_26__["enable"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "disableLogger", function() { return _util_logger_js__WEBPACK_IMPORTED_MODULE_26__["disable"]; }); + +/* harmony import */ var _thirdParty_register_js__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ./thirdParty/register.js */ "./thirdParty/register.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "register", function() { return _thirdParty_register_js__WEBPACK_IMPORTED_MODULE_27__["default"]; }); + +/* harmony import */ var _thirdParty_registerSome_js__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./thirdParty/registerSome.js */ "./thirdParty/registerSome.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "registerSome", function() { return _thirdParty_registerSome_js__WEBPACK_IMPORTED_MODULE_28__["default"]; }); + +/* harmony import */ var _synchronization_wwwcSynchronizer_js__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ./synchronization/wwwcSynchronizer.js */ "./synchronization/wwwcSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "wwwcSynchronizer", function() { return _synchronization_wwwcSynchronizer_js__WEBPACK_IMPORTED_MODULE_29__["default"]; }); + +/* harmony import */ var _synchronization_updateImageSynchronizer_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./synchronization/updateImageSynchronizer.js */ "./synchronization/updateImageSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "updateImageSynchronizer", function() { return _synchronization_updateImageSynchronizer_js__WEBPACK_IMPORTED_MODULE_30__["default"]; }); + +/* harmony import */ var _synchronization_Synchronizer_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ./synchronization/Synchronizer.js */ "./synchronization/Synchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Synchronizer", function() { return _synchronization_Synchronizer_js__WEBPACK_IMPORTED_MODULE_31__["default"]; }); + +/* harmony import */ var _synchronization_stackScrollSynchronizer_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ./synchronization/stackScrollSynchronizer.js */ "./synchronization/stackScrollSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackScrollSynchronizer", function() { return _synchronization_stackScrollSynchronizer_js__WEBPACK_IMPORTED_MODULE_32__["default"]; }); + +/* harmony import */ var _synchronization_stackImagePositionSynchronizer_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./synchronization/stackImagePositionSynchronizer.js */ "./synchronization/stackImagePositionSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackImagePositionSynchronizer", function() { return _synchronization_stackImagePositionSynchronizer_js__WEBPACK_IMPORTED_MODULE_33__["default"]; }); + +/* harmony import */ var _synchronization_stackImagePositionOffsetSynchronizer_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./synchronization/stackImagePositionOffsetSynchronizer.js */ "./synchronization/stackImagePositionOffsetSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackImagePositionOffsetSynchronizer", function() { return _synchronization_stackImagePositionOffsetSynchronizer_js__WEBPACK_IMPORTED_MODULE_34__["default"]; }); + +/* harmony import */ var _synchronization_stackImageIndexSynchronizer_js__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ./synchronization/stackImageIndexSynchronizer.js */ "./synchronization/stackImageIndexSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "stackImageIndexSynchronizer", function() { return _synchronization_stackImageIndexSynchronizer_js__WEBPACK_IMPORTED_MODULE_35__["default"]; }); + +/* harmony import */ var _synchronization_panZoomSynchronizer_js__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ./synchronization/panZoomSynchronizer.js */ "./synchronization/panZoomSynchronizer.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "panZoomSynchronizer", function() { return _synchronization_panZoomSynchronizer_js__WEBPACK_IMPORTED_MODULE_36__["default"]; }); + +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_37__ = __webpack_require__(/*! ./externalModules.js */ "./externalModules.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "external", function() { return _externalModules_js__WEBPACK_IMPORTED_MODULE_37__["default"]; }); + +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_38__ = __webpack_require__(/*! ./events.js */ "./events.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EVENTS", function() { return _events_js__WEBPACK_IMPORTED_MODULE_38__["default"]; }); + +/* harmony import */ var _version_js__WEBPACK_IMPORTED_MODULE_39__ = __webpack_require__(/*! ./version.js */ "./version.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "version", function() { return _version_js__WEBPACK_IMPORTED_MODULE_39__["default"]; }); + +/* harmony import */ var _importInternal_js__WEBPACK_IMPORTED_MODULE_40__ = __webpack_require__(/*! ./importInternal.js */ "./importInternal.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "importInternal", function() { return _importInternal_js__WEBPACK_IMPORTED_MODULE_40__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "import", function() { return _importInternal_js__WEBPACK_IMPORTED_MODULE_40__["default"]; }); + +/** + * Root + * @namespace CornerstoneTools + */ + +/** + * Drawing API to assist in consistent annotation creation + * @namespace Drawing + */ + +/** + * Event dispatchers listen for events from `cornerstone` and `enabledElements`. Dispatchers + * choose which tool(s) get to handle the event by looking at callbacks, priority, and other factors. + * @private + * @namespace EventDispatchers + */ + +/** + * Event listeners normalize events emitted by `cornerstone` and `enabledElements`. The listeners + * then re-emit events prefixed with `cornerstonetools`. For example, `mousemove` becomes `cornerstonetoolsmousemove`. + * Most of these events are caught by an `eventDispatcher`, and used to shape tool behavior. + * @private + * @namespace EventListeners + */ + +/** + * Manipulators describe a tool's `handle` behavior. Leveraging a small set of manipulators + * allows us to create a consistent experience when interacting with tools via their handles. + * @namespace Manipulators + */ + +/** + * Mixins are "tool beahviors" that can be added to a tool via its mixin + * array configuration property + * @namespace Mixins + */ + +/** + * StateManagement + * @namespace StateManagement + */ + +/** + * Sync + * @namespace Synchronization + */ + +/** + * Third party + * @namespace ThirdParty + */ + +/** + * Tools + * @namespace Tools + */ + +/** + * Tools that extend the {@link #Tools.Base.BaseAnnotationTool|`BaseAnnotationTool`} + * @namespace Tools.Annotation + */ + +/** + * The parent (abstract) classes that all tools derive from. + * @namespace Tools.Base + */ + +/** + * Tools that extend the {@link #Tools.Base.BaseBrushTool|`BaseBrushTool`} + * @namespace Tools.Brush + */ + +/** + * Util + * @namespace Util + */ + + + + // ~~~~~~ STACK TOOLS ~~~~~ // + + + + // ~~~~~~ STATE MANAGEMENT ~~~~~ // + + + + + + + + + + + + + + + + + + + // ~~~~~~ ORIENTATION ~~~~~ // + + // ~~~~~~ CANVAS EXPORT ~~~~~ // + + + // ~~~~~~ THIRD PARTY SUPPORT ~~~~~ // + + + // ~~~~~~ SYNCHRONIZERS ~~~~~ // + + + + + + + + + // ~~~~~~ REQUEST POOL MANAGER ~~~~~ // + + + + + +var cornerstoneTools = { + // ~~~ TOOLS + // ~ Annotation Tools + AngleTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["AngleTool"], + ArrowAnnotateTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["ArrowAnnotateTool"], + BidirectionalTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["BidirectionalTool"], + CircleRoiTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["CircleRoiTool"], + CobbAngleTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["CobbAngleTool"], + EllipticalRoiTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["EllipticalRoiTool"], + FreehandRoiTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["FreehandRoiTool"], + LengthTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["LengthTool"], + ProbeTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["ProbeTool"], + RectangleRoiTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["RectangleRoiTool"], + TextMarkerTool: _tools_annotation_index_js__WEBPACK_IMPORTED_MODULE_0__["TextMarkerTool"], + // ~ Segmentation Tools + BrushTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["BrushTool"], + SphericalBrushTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["SphericalBrushTool"], + RectangleScissorsTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["RectangleScissorsTool"], + FreehandScissorsTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["FreehandScissorsTool"], + CircleScissorsTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["CircleScissorsTool"], + CorrectionScissorsTool: _tools_segmentation_index_js__WEBPACK_IMPORTED_MODULE_1__["CorrectionScissorsTool"], + // ~ Tools + CrosshairsTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["CrosshairsTool"], + DoubleTapFitToWindowTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["DoubleTapFitToWindowTool"], + DragProbeTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["DragProbeTool"], + EraserTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["EraserTool"], + FreehandRoiSculptorTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["FreehandRoiSculptorTool"], + MagnifyTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["MagnifyTool"], + OverlayTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["OverlayTool"], + OrientationMarkersTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["OrientationMarkersTool"], + PanMultiTouchTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["PanMultiTouchTool"], + PanTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["PanTool"], + ReferenceLinesTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ReferenceLinesTool"], + RotateTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["RotateTool"], + RotateTouchTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["RotateTouchTool"], + ScaleOverlayTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ScaleOverlayTool"], + StackScrollMouseWheelTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollMouseWheelTool"], + StackScrollMultiTouchTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollMultiTouchTool"], + StackScrollTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["StackScrollTool"], + WwwcRegionTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["WwwcRegionTool"], + WwwcTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["WwwcTool"], + ZoomMouseWheelTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomMouseWheelTool"], + ZoomTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomTool"], + ZoomTouchPinchTool: _tools_index_js__WEBPACK_IMPORTED_MODULE_2__["ZoomTouchPinchTool"], + init: _init_js__WEBPACK_IMPORTED_MODULE_3__["default"], + stackPrefetch: _stackTools_stackPrefetch_js__WEBPACK_IMPORTED_MODULE_4__["default"], + stackRenderers: _stackTools_stackRenderers_js__WEBPACK_IMPORTED_MODULE_5__["default"], + playClip: _stackTools_playClip_js__WEBPACK_IMPORTED_MODULE_6__["playClip"], + stopClip: _stackTools_playClip_js__WEBPACK_IMPORTED_MODULE_6__["stopClip"], + store: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["default"], + getModule: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["getModule"], + getToolForElement: _store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_8__["default"], + addTool: _store_addTool_js__WEBPACK_IMPORTED_MODULE_9__["addTool"], + addToolForElement: _store_addTool_js__WEBPACK_IMPORTED_MODULE_9__["addToolForElement"], + removeTool: _store_removeTool_js__WEBPACK_IMPORTED_MODULE_10__["removeTool"], + removeToolForElement: _store_removeTool_js__WEBPACK_IMPORTED_MODULE_10__["removeToolForElement"], + setToolOptions: _store_setToolOptions_js__WEBPACK_IMPORTED_MODULE_11__["setToolOptions"], + setToolOptionsForElement: _store_setToolOptions_js__WEBPACK_IMPORTED_MODULE_11__["setToolOptionsForElement"], + isToolActiveForElement: _store_isToolActiveForElement__WEBPACK_IMPORTED_MODULE_13__["default"], + setToolActive: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolActive"], + setToolActiveForElement: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolActiveForElement"], + setToolEnabled: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolEnabled"], + setToolEnabledForElement: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolEnabledForElement"], + setToolDisabled: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolDisabled"], + setToolDisabledForElement: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolDisabledForElement"], + setToolPassive: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolPassive"], + setToolPassiveForElement: _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_12__["setToolPassiveForElement"], + addToolState: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["addToolState"], + getToolState: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["getToolState"], + removeToolState: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["removeToolState"], + clearToolState: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["clearToolState"], + setElementToolStateManager: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["setElementToolStateManager"], + getElementToolStateManager: _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_14__["getElementToolStateManager"], + textStyle: _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_15__["default"], + toolStyle: _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_16__["default"], + toolColors: _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_17__["default"], + toolCoordinates: _stateManagement_toolCoordinates_js__WEBPACK_IMPORTED_MODULE_18__["default"], + stackSpecificStateManager: _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["stackSpecificStateManager"], + newStackSpecificToolStateManager: _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["newStackSpecificToolStateManager"], + addStackStateManager: _stateManagement_stackSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_19__["addStackStateManager"], + loadHandlerManager: _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_20__["default"], + newImageIdSpecificToolStateManager: _stateManagement_imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_21__["newImageIdSpecificToolStateManager"], + globalImageIdSpecificToolStateManager: _stateManagement_imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_21__["globalImageIdSpecificToolStateManager"], + newFrameOfReferenceSpecificToolStateManager: _stateManagement_frameOfReferenceStateManager_js__WEBPACK_IMPORTED_MODULE_22__["newFrameOfReferenceSpecificToolStateManager"], + globalFrameOfReferenceSpecificToolStateManager: _stateManagement_frameOfReferenceStateManager_js__WEBPACK_IMPORTED_MODULE_22__["globalFrameOfReferenceSpecificToolStateManager"], + forceEnabledElementResize: _eventListeners_windowResizeHandler_js__WEBPACK_IMPORTED_MODULE_23__["forceEnabledElementResize"], + orientation: _orientation_index_js__WEBPACK_IMPORTED_MODULE_24__["default"], + SaveAs: _util_SaveAs_js__WEBPACK_IMPORTED_MODULE_25__["default"], + enableLogger: _util_logger_js__WEBPACK_IMPORTED_MODULE_26__["enable"], + disableLogger: _util_logger_js__WEBPACK_IMPORTED_MODULE_26__["disable"], + importInternal: _importInternal_js__WEBPACK_IMPORTED_MODULE_40__["default"], + import: _importInternal_js__WEBPACK_IMPORTED_MODULE_40__["default"], + register: _thirdParty_register_js__WEBPACK_IMPORTED_MODULE_27__["default"], + registerSome: _thirdParty_registerSome_js__WEBPACK_IMPORTED_MODULE_28__["default"], + wwwcSynchronizer: _synchronization_wwwcSynchronizer_js__WEBPACK_IMPORTED_MODULE_29__["default"], + updateImageSynchronizer: _synchronization_updateImageSynchronizer_js__WEBPACK_IMPORTED_MODULE_30__["default"], + Synchronizer: _synchronization_Synchronizer_js__WEBPACK_IMPORTED_MODULE_31__["default"], + stackScrollSynchronizer: _synchronization_stackScrollSynchronizer_js__WEBPACK_IMPORTED_MODULE_32__["default"], + stackImagePositionSynchronizer: _synchronization_stackImagePositionSynchronizer_js__WEBPACK_IMPORTED_MODULE_33__["default"], + stackImagePositionOffsetSynchronizer: _synchronization_stackImagePositionOffsetSynchronizer_js__WEBPACK_IMPORTED_MODULE_34__["default"], + stackImageIndexSynchronizer: _synchronization_stackImageIndexSynchronizer_js__WEBPACK_IMPORTED_MODULE_35__["default"], + panZoomSynchronizer: _synchronization_panZoomSynchronizer_js__WEBPACK_IMPORTED_MODULE_36__["default"], + external: _externalModules_js__WEBPACK_IMPORTED_MODULE_37__["default"], + EVENTS: _events_js__WEBPACK_IMPORTED_MODULE_38__["default"], + version: _version_js__WEBPACK_IMPORTED_MODULE_39__["default"] +}; // Named Exports + + + +/* harmony default export */ __webpack_exports__["default"] = (cornerstoneTools); + +/***/ }), + +/***/ "./init.js": +/*!*****************!*\ + !*** ./init.js ***! + \*****************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store/index.js */ "./store/index.js"); +/* harmony import */ var _store_internals_addEnabledElement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store/internals/addEnabledElement.js */ "./store/internals/addEnabledElement.js"); +/* harmony import */ var _store_internals_removeEnabledElement_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store/internals/removeEnabledElement.js */ "./store/internals/removeEnabledElement.js"); +/* harmony import */ var _eventListeners_windowResizeHandler_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./eventListeners/windowResizeHandler.js */ "./eventListeners/windowResizeHandler.js"); + + + + + +/** + * Merges the provided configuration with default values and returns a + * configured CornerstoneTools instance. + * @export + * @public + * @method + * @name init + * + * @param {Object|Object[]} [defaultConfiguration = {}] The configuration to apply. Assumed globalConfiguration + * only one value, otherwise moduleName, configuration entires in an array. + * @returns {Object} A configured CornerstoneTools instance with top level API members. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function () { + var defaultConfiguration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _addCornerstoneEventListeners(); + + _initModules(); + + var globalConfigurationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_1__["getModule"])('globalConfiguration'); + + if (Array.isArray(defaultConfiguration)) { + defaultConfiguration.forEach(function (configurationEntry) { + var moduleName = configurationEntry.moduleName, + configuration = configurationEntry.configuration; + var module = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_1__["getModule"])(moduleName); + + if (module) { + module.configuration = Object.assign({}, module.configuration, configuration); + } + }); + } else { + // DefaultConfiguration is an object, default to assigning it to globalConfiguration. + globalConfigurationModule.configuration = Object.assign({}, globalConfigurationModule.configuration, defaultConfiguration); + } + + if (globalConfigurationModule.configuration.autoResizeViewports) { + _eventListeners_windowResizeHandler_js__WEBPACK_IMPORTED_MODULE_4__["default"].enable(); + } +}); +/** + * Wires up event listeners for the Cornerstone#ElementDisabled and + * Cornerstone#ElementEnabled events. + * @private + * @method + * @returns {void} + */ + +function _addCornerstoneEventListeners() { + // Clear any listeners that may already be set + _removeCornerstoneEventListeners(); + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var elementEnabledEvent = cornerstone.EVENTS.ELEMENT_ENABLED; + var elementDisabledEvent = cornerstone.EVENTS.ELEMENT_DISABLED; + cornerstone.events.addEventListener(elementEnabledEvent, _store_internals_addEnabledElement_js__WEBPACK_IMPORTED_MODULE_2__["default"]); + cornerstone.events.addEventListener(elementDisabledEvent, _store_internals_removeEnabledElement_js__WEBPACK_IMPORTED_MODULE_3__["default"]); +} +/** + * Removes event listeners for the Cornerstone#ElementDisabled and + * Cornerstone#ElementEnabled events. + * @private + * @method + * @returns {void} + */ + + +function _removeCornerstoneEventListeners() { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var elementEnabledEvent = cornerstone.EVENTS.ELEMENT_ENABLED; + var elementDisabledEvent = cornerstone.EVENTS.ELEMENT_DISABLED; + cornerstone.events.removeEventListener(elementEnabledEvent, _store_internals_addEnabledElement_js__WEBPACK_IMPORTED_MODULE_2__["default"]); + cornerstone.events.removeEventListener(elementDisabledEvent, _store_internals_removeEnabledElement_js__WEBPACK_IMPORTED_MODULE_3__["default"]); +} +/* + * TODO: This could cause issues if the module was already initialized for + * the store. As there's nothing stopping implementers from calling `init` + * multiple times. Modules should self-check if they have already been + * registered to prevent issues. + */ + +/** + * Iterate over our store's modules. If the module has an `onRegisterCallback` + * call it. This hook can be used to setup any global store requirements per + * module. + * @private + * @method + * @returns {void} + */ + + +function _initModules() { + var modules = _store_index_js__WEBPACK_IMPORTED_MODULE_1__["default"].modules; + Object.keys(modules).forEach(function (key) { + if (typeof modules[key].onRegisterCallback === 'function') { + modules[key].onRegisterCallback(); + } + }); +} + +/***/ }), + +/***/ "./lib.js": +/*!****************!*\ + !*** ./lib.js ***! + \****************/ +/*! exports provided: lib */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lib", function() { return lib; }); +/* harmony import */ var _tools_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools/base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./tools/base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _tools_base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tools/base/BaseBrushTool.js */ "./tools/base/BaseBrushTool.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./util/findAndMoveHelpers.js */ "./util/findAndMoveHelpers.js"); +/* harmony import */ var _mixins_index_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./mixins/index.js */ "./mixins/index.js"); +/* harmony import */ var _tools_cursors_index_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./tools/cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./util/clip.js */ "./util/clip.js"); +/* harmony import */ var _util_debounce__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./util/debounce */ "./util/debounce.js"); +/* harmony import */ var _util_deepmerge__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./util/deepmerge */ "./util/deepmerge.js"); +/* harmony import */ var _util_getDefault__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./util/getDefault */ "./util/getDefault.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _util_isEmptyObject__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./util/isEmptyObject */ "./util/isEmptyObject.js"); +/* harmony import */ var _util_isObject__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./util/isObject */ "./util/isObject.js"); +/* harmony import */ var _util_isPointInImage__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./util/isPointInImage */ "./util/isPointInImage.js"); +/* harmony import */ var _util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./util/isPointInPolygon */ "./util/isPointInPolygon.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./util/throttle */ "./util/throttle.js"); +/* harmony import */ var _util_wait__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./util/wait */ "./util/wait.js"); +/* harmony import */ var _util_getKeyPressData__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./util/getKeyPressData */ "./util/getKeyPressData.js"); +/* harmony import */ var _util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./util/getProximityThreshold.js */ "./util/getProximityThreshold.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _drawing_drawArrow_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./drawing/drawArrow.js */ "./drawing/drawArrow.js"); +/* harmony import */ var _drawing_drawLink_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./drawing/drawLink.js */ "./drawing/drawLink.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _util_getLuminance_js__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ./util/getLuminance.js */ "./util/getLuminance.js"); +/* harmony import */ var _util_getROITextBoxCoords__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./util/getROITextBoxCoords */ "./util/getROITextBoxCoords.js"); +/* harmony import */ var _util_copyPoints_js__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ./util/copyPoints.js */ "./util/copyPoints.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _util_setContextToDisplayFontSize_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ./util/setContextToDisplayFontSize.js */ "./util/setContextToDisplayFontSize.js"); +/* harmony import */ var _util_scrollToIndex_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ./util/scrollToIndex.js */ "./util/scrollToIndex.js"); +/* harmony import */ var _util_scroll_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./util/scroll.js */ "./util/scroll.js"); +/* harmony import */ var _util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./util/roundToDecimal.js */ "./util/roundToDecimal.js"); +/* harmony import */ var _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ./util/pointProjector.js */ "./util/pointProjector.js"); +/* harmony import */ var _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ./util/lineSegDistance.js */ "./util/lineSegDistance.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_37__ = __webpack_require__(/*! ./util/logger */ "./util/logger.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_38__ = __webpack_require__(/*! ./util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); +/* harmony import */ var _util_makeUnselectable_js__WEBPACK_IMPORTED_MODULE_39__ = __webpack_require__(/*! ./util/makeUnselectable.js */ "./util/makeUnselectable.js"); +/* harmony import */ var _util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_40__ = __webpack_require__(/*! ./util/getRGBPixels.js */ "./util/getRGBPixels.js"); +/* harmony import */ var _util_getMaxSimultaneousRequests_js__WEBPACK_IMPORTED_MODULE_41__ = __webpack_require__(/*! ./util/getMaxSimultaneousRequests.js */ "./util/getMaxSimultaneousRequests.js"); +/* harmony import */ var _util_angleBetweenPoints_js__WEBPACK_IMPORTED_MODULE_42__ = __webpack_require__(/*! ./util/angleBetweenPoints.js */ "./util/angleBetweenPoints.js"); +/* harmony import */ var _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_43__ = __webpack_require__(/*! ./util/numbersWithCommas.js */ "./util/numbersWithCommas.js"); +/* harmony import */ var _tools_cursors_MouseCursor_js__WEBPACK_IMPORTED_MODULE_44__ = __webpack_require__(/*! ./tools/cursors/MouseCursor.js */ "./tools/cursors/MouseCursor.js"); +/* harmony import */ var _util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_45__ = __webpack_require__(/*! ./util/ellipse/index.js */ "./util/ellipse/index.js"); +/* harmony import */ var _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_46__ = __webpack_require__(/*! ./util/freehand/index.js */ "./util/freehand/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_47__ = __webpack_require__(/*! ./util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_48__ = __webpack_require__(/*! ./util/zoom/index.js */ "./util/zoom/index.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_49__ = __webpack_require__(/*! ./util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_50__ = __webpack_require__(/*! ./util/convertToVector3.js */ "./util/convertToVector3.js"); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +var lib = { + 'base/BaseTool': _tools_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_0__["default"], + 'base/BaseAnnotationTool': _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_1__["default"], + 'base/BaseBrushTool': _tools_base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_2__["default"], + 'tools/cursors/MouseCursor': _tools_cursors_MouseCursor_js__WEBPACK_IMPORTED_MODULE_44__["default"], + 'tools/cursors': _tools_cursors_index_js__WEBPACK_IMPORTED_MODULE_6__, + 'manipulators/anyHandlesOutsideImage': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["anyHandlesOutsideImage"], + 'manipulators/getHandleNearImagePoint': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["getHandleNearImagePoint"], + 'manipulators/getHandlePixelPosition': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["getHandlePixelPosition"], + 'manipulators/handleActivator': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["handleActivator"], + 'manipulators/moveAllHandles': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveAllHandles"], + 'manipulators/moveHandle': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveHandle"], + 'manipulators/moveNewHandle': _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveNewHandle"], + 'manipulators/moveHandleNearImagePoint': _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_4__["moveHandleNearImagePoint"], + 'manipulators/findHandleDataNearImagePoint': _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_4__["findHandleDataNearImagePoint"], + 'manipulators/moveAnnotation': _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_4__["moveAnnotation"], + 'mixins/activeOrDisabledBinaryTool': _mixins_index_js__WEBPACK_IMPORTED_MODULE_5__["default"].activeOrDisabledBinaryTool, + 'mixins/enabledOrDisabledBinaryTool': _mixins_index_js__WEBPACK_IMPORTED_MODULE_5__["default"].enabledOrDisabledBinaryTool, + 'drawing/getNewContext': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["getNewContext"], + 'drawing/draw': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["draw"], + 'drawing/path': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["path"], + 'drawing/setShadow': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["setShadow"], + 'drawing/drawLine': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"], + 'drawing/drawLines': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLines"], + 'drawing/drawJoinedLines': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawJoinedLines"], + 'drawing/drawCircle': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawCircle"], + 'drawing/drawEllipse': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawEllipse"], + 'drawing/drawRect': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawRect"], + 'drawing/fillOutsideRect': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["fillOutsideRect"], + 'drawing/drawTextBox': _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_21__["default"], + 'drawing/drawArrow': _drawing_drawArrow_js__WEBPACK_IMPORTED_MODULE_22__["default"], + 'drawing/fillBox': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["fillBox"], + 'drawing/fillTextLines': _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["fillTextLines"], + 'drawing/drawLink': _drawing_drawLink_js__WEBPACK_IMPORTED_MODULE_23__["default"], + 'drawing/drawLinkedTextBox': _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_24__["default"], + 'drawing/drawHandles': _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_25__["default"], + 'drawing/textBoxWidth': _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_21__["textBoxWidth"], + 'util/getActiveTool': _util_getActiveTool__WEBPACK_IMPORTED_MODULE_26__["default"], + 'util/getLuminance': _util_getLuminance_js__WEBPACK_IMPORTED_MODULE_27__["default"], + 'util/getROITextBoxCoords': _util_getROITextBoxCoords__WEBPACK_IMPORTED_MODULE_28__["default"], + 'util/copyPoints': _util_copyPoints_js__WEBPACK_IMPORTED_MODULE_29__["default"], + 'util/calculateSUV': _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_30__["default"], + 'util/setContextToDisplayFontSize': _util_setContextToDisplayFontSize_js__WEBPACK_IMPORTED_MODULE_31__["default"], + 'util/scrollToIndex': _util_scrollToIndex_js__WEBPACK_IMPORTED_MODULE_32__["default"], + 'util/scroll': _util_scroll_js__WEBPACK_IMPORTED_MODULE_33__["default"], + 'util/roundToDecimal': _util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_34__["default"], + 'util/projectPatientPointToImagePlane': _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_35__["projectPatientPointToImagePlane"], + 'util/imagePointToPatientPoint': _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_35__["imagePointToPatientPoint"], + 'util/planePlaneIntersection': _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_35__["planePlaneIntersection"], + 'util/pointInsideBoundingBox': _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_38__["default"], + 'util/makeUnselectable': _util_makeUnselectable_js__WEBPACK_IMPORTED_MODULE_39__["default"], + 'util/getRGBPixels': _util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_40__["default"], + 'util/getBrowserInfo': _util_getMaxSimultaneousRequests_js__WEBPACK_IMPORTED_MODULE_41__["getBrowserInfo"], + 'util/isMobileDevice': _util_getMaxSimultaneousRequests_js__WEBPACK_IMPORTED_MODULE_41__["isMobileDevice"], + 'util/angleBetweenPoints': _util_angleBetweenPoints_js__WEBPACK_IMPORTED_MODULE_42__["default"], + 'util/numbersWithCommas': _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_43__["default"], + 'util/lineSegDistance': _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_36__["default"], + 'util/triggerEvent': _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_49__["default"], + 'util/convertToVector3': _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_50__["default"], + 'util/clip': _util_clip_js__WEBPACK_IMPORTED_MODULE_8__["clip"], + 'util/clipToBox': _util_clip_js__WEBPACK_IMPORTED_MODULE_8__["clipToBox"], + 'util/clipBoxToDisplayedArea': _util_clip_js__WEBPACK_IMPORTED_MODULE_8__["clipBoxToDisplayedArea"], + 'util/debounce': _util_debounce__WEBPACK_IMPORTED_MODULE_9__["default"], + 'util/deepmerge': _util_deepmerge__WEBPACK_IMPORTED_MODULE_10__["default"], + 'util/getDefault': _util_getDefault__WEBPACK_IMPORTED_MODULE_11__["default"], + 'util/getProximityThreshold': _util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_20__["default"], + 'util/getPixelSpacing': _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_12__["default"], + 'util/isEmptyObject': _util_isEmptyObject__WEBPACK_IMPORTED_MODULE_13__["default"], + 'util/isObject': _util_isObject__WEBPACK_IMPORTED_MODULE_14__["default"], + 'util/isPointInImage': _util_isPointInImage__WEBPACK_IMPORTED_MODULE_15__["default"], + 'util/isPointInPolygon': _util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_16__["default"], + 'util/getLogger': _util_logger__WEBPACK_IMPORTED_MODULE_37__["getLogger"], + 'util/throttle': _util_throttle__WEBPACK_IMPORTED_MODULE_17__["default"], + 'util/wait': _util_wait__WEBPACK_IMPORTED_MODULE_18__["wait"], + 'util/waitForEnabledElementImageToLoad': _util_wait__WEBPACK_IMPORTED_MODULE_18__["waitForEnabledElementImageToLoad"], + 'util/getKeyPressData': _util_getKeyPressData__WEBPACK_IMPORTED_MODULE_19__["default"], + // Whole tool specific util packages + 'util/ellipseUtils': _util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_45__["default"], + 'util/freehandUtils': _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_46__["default"], + 'util/segmentationUtils': _util_segmentation__WEBPACK_IMPORTED_MODULE_47__, + 'util/zoomUtils': _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_48__["default"] +}; + +/***/ }), + +/***/ "./manipulators/anyHandlesOutsideImage.js": +/*!************************************************!*\ + !*** ./manipulators/anyHandlesOutsideImage.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Determine if a handle is outside the bounds of the rendered image. + * @public + * @function anyHandlesOutsideImage + * @memberof Manipulators + * + * @param {*} renderData - Cornerstone Tool's event detail + * @param {Object} handles - An object containing named handles + * @returns {Boolean} - True if the handle was placed outside the image + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (renderData, handles) { + var image = renderData.image; + var imageRect = { + left: 0, + top: 0, + width: image.width, + height: image.height + }; + var handleOutsideImage = false; + Object.keys(handles).forEach(function (name) { + var handle = handles[name]; + + if (handle.allowedOutsideImage === true) { + return; + } + + if (_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.insideRect(handle, imageRect) === false) { + handleOutsideImage = true; + } + }); + return handleOutsideImage; +}); + +/***/ }), + +/***/ "./manipulators/getHandleNearImagePoint.js": +/*!*************************************************!*\ + !*** ./manipulators/getHandleNearImagePoint.js ***! + \*************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); + + + +/** + * Returns the first handle found to be near the provided point. Handles to search can be an array of handles, an + * object of named handles, or an object of named handles AND named arrays of handles. + * + * @public + * @function getHandleNearImagePoint + * @memberof Manipulators + * + * @param {*} element - Target enabledElement + * @param {(Array|Object)} handles - An arry of handles, object with named handles, or object with named handles AND named arrays of handles + * @param {Object} coords - The coordinates to measure from when determining distance from handles + * @param {number} distanceThreshold - minimum distance handle needs to be from provided coords + * @returns {Object} Handle + */ + +var getHandleNearImagePoint = function getHandleNearImagePoint(element, handles, coords, distanceThreshold) { + var nearbyHandle; + + if (!handles) { + return; + } + + if (Array.isArray(handles)) { + var handleKeys = Object.keys(handles); + + for (var i = 0; i < handleKeys.length; i++) { + var key = handleKeys[i]; + var handle = handles[key]; + + if ( // Not a true handle + !handle.hasOwnProperty('x') || !handle.hasOwnProperty('y')) { + continue; + } + + if (_isHandleNearImagePoint(handle, element, coords, distanceThreshold)) { + nearbyHandle = handle; + break; + } + } + } else if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(handles) === 'object') { + var _handleKeys = Object.keys(handles); + + for (var _i = 0; _i < _handleKeys.length; _i++) { + var handleName = _handleKeys[_i]; + + if (Array.isArray(handles[handleName])) { + nearbyHandle = getHandleNearImagePoint(element, handles[handleName], coords, distanceThreshold); + + if (nearbyHandle) { + break; + } + } else { + var _handle = handles[handleName]; + + if (_isHandleNearImagePoint(_handle, element, coords, distanceThreshold)) { + nearbyHandle = _handle; + break; + } + } + } + } + + return nearbyHandle; +}; +/** + * Determines if the handle is less than the provided distance from the provided coordinates + * @private + * @function _isHandleNearImagePoint + * + * @param {*} handle + * @param {*} element + * @param {*} coords + * @param {*} distanceThreshold + * @returns {boolean} true if handles is near image point + */ + + +var _isHandleNearImagePoint = function _isHandleNearImagePoint(handle, element, coords, distanceThreshold) { + if (handle.hasOwnProperty('pointNearHandle')) { + if (handle.pointNearHandle(element, handle, coords)) { + return true; + } + } else if (handle.hasBoundingBox === true) { + if (Object(_util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_2__["default"])(handle, coords)) { + return true; + } + } else { + var handleCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, handle); + var distance = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.distance(handleCanvas, coords); + + if (distance <= distanceThreshold) { + return true; + } + } + + return false; +}; + +/* harmony default export */ __webpack_exports__["default"] = (getHandleNearImagePoint); + +/***/ }), + +/***/ "./manipulators/getHandlePixelPosition.js": +/*!************************************************!*\ + !*** ./manipulators/getHandlePixelPosition.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); + + +/** + * Return the handle position considering offset for touch interaction. + * @public + * @function getHandlePixelPosition + * @memberof Manipulators + * + * @param {Object} eventData - Data object associated with the event + * @param {string} interactionType - Type of user's input + * @returns {Object} - The translated point object + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (eventData, interactionType) { + var currentPoints = eventData.currentPoints, + element = eventData.element; + var page = currentPoints.page; + var handleTouchOffset = _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].handleTouchOffset; + var offsetX = 0; + var offsetY = 0; + + if (interactionType === 'touch') { + offsetX = handleTouchOffset.x; + offsetY = handleTouchOffset.y; + } + + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.pageToPixel(element, page.x + offsetX, page.y + offsetY); +}); + +/***/ }), + +/***/ "./manipulators/handleActivator.js": +/*!*****************************************!*\ + !*** ./manipulators/handleActivator.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); + +/** + * Update the active handle + * @public + * @function handleActivator + * @memberof Manipulators + * + * @param {*} element + * @param {*} handles + * @param {*} canvasPoint + * @param {*} distanceThreshold + * @returns {Boolean} - True if a handle was activated + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, handles, canvasPoint, distanceThreshold) { + if (!distanceThreshold) { + distanceThreshold = 6; + } + + var activeHandle = _getActiveHandle(handles); + + var nearbyHandle = Object(_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_0__["default"])(element, handles, canvasPoint, distanceThreshold); + + if (activeHandle !== nearbyHandle) { + if (nearbyHandle !== undefined) { + nearbyHandle.active = true; + } + + if (activeHandle !== undefined) { + activeHandle.active = false; + } + + return true; + } + + return false; +}); +/** + * + * @private + * + * @param {*} handles + * @returns {Object} - Activated Handle + */ + +function _getActiveHandle(handles) { + var activeHandle; + Object.keys(handles).forEach(function (name) { + var handle = handles[name]; + + if (handle.active === true) { + activeHandle = handle; + return; + } + }); + return activeHandle; +} + +/***/ }), + +/***/ "./manipulators/index.js": +/*!*******************************!*\ + !*** ./manipulators/index.js ***! + \*******************************/ +/*! exports provided: anyHandlesOutsideImage, getHandleNearImagePoint, getHandlePixelPosition, handleActivator, moveAllHandles, moveHandle, moveNewHandle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "anyHandlesOutsideImage", function() { return _anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getHandleNearImagePoint", function() { return _getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getHandlePixelPosition.js */ "./manipulators/getHandlePixelPosition.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getHandlePixelPosition", function() { return _getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _handleActivator_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./handleActivator.js */ "./manipulators/handleActivator.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "handleActivator", function() { return _handleActivator_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _moveAllHandles_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./moveAllHandles.js */ "./manipulators/moveAllHandles.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "moveAllHandles", function() { return _moveAllHandles_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony import */ var _moveHandle_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./moveHandle.js */ "./manipulators/moveHandle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "moveHandle", function() { return _moveHandle_js__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + +/* harmony import */ var _moveNewHandle_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./moveNewHandle.js */ "./manipulators/moveNewHandle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "moveNewHandle", function() { return _moveNewHandle_js__WEBPACK_IMPORTED_MODULE_6__["default"]; }); + + + + + + + + + + +/***/ }), + +/***/ "./manipulators/moveAllHandles.js": +/*!****************************************!*\ + !*** ./manipulators/moveAllHandles.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../tools/base/BaseAnnotationTool */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_9__["getLogger"])('manipulators:moveAllHandles'); +var manipulatorStateModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_6__["getModule"])('manipulatorState'); +var _dragEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG] +}; +var _upOrEndEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG_END, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PRESS, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP] +}; +/** + * Manipulator to move all provided handles at the same time + * @public + * @function moveAllHandles + * @memberof Manipulators + * + * @param {*} evtDetail + * @param {*} evtDetail.element + * @param {String} toolName + * @param {*} annotation + * @param {*} [handle=null] - not needed by moveAllHandles, but keeps call signature the same as `moveHandle` + * @param {Object} [options={}] + * @param {Boolean} [options.deleteIfHandleOutsideImage] + * @param {Boolean} [options.preventHandleOutsideImage] + * @param {string} [interactionType=mouse] + * @param {function} [doneMovingCallback] + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (_ref, toolName, annotation, handle) { + var element = _ref.element; + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var interactionType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'mouse'; + var doneMovingCallback = arguments.length > 6 ? arguments[6] : undefined; + // Use global defaults, unless overidden by provided options + options = Object.assign({ + deleteIfHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_6__["state"].deleteIfHandleOutsideImage, + preventHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_6__["state"].preventHandleOutsideImage + }, options); + + var dragHandler = _dragHandler.bind(this, toolName, annotation, options, interactionType); // So we don't need to inline the entire `upOrEndHandler` function + + + var upOrEndHandler = function upOrEndHandler(evt) { + _upOrEndHandler(toolName, annotation, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, evt, doneMovingCallback); + }; + + manipulatorStateModule.setters.addActiveManipulatorForElement(element, _cancelEventHandler.bind(null, annotation, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, element, doneMovingCallback)); + annotation.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_6__["state"].isToolLocked = true; // Add Event Listeners + + _dragEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, dragHandler); + }); + + _upOrEndEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, upOrEndHandler); + }); +}); + +function _dragHandler(toolName, annotation) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var interactionType = arguments.length > 3 ? arguments[3] : undefined; + var evt = arguments.length > 4 ? arguments[4] : undefined; + var _evt$detail = evt.detail, + element = _evt$detail.element, + image = _evt$detail.image, + buttons = _evt$detail.buttons; + var _evt$detail$deltaPoin = evt.detail.deltaPoints.image, + x = _evt$detail$deltaPoin.x, + y = _evt$detail$deltaPoin.y; + annotation.active = true; + annotation.invalidated = true; + var handleKeys = Object.keys(annotation.handles); + + for (var i = 0; i < handleKeys.length; i++) { + var key = handleKeys[i]; + var handle = annotation.handles[key]; + + if ( // Don't move this part of the annotation + handle.movesIndependently === true || // Not a true handle + !handle.hasOwnProperty('x') || !handle.hasOwnProperty('y')) { + continue; + } + + handle.x += x; + handle.y += y; + + if (options.preventHandleOutsideImage) { + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_5__["clipToBox"])(handle, image); + } + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_7__["default"])(element, buttons, interactionType); + + if (activeTool instanceof _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_8__["default"]) { + activeTool.updateCachedStats(image, element, annotation); + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_MODIFIED; + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: annotation + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, eventType, modifiedEventData); + evt.preventDefault(); + evt.stopPropagation(); +} + +function _cancelEventHandler(annotation) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var interactionType = arguments.length > 2 ? arguments[2] : undefined; + + var _ref2 = arguments.length > 3 ? arguments[3] : undefined, + dragHandler = _ref2.dragHandler, + upOrEndHandler = _ref2.upOrEndHandler; + + var element = arguments.length > 4 ? arguments[4] : undefined; + var doneMovingCallback = arguments.length > 5 ? arguments[5] : undefined; + + _endHandler(annotation, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, element, doneMovingCallback, false); +} + +function _upOrEndHandler(toolName, annotation) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var interactionType = arguments.length > 3 ? arguments[3] : undefined; + + var _ref3 = arguments.length > 4 ? arguments[4] : undefined, + dragHandler = _ref3.dragHandler, + upOrEndHandler = _ref3.upOrEndHandler; + + var evt = arguments.length > 5 ? arguments[5] : undefined; + var doneMovingCallback = arguments.length > 6 ? arguments[6] : undefined; + var eventData = evt.detail; + var element = eventData.element; + manipulatorStateModule.setters.removeActiveManipulatorForElement(element); // If any handle is outside the image, delete the tool data + + if (options.deleteIfHandleOutsideImage && Object(_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__["default"])(eventData, annotation.handles)) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["removeToolState"])(element, toolName, annotation); + } + + _endHandler(annotation, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, element, doneMovingCallback, true); +} + +function _endHandler(annotation) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var interactionType = arguments.length > 2 ? arguments[2] : undefined; + + var _ref4 = arguments.length > 3 ? arguments[3] : undefined, + dragHandler = _ref4.dragHandler, + upOrEndHandler = _ref4.upOrEndHandler; + + var element = arguments.length > 4 ? arguments[4] : undefined; + var doneMovingCallback = arguments.length > 5 ? arguments[5] : undefined; + var success = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true; + annotation.active = false; + annotation.invalidated = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_6__["state"].isToolLocked = false; // Remove Event Listeners + + _dragEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, dragHandler); + }); + + _upOrEndEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, upOrEndHandler); + }); + + if (typeof options.doneMovingCallback === 'function') { + logger.warn('`options.doneMovingCallback` has been depricated. See https://github.com/cornerstonejs/cornerstoneTools/pull/915 for details.'); + options.doneMovingCallback(success); + } + + if (typeof doneMovingCallback === 'function') { + doneMovingCallback(success); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} + +/***/ }), + +/***/ "./manipulators/moveHandle.js": +/*!************************************!*\ + !*** ./manipulators/moveHandle.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./getHandlePixelPosition.js */ "./manipulators/getHandlePixelPosition.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../tools/base/BaseAnnotationTool */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_10__["getLogger"])('manipulators:moveHandle'); +var manipulatorStateModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_7__["getModule"])('manipulatorState'); +var runAnimation = { + value: false +}; +var _dragEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG] +}; +var _upOrEndEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG_END, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PRESS, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP] +}; +/** + * Move the provided handle + * + * @public + * @method moveHandle + * @memberof Manipulators + * + * @param {*} evtDetail + * @param {*} toolName + * @param {*} annotation + * @param {*} handle + * @param {*} [options={}] + * @param {Boolean} [options.deleteIfHandleOutsideImage] + * @param {Boolean} [options.preventHandleOutsideImage] + * @param {*} [interactionType=mouse] + * @param {function} doneMovingCallback + * @returns {undefined} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (evtDetail, toolName, annotation, handle) { + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var interactionType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'mouse'; + var doneMovingCallback = arguments.length > 6 ? arguments[6] : undefined; + // Use global defaults, unless overidden by provided options + options = Object.assign({ + deleteIfHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].deleteIfHandleOutsideImage, + preventHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].preventHandleOutsideImage + }, options); + var element = evtDetail.element; + + var dragHandler = _dragHandler.bind(this, toolName, annotation, handle, options, interactionType); // So we don't need to inline the entire `upOrEndHandler` function + + + var upOrEndHandler = function upOrEndHandler() { + _upOrEndHandler(toolName, evtDetail, annotation, handle, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, doneMovingCallback); + }; + + manipulatorStateModule.setters.addActiveManipulatorForElement(element, _cancelEventHandler.bind(null, toolName, evtDetail, annotation, handle, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, doneMovingCallback)); + handle.active = true; + handle.moving = true; + annotation.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].isToolLocked = true; // Add Event Listeners + + _dragEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, dragHandler); + }); + + _upOrEndEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, upOrEndHandler); + }); // ========================== + // ======== TOUCH ========== + // ========================== + + + if (interactionType === 'touch') { + runAnimation.value = true; + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + var targetLocation = Object(_getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(evtDetail, interactionType); + + _animate(handle, runAnimation, enabledElement, targetLocation); + } +}); + +function _dragHandler(toolName, annotation, handle, options, interactionType, evt) { + var _evt$detail = evt.detail, + image = _evt$detail.image, + element = _evt$detail.element, + buttons = _evt$detail.buttons; + var targetLocation = Object(_getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(evt.detail, interactionType); + runAnimation.value = false; + handle.active = true; + handle.hasMoved = true; + handle.x = targetLocation.x; + handle.y = targetLocation.y; // TODO: A way to not flip this for textboxes on annotations + + annotation.invalidated = true; + + if (options.preventHandleOutsideImage) { + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_6__["clipToBox"])(handle, image); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_8__["default"])(element, buttons, interactionType); + + if (activeTool instanceof _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_9__["default"]) { + activeTool.updateCachedStats(image, element, annotation); + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_MODIFIED; + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: annotation + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, eventType, modifiedEventData); +} + +function _cancelEventHandler(toolName, evtDetail, annotation, handle) { + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var interactionType = arguments.length > 5 ? arguments[5] : undefined; + + var _ref = arguments.length > 6 ? arguments[6] : undefined, + dragHandler = _ref.dragHandler, + upOrEndHandler = _ref.upOrEndHandler; + + var doneMovingCallback = arguments.length > 7 ? arguments[7] : undefined; + + _endHandler(toolName, evtDetail, annotation, handle, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, doneMovingCallback, false); +} + +function _upOrEndHandler(toolName, evtDetail, annotation, handle) { + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var interactionType = arguments.length > 5 ? arguments[5] : undefined; + + var _ref2 = arguments.length > 6 ? arguments[6] : undefined, + dragHandler = _ref2.dragHandler, + upOrEndHandler = _ref2.upOrEndHandler; + + var doneMovingCallback = arguments.length > 7 ? arguments[7] : undefined; + var element = evtDetail.element; + manipulatorStateModule.setters.removeActiveManipulatorForElement(element); + + _endHandler(toolName, evtDetail, annotation, handle, options, interactionType, { + dragHandler: dragHandler, + upOrEndHandler: upOrEndHandler + }, doneMovingCallback, true); +} + +function _endHandler(toolName, evtDetail, annotation, handle) { + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + var interactionType = arguments.length > 5 ? arguments[5] : undefined; + + var _ref3 = arguments.length > 6 ? arguments[6] : undefined, + dragHandler = _ref3.dragHandler, + upOrEndHandler = _ref3.upOrEndHandler; + + var doneMovingCallback = arguments.length > 7 ? arguments[7] : undefined; + var success = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : true; + var element = evtDetail.element; + handle.active = false; + handle.moving = false; + annotation.active = false; + annotation.invalidated = true; + runAnimation.value = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].isToolLocked = false; // Remove Event Listeners + + _dragEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, dragHandler); + }); + + _upOrEndEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, upOrEndHandler); + }); // If any handle is outside the image, delete the tool data + + + if (options.deleteIfHandleOutsideImage && Object(_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__["default"])(evtDetail, annotation.handles)) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["removeToolState"])(element, toolName, annotation); + } // // TODO: What dark magic makes us want to handle TOUCH_PRESS differently? + // if (evt.type === EVENTS.TOUCH_PRESS) { + // evt.detail.handlePressed = annotation; + // handle.x = image.x; // Original Event + // handle.y = image.y; + // } + + + if (typeof options.doneMovingCallback === 'function') { + logger.warn('`options.doneMovingCallback` has been depricated. See https://github.com/cornerstonejs/cornerstoneTools/pull/915 for details.'); + options.doneMovingCallback(success); + } + + if (typeof doneMovingCallback === 'function') { + doneMovingCallback(success); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} +/** + * Animates the provided handle using `requestAnimationFrame` + * @private + * @method _animate + * + * @param {*} handle + * @param {*} runAnimation + * @param {*} enabledElement + * @param {*} targetLocation + * @returns {undefined} + */ + + +function _animate(handle, runAnimation, enabledElement, targetLocation) { + if (!runAnimation.value) { + return; + } // Pixels / second + + + var distanceRemaining = Math.abs(handle.y - targetLocation.y); + var linearDistEachFrame = distanceRemaining / 10; + + if (distanceRemaining < 1) { + handle.y = targetLocation.y; + runAnimation.value = false; + return; + } + + if (handle.y > targetLocation.y) { + handle.y -= linearDistEachFrame; + } else if (handle.y < targetLocation.y) { + handle.y += linearDistEachFrame; + } // Update the image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(enabledElement.element); // Request a new frame + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.requestAnimationFrame(function () { + _animate(handle, runAnimation, enabledElement, targetLocation); + }); +} + +/***/ }), + +/***/ "./manipulators/moveNewHandle.js": +/*!***************************************!*\ + !*** ./manipulators/moveNewHandle.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./getHandlePixelPosition.js */ "./manipulators/getHandlePixelPosition.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../tools/base/BaseAnnotationTool */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_10__["getLogger"])('manipulators:moveNewHandle'); +var manipulatorStateModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_7__["getModule"])('manipulatorState'); +var _moveEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_MOVE, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_DRAG], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_DRAG] +}; +var _moveEndEvents = { + mouse: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_UP, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MOUSE_CLICK], + touch: [_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_END, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_PINCH, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TAP] +}; +/** + * Move a new handle + * + * @public + * @method moveNewHandle + * @memberof Manipulators + * + * @param {*} eventData + * @param {*} toolName + * @param {*} annotation + * @param {*} handle + * @param {*} [options={}] + * @param {Boolean} [options.deleteIfHandleOutsideImage] + * @param {Boolean} [options.preventHandleOutsideImage] + * @param {string} [interactionType=mouse] + * @param {function} [doneMovingCallback] + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (eventData, toolName, annotation, handle, options) { + var interactionType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'mouse'; + var doneMovingCallback = arguments.length > 6 ? arguments[6] : undefined; + // Use global defaults, unless overidden by provided options + options = Object.assign({ + deleteIfHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].deleteIfHandleOutsideImage, + preventHandleOutsideImage: _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].preventHandleOutsideImage + }, options); + options.hasMoved = false; + var element = eventData.element; + annotation.active = true; + handle.moving = true; + handle.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].isToolLocked = true; + + function moveHandler(evt) { + _moveHandler(toolName, annotation, handle, options, interactionType, evt); + } // So we don't need to inline the entire `moveEndEventHandler` function + + + function moveEndHandler(evt) { + _moveEndHandler(toolName, annotation, handle, options, interactionType, { + moveHandler: moveHandler, + moveEndHandler: moveEndHandler + }, evt, doneMovingCallback); + } // Factory function + // begin, end, cancel + // Or... Handle "CANCEL" + // TODO: SETUP IN all other manipulators + // Add event listeners + + + _moveEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, moveHandler); + }); + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START, _stopImmediatePropagation); + + _moveEndEvents[interactionType].forEach(function (eventType) { + element.addEventListener(eventType, moveEndHandler); + }); // When cancelling... What is our active tool? + // `isToolLocked` ... Track which (annotation) tool is being manipulated + // If not "completed", removeToolState (maybe an `isComplete` flag) + // 5 locations: MEASUREMENT_COMPLETED + // Firing event... Sets `isCompleted` flag for annotation uuid + + + manipulatorStateModule.setters.addActiveManipulatorForElement(element, _cancelEventHandler.bind(null, annotation, handle, options, interactionType, { + moveHandler: moveHandler, + moveEndHandler: moveEndHandler + }, element, doneMovingCallback)); +}); +/** + * Updates annotation as the "pointer" is moved/dragged + * Emits `cornerstonetoolsmeasurementmodified` events + * + * @param {string} toolName + * @param {*} annotation + * @param {*} handle + * @param {*} options + * @param {string} interactionType + * @param {*} evt + * + * @returns {void} + */ + +function _moveHandler(toolName, annotation, handle, options, interactionType, evt) { + var _evt$detail = evt.detail, + image = _evt$detail.image, + element = _evt$detail.element, + buttons = _evt$detail.buttons; + var targetLocation = Object(_getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(evt.detail, interactionType); + options.hasMoved = true; + annotation.invalidated = true; + handle.active = true; + handle.x = targetLocation.x; + handle.y = targetLocation.y; + + if (options && options.preventHandleOutsideImage) { + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_6__["clipToBox"])(handle, image); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_8__["default"])(element, buttons, interactionType); + + if (activeTool instanceof _tools_base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_9__["default"]) { + activeTool.updateCachedStats(image, element, annotation); + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_MODIFIED; + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: annotation + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, eventType, modifiedEventData); +} + +function _endHandler(interactionType, options, element, _ref, doneMovingCallback) { + var moveHandler = _ref.moveHandler, + moveEndHandler = _ref.moveEndHandler; + var success = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true; + + // Remove event listeners + _moveEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, moveHandler); + }); + + _moveEndEvents[interactionType].forEach(function (eventType) { + element.removeEventListener(eventType, moveEndHandler); + }); + + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOUCH_START, _stopImmediatePropagation); + _store_index_js__WEBPACK_IMPORTED_MODULE_7__["state"].isToolLocked = false; + + if (typeof doneMovingCallback === 'function') { + doneMovingCallback(success); + } + + if (typeof options.doneMovingCallback === 'function') { + logger.warn('`options.doneMovingCallback` has been depricated. See https://github.com/cornerstonejs/cornerstoneTools/pull/915 for details.'); + options.doneMovingCallback(success); + } // Update Image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} + +function _moveEndHandler(toolName, annotation, handle, options, interactionType, _ref2, evt, doneMovingCallback) { + var moveHandler = _ref2.moveHandler, + moveEndHandler = _ref2.moveEndHandler; + var eventData = evt.detail; + var element = eventData.element; + var moveNewHandleSuccessful = true; + + if (options.hasMoved === false) { + return; + } + + var targetLocation = Object(_getHandlePixelPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData, interactionType); // "Release" the handle + + annotation.active = false; + annotation.invalidated = true; + handle.active = false; + handle.moving = false; + handle.x = targetLocation.x; + handle.y = targetLocation.y; + manipulatorStateModule.setters.removeActiveManipulatorForElement(element); // TODO: WHY? + // Why would a Touch_Pinch or Touch_Press be associated with a new handle? + // if (evt.type === EVENTS.TOUCH_PINCH || evt.type === EVENTS.TOUCH_PRESS) { + // handle.active = false; + // external.cornerstone.updateImage(element); + // if (typeof options.doneMovingCallback === 'function') { + // logger.warn( + // '`options.doneMovingCallback` has been depricated. See https://github.com/cornerstonejs/cornerstoneTools/pull/915 for details.' + // ); + // options.doneMovingCallback(success); + // } + // if (typeof doneMovingCallback === 'function') { + // doneMovingCallback(success); + // } + // return; + // } + + if (options.preventHandleOutsideImage) { + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_6__["clipToBox"])(handle, evt.detail.image); + } // If any handle is outside the image, delete the tool data + + + if (options.deleteIfHandleOutsideImage && Object(_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_2__["default"])(evt.detail, annotation.handles)) { + annotation.cancelled = true; + moveNewHandleSuccessful = false; + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["removeToolState"])(element, toolName, annotation); + } + + _endHandler(interactionType, options, element, { + moveHandler: moveHandler, + moveEndHandler: moveEndHandler + }, doneMovingCallback, moveNewHandleSuccessful); +} + +function _cancelEventHandler(annotation, handle, options, interactionType, _ref3, element, doneMovingCallback) { + var moveHandler = _ref3.moveHandler, + moveEndHandler = _ref3.moveEndHandler; + // "Release" the handle + annotation.active = false; + annotation.invalidated = true; + handle.active = false; + + _endHandler(interactionType, options, element, { + moveHandler: moveHandler, + moveEndHandler: moveEndHandler + }, doneMovingCallback, false); +} +/** + * Stop the CornerstoneToolsTouchStart event from + * Becoming a CornerstoneToolsTouchStartActive event when + * MoveNewHandle ends + * + * @private + * @function _stopImmediatePropagation + * + * @param {*} evt + * @returns {Boolean} false + */ + + +function _stopImmediatePropagation(evt) { + evt.stopImmediatePropagation(); + return false; +} + +/***/ }), + +/***/ "./mixins/activeOrDisabledBinaryTool.js": +/*!**********************************************!*\ + !*** ./mixins/activeOrDisabledBinaryTool.js ***! + \**********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/setToolMode.js */ "./store/setToolMode.js"); + +/** + * If one attempts to change mode to 'passive', redirect the tool to 'disabled'. + * + * @param {HTMLElement} element The element on which the tool resides. + * @returns {undefined} + */ + +function passiveCallback(element) { + Object(_store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__["setToolDisabledForElement"])(element, this.name); +} +/** + * If one attempts to turn the tool 'enabled', redirect the tool to 'active'. + * + * @param {HTMLElement} element The element on which the tool resides. + * @returns {undefined} + */ + + +function enabledCallback(element) { + Object(_store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__["setToolActiveForElement"])(element, this.name); +} +/** + * @mixin activeOrDisabledBinaryTool - Redirect enabled/passive mode changes to active/disabled. + * @memberof Mixins + */ + + +/* harmony default export */ __webpack_exports__["default"] = ({ + passiveCallback: passiveCallback, + enabledCallback: enabledCallback +}); + +/***/ }), + +/***/ "./mixins/enabledOrDisabledBinaryTool.js": +/*!***********************************************!*\ + !*** ./mixins/enabledOrDisabledBinaryTool.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/setToolMode.js */ "./store/setToolMode.js"); + +/** + * If one attempts to change mode to 'passive', redirect the tool to 'disabled'. + * + * @param {HTMLElement} element The element on which the tool resides. + * @returns {undefined} + */ + +function passiveCallback(element) { + Object(_store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__["setToolDisabledForElement"])(element, this.name); +} +/** + * If one attempts to change mode to 'active', redirect the tool to 'enabled'. + * + * @param {HTMLElement} element The element on which the tool resides. + * @returns {undefined} + */ + + +function activeCallback(element) { + Object(_store_setToolMode_js__WEBPACK_IMPORTED_MODULE_0__["setToolEnabledForElement"])(element, this.name); +} +/** + * + * @mixin enabledOrDisabledBinaryTool - Redirect active/passive mode changes to enabled/disabled. + * @memberof Mixins + */ + + +/* harmony default export */ __webpack_exports__["default"] = ({ + passiveCallback: passiveCallback, + activeCallback: activeCallback +}); + +/***/ }), + +/***/ "./mixins/index.js": +/*!*************************!*\ + !*** ./mixins/index.js ***! + \*************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _activeOrDisabledBinaryTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./activeOrDisabledBinaryTool.js */ "./mixins/activeOrDisabledBinaryTool.js"); +/* harmony import */ var _enabledOrDisabledBinaryTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./enabledOrDisabledBinaryTool.js */ "./mixins/enabledOrDisabledBinaryTool.js"); +/* harmony import */ var _segmentation_circleSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./segmentation/circleSegmentationMixin.js */ "./mixins/segmentation/circleSegmentationMixin.js"); +/* harmony import */ var _segmentation_polylineSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./segmentation/polylineSegmentationMixin.js */ "./mixins/segmentation/polylineSegmentationMixin.js"); +/* harmony import */ var _segmentation_freehandSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./segmentation/freehandSegmentationMixin.js */ "./mixins/segmentation/freehandSegmentationMixin.js"); +/* harmony import */ var _segmentation_rectangleSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./segmentation/rectangleSegmentationMixin.js */ "./mixins/segmentation/rectangleSegmentationMixin.js"); +/* harmony import */ var _segmentation_renderBrushMixin_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./segmentation/renderBrushMixin.js */ "./mixins/segmentation/renderBrushMixin.js"); + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = ({ + activeOrDisabledBinaryTool: _activeOrDisabledBinaryTool_js__WEBPACK_IMPORTED_MODULE_0__["default"], + enabledOrDisabledBinaryTool: _enabledOrDisabledBinaryTool_js__WEBPACK_IMPORTED_MODULE_1__["default"], + circleSegmentationMixin: _segmentation_circleSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_2__["default"], + polylineSegmentationMixin: _segmentation_polylineSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_3__["default"], + freehandSegmentationMixin: _segmentation_freehandSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_4__["default"], + rectangleSegmentationMixin: _segmentation_rectangleSegmentationMixin_js__WEBPACK_IMPORTED_MODULE_5__["default"], + renderBrushMixin: _segmentation_renderBrushMixin_js__WEBPACK_IMPORTED_MODULE_6__["default"] +}); + +/***/ }), + +/***/ "./mixins/segmentation/circleSegmentationMixin.js": +/*!********************************************************!*\ + !*** ./mixins/segmentation/circleSegmentationMixin.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _drawing__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../drawing */ "./drawing/index.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); +/* harmony import */ var _util_isEmptyObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../util/isEmptyObject */ "./util/isEmptyObject.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../store */ "./store/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../util/segmentation */ "./util/segmentation/index.js"); + + + + + + +var _getModule = Object(_store__WEBPACK_IMPORTED_MODULE_3__["getModule"])('segmentation'), + getters = _getModule.getters, + setters = _getModule.setters; +/** + * Sets the start and end handle points to empty objects + * + * @private + * @method _resetHandles + * @returns {undefined} + */ + + +function _resetHandles() { + this.handles = { + start: {}, + end: {} + }; +} +/** + * Render hook: draws the Scissors's outline, box, or circle + * + * @param {Object} evt Cornerstone.event#cornerstoneimagerendered > cornerstoneimagerendered event + * @memberof Tools.ScissorsTool + * @returns {void} + */ + + +function renderToolData(evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element; + var color = getters.brushColor(element, true); + var context = Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["getNewContext"])(eventData.canvasContext.canvas); + var distance = _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath.point.distance; + Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["draw"])(context, function (context) { + if (!_this.handles) { + return null; + } + + var startCanvas = _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, _this.handles.start); + var endCanvas = _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.pixelToCanvas(element, _this.handles.end); // Calculating the radius where startCanvas is the center of the circle to be drawn + + var radius = distance(startCanvas, endCanvas); // Draw Circle + + Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["drawCircle"])(context, element, _this.handles.start, radius, { + color: color + }); + }); +} +/** + * Sets the start handle point and claims the eventDispatcher event + * + * @private + * @param {*} evt // mousedown, touchstart, click + * @returns {Boolean} True + */ + + +function _startOutliningRegion(evt) { + var consumeEvent = true; + var element = evt.detail.element; + var image = evt.detail.currentPoints.image; + + if (Object(_util_isEmptyObject__WEBPACK_IMPORTED_MODULE_2__["default"])(this.handles.start)) { + this.handles.start = image; + } else { + this.handles.end = image; + + this._applyStrategy(evt); + } + + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + return consumeEvent; +} +/** + * This function will update the handles and updateImage to force re-draw + * + * @private + * @method _setHandlesAndUpdate + * @param {(CornerstoneTools.event#TOUCH_DRAG|CornerstoneTools.event#MOUSE_DRAG|CornerstoneTools.event#MOUSE_MOVE)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _setHandlesAndUpdate(evt) { + var _evt$detail = evt.detail, + element = _evt$detail.element, + currentPoints = _evt$detail.currentPoints; + var image = currentPoints.image; + this.handles.end = image; + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} +/** + * Event handler for MOUSE_UP/TOUCH_END during handle drag event loop. + * + * @private + * @method _applyStrategy + * @param {(CornerstoneTools.event#MOUSE_UP|CornerstoneTools.event#TOUCH_END)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _applyStrategy(evt) { + evt.detail.handles = this.handles; + var element = evt.detail.element; + + var _getters$labelmap2D = getters.labelmap2D(element), + labelmap2D = _getters$labelmap2D.labelmap2D, + labelmap3D = _getters$labelmap2D.labelmap3D, + currentImageIdIndex = _getters$labelmap2D.currentImageIdIndex; + + var pixelData = labelmap2D.pixelData; + var previousPixeldata = pixelData.slice(); + var points = { + start: { + x: this.handles.start.x, + y: this.handles.start.y + }, + end: { + x: this.handles.end.x, + y: this.handles.end.y + } + }; + var operationData = { + points: points, + pixelData: pixelData, + segmentIndex: labelmap3D.activeSegmentIndex, + segmentationMixinType: "circleSegmentationMixin" + }; + this.applyActiveStrategy(evt, operationData); + var operation = { + imageIdIndex: currentImageIdIndex, + diff: Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_4__["getDiffBetweenPixelData"])(previousPixeldata, pixelData) + }; + setters.pushState(this.element, [operation]); // Invalidate the brush tool data so it is redrawn + + setters.updateSegmentsOnLabelmap2D(labelmap2D); + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + + this._resetHandles(); +} +/** + * @mixin circleSegmentationMixin - Segmentation operations for circles. + * @memberof Mixins + */ + + +/* harmony default export */ __webpack_exports__["default"] = ({ + postTouchStartCallback: _startOutliningRegion, + postMouseDownCallback: _startOutliningRegion, + mouseClickCallback: _startOutliningRegion, + touchDragCallback: _setHandlesAndUpdate, + mouseDragCallback: _setHandlesAndUpdate, + mouseMoveCallback: _setHandlesAndUpdate, + touchEndCallback: _applyStrategy, + mouseUpCallback: _applyStrategy, + initializeMixin: _resetHandles, + renderToolData: renderToolData, + _resetHandles: _resetHandles, + _applyStrategy: _applyStrategy +}); + +/***/ }), + +/***/ "./mixins/segmentation/freehandSegmentationMixin.js": +/*!**********************************************************!*\ + !*** ./mixins/segmentation/freehandSegmentationMixin.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store */ "./store/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _drawing__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../drawing */ "./drawing/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../util/segmentation */ "./util/segmentation/index.js"); + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('tools:ScissorsTool'); + +var _getModule = Object(_store__WEBPACK_IMPORTED_MODULE_2__["getModule"])('segmentation'), + getters = _getModule.getters, + setters = _getModule.setters; +/** + * Render hook: draws the FreehandScissors's outline + * + * @param {Object} evt Cornerstone.event#cornerstoneimagerendered > cornerstoneimagerendered event + * @memberof Tools.ScissorsTool + * @returns {void} + */ + + +function renderToolData(evt) { + var eventData = evt.detail; + var element = eventData.element; + var color = getters.brushColor(element, true); + var context = Object(_drawing__WEBPACK_IMPORTED_MODULE_4__["getNewContext"])(eventData.canvasContext.canvas); + var points = this.handles.points; + + if (points.length < 2) { + return; + } + + Object(_drawing__WEBPACK_IMPORTED_MODULE_4__["draw"])(context, function (context) { + for (var j = 0; j < points.length; j++) { + var lines = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(points[j].lines); + + if (j === points.length - 1) { + // If it's still being actively drawn, keep the last line to + // The mouse location + lines.push(points[0]); + } + + Object(_drawing__WEBPACK_IMPORTED_MODULE_4__["drawJoinedLines"])(context, element, points[j], lines, { + color: color + }); + } + }); +} +/** + * Sets the start handle point and claims the eventDispatcher event + * + * @private + * @param {*} evt // mousedown, touchstart, click + * @returns {void|null} + */ + + +function _startOutliningRegion(evt) { + var element = evt.detail.element; + var image = evt.detail.currentPoints.image; + var points = this.handles.points; + + if (!points.length) { + logger.warn('Something went wrong, empty handles detected.'); + return null; + } + + points.push({ + x: image.x, + y: image.y, + lines: [] + }); + this.currentHandle += 1; + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} +/** + * This function will update the handles and updateImage to force re-draw + * + * @private + * @method _setHandlesAndUpdate + * @param {(CornerstoneTools.event#TOUCH_DRAG|CornerstoneTools.event#MOUSE_DRAG|CornerstoneTools.event#MOUSE_MOVE)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _setHandlesAndUpdate(evt) { + var eventData = evt.detail; + var element = evt.detail.element; + + this._addPoint(eventData); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} +/** + * Event handler for MOUSE_UP/TOUCH_END during handle drag event loop. + * + * @private + * @method _applyStrategy + * @param {(CornerstoneTools.event#MOUSE_UP|CornerstoneTools.event#TOUCH_END)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _applyStrategy(evt) { + var points = this.handles.points; + var element = evt.detail.element; + + var _getters$labelmap2D = getters.labelmap2D(element), + labelmap2D = _getters$labelmap2D.labelmap2D, + labelmap3D = _getters$labelmap2D.labelmap3D, + currentImageIdIndex = _getters$labelmap2D.currentImageIdIndex; + + var pixelData = labelmap2D.pixelData; + var previousPixeldata = pixelData.slice(); + var operationData = { + points: points, + pixelData: pixelData, + segmentIndex: labelmap3D.activeSegmentIndex, + segmentationMixinType: "freehandSegmentationMixin" + }; + this.applyActiveStrategy(evt, operationData); + var operation = { + imageIdIndex: currentImageIdIndex, + diff: Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_5__["getDiffBetweenPixelData"])(previousPixeldata, pixelData) + }; + setters.pushState(this.element, [operation]); // Invalidate the brush tool data so it is redrawn + + setters.updateSegmentsOnLabelmap2D(labelmap2D); + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + + this._resetHandles(); +} +/** + * Sets the start and end handle points to empty objects + * + * @private + * @method _resetHandles + * @returns {undefined} + */ + + +function _resetHandles() { + this.handles = { + points: [] + }; + this.currentHandle = 0; +} +/** + * Adds a point on mouse click in polygon mode. + * + * @private + * @param {Object} evt - data object associated with an event. + * @returns {void} + */ + + +function _addPoint(evt) { + var points = this.handles.points; + + if (points.length) { + // Add the line from the current handle to the new handle + points[this.currentHandle - 1].lines.push({ + x: evt.currentPoints.image.x, + y: evt.currentPoints.image.y, + lines: [] + }); + } // Add the new handle + + + points.push({ + x: evt.currentPoints.image.x, + y: evt.currentPoints.image.y, + lines: [] + }); // Increment the current handle value + + this.currentHandle += 1; // Force onImageRendered to fire + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(evt.element); +} +/** + * @mixin freehandSegmentationMixin - segmentation operations for freehand + * @memberof Mixins + */ + + +/* harmony default export */ __webpack_exports__["default"] = ({ + postTouchStartCallback: _startOutliningRegion, + postMouseDownCallback: _startOutliningRegion, + mouseClickCallback: _startOutliningRegion, + touchDragCallback: _setHandlesAndUpdate, + mouseDragCallback: _setHandlesAndUpdate, + mouseMoveCallback: _setHandlesAndUpdate, + touchEndCallback: _applyStrategy, + mouseUpCallback: _applyStrategy, + initializeMixin: _resetHandles, + renderToolData: renderToolData, + _resetHandles: _resetHandles, + _addPoint: _addPoint, + _applyStrategy: _applyStrategy +}); + +/***/ }), + +/***/ "./mixins/segmentation/polylineSegmentationMixin.js": +/*!**********************************************************!*\ + !*** ./mixins/segmentation/polylineSegmentationMixin.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _drawing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../drawing */ "./drawing/index.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store */ "./store/index.js"); +/* harmony import */ var _freehandSegmentationMixin__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./freehandSegmentationMixin */ "./mixins/segmentation/freehandSegmentationMixin.js"); + + + + + +var _getModule = Object(_store__WEBPACK_IMPORTED_MODULE_2__["getModule"])('segmentation'), + getters = _getModule.getters; +/** + * Override for `freehandSegmentationMixin`'s `renderToolData` method to render a polyline instead + * of a freehand region with the first and last point connected. Apply after the `freehandSegmentationMixin`. + * + * @override + * @param {Object} evt The cornerstone render event. + * @returns {null} + */ + + +function renderToolData(evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element; + var color = getters.brushColor(element, true); + var context = Object(_drawing__WEBPACK_IMPORTED_MODULE_1__["getNewContext"])(eventData.canvasContext.canvas); + var handles = this.handles; + Object(_drawing__WEBPACK_IMPORTED_MODULE_1__["draw"])(context, function (context) { + var isNotTheFirstHandle = handles.points.length > 1; + + if (isNotTheFirstHandle) { + for (var j = 0; j < handles.points.length; j++) { + var lines = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(handles.points[j].lines); + + Object(_drawing__WEBPACK_IMPORTED_MODULE_1__["drawJoinedLines"])(context, element, _this.handles.points[j], lines, { + color: color + }); + } + } + }); +} + +var polylineSegmentationMixin = Object.assign({}, _freehandSegmentationMixin__WEBPACK_IMPORTED_MODULE_3__["default"], { + renderToolData: renderToolData +}); +/** + * @mixin freehandPolylineRenderOverride - segmentation operations for corrections Polyline + * @memberof Mixins + */ + +/* harmony default export */ __webpack_exports__["default"] = (polylineSegmentationMixin); + +/***/ }), + +/***/ "./mixins/segmentation/rectangleSegmentationMixin.js": +/*!***********************************************************!*\ + !*** ./mixins/segmentation/rectangleSegmentationMixin.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _drawing__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../drawing */ "./drawing/index.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); +/* harmony import */ var _util_isEmptyObject__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../util/isEmptyObject */ "./util/isEmptyObject.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../store */ "./store/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../util/segmentation */ "./util/segmentation/index.js"); + + + + + + +var _getModule = Object(_store__WEBPACK_IMPORTED_MODULE_3__["getModule"])('segmentation'), + getters = _getModule.getters, + setters = _getModule.setters; +/** + * Render hook: draws the Scissors's outline, box, or circle + * + * @param {Object} evt Cornerstone.event#cornerstoneimagerendered > cornerstoneimagerendered event + * @memberof Tools.ScissorsTool + * @returns {void} + */ + + +function renderToolData(evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element; + var color = getters.brushColor(element, true); + var context = Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["getNewContext"])(eventData.canvasContext.canvas); + Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["draw"])(context, function (context) { + Object(_drawing__WEBPACK_IMPORTED_MODULE_0__["drawRect"])(context, element, _this.handles.start, _this.handles.end, { + color: color + }); + }); +} +/** + * Sets the start handle point and claims the eventDispatcher event + * + * @private + * @param {*} evt // mousedown, touchstart, click + * @returns {Boolean} True + */ + + +function _startOutliningRegion(evt) { + var consumeEvent = true; + var element = evt.detail.element; + var image = evt.detail.currentPoints.image; + + if (Object(_util_isEmptyObject__WEBPACK_IMPORTED_MODULE_2__["default"])(this.handles.start)) { + this.handles.start = image; + } else { + this.handles.end = image; + + this._applyStrategy(evt); + } + + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + return consumeEvent; +} +/** + * This function will update the handles and updateImage to force re-draw + * + * @private + * @method _setHandlesAndUpdate + * @param {(CornerstoneTools.event#TOUCH_DRAG|CornerstoneTools.event#MOUSE_DRAG|CornerstoneTools.event#MOUSE_MOVE)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _setHandlesAndUpdate(evt) { + var _evt$detail = evt.detail, + element = _evt$detail.element, + image = _evt$detail.currentPoints.image; + this.handles.end = image; + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); +} +/** + * Event handler for MOUSE_UP/TOUCH_END during handle drag event loop. + * + * @private + * @method _applyStrategy + * @param {(CornerstoneTools.event#MOUSE_UP|CornerstoneTools.event#TOUCH_END)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + +function _applyStrategy(evt) { + evt.detail.handles = this.handles; + var element = evt.detail.element; + + var _getters$labelmap2D = getters.labelmap2D(element), + labelmap2D = _getters$labelmap2D.labelmap2D, + labelmap3D = _getters$labelmap2D.labelmap3D, + currentImageIdIndex = _getters$labelmap2D.currentImageIdIndex; + + var pixelData = labelmap2D.pixelData; + var previousPixeldata = pixelData.slice(); + var points = [{ + x: this.handles.start.x, + y: this.handles.start.y + }, { + x: this.handles.end.x, + y: this.handles.end.y + }]; + var operationData = { + points: points, + pixelData: pixelData, + segmentIndex: labelmap3D.activeSegmentIndex, + segmentationMixinType: "rectangleSegmentationMixin" + }; + this.applyActiveStrategy(evt, operationData); + var operation = { + imageIdIndex: currentImageIdIndex, + diff: Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_4__["getDiffBetweenPixelData"])(previousPixeldata, pixelData) + }; + setters.pushState(this.element, [operation]); // Invalidate the brush tool data so it is redrawn + + setters.updateSegmentsOnLabelmap2D(labelmap2D); + _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + + this._resetHandles(); +} +/** + * Sets the start and end handle points to empty objects + * + * @private + * @method _resetHandles + * @returns {void} + */ + + +function _resetHandles() { + this.handles = { + start: {}, + end: {} + }; +} +/** + * @mixin rectangleSegmentationMixin - segmentation operations for rectangles + * @memberof Mixins + */ + + +/* harmony default export */ __webpack_exports__["default"] = ({ + postTouchStartCallback: _startOutliningRegion, + postMouseDownCallback: _startOutliningRegion, + mouseClickCallback: _startOutliningRegion, + touchDragCallback: _setHandlesAndUpdate, + mouseDragCallback: _setHandlesAndUpdate, + mouseMoveCallback: _setHandlesAndUpdate, + touchEndCallback: _applyStrategy, + mouseUpCallback: _applyStrategy, + initializeMixin: _resetHandles, + renderToolData: renderToolData, + _resetHandles: _resetHandles, + _applyStrategy: _applyStrategy +}); + +/***/ }), + +/***/ "./mixins/segmentation/renderBrushMixin.js": +/*!*************************************************!*\ + !*** ./mixins/segmentation/renderBrushMixin.js ***! + \*************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); + + +/** + * Called by the event dispatcher to render the image. + * + * @param {Object} evt - The event. + * @returns {void} + */ + +function renderBrush(evt) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + + var _getModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_1__["getModule"])('segmentation'), + getters = _getModule.getters, + configuration = _getModule.configuration; + + var eventData = evt.detail; + var viewport = eventData.viewport; + var mousePosition; + + if (this._drawing) { + mousePosition = this._lastImageCoords; + } else if (this._mouseUpRender) { + mousePosition = this._lastImageCoords; + this._mouseUpRender = false; + } else { + mousePosition = _store_index_js__WEBPACK_IMPORTED_MODULE_1__["default"].state.mousePositionImage; + } + + if (!mousePosition) { + return; + } + + var _eventData$image = eventData.image, + rows = _eventData$image.rows, + columns = _eventData$image.columns; + var _mousePosition = mousePosition, + x = _mousePosition.x, + y = _mousePosition.y; + + if (x < 0 || x > columns || y < 0 || y > rows) { + return; + } // Draw the hover overlay on top of the pixel data + + + var radius = configuration.radius; + var context = eventData.canvasContext; + var element = eventData.element; + var color = getters.brushColor(element, this._drawing); + context.setTransform(1, 0, 0, 1, 0, 0); + var circleRadius = radius * viewport.scale; + var mouseCoordsCanvas = cornerstone.pixelToCanvas(element, mousePosition); + context.beginPath(); + context.strokeStyle = color; + context.ellipse(mouseCoordsCanvas.x, mouseCoordsCanvas.y, circleRadius, circleRadius, 0, 0, 2 * Math.PI); + context.stroke(); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + renderBrush: renderBrush +}); + +/***/ }), + +/***/ "./orientation/getOrientationString.js": +/*!*********************************************!*\ + !*** ./orientation/getOrientationString.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); + + +/** + * Returns the orientation of the vector in the patient coordinate system. + * @public + * @function getOrientationString + * + * @param {Array|cornerstoneMath.Vector3} vector Input array or Vector3 + * @returns {string} The orientation in the patient coordinate system. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (vector) { + var vec3 = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(vector); // Thanks to David Clunie + // https://sites.google.com/site/dicomnotes/ + + var orientation = ''; + var orientationX = vec3.x < 0 ? 'R' : 'L'; + var orientationY = vec3.y < 0 ? 'A' : 'P'; + var orientationZ = vec3.z < 0 ? 'F' : 'H'; // Should probably make this a function vector3.abs + + var abs = new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Vector3(Math.abs(vec3.x), Math.abs(vec3.y), Math.abs(vec3.z)); + var MIN = 0.0001; + + for (var i = 0; i < 3; i++) { + if (abs.x > MIN && abs.x > abs.y && abs.x > abs.z) { + orientation += orientationX; + abs.x = 0; + } else if (abs.y > MIN && abs.y > abs.x && abs.y > abs.z) { + orientation += orientationY; + abs.y = 0; + } else if (abs.z > MIN && abs.z > abs.x && abs.z > abs.y) { + orientation += orientationZ; + abs.z = 0; + } else if (abs.x > MIN && abs.y > MIN && abs.x === abs.y) { + orientation += orientationX + orientationY; + abs.x = 0; + abs.y = 0; + } else if (abs.x > MIN && abs.z > MIN && abs.x === abs.z) { + orientation += orientationX + orientationZ; + abs.x = 0; + abs.z = 0; + } else if (abs.y > MIN && abs.z > MIN && abs.y === abs.z) { + orientation += orientationY + orientationZ; + abs.y = 0; + abs.z = 0; + } else { + break; + } + } + + return orientation; +}); + +/***/ }), + +/***/ "./orientation/index.js": +/*!******************************!*\ + !*** ./orientation/index.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _getOrientationString_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getOrientationString.js */ "./orientation/getOrientationString.js"); +/* harmony import */ var _invertOrientationString_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./invertOrientationString.js */ "./orientation/invertOrientationString.js"); + + +var orientation = { + getOrientationString: _getOrientationString_js__WEBPACK_IMPORTED_MODULE_0__["default"], + invertOrientationString: _invertOrientationString_js__WEBPACK_IMPORTED_MODULE_1__["default"] +}; +/* harmony default export */ __webpack_exports__["default"] = (orientation); + +/***/ }), + +/***/ "./orientation/invertOrientationString.js": +/*!************************************************!*\ + !*** ./orientation/invertOrientationString.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Inverts an orientation string. + * @public + * @function invertOrientationString + * + * @param {string} orientationString The orientation. + * @returns {string} The inverted orientationString. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (orientationString) { + var inverted = orientationString.replace('H', 'f'); + inverted = inverted.replace('F', 'h'); + inverted = inverted.replace('R', 'l'); + inverted = inverted.replace('L', 'r'); + inverted = inverted.replace('A', 'p'); + inverted = inverted.replace('P', 'a'); + inverted = inverted.toUpperCase(); + return inverted; +}); + +/***/ }), + +/***/ "./stackTools/fusionRenderer.js": +/*!**************************************!*\ + !*** ./stackTools/fusionRenderer.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FusionRenderer; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); + + + + + +var FusionRenderer = +/*#__PURE__*/ +function () { + function FusionRenderer() { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FusionRenderer); + + this.currentImageIdIndex = 0; + this.layerIds = []; + this.findImageFn = undefined; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(FusionRenderer, [{ + key: "render", + value: function render(element, imageStacks) { + var _this = this; + + // Move this to base Renderer class + if (!Number.isInteger(this.currentImageIdIndex)) { + throw new Error('FusionRenderer: render - Image ID Index is not an integer'); + } + + if (!this.findImageFn) { + throw new Error('No findImage function has been defined'); + } + + if (!imageStacks) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, 'stack'); + imageStacks = toolData.data; + } // TODO: Figure out what to do with LoadHandlers in this scenario... + + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone; // For the base layer, go to the currentImageIdIndex + + var baseImageObject = imageStacks[0]; + var currentImageId = baseImageObject.imageIds[this.currentImageIdIndex]; + var overlayImageStacks = imageStacks.slice(1, imageStacks.length); + cornerstone.loadAndCacheImage(currentImageId).then(function (baseImage) { + var baseLayerId = _this.layerIds[0]; // Get the base layer if one exists + + if (baseLayerId) { + cornerstone.setLayerImage(element, baseImage, baseLayerId); + } else { + // Otherwise, create a new layer with the base layer's image + baseLayerId = cornerstone.addLayer(element, baseImage, baseImageObject.options); + + _this.layerIds.push(baseLayerId); + } // Display the image immediately while the overlay images are identified + + + cornerstone.displayImage(element, baseImage); // Loop through the remaining 'overlay' image stacks + + overlayImageStacks.forEach(function (imgObj, overlayLayerIndex) { + var imageId = _this.findImageFn(imgObj.imageIds, currentImageId); + + var layerIndex = overlayLayerIndex + 1; + var currentLayerId = _this.layerIds[layerIndex]; // If no layer exists yet for this overlaid stack, create + // One and add it to the layerIds property for this instance + // Of the fusion renderer. + + if (!currentLayerId) { + currentLayerId = cornerstone.addLayer(element, undefined, imgObj.options); + + _this.layerIds.push(currentLayerId); + } + + if (imageId) { + // If an imageId was returned from the findImage function, + // Load it, make sure it's visible and update the layer + // With the new image object. + cornerstone.loadAndCacheImage(imageId).then(function (image) { + cornerstone.setLayerImage(element, image, currentLayerId); + cornerstone.updateImage(element); + }); + } else { + // If no imageId was returned from the findImage function. + // This means that there is no relevant image to display. + cornerstone.setLayerImage(element, undefined, currentLayerId); + cornerstone.setActiveLayer(element, baseLayerId); + cornerstone.updateImage(element); + } + }); + }); + } + }]); + + return FusionRenderer; +}(); + + + +/***/ }), + +/***/ "./stackTools/playClip.js": +/*!********************************!*\ + !*** ./stackTools/playClip.js ***! + \********************************/ +/*! exports provided: playClip, stopClip */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "playClip", function() { return playClip; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "stopClip", function() { return stopClip; }); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); + + + + + +var toolName = 'playClip'; +/** + * [private] Turns a Frame Time Vector (0018,1065) array into a normalized array of timeouts. Each element + * ... of the resulting array represents the amount of time each frame will remain on the screen. + * @param {Array} vector A Frame Time Vector (0018,1065) as specified in section C.7.6.5.1.2 of DICOM standard. + * @param {Number} speed A speed factor which will be applied to each element of the resulting array. + * @returns {Array} An array with timeouts for each animation frame. + */ + +function getPlayClipTimeouts(vector, speed) { + var i; + var sample; + var delay; + var sum = 0; + var limit = vector.length; + var timeouts = []; // Initialize time varying to false + + timeouts.isTimeVarying = false; + + if (typeof speed !== 'number' || speed <= 0) { + speed = 1; + } // First element of a frame time vector must be discarded + + + for (i = 1; i < limit; i++) { + // eslint-disable-next-line no-bitwise + delay = Number(vector[i]) / speed | 0; // Integral part only + + timeouts.push(delay); + + if (i === 1) { + // Use first item as a sample for comparison + sample = delay; + } else if (delay !== sample) { + timeouts.isTimeVarying = true; + } + + sum += delay; + } + + if (timeouts.length > 0) { + if (timeouts.isTimeVarying) { + // If it's a time varying vector, make the last item an average... + // eslint-disable-next-line no-bitwise + delay = sum / timeouts.length | 0; + } else { + delay = timeouts[0]; + } + + timeouts.push(delay); + } + + return timeouts; +} +/** + * [private] Performs the heavy lifting of stopping an ongoing animation. + * @param {Object} playClipData The data from playClip that needs to be stopped. + * @returns {void} + */ + + +function stopClipWithData(playClipData) { + var id = playClipData.intervalId; + + if (typeof id !== 'undefined') { + playClipData.intervalId = undefined; + + if (playClipData.usingFrameTimeVector) { + clearTimeout(id); + } else { + clearInterval(id); + } + } +} +/** + * [private] Trigger playClip tool stop event. + * @param {HTMLElement} element + * @returns {void} + */ + + +function triggerStopEvent(element) { + var eventDetail = { + element: element + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].CLIP_STOPPED, eventDetail); +} +/** + * Starts playing a clip or adjusts the frame rate of an already playing clip. framesPerSecond is + * optional and defaults to 30 if not specified. A negative framesPerSecond will play the clip in reverse. + * The element must be a stack of images + * @param {HTMLElement} element + * @param {number} framesPerSecond + * @returns {void} + */ + + +function playClip(element, framesPerSecond) { + var playClipData; + var playClipTimeouts; + + if (element === undefined) { + throw new Error('playClip: element must not be undefined'); + } + + var stackToolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, 'stack'); + + if (!stackToolData || !stackToolData.data || !stackToolData.data.length) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone; // If we have more than one stack, check if we have a stack renderer defined + + var stackRenderer; + + if (stackToolData.data.length > 1) { + var stackRendererData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, 'stackRenderer'); + + if (stackRendererData && stackRendererData.data && stackRendererData.data.length) { + stackRenderer = stackRendererData.data[0]; + } + } + + var stackData = stackToolData.data[0]; + var playClipToolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, toolName); + + if (!playClipToolData || !playClipToolData.data || !playClipToolData.data.length) { + playClipData = { + intervalId: undefined, + framesPerSecond: 30, + lastFrameTimeStamp: undefined, + frameRate: 0, + frameTimeVector: undefined, + ignoreFrameTimeVector: false, + usingFrameTimeVector: false, + speed: 1, + reverse: false, + loop: true + }; + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["addToolState"])(element, toolName, playClipData); + } else { + playClipData = playClipToolData.data[0]; // Make sure the specified clip is not running before any property update + + stopClipWithData(playClipData); + } // If a framesPerSecond is specified and is valid, update the playClipData now + + + if (framesPerSecond < 0 || framesPerSecond > 0) { + playClipData.framesPerSecond = Number(framesPerSecond); + playClipData.reverse = playClipData.framesPerSecond < 0; // If framesPerSecond is given, frameTimeVector will be ignored... + + playClipData.ignoreFrameTimeVector = true; + } // Determine if frame time vector should be used instead of a fixed frame rate... + + + if (playClipData.ignoreFrameTimeVector !== true && playClipData.frameTimeVector && playClipData.frameTimeVector.length === stackData.imageIds.length) { + playClipTimeouts = getPlayClipTimeouts(playClipData.frameTimeVector, playClipData.speed); + } // This function encapsulates the frame rendering logic... + + + var playClipAction = function playClipAction() { + // Hoisting of context variables + var loader, + startLoadingHandler, + endLoadingHandler, + errorLoadingHandler, + newImageIdIndex = stackData.currentImageIdIndex; + var imageCount = stackData.imageIds.length; + + if (playClipData.reverse) { + newImageIdIndex--; + } else { + newImageIdIndex++; + } + + if (!playClipData.loop && (newImageIdIndex < 0 || newImageIdIndex >= imageCount)) { + stopClipWithData(playClipData); + triggerStopEvent(element); + return; + } // Loop around if we go outside the stack + + + if (newImageIdIndex >= imageCount) { + newImageIdIndex = 0; + } + + if (newImageIdIndex < 0) { + newImageIdIndex = imageCount - 1; + } + + if (newImageIdIndex !== stackData.currentImageIdIndex) { + startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getStartLoadHandler(element); + endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getEndLoadHandler(element); + errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorLoadingHandler(element); + + if (startLoadingHandler) { + startLoadingHandler(element); + } + + if (stackData.preventCache === true) { + loader = cornerstone.loadImage(stackData.imageIds[newImageIdIndex]); + } else { + loader = cornerstone.loadAndCacheImage(stackData.imageIds[newImageIdIndex]); + } + + loader.then(function (image) { + try { + stackData.currentImageIdIndex = newImageIdIndex; + + if (stackRenderer) { + stackRenderer.currentImageIdIndex = newImageIdIndex; + stackRenderer.render(element, stackToolData.data); + } else { + cornerstone.displayImage(element, image); + } + + if (endLoadingHandler) { + endLoadingHandler(element, image); + } + } catch (error) { + return; + } + }, function (error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(element, imageId, error); + } + }); + } + }; // If playClipTimeouts array is available, not empty and its elements are NOT uniform ... + // ... (at least one timeout is different from the others), use alternate setTimeout implementation + + + if (playClipTimeouts && playClipTimeouts.length > 0 && playClipTimeouts.isTimeVarying) { + playClipData.usingFrameTimeVector = true; + playClipData.intervalId = setTimeout(function playClipTimeoutHandler() { + playClipData.intervalId = setTimeout(playClipTimeoutHandler, playClipTimeouts[stackData.currentImageIdIndex]); + playClipAction(); + }, 0); + } else { + // ... otherwise user setInterval implementation which is much more efficient. + playClipData.usingFrameTimeVector = false; + playClipData.intervalId = setInterval(playClipAction, 1000 / Math.abs(playClipData.framesPerSecond)); + } +} +/** + * Stops an already playing clip. + * @param {HTMLElement} element + * @returns {void} + */ + + +function stopClip(element) { + var playClipToolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, toolName); + + if (!playClipToolData || !playClipToolData.data || !playClipToolData.data.length) { + return; + } + + stopClipWithData(playClipToolData.data[0]); +} + + + +/***/ }), + +/***/ "./stackTools/stackPrefetch.js": +/*!*************************************!*\ + !*** ./stackTools/stackPrefetch.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_triggerEvent__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/triggerEvent */ "./util/triggerEvent.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../events.js */ "./events.js"); + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('stackTools:stackPrefetch'); +var toolName = 'stackPrefetch'; +var requestType = 'prefetch'; +var priority = 0; +var addToBeginning = true; +var configuration = { + maxImagesToPrefetch: Infinity, + preserveExistingPool: false +}; +var resetPrefetchTimeout; +var resetPrefetchDelay = 10; + +function range(lowEnd, highEnd) { + // Javascript version of Python's range function + // http://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-an-array-based-on-suppl + lowEnd = Math.round(lowEnd) || 0; + highEnd = Math.round(highEnd) || 0; + var arr = []; + var c = highEnd - lowEnd + 1; + + if (c <= 0) { + return arr; + } + + while (c--) { + arr[c] = highEnd--; + } + + return arr; +} + +function nearestIndex(arr, x) { + // Return index of nearest values in array + // http://stackoverflow.com/questions/25854212/return-index-of-nearest-values-in-an-array + var low = 0; + var high = arr.length - 1; + arr.forEach(function (v, idx) { + if (v < x) { + low = Math.max(idx, low); + } else if (v > x) { + high = Math.min(idx, high); + } + }); + return { + low: low, + high: high + }; +} + +function prefetch(element) { + // Check to make sure stack data exists + var stackData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + + if (!stackData || !stackData.data || !stackData.data.length) { + return; + } + + var stack = stackData.data[0]; // Get the stackPrefetch tool data + + var stackPrefetchData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, toolName); + + if (!stackPrefetchData) { + return; + } + + var stackPrefetch = stackPrefetchData.data[0] || {}; // If all the requests are complete, disable the stackPrefetch tool + + if (!stackPrefetch.indicesToRequest || !stackPrefetch.indicesToRequest.length) { + stackPrefetch.enabled = false; + } // Make sure the tool is still enabled + + + if (stackPrefetch.enabled === false) { + return; + } // Remove an imageIdIndex from the list of indices to request + // This fires when the individual image loading deferred is resolved + + + function removeFromList(imageIdIndex) { + var index = stackPrefetch.indicesToRequest.indexOf(imageIdIndex); + + if (index > -1) { + // Don't remove last element if imageIdIndex not found + stackPrefetch.indicesToRequest.splice(index, 1); + } + } // Remove all already cached images from the + // IndicesToRequest array + + + stackPrefetchData.data[0].indicesToRequest.sort(function (a, b) { + return a - b; + }); + var indicesToRequestCopy = stackPrefetch.indicesToRequest.slice(); + indicesToRequestCopy.forEach(function (imageIdIndex) { + var imageId = stack.imageIds[imageIdIndex]; + + if (!imageId) { + return; + } + + var imageLoadObject = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.imageCache.getImageLoadObject(imageId); + + if (imageLoadObject) { + removeFromList(imageIdIndex); + } + }); // Stop here if there are no images left to request + // After those in the cache have been removed + + if (!stackPrefetch.indicesToRequest.length) { + return; + } // Clear the requestPool of prefetch requests, if needed. + + + if (!configuration.preserveExistingPool) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.imageLoadPoolManager.clearRequestStack(requestType); + } // Identify the nearest imageIdIndex to the currentImageIdIndex + + + var nearest = nearestIndex(stackPrefetch.indicesToRequest, stack.currentImageIdIndex); + var imageId; + var nextImageIdIndex; + var preventCache = false; + + function doneCallback(image) { + logger.log('prefetch done: %s', image.imageId); + var imageIdIndex = stack.imageIds.indexOf(image.imageId); + removeFromList(imageIdIndex); + Object(_util_triggerEvent__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_5__["default"].STACK_PREFETCH_IMAGE_LOADED, { + element: element, + imageId: image.imageId, + imageIndex: imageIdIndex, + stackPrefetch: stackPrefetch, + stack: stack + }); // If there are no more images to fetch + + if (!(stackPrefetch.indicesToRequest && stackPrefetch.indicesToRequest.length > 0)) { + Object(_util_triggerEvent__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_5__["default"].STACK_PREFETCH_DONE, { + element: element, + stackPrefetch: stackPrefetch, + stack: stack + }); + } + } // Retrieve the errorLoadingHandler if one exists + + + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_1__["default"].getErrorLoadingHandler(element); + + function failCallback(error) { + logger.log('prefetch errored: %o', error); + + if (errorLoadingHandler) { + errorLoadingHandler(element, imageId, error, 'stackPrefetch'); + } + } // Prefetch images around the current image (before and after) + + + var lowerIndex = nearest.low; + var higherIndex = nearest.high; + var imageIdsToPrefetch = []; + + while (lowerIndex >= 0 || higherIndex < stackPrefetch.indicesToRequest.length) { + var currentIndex = stack.currentImageIdIndex; + var shouldSkipLower = currentIndex - stackPrefetch.indicesToRequest[lowerIndex] > configuration.maxImagesToPrefetch; + var shouldSkipHigher = stackPrefetch.indicesToRequest[higherIndex] - currentIndex > configuration.maxImagesToPrefetch; + var shouldLoadLower = !shouldSkipLower && lowerIndex >= 0; + var shouldLoadHigher = !shouldSkipHigher && higherIndex < stackPrefetch.indicesToRequest.length; + + if (!shouldLoadHigher && !shouldLoadLower) { + break; + } + + if (shouldLoadLower) { + nextImageIdIndex = stackPrefetch.indicesToRequest[lowerIndex--]; + imageId = stack.imageIds[nextImageIdIndex]; + imageIdsToPrefetch.push(imageId); + } + + if (shouldLoadHigher) { + nextImageIdIndex = stackPrefetch.indicesToRequest[higherIndex++]; + imageId = stack.imageIds[nextImageIdIndex]; + imageIdsToPrefetch.push(imageId); + } + } + + var requestFn; + var options = { + addToBeginning: addToBeginning, + priority: priority, + requestType: requestType + }; + + if (preventCache) { + requestFn = function requestFn(id) { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.loadImage(id, options); + }; + } else { + requestFn = function requestFn(id) { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.loadAndCacheImage(id, options); + }; + } + + imageIdsToPrefetch.reverse().forEach(function (imageId) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.imageLoadPoolManager.addRequest(requestFn.bind(null, imageId), requestType, // Additional details + { + imageId: imageId + }, priority, addToBeginning); + }); +} + +function getPromiseRemovedHandler(element) { + return function (e) { + var eventData = e.detail; // When an imagePromise has been pushed out of the cache, re-add its index + // It to the indicesToRequest list so that it will be retrieved later if the + // CurrentImageIdIndex is changed to an image nearby + + var stackData; + + try { + // It will throw an exception in some cases (eg: thumbnails) + stackData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + } catch (error) { + return; + } + + if (!stackData || !stackData.data || !stackData.data.length) { + return; + } + + var stack = stackData.data[0]; + var imageIdIndex = stack.imageIds.indexOf(eventData.imageId); // Make sure the image that was removed is actually in this stack + // Before adding it to the indicesToRequest array + + if (imageIdIndex < 0) { + return; + } + + var stackPrefetchData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, toolName); + + if (!stackPrefetchData || !stackPrefetchData.data || !stackPrefetchData.data.length) { + return; + } + + stackPrefetchData.data[0].indicesToRequest.push(imageIdIndex); + }; +} + +function onImageUpdated(e) { + // Start prefetching again (after a delay) + // When the user has scrolled to a new image + clearTimeout(resetPrefetchTimeout); + resetPrefetchTimeout = setTimeout(function () { + var element = e.target; // If playClip is enabled and the user loads a different series in the viewport + // An exception will be thrown because the element will not be enabled anymore + + try { + prefetch(element); + } catch (error) { + return; + } + }, resetPrefetchDelay); +} + +function enable(element) { + // Clear old prefetch data. Skipping this can cause problems when changing the series inside an element + var stackPrefetchDataArray = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, toolName); + stackPrefetchDataArray.data = []; // First check that there is stack data available + + var stackData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + + if (!stackData || !stackData.data || !stackData.data.length) { + return; + } + + var stack = stackData.data[0]; // Check if we are allowed to cache images in this stack + + if (stack.preventCache === true) { + logger.warn('A stack that should not be cached was given the stackPrefetch'); + return; + } // Use the currentImageIdIndex from the stack as the initalImageIdIndex + + + var stackPrefetchData = { + indicesToRequest: range(0, stack.imageIds.length - 1), + enabled: true, + direction: 1 + }; // Remove the currentImageIdIndex from the list to request + + var indexOfCurrentImage = stackPrefetchData.indicesToRequest.indexOf(stack.currentImageIdIndex); + stackPrefetchData.indicesToRequest.splice(indexOfCurrentImage, 1); + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["addToolState"])(element, toolName, stackPrefetchData); + prefetch(element); + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.NEW_IMAGE, onImageUpdated); + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.NEW_IMAGE, onImageUpdated); + var promiseRemovedHandler = getPromiseRemovedHandler(element); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.events.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.IMAGE_CACHE_PROMISE_REMOVED, promiseRemovedHandler); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.events.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.IMAGE_CACHE_PROMISE_REMOVED, promiseRemovedHandler); +} + +function disable(element) { + clearTimeout(resetPrefetchTimeout); + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.NEW_IMAGE, onImageUpdated); + var promiseRemovedHandler = getPromiseRemovedHandler(element); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.events.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.IMAGE_CACHE_PROMISE_REMOVED, promiseRemovedHandler); + var stackPrefetchData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, toolName); // If there is actually something to disable, disable it + + if (stackPrefetchData && stackPrefetchData.data.length) { + stackPrefetchData.data[0].enabled = false; // Clear current prefetch requests from the requestPool + + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.imageLoadPoolManager.clearRequestStack(requestType); + } +} + +function getConfiguration() { + return configuration; +} + +function setConfiguration(config) { + configuration = config; +} // Module/private exports + + +var stackPrefetch = { + enable: enable, + disable: disable, + getConfiguration: getConfiguration, + setConfiguration: setConfiguration +}; +/* harmony default export */ __webpack_exports__["default"] = (stackPrefetch); + +/***/ }), + +/***/ "./stackTools/stackRenderers.js": +/*!**************************************!*\ + !*** ./stackTools/stackRenderers.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _fusionRenderer_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./fusionRenderer.js */ "./stackTools/fusionRenderer.js"); + +var stackRenderers = {}; +stackRenderers.FusionRenderer = _fusionRenderer_js__WEBPACK_IMPORTED_MODULE_0__["default"]; +/* harmony default export */ __webpack_exports__["default"] = (stackRenderers); + +/***/ }), + +/***/ "./stateManagement/frameOfReferenceStateManager.js": +/*!*********************************************************!*\ + !*** ./stateManagement/frameOfReferenceStateManager.js ***! + \*********************************************************/ +/*! exports provided: newFrameOfReferenceSpecificToolStateManager, globalFrameOfReferenceSpecificToolStateManager */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "newFrameOfReferenceSpecificToolStateManager", function() { return newFrameOfReferenceSpecificToolStateManager; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "globalFrameOfReferenceSpecificToolStateManager", function() { return globalFrameOfReferenceSpecificToolStateManager; }); +/** + * Implements a frame-of-reference specific tool state management strategy. This means that + * Measurement data are tied to a specific frame of reference UID and only visible to objects using + * That frame-of-reference UID. + * @public + * @constructor newFrameOfReferenceSpecificToolStateManager + * @memberof StateManagement + * + * @returns {Object} A frameOfReferenceSpecificToolStateManager instance. + */ +function newFrameOfReferenceSpecificToolStateManager() { + var toolState = {}; // Here we add tool state, this is done by tools as well + // As modules that restore saved state + + function addFrameOfReferenceSpecificToolState(frameOfReference, toolName, data) { + // If we don't have any tool state for this frameOfReference, add an empty object + if (toolState.hasOwnProperty(frameOfReference) === false) { + toolState[frameOfReference] = {}; + } + + var frameOfReferenceToolState = toolState[frameOfReference]; // If we don't have tool state for this type of tool, add an empty object + + if (frameOfReferenceToolState.hasOwnProperty(toolName) === false) { + frameOfReferenceToolState[toolName] = { + data: [] + }; + } + + var toolData = frameOfReferenceToolState[toolName]; // Finally, add this new tool to the state + + toolData.data.push(data); + } // Here you can get state - used by tools as well as modules + // That save state persistently + + + function getFrameOfReferenceSpecificToolState(frameOfReference, toolName) { + // If we don't have any tool state for this frame of reference, return undefined + if (toolState.hasOwnProperty(frameOfReference) === false) { + return; + } + + var frameOfReferenceToolState = toolState[frameOfReference]; // If we don't have tool state for this type of tool, return undefined + + if (frameOfReferenceToolState.hasOwnProperty(toolName) === false) { + return; + } + + var toolData = frameOfReferenceToolState[toolName]; + return toolData; + } + + function removeFrameOfReferenceSpecificToolState(frameOfReference, toolName, data) { + // If we don't have any tool state for this frame of reference, return undefined + if (toolState.hasOwnProperty(frameOfReference) === false) { + return; + } + + var frameOfReferenceToolState = toolState[frameOfReference]; // If we don't have tool state for this type of tool, return undefined + + if (frameOfReferenceToolState.hasOwnProperty(toolName) === false) { + return; + } + + var toolData = frameOfReferenceToolState[toolName]; // Find this tool data + + var indexOfData = -1; + + for (var i = 0; i < toolData.data.length; i++) { + if (toolData.data[i] === data) { + indexOfData = i; + } + } + + if (indexOfData !== -1) { + toolData.data.splice(indexOfData, 1); + } + } + + return { + get: getFrameOfReferenceSpecificToolState, + add: addFrameOfReferenceSpecificToolState, + remove: removeFrameOfReferenceSpecificToolState + }; +} // A global frameOfReferenceSpecificToolStateManager - the most common case is to share 3d information +// Between stacks of images + + +var globalFrameOfReferenceSpecificToolStateManager = newFrameOfReferenceSpecificToolStateManager(); + + +/***/ }), + +/***/ "./stateManagement/imageIdSpecificStateManager.js": +/*!********************************************************!*\ + !*** ./stateManagement/imageIdSpecificStateManager.js ***! + \********************************************************/ +/*! exports provided: newImageIdSpecificToolStateManager, globalImageIdSpecificToolStateManager */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "newImageIdSpecificToolStateManager", function() { return newImageIdSpecificToolStateManager; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "globalImageIdSpecificToolStateManager", function() { return globalImageIdSpecificToolStateManager; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Implements an imageId specific tool state management strategy. This means that + * Measurements data is tied to a specific imageId and only visible for enabled elements + * That are displaying that imageId. + * @public + * @constructor newImageIdSpecificToolStateManager + * @memberof StateManagement + * + * @returns {Object} An imageIdSpecificToolStateManager instance. + */ + +function newImageIdSpecificToolStateManager() { + var toolState = {}; // Here we add tool state, this is done by tools as well + // As modules that restore saved state + + function saveImageIdToolState(imageId) { + return toolState[imageId]; + } + + function restoreImageIdToolState(imageId, imageIdToolState) { + toolState[imageId] = imageIdToolState; + } + + function saveToolState() { + return toolState; + } + + function restoreToolState(savedToolState) { + toolState = savedToolState; + } // Here we add tool state, this is done by tools as well + // As modules that restore saved state + + + function addElementToolState(element, toolName, data) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); // If we don't have an image for this element exit early + + if (!enabledElement.image) { + return; + } + + addImageIdToolState(enabledElement.image.imageId, toolName, data); + } + + function addImageIdToolState(imageId, toolName, data) { + // If we don't have any tool state for this imageId, add an empty object + if (toolState.hasOwnProperty(imageId) === false) { + toolState[imageId] = {}; + } + + var imageIdToolState = toolState[imageId]; // If we don't have tool state for this tool name, add an empty object + + if (imageIdToolState.hasOwnProperty(toolName) === false) { + imageIdToolState[toolName] = { + data: [] + }; + } + + var toolData = imageIdToolState[toolName]; // Finally, add this new tool to the state + + toolData.data.push(data); + } + + function getElementToolState(element, toolName) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); // If the element does not have an image return undefined. + + if (!enabledElement.image) { + return; + } + + return getImageIdToolState(enabledElement.image.imageId, toolName); + } // Here you can get state - used by tools as well as modules + // That save state persistently + + + function getImageIdToolState(imageId, toolName) { + // If we don't have any tool state for this imageId, return undefined + if (toolState.hasOwnProperty(imageId) === false) { + return; + } + + var imageIdToolState = toolState[imageId]; // If we don't have tool state for this tool name, return undefined + + if (imageIdToolState.hasOwnProperty(toolName) === false) { + return; + } + + return imageIdToolState[toolName]; + } // Replaces the given tool's state using the provided element's imageId + + + function setElementToolState(element, toolName, data) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + setImageIdToolState(enabledElement.image.imageId, toolName, data); + } // Replaces the imageId's tool state for a given tool + + + function setImageIdToolState(imageId, toolName, data) { + var imageIdToolState = toolState[imageId]; // Set the toolState + + imageIdToolState[toolName] = data; + } // Clears all tool data from this toolStateManager. + + + function clearElementToolState(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + + clearImageIdToolState(enabledElement.image.imageId); + } + + function clearImageIdToolState(imageId) { + if (toolState.hasOwnProperty(imageId) === false) { + return; + } + + delete toolState[imageId]; + } + + return { + get: getElementToolState, + add: addElementToolState, + set: setElementToolState, + clear: clearElementToolState, + getImageIdToolState: getImageIdToolState, + addImageIdToolState: addImageIdToolState, + setImageIdToolState: setImageIdToolState, + clearImageIdToolState: clearImageIdToolState, + saveImageIdToolState: saveImageIdToolState, + restoreImageIdToolState: restoreImageIdToolState, + saveToolState: saveToolState, + restoreToolState: restoreToolState, + toolState: toolState + }; +} // A global imageIdSpecificToolStateManager - the most common case is to share state between all +// Visible enabled images + + +var globalImageIdSpecificToolStateManager = newImageIdSpecificToolStateManager(); + + +/***/ }), + +/***/ "./stateManagement/loadHandlerManager.js": +/*!***********************************************!*\ + !*** ./stateManagement/loadHandlerManager.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +var _DEFAULT_LOAD_HANDLER = 'DEFAULT'; +var defaultStartLoadHandler = {}; +var defaultEndLoadHandler = {}; +var defaultErrorLoadingHandler = {}; + +function _getUUIDFromElement(element) { + if (!element) { + return _DEFAULT_LOAD_HANDLER; + } + + var uuid = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element).uuid; + + if (!uuid) { + throw new Error('Something went wrong when getting uuid from element'); + } + + return uuid; +} + +function setStartLoadHandler(handler) { + var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + + if (!handler) { + throw new Error('The Handler function must be defined'); + } + + var uuid = _getUUIDFromElement(element); + + defaultStartLoadHandler[uuid] = handler; +} + +function getStartLoadHandler(element) { + var uuid = _getUUIDFromElement(element); + + return defaultStartLoadHandler[uuid] || defaultStartLoadHandler[_DEFAULT_LOAD_HANDLER]; +} + +function setEndLoadHandler(handler) { + var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + + if (!handler) { + throw new Error('The Handler function must be defined'); + } + + var uuid = _getUUIDFromElement(element); + + defaultEndLoadHandler[uuid] = handler; +} + +function getEndLoadHandler(element) { + var uuid = _getUUIDFromElement(element); + + return defaultEndLoadHandler[uuid] || defaultEndLoadHandler[_DEFAULT_LOAD_HANDLER]; +} + +function setErrorLoadingHandler(handler) { + var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; + + if (!handler) { + throw new Error('The Handler function must be defined'); + } + + var uuid = _getUUIDFromElement(element); + + defaultErrorLoadingHandler[uuid] = handler; +} + +function getErrorLoadingHandler(element) { + var uuid = _getUUIDFromElement(element); + + return defaultErrorLoadingHandler[uuid] || defaultErrorLoadingHandler[_DEFAULT_LOAD_HANDLER]; +} + +function removeHandlers(element) { + var uuid = _getUUIDFromElement(element); + + delete defaultStartLoadHandler[uuid]; + delete defaultEndLoadHandler[uuid]; + delete defaultErrorLoadingHandler[uuid]; +} + +var loadHandlerManager = { + setStartLoadHandler: setStartLoadHandler, + getStartLoadHandler: getStartLoadHandler, + setEndLoadHandler: setEndLoadHandler, + getEndLoadHandler: getEndLoadHandler, + setErrorLoadingHandler: setErrorLoadingHandler, + getErrorLoadingHandler: getErrorLoadingHandler, + removeHandlers: removeHandlers +}; +/* harmony default export */ __webpack_exports__["default"] = (loadHandlerManager); + +/***/ }), + +/***/ "./stateManagement/stackSpecificStateManager.js": +/*!******************************************************!*\ + !*** ./stateManagement/stackSpecificStateManager.js ***! + \******************************************************/ +/*! exports provided: stackSpecificStateManager, newStackSpecificToolStateManager, addStackStateManager */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "stackSpecificStateManager", function() { return stackSpecificStateManager; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "newStackSpecificToolStateManager", function() { return newStackSpecificToolStateManager; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addStackStateManager", function() { return addStackStateManager; }); +/* harmony import */ var _imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./imageIdSpecificStateManager.js */ "./stateManagement/imageIdSpecificStateManager.js"); +/* harmony import */ var _toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./toolState.js */ "./stateManagement/toolState.js"); + + +/** + * Implements an Stack specific tool state management strategy. This means + * That tool data is shared between all imageIds in a given stack. + * @public + * @constructor newStackSpecificToolStateManager + * @memberof StateManagement + * + * @param {string[]} toolNames List of tools that should have state shared across a stack (a display set) of images + * @param {Object} oldStateManager The imageIdSpecificStateManager. + * @returns {Object} A stackSpecificToolStateManager instance. + */ + +function newStackSpecificToolStateManager(toolNames, oldStateManager) { + var toolState = {}; + + function saveToolState() { + return toolState; + } + + function restoreToolState(stackToolState) { + toolState = stackToolState; + } // Here we add tool state, this is done by tools as well + // As modules that restore saved state + + + function addStackSpecificToolState(element, toolName, data) { + // If this is a tool type to apply to the stack, do so + if (toolNames.indexOf(toolName) >= 0) { + // If we don't have tool state for this tool name, add an empty object + if (toolState.hasOwnProperty(toolName) === false) { + toolState[toolName] = { + data: [] + }; + } + + var toolData = toolState[toolName]; // Finally, add this new tool to the state + + toolData.data.push(data); + } else { + // Call the imageId specific tool state manager + return oldStateManager.add(element, toolName, data); + } + } // Here you can get state - used by tools as well as modules + // That save state persistently + + + function getStackSpecificToolState(element, toolName) { + // If this is a tool type to apply to the stack, do so + if (toolNames.indexOf(toolName) >= 0) { + // If we don't have tool state for this tool name, add an empty object + if (toolState.hasOwnProperty(toolName) === false) { + toolState[toolName] = { + data: [] + }; + } + + return toolState[toolName]; + } // Call the imageId specific tool state manager + + + return oldStateManager.get(element, toolName); + } + + var stackSpecificToolStateManager = { + get: getStackSpecificToolState, + add: addStackSpecificToolState, + saveToolState: saveToolState, + restoreToolState: restoreToolState, + toolState: toolState + }; + return stackSpecificToolStateManager; +} + +var stackStateManagers = []; + +function addStackStateManager(element, otherTools) { + var oldStateManager = Object(_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getElementToolStateManager"])(element); + + if (!oldStateManager) { + oldStateManager = _imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_0__["globalImageIdSpecificToolStateManager"]; + } + + var stackTools = ['stack', 'stackPrefetch', 'playClip', 'volume', 'slab', 'referenceLines', 'crosshairs', 'stackRenderer']; + + if (otherTools) { + stackTools = stackTools.concat(otherTools); + } + + var stackSpecificStateManager = newStackSpecificToolStateManager(stackTools, oldStateManager); + stackStateManagers.push(stackSpecificStateManager); + Object(_toolState_js__WEBPACK_IMPORTED_MODULE_1__["setElementToolStateManager"])(element, stackSpecificStateManager); +} + +var stackSpecificStateManager = { + newStackSpecificToolStateManager: newStackSpecificToolStateManager, + addStackStateManager: addStackStateManager +}; + + +/***/ }), + +/***/ "./stateManagement/textStyle.js": +/*!**************************************!*\ + !*** ./stateManagement/textStyle.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var textStyle = { + fontSize: 15, + fontFamily: 'Arial', + backgroundColor: 'transparent' +}; +/** + * @deprecated + * This function will be deprecated and users must use `setFontSize` and + * `setFontFamily` to set the font configuration independently. + * + * @param {string} font Font string with font size and font family + * @returns {void} + */ + +function setFont(font) { + var split = font.split('px '); + + if (split.length === 2) { + setFontSize(parseFloat(split[0])); + setFontFamily(split[1]); + } +} +/** + * Returns all the font styling properties combined into a single string + * following the CSS font property pattern. + * @see {@link https://www.w3.org/TR/css-fonts-3/#font-prop|3.7. Shorthand font property: the font property} + * + * @returns {string} CSS font property + */ + + +function getFont() { + return "".concat(textStyle.fontSize, "px ").concat(textStyle.fontFamily); +} +/** + * Sets the font family that will be used for general font rendering. + * @see {@link https://www.w3.org/TR/css-fonts-3/#font-family-prop|3.1. Font family: the font-family property} + * + * @param {string} fontFamily Name of the font to be used + * @returns {void} + */ + + +function setFontFamily(fontFamily) { + if (typeof fontFamily !== 'string') { + throw new Error('Font family must be a valid string'); + } + + textStyle.fontFamily = fontFamily; +} +/** + * Returns the defined font family for rendering text boxes. + * + * @returns {string} The font family used for rendering text boxes + */ + + +function getFontFamily() { + return textStyle.fontFamily; +} +/** + * Sets the font size in pixels that will be used for general font rendering. + * + * @param {number} fontSize Font size in pixels + * @returns {void} + */ + + +function setFontSize(fontSize) { + if (typeof fontSize !== 'number' || isNaN(fontSize) || !isFinite(fontSize)) { + throw new Error('Font size must be a valid number'); + } + + textStyle.fontSize = parseFloat(fontSize); +} +/** + * Returns the font size in pixels that will be used for general font rendering. + * + * @returns {number} Font size in pixels + */ + + +function getFontSize() { + return textStyle.fontSize; +} +/** + * Changes the background color of the text's bounding box. + * The default background color is transparent, that's why it doesn't display + * any background for the text box. + * + * @param {string} backgroundColor Background color for the text + * @returns {void} + */ + + +function setBackgroundColor(backgroundColor) { + textStyle.backgroundColor = backgroundColor; +} +/** + * Returns the background color that is being used for rendering text boxes. + * + * @returns {string} The background color for the text's bounding box + */ + + +function getBackgroundColor() { + return textStyle.backgroundColor; +} + +var textStyleApi = { + setFont: setFont, + getFont: getFont, + setFontSize: setFontSize, + getFontSize: getFontSize, + setFontFamily: setFontFamily, + getFontFamily: getFontFamily, + setBackgroundColor: setBackgroundColor, + getBackgroundColor: getBackgroundColor +}; +/* harmony default export */ __webpack_exports__["default"] = (textStyleApi); + +/***/ }), + +/***/ "./stateManagement/toolColors.js": +/*!***************************************!*\ + !*** ./stateManagement/toolColors.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var defaultColor = 'white', + activeColor = 'greenyellow', + fillColor = 'transparent'; + +function setFillColor(color) { + fillColor = color; +} + +function getFillColor() { + return fillColor; +} + +function setToolColor(color) { + defaultColor = color; +} + +function getToolColor() { + return defaultColor; +} + +function setActiveColor(color) { + activeColor = color; +} + +function getActiveColor() { + return activeColor; +} + +function getColorIfActive(data) { + if (data.color) { + return data.color; + } + + return data.active ? activeColor : defaultColor; +} + +var toolColors = { + setFillColor: setFillColor, + getFillColor: getFillColor, + setToolColor: setToolColor, + getToolColor: getToolColor, + setActiveColor: setActiveColor, + getActiveColor: getActiveColor, + getColorIfActive: getColorIfActive +}; +/* harmony default export */ __webpack_exports__["default"] = (toolColors); + +/***/ }), + +/***/ "./stateManagement/toolCoordinates.js": +/*!********************************************!*\ + !*** ./stateManagement/toolCoordinates.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var coordsData; + +function setCoords(eventData) { + coordsData = eventData.currentPoints.canvas; +} + +function getCoords() { + return coordsData; +} + +var toolCoordinates = { + setCoords: setCoords, + getCoords: getCoords +}; +/* harmony default export */ __webpack_exports__["default"] = (toolCoordinates); + +/***/ }), + +/***/ "./stateManagement/toolState.js": +/*!**************************************!*\ + !*** ./stateManagement/toolState.js ***! + \**************************************/ +/*! exports provided: addToolState, getToolState, removeToolState, clearToolState, setElementToolStateManager, getElementToolStateManager */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addToolState", function() { return addToolState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getToolState", function() { return getToolState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeToolState", function() { return removeToolState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clearToolState", function() { return clearToolState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setElementToolStateManager", function() { return setElementToolStateManager; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getElementToolStateManager", function() { return getElementToolStateManager; }); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./imageIdSpecificStateManager.js */ "./stateManagement/imageIdSpecificStateManager.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_uuidv4_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/uuidv4.js */ "./util/uuidv4.js"); + + + + + +/** + * Returns the toolstate for a specific element. + * @public + * @function getElementToolStateManager + * + * @param {HTMLElement} element The element. + * @returns {Object} The toolState. + */ + +function getElementToolStateManager(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); // If the enabledElement has no toolStateManager, create a default one for it + // NOTE: This makes state management element specific + + if (enabledElement.toolStateManager === undefined) { + enabledElement.toolStateManager = _imageIdSpecificStateManager_js__WEBPACK_IMPORTED_MODULE_2__["globalImageIdSpecificToolStateManager"]; + } + + return enabledElement.toolStateManager; +} +/** + * Adds tool state to the toolStateManager, this is done by tools as well + * as modules that restore saved state. + * @public + * @method addToolState + * + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool the state belongs to. + * @param {Object} measurementData The data to store in the state. + * @returns {undefined} + */ + + +function addToolState(element, toolName, measurementData) { + var toolStateManager = getElementToolStateManager(element); + measurementData.uuid = measurementData.uuid || Object(_util_uuidv4_js__WEBPACK_IMPORTED_MODULE_4__["default"])(); + toolStateManager.add(element, toolName, measurementData); + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_ADDED; + var eventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, eventType, eventData); +} +/** + * Returns tool specific state of an element. Used by tools as well as modules + * that save state persistently + * @export + * @public + * @method + * @name getToolState + * + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool the state belongs to. + * @returns {Object} The element's state for the given toolName. + */ + + +function getToolState(element, toolName) { + var toolStateManager = getElementToolStateManager(element); + return toolStateManager.get(element, toolName); +} +/** + * Removes specific tool state from the toolStateManager. + * @public + * @method removeToolState + * + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool the state belongs to. + * @param {Object} data The data to remove from the toolStateManager. + * @returns {undefined} + */ + + +function removeToolState(element, toolName, data) { + var toolStateManager = getElementToolStateManager(element); + var toolData = toolStateManager.get(element, toolName); + + if (!toolData || !toolData.data || !toolData.data.length) { + return; + } // Find this tool data + + + var indexOfData = -1; + + for (var i = 0; i < toolData.data.length; i++) { + if (toolData.data[i] === data) { + indexOfData = i; + } + } + + if (indexOfData !== -1) { + toolData.data.splice(indexOfData, 1); + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].MEASUREMENT_REMOVED; + var eventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: data + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_3__["default"])(element, eventType, eventData); + } +} +/** + * Removes all toolState from the toolStateManager corresponding to + * the toolName and element. + * @public + * @method clearToolState + * + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool the state belongs to. + * @returns {undefined} + */ + + +function clearToolState(element, toolName) { + var toolStateManager = getElementToolStateManager(element); + var toolData = toolStateManager.get(element, toolName); // If any toolData actually exists, clear it + + if (toolData !== undefined) { + toolData.data = []; + } +} +/** + * Sets the tool state manager for an element + * @public + * @method setElementToolStateManager + * + * @param {HTMLElement} element The element. + * @param {Object} toolStateManager The toolStateManager. + * @returns {undefined} + */ + + +function setElementToolStateManager(element, toolStateManager) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.getEnabledElement(element); + enabledElement.toolStateManager = toolStateManager; +} + + + +/***/ }), + +/***/ "./stateManagement/toolStyle.js": +/*!**************************************!*\ + !*** ./stateManagement/toolStyle.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var defaultWidth = 1, + activeWidth = 2; + +function setToolWidth(width) { + defaultWidth = width; +} + +function getToolWidth() { + return defaultWidth; +} + +function setActiveWidth(width) { + activeWidth = width; +} + +function getActiveWidth() { + return activeWidth; +} + +var toolStyle = { + setToolWidth: setToolWidth, + getToolWidth: getToolWidth, + setActiveWidth: setActiveWidth, + getActiveWidth: getActiveWidth +}; +/* harmony default export */ __webpack_exports__["default"] = (toolStyle); + +/***/ }), + +/***/ "./store/addTool.js": +/*!**************************!*\ + !*** ./store/addTool.js ***! + \**************************/ +/*! exports provided: addTool, addToolForElement */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addTool", function() { return addTool; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addToolForElement", function() { return addToolForElement; }); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); +/* harmony import */ var _getToolForElement_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getToolForElement.js */ "./store/getToolForElement.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_2__["getLogger"])('addTool'); +/** + * Adds a tool to an enabled element. + * + * @public + * @function addToolForElement + * @memberof CornerstoneTools + * + * @param {HTMLElement} element The element to add the tool to. + * @param {BaseTool} ApiTool The tool to add to the element. + * @param {Object} [props] Override the default tool props + * @returns {undefined} + */ + +var addToolForElement = function addToolForElement(element, ApiTool, props) { + // Instantiating the tool here makes it harder to accidentally add + // The same tool (by reference) for multiple elements (which would reassign the tool + // To a new element). + var tool = new ApiTool(props); + var toolAlreadyAddedToElement = Object(_getToolForElement_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, tool.name); + + if (toolAlreadyAddedToElement) { + logger.warn('%s has already been added to the target element', tool.name); + return; + } + + tool.element = element; + _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.tools.push(tool); +}; +/** + * Adds a tool to all enabled element. + * + * @public + * @function addTool + * @memberof CornerstoneTools + * + * @param {BaseTool} ApiTool The tool to add to each element. + * @param {Object} [props] Override the default tool configuration + * @returns {undefined} + */ + + +var addTool = function addTool(ApiTool, props) { + _addToolGlobally(ApiTool, props); + + _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.enabledElements.forEach(function (element) { + addToolForElement(element, ApiTool, props); + }); +}; +/** + * Adds tool with matching name from globally registered tools. + * Requires `globalToolSyncEnabled` to be set to true + * + * @private + * @function addToolGlobally + * + * @param {BaseTool} ApiTool + * @param {Object} [props] Override the default tool configuration + * @returns {undefined} + */ + + +var _addToolGlobally = function _addToolGlobally(ApiTool, props) { + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('globalConfiguration'), + configuration = _getModule.configuration; + + if (!configuration.globalToolSyncEnabled) { + return; + } + + var tool = new ApiTool(props); + var toolAlreadyAddedGlobally = _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.globalTools[tool.name] !== undefined; + + if (toolAlreadyAddedGlobally) { + logger.warn('%s has already been added globally', tool.name); + return; + } + + _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.globalTools[tool.name] = { + tool: ApiTool, + props: props, + activeBindings: [] + }; +}; + + + +/***/ }), + +/***/ "./store/filterToolsUsableWithMultiPartTools.js": +/*!******************************************************!*\ + !*** ./store/filterToolsUsableWithMultiPartTools.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../tools/base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _tools_base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../tools/base/BaseBrushTool.js */ "./tools/base/BaseBrushTool.js"); + + +/** + * Filters an array of tools, returning only tools which are active or passive. + * @export + * @public + * @method + * @name filterToolsUseableWithMultiPartTools + * + * @param {Object[]} tools The input tool array. + * @returns {Object[]} The filtered array. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (tools) { + return tools.filter(function (tool) { + return !tool.isMultiPartTool && !(tool instanceof _tools_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_0__["default"]) && !(tool instanceof _tools_base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_1__["default"]); + }); +}); + +/***/ }), + +/***/ "./store/getActiveToolsForElement.js": +/*!*******************************************!*\ + !*** ./store/getActiveToolsForElement.js ***! + \*******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Filters an array of tools, returning only tools which are active. + * @export + * @public + * @method + * @name getActiveToolsForElement + * + * @param {HTMLElement} element The element. + * @param {Object[]} tools The input tool array. + * @param {string} handlerType The input type being queried. + * @returns {Object[]} The filtered array. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (element, tools, handlerType) { + return tools.filter(function (tool) { + return tool.element === element && tool.mode === 'active' && (handlerType === undefined || tool.options["is".concat(handlerType, "Active")]); + }); +}); + +/***/ }), + +/***/ "./store/getInteractiveToolsForElement.js": +/*!************************************************!*\ + !*** ./store/getInteractiveToolsForElement.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Filters an array of tools, returning only tools which are active or passive. + * @export + * @public + * @method + * @name getInteractiveToolsForElement + * + * @param {HTMLElement} element The element. + * @param {Object[]} tools The input tool array. + * @returns {Object[]} The filtered array. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (element, tools) { + return tools.filter(function (tool) { + return tool.element === element && (tool.mode === 'active' || tool.mode === 'passive'); + }); +}); + +/***/ }), + +/***/ "./store/getToolForElement.js": +/*!************************************!*\ + !*** ./store/getToolForElement.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); + +/** + * Returns the tool instance attached to the element. + * @export + * @public + * @method + * @name getToolForElement + * + * @param {HTMLElement} element The element. + * @param {string} name The tool's name. + * @returns {Object} The tool instance. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, name) { + return _index_js__WEBPACK_IMPORTED_MODULE_0__["state"].tools.find(function (tool) { + return tool.element === element && tool.name === name; + }); +}); + +/***/ }), + +/***/ "./store/getToolsWithDataForElement.js": +/*!*********************************************!*\ + !*** ./store/getToolsWithDataForElement.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../stateManagement/toolState.js */ "./stateManagement/toolState.js"); + +/** + * Filters an array of tools, returning only tools which have annotation data. + * @export + * @public + * @method + * @name getToolsWithDataForElement + * + * @param {HTMLElement} element The element. + * @param {Object[]} tools The input tool array. + * @returns {Object[]} The filtered array. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, tools) { + return tools.filter(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__["getToolState"])(element, tool.name); + return toolState && toolState.data.length > 0; + }); +}); + +/***/ }), + +/***/ "./store/getToolsWithMoveableHandles.js": +/*!**********************************************!*\ + !*** ./store/getToolsWithMoveableHandles.js ***! + \**********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/getProximityThreshold.js */ "./util/getProximityThreshold.js"); + + + +/** + * Filters an array of tools, returning only tools with moveable handles at the + * mouse location. + * + * @public + * @function getToolsWithMoveableHandles + * + * @param {HTMLElement} element The element + * @param {Object[]} tools The input tool array. + * @param {Object} coords The coordinates of the mouse position. + * @param {string} [interactionType=mouse] + * @returns {Object[]} The filtered array. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, tools, coords) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + return tools.filter(function (tool) { + var distanceThreshold = Object(_util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_2__["default"])(interactionType, tool.name); + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__["getToolState"])(element, tool.name); + + for (var i = 0; i < toolState.data.length; i++) { + if (Object(_manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, toolState.data[i].handles, coords, distanceThreshold) !== undefined) { + return true; + } + } + + return false; + }); +}); + +/***/ }), + +/***/ "./store/index.js": +/*!************************!*\ + !*** ./store/index.js ***! + \************************/ +/*! exports provided: state, getters, modules, getModule, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "state", function() { return state; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getters", function() { return getters; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "modules", function() { return modules; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getModule", function() { return getModule; }); +/* harmony import */ var _modules_segmentationModule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/segmentationModule */ "./store/modules/segmentationModule/index.js"); +/* harmony import */ var _modules_manipulatorStateModule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/manipulatorStateModule */ "./store/modules/manipulatorStateModule.js"); +/* harmony import */ var _modules_cursorModule_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/cursorModule.js */ "./store/modules/cursorModule.js"); +/* harmony import */ var _modules_globalConfigurationModule_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./modules/globalConfigurationModule.js */ "./store/modules/globalConfigurationModule.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); +// Modules + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_5__["getLogger"])('store:modules:storeLogger'); +var state = { + // Global + globalTools: {}, + globalToolChangeHistory: [], + // Tracking + enabledElements: [], + tools: [], + isToolLocked: false, + activeMultiPartTool: null, + mousePositionImage: {}, + // Settings + clickProximity: 6, + touchProximity: 10, + handleRadius: 6, + deleteIfHandleOutsideImage: true, + preventHandleOutsideImage: false, + preventTextBoxOutsideDisplayedArea: false, + // Average pixel width of index finger is 45-57 pixels + // https://www.smashingmagazine.com/2012/02/finger-friendly-design-ideal-mobile-touchscreen-target-sizes/ + handleTouchOffset: { + x: 0, + y: -57 + }, + // Cursor + svgCursorUrl: null +}; +var getters = { + mouseTools: function mouseTools() { + return state.tools.filter(function (tool) { + return tool.supportedInteractionTypes.includes('Mouse'); + }); + }, + touchTools: function touchTools() { + return state.tools.filter(function (tool) { + return tool.supportedInteractionTypes.includes('Touch'); + }); + }, + enabledElementByUID: function enabledElementByUID(enabledElementUID) { + return state.enabledElements.find(function (element) { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_4__["default"].cornerstone.getEnabledElement(element).uuid === enabledElementUID; + }); + } +}; +var modules = { + segmentation: _modules_segmentationModule__WEBPACK_IMPORTED_MODULE_0__["default"], + cursor: _modules_cursorModule_js__WEBPACK_IMPORTED_MODULE_2__["default"], + globalConfiguration: _modules_globalConfigurationModule_js__WEBPACK_IMPORTED_MODULE_3__["default"], + manipulatorState: _modules_manipulatorStateModule__WEBPACK_IMPORTED_MODULE_1__["default"] +}; +function getModule(moduleName) { + return modules[moduleName]; +} +/* harmony default export */ __webpack_exports__["default"] = ({ + modules: modules, + state: state, + getters: getters +}); + +/***/ }), + +/***/ "./store/internals/addEnabledElement.js": +/*!**********************************************!*\ + !*** ./store/internals/addEnabledElement.js ***! + \**********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../eventListeners/index.js */ "./eventListeners/index.js"); +/* harmony import */ var _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../eventDispatchers/index.js */ "./eventDispatchers/index.js"); +/* harmony import */ var _addTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../addTool.js */ "./store/addTool.js"); +/* harmony import */ var _setToolMode_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../setToolMode.js */ "./store/setToolMode.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../index.js */ "./store/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_5__["getLogger"])('internals:addEnabledElement'); +/** + * Element Enabled event. + * + * @event Cornerstone#ElementEnabled + * @type {Object} + * @property {string} type + * @property {Object} detail + * @property {HTMLElement} detail.element - The element being enabled. + */ + +/* TODO: It would be nice if this automatically added "all tools" + * To the enabledElement that already exist on all other tools. + * A half-measure might be a new method to "duplicate" the tool + * Configuration for an existing enabled element + * We may need to also save/store the original class/constructor per tool + * To accomplish this + */ + +/** + * Adds an enabledElement to our store. + * @export + * @private + * @method + * @name addEnabledElement + * @param {Cornerstone#ElementEnabled} elementEnabledEvt + * @listens Cornerstone#ElementEnabled + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (elementEnabledEvt) { + logger.log('EVENT:ELEMENT_ENABLED'); + var enabledElement = elementEnabledEvt.detail.element; // Dispatchers + + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["imageRenderedEventDispatcher"].enable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["newImageEventDispatcher"].enable(enabledElement); + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_4__["getModule"])('globalConfiguration'), + configuration = _getModule.configuration; // Mouse + + + if (configuration.mouseEnabled) { + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["mouseEventListeners"].enable(enabledElement); + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["wheelEventListener"].enable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseToolEventDispatcher"].enable(enabledElement); + } // Touch + + + if (configuration.touchEnabled) { + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["touchEventListeners"].enable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchToolEventDispatcher"].enable(enabledElement); + } // State + + + _addEnabledElement(enabledElement); +}); +/** + * Adds the enabled element to the store. + * @private + * @method + * @param {HTMLElement} enabledElement + * @returns {void} + */ + +var _addEnabledElement = function _addEnabledElement(enabledElement) { + _index_js__WEBPACK_IMPORTED_MODULE_4__["default"].state.enabledElements.push(enabledElement); + + if (_index_js__WEBPACK_IMPORTED_MODULE_4__["default"].modules) { + _initModulesOnElement(enabledElement); + } + + _addGlobalToolsToElement(enabledElement); + + _repeatGlobalToolHistory(enabledElement); +}; +/** + * Iterate over our store's modules. If the module has an `enabledElementCallback` + * call it and pass it a reference to our enabled element. + * @private + * @method + * @param {Object} enabledElement + * @returns {void} + */ + + +function _initModulesOnElement(enabledElement) { + var modules = _index_js__WEBPACK_IMPORTED_MODULE_4__["default"].modules; + Object.keys(modules).forEach(function (key) { + if (typeof modules[key].enabledElementCallback === 'function') { + modules[key].enabledElementCallback(enabledElement); + } + }); +} +/** + * Iterate over our stores globalTools adding each one to `enabledElement` + * @private + * @method + * @param {HTMLElement} enabledElement + * @returns {void} + */ + + +function _addGlobalToolsToElement(enabledElement) { + var _getModule2 = Object(_index_js__WEBPACK_IMPORTED_MODULE_4__["getModule"])('globalConfiguration'), + configuration = _getModule2.configuration; + + if (!configuration.globalToolSyncEnabled) { + return; + } + + Object.keys(_index_js__WEBPACK_IMPORTED_MODULE_4__["default"].state.globalTools).forEach(function (key) { + var _store$state$globalTo = _index_js__WEBPACK_IMPORTED_MODULE_4__["default"].state.globalTools[key], + tool = _store$state$globalTo.tool, + props = _store$state$globalTo.props; + Object(_addTool_js__WEBPACK_IMPORTED_MODULE_2__["addToolForElement"])(enabledElement, tool, props); + }); +} +/** + * Iterate over the globalToolChangeHistory and apply each `historyEvent` + * to the supplied `enabledElement`. + * @private + * @method + * @param {HTMLElement} enabledElement + * @returns {void} + */ + + +function _repeatGlobalToolHistory(enabledElement) { + var _getModule3 = Object(_index_js__WEBPACK_IMPORTED_MODULE_4__["getModule"])('globalConfiguration'), + configuration = _getModule3.configuration; + + if (!configuration.globalToolSyncEnabled) { + return; + } + + var setToolModeFns = { + active: _setToolMode_js__WEBPACK_IMPORTED_MODULE_3__["setToolActiveForElement"], + passive: _setToolMode_js__WEBPACK_IMPORTED_MODULE_3__["setToolPassiveForElement"], + enabled: _setToolMode_js__WEBPACK_IMPORTED_MODULE_3__["setToolEnabledForElement"], + disabled: _setToolMode_js__WEBPACK_IMPORTED_MODULE_3__["setToolDisabledForElement"] + }; + _index_js__WEBPACK_IMPORTED_MODULE_4__["default"].state.globalToolChangeHistory.forEach(function (historyEvent) { + var args = historyEvent.args.slice(0); + args.unshift(enabledElement); + setToolModeFns[historyEvent.mode].apply(null, args); + }); +} + +/***/ }), + +/***/ "./store/internals/removeEnabledElement.js": +/*!*************************************************!*\ + !*** ./store/internals/removeEnabledElement.js ***! + \*************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../eventListeners/index.js */ "./eventListeners/index.js"); +/* harmony import */ var _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../eventDispatchers/index.js */ "./eventDispatchers/index.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../index.js */ "./store/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _setToolMode__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../setToolMode */ "./store/setToolMode.js"); + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('internals:removeEnabledElement'); +/** + * Element Disabled event. + * + * @event Cornerstone#ElementDisabled + * @type {Object} + * @property {string} type + * @property {Object} detail + * @property {HTMLElement} detail.element - The element being disabled. + */ + +/** + * Removes an enabledElement from our store, and all associated tools that were added to it. + * @export + * @private + * @method + * @name removeEnabledElement + * @param {Cornerstone#ElementDisabled} elementDisabledEvt + * @listens Cornerstone#ElementDisabled + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (elementDisabledEvt) { + logger.log('EVENT:ELEMENT_DISABLED'); + var enabledElement = elementDisabledEvt.detail.element; + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_2__["getModule"])('globalConfiguration'), + configuration = _getModule.configuration; // Dispatchers + + + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["imageRenderedEventDispatcher"].disable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["newImageEventDispatcher"].disable(enabledElement); // Mouse + + if (configuration.mouseEnabled) { + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["mouseEventListeners"].disable(enabledElement); + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["wheelEventListener"].disable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["mouseToolEventDispatcher"].disable(enabledElement); + } // Touch + + + if (configuration.touchEnabled) { + _eventListeners_index_js__WEBPACK_IMPORTED_MODULE_0__["touchEventListeners"].disable(enabledElement); + _eventDispatchers_index_js__WEBPACK_IMPORTED_MODULE_1__["touchToolEventDispatcher"].disable(enabledElement); + } // State + + + _removeAllToolsForElement(enabledElement); + + _removeEnabledElement(enabledElement); + + _removeLoadHandlers(enabledElement); +}); +/** + * Remove all tools associated with enabled element. + * @private + * @method + * @param {HTMLElement} enabledElement + * @returns {void} + */ + +var _removeAllToolsForElement = function _removeAllToolsForElement(enabledElement) { + _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].state.tools.forEach(function (tool) { + if (tool.element === enabledElement) { + Object(_setToolMode__WEBPACK_IMPORTED_MODULE_5__["setToolDisabledForElement"])(tool.element, tool.name); + } + }); + _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].state.tools = _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].state.tools.filter(function (tool) { + return tool.element !== enabledElement; + }); +}; +/** + * Remove the enabled element from the store if it exists. + * @private + * @method + * @param {HTMLElement} enabledElement + * @returns {void} + */ + + +var _removeEnabledElement = function _removeEnabledElement(enabledElement) { + if (_index_js__WEBPACK_IMPORTED_MODULE_2__["default"].modules) { + _cleanModulesOnElement(enabledElement); + } + + var foundElementIndex = _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].state.enabledElements.findIndex(function (element) { + return element === enabledElement; + }); + + if (foundElementIndex > -1) { + _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].state.enabledElements.splice(foundElementIndex, 1); + } else { + logger.warn('unable to remove element'); + } +}; +/** + * Remove load handler for the element + * @private + * @method + * @param {HTMLElement} element + * @returns {void} + */ + + +var _removeLoadHandlers = function _removeLoadHandlers(element) { + _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_4__["default"].removeHandlers(element); +}; +/** + * Iterate over our store's modules. If the module has a + * `removeEnabledElementCallback` call it and clean up unneeded metadata. + * @private + * @method + * @param {Object} enabledElement + * @returns {void} + */ + + +function _cleanModulesOnElement(enabledElement) { + var modules = _index_js__WEBPACK_IMPORTED_MODULE_2__["default"].modules; + Object.keys(modules).forEach(function (key) { + if (typeof modules[key].removeEnabledElementCallback === 'function') { + modules[key].removeEnabledElementCallback(enabledElement); + } + }); +} + +/***/ }), + +/***/ "./store/isToolActiveForElement.js": +/*!*****************************************!*\ + !*** ./store/isToolActiveForElement.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _getToolForElement_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getToolForElement.js */ "./store/getToolForElement.js"); + +/** + * Queries if a tool is active on the specified element. + * @export + * @public + * @method + * @name isToolActiveForElement + * + * @param {HTMLElement} element The element being queried. + * @param {string} name The name of the tool. + * @returns {boolean} True if the tool is active. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, name) { + var tool = Object(_getToolForElement_js__WEBPACK_IMPORTED_MODULE_0__["default"])(element, name); + return tool.mode === 'active'; +}); + +/***/ }), + +/***/ "./store/modules/cursorModule.js": +/*!***************************************!*\ + !*** ./store/modules/cursorModule.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); + +var configuration = { + iconSize: 16, + viewBox: { + x: 16, + y: 16 + }, + mousePoint: { + x: 8, + y: 8 + }, + mousePointerGroupString: "\n \n \n " +}; +var setters = { + defaultOptions: function defaultOptions(newOptions) { + Object.assign(configuration, newOptions); + } +}; +var getters = { + defaultOptions: function defaultOptions() { + return configuration; + } +}; +/* harmony default export */ __webpack_exports__["default"] = ({ + configuration: configuration, + getters: getters, + setters: setters +}); + +/***/ }), + +/***/ "./store/modules/globalConfigurationModule.js": +/*!****************************************************!*\ + !*** ./store/modules/globalConfigurationModule.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var configuration = { + mouseEnabled: true, + touchEnabled: true, + globalToolSyncEnabled: false, + showSVGCursors: false, + autoResizeViewports: true, + lineDash: [4, 4] +}; +/* harmony default export */ __webpack_exports__["default"] = ({ + configuration: configuration +}); + +/***/ }), + +/***/ "./store/modules/manipulatorStateModule.js": +/*!*************************************************!*\ + !*** ./store/modules/manipulatorStateModule.js ***! + \*************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); + +var state = { + activeManipulators: {} +}; + +function addActiveManipulatorForElement(element, cancelFn) { + var enabledElement = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + var enabledElementUUID = enabledElement.uuid; + state.activeManipulators[enabledElementUUID] = cancelFn; +} + +function removeActiveManipulatorForElement(element) { + var enabledElement = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + var enabledElementUUID = enabledElement.uuid; + var activeManipulators = state.activeManipulators; + delete activeManipulators[enabledElementUUID]; +} + +function cancelActiveManipulatorsForElement(element) { + var enabledElement = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + var enabledElementUUID = enabledElement.uuid; + + _cancelActiveManipulatorsForElementUUID(enabledElementUUID); +} + +function _cancelActiveManipulatorsForElementUUID(enabledElementUUID) { + var activeManipulators = state.activeManipulators; + var cancelFn = activeManipulators[enabledElementUUID]; + + if (typeof cancelFn === 'function') { + cancelFn(); + } + + delete activeManipulators[enabledElementUUID]; +} + +function cancelActiveManipulators() { + var activeManipulators = state.activeManipulators; + Object.keys(activeManipulators).forEach(function (enabledElementUUID) { + return _cancelActiveManipulatorsForElementUUID(enabledElementUUID); + }); +} + +function _cornerstoneNewImageHandler(evt) { + var eventData = evt.detail; + var element = eventData.element; + removeActiveManipulatorForElement(element); +} + +function removeEnabledElementCallback(element) { + var NEW_IMAGE = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.NEW_IMAGE; + element.removeEventListener(NEW_IMAGE, _cornerstoneNewImageHandler); + removeActiveManipulatorForElement(element); +} + +function enabledElementCallback(element) { + var NEW_IMAGE = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.NEW_IMAGE; + element.removeEventListener(NEW_IMAGE, _cornerstoneNewImageHandler); + element.addEventListener(NEW_IMAGE, _cornerstoneNewImageHandler); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + setters: { + // Add/remove + addActiveManipulatorForElement: addActiveManipulatorForElement, + removeActiveManipulatorForElement: removeActiveManipulatorForElement, + // Cancel + cancelActiveManipulatorsForElement: cancelActiveManipulatorsForElement, + cancelActiveManipulators: cancelActiveManipulators + }, + state: state, + enabledElementCallback: enabledElementCallback, + removeEnabledElementCallback: removeEnabledElementCallback +}); + +/***/ }), + +/***/ "./store/modules/segmentationModule/activeLabelmapIndex.js": +/*!*****************************************************************!*\ + !*** ./store/modules/segmentationModule/activeLabelmapIndex.js ***! + \*****************************************************************/ +/*! exports provided: getActiveLabelmapIndex, setActiveLabelmapIndex */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getActiveLabelmapIndex", function() { return getActiveLabelmapIndex; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setActiveLabelmapIndex", function() { return setActiveLabelmapIndex; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _addLabelmap3D__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./addLabelmap3D */ "./store/modules/segmentationModule/addLabelmap3D.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); + + + + + +/** + * Returns the index of the active `Labelmap3D`. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone + * enabled element or its UUID. + * @returns {number} The index of the active `Labelmap3D`. + */ + +function getActiveLabelmapIndex(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_3__["default"].series[firstImageId]; + + if (!brushStackState) { + return; + } + + return brushStackState.activeLabelmapIndex; +} +/** + * Sets the active `labelmapIndex` for the `BrushStackState` displayed on this + * element. Creates the corresponding `Labelmap3D` if it doesn't exist. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} labelmapIndex = 0 The index of the labelmap. + * @returns {null} + */ + + +function setActiveLabelmapIndex(elementOrEnabledElementUID) { + var labelmapIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_4__["default"].cornerstone; + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var enabledElement = cornerstone.getEnabledElement(element); + var _enabledElement$image = enabledElement.image, + rows = _enabledElement$image.rows, + columns = _enabledElement$image.columns; + var numberOfFrames = stackData.imageIds.length; + var size = rows * columns * numberOfFrames; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_3__["default"].series[firstImageId]; + + if (brushStackState) { + brushStackState.activeLabelmapIndex = labelmapIndex; + + if (!brushStackState.labelmaps3D[labelmapIndex]) { + Object(_addLabelmap3D__WEBPACK_IMPORTED_MODULE_2__["default"])(brushStackState, labelmapIndex, size); + } + } else { + _state__WEBPACK_IMPORTED_MODULE_3__["default"].series[firstImageId] = { + activeLabelmapIndex: labelmapIndex, + labelmaps3D: [] + }; + brushStackState = _state__WEBPACK_IMPORTED_MODULE_3__["default"].series[firstImageId]; + Object(_addLabelmap3D__WEBPACK_IMPORTED_MODULE_2__["default"])(brushStackState, labelmapIndex, size); + } + + cornerstone.updateImage(element); +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/activeSegmentIndex.js": +/*!****************************************************************!*\ + !*** ./store/modules/segmentationModule/activeSegmentIndex.js ***! + \****************************************************************/ +/*! exports provided: getActiveSegmentIndex, setActiveSegmentIndex, incrementActiveSegmentIndex, decrementActiveSegmentIndex */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getActiveSegmentIndex", function() { return getActiveSegmentIndex; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setActiveSegmentIndex", function() { return setActiveSegmentIndex; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "incrementActiveSegmentIndex", function() { return incrementActiveSegmentIndex; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "decrementActiveSegmentIndex", function() { return decrementActiveSegmentIndex; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + + + +/** + * Returns the `activeSegmentIndex` for the active `Labelmap3D` for the `BrushStackState` displayed on the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} [labelmapIndex] The labelmap index, defaults to the active labelmap index. + * @returns {number} The active segment index. + */ + +function getActiveSegmentIndex(elementOrEnabledElementUID, labelmapIndex) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (brushStackState) { + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + + if (labelmap3D) { + return labelmap3D.activeSegmentIndex; + } + } + + return 1; +} +/** + * Sets the `activeSegmentIndex` for the active `Labelmap3D` on the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} segmentIndex The segmentIndex to set active. + * @returns {null} + */ + + +function setActiveSegmentIndex(elementOrEnabledElementUID, segmentIndex) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + return; + } + + var activeLabelmapIndex = brushStackState.activeLabelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[activeLabelmapIndex]; + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_3__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + if (segmentIndex <= 0) { + segmentIndex = 1; + } else if (segmentIndex > configuration.segmentsPerLabelmap) { + segmentIndex = configuration.segmentsPerLabelmap; + } + + labelmap3D.activeSegmentIndex = segmentIndex; +} +/** + * Increment the `activeSegmentIndex` for the active `Labelmap3D` on the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @returns {null} + */ + + +function incrementActiveSegmentIndex(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + _changeActiveSegmentIndex(element, 'increase'); +} +/** + * Decrement the `activeSegmentIndex` for the active `Labelmap3D` on the element. + * + * @param {HTMLElement} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @returns {null} + */ + + +function decrementActiveSegmentIndex(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + _changeActiveSegmentIndex(element, 'decrease'); +} +/** + * Changes the `activeSegmentIndex` for the active `Labelmap3D` on the element. + * + * @param {HTMLElement} element The cornerstone enabled element. + * @param {string} increaseOrDecrease = Whether to increase/decrease the activeLabelmapIndex. + * @returns {null} + */ + + +function _changeActiveSegmentIndex(element) { + var increaseOrDecrease = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'increase'; + + var _getModule2 = Object(_index_js__WEBPACK_IMPORTED_MODULE_3__["getModule"])('segmentation'), + configuration = _getModule2.configuration; + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + return; + } + + var activeLabelmapIndex = brushStackState.activeLabelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[activeLabelmapIndex]; + + switch (increaseOrDecrease) { + case 'increase': + labelmap3D.activeSegmentIndex++; + + if (labelmap3D.activeSegmentIndex > configuration.segmentsPerLabelmap) { + labelmap3D.activeSegmentIndex = 1; + } + + break; + + case 'decrease': + labelmap3D.activeSegmentIndex--; + + if (labelmap3D.activeSegmentIndex <= 0) { + labelmap3D.activeSegmentIndex = configuration.segmentsPerLabelmap; + } + + break; + } +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/addLabelmap2D.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/addLabelmap2D.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return addLabelmap2D; }); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_0__["default"].UINT_16_ARRAY, + FLOAT_32_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_0__["default"].FLOAT_32_ARRAY; +/** + * Adds a `Labelmap2D` view of one frame of a `Labelmap3D`. + * + * @param {BrushStackState} brushStackState The `BrushStackState` for a particular `Series`. + * @param {number} labelmapIndex The labelmap index. + * @param {number} imageIdIndex The stack position of the image. + * @param {number} rows The number of rows in the image. + * @param {number} columns The number of columns in the image. + * @returns {null} + */ + +function addLabelmap2D(brushStackState, labelmapIndex, imageIdIndex, rows, columns) { + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_1__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var sliceLength = rows * columns; + var elementOffset = sliceLength * imageIdIndex; + var pixelData; + + switch (configuration.arrayType) { + case UINT_16_ARRAY: + pixelData = new Uint16Array(brushStackState.labelmaps3D[labelmapIndex].buffer, elementOffset * 2, // 2 bytes/voxel + sliceLength); + break; + + case FLOAT_32_ARRAY: + pixelData = new Float32Array(brushStackState.labelmaps3D[labelmapIndex].buffer, elementOffset * 4, // 4 bytes/voxel + sliceLength); + break; + + default: + throw new Error("Unsupported Array Type ".concat(configuration.arrayType)); + } + + brushStackState.labelmaps3D[labelmapIndex].labelmaps2D[imageIdIndex] = { + pixelData: pixelData, + segmentsOnLabelmap: [] + }; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/addLabelmap3D.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/addLabelmap3D.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return addLabelmap3D; }); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_0__["default"].UINT_16_ARRAY, + FLOAT_32_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_0__["default"].FLOAT_32_ARRAY; +/** + * AddLabelmap3D - Adds a `Labelmap3D` object to the `BrushStackState` object. + * + * @param {BrushStackState} brushStackState The labelmap state for a particular stack. + * @param {number} labelmapIndex The labelmapIndex to set. + * @param {number} size The size of the ArrayBuffer in bytes/ 2. + * @returns {null} + */ + +function addLabelmap3D(brushStackState, labelmapIndex, size) { + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_1__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var bytesPerVoxel; + + switch (configuration.arrayType) { + case UINT_16_ARRAY: + bytesPerVoxel = 2; + break; + + case FLOAT_32_ARRAY: + bytesPerVoxel = 4; + break; + + default: + throw new Error("Unsupported Array Type ".concat(configuration.arrayType)); + } // Buffer size is multiplied by bytesPerVoxel to allocate enough space. + + + brushStackState.labelmaps3D[labelmapIndex] = { + buffer: new ArrayBuffer(size * bytesPerVoxel), + labelmaps2D: [], + metadata: [], + activeSegmentIndex: 1, + colorLUTIndex: 0, + segmentsHidden: [], + undo: [], + redo: [] + }; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/arrayTypes.js": +/*!********************************************************!*\ + !*** ./store/modules/segmentationModule/arrayTypes.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var ARRAY_TYPES = { + UINT_16_ARRAY: 0, + FLOAT_32_ARRAY: 1 +}; +/* harmony default export */ __webpack_exports__["default"] = (ARRAY_TYPES); + +/***/ }), + +/***/ "./store/modules/segmentationModule/colorLUT.js": +/*!******************************************************!*\ + !*** ./store/modules/segmentationModule/colorLUT.js ***! + \******************************************************/ +/*! exports provided: default, setColorLUTIndexForLabelmap3D, getColorForSegmentIndexColorLUT, setColorForSegmentIndexOfColorLUT, getColorLUT */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return setColorLUT; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setColorLUTIndexForLabelmap3D", function() { return setColorLUTIndexForLabelmap3D; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getColorForSegmentIndexColorLUT", function() { return getColorForSegmentIndexColorLUT; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setColorForSegmentIndexOfColorLUT", function() { return setColorForSegmentIndexOfColorLUT; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getColorLUT", function() { return getColorLUT; }); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_1__["getLogger"])('store:modules:segmentationModule:setColorLUT'); +/** + * SetColorLUT - Sets the labelmap to a specfic LUT, or generates a new LUT. + * + * @param {number} labelmapIndex The labelmap index to apply the color LUT to. + * @param {number[][]} [colorLUT] An array of The colorLUT to set. + * @returns {null} + */ + +function setColorLUT(colorLUTIndex) { + var colorLUT = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_3__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var segmentsPerLabelmap = configuration.segmentsPerLabelmap; + + if (colorLUT) { + _checkColorLUTLength(colorLUT, segmentsPerLabelmap); + + if (colorLUT.length < segmentsPerLabelmap) { + colorLUT = [].concat(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(colorLUT), _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(_generateNewColorLUT(segmentsPerLabelmap - colorLUT.length))); + } + } else { + // Autogenerate colorLUT. + colorLUT = colorLUT || _generateNewColorLUT(segmentsPerLabelmap); + } // Apppend the "zero" (no label) color to the front of the LUT. + + + colorLUT.unshift([0, 0, 0, 0]); + _state__WEBPACK_IMPORTED_MODULE_2__["default"].colorLutTables[colorLUTIndex] = colorLUT; +} +function setColorLUTIndexForLabelmap3D(labelmap3D, colorLUTIndex) { + labelmap3D.colorLUTIndex = colorLUTIndex; +} +function getColorForSegmentIndexColorLUT(labelmap3DOrColorLUTIndex, segmentIndex) { + var colorLUT = getColorLUT(labelmap3DOrColorLUTIndex); + return colorLUT[segmentIndex]; +} +/** + * Sets a single color of a colorLUT. + * + * @param {Object|number} labelmap3DOrColorLUTIndex Either a `Labelmap3D` object (who's referenced colorLUT will be changed), or a colorLUTIndex. + * @param {number} segmentIndex The segmentIndex color to change. + * @param {number[]} colorArray The color values in RGBA array format (required length 4). + */ + +function setColorForSegmentIndexOfColorLUT(labelmap3DOrColorLUTIndex, segmentIndex, colorArray) { + var colorLUT = getColorLUT(labelmap3DOrColorLUTIndex); + colorLUT[segmentIndex] = colorArray; +} +function getColorLUT(labelmap3DOrColorLUTIndex) { + if (typeof labelmap3DOrColorLUTIndex === 'number') { + return _state__WEBPACK_IMPORTED_MODULE_2__["default"].colorLutTables[labelmap3DOrColorLUTIndex]; + } + + return _state__WEBPACK_IMPORTED_MODULE_2__["default"].colorLutTables[labelmap3DOrColorLUTIndex.colorLUTIndex]; +} +/** + * Checks the length of `colorLUT` compared to `segmnetsPerLabelmap` and flags up any warnings. + * @param {number[][]} colorLUT + * @param {number} segmentsPerLabelmap + * @returns {boolean} Whether the length is valid. + */ + +function _checkColorLUTLength(colorLUT, segmentsPerLabelmap) { + if (colorLUT.length < segmentsPerLabelmap) { + logger.warn("The provided colorLUT only provides ".concat(colorLUT.length, " labels, whereas segmentsPerLabelmap is set to ").concat(segmentsPerLabelmap, ". Autogenerating the rest.")); + } else if (colorLUT.length > segmentsPerLabelmap) { + logger.warn("segmentsPerLabelmap is set to ".concat(segmentsPerLabelmap, ", and the provided colorLUT provides ").concat(colorLUT.length, ". Using the first ").concat(segmentsPerLabelmap, " colors from the LUT.")); + } +} +/** + * Generates a new color LUT (Look Up Table) of length `numberOfColors`, + * which returns an RGBA color for each segment index. + * + * @param {Number} numberOfColors = 255 The number of colors to generate + * @returns {Number[][]} The array of RGB values. + */ + + +function _generateNewColorLUT() { + var numberOfColors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 255; + var rgbArr = []; + + for (var i = 0; i < numberOfColors; i++) { + rgbArr.push(getRGBAfromHSLA(getNextHue(), getNextL())); + } + + return rgbArr; +} + +var goldenAngle = 137.5; +var hueValue = 222.5; + +function getNextHue() { + hueValue += goldenAngle; + + if (hueValue >= 360) { + hueValue -= 360; + } + + return hueValue; +} + +var l = 0.6; +var maxL = 0.82; +var minL = 0.3; +var incL = 0.07; + +function getNextL() { + l += incL; + + if (l > maxL) { + var diff = l - maxL; + l = minL + diff; + } + + return l; +} +/** + * GetRGBAfromHSL - Returns an RGBA color given H, S, L and A. + * + * @param {Number} hue The hue. + * @param {Number} s = 1 The saturation. + * @param {Number} l = 0.6 The lightness. + * @param {Number} alpha = 255 The alpha. + * @returns {Number[]} The RGBA formatted color. + */ + + +function getRGBAfromHSLA(hue) { + var s = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var l = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.6; + var alpha = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 255; + var c = (1 - Math.abs(2 * l - 1)) * s; + var x = c * (1 - Math.abs(hue / 60 % 2 - 1)); + var m = l - c / 2; + var r, g, b; + + if (hue < 60) { + r = c; + g = x; + b = 0; + } else if (hue < 120) { + r = x; + g = c; + b = 0; + } else if (hue < 180) { + r = 0; + g = c; + b = x; + } else if (hue < 240) { + r = 0; + g = x; + b = c; + } else if (hue < 300) { + r = x; + g = 0; + b = c; + } else if (hue < 360) { + r = c; + g = 0; + b = x; + } + + return [(r + m) * 255, (g + m) * 255, (b + m) * 255, alpha]; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/defaultConfiguration.js": +/*!******************************************************************!*\ + !*** ./store/modules/segmentationModule/defaultConfiguration.js ***! + \******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_0__["default"].UINT_16_ARRAY; // Segmentation module configuration. + +var defaultConfiguration = { + renderOutline: true, + renderFill: true, + shouldRenderInactiveLabelmaps: true, + radius: 10, + minRadius: 1, + maxRadius: 50, + fillAlpha: 0.2, + fillAlphaInactive: 0.1, + outlineAlpha: 0.7, + outlineAlphaInactive: 0.35, + outlineWidth: 3, + storeHistory: true, + segmentsPerLabelmap: 65535, + // Max is 65535 due to using 16-bit Unsigned ints. + arrayType: UINT_16_ARRAY +}; +/* harmony default export */ __webpack_exports__["default"] = (defaultConfiguration); + +/***/ }), + +/***/ "./store/modules/segmentationModule/deleteSegment.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/deleteSegment.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return deleteSegment; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); + + + + +/** + * Deletes the segment and any associated metadata from the `Labelmap3D`. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled element or its UUID. + * @param {number} segmentIndex The segment Index + * @param {number} [labelmapIndex] The labelmap index. Defaults to the active labelmap index. + * + * @returns {null} + */ + +function deleteSegment(elementOrEnabledElementUID, segmentIndex, labelmapIndex) { + if (!segmentIndex) { + return; + } + + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + return; + } + + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + + if (!labelmap3D) { + return; + } // Delete metadata if present. + + + delete labelmap3D.metadata[segmentIndex]; + var labelmaps2D = labelmap3D.labelmaps2D; // Clear segment's voxels. + + for (var i = 0; i < labelmaps2D.length; i++) { + var labelmap2D = labelmaps2D[i]; // If the labelmap2D has data, and it contains the segment, delete it. + + if (labelmap2D && labelmap2D.segmentsOnLabelmap.includes(segmentIndex)) { + var pixelData = labelmap2D.pixelData; // Remove this segment from the list. + + var indexOfSegment = labelmap2D.segmentsOnLabelmap.indexOf(segmentIndex); + labelmap2D.segmentsOnLabelmap.splice(indexOfSegment, 1); // Delete the label for this segment. + + for (var p = 0; p < pixelData.length; p++) { + if (pixelData[p] === segmentIndex) { + pixelData[p] = 0; + } + } + } + } + + _externalModules__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.updateImage(element); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getBrushColor.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/getBrushColor.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getBrushColor; }); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('store:modules:segmentationModule:getBrushColor'); +/** + * Returns the brush color as a rgba CSS color for the active segment of the active + * `Labelmap3D` for the `BrushStackState` displayed on the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {boolean} drawing = false Whether the user is drawing or not. + * @returns {string} An rgba value as a string. + */ + +function getBrushColor(elementOrEnabledElementUID) { + var drawing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_2__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__["getToolState"])(element, 'stack'); + + if (!stackState) { + logger.error('Consumers must define stacks in their application if using segmentations in cornerstoneTools.'); + return; + } + + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_1__["default"].series[firstImageId]; + var color; + + if (brushStackState) { + var activeLabelmapIndex = brushStackState.activeLabelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[activeLabelmapIndex]; + var activeSegmentIndex = labelmap3D.activeSegmentIndex; + color = _state__WEBPACK_IMPORTED_MODULE_1__["default"].colorLutTables[labelmap3D.colorLUTIndex][activeSegmentIndex]; + } else { + // No data yet, make brush the default color of colormap 0. + color = _state__WEBPACK_IMPORTED_MODULE_1__["default"].colorLutTables[0][1]; + } + + return drawing ? "rgba(".concat(color[0], ", ").concat(color[1], ", ").concat(color[2], ", 1.0 )") : "rgba(".concat(color[0], ", ").concat(color[1], ", ").concat(color[2], ", 0.8 )"); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getElement.js": +/*!********************************************************!*\ + !*** ./store/modules/segmentationModule/getElement.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _getElement; }); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + +/** + * Returns the cornerstone enabled element given either the element or its enabledElement UUID. + * + * @param {string|HTMLElement} elementOrEnabledElementUID The enabledElement + * or its UUID. + * @returns {HTMLElement} + */ + +function _getElement(elementOrEnabledElementUID) { + if (elementOrEnabledElementUID instanceof HTMLElement) { + return elementOrEnabledElementUID; + } + + return _index_js__WEBPACK_IMPORTED_MODULE_0__["getters"].enabledElementByUID(elementOrEnabledElementUID); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getLabelmap2D.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/getLabelmap2D.js ***! + \***********************************************************/ +/*! exports provided: default, getLabelmap2DByImageIdIndex */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getLabelmap2D; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLabelmap2DByImageIdIndex", function() { return getLabelmap2DByImageIdIndex; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getSegmentsOnPixeldata */ "./store/modules/segmentationModule/getSegmentsOnPixeldata.js"); +/* harmony import */ var _addLabelmap3D__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./addLabelmap3D */ "./store/modules/segmentationModule/addLabelmap3D.js"); +/* harmony import */ var _addLabelmap2D__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./addLabelmap2D */ "./store/modules/segmentationModule/addLabelmap2D.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + + + + + + + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_7__["default"].UINT_16_ARRAY, + FLOAT_32_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_7__["default"].FLOAT_32_ARRAY; +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_9__["getLogger"])('store:modules:segmentationModule:getLabelmap2D'); +/** + * Returns the active `labelmap3D` and the `currentImageIdIndex`. If a labelmap does + * not get exist, creates a new one. Generates a `labelmap2D` for the `currentImageIndex` + * if it does not yet exist. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @returns {Object} The `Labelmap2D`, `Labelmap3D`, `activeLabelmapIndex` and `currentImageIdIndex`. + */ + +function getLabelmap2D(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone; + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + + if (!stackState) { + logger.error('Consumers must define stacks in their application if using segmentations in cornerstoneTools.'); + return; + } + + var stackData = stackState.data[0]; + var enabledElement = cornerstone.getEnabledElement(element); + var currentImageIdIndex = stackData.currentImageIdIndex; + var _enabledElement$image = enabledElement.image, + rows = _enabledElement$image.rows, + columns = _enabledElement$image.columns; + var numberOfFrames = stackData.imageIds.length; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_6__["default"].series[firstImageId]; + var activeLabelmapIndex; + + if (brushStackState) { + activeLabelmapIndex = brushStackState.activeLabelmapIndex; + + if (!brushStackState.labelmaps3D[activeLabelmapIndex]) { + var size = rows * columns * numberOfFrames; + Object(_addLabelmap3D__WEBPACK_IMPORTED_MODULE_3__["default"])(brushStackState, activeLabelmapIndex, size); + } + + if (!brushStackState.labelmaps3D[activeLabelmapIndex].labelmaps2D[currentImageIdIndex]) { + Object(_addLabelmap2D__WEBPACK_IMPORTED_MODULE_4__["default"])(brushStackState, activeLabelmapIndex, currentImageIdIndex, rows, columns); + } + } else { + activeLabelmapIndex = 0; + _state__WEBPACK_IMPORTED_MODULE_6__["default"].series[firstImageId] = { + activeLabelmapIndex: activeLabelmapIndex, + labelmaps3D: [] + }; + brushStackState = _state__WEBPACK_IMPORTED_MODULE_6__["default"].series[firstImageId]; + + var _size = rows * columns * numberOfFrames; + + Object(_addLabelmap3D__WEBPACK_IMPORTED_MODULE_3__["default"])(brushStackState, activeLabelmapIndex, _size); + Object(_addLabelmap2D__WEBPACK_IMPORTED_MODULE_4__["default"])(brushStackState, activeLabelmapIndex, currentImageIdIndex, rows, columns); + } + + var labelmap3D = brushStackState.labelmaps3D[activeLabelmapIndex]; + return { + labelmap2D: labelmap3D.labelmaps2D[currentImageIdIndex], + labelmap3D: labelmap3D, + currentImageIdIndex: currentImageIdIndex, + activeLabelmapIndex: activeLabelmapIndex + }; +} +/** + * Returns a `Labelmap2D` view of a `Labelmap3D` for the given `imageIdIndex`. + * Creates and caches it if it doesn't yet exist. + * + * @param {Labelmap3D} labelmap3D The `Labelmap3D` object. + * @param {number} imageIdIndex The imageId Index. + * @param {number} rows The number of rows. + * @param {number} columns The number of columns. + * @returns {null} + */ + +function getLabelmap2DByImageIdIndex(labelmap3D, imageIdIndex, rows, columns) { + if (!labelmap3D.labelmaps2D[imageIdIndex]) { + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_8__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var sliceLength = rows * columns; + var elementOffset = sliceLength * imageIdIndex; + var pixelData; + + switch (configuration.arrayType) { + case UINT_16_ARRAY: + pixelData = new Uint16Array(labelmap3D.buffer, elementOffset * 2, // 2 bytes/voxel + sliceLength); + break; + + case FLOAT_32_ARRAY: + pixelData = new Float32Array(labelmap3D.buffer, elementOffset * 4, // 4 bytes/voxel + sliceLength); + break; + + default: + throw new Error("Unsupported Array Type ".concat(configuration.arrayType)); + } + + labelmap3D.labelmaps2D[imageIdIndex] = { + pixelData: pixelData, + segmentsOnLabelmap: Object(_getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_2__["default"])(pixelData) + }; + } + + return labelmap3D.labelmaps2D[imageIdIndex]; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getLabelmapBuffers.js": +/*!****************************************************************!*\ + !*** ./store/modules/segmentationModule/getLabelmapBuffers.js ***! + \****************************************************************/ +/*! exports provided: getLabelmapBuffers, getActiveLabelmapBuffer */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLabelmapBuffers", function() { return getLabelmapBuffers; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getActiveLabelmapBuffer", function() { return getActiveLabelmapBuffer; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _getLabelmaps3D__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getLabelmaps3D */ "./store/modules/segmentationModule/getLabelmaps3D.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + + + + + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_4__["default"].UINT_16_ARRAY, + FLOAT_32_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_4__["default"].FLOAT_32_ARRAY; +/** + * GetLabelmapBuffers - Returns the `buffer` of each `Labelmap3D` associated + * with the `BrushStackState` displayed on the element, or a specific + * one if `labelmapIndex` is defined. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {type} [labelmapIndex] Optional filtering to only return one labelmap. + * @returns {Object|Object[]} An array of objects containing the `labelmapIndex`, and the corresponding buffer and `colorLUT`. + * Only one object if `labelmapIndex` was specified. + * + */ + +function getLabelmapBuffers(elementOrEnabledElementUID, labelmapIndex) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var _getLabelmaps3D = Object(_getLabelmaps3D__WEBPACK_IMPORTED_MODULE_2__["default"])(element), + labelmaps3D = _getLabelmaps3D.labelmaps3D; + + if (!labelmaps3D) { + return []; + } + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_5__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var type; + var bytesPerVoxel; + + switch (configuration.arrayType) { + case UINT_16_ARRAY: + type = 'Uint16Array'; + bytesPerVoxel = '2'; + break; + + case FLOAT_32_ARRAY: + type = 'Float32Array'; + bytesPerVoxel = '4'; + break; + + default: + throw new Error("Unsupported Array Type ".concat(configuration.arrayType)); + } + + var colorLutTables = _state__WEBPACK_IMPORTED_MODULE_3__["default"].colorLutTables; + + if (labelmapIndex !== undefined) { + var labelmap3D = labelmaps3D[labelmapIndex]; + + if (labelmap3D) { + return { + labelmapIndex: labelmapIndex, + bytesPerVoxel: bytesPerVoxel, + type: type, + buffer: labelmap3D.buffer, + colorLUT: colorLutTables[labelmap3D.colorLUTIndex] + }; + } + + return; + } + + var labelmapBuffers = []; + + for (var i = 0; i < labelmaps3D.length; i++) { + var _labelmap3D = labelmaps3D[i]; + + if (_labelmap3D) { + labelmapBuffers.push({ + labelmapIndex: i, + bytesPerVoxel: 2, + buffer: _labelmap3D.buffer, + colorLUT: colorLutTables[_labelmap3D.colorLUTIndex] + }); + } + } + + return labelmapBuffers; +} +/** + * Returns the `buffer` corresponding to the active `Labelmap3D` associated with the + * `BrushStackState` displayed onv the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @returns {Object} An object containing the `labelmapIndex` and + * corresponding `buffer`. + */ + + +function getActiveLabelmapBuffer(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var imageIds = stackState.data[0].imageIds; + var firstImageId = imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_3__["default"].series[firstImageId]; + + if (!brushStackState) { + return; + } + + var activeLabelmapIndex = brushStackState.activeLabelmapIndex; + return getLabelmapBuffers(element, activeLabelmapIndex); +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/getLabelmapStats.js": +/*!**************************************************************!*\ + !*** ./store/modules/segmentationModule/getLabelmapStats.js ***! + \**************************************************************/ +/*! exports provided: default, _calculateLabelmapStats */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getLabelmapStats; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_calculateLabelmapStats", function() { return _calculateLabelmapStats; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('store:modules:segmentationModule:getLabelmapStats'); +/** + * Returns the maximum pixel value, mean and standard deviation of the segment + * given by the `segmentIndex` and `labelmapIndex`. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} segmentIndex The segment index to query. + * @param {number} labelmapIndex The `labelmapIndex` of the `Labelmap3D` to query. + * Defaults to the activeLabelmapIndex if not given. + * @returns {Promise|null} A promise that resolves to an object containing + * the maximum pixel value, the mean and the standard deviation. + * Returns null if no cornerstone element is found. + */ + +function getLabelmapStats(elementOrEnabledElementUID, segmentIndex, labelmapIndex) { + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone; + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return null; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var imageIds = stackState.data[0].imageIds; + var firstImageId = imageIds[0]; + return new Promise(function (resolve) { + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + resolve(null); + } + + var _getImagePlanes2 = _getImagePlanes(imageIds), + sufficientMetadata = _getImagePlanes2.sufficientMetadata, + imagePlanes = _getImagePlanes2.imagePlanes; + + if (!sufficientMetadata) { + logger.warn('Insufficient imagePlaneModule information to calculate volume statistics.'); + resolve(null); + } + + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + var imagePromises = []; + + for (var i = 0; i < imageIds.length; i++) { + imagePromises.push(cornerstone.loadAndCacheImage(imageIds[i])); + } + + Promise.all(imagePromises).then(function (images) { + var stats = _calculateLabelmapStats(labelmap3D, images, imagePlanes, segmentIndex); + + resolve(stats); + }); + }); +} +/** + * + * @param {string[]} imageIds An array of cornerstone imageIds. + * @returns {Object} An object containing an array of per-frame imagePlane metadata, + * and a flag indicating if the metadata was present. + */ + +function _getImagePlanes(imageIds) { + var imagePlanes = []; + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone; + var metadataProvider = cornerstone.metaData; + var sufficientMetadata = true; + + for (var i = 0; i < imageIds.length; i++) { + var imagePlaneModule = metadataProvider.get('imagePlaneModule', imageIds[i]); + + if (!imagePlaneModule) { + sufficientMetadata = false; + break; + } + + imagePlanes.push(imagePlaneModule); + } + + return { + sufficientMetadata: sufficientMetadata, + imagePlanes: imagePlanes + }; +} +/** + * + * @param {Labelmap3D} labelmap3D The labelmap3D object. + * @param {Object[]} images An array of cornerstone images. + * @param {Object[]} imagePlanes An array of the per-frame imagePlane metadata. + * @param {number} segmentIndex + * + * @returns {Object} Statistics object containing the volume in mm^3; and the + * min, max, mean and stdev of the segmented voxels. + */ + + +function _calculateLabelmapStats(labelmap3D, images, imagePlanes, segmentIndex) { + var voxelsPerFrame = _getVoxelsPerFrameForSegment(labelmap3D, images, imagePlanes, segmentIndex); + + var volumeWeightedMean = 0; + var max = voxelsPerFrame[0].values[0]; + var min = max; + var volume = 0; // Calculate Min, Max, volume and mean. + + for (var i = 0; i < voxelsPerFrame.length; i++) { + var _voxelsPerFrame$i = voxelsPerFrame[i], + values = _voxelsPerFrame$i.values, + voxelInMM3 = _voxelsPerFrame$i.voxelInMM3; + volume += voxelInMM3 * values.length; + var sum = 0; + values.forEach(function (value) { + if (value > max) { + max = value; + } else if (value < min) { + min = value; + } + + sum += value; + }); + volumeWeightedMean += sum * voxelInMM3; + } + + volumeWeightedMean /= volume; + var volumeWeightedStDev = 0; // Calculate the volume weigthed standard deviation. + + for (var _i = 0; _i < voxelsPerFrame.length; _i++) { + var _voxelsPerFrame$_i = voxelsPerFrame[_i], + values = _voxelsPerFrame$_i.values, + voxelInMM3 = _voxelsPerFrame$_i.voxelInMM3; + var stdDevSum = 0; + values.forEach(function (value) { + stdDevSum += Math.pow(value - volumeWeightedMean, 2); + }); + volumeWeightedStDev += stdDevSum * voxelInMM3; + } + + volumeWeightedStDev /= volume; + volumeWeightedStDev = Math.sqrt(volumeWeightedStDev); + return { + volume: volume, + mean: volumeWeightedMean, + stdDev: volumeWeightedStDev, + max: max, + min: min + }; +} +/** + * Returns an array of voxel values masked by the segment for each frame, + * as well as the real world volume of a voxel on that frame. + * + * @param {Labelmap3D} labelmap3D The `Labelmap3D` object. + * @param {Object[]} images An array of cornerstone images. + * @param {Object[]} imagePlanes An array of the per-frame imagePlane metadata. + * @param {number} segmentIndex The index of the segment to check. + * + * @returns {Object[]} An array of voxel values and voxel volumes per frame. + */ + +function _getVoxelsPerFrameForSegment(labelmap3D, images, imagePlanes, segmentIndex) { + var _images$ = images[0], + rowPixelSpacing = _images$.rowPixelSpacing, + columnPixelSpacing = _images$.columnPixelSpacing; + var labelmaps2D = labelmap3D.labelmaps2D; + var voxelsPerFrame = []; + + for (var i = 0; i < labelmaps2D.length; i++) { + var labelmap2D = labelmaps2D[i]; + + if (labelmap2D && labelmap2D.segmentsOnLabelmap.includes(segmentIndex)) { + var sliceThickness = _getSliceThickness(images, imagePlanes, i); + + var voxelInMM3 = sliceThickness * rowPixelSpacing * columnPixelSpacing; + var segmentationPixelData = labelmap2D.pixelData; + var imagePixelData = images[i].getPixelData(); + var values = []; // Iterate over segmentationPixelData and count voxels. + + for (var p = 0; p < segmentationPixelData.length; p++) { + if (segmentationPixelData[p] === segmentIndex) { + values.push(imagePixelData[p]); + } + } + + voxelsPerFrame.push({ + voxelInMM3: voxelInMM3, + values: values + }); + } + } + + return voxelsPerFrame; +} +/** + * Estimates the slice thickness given the image position patient of adjacent frames. + * For the edges the slice thickness is assumed to be the perpendicular distance to the closest frame. + * For all other frames the slice thickness is taken to be the sum of half of the distance to the frame above and below. + * + * Voxels on the first or last frame are assumed to be full occupied. + * + * @param {Object[]} images An array of cornerstone images. + * @param {Object[]} imagePlanes An array of the per-frame imagePlane metadata. + * @param {number} frameIndex The index of the frame to get the slice thickness for. + * + * @returns {number} + */ + + +function _getSliceThickness(images, imagePlanes, frameIndex) { + var numberOfSlices = images.length; + var ipp = imagePlanes[frameIndex].imagePositionPatient; // Special cases: Edge of volume - Assume thickness is the distance + // between the current slice and the closest slice as this is all the information we have. + + if (frameIndex === 0) { + var _ippAbove = imagePlanes[frameIndex + 1].imagePositionPatient; + return distanceBetweenSlices(ipp, _ippAbove); + } else if (frameIndex === numberOfSlices - 1) { + var _ippBelow = imagePlanes[frameIndex - 1].imagePositionPatient; + return distanceBetweenSlices(ipp, _ippBelow); + } // Estimate slice thickness from the two adjacent slices. + + + var ippBelow = imagePlanes[frameIndex - 1].imagePositionPatient; + var ippAbove = imagePlanes[frameIndex + 1].imagePositionPatient; + return (distanceBetweenSlices(ipp, ippBelow) + distanceBetweenSlices(ipp, ippAbove)) / 2; +} +/** + * Returns the ditance between two imagePostionPatient coordinates. + * + * @param {number[]} ipp1 The first image position patient array. + * @param {number[]} ipp2 The second image position patient array. + */ + + +function distanceBetweenSlices(ipp1, ipp2) { + return Math.sqrt(Math.pow(ipp1[0] - ipp2[0], 2) + Math.pow(ipp1[1] - ipp2[1], 2) + Math.pow(ipp1[2] - ipp2[2], 2)); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getLabelmaps3D.js": +/*!************************************************************!*\ + !*** ./store/modules/segmentationModule/getLabelmaps3D.js ***! + \************************************************************/ +/*! exports provided: default, getLabelmap3D */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getLabelmaps3D; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLabelmap3D", function() { return getLabelmap3D; }); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('store:modules:segmentationModule:getLabelmaps3D'); +/** + * Returns the `Labelmap3D` objects associated with the series displayed + * in the element, the `activeLabelmapIndex` and the `currentImageIdIndex`. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @returns {Object} An object containing `Labelmap3D` objects, + * the `activeLabelmapIndex` amd the `currentImageIdIndex`. + */ + +function getLabelmaps3D(elementOrEnabledElementUID) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_1__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__["getToolState"])(element, 'stack'); + + if (!stackState) { + logger.error('Consumers must define stacks in their application if using segmentations in cornerstoneTools.'); + return; + } + + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + var labelmaps3D; + var activeLabelmapIndex; + + if (brushStackState) { + labelmaps3D = brushStackState.labelmaps3D; + activeLabelmapIndex = brushStackState.activeLabelmapIndex; + } + + return { + labelmaps3D: labelmaps3D, + activeLabelmapIndex: activeLabelmapIndex, + currentImageIdIndex: stackData.currentImageIdIndex + }; +} +/** + * Returns a single `Labelmap3D` object associated with the series displayed + * in the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} [labelmapIndex] The index of the `Labelmap3D` to retrieve. Defaults to + * the `activeLabelmapIndex`. + * @returns {Object} A `Labelmap3D` object. + */ + +function getLabelmap3D(elementOrEnabledElementUID, labelmapIndex) { + var _getLabelmaps3D = getLabelmaps3D(elementOrEnabledElementUID), + labelmaps3D = _getLabelmaps3D.labelmaps3D, + activeLabelmapIndex = _getLabelmaps3D.activeLabelmapIndex; + + labelmapIndex = labelmapIndex !== undefined ? labelmapIndex : activeLabelmapIndex; + return labelmaps3D[labelmapIndex]; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getSegmentOfActiveLabelmapAtEvent.js": +/*!*******************************************************************************!*\ + !*** ./store/modules/segmentationModule/getSegmentOfActiveLabelmapAtEvent.js ***! + \*******************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getSegmentOfActiveLabelmapAtEvent; }); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _util_isPointInImage__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/isPointInImage */ "./util/isPointInImage.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('store:modules:segmentationModule:getSegmentOfActiveLabelmapAtEvent'); +/** + * Returns the segmentIndex at the event position and its corresponding metadata. + * @param {Object} evt A cornerstone event with a currentPoints property. + * + * @returns {Object} An `Object` with the `segmentIndex` and its `metadata`. + */ + +function getSegmentOfActiveLabelmapAtEvent(evt) { + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image, + currentPoints = eventData.currentPoints; + + if (!currentPoints) { + logger.warn('Not a cornerstone input event.'); + return; + } + + var cols = image.width; + var rows = image.height; + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_0__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var currentImageIdIndex = stackData.currentImageIdIndex; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_1__["default"].series[firstImageId]; + var activeLabelmapIndex = brushStackState.activeLabelmapIndex; + var labelmap3D = brushStackState.labelmaps3D[activeLabelmapIndex]; + + if (!labelmap3D) { + // No labelmap3D === no segment here. + return; + } + + var labelmap2D = labelmap3D.labelmaps2D[currentImageIdIndex]; + + if (!labelmap2D) { + // No labelmap on this imageId === no segment here. + return; + } + + var pixelData = labelmap2D.pixelData; + var _currentPoints$image = currentPoints.image, + x = _currentPoints$image.x, + y = _currentPoints$image.y; + x = Math.floor(x); + y = Math.floor(y); + + if (Object(_util_isPointInImage__WEBPACK_IMPORTED_MODULE_2__["default"])({ + x: x, + y: y + }, rows, cols)) { + var segmentIndex = pixelData[y * cols + x]; + + if (segmentIndex === 0) { + return; + } + + return { + segmentIndex: segmentIndex, + metadata: labelmap3D.metadata[segmentIndex] + }; + } // Outside image === no segment here. + + + return; +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/getSegmentsOnPixeldata.js": +/*!********************************************************************!*\ + !*** ./store/modules/segmentationModule/getSegmentsOnPixeldata.js ***! + \********************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getSegmentsOnPixelData; }); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * Returns an array of the segment indicies present on the `pixelData`. + * @param {UInt16Array|Float32Array} pixelData The pixel data array. + */ +function getSegmentsOnPixelData(pixelData) { + return _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(new Set(pixelData)); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/history.js": +/*!*****************************************************!*\ + !*** ./store/modules/segmentationModule/history.js ***! + \*****************************************************/ +/*! exports provided: pushState, undo, redo */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pushState", function() { return pushState; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "undo", function() { return undo; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "redo", function() { return redo; }); +/* harmony import */ var _getLabelmaps3D__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getLabelmaps3D */ "./store/modules/segmentationModule/getLabelmaps3D.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_1__["getLogger"])('util:segmentation:labelmap3DHistory'); + +function pushState(element, operations, labelmapIndex) { + var labelmap3D = Object(_getLabelmaps3D__WEBPACK_IMPORTED_MODULE_0__["getLabelmap3D"])(element, labelmapIndex); + labelmap3D.undo.push(operations); + labelmap3D.redo = []; +} + +function undo(element, labelmapIndex) { + var labelmap3D = Object(_getLabelmaps3D__WEBPACK_IMPORTED_MODULE_0__["getLabelmap3D"])(element, labelmapIndex); + var undo = labelmap3D.undo, + redo = labelmap3D.redo; + + if (!undo.length) { + logger.warn('No undos left.'); + return; + } // Pop last set of operations from undo. + + + var operations = undo.pop(); // Undo operations. + + applyState(labelmap3D, operations, 1); // Push set of operations to redo. + + redo.push(operations); + _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone.updateImage(element); +} + +function redo(element, labelmapIndex) { + var labelmap3D = Object(_getLabelmaps3D__WEBPACK_IMPORTED_MODULE_0__["getLabelmap3D"])(element, labelmapIndex); + var undo = labelmap3D.undo, + redo = labelmap3D.redo; + + if (!redo.length) { + logger.warn('No redos left.'); + return; + } // Pop last set of operations from redo. + + + var operations = redo.pop(); // Redo operations. + + applyState(labelmap3D, operations, 2); // Push set of operations to undo. + + undo.push(operations); + _externalModules__WEBPACK_IMPORTED_MODULE_2__["default"].cornerstone.updateImage(element); +} + + + +function applyState(labelmap3D, operations, replaceIndex) { + var labelmaps2D = labelmap3D.labelmaps2D; + operations.forEach(function (operation) { + var imageIdIndex = operation.imageIdIndex, + diff = operation.diff; + var labelmap2D = labelmaps2D[imageIdIndex]; + var pixelData = labelmap2D.pixelData; + + for (var i = 0; i < diff.length; i++) { + var diffI = diff[i]; + pixelData[diffI[0]] = diffI[replaceIndex]; + } + }); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/index.js": +/*!***************************************************!*\ + !*** ./store/modules/segmentationModule/index.js ***! + \***************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _metadata__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./metadata */ "./store/modules/segmentationModule/metadata.js"); +/* harmony import */ var _activeLabelmapIndex__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./activeLabelmapIndex */ "./store/modules/segmentationModule/activeLabelmapIndex.js"); +/* harmony import */ var _activeSegmentIndex__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./activeSegmentIndex */ "./store/modules/segmentationModule/activeSegmentIndex.js"); +/* harmony import */ var _segmentVisibility_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./segmentVisibility.js */ "./store/modules/segmentationModule/segmentVisibility.js"); +/* harmony import */ var _getLabelmapBuffers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./getLabelmapBuffers */ "./store/modules/segmentationModule/getLabelmapBuffers.js"); +/* harmony import */ var _setLabelmap3D_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./setLabelmap3D.js */ "./store/modules/segmentationModule/setLabelmap3D.js"); +/* harmony import */ var _getLabelmapStats__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./getLabelmapStats */ "./store/modules/segmentationModule/getLabelmapStats.js"); +/* harmony import */ var _getLabelmaps3D__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./getLabelmaps3D */ "./store/modules/segmentationModule/getLabelmaps3D.js"); +/* harmony import */ var _getLabelmap2D__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./getLabelmap2D */ "./store/modules/segmentationModule/getLabelmap2D.js"); +/* harmony import */ var _getSegmentOfActiveLabelmapAtEvent__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./getSegmentOfActiveLabelmapAtEvent */ "./store/modules/segmentationModule/getSegmentOfActiveLabelmapAtEvent.js"); +/* harmony import */ var _colorLUT__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./colorLUT */ "./store/modules/segmentationModule/colorLUT.js"); +/* harmony import */ var _getBrushColor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./getBrushColor */ "./store/modules/segmentationModule/getBrushColor.js"); +/* harmony import */ var _getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./getSegmentsOnPixeldata */ "./store/modules/segmentationModule/getSegmentsOnPixeldata.js"); +/* harmony import */ var _deleteSegment__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./deleteSegment */ "./store/modules/segmentationModule/deleteSegment.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _defaultConfiguration__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./defaultConfiguration */ "./store/modules/segmentationModule/defaultConfiguration.js"); +/* harmony import */ var _history__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./history */ "./store/modules/segmentationModule/history.js"); +/* harmony import */ var _setRadius__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./setRadius */ "./store/modules/segmentationModule/setRadius.js"); + + + + + + + + + + + + + + + + + + +/** + * A map of `firstImageId` to associated `BrushStackState`, where + * `firstImageId` is the `imageId` of the first image in a stack. + * + * @typedef {Object} Series + */ + +/** + * @typedef {Object} BrushStackState An object defining a set of 3D labelmaps + * associated with a specific cornerstone stack. + * @property {number} activeLabelmapIndex The index of the active `Labelmap3D`. + * @property {Labelmap3D[]} labelmaps3D An array of `Labelmap3D` objects. + */ + +/** + * A 3D labelmap object which stores the labelmap data for an entire stack of cornerstone images. + * + * @typedef {Object} Labelmap3D An object defining a 3D labelmap. + * @property {ArrayBuffer} buffer An array buffer to store the pixel data of the `Labelmap3D` (2 bytes/voxel for Uint16 and 4 bytes/voxel for Float32). + * @property {Labelmap2D[]} labelmaps2D array of `labelmap2D` views on the `buffer`, indexed by in-stack + * image positions. + * @property {Object[]} metadata An array of metadata per segment. Metadata is optional and its form is + * application specific. + * @property {number} activeSegmentIndex The index of the active segment for this `Labelmap3D`. + * @property {number} colorLUTIndex The index of the color LUT to use when displaying this `Labelmap3D`. + * @property {boolean[]} segmentsHidden The visibility of segments on this labelmap. + * If an element is `true`, the element is hidden. If it `false|undefined`, the segment is visible. + * @property {Object[]} undo A history of operations that can be reversed. + * @property {Object[]} redo A history of reverted operations, so that an undo can be reversed. + * Is cleared when changes are made to the labelmap. + */ + +/** + * A 2D labelmap object which accesses only one frame's worth of data from its parent `Labelmap3D`. + * + * @typedef {Object} Labelmap2D An object defining a 2D view on a section of a `Labelmap3D`'s `buffer`. + * @property {Uint16Array|Float32Array} pixelData A 2D view on a section of the parent `Labelmap3D`'s `buffer`. + * @property {number[]} segmentsOnLabelmap An array of segments present in the `pixelData`. + */ + +/** + * OnRegisterCallback - Initialise a single default colorLUT when cornerstoneTools is initialised. + * + * @returns {null} + */ + +function onRegisterCallback() { + Object(_colorLUT__WEBPACK_IMPORTED_MODULE_10__["default"])(0); +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + state: _state__WEBPACK_IMPORTED_MODULE_14__["default"], + configuration: _defaultConfiguration__WEBPACK_IMPORTED_MODULE_15__["default"], + onRegisterCallback: onRegisterCallback, + getters: { + metadata: _metadata__WEBPACK_IMPORTED_MODULE_0__["getMetadata"], + labelmap3D: _getLabelmaps3D__WEBPACK_IMPORTED_MODULE_7__["getLabelmap3D"], + labelmaps3D: _getLabelmaps3D__WEBPACK_IMPORTED_MODULE_7__["default"], + activeLabelmapIndex: _activeLabelmapIndex__WEBPACK_IMPORTED_MODULE_1__["getActiveLabelmapIndex"], + activeSegmentIndex: _activeSegmentIndex__WEBPACK_IMPORTED_MODULE_2__["getActiveSegmentIndex"], + isSegmentVisible: _segmentVisibility_js__WEBPACK_IMPORTED_MODULE_3__["isSegmentVisible"], + labelmap2D: _getLabelmap2D__WEBPACK_IMPORTED_MODULE_8__["default"], + labelmap2DByImageIdIndex: _getLabelmap2D__WEBPACK_IMPORTED_MODULE_8__["getLabelmap2DByImageIdIndex"], + labelmapStats: _getLabelmapStats__WEBPACK_IMPORTED_MODULE_6__["default"], + segmentOfActiveLabelmapAtEvent: _getSegmentOfActiveLabelmapAtEvent__WEBPACK_IMPORTED_MODULE_9__["default"], + brushColor: _getBrushColor__WEBPACK_IMPORTED_MODULE_11__["default"], + labelmapBuffers: _getLabelmapBuffers__WEBPACK_IMPORTED_MODULE_4__["getLabelmapBuffers"], + activeLabelmapBuffer: _getLabelmapBuffers__WEBPACK_IMPORTED_MODULE_4__["getActiveLabelmapBuffer"], + colorLUT: _colorLUT__WEBPACK_IMPORTED_MODULE_10__["getColorLUT"], + colorForSegmentIndexColorLUT: _colorLUT__WEBPACK_IMPORTED_MODULE_10__["getColorForSegmentIndexColorLUT"] + }, + setters: { + metadata: _metadata__WEBPACK_IMPORTED_MODULE_0__["setMetadata"], + labelmap3DForElement: _setLabelmap3D_js__WEBPACK_IMPORTED_MODULE_5__["setLabelmap3DForElement"], + labelmap3DByFirstImageId: _setLabelmap3D_js__WEBPACK_IMPORTED_MODULE_5__["setLabelmap3DByFirstImageId"], + incrementActiveSegmentIndex: _activeSegmentIndex__WEBPACK_IMPORTED_MODULE_2__["incrementActiveSegmentIndex"], + decrementActiveSegmentIndex: _activeSegmentIndex__WEBPACK_IMPORTED_MODULE_2__["decrementActiveSegmentIndex"], + activeSegmentIndex: _activeSegmentIndex__WEBPACK_IMPORTED_MODULE_2__["setActiveSegmentIndex"], + toggleSegmentVisibility: _segmentVisibility_js__WEBPACK_IMPORTED_MODULE_3__["toggleSegmentVisibility"], + updateSegmentsOnLabelmap2D: function updateSegmentsOnLabelmap2D(labelmap2D) { + labelmap2D.segmentsOnLabelmap = Object(_getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_12__["default"])(labelmap2D.pixelData); + }, + deleteSegment: _deleteSegment__WEBPACK_IMPORTED_MODULE_13__["default"], + colorLUT: _colorLUT__WEBPACK_IMPORTED_MODULE_10__["default"], + colorLUTIndexForLabelmap3D: _colorLUT__WEBPACK_IMPORTED_MODULE_10__["setColorLUTIndexForLabelmap3D"], + colorForSegmentIndexOfColorLUT: _colorLUT__WEBPACK_IMPORTED_MODULE_10__["setColorForSegmentIndexOfColorLUT"], + activeLabelmapIndex: _activeLabelmapIndex__WEBPACK_IMPORTED_MODULE_1__["setActiveLabelmapIndex"], + radius: _setRadius__WEBPACK_IMPORTED_MODULE_17__["default"], + pushState: _history__WEBPACK_IMPORTED_MODULE_16__["pushState"], + undo: _history__WEBPACK_IMPORTED_MODULE_16__["undo"], + redo: _history__WEBPACK_IMPORTED_MODULE_16__["redo"] + } +}); + +/***/ }), + +/***/ "./store/modules/segmentationModule/metadata.js": +/*!******************************************************!*\ + !*** ./store/modules/segmentationModule/metadata.js ***! + \******************************************************/ +/*! exports provided: getMetadata, setMetadata */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getMetadata", function() { return getMetadata; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setMetadata", function() { return setMetadata; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _addLabelmap3D__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./addLabelmap3D */ "./store/modules/segmentationModule/addLabelmap3D.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../externalModules */ "./externalModules.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); + + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('store:modules:segmentationModule:metadata'); +/** + * GetMetadata - Returns the metadata object for a particular segment if + * segmentIndex is specified, otherwise returns an array of all segment metadata + * for the labelmap. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} [labelmapIndex] If undefined, defaults to the active + * labelmap index. + * @param {number} [segmentIndex] The segment index. + * @returns {Object|Object[]} A metadata object or an array of + * metadata objects. + */ + +function getMetadata(elementOrEnabledElementUID, labelmapIndex, segmentIndex) { + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_5__["default"].series[firstImageId]; + + if (!brushStackState) { + logger.warn("brushStackState is undefined"); + return; + } + + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + + if (!brushStackState.labelmaps3D[labelmapIndex]) { + logger.warn("No labelmap3D of labelmap index ".concat(labelmapIndex, " on stack.")); + return; + } + + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + + if (segmentIndex === undefined) { + return labelmap3D.metadata; + } + + return labelmap3D.metadata[segmentIndex]; +} +/** + * SetMetadata - Sets the metadata object for a particular segment of a + * `Labelmap3D`. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} labelmapIndex = 0 The labelmap index. + * @param {number} segmentIndex The segment index. + * @param {Object} metadata The metadata object to set. + * @returns {null} + */ + + +function setMetadata(elementOrEnabledElementUID) { + var labelmapIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + var segmentIndex = arguments.length > 2 ? arguments[2] : undefined; + var metadata = arguments.length > 3 ? arguments[3] : undefined; + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone; + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_5__["default"].series[firstImageId]; + + if (!brushStackState) { + _state__WEBPACK_IMPORTED_MODULE_5__["default"].series[firstImageId] = { + labelmapIndex: labelmapIndex, + labelmaps3D: [] + }; + brushStackState = _state__WEBPACK_IMPORTED_MODULE_5__["default"].series[firstImageId]; + } + + if (!brushStackState.labelmaps3D[labelmapIndex]) { + var enabledElement = cornerstone.getEnabledElement(element); + var _enabledElement$image = enabledElement.image, + rows = _enabledElement$image.rows, + columns = _enabledElement$image.columns; + var numberOfFrames = stackData.imageIds.length; + var size = rows * columns * numberOfFrames; + Object(_addLabelmap3D__WEBPACK_IMPORTED_MODULE_1__["default"])(brushStackState, labelmapIndex, size); + } + + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + labelmap3D.metadata[segmentIndex] = metadata; +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/segmentVisibility.js": +/*!***************************************************************!*\ + !*** ./store/modules/segmentationModule/segmentVisibility.js ***! + \***************************************************************/ +/*! exports provided: isSegmentVisible, toggleSegmentVisibility */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isSegmentVisible", function() { return isSegmentVisible; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "toggleSegmentVisibility", function() { return toggleSegmentVisibility; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('store:modules:segmentationModule:segmentVisibility'); +/** + * Returns if a segment is visible. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} segmentIndex The segment index. + * @param {number} [labelmapIndex] If undefined, defaults to the active + * labelmap index. + * @returns {boolean} True if the segment is visible. + */ + +function isSegmentVisible(elementOrEnabledElementUID, segmentIndex, labelmapIndex) { + if (!segmentIndex) { + return; + } + + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + logger.warn("brushStackState is undefined"); + return; + } + + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + + if (!brushStackState.labelmaps3D[labelmapIndex]) { + logger.warn("No labelmap3D of labelmap index ".concat(labelmapIndex, " on stack.")); + return; + } + + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + var visible = !labelmap3D.segmentsHidden[segmentIndex]; + return visible; +} +/** + * Toggles the visability of a segment. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone enabled + * element or its UUID. + * @param {number} segmentIndex The segment index. + * @param {number} [labelmapIndex] If undefined, defaults to the active + * labelmap index. + * @returns {boolean} True if the segment is now visible. + */ + + +function toggleSegmentVisibility(elementOrEnabledElementUID, segmentIndex, labelmapIndex) { + if (!segmentIndex) { + return; + } + + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var firstImageId = stackData.imageIds[0]; + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + logger.warn("brushStackState is undefined"); + return; + } + + labelmapIndex = labelmapIndex === undefined ? brushStackState.activeLabelmapIndex : labelmapIndex; + + if (!brushStackState.labelmaps3D[labelmapIndex]) { + logger.warn("No labelmap3D of labelmap index ".concat(labelmapIndex, " on stack.")); + return; + } + + var labelmap3D = brushStackState.labelmaps3D[labelmapIndex]; + var segmentsHidden = labelmap3D.segmentsHidden; + segmentsHidden[segmentIndex] = !segmentsHidden[segmentIndex]; + return !segmentsHidden[segmentIndex]; +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/setLabelmap3D.js": +/*!***********************************************************!*\ + !*** ./store/modules/segmentationModule/setLabelmap3D.js ***! + \***********************************************************/ +/*! exports provided: setLabelmap3DByFirstImageId, setLabelmap3DForElement */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setLabelmap3DByFirstImageId", function() { return setLabelmap3DByFirstImageId; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setLabelmap3DForElement", function() { return setLabelmap3DForElement; }); +/* harmony import */ var _getElement__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getElement */ "./store/modules/segmentationModule/getElement.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _state__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./state */ "./store/modules/segmentationModule/state.js"); +/* harmony import */ var _getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./getSegmentsOnPixeldata */ "./store/modules/segmentationModule/getSegmentsOnPixeldata.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _arrayTypes__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./arrayTypes */ "./store/modules/segmentationModule/arrayTypes.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../index.js */ "./store/index.js"); + + + + + + + +var UINT_16_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_5__["default"].UINT_16_ARRAY, + FLOAT_32_ARRAY = _arrayTypes__WEBPACK_IMPORTED_MODULE_5__["default"].FLOAT_32_ARRAY; +/** + * Takes a 16-bit encoded `ArrayBuffer` and stores it as a `Labelmap3D` for the + * `BrushStackState` associated with the element. + * + * @param {HTMLElement|string} elementOrEnabledElementUID The cornerstone + * enabled element or its UUID. + * @param {ArrayBuffer} buffer + * @param {number} labelmapIndex The index to store the labelmap under. + * @param {Object[]} metadata = [] Any metadata about the segments. + * @param {number[][]} [segmentsOnLabelmapArray] An array of array of segments on each imageIdIndex. + * If not present, is calculated. + * @param {colorLUTIndex} [colorLUTIndex = 0] The index of the colorLUT to use to render the segmentation. + * @returns {null} + */ + +function setLabelmap3DForElement(elementOrEnabledElementUID, buffer, labelmapIndex) { + var metadata = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; + var segmentsOnLabelmapArray = arguments.length > 4 ? arguments[4] : undefined; + var colorLUTIndex = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0; + var element = Object(_getElement__WEBPACK_IMPORTED_MODULE_0__["default"])(elementOrEnabledElementUID); + + if (!element) { + return; + } + + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + var numberOfFrames = stackState.data[0].imageIds.length; + var firstImageId = stackState.data[0].imageIds[0]; + setLabelmap3DByFirstImageId(firstImageId, buffer, labelmapIndex, metadata, numberOfFrames, segmentsOnLabelmapArray, colorLUTIndex); + Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_4__["triggerLabelmapModifiedEvent"])(element, labelmapIndex); +} +/** + * Takes an 16-bit encoded `ArrayBuffer` and stores it as a `Labelmap3D` for + * the `BrushStackState` associated with the firstImageId. + * + * @param {HTMLElement|string} firstImageId The firstImageId of the series to + * store the segmentation on. + * @param {ArrayBuffer} buffer + * @param {number} labelmapIndex The index to store the labelmap under. + * @param {Object[]} metadata = [] Any metadata about the segments. + * @param {number} numberOfFrames The number of frames, required to set up the + * relevant labelmap2D views. + * @param {number[][]} [segmentsOnLabelmapArray] An array of array of segments on each imageIdIndex. + * If not present, is calculated. + * @param {colorLUTIndex} [colorLUTIndex = 0] The index of the colorLUT to use to render the segmentation. + * @returns {null} + */ + + +function setLabelmap3DByFirstImageId(firstImageId, buffer, labelmapIndex) { + var metadata = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; + var numberOfFrames = arguments.length > 4 ? arguments[4] : undefined; + var segmentsOnLabelmapArray = arguments.length > 5 ? arguments[5] : undefined; + var colorLUTIndex = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0; + + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_6__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + var brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + + if (!brushStackState) { + _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId] = { + activeLabelmapIndex: labelmapIndex, + labelmaps3D: [] + }; + brushStackState = _state__WEBPACK_IMPORTED_MODULE_2__["default"].series[firstImageId]; + } + + brushStackState.labelmaps3D[labelmapIndex] = { + buffer: buffer, + labelmaps2D: [], + metadata: metadata, + activeSegmentIndex: 1, + colorLUTIndex: colorLUTIndex, + segmentsHidden: [], + undo: [], + redo: [] + }; + var labelmaps2D = brushStackState.labelmaps3D[labelmapIndex].labelmaps2D; + var slicelengthInBytes = buffer.byteLength / numberOfFrames; + + for (var i = 0; i < numberOfFrames; i++) { + var pixelData = void 0; + + switch (configuration.arrayType) { + case UINT_16_ARRAY: + pixelData = new Uint16Array(buffer, slicelengthInBytes * i, // 2 bytes/voxel + slicelengthInBytes / 2); + break; + + case FLOAT_32_ARRAY: + pixelData = new Float32Array(buffer, slicelengthInBytes * i, slicelengthInBytes / 4); + break; + + default: + throw new Error("Unsupported Array Type ".concat(configuration.arrayType)); + } + + var segmentsOnLabelmap = segmentsOnLabelmapArray ? segmentsOnLabelmapArray[i] : Object(_getSegmentsOnPixeldata__WEBPACK_IMPORTED_MODULE_3__["default"])(pixelData); + + if (segmentsOnLabelmap && segmentsOnLabelmap.some(function (segment) { + return segment; + })) { + labelmaps2D[i] = { + pixelData: pixelData, + segmentsOnLabelmap: segmentsOnLabelmap + }; + } + } +} + + + +/***/ }), + +/***/ "./store/modules/segmentationModule/setRadius.js": +/*!*******************************************************!*\ + !*** ./store/modules/segmentationModule/setRadius.js ***! + \*******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return setRadius; }); +/* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../index */ "./store/index.js"); + +function setRadius(newRadius) { + var _getModule = Object(_index__WEBPACK_IMPORTED_MODULE_0__["getModule"])('segmentation'), + configuration = _getModule.configuration; + + configuration.radius = Math.min(Math.max(newRadius, configuration.minRadius), configuration.maxRadius); +} + +/***/ }), + +/***/ "./store/modules/segmentationModule/state.js": +/*!***************************************************!*\ + !*** ./store/modules/segmentationModule/state.js ***! + \***************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +// Internal state of the brush module. +var state = { + series: {}, + colorLutTables: [] +}; +/* harmony default export */ __webpack_exports__["default"] = (state); + +/***/ }), + +/***/ "./store/removeTool.js": +/*!*****************************!*\ + !*** ./store/removeTool.js ***! + \*****************************/ +/*! exports provided: removeTool, removeToolForElement */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeTool", function() { return removeTool; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeToolForElement", function() { return removeToolForElement; }); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); + +/** + * Deactivates and removes the tool from the target element with the provided name + * + * @export + * @public + * @method + * @name removeToolForElement + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool. + * @returns {void} + */ + +var removeToolForElement = function removeToolForElement(element, toolName) { + var toolIndex = _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.tools.findIndex(function (tool) { + return tool.element === element && tool.name === toolName; + }); + + if (toolIndex >= 0) { + _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.tools.splice(toolIndex, 1); + } +}; +/** + * Removes all tools from all enabled elements with the provided name. + * + * @export + * @public + * @method + * @name removeTool + * @param {string} toolName The name of the tool. + * @returns {void} + */ + + +var removeTool = function removeTool(toolName) { + _removeToolGlobally(toolName); + + _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.enabledElements.forEach(function (element) { + removeToolForElement(element, toolName); + }); +}; +/** + * Removes tool with matching name from globally registered tools. + * Requires `globalToolSyncEnabled` to be set to true + * + * @private + * @method + * @name removeToolGlobally + * @param {string} toolName The name of the tool to remove. + * @returns {void} + */ + + +var _removeToolGlobally = function _removeToolGlobally(toolName) { + var _getModule = Object(_index_js__WEBPACK_IMPORTED_MODULE_0__["getModule"])('globalConfiguration'), + configuration = _getModule.configuration; + + if (!configuration.globalToolSyncEnabled) { + return; + } + + if (_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.globalTools[toolName]) { + delete _index_js__WEBPACK_IMPORTED_MODULE_0__["default"].state.globalTools[toolName]; + } +}; + + + +/***/ }), + +/***/ "./store/setToolCursor.js": +/*!********************************!*\ + !*** ./store/setToolCursor.js ***! + \********************************/ +/*! exports provided: setToolCursor, resetToolCursor, hideToolCursor */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolCursor", function() { return setToolCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resetToolCursor", function() { return resetToolCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hideToolCursor", function() { return hideToolCursor; }); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); + + +var globalConfiguration = _index_js__WEBPACK_IMPORTED_MODULE_0__["modules"].globalConfiguration; +/** + * Creates an SVG Cursor for the target element + * + * @param {HTMLElement} element - The DOM Element to draw on + * @param {MouseCursor} svgCursor - The cursor. + * @returns {void} + */ + +function setToolCursor(element, svgCursor) { + if (!globalConfiguration.configuration.showSVGCursors) { + return; + } // TODO: (state vs options) Exit if cursor wasn't updated + // TODO: Exit if invalid options to create cursor + // Note: Max size of an SVG cursor is 128x128, default is 32x32. + + + var cursorBlob = svgCursor.getIconWithPointerSVG(); + var mousePoint = svgCursor.mousePoint; + var svgCursorUrl = window.URL.createObjectURL(cursorBlob); + element.style.cursor = "url('".concat(svgCursorUrl, "') ").concat(mousePoint, ", auto"); + _index_js__WEBPACK_IMPORTED_MODULE_0__["state"].svgCursorUrl = svgCursorUrl; +} + +function resetToolCursor(element) { + _clearStateAndSetCursor(element, 'initial'); +} + +function hideToolCursor(element) { + if (!globalConfiguration.configuration.showSVGCursors) { + return; + } + + _clearStateAndSetCursor(element, 'none'); +} + +function _clearStateAndSetCursor(element, cursorSeting) { + if (_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].svgCursorUrl) { + window.URL.revokeObjectURL(_index_js__WEBPACK_IMPORTED_MODULE_0__["state"].svgCursorUrl); + } + + _index_js__WEBPACK_IMPORTED_MODULE_0__["state"].svgCursorUrl = null; + element.style.cursor = cursorSeting; +} + +/***/ }), + +/***/ "./store/setToolMode.js": +/*!******************************!*\ + !*** ./store/setToolMode.js ***! + \******************************/ +/*! exports provided: setToolActive, setToolActiveForElement, setToolDisabled, setToolDisabledForElement, setToolEnabled, setToolEnabledForElement, setToolPassive, setToolPassiveForElement, setToolMode, setToolModeForElement, _getNormalizedOptions, _mergeMouseButtonMask */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolActive", function() { return setToolActive; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolActiveForElement", function() { return setToolActiveForElement; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolDisabled", function() { return setToolDisabled; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolDisabledForElement", function() { return setToolDisabledForElement; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolEnabled", function() { return setToolEnabled; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolEnabledForElement", function() { return setToolEnabledForElement; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolPassive", function() { return setToolPassive; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolPassiveForElement", function() { return setToolPassiveForElement; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolMode", function() { return setToolMode; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolModeForElement", function() { return setToolModeForElement; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_getNormalizedOptions", function() { return _getNormalizedOptions; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_mergeMouseButtonMask", function() { return _mergeMouseButtonMask; }); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../events.js */ "./events.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _getToolForElement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getToolForElement.js */ "./store/getToolForElement.js"); +/* harmony import */ var _setToolCursor_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); + + + + + + +var globalConfiguration = Object(_index_js__WEBPACK_IMPORTED_MODULE_5__["getModule"])('globalConfiguration'); +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('store:setToolMode'); +/** + * Sets a tool's state, with the provided toolName and element, to 'active'. Active tools are rendered, + * respond to user input, and can create new data. + * + * @public + * @function setToolActiveForElement + * @memberof CornerstoneTools + * + * @example Setting a tool 'active' for a specific interaction type. + * // Sets length tool to Active + * setToolActiveForElement(element, 'Length', { + * mouseButtonMask: 1 + * }, ['Mouse']) + * @example Setting a tool 'active' for all interaction types. + * // Sets length tool to Active + * setToolActiveForElement(element, 'Length', { + * mouseButtonMask: 1 + * }) + * @param {HTMLElement} element + * @param {string} toolName + * @param {(Object|string[]|number)} options + * @param {(string[])} interactionTypes + * @returns {undefined} + */ + +var setToolActiveForElement = function setToolActiveForElement(element, toolName, options, interactionTypes) { + // If interactionTypes was passed in via options + if (interactionTypes === undefined && Array.isArray(options)) { + interactionTypes = options; + options = null; + } + + var tool = Object(_getToolForElement_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, toolName); + + if (tool) { + _resolveInputConflicts(element, tool, options, interactionTypes); // Iterate over specific interaction types and set active + // This is used as a secondary check on active tools to find the active "parts" of the tool + + + tool.supportedInteractionTypes.forEach(function (interactionType) { + if (interactionTypes === undefined || interactionTypes.includes(interactionType)) { + options["is".concat(interactionType, "Active")] = true; + } else { + options["is".concat(interactionType, "Active")] = false; + } + }); + + if (globalConfiguration.configuration.showSVGCursors && tool.supportedInteractionTypes.includes('Mouse')) { + _setToolCursorIfPrimary(element, options, tool); + } + } // Resume normal behavior + + + setToolModeForElement('active', null, element, toolName, options); +}; + +function _setToolCursorIfPrimary(element, options, tool) { + var mouseButtonMask; + + if (typeof options === 'number') { + mouseButtonMask = [options]; + } else { + mouseButtonMask = options.mouseButtonMask; + } + + if (mouseButtonMask.includes(1)) { + if (tool.svgCursor) { + Object(_setToolCursor_js__WEBPACK_IMPORTED_MODULE_3__["setToolCursor"])(tool.element, tool.svgCursor); + } else if (tool.hideDefaultCursor) { + Object(_setToolCursor_js__WEBPACK_IMPORTED_MODULE_3__["hideToolCursor"])(element); + } else { + Object(_setToolCursor_js__WEBPACK_IMPORTED_MODULE_3__["resetToolCursor"])(element); + } + } +} +/** + * Sets all tool's state, with the provided toolName, to 'active'. Active tools are rendered, + * respond to user input, and can create new data. + * @public + * @function setToolActive + * @memberof CornerstoneTools + * + * @param {string} toolName + * @param {(Object|string[]|number)} options + * @param {(string[])} interactionTypes + * @returns {undefined} + */ + + +var setToolActive = function setToolActive(toolName, options, interactionTypes) { + _trackGlobalToolModeChange('active', toolName, options, interactionTypes); + + _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.enabledElements.forEach(function (element) { + setToolActiveForElement(element, toolName, options, interactionTypes); + }); +}; +/** + * Sets a tool's state, with the provided toolName and element, to 'disabled'. Disabled tools are not rendered, + * and do not respond to user input + * @public + * @function setToolDisabledForElement + * @memberof CornerstoneTools + * + * @param {HTMLElement} element + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + + +var setToolDisabledForElement = setToolModeForElement.bind(null, 'disabled', null); +/** + * Sets all tool's state, with the provided toolName, to 'disabled'. Disabled tools are not rendered, + * and do not respond to user input + * @public + * @function setToolDisabled + * @memberof CornerstoneTools + * + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + +var setToolDisabled = setToolMode.bind(null, 'disabled', null); +/** + * Sets a tool's state, with the provided toolName and element, to 'enabled'. Enabled tools are rendered, + * but do not respond to user input + * @public + * @function setToolEnabledForElement + * @memberof CornerstoneTools + * + * @param {HTMLElement} element + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + +var setToolEnabledForElement = setToolModeForElement.bind(null, 'enabled', null); +/** + * Sets all tool's state, with the provided toolName, to 'enabled'. Enabled tools are rendered, + * but do not respond to user input + * @public + * @function setToolEnabled + * @memberof CornerstoneTools + * + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + +var setToolEnabled = setToolMode.bind(null, 'enabled', null); +/** + * Sets a tool's state, with the provided toolName and element, to 'passive'. Passive tools are rendered and respond to user input, + * but do not create new measurements or annotations. + * @public + * @function setToolPassiveForElement + * @memberof CornerstoneTools + * + * @param {HTMLElement} element + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + +var setToolPassiveForElement = setToolModeForElement.bind(null, 'passive', _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOOL_DEACTIVATED); +/** + * Sets all tool's state, with the provided toolName, to 'passive'. Passive tools are rendered and respond to user input, + * but do not create new measurements or annotations. + * @public + * @function setToolPassive + * @memberof CornerstoneTools + * + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + +var setToolPassive = setToolMode.bind(null, 'passive', _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].TOOL_DEACTIVATED); +/** + * An internal method that helps make sure we change tool mode in a consistent + * way + * @private + * @function setToolModeForElement + * + * @param {string} mode + * @param {string} changeEvent + * @param {HTMLElement} element + * @param {string} toolName + * @param {(Object|number[]|number)} options + * @returns {undefined} + */ + +function setToolModeForElement(mode, changeEvent, element, toolName, options) { + var tool = Object(_getToolForElement_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, toolName); + + if (!tool) { + logger.warn('Unable to find tool "%s" for enabledElement', toolName); + return; + } + + options = _getNormalizedOptions(options); // Keep the same if not an array (undefined) + // Reset if empty array + // Merge if array contains any bindings + + if (Array.isArray(options.mouseButtonMask) && options.mouseButtonMask.length !== 0 && Array.isArray(tool.options.mouseButtonMask)) { + options.mouseButtonMask = _mergeMouseButtonMask(options.mouseButtonMask, tool.options.mouseButtonMask); + } // Set mode & options + + + tool.mode = mode; + tool.mergeOptions(options); // Call tool's hook for this event, if one exists + + if (tool["".concat(mode, "Callback")]) { + tool["".concat(mode, "Callback")](element, options); + } // Emit event indicating tool state change + + + if (changeEvent) { + var statusChangeEventData = { + options: options, + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + type: changeEvent + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_1__["default"])(element, changeEvent, statusChangeEventData); + } // Trigger Update + // Todo: don't error out if image hasn't been loaded... + // Cornerstone.updateImage(element); + +} +/** + * A helper/quick way to set a tool's mode for all canvases + * + * @private + * @function setToolMode + * + * @param {string} mode + * @param {string} changeEvent + * @param {string} toolName + * @param {(Object|number)} options + * @returns {undefined} + */ + + +function setToolMode(mode, changeEvent, toolName, options) { + _trackGlobalToolModeChange(mode, toolName, options); + + _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.enabledElements.forEach(function (element) { + setToolModeForElement(mode, changeEvent, element, toolName, options); + }); +} +/** + * Find tool's that conflict with the incoming tool's mouse/touch bindings and + * resolve those conflicts. + * + * @private + * @function _resolveInputConflicts + * + * @param {HTMLElement} element + * @param {Object} tool + * @param {(Object|number)} options + * @param {(Array)} interactionTypes + * @returns {undefined} + */ + + +function _resolveInputConflicts(element, tool, options, interactionTypes) { + // Iterate over the interaction types our tool supports. + // For each one we intend to activate, check for potential conflicts + // And resolve them + tool.supportedInteractionTypes.forEach(function (interactionType) { + if (interactionTypes === undefined || interactionTypes.includes(interactionType)) { + var inputResolver = _inputResolvers[interactionType]; + + if (inputResolver) { + inputResolver(tool, element, options); + } else { + logger.warn('Unable to resolve input conflicts for type %s', interactionType); + } + } + }); + var activeToolsForElement = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.filter(function (t) { + return t.element === element && t.mode === 'active' && t.supportedInteractionTypes.length > 0; + }); + activeToolsForElement.forEach(function (t) { + var toolHasAnyActiveInteractionType = false; + t.supportedInteractionTypes.forEach(function (interactionType) { + if (t.options["is".concat(interactionType, "Active")]) { + toolHasAnyActiveInteractionType = true; + } + }); + + if (!toolHasAnyActiveInteractionType) { + logger.log("Setting tool %s's to PASSIVE", t.name); + setToolPassiveForElement(element, t.name); + } + }); +} +/** + * Resolves conflicting active tools when activating a tool for mouse interaction + * @private + * @function _resolveMouseInputConflicts + * + * @param {Object} tool + * @param {HTMLElement} element + * @param {(Object|number)} options + * @returns {undefined} + */ + + +function _resolveMouseInputConflicts(tool, element, options) { + var mouseButtonMask = _getNormalizedOptions(options).mouseButtonMask; + + var hasMouseButtonMask = Array.isArray(mouseButtonMask) && mouseButtonMask.length > 0; + + if (!hasMouseButtonMask) { + return; + } + + var activeToolWithMatchingMouseButtonMask = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options.isMouseActive === true && Array.isArray(t.options.mouseButtonMask) && t.options.mouseButtonMask.some(function (v) { + return mouseButtonMask.includes(v); + }); + }); + + if (activeToolWithMatchingMouseButtonMask) { + // Remove collissions + activeToolWithMatchingMouseButtonMask.options.mouseButtonMask = activeToolWithMatchingMouseButtonMask.options.mouseButtonMask.filter(function (mask) { + return !mouseButtonMask.includes(mask); + }); // If no remaining bindings, set inactive + + if (activeToolWithMatchingMouseButtonMask.options.mouseButtonMask.length === 0) { + activeToolWithMatchingMouseButtonMask.options.isMouseActive = false; + } + } +} +/** + * Resolves conflicting active tools when activating a tool for touch interaction + * @private + * @function _resolveTouchInputConflicts + * + * @param {Object} tool + * @param {HTMLElement} element + * @returns {undefined} + */ + + +function _resolveTouchInputConflicts(tool, element) { + var activeTouchTool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options.isTouchActive === true; + }); + var activeMultiTouchToolWithOneTouchPointer = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options.isMultiTouchActive === true && t.configuration.touchPointers === 1; + }); + + if (activeTouchTool) { + logger.log("Setting tool %s's isTouchActive to false", activeTouchTool.name); + activeTouchTool.options.isTouchActive = false; + } + + if (activeMultiTouchToolWithOneTouchPointer) { + logger.log("Setting tool %s's isTouchActive to false", activeMultiTouchToolWithOneTouchPointer.name); + activeMultiTouchToolWithOneTouchPointer.options.isMultiTouchActive = false; + } +} +/** + * Resolves conflicting active tools when activating a tool for MultiTouch interaction + * @private + * @function _resolveMultiTouchInputConflicts + * + * @param {Object} tool + * @param {HTMLElement} element + * @returns {undefined} + */ + + +function _resolveMultiTouchInputConflicts(tool, element) { + var activeMultiTouchTool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options.isMultiTouchActive === true && t.configuration.touchPointers === tool.configuration.touchPointers; + }); + var activeTouchTool; + + if (tool.configuration.touchPointers === 1) { + activeTouchTool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options.isTouchActive === true; + }); + } + + if (activeMultiTouchTool) { + logger.log("Setting tool %s's isMultiTouchActive to false", activeMultiTouchTool.name); + activeMultiTouchTool.options.isMultiTouchActive = false; + } + + if (activeTouchTool) { + logger.log("Setting tool %s's isTouchActive to false", activeTouchTool.name); + activeTouchTool.options.isTouchActive = false; + } +} +/** + * If the incoming tool isTouchActive, find any conflicting tools + * and set their isTouchActive to false to avoid conflicts. + * + * @private + * @function _resolveGenericInputConflicts + * + * @param {string} interactionType + * @param {Object} tool + * @param {HTMLElement} element + * @param {(Object|number)} options + * @returns {undefined} + */ + + +function _resolveGenericInputConflicts(interactionType, tool, element) { + var interactionTypeFlag = "is".concat(interactionType, "Active"); + var activeToolWithActiveInteractionType = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.tools.find(function (t) { + return t.element === element && t.mode === 'active' && t.options[interactionTypeFlag] === true; + }); + + if (activeToolWithActiveInteractionType) { + logger.log("Setting tool %s's %s to false", activeToolWithActiveInteractionType.name, interactionTypeFlag); + activeToolWithActiveInteractionType.options[interactionTypeFlag] = false; + } +} + +function _trackGlobalToolModeChange(mode, toolName, options, interactionTypes) { + if (!globalConfiguration.configuration.globalToolSyncEnabled) { + return; + } // Update Tool History + + + var historyEvent = { + mode: mode, + args: [toolName, options] + }; + + if (interactionTypes) { + historyEvent.push(interactionTypes); + } + + _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalToolChangeHistory.push(historyEvent); + var arbitraryChangeHistoryLimit = 50; + + if (_index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalToolChangeHistory.length > arbitraryChangeHistoryLimit) { + _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalToolChangeHistory.shift(); + } // Update ActiveBindings Array + + + var globalTool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalTools[toolName]; + + if (!globalTool) { + logger.warn("setToolMode call for tool not available globally: ".concat(toolName)); + return; + } + + if (mode === 'active') { + var stringBindings = _determineStringBindings(toolName, options, interactionTypes); // Remove the incoming bindings from all global tools + + + Object.keys(_index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalTools).forEach(function (key) { + var tool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalTools[key]; + tool.activeBindings = tool.activeBindings.filter(function (binding) { + return !stringBindings.includes(binding); + }); + }); // @HACK: Clear mouse bindings + + if (stringBindings.some(function (binding) { + return binding.includes('Mouse-DELETE'); + })) { + globalTool.activeBindings = globalTool.activeBindings.filter(function (binding) { + return !binding.includes('Mouse'); + }); + stringBindings = stringBindings.filter(function (binding) { + return !binding.includes('Mouse'); + }); + } + + globalTool.activeBindings = globalTool.activeBindings.concat(stringBindings); + } else { + globalTool.activeBindings = []; + } +} + +function _determineStringBindings(toolName, options, interactionTypes) { + if (interactionTypes === undefined && Array.isArray(options)) { + interactionTypes = options; + options = null; + } + + var stringBindings = []; + var globalTool = _index_js__WEBPACK_IMPORTED_MODULE_5__["default"].state.globalTools[toolName]; + + if (globalTool) { + // eslint-disable-next-line new-cap + var tool = new globalTool.tool(globalTool.props); + tool.supportedInteractionTypes.forEach(function (interactionType) { + if (interactionTypes === undefined || interactionTypes.includes(interactionType)) { + if (interactionType === 'Mouse') { + var mouseButtonMasks = _getNormalizedOptions(options).mouseButtonMask; // Add or delete + + + if (Array.isArray(mouseButtonMasks) && mouseButtonMasks.length > 0) { + mouseButtonMasks.forEach(function (mask) { + return stringBindings.push("".concat(interactionType, "-").concat(mask)); + }); + } else if (Array.isArray(mouseButtonMasks) && mouseButtonMasks.length === 0) { + stringBindings.push("".concat(interactionType, "-DELETE")); + } + } else if (interactionType === 'MultiTouch') { + stringBindings.push("".concat(interactionType, "-").concat(tool.configuration.touchPointers)); + } else { + stringBindings.push(interactionType); + } + } + }); + } + + return stringBindings; +} + +var _inputResolvers = { + Mouse: _resolveMouseInputConflicts, + MouseWheel: _resolveGenericInputConflicts.bind(undefined, 'MouseWheel'), + Touch: _resolveTouchInputConflicts, + TouchPinch: _resolveGenericInputConflicts.bind(undefined, 'TouchPinch'), + TouchRotate: _resolveGenericInputConflicts.bind(undefined, 'TouchRotate'), + DoubleTap: _resolveGenericInputConflicts.bind(undefined, 'DoubleTap'), + MultiTouch: _resolveMultiTouchInputConflicts +}; + +function _getNormalizedOptions(options) { + if (Array.isArray(options)) { + // If options is an array assume the array is the mouseButtonMask array + options = { + mouseButtonMask: options + }; + } else if (options !== Object(options)) { + // And if it's something other than an object, assume options is + // a single mouseButtonMask + options = { + mouseButtonMask: [options] + }; + } // If there is still no 'mouseButtonMask' default it to an empty array + + + if (!options.hasOwnProperty('mouseButtonMask')) { + options.mouseButtonMask = []; + } + + if (!Array.isArray(options.mouseButtonMask)) { + options.mouseButtonMask = [options.mouseButtonMask]; + } // Now filter out anything that is not an number or is the number 0 + + + options.mouseButtonMask = options.mouseButtonMask.filter(function (o) { + return typeof o === 'number' && o !== 0; + }); + return options; +} + +function _mergeMouseButtonMask(newMask, oldMask) { + // Merges and removes duplicates + return newMask.concat(oldMask).reduce(function (acc, m) { + if (acc.indexOf(m) === -1) { + acc.push(m); + } + + return acc; + }, []); +} + + + +/***/ }), + +/***/ "./store/setToolOptions.js": +/*!*********************************!*\ + !*** ./store/setToolOptions.js ***! + \*********************************/ +/*! exports provided: setToolOptions, setToolOptionsForElement */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolOptions", function() { return setToolOptions; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolOptionsForElement", function() { return setToolOptionsForElement; }); +/* harmony import */ var _getToolForElement_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getToolForElement.js */ "./store/getToolForElement.js"); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./index.js */ "./store/index.js"); + + +/** + * Sets the options of a tool on a specific element. + * @export + * @public + * @method + * @name setToolOptionsForElement + * + * @param {HTMLElement} element The element. + * @param {string} toolName The name of the tool. + * @param {Object} options The options to set. + * @returns {void} + */ + +var setToolOptionsForElement = function setToolOptionsForElement(element, toolName, options) { + var tool = Object(_getToolForElement_js__WEBPACK_IMPORTED_MODULE_0__["default"])(element, toolName); + + if (tool) { + tool.mergeOptions(options); + } +}; +/** + * Sets the options of a tool for all elements. + * @export + * @public + * @method + * @name setToolOptions + * + * @param {string} toolName + * @param {Object} options + * @returns {void} + */ + + +var setToolOptions = function setToolOptions(toolName, options) { + _index_js__WEBPACK_IMPORTED_MODULE_1__["state"].enabledElements.forEach(function (element) { + setToolOptionsForElement(element, toolName, options); + }); +}; + + + +/***/ }), + +/***/ "./synchronization/Synchronizer.js": +/*!*****************************************!*\ + !*** ./synchronization/Synchronizer.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); +/* harmony import */ var _toolOptions_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../toolOptions.js */ "./toolOptions.js"); + + + +/** + * Return an array filtered to only its unique members + * + * @private + * @param {Array} array - The array to filter + * @returns {Array} + */ + +function unique(array) { + return array.filter(function (value, index, self) { + return self.indexOf(value) === index; + }); +} +/** + * Synchronize target and source elements when an event fires on the source element + * @export @public constructor + * @name Synchronizer + * + * @param {String} event - The event(s) that will trigger synchronization. Separate multiple events by a space + * @param {Function} handler - The function that will make the necessary changes to the target element in order to synchronize it with the source element + * @returns {void} + */ + + +function Synchronizer(event, handler) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var that = this; + var sourceElements = []; // Source elements fire the events we want to synchronize to + + var targetElements = []; // Target elements we want to synchronize to source elements + + var ignoreFiredEvents = false; + var initialData = {}; + var eventHandler = handler; + this.enabled = true; + /** + * Update the event handler to perform synchronization + * @param {Function} handler - The event handler function + * @returns {void} + */ + + this.setHandler = function (handler) { + eventHandler = handler; + }; + /** + * Return a reference to the event handler function + * @returns {Function} + */ + + + this.getHandler = function () { + return eventHandler; + }; + /** + * Calculate the initial distances between the source image and each + * of the target images + * @returns {void} + */ + + + this.getDistances = function () { + if (!sourceElements.length || !targetElements.length) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + initialData.distances = {}; + initialData.imageIds = { + sourceElements: [], + targetElements: [] + }; + sourceElements.forEach(function (sourceElement) { + var sourceEnabledElement = cornerstone.getEnabledElement(sourceElement); + + if (!sourceEnabledElement || !sourceEnabledElement.image) { + return; + } + + var sourceImageId = sourceEnabledElement.image.imageId; + var sourceImagePlane = cornerstone.metaData.get('imagePlaneModule', sourceImageId); + + if (!sourceImagePlane || !sourceImagePlane.imagePositionPatient) { + return; + } + + var sourceImagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(sourceImagePlane.imagePositionPatient); + + if (initialData.hasOwnProperty(sourceEnabledElement)) { + return; + } + + initialData.distances[sourceImageId] = {}; + initialData.imageIds.sourceElements.push(sourceImageId); + targetElements.forEach(function (targetElement) { + var targetEnabledElement = cornerstone.getEnabledElement(targetElement); + + if (!targetEnabledElement || !targetEnabledElement.image) { + return; + } + + var targetImageId = targetEnabledElement.image.imageId; + initialData.imageIds.targetElements.push(targetImageId); + + if (sourceElement === targetElement) { + return; + } + + if (sourceImageId === targetImageId) { + return; + } + + if (initialData.distances[sourceImageId].hasOwnProperty(targetImageId)) { + return; + } + + var targetImagePlane = cornerstone.metaData.get('imagePlaneModule', targetImageId); + + if (!targetImagePlane || !targetImagePlane.imagePositionPatient) { + return; + } + + var targetImagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(targetImagePlane.imagePositionPatient); + initialData.distances[sourceImageId][targetImageId] = targetImagePosition.clone().sub(sourceImagePosition); + }); + + if (!Object.keys(initialData.distances[sourceImageId]).length) { + delete initialData.distances[sourceImageId]; + } + }); + }; + /** + * Gather necessary event data and call synchronization handler + * + * @private + * @param {HTMLElement} sourceElement - The source element for the event + * @param {Object} eventData - The data object for the source event + * @returns {void} + */ + + + this.fireEvent = function (sourceElement, eventData) { + var isDisabled = !that.enabled; + var noElements = !sourceElements.length || !targetElements.length; + + if (isDisabled || noElements) { + return; + } + + ignoreFiredEvents = true; + targetElements.forEach(function (targetElement) { + var targetIndex = targetElements.indexOf(targetElement); + + if (targetIndex === -1) { + return; + } + + var targetImageId = initialData.imageIds.targetElements[targetIndex]; + var sourceIndex = sourceElements.indexOf(sourceElement); + + if (sourceIndex === -1) { + return; + } + + var sourceImageId = initialData.imageIds.sourceElements[sourceIndex]; + var positionDifference; + + if (sourceImageId === targetImageId) { + positionDifference = 0; + } else if (initialData.distances[sourceImageId] !== undefined) { + positionDifference = initialData.distances[sourceImageId][targetImageId]; + } + + eventHandler(that, sourceElement, targetElement, eventData, positionDifference); + }); + ignoreFiredEvents = false; + }; + /** + * Call fireEvent if not ignoring events, and pass along event data + * + * @private + * @param {Event} e - The source event object + * @returns {void} + */ + + + this.onEvent = function (e) { + var eventData = e.detail; + + if (ignoreFiredEvents === true) { + return; + } + + that.fireEvent(e.currentTarget, eventData); + }; + /** + * Add a source element to this synchronizer + * + * @param {HTMLElement} element - The new source element + * @returns {void} + */ + + + this.addSource = function (element) { + // Return if this element was previously added + var index = sourceElements.indexOf(element); + + if (index !== -1) { + return; + } // Add to our list of enabled elements + + + sourceElements.push(element); // Subscribe to the event + + event.split(' ').forEach(function (oneEvent) { + element.addEventListener(oneEvent, that.onEvent); + }); // Update the initial distances between elements + + that.getDistances(); + that.updateDisableHandlers(); + }; + /** + * Add a target element to this synchronizer + * + * @param {HTMLElement} element - The new target element to be synchronized + * @returns {void} + */ + + + this.addTarget = function (element) { + // Return if this element was previously added + var index = targetElements.indexOf(element); + + if (index !== -1) { + return; + } // Add to our list of enabled elements + + + targetElements.push(element); // Update the initial distances between elements + + that.getDistances(); // Invoke the handler for this new target element + + eventHandler(that, element, element, 0); + that.updateDisableHandlers(); + }; + /** + * Add an element to this synchronizer as both a source and a target + * + * @param {HTMLElement} element - The new element + * @returns {void} + */ + + + this.add = function (element) { + that.addSource(element); + that.addTarget(element); + }; + /** + * Remove a source element from this synchronizer + * + * @param {HTMLElement} element - The element to be removed + * @returns {void} + */ + + + this.removeSource = function (element) { + // Find the index of this element + var index = sourceElements.indexOf(element); + + if (index === -1) { + return; + } // Remove this element from the array + + + sourceElements.splice(index, 1); // Stop listening for the event + + event.split(' ').forEach(function (oneEvent) { + element.removeEventListener(oneEvent, that.onEvent); + }); // Update the initial distances between elements + + that.getDistances(); // Update everyone listening for events + + that.fireEvent(element); + that.updateDisableHandlers(); + }; + /** + * Remove a target element from this synchronizer + * + * @param {HTMLElement} element - The element to be removed + * @returns {void} + */ + + + this.removeTarget = function (element) { + // Find the index of this element + var index = targetElements.indexOf(element); + + if (index === -1) { + return; + } // Remove this element from the array + + + targetElements.splice(index, 1); // Update the initial distances between elements + + that.getDistances(); // Invoke the handler for the removed target + + eventHandler(that, element, element, 0); + that.updateDisableHandlers(); + }; + /** + * Remove an element from this synchronizer as both a target and source + * + * @param {HTMLElement} element - The element to be removed + * @returns {void} + */ + + + this.remove = function (element) { + that.removeTarget(element); + that.removeSource(element); + }; + /** + * Get the array of source elements + * + * @returns {HTMLElement[]} + */ + + + this.getSourceElements = function () { + return sourceElements; + }; + /** + * Get the array of target elements + * + * @returns {HTMLElement[]} + */ + + + this.getTargetElements = function () { + return targetElements; + }; + /** + * Display an image while halting synchronization + * + * @param {HTMLElement} element - The element containing the image + * @param {Object} image - The cornerstone image object + * @param {Object} viewport - The cornerstone viewport object + * @returns {void} + */ + + + this.displayImage = function (element, image, viewport) { + ignoreFiredEvents = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.displayImage(element, image, viewport); + ignoreFiredEvents = false; + }; + /** + * Update a viewport while halting synchronization + * + * @param {HTMLElement} element - The target element + * @param {Object} viewport - The new cornerstone viewport object + * @returns {void} + */ + + + this.setViewport = function (element, viewport) { + ignoreFiredEvents = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.setViewport(element, viewport); + ignoreFiredEvents = false; + }; + /** + * Remove an element from the synchronizer based on an event from that element + * + * @private + * @param {Event} e - The event whose element will be removed + * @returns {void} + */ + + + function disableHandler(e) { + var element = e.detail.element; + that.remove(element); + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_2__["clearToolOptionsByElement"])(element); + } + /** + * Add an event listener to each element that can remove it from the synchronizer + * @returns {void} + */ + + + this.updateDisableHandlers = function () { + var elements = unique(sourceElements.concat(targetElements)); + elements.forEach(function (element) { + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.ELEMENT_DISABLED, disableHandler); + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.ELEMENT_DISABLED, disableHandler); + }); + }; + /** + * Remove all elements from this synchronizer + * @returns {void} + */ + + + this.destroy = function () { + var elements = unique(sourceElements.concat(targetElements)); + elements.forEach(function (element) { + that.remove(element); + }); + }; +} + +/* harmony default export */ __webpack_exports__["default"] = (Synchronizer); + +/***/ }), + +/***/ "./synchronization/panZoomSynchronizer.js": +/*!************************************************!*\ + !*** ./synchronization/panZoomSynchronizer.js ***! + \************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Synchronize the target zoom and pan to match the source + * @export + * @public + * @method + * @name panZoomSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element for the zoom and pan values + * @param {HTMLElement} targetElement - The target element + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; // Get the source and target viewports + + var sourceViewport = cornerstone.getViewport(sourceElement); + var targetViewport = cornerstone.getViewport(targetElement); // Do nothing if the scale and translation are the same + + if (targetViewport.scale === sourceViewport.scale && targetViewport.translation.x === sourceViewport.translation.x && targetViewport.translation.y === sourceViewport.translation.y) { + return; + } // Scale and/or translation are different, sync them + + + targetViewport.scale = sourceViewport.scale; + targetViewport.translation.x = sourceViewport.translation.x; + targetViewport.translation.y = sourceViewport.translation.y; + synchronizer.setViewport(targetElement, targetViewport); +}); + +/***/ }), + +/***/ "./synchronization/stackImageIndexSynchronizer.js": +/*!********************************************************!*\ + !*** ./synchronization/stackImageIndexSynchronizer.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); + + + + +/** + * Synchronize the target stack to the index closest to the source stack's index + * @export + * @public + * @method + * @name stackImageIndexSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element for the index value + * @param {HTMLElement} targetElement - The target element + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var sourceStackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(sourceElement, 'stack'); + var sourceStackData = sourceStackToolDataSource.data[0]; + var targetStackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(targetElement, 'stack'); + var targetStackData = targetStackToolDataSource.data[0]; + var newImageIdIndex = sourceStackData.currentImageIdIndex; // Clamp the index + + newImageIdIndex = Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_3__["default"])(newImageIdIndex, 0, targetStackData.imageIds.length - 1); // Do nothing if the index has not changed + + if (newImageIdIndex === targetStackData.currentImageIdIndex) { + return; + } + + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getStartLoadHandler(targetElement); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getEndLoadHandler(targetElement); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorLoadingHandler(targetElement); + + if (startLoadingHandler) { + startLoadingHandler(targetElement); + } + + var loader; + + if (targetStackData.preventCache === true) { + loader = cornerstone.loadImage(targetStackData.imageIds[newImageIdIndex]); + } else { + loader = cornerstone.loadAndCacheImage(targetStackData.imageIds[newImageIdIndex]); + } + + loader.then(function (image) { + var viewport = cornerstone.getViewport(targetElement); + targetStackData.currentImageIdIndex = newImageIdIndex; + synchronizer.displayImage(targetElement, image, viewport); + + if (endLoadingHandler) { + endLoadingHandler(targetElement, image); + } + }, function (error) { + var imageId = targetStackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(targetElement, imageId, error); + } + }); +}); + +/***/ }), + +/***/ "./synchronization/stackImagePositionOffsetSynchronizer.js": +/*!*****************************************************************!*\ + !*** ./synchronization/stackImagePositionOffsetSynchronizer.js ***! + \*****************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); + + + + // In the future we will want to have a way to manually register links sets of the same orientation (e.g. an axial link set from a prior with an axial link set of a current). The user could do this by scrolling the two stacks to a similar location and then doing a user action (e.g. right click link) at which point the system will capture the delta between the image position (patient) of both stacks and use that to sync them. This offset will need to be adjustable. + +/** + * Calculate a position in space that is offset from the source image's position, + * and synchronize the target stack to the image that is closest to that position. + * @export + * @public + * @method + * @name stackImagePositionOffsetSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element + * @param {HTMLElement} targetElement - The target element + * @param {Object} eventData - The data object from the triggering event + * @param {Object} positionDifference - An object with { x, y, z } values that will be + * added to the source image's coordinates + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement, eventData, positionDifference) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var sourceStackData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(sourceElement, 'stack').data[0]; + var sourceImageId = sourceStackData.imageIds[sourceStackData.currentImageIdIndex]; + var sourceImagePlane = cornerstone.metaData.get('imagePlaneModule', sourceImageId); + + if (sourceImagePlane === undefined || sourceImagePlane.imagePositionPatient === undefined) { + return; + } + + var sourceImagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(sourceImagePlane.imagePositionPatient); + var stackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(targetElement, 'stack'); + var stackData = stackToolDataSource.data[0]; + var minDistance = Number.MAX_VALUE; + var newImageIdIndex = -1; + + if (!positionDifference) { + return; + } + + var finalPosition = sourceImagePosition.clone().add(positionDifference); + stackData.imageIds.forEach(function (imageId, index) { + var imagePlane = cornerstone.metaData.get('imagePlaneModule', imageId); + + if (imagePlane === undefined || imagePlane.imagePositionPatient === undefined) { + return; + } + + var imagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(imagePlane.imagePositionPatient); + var distance = finalPosition.distanceToSquared(imagePosition); + + if (distance < minDistance) { + minDistance = distance; + newImageIdIndex = index; + } + }); + + if (newImageIdIndex === stackData.currentImageIdIndex || newImageIdIndex === -1) { + return; + } + + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getStartLoadHandler(targetElement); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getEndLoadHandler(targetElement); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorLoadingHandler(targetElement); + stackData.currentImageIdIndex = newImageIdIndex; + var newImageId = stackData.imageIds[newImageIdIndex]; + + if (startLoadingHandler) { + startLoadingHandler(targetElement); + } + + var loader; + + if (stackData.preventCache === true) { + loader = cornerstone.loadImage(newImageId); + } else { + loader = cornerstone.loadAndCacheImage(newImageId); + } + + loader.then(function (image) { + var viewport = cornerstone.getViewport(targetElement); + + if (stackData.currentImageIdIndex !== newImageIdIndex) { + return; + } + + synchronizer.displayImage(targetElement, image, viewport); + + if (endLoadingHandler) { + endLoadingHandler(targetElement, image); + } + }, function (error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(targetElement, imageId, error); + } + }); +}); + +/***/ }), + +/***/ "./synchronization/stackImagePositionSynchronizer.js": +/*!***********************************************************!*\ + !*** ./synchronization/stackImagePositionSynchronizer.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); + + + + +/** + * Synchronize the target stack to the image closest to the source image's position + * @export + * @public + * @method + * @name stackImagePositionSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element for the image position + * @param {HTMLElement} targetElement - The target element + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var sourceStackData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(sourceElement, 'stack').data[0]; + var sourceImageId = sourceStackData.imageIds[sourceStackData.currentImageIdIndex]; + var sourceImagePlane = cornerstone.metaData.get('imagePlaneModule', sourceImageId); + + if (sourceImagePlane === undefined || sourceImagePlane.imagePositionPatient === undefined) { + // Console.log('No position found for image ' + sourceImage.imageId); + return; + } + + var sourceImagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(sourceImagePlane.imagePositionPatient); + var stackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(targetElement, 'stack'); + var stackData = stackToolDataSource.data[0]; + var minDistance = Number.MAX_VALUE; + var newImageIdIndex = -1; + stackData.imageIds.forEach(function (imageId, index) { + var imagePlane = cornerstone.metaData.get('imagePlaneModule', imageId); + + if (imagePlane === undefined || imagePlane.imagePositionPatient === undefined) { + // Console.log('No position found for image ' + imageId); + return; + } + + var imagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(imagePlane.imagePositionPatient); + var distance = imagePosition.distanceToSquared(sourceImagePosition); // Console.log(index + '=' + distance); + + if (distance < minDistance) { + minDistance = distance; + newImageIdIndex = index; + } + }); + + if (newImageIdIndex === stackData.currentImageIdIndex) { + return; + } + + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getStartLoadHandler(targetElement); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getEndLoadHandler(targetElement); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorLoadingHandler(targetElement); + stackData.currentImageIdIndex = newImageIdIndex; + var newImageId = stackData.imageIds[newImageIdIndex]; + + if (startLoadingHandler) { + startLoadingHandler(targetElement); + } + + if (newImageIdIndex !== -1) { + var loader; + + if (stackData.preventCache === true) { + loader = cornerstone.loadImage(newImageId); + } else { + loader = cornerstone.loadAndCacheImage(newImageId); + } + + loader.then(function (image) { + var viewport = cornerstone.getViewport(targetElement); + + if (stackData.currentImageIdIndex !== newImageIdIndex) { + return; + } + + synchronizer.displayImage(targetElement, image, viewport); + + if (endLoadingHandler) { + endLoadingHandler(targetElement, image); + } + }, function (error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(targetElement, imageId, error); + } + }); + } +}); + +/***/ }), + +/***/ "./synchronization/stackScrollSynchronizer.js": +/*!****************************************************!*\ + !*** ./synchronization/stackScrollSynchronizer.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); + + + + +/** + * Propogate scrolling actions from the source element to the target element. + * @export + * @public + * @method + * @name stackScrollSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element for the scroll event + * @param {HTMLElement} targetElement - The target element + * @param {Object} eventData - The data object from the triggering event + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement, eventData) { + // If the target and source are the same, stop + if (sourceElement === targetElement) { + return; + } // If there is no event, or direction is 0, stop + + + if (!eventData || !eventData.direction) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; // Get the stack of the target viewport + + var stackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(targetElement, 'stack'); + var stackData = stackToolDataSource.data[0]; // Get the new index for the stack + + var newImageIdIndex = stackData.currentImageIdIndex + eventData.direction; // Ensure the index does not exceed the bounds of the stack + + newImageIdIndex = Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_3__["default"])(newImageIdIndex, 0, stackData.imageIds.length - 1); // If the index has not changed, stop here + + if (stackData.currentImageIdIndex === newImageIdIndex) { + return; + } + + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getStartLoadHandler(targetElement); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getEndLoadHandler(targetElement); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorLoadingHandler(targetElement); + stackData.currentImageIdIndex = newImageIdIndex; + var newImageId = stackData.imageIds[newImageIdIndex]; + + if (startLoadingHandler) { + startLoadingHandler(targetElement); + } + + var loader; + + if (stackData.preventCache === true) { + loader = cornerstone.loadImage(newImageId); + } else { + loader = cornerstone.loadAndCacheImage(newImageId); + } + + loader.then(function (image) { + var viewport = cornerstone.getViewport(targetElement); + + if (stackData.currentImageIdIndex !== newImageIdIndex) { + return; + } + + synchronizer.displayImage(targetElement, image, viewport); + + if (endLoadingHandler) { + endLoadingHandler(targetElement, image); + } + }, function (error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(targetElement, imageId, error); + } + }); +}); + +/***/ }), + +/***/ "./synchronization/updateImageSynchronizer.js": +/*!****************************************************!*\ + !*** ./synchronization/updateImageSynchronizer.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Redraw target image immediately any time handler is called from source element. + * @export + * @public + * @method + * @name updateImageSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element + * @param {HTMLElement} targetElement - The target element + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(targetElement); +}); + +/***/ }), + +/***/ "./synchronization/wwwcSynchronizer.js": +/*!*********************************************!*\ + !*** ./synchronization/wwwcSynchronizer.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Synchronize the target viewport ww/wc to match the source element. + * @export + * @public + * @method + * @name wwwcSynchronizer + * + * @param {Object} synchronizer - The Synchronizer instance that attaches this + * handler to an event + * @param {HTMLElement} sourceElement - The source element for the ww/wc values + * @param {HTMLElement} targetElement - The target element + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (synchronizer, sourceElement, targetElement) { + // Ignore the case where the source and target are the same enabled element + if (targetElement === sourceElement) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; // Get the source and target viewports + + var sourceViewport = cornerstone.getViewport(sourceElement); + var targetViewport = cornerstone.getViewport(targetElement); // Do nothing if the ww/wc already match + + if (targetViewport.voi.windowWidth === sourceViewport.voi.windowWidth && targetViewport.voi.windowCenter === sourceViewport.voi.windowCenter && targetViewport.invert === sourceViewport.invert) { + return; + } // Www/wc are different, sync them + + + targetViewport.voi.windowWidth = sourceViewport.voi.windowWidth; + targetViewport.voi.windowCenter = sourceViewport.voi.windowCenter; + targetViewport.invert = sourceViewport.invert; + synchronizer.setViewport(targetElement, targetViewport); +}); + +/***/ }), + +/***/ "./thirdParty/register.js": +/*!********************************!*\ + !*** ./thirdParty/register.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _registerModule_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./registerModule.js */ "./thirdParty/registerModule.js"); +/* harmony import */ var _registerMixin_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./registerMixin.js */ "./thirdParty/registerMixin.js"); +/* harmony import */ var _registerItem_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./registerItem.js */ "./thirdParty/registerItem.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('thirdParty:register'); +/** + * Register an item or module to cornerstoneTools. + * @export + * @public + * @method + * @name register + * + * @param {string} type The type of the item/module. + * @param {string} name The name of the item/module. + * @param {Object|function} item The item/module itself. + * @param {boolean} [overwrite=false] Whether an item/module should be + * overwritten, should it have the same name. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (type, name, item) { + var overwrite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + + if (!isValidInput(type, name, item)) { + return; + } + + switch (type) { + case 'module': + Object(_registerModule_js__WEBPACK_IMPORTED_MODULE_1__["default"])(name, item, overwrite); + break; + + case 'mixin': + Object(_registerMixin_js__WEBPACK_IMPORTED_MODULE_2__["default"])(name, item, overwrite); + break; + + default: + Object(_registerItem_js__WEBPACK_IMPORTED_MODULE_3__["default"])(type, name, item, overwrite); + } +}); +/** + * Returns true if the item is valid, this avoids + * clogging up the library with invalid data. + * @private + * @method + * @name isValidInput + * + * @param {string} type The type of the item/module. + * @param {string} name The name of the item/module. + * @param {Object|function} item The item/module itself. + * @returns {boolean} Whether the input is valid. + */ + +function isValidInput(type, name, item) { + if (!type) { + logger.warn('The type must be given in order to register.'); + return false; + } + + if (!name) { + logger.warn("The %s must have a name in order to register.", type); + return false; + } + + if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(item) !== 'object' && typeof item !== 'function') { + logger.warn("The %s is a %s, it should be an Object or a function.", item, _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(item)); + return false; + } + + return true; +} + +/***/ }), + +/***/ "./thirdParty/registerItem.js": +/*!************************************!*\ + !*** ./thirdParty/registerItem.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../lib.js */ "./lib.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_1__["getLogger"])('thirdParty:registerType'); +/** + * Register an item to cornerstoneTools. + * @export + * @private + * @method + * @name registerItem + * + * @param {string} type The type of the item. + * @param {string} name The name of the item. + * @param {Object|function} item The item itself. + * @param {boolean} [overwrite=false] Whether an item should be overwritten, + * should it have the same name. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (type, name, item) { + var overwrite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + var itemKey = "".concat(type, "/").concat(name); + var alreadyRegistered = isItemNameRegistered(itemKey); + + if (alreadyRegistered && !overwrite) { + logger.warn('%s is already registered', itemKey); + return; + } + + if (alreadyRegistered) { + logger.warn('Overwriting %s', itemKey); + } + + _lib_js__WEBPACK_IMPORTED_MODULE_0__["lib"][itemKey] = item; +}); + +function isItemNameRegistered(itemKey) { + return _lib_js__WEBPACK_IMPORTED_MODULE_0__["lib"][itemKey] !== undefined; +} + +/***/ }), + +/***/ "./thirdParty/registerMixin.js": +/*!*************************************!*\ + !*** ./thirdParty/registerMixin.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../lib.js */ "./lib.js"); +/* harmony import */ var _mixins_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../mixins/index.js */ "./mixins/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_2__["getLogger"])('thirdParty:registerMixin'); +/** + * Register an mixin to cornerstoneTools. + * @export + * @private + * @method + * @name registerMixin + * + * @param {string} name The name of the mixin. + * @param {Object} mixin The mixin itself. + * @param {boolean} [overwrite=false] Whether an mixin should be overwritten, + * should it have the same name. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (name, mixin) { + var overwrite = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var alreadyRegistered = isMixinRegistered(name); + + if (alreadyRegistered && !overwrite) { + logger.warn('mixins/%s is already registered', name); + return; + } + + if (alreadyRegistered) { + logger.warn('Overwriting mixins/%s', name); + } // Register to the mixins object + + + _mixins_index_js__WEBPACK_IMPORTED_MODULE_1__["default"][name] = mixin; // Reference the mixin from the library so it can be exported externally. + + _lib_js__WEBPACK_IMPORTED_MODULE_0__["lib"]["mixins/".concat(name)] = _mixins_index_js__WEBPACK_IMPORTED_MODULE_1__["default"][name]; +}); + +function isMixinRegistered(name) { + return _mixins_index_js__WEBPACK_IMPORTED_MODULE_1__["default"][name] !== undefined; +} + +/***/ }), + +/***/ "./thirdParty/registerModule.js": +/*!**************************************!*\ + !*** ./thirdParty/registerModule.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_1__["getLogger"])('thirdParty:registerModule'); +/** + * Register a module. + * @export + * @private + * @method + * @name registerModule + * + * @param {string} name The name of the module. + * @param {Object} newModule The module to register. + * @param {boolean} [overwrite] Whether a module should be overwritten, + * should it have the same name. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (name, newModule) { + var overwrite = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var alreadyRegistered = isModuleNameRegistered(name); + + if (alreadyRegistered && !overwrite) { + logger.warn('A module with the name %s is already registered', name); + return; + } + + if (alreadyRegistered) { + logger.warn('Overwriting module %s', name); + } + + _store_index_js__WEBPACK_IMPORTED_MODULE_0__["modules"][name] = newModule; + + if (typeof _store_index_js__WEBPACK_IMPORTED_MODULE_0__["modules"][name].onRegisterCallback === 'function') { + _store_index_js__WEBPACK_IMPORTED_MODULE_0__["modules"][name].onRegisterCallback(); + } +}); + +function isModuleNameRegistered(name) { + return _store_index_js__WEBPACK_IMPORTED_MODULE_0__["modules"][name] !== undefined; +} + +/***/ }), + +/***/ "./thirdParty/registerSome.js": +/*!************************************!*\ + !*** ./thirdParty/registerSome.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _register_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./register.js */ "./thirdParty/register.js"); + +/** + * Register an array of items and/or modules to cornerstoneTools. + * @export + * @public + * @method + * @name registerSome + * + * @param {Object[]} items An array of items/modules to register. + * @param {boolean} [overwrite=false] Whether an item/module should be + * overwritten, should it have the same name. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (items) { + var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + items.forEach(function (_ref) { + var type = _ref.type, + name = _ref.name, + item = _ref.item; + Object(_register_js__WEBPACK_IMPORTED_MODULE_0__["default"])(type, name, item, overwrite); + }); +}); + +/***/ }), + +/***/ "./toolOptions.js": +/*!************************!*\ + !*** ./toolOptions.js ***! + \************************/ +/*! exports provided: getToolOptions, setToolOptions, clearToolOptions, clearToolOptionsByToolType, clearToolOptionsByToolName, clearToolOptionsByElement */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getToolOptions", function() { return getToolOptions; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setToolOptions", function() { return setToolOptions; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clearToolOptions", function() { return clearToolOptions; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clearToolOptionsByToolType", function() { return clearToolOptionsByToolType; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clearToolOptionsByToolName", function() { return clearToolOptionsByToolName; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clearToolOptionsByElement", function() { return clearToolOptionsByElement; }); +var elementToolOptions = {}; +/** + * Retrieve the options object associated with a particular toolName and element + * @export + * @public + * @method + * @name getToolOptions + * + * @param {string} toolName Tool name identifier of the target options object + * @param {HTMLElement} element Element of the target options object + * + * @returns {Object} Target options object (empty if not yet set) + */ + +function getToolOptions(toolName, element) { + if (!elementToolOptions[toolName]) { + return {}; + } + + var toolOptions = elementToolOptions[toolName]; + var optionsObject = toolOptions.find(function (toolOptionObject) { + return toolOptionObject.element === element; + }); + + if (!optionsObject) { + return {}; + } + + return optionsObject.options; +} +/** + * Set the options object associated with a particular toolName and element. + * @export + * @public + * @method + * @name setToolOptions + * + * @param {string} toolName Tool name identifier of the target options object. + * @param {HTMLElement} element Element of the target options object. + * @param {Object} options Options object to store at target. + * @returns {void} + */ + + +function setToolOptions(toolName, element, options) { + if (!elementToolOptions[toolName]) { + elementToolOptions[toolName] = [{ + element: element, + options: options + }]; + return; + } + + var toolOptions = elementToolOptions[toolName]; + var index = toolOptions.findIndex(function (toolOptionObject) { + return toolOptionObject.element === element; + }); + + if (index === -1) { + elementToolOptions[toolName].push({ + element: element, + options: options + }); + } else { + var elementOptions = elementToolOptions[toolName][index].options || {}; + elementToolOptions[toolName][index].options = Object.assign(elementOptions, options); + } +} +/** + * Clear the options object associated with a particular toolName and element. + * @export + * @public + * @method + * @name clearToolOptions + * + * @param {string} toolName Tool name identifier of the target options object. + * @param {HTMLElement} element Element of the target options object. + * @returns {void} + */ + + +function clearToolOptions(toolName, element) { + var toolOptions = elementToolOptions[toolName]; + + if (toolOptions) { + elementToolOptions[toolName] = toolOptions.filter(function (toolOptionObject) { + return toolOptionObject.element !== element; + }); + } +} +/** + * Clear the options objects associated with a particular toolType. + * + * Deprecation notice: use clearToolOptionsByToolName instead + * @deprecated + * + * @export + * @public + * @method + * @name clearToolOptionsByToolType + * + * @param {string} toolType Tool type identifier of the target options objects. + * @returns {void} + */ + + +function clearToolOptionsByToolType(toolType) { + return clearToolOptionsByToolName(toolType); +} +/** + * Clear the options objects associated with a particular toolName. + * @export + * @public + * @method + * @name clearToolOptionsByToolName + * + * @param {string} toolName Tool name identifier of the target options objects. + * @returns {void} + */ + + +function clearToolOptionsByToolName(toolName) { + delete elementToolOptions[toolName]; +} +/** + * Clear the options objects associated with a particular element. + * @export + * @public + * @method + * @name clearToolOptionsByElement + * + * @param {HTMLElement} element Element of the target options objects. + * @returns {void} + */ + + +function clearToolOptionsByElement(element) { + for (var toolName in elementToolOptions) { + elementToolOptions[toolName] = elementToolOptions[toolName].filter(function (toolOptionObject) { + return toolOptionObject.element !== element; + }); + } +} + + + +/***/ }), + +/***/ "./tools/CrosshairsTool.js": +/*!*********************************!*\ + !*** ./tools/CrosshairsTool.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CrosshairsTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/pointProjector.js */ "./util/pointProjector.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); +/* harmony import */ var _toolOptions_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../toolOptions.js */ "./toolOptions.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + + + + +/** + * @public + * @class CrosshairsTool + * @memberof Tools + * + * @classdesc Tool for finding the slice in another element corresponding to the + * image position in a synchronized image series. + * @extends Tools.Base.BaseTool + */ + +var CrosshairsTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(CrosshairsTool, _BaseTool); + + function CrosshairsTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, CrosshairsTool); + + var defaultProps = { + name: 'Crosshairs', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__["crosshairsCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(CrosshairsTool).call(this, props, defaultProps)); + _this.preMouseDownCallback = _this._chooseLocation.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.mouseDragCallback = _this._chooseLocation.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchDragCallback = _this._chooseLocation.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(CrosshairsTool, [{ + key: "_chooseLocation", + value: function _chooseLocation(evt) { + var eventData = evt.detail; + var element = eventData.element; // Prevent CornerstoneToolsTouchStartActive from killing any press events + + evt.stopImmediatePropagation(); // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + + if (!toolData) { + return; + } // Get current element target information + + + var sourceElement = element; + var sourceEnabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.getEnabledElement(sourceElement); + var sourceImageId = sourceEnabledElement.image.imageId; + var sourceImagePlane = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.metaData.get('imagePlaneModule', sourceImageId); + + if (!sourceImagePlane) { + return; + } // Get currentPoints from mouse cursor on selected element + + + var sourceImagePoint = eventData.currentPoints.image; // Transfer this to a patientPoint given imagePlane metadata + + var patientPoint = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_10__["imagePointToPatientPoint"])(sourceImagePoint, sourceImagePlane); // Get the enabled elements associated with this synchronization context + + var syncContext = toolData.data[0].synchronizationContext; + var enabledElements = syncContext.getSourceElements(); // Iterate over each synchronized element + + enabledElements.forEach(function (targetElement) { + // Don't do anything if the target is the same as the source + if (targetElement === sourceElement) { + return; + } + + var minDistance = Number.MAX_VALUE; + var newImageIdIndex = -1; + var stackToolDataSource = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(targetElement, 'stack'); + + if (stackToolDataSource === undefined) { + return; + } + + var stackData = stackToolDataSource.data[0]; // Find within the element's stack the closest image plane to selected location + + stackData.imageIds.forEach(function (imageId, index) { + var imagePlane = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.metaData.get('imagePlaneModule', imageId); // Skip if the image plane is not ready + + if (!imagePlane || !imagePlane.imagePositionPatient || !imagePlane.rowCosines || !imagePlane.columnCosines) { + return; + } + + var imagePosition = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_11__["default"])(imagePlane.imagePositionPatient); + var row = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_11__["default"])(imagePlane.rowCosines); + var column = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_11__["default"])(imagePlane.columnCosines); + var normal = column.clone().cross(row.clone()); + var distance = Math.abs(normal.clone().dot(imagePosition) - normal.clone().dot(patientPoint)); + + if (distance < minDistance) { + minDistance = distance; + newImageIdIndex = index; + } + }); + + if (newImageIdIndex === stackData.currentImageIdIndex) { + return; + } // Switch the loaded image to the required image + + + if (newImageIdIndex !== -1 && stackData.imageIds[newImageIdIndex] !== undefined) { + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_8__["default"].getStartLoadHandler(targetElement); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_8__["default"].getEndLoadHandler(targetElement); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_8__["default"].getErrorLoadingHandler(targetElement); + + if (startLoadingHandler) { + startLoadingHandler(targetElement); + } + + var loader; + + if (stackData.preventCache === true) { + loader = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.loadImage(stackData.imageIds[newImageIdIndex]); + } else { + loader = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.loadAndCacheImage(stackData.imageIds[newImageIdIndex]); + } + + loader.then(function (image) { + var viewport = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.getViewport(targetElement); + stackData.currentImageIdIndex = newImageIdIndex; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.displayImage(targetElement, image, viewport); + + if (endLoadingHandler) { + endLoadingHandler(targetElement, image); + } + }, function (error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(targetElement, imageId, error); + } + }); + } + }); + } + }, { + key: "activeCallback", + value: function activeCallback(element, _ref) { + var mouseButtonMask = _ref.mouseButtonMask, + synchronizationContext = _ref.synchronizationContext; + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_12__["setToolOptions"])(this.name, element, { + mouseButtonMask: mouseButtonMask + }); // Clear any currently existing toolData + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["clearToolState"])(element, this.name); + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["addToolState"])(element, this.name, { + synchronizationContext: synchronizationContext + }); + } + }]); + + return CrosshairsTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/DoubleTapFitToWindowTool.js": +/*!*******************************************!*\ + !*** ./tools/DoubleTapFitToWindowTool.js ***! + \*******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return DoubleTapFitToWindowTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); + + + + + + + +/** + * @public + * @class DoubleTapFitToWindowTool + * @memberof Tools + * + * @classdesc Tool which calls the external cornerstone.fitToWindow() function + * on double tap. + * @extends Tools.Base.BaseTool + */ + +var DoubleTapFitToWindowTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(DoubleTapFitToWindowTool, _BaseTool); + + function DoubleTapFitToWindowTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, DoubleTapFitToWindowTool); + + var defaultProps = { + name: 'DoubleTapFitToWindow', + supportedInteractionTypes: ['DoubleTap'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(DoubleTapFitToWindowTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(DoubleTapFitToWindowTool, [{ + key: "doubleTapCallback", + value: function doubleTapCallback(evt) { + var eventData = evt.detail; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.fitToWindow(eventData.element); + } + }]); + + return DoubleTapFitToWindowTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/DragProbeTool.js": +/*!********************************!*\ + !*** ./tools/DragProbeTool.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return DragProbeTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/getRGBPixels.js */ "./util/getRGBPixels.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + + + + + +/** + * @public + * @class DragProbeTool + * @memberof Tools + * + * @classdesc Tool which provides a probe of the image data at the + * input position on drag. + * @extends Tools.Base.BaseTool + */ + +var DragProbeTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(DragProbeTool, _BaseTool); + + function DragProbeTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, DragProbeTool); + + var defaultProps = { + name: 'DragProbe', + strategies: { + default: defaultStrategy, + minimal: minimalStrategy + }, + defaultStrategy: 'default', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_14__["probeCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(DragProbeTool).call(this, props, defaultProps)); + _this.touchDragCallback = _this._movingEventCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchEndCallback = _this._endMovingEventCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.mouseDragCallback = _this._movingEventCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.mouseUpCallback = _this._endMovingEventCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.dragEventData = {}; + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(DragProbeTool, [{ + key: "_movingEventCallback", + value: function _movingEventCallback(evt) { + var eventData = evt.detail; + var element = eventData.element; + this.dragEventData = eventData; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + } + }, { + key: "_endMovingEventCallback", + value: function _endMovingEventCallback(evt) { + var eventData = evt.detail; + var element = eventData.element; + this.dragEventData = {}; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + if (!this.dragEventData.currentPoints) { + return; + } + + if (evt && evt.detail && Boolean(Object.keys(this.dragEventData.currentPoints).length)) { + evt.detail.currentPoints = this.dragEventData.currentPoints; + this.applyActiveStrategy(evt); + } + } + }]); + + return DragProbeTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); +/** + * Default strategy will pick the exactly point of mouse/touch interact and display the probe data. + * + * @param {Object} evt Image rendered event + * @returns {void} + */ + + + + +function defaultStrategy(evt) { + var config = this.configuration; + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone; + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image, + currentPoints = eventData.currentPoints, + canvasContext = eventData.canvasContext; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["getNewContext"])(canvasContext.canvas); + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getActiveColor(); + var fontHeight = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize(); + var x = Math.round(currentPoints.image.x); + var y = Math.round(currentPoints.image.y); + + if (x < 0 || y < 0 || x >= image.columns || y >= image.rows) { + return; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["setShadow"])(context, config); + var text = "".concat(x, ", ").concat(y); + var storedPixels; + var str; + + if (image.color) { + storedPixels = Object(_util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_10__["default"])(element, x, y, 1, 1); + str = "R: ".concat(storedPixels[0], " G: ").concat(storedPixels[1], " B: ").concat(storedPixels[2], " A: ").concat(storedPixels[3]); + } else { + storedPixels = cornerstone.getStoredPixels(element, x, y, 1, 1); + var sp = storedPixels[0]; + var mo = sp * image.slope + image.intercept; + var suv = Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__["default"])(image, sp); // Draw text + + str = "SP: ".concat(sp, " MO: ").concat(parseFloat(mo.toFixed(3))); + + if (suv) { + str += " SUV: ".concat(parseFloat(suv.toFixed(3))); + } + } // Draw text 5px away from cursor + + + var textCoords = { + x: currentPoints.canvas.x + 5, + y: currentPoints.canvas.y - 5 + }; + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__["default"])(context, str, textCoords.x, textCoords.y + fontHeight + 5, color); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__["default"])(context, text, textCoords.x, textCoords.y, color); + }); +} +/** + * Minimal strategy will position a circle and use the center of the circle to calculate and display probe data. + * + * @param {Object} evt Image rendered event + * @returns {void} + */ + + +function minimalStrategy(evt) { + var config = this.configuration; + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone; + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image, + currentPoints = eventData.currentPoints, + canvasContext = eventData.canvasContext, + isTouchEvent = eventData.isTouchEvent; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["getNewContext"])(canvasContext.canvas); + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getActiveColor(); + var pageCoordY = currentPoints.page.y - _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize() / 2; + + if (isTouchEvent) { + pageCoordY = currentPoints.page.y - _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize() * 4; + } + + var toolCoords = cornerstone.pageToPixel(element, currentPoints.page.x, pageCoordY); + + if (toolCoords.x < 0 || toolCoords.y < 0 || toolCoords.x >= image.columns || toolCoords.y >= image.rows) { + return; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["setShadow"])(context, config); + var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId); + var modality = seriesModule && seriesModule.modality; + var storedPixels; + var text = ''; + + if (image.color) { + storedPixels = Object(_util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_10__["default"])(element, toolCoords.x, toolCoords.y, 1, 1); + text = "R: ".concat(storedPixels[0], " G: ").concat(storedPixels[1], " B: ").concat(storedPixels[2]); + } else { + storedPixels = cornerstone.getStoredPixels(element, toolCoords.x, toolCoords.y, 1, 1); + var sp = storedPixels[0]; + var mo = sp * image.slope + image.intercept; + var modalityPixelValueText = parseFloat(mo.toFixed(2)); + + if (modality === 'CT') { + text += "HU: ".concat(modalityPixelValueText); + } else if (modality === 'PT') { + text += modalityPixelValueText; + var suv = Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__["default"])(image, sp); + + if (suv) { + text += " SUV: ".concat(parseFloat(suv.toFixed(2))); + } + } else { + text += modalityPixelValueText; + } + } // Prepare text + + + var textCoords = cornerstone.pixelToCanvas(element, toolCoords); // Translate the x/y away from the cursor + + var translation = { + x: 12, + y: -(_stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize() + 10) / 2 + }; + var handleRadius = 6; + var padding = 5; + var width = Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__["textBoxWidth"])(context, text, padding); + + if (isTouchEvent) { + translation = { + x: -width / 2, + y: -_stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize() - 10 - 2 * handleRadius + }; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["drawCircle"])(context, element, textCoords, handleRadius, { + color: color + }, 'canvas'); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__["default"])(context, text, textCoords.x + translation.x, textCoords.y + translation.y, color); + }); +} + +/***/ }), + +/***/ "./tools/EraserTool.js": +/*!*****************************!*\ + !*** ./tools/EraserTool.js ***! + \*****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return EraserTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../store/index.js */ "./store/index.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + +/** + * @public + * @class EraserTool + * @memberof Tools + * + * @classdesc Tool for deleting the data of other Annotation Tools. + * @extends Tools.Base.BaseTool + */ + +var EraserTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(EraserTool, _BaseTool); + + function EraserTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, EraserTool); + + var defaultProps = { + name: 'Eraser', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__["eraserCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(EraserTool).call(this, props, defaultProps)); + _this.preMouseDownCallback = _this._deleteAllNearbyTools.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.preTouchStartCallback = _this._deleteAllNearbyTools.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(EraserTool, [{ + key: "_deleteAllNearbyTools", + value: function _deleteAllNearbyTools(evt) { + var coords = evt.detail.currentPoints.canvas; + var element = evt.detail.element; + _store_index_js__WEBPACK_IMPORTED_MODULE_9__["state"].tools.forEach(function (tool) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["getToolState"])(element, tool.name); + + if (toolState) { + // Modifying in a foreach? Probably not ideal + toolState.data.forEach(function (data) { + if (typeof tool.pointNearTool === 'function' && tool.pointNearTool(element, data, coords)) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["removeToolState"])(element, tool.name, data); + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + } + }); + } + }); + var consumeEvent = true; + return consumeEvent; + } + }]); + + return EraserTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); + + + +/***/ }), + +/***/ "./tools/FreehandRoiSculptorTool.js": +/*!******************************************!*\ + !*** ./tools/FreehandRoiSculptorTool.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FreehandRoiSculptorTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../store/index.js */ "./store/index.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../store/getToolForElement.js */ "./store/getToolForElement.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../store/setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../util/freehand/index.js */ "./util/freehand/index.js"); + + + + + + + + + + + + + + + + + + +var FreehandHandleData = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_17__["default"].FreehandHandleData; +/** + * @public + * @class FreehandRoiSculptorTool + * @memberof Tools + * + * @classdesc Tool for easily sculpting annotations drawn with + * the FreehandRoiTool. + * @extends Tools.Base.BaseTool + */ + +var FreehandRoiSculptorTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(FreehandRoiSculptorTool, _BaseTool); + + function FreehandRoiSculptorTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FreehandRoiSculptorTool); + + var defaultProps = { + name: 'FreehandRoiSculptor', + referencedToolName: 'FreehandRoi', + supportedInteractionTypes: ['Mouse', 'Touch', 'DoubleTap'], + mixins: ['activeOrDisabledBinaryTool'], + configuration: getDefaultFreehandRoiSculptorToolConfiguration(), + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_16__["freehandRoiSculptorCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(FreehandRoiSculptorTool).call(this, props, defaultProps)); + _this.updateOnMouseMove = true; + _this.isMultiPartTool = true; + _this.referencedToolName = _this.initialConfiguration.referencedToolName; + _this._active = false; // Create bound functions for private event loop. + + _this.activeMouseUpCallback = _this.activeMouseUpCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.activeTouchEndCallback = _this.activeTouchEndCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.activeMouseDragCallback = _this.activeMouseDragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(FreehandRoiSculptorTool, [{ + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + + if (this.configuration.currentTool === null) { + return false; + } + + var element = eventData.element; + var config = this.configuration; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolState.data[config.currentTool]; + + if (!data) { + return false; + } + + if (this._active) { + var context = eventData.canvasContext.canvas.getContext('2d'); + var options = { + color: this.configuration.dragColor, + fill: null, + handleRadius: this._toolSizeCanvas + }; + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_9__["default"])(context, eventData, this.configuration.mouseLocation.handles, options); + } else if (this.configuration.showCursorOnHover && !this._recentTouchEnd) { + this._renderHoverCursor(evt); + } + } + }, { + key: "doubleClickCallback", + value: function doubleClickCallback(evt) { + var eventData = evt.detail; + + this._selectFreehandTool(eventData); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(eventData.element); + } + }, { + key: "doubleTapCallback", + value: function doubleTapCallback(evt) { + var eventData = evt.detail; + + this._selectFreehandTool(eventData); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(eventData.element); + } + }, { + key: "preTouchStartCallback", + value: function preTouchStartCallback(evt) { + this._initialiseSculpting(evt); + + return true; + } + /** + * Event handler for MOUSE_DOWN. + * + * @param {Object} evt - The event. + * @returns {boolean} + */ + + }, { + key: "preMouseDownCallback", + value: function preMouseDownCallback(evt) { + if (!this.options.mouseButtonMask.includes(evt.detail.buttons)) { + return; + } + + this._initialiseSculpting(evt); + + return true; + } + /** + * Event handler for MOUSE_DRAG during the active loop. + * + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "activeMouseDragCallback", + value: function activeMouseDragCallback(evt) { + var config = this.configuration; + + if (!this._active) { + return; + } + + var eventData = evt.detail; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(eventData.element, this.referencedToolName); + + if (!toolState) { + return; + } + + var points = toolState.data[config.currentTool].handles.points; // Set the mouseLocation handle + + this._getMouseLocation(eventData); + + this._sculpt(eventData, points); // Update the image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(eventData.element); + } + /** + * Event handler for MOUSE_UP during the active loop. + * + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "activeMouseUpCallback", + value: function activeMouseUpCallback(evt) { + this._activeEnd(evt); + } + /** + * Event handler for TOUCH_END during the active loop. + * + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "activeTouchEndCallback", + value: function activeTouchEndCallback(evt) { + this._activeEnd(evt); + + this._deselectAllTools(evt); + + this._recentTouchEnd = true; + } + }, { + key: "_activeEnd", + value: function _activeEnd(evt) { + var eventData = evt.detail; + var element = eventData.element; + var config = this.configuration; + this._active = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_10__["state"].isMultiPartToolActive = false; + + this._getMouseLocation(eventData); + + this._invalidateToolData(eventData); + + config.mouseUpRender = true; + + this._deactivateSculpt(element); // Update the image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(eventData.element); + preventPropagation(evt); + } + /** + * Renders the cursor + * + * @private + * @param {type} evt description + * @returns {void} + */ + + }, { + key: "_renderHoverCursor", + value: function _renderHoverCursor(evt) { + var eventData = evt.detail; + var element = eventData.element; + var context = eventData.canvasContext.canvas.getContext('2d'); + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolState.data[this.configuration.currentTool]; + this._recentTouchEnd = false; + var coords; + + if (this.configuration.mouseUpRender) { + coords = this.configuration.mouseLocation.handles.start; + this.configuration.mouseUpRender = false; + } else { + coords = _store_index_js__WEBPACK_IMPORTED_MODULE_10__["state"].mousePositionImage; + } + + var freehandRoiTool = Object(_store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, this.referencedToolName); + var radiusCanvas = freehandRoiTool.distanceFromPointCanvas(element, data, coords); + this.configuration.mouseLocation.handles.start.x = coords.x; + this.configuration.mouseLocation.handles.start.y = coords.y; + + if (this.configuration.limitRadiusOutsideRegion) { + var unlimitedRadius = radiusCanvas; + radiusCanvas = this._limitCursorRadiusCanvas(eventData, radiusCanvas); // Fade if distant + + if (unlimitedRadius > this.configuration.hoverCursorFadeDistance * radiusCanvas) { + context.globalAlpha = this.configuration.hoverCursorFadeAlpha; + } + } + + var options = { + fill: null, + color: this.configuration.hoverColor, + handleRadius: radiusCanvas + }; + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_9__["default"])(context, eventData, this.configuration.mouseLocation.handles, options); + + if (this.configuration.limitRadiusOutsideRegion) { + context.globalAlpha = 1.0; // Reset drawing alpha for other draw calls. + } + } + /** + * Event handler for NEW_IMAGE event. + * + * @public + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "newImageCallback", + value: function newImageCallback(evt) { + this._deselectAllTools(evt); + } + /** + * Event handler for switching mode to enabled. + * + * @public + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "enabledCallback", + value: function enabledCallback(evt) { + this._deselectAllTools(evt); + } + /** + * Event handler for switching mode to passive. + * + * @public + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "passiveCallback", + value: function passiveCallback(evt) { + this._deselectAllTools(evt); + } + /** + * Event handler for switching mode to disabled. + * + * @public + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "disabledCallback", + value: function disabledCallback(evt) { + this._deselectAllTools(evt); + } + /** + * Select the freehand tool to be edited. + * + * @private + * @param {Object} eventData - Data object associated with the event. + * @returns {void} + */ + + }, { + key: "_selectFreehandTool", + value: function _selectFreehandTool(eventData) { + var config = this.configuration; + var element = eventData.element; + + var closestToolIndex = this._getClosestFreehandToolOnElement(element, eventData); + + if (closestToolIndex === undefined) { + return; + } + + config.currentTool = closestToolIndex; + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_15__["hideToolCursor"])(element); + } + /** + * Activate the selected freehand tool and deactivate others. + * + * @private + * @param {Object} element - The parent element of the freehand tool. + * @param {Number} toolIndex - The ID of the freehand tool. + * @returns {void} + */ + + }, { + key: "_activateFreehandTool", + value: function _activateFreehandTool(element, toolIndex) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolState.data; + var config = this.configuration; + config.currentTool = toolIndex; + + for (var i = 0; i < data.length; i++) { + if (i === toolIndex) { + data[i].active = true; + } else { + data[i].active = false; + } + } + } + /** + * Choose the tool radius from the mouse position relative to the active freehand + * tool, and begin sculpting. + * + * @private + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "_initialiseSculpting", + value: function _initialiseSculpting(evt) { + var eventData = evt.detail; + var config = this.configuration; + var element = eventData.element; + + if (config.currentTool === null) { + this._selectFreehandTool(eventData); + + if (config.currentTool === null) { + return; + } + } + + this._active = true; // Interupt event dispatcher + + _store_index_js__WEBPACK_IMPORTED_MODULE_10__["state"].isMultiPartToolActive = true; + + this._configureToolSize(eventData); + + this._getMouseLocation(eventData); + + this._activateFreehandTool(element, config.currentTool); + + this._activateSculpt(element); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(eventData.element); + } + /** + * Sculpts the freehand ROI with the circular freehandSculpter tool, moving, + * adding and removing handles as necessary. + * + * @private + * @param {Object} eventData - Data object associated with the event. + * @param {Object} points - Array of points. + * @returns {void} + */ + + }, { + key: "_sculpt", + value: function _sculpt(eventData, points) { + var config = this.configuration; + this._sculptData = { + element: eventData.element, + image: eventData.image, + mousePoint: eventData.currentPoints.image, + points: points, + toolSize: this._toolSizeImage, + minSpacing: config.minSpacing, + maxSpacing: Math.max(this._toolSizeImage, config.minSpacing * 2) + }; // Push existing handles radially away from tool. + + var pushedHandles = this._pushHandles(); // Insert new handles in sparsely populated areas of the + // Pushed part of the contour. + + + if (pushedHandles.first !== undefined) { + this._insertNewHandles(pushedHandles); // If any handles have been pushed very close together or even overlap, + // Combine these into a single handle. + + + this._consolidateHandles(); + } + } + /** + * _pushHandles -Pushes the points radially away from the mouse if they are + * contained within the circle defined by the freehandSculpter's toolSize and + * the mouse position. + * + * @returns {Object} The first and last pushedHandles. + */ + + }, { + key: "_pushHandles", + value: function _pushHandles() { + var _this$_sculptData = this._sculptData, + points = _this$_sculptData.points, + mousePoint = _this$_sculptData.mousePoint, + toolSize = _this$_sculptData.toolSize; + var pushedHandles = {}; + + for (var i = 0; i < points.length; i++) { + var distanceToHandle = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(points[i], mousePoint); + + if (distanceToHandle > toolSize) { + continue; + } // Push point if inside circle, to edge of circle. + + + this._pushOneHandle(i, distanceToHandle); + + if (pushedHandles.first === undefined) { + pushedHandles.first = i; + pushedHandles.last = i; + } else { + pushedHandles.last = i; + } + } + + return pushedHandles; + } + /** + * Pushes one handle. + * + * @private + * @param {number} i - The index of the handle to push. + * @param {number} distanceToHandle - The distance between the mouse cursor and the handle. + * @returns {void} + */ + + }, { + key: "_pushOneHandle", + value: function _pushOneHandle(i, distanceToHandle) { + var _this$_sculptData2 = this._sculptData, + points = _this$_sculptData2.points, + mousePoint = _this$_sculptData2.mousePoint, + toolSize = _this$_sculptData2.toolSize, + image = _this$_sculptData2.image; + var handle = points[i]; + var directionUnitVector = { + x: (handle.x - mousePoint.x) / distanceToHandle, + y: (handle.y - mousePoint.y) / distanceToHandle + }; + var position = { + x: mousePoint.x + toolSize * directionUnitVector.x, + y: mousePoint.y + toolSize * directionUnitVector.y + }; + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_12__["clipToBox"])(position, image); + handle.x = position.x; + handle.y = position.y; // Push lines + + var lastHandleIndex = this.constructor._getPreviousHandleIndex(i, points.length); + + points[lastHandleIndex].lines.pop(); + points[lastHandleIndex].lines.push(handle); + } + /** + * Inserts additional handles in sparsely sampled regions of the contour. The + * new handles are placed on the circle defined by the the freehandSculpter's + * toolSize and the mouse position. + * @private + * @param {Array} pushedHandles + * @returns {void} + */ + + }, { + key: "_insertNewHandles", + value: function _insertNewHandles(pushedHandles) { + var indiciesToInsertAfter = this._findNewHandleIndicies(pushedHandles); + + var newIndexModifier = 0; + + for (var i = 0; i < indiciesToInsertAfter.length; i++) { + var insertIndex = indiciesToInsertAfter[i] + 1 + newIndexModifier; + + this._insertHandleRadially(insertIndex); + + newIndexModifier++; + } + } + /** + * Returns an array of indicies that describe where new handles should be + * inserted (where the distance between subsequent handles is > + * config.maxSpacing). + * + * @private + * @param {Object} pushedHandles - The first and last handles that were pushed. + * @returns {Object} An array of indicies that describe where new handles should be inserted. + */ + + }, { + key: "_findNewHandleIndicies", + value: function _findNewHandleIndicies(pushedHandles) { + var _this$_sculptData3 = this._sculptData, + points = _this$_sculptData3.points, + maxSpacing = _this$_sculptData3.maxSpacing; + var indiciesToInsertAfter = []; + + for (var i = pushedHandles.first; i <= pushedHandles.last; i++) { + this._checkSpacing(i, points, indiciesToInsertAfter, maxSpacing); + } + + var pointAfterLast = this.constructor._getNextHandleIndex(pushedHandles.last, points.length); // Check points before and after those pushed. + + + if (pointAfterLast !== pushedHandles.first) { + this._checkSpacing(pointAfterLast, points, indiciesToInsertAfter, maxSpacing); + + var pointBeforeFirst = this.constructor._getPreviousHandleIndex(pushedHandles.first, points.length); + + if (pointBeforeFirst !== pointAfterLast) { + this._checkSpacing(pointBeforeFirst, points, indiciesToInsertAfter, maxSpacing); + } + } + + return indiciesToInsertAfter; + } + /** + * _checkSpacing - description + *@modifies indiciesToInsertAfter + * + * @param {number} i - The index to check. + * @param {Object} points - The points. + * @param {Array} indiciesToInsertAfter - The working list of indicies to insert new points after. + * @param {number} maxSpacing + * @returns {void} + */ + + }, { + key: "_checkSpacing", + value: function _checkSpacing(i, points, indiciesToInsertAfter, maxSpacing) { + var nextHandleIndex = this.constructor._getNextHandleIndex(i, points.length); + + var distanceToNextHandle = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(points[i], points[nextHandleIndex]); + + if (distanceToNextHandle > maxSpacing) { + indiciesToInsertAfter.push(i); + } + } + /** + * Inserts a handle on the surface of the circle defined by toolSize and the + * mousePoint. + * + * @private + * @param {number} insertIndex - The index to insert the new handle. + * @returns {void} + */ + + }, { + key: "_insertHandleRadially", + value: function _insertHandleRadially(insertIndex) { + var points = this._sculptData.points; + var previousIndex = insertIndex - 1; + + var nextIndex = this.constructor._getNextHandleIndexBeforeInsert(insertIndex, points.length); + + var insertPosition = this._getInsertPosition(insertIndex, previousIndex, nextIndex); + + var handleData = new FreehandHandleData(insertPosition); + points.splice(insertIndex, 0, handleData); // Add the line from the previous handle to the inserted handle (note the tool is now one increment longer) + + points[previousIndex].lines.pop(); + points[previousIndex].lines.push(points[insertIndex]); + _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_17__["default"].addLine(points, insertIndex); + } + /** + * Checks for any close points and consolidates these to a + * single point. + * + * @private + * @returns {void} + */ + + }, { + key: "_consolidateHandles", + value: function _consolidateHandles() { + var points = this._sculptData.points; // Don't merge handles if it would destroy the polygon. + + if (points.length <= 3) { + return; + } + + var closePairs = this._findCloseHandlePairs(); + + this._mergeCloseHandles(closePairs); + } + /** + * Finds pairs of close handles with seperations < config.minSpacing. No handle + * is included in more than one pair, to avoid spurious deletion of densely + * populated regions of the contour (see mergeCloseHandles). + * + * @private + * @returns {Array} An array of close pairs in points. + */ + + }, { + key: "_findCloseHandlePairs", + value: function _findCloseHandlePairs() { + var _this$_sculptData4 = this._sculptData, + points = _this$_sculptData4.points, + minSpacing = _this$_sculptData4.minSpacing; + var closePairs = []; + var length = points.length; + + for (var i = 0; i < length; i++) { + var nextHandleIndex = this.constructor._getNextHandleIndex(i, points.length); + + var distanceToNextHandle = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(points[i], points[nextHandleIndex]); + + if (distanceToNextHandle < minSpacing) { + var pair = [i, nextHandleIndex]; + closePairs.push(pair); // Don't check last node if first in pair to avoid double counting. + + if (i === 0) { + length -= 1; + } // Don't double count pairs in order to prevent your polygon collapsing to a singularity. + + + i++; + } + } + + return closePairs; + } + /** + * Merges points given a list of close pairs. The points are merged in an + * iterative fashion to prevent generating a singularity in some edge cases. + * + * @private + * @param {Array} closePairs - An array of pairs of handle indicies. + * @returns {void} + */ + + }, { + key: "_mergeCloseHandles", + value: function _mergeCloseHandles(closePairs) { + var removedIndexModifier = 0; + + for (var i = 0; i < closePairs.length; i++) { + var pair = this.constructor._getCorrectedPair(closePairs[i], removedIndexModifier); + + this._combineHandles(pair); + + removedIndexModifier++; + } // Recursively remove problem childs + + + var newClosePairs = this._findCloseHandlePairs(); + + if (newClosePairs.length) { + this._mergeCloseHandles(newClosePairs); + } + } + /** + * Combines two handles defined by the indicies in handlePairs. + * + * @private + * @param {Object} handlePair - A pair of handle indicies. + * @returns {void} + */ + + }, { + key: "_combineHandles", + value: function _combineHandles(handlePair) { + var _this$_sculptData5 = this._sculptData, + points = _this$_sculptData5.points, + image = _this$_sculptData5.image; // Calculate combine position: half way between the handles. + + var midPoint = { + x: (points[handlePair[0]].x + points[handlePair[1]].x) / 2.0, + y: (points[handlePair[0]].y + points[handlePair[1]].y) / 2.0 + }; + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_12__["clipToBox"])(midPoint, image); // Move first point to midpoint + + points[handlePair[0]].x = midPoint.x; + points[handlePair[0]].y = midPoint.y; // Link first point to handle that second point links to. + + var handleAfterPairIndex = this.constructor._getNextHandleIndex(handlePair[1], points.length); + + points[handlePair[0]].lines.pop(); + points[handlePair[0]].lines.push(points[handleAfterPairIndex]); // Remove the latter handle + + points.splice(handlePair[1], 1); + } + /** + * Calculates the distance to the closest handle in the tool, and stores the + * result in this._toolSizeImage and this._toolSizeCanvas. + * + * @private + * @param {Object} eventData - Data object associated with the event. + * @returns {void} + */ + + }, { + key: "_configureToolSize", + value: function _configureToolSize(eventData) { + var element = eventData.element; + var config = this.configuration; + var toolIndex = config.currentTool; + var coords = eventData.currentPoints.image; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolState.data[toolIndex]; + var freehandRoiTool = Object(_store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, this.referencedToolName); + var radiusImage = freehandRoiTool.distanceFromPoint(element, data, coords); + var radiusCanvas = freehandRoiTool.distanceFromPointCanvas(element, data, coords); // Check if should limit maximum size. + + if (config.limitRadiusOutsideRegion) { + radiusImage = this._limitCursorRadiusImage(eventData, radiusImage); + radiusCanvas = this._limitCursorRadiusCanvas(eventData, radiusCanvas); + } + + this._toolSizeImage = radiusImage; + this._toolSizeCanvas = radiusCanvas; + } + /** + * Gets the current mouse location and stores it in the configuration object. + * + * @private + * @param {Object} eventData - The data assoicated with the event. + * @returns {void} + */ + + }, { + key: "_getMouseLocation", + value: function _getMouseLocation(eventData) { + var config = this.configuration; + config.mouseLocation.handles.start.x = eventData.currentPoints.image.x; + config.mouseLocation.handles.start.y = eventData.currentPoints.image.y; + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_12__["clipToBox"])(config.mouseLocation.handles.start, eventData.image); + } + /** + * Attaches event listeners to the element such that is is visible, modifiable, and new data can be created. + * + * @private + * @param {Object} element - The viewport element to attach event listeners to. + * @modifies {element} + * @returns {void} + */ + + }, { + key: "_activateSculpt", + value: function _activateSculpt(element) { + this._deactivateSculpt(element); // Begin activeMouseDragCallback loop - call activeMouseUpCallback at end of drag or straight away if just a click. + + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this.activeMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_CLICK, this.activeMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this.activeMouseDragCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this.activeTouchEndCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_TAP, this.activeTouchEndCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this.activeMouseDragCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Removes event listeners from the element. + * + * @private + * @param {Object} element - The viewport element to remove event listeners from. + * @modifies {element} + * @returns {void} + */ + + }, { + key: "_deactivateSculpt", + value: function _deactivateSculpt(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this.activeMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_CLICK, this.activeMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this.activeMouseDragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this.activeTouchEndCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_TAP, this.activeTouchEndCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this.activeMouseDragCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Invalidate the freehand tool data, tirggering re-calculation of statistics. + * + * @private + * @param {Object} eventData - Data object associated with the event. + * @returns {void} + */ + + }, { + key: "_invalidateToolData", + value: function _invalidateToolData(eventData) { + var config = this.configuration; + var element = eventData.element; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolData.data[config.currentTool]; + data.invalidated = true; + } + /** + * Deactivates all freehand ROIs and change currentTool to null + * + * @private + * @param {Object} evt - The event. + * @returns {void} + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "_deselectAllTools", + value: function _deselectAllTools(evt) { + var config = this.configuration; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(this.element, this.referencedToolName); + config.currentTool = null; + + if (toolData) { + for (var i = 0; i < toolData.data.length; i++) { + toolData.data[i].active = false; + } + } + + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_15__["setToolCursor"])(this.element, this.svgCursor); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + /** + * Given a pair of indicies, and the number of points already removed, + * convert to the correct live indicies. + * + * @private + * @static + * @param {Object} pair A pairs of handle indicies. + * @param {Number} removedIndexModifier The number of handles already removed. + * @returns {Object} The corrected pair of handle indicies. + */ + + }, { + key: "_limitCursorRadiusCanvas", + + /** + * Limits the cursor radius so that it its maximum area is the same as the + * ROI being sculpted (in canvas coordinates). + * + * @private + * @param {Object} eventData Data object associated with the event. + * @param {Number} radiusCanvas The distance from the mouse to the ROI + * in canvas coordinates. + * @returns {Number} The limited radius in canvas coordinates. + */ + value: function _limitCursorRadiusCanvas(eventData, radiusCanvas) { + return this._limitCursorRadius(eventData, radiusCanvas, true); + } + /** + * Limits the cursor radius so that it its maximum area is the same as the + * ROI being sculpted (in image coordinates). + * + * @private + * @param {Object} eventData Data object associated with the event. + * @param {Number} radiusImage The distance from the mouse to the ROI + * in image coordinates. + * @returns {Number} The limited radius in image coordinates. + */ + + }, { + key: "_limitCursorRadiusImage", + value: function _limitCursorRadiusImage(eventData, radiusImage) { + return this._limitCursorRadius(eventData, radiusImage, false); + } + /** + * Limits the cursor radius so that it its maximum area is the same as the + * ROI being sculpted. + * + * @private + * @param {Object} eventData Data object associated with the event. + * @param {Number} radius The distance from the mouse to the ROI. + * @param {Boolean} canvasCoords Whether the calculation should be performed + * In canvas coordinates. + * @returns {Number} The limited radius. + */ + + }, { + key: "_limitCursorRadius", + value: function _limitCursorRadius(eventData, radius) { + var canvasCoords = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var element = eventData.element; + var image = eventData.image; + var config = this.configuration; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + var data = toolState.data[config.currentTool]; + var areaModifier = 1.0; + + if (canvasCoords) { + var topLeft = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, { + x: 0, + y: 0 + }); + var bottomRight = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, { + x: image.width, + y: image.height + }); + var canvasArea = (bottomRight.x - topLeft.x) * (bottomRight.y - topLeft.y); + areaModifier = canvasArea / (image.width * image.height); + } + + var area = data.area * areaModifier; + var maxRadius = Math.pow(area / Math.PI, 0.5); + return Math.min(radius, maxRadius); + } + /** + * Finds the nearest handle to the mouse cursor for all freehand + * data on the element. + * + * @private + * @param {Object} element - The element. + * @param {Object} eventData - Data object associated with the event. + * @returns {Number} The tool index of the closest freehand tool. + */ + + }, { + key: "_getClosestFreehandToolOnElement", + value: function _getClosestFreehandToolOnElement(element, eventData) { + var freehand = Object(_store_getToolForElement_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, this.referencedToolName); + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_11__["getToolState"])(element, this.referencedToolName); + + if (!toolState) { + return; + } + + var data = toolState.data; + var pixelCoords = eventData.currentPoints.image; + var closest = { + distance: Infinity, + toolIndex: null + }; + + for (var i = 0; i < data.length; i++) { + var distanceFromToolI = freehand.distanceFromPoint(element, data[i], pixelCoords); + + if (distanceFromToolI === -1) { + continue; + } + + if (distanceFromToolI < closest.distance) { + closest.distance = distanceFromToolI; + closest.toolIndex = i; + } + } + + return closest.toolIndex; + } + /** + * Returns the next handle index. + * + * @private + * @static + * @param {Number} i - The handle index. + * @param {Number} length - The length of the polygon. + * @returns {Number} The next handle index. + */ + + }, { + key: "_getInsertPosition", + + /** + * Calculates the position that a new handle should be inserted. + * + * @private + * @static + * @param {Number} insertIndex - The index to insert the new handle. + * @param {Number} previousIndex - The previous index. + * @param {Number} nextIndex - The next index. + * @returns {Object} The position the handle should be inserted. + */ + value: function _getInsertPosition(insertIndex, previousIndex, nextIndex) { + var _this$_sculptData6 = this._sculptData, + points = _this$_sculptData6.points, + toolSize = _this$_sculptData6.toolSize, + mousePoint = _this$_sculptData6.mousePoint, + image = _this$_sculptData6.image; // Calculate insert position: half way between the handles, then pushed out + // Radially to the edge of the freehandSculpter. + + var midPoint = { + x: (points[previousIndex].x + points[nextIndex].x) / 2.0, + y: (points[previousIndex].y + points[nextIndex].y) / 2.0 + }; + var distanceToMidPoint = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(mousePoint, midPoint); + var insertPosition; + + if (distanceToMidPoint < toolSize) { + var directionUnitVector = { + x: (midPoint.x - mousePoint.x) / distanceToMidPoint, + y: (midPoint.y - mousePoint.y) / distanceToMidPoint + }; + insertPosition = { + x: mousePoint.x + toolSize * directionUnitVector.x, + y: mousePoint.y + toolSize * directionUnitVector.y + }; + } else { + insertPosition = midPoint; + } + + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_12__["clipToBox"])(insertPosition, image); + return insertPosition; + } // =================================================================== + // Public Configuration API. . + // =================================================================== + + }, { + key: "minSpacing", + get: function get() { + return this.configuration.minSpacing; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehandSculpter minSpacing to a value other than a number.'); + } + + this.configuration.minSpacing = value; + } + }, { + key: "maxSpacing", + get: function get() { + return this.configuration.maxSpacing; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehandSculpter maxSpacing to a value other than a number.'); + } + + this.configuration.maxSpacing = value; + } + }, { + key: "showCursorOnHover", + get: function get() { + return this.configuration.showCursorOnHover; + }, + set: function set(value) { + if (typeof value !== 'boolean') { + throw new Error('Attempting to set freehandSculpter showCursorOnHover to a value other than a boolean.'); + } + + this.configuration.showCursorOnHover = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "limitRadiusOutsideRegion", + get: function get() { + return this.configuration.limitRadiusOutsideRegion; + }, + set: function set(value) { + if (typeof value !== 'boolean') { + throw new Error('Attempting to set freehandSculpter limitRadiusOutsideRegion to a value other than a boolean.'); + } + + this.configuration.limitRadiusOutsideRegion = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "hoverCursorFadeAlpha", + get: function get() { + return this.configuration.hoverCursorFadeAlpha; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehandSculpter hoverCursorFadeAlpha to a value other than a number.'); + } // Clamp the value from 0 to 1. + + + value = Math.max(Math.min(value, 1.0), 0.0); + this.configuration.hoverCursorFadeAlpha = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "hoverCursorFadeDistance", + get: function get() { + return this.configuration.hoverCursorFadeDistance; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehandSculpter hoverCursorFadeDistance to a value other than a number.'); + } // Don't allow to fade a distances smaller than the tool's radius. + + + value = Math.max(value, 1.0); + this.configuration.hoverCursorFadeDistance = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }], [{ + key: "_getCorrectedPair", + value: function _getCorrectedPair(pair, removedIndexModifier) { + var correctedPair = [pair[0] - removedIndexModifier, pair[1] - removedIndexModifier]; // Deal with edge case of last node + first node. + + if (correctedPair[1] < 0) { + correctedPair[1] = 0; + } + + return correctedPair; + } + }, { + key: "_getNextHandleIndex", + value: function _getNextHandleIndex(i, length) { + if (i === length - 1) { + return 0; + } + + return i + 1; + } + /** + * Returns the previous handle index. + * + * @private + * @static + * @param {Number} i - The handle index. + * @param {Number} length - The length of the polygon. + * @returns {Number} The previous handle index. + */ + + }, { + key: "_getPreviousHandleIndex", + value: function _getPreviousHandleIndex(i, length) { + if (i === 0) { + return length - 1; + } + + return i - 1; + } + /** + * Returns the next handle index, with a correction considering a handle is + * about to be inserted. + * + * @private + * @static + * @param {Number} insertIndex - The index in which the handle is being inserted. + * @param {Number} length - The length of the polygon. + * @returns {Number} The next handle index. + */ + + }, { + key: "_getNextHandleIndexBeforeInsert", + value: function _getNextHandleIndexBeforeInsert(insertIndex, length) { + if (insertIndex === length) { + return 0; + } // Index correction here: The line bellow is correct, as we haven't inserted our handle yet! + + + return insertIndex; + } + }]); + + return FreehandRoiSculptorTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_14__["default"]); +/** + * Returns the default freehandRoiSculptorTool configuration. + * + * @returns {Object} The default configuration object. + */ + + + + +function getDefaultFreehandRoiSculptorToolConfiguration() { + return { + mouseLocation: { + handles: { + start: { + highlight: true, + active: true + } + } + }, + minSpacing: 1, + currentTool: null, + dragColor: _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_8__["default"].getActiveColor(), + hoverColor: _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolColor(), + + /* --- Hover options --- + showCursorOnHover: Shows a preview of the sculpting radius on hover. + limitRadiusOutsideRegion: Limit max toolsize outside the subject ROI based + on subject ROI area. + hoverCursorFadeAlpha: Alpha to fade to when tool very distant from + subject ROI. + hoverCursorFadeDistance: Distance from ROI in which to fade the hoverCursor + (in units of radii). + */ + showCursorOnHover: true, + limitRadiusOutsideRegion: true, + hoverCursorFadeAlpha: 0.5, + hoverCursorFadeDistance: 1.2 + }; +} + +function preventPropagation(evt) { + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); +} + +/***/ }), + +/***/ "./tools/MagnifyTool.js": +/*!******************************!*\ + !*** ./tools/MagnifyTool.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return MagnifyTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../store/setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + +/** + * @public + * @class MagnifyTool + * @memberof Tools + * + * @classdesc Tool for inspecting a region at increased magnification. + * @extends Tools.Base.BaseTool + */ + +var MagnifyTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(MagnifyTool, _BaseTool); + + function MagnifyTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, MagnifyTool); + + var defaultProps = { + name: 'Magnify', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + magnifySize: 300, + magnificationLevel: 2 + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__["magnifyCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(MagnifyTool).call(this, props, defaultProps)); + _this.zoomCanvas = undefined; + _this.zoomElement = undefined; // Mode Callbacks: (element, options) + + _this.activeCallback = _this._createMagnificationCanvas.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.enabledCallback = _this._createMagnificationCanvas.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.disabledCallback = _this._destroyMagnificationCanvas.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // Touch + + _this.postTouchStartCallback = _this._addMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchDragCallback = _this._updateMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchEndCallback = _this._removeMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchDragEndCallback = _this._removeMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // Mouse + + _this.postMouseDownCallback = _this._addMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.mouseDragCallback = _this._updateMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.mouseUpCallback = _this._removeMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // On quick clicks, mouseUp does not fire, but this does + + _this.mouseClickCallback = _this._removeMagnifyingGlass.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // Misc + + _this.newImageCallback = _this._drawMagnificationTool.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(MagnifyTool, [{ + key: "_addMagnifyingGlass", + value: function _addMagnifyingGlass(evt) { + var _this2 = this; + + // Ignore until next event + this._removeZoomElement(); + + this._drawZoomedElement(evt); // On next frame + + + window.requestAnimationFrame(function () { + return _this2._drawMagnificationTool(evt); + }); + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__["hideToolCursor"])(evt.detail.element); + evt.preventDefault(); + evt.stopPropagation(); + } + }, { + key: "_updateMagnifyingGlass", + value: function _updateMagnifyingGlass(evt) { + this._drawMagnificationTool(evt); + + evt.preventDefault(); + evt.stopPropagation(); + } + }, { + key: "_removeMagnifyingGlass", + value: function _removeMagnifyingGlass(evt) { + var element = evt.detail.element; // Re-enable the mouse cursor + + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__["setToolCursor"])(this.element, this.svgCursor); + element.querySelector('.magnifyTool').style.display = 'none'; + + this._removeZoomElement(); + } + }, { + key: "_drawMagnificationTool", + value: function _drawMagnificationTool(evt) { + var element = evt.detail.element; + var magnifyCanvas = element.querySelector('.magnifyTool'); + + if (!magnifyCanvas) { + this._createMagnificationCanvas(element); + } + + if (this.zoomCanvas === undefined) { + return; + } // The 'not' magnifyTool class here is necessary because cornerstone places + // No classes of it's own on the canvas we want to select + + + var canvas = element.querySelector('canvas:not(.magnifyTool)'); + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["getNewContext"])(magnifyCanvas); // Calculate the on-canvas location of the mouse pointer / touch + + var canvasLocation = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.pixelToCanvas(evt.detail.element, evt.detail.currentPoints.image); // Shrink magnifier to smallest canvas dimension if smaller than desired magnifier size + + var magnifySize = Math.min(this.configuration.magnifySize, canvas.width, canvas.height); + var magnificationLevel = this.configuration.magnificationLevel; + magnifyCanvas.width = magnifySize; + magnifyCanvas.height = magnifySize; // Constrain drag movement to zoomed image boundaries + + canvasLocation.x = Math.max(canvasLocation.x, 0.5 * magnifySize / magnificationLevel); + canvasLocation.x = Math.min(canvasLocation.x, canvas.width - 0.5 * magnifySize / magnificationLevel); + canvasLocation.y = Math.max(canvasLocation.y, 0.5 * magnifySize / magnificationLevel); + canvasLocation.y = Math.min(canvasLocation.y, canvas.height - 0.5 * magnifySize / magnificationLevel); + var copyFrom = { + x: canvasLocation.x * magnificationLevel - 0.5 * magnifySize, + y: canvasLocation.y * magnificationLevel - 0.5 * magnifySize + }; + copyFrom.x = Math.max(copyFrom.x, 0); + copyFrom.y = Math.max(copyFrom.y, 0); + context.drawImage(this.zoomCanvas, copyFrom.x, copyFrom.y, magnifySize, magnifySize, 0, 0, magnifySize, magnifySize); // Place the magnification tool at the same location as the pointer + + var touchOffset = evt.detail.isTouchEvent ? 120 : 0; + var magnifyPosition = { + top: Math.max(canvasLocation.y - 0.5 * magnifySize - touchOffset, 0), + left: Math.max(canvasLocation.x - 0.5 * magnifySize, 0) + }; // Get full magnifier dimensions with borders + + var magnifierBox = magnifyCanvas.getBoundingClientRect(); // Constrain magnifier to canvas boundaries + + magnifyPosition.top = Math.min(magnifyPosition.top, canvas.height - magnifierBox.height); + magnifyPosition.left = Math.min(magnifyPosition.left, canvas.width - magnifierBox.width); + magnifyCanvas.style.top = "".concat(magnifyPosition.top, "px"); + magnifyCanvas.style.left = "".concat(magnifyPosition.left, "px"); + magnifyCanvas.style.display = 'block'; + } + /** + * Creates a cornerstone enabled element, and renders the target image at the + * desired magnification level using it. + * + * @private + * @param {*} evt + * @returns {void} + */ + + }, { + key: "_drawZoomedElement", + value: function _drawZoomedElement(evt) { + var element = evt.detail.element; + var enabledElement = evt.detail.enabledElement; + + if (enabledElement === undefined) { + enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.getEnabledElement(element); + } + + var magnificationLevel = this.configuration.magnificationLevel; + var origCanvas = enabledElement.canvas; + var image = enabledElement.image; // Create a new cornerstone enabledElement + + if (!this.zoomElement) { + this.zoomElement = document.createElement('div'); + this.zoomElement.width = origCanvas.width * magnificationLevel; + this.zoomElement.height = origCanvas.height * magnificationLevel; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.enable(this.zoomElement, enabledElement.options); + } + + var zoomEnabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.getEnabledElement(this.zoomElement); + var viewport = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.getViewport(enabledElement.element); + this.zoomCanvas = zoomEnabledElement.canvas; + this.zoomCanvas.width = origCanvas.width * magnificationLevel; + this.zoomCanvas.height = origCanvas.height * magnificationLevel; + zoomEnabledElement.viewport = Object.assign({}, viewport); // Update it's viewport to render at desired magnification level + + viewport.scale *= magnificationLevel; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.displayImage(this.zoomElement, image); + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.setViewport(this.zoomElement, viewport); // To do enable annotation tools for zoomElement + } + /** + * Removes the canvas and associated enabled element that's + * used to render the zoomed image. + * @returns {void} + */ + + }, { + key: "_removeZoomElement", + value: function _removeZoomElement() { + if (this.zoomElement !== undefined) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.disable(this.zoomElement); + this.zoomElement = undefined; + this.zoomCanvas = undefined; + } + } + /** + * The canvas used to render the zoomed image. + * It will be displayed and clipped inside the magnifying glass frame/element. + * + * @private + * + * @param {*} element + * @returns {void} + */ + + }, { + key: "_createMagnificationCanvas", + value: function _createMagnificationCanvas(element) { + // If the magnifying glass canvas doesn't already exist + if (element.querySelector('.magnifyTool') === null) { + // Create a canvas and append it as a child to the element + var magnifyCanvas = document.createElement('canvas'); // The magnifyTool class is used to find the canvas later on + // Make sure position is absolute so the canvas can follow the mouse / touch + + magnifyCanvas.classList.add('magnifyTool'); + magnifyCanvas.width = this.configuration.magnifySize; + magnifyCanvas.height = this.configuration.magnifySize; + magnifyCanvas.style.position = 'absolute'; + magnifyCanvas.style.display = 'none'; + element.appendChild(magnifyCanvas); + } + } + /** + * + * + * @param {*} element + * @returns {void} + */ + + }, { + key: "_destroyMagnificationCanvas", + value: function _destroyMagnificationCanvas(element) { + var magnifyCanvas = element.querySelector('.magnifyTool'); + + if (magnifyCanvas) { + element.removeChild(magnifyCanvas); + } + } + }]); + + return MagnifyTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_8__["default"]); + + + +/***/ }), + +/***/ "./tools/OrientationMarkersTool.js": +/*!*****************************************!*\ + !*** ./tools/OrientationMarkersTool.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return OrientationMarkersTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _orientation_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../orientation/index.js */ "./orientation/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); + + + + + + + + // Drawing + + + + +/** + * @public + * @class OrientationMarkersTool + * @memberof Tools + * + * @classdesc Tool for displaying orientation markers on the image. + * @extends Tools.Base.BaseTool + */ + +var OrientationMarkersTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(OrientationMarkersTool, _BaseTool); + + function OrientationMarkersTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, OrientationMarkersTool); + + var defaultProps = { + name: 'OrientationMarkers', + configuration: { + drawAllMarkers: true + }, + mixins: ['enabledOrDisabledBinaryTool'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(OrientationMarkersTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(OrientationMarkersTool, [{ + key: "enabledCallback", + value: function enabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "forceImageUpdate", + value: function forceImageUpdate(element) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone; + var enabledElement = cornerstone.getEnabledElement(element); + + if (enabledElement.image) { + cornerstone.updateImage(element); + } + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_8__["getNewContext"])(eventData.canvasContext.canvas); + var element = eventData.element; + var markers = getOrientationMarkers(element); + + if (!markers) { + return; + } + + var coords = getOrientationMarkerPositions(element, markers); + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getToolColor(); + var textWidths = { + top: Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["textBoxWidth"])(context, markers.top, 0), + left: Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["textBoxWidth"])(context, markers.left, 0), + right: Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["textBoxWidth"])(context, markers.right, 0), + bottom: Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["textBoxWidth"])(context, markers.bottom, 0), + height: Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["textBoxWidth"])(context, 'M', 0) // Trick to get an approximation of the height of the text + + }; + drawTopLeftText(context, markers, coords, textWidths, color); + + if (this.configuration.drawAllMarkers) { + drawBottomRightText(context, markers, coords, textWidths, color); + } + } + }]); + + return OrientationMarkersTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +var drawTopLeftText = function drawTopLeftText(context, markers, coords, textWidths, color) { + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["default"])(context, markers.top, coords.top.x - textWidths.top / 2, coords.top.y, color); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["default"])(context, markers.left, coords.left.x - textWidths.left / 2, coords.left.y, color); +}; + +var drawBottomRightText = function drawBottomRightText(context, markers, coords, textWidths, color) { + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["default"])(context, markers.right, coords.right.x - textWidths.right, coords.right.y, color); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_10__["default"])(context, markers.bottom, coords.bottom.x - textWidths.bottom / 2, coords.bottom.y - textWidths.height, color); +}; + +var getOrientationMarkers = function getOrientationMarkers(element) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone; + var enabledElement = cornerstone.getEnabledElement(element); + var imagePlane = cornerstone.metaData.get('imagePlaneModule', enabledElement.image.imageId); + + if (!imagePlane || !imagePlane.rowCosines || !imagePlane.columnCosines) { + return; + } + + var row = _orientation_index_js__WEBPACK_IMPORTED_MODULE_7__["default"].getOrientationString(imagePlane.rowCosines); + var column = _orientation_index_js__WEBPACK_IMPORTED_MODULE_7__["default"].getOrientationString(imagePlane.columnCosines); + var oppositeRow = _orientation_index_js__WEBPACK_IMPORTED_MODULE_7__["default"].invertOrientationString(row); + var oppositeColumn = _orientation_index_js__WEBPACK_IMPORTED_MODULE_7__["default"].invertOrientationString(column); + return { + top: oppositeColumn, + bottom: column, + left: oppositeRow, + right: row + }; +}; + +var getOrientationMarkerPositions = function getOrientationMarkerPositions(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getEnabledElement(element); + var top = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, { + x: enabledElement.image.width / 2, + y: 5 + }); + var bottom = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, { + x: enabledElement.image.width / 2, + y: enabledElement.image.height - 15 + }); + var left = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, { + x: 5, + y: enabledElement.image.height / 2 + }); + var right = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, { + x: enabledElement.image.width - 10, + y: enabledElement.image.height / 2 + }); + return { + top: top, + bottom: bottom, + left: left, + right: right + }; +}; + +/***/ }), + +/***/ "./tools/OverlayTool.js": +/*!******************************!*\ + !*** ./tools/OverlayTool.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return OverlayTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../store/index */ "./store/index.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); + + + + + + + + +var globalConfiguration = _store_index__WEBPACK_IMPORTED_MODULE_5__["modules"].globalConfiguration; +/** + * + * http://dicom.nema.org/dicom/2013/output/chtml/part03/sect_C.9.html + * + * @public + * @class Overlay + * @memberof Tools + * + * @classdesc Tool for displaying a scale overlay on the image. Uses viewport.overlayColor to set the default colour. + * @extends Tools.Base.BaseTool + */ + +var OverlayTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(OverlayTool, _BaseTool); + + function OverlayTool() { + var _this; + + var configuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, OverlayTool); + + var defaultConfig = { + name: 'Overlay', + configuration: {}, + mixins: ['enabledOrDisabledBinaryTool'] + }; + var initialConfiguration = Object.assign(defaultConfig, configuration); + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(OverlayTool).call(this, initialConfiguration)); + _this.initialConfiguration = initialConfiguration; + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(OverlayTool, [{ + key: "enabledCallback", + value: function enabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "forceImageUpdate", + value: function forceImageUpdate(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.getEnabledElement(element); + + if (enabledElement.image) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + } + } + }, { + key: "setupRender", + value: function setupRender(image) { + if (!image) { + return; + } + + var overlayPlaneMetadata = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.metaData.get('overlayPlaneModule', image.imageId); + + if (!overlayPlaneMetadata || !overlayPlaneMetadata.overlays || !overlayPlaneMetadata.overlays.length) { + return; + } + + return overlayPlaneMetadata; + } + }, { + key: "setupViewport", + value: function setupViewport(viewport) { + if (viewport.overlayColor === undefined) { + viewport.overlayColor = globalConfiguration.configuration.overlayColor || 'white'; + } // Allow turning off overlays by setting overlayColor to false + + + if (viewport.overlayColor === false) { + return; + } + + return true; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + var enabledElement = eventData.enabledElement, + image = eventData.image, + viewport = eventData.viewport, + canvasContext = eventData.canvasContext; + var overlayPlaneMetadata = this.setupRender(image); + + if (!eventData || !enabledElement || !overlayPlaneMetadata) { + return; + } + + if (!this.setupViewport(viewport)) { + return; + } + + var imageWidth = image.columns; + var imageHeight = image.rows; + overlayPlaneMetadata.overlays.forEach(function (overlay) { + if (overlay.visible === false) { + return; + } + + var layerCanvas = document.createElement('canvas'); + layerCanvas.width = imageWidth; + layerCanvas.height = imageHeight; + var layerContext = layerCanvas.getContext('2d'); + layerContext.fillStyle = overlay.fillStyle || viewport.overlayColor; + + if (overlay.type === 'R') { + layerContext.fillRect(0, 0, layerCanvas.width, layerCanvas.height); + layerContext.globalCompositeOperation = 'xor'; + } + + var i = 0; + + for (var y = 0; y < overlay.rows; y++) { + for (var x = 0; x < overlay.columns; x++) { + if (overlay.pixelData[i++] > 0) { + layerContext.fillRect(x, y, 1, 1); + } + } + } // Guard against non-number values + + + var overlayX = !isNaN(parseFloat(overlay.x)) && isFinite(overlay.x) ? overlay.x : 0; + var overlayY = !isNaN(parseFloat(overlay.y)) && isFinite(overlay.y) ? overlay.y : 0; // Draw the overlay layer onto the canvas + + canvasContext.drawImage(layerCanvas, overlayX, overlayY); + }); + } + }]); + + return OverlayTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); + + + +/***/ }), + +/***/ "./tools/PanMultiTouchTool.js": +/*!************************************!*\ + !*** ./tools/PanMultiTouchTool.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return PanMultiTouchTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); + + + + + + + + +/** + * @public + * @class PanMultiTouchTool + * @memberof Tools + * + * @classdesc Tool for panning the image using multi-touch. + * @extends Tools.Base.BaseTool + */ + +var PanMultiTouchTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(PanMultiTouchTool, _BaseTool); + + function PanMultiTouchTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, PanMultiTouchTool); + + var defaultProps = { + name: 'PanMultiTouch', + supportedInteractionTypes: ['MultiTouch'], + configuration: { + touchPointers: 2 + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(PanMultiTouchTool).call(this, props, defaultProps)); // Touch + + _this.multiTouchDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(PanMultiTouchTool, [{ + key: "_dragCallback", + value: function _dragCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + viewport = eventData.viewport; + + if (eventData.numPointers === this.configuration.touchPointers) { + var translation = this._getTranslation(eventData); + + this._applyTranslation(viewport, translation); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.setViewport(element, viewport); + } + } + }, { + key: "_getTranslation", + value: function _getTranslation(eventData) { + var viewport = eventData.viewport, + image = eventData.image, + deltaPoints = eventData.deltaPoints; + var widthScale = viewport.scale; + var heightScale = viewport.scale; + + if (image.rowPixelSpacing < image.columnPixelSpacing) { + widthScale *= image.columnPixelSpacing / image.rowPixelSpacing; + } else if (image.columnPixelSpacing < image.rowPixelSpacing) { + heightScale *= image.rowPixelSpacing / image.columnPixelSpacing; + } + + return { + x: deltaPoints.page.x / widthScale, + y: deltaPoints.page.y / heightScale + }; + } + }, { + key: "_applyTranslation", + value: function _applyTranslation(viewport, translation) { + viewport.translation.x += translation.x; + viewport.translation.y += translation.y; + } + }]); + + return PanMultiTouchTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); + + + +/***/ }), + +/***/ "./tools/PanTool.js": +/*!**************************!*\ + !*** ./tools/PanTool.js ***! + \**************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return PanTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + +/** + * @public + * @class PanTool + * @memberof Tools + * + * @classdesc Tool for panning the image. + * @extends Tools.Base.BaseTool + */ + +var PanTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(PanTool, _BaseTool); + + function PanTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, PanTool); + + var defaultProps = { + name: 'Pan', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_8__["panCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(PanTool).call(this, props, defaultProps)); // Touch + + _this.touchDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // Mouse + + _this.mouseDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(PanTool, [{ + key: "_dragCallback", + value: function _dragCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + viewport = eventData.viewport; + + var translation = this._getTranslation(eventData); + + this._applyTranslation(viewport, translation); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.setViewport(element, viewport); + } + }, { + key: "_getTranslation", + value: function _getTranslation(eventData) { + var viewport = eventData.viewport, + image = eventData.image, + deltaPoints = eventData.deltaPoints; + var widthScale = viewport.scale; + var heightScale = viewport.scale; + + if (image.rowPixelSpacing < image.columnPixelSpacing) { + widthScale *= image.columnPixelSpacing / image.rowPixelSpacing; + } else if (image.columnPixelSpacing < image.rowPixelSpacing) { + heightScale *= image.rowPixelSpacing / image.columnPixelSpacing; + } + + return { + x: deltaPoints.page.x / widthScale, + y: deltaPoints.page.y / heightScale + }; + } + }, { + key: "_applyTranslation", + value: function _applyTranslation(viewport, translation) { + viewport.translation.x += translation.x; + viewport.translation.y += translation.y; + } + }]); + + return PanTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); + + + +/***/ }), + +/***/ "./tools/ReferenceLinesTool.js": +/*!*************************************!*\ + !*** ./tools/ReferenceLinesTool.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ReferenceLinesTool; }); +/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/regenerator */ "../node_modules/@babel/runtime/regenerator/index.js"); +/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "../node_modules/@babel/runtime/helpers/asyncToGenerator.js"); +/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_6__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _referenceLines_renderActiveReferenceLine_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./referenceLines/renderActiveReferenceLine.js */ "./tools/referenceLines/renderActiveReferenceLine.js"); +/* harmony import */ var _util_wait_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../util/wait.js */ "./util/wait.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_12__["getLogger"])('tools:ReferenceLinesTool'); +/** + * When enabled, this tool will display references lines for each source + * enabledElement in the provided synchronizer. This tool can also be configured + * to use a custom renderer for alternative reference line rendering behavior + * + * TODO: Need to watch for configuration changes to update ToolState + * TODO: + * + * @export @public @class + * @name ReferenceLinesTool + * @classdesc Tool for displaying reference lines of other enabledElements + * @extends Tools.Base.BaseTool + */ + +var ReferenceLinesTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_6___default()(ReferenceLinesTool, _BaseTool); + + function ReferenceLinesTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2___default()(this, ReferenceLinesTool); + + var defaultProps = { + name: 'ReferenceLines', + mixins: ['enabledOrDisabledBinaryTool'], + configuration: { + renderer: _referenceLines_renderActiveReferenceLine_js__WEBPACK_IMPORTED_MODULE_10__["default"] + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5___default()(ReferenceLinesTool).call(this, props, defaultProps)); + _this.renderer = null; + _this.synchronizationContext = null; + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3___default()(ReferenceLinesTool, [{ + key: "enabledCallback", + value: function () { + var _enabledCallback = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()( + /*#__PURE__*/ + _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee(element) { + var _ref, + synchronizationContext, + renderer, + enabledElement, + _args = arguments; + + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _ref = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, synchronizationContext = _ref.synchronizationContext; + renderer = this.configuration.renderer; + _context.next = 4; + return Object(_util_wait_js__WEBPACK_IMPORTED_MODULE_11__["waitForEnabledElementImageToLoad"])(element); + + case 4: + enabledElement = _context.sent; + + if (!(!enabledElement || !renderer || !synchronizationContext)) { + _context.next = 8; + break; + } + + // TODO: Unable to add tool state, image never loaded. + // Should we `setToolDisabledForElement` here? + logger.warn("Unable to enable ".concat(this.name, ". Exiting enable callback. Tool will be enabled, but will not render.")); + return _context.abrupt("return"); + + case 8: + this.renderer = renderer; + this.synchronizationContext = synchronizationContext; + this.forceImageUpdate(element); + + case 11: + case "end": + return _context.stop(); + } + } + }, _callee, this); + })); + + function enabledCallback(_x) { + return _enabledCallback.apply(this, arguments); + } + + return enabledCallback; + }() + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "forceImageUpdate", + value: function forceImageUpdate(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.getEnabledElement(element); + + if (enabledElement.image) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; // No renderer or synch context? Adios + + if (!this.renderer || !this.synchronizationContext) { + return; + } // Get the enabled elements associated with this synchronization context and draw them + + + var enabledElements = this.synchronizationContext.getSourceElements(); + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_9__["getNewContext"])(eventData.canvasContext.canvas); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.setToPixelCoordinateSystem(eventData.enabledElement, context); + enabledElements.forEach(function (referenceEnabledElement) { + // Don't draw ourselves + if (referenceEnabledElement === evt.currentTarget) { + return; + } // Render it + + + _this2.renderer(context, eventData, evt.currentTarget, referenceEnabledElement); + }); + } + }]); + + return ReferenceLinesTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_8__["default"]); + + + +/***/ }), + +/***/ "./tools/RotateTool.js": +/*!*****************************!*\ + !*** ./tools/RotateTool.js ***! + \*****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return RotateTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_angleBetweenPoints_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/angleBetweenPoints.js */ "./util/angleBetweenPoints.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + +/** + * @public + * @class RotateTool + * @memberof Tools + * + * @classdesc Tool for rotating the image. + * @extends Tools.Base.BaseTool + */ + +var RotateTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(RotateTool, _BaseTool); + + function RotateTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, RotateTool); + + var defaultProps = { + name: 'Rotate', + strategies: { + default: defaultStrategy, + horizontal: horizontalStrategy, + vertical: verticalStrategy + }, + defaultStrategy: 'default', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + roundAngles: false, + flipHorizontal: false, + flipVertical: false, + rotateScale: 1 + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_8__["rotateCursor"] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(RotateTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(RotateTool, [{ + key: "touchDragCallback", + value: function touchDragCallback(evt) { + this.dragCallback(evt); + } + }, { + key: "mouseDragCallback", + value: function mouseDragCallback(evt) { + this.dragCallback(evt); + } + }, { + key: "postMouseDownCallback", + value: function postMouseDownCallback(evt) { + this.initialRotation = evt.detail.viewport.rotation; + } + }, { + key: "dragCallback", + value: function dragCallback(evt) { + evt.detail.viewport.initialRotation = this.initialRotation; + this.applyActiveStrategy(evt); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(evt.detail.element, evt.detail.viewport); + } + }]); + + return RotateTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +function defaultStrategy(evt) { + var _this$configuration = this.configuration, + roundAngles = _this$configuration.roundAngles, + rotateScale = _this$configuration.rotateScale; + var _evt$detail = evt.detail, + element = _evt$detail.element, + viewport = _evt$detail.viewport, + startPoints = _evt$detail.startPoints, + currentPoints = _evt$detail.currentPoints; + var initialRotation = viewport.initialRotation ? viewport.initialRotation : viewport.rotation; // Calculate the center of the image + + var rect = element.getBoundingClientRect(element); + var width = element.clientWidth, + height = element.clientHeight; + var scale = viewport.scale, + translation = viewport.translation; + var centerPoints = { + x: rect.left + width / 2 + translation.x * scale, + y: rect.top + height / 2 + translation.y * scale + }; + var angleInfo = Object(_util_angleBetweenPoints_js__WEBPACK_IMPORTED_MODULE_7__["default"])(centerPoints, startPoints.client, currentPoints.client); + angleInfo.angle *= rotateScale; + + if (roundAngles) { + angleInfo.angle = Math.ceil(angleInfo.angle); + } + + if (angleInfo.direction < 0) { + angleInfo.angle = -angleInfo.angle; + } + + viewport.rotation = initialRotation + angleInfo.angle; +} + +function horizontalStrategy(evt) { + var _this$configuration2 = this.configuration, + roundAngles = _this$configuration2.roundAngles, + flipHorizontal = _this$configuration2.flipHorizontal, + rotateScale = _this$configuration2.rotateScale; + var _evt$detail2 = evt.detail, + viewport = _evt$detail2.viewport, + startPoints = _evt$detail2.startPoints, + currentPoints = _evt$detail2.currentPoints; + var initialRotation = viewport.initialRotation; + var initialPointX = startPoints.client.x; + var currentPointX = currentPoints.client.x; + var angle = (currentPointX - initialPointX) * rotateScale; + + if (roundAngles) { + angle = Math.round(Math.abs(angle)) * (angle > 0 ? 1 : -1); + } + + if (flipHorizontal) { + angle = -angle; + } + + viewport.rotation = initialRotation + angle; +} + +function verticalStrategy(evt) { + var _this$configuration3 = this.configuration, + roundAngles = _this$configuration3.roundAngles, + flipVertical = _this$configuration3.flipVertical, + rotateScale = _this$configuration3.rotateScale; + var _evt$detail3 = evt.detail, + viewport = _evt$detail3.viewport, + startPoints = _evt$detail3.startPoints, + currentPoints = _evt$detail3.currentPoints; + var initialRotation = viewport.initialRotation; + var initialPointY = startPoints.client.y; + var currentPointY = currentPoints.client.y; + var angle = (currentPointY - initialPointY) * rotateScale; + + if (roundAngles) { + angle = Math.round(Math.abs(angle)) * (angle > 0 ? 1 : -1); + } + + if (flipVertical) { + angle = -angle; + } + + viewport.rotation = initialRotation + angle; +} + +/***/ }), + +/***/ "./tools/RotateTouchTool.js": +/*!**********************************!*\ + !*** ./tools/RotateTouchTool.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return RotateTouchTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); + + + + + + + +/** + * @public + * @class RotateTouchTool + * @memberof Tools + * + * @classdesc Tool for rotating the image using touch. + * @extends Tools.Base.BaseTool + */ + +var RotateTouchTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(RotateTouchTool, _BaseTool); + + function RotateTouchTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, RotateTouchTool); + + var defaultProps = { + name: 'RotateTouch', + supportedInteractionTypes: ['TouchRotate'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(RotateTouchTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(RotateTouchTool, [{ + key: "touchRotateCallback", + value: function touchRotateCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + viewport = eventData.viewport, + rotation = eventData.rotation; + viewport.rotation += rotation; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(element, viewport); + } + }]); + + return RotateTouchTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/ScaleOverlayTool.js": +/*!***********************************!*\ + !*** ./tools/ScaleOverlayTool.js ***! + \***********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ScaleOverlayTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/logger.js */ "./util/logger.js"); + + + + + + + // Drawing + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_10__["getLogger"])('tools:ScaleOverlayTool'); +/** + * @public + * @class ScaleOverlayTool + * @memberof Tools + * + * @classdesc Tool for displaying a scale overlay on the image. + * @extends Tools.Base.BaseTool + */ + +var ScaleOverlayTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ScaleOverlayTool, _BaseTool); + + function ScaleOverlayTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ScaleOverlayTool); + + var defaultProps = { + name: 'ScaleOverlay', + configuration: { + minorTickLength: 12.5, + majorTickLength: 25 + }, + mixins: ['enabledOrDisabledBinaryTool'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ScaleOverlayTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ScaleOverlayTool, [{ + key: "enabledCallback", + value: function enabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + this.forceImageUpdate(element); + } + }, { + key: "forceImageUpdate", + value: function forceImageUpdate(element) { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getEnabledElement(element); + + if (enabledElement.image) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + } + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["getNewContext"])(eventData.canvasContext.canvas); + var image = eventData.image, + viewport = eventData.viewport, + element = eventData.element; + var rowPixelSpacing = image.rowPixelSpacing; + var colPixelSpacing = image.columnPixelSpacing; + var imagePlane = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('imagePlaneModule', image.imageId); + + if (imagePlane) { + rowPixelSpacing = imagePlane.rowPixelSpacing || imagePlane.rowImagePixelSpacing; + colPixelSpacing = imagePlane.columnPixelSpacing || imagePlane.colImagePixelSpacing; + } // Check whether pixel spacing is defined + + + if (!rowPixelSpacing || !colPixelSpacing) { + logger.warn("unable to define rowPixelSpacing or colPixelSpacing from data on ".concat(this.name, "'s renderToolData")); + return; + } + + var canvasSize = { + width: context.canvas.width, + height: context.canvas.height + }; // Distance between intervals is 10mm + + var verticalIntervalScale = 10.0 / rowPixelSpacing * viewport.scale; + var horizontalIntervalScale = 10.0 / colPixelSpacing * viewport.scale; // 0.1 and 0.05 gives margin to horizontal and vertical lines + + var hscaleBounds = computeScaleBounds(canvasSize, 0.25, 0.05); + var vscaleBounds = computeScaleBounds(canvasSize, 0.05, 0.15); + + if (!canvasSize.width || !canvasSize.height || !hscaleBounds || !vscaleBounds) { + return; + } + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getToolColor(); + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + var imageAttributes = Object.assign({}, { + hscaleBounds: hscaleBounds, + vscaleBounds: vscaleBounds, + verticalMinorTick: verticalIntervalScale, + horizontalMinorTick: horizontalIntervalScale, + verticalLine: { + start: { + x: vscaleBounds.bottomRight.x, + y: vscaleBounds.topLeft.y + }, + end: { + x: vscaleBounds.bottomRight.x, + y: vscaleBounds.bottomRight.y + } + }, + horizontalLine: { + start: { + x: hscaleBounds.topLeft.x, + y: hscaleBounds.bottomRight.y + }, + end: { + x: hscaleBounds.bottomRight.x, + y: hscaleBounds.bottomRight.y + } + }, + color: color, + lineWidth: lineWidth + }, this.configuration); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["setShadow"])(context, imageAttributes); // Draw vertical line + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, imageAttributes.verticalLine.start, imageAttributes.verticalLine.end, { + color: imageAttributes.color, + lineWidth: imageAttributes.lineWidth + }, 'canvas'); + drawVerticalScalebarIntervals(context, element, imageAttributes); // Draw horizontal line + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, imageAttributes.horizontalLine.start, imageAttributes.horizontalLine.end, { + color: imageAttributes.color, + lineWidth: imageAttributes.lineWidth + }, 'canvas'); + drawHorizontalScalebarIntervals(context, element, imageAttributes); + }); + } + }]); + + return ScaleOverlayTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * Computes the max bound for scales on the image + * @param {{width: number, height: number}} canvasSize + * @param {number} horizontalReduction + * @param {number} verticalReduction + * @returns {Object.} + */ + + + + +var computeScaleBounds = function computeScaleBounds(canvasSize, horizontalReduction, verticalReduction) { + var hReduction = horizontalReduction * Math.min(1000, canvasSize.width); + var vReduction = verticalReduction * Math.min(1000, canvasSize.height); + var canvasBounds = { + left: hReduction, + top: vReduction, + width: canvasSize.width - 2 * hReduction, + height: canvasSize.height - 2 * vReduction + }; + return { + topLeft: { + x: canvasBounds.left, + y: canvasBounds.top + }, + bottomRight: { + x: canvasBounds.left + canvasBounds.width, + y: canvasBounds.top + canvasBounds.height + } + }; +}; +/** + * @param {CanvasRenderingContext2D} context + * @param {HTMLElement} element + * @param {Object} imageAttributes + * @returns {void} + */ + + +var drawVerticalScalebarIntervals = function drawVerticalScalebarIntervals(context, element, imageAttributes) { + var i = 0; + + while (imageAttributes.verticalLine.start.y + i * imageAttributes.verticalMinorTick <= imageAttributes.vscaleBounds.bottomRight.y) { + var color = imageAttributes.color, + lineWidth = imageAttributes.lineWidth; + var startPoint = { + x: imageAttributes.verticalLine.start.x, + y: imageAttributes.verticalLine.start.y + i * imageAttributes.verticalMinorTick + }; + var endPoint = { + x: 0, + y: imageAttributes.verticalLine.start.y + i * imageAttributes.verticalMinorTick + }; + + if (i % 5 === 0) { + endPoint.x = imageAttributes.verticalLine.start.x - imageAttributes.majorTickLength; + } else { + endPoint.x = imageAttributes.verticalLine.start.x - imageAttributes.minorTickLength; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, startPoint, endPoint, { + color: color, + lineWidth: lineWidth + }, 'canvas'); + i++; + } +}; +/** + * @param {CanvasRenderingContext2D} context + * @param {HTMLElement} element + * @param {Object} imageAttributes + * @returns {void} + */ + + +var drawHorizontalScalebarIntervals = function drawHorizontalScalebarIntervals(context, element, imageAttributes) { + var i = 0; + + while (imageAttributes.horizontalLine.start.x + i * imageAttributes.horizontalMinorTick <= imageAttributes.hscaleBounds.bottomRight.x) { + var color = imageAttributes.color, + lineWidth = imageAttributes.lineWidth; + var startPoint = { + x: imageAttributes.horizontalLine.start.x + i * imageAttributes.horizontalMinorTick, + y: imageAttributes.horizontalLine.start.y + }; + var endPoint = { + x: imageAttributes.horizontalLine.start.x + i * imageAttributes.horizontalMinorTick, + y: 0 + }; + + if (i % 5 === 0) { + endPoint.y = imageAttributes.horizontalLine.start.y - imageAttributes.majorTickLength; + } else { + endPoint.y = imageAttributes.horizontalLine.start.y - imageAttributes.minorTickLength; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, startPoint, endPoint, { + color: color, + lineWidth: lineWidth + }, 'canvas'); + i++; + } +}; + +/***/ }), + +/***/ "./tools/StackScrollMouseWheelTool.js": +/*!********************************************!*\ + !*** ./tools/StackScrollMouseWheelTool.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return StackScrollMouseWheelTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_scroll_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../util/scroll.js */ "./util/scroll.js"); + + + + + + + +/** + * @public + * @class StackScrollMouseWheelTool + * @memberof Tools + * + * @classdesc Tool for scrolling through a series using the mouse wheel. + * @extends Tools.Base.BaseTool + */ + +var StackScrollMouseWheelTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(StackScrollMouseWheelTool, _BaseTool); + + function StackScrollMouseWheelTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, StackScrollMouseWheelTool); + + var defaultProps = { + name: 'StackScrollMouseWheel', + supportedInteractionTypes: ['MouseWheel'], + configuration: { + loop: false, + allowSkipping: true, + invert: false + } + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(StackScrollMouseWheelTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(StackScrollMouseWheelTool, [{ + key: "mouseWheelCallback", + value: function mouseWheelCallback(evt) { + var _evt$detail = evt.detail, + images = _evt$detail.direction, + element = _evt$detail.element; + var _this$configuration = this.configuration, + loop = _this$configuration.loop, + allowSkipping = _this$configuration.allowSkipping, + invert = _this$configuration.invert; + var direction = invert ? -images : images; + Object(_util_scroll_js__WEBPACK_IMPORTED_MODULE_6__["default"])(element, direction, loop, allowSkipping); + } + }]); + + return StackScrollMouseWheelTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_5__["default"]); + + + +/***/ }), + +/***/ "./tools/StackScrollMultiTouchTool.js": +/*!********************************************!*\ + !*** ./tools/StackScrollMultiTouchTool.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return StackScrollMultiTouchTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_scroll_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/scroll.js */ "./util/scroll.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _toolOptions_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../toolOptions.js */ "./toolOptions.js"); + + + + + + + + + + +/** + * @public + * @class StackScrollMultiTouchTool + * @memberof Tools + * + * @classdesc Tool for scrolling through a series using multi-touch. + * @extends Tools.Base.BaseTool + */ + +var StackScrollMultiTouchTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(StackScrollMultiTouchTool, _BaseTool); + + function StackScrollMultiTouchTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, StackScrollMultiTouchTool); + + var defaultProps = { + name: 'StackScrollMultiTouch', + supportedInteractionTypes: ['MultiTouch'], + configuration: { + loop: false, + allowSkipping: true, + touchPointers: 3 + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(StackScrollMultiTouchTool).call(this, props, defaultProps)); + _this.multiTouchDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(StackScrollMultiTouchTool, [{ + key: "_dragCallback", + value: function _dragCallback(evt) { + var eventData = evt.detail; + + if (eventData.numPointers === this.configuration.touchPointers) { + var element = eventData.element, + deltaPoints = eventData.deltaPoints; + var _this$configuration = this.configuration, + loop = _this$configuration.loop, + allowSkipping = _this$configuration.allowSkipping; + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["getToolOptions"])(this.name, element); + + var pixelsPerImage = this._getPixelPerImage(element); + + var deltaY = this._getDeltaY(element, deltaPoints.page.y); + + if (!pixelsPerImage) { + return; + } + + if (Math.abs(deltaY) >= pixelsPerImage) { + var imageIdIndexOffset = Math.round(deltaY / pixelsPerImage); + Object(_util_scroll_js__WEBPACK_IMPORTED_MODULE_7__["default"])(element, imageIdIndexOffset, loop, allowSkipping); + options.deltaY = deltaY % pixelsPerImage; + } else { + options.deltaY = deltaY; + } + + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["setToolOptions"])(this.name, element, options); + } + } + }, { + key: "_getDeltaY", + value: function _getDeltaY(element, deltaPointsY) { + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["getToolOptions"])(this.name, element); + var deltaY = options.deltaY || 0; + return deltaY + deltaPointsY; + } + }, { + key: "_getPixelPerImage", + value: function _getPixelPerImage(element) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["getToolState"])(element, 'stack'); + + if (!toolData || !toolData.data || !toolData.data.length) { + return; + } + + var stackData = toolData.data[0]; + var stackScrollSpeed = this.configuration.stackScrollSpeed; // The Math.max here makes it easier to mouseDrag-scroll small or really large image stacks + + return stackScrollSpeed || Math.max(2, element.offsetHeight / Math.max(stackData.imageIds.length, 8)); + } + }]); + + return StackScrollMultiTouchTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/StackScrollTool.js": +/*!**********************************!*\ + !*** ./tools/StackScrollTool.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return StackScrollTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_scroll_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/scroll.js */ "./util/scroll.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _toolOptions_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../toolOptions.js */ "./toolOptions.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + +/** + * @public + * @class StackScrollTool + * @memberof Tools + * + * @classdesc Tool for scrolling through a series. + * @extends Tools.Base.BaseTool + */ + +var StackScrollTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(StackScrollTool, _BaseTool); + + function StackScrollTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, StackScrollTool); + + var defaultProps = { + name: 'StackScroll', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + loop: false, + allowSkipping: true + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_10__["stackScrollCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(StackScrollTool).call(this, props, defaultProps)); + _this.mouseDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.touchDragCallback = _this._dragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(StackScrollTool, [{ + key: "_dragCallback", + value: function _dragCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + deltaPoints = eventData.deltaPoints; + var _this$configuration = this.configuration, + loop = _this$configuration.loop, + allowSkipping = _this$configuration.allowSkipping; + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["getToolOptions"])(this.name, element); + + var pixelsPerImage = this._getPixelPerImage(element); + + var deltaY = this._getDeltaY(element, deltaPoints.page.y); + + if (!pixelsPerImage) { + return; + } + + if (Math.abs(deltaY) >= pixelsPerImage) { + var imageIdIndexOffset = Math.round(deltaY / pixelsPerImage); + Object(_util_scroll_js__WEBPACK_IMPORTED_MODULE_7__["default"])(element, imageIdIndexOffset, loop, allowSkipping); + options.deltaY = deltaY % pixelsPerImage; + } else { + options.deltaY = deltaY; + } + + Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["setToolOptions"])(this.name, element, options); + } + }, { + key: "_getDeltaY", + value: function _getDeltaY(element, deltaPointsY) { + var options = Object(_toolOptions_js__WEBPACK_IMPORTED_MODULE_9__["getToolOptions"])(this.name, element); + var deltaY = options.deltaY || 0; + return deltaY + deltaPointsY; + } + }, { + key: "_getPixelPerImage", + value: function _getPixelPerImage(element) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["getToolState"])(element, 'stack'); + + if (!toolData || !toolData.data || !toolData.data.length) { + return; + } + + var stackData = toolData.data[0]; + var stackScrollSpeed = this.configuration.stackScrollSpeed; // The Math.max here makes it easier to mouseDrag-scroll small or really large image stacks + + return stackScrollSpeed || Math.max(2, element.offsetHeight / Math.max(stackData.imageIds.length, 8)); + } + }]); + + return StackScrollTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/WwwcRegionTool.js": +/*!*********************************!*\ + !*** ./tools/WwwcRegionTool.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return WwwcRegionTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _util_getLuminance_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../util/getLuminance.js */ "./util/getLuminance.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + // Drawing + + + + + + +/** + * @public + * @class WwwcRegionTool + * @memberof Tools + * + * @classdesc Tool for setting wwwc based on a rectangular region. + * @extends Tools.Base.BaseTool + */ + +var WwwcRegionTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(WwwcRegionTool, _BaseTool); + + /** @inheritdoc */ + function WwwcRegionTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, WwwcRegionTool); + + var defaultProps = { + name: 'WwwcRegion', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + minWindowWidth: 10 + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_12__["wwwcRegionCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(WwwcRegionTool).call(this, props, defaultProps)); + + _this._resetHandles(); // + // Touch + // + + /** @inheritdoc */ + + + _this.postTouchStartCallback = _this._startOutliningRegion.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.touchDragCallback = _this._setHandlesAndUpdate.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.touchEndCallback = _this._applyStrategy.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); // + // MOUSE + // + + /** @inheritdoc */ + + _this.postMouseDownCallback = _this._startOutliningRegion.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.mouseClickCallback = _this._startOutliningRegion.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.mouseDragCallback = _this._setHandlesAndUpdate.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.mouseMoveCallback = _this._setHandlesAndUpdate.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + /** @inheritdoc */ + + _this.mouseUpCallback = _this._applyStrategy.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + /** + * Render hook: draws the WWWCRegion's "box" when selecting + * + * @param {Cornerstone.event#cornerstoneimagerendered} evt cornerstoneimagerendered event + * @memberof Tools.WwwcRegionTool + * @returns {void} + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(WwwcRegionTool, [{ + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; + var element = eventData.element; + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__["default"].getColorIfActive({ + active: true + }); + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_8__["getNewContext"])(eventData.canvasContext.canvas); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_8__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_8__["drawRect"])(context, element, _this2.handles.start, _this2.handles.end, { + color: color + }); + }); + } + /** + * Sets the start handle point and claims the eventDispatcher event + * + * @private + * @param {*} evt // mousedown, touchstart, click + * @returns {Boolean} True + */ + + }, { + key: "_startOutliningRegion", + value: function _startOutliningRegion(evt) { + var consumeEvent = true; + var element = evt.detail.element; + var image = evt.detail.currentPoints.image; + + if (_isEmptyObject(this.handles.start)) { + this.handles.start = image; + } else { + this.handles.end = image; + + this._applyStrategy(evt); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + return consumeEvent; + } + /** + * This function will update the handles and updateImage to force re-draw + * + * @private + * @method _setHandlesAndUpdate + * @param {(CornerstoneTools.event#TOUCH_DRAG|CornerstoneTools.event#MOUSE_DRAG|CornerstoneTools.event#MOUSE_MOVE)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + }, { + key: "_setHandlesAndUpdate", + value: function _setHandlesAndUpdate(evt) { + var element = evt.detail.element; + var image = evt.detail.currentPoints.image; + this.handles.end = image; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); + } + /** + * Event handler for MOUSE_UP/TOUCH_END during handle drag event loop. + * + * @private + * @method _applyStrategy + * @param {(CornerstoneTools.event#MOUSE_UP|CornerstoneTools.event#TOUCH_END)} evt Interaction event emitted by an enabledElement + * @returns {void} + */ + + }, { + key: "_applyStrategy", + value: function _applyStrategy(evt) { + if (_isEmptyObject(this.handles.start) || _isEmptyObject(this.handles.end)) { + return; + } + + evt.detail.handles = this.handles; + + _applyWWWCRegion(evt, this.configuration); + + this._resetHandles(); + } + /** + * Sets the start and end handle points to empty objects + * + * @private + * @method _resetHandles + * @returns {undefined} + */ + + }, { + key: "_resetHandles", + value: function _resetHandles() { + this.handles = { + start: {}, + end: {} + }; + } + }]); + + return WwwcRegionTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); +/** + * Helper to determine if an object has no keys and is the correct type (is empty) + * + * @private + * @function _isEmptyObject + * @param {Object} obj The object to check + * @returns {Boolean} true if the object is empty + */ + + + + +var _isEmptyObject = function _isEmptyObject(obj) { + return Object.keys(obj).length === 0 && obj.constructor === Object; +}; +/** + * Calculates the minimum and maximum value in the given pixel array + * and updates the viewport of the element in the event. + * + * @private + * @method _applyWWWCRegion + * @param {(CornerstoneTools.event#MOUSE_UP|CornerstoneTools.event#TOUCH_END)} evt Interaction event emitted by an enabledElement + * @param {Object} config The tool's configuration object + * @returns {void} + */ + + +var _applyWWWCRegion = function _applyWWWCRegion(evt, config) { + var eventData = evt.detail; + var image = eventData.image, + element = eventData.element; + var _evt$detail$handles = evt.detail.handles, + startPoint = _evt$detail$handles.start, + endPoint = _evt$detail$handles.end; // Get the rectangular region defined by the handles + + var left = Math.min(startPoint.x, endPoint.x); + var top = Math.min(startPoint.y, endPoint.y); + var width = Math.abs(startPoint.x - endPoint.x); + var height = Math.abs(startPoint.y - endPoint.y); // Bound the rectangle so we don't get undefined pixels + + left = Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_9__["default"])(left, 0, image.width); + top = Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_9__["default"])(top, 0, image.height); + width = Math.floor(Math.min(width, Math.abs(image.width - left))); + height = Math.floor(Math.min(height, Math.abs(image.height - top))); // Get the pixel data in the rectangular region + + var pixelLuminanceData = Object(_util_getLuminance_js__WEBPACK_IMPORTED_MODULE_10__["default"])(element, left, top, width, height); // Calculate the minimum and maximum pixel values + + var minMaxMean = _calculateMinMaxMean(pixelLuminanceData, image.minPixelValue, image.maxPixelValue); // Adjust the viewport window width and center based on the calculated values + + + var viewport = eventData.viewport; + + if (config.minWindowWidth === undefined) { + config.minWindowWidth = 10; + } + + viewport.voi.windowWidth = Math.max(Math.abs(minMaxMean.max - minMaxMean.min), config.minWindowWidth); + viewport.voi.windowCenter = minMaxMean.mean; // Unset any existing VOI LUT + + viewport.voiLUT = undefined; + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.setViewport(element, viewport); + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(element); +}; +/** + * Calculates the minimum, maximum, and mean value in the given pixel array + * + * @private + * @method _calculateMinMaxMean + * @param {number[]} pixelLuminance array of pixel luminance values + * @param {number} globalMin starting "min" valie + * @param {bumber} globalMax starting "max" value + * @returns {Object} {min: number, max: number, mean: number } + */ + + +var _calculateMinMaxMean = function _calculateMinMaxMean(pixelLuminance, globalMin, globalMax) { + var numPixels = pixelLuminance.length; + var min = globalMax; + var max = globalMin; + var sum = 0; + + if (numPixels < 2) { + return { + min: min, + max: max, + mean: (globalMin + globalMax) / 2 + }; + } + + for (var index = 0; index < numPixels; index++) { + var spv = pixelLuminance[index]; + min = Math.min(min, spv); + max = Math.max(max, spv); + sum += spv; + } + + return { + min: min, + max: max, + mean: sum / numPixels + }; +}; + +/***/ }), + +/***/ "./tools/WwwcTool.js": +/*!***************************!*\ + !*** ./tools/WwwcTool.js ***! + \***************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return WwwcTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + +/** + * @public + * @class WwwcTool + * @memberof Tools + * + * @classdesc Tool for setting wwwc by dragging with mouse/touch. + * @extends Tools.Base.BaseTool + */ + +var WwwcTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(WwwcTool, _BaseTool); + + function WwwcTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, WwwcTool); + + var defaultProps = { + name: 'Wwwc', + strategies: { + basicLevelingStrategy: basicLevelingStrategy + }, + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + orientation: 0 + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_7__["wwwcCursor"] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(WwwcTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(WwwcTool, [{ + key: "mouseDragCallback", + value: function mouseDragCallback(evt) { + this.applyActiveStrategy(evt); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(evt.detail.element, evt.detail.viewport); + } + }, { + key: "touchDragCallback", + value: function touchDragCallback(evt) { + // Prevent CornerstoneToolsTouchStartActive from killing any press events + evt.stopImmediatePropagation(); + this.applyActiveStrategy(evt); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(evt.detail.element, evt.detail.viewport); + } + }]); + + return WwwcTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * Here we normalize the ww/wc adjustments so the same number of on screen pixels + * adjusts the same percentage of the dynamic range of the image. This is needed to + * provide consistency for the ww/wc tool regardless of the dynamic range (e.g. an 8 bit + * image will feel the same as a 16 bit image would) + * + * @param {Object} evt + * @param {Object} { orienttion } + * @returns {void} + */ + + + + +function basicLevelingStrategy(evt) { + var orientation = this.configuration.orientation; + var eventData = evt.detail; + var maxVOI = eventData.image.maxPixelValue * eventData.image.slope + eventData.image.intercept; + var minVOI = eventData.image.minPixelValue * eventData.image.slope + eventData.image.intercept; + var imageDynamicRange = maxVOI - minVOI; + var multiplier = imageDynamicRange / 1024; + var deltaX = eventData.deltaPoints.page.x * multiplier; + var deltaY = eventData.deltaPoints.page.y * multiplier; + + if (orientation === 0) { + eventData.viewport.voi.windowWidth += deltaX; + eventData.viewport.voi.windowCenter += deltaY; + } else { + eventData.viewport.voi.windowWidth += deltaY; + eventData.viewport.voi.windowCenter += deltaX; + } // Unset any existing VOI LUT + + + eventData.viewport.voiLUT = undefined; +} + +/***/ }), + +/***/ "./tools/ZoomMouseWheelTool.js": +/*!*************************************!*\ + !*** ./tools/ZoomMouseWheelTool.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ZoomMouseWheelTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/zoom/index.js */ "./util/zoom/index.js"); + + + + + + + + +/** + * @public + * @class ZoomMouseWheelTool + * @memberof Tools + * + * @classdesc Tool for changing magnification with the mouse wheel. + * @extends Tools.Base.BaseTool + */ + +var ZoomMouseWheelTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ZoomMouseWheelTool, _BaseTool); + + function ZoomMouseWheelTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ZoomMouseWheelTool); + + var defaultProps = { + name: 'ZoomMouseWheel', + supportedInteractionTypes: ['MouseWheel'], + configuration: { + minScale: 0.25, + maxScale: 20.0, + invert: false + } + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ZoomMouseWheelTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ZoomMouseWheelTool, [{ + key: "mouseWheelCallback", + value: function mouseWheelCallback(evt) { + var _evt$detail = evt.detail, + element = _evt$detail.element, + viewport = _evt$detail.viewport, + spinY = _evt$detail.spinY; + var _this$configuration = this.configuration, + invert = _this$configuration.invert, + maxScale = _this$configuration.maxScale, + minScale = _this$configuration.minScale; + var ticks = invert ? spinY / 4 : -spinY / 4; + var updatedViewport = Object(_util_zoom_index_js__WEBPACK_IMPORTED_MODULE_7__["changeViewportScale"])(viewport, ticks, { + maxScale: maxScale, + minScale: minScale + }); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(element, updatedViewport); + } + }]); + + return ZoomMouseWheelTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/ZoomTool.js": +/*!***************************!*\ + !*** ./tools/ZoomTool.js ***! + \***************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ZoomTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../util/zoom/index.js */ "./util/zoom/index.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + +var correctShift = _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_8__["default"].correctShift, + changeViewportScale = _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_8__["default"].changeViewportScale; +/** + * @public + * @class ZoomTool + * @memberof Tools + * + * @classdesc Tool for changing magnification. + * @extends Tools.Base.BaseTool + */ + +var ZoomTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ZoomTool, _BaseTool); + + function ZoomTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ZoomTool); + + var defaultProps = { + name: 'Zoom', + strategies: { + default: defaultStrategy, + translate: translateStrategy, + zoomToCenter: zoomToCenterStrategy + }, + defaultStrategy: 'default', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + invert: false, + preventZoomOutsideImage: false, + minScale: 0.25, + maxScale: 20.0 + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_9__["zoomCursor"] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ZoomTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ZoomTool, [{ + key: "touchDragCallback", + value: function touchDragCallback(evt) { + dragCallback.call(this, evt); + } + }, { + key: "mouseDragCallback", + value: function mouseDragCallback(evt) { + dragCallback.call(this, evt); + } + }]); + + return ZoomTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +var dragCallback = function dragCallback(evt) { + var deltaY = evt.detail.deltaPoints.page.y; + + if (!deltaY) { + return false; + } + + this.applyActiveStrategy(evt, this.configuration); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(evt.detail.element, evt.detail.viewport); +}; +/** + * The default strategy keeps the target location fixed on the page + * as we zoom in/out. + * + * @param {*} evt + * @param {*} { invert, maxScale, minScale } + * @returns {void} + */ + + +function defaultStrategy(evt) { + var _this$configuration = this.configuration, + invert = _this$configuration.invert, + maxScale = _this$configuration.maxScale, + minScale = _this$configuration.minScale; + var deltaY = evt.detail.deltaPoints.page.y; + var ticks = invert ? -deltaY / 100 : deltaY / 100; + var _evt$detail = evt.detail, + element = _evt$detail.element, + viewport = _evt$detail.viewport; + var _ref = [evt.detail.startPoints.page.x, evt.detail.startPoints.page.y, evt.detail.startPoints.image.x, evt.detail.startPoints.image.y], + startX = _ref[0], + startY = _ref[1], + imageX = _ref[2], + imageY = _ref[3]; // Calculate the new scale factor based on how far the mouse has changed + + var updatedViewport = changeViewportScale(viewport, ticks, { + maxScale: maxScale, + minScale: minScale + }); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(element, updatedViewport); // Now that the scale has been updated, determine the offset we need to apply to the center so we can + // Keep the original start location in the same position + + var newCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pageToPixel(element, startX, startY); // The shift we will use is the difference between the original image coordinates of the point we've selected + // And the image coordinates of the same point on the page after the viewport scaling above has been performed + // This shift is in image coordinates, and is designed to keep the target location fixed on the page. + + var shift = { + x: imageX - newCoords.x, + y: imageY - newCoords.y + }; // Correct the required shift using the viewport rotation and flip parameters + + shift = correctShift(shift, updatedViewport); // Apply the shift to the Viewport's translation setting + + viewport.translation.x -= shift.x; + viewport.translation.y -= shift.y; +} + +function translateStrategy(evt) { + var _this$configuration2 = this.configuration, + invert = _this$configuration2.invert, + preventZoomOutsideImage = _this$configuration2.preventZoomOutsideImage, + maxScale = _this$configuration2.maxScale, + minScale = _this$configuration2.minScale; + var deltaY = evt.detail.deltaPoints.page.y; + var ticks = invert ? -deltaY / 100 : deltaY / 100; + var image = evt.detail.image; + var viewport = evt.detail.viewport; + var _ref2 = [evt.detail.startPoints.image.x, evt.detail.startPoints.image.y], + startX = _ref2[0], + startY = _ref2[1]; // Calculate the new scale factor based on how far the mouse has changed + // Note that in this case we don't need to update the viewport after the initial + // Zoom step since we aren't don't intend to keep the target position static on + // The page + + var updatedViewport = changeViewportScale(viewport, ticks, { + maxScale: maxScale, + minScale: minScale + }); // Define the default shift to take place during this zoom step + + var shift = { + x: 0, + y: 0 + }; // Define the parameters for the translate strategy + + var translateSpeed = 8; + var outwardsMinScaleToTranslate = 3; + var minTranslation = 0.01; + + if (ticks < 0) { + // Zoom outwards from the image center + if (updatedViewport.scale < outwardsMinScaleToTranslate) { + // If the current translation is smaller than the minimum desired translation, + // Set the translation to zero + if (Math.abs(updatedViewport.translation.x) < minTranslation) { + updatedViewport.translation.x = 0; + } else { + shift.x = updatedViewport.translation.x / translateSpeed; + } // If the current translation is smaller than the minimum desired translation, + // Set the translation to zero + + + if (Math.abs(updatedViewport.translation.y) < minTranslation) { + updatedViewport.translation.y = 0; + } else { + shift.y = updatedViewport.translation.y / translateSpeed; + } + } + } else { + // Zoom inwards to the current image point + // Identify the coordinates of the point the user is trying to zoom into + // If we are not allowed to zoom outside the image, bound the user-selected position to + // A point inside the image + if (preventZoomOutsideImage) { + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_7__["clipToBox"])(evt.detail.startPoints.image, image); + } // Calculate the translation value that would place the desired image point in the center + // Of the viewport + + + var desiredTranslation = { + x: image.width / 2 - startX, + y: image.height / 2 - startY + }; // Correct the target location using the viewport rotation and flip parameters + + desiredTranslation = correctShift(desiredTranslation, updatedViewport); // Calculate the difference between the current viewport translation value and the + // Final desired translation values + + var distanceToDesired = { + x: updatedViewport.translation.x - desiredTranslation.x, + y: updatedViewport.translation.y - desiredTranslation.y + }; // If the current translation is smaller than the minimum desired translation, + // Stop translating in the x-direction + + if (Math.abs(distanceToDesired.x) < minTranslation) { + updatedViewport.translation.x = desiredTranslation.x; + } else { + // Otherwise, shift the viewport by one step + shift.x = distanceToDesired.x / translateSpeed; + } // If the current translation is smaller than the minimum desired translation, + // Stop translating in the y-direction + + + if (Math.abs(distanceToDesired.y) < minTranslation) { + updatedViewport.translation.y = desiredTranslation.y; + } else { + // Otherwise, shift the viewport by one step + shift.y = distanceToDesired.y / translateSpeed; + } + } // Apply the shift to the Viewport's translation setting + + + updatedViewport.translation.x -= shift.x; + updatedViewport.translation.y -= shift.y; +} + +function zoomToCenterStrategy(evt) { + var _this$configuration3 = this.configuration, + invert = _this$configuration3.invert, + maxScale = _this$configuration3.maxScale, + minScale = _this$configuration3.minScale; + var deltaY = evt.detail.deltaPoints.page.y; + var ticks = invert ? -deltaY / 100 : deltaY / 100; + var viewport = evt.detail.viewport; // Calculate the new scale factor based on how far the mouse has changed + + changeViewportScale(viewport, ticks, { + maxScale: maxScale, + minScale: minScale + }); +} + +/***/ }), + +/***/ "./tools/ZoomTouchPinchTool.js": +/*!*************************************!*\ + !*** ./tools/ZoomTouchPinchTool.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ZoomTouchPinchTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./base/BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/zoom/index.js */ "./util/zoom/index.js"); + + + + + + + + +var correctShift = _util_zoom_index_js__WEBPACK_IMPORTED_MODULE_7__["default"].correctShift; +/** + * + * + * @public + * @class ZoomTouchPinchTool + * @memberof Tools + * + * @extends {BaseTool} + */ + +var ZoomTouchPinchTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ZoomTouchPinchTool, _BaseTool); + + function ZoomTouchPinchTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ZoomTouchPinchTool); + + var defaultProps = { + name: 'ZoomTouchPinch', + // TODO: Do we need a better way to specify touchPinch? + supportedInteractionTypes: ['TouchPinch'], + configuration: { + minScale: 0.25, + maxScale: 20.0 + } + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ZoomTouchPinchTool).call(this, props, defaultProps)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ZoomTouchPinchTool, [{ + key: "touchPinchCallback", + value: function touchPinchCallback(evt) { + var _evt$detail = evt.detail, + element = _evt$detail.element, + viewport = _evt$detail.viewport, + scaleChange = _evt$detail.scaleChange; + var _ref = [evt.detail.startPoints.page.x, evt.detail.startPoints.page.y, evt.detail.startPoints.image.x, evt.detail.startPoints.image.y], + pageStartX = _ref[0], + pageStartY = _ref[1], + imageStartX = _ref[2], + imageStartY = _ref[3]; + var _this$configuration = this.configuration, + maxScale = _this$configuration.maxScale, + minScale = _this$configuration.minScale; // Change the scale based on the pinch gesture's scale change + + viewport.scale += scaleChange * viewport.scale; + + if (maxScale && viewport.scale > maxScale) { + viewport.scale = maxScale; + } else if (minScale && viewport.scale < minScale) { + viewport.scale = minScale; + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(element, viewport); // Now that the scale has been updated, determine the offset we need to apply to the center so we can + // Keep the original start location in the same position + + var newCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pageToPixel(element, pageStartX, pageStartY); + var shift = { + x: imageStartX - newCoords.x, + y: imageStartY - newCoords.y + }; + shift = correctShift(shift, viewport); + viewport.translation.x -= shift.x; + viewport.translation.y -= shift.y; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.setViewport(element, viewport); + } + }]); + + return ZoomTouchPinchTool; +}(_base_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/annotation/AngleTool.js": +/*!***************************************!*\ + !*** ./tools/annotation/AngleTool.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return AngleTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../util/lineSegDistance.js */ "./util/lineSegDistance.js"); +/* harmony import */ var _util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../util/roundToDecimal.js */ "./util/roundToDecimal.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../../events.js */ "./events.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + + // State + + + + // Manipulators + + // Drawing + + + + + + + + + + + + + +/** + * @public + * @class AngleTool + * @memberof Tools.Annotation + * @classdesc Create and position an angle by placing three consecutive points. + * @extends Tools.Base.BaseAnnotationTool + * @hideconstructor + * + * @param {ToolConfiguration} [props={}] + */ + +var AngleTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(AngleTool, _BaseAnnotationTool); + + function AngleTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, AngleTool); + + var defaultProps = { + name: 'Angle', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_17__["angleCursor"], + configuration: { + drawHandles: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + renderDashed: false + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(AngleTool).call(this, props, defaultProps)); + _this.preventNewMeasurement = false; + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_21__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(AngleTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + // Create the measurement data for this tool with the end handle activated + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + start: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + middle: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + }, + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + if (data.visible === false) { + return false; + } + + return Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__["default"])(element, data.handles.start, data.handles.middle, coords) < 25 || Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__["default"])(element, data.handles.middle, data.handles.end, coords) < 25; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var sideA = getSide(image, data.handles.middle, data.handles.start); + var sideB = getSide(image, data.handles.end, data.handles.middle); + var sideC = getSide(image, data.handles.end, data.handles.start); + var sideALength = length(sideA); + var sideBLength = length(sideB); + var sideCLength = length(sideC); // Cosine law + + var angle = Math.acos((Math.pow(sideALength, 2) + Math.pow(sideBLength, 2) - Math.pow(sideCLength, 2)) / (2 * sideALength * sideBLength)); + angle *= 180 / Math.PI; + data.rAngle = Object(_util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_16__["default"])(angle, 2); + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; + var enabledElement = eventData.enabledElement; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["getToolState"])(evt.currentTarget, this.name); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_22__["getModule"])('globalConfiguration').configuration.lineDash; + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["getNewContext"])(eventData.canvasContext.canvas); + var image = eventData.image, + element = eventData.element; + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_20__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; + + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["setShadow"])(context, _this2.configuration); // Differentiate the color of activation tool + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + var handleStartCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(eventData.element, data.handles.start); + var handleMiddleCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(eventData.element, data.handles.middle); + var lineOptions = { + color: color + }; + + if (renderDashed) { + lineOptions.lineDash = lineDash; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawJoinedLines"])(context, eventData.element, data.handles.start, [data.handles.middle, data.handles.end], lineOptions); // Draw the handles + + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_14__["default"])(context, eventData, data.handles, handleOptions); + } // Update textbox stats + + + if (data.invalidated === true) { + if (data.rAngle) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } + + if (data.rAngle) { + var text = textBoxText(data, rowPixelSpacing, colPixelSpacing); + var distance = 15; + var textCoords; + + if (!data.handles.textBox.hasMoved) { + textCoords = { + x: handleMiddleCanvas.x, + y: handleMiddleCanvas.y + }; + var padding = 5; + var textWidth = Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_13__["textBoxWidth"])(context, text, padding); + + if (handleMiddleCanvas.x < handleStartCanvas.x) { + textCoords.x -= distance + textWidth + 10; + } else { + textCoords.x += distance; + } + + var transform = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.internal.getTransform(enabledElement); + transform.invert(); + var coords = transform.transformPoint(textCoords.x, textCoords.y); + data.handles.textBox.x = coords.x; + data.handles.textBox.y = coords.y; + } + + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_12__["default"])(context, eventData.element, data.handles.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, 0, true); + } + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + + function textBoxText(data, rowPixelSpacing, colPixelSpacing) { + var suffix = !rowPixelSpacing || !colPixelSpacing ? ' (isotropic)' : ''; + var str = '00B0'; // Degrees symbol + + return data.rAngle.toString() + String.fromCharCode(parseInt(str, 16)) + suffix; + } + + function textBoxAnchorPoints(handles) { + return [handles.start, handles.middle, handles.end]; + } + } + }, { + key: "addNewMeasurement", + value: function addNewMeasurement(evt, interactionType) { + var _this3 = this; + + if (this.preventNewMeasurement) { + return; + } + + this.preventNewMeasurement = true; + evt.preventDefault(); + evt.stopPropagation(); + var eventData = evt.detail; + var measurementData = this.createNewMeasurement(eventData); + var element = evt.detail.element; // Associate this data with this imageId so we can render it and manipulate it + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["addToolState"])(element, this.name, measurementData); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); // Step 1, create start and second middle. + + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_10__["moveNewHandle"])(eventData, this.name, measurementData, measurementData.handles.middle, this.options, interactionType, function (success) { + measurementData.active = false; + + if (!success) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["removeToolState"])(element, _this3.name, measurementData); + _this3.preventNewMeasurement = false; + return; + } + + measurementData.handles.end.active = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); // Step 2, create end. + + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_10__["moveNewHandle"])(eventData, _this3.name, measurementData, measurementData.handles.end, _this3.options, interactionType, function (success) { + if (success) { + measurementData.active = false; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + } else { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["removeToolState"])(element, _this3.name, measurementData); + } + + _this3.preventNewMeasurement = false; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + var modifiedEventData = { + toolName: _this3.name, + toolType: _this3.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_18__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_19__["default"].MEASUREMENT_COMPLETED, modifiedEventData); + }); + }); + } + }]); + + return AngleTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +function length(vector) { + return Math.sqrt(Math.pow(vector.x, 2) + Math.pow(vector.y, 2)); +} + +function getSide(image, handleEnd, handleStart) { + var _getPixelSpacing2 = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_20__["default"])(image), + rowPixelSpacing = _getPixelSpacing2.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing2.colPixelSpacing; + + return { + x: (handleEnd.x - handleStart.x) * (colPixelSpacing || 1), + y: (handleEnd.y - handleStart.y) * (rowPixelSpacing || 1) + }; +} + +/***/ }), + +/***/ "./tools/annotation/ArrowAnnotateTool.js": +/*!***********************************************!*\ + !*** ./tools/annotation/ArrowAnnotateTool.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ArrowAnnotateTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../events.js */ "./events.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); +/* harmony import */ var _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../util/lineSegDistance.js */ "./util/lineSegDistance.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawArrow_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./../../drawing/drawArrow.js */ "./drawing/drawArrow.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./../../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + +/* eslint no-alert: 0 */ + + + + + + + + + + + + + + + + + + +/** + * @public + * @class ArrowAnnotateTool + * @memberof Tools.Annotation + * @classdesc Create and position an arrow and label + * @extends Tools.Base.BaseAnnotationTool + */ + +var ArrowAnnotateTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ArrowAnnotateTool, _BaseAnnotationTool); + + function ArrowAnnotateTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ArrowAnnotateTool); + + var defaultProps = { + name: 'ArrowAnnotate', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + getTextCallback: getTextCallback, + changeTextCallback: changeTextCallback, + drawHandles: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + arrowFirst: true, + renderDashed: false, + allowEmptyLabel: false + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_21__["arrowAnnotateCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ArrowAnnotateTool).call(this, props, defaultProps)); + _this.preventNewMeasurement = false; + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ArrowAnnotateTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(evt) { + // Create the measurement data for this tool with the end handle activated + return { + visible: true, + active: true, + color: undefined, + handles: { + start: { + x: evt.detail.currentPoints.image.x, + y: evt.detail.currentPoints.image.y, + highlight: true, + active: false + }, + end: { + x: evt.detail.currentPoints.image.x, + y: evt.detail.currentPoints.image.y, + highlight: true, + active: false + }, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + if (data.visible === false) { + return false; + } + + return Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, data.handles.start, data.handles.end, coords) < 25; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats() {// Implementing to satisfy BaseAnnotationTool + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var _evt$detail = evt.detail, + element = _evt$detail.element, + enabledElement = _evt$detail.enabledElement; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["getToolState"])(element, this.name); + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var canvas = evt.detail.canvasContext.canvas; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_17__["getNewContext"])(canvas); + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + var lineDash; + + if (renderDashed) { + lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_22__["getModule"])('globalConfiguration').configuration.lineDash; + } + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_17__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_17__["setShadow"])(context, _this2.configuration); + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_10__["default"].getColorIfActive(data); // Draw the arrow + + var handleStartCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.start); + var handleEndCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); // Config.arrowFirst = false; + + if (_this2.configuration.arrowFirst) { + Object(_drawing_drawArrow_js__WEBPACK_IMPORTED_MODULE_18__["default"])(context, handleEndCanvas, handleStartCanvas, color, lineWidth, lineDash); + } else { + Object(_drawing_drawArrow_js__WEBPACK_IMPORTED_MODULE_18__["default"])(context, handleStartCanvas, handleEndCanvas, color, lineWidth, lineDash); + } + + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_19__["default"])(context, evt.detail, data.handles, handleOptions); + } + + var text = textBoxText(data); // Draw the text + + if (text && text !== '') { + // Calculate the text coordinates. + var padding = 5; + var textWidth = Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_20__["textBoxWidth"])(context, text, padding); + var textHeight = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_9__["default"].getFontSize() + 10; + var distance = Math.max(textWidth, textHeight) / 2 + 5; + + if (handleEndCanvas.x < handleStartCanvas.x) { + distance = -distance; + } + + if (!data.handles.textBox.hasMoved) { + var textCoords; + + if (_this2.configuration.arrowFirst) { + textCoords = { + x: handleEndCanvas.x - textWidth / 2 + distance, + y: handleEndCanvas.y - textHeight / 2 + }; + } else { + // If the arrow is at the End position, the text should + // Be placed near the Start position + textCoords = { + x: handleStartCanvas.x - textWidth / 2 - distance, + y: handleStartCanvas.y - textHeight / 2 + }; + } + + var transform = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.internal.getTransform(enabledElement); + transform.invert(); + var coords = transform.transformPoint(textCoords.x, textCoords.y); + data.handles.textBox.x = coords.x; + data.handles.textBox.y = coords.y; + } + + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_16__["default"])(context, element, data.handles.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, 0, false); + } + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + + function textBoxText(data) { + return data.text; + } + + function textBoxAnchorPoints(handles) { + var midpoint = { + x: (handles.start.x + handles.end.x) / 2, + y: (handles.start.y + handles.end.y) / 2 + }; + return [handles.start, midpoint, handles.end]; + } + } + }, { + key: "addNewMeasurement", + value: function addNewMeasurement(evt, interactionType) { + var _this3 = this; + + var element = evt.detail.element; + var measurementData = this.createNewMeasurement(evt); + var allowEmptyLabel = this.configuration.allowEmptyLabel; // Associate this data with this imageId so we can render it and manipulate it + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["addToolState"])(element, this.name, measurementData); + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_11__["moveNewHandle"])(evt.detail, this.name, measurementData, measurementData.handles.end, this.options, interactionType, function (success) { + if (success) { + if (measurementData.text === undefined) { + _this3.configuration.getTextCallback(function (text) { + if (text || allowEmptyLabel) { + measurementData.text = text; + measurementData.active = false; + var modifiedEventData = { + toolName: _this3.name, + toolType: _this3.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_14__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MEASUREMENT_COMPLETED, modifiedEventData); + } else { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["removeToolState"])(element, _this3.name, measurementData); + } + }, evt.detail); + } + } else { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["removeToolState"])(element, _this3.name, measurementData); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + }); + } + }, { + key: "doubleClickCallback", + value: function doubleClickCallback(evt) { + return this._updateTextForNearbyAnnotation(evt); + } + }, { + key: "touchPressCallback", + value: function touchPressCallback(evt) { + return this._updateTextForNearbyAnnotation(evt); + } + }, { + key: "_updateTextForNearbyAnnotation", + value: function _updateTextForNearbyAnnotation(evt) { + var element = evt.detail.element; + var coords = evt.detail.currentPoints.canvas; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["getToolState"])(element, this.name); + + if (!toolState) { + return false; + } + + for (var i = 0; i < toolState.data.length; i++) { + var data = toolState.data[i]; + + if (this.pointNearTool(element, data, coords) || Object(_util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_12__["default"])(data.handles.textBox, coords)) { + data.active = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); // Allow relabelling via a callback + + this.configuration.changeTextCallback(data, evt.detail, this._doneChangingTextCallback.bind(this, element, data)); + evt.stopImmediatePropagation(); + evt.preventDefault(); + evt.stopPropagation(); + return true; + } + } + } + }, { + key: "_doneChangingTextCallback", + value: function _doneChangingTextCallback(element, measurementData, updatedText, deleteTool) { + if (deleteTool === true) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_15__["removeToolState"])(element, this.name, measurementData); + } else { + measurementData.text = updatedText; + } + + measurementData.active = false; + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_14__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MEASUREMENT_MODIFIED, { + toolName: this.name, + toolType: this.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }); + } + }]); + + return ArrowAnnotateTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +function getTextCallback(doneChangingTextCallback) { + doneChangingTextCallback(prompt('请输入注释:')); +} + +function changeTextCallback(data, eventData, doneChangingTextCallback) { + doneChangingTextCallback(prompt('请输入注释:')); +} + +/***/ }), + +/***/ "./tools/annotation/BidirectionalTool.js": +/*!***********************************************!*\ + !*** ./tools/annotation/BidirectionalTool.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BidirectionalTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _bidirectionalTool_createNewMeasurement_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./bidirectionalTool/createNewMeasurement.js */ "./tools/annotation/bidirectionalTool/createNewMeasurement.js"); +/* harmony import */ var _bidirectionalTool_pointNearTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./bidirectionalTool/pointNearTool.js */ "./tools/annotation/bidirectionalTool/pointNearTool.js"); +/* harmony import */ var _bidirectionalTool_renderToolData_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./bidirectionalTool/renderToolData.js */ "./tools/annotation/bidirectionalTool/renderToolData.js"); +/* harmony import */ var _bidirectionalTool_addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./bidirectionalTool/addNewMeasurement.js */ "./tools/annotation/bidirectionalTool/addNewMeasurement.js"); +/* harmony import */ var _bidirectionalTool_mouseMoveCallback_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./bidirectionalTool/mouseMoveCallback.js */ "./tools/annotation/bidirectionalTool/mouseMoveCallback.js"); +/* harmony import */ var _bidirectionalTool_handleSelectedCallback_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./bidirectionalTool/handleSelectedCallback.js */ "./tools/annotation/bidirectionalTool/handleSelectedCallback.js"); +/* harmony import */ var _bidirectionalTool_handleSelectedMouseCallback_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./bidirectionalTool/handleSelectedMouseCallback.js */ "./tools/annotation/bidirectionalTool/handleSelectedMouseCallback.js"); +/* harmony import */ var _bidirectionalTool_handleSelectedTouchCallback_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./bidirectionalTool/handleSelectedTouchCallback.js */ "./tools/annotation/bidirectionalTool/handleSelectedTouchCallback.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _bidirectionalTool_utils_calculateLongestAndShortestDiameters__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./bidirectionalTool/utils/calculateLongestAndShortestDiameters */ "./tools/annotation/bidirectionalTool/utils/calculateLongestAndShortestDiameters.js"); + + + + + + + + + + + + + + + + + + + + +var emptyLocationCallback = function emptyLocationCallback(measurementData, eventData, doneCallback) { + return doneCallback(); +}; +/** + * @public + * @class BidirectionalTool + * @memberof Tools.Annotation + * @classdesc Create and position an annotation that measures the + * length and width of a region. + * @extends Tools.Base.BaseAnnotationTool + */ + + +var BidirectionalTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(BidirectionalTool, _BaseAnnotationTool); + + function BidirectionalTool(props) { + var _this; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, BidirectionalTool); + + var defaultProps = { + name: 'Bidirectional', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + changeMeasurementLocationCallback: emptyLocationCallback, + getMeasurementLocationCallback: emptyLocationCallback, + textBox: '', + shadow: '', + drawHandles: true, + drawHandlesOnHover: true, + hideHandlesIfMoving: false, + renderDashed: false, + additionalData: [] + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__["bidirectionalCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(BidirectionalTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_16__["default"])(_this.updateCachedStats, 110); + _this.createNewMeasurement = _bidirectionalTool_createNewMeasurement_js__WEBPACK_IMPORTED_MODULE_7__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.pointNearTool = _bidirectionalTool_pointNearTool_js__WEBPACK_IMPORTED_MODULE_8__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.renderToolData = _bidirectionalTool_renderToolData_js__WEBPACK_IMPORTED_MODULE_9__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.addNewMeasurement = _bidirectionalTool_addNewMeasurement_js__WEBPACK_IMPORTED_MODULE_10__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._moveCallback = _bidirectionalTool_mouseMoveCallback_js__WEBPACK_IMPORTED_MODULE_11__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.handleSelectedCallback = _bidirectionalTool_handleSelectedCallback_js__WEBPACK_IMPORTED_MODULE_12__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.handleSelectedMouseCallback = _bidirectionalTool_handleSelectedMouseCallback_js__WEBPACK_IMPORTED_MODULE_13__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.handleSelectedTouchCallback = _bidirectionalTool_handleSelectedTouchCallback_js__WEBPACK_IMPORTED_MODULE_14__["default"].bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(BidirectionalTool, [{ + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + // Prevent updating other tools' data + if (data.toolName !== this.name) { + return; + } + + var pixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_17__["default"])(image); + + var _calculateLongestAndS = Object(_bidirectionalTool_utils_calculateLongestAndShortestDiameters__WEBPACK_IMPORTED_MODULE_18__["default"])(data, pixelSpacing), + longestDiameter = _calculateLongestAndS.longestDiameter, + shortestDiameter = _calculateLongestAndS.shortestDiameter; // Set measurement text to show lesion table + + + data.longestDiameter = longestDiameter; + data.shortestDiameter = shortestDiameter; + data.invalidated = false; + } + }]); + + return BidirectionalTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/annotation/CircleRoiTool.js": +/*!*******************************************!*\ + !*** ./tools/annotation/CircleRoiTool.js ***! + \*******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CircleRoiTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../util/ellipse/index.js */ "./util/ellipse/index.js"); +/* harmony import */ var _util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../util/getROITextBoxCoords.js */ "./util/getROITextBoxCoords.js"); +/* harmony import */ var _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../util/numbersWithCommas.js */ "./util/numbersWithCommas.js"); +/* harmony import */ var _util_throttle_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../util/throttle.js */ "./util/throttle.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_getCircleCoords__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../../util/getCircleCoords */ "./util/getCircleCoords.js"); + + + + + + + // State + + + + + // Drawing + + // Util + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_17__["getLogger"])('tools:annotation:CircleRoiTool'); +/** + * @public + * @class CircleRoiTool + * @memberof Tools.Annotation + * @classdesc Tool for drawing circular regions of interest, and measuring + * the statistics of the enclosed pixels. + * @extends Tools.Base.BaseAnnotationTool + */ + +var CircleRoiTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(CircleRoiTool, _BaseAnnotationTool); + + function CircleRoiTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, CircleRoiTool); + + var defaultProps = { + name: 'CircleRoi', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_19__["circleRoiCursor"], + configuration: { + centerPointRadius: 0, + renderDashed: false, + hideHandlesIfMoving: false + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(CircleRoiTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle_js__WEBPACK_IMPORTED_MODULE_16__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(CircleRoiTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + start: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + }, + initialRotation: eventData.viewport.rotation, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords, interactionType) { + var hasStartAndEndHandles = data && data.handles && data.handles.start && data.handles.end; + var getDistance = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstoneMath.point.distance; + + if (!hasStartAndEndHandles) { + logger.warn("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + } + + if (!hasStartAndEndHandles || data.visible === false) { + return false; + } + + var distance = interactionType === 'mouse' ? 15 : 25; + var startCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.start); + var endCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); // StartCanvas is the center of the circle + + var distanceFromCenter = getDistance(startCanvas, coords); // Getting radius of circle annotation in canvas + + var radius = getDistance(startCanvas, endCanvas); // Checking if point is near the tool by comparing its distance from the center of the circle + + return distanceFromCenter > radius - distance / 2 && distanceFromCenter < radius + distance / 2; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; + var modality = seriesModule.modality; + var pixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__["default"])(image); + + var stats = _calculateStats(image, element, data.handles, modality, pixelSpacing); + + data.cachedStats = stats; + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } + + var getDistance = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstoneMath.point.distance; + var eventData = evt.detail; + var image = eventData.image, + element = eventData.element, + canvasContext = eventData.canvasContext; + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed, + centerPointRadius = _this$configuration.centerPointRadius; + var newContext = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["getNewContext"])(canvasContext.canvas); + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; + + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_10__["getModule"])('globalConfiguration').configuration.lineDash; // Meta + + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; // Pixel Spacing + + var modality = seriesModule.modality; + var hasPixelSpacing = rowPixelSpacing && colPixelSpacing; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["draw"])(newContext, function (context) { + // If we have tool data for this element, iterate over each set and draw it + for (var i = 0; i < toolData.data.length; i++) { + var data = toolData.data[i]; + + if (data.visible === false) { + continue; + } // Configure + + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["setShadow"])(context, _this2.configuration); + var startCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.start); + var endCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); // Calculating the radius where startCanvas is the center of the circle to be drawn + + var radius = getDistance(startCanvas, endCanvas); + var circleOptions = { + color: color + }; + + if (renderDashed) { + circleOptions.lineDash = lineDash; + } // Draw Circle + + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawCircle"])(context, element, data.handles.start, radius, circleOptions, 'pixel'); + + if (centerPointRadius && radius > 3 * centerPointRadius) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawCircle"])(context, element, data.handles.start, centerPointRadius, circleOptions, 'pixel'); + } + + if (data.handles) { + data.handles.start.drawnIndependently = true; + data.handles.end.drawnIndependently = true; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawHandles"])(context, eventData, data.handles, handleOptions); // Update textbox stats + + if (data.invalidated === true) { + if (data.cachedStats) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } // Default to textbox on right side of ROI + + + if (!data.handles.textBox.hasMoved) { + var defaultCoords = Object(_util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_14__["default"])(eventData.viewport, data.handles); + Object.assign(data.handles.textBox, defaultCoords); + } + + var textBoxAnchorPoints = function textBoxAnchorPoints(handles) { + return _findTextBoxAnchorPoints(handles.start, handles.end); + }; + + var textBoxContent = _createTextBoxContent(context, image.color, data.cachedStats, modality, hasPixelSpacing, _this2.configuration); + + data.unit = _getUnit(modality, _this2.configuration.showHounsfieldUnits); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawLinkedTextBox"])(context, element, data.handles.textBox, textBoxContent, data.handles, textBoxAnchorPoints, color, lineWidth, 10, true); + } + }); + } + }]); + + return CircleRoiTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {Array.<{x: number, y: number}>} + */ + + + + +function _findTextBoxAnchorPoints(startHandle, endHandle) { + var _getCircleCoords = Object(_util_getCircleCoords__WEBPACK_IMPORTED_MODULE_20__["default"])(startHandle, endHandle), + left = _getCircleCoords.left, + top = _getCircleCoords.top, + width = _getCircleCoords.width, + height = _getCircleCoords.height; + + return [{ + // Top middle point of ellipse + x: left + width / 2, + y: top + }, { + // Left middle point of ellipse + x: left, + y: top + height / 2 + }, { + // Bottom middle point of ellipse + x: left + width / 2, + y: top + height + }, { + // Right middle point of ellipse + x: left + width, + y: top + height / 2 + }]; +} + +function _getUnit(modality, showHounsfieldUnits) { + return modality === 'CT' && showHounsfieldUnits !== false ? 'HU' : ''; +} +/** + * + * + * @param {*} context + * @param {*} isColorImage + * @param {*} { area, mean, stdDev, min, max, meanStdDevSUV } + * @param {*} modality + * @param {*} hasPixelSpacing + * @param {*} [options={}] - { showMinMax, showHounsfieldUnits } + * @returns {string[]} + */ + + +function _createTextBoxContent(context, isColorImage) { + var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref$area = _ref.area, + area = _ref$area === void 0 ? 0 : _ref$area, + _ref$radius = _ref.radius, + radius = _ref$radius === void 0 ? 0 : _ref$radius, + _ref$perimeter = _ref.perimeter, + perimeter = _ref$perimeter === void 0 ? 0 : _ref$perimeter, + _ref$mean = _ref.mean, + mean = _ref$mean === void 0 ? 0 : _ref$mean, + _ref$stdDev = _ref.stdDev, + stdDev = _ref$stdDev === void 0 ? 0 : _ref$stdDev, + _ref$min = _ref.min, + min = _ref$min === void 0 ? 0 : _ref$min, + _ref$max = _ref.max, + max = _ref$max === void 0 ? 0 : _ref$max, + _ref$meanStdDevSUV = _ref.meanStdDevSUV, + meanStdDevSUV = _ref$meanStdDevSUV === void 0 ? 0 : _ref$meanStdDevSUV; + + var modality = arguments.length > 3 ? arguments[3] : undefined; + var hasPixelSpacing = arguments.length > 4 ? arguments[4] : undefined; + var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + var showMinMax = options.showMinMax || false; + var textLines = []; // Don't display mean/standardDev for color images + + var otherLines = []; + + if (!isColorImage) { + var hasStandardUptakeValues = meanStdDevSUV && meanStdDevSUV.mean !== 0; + + var unit = _getUnit(modality, options.showHounsfieldUnits); + + var meanString = "Mean: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(mean.toFixed(2)), " ").concat(unit); + var stdDevString = "Std Dev: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(stdDev.toFixed(2)), " ").concat(unit); // If this image has SUV values to display, concatenate them to the text line + + if (hasStandardUptakeValues) { + var SUVtext = ' SUV: '; + var meanSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(meanStdDevSUV.mean.toFixed(2))); + var stdDevSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(meanStdDevSUV.stdDev.toFixed(2))); + var targetStringLength = Math.floor(context.measureText("".concat(stdDevString, " ")).width); + + while (context.measureText(meanString).width < targetStringLength) { + meanString += ' '; + } + + otherLines.push("".concat(meanString).concat(meanSuvString)); + otherLines.push("".concat(stdDevString, " ").concat(stdDevSuvString)); + } else { + otherLines.push("".concat(meanString, " ").concat(stdDevString)); + } + + if (showMinMax) { + var minString = "Min: ".concat(min, " ").concat(unit); + var maxString = "Max: ".concat(max, " ").concat(unit); + + var _targetStringLength = hasStandardUptakeValues ? Math.floor(context.measureText("".concat(stdDevString, " ")).width) : Math.floor(context.measureText("".concat(meanString, " ")).width); + + while (context.measureText(minString).width < _targetStringLength) { + minString += ' '; + } + + otherLines.push("".concat(minString).concat(maxString)); + } + } + + textLines.push(_formatArea(area, hasPixelSpacing)); + + if (radius) { + textLines.push(_formatLength(radius, 'Radius', hasPixelSpacing)); + } + + if (perimeter) { + textLines.push(_formatLength(perimeter, 'Perimeter', hasPixelSpacing)); + } + + otherLines.forEach(function (x) { + return textLines.push(x); + }); + return textLines; +} +/** + * + * + * @param {*} area + * @param {*} hasPixelSpacing + * @returns {string} The formatted label for showing area + */ + + +function _formatArea(area, hasPixelSpacing) { + // This uses Char code 178 for a superscript 2 + var suffix = hasPixelSpacing ? " mm".concat(String.fromCharCode(178)) : " px".concat(String.fromCharCode(178)); + return "Area: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(area.toFixed(2))).concat(suffix); +} + +function _formatLength(value, name, hasPixelSpacing) { + if (!value) { + return ''; + } + + var suffix = hasPixelSpacing ? ' mm' : ' px'; + return "".concat(name, ": ").concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(value.toFixed(1))).concat(suffix); +} +/** + * + * + * @param {*} image + * @param {*} element + * @param {*} handles + * @param {*} modality + * @param {*} pixelSpacing + * @returns {Object} The Stats object + */ + + +function _calculateStats(image, element, handles, modality, pixelSpacing) { + // Retrieve the bounds of the ellipse in image coordinates + var circleCoordinates = Object(_util_getCircleCoords__WEBPACK_IMPORTED_MODULE_20__["default"])(handles.start, handles.end); // Retrieve the array of pixels that the ellipse bounds cover + + var pixels = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getPixels(element, circleCoordinates.left, circleCoordinates.top, circleCoordinates.width, circleCoordinates.height); // Calculate the mean & standard deviation from the pixels and the ellipse details. + + var ellipseMeanStdDev = Object(_util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__["calculateEllipseStatistics"])(pixels, circleCoordinates); + var meanStdDevSUV; + + if (modality === 'PT') { + meanStdDevSUV = { + mean: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__["default"])(image, ellipseMeanStdDev.mean, true) || 0, + stdDev: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__["default"])(image, ellipseMeanStdDev.stdDev, true) || 0 + }; + } + + var radius = circleCoordinates.width * (pixelSpacing && pixelSpacing.colPixelSpacing || 1) / 2; + var perimeter = 2 * Math.PI * radius; + var area = Math.PI * (circleCoordinates.width * (pixelSpacing && pixelSpacing.colPixelSpacing || 1) / 2) * (circleCoordinates.height * (pixelSpacing && pixelSpacing.rowPixelSpacing || 1) / 2); + return { + area: area || 0, + radius: radius || 0, + perimeter: perimeter || 0, + count: ellipseMeanStdDev.count || 0, + mean: ellipseMeanStdDev.mean || 0, + variance: ellipseMeanStdDev.variance || 0, + stdDev: ellipseMeanStdDev.stdDev || 0, + min: ellipseMeanStdDev.min || 0, + max: ellipseMeanStdDev.max || 0, + meanStdDevSUV: meanStdDevSUV + }; +} + +/***/ }), + +/***/ "./tools/annotation/CobbAngleTool.js": +/*!*******************************************!*\ + !*** ./tools/annotation/CobbAngleTool.js ***! + \*******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CobbAngleTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../util/lineSegDistance.js */ "./util/lineSegDistance.js"); +/* harmony import */ var _util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../util/roundToDecimal.js */ "./util/roundToDecimal.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./../../events.js */ "./events.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + + // State + + + + + // Manipulators + + // Drawing + + + + + + + + + + + + +/** + * @public + * @class CobbAngleTool + * @memberof Tools.Annotation + * @classdesc Tool for measuring the angle between two straight lines. + * @extends Tools.Base.BaseAnnotationTool + */ + +var CobbAngleTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(CobbAngleTool, _BaseAnnotationTool); + + function CobbAngleTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, CobbAngleTool); + + var defaultProps = { + name: 'CobbAngle', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_18__["cobbAngleCursor"], + configuration: { + drawHandles: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + renderDashed: false + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(CobbAngleTool).call(this, props, defaultProps)); + _this.hasIncomplete = false; + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_20__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(CobbAngleTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + // Create the measurement data for this tool with the end handle activated + this.hasIncomplete = true; + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + complete: false, + value: '', + handles: { + start: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + }, + start2: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false, + drawnIndependently: true + }, + end2: { + x: eventData.currentPoints.image.x + 1, + y: eventData.currentPoints.image.y, + highlight: true, + active: false, + drawnIndependently: true + }, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + /** + * + * + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {Boolean} + */ + + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + if (data.visible === false) { + return false; + } + + if (this.hasIncomplete) { + return false; + } + + var seg1Near = Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__["default"])(element, data.handles.start, data.handles.end, coords) < 25; + var seg2Near = Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_15__["default"])(element, data.handles.start2, data.handles.end2, coords) < 25; + return seg1Near || seg2Near; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_21__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; + + var dx1 = (Math.ceil(data.handles.start.x) - Math.ceil(data.handles.end.x)) * (colPixelSpacing || 1); + var dy1 = (Math.ceil(data.handles.start.y) - Math.ceil(data.handles.end.y)) * (rowPixelSpacing || 1); + var dx2 = (Math.ceil(data.handles.start2.x) - Math.ceil(data.handles.end2.x)) * (colPixelSpacing || 1); + var dy2 = (Math.ceil(data.handles.start2.y) - Math.ceil(data.handles.end2.y)) * (rowPixelSpacing || 1); + var angle = Math.acos(Math.abs((dx1 * dx2 + dy1 * dy2) / (Math.sqrt(dx1 * dx1 + dy1 * dy1) * Math.sqrt(dx2 * dx2 + dy2 * dy2)))); + angle *= 180 / Math.PI; + data.rAngle = Object(_util_roundToDecimal_js__WEBPACK_IMPORTED_MODULE_16__["default"])(angle, 2); + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["getNewContext"])(eventData.canvasContext.canvas); + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_9__["default"].getToolWidth(); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_22__["getModule"])('globalConfiguration').configuration.lineDash; + var font = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_7__["default"].getFont(); + var element = evt.detail.element; + var image = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getEnabledElement(element).image; + + var _getPixelSpacing2 = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_21__["default"])(image), + rowPixelSpacing = _getPixelSpacing2.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing2.colPixelSpacing; + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + if (!data.value) { + data.value = _this2.textBoxText(data, rowPixelSpacing, colPixelSpacing); + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["setShadow"])(context, _this2.configuration); // Differentiate the color of activation tool + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_10__["default"].getColorIfActive(data); + var lineOptions = { + color: color + }; + + if (renderDashed) { + lineOptions.lineDash = lineDash; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["drawLine"])(context, eventData.element, data.handles.start, data.handles.end, lineOptions); + + if (data.complete) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_12__["drawLine"])(context, eventData.element, data.handles.start2, data.handles.end2, lineOptions); + } // Draw the handles + + + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_13__["default"])(context, eventData, data.handles, handleOptions); + } // Draw the text + + + context.fillStyle = color; + var text = data.value; + + if (!data.handles.textBox.hasMoved) { + var textCoords = { + x: (data.handles.start.x + data.handles.end.x) / 2, + y: (data.handles.start.y + data.handles.end.y) / 2 - 10 + }; + context.font = font; + data.handles.textBox.x = textCoords.x; + data.handles.textBox.y = textCoords.y; + } + + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_14__["default"])(context, eventData.element, data.handles.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, 0, true); + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + + function textBoxAnchorPoints(handles) { + return [handles.start, handles.start2, handles.end, handles.end2]; + } + } + }, { + key: "getIncomplete", + value: function getIncomplete(element) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["getToolState"])(element, this.name); + + if (toolState && Array.isArray(toolState.data)) { + return toolState.data.find(function (_ref) { + var complete = _ref.complete; + return complete === false; + }); + } + } + }, { + key: "addNewMeasurement", + value: function addNewMeasurement(evt, interactionType) { + var _this3 = this; + + evt.preventDefault(); + evt.stopPropagation(); + var eventData = evt.detail; + var measurementData; + var toMoveHandle; + + var doneMovingCallback = function doneMovingCallback(success) { + // DoneMovingCallback for first measurement. + if (!success) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["removeToolState"])(element, _this3.name, measurementData); + return; + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_COMPLETED; + var eventData = { + toolName: _this3.name, + toolType: _this3.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_19__["default"])(element, eventType, eventData); + }; // Search for incomplete measurements + + + var element = evt.detail.element; + var pendingMeasurement = this.getIncomplete(element); + + if (pendingMeasurement) { + measurementData = pendingMeasurement; + measurementData.complete = true; + measurementData.handles.start2 = { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + drawnIndependently: false, + highlight: true, + active: false + }; + measurementData.handles.end2 = { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + drawnIndependently: false, + highlight: true, + active: true + }; + toMoveHandle = measurementData.handles.end2; + this.hasIncomplete = false; + + doneMovingCallback = function doneMovingCallback(success) { + // DoneMovingCallback for second measurement + if (!success) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["removeToolState"])(element, _this3.name, measurementData); + return; + } + + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_COMPLETED; + var eventData = { + toolName: _this3.name, + toolType: _this3.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_19__["default"])(element, eventType, eventData); + }; + } else { + measurementData = this.createNewMeasurement(eventData); + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_8__["addToolState"])(element, this.name, measurementData); + toMoveHandle = measurementData.handles.end; + } // Associate this data with this imageId so we can render it and manipulate it + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.updateImage(element); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_11__["moveNewHandle"])(eventData, this.name, measurementData, toMoveHandle, this.options, interactionType, doneMovingCallback); + } + }, { + key: "onMeasureModified", + value: function onMeasureModified(ev) { + var element = ev.detail.element; + var image = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getEnabledElement(element).image; + + var _getPixelSpacing3 = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_21__["default"])(image), + rowPixelSpacing = _getPixelSpacing3.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing3.colPixelSpacing; + + if (ev.detail.toolName !== this.name) { + return; + } + + var data = ev.detail.measurementData; // Update textbox stats + + if (data.invalidated === true) { + if (data.rAngle) { + this.throttledUpdateCachedStats(image, element, data); + } else { + this.updateCachedStats(image, element, data); + } + } + + data.value = this.textBoxText(data, rowPixelSpacing, colPixelSpacing); + } + }, { + key: "textBoxText", + value: function textBoxText(_ref2, rowPixelSpacing, colPixelSpacing) { + var rAngle = _ref2.rAngle; + + if (rAngle === undefined) { + return ''; + } + + if (Number.isNaN(rAngle)) { + return ''; + } + + var suffix = !rowPixelSpacing || !colPixelSpacing ? ' (isotropic)' : ''; + return "".concat(rAngle, "\xB0").concat(suffix); + } + }, { + key: "activeCallback", + value: function activeCallback(element) { + this.onMeasureModified = this.onMeasureModified.bind(this); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_MODIFIED, this.onMeasureModified); + } + }, { + key: "passiveCallback", + value: function passiveCallback(element) { + this.onMeasureModified = this.onMeasureModified.bind(this); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_MODIFIED, this.onMeasureModified); + } + }, { + key: "enabledCallback", + value: function enabledCallback(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_MODIFIED, this.onMeasureModified); + } + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_17__["default"].MEASUREMENT_MODIFIED, this.onMeasureModified); + } + }]); + + return CobbAngleTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/annotation/EllipticalRoiTool.js": +/*!***********************************************!*\ + !*** ./tools/annotation/EllipticalRoiTool.js ***! + \***********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return EllipticalRoiTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../manipulators/getHandleNearImagePoint */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../util/ellipse/index.js */ "./util/ellipse/index.js"); +/* harmony import */ var _util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../util/getROITextBoxCoords.js */ "./util/getROITextBoxCoords.js"); +/* harmony import */ var _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../util/numbersWithCommas.js */ "./util/numbersWithCommas.js"); +/* harmony import */ var _util_throttle_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../util/throttle.js */ "./util/throttle.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + + // State + + + + + // Drawing + + // Util + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_18__["getLogger"])('tools:annotation:EllipticalRoiTool'); +/** + * @public + * @class EllipticalRoiTool + * @memberof Tools.Annotation + * @classdesc Tool for drawing elliptical regions of interest, and measuring + * the statistics of the enclosed pixels. + * @extends Tools.Base.BaseAnnotationTool + */ + +var EllipticalRoiTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(EllipticalRoiTool, _BaseAnnotationTool); + + function EllipticalRoiTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, EllipticalRoiTool); + + var defaultProps = { + name: 'EllipticalRoi', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + // showMinMax: false, + // showHounsfieldUnits: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + renderDashed: false + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_17__["ellipticalRoiCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(EllipticalRoiTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle_js__WEBPACK_IMPORTED_MODULE_16__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(EllipticalRoiTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + start: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + }, + initialRotation: eventData.viewport.rotation, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords, interactionType) { + var hasStartAndEndHandles = data && data.handles && data.handles.start && data.handles.end; + var validParameters = hasStartAndEndHandles; + + if (!validParameters) { + logger.warn("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + } + + if (!validParameters || data.visible === false) { + return false; + } + + var handleNearImagePoint = Object(_manipulators_getHandleNearImagePoint__WEBPACK_IMPORTED_MODULE_10__["default"])(element, data.handles, coords, 6); + + if (handleNearImagePoint) { + return true; + } + + var distance = interactionType === 'mouse' ? 15 : 25; + var startCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.start); + var endCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); + var minorEllipse = { + left: Math.min(startCanvas.x, endCanvas.x) + distance / 2, + top: Math.min(startCanvas.y, endCanvas.y) + distance / 2, + width: Math.abs(startCanvas.x - endCanvas.x) - distance, + height: Math.abs(startCanvas.y - endCanvas.y) - distance + }; + var majorEllipse = { + left: Math.min(startCanvas.x, endCanvas.x) - distance / 2, + top: Math.min(startCanvas.y, endCanvas.y) - distance / 2, + width: Math.abs(startCanvas.x - endCanvas.x) + distance, + height: Math.abs(startCanvas.y - endCanvas.y) + distance + }; + var pointInMinorEllipse = Object(_util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__["pointInEllipse"])(minorEllipse, coords); + var pointInMajorEllipse = Object(_util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__["pointInEllipse"])(majorEllipse, coords); + + if (pointInMajorEllipse && !pointInMinorEllipse) { + return true; + } + + return false; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; + var modality = seriesModule.modality; + var pixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_19__["default"])(image); + + var stats = _calculateStats(image, element, data.handles, modality, pixelSpacing); + + data.cachedStats = stats; + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } + + var eventData = evt.detail; + var image = eventData.image, + element = eventData.element; + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_20__["getModule"])('globalConfiguration').configuration.lineDash; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["getNewContext"])(eventData.canvasContext.canvas); + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_19__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; // Meta + + + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; // Pixel Spacing + + var modality = seriesModule.modality; + var hasPixelSpacing = rowPixelSpacing && colPixelSpacing; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["draw"])(context, function (context) { + // If we have tool data for this element - iterate over each set and draw it + for (var i = 0; i < toolData.data.length; i++) { + var data = toolData.data[i]; + + if (data.visible === false) { + continue; + } // Configure + + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["setShadow"])(context, _this2.configuration); + var ellipseOptions = { + color: color + }; + + if (renderDashed) { + ellipseOptions.lineDash = lineDash; + } // Draw + + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawEllipse"])(context, element, data.handles.start, data.handles.end, ellipseOptions, 'pixel', data.handles.initialRotation); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawHandles"])(context, eventData, data.handles, handleOptions); // Update textbox stats + + if (data.invalidated === true) { + if (data.cachedStats) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } // Default to textbox on right side of ROI + + + if (!data.handles.textBox.hasMoved) { + var defaultCoords = Object(_util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_14__["default"])(eventData.viewport, data.handles); + Object.assign(data.handles.textBox, defaultCoords); + } + + var textBoxAnchorPoints = function textBoxAnchorPoints(handles) { + return _findTextBoxAnchorPoints(handles.start, handles.end); + }; + + var textBoxContent = _createTextBoxContent(context, image.color, data.cachedStats, modality, hasPixelSpacing, _this2.configuration); + + data.unit = _getUnit(modality, _this2.configuration.showHounsfieldUnits); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_11__["drawLinkedTextBox"])(context, element, data.handles.textBox, textBoxContent, data.handles, textBoxAnchorPoints, color, lineWidth, 10, true); + } + }); + } + }]); + + return EllipticalRoiTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {Array.<{x: number, y: number}>} + */ + + + + +function _findTextBoxAnchorPoints(startHandle, endHandle) { + var _getEllipseImageCoord = _getEllipseImageCoordinates(startHandle, endHandle), + left = _getEllipseImageCoord.left, + top = _getEllipseImageCoord.top, + width = _getEllipseImageCoord.width, + height = _getEllipseImageCoord.height; + + return [{ + // Top middle point of ellipse + x: left + width / 2, + y: top + }, { + // Left middle point of ellipse + x: left, + y: top + height / 2 + }, { + // Bottom middle point of ellipse + x: left + width / 2, + y: top + height + }, { + // Right middle point of ellipse + x: left + width, + y: top + height / 2 + }]; +} + +function _getUnit(modality, showHounsfieldUnits) { + return modality === 'CT' && showHounsfieldUnits !== false ? 'HU' : ''; +} +/** + * + * + * @param {*} context + * @param {*} isColorImage + * @param {*} { area, mean, stdDev, min, max, meanStdDevSUV } + * @param {*} modality + * @param {*} hasPixelSpacing + * @param {*} [options={}] - { showMinMax, showHounsfieldUnits } + * @returns {string[]} + */ + + +function _createTextBoxContent(context, isColorImage) { + var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + area = _ref.area, + mean = _ref.mean, + stdDev = _ref.stdDev, + min = _ref.min, + max = _ref.max, + meanStdDevSUV = _ref.meanStdDevSUV; + + var modality = arguments.length > 3 ? arguments[3] : undefined; + var hasPixelSpacing = arguments.length > 4 ? arguments[4] : undefined; + var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + var showMinMax = options.showMinMax || false; + var textLines = []; // Don't display mean/standardDev for color images + + var otherLines = []; + + if (!isColorImage) { + var hasStandardUptakeValues = meanStdDevSUV && meanStdDevSUV.mean !== 0; + + var unit = _getUnit(modality, options.showHounsfieldUnits); + + var meanString = "Mean: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(mean.toFixed(2)), " ").concat(unit); + var stdDevString = "Std Dev: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(stdDev.toFixed(2)), " ").concat(unit); // If this image has SUV values to display, concatenate them to the text line + + if (hasStandardUptakeValues) { + var SUVtext = ' SUV: '; + var meanSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(meanStdDevSUV.mean.toFixed(2))); + var stdDevSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(meanStdDevSUV.stdDev.toFixed(2))); + var targetStringLength = Math.floor(context.measureText("".concat(stdDevString, " ")).width); + + while (context.measureText(meanString).width < targetStringLength) { + meanString += ' '; + } + + otherLines.push("".concat(meanString).concat(meanSuvString)); + otherLines.push("".concat(stdDevString, " ").concat(stdDevSuvString)); + } else { + otherLines.push("".concat(meanString)); + otherLines.push("".concat(stdDevString)); + } + + if (showMinMax) { + var minString = "Min: ".concat(min, " ").concat(unit); + var maxString = "Max: ".concat(max, " ").concat(unit); + + var _targetStringLength = hasStandardUptakeValues ? Math.floor(context.measureText("".concat(stdDevString, " ")).width) : Math.floor(context.measureText("".concat(meanString, " ")).width); + + while (context.measureText(minString).width < _targetStringLength) { + minString += ' '; + } + + otherLines.push("".concat(minString).concat(maxString)); + } + } + + textLines.push(_formatArea(area, hasPixelSpacing)); + otherLines.forEach(function (x) { + return textLines.push(x); + }); + return textLines; +} +/** + * + * + * @param {*} area + * @param {*} hasPixelSpacing + * @returns {string} The formatted label for showing area + */ + + +function _formatArea(area, hasPixelSpacing) { + // This uses Char code 178 for a superscript 2 + var suffix = hasPixelSpacing ? " mm".concat(String.fromCharCode(178)) : " px".concat(String.fromCharCode(178)); + return "Area: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_15__["default"])(area.toFixed(2))).concat(suffix); +} +/** + * + * + * @param {*} image + * @param {*} element + * @param {*} handles + * @param {*} modality + * @param {*} pixelSpacing + * @returns {Object} The Stats object + */ + + +function _calculateStats(image, element, handles, modality, pixelSpacing) { + // Retrieve the bounds of the ellipse in image coordinates + var ellipseCoordinates = _getEllipseImageCoordinates(handles.start, handles.end); // Retrieve the array of pixels that the ellipse bounds cover + + + var pixels = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getPixels(element, ellipseCoordinates.left, ellipseCoordinates.top, ellipseCoordinates.width, ellipseCoordinates.height); // Calculate the mean & standard deviation from the pixels and the ellipse details. + + var ellipseMeanStdDev = Object(_util_ellipse_index_js__WEBPACK_IMPORTED_MODULE_13__["calculateEllipseStatistics"])(pixels, ellipseCoordinates); + var meanStdDevSUV; + + if (modality === 'PT') { + meanStdDevSUV = { + mean: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__["default"])(image, ellipseMeanStdDev.mean, true) || 0, + stdDev: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_12__["default"])(image, ellipseMeanStdDev.stdDev, true) || 0 + }; + } // Calculate the image area from the ellipse dimensions and pixel spacing + + + var area = Math.PI * (ellipseCoordinates.width * (pixelSpacing.colPixelSpacing || 1) / 2) * (ellipseCoordinates.height * (pixelSpacing.rowPixelSpacing || 1) / 2); + return { + area: area || 0, + count: ellipseMeanStdDev.count || 0, + mean: ellipseMeanStdDev.mean || 0, + variance: ellipseMeanStdDev.variance || 0, + stdDev: ellipseMeanStdDev.stdDev || 0, + min: ellipseMeanStdDev.min || 0, + max: ellipseMeanStdDev.max || 0, + meanStdDevSUV: meanStdDevSUV + }; +} +/** + * Retrieve the bounds of the ellipse in image coordinates + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {{ left: number, top: number, width: number, height: number }} + */ + + +function _getEllipseImageCoordinates(startHandle, endHandle) { + return { + left: Math.round(Math.min(startHandle.x, endHandle.x)), + top: Math.round(Math.min(startHandle.y, endHandle.y)), + width: Math.round(Math.abs(startHandle.x - endHandle.x)), + height: Math.round(Math.abs(startHandle.y - endHandle.y)) + }; +} + +/***/ }), + +/***/ "./tools/annotation/FreehandRoiTool.js": +/*!*********************************************!*\ + !*** ./tools/annotation/FreehandRoiTool.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FreehandRoiTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../util/findAndMoveHelpers.js */ "./util/findAndMoveHelpers.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../../util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../util/numbersWithCommas.js */ "./util/numbersWithCommas.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _util_clip_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../../util/clip.js */ "./util/clip.js"); +/* harmony import */ var _store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ../../store/setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ../../util/freehand/index.js */ "./util/freehand/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); + + + + + + + + + // State + + + + + + // Manipulators + + // Implementation Logic + + + + + // Drawing + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_26__["getLogger"])('tools:annotation:FreehandRoiTool'); +var insertOrDelete = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__["default"].insertOrDelete, + freehandArea = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__["default"].freehandArea, + calculateFreehandStatistics = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__["default"].calculateFreehandStatistics, + freehandIntersect = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__["default"].freehandIntersect, + FreehandHandleData = _util_freehand_index_js__WEBPACK_IMPORTED_MODULE_25__["default"].FreehandHandleData; +/** + * @public + * @class FreehandRoiTool + * @memberof Tools.Annotation + * @classdesc Tool for drawing arbitrary polygonal regions of interest, and + * measuring the statistics of the enclosed pixels. + * @extends Tools.Base.BaseAnnotationTool + */ + +var FreehandRoiTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(FreehandRoiTool, _BaseAnnotationTool); + + function FreehandRoiTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FreehandRoiTool); + + var defaultProps = { + name: 'FreehandRoi', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: defaultFreehandConfiguration(), + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_24__["freehandRoiCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(FreehandRoiTool).call(this, props, defaultProps)); + _this.isMultiPartTool = true; + _this._drawing = false; + _this._dragging = false; + _this._modifying = false; // Create bound callback functions for private event loops + + _this._drawingMouseDownCallback = _this._drawingMouseDownCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingMouseMoveCallback = _this._drawingMouseMoveCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingMouseDragCallback = _this._drawingMouseDragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingMouseUpCallback = _this._drawingMouseUpCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingMouseDoubleClickCallback = _this._drawingMouseDoubleClickCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._editMouseUpCallback = _this._editMouseUpCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._editMouseDragCallback = _this._editMouseDragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingTouchStartCallback = _this._drawingTouchStartCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingTouchDragCallback = _this._drawingTouchDragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._drawingDoubleTapClickCallback = _this._drawingDoubleTapClickCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this._editTouchDragCallback = _this._editTouchDragCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_27__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(FreehandRoiTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + var measurementData = { + visible: true, + active: true, + invalidated: true, + color: undefined, + handles: { + points: [] + } + }; + measurementData.handles.textBox = { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + }; + return measurementData; + } + /** + * + * + * @param {*} element element + * @param {*} data data + * @param {*} coords coords + * @returns {Boolean} + */ + + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + var validParameters = data && data.handles && data.handles.points; + + if (!validParameters) { + throw new Error("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + } + + if (!validParameters || data.visible === false) { + return false; + } + + var isPointNearTool = this._pointNearHandle(element, data, coords); + + if (isPointNearTool !== undefined) { + return true; + } + + return false; + } + /** + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {number} the distance in px from the provided coordinates to the + * closest rendered portion of the annotation. -1 if the distance cannot be + * calculated. + */ + + }, { + key: "distanceFromPoint", + value: function distanceFromPoint(element, data, coords) { + var distance = Infinity; + + for (var i = 0; i < data.handles.points.length; i++) { + var distanceI = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(data.handles.points[i], coords); + distance = Math.min(distance, distanceI); + } // If an error caused distance not to be calculated, return -1. + + + if (distance === Infinity) { + return -1; + } + + return distance; + } + /** + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {number} the distance in canvas units from the provided coordinates to the + * closest rendered portion of the annotation. -1 if the distance cannot be + * calculated. + */ + + }, { + key: "distanceFromPointCanvas", + value: function distanceFromPointCanvas(element, data, coords) { + var distance = Infinity; + + if (!data) { + return -1; + } + + var canvasCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, coords); + var points = data.handles.points; + + for (var i = 0; i < points.length; i++) { + var handleCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, points[i]); + var distanceI = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(handleCanvas, canvasCoords); + distance = Math.min(distance, distanceI); + } // If an error caused distance not to be calculated, return -1. + + + if (distance === Infinity) { + return -1; + } + + return distance; + } + /** + * + * + * + * @param {Object} image image + * @param {Object} element element + * @param {Object} data data + * + * @returns {void} void + */ + + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + // Define variables for the area and mean/standard deviation + var meanStdDev, meanStdDevSUV; + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId); + var modality = seriesModule ? seriesModule.modality : null; + var points = data.handles.points; // If the data has been invalidated, and the tool is not currently active, + // We need to calculate it again. + // Retrieve the bounds of the ROI in image coordinates + + var bounds = { + left: points[0].x, + right: points[0].x, + bottom: points[0].y, + top: points[0].x + }; + + for (var i = 0; i < points.length; i++) { + bounds.left = Math.min(bounds.left, points[i].x); + bounds.right = Math.max(bounds.right, points[i].x); + bounds.bottom = Math.min(bounds.bottom, points[i].y); + bounds.top = Math.max(bounds.top, points[i].y); + } + + var polyBoundingBox = { + left: bounds.left, + top: bounds.bottom, + width: Math.abs(bounds.right - bounds.left), + height: Math.abs(bounds.top - bounds.bottom) + }; // Store the bounding box information for the text box + + data.polyBoundingBox = polyBoundingBox; // First, make sure this is not a color image, since no mean / standard + // Deviation will be calculated for color images. + + if (!image.color) { + // Retrieve the array of pixels that the ROI bounds cover + var pixels = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.getPixels(element, polyBoundingBox.left, polyBoundingBox.top, polyBoundingBox.width, polyBoundingBox.height); // Calculate the mean & standard deviation from the pixels and the object shape + + meanStdDev = calculateFreehandStatistics.call(this, pixels, polyBoundingBox, data.handles.points); + + if (modality === 'PT') { + // If the image is from a PET scan, use the DICOM tags to + // Calculate the SUV from the mean and standard deviation. + // Note that because we are using modality pixel values from getPixels, and + // The calculateSUV routine also rescales to modality pixel values, we are first + // Returning the values to storedPixel values before calcuating SUV with them. + // TODO: Clean this up? Should we add an option to not scale in calculateSUV? + meanStdDevSUV = { + mean: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_16__["default"])(image, (meanStdDev.mean - image.intercept) / image.slope), + stdDev: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_16__["default"])(image, (meanStdDev.stdDev - image.intercept) / image.slope) + }; + } // If the mean and standard deviation values are sane, store them for later retrieval + + + if (meanStdDev && !isNaN(meanStdDev.mean)) { + data.meanStdDev = meanStdDev; + data.meanStdDevSUV = meanStdDevSUV; + } + } // Retrieve the pixel spacing values, and if they are not + // Real non-zero values, set them to 1 + + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__["default"])(image), + colPixelSpacing = _getPixelSpacing.colPixelSpacing, + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing; + + var scaling = (colPixelSpacing || 1) * (rowPixelSpacing || 1); + var area = freehandArea(data.handles.points, scaling); // If the area value is sane, store it for later retrieval + + if (!isNaN(area)) { + data.area = area; + } // Set the invalidated flag to false so that this data won't automatically be recalculated + + + data.invalidated = false; + } + /** + * + * + * @param {*} evt + * @returns {undefined} + */ + + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; // If we have no toolState for this element, return immediately as there is nothing to do + + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(evt.currentTarget, this.name); + + if (!toolState) { + return; + } + + var image = eventData.image, + element = eventData.element; + var config = this.configuration; + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId); + var modality = seriesModule ? seriesModule.modality : null; // We have tool data for this element - iterate over each one and draw it + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_19__["getNewContext"])(eventData.canvasContext.canvas); + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_10__["default"].getToolWidth(); + var renderDashed = config.renderDashed; + var lineDash = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_12__["getModule"])('globalConfiguration').configuration.lineDash; + + var _loop = function _loop(i) { + var data = toolState.data[i]; + + if (data.visible === false) { + return "continue"; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_19__["draw"])(context, function (context) { + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__["default"].getColorIfActive(data); + var fillColor; + + if (data.active) { + if (data.handles.invalidHandlePlacement) { + color = config.invalidColor; + fillColor = config.invalidColor; + } else { + color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__["default"].getColorIfActive(data); + fillColor = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__["default"].getFillColor(); + } + } else { + fillColor = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_11__["default"].getToolColor(); + } + + var options = { + color: color + }; + + if (renderDashed) { + options.lineDash = lineDash; + } + + if (data.handles.points.length) { + var points = data.handles.points; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_19__["drawJoinedLines"])(context, element, points[0], points, options); + + if (data.polyBoundingBox) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_19__["drawJoinedLines"])(context, element, points[points.length - 1], [points[0]], options); + } else { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_19__["drawJoinedLines"])(context, element, points[points.length - 1], [config.mouseLocation.handles.start], options); + } + } // Draw handles + + + options = { + color: color, + fill: fillColor + }; + + if (config.alwaysShowHandles || data.active && data.polyBoundingBox) { + // Render all handles + options.handleRadius = config.activeHandleRadius; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_21__["default"])(context, eventData, data.handles.points, options); + } + } + + if (data.canComplete) { + // Draw large handle at the origin if can complete drawing + options.handleRadius = config.completeHandleRadius; + var handle = data.handles.points[0]; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_21__["default"])(context, eventData, [handle], options); + } + } + + if (data.active && !data.polyBoundingBox) { + // Draw handle at origin and at mouse if actively drawing + options.handleRadius = config.activeHandleRadius; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_21__["default"])(context, eventData, config.mouseLocation.handles, options); + } + + var firstHandle = data.handles.points[0]; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_21__["default"])(context, eventData, [firstHandle], options); + } + } // Update textbox stats + + + if (data.invalidated === true && !data.active) { + if (data.meanStdDev && data.meanStdDevSUV && data.area) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } // Only render text if polygon ROI has been completed and freehand 'shiftKey' mode was not used: + + + if (data.polyBoundingBox && !data.handles.textBox.freehand) { + // If the textbox has not been moved by the user, it should be displayed on the right-most + // Side of the tool. + if (!data.handles.textBox.hasMoved) { + // Find the rightmost side of the polyBoundingBox at its vertical center, and place the textbox here + // Note that this calculates it in image coordinates + data.handles.textBox.x = data.polyBoundingBox.left + data.polyBoundingBox.width; + data.handles.textBox.y = data.polyBoundingBox.top + data.polyBoundingBox.height / 2; + } + + var text = textBoxText.call(_this2, data); + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_20__["default"])(context, element, data.handles.textBox, text, data.handles.points, textBoxAnchorPoints, color, lineWidth, 0, true); + } + }); + }; + + for (var i = 0; i < toolState.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + + function textBoxText(data) { + var meanStdDev = data.meanStdDev, + meanStdDevSUV = data.meanStdDevSUV, + area = data.area; // Define an array to store the rows of text for the textbox + + var textLines = []; // If the mean and standard deviation values are present, display them + + if (meanStdDev && meanStdDev.mean !== undefined) { + // If the modality is CT, add HU to denote Hounsfield Units + var moSuffix = ''; + + if (modality === 'CT') { + moSuffix = 'HU'; + } + + data.unit = moSuffix; // Create a line of text to display the mean and any units that were specified (i.e. HU) + + var meanText = "Mean: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__["default"])(meanStdDev.mean.toFixed(2)), " ").concat(moSuffix); // Create a line of text to display the standard deviation and any units that were specified (i.e. HU) + + var stdDevText = "StdDev: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__["default"])(meanStdDev.stdDev.toFixed(2)), " ").concat(moSuffix); // If this image has SUV values to display, concatenate them to the text line + + if (meanStdDevSUV && meanStdDevSUV.mean !== undefined) { + var SUVtext = ' SUV: '; + meanText += SUVtext + Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__["default"])(meanStdDevSUV.mean.toFixed(2)); + stdDevText += SUVtext + Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__["default"])(meanStdDevSUV.stdDev.toFixed(2)); + } // Add these text lines to the array to be displayed in the textbox + + + textLines.push(meanText); + textLines.push(stdDevText); + } // If the area is a sane value, display it + + + if (area) { + // Determine the area suffix based on the pixel spacing in the image. + // If pixel spacing is present, use millimeters. Otherwise, use pixels. + // This uses Char code 178 for a superscript 2 + var suffix = " mm".concat(String.fromCharCode(178)); + + var _getPixelSpacing2 = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_18__["default"])(image), + rowPixelSpacing = _getPixelSpacing2.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing2.colPixelSpacing; + + if (!rowPixelSpacing || !colPixelSpacing) { + suffix = " pixels".concat(String.fromCharCode(178)); + } // Create a line of text to display the area and its units + + + var areaText = "Area: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_17__["default"])(area.toFixed(2))).concat(suffix); // Add this text line to the array to be displayed in the textbox + + textLines.push(areaText); + } + + return textLines; + } + + function textBoxAnchorPoints(handles) { + return handles; + } + } + }, { + key: "addNewMeasurement", + value: function addNewMeasurement(evt) { + var eventData = evt.detail; + + this._startDrawing(evt); + + this._addPoint(eventData); + + preventPropagation(evt); + } + }, { + key: "preMouseDownCallback", + value: function preMouseDownCallback(evt) { + var eventData = evt.detail; + + var nearby = this._pointNearHandleAllTools(eventData); + + if (eventData.event.ctrlKey) { + if (nearby !== undefined && nearby.handleNearby.hasBoundingBox) {// Ctrl + clicked textBox, do nothing but still consume event. + } else { + insertOrDelete.call(this, evt, nearby); + } + + preventPropagation(evt); + return true; + } + + return false; + } + }, { + key: "handleSelectedCallback", + value: function handleSelectedCallback(evt, toolData, handle) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + var element = evt.detail.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + + if (handle.hasBoundingBox) { + // Use default move handler. + Object(_util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_14__["moveHandleNearImagePoint"])(evt, this, toolData, handle, interactionType); + return; + } + + var config = this.configuration; + config.dragOrigin = { + x: handle.x, + y: handle.y + }; // Iterating over handles of all toolData instances to find the indices of the selected handle + + for (var toolIndex = 0; toolIndex < toolState.data.length; toolIndex++) { + var points = toolState.data[toolIndex].handles.points; + + for (var p = 0; p < points.length; p++) { + if (points[p] === handle) { + config.currentHandle = p; + config.currentTool = toolIndex; + } + } + } + + this._modifying = true; + + this._activateModify(element); // Interupt eventDispatchers + + + preventPropagation(evt); + } + /** + * Event handler for MOUSE_MOVE during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingMouseMoveCallback", + value: function _drawingMouseMoveCallback(evt) { + var eventData = evt.detail; + var currentPoints = eventData.currentPoints, + element = eventData.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var currentTool = config.currentTool; + var data = toolState.data[currentTool]; + var coords = currentPoints.canvas; // Set the mouseLocation handle + + this._getMouseLocation(eventData); + + this._checkInvalidHandleLocation(data, eventData); // Mouse move -> Polygon Mode + + + var handleNearby = this._pointNearHandle(element, data, coords); + + var points = data.handles.points; // If there is a handle nearby to snap to + // (and it's not the actual mouse handle) + + if (handleNearby !== undefined && !handleNearby.hasBoundingBox && handleNearby < points.length - 1) { + config.mouseLocation.handles.start.x = points[handleNearby].x; + config.mouseLocation.handles.start.y = points[handleNearby].y; + } // Force onImageRendered + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Event handler for MOUSE_DRAG during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingMouseDragCallback", + value: function _drawingMouseDragCallback(evt) { + if (!this.options.mouseButtonMask.includes(evt.detail.buttons)) { + return; + } + + this._drawingDrag(evt); + } + /** + * Event handler for TOUCH_DRAG during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingTouchDragCallback", + value: function _drawingTouchDragCallback(evt) { + this._drawingDrag(evt); + } + }, { + key: "_drawingDrag", + value: function _drawingDrag(evt) { + var eventData = evt.detail; + var element = eventData.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var currentTool = config.currentTool; + var data = toolState.data[currentTool]; // Set the mouseLocation handle + + this._getMouseLocation(eventData); + + this._checkInvalidHandleLocation(data, eventData); + + this._addPointPencilMode(eventData, data.handles.points); + + this._dragging = true; // Force onImageRendered + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Event handler for MOUSE_UP during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingMouseUpCallback", + value: function _drawingMouseUpCallback(evt) { + var element = evt.detail.element; + + if (!this._dragging) { + return; + } + + this._dragging = false; + var config = this.configuration; + var currentTool = config.currentTool; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var data = toolState.data[currentTool]; + + if (!freehandIntersect.end(data.handles.points) && data.canComplete) { + var lastHandlePlaced = config.currentHandle; + + this._endDrawing(element, lastHandlePlaced); + } + + preventPropagation(evt); + return; + } + /** + * Event handler for MOUSE_DOWN during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingMouseDownCallback", + value: function _drawingMouseDownCallback(evt) { + var eventData = evt.detail; + var buttons = eventData.buttons, + currentPoints = eventData.currentPoints, + element = eventData.element; + + if (!this.options.mouseButtonMask.includes(buttons)) { + return; + } + + var coords = currentPoints.canvas; + var config = this.configuration; + var currentTool = config.currentTool; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var data = toolState.data[currentTool]; + + var handleNearby = this._pointNearHandle(element, data, coords); + + if (!freehandIntersect.end(data.handles.points) && data.canComplete) { + var lastHandlePlaced = config.currentHandle; + + this._endDrawing(element, lastHandlePlaced); + } else if (handleNearby === undefined) { + this._addPoint(eventData); + } + + preventPropagation(evt); + return; + } + /** + * Event handler for TOUCH_START during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingTouchStartCallback", + value: function _drawingTouchStartCallback(evt) { + var eventData = evt.detail; + var currentPoints = eventData.currentPoints, + element = eventData.element; + var coords = currentPoints.canvas; + var config = this.configuration; + var currentTool = config.currentTool; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var data = toolState.data[currentTool]; + + var handleNearby = this._pointNearHandle(element, data, coords); + + if (!freehandIntersect.end(data.handles.points) && data.canComplete) { + var lastHandlePlaced = config.currentHandle; + + this._endDrawing(element, lastHandlePlaced); + } else if (handleNearby === undefined) { + this._addPoint(eventData); + } + + preventPropagation(evt); + return; + } + /** Ends the active drawing loop and completes the polygon. + * + * @public + * @param {Object} element - The element on which the roi is being drawn. + * @returns {null} + */ + + }, { + key: "completeDrawing", + value: function completeDrawing(element) { + if (!this._drawing) { + return; + } + + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var data = toolState.data[config.currentTool]; + + if (!freehandIntersect.end(data.handles.points) && data.handles.points.length >= 2) { + var lastHandlePlaced = config.currentHandle; + data.polyBoundingBox = {}; + + this._endDrawing(element, lastHandlePlaced); + } + } + /** + * Event handler for MOUSE_DOUBLE_CLICK during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingMouseDoubleClickCallback", + value: function _drawingMouseDoubleClickCallback(evt) { + var element = evt.detail.element; + this.completeDrawing(element); + preventPropagation(evt); + } + /** + * Event handler for DOUBLE_TAP during drawing event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_drawingDoubleTapClickCallback", + value: function _drawingDoubleTapClickCallback(evt) { + var element = evt.detail.element; + this.completeDrawing(element); + preventPropagation(evt); + } + /** + * Event handler for MOUSE_DRAG during handle drag event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_editMouseDragCallback", + value: function _editMouseDragCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + buttons = eventData.buttons; + + if (!this.options.mouseButtonMask.includes(buttons)) { + return; + } + + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var data = toolState.data[config.currentTool]; + var currentHandle = config.currentHandle; + var points = data.handles.points; + var handleIndex = -1; // Set the mouseLocation handle + + this._getMouseLocation(eventData); + + data.handles.invalidHandlePlacement = freehandIntersect.modify(points, currentHandle); + data.active = true; + data.highlight = true; + points[currentHandle].x = config.mouseLocation.handles.start.x; + points[currentHandle].y = config.mouseLocation.handles.start.y; + handleIndex = this._getPrevHandleIndex(currentHandle, points); + + if (currentHandle >= 0) { + var lastLineIndex = points[handleIndex].lines.length - 1; + var lastLine = points[handleIndex].lines[lastLineIndex]; + lastLine.x = config.mouseLocation.handles.start.x; + lastLine.y = config.mouseLocation.handles.start.y; + } // Update the image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Event handler for TOUCH_DRAG during handle drag event loop. + * + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "_editTouchDragCallback", + value: function _editTouchDragCallback(evt) { + var eventData = evt.detail; + var element = eventData.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var data = toolState.data[config.currentTool]; + var currentHandle = config.currentHandle; + var points = data.handles.points; + var handleIndex = -1; // Set the mouseLocation handle + + this._getMouseLocation(eventData); + + data.handles.invalidHandlePlacement = freehandIntersect.modify(points, currentHandle); + data.active = true; + data.highlight = true; + points[currentHandle].x = config.mouseLocation.handles.start.x; + points[currentHandle].y = config.mouseLocation.handles.start.y; + handleIndex = this._getPrevHandleIndex(currentHandle, points); + + if (currentHandle >= 0) { + var lastLineIndex = points[handleIndex].lines.length - 1; + var lastLine = points[handleIndex].lines[lastLineIndex]; + lastLine.x = config.mouseLocation.handles.start.x; + lastLine.y = config.mouseLocation.handles.start.y; + } // Update the image + + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Returns the previous handle to the current one. + * @param {Number} currentHandle - the current handle index + * @param {Array} points - the handles Array of the freehand data + * @returns {Number} - The index of the previos handle + */ + + }, { + key: "_getPrevHandleIndex", + value: function _getPrevHandleIndex(currentHandle, points) { + if (currentHandle === 0) { + return points.length - 1; + } + + return currentHandle - 1; + } + /** + * Event handler for MOUSE_UP during handle drag event loop. + * + * @private + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_editMouseUpCallback", + value: function _editMouseUpCallback(evt) { + var eventData = evt.detail; + var element = eventData.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + + this._deactivateModify(element); + + this._dropHandle(eventData, toolState); + + this._endDrawing(element); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Places a handle of the freehand tool if the new location is valid. + * If the new location is invalid the handle snaps back to its previous position. + * + * @private + * @param {Object} eventData - Data object associated with the event. + * @param {Object} toolState - The data associated with the freehand tool. + * @modifies {toolState} + * @returns {undefined} + */ + + }, { + key: "_dropHandle", + value: function _dropHandle(eventData, toolState) { + var config = this.configuration; + var currentTool = config.currentTool; + var handles = toolState.data[currentTool].handles; + var points = handles.points; // Don't allow the line being modified to intersect other lines + + if (handles.invalidHandlePlacement) { + var currentHandle = config.currentHandle; + var currentHandleData = points[currentHandle]; + var previousHandleData; + + if (currentHandle === 0) { + var lastHandleID = points.length - 1; + previousHandleData = points[lastHandleID]; + } else { + previousHandleData = points[currentHandle - 1]; + } // Snap back to previous position + + + currentHandleData.x = config.dragOrigin.x; + currentHandleData.y = config.dragOrigin.y; + previousHandleData.lines[0] = currentHandleData; + handles.invalidHandlePlacement = false; + } + } + /** + * Begining of drawing loop when tool is active and a click event happens far + * from existing handles. + * + * @private + * @param {Object} evt - The event. + * @returns {undefined} + */ + + }, { + key: "_startDrawing", + value: function _startDrawing(evt) { + var eventData = evt.detail; + var measurementData = this.createNewMeasurement(eventData); + var element = eventData.element; + var config = this.configuration; + var interactionType; + + if (evt.type === _events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DOWN_ACTIVATE) { + interactionType = 'Mouse'; + } else if (evt.type === _events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_START_ACTIVE) { + interactionType = 'Touch'; + } + + this._activateDraw(element, interactionType); + + this._getMouseLocation(eventData); + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["addToolState"])(element, this.name, measurementData); + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + config.currentTool = toolState.data.length - 1; + this._activeDrawingToolReference = toolState.data[config.currentTool]; + } + /** + * Adds a point on mouse click in polygon mode. + * + * @private + * @param {Object} eventData - data object associated with an event. + * @returns {undefined} + */ + + }, { + key: "_addPoint", + value: function _addPoint(eventData) { + var currentPoints = eventData.currentPoints, + element = eventData.element; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); // Get the toolState from the last-drawn polygon + + var config = this.configuration; + var data = toolState.data[config.currentTool]; + + if (data.handles.invalidHandlePlacement) { + return; + } + + var newHandleData = new FreehandHandleData(currentPoints.image); // If this is not the first handle + + if (data.handles.points.length) { + // Add the line from the current handle to the new handle + data.handles.points[config.currentHandle - 1].lines.push(currentPoints.image); + } // Add the new handle + + + data.handles.points.push(newHandleData); // Increment the current handle value + + config.currentHandle += 1; // Force onImageRendered to fire + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + this.fireModifiedEvent(element, data); + } + /** + * If in pencilMode, check the mouse position is farther than the minimum + * distance between points, then add a point. + * + * @private + * @param {Object} eventData - Data object associated with an event. + * @param {Object} points - Data object associated with the tool. + * @returns {undefined} + */ + + }, { + key: "_addPointPencilMode", + value: function _addPointPencilMode(eventData, points) { + var _this3 = this; + + var config = this.configuration; + var element = eventData.element; + var mousePoint = config.mouseLocation.handles.start; + + var handleFurtherThanMinimumSpacing = function handleFurtherThanMinimumSpacing(handle) { + return _this3._isDistanceLargerThanSpacing(element, handle, mousePoint); + }; + + if (points.every(handleFurtherThanMinimumSpacing)) { + this._addPoint(eventData); + } + } + /** + * Ends the active drawing loop and completes the polygon. + * + * @private + * @param {Object} element - The element on which the roi is being drawn. + * @param {Object} handleNearby - the handle nearest to the mouse cursor. + * @returns {undefined} + */ + + }, { + key: "_endDrawing", + value: function _endDrawing(element, handleNearby) { + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var data = toolState.data[config.currentTool]; + data.active = false; + data.highlight = false; + data.handles.invalidHandlePlacement = false; // Connect the end handle to the origin handle + + if (handleNearby !== undefined) { + var points = data.handles.points; + points[config.currentHandle - 1].lines.push(points[0]); + } + + if (this._modifying) { + this._modifying = false; + data.invalidated = true; + } // Reset the current handle + + + config.currentHandle = 0; + config.currentTool = -1; + data.canComplete = false; + + if (this._drawing) { + this._deactivateDraw(element); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + this.fireModifiedEvent(element, data); + this.fireCompletedEvent(element, data); + } + /** + * Returns a handle of a particular tool if it is close to the mouse cursor + * + * @private + * @param {Object} element - The element on which the roi is being drawn. + * @param {Object} data Data object associated with the tool. + * @param {*} coords + * @returns {Number|Object|Boolean} + */ + + }, { + key: "_pointNearHandle", + value: function _pointNearHandle(element, data, coords) { + if (data.handles === undefined || data.handles.points === undefined) { + return; + } + + if (data.visible === false) { + return; + } + + for (var i = 0; i < data.handles.points.length; i++) { + var handleCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, data.handles.points[i]); + + if (_externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(handleCanvas, coords) < 6) { + return i; + } + } // Check to see if mouse in bounding box of textbox + + + if (data.handles.textBox) { + if (Object(_util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_15__["default"])(data.handles.textBox, coords)) { + return data.handles.textBox; + } + } + } + /** + * Returns a handle if it is close to the mouse cursor (all tools) + * + * @private + * @param {Object} eventData - data object associated with an event. + * @returns {Object} + */ + + }, { + key: "_pointNearHandleAllTools", + value: function _pointNearHandleAllTools(eventData) { + var currentPoints = eventData.currentPoints, + element = eventData.element; + var coords = currentPoints.canvas; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + + if (!toolState) { + return; + } + + var handleNearby; + + for (var toolIndex = 0; toolIndex < toolState.data.length; toolIndex++) { + handleNearby = this._pointNearHandle(element, toolState.data[toolIndex], coords); + + if (handleNearby !== undefined) { + return { + handleNearby: handleNearby, + toolIndex: toolIndex + }; + } + } + } + /** + * Gets the current mouse location and stores it in the configuration object. + * + * @private + * @param {Object} eventData The data assoicated with the event. + * @returns {undefined} + */ + + }, { + key: "_getMouseLocation", + value: function _getMouseLocation(eventData) { + var currentPoints = eventData.currentPoints, + image = eventData.image; // Set the mouseLocation handle + + var config = this.configuration; + config.mouseLocation.handles.start.x = currentPoints.image.x; + config.mouseLocation.handles.start.y = currentPoints.image.y; + Object(_util_clip_js__WEBPACK_IMPORTED_MODULE_22__["clipToBox"])(config.mouseLocation.handles.start, image); + } + /** + * Returns true if the proposed location of a new handle is invalid. + * + * @private + * @param {Object} data Data object associated with the tool. + * @param {Object} eventData The data assoicated with the event. + * @returns {Boolean} + */ + + }, { + key: "_checkInvalidHandleLocation", + value: function _checkInvalidHandleLocation(data, eventData) { + if (data.handles.points.length < 2) { + return true; + } + + var invalidHandlePlacement; + + if (this._dragging) { + invalidHandlePlacement = this._checkHandlesPencilMode(data, eventData); + } else { + invalidHandlePlacement = this._checkHandlesPolygonMode(data, eventData); + } + + data.handles.invalidHandlePlacement = invalidHandlePlacement; + } + /** + * Returns true if the proposed location of a new handle is invalid (in polygon mode). + * + * @private + * + * @param {Object} data - data object associated with the tool. + * @param {Object} eventData The data assoicated with the event. + * @returns {Boolean} + */ + + }, { + key: "_checkHandlesPolygonMode", + value: function _checkHandlesPolygonMode(data, eventData) { + var config = this.configuration; + var element = eventData.element; + var mousePoint = config.mouseLocation.handles.start; + var points = data.handles.points; + var invalidHandlePlacement = false; + data.canComplete = false; + + var mouseAtOriginHandle = this._isDistanceSmallerThanCompleteSpacingCanvas(element, points[0], mousePoint); + + if (mouseAtOriginHandle && !freehandIntersect.end(points) && points.length > 2) { + data.canComplete = true; + invalidHandlePlacement = false; + } else { + invalidHandlePlacement = freehandIntersect.newHandle(mousePoint, points); + } + + return invalidHandlePlacement; + } + /** + * Returns true if the proposed location of a new handle is invalid (in pencilMode). + * + * @private + * @param {Object} data - data object associated with the tool. + * @param {Object} eventData The data associated with the event. + * @returns {Boolean} + */ + + }, { + key: "_checkHandlesPencilMode", + value: function _checkHandlesPencilMode(data, eventData) { + var config = this.configuration; + var mousePoint = config.mouseLocation.handles.start; + var points = data.handles.points; + var invalidHandlePlacement = freehandIntersect.newHandle(mousePoint, points); + + if (invalidHandlePlacement === false) { + invalidHandlePlacement = this._invalidHandlePencilMode(data, eventData); + } + + return invalidHandlePlacement; + } + /** + * Returns true if the mouse position is far enough from previous points (in pencilMode). + * + * @private + * @param {Object} data - data object associated with the tool. + * @param {Object} eventData The data associated with the event. + * @returns {Boolean} + */ + + }, { + key: "_invalidHandlePencilMode", + value: function _invalidHandlePencilMode(data, eventData) { + var config = this.configuration; + var element = eventData.element; + var mousePoint = config.mouseLocation.handles.start; + var points = data.handles.points; + + var mouseAtOriginHandle = this._isDistanceSmallerThanCompleteSpacingCanvas(element, points[0], mousePoint); + + if (mouseAtOriginHandle) { + data.canComplete = true; + return false; + } + + data.canComplete = false; // Compare with all other handles appart from the last one + + for (var i = 1; i < points.length - 1; i++) { + if (this._isDistanceSmallerThanSpacing(element, points[i], mousePoint)) { + return true; + } + } + + return false; + } + /** + * Returns true if two points are closer than this.configuration.spacing. + * + * @private + * @param {Object} element The element on which the roi is being drawn. + * @param {Object} p1 The first point, in pixel space. + * @param {Object} p2 The second point, in pixel space. + * @returns {boolean} True if the distance is smaller than the + * allowed canvas spacing. + */ + + }, { + key: "_isDistanceSmallerThanCompleteSpacingCanvas", + value: function _isDistanceSmallerThanCompleteSpacingCanvas(element, p1, p2) { + var p1Canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, p1); + var p2Canvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(element, p2); + var completeHandleRadius; + + if (this._drawingInteractionType === 'Mouse') { + completeHandleRadius = this.configuration.completeHandleRadius; + } else if (this._drawingInteractionType === 'Touch') { + completeHandleRadius = this.configuration.completeHandleRadiusTouch; + } + + return this._compareDistanceToSpacing(element, p1Canvas, p2Canvas, '<', completeHandleRadius); + } + /** + * Returns true if two points are closer than this.configuration.spacing. + * + * @private + * @param {Object} element The element on which the roi is being drawn. + * @param {Object} p1 The first point, in pixel space. + * @param {Object} p2 The second point, in pixel space. + * @returns {boolean} True if the distance is smaller than the + * allowed canvas spacing. + */ + + }, { + key: "_isDistanceSmallerThanSpacing", + value: function _isDistanceSmallerThanSpacing(element, p1, p2) { + return this._compareDistanceToSpacing(element, p1, p2, '<'); + } + /** + * Returns true if two points are farther than this.configuration.spacing. + * + * @private + * @param {Object} element The element on which the roi is being drawn. + * @param {Object} p1 The first point, in pixel space. + * @param {Object} p2 The second point, in pixel space. + * @returns {boolean} True if the distance is smaller than the + * allowed canvas spacing. + */ + + }, { + key: "_isDistanceLargerThanSpacing", + value: function _isDistanceLargerThanSpacing(element, p1, p2) { + return this._compareDistanceToSpacing(element, p1, p2, '>'); + } + /** + * Compares the distance between two points to this.configuration.spacing. + * + * @private + * @param {Object} element The element on which the roi is being drawn. + * @param {Object} p1 The first point, in pixel space. + * @param {Object} p2 The second point, in pixel space. + * @param {string} comparison The comparison to make. + * @param {number} spacing The allowed canvas spacing + * @returns {boolean} True if the distance is smaller than the + * allowed canvas spacing. + */ + + }, { + key: "_compareDistanceToSpacing", + value: function _compareDistanceToSpacing(element, p1, p2) { + var comparison = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '>'; + var spacing = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.configuration.spacing; + + if (comparison === '>') { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(p1, p2) > spacing; + } + + return _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.distance(p1, p2) < spacing; + } + /** + * Adds drawing loop event listeners. + * + * @private + * @param {Object} element - The viewport element to add event listeners to. + * @param {string} interactionType - The interactionType used for the loop. + * @modifies {element} + * @returns {undefined} + */ + + }, { + key: "_activateDraw", + value: function _activateDraw(element) { + var interactionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Mouse'; + this._drawing = true; + this._drawingInteractionType = interactionType; + _store_index_js__WEBPACK_IMPORTED_MODULE_12__["state"].isMultiPartToolActive = true; + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_23__["hideToolCursor"])(this.element); // Polygonal Mode + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DOWN, this._drawingMouseDownCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_MOVE, this._drawingMouseMoveCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DOUBLE_CLICK, this._drawingMouseDoubleClickCallback); // Drag/Pencil Mode + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this._drawingMouseDragCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this._drawingMouseUpCallback); // Touch + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_START, this._drawingMouseMoveCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_START, this._drawingTouchStartCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this._drawingTouchDragCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this._drawingMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].DOUBLE_TAP, this._drawingDoubleTapClickCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Removes drawing loop event listeners. + * + * @private + * @param {Object} element - The viewport element to add event listeners to. + * @modifies {element} + * @returns {undefined} + */ + + }, { + key: "_deactivateDraw", + value: function _deactivateDraw(element) { + this._drawing = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_12__["state"].isMultiPartToolActive = false; + this._activeDrawingToolReference = null; + this._drawingInteractionType = null; + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_23__["setToolCursor"])(this.element, this.svgCursor); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DOWN, this._drawingMouseDownCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_MOVE, this._drawingMouseMoveCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DOUBLE_CLICK, this._drawingMouseDoubleClickCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this._drawingMouseDragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this._drawingMouseUpCallback); // Touch + + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_START, this._drawingTouchStartCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this._drawingTouchDragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_START, this._drawingMouseMoveCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this._drawingMouseUpCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Adds modify loop event listeners. + * + * @private + * @param {Object} element - The viewport element to add event listeners to. + * @modifies {element} + * @returns {undefined} + */ + + }, { + key: "_activateModify", + value: function _activateModify(element) { + _store_index_js__WEBPACK_IMPORTED_MODULE_12__["state"].isToolLocked = true; + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this._editMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this._editMouseDragCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_CLICK, this._editMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this._editMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this._editTouchDragCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * Removes modify loop event listeners. + * + * @private + * @param {Object} element - The viewport element to add event listeners to. + * @modifies {element} + * @returns {undefined} + */ + + }, { + key: "_deactivateModify", + value: function _deactivateModify(element) { + _store_index_js__WEBPACK_IMPORTED_MODULE_12__["state"].isToolLocked = false; + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_UP, this._editMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_DRAG, this._editMouseDragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MOUSE_CLICK, this._editMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_END, this._editMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_6__["default"].TOUCH_DRAG, this._editTouchDragCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + }, { + key: "passiveCallback", + value: function passiveCallback(element) { + this._closeToolIfDrawing(element); + } + }, { + key: "enabledCallback", + value: function enabledCallback(element) { + this._closeToolIfDrawing(element); + } + }, { + key: "disabledCallback", + value: function disabledCallback(element) { + this._closeToolIfDrawing(element); + } + }, { + key: "_closeToolIfDrawing", + value: function _closeToolIfDrawing(element) { + if (this._drawing) { + // Actively drawing but changed mode. + var config = this.configuration; + var lastHandlePlaced = config.currentHandle; + + this._endDrawing(element, lastHandlePlaced); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + } + /** + * Fire MEASUREMENT_MODIFIED event on provided element + * @param {any} element which freehand data has been modified + * @param {any} measurementData the measurment data + * @returns {void} + */ + + }, { + key: "fireModifiedEvent", + value: function fireModifiedEvent(element, measurementData) { + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MEASUREMENT_MODIFIED; + var eventData = { + toolName: this.name, + toolType: this.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, eventType, eventData); + } + }, { + key: "fireCompletedEvent", + value: function fireCompletedEvent(element, measurementData) { + var eventType = _events_js__WEBPACK_IMPORTED_MODULE_6__["default"].MEASUREMENT_COMPLETED; + var eventData = { + toolName: this.name, + toolType: this.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, eventType, eventData); + } // =================================================================== + // Public Configuration API. . + // =================================================================== + + }, { + key: "cancelDrawing", + + /** + * Ends the active drawing loop and removes the polygon. + * + * @public + * @param {Object} element - The element on which the roi is being drawn. + * @returns {null} + */ + value: function cancelDrawing(element) { + if (!this._drawing) { + return; + } + + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["getToolState"])(element, this.name); + var config = this.configuration; + var data = toolState.data[config.currentTool]; + data.active = false; + data.highlight = false; + data.handles.invalidHandlePlacement = false; // Reset the current handle + + config.currentHandle = 0; + config.currentTool = -1; + data.canComplete = false; + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_9__["removeToolState"])(element, this.name, data); + + this._deactivateDraw(element); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + /** + * New image event handler. + * + * @public + * @param {Object} evt The event. + * @returns {null} + */ + + }, { + key: "newImageCallback", + value: function newImageCallback(evt) { + var config = this.configuration; + + if (!(this._drawing && this._activeDrawingToolReference)) { + return; + } // Actively drawing but scrolled to different image. + + + var element = evt.detail.element; + var data = this._activeDrawingToolReference; + data.active = false; + data.highlight = false; + data.handles.invalidHandlePlacement = false; // Connect the end handle to the origin handle + + var points = data.handles.points; + points[config.currentHandle - 1].lines.push(points[0]); // Reset the current handle + + config.currentHandle = 0; + config.currentTool = -1; + data.canComplete = false; + + this._deactivateDraw(element); + + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + }, { + key: "spacing", + get: function get() { + return this.configuration.spacing; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehand spacing to a value other than a number.'); + } + + this.configuration.spacing = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "activeHandleRadius", + get: function get() { + return this.configuration.activeHandleRadius; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehand activeHandleRadius to a value other than a number.'); + } + + this.configuration.activeHandleRadius = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "completeHandleRadius", + get: function get() { + return this.configuration.completeHandleRadius; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('Attempting to set freehand completeHandleRadius to a value other than a number.'); + } + + this.configuration.completeHandleRadius = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "alwaysShowHandles", + get: function get() { + return this.configuration.alwaysShowHandles; + }, + set: function set(value) { + if (typeof value !== 'boolean') { + throw new Error('Attempting to set freehand alwaysShowHandles to a value other than a boolean.'); + } + + this.configuration.alwaysShowHandles = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }, { + key: "invalidColor", + get: function get() { + return this.configuration.invalidColor; + }, + set: function set(value) { + /* + It'd be easy to check if the color was e.g. a valid rgba color. However + it'd be difficult to check if the color was a named CSS color without + bloating the library, so we don't. If the canvas can't intepret the color + it'll show up grey. + */ + this.configuration.invalidColor = value; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(this.element); + } + }]); + + return FreehandRoiTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_8__["default"]); + + + +function defaultFreehandConfiguration() { + return { + mouseLocation: { + handles: { + start: { + highlight: true, + active: true + } + } + }, + spacing: 1, + activeHandleRadius: 3, + completeHandleRadius: 6, + completeHandleRadiusTouch: 28, + alwaysShowHandles: false, + invalidColor: 'crimson', + currentHandle: 0, + currentTool: -1, + drawHandles: true, + renderDashed: false + }; +} + +function preventPropagation(evt) { + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); +} + +/***/ }), + +/***/ "./tools/annotation/LengthTool.js": +/*!****************************************!*\ + !*** ./tools/annotation/LengthTool.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return LengthTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../util/lineSegDistance.js */ "./util/lineSegDistance.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + // State + + + + // Drawing + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_14__["getLogger"])('tools:annotation:LengthTool'); +/** + * @public + * @class LengthTool + * @memberof Tools.Annotation + * @classdesc Tool for measuring distances. + * @extends Tools.Base.BaseAnnotationTool + */ + +var LengthTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(LengthTool, _BaseAnnotationTool); + + function LengthTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, LengthTool); + + var defaultProps = { + name: 'Length', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__["lengthCursor"], + configuration: { + drawHandles: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + renderDashed: false, + digits: 2 + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(LengthTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_16__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(LengthTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + var _eventData$currentPoi = eventData.currentPoints.image, + x = _eventData$currentPoi.x, + y = _eventData$currentPoi.y; + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + start: { + x: x, + y: y, + highlight: true, + active: false + }, + end: { + x: x, + y: y, + highlight: true, + active: true + }, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + /** + * + * + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {Boolean} + */ + + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + var hasStartAndEndHandles = data && data.handles && data.handles.start && data.handles.end; + var validParameters = hasStartAndEndHandles; + + if (!validParameters) { + logger.warn("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + return false; + } + + if (data.visible === false) { + return false; + } + + return Object(_util_lineSegDistance_js__WEBPACK_IMPORTED_MODULE_12__["default"])(element, data.handles.start, data.handles.end, coords) < 25; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_15__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; // Set rowPixelSpacing and columnPixelSpacing to 1 if they are undefined (or zero) + + + var dx = (data.handles.end.x - data.handles.start.x) * (colPixelSpacing || 1); + var dy = (data.handles.end.y - data.handles.start.y) * (rowPixelSpacing || 1); // Calculate the length, and create the text variable with the millimeters or pixels suffix + + var length = Math.sqrt(dx * dx + dy * dy); // Store the length inside the tool for outside access + + data.length = length; + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed, + digits = _this$configuration.digits; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_9__["getNewContext"])(eventData.canvasContext.canvas); + var image = eventData.image, + element = eventData.element; + + var _getPixelSpacing2 = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_15__["default"])(image), + rowPixelSpacing = _getPixelSpacing2.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing2.colPixelSpacing; + + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_7__["default"].getToolWidth(); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_17__["getModule"])('globalConfiguration').configuration.lineDash; + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_9__["draw"])(context, function (context) { + // Configurable shadow + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_9__["setShadow"])(context, _this2.configuration); + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_8__["default"].getColorIfActive(data); + var lineOptions = { + color: color + }; + + if (renderDashed) { + lineOptions.lineDash = lineDash; + } // Draw the measurement line + + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_9__["drawLine"])(context, element, data.handles.start, data.handles.end, lineOptions); // Draw the handles + + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + + if (_this2.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_11__["default"])(context, eventData, data.handles, handleOptions); + } + + if (!data.handles.textBox.hasMoved) { + var coords = { + x: Math.max(data.handles.start.x, data.handles.end.x) + }; // Depending on which handle has the largest x-value, + // Set the y-value for the text box + + if (coords.x === data.handles.start.x) { + coords.y = data.handles.start.y; + } else { + coords.y = data.handles.end.y; + } + + data.handles.textBox.x = coords.x; + data.handles.textBox.y = coords.y; + } // Move the textbox slightly to the right and upwards + // So that it sits beside the length tool handle + + + var xOffset = 10; // Update textbox stats + + if (data.invalidated === true) { + if (data.length) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } + + var text = textBoxText(data, rowPixelSpacing, colPixelSpacing); + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_10__["default"])(context, element, data.handles.textBox, text, data.handles, textBoxAnchorPoints, color, lineWidth, xOffset, true); + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } // - SideEffect: Updates annotation 'suffix' + + + function textBoxText(annotation, rowPixelSpacing, colPixelSpacing) { + var measuredValue = _sanitizeMeasuredValue(annotation.length); // Measured value is not defined, return empty string + + + if (!measuredValue) { + return ''; + } // Set the length text suffix depending on whether or not pixelSpacing is available + + + var suffix = 'mm'; + + if (!rowPixelSpacing || !colPixelSpacing) { + suffix = 'pixels'; + } + + annotation.unit = suffix; + return "".concat(measuredValue.toFixed(digits), " ").concat(suffix); + } + + function textBoxAnchorPoints(handles) { + var midpoint = { + x: (handles.start.x + handles.end.x) / 2, + y: (handles.start.y + handles.end.y) / 2 + }; + return [handles.start, midpoint, handles.end]; + } + } + }]); + + return LengthTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_5__["default"]); +/** + * Attempts to sanitize a value by casting as a number; if unable to cast, + * we return `undefined` + * + * @param {*} value + * @returns a number or undefined + */ + + + + +function _sanitizeMeasuredValue(value) { + var parsedValue = Number(value); + var isNumber = !isNaN(parsedValue); + return isNumber ? parsedValue : undefined; +} + +/***/ }), + +/***/ "./tools/annotation/ProbeTool.js": +/*!***************************************!*\ + !*** ./tools/annotation/ProbeTool.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ProbeTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../stateManagement/textStyle.js */ "./stateManagement/textStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../util/getRGBPixels.js */ "./util/getRGBPixels.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_throttle__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../util/throttle */ "./util/throttle.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + + // State + + + + // Drawing + + + + // Utilities + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_16__["getLogger"])('tools:annotation:ProbeTool'); +/** + * @public + * @class ProbeTool + * @memberof Tools.Annotation + * @classdesc Tool which provides a probe of the image data at the + * desired position. + * @extends Tools.Base.BaseAnnotationTool + */ + +var ProbeTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(ProbeTool, _BaseAnnotationTool); + + function ProbeTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ProbeTool); + + var defaultProps = { + name: 'Probe', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__["probeCursor"], + configuration: { + drawHandles: true, + renderDashed: false + } + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(ProbeTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle__WEBPACK_IMPORTED_MODULE_17__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(ProbeTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + } + } + }; + } + /** + * + * + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {Boolean} + */ + + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + var hasEndHandle = data && data.handles && data.handles.end; + var validParameters = hasEndHandle; + + if (!validParameters) { + logger.warn("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + } + + if (!validParameters || data.visible === false) { + return false; + } + + var probeCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); + return _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstoneMath.point.distance(probeCoords, coords) < 5; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var x = Math.round(data.handles.end.x); + var y = Math.round(data.handles.end.y); + var stats = {}; + + if (x >= 0 && y >= 0 && x < image.columns && y < image.rows) { + stats.x = x; + stats.y = y; + + if (image.color) { + stats.storedPixels = Object(_util_getRGBPixels_js__WEBPACK_IMPORTED_MODULE_13__["default"])(element, x, y, 1, 1); + } else { + stats.storedPixels = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getStoredPixels(element, x, y, 1, 1); + stats.sp = stats.storedPixels[0]; + stats.mo = stats.sp * image.slope + image.intercept; + stats.suv = Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_14__["default"])(image, stats.sp); + } + } + + data.cachedStats = stats; + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var eventData = evt.detail; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + renderDashed = _this$configuration.renderDashed; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["getNewContext"])(eventData.canvasContext.canvas); + var image = eventData.image, + element = eventData.element; + var fontHeight = _stateManagement_textStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getFontSize(); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_18__["getModule"])('globalConfiguration').configuration.lineDash; + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["draw"])(context, function (context) { + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + + if (_this2.configuration.drawHandles) { + // Draw the handles + var handleOptions = { + handleRadius: handleRadius, + color: color + }; + + if (renderDashed) { + handleOptions.lineDash = lineDash; + } + + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_12__["default"])(context, eventData, data.handles, handleOptions); + } // Update textbox stats + + + if (data.invalidated === true) { + if (data.cachedStats) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } + + var text, str; + var _data$cachedStats = data.cachedStats, + x = _data$cachedStats.x, + y = _data$cachedStats.y, + storedPixels = _data$cachedStats.storedPixels, + sp = _data$cachedStats.sp, + mo = _data$cachedStats.mo, + suv = _data$cachedStats.suv; + + if (x >= 0 && y >= 0 && x < image.columns && y < image.rows) { + text = "".concat(x, ", ").concat(y); + + if (image.color) { + str = "R: ".concat(storedPixels[0], " G: ").concat(storedPixels[1], " B: ").concat(storedPixels[2]); + } else { + // Draw text + str = "SP: ".concat(sp, " MO: ").concat(parseFloat(mo.toFixed(3))); + + if (suv) { + str += " SUV: ".concat(parseFloat(suv.toFixed(3))); + } + } // Coords for text + + + var coords = { + // Translate the x/y away from the cursor + x: data.handles.end.x + 3, + y: data.handles.end.y - 3 + }; + var textCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(eventData.element, coords); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__["default"])(context, str, textCoords.x, textCoords.y + fontHeight + 5, color); + Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__["default"])(context, text, textCoords.x, textCoords.y, color); + } + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + } + }]); + + return ProbeTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + + + +/***/ }), + +/***/ "./tools/annotation/RectangleRoiTool.js": +/*!**********************************************!*\ + !*** ./tools/annotation/RectangleRoiTool.js ***! + \**********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return RectangleRoiTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../util/calculateSUV.js */ "./util/calculateSUV.js"); +/* harmony import */ var _util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../util/getROITextBoxCoords.js */ "./util/getROITextBoxCoords.js"); +/* harmony import */ var _util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../util/numbersWithCommas.js */ "./util/numbersWithCommas.js"); +/* harmony import */ var _util_throttle_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../util/throttle.js */ "./util/throttle.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../store/index */ "./store/index.js"); + + + + + + + // State + + + + // Drawing + + // Util + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_16__["getLogger"])('tools:annotation:RectangleRoiTool'); +/** + * @public + * @class RectangleRoiTool + * @memberof Tools.Annotation + * @classdesc Tool for drawing rectangular regions of interest, and measuring + * the statistics of the enclosed pixels. + * @extends Tools.Base.BaseAnnotationTool + */ + +var RectangleRoiTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(RectangleRoiTool, _BaseAnnotationTool); + + function RectangleRoiTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, RectangleRoiTool); + + var defaultProps = { + name: 'RectangleRoi', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + drawHandles: true, + drawHandlesOnHover: false, + hideHandlesIfMoving: false, + renderDashed: false // showMinMax: false, + // showHounsfieldUnits: true + + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_15__["rectangleRoiCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(RectangleRoiTool).call(this, props, defaultProps)); + _this.throttledUpdateCachedStats = Object(_util_throttle_js__WEBPACK_IMPORTED_MODULE_14__["default"])(_this.updateCachedStats, 110); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(RectangleRoiTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var goodEventData = eventData && eventData.currentPoints && eventData.currentPoints.image; + + if (!goodEventData) { + logger.error("required eventData not supplied to tool ".concat(this.name, "'s createNewMeasurement")); + return; + } + + return { + visible: true, + active: true, + color: undefined, + invalidated: true, + handles: { + start: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: false + }, + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true + }, + initialRotation: eventData.viewport.rotation, + textBox: { + active: false, + hasMoved: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + } + } + }; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords, interactionType) { + var hasStartAndEndHandles = data && data.handles && data.handles.start && data.handles.end; + var validParameters = hasStartAndEndHandles; + + if (!validParameters) { + logger.warn("invalid parameters supplied to tool ".concat(this.name, "'s pointNearTool")); + } + + if (!validParameters || data.visible === false) { + return false; + } + + var distance = interactionType === 'mouse' ? 15 : 25; + var startCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.start); + var endCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.pixelToCanvas(element, data.handles.end); + var rect = { + left: Math.min(startCanvas.x, endCanvas.x), + top: Math.min(startCanvas.y, endCanvas.y), + width: Math.abs(startCanvas.x - endCanvas.x), + height: Math.abs(startCanvas.y - endCanvas.y) + }; + var distanceToPoint = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstoneMath.rect.distanceToPoint(rect, coords); + return distanceToPoint < distance; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; + var modality = seriesModule.modality; + var pixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_17__["default"])(image); + + var stats = _calculateStats(image, element, data.handles, modality, pixelSpacing); + + data.cachedStats = stats; + data.invalidated = false; + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var _this2 = this; + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_7__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } + + var eventData = evt.detail; + var image = eventData.image, + element = eventData.element; + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_8__["default"].getToolWidth(); + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_18__["getModule"])('globalConfiguration').configuration.lineDash; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["getNewContext"])(eventData.canvasContext.canvas); + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_17__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; // Meta + + + var seriesModule = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.metaData.get('generalSeriesModule', image.imageId) || {}; // Pixel Spacing + + var modality = seriesModule.modality; + var hasPixelSpacing = rowPixelSpacing && colPixelSpacing; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["draw"])(context, function (context) { + // If we have tool data for this element - iterate over each set and draw it + for (var i = 0; i < toolData.data.length; i++) { + var data = toolData.data[i]; + + if (data.visible === false) { + continue; + } // Configure + + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["setShadow"])(context, _this2.configuration); + var rectOptions = { + color: color + }; + + if (renderDashed) { + rectOptions.lineDash = lineDash; + } // Draw + + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["drawRect"])(context, element, data.handles.start, data.handles.end, rectOptions, 'pixel', data.handles.initialRotation); + + if (_this2.configuration.drawHandles) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["drawHandles"])(context, eventData, data.handles, handleOptions); + } // Update textbox stats + + + if (data.invalidated === true) { + if (data.cachedStats) { + _this2.throttledUpdateCachedStats(image, element, data); + } else { + _this2.updateCachedStats(image, element, data); + } + } // Default to textbox on right side of ROI + + + if (!data.handles.textBox.hasMoved) { + var defaultCoords = Object(_util_getROITextBoxCoords_js__WEBPACK_IMPORTED_MODULE_12__["default"])(eventData.viewport, data.handles); + Object.assign(data.handles.textBox, defaultCoords); + } + + var textBoxAnchorPoints = function textBoxAnchorPoints(handles) { + return _findTextBoxAnchorPoints(handles.start, handles.end); + }; + + var textBoxContent = _createTextBoxContent(context, image.color, data.cachedStats, modality, hasPixelSpacing, _this2.configuration); + + data.unit = _getUnit(modality, _this2.configuration.showHounsfieldUnits); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["drawLinkedTextBox"])(context, element, data.handles.textBox, textBoxContent, data.handles, textBoxAnchorPoints, color, lineWidth, 10, true); + } + }); + } + }]); + + return RectangleRoiTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * TODO: This is the same method (+ GetPixels) for the other ROIs + * TODO: The pixel filtering is the unique bit + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {{ left: number, top: number, width: number, height: number}} + */ + + + + +function _getRectangleImageCoordinates(startHandle, endHandle) { + return { + left: Math.min(startHandle.x, endHandle.x), + top: Math.min(startHandle.y, endHandle.y), + width: Math.abs(startHandle.x - endHandle.x), + height: Math.abs(startHandle.y - endHandle.y) + }; +} +/** + * + * + * @param {*} image + * @param {*} element + * @param {*} handles + * @param {*} modality + * @param {*} pixelSpacing + * @returns {Object} The Stats object + */ + + +function _calculateStats(image, element, handles, modality, pixelSpacing) { + // Retrieve the bounds of the rectangle in image coordinates + var roiCoordinates = _getRectangleImageCoordinates(handles.start, handles.end); // Retrieve the array of pixels that the rectangle bounds cover + + + var pixels = _externalModules_js__WEBPACK_IMPORTED_MODULE_5__["default"].cornerstone.getPixels(element, roiCoordinates.left, roiCoordinates.top, roiCoordinates.width, roiCoordinates.height); // Calculate the mean & standard deviation from the pixels and the rectangle details + + var roiMeanStdDev = _calculateRectangleStats(pixels, roiCoordinates); + + var meanStdDevSUV; + + if (modality === 'PT') { + meanStdDevSUV = { + mean: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__["default"])(image, roiMeanStdDev.mean, true) || 0, + stdDev: Object(_util_calculateSUV_js__WEBPACK_IMPORTED_MODULE_11__["default"])(image, roiMeanStdDev.stdDev, true) || 0 + }; + } // Calculate the image area from the rectangle dimensions and pixel spacing + + + var area = roiCoordinates.width * (pixelSpacing.colPixelSpacing || 1) * (roiCoordinates.height * (pixelSpacing.rowPixelSpacing || 1)); + var perimeter = roiCoordinates.width * 2 * (pixelSpacing.colPixelSpacing || 1) + roiCoordinates.height * 2 * (pixelSpacing.rowPixelSpacing || 1); + return { + area: area || 0, + perimeter: perimeter, + count: roiMeanStdDev.count || 0, + mean: roiMeanStdDev.mean || 0, + variance: roiMeanStdDev.variance || 0, + stdDev: roiMeanStdDev.stdDev || 0, + min: roiMeanStdDev.min || 0, + max: roiMeanStdDev.max || 0, + meanStdDevSUV: meanStdDevSUV + }; +} +/** + * + * + * @param {*} sp + * @param {*} rectangle + * @returns {{ count, number, mean: number, variance: number, stdDev: number, min: number, max: number }} + */ + + +function _calculateRectangleStats(sp, rectangle) { + var sum = 0; + var sumSquared = 0; + var count = 0; + var index = 0; + var min = sp ? sp[0] : null; + var max = sp ? sp[0] : null; + + for (var y = rectangle.top; y < rectangle.top + rectangle.height; y++) { + for (var x = rectangle.left; x < rectangle.left + rectangle.width; x++) { + sum += sp[index]; + sumSquared += sp[index] * sp[index]; + min = Math.min(min, sp[index]); + max = Math.max(max, sp[index]); + count++; // TODO: Wouldn't this just be sp.length? + + index++; + } + } + + if (count === 0) { + return { + count: count, + mean: 0.0, + variance: 0.0, + stdDev: 0.0, + min: 0.0, + max: 0.0 + }; + } + + var mean = sum / count; + var variance = sumSquared / count - mean * mean; + return { + count: count, + mean: mean, + variance: variance, + stdDev: Math.sqrt(variance), + min: min, + max: max + }; +} +/** + * + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {Array.<{x: number, y: number}>} + */ + + +function _findTextBoxAnchorPoints(startHandle, endHandle) { + var _getRectangleImageCoo = _getRectangleImageCoordinates(startHandle, endHandle), + left = _getRectangleImageCoo.left, + top = _getRectangleImageCoo.top, + width = _getRectangleImageCoo.width, + height = _getRectangleImageCoo.height; + + return [{ + // Top middle point of rectangle + x: left + width / 2, + y: top + }, { + // Left middle point of rectangle + x: left, + y: top + height / 2 + }, { + // Bottom middle point of rectangle + x: left + width / 2, + y: top + height + }, { + // Right middle point of rectangle + x: left + width, + y: top + height / 2 + }]; +} +/** + * + * + * @param {*} area + * @param {*} hasPixelSpacing + * @returns {string} The formatted label for showing area + */ + + +function _formatArea(area, hasPixelSpacing) { + // This uses Char code 178 for a superscript 2 + var suffix = hasPixelSpacing ? " mm".concat(String.fromCharCode(178)) : " px".concat(String.fromCharCode(178)); + return "Area: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__["default"])(area.toFixed(2))).concat(suffix); +} + +function _getUnit(modality, showHounsfieldUnits) { + return modality === 'CT' && showHounsfieldUnits !== false ? 'HU' : ''; +} +/** + * TODO: This is identical to EllipticalROI's same fn + * TODO: We may want to make this a utility for ROIs with these values? + * + * @param {*} context + * @param {*} isColorImage + * @param {*} { area, mean, stdDev, min, max, meanStdDevSUV } + * @param {*} modality + * @param {*} hasPixelSpacing + * @param {*} [options={}] + * @returns {string[]} + */ + + +function _createTextBoxContent(context, isColorImage, _ref, modality, hasPixelSpacing) { + var area = _ref.area, + mean = _ref.mean, + stdDev = _ref.stdDev, + min = _ref.min, + max = _ref.max, + meanStdDevSUV = _ref.meanStdDevSUV; + var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; + var showMinMax = options.showMinMax || false; + var textLines = []; + var otherLines = []; + + if (!isColorImage) { + var hasStandardUptakeValues = meanStdDevSUV && meanStdDevSUV.mean !== 0; + + var unit = _getUnit(modality, options.showHounsfieldUnits); + + var meanString = "Mean: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__["default"])(mean.toFixed(2)), " ").concat(unit); + var stdDevString = "Std Dev: ".concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__["default"])(stdDev.toFixed(2)), " ").concat(unit); // If this image has SUV values to display, concatenate them to the text line + + if (hasStandardUptakeValues) { + var SUVtext = ' SUV: '; + var meanSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__["default"])(meanStdDevSUV.mean.toFixed(2))); + var stdDevSuvString = "".concat(SUVtext).concat(Object(_util_numbersWithCommas_js__WEBPACK_IMPORTED_MODULE_13__["default"])(meanStdDevSUV.stdDev.toFixed(2))); + var targetStringLength = Math.floor(context.measureText("".concat(stdDevString, " ")).width); + + while (context.measureText(meanString).width < targetStringLength) { + meanString += ' '; + } + + otherLines.push("".concat(meanString).concat(meanSuvString)); + otherLines.push("".concat(stdDevString, " ").concat(stdDevSuvString)); + } else { + otherLines.push("".concat(meanString)); + otherLines.push("".concat(stdDevString)); + } + + if (showMinMax) { + var minString = "Min: ".concat(min, " ").concat(unit); + var maxString = "Max: ".concat(max, " ").concat(unit); + + var _targetStringLength = hasStandardUptakeValues ? Math.floor(context.measureText("".concat(stdDevString, " ")).width) : Math.floor(context.measureText("".concat(meanString, " ")).width); + + while (context.measureText(minString).width < _targetStringLength) { + minString += ' '; + } + + otherLines.push("".concat(minString).concat(maxString)); + } + } + + textLines.push(_formatArea(area, hasPixelSpacing)); + otherLines.forEach(function (x) { + return textLines.push(x); + }); + return textLines; +} + +/***/ }), + +/***/ "./tools/annotation/TextMarkerTool.js": +/*!********************************************!*\ + !*** ./tools/annotation/TextMarkerTool.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TextMarkerTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base/BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../../drawing/drawTextBox.js */ "./drawing/drawTextBox.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../cursors/index.js */ "./tools/cursors/index.js"); + + + + + + + + + + + + + + +/** + * @public + * @class TextMarkerTool + * @memberof Tools.Annotation + * + * @classdesc Tool for annotating an image with text markers. + * @extends Tools.Base.BaseAnnotationTool + */ + +var TextMarkerTool = +/*#__PURE__*/ +function (_BaseAnnotationTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(TextMarkerTool, _BaseAnnotationTool); + + function TextMarkerTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, TextMarkerTool); + + var defaultProps = { + name: 'TextMarker', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + markers: [], + current: '', + ascending: true, + loop: false, + changeTextCallback: changeTextCallback + }, + svgCursor: _cursors_index_js__WEBPACK_IMPORTED_MODULE_13__["textMarkerCursor"] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(TextMarkerTool).call(this, props, defaultProps)); + _this.touchPressCallback = _this._changeText.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + _this.doubleClickCallback = _this._changeText.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(TextMarkerTool, [{ + key: "createNewMeasurement", + value: function createNewMeasurement(eventData) { + var config = this.configuration; + + if (!config.current) { + return; + } // Create the measurement data for this tool with the end handle activated + + + var measurementData = { + visible: true, + active: true, + text: config.current, + color: undefined, + handles: { + end: { + x: eventData.currentPoints.image.x, + y: eventData.currentPoints.image.y, + highlight: true, + active: true, + hasBoundingBox: true + } + } + }; // Create a rectangle representing the image + + var imageRect = { + left: 0, + top: 0, + width: eventData.image.width, + height: eventData.image.height + }; // Check if the current handle is outside the image, + // If it is, prevent the handle creation + + if (!_externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.point.insideRect(measurementData.handles.end, imageRect)) { + return; + } // Update the current marker for the next marker + + + var currentIndex = config.markers.indexOf(config.current); + var increment = config.ascending ? 1 : -1; + currentIndex += increment; + + if (currentIndex >= config.markers.length) { + currentIndex = config.loop ? 0 : -1; + } else if (currentIndex < 0) { + currentIndex = config.loop ? config.markers.length : -1; + } + + config.current = config.markers[currentIndex]; + return measurementData; + } + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + if (data.visible === false) { + return false; + } + + if (!data.handles.end.boundingBox) { + return; + } + + var distanceToPoint = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstoneMath.rect.distanceToPoint(data.handles.end.boundingBox, coords); + var insideBoundingBox = Object(_util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_8__["default"])(data.handles.end, coords); + return distanceToPoint < 10 || insideBoundingBox; + } + }, { + key: "updateCachedStats", + value: function updateCachedStats() {// Implementing to satisfy BaseAnnotationTool + } + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + var config = this.configuration; // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_12__["getToolState"])(eventData.element, this.name); + + if (!toolData) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["getNewContext"])(eventData.canvasContext.canvas); + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_9__["default"].getColorIfActive(data); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_10__["setShadow"])(context, config); + var textCoords = _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.pixelToCanvas(eventData.element, data.handles.end); + var options = { + centering: { + x: true, + y: true + } + }; + data.handles.end.boundingBox = Object(_drawing_drawTextBox_js__WEBPACK_IMPORTED_MODULE_11__["default"])(context, data.text, textCoords.x, textCoords.y - 10, color, options); + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } + } + }, { + key: "_changeText", + value: function _changeText(evt) { + var eventData = evt.detail; + var element = eventData.element, + currentPoints = eventData.currentPoints; + var data; + + function doneChangingTextCallback(data, updatedText, deleteTool) { + if (deleteTool === true) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_12__["removeToolState"])(element, this.name, data); + } else { + data.text = updatedText; + } + + data.active = false; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); + } + + var config = this.configuration; + var coords = currentPoints.canvas; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_12__["getToolState"])(element, this.name); // Now check to see if there is a handle we can move + + if (!toolData) { + return; + } + + for (var i = 0; i < toolData.data.length; i++) { + data = toolData.data[i]; + + if (this.pointNearTool(element, data, coords)) { + data.active = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_7__["default"].cornerstone.updateImage(element); // Allow relabelling via a callback + + config.changeTextCallback(data, eventData, doneChangingTextCallback); + evt.stopImmediatePropagation(); + evt.preventDefault(); + evt.stopPropagation(); + return; + } + } + } + }]); + + return TextMarkerTool; +}(_base_BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); +/** + * This function is a callback to be overwriten in order to provide the wanted feature + * modal, overlay, popup or any kind of interaction with the user to be able to update + * the text marker label. + * + * @param {Object} data + * @param {Object} eventData + * @param {doneChangingTextCallback} doneChangingTextCallback + * @returns {void} + */ + + + + +var changeTextCallback = function changeTextCallback(data, eventData, doneChangingTextCallback) { + // eslint-disable-next-line no-alert + doneChangingTextCallback(data, prompt('请输入注释内容')); +}; +/** + * @callback doneChangingTextCallback + * @param {Object} data + * @param {string} text - The new text + */ + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/addNewMeasurement.js": +/*!*****************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/addNewMeasurement.js ***! + \*****************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../events.js */ "./events.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../../manipulators/anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../util/triggerEvent.js */ "./util/triggerEvent.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _BidirectionalTool__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../BidirectionalTool */ "./tools/annotation/BidirectionalTool.js"); +/* harmony import */ var _utils_updatePerpendicularLineHandles_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./utils/updatePerpendicularLineHandles.js */ "./tools/annotation/bidirectionalTool/utils/updatePerpendicularLineHandles.js"); + + + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt, interactionType) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image, + buttons = eventData.buttons; + var config = this.configuration; + + if (checkPixelSpacing(image)) { + return; + } + + var measurementData = this.createNewMeasurement(eventData); + + var doneCallback = function doneCallback() { + measurementData.active = false; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + }; // Associate this data with this imageId so we can render it and manipulate it + + + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["addToolState"])(element, this.name, measurementData); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + var timestamp = new Date().getTime(); + var _measurementData$hand = measurementData.handles, + end = _measurementData$hand.end, + perpendicularStart = _measurementData$hand.perpendicularStart; + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_2__["moveNewHandle"])(eventData, this.name, measurementData, end, {}, interactionType, function (success) { + if (!success) { + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["removeToolState"])(element, _this.name, measurementData); + return; + } + + var handles = measurementData.handles, + longestDiameter = measurementData.longestDiameter, + shortestDiameter = measurementData.shortestDiameter; + var hasHandlesOutside = Object(_manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData, handles); + var longestDiameterSize = parseFloat(longestDiameter) || 0; + var shortestDiameterSize = parseFloat(shortestDiameter) || 0; + var isTooSmal = longestDiameterSize < 1 || shortestDiameterSize < 1; + var isTooFast = new Date().getTime() - timestamp < 150; + + if (hasHandlesOutside || isTooSmal || isTooFast) { + // Delete the measurement + measurementData.cancelled = true; + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["removeToolState"])(element, _this.name, measurementData); + } else { + // Set lesionMeasurementData Session + config.getMeasurementLocationCallback(measurementData, eventData, doneCallback); + } // Update perpendicular line and disconnect it from the long-line + + + Object(_utils_updatePerpendicularLineHandles_js__WEBPACK_IMPORTED_MODULE_8__["default"])(eventData, measurementData); + perpendicularStart.locked = false; + measurementData.invalidated = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_6__["default"])(element, buttons, interactionType); + + if (activeTool instanceof _BidirectionalTool__WEBPACK_IMPORTED_MODULE_7__["default"]) { + activeTool.updateCachedStats(image, element, measurementData); + } + + var modifiedEventData = { + toolName: _this.name, + toolType: _this.name, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: measurementData + }; + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_1__["default"].MEASUREMENT_MODIFIED, modifiedEventData); + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_5__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_1__["default"].MEASUREMENT_COMPLETED, modifiedEventData); + }); +}); + +var checkPixelSpacing = function checkPixelSpacing(image) { + var imagePlane = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.metaData.get('imagePlaneModule', image.imageId); + var rowPixelSpacing = image.rowPixelSpacing; + var colPixelSpacing = image.columnPixelSpacing; + + if (imagePlane) { + rowPixelSpacing = imagePlane.rowPixelSpacing || imagePlane.rowImagePixelSpacing; + colPixelSpacing = imagePlane.columnPixelSpacing || imagePlane.colImagePixelSpacing; + } // LT-29 Disable Target Measurements when pixel spacing is not available + + + return !rowPixelSpacing || !colPixelSpacing; +}; + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/createNewMeasurement.js": +/*!********************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/createNewMeasurement.js ***! + \********************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +var getHandle = function getHandle(x, y, index) { + var extraAttributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + return Object.assign({ + x: x, + y: y, + index: index, + drawnIndependently: false, + allowedOutsideImage: false, + highlight: true, + active: false + }, extraAttributes); +}; + +/* harmony default export */ __webpack_exports__["default"] = (function (mouseEventData) { + var _mouseEventData$curre = mouseEventData.currentPoints.image, + x = _mouseEventData$curre.x, + y = _mouseEventData$curre.y; // Create the measurement data for this tool with the end handle activated + + var measurementData = { + toolName: this.name, + toolType: this.name, + // Deprecation notice: toolType will be replaced by toolName + isCreating: true, + visible: true, + active: true, + invalidated: true, + handles: { + start: getHandle(x, y, 0), + end: getHandle(x, y, 1, { + active: true + }), + perpendicularStart: getHandle(x, y, 2, { + locked: true + }), + perpendicularEnd: getHandle(x, y, 3), + textBox: getHandle(x - 50, y - 70, null, { + highlight: false, + hasMoved: true, + active: false, + movesIndependently: false, + drawnIndependently: true, + allowedOutsideImage: true, + hasBoundingBox: true + }) + }, + longestDiameter: 0, + shortestDiameter: 0 + }; + return measurementData; +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/handleSelectedCallback.js": +/*!**********************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/handleSelectedCallback.js ***! + \**********************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony default export */ __webpack_exports__["default"] = (function (evt, toolData, handle) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + + if (interactionType === 'touch') { + this.handleSelectedTouchCallback(evt); + } else { + this.handleSelectedMouseCallback(evt); + } +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/handleSelectedMouseCallback.js": +/*!***************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/handleSelectedMouseCallback.js ***! + \***************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../events.js */ "./events.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../../manipulators/anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _moveHandle_moveHandle_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./moveHandle/moveHandle.js */ "./tools/annotation/bidirectionalTool/moveHandle/moveHandle.js"); +/* harmony import */ var _invertHandles_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./invertHandles.js */ "./tools/annotation/bidirectionalTool/invertHandles.js"); +/* harmony import */ var _store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../../store/setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../../util/getProximityThreshold.js */ "./util/getProximityThreshold.js"); + + +/* jshint -W083 */ + + + + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element; + var data; + var distanceThreshold = Object(_util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_10__["default"])('mouse', this.name); + + var handleDoneMove = function handleDoneMove(handle) { + data.invalidated = true; + + if (Object(_manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_4__["default"])(eventData, data.handles)) { + // Delete the measurement + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["removeToolState"])(element, _this.name, data); + } // Update the handles to keep selected state + + + if (handle) { + handle.moving = false; + handle.selected = true; + } + + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__["setToolCursor"])(_this.element, _this.svgCursor); + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_MOVE, _this._moveCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_START, _this._moveCallback); + }; + + var coords = eventData.startPoints.canvas; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } // Now check to see if there is a handle we can move + + + var _loop = function _loop(i) { + data = toolData.data[i]; + var handleParams = [element, data.handles, coords, distanceThreshold]; + var handle = _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_5__["default"].apply(void 0, handleParams); + + if (handle) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_MOVE, _this._moveCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_START, _this._moveCallback); + data.active = true; + unselectAllHandles(data.handles); + handle.moving = true; // Invert handles if needed + + handle = Object(_invertHandles_js__WEBPACK_IMPORTED_MODULE_8__["default"])(eventData, data, handle); + /* Hide the cursor to improve precision while resizing the line or set to move + if dragging text box + */ + + if (!handle.hasBoundingBox) { + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_9__["hideToolCursor"])(_this.element); + } + + Object(_moveHandle_moveHandle_js__WEBPACK_IMPORTED_MODULE_7__["default"])(eventData, _this.name, data, handle, function () { + return handleDoneMove(handle); + }); + preventPropagation(evt); + return { + v: true + }; + } + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(_ret) === "object") return _ret.v; + } + + var getDoneMovingCallback = function getDoneMovingCallback(handles) { + return function () { + setHandlesMovingState(handles, false); + handleDoneMove(); + }; + }; + + for (var i = 0; i < toolData.data.length; i++) { + data = toolData.data[i]; + + if (this.pointNearTool(element, data, coords, 'mouse')) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_MOVE, this._moveCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_START, this._moveCallback); + data.active = true; + unselectAllHandles(data.handles); + setHandlesMovingState(data.handles, true); + var doneMovingCallback = getDoneMovingCallback(data.handles); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_6__["moveAllHandles"])(eventData, this.name, data, null, { + deleteIfHandleOutsideImage: true, + preventHandleOutsideImage: false + }, 'mouse', doneMovingCallback); + preventPropagation(evt); + return true; + } + } +}); // Clear the selected state for the given handles object + +var unselectAllHandles = function unselectAllHandles(handles) { + var imageNeedsUpdate = false; + Object.keys(handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + handles[handleKey].selected = false; + imageNeedsUpdate = handles[handleKey].active || imageNeedsUpdate; + handles[handleKey].active = false; + }); + return imageNeedsUpdate; +}; + +var setHandlesMovingState = function setHandlesMovingState(handles, state) { + Object.keys(handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + handles[handleKey].moving = state; + }); +}; + +var preventPropagation = function preventPropagation(evt) { + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); +}; + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/handleSelectedTouchCallback.js": +/*!***************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/handleSelectedTouchCallback.js ***! + \***************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../store/index.js */ "./store/index.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../../events.js */ "./events.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../../manipulators/anyHandlesOutsideImage.js */ "./manipulators/anyHandlesOutsideImage.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _moveHandle_touchMoveHandle_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./moveHandle/touchMoveHandle.js */ "./tools/annotation/bidirectionalTool/moveHandle/touchMoveHandle.js"); + + +/* jshint -W083 */ + + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element; + var data; + var distanceThreshold = _store_index_js__WEBPACK_IMPORTED_MODULE_2__["state"].touchProximity; + + var handleDoneMove = function handleDoneMove(handle) { + data.invalidated = true; + + if (Object(_manipulators_anyHandlesOutsideImage_js__WEBPACK_IMPORTED_MODULE_5__["default"])(eventData, data.handles)) { + // Delete the measurement + Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["removeToolState"])(element, _this.name, data); + } // Update the handles to keep selected state + + + if (handle) { + handle.moving = false; + handle.selected = true; + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.updateImage(element); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_3__["default"].TOUCH_DRAG, _this._moveCallback); + }; + + var coords = eventData.startPoints.canvas; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_4__["getToolState"])(evt.currentTarget, this.name); + + if (!toolData) { + return; + } // Now check to see if there is a handle we can move + + + var _loop = function _loop(i) { + data = toolData.data[i]; + var handleParams = [element, data.handles, coords, distanceThreshold]; + var handle = _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_6__["default"].apply(void 0, handleParams); + + if (handle) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_3__["default"].TOUCH_DRAG, _this._moveCallback); + data.active = true; + unselectAllHandles(data.handles); + handle.moving = true; + Object(_moveHandle_touchMoveHandle_js__WEBPACK_IMPORTED_MODULE_8__["default"])(eventData, _this.name, data, handle, function () { + return handleDoneMove(handle); + }); + preventPropagation(evt); + return { + v: true + }; + } + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(_ret) === "object") return _ret.v; + } + + var getDoneMovingCallback = function getDoneMovingCallback(handles) { + return function () { + setHandlesMovingState(handles, false); + handleDoneMove(); + }; + }; + + for (var i = 0; i < toolData.data.length; i++) { + data = toolData.data[i]; + + if (this.pointNearTool(element, data, coords, 'touch')) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_3__["default"].TOUCH_DRAG, this._moveCallback); + data.active = true; + unselectAllHandles(data.handles); + setHandlesMovingState(data.handles, true); + var doneMovingCallback = getDoneMovingCallback(data.handles); + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_7__["moveAllHandles"])(eventData, this.name, data, null, { + deleteIfHandleOutsideImage: true, + preventHandleOutsideImage: false + }, 'touch', doneMovingCallback); + preventPropagation(evt); + return true; + } + } +}); // Clear the selected state for the given handles object + +var unselectAllHandles = function unselectAllHandles(handles) { + var imageNeedsUpdate = false; + Object.keys(handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + handles[handleKey].selected = false; + imageNeedsUpdate = handles[handleKey].active || imageNeedsUpdate; + handles[handleKey].active = false; + }); + return imageNeedsUpdate; +}; + +var setHandlesMovingState = function setHandlesMovingState(handles, state) { + Object.keys(handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + handles[handleKey].moving = state; + }); +}; + +var preventPropagation = function preventPropagation(evt) { + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); +}; + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/invertHandles.js": +/*!*************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/invertHandles.js ***! + \*************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return invertHandles; }); +var swapAttribute = function swapAttribute(a, b, attribute) { + var originalA = a[attribute]; + var originalB = b[attribute]; + a[attribute] = originalB; + b[attribute] = originalA; +}; + +var swapHandles = function swapHandles(a, b) { + swapAttribute(a, b, 'x'); + swapAttribute(a, b, 'y'); + swapAttribute(a, b, 'moving'); + swapAttribute(a, b, 'hover'); + swapAttribute(a, b, 'active'); + swapAttribute(a, b, 'selected'); +}; + +function invertHandles(eventData, measurementData, handle) { + var _eventData$image = eventData.image, + rowPixelSpacing = _eventData$image.rowPixelSpacing, + columnPixelSpacing = _eventData$image.columnPixelSpacing; + var handles = measurementData.handles; + var start = handles.start, + end = handles.end, + perpendicularStart = handles.perpendicularStart, + perpendicularEnd = handles.perpendicularEnd; // Calculate the long axis length + + var dx = (start.x - end.x) * (columnPixelSpacing || 1); + var dy = (start.y - end.y) * (rowPixelSpacing || 1); + var length = Math.sqrt(dx * dx + dy * dy); // Calculate the short axis length + + var wx = (perpendicularStart.x - perpendicularEnd.x) * (columnPixelSpacing || 1); + var wy = (perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1); + var width = Math.sqrt(wx * wx + wy * wy) || 0; + + if (width > length) { + swapHandles(start, end); + swapHandles(start, perpendicularStart); + swapHandles(end, perpendicularEnd); + return Object.values(handles).find(function (h) { + return h.moving === true; + }); + } + + return handle; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/mouseMoveCallback.js": +/*!*****************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/mouseMoveCallback.js ***! + \*****************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolCoordinates_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../stateManagement/toolCoordinates.js */ "./stateManagement/toolCoordinates.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); + + + + // Replaces the cornerstoneTools.handleActivator function by skiping the active handle comparison + +var handleActivator = function handleActivator(element, handles, canvasPoint) { + var distanceThreshold = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 6; + var nearbyHandle = Object(_manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, handles, canvasPoint, distanceThreshold); + var handleActivatorChanged = false; + Object.keys(handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + var handle = handles[handleKey]; + var newActiveState = handle === nearbyHandle; + + if (handle.active !== newActiveState) { + handleActivatorChanged = true; + } + + handle.active = newActiveState; + }); + return handleActivatorChanged; +}; // MouseMoveCallback is used to hide handles when mouse is away + + +/* harmony default export */ __webpack_exports__["default"] = (function (event) { + var _this = this; + + var eventData = event.detail; + var element = eventData.element; + _stateManagement_toolCoordinates_js__WEBPACK_IMPORTED_MODULE_1__["default"].setCoords(eventData); // If we have no tool data for this element, do nothing + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_3__["getToolState"])(element, this.name); + + if (!toolData) { + return; + } // We have tool data, search through all data and see if we can activate a handle + + + var imageNeedsUpdate = false; + + var _loop = function _loop(i) { + // Get the cursor position in canvas coordinates + var coords = eventData.currentPoints.canvas; + var data = toolData.data[i]; + var handleActivatorChanged = handleActivator(element, data.handles, coords); + Object.keys(data.handles).forEach(function (handleKey) { + if (handleKey === 'textBox') { + return; + } + + var handle = data.handles[handleKey]; + handle.hover = handle.active; + }); + + if (handleActivatorChanged) { + imageNeedsUpdate = true; + } + + var nearTool = _this.pointNearTool(element, data, coords, 'mouse'); + + var nearToolAndInactive = nearTool && !data.active; + var notNearToolAndActive = !nearTool && data.active; + + if (nearToolAndInactive || notNearToolAndActive) { + data.active = !data.active; + imageNeedsUpdate = true; + } + }; + + for (var i = 0; i < toolData.data.length; i++) { + _loop(i); + } // Handle activation status changed, redraw the image + + + if (imageNeedsUpdate === true) { + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + } +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/getBaseData.js": +/*!**********************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/getBaseData.js ***! + \**********************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getBaseData; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _utils_getDistanceWithPixelSpacing_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/getDistanceWithPixelSpacing.js */ "./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js"); + + + +function createLine(startPoint, endPoint) { + return { + start: startPoint, + end: endPoint + }; +} +/** + * Extract and group the base data to be used on bidirectional tool lines + * moving. + * + * @param {*} measurementData Data from current bidirectional tool measurement + * @param {*} eventData Data object associated with the event + * @param {*} fixedPoint Point that is not being moved in line + * + * @returns {*} Grouped that needed for lines moving + */ + + +function getBaseData(measurementData, eventData, fixedPoint) { + var lineSegment = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment; + var _measurementData$hand = measurementData.handles, + start = _measurementData$hand.start, + end = _measurementData$hand.end, + perpendicularStart = _measurementData$hand.perpendicularStart, + perpendicularEnd = _measurementData$hand.perpendicularEnd; + var _eventData$image = eventData.image, + _eventData$image$colu = _eventData$image.columnPixelSpacing, + columnPixelSpacing = _eventData$image$colu === void 0 ? 1 : _eventData$image$colu, + _eventData$image$rowP = _eventData$image.rowPixelSpacing, + rowPixelSpacing = _eventData$image$rowP === void 0 ? 1 : _eventData$image$rowP; + var longLine = createLine(start, end); + var perpendicularLine = createLine(perpendicularStart, perpendicularEnd); + var intersection = lineSegment.intersectLine(longLine, perpendicularLine); + var distanceToFixed = Object(_utils_getDistanceWithPixelSpacing_js__WEBPACK_IMPORTED_MODULE_1__["default"])(columnPixelSpacing, rowPixelSpacing, fixedPoint, intersection); + return { + columnPixelSpacing: columnPixelSpacing, + // Width that a pixel represents in mm + rowPixelSpacing: rowPixelSpacing, + // Height that a pixel represents in mm + start: start, + // Start point of the long line + end: end, + // End point of the long line + perpendicularStart: perpendicularStart, + // Start point of the perpendicular line + perpendicularEnd: perpendicularEnd, + // End point of the perpendicular line + longLine: longLine, + // Long line object containing the start and end points + intersection: intersection, + // Intersection point between long and perpendicular lines + distanceToFixed: distanceToFixed, + // Distance from intersection to the fixed point + fixedPoint: fixedPoint // Opposite point from the handle that is being moved + + }; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/moveHandle.js": +/*!*********************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/moveHandle.js ***! + \*********************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../store/index.js */ "./store/index.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../../events.js */ "./events.js"); +/* harmony import */ var _setHandlesPosition_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./setHandlesPosition.js */ "./tools/annotation/bidirectionalTool/moveHandle/setHandlesPosition.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../base/BaseAnnotationTool */ "./tools/base/BaseAnnotationTool.js"); + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (mouseEventData, toolName, data, handle, doneMovingCallback, preventHandleOutsideImage) { + var element = mouseEventData.element, + image = mouseEventData.image, + buttons = mouseEventData.buttons; + var distanceFromTool = { + x: handle.x - mouseEventData.currentPoints.image.x, + y: handle.y - mouseEventData.currentPoints.image.y + }; + + var _dragCallback = function _dragCallback(event) { + var eventData = event.detail; + handle.hasMoved = true; + + if (handle.index === undefined || handle.index === null) { + handle.x = eventData.currentPoints.image.x + distanceFromTool.x; + handle.y = eventData.currentPoints.image.y + distanceFromTool.y; + } else { + Object(_setHandlesPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(handle, eventData, data, distanceFromTool); + } + + if (preventHandleOutsideImage) { + handle.x = Math.max(handle.x, 0); + handle.x = Math.min(handle.x, eventData.image.width); + handle.y = Math.max(handle.y, 0); + handle.y = Math.min(handle.y, eventData.image.height); + } + + data.invalidated = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_4__["default"])(element, buttons, 'mouse'); + + if (activeTool instanceof _base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_5__["default"]) { + activeTool.updateCachedStats(image, element, data); + } + + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: data + }; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.triggerEvent(element, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MEASUREMENT_MODIFIED, modifiedEventData); + }; + + handle.active = true; + handle.moving = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = true; + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_DRAG, _dragCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG, _dragCallback); + var currentImage = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getImage(element); + + var imageRenderedHandler = function imageRenderedHandler() { + var newImage = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getImage(element); // Check if the rendered image changed during measurement modifying and stop it if so + + if (newImage.imageId !== currentImage.imageId) { + interactionEndCallback(); + } + }; // Bind the event listener for image rendering + + + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.IMAGE_RENDERED, imageRenderedHandler); + + var interactionEndCallback = function interactionEndCallback() { + handle.active = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = false; + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.EVENTS.IMAGE_RENDERED, imageRenderedHandler); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_DRAG, _dragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_UP, interactionEndCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_CLICK, interactionEndCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG, _dragCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG_END, interactionEndCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TAP, interactionEndCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + + if (typeof doneMovingCallback === 'function') { + doneMovingCallback(); + } + }; + + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_UP, interactionEndCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MOUSE_CLICK, interactionEndCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG_END, interactionEndCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TAP, interactionEndCallback); +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/moveLongLine.js": +/*!************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/moveLongLine.js ***! + \************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return moveLongLine; }); +/* harmony import */ var _utils_getDistanceWithPixelSpacing_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/getDistanceWithPixelSpacing.js */ "./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js"); +/* harmony import */ var _getBaseData_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../getBaseData.js */ "./tools/annotation/bidirectionalTool/moveHandle/getBaseData.js"); +/* harmony import */ var _updatePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./updatePerpendicularLine.js */ "./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/updatePerpendicularLine.js"); + + + +/** + * Move the long line updating the perpendicular line handles position. + * + * @param {*} proposedPoint Point that was moved in bidirectional tool + * @param {*} measurementData Data from current bidirectional tool measurement + * @param {*} eventData Data object associated with the event + * @param {*} fixedPoint Point that is not being moved in long line + * + * @returns {boolean} True if perpendicular handles were updated, false if not + */ + +function moveLongLine(proposedPoint, measurementData, eventData, fixedPoint) { + var baseData = Object(_getBaseData_js__WEBPACK_IMPORTED_MODULE_1__["default"])(measurementData, eventData, fixedPoint); + var columnPixelSpacing = baseData.columnPixelSpacing, + rowPixelSpacing = baseData.rowPixelSpacing, + distanceToFixed = baseData.distanceToFixed; // Calculate the length of the new line, considering the proposed point + + var newLineLength = Object(_utils_getDistanceWithPixelSpacing_js__WEBPACK_IMPORTED_MODULE_0__["default"])(columnPixelSpacing, rowPixelSpacing, fixedPoint, proposedPoint); // Stop here if the handle tries to move before the intersection point + + if (newLineLength <= distanceToFixed) { + return false; + } // Calculate the new intersection point + + + var distanceRatio = distanceToFixed / newLineLength; + var newIntersection = { + x: fixedPoint.x + (proposedPoint.x - fixedPoint.x) * distanceRatio, + y: fixedPoint.y + (proposedPoint.y - fixedPoint.y) * distanceRatio + }; // Calculate and the new position of the perpendicular handles + + var newLine = Object(_updatePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_2__["default"])(baseData, newIntersection); // Update the perpendicular line handles + + measurementData.handles.perpendicularStart.x = newLine.start.x; + measurementData.handles.perpendicularStart.y = newLine.start.y; + measurementData.handles.perpendicularEnd.x = newLine.end.x; + measurementData.handles.perpendicularEnd.y = newLine.end.y; + return true; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/updatePerpendicularLine.js": +/*!***********************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/updatePerpendicularLine.js ***! + \***********************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return updatePerpendicularLine; }); +/* harmony import */ var _utils_getLineVector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/getLineVector */ "./tools/annotation/bidirectionalTool/utils/getLineVector.js"); +/* harmony import */ var _utils_getDistanceWithPixelSpacing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/getDistanceWithPixelSpacing */ "./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js"); + + +/** + * Returns the updated line object that will be used to change the position of + * the perpendicular line handles. + * + * @param {*} baseData Base data for bidirectional line moving + * @param {*} mid Middle point considering the proposed point + * + * @returns {*} Returns a line object with the updated handles position + */ + +function updatePerpendicularLine(baseData, mid) { + var columnPixelSpacing = baseData.columnPixelSpacing, + rowPixelSpacing = baseData.rowPixelSpacing, + start = baseData.start, + perpendicularStart = baseData.perpendicularStart, + perpendicularEnd = baseData.perpendicularEnd, + intersection = baseData.intersection, + fixedPoint = baseData.fixedPoint; // Get the original distance from perpendicular start handle to intersection + + var distancePS = Object(_utils_getDistanceWithPixelSpacing__WEBPACK_IMPORTED_MODULE_1__["default"])(columnPixelSpacing, rowPixelSpacing, perpendicularStart, intersection); // Get the original distance from perpendicular end handle to intersection + + var distancePE = Object(_utils_getDistanceWithPixelSpacing__WEBPACK_IMPORTED_MODULE_1__["default"])(columnPixelSpacing, rowPixelSpacing, perpendicularEnd, intersection); // Inclination of the perpendicular line + + var vector = Object(_utils_getLineVector__WEBPACK_IMPORTED_MODULE_0__["default"])(columnPixelSpacing, rowPixelSpacing, fixedPoint, mid); // Define the multiplier + + var multiplier = fixedPoint === start ? 1 : -1; + var rowMultiplier = multiplier * rowPixelSpacing; + var columnMultiplier = multiplier * columnPixelSpacing; // Calculate and return the new position of the perpendicular handles + + return { + start: { + x: mid.x + vector.y * distancePS * rowMultiplier, + y: mid.y + vector.x * distancePS * columnMultiplier * -1 + }, + end: { + x: mid.x + vector.y * distancePE * rowMultiplier * -1, + y: mid.y + vector.x * distancePE * columnMultiplier + } + }; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getDirectionMultiplier.js": +/*!*******************************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getDirectionMultiplier.js ***! + \*******************************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getDirectionMultiplier; }); +/* harmony import */ var _isPerpendicularEndFixed_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./isPerpendicularEndFixed.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/isPerpendicularEndFixed.js"); + +/** + * Return the direction multiplier based on the perpendicular fixed point and + * the end point. + * + * @param {*} fixedPoint Point that is not being moved in perpendicular line + * @param {*} perpendicularEnd The end point of the perpencular line + * + * @returns {number} Returns -1 if end point is not being moved or 1 if it is + */ + +function getDirectionMultiplier(fixedPoint, perpendicularEnd) { + return Object(_isPerpendicularEndFixed_js__WEBPACK_IMPORTED_MODULE_0__["default"])(fixedPoint, perpendicularEnd) ? -1 : 1; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getHelperLine.js": +/*!**********************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getHelperLine.js ***! + \**********************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getHelperLine; }); +/* harmony import */ var _getDirectionMultiplier__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getDirectionMultiplier */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getDirectionMultiplier.js"); + +/** + * Creates a helper line with the same inclination as the perpendicular line + * but having the start point as the proposed point. + * This line will start in the proposed point and will grow in the long line + * direction trying to cross it to enable finding the intersection point + * between the long line and this new perpendicular line. + * + * @param {*} baseData Base data for bidirectional line moving + * @param {*} proposedPoint Point that was moved in bidirectional tool + * @param {*} vector Vector with the perpendicular line inclination + * + * @returns {*} Returns the helper line containing the start and end points + */ + +function getHelperLine(baseData, proposedPoint, vector) { + var columnPixelSpacing = baseData.columnPixelSpacing, + rowPixelSpacing = baseData.rowPixelSpacing, + perpendicularEnd = baseData.perpendicularEnd, + fixedPoint = baseData.fixedPoint; // Create a helper line to find the intesection point in the long line + + var highNumber = Number.MAX_SAFE_INTEGER; // Get the multiplier + + var multiplier = Object(_getDirectionMultiplier__WEBPACK_IMPORTED_MODULE_0__["default"])(fixedPoint, perpendicularEnd) * highNumber; + return { + start: proposedPoint, + end: { + x: proposedPoint.x + vector.y * rowPixelSpacing * multiplier, + y: proposedPoint.y + vector.x * columnPixelSpacing * multiplier * -1 + } + }; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getMovingPoint.js": +/*!***********************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getMovingPoint.js ***! + \***********************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getMovingPoint; }); +/* harmony import */ var _isPerpendicularEndFixed_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./isPerpendicularEndFixed.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/isPerpendicularEndFixed.js"); + +/** + * Utility function to return the point that is the opposite of the fixed + * point (the point not being moved in the bidirectional tool's perpendicular + * line). + * + * @param {*} fixedPoint Point that is not being moved in perpendicular line + * @param {*} perpendicularStart The start point of the perpencular line + * @param {*} perpendicularEnd The end point of the perpencular line + * + * @returns {*} Point that is being moved in perpendicular line + */ + +function getMovingPoint(fixedPoint, perpendicularStart, perpendicularEnd) { + if (Object(_isPerpendicularEndFixed_js__WEBPACK_IMPORTED_MODULE_0__["default"])(fixedPoint, perpendicularEnd)) { + return perpendicularStart; + } + + return perpendicularEnd; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/isPerpendicularEndFixed.js": +/*!********************************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/isPerpendicularEndFixed.js ***! + \********************************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return isPerpendicularEndFixed; }); +/** + * Returns true if the end point is the point that is not being moved in the + * perpendicular line. + * + * @param {*} fixedPoint Point that is not being moved in perpendicular line + * @param {*} perpendicularEnd The end point of the perpencular line + * + * @returns {boolean} Returns true if the fixed point is the end point + */ +function isPerpendicularEndFixed(fixedPoint, perpendicularEnd) { + return fixedPoint === perpendicularEnd; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/lineHasLength.js": +/*!**********************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/lineHasLength.js ***! + \**********************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return lineHasLength; }); +/* harmony import */ var _utils_getDistanceWithPixelSpacing__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/getDistanceWithPixelSpacing */ "./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js"); + +/** + * Returns true if the given line object has its length different from zero, + * considering the column and row pixel spacings. + * + * @param {number} columnPixelSpacing Width that a pixel represents in mm + * @param {number} rowPixelSpacing Height that a pixel represents in mm + * @param {*} line Line object that will have its length calculated + * + * @returns {boolean} Returns true if line has any length + */ + +function lineHasLength(columnPixelSpacing, rowPixelSpacing, line) { + var lineLength = Object(_utils_getDistanceWithPixelSpacing__WEBPACK_IMPORTED_MODULE_0__["default"])(columnPixelSpacing, rowPixelSpacing, line.start, line.end); + return lineLength !== 0; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/movePerpendicularLine.js": +/*!******************************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/movePerpendicularLine.js ***! + \******************************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return movePerpendicularLine; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _utils_getLineVector_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/getLineVector.js */ "./tools/annotation/bidirectionalTool/utils/getLineVector.js"); +/* harmony import */ var _getBaseData_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../getBaseData.js */ "./tools/annotation/bidirectionalTool/moveHandle/getBaseData.js"); +/* harmony import */ var _lineHasLength_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./lineHasLength.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/lineHasLength.js"); +/* harmony import */ var _getHelperLine_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./getHelperLine.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getHelperLine.js"); +/* harmony import */ var _updatePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./updatePerpendicularLine.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/updatePerpendicularLine.js"); + + + + + + +/** + * Move the perpendicular line updating the opposite handle position. + * + * @param {*} proposedPoint Point that was moved in bidirectional tool + * @param {*} measurementData Data from current bidirectional tool measurement + * @param {*} eventData Data object associated with the event + * @param {*} fixedPoint Point that is not being moved in long line + * + * @returns {boolean} True if perpendicular handles were updated, false if not + */ + +function movePerpendicularLine(proposedPoint, measurementData, eventData, fixedPoint) { + var lineSegment = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment; + var baseData = Object(_getBaseData_js__WEBPACK_IMPORTED_MODULE_2__["default"])(measurementData, eventData, fixedPoint); + var columnPixelSpacing = baseData.columnPixelSpacing, + rowPixelSpacing = baseData.rowPixelSpacing, + start = baseData.start, + longLine = baseData.longLine, + intersection = baseData.intersection; // Stop here if the long line has no length + + if (!Object(_lineHasLength_js__WEBPACK_IMPORTED_MODULE_3__["default"])(columnPixelSpacing, rowPixelSpacing, longLine)) { + return false; + } // Inclination of the perpendicular line + + + var vector = Object(_utils_getLineVector_js__WEBPACK_IMPORTED_MODULE_1__["default"])(columnPixelSpacing, rowPixelSpacing, start, intersection); // Get a helper line to calculate the intersection + + var helperLine = Object(_getHelperLine_js__WEBPACK_IMPORTED_MODULE_4__["default"])(baseData, proposedPoint, vector); // Find the new intersection in the long line + + var newIntersection = lineSegment.intersectLine(longLine, helperLine); // Stop the flow here if there's no intersection point between lines + + if (!newIntersection) { + return false; + } // Calculate and the new position of the perpendicular handles + + + var newLine = Object(_updatePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_5__["default"])(baseData, newIntersection, helperLine, vector); // Change the position of the perpendicular line handles + + measurementData.handles.perpendicularStart.x = newLine.start.x; + measurementData.handles.perpendicularStart.y = newLine.start.y; + measurementData.handles.perpendicularEnd.x = newLine.end.x; + measurementData.handles.perpendicularEnd.y = newLine.end.y; + return true; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/updatePerpendicularLine.js": +/*!********************************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/updatePerpendicularLine.js ***! + \********************************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return updatePerpendicularLine; }); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../node_modules/@babel/runtime/helpers/defineProperty.js"); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _getDirectionMultiplier__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getDirectionMultiplier */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getDirectionMultiplier.js"); +/* harmony import */ var _getMovingPoint__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getMovingPoint */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/getMovingPoint.js"); + + + +/** + * Returns the updated line object that will be used to change the position of + * the perpendicular line handles. + * + * @param {*} baseData Base data for bidirectional line moving + * @param {*} mid Middle point considering the proposed point + * @param {*} helperLine Line based on proposed point that crosses long line + * @param {*} vector Vector with the perpendicular line inclination + * + * @returns {*} Returns a line object with the updated handles position + */ + +function updatePerpendicularLine(baseData, mid, helperLine, vector) { + var _ref; + + var columnPixelSpacing = baseData.columnPixelSpacing, + rowPixelSpacing = baseData.rowPixelSpacing, + fixedPoint = baseData.fixedPoint, + perpendicularStart = baseData.perpendicularStart, + perpendicularEnd = baseData.perpendicularEnd, + distanceToFixed = baseData.distanceToFixed; // Get the multiplier + + var multiplier = Object(_getDirectionMultiplier__WEBPACK_IMPORTED_MODULE_1__["default"])(fixedPoint, perpendicularEnd) * distanceToFixed; // Define the moving point + + var movingPoint = Object(_getMovingPoint__WEBPACK_IMPORTED_MODULE_2__["default"])(fixedPoint, perpendicularStart, perpendicularEnd); // Get the object keys for moving and fixed points + + var isMovingStart = movingPoint === perpendicularStart; + var movingKey = isMovingStart ? 'start' : 'end'; + var fixedKey = isMovingStart ? 'end' : 'start'; // Calculate and return the new position of the perpendicular handles + + return _ref = {}, _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(_ref, movingKey, { + x: helperLine.start.x, + y: helperLine.start.y + }), _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(_ref, fixedKey, { + x: mid.x + vector.y * rowPixelSpacing * multiplier, + y: mid.y + vector.x * columnPixelSpacing * multiplier * -1 + }), _ref; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/setHandlesPosition.js": +/*!*****************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/setHandlesPosition.js ***! + \*****************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _moveLongLine_moveLongLine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./moveLongLine/moveLongLine.js */ "./tools/annotation/bidirectionalTool/moveHandle/moveLongLine/moveLongLine.js"); +/* harmony import */ var _movePerpendicularLine_movePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./movePerpendicularLine/movePerpendicularLine.js */ "./tools/annotation/bidirectionalTool/moveHandle/movePerpendicularLine/movePerpendicularLine.js"); + + + // Sets position of handles(start, end, perpendicularStart, perpendicularEnd) + +/* harmony default export */ __webpack_exports__["default"] = (function (handle, eventData, data, distanceFromTool) { + var movedPoint; + var outOfBounds; + var result; + var intersection; + var d1; + var d2; + var longLine = {}; + var perpendicularLine = {}; + var proposedPoint = { + x: eventData.currentPoints.image.x + distanceFromTool.x, + y: eventData.currentPoints.image.y + distanceFromTool.y + }; + + if (handle.index === 0) { + // If long-axis start point is moved + result = Object(_moveLongLine_moveLongLine_js__WEBPACK_IMPORTED_MODULE_1__["default"])(proposedPoint, data, eventData, data.handles.end); + + if (result) { + handle.x = proposedPoint.x; + handle.y = proposedPoint.y; + } else { + eventData.currentPoints.image.x = handle.x; + eventData.currentPoints.image.y = handle.y; + } + } else if (handle.index === 1) { + // If long-axis end point is moved + result = Object(_moveLongLine_moveLongLine_js__WEBPACK_IMPORTED_MODULE_1__["default"])(proposedPoint, data, eventData, data.handles.start); + + if (result) { + handle.x = proposedPoint.x; + handle.y = proposedPoint.y; + } else { + eventData.currentPoints.image.x = handle.x; + eventData.currentPoints.image.y = handle.y; + } + } else if (handle.index === 2) { + outOfBounds = false; // If perpendicular start point is moved + + longLine.start = { + x: data.handles.start.x, + y: data.handles.start.y + }; + longLine.end = { + x: data.handles.end.x, + y: data.handles.end.y + }; + perpendicularLine.start = { + x: data.handles.perpendicularEnd.x, + y: data.handles.perpendicularEnd.y + }; + perpendicularLine.end = { + x: proposedPoint.x, + y: proposedPoint.y + }; + intersection = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); + + if (!intersection) { + perpendicularLine.end = { + x: data.handles.perpendicularStart.x, + y: data.handles.perpendicularStart.y + }; + intersection = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); + d1 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance(intersection, data.handles.start); + d2 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance(intersection, data.handles.end); + + if (!intersection || d1 < 3 || d2 < 3) { + outOfBounds = true; + } + } + + movedPoint = false; + + if (!outOfBounds) { + movedPoint = Object(_movePerpendicularLine_movePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_2__["default"])(proposedPoint, data, eventData, data.handles.perpendicularEnd); + + if (!movedPoint) { + eventData.currentPoints.image.x = data.handles.perpendicularStart.x; + eventData.currentPoints.image.y = data.handles.perpendicularStart.y; + } + } + } else if (handle.index === 3) { + outOfBounds = false; // If perpendicular end point is moved + + longLine.start = { + x: data.handles.start.x, + y: data.handles.start.y + }; + longLine.end = { + x: data.handles.end.x, + y: data.handles.end.y + }; + perpendicularLine.start = { + x: data.handles.perpendicularStart.x, + y: data.handles.perpendicularStart.y + }; + perpendicularLine.end = { + x: proposedPoint.x, + y: proposedPoint.y + }; + intersection = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); + + if (!intersection) { + perpendicularLine.end = { + x: data.handles.perpendicularEnd.x, + y: data.handles.perpendicularEnd.y + }; + intersection = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); + d1 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance(intersection, data.handles.start); + d2 = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance(intersection, data.handles.end); + + if (!intersection || d1 < 3 || d2 < 3) { + outOfBounds = true; + } + } + + movedPoint = false; + + if (!outOfBounds) { + movedPoint = Object(_movePerpendicularLine_movePerpendicularLine_js__WEBPACK_IMPORTED_MODULE_2__["default"])(proposedPoint, data, eventData, data.handles.perpendicularStart); + + if (!movedPoint) { + eventData.currentPoints.image.x = data.handles.perpendicularEnd.x; + eventData.currentPoints.image.y = data.handles.perpendicularEnd.y; + } + } + } +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/moveHandle/touchMoveHandle.js": +/*!**************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/moveHandle/touchMoveHandle.js ***! + \**************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../store/index.js */ "./store/index.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../../events.js */ "./events.js"); +/* harmony import */ var _setHandlesPosition_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./setHandlesPosition.js */ "./tools/annotation/bidirectionalTool/moveHandle/setHandlesPosition.js"); +/* harmony import */ var _util_getActiveTool__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../../util/getActiveTool */ "./util/getActiveTool.js"); +/* harmony import */ var _base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../base/BaseAnnotationTool */ "./tools/base/BaseAnnotationTool.js"); + + + + + + +var touchEndEvents = [_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_END, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG_END, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_PINCH, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_PRESS, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TAP]; +/* harmony default export */ __webpack_exports__["default"] = (function (mouseEventData, toolName, data, handle, doneMovingCallback, preventHandleOutsideImage) { + var element = mouseEventData.element, + image = mouseEventData.image, + buttons = mouseEventData.buttons; + var distanceFromTool = { + x: handle.x - mouseEventData.currentPoints.image.x, + y: handle.y - mouseEventData.currentPoints.image.y + }; + + var touchDragCallback = function touchDragCallback(event) { + var eventData = event.detail; + handle.hasMoved = true; + + if (handle.index === undefined || handle.index === null) { + handle.x = eventData.currentPoints.image.x + distanceFromTool.x; + handle.y = eventData.currentPoints.image.y + distanceFromTool.y; + } else { + Object(_setHandlesPosition_js__WEBPACK_IMPORTED_MODULE_3__["default"])(handle, eventData, data, distanceFromTool); + } + + if (preventHandleOutsideImage) { + handle.x = Math.max(handle.x, 0); + handle.x = Math.min(handle.x, eventData.image.width); + handle.y = Math.max(handle.y, 0); + handle.y = Math.min(handle.y, eventData.image.height); + } + + data.invalidated = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + var activeTool = Object(_util_getActiveTool__WEBPACK_IMPORTED_MODULE_4__["default"])(element, buttons, 'touch'); + + if (activeTool instanceof _base_BaseAnnotationTool__WEBPACK_IMPORTED_MODULE_5__["default"]) { + activeTool.updateCachedStats(image, element, data); + } + + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: data + }; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.triggerEvent(element, _events_js__WEBPACK_IMPORTED_MODULE_2__["default"].MEASUREMENT_MODIFIED, modifiedEventData); + }; + + handle.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = true; + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG, touchDragCallback); + + var touchEndCallback = function touchEndCallback() { + handle.active = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = false; + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_2__["default"].TOUCH_DRAG, touchDragCallback); + touchEndEvents.forEach(function (eventType) { + element.removeEventListener(eventType, touchEndCallback); + }); + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.updateImage(element); + + if (typeof doneMovingCallback === 'function') { + doneMovingCallback(); + } + }; + + touchEndEvents.forEach(function (eventType) { + element.addEventListener(eventType, touchEndCallback); + }); +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/pointNearTool.js": +/*!*************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/pointNearTool.js ***! + \*************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../util/getProximityThreshold.js */ "./util/getProximityThreshold.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../../util/pointInsideBoundingBox.js */ "./util/pointInsideBoundingBox.js"); + + + + +var pointNearPerpendicular = function pointNearPerpendicular(element, handles, coords, distanceThreshold) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone; + var cornerstoneMath = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath; + var lineSegment = { + start: cornerstone.pixelToCanvas(element, handles.perpendicularStart), + end: cornerstone.pixelToCanvas(element, handles.perpendicularEnd) + }; + var distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords); + return distanceToPoint < distanceThreshold; +}; + +/* harmony default export */ __webpack_exports__["default"] = (function (element, data, coords) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone; + var cornerstoneMath = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstoneMath; + var handles = data.handles; + var lineSegment = { + start: cornerstone.pixelToCanvas(element, handles.start), + end: cornerstone.pixelToCanvas(element, handles.end) + }; + var distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords); + + if (Object(_util_pointInsideBoundingBox_js__WEBPACK_IMPORTED_MODULE_2__["default"])(handles.textBox, coords)) { + return true; + } + + var distanceThreshold = Object(_util_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_0__["default"])(interactionType, 'Bidirectional'); + + if (pointNearPerpendicular(element, handles, coords, distanceThreshold)) { + return true; + } + + return distanceToPoint < distanceThreshold; +}); + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/renderToolData.js": +/*!**************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/renderToolData.js ***! + \**************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../../drawing/drawHandles.js */ "./drawing/drawHandles.js"); +/* harmony import */ var _utils_updatePerpendicularLineHandles_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/updatePerpendicularLineHandles.js */ "./tools/annotation/bidirectionalTool/utils/updatePerpendicularLineHandles.js"); +/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../store/index */ "./store/index.js"); +/* harmony import */ var _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../../stateManagement/toolStyle.js */ "./stateManagement/toolStyle.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../../drawing/index.js */ "./drawing/index.js"); +/* harmony import */ var _drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../../drawing/drawLinkedTextBox.js */ "./drawing/drawLinkedTextBox.js"); +/* harmony import */ var _util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../../util/getPixelSpacing */ "./util/getPixelSpacing.js"); + + +/* eslint no-loop-func: 0 */ +// --> OFF + + + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = (function (evt) { + var _this = this; + + var eventData = evt.detail; + var element = eventData.element, + canvasContext = eventData.canvasContext, + image = eventData.image; + var _this$configuration = this.configuration, + handleRadius = _this$configuration.handleRadius, + drawHandlesOnHover = _this$configuration.drawHandlesOnHover, + hideHandlesIfMoving = _this$configuration.hideHandlesIfMoving, + renderDashed = _this$configuration.renderDashed; + var lineDash = Object(_store_index__WEBPACK_IMPORTED_MODULE_3__["getModule"])('globalConfiguration').configuration.lineDash; // If we have no toolData for this element, return immediately as there is nothing to do + + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__["getToolState"])(element, this.name); + + if (!toolData) { + return; + } + + var _getPixelSpacing = Object(_util_getPixelSpacing__WEBPACK_IMPORTED_MODULE_9__["default"])(image), + rowPixelSpacing = _getPixelSpacing.rowPixelSpacing, + colPixelSpacing = _getPixelSpacing.colPixelSpacing; // LT-29 Disable Target Measurements when pixel spacing is not available + + + if (!rowPixelSpacing || !colPixelSpacing) { + return; + } // We have tool data for this element - iterate over each one and draw it + + + var context = Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["getNewContext"])(canvasContext.canvas); + var color; + var lineWidth = _stateManagement_toolStyle_js__WEBPACK_IMPORTED_MODULE_4__["default"].getToolWidth(); + + var _loop = function _loop(i) { + var data = toolData.data[i]; + + if (data.visible === false) { + return "continue"; + } + + color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_5__["default"].getColorIfActive(data); // Calculate the data measurements + + if (data.invalidated === true) { + if (data.longestDiameter && data.shortestDiameter) { + _this.throttledUpdateCachedStats(image, element, data); + } else { + _this.updateCachedStats(image, element, data); + } + } + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["draw"])(context, function (context) { + // Configurable shadow + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["setShadow"])(context, _this.configuration); + var _data$handles = data.handles, + start = _data$handles.start, + end = _data$handles.end, + perpendicularStart = _data$handles.perpendicularStart, + perpendicularEnd = _data$handles.perpendicularEnd, + textBox = _data$handles.textBox; + var lineOptions = { + color: color + }; + var perpendicularLineOptions = { + color: color, + strokeWidth: strokeWidth + }; + + if (renderDashed) { + lineOptions.lineDash = lineDash; + perpendicularLineOptions.lineDash = lineDash; + } // Draw the measurement line + + + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, start, end, lineOptions); // Draw perpendicular line + + var strokeWidth = lineWidth; + Object(_utils_updatePerpendicularLineHandles_js__WEBPACK_IMPORTED_MODULE_2__["default"])(eventData, data); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_7__["drawLine"])(context, element, perpendicularStart, perpendicularEnd, perpendicularLineOptions); // Draw the handles + + var handleOptions = { + color: color, + handleRadius: handleRadius, + drawHandlesIfActive: drawHandlesOnHover, + hideHandlesIfMoving: hideHandlesIfMoving + }; // Draw the handles + + if (_this.configuration.drawHandles) { + Object(_drawing_drawHandles_js__WEBPACK_IMPORTED_MODULE_1__["default"])(context, eventData, data.handles, handleOptions); + } // Draw the textbox + // Move the textbox slightly to the right and upwards + // So that it sits beside the length tool handle + + + var xOffset = 10; + + var textBoxAnchorPoints = function textBoxAnchorPoints(handles) { + return [handles.start, handles.end, handles.perpendicularStart, handles.perpendicularEnd]; + }; + + var textLines = getTextBoxText(data, rowPixelSpacing, colPixelSpacing); + Object(_drawing_drawLinkedTextBox_js__WEBPACK_IMPORTED_MODULE_8__["default"])(context, element, textBox, textLines, data.handles, textBoxAnchorPoints, color, lineWidth, xOffset, true); + }); + }; + + for (var i = 0; i < toolData.data.length; i++) { + var _ret = _loop(i); + + if (_ret === "continue") continue; + } +}); + +var getTextBoxText = function getTextBoxText(data, rowPixelSpacing, colPixelSpacing) { + var suffix = ' mm'; + + if (!rowPixelSpacing || !colPixelSpacing) { + suffix = ' pixels'; + } + + var lengthText = " L ".concat(data.longestDiameter).concat(suffix); + var widthText = " W ".concat(data.shortestDiameter).concat(suffix); + var labels = data.labels; + + if (labels && Array.isArray(labels)) { + return [].concat(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(labels), [lengthText, widthText]); + } + + return [lengthText, widthText]; +}; + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/utils/calculateLongestAndShortestDiameters.js": +/*!******************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/utils/calculateLongestAndShortestDiameters.js ***! + \******************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return calculateLongestAndShortestDiameters; }); +/** + * Calculates longest and shortest diameters using measurement handles and pixelSpacing + * @param {Object} measurementData + * @param {Object} pixelSpacing pixelSpacing + * + *@returns {Object} longestDiameter and shortestDiameter + */ +function calculateLongestAndShortestDiameters(measurementData, pixelSpacing) { + var rowPixelSpacing = pixelSpacing.rowPixelSpacing, + colPixelSpacing = pixelSpacing.colPixelSpacing; + var _measurementData$hand = measurementData.handles, + start = _measurementData$hand.start, + end = _measurementData$hand.end, + perpendicularStart = _measurementData$hand.perpendicularStart, + perpendicularEnd = _measurementData$hand.perpendicularEnd; // Calculate the long axis length + + var dx = (start.x - end.x) * (colPixelSpacing || 1); + var dy = (start.y - end.y) * (rowPixelSpacing || 1); + var length = Math.sqrt(dx * dx + dy * dy); // Calculate the short axis length + + var wx = (perpendicularStart.x - perpendicularEnd.x) * (colPixelSpacing || 1); + var wy = (perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1); + var width = Math.sqrt(wx * wx + wy * wy); + + if (!width) { + width = 0; + } // Length is always longer than width + + + if (width > length) { + var tempW = width; + var tempL = length; + length = tempW; + width = tempL; + } + + return { + longestDiameter: length.toFixed(1), + shortestDiameter: width.toFixed(1) + }; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js": +/*!*********************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/utils/getDistanceWithPixelSpacing.js ***! + \*********************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getDistanceWithPixelSpacing; }); +/** + * Return the distance between 2 points considering the pixel spacing + * + * @param {number} columnPixelSpacing Width that a pixel represents in mm + * @param {number} rowPixelSpacing Height that a pixel represents in mm + * @param {*} startPoint Start point of the line + * @param {*} endPoint End point of the line + * + * @returns {number} Distance between the 2 given points considering the pixel spacing + */ +function getDistanceWithPixelSpacing(columnPixelSpacing, rowPixelSpacing, startPoint, endPoint) { + var calcX = (startPoint.x - endPoint.x) / rowPixelSpacing; + var calcY = (startPoint.y - endPoint.y) / columnPixelSpacing; + return Math.sqrt(calcX * calcX + calcY * calcY); +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/utils/getLineVector.js": +/*!*******************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/utils/getLineVector.js ***! + \*******************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getLineVector; }); +/** + * Return the Vector of a line which determines its inclination and length + * + * @param {number} columnPixelSpacing Width that a pixel represents in mm + * @param {number} rowPixelSpacing Height that a pixel represents in mm + * @param {*} startPoint Start point of the line + * @param {*} endPoint End point of the line + * + * @returns {*} Resulting line inclination vector + */ +function getLineVector(columnPixelSpacing, rowPixelSpacing, startPoint, endPoint) { + var dx = (startPoint.x - endPoint.x) * columnPixelSpacing; + var dy = (startPoint.y - endPoint.y) * rowPixelSpacing; + var length = Math.sqrt(dx * dx + dy * dy); + var vectorX = dx / length; + var vectorY = dy / length; + return { + x: vectorX, + y: vectorY, + length: length + }; +} + +/***/ }), + +/***/ "./tools/annotation/bidirectionalTool/utils/updatePerpendicularLineHandles.js": +/*!************************************************************************************!*\ + !*** ./tools/annotation/bidirectionalTool/utils/updatePerpendicularLineHandles.js ***! + \************************************************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return updatePerpendicularLineHandles; }); +/* harmony import */ var _getLineVector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./getLineVector */ "./tools/annotation/bidirectionalTool/utils/getLineVector.js"); + +/** + * Update the perpendicular line handles when the measurement is being created. + * This method will make the perpendicular line intersect in the middle of the + * long line and assume half the size of the long line. + * + * @param {*} eventData Data object associated with the event + * @param {*} measurementData Data from current bidirectional tool measurement + * + * @returns {boolean} False in case the handle is not locked or true when moved + */ + +function updatePerpendicularLineHandles(eventData, measurementData) { + if (!measurementData.handles.perpendicularStart.locked) { + return false; + } + + var startX, startY, endX, endY; + var _measurementData$hand = measurementData.handles, + start = _measurementData$hand.start, + end = _measurementData$hand.end; + var _eventData$image = eventData.image, + _eventData$image$colu = _eventData$image.columnPixelSpacing, + columnPixelSpacing = _eventData$image$colu === void 0 ? 1 : _eventData$image$colu, + _eventData$image$rowP = _eventData$image.rowPixelSpacing, + rowPixelSpacing = _eventData$image$rowP === void 0 ? 1 : _eventData$image$rowP; + + if (start.x === end.x && start.y === end.y) { + startX = start.x; + startY = start.y; + endX = end.x; + endY = end.y; + } else { + // Mid point of long-axis line + var mid = { + x: (start.x + end.x) / 2, + y: (start.y + end.y) / 2 + }; // Inclination of the perpendicular line + + var vector = Object(_getLineVector__WEBPACK_IMPORTED_MODULE_0__["default"])(columnPixelSpacing, rowPixelSpacing, start, end); + var perpendicularLineLength = vector.length / 2; + var rowMultiplier = perpendicularLineLength / (2 * rowPixelSpacing); + var columnMultiplier = perpendicularLineLength / (2 * columnPixelSpacing); + startX = mid.x + columnMultiplier * vector.y; + startY = mid.y - rowMultiplier * vector.x; + endX = mid.x - columnMultiplier * vector.y; + endY = mid.y + rowMultiplier * vector.x; + } + + measurementData.handles.perpendicularStart.x = startX; + measurementData.handles.perpendicularStart.y = startY; + measurementData.handles.perpendicularEnd.x = endX; + measurementData.handles.perpendicularEnd.y = endY; + return true; +} + +/***/ }), + +/***/ "./tools/annotation/index.js": +/*!***********************************!*\ + !*** ./tools/annotation/index.js ***! + \***********************************/ +/*! exports provided: AngleTool, ArrowAnnotateTool, BidirectionalTool, CircleRoiTool, CobbAngleTool, EllipticalRoiTool, FreehandRoiTool, LengthTool, ProbeTool, RectangleRoiTool, TextMarkerTool, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _AngleTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./AngleTool.js */ "./tools/annotation/AngleTool.js"); +/* harmony import */ var _ArrowAnnotateTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ArrowAnnotateTool.js */ "./tools/annotation/ArrowAnnotateTool.js"); +/* harmony import */ var _BidirectionalTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BidirectionalTool.js */ "./tools/annotation/BidirectionalTool.js"); +/* harmony import */ var _CircleRoiTool_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./CircleRoiTool.js */ "./tools/annotation/CircleRoiTool.js"); +/* harmony import */ var _CobbAngleTool_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CobbAngleTool.js */ "./tools/annotation/CobbAngleTool.js"); +/* harmony import */ var _EllipticalRoiTool_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./EllipticalRoiTool.js */ "./tools/annotation/EllipticalRoiTool.js"); +/* harmony import */ var _FreehandRoiTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./FreehandRoiTool.js */ "./tools/annotation/FreehandRoiTool.js"); +/* harmony import */ var _LengthTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./LengthTool.js */ "./tools/annotation/LengthTool.js"); +/* harmony import */ var _ProbeTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./ProbeTool.js */ "./tools/annotation/ProbeTool.js"); +/* harmony import */ var _RectangleRoiTool_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./RectangleRoiTool.js */ "./tools/annotation/RectangleRoiTool.js"); +/* harmony import */ var _TextMarkerTool_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./TextMarkerTool.js */ "./tools/annotation/TextMarkerTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AngleTool", function() { return _AngleTool_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrowAnnotateTool", function() { return _ArrowAnnotateTool_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BidirectionalTool", function() { return _BidirectionalTool_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CircleRoiTool", function() { return _CircleRoiTool_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CobbAngleTool", function() { return _CobbAngleTool_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EllipticalRoiTool", function() { return _EllipticalRoiTool_js__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandRoiTool", function() { return _FreehandRoiTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LengthTool", function() { return _LengthTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ProbeTool", function() { return _ProbeTool_js__WEBPACK_IMPORTED_MODULE_8__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RectangleRoiTool", function() { return _RectangleRoiTool_js__WEBPACK_IMPORTED_MODULE_9__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TextMarkerTool", function() { return _TextMarkerTool_js__WEBPACK_IMPORTED_MODULE_10__["default"]; }); + + + + + + + + + + + + // Named Exports + + + + + + + + + + + + // Namespace, default export + +/* harmony default export */ __webpack_exports__["default"] = ({ + AngleTool: _AngleTool_js__WEBPACK_IMPORTED_MODULE_0__["default"], + ArrowAnnotateTool: _ArrowAnnotateTool_js__WEBPACK_IMPORTED_MODULE_1__["default"], + BidirectionalTool: _BidirectionalTool_js__WEBPACK_IMPORTED_MODULE_2__["default"], + CircleRoiTool: _CircleRoiTool_js__WEBPACK_IMPORTED_MODULE_3__["default"], + CobbAngleTool: _CobbAngleTool_js__WEBPACK_IMPORTED_MODULE_4__["default"], + EllipticalRoiTool: _EllipticalRoiTool_js__WEBPACK_IMPORTED_MODULE_5__["default"], + FreehandRoiTool: _FreehandRoiTool_js__WEBPACK_IMPORTED_MODULE_6__["default"], + LengthTool: _LengthTool_js__WEBPACK_IMPORTED_MODULE_7__["default"], + ProbeTool: _ProbeTool_js__WEBPACK_IMPORTED_MODULE_8__["default"], + RectangleRoiTool: _RectangleRoiTool_js__WEBPACK_IMPORTED_MODULE_9__["default"], + TextMarkerTool: _TextMarkerTool_js__WEBPACK_IMPORTED_MODULE_10__["default"] +}); + +/***/ }), + +/***/ "./tools/base/BaseAnnotationTool.js": +/*!******************************************!*\ + !*** ./tools/base/BaseAnnotationTool.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _BaseTool_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _manipulators_handleActivator_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../manipulators/handleActivator.js */ "./manipulators/handleActivator.js"); +/* harmony import */ var _util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../util/findAndMoveHelpers.js */ "./util/findAndMoveHelpers.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../util/logger */ "./util/logger.js"); + + + + + + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_9__["getLogger"])('baseAnnotationTool'); +/** + * @memberof Tools.Base + * @classdesc Abstract class for tools which create and display annotations on the + * cornerstone canvas. + * @extends Tools.Base.BaseTool + */ + +var BaseAnnotationTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_4___default()(BaseAnnotationTool, _BaseTool); + + function BaseAnnotationTool() { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, BaseAnnotationTool); + + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(BaseAnnotationTool).apply(this, arguments)); + } + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(BaseAnnotationTool, [{ + key: "createNewMeasurement", + // =================================================================== + // Abstract Methods - Must be implemented. + // =================================================================== + + /** + * Creates a new annotation. + * + * @method createNewMeasurement + * @memberof Tools.Base.BaseAnnotationTool + * + * @param {type} evt description + * @returns {type} description + */ + // eslint-disable-next-line no-unused-vars + value: function createNewMeasurement(evt) { + throw new Error("Method createNewMeasurement not implemented for ".concat(this.name, ".")); + } + /** + * + * Returns true if the given coords are need the tool. + * + * @method pointNearTool + * @memberof Tools.Base.BaseAnnotationTool + * + * @param {*} element + * @param {*} data + * @param {*} coords + * @param {string} [interactionType=mouse] + * @returns {boolean} If the point is near the tool + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "pointNearTool", + value: function pointNearTool(element, data, coords) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + throw new Error("Method pointNearTool not implemented for ".concat(this.name, ".")); + } + /** + * Returns the distance in px from the given coords to the closest handle of the annotation. + * + * @method distanceFromPoint + * @memberof Tools.Base.BaseAnnotationTool + * + * @param {*} element + * @param {*} data + * @param {*} coords + * @returns {number} - the distance in px from the provided coordinates to the + * closest rendered portion of the annotation. -1 if the distance cannot be + * calculated. + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "distanceFromPoint", + value: function distanceFromPoint(element, data, coords) { + throw new Error("Method distanceFromPoint not implemented for ".concat(this.name, ".")); + } + /** + * Used to redraw the tool's annotation data per render + * + * @abstract + * @param {*} evt + * @returns {void} + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "renderToolData", + value: function renderToolData(evt) { + throw new Error("renderToolData not implemented for ".concat(this.name, ".")); + } // =================================================================== + // Virtual Methods - Have default behavior but may be overriden. + // =================================================================== + + /** + * Event handler for MOUSE_MOVE event. + * + * @abstract + * @event + * @param {Object} evt - The event. + * @returns {boolean} - True if the image needs to be updated + */ + + }, { + key: "mouseMoveCallback", + value: function mouseMoveCallback(evt) { + var _evt$detail = evt.detail, + element = _evt$detail.element, + currentPoints = _evt$detail.currentPoints; + var coords = currentPoints.canvas; + var toolState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_6__["getToolState"])(element, this.name); + var imageNeedsUpdate = false; + + for (var d = 0; d < toolState.data.length; d++) { + var data = toolState.data[d]; // Hovering a handle? + + if (Object(_manipulators_handleActivator_js__WEBPACK_IMPORTED_MODULE_7__["default"])(element, data.handles, coords) === true) { + imageNeedsUpdate = true; + } // Tool data's 'active' does not match coordinates + // TODO: can't we just do an if/else and save on a pointNearTool check? + + + var nearToolAndNotMarkedActive = this.pointNearTool(element, data, coords, 'mouse') && !data.active; + var notNearToolAndMarkedActive = !this.pointNearTool(element, data, coords, 'mouse') && data.active; + + if (nearToolAndNotMarkedActive || notNearToolAndMarkedActive) { + data.active = !data.active; + imageNeedsUpdate = true; + } + } + + return imageNeedsUpdate; + } + /** + * Custom callback for when a handle is selected. + * @method handleSelectedCallback + * @memberof Tools.Base.BaseAnnotationTool + * + * @param {*} evt - + * @param {*} toolData - + * @param {*} handle - The selected handle. + * @param {String} interactionType - + * @returns {void} + */ + + }, { + key: "handleSelectedCallback", + value: function handleSelectedCallback(evt, toolData, handle) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + Object(_util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_8__["moveHandleNearImagePoint"])(evt, this, toolData, handle, interactionType); + } + /** + * Custom callback for when a tool is selected. + * + * @method toolSelectedCallback + * @memberof Tools.Base.BaseAnnotationTool + * + * @param {*} evt + * @param {*} annotation + * @param {string} [interactionType=mouse] + * @returns {void} + */ + + }, { + key: "toolSelectedCallback", + value: function toolSelectedCallback(evt, annotation) { + var interactionType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'mouse'; + Object(_util_findAndMoveHelpers_js__WEBPACK_IMPORTED_MODULE_8__["moveAnnotation"])(evt, this, annotation, interactionType); + } + /** + * Updates cached statistics for the tool's annotation data on the element + * + * @param {*} image + * @param {*} element + * @param {*} data + * @returns {void} + */ + + }, { + key: "updateCachedStats", + value: function updateCachedStats(image, element, data) { + // eslint-disable-line + logger.warn("updateCachedStats not implemented for ".concat(this.name, ".")); + } + }]); + + return BaseAnnotationTool; +}(_BaseTool_js__WEBPACK_IMPORTED_MODULE_5__["default"]); + +/* harmony default export */ __webpack_exports__["default"] = (BaseAnnotationTool); + +/***/ }), + +/***/ "./tools/base/BaseBrushTool.js": +/*!*************************************!*\ + !*** ./tools/base/BaseBrushTool.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _BaseTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _store_isToolActiveForElement_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../store/isToolActiveForElement.js */ "./store/isToolActiveForElement.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../util/segmentation */ "./util/segmentation/index.js"); + + + + + + + + + + + + +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_10__["getModule"])('segmentation'); +/** + * @abstract + * @memberof Tools.Base + * @classdesc Abstract class for tools which manipulate the mask data to be displayed on + * the cornerstone canvas. + * @extends Tools.Base.BaseTool + */ + +var BaseBrushTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(BaseBrushTool, _BaseTool); + + function BaseBrushTool(props) { + var _this; + + var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, BaseBrushTool); + + if (!defaultProps.configuration) { + defaultProps.configuration = { + alwaysEraseOnClick: false + }; + } + + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(BaseBrushTool).call(this, props, defaultProps)); + _this.updateOnMouseMove = true; + _this.hideDefaultCursor = true; + _this._drawing = false; + _this._drawingMouseUpCallback = _this._drawingMouseUpCallback.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } // =================================================================== + // Abstract Methods - Must be implemented. + // =================================================================== + + /** + * Helper function for rendering the brush. + * + * @abstract + * @param {Object} evt - The event. + * @returns {void} + */ + // eslint-disable-next-line no-unused-vars + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(BaseBrushTool, [{ + key: "renderBrush", + value: function renderBrush(evt) { + throw new Error("Method renderBrush not implemented for ".concat(this.name, ".")); + } + /** + * Paints the data to the labelmap. + * + * @protected + * @abstract + * @param {Object} evt The event. + * @returns {void} + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "_paint", + value: function _paint(evt) { + throw new Error("Method _paint not implemented for ".concat(this.name, ".")); + } // =================================================================== + // Virtual Methods - Have default behavior but may be overriden. + // =================================================================== + + /** + * Event handler for MOUSE_DRAG event. + * + * @override + * @abstract + * @event + * @param {Object} evt - The event. + */ + + }, { + key: "mouseDragCallback", + value: function mouseDragCallback(evt) { + var currentPoints = evt.detail.currentPoints; + this._lastImageCoords = currentPoints.image; // Safety measure incase _startPainting is overridden and doesn't always + // start a paint. + + if (this._drawing) { + this._paint(evt); + } + } + /** + * Event handler for MOUSE_DOWN event. + * + * @override + * @abstract + * @event + * @param {Object} evt - The event. + */ + + }, { + key: "preMouseDownCallback", + value: function preMouseDownCallback(evt) { + var eventData = evt.detail; + var element = eventData.element, + currentPoints = eventData.currentPoints; + + this._startPainting(evt); + + this._lastImageCoords = currentPoints.image; + this._drawing = true; + + this._startListeningForMouseUp(element); + + this._paint(evt); + + return true; + } + /** + * Initialise painting with BaseBrushTool. + * + * @abstract + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "_startPainting", + value: function _startPainting(evt) { + var eventData = evt.detail; + var element = eventData.element; + var configuration = segmentationModule.configuration, + getters = segmentationModule.getters; + + var _getters$labelmap2D = getters.labelmap2D(element), + labelmap2D = _getters$labelmap2D.labelmap2D, + labelmap3D = _getters$labelmap2D.labelmap3D, + currentImageIdIndex = _getters$labelmap2D.currentImageIdIndex, + activeLabelmapIndex = _getters$labelmap2D.activeLabelmapIndex; + + var shouldErase = this._isCtrlDown(eventData) || this.configuration.alwaysEraseOnClick; + this.paintEventData = { + labelmap2D: labelmap2D, + labelmap3D: labelmap3D, + currentImageIdIndex: currentImageIdIndex, + activeLabelmapIndex: activeLabelmapIndex, + shouldErase: shouldErase + }; + + if (configuration.storeHistory) { + var previousPixelData = labelmap2D.pixelData.slice(); + this.paintEventData.previousPixelData = previousPixelData; + } + } + /** + * End painting with BaseBrushTool. + * + * @abstract + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "_endPainting", + value: function _endPainting(evt) { + var configuration = segmentationModule.configuration, + setters = segmentationModule.setters; + var _this$paintEventData = this.paintEventData, + labelmap2D = _this$paintEventData.labelmap2D, + currentImageIdIndex = _this$paintEventData.currentImageIdIndex; // Grab the labels on the slice. + + var segmentSet = new Set(labelmap2D.pixelData); + var iterator = segmentSet.values(); + var segmentsOnLabelmap = []; + var done = false; + + while (!done) { + var next = iterator.next(); + done = next.done; + + if (!done) { + segmentsOnLabelmap.push(next.value); + } + } + + labelmap2D.segmentsOnLabelmap = segmentsOnLabelmap; + + if (configuration.storeHistory) { + var previousPixelData = this.paintEventData.previousPixelData; + var newPixelData = labelmap2D.pixelData; + var operation = { + imageIdIndex: currentImageIdIndex, + diff: Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_11__["getDiffBetweenPixelData"])(previousPixelData, newPixelData) + }; + setters.pushState(this.element, [operation]); + } + + Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_11__["triggerLabelmapModifiedEvent"])(this.element); + } // =================================================================== + // Implementation interface + // =================================================================== + + /** + * Event handler for MOUSE_MOVE event. + * + * @override + * @abstract + * @event + * @param {Object} evt - The event. + */ + + }, { + key: "mouseMoveCallback", + value: function mouseMoveCallback(evt) { + var currentPoints = evt.detail.currentPoints; + this._lastImageCoords = currentPoints.image; + } + /** + * Used to redraw the tool's cursor per render. + * + * @override + * @param {Object} evt - The event. + */ + + }, { + key: "renderToolData", + value: function renderToolData(evt) { + var eventData = evt.detail; + var element = eventData.element; // Only brush needs to render. + + if (Object(_store_isToolActiveForElement_js__WEBPACK_IMPORTED_MODULE_9__["default"])(element, this.name)) { + // Call the hover event for the brush + this.renderBrush(evt); + } + } + /** + * Event handler for switching mode to passive. + * + * @override + * @event + * @param {Object} evt - The event. + */ + // eslint-disable-next-line no-unused-vars + + }, { + key: "passiveCallback", + value: function passiveCallback(evt) { + try { + _externalModules_js__WEBPACK_IMPORTED_MODULE_8__["default"].cornerstone.updateImage(this.element); + } catch (error) { + // It is possible that the image has not been loaded + // when this is called. + return; + } + } + /** + * Event handler for MOUSE_UP during the drawing event loop. + * + * @protected + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + }, { + key: "_drawingMouseUpCallback", + value: function _drawingMouseUpCallback(evt) { + var eventData = evt.detail; + var element = eventData.element; + + this._endPainting(evt); + + this._drawing = false; + this._mouseUpRender = true; + + this._stopListeningForMouseUp(element); + } + }, { + key: "newImageCallback", + value: function newImageCallback(evt) { + if (this._drawing) { + // End painting on one slice and start on another. + this._endPainting(evt); + + this._startPainting(evt); + } + } + /** + * Adds modify loop event listeners. + * + * @protected + * @param {Object} element - The viewport element to add event listeners to. + * @modifies {element} + * @returns {void} + */ + + }, { + key: "_startListeningForMouseUp", + value: function _startListeningForMouseUp(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_UP, this._drawingMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_CLICK, this._drawingMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_UP, this._drawingMouseUpCallback); + element.addEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_CLICK, this._drawingMouseUpCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_8__["default"].cornerstone.updateImage(element); + } + /** + * Adds modify loop event listeners. + * + * @protected + * @param {Object} element - The viewport element to add event listeners to. + * @modifies {element} + * @returns {void} + */ + + }, { + key: "_stopListeningForMouseUp", + value: function _stopListeningForMouseUp(element) { + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_UP, this._drawingMouseUpCallback); + element.removeEventListener(_events_js__WEBPACK_IMPORTED_MODULE_7__["default"].MOUSE_CLICK, this._drawingMouseUpCallback); + _externalModules_js__WEBPACK_IMPORTED_MODULE_8__["default"].cornerstone.updateImage(element); + } // =================================================================== + // Brush API. This is effectively a wrapper around the store. + // =================================================================== + + /** + * Increases the brush size + * + * @public + * @api + * @returns {void} + */ + + }, { + key: "increaseBrushSize", + value: function increaseBrushSize() { + var configuration = segmentationModule.configuration, + setters = segmentationModule.setters; + var oldRadius = configuration.radius; + var newRadius = Math.floor(oldRadius * 1.2); // If e.g. only 2 pixels big. Math.floor(2*1.2) = 2. + // Hence, have minimum increment of 1 pixel. + + if (newRadius === oldRadius) { + newRadius += 1; + } + + setters.radius(newRadius); + } + /** + * Decreases the brush size + * + * @public + * @api + * @returns {void} + */ + + }, { + key: "decreaseBrushSize", + value: function decreaseBrushSize() { + var configuration = segmentationModule.configuration, + setters = segmentationModule.setters; + var oldRadius = configuration.radius; + var newRadius = Math.floor(oldRadius * 0.8); + setters.radius(newRadius); + } + }, { + key: "_isCtrlDown", + value: function _isCtrlDown(eventData) { + return eventData.event && eventData.event.ctrlKey || eventData.ctrlKey; + } + }]); + + return BaseBrushTool; +}(_BaseTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]); + +/* harmony default export */ __webpack_exports__["default"] = (BaseBrushTool); + +/***/ }), + +/***/ "./tools/base/BaseTool.js": +/*!********************************!*\ + !*** ./tools/base/BaseTool.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _mixins_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../mixins/index.js */ "./mixins/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); +/* harmony import */ var _util_deepmerge_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../../util/deepmerge.js */ "./util/deepmerge.js"); +/* harmony import */ var _store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../store/setToolCursor.js */ "./store/setToolCursor.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../store */ "./store/index.js"); + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('tools:base:BaseTool'); +var globalConfigurationModule = Object(_store__WEBPACK_IMPORTED_MODULE_7__["getModule"])('globalConfiguration'); +/** + * @typedef ToolConfiguration + * @param {String} name + * @param {object} strategies - Named strategy functions + * @param {String} defaultStrategy - The name of the strategy to use by default + * @param {Object} configuration + * @param {String[]} mixins - A list of mixin names to apply to the tool + */ + +/** + * @memberof Tools.Base + * @classdesc BaseTool Class description + * @property {String[]} supportedInteractionTypes - A string list of ways the tool can interact with the user + */ + +var BaseTool = +/*#__PURE__*/ +function () { + /** + * Constructor description + * @param {props} [props={}] Tool properties set on instantiation of a tool + * @param {defaultProps} [defaultProps={}] Tools Default properties + */ + function BaseTool(props, defaultProps) { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, BaseTool); + + /** + * Merge default props with custom props + */ + this.initialConfiguration = Object(_util_deepmerge_js__WEBPACK_IMPORTED_MODULE_5__["default"])(defaultProps, props); + var _this$initialConfigur = this.initialConfiguration, + name = _this$initialConfigur.name, + strategies = _this$initialConfigur.strategies, + defaultStrategy = _this$initialConfigur.defaultStrategy, + configuration = _this$initialConfigur.configuration, + supportedInteractionTypes = _this$initialConfigur.supportedInteractionTypes, + mixins = _this$initialConfigur.mixins, + svgCursor = _this$initialConfigur.svgCursor; + /** + * A unique, identifying tool name + * @type {String} + */ + + this.name = name; + /** @type {String} */ + + this.mode = 'disabled'; + this.element = undefined; + this.supportedInteractionTypes = supportedInteractionTypes || []; + this.strategies = strategies || {}; + this.defaultStrategy = defaultStrategy || Object.keys(this.strategies)[0] || undefined; + this.activeStrategy = this.defaultStrategy; + + if (svgCursor) { + this.svgCursor = svgCursor; + } // Options are set when a tool is added, during a "mode" change, + // or via a tool's option's setter + + + this._options = {}; // Configuration is set at tool initalization + + this._configuration = Object.assign({}, configuration); // `updateOnMouseMove` causes the frame to render on every mouse move when + // the tool is active. This is useful for tools that render large/dynamic + // items to the canvas which can't easily be respresented with an SVG Cursor. + + this.updateOnMouseMove = false; + this.hideDefaultCursor = false; // Apply mixins if mixinsArray is not empty. + + if (mixins && mixins.length) { + this._applyMixins(mixins); + } + + this._cursors = Object.assign({}, this.initialConfiguration.cursors); + var defaultCursor = this.defaultStrategy && this._cursors[this.activeStrategy]; + + if (defaultCursor) { + this.svgCursor = defaultCursor; + } + } // + // CONFIGURATION + // + + /** + * Config... + * @public + * @type {Object} + * @instance + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(BaseTool, [{ + key: "mergeOptions", + + /** + * Merges provided options with existing options. + * + * @public + * @instance + * @param {Object} options - options object to merge with existing options. + * @returns {undefined} + */ + value: function mergeOptions(options) { + this._options = Object.assign({}, this._options, options); + } + /** + * Clears the tools options. + * + * @public + * @instance + * @memberof Tools.Base.BaseTool + * @returns {undefined} + */ + + }, { + key: "clearOptions", + value: function clearOptions() { + this._options = {}; + } + /** + * Apply the currently set/active strategy. + * + * @public + * @instance + * @method applyActiveStrategy + * @memberof Tools.Base.BaseTool + * + * @param {Object} evt The event that triggered the strategies application + * @param {Object} operationData - An object containing extra data not present in the `evt`, + * required to apply the strategy. + * @returns {*} strategies vary widely; check each specific strategy to find expected return value + */ + + }, { + key: "applyActiveStrategy", + value: function applyActiveStrategy(evt, operationData) { + return this.strategies[this.activeStrategy].call(this, evt, operationData); + } + /** + * Iterates over registered mixins; any matching names in the provided `mixinsArray` will + * be merged with this instance. + * + * @private + * @method _applyMixins + * @param {string[]} mixinsArray An array of mixin identifiers (strings). + * @returns {undefined} + */ + + }, { + key: "_applyMixins", + value: function _applyMixins(mixinsArray) { + for (var i = 0; i < mixinsArray.length; i++) { + var mixin = _mixins_index_js__WEBPACK_IMPORTED_MODULE_3__["default"]["".concat(mixinsArray[i])]; + + if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(mixin) === 'object') { + Object.assign(this, mixin); + + if (typeof this.initializeMixin === 'function') { + // Run the mixin's initialisation process. + this.initializeMixin(); + } + } else { + logger.warn("".concat(this.name, ": mixin ").concat(_mixins_index_js__WEBPACK_IMPORTED_MODULE_3__["default"][i], " does not exist.")); + } + } // Don't keep initialiseMixin from last mixin. + + + if (this.initializeMixin === 'function') { + delete this.initializeMixin; + } + } + /** + * Change the active strategy. + * + * @public + * @method setActiveStrategy + * @param {string} strategy + * @returns {null} + */ + + }, { + key: "setActiveStrategy", + value: function setActiveStrategy(strategy) { + this.activeStrategy = strategy; + + if (globalConfigurationModule.configuration.showSVGCursors) { + this.changeCursor(this.element, strategy); + } + } + /** + * Function responsible for changing the Cursor, according to the strategy. + * @param {HTMLElement} element + * @param {string} strategy The strategy to be used on Tool + * @public + * @returns {void} + */ + + }, { + key: "changeCursor", + value: function changeCursor(element, strategy) { + // Necessary to avoid setToolCursor call without elements, which throws an error. + if (!element) { + return; + } // If there are cursors set per strategy, change the cursor. + + + var cursor = this._cursors[strategy]; + + if (cursor) { + this.svgCursor = cursor; + + if (this.mode === 'active') { + Object(_store_setToolCursor_js__WEBPACK_IMPORTED_MODULE_6__["setToolCursor"])(element, cursor); // External.cornerstone.updateImage(element); + } + } + } // =================================================================== + // Virtual Methods - Have default behavior but may be overridden. + // =================================================================== + // + // MOUSE + // + + /** + * Callback that takes priority if the tool is active, before `MOUSE_DOWN` + * events are processed. Does nothing by default. + * + * @callback BaseTool~preMouseDownCallback + * @param {CornerstoneTools.event:cornerstonetoolsmousedown} evt + * @returns {boolean} consumedEvent - True if function consumed the event. + */ + + /** + * Callback that takes priority if the tool is active, after `MOUSE_DOWN` + * events are processed. Does nothing by default. + * + * @callback BaseTool~postMouseDownCallback + * @param {CornerstoneTools.event:cornerstonetoolsmousedown} evt + * @returns {boolean} consumedEvent - True if function consumed the event. + */ + + /** + * Callback that is called if the tool is active, after `MOUSE_DOWN` + * events are processed. Does nothing by default. + * + * @virtual + * @param {type} evt + * @returns {boolean} consumedEvent - True if function consumed the event. + */ + + /** + * Example implementation: + * + * postMouseDownCallback(evt) { + * return false; + * } + */ + + /** + * Callback that takes priority if the tool is active, before `TOUCH_START` + * events are processed. Does nothing by default. + * + * @virtual + * @param {type} evt + * @returns {boolean} consumedEvent - True if function consumed the event. + */ + + /** + * Example implementation: + * + * preTouchStartCallback(evt) { + * return false; + * } + */ + + /** + * Callback that is called if the tool is active, after `TOUCH_START` + * events are processed. Does nothing by default. + * + * @virtual + * @param {type} evt + * @returns {boolean} consumedEvent - True if function consumed the event. + */ + + /** + * Example implementation: + * + * postTouchStartCallback(evt) { + * return false; + * } + */ + + }, { + key: "configuration", + get: function get() { + return this._configuration; + }, + set: function set(configuration) { + this._configuration = configuration; + } // + // OPTIONS + // + + /** + * Options... + * @readonly + * @instance + */ + + }, { + key: "options", + get: function get() { + return this._options; + } + }], [{ + key: "configuration", + get: function get() {} + }]); + + return BaseTool; +}(); + +/* harmony default export */ __webpack_exports__["default"] = (BaseTool); + +/***/ }), + +/***/ "./tools/base/index.js": +/*!*****************************!*\ + !*** ./tools/base/index.js ***! + \*****************************/ +/*! exports provided: BaseAnnotationTool, BaseBrushTool, BaseTool, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseAnnotationTool.js */ "./tools/base/BaseAnnotationTool.js"); +/* harmony import */ var _BaseTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BaseTool.js */ "./tools/base/BaseTool.js"); +/* harmony import */ var _BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BaseBrushTool.js */ "./tools/base/BaseBrushTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BaseAnnotationTool", function() { return _BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BaseBrushTool", function() { return _BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BaseTool", function() { return _BaseTool_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + + + + // Named Exports + + + + // Namespace, default export + +/* harmony default export */ __webpack_exports__["default"] = ({ + BaseAnnotationTool: _BaseAnnotationTool_js__WEBPACK_IMPORTED_MODULE_0__["default"], + BaseBrushTool: _BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_2__["default"], + BaseTool: _BaseTool_js__WEBPACK_IMPORTED_MODULE_1__["default"] +}); + +/***/ }), + +/***/ "./tools/cursors/MouseCursor.js": +/*!**************************************!*\ + !*** ./tools/cursors/MouseCursor.js ***! + \**************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return MouseCursor; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../store/index.js */ "./store/index.js"); + + + + +var cursorModule = _store_index_js__WEBPACK_IMPORTED_MODULE_3__["modules"].cursor; +/* eslint-disable valid-jsdoc */ + +/* +MACROS - The following keys will have the appropriate value injected when +an SVG is requested: + +- ACTIVE_COLOR => options.activeColor || toolColors.getActiveColor(); +- TOOL_COLOR => options.toolColor || toolColors.getToolColor(); +- FILL_COLOR => options.fillColor || toolColors.getFillColor(); +*/ + +var MouseCursor = +/*#__PURE__*/ +function () { + function MouseCursor(iconGroupString, options) { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, MouseCursor); + + this.iconGroupString = iconGroupString; + this.options = Object.assign({}, cursorModule.getters.defaultOptions(), options); + } + /** + * Returns an SVG of the icon only. + * + * @param {Object} options - An object which overrides default properties of the returned SVG. + * @returns {Blob} The SVG of the icon. + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(MouseCursor, [{ + key: "getIconSVG", + value: function getIconSVG() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var svgString = this._generateIconSVGString(options); + + return new Blob([svgString], { + type: 'image/svg+xml' + }); + } + /** + * Returns a string representation of the SVG of the icon only. + * + * @param {Object} options - An object which overrides default properties of the returned SVG. + * @returns {string} The stringified SVG of the icon. + */ + + }, { + key: "getIconSVGString", + value: function getIconSVGString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return this._generateIconSVGString(options); + } + /** + * Returns an SVG of the icon + pointer. + * + * @param {Object} options - An object which overrides default properties of the returned SVG. + * @returns {Blob} The SVG of the icon + pointer.. + */ + + }, { + key: "getIconWithPointerSVG", + value: function getIconWithPointerSVG() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var svgString = this._generateIconWithPointerSVGString(options); + + return new Blob([svgString], { + type: 'image/svg+xml' + }); + } + /** + * Returns a string representation of the SVG of the icon + pointer. + * + * @param {Object} options - An object which overrides default properties of the returned SVG. + * @returns {string} The stringified SVG of the icon + pointer. + */ + + }, { + key: "getIconWithPointerString", + value: function getIconWithPointerString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return this._generateIconWithPointerSVGString(options); + } + /** + * Returns the mousePoint as a space separated string. + * + * @returns {string} The mousePoint. + */ + + }, { + key: "_generateIconWithPointerSVGString", + + /** + * Generates a string representation of the icon + pointer. + * + * @param {Object} options - An object which overrides default properties of the returned string. + * @returns {string} The SVG as a string. + */ + value: function _generateIconWithPointerSVGString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var svgOptions = Object.assign({}, this.options, options); + var mousePointerGroupString = svgOptions.mousePointerGroupString, + iconSize = svgOptions.iconSize, + viewBox = svgOptions.viewBox; + var scale = iconSize / Math.max(viewBox.x, viewBox.y); + var svgSize = 16 + iconSize; + var svgString = "\n \n \n ").concat(mousePointerGroupString, "\n \n \n ").concat(this.iconGroupString, "\n \n "); + return this._injectColors(svgString, svgOptions); + } + /** + * Generates a string representation of the icon. + * + * @param {Object} options - An object which overrides default properties of the returned string. + * @returns {string} The SVG as a string. + */ + + }, { + key: "_generateIconSVGString", + value: function _generateIconSVGString() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var svgOptions = Object.assign({}, this.options, options); + var iconSize = svgOptions.iconSize, + viewBox = svgOptions.viewBox; + var svgString = "\n \n ").concat(this.iconGroupString, "\n "); + return this._injectColors(svgString, svgOptions); + } + /** + * Replaces ACTIVE_COLOR, TOOL_COLOR and FILL_COLOR in svgString with their appropriate values. + * + * @param {string} svgString - The string to modify. + * @param {Object} options - Optional overrides for the colors. + * @returns {string} The string with color values injected. + */ + + }, { + key: "_injectColors", + value: function _injectColors(svgString) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var activeColor = options.activeColor || _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__["default"].getActiveColor(); + var toolColor = options.toolColor || _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__["default"].getToolColor(); + var fillColor = options.fillColor || _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__["default"].getFillColor(); + return svgString.replace(/ACTIVE_COLOR/g, "".concat(activeColor)).replace(/TOOL_COLOR/g, "".concat(toolColor)).replace(/FILL_COLOR/g, "".concat(fillColor)); + } + }, { + key: "mousePoint", + get: function get() { + var mousePoint = this.options.mousePoint; + return "".concat(mousePoint.x, " ").concat(mousePoint.y); + } + }]); + + return MouseCursor; +}(); + + + +/***/ }), + +/***/ "./tools/cursors/index.js": +/*!********************************!*\ + !*** ./tools/cursors/index.js ***! + \********************************/ +/*! exports provided: angleCursor, arrowAnnotateCursor, bidirectionalCursor, cobbAngleCursor, circleRoiCursor, ellipticalRoiCursor, freehandRoiCursor, freehandRoiSculptorCursor, lengthCursor, probeCursor, rectangleRoiCursor, textMarkerCursor, crosshairsCursor, eraserCursor, magnifyCursor, panCursor, rotateCursor, stackScrollCursor, wwwcRegionCursor, wwwcCursor, zoomCursor, freehandEraseInsideCursor, freehandFillInsideCursor, freehandEraseOutsideCursor, freehandFillOutsideCursor, segRectangleEraseInsideCursor, segRectangleFillInsideCursor, segRectangleEraseOutsideCursor, segRectangleFillOutsideCursor, segCircleEraseInsideCursor, segCircleFillInsideCursor, segCircleEraseOutsideCursor, segCircleFillOutsideCursor */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "angleCursor", function() { return angleCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "arrowAnnotateCursor", function() { return arrowAnnotateCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bidirectionalCursor", function() { return bidirectionalCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cobbAngleCursor", function() { return cobbAngleCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "circleRoiCursor", function() { return circleRoiCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ellipticalRoiCursor", function() { return ellipticalRoiCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandRoiCursor", function() { return freehandRoiCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandRoiSculptorCursor", function() { return freehandRoiSculptorCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lengthCursor", function() { return lengthCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "probeCursor", function() { return probeCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rectangleRoiCursor", function() { return rectangleRoiCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textMarkerCursor", function() { return textMarkerCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "crosshairsCursor", function() { return crosshairsCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraserCursor", function() { return eraserCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "magnifyCursor", function() { return magnifyCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "panCursor", function() { return panCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rotateCursor", function() { return rotateCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "stackScrollCursor", function() { return stackScrollCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wwwcRegionCursor", function() { return wwwcRegionCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wwwcCursor", function() { return wwwcCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "zoomCursor", function() { return zoomCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandEraseInsideCursor", function() { return freehandEraseInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandFillInsideCursor", function() { return freehandFillInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandEraseOutsideCursor", function() { return freehandEraseOutsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "freehandFillOutsideCursor", function() { return freehandFillOutsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segRectangleEraseInsideCursor", function() { return segRectangleEraseInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segRectangleFillInsideCursor", function() { return segRectangleFillInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segRectangleEraseOutsideCursor", function() { return segRectangleEraseOutsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segRectangleFillOutsideCursor", function() { return segRectangleFillOutsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segCircleEraseInsideCursor", function() { return segCircleEraseInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segCircleFillInsideCursor", function() { return segCircleFillInsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segCircleEraseOutsideCursor", function() { return segCircleEraseOutsideCursor; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "segCircleFillOutsideCursor", function() { return segCircleFillOutsideCursor; }); +/* harmony import */ var _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MouseCursor.js */ "./tools/cursors/MouseCursor.js"); + +/* +MACROS: + +The following keys will have the appropriate value injected by the MouseCursor +class when an SVG is requested: + +- ACTIVE_COLOR => options.activeColor || toolColors.getActiveColor(); +- TOOL_COLOR => options.toolColor || toolColors.getToolColor(); +- FILL_COLOR => options.fillColor || toolColors.getFillColor(); +*/ + +var angleCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var arrowAnnotateCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n ", { + viewBox: { + x: 24, + y: 24 + } +}); +var bidirectionalCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n \n \n \n \n \n ", { + viewBox: { + x: 48, + y: 48 + } +}); +var cobbAngleCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n \n \n \n ", { + viewBox: { + x: 32, + y: 32 + } +}); +var circleRoiCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 32, + y: 32 + } +}); +var ellipticalRoiCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 32, + y: 32 + } +}); +var freehandRoiCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", { + viewBox: { + x: 18, + y: 18 + } +}); +var freehandRoiSculptorCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", { + viewBox: { + x: 18, + y: 18 + } +}); +var lengthCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n \n ", { + viewBox: { + x: 24, + y: 24 + } +}); +var probeCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var rectangleRoiCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var textMarkerCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var crosshairsCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var eraserCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 2048, + y: 1792 + } +}); +var magnifyCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 512, + y: 512 + } +}); +var panCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var rotateCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var stackScrollCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 24, + y: 28 + } +}); +var wwwcRegionCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("", { + viewBox: { + x: 1792, + y: 1792 + } +}); +var wwwcCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n ", { + viewBox: { + x: 18, + y: 18 + } +}); +var zoomCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("\n ", { + viewBox: { + x: 640, + y: 512 + } +}); +var segToolCursorBoundaries = { + x: 127, + y: 60 +}; + +var minusRect = function minusRect() { + var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ACTIVE_COLOR'; + return ""); +}; + +var plusRect = function plusRect() { + var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ACTIVE_COLOR'; + return "\n "); +}; + +var scissorIcon = ""; +var rectangleIcon = ""; +var circleIcon = ""; +var freehandEraseInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(scissorIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var freehandFillInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(scissorIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); +var freehandEraseOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(scissorIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var freehandFillOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(scissorIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); +var segRectangleEraseInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(rectangleIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var segRectangleFillInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(rectangleIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); +var segRectangleEraseOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(rectangleIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var segRectangleFillOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(rectangleIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); +var segCircleEraseInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(circleIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var segCircleFillInsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(circleIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); +var segCircleEraseOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(circleIcon, " ").concat(minusRect()), { + viewBox: segToolCursorBoundaries +}); +var segCircleFillOutsideCursor = new _MouseCursor_js__WEBPACK_IMPORTED_MODULE_0__["default"]("".concat(circleIcon, " ").concat(plusRect()), { + viewBox: segToolCursorBoundaries +}); + +/***/ }), + +/***/ "./tools/index.js": +/*!************************!*\ + !*** ./tools/index.js ***! + \************************/ +/*! exports provided: CrosshairsTool, DoubleTapFitToWindowTool, DragProbeTool, EraserTool, FreehandRoiSculptorTool, MagnifyTool, OverlayTool, OrientationMarkersTool, PanMultiTouchTool, PanTool, ReferenceLinesTool, RotateTool, RotateTouchTool, ScaleOverlayTool, StackScrollMouseWheelTool, StackScrollMultiTouchTool, StackScrollTool, WwwcRegionTool, WwwcTool, ZoomMouseWheelTool, ZoomTool, ZoomTouchPinchTool, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _CrosshairsTool_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CrosshairsTool.js */ "./tools/CrosshairsTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CrosshairsTool", function() { return _CrosshairsTool_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _DoubleTapFitToWindowTool_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./DoubleTapFitToWindowTool.js */ "./tools/DoubleTapFitToWindowTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DoubleTapFitToWindowTool", function() { return _DoubleTapFitToWindowTool_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _DragProbeTool_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./DragProbeTool.js */ "./tools/DragProbeTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DragProbeTool", function() { return _DragProbeTool_js__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _EraserTool_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EraserTool.js */ "./tools/EraserTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EraserTool", function() { return _EraserTool_js__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony import */ var _FreehandRoiSculptorTool_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./FreehandRoiSculptorTool.js */ "./tools/FreehandRoiSculptorTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandRoiSculptorTool", function() { return _FreehandRoiSculptorTool_js__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony import */ var _MagnifyTool_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./MagnifyTool.js */ "./tools/MagnifyTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MagnifyTool", function() { return _MagnifyTool_js__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + +/* harmony import */ var _OverlayTool_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./OverlayTool.js */ "./tools/OverlayTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OverlayTool", function() { return _OverlayTool_js__WEBPACK_IMPORTED_MODULE_6__["default"]; }); + +/* harmony import */ var _OrientationMarkersTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./OrientationMarkersTool.js */ "./tools/OrientationMarkersTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OrientationMarkersTool", function() { return _OrientationMarkersTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]; }); + +/* harmony import */ var _PanMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./PanMultiTouchTool.js */ "./tools/PanMultiTouchTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PanMultiTouchTool", function() { return _PanMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_8__["default"]; }); + +/* harmony import */ var _PanTool_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./PanTool.js */ "./tools/PanTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PanTool", function() { return _PanTool_js__WEBPACK_IMPORTED_MODULE_9__["default"]; }); + +/* harmony import */ var _ReferenceLinesTool_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./ReferenceLinesTool.js */ "./tools/ReferenceLinesTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ReferenceLinesTool", function() { return _ReferenceLinesTool_js__WEBPACK_IMPORTED_MODULE_10__["default"]; }); + +/* harmony import */ var _RotateTool_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./RotateTool.js */ "./tools/RotateTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RotateTool", function() { return _RotateTool_js__WEBPACK_IMPORTED_MODULE_11__["default"]; }); + +/* harmony import */ var _RotateTouchTool_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./RotateTouchTool.js */ "./tools/RotateTouchTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RotateTouchTool", function() { return _RotateTouchTool_js__WEBPACK_IMPORTED_MODULE_12__["default"]; }); + +/* harmony import */ var _ScaleOverlayTool_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./ScaleOverlayTool.js */ "./tools/ScaleOverlayTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScaleOverlayTool", function() { return _ScaleOverlayTool_js__WEBPACK_IMPORTED_MODULE_13__["default"]; }); + +/* harmony import */ var _StackScrollMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./StackScrollMouseWheelTool.js */ "./tools/StackScrollMouseWheelTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollMouseWheelTool", function() { return _StackScrollMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_14__["default"]; }); + +/* harmony import */ var _StackScrollMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./StackScrollMultiTouchTool.js */ "./tools/StackScrollMultiTouchTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollMultiTouchTool", function() { return _StackScrollMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_15__["default"]; }); + +/* harmony import */ var _StackScrollTool_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./StackScrollTool.js */ "./tools/StackScrollTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "StackScrollTool", function() { return _StackScrollTool_js__WEBPACK_IMPORTED_MODULE_16__["default"]; }); + +/* harmony import */ var _WwwcRegionTool_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./WwwcRegionTool.js */ "./tools/WwwcRegionTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WwwcRegionTool", function() { return _WwwcRegionTool_js__WEBPACK_IMPORTED_MODULE_17__["default"]; }); + +/* harmony import */ var _WwwcTool_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./WwwcTool.js */ "./tools/WwwcTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WwwcTool", function() { return _WwwcTool_js__WEBPACK_IMPORTED_MODULE_18__["default"]; }); + +/* harmony import */ var _ZoomMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./ZoomMouseWheelTool.js */ "./tools/ZoomMouseWheelTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomMouseWheelTool", function() { return _ZoomMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_19__["default"]; }); + +/* harmony import */ var _ZoomTool_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ZoomTool.js */ "./tools/ZoomTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomTool", function() { return _ZoomTool_js__WEBPACK_IMPORTED_MODULE_20__["default"]; }); + +/* harmony import */ var _ZoomTouchPinchTool_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./ZoomTouchPinchTool.js */ "./tools/ZoomTouchPinchTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ZoomTouchPinchTool", function() { return _ZoomTouchPinchTool_js__WEBPACK_IMPORTED_MODULE_21__["default"]; }); + + + + + + + + + + + + + + + + + + + + + + + // Named Exports + + // Namespace, default export + +/* harmony default export */ __webpack_exports__["default"] = ({ + CrosshairsTool: _CrosshairsTool_js__WEBPACK_IMPORTED_MODULE_0__["default"], + DoubleTapFitToWindowTool: _DoubleTapFitToWindowTool_js__WEBPACK_IMPORTED_MODULE_1__["default"], + DragProbeTool: _DragProbeTool_js__WEBPACK_IMPORTED_MODULE_2__["default"], + EraserTool: _EraserTool_js__WEBPACK_IMPORTED_MODULE_3__["default"], + FreehandRoiSculptorTool: _FreehandRoiSculptorTool_js__WEBPACK_IMPORTED_MODULE_4__["default"], + MagnifyTool: _MagnifyTool_js__WEBPACK_IMPORTED_MODULE_5__["default"], + OverlayTool: _OverlayTool_js__WEBPACK_IMPORTED_MODULE_6__["default"], + OrientationMarkersTool: _OrientationMarkersTool_js__WEBPACK_IMPORTED_MODULE_7__["default"], + PanMultiTouchTool: _PanMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_8__["default"], + PanTool: _PanTool_js__WEBPACK_IMPORTED_MODULE_9__["default"], + ReferenceLinesTool: _ReferenceLinesTool_js__WEBPACK_IMPORTED_MODULE_10__["default"], + RotateTool: _RotateTool_js__WEBPACK_IMPORTED_MODULE_11__["default"], + RotateTouchTool: _RotateTouchTool_js__WEBPACK_IMPORTED_MODULE_12__["default"], + ScaleOverlayTool: _ScaleOverlayTool_js__WEBPACK_IMPORTED_MODULE_13__["default"], + StackScrollMouseWheelTool: _StackScrollMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_14__["default"], + StackScrollMultiTouchTool: _StackScrollMultiTouchTool_js__WEBPACK_IMPORTED_MODULE_15__["default"], + StackScrollTool: _StackScrollTool_js__WEBPACK_IMPORTED_MODULE_16__["default"], + WwwcRegionTool: _WwwcRegionTool_js__WEBPACK_IMPORTED_MODULE_17__["default"], + WwwcTool: _WwwcTool_js__WEBPACK_IMPORTED_MODULE_18__["default"], + ZoomMouseWheelTool: _ZoomMouseWheelTool_js__WEBPACK_IMPORTED_MODULE_19__["default"], + ZoomTool: _ZoomTool_js__WEBPACK_IMPORTED_MODULE_20__["default"], + ZoomTouchPinchTool: _ZoomTouchPinchTool_js__WEBPACK_IMPORTED_MODULE_21__["default"] +}); + +/***/ }), + +/***/ "./tools/referenceLines/calculateReferenceLine.js": +/*!********************************************************!*\ + !*** ./tools/referenceLines/calculateReferenceLine.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _util_pointProjector_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../util/pointProjector.js */ "./util/pointProjector.js"); + +/** + * Calculates a reference line between two planes by projecting the top left hand corner and bottom right hand corner + * Of the reference image onto the target image. Ideally we would calculate the intersection between the planes but + * That requires a bit more math and this works fine for most cases. + * + * @export + * @public + * @method + * @name calculateReferenceLine + * @param {Object} targetImagePlane The imagePlane on which the reference line will be drawn. + * @param {Object} referenceImagePlane The imagePlane being referenced. + * @returns {Object} The start and end points of the line to be drawn. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (targetImagePlane, referenceImagePlane) { + var points = Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_0__["planePlaneIntersection"])(targetImagePlane, referenceImagePlane); + + if (!points) { + return; + } + + return { + start: Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_0__["projectPatientPointToImagePlane"])(points.start, targetImagePlane), + end: Object(_util_pointProjector_js__WEBPACK_IMPORTED_MODULE_0__["projectPatientPointToImagePlane"])(points.end, targetImagePlane) + }; +}); + +/***/ }), + +/***/ "./tools/referenceLines/renderActiveReferenceLine.js": +/*!***********************************************************!*\ + !*** ./tools/referenceLines/renderActiveReferenceLine.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _calculateReferenceLine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./calculateReferenceLine.js */ "./tools/referenceLines/calculateReferenceLine.js"); +/* harmony import */ var _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../stateManagement/toolColors.js */ "./stateManagement/toolColors.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../util/convertToVector3.js */ "./util/convertToVector3.js"); +/* harmony import */ var _drawing_index_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../drawing/index.js */ "./drawing/index.js"); + + + + + +/** + * Renders the active reference line. + * + * @export @public @method + * @name renderActiveReferenceLine + * @param {Object} context The canvas context. + * @param {Object} eventData The data associated with the event. + * @param {HTMLElement} targetElement The element on which to render the reference line. + * @param {HTMLElement} referenceElement The element referenced by the line. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (context, eventData, targetElement, referenceElement) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var targetImage = cornerstone.getEnabledElement(targetElement).image; + var referenceImage = cornerstone.getEnabledElement(referenceElement).image; // Make sure the images are actually loaded for the target and reference + + if (!targetImage || !referenceImage) { + return; + } + + var targetImagePlane = cornerstone.metaData.get('imagePlaneModule', targetImage.imageId); + var referenceImagePlane = cornerstone.metaData.get('imagePlaneModule', referenceImage.imageId); // Make sure the target and reference actually have image plane metadata + + if (!targetImagePlane || !referenceImagePlane || !targetImagePlane.rowCosines || !targetImagePlane.columnCosines || !targetImagePlane.imagePositionPatient || !referenceImagePlane.rowCosines || !referenceImagePlane.columnCosines || !referenceImagePlane.imagePositionPatient) { + return; + } // The image planes must be in the same frame of reference + + + if (targetImagePlane.frameOfReferenceUID !== referenceImagePlane.frameOfReferenceUID) { + return; + } + + targetImagePlane.rowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(targetImagePlane.rowCosines); + targetImagePlane.columnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(targetImagePlane.columnCosines); + targetImagePlane.imagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(targetImagePlane.imagePositionPatient); + referenceImagePlane.rowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(referenceImagePlane.rowCosines); + referenceImagePlane.columnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(referenceImagePlane.columnCosines); + referenceImagePlane.imagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_3__["default"])(referenceImagePlane.imagePositionPatient); // The image plane normals must be > 30 degrees apart + + var targetNormal = targetImagePlane.rowCosines.clone().cross(targetImagePlane.columnCosines); + var referenceNormal = referenceImagePlane.rowCosines.clone().cross(referenceImagePlane.columnCosines); + var angleInRadians = targetNormal.angleTo(referenceNormal); + angleInRadians = Math.abs(angleInRadians); + + if (angleInRadians < 0.5) { + // 0.5 radians = ~30 degrees + return; + } + + var referenceLine = Object(_calculateReferenceLine_js__WEBPACK_IMPORTED_MODULE_1__["default"])(targetImagePlane, referenceImagePlane); + + if (!referenceLine) { + return; + } + + var color = _stateManagement_toolColors_js__WEBPACK_IMPORTED_MODULE_2__["default"].getActiveColor(); // Draw the referenceLines + + context.setTransform(1, 0, 0, 1, 0, 0); + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_4__["draw"])(context, function (context) { + Object(_drawing_index_js__WEBPACK_IMPORTED_MODULE_4__["drawLine"])(context, eventData.element, referenceLine.start, referenceLine.end, { + color: color + }); + }); +}); + +/***/ }), + +/***/ "./tools/segmentation/BrushTool.js": +/*!*****************************************!*\ + !*** ./tools/segmentation/BrushTool.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BrushTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../base */ "./tools/base/index.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_segmentation_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../util/segmentation/index.js */ "./util/segmentation/index.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_10__["getLogger"])('tools:BrushTool'); +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_8__["getModule"])('segmentation'); +/** + * @public + * @class BrushTool + * @memberof Tools.Brush + * @classdesc Tool for drawing segmentations on an image. + * @extends Tools.Base.BaseBrushTool + */ + +var BrushTool = +/*#__PURE__*/ +function (_BaseBrushTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(BrushTool, _BaseBrushTool); + + function BrushTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, BrushTool); + + var defaultProps = { + name: 'Brush', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: {}, + mixins: ['renderBrushMixin'] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(BrushTool).call(this, props, defaultProps)); + _this.touchDragCallback = _this._paint.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + /** + * Paints the data to the labelmap. + * + * @protected + * @param {Object} evt The data object associated with the event. + * @returns {void} + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(BrushTool, [{ + key: "_paint", + value: function _paint(evt) { + var configuration = segmentationModule.configuration; + var eventData = evt.detail; + var element = eventData.element; + var _eventData$image = eventData.image, + rows = _eventData$image.rows, + columns = _eventData$image.columns; + var _eventData$currentPoi = eventData.currentPoints.image, + x = _eventData$currentPoi.x, + y = _eventData$currentPoi.y; + + if (x < 0 || x > columns || y < 0 || y > rows) { + return; + } + + var radius = configuration.radius; + var pointerArray = Object(_util_segmentation_index_js__WEBPACK_IMPORTED_MODULE_9__["getCircle"])(radius, rows, columns, x, y); + var _this$paintEventData = this.paintEventData, + labelmap2D = _this$paintEventData.labelmap2D, + labelmap3D = _this$paintEventData.labelmap3D, + shouldErase = _this$paintEventData.shouldErase; // Draw / Erase the active color. + + Object(_util_segmentation_index_js__WEBPACK_IMPORTED_MODULE_9__["drawBrushPixels"])(pointerArray, labelmap2D.pixelData, labelmap3D.activeSegmentIndex, columns, shouldErase); + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(evt.detail.element); + } + }]); + + return BrushTool; +}(_base__WEBPACK_IMPORTED_MODULE_7__["BaseBrushTool"]); + + + +/***/ }), + +/***/ "./tools/segmentation/CircleScissorsTool.js": +/*!**************************************************!*\ + !*** ./tools/segmentation/CircleScissorsTool.js ***! + \**************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CircleScissorsTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _base__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../base */ "./tools/base/index.js"); +/* harmony import */ var _strategies__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./strategies */ "./tools/segmentation/strategies/index.js"); +/* harmony import */ var _cursors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../cursors */ "./tools/cursors/index.js"); + + + + + + + +/** + * @public + * @class CircleScissorsTool + * @memberof Tools + * @classdesc Tool for manipulating labelmap data by drawing a circle. + * @extends Tools.Base.BaseTool + */ + +var CircleScissorsTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default()(CircleScissorsTool, _BaseTool); + + /** @inheritdoc */ + function CircleScissorsTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, CircleScissorsTool); + + var defaultProps = { + name: 'CircleScissors', + strategies: { + FILL_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillInsideCircle"], + FILL_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillOutsideCircle"], + ERASE_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseOutsideCircle"], + ERASE_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseInsideCircle"] + }, + cursors: { + FILL_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segCircleFillInsideCursor"], + FILL_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segCircleFillOutsideCursor"], + ERASE_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segCircleEraseOutsideCursor"], + ERASE_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segCircleEraseInsideCursor"] + }, + defaultStrategy: 'FILL_INSIDE', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors__WEBPACK_IMPORTED_MODULE_6__["segCircleFillInsideCursor"], + mixins: ['circleSegmentationMixin'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default()(CircleScissorsTool).call(this, props, defaultProps)); + } + + return CircleScissorsTool; +}(_base__WEBPACK_IMPORTED_MODULE_4__["BaseTool"]); + + + +/***/ }), + +/***/ "./tools/segmentation/CorrectionScissorsTool.js": +/*!******************************************************!*\ + !*** ./tools/segmentation/CorrectionScissorsTool.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CorrectionScissorsTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _base__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../base */ "./tools/base/index.js"); +/* harmony import */ var _cursors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../cursors */ "./tools/cursors/index.js"); +/* harmony import */ var _strategies__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./strategies */ "./tools/segmentation/strategies/index.js"); + + + + + + + +/** + * @public + * @class CorrectionScissorsTool + * @memberof Tools + * @classdesc Tool for correcting segments on a labelmap. + * @extends Tools.Base.BaseTool + */ + +var CorrectionScissorsTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default()(CorrectionScissorsTool, _BaseTool); + + /** @inheritdoc */ + function CorrectionScissorsTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, CorrectionScissorsTool); + + var defaultProps = { + name: 'CorrectionScissors', + strategies: { + CORRECTION: _strategies__WEBPACK_IMPORTED_MODULE_6__["correction"] + }, + cursors: { + CORRECTION: _cursors__WEBPACK_IMPORTED_MODULE_5__["freehandFillInsideCursor"] + }, + defaultStrategy: 'CORRECTION', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors__WEBPACK_IMPORTED_MODULE_5__["freehandFillInsideCursor"], + mixins: ['polylineSegmentationMixin'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default()(CorrectionScissorsTool).call(this, props, defaultProps)); + } + + return CorrectionScissorsTool; +}(_base__WEBPACK_IMPORTED_MODULE_4__["BaseTool"]); + + + +/***/ }), + +/***/ "./tools/segmentation/FreehandScissorsTool.js": +/*!****************************************************!*\ + !*** ./tools/segmentation/FreehandScissorsTool.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FreehandScissorsTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _cursors__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../cursors */ "./tools/cursors/index.js"); +/* harmony import */ var _strategies__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./strategies */ "./tools/segmentation/strategies/index.js"); +/* harmony import */ var _base__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../base */ "./tools/base/index.js"); + + + + + + + +/** + * @public + * @class FreehandScissorsTool + * @memberof Tools + * @classdesc Tool for manipulating labelmap data by drawing a freehand polygon. + * @extends Tools.Base.BaseTool + */ + +var FreehandScissorsTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default()(FreehandScissorsTool, _BaseTool); + + /** @inheritdoc */ + function FreehandScissorsTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FreehandScissorsTool); + + var defaultProps = { + name: 'FreehandScissors', + strategies: { + FILL_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillInsideFreehand"], + FILL_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillOutsideFreehand"], + ERASE_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseOutsideFreehand"], + ERASE_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseInsideFreehand"] + }, + cursors: { + FILL_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_4__["freehandFillInsideCursor"], + FILL_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_4__["freehandFillOutsideCursor"], + ERASE_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_4__["freehandEraseOutsideCursor"], + ERASE_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_4__["freehandEraseInsideCursor"] + }, + defaultStrategy: 'FILL_INSIDE', + supportedInteractionTypes: ['Mouse', 'Touch'], + svgCursor: _cursors__WEBPACK_IMPORTED_MODULE_4__["freehandFillInsideCursor"], + mixins: ['freehandSegmentationMixin'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default()(FreehandScissorsTool).call(this, props, defaultProps)); + } + + return FreehandScissorsTool; +}(_base__WEBPACK_IMPORTED_MODULE_6__["BaseTool"]); + + + +/***/ }), + +/***/ "./tools/segmentation/RectangleScissorsTool.js": +/*!*****************************************************!*\ + !*** ./tools/segmentation/RectangleScissorsTool.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return RectangleScissorsTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _base__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../base */ "./tools/base/index.js"); +/* harmony import */ var _strategies__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./strategies */ "./tools/segmentation/strategies/index.js"); +/* harmony import */ var _cursors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../cursors */ "./tools/cursors/index.js"); + + + + + + + +/** + * @public + * @class RectangleScissorsTool + * @memberof Tools + * @classdesc Tool for manipulating labelmap data by drawing a rectangle. + * @extends Tools.Base.BaseTool + */ + +var RectangleScissorsTool = +/*#__PURE__*/ +function (_BaseTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default()(RectangleScissorsTool, _BaseTool); + + /** @inheritdoc */ + function RectangleScissorsTool() { + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, RectangleScissorsTool); + + var defaultProps = { + name: 'RectangleScissors', + strategies: { + FILL_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillInsideRectangle"], + FILL_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["fillOutsideRectangle"], + ERASE_OUTSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseOutsideRectangle"], + ERASE_INSIDE: _strategies__WEBPACK_IMPORTED_MODULE_5__["eraseInsideRectangle"] + }, + cursors: { + FILL_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segRectangleFillInsideCursor"], + FILL_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segRectangleFillOutsideCursor"], + ERASE_OUTSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segRectangleEraseOutsideCursor"], + ERASE_INSIDE: _cursors__WEBPACK_IMPORTED_MODULE_6__["segRectangleEraseInsideCursor"] + }, + defaultStrategy: 'FILL_INSIDE', + supportedInteractionTypes: ['Mouse', 'Touch'], + mixins: ['rectangleSegmentationMixin'] + }; + return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_1___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_2___default()(RectangleScissorsTool).call(this, props, defaultProps)); + } + + return RectangleScissorsTool; +}(_base__WEBPACK_IMPORTED_MODULE_4__["BaseTool"]); + + + +/***/ }), + +/***/ "./tools/segmentation/SphericalBrushTool.js": +/*!**************************************************!*\ + !*** ./tools/segmentation/SphericalBrushTool.js ***! + \**************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return SphericalBrushTool; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js"); +/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "../node_modules/@babel/runtime/helpers/getPrototypeOf.js"); +/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/assertThisInitialized */ "../node_modules/@babel/runtime/helpers/assertThisInitialized.js"); +/* harmony import */ var _babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/inherits */ "../node_modules/@babel/runtime/helpers/inherits.js"); +/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../base/BaseBrushTool.js */ "./tools/base/BaseBrushTool.js"); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../../store/index.js */ "./store/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _util_logger_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../util/logger.js */ "./util/logger.js"); + + + + + + + + + + + + + +var logger = Object(_util_logger_js__WEBPACK_IMPORTED_MODULE_11__["getLogger"])('tools:SphericalBrushTool'); +var segmentationModule = Object(_store_index_js__WEBPACK_IMPORTED_MODULE_8__["getModule"])('segmentation'); +/** + * @public + * @class BrushTool + * @memberof Tools.Brush + * @classdesc Tool for drawing segmentations on an image. + * @extends Tools.Base.BaseBrushTool + */ + +var SphericalBrushTool = +/*#__PURE__*/ +function (_BaseBrushTool) { + _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(SphericalBrushTool, _BaseBrushTool); + + function SphericalBrushTool() { + var _this; + + var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, SphericalBrushTool); + + var defaultProps = { + name: 'SphericalBrush', + supportedInteractionTypes: ['Mouse', 'Touch'], + configuration: { + alwaysEraseOnClick: false + }, + mixins: ['renderBrushMixin'] + }; + _this = _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(SphericalBrushTool).call(this, props, defaultProps)); + _this.touchDragCallback = _this._paint.bind(_babel_runtime_helpers_assertThisInitialized__WEBPACK_IMPORTED_MODULE_4___default()(_this)); + return _this; + } + /** + * Initialise painting with BaseBrushTool. + * + * @abstract + * @event + * @param {Object} evt - The event. + * @returns {void} + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(SphericalBrushTool, [{ + key: "_startPainting", + value: function _startPainting(evt) { + var configuration = segmentationModule.configuration, + getters = segmentationModule.getters; + var eventData = evt.detail; + var element = eventData.element, + image = eventData.image; + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone; + var radius = configuration.radius; + var rows = image.rows, + columns = image.columns; + var pixelSpacing = Math.max(image.rowPixelSpacing, image.columnPixelSpacing); + var stackState = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_10__["getToolState"])(element, 'stack'); + var stackData = stackState.data[0]; + var imageIds = stackData.imageIds; + + var _getters$labelmap2D = getters.labelmap2D(element), + labelmap2D = _getters$labelmap2D.labelmap2D, + labelmap3D = _getters$labelmap2D.labelmap3D, + currentImageIdIndex = _getters$labelmap2D.currentImageIdIndex, + activeLabelmapIndex = _getters$labelmap2D.activeLabelmapIndex; + + var shouldErase = this._isCtrlDown(eventData) || this.configuration.alwaysEraseOnClick; + var imagePlaneOfCurrentImage = cornerstone.metaData.get('imagePlaneModule', image.imageId); + var imagesInRange; + + if (imagePlaneOfCurrentImage) { + var ippOfCurrentImage = imagePlaneOfCurrentImage.imagePositionPatient; + imagesInRange = this._getImagesInRange(currentImageIdIndex, ippOfCurrentImage, imageIds, radius, pixelSpacing); + } else { + logger.warn("No imagePlane metadata found for image, defaulting to circle brush application."); + imagesInRange = [// The current image. + { + imageIdIndex: currentImageIdIndex, + radiusOnImage: radius + }]; + } + + this.paintEventData = { + labelmap2D: labelmap2D, + labelmap3D: labelmap3D, + currentImageIdIndex: currentImageIdIndex, + activeLabelmapIndex: activeLabelmapIndex, + shouldErase: shouldErase, + imagesInRange: imagesInRange + }; + + if (configuration.storeHistory) { + var previousPixeldataForImagesInRange = []; + + for (var i = 0; i < imagesInRange.length; i++) { + var imageIdIndex = imagesInRange[i].imageIdIndex; + var labelmap2DForImageIdIndex = getters.labelmap2DByImageIdIndex(labelmap3D, imageIdIndex, rows, columns); + var previousPixeldata = labelmap2DForImageIdIndex.pixelData.slice(); + previousPixeldataForImagesInRange.push(previousPixeldata); + } + + this.paintEventData.previousPixeldataForImagesInRange = previousPixeldataForImagesInRange; + } + } + /** + * Paints the data to the labelmap. + * + * @private + * @param {Object} evt The data object associated with the event. + * @returns {void} + */ + + }, { + key: "_paint", + value: function _paint(evt) { + var getters = segmentationModule.getters; + var eventData = evt.detail; + var element = eventData.element; + var image = eventData.image; + var rows = image.rows, + columns = image.columns; + var _eventData$currentPoi = eventData.currentPoints.image, + x = _eventData$currentPoi.x, + y = _eventData$currentPoi.y; + + if (x < 0 || x > columns || y < 0 || y > rows) { + return; + } + + var _this$paintEventData = this.paintEventData, + labelmap3D = _this$paintEventData.labelmap3D, + imagesInRange = _this$paintEventData.imagesInRange, + shouldErase = _this$paintEventData.shouldErase; + + for (var i = 0; i < imagesInRange.length; i++) { + var _imagesInRange$i = imagesInRange[i], + imageIdIndex = _imagesInRange$i.imageIdIndex, + radiusOnImage = _imagesInRange$i.radiusOnImage; + var pointerArray = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_9__["getCircle"])(radiusOnImage, rows, columns, x, y); // Cache the view on this image if its not present. + + var labelmap2DForImageIdIndex = getters.labelmap2DByImageIdIndex(labelmap3D, imageIdIndex, rows, columns); // Draw / Erase the active color. + + Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_9__["drawBrushPixels"])(pointerArray, labelmap2DForImageIdIndex.pixelData, labelmap3D.activeSegmentIndex, columns, shouldErase); + } + + _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.updateImage(evt.detail.element); + } + /** + * _getImagesInRange - Returns an array of image Ids within range of the + * sphere, and the in-plane brush radii of those images. + * + * @param {string} currentImageIdIndex The imageId of the image displayed on + * the cornerstone enabled element. + * @param {number[]} ippOfCurrentImage The image position patient of the image. + * @param {string[]} imageIds An array of images in the stack. + * @param {number} radius The radius of the sphere. + * @param {number} pixelSpacing The pixelSpacing. + * @returns {Object[]} An array of imageIds in range and their + * in plane brush radii. + */ + + }, { + key: "_getImagesInRange", + value: function _getImagesInRange(currentImageIdIndex, ippOfCurrentImage, imageIds, radius, pixelSpacing) { + var radiusInMM = radius * pixelSpacing; + var imagesInRange = [// The current image. + { + imageIdIndex: currentImageIdIndex, + radiusOnImage: radius + }]; // Check images above + + for (var i = currentImageIdIndex + 1; i < imageIds.length; i++) { + var radiusOnImage = this._getRadiusOnImage(imageIds[i], ippOfCurrentImage, radiusInMM, pixelSpacing); + + if (!radiusOnImage) { + break; + } + + imagesInRange.push({ + imageIdIndex: i, + radiusOnImage: radiusOnImage + }); + } // Check images below + + + for (var _i = currentImageIdIndex - 1; _i >= 0; _i--) { + var _radiusOnImage = this._getRadiusOnImage(imageIds[_i], ippOfCurrentImage, radiusInMM, pixelSpacing); + + if (!_radiusOnImage) { + break; + } + + imagesInRange.push({ + imageIdIndex: _i, + radiusOnImage: _radiusOnImage + }); + } + + return imagesInRange; + } + /** + * _getRadiusOnImage - If the image is in range of the spherical brush, returns + * the in-plane brush radius on that image. + * + * @param {string} imageId The cornerstone imageId of the image. + * @param {number[]} ippOfCurrentImage The image position patient of the current image. + * @param {number} radiusInMM The radius of the sphere in millimeters. + * @param {string} pixelSpacing The pixelspacing. + * @returns {number|undefined} The brush radius on the image, undefined if + * the image is out of range of the sphere. + */ + + }, { + key: "_getRadiusOnImage", + value: function _getRadiusOnImage(imageId, ippOfCurrentImage, radiusInMM, pixelSpacing) { + var imagePlane = _externalModules_js__WEBPACK_IMPORTED_MODULE_6__["default"].cornerstone.metaData.get('imagePlaneModule', imageId); + + if (!imagePlane) { + logger.warn("Can't find imagePlane metadata for image, cancelling spherical brushing on: ".concat(imageId, ",")); + return; + } + + var ipp = imagePlane.imagePositionPatient; + var distance = Math.sqrt(Math.pow(ipp[0] - ippOfCurrentImage[0], 2) + Math.pow(ipp[1] - ippOfCurrentImage[1], 2) + Math.pow(ipp[2] - ippOfCurrentImage[2], 2)); + + if (distance > radiusInMM) { + // Image too far away, break! + return; + } + + return Math.floor(Math.sqrt(Math.pow(radiusInMM, 2) - Math.pow(distance, 2)) / pixelSpacing); + } + }, { + key: "_endPainting", + value: function _endPainting(evt) { + var _this$paintEventData2 = this.paintEventData, + labelmap3D = _this$paintEventData2.labelmap3D, + imagesInRange = _this$paintEventData2.imagesInRange; + var operations = []; + var configuration = segmentationModule.configuration, + setters = segmentationModule.setters; + + for (var i = 0; i < imagesInRange.length; i++) { + var imageIdIndex = imagesInRange[i].imageIdIndex; + var labelmap2D = labelmap3D.labelmaps2D[imageIdIndex]; // Grab the labels on the slice. + + var segmentSet = new Set(labelmap2D.pixelData); + var iterator = segmentSet.values(); + var segmentsOnLabelmap = []; + var done = false; + + while (!done) { + var next = iterator.next(); + done = next.done; + + if (!done) { + segmentsOnLabelmap.push(next.value); + } + } + + labelmap2D.segmentsOnLabelmap = segmentsOnLabelmap; + + if (configuration.storeHistory) { + var previousPixeldataForImagesInRange = this.paintEventData.previousPixeldataForImagesInRange; + var previousPixeldata = previousPixeldataForImagesInRange[i]; + var _labelmap2D = labelmap3D.labelmaps2D[imageIdIndex]; + var newPixelData = _labelmap2D.pixelData; + operations.push({ + imageIdIndex: imageIdIndex, + diff: Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_9__["getDiffBetweenPixelData"])(previousPixeldata, newPixelData) + }); + } + } + + if (configuration.storeHistory) { + setters.pushState(this.element, operations); + } + + Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_9__["triggerLabelmapModifiedEvent"])(this.element); + } + }]); + + return SphericalBrushTool; +}(_base_BaseBrushTool_js__WEBPACK_IMPORTED_MODULE_7__["default"]); + + + +/***/ }), + +/***/ "./tools/segmentation/index.js": +/*!*************************************!*\ + !*** ./tools/segmentation/index.js ***! + \*************************************/ +/*! exports provided: BrushTool, SphericalBrushTool, FreehandScissorsTool, RectangleScissorsTool, CircleScissorsTool, CorrectionScissorsTool, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _BrushTool__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BrushTool */ "./tools/segmentation/BrushTool.js"); +/* harmony import */ var _SphericalBrushTool__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SphericalBrushTool */ "./tools/segmentation/SphericalBrushTool.js"); +/* harmony import */ var _FreehandScissorsTool__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./FreehandScissorsTool */ "./tools/segmentation/FreehandScissorsTool.js"); +/* harmony import */ var _RectangleScissorsTool__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./RectangleScissorsTool */ "./tools/segmentation/RectangleScissorsTool.js"); +/* harmony import */ var _CircleScissorsTool__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CircleScissorsTool */ "./tools/segmentation/CircleScissorsTool.js"); +/* harmony import */ var _CorrectionScissorsTool__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./CorrectionScissorsTool */ "./tools/segmentation/CorrectionScissorsTool.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BrushTool", function() { return _BrushTool__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SphericalBrushTool", function() { return _SphericalBrushTool__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FreehandScissorsTool", function() { return _FreehandScissorsTool__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RectangleScissorsTool", function() { return _RectangleScissorsTool__WEBPACK_IMPORTED_MODULE_3__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CircleScissorsTool", function() { return _CircleScissorsTool__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CorrectionScissorsTool", function() { return _CorrectionScissorsTool__WEBPACK_IMPORTED_MODULE_5__["default"]; }); + + + + + + + // Named Exports + + + + + + + // Namespace, default export + +/* harmony default export */ __webpack_exports__["default"] = ({ + BrushTool: _BrushTool__WEBPACK_IMPORTED_MODULE_0__["default"], + SphericalBrushTool: _SphericalBrushTool__WEBPACK_IMPORTED_MODULE_1__["default"], + CircleScissorsTool: _CircleScissorsTool__WEBPACK_IMPORTED_MODULE_4__["default"], + CorrectionScissorsTool: _CorrectionScissorsTool__WEBPACK_IMPORTED_MODULE_5__["default"], + FreehandScissorsTool: _FreehandScissorsTool__WEBPACK_IMPORTED_MODULE_2__["default"], + RectangleScissorsTool: _RectangleScissorsTool__WEBPACK_IMPORTED_MODULE_3__["default"] +}); + +/***/ }), + +/***/ "./tools/segmentation/strategies/correction.js": +/*!*****************************************************!*\ + !*** ./tools/segmentation/strategies/correction.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return correction; }); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./index.js */ "./tools/segmentation/strategies/index.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_clip__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/clip */ "./util/clip.js"); +/* harmony import */ var _util_isPointInImage__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/isPointInImage */ "./util/isPointInImage.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_5__["getLogger"])('util:segmentation:operations:correction'); +/** + * Using the stroke given, determine which action(s) to perfom: + * - Stroke starts and ends inside a segmentation: Behaves as an subtractive freehand scissors. + * - Stroke starts and ends outside a segmentation: Behaves as an additive freehand scissors. + * - Stroke out-in-out: Section is subtracted. + * - Stroke in-out-in: Section is added. + * + * @param {Object} evt The cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * + * @returns {null} + */ + +function correction(evt, operationData) { + var pixelData = operationData.pixelData, + segmentIndex = operationData.segmentIndex, + segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "freehandSegmentationMixin") { + logger.error("correction operation requires freehandSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var nodes = snapPointsToGrid(evt, operationData); + var scissorOperation = checkIfSimpleScissorOperation(nodes, segmentIndex); + + if (scissorOperation.isScissorOperation) { + if (scissorOperation.operation === 'fillInsideFreehand') { + logger.warn('The line never intersects a segment.'); + Object(_index_js__WEBPACK_IMPORTED_MODULE_1__["fillInsideFreehand"])(evt, operationData); + } else if (scissorOperation.operation === 'eraseInsideFreehand') { + logger.warn('The line is only ever inside the segment.'); + Object(_index_js__WEBPACK_IMPORTED_MODULE_1__["eraseInsideFreehand"])(evt, operationData); + } + + return; + } // Create binary labelmap with only this segment for calculations of each operation. + + + var workingLabelMap = new Uint8Array(pixelData.length); + var operations = splitLineIntoSeperateOperations(nodes, segmentIndex); + operations.forEach(function (operation) { + performOperation(operation, pixelData, workingLabelMap, segmentIndex, evt); + }); +} +/** + * Snap the freehand points to the labelmap grid and attach a label for each node. + * + * @param {Object[]} points An array of points drawn by the user. + * @param {UInt16Array|Float32Array} pixelData The 2D labelmap. + * @param {Object} evt The cornerstone event. + * @returns {Object[]} + */ + +function snapPointsToGrid(evt, operationData) { + var pixelData = operationData.pixelData, + points = operationData.points; + var image = evt.detail.image; + var cols = image.width; + var rows = image.height; + var nodes = []; + + for (var i = 0; i < points.length; i++) { + var point = points[i]; + var x = Math.floor(point.x); + var y = Math.floor(point.y); // Clamp within the confines of the image. + + x = Object(_util_clip__WEBPACK_IMPORTED_MODULE_3__["default"])(x, 0, cols - 1); + y = Object(_util_clip__WEBPACK_IMPORTED_MODULE_3__["default"])(y, 0, rows - 1); + var lastNode = nodes[nodes.length - 1]; // Skip double counting of closely drawn freehand points. + + if (lastNode && x === lastNode.x && y === lastNode.y) { + continue; + } + + nodes.push({ + x: x, + y: y, + segment: pixelData[y * cols + x] + }); + } + + return nodes; +} +/** + * Check if the operation is a simple scissors add/remove. + * @param {Object[]} nodes - The nodes snapped to the grid. + * @param {number} segmentIndex + * @returns {Object} Information about the operation. + * `isScissorOperation` is true if the operation is a simple scissor. + * If `isScissorOperation` is true, `operation` says which operation. + */ + + +function checkIfSimpleScissorOperation(nodes, segmentIndex) { + var allInside = true; + var allOutside = true; + + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + + if (node.segment === segmentIndex) { + allOutside = false; + } else { + allInside = false; + } + + if (!allInside && !allOutside) { + break; + } + } + + if (allOutside) { + return { + isScissorOperation: true, + operation: 'fillInsideFreehand' + }; + } else if (allInside) { + return { + isScissorOperation: true, + operation: 'eraseInsideFreehand' + }; + } + + return { + isScissorOperation: false + }; +} +/** + * Performs the given add/subtract operation using a modification of the Tobias Heimann Correction Algorithm: + * The algorithm is described in full length in Tobias Heimann's diploma thesis (MBI Technical Report 145, p. 37 - 40). + * + * @param {Object} operation The operation. + * @param {UInt16Array|Float32Array} pixelData The 2D labelmap. + * @param {UInt16Array|Float32Array} workingLabelMap A copy of the labelmap for processing purposes. + * @param {number} segmentIndex The label of the tool being used. + * @param {Object} evt The cornerstone event. + */ + + +function performOperation(operation, pixelData, workingLabelMap, segmentIndex, evt) { + var _evt$detail$image = evt.detail.image, + cols = _evt$detail$image.width, + rows = _evt$detail$image.height; + var nodes = operation.nodes, + additive = operation.additive; + var shouldFillOver = additive ? 0 : 1; // Local getters to swap from cornerstone vector notation and flattened array indicies. + + var getPixelIndex = function getPixelIndex(pixelCoord) { + return pixelCoord.y * cols + pixelCoord.x; + }; + + var getPixelCoordinateFromPixelIndex = function getPixelCoordinateFromPixelIndex(pixelIndex) { + return { + x: pixelIndex % cols, + y: Math.floor(pixelIndex / cols) + }; + }; + + if (additive) { + logger.warn('additive operation...'); + } else { + logger.warn('subtractive operation...'); + } + + var _getPixelPaths = getPixelPaths(nodes), + pixelPath = _getPixelPaths.pixelPath, + leftPath = _getPixelPaths.leftPath, + rightPath = _getPixelPaths.rightPath; // Find extent of region for floodfill (This segment + the drawn loop). + // This is to reduce the extent of the outwards floodfill, which constitutes 99% of the computation. + + + var firstPixelOnPath = pixelPath[0]; + var boundingBox = { + xMin: firstPixelOnPath.x, + xMax: firstPixelOnPath.x, + yMin: firstPixelOnPath.y, + yMax: firstPixelOnPath.y + }; // ...whilst also initializing the workingLabelmap + + for (var i = 0; i < workingLabelMap.length; i++) { + if (pixelData[i] === segmentIndex) { + var pixel = getPixelCoordinateFromPixelIndex(i); + expandBoundingBox(boundingBox, pixel); + workingLabelMap[i] = 1; + } else { + workingLabelMap[i] = 0; + } + } // Set workingLabelmap pixelPath to 2 to form a + // Boundary in the working labelmap to contain the flood fills. + + + for (var _i = 0; _i < pixelPath.length; _i++) { + var _pixel = pixelPath[_i]; + workingLabelMap[getPixelIndex(_pixel)] = 2; + expandBoundingBox(boundingBox, _pixel); + } + + clipBoundingBox(boundingBox, rows, cols); + var xMin = boundingBox.xMin, + xMax = boundingBox.xMax, + yMin = boundingBox.yMin, + yMax = boundingBox.yMax; // Define a getter for the fill routine to access the working label map. + + function getter(x, y) { + // Check if out of bounds, as the flood filler doesn't know about the dimensions of + // The data structure. E.g. if cols is 10, (0,1) and (10, 0) would point to the same + // position in this getter. + if (x >= xMax || x < xMin || y >= yMax || y < yMin) { + return; + } + + return workingLabelMap[y * cols + x]; + } + + var leftArea = 0; + var rightArea = 0; // Traverse the path whilst pouring paint off the left and right sides. + + for (var _i2 = 0; _i2 < leftPath.length; _i2++) { + // Left fill + var leftPixel = leftPath[_i2]; + var leftValue = workingLabelMap[getPixelIndex(leftPixel)]; + + if (leftValue === shouldFillOver && Object(_util_isPointInImage__WEBPACK_IMPORTED_MODULE_4__["default"])(leftPixel, rows, cols)) { + leftArea += fillFromPixel(leftPixel, 3, workingLabelMap, getter, cols); + } // Right fill + + + var rightPixel = rightPath[_i2]; + var rightValue = workingLabelMap[getPixelIndex(rightPixel)]; + + if (rightValue === shouldFillOver && Object(_util_isPointInImage__WEBPACK_IMPORTED_MODULE_4__["default"])(rightPixel, rows, cols)) { + rightArea += fillFromPixel(rightPixel, 4, workingLabelMap, getter, cols); + } + } + + if (leftArea === 0 || rightArea === 0) { + // The areas are connected, therefore the start and end + // Of the path go through unconnected regions, exit. + return; + } + + var replaceValue = additive ? segmentIndex : 0; // Fill in smallest area. + + var fillValue = leftArea < rightArea ? 3 : 4; + + for (var _i3 = 0; _i3 < workingLabelMap.length; _i3++) { + if (workingLabelMap[_i3] === fillValue) { + pixelData[_i3] = replaceValue; + } + } + + if (replaceValue === segmentIndex) { + // Fill in the path. + for (var _i4 = 0; _i4 < pixelPath.length; _i4++) { + pixelData[getPixelIndex(pixelPath[_i4])] = segmentIndex; + } + } else { + // Only erase this segment. + for (var _i5 = 0; _i5 < pixelPath.length; _i5++) { + var pixelIndex = getPixelIndex(pixelPath[_i5]); + + if (pixelData[pixelIndex] === segmentIndex) { + pixelData[pixelIndex] = 0; + } + } + } +} +/** + * Expands the bounding box if the pixel falls outside it. + * + * @param {Object} boundingBox The bounding box. + * @param {Object} pixel The pixel. + * @returns {null} + */ + + +function expandBoundingBox(boundingBox, pixel) { + var x = pixel.x, + y = pixel.y; + + if (x < boundingBox.xMin) { + boundingBox.xMin = x; + } + + if (x > boundingBox.xMax) { + boundingBox.xMax = x; + } + + if (y < boundingBox.yMin) { + boundingBox.yMin = y; + } + + if (y > boundingBox.yMax) { + boundingBox.yMax = y; + } +} +/** + * Expands the bounding box by 2 px and then clips it to the image size. + * @param {Object} boundingBox The bounding box. + * @param {number} rows The number of rows. + * @param {number} cols The number of columns. + * @returns {null} + */ + + +function clipBoundingBox(boundingBox, rows, cols) { + // Add a 2px border to stop the floodfill starting out of bounds and exploading. + var border = 2; + boundingBox.xMax = Math.min(boundingBox.xMax + border, cols); + boundingBox.xMin = Math.max(boundingBox.xMin - border, 0); + boundingBox.yMax = Math.min(boundingBox.yMax + border, rows); + boundingBox.yMin = Math.max(boundingBox.yMin - border, 0); +} +/** + * Performs a floodfill from the given pixel to the workingLabelMap. + * @param {Object} pixel The pixel. + * @param {number} fillValue The fill value. + * @param {UInt8Array} workingLabelMap The working labelmap. + * @param {function} getter The getter function for pixels in the labelmap. + * @param {number} cols The number of columns. + * @returns {number} The number of pixels flooded. + */ + + +function fillFromPixel(pixel, fillValue, workingLabelMap, getter, cols) { + var result = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_2__["floodFill"])(getter, [pixel.x, pixel.y]); + var flooded = result.flooded; + + for (var p = 0; p < flooded.length; p++) { + var floodedI = flooded[p]; + workingLabelMap[floodedI[1] * cols + floodedI[0]] = fillValue; + } + + return flooded.length; +} +/** + * Interpolates the pixelPath using an obstacleless path finding algorithm. + * @param {Object[]} nodes The nodes to interpolate between. + * @returns {Object} The pixelPath, and the path to the left and right of it. + */ + + +function getPixelPaths(nodes) { + var pixelPath = []; + + for (var i = 0; i < nodes.length - 1; i++) { + // Push the node. + pixelPath.push(nodes[i]); // Path towards next node. + + pixelPath.push.apply(pixelPath, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_2__["getPixelPathBetweenPixels"])(nodes[i], nodes[i + 1]))); + } // Push final node. + + + pixelPath.push[nodes[nodes.length - 1]]; // Get paths on either side. + + var leftPath = []; + var rightPath = []; + + for (var _i6 = 0; _i6 < pixelPath.length - 1; _i6++) { + var _getNodesPerpendicula = getNodesPerpendicularToPathPixel(pixelPath[_i6], pixelPath[_i6 + 1]), + left = _getNodesPerpendicula.left, + right = _getNodesPerpendicula.right; + + leftPath.push(left); + rightPath.push(right); + } + + return { + pixelPath: pixelPath, + leftPath: leftPath, + rightPath: rightPath + }; +} +/** + * Using the current and next pixel on the path, determine the adjacent pixels + * which are perpendicular to the path direction. (i.e. to the left and to the right). + * + * @param {Object} pathPixel The pixel being queried. + * @param {Object} nextPathPixel the pathPixel's successor. + * + * @returns {Object} The coordinates of the left and right perpendicular pixels. + */ + + +function getNodesPerpendicularToPathPixel(pathPixel, nextPathPixel) { + var direction = { + x: nextPathPixel.x - pathPixel.x, + y: nextPathPixel.y - pathPixel.y + }; // P = pathPixel, n = nextPathPixel, L = left, R = right + // + // |n| |R| | |n| | |L| |n| + // | |p| | |L|p|R| | |p| | + // |L| | | | | | | | | |R| + // + // | |R| | | |L| | + // |n|p| | | |p|n| + // | |L| | | |R| | + // + // |R| | | | | | | | | |L| + // | |p| | |R|p|L| | |p| | + // |n| |L| | |n| | |R| |n| + + if (direction.x === -1 && direction.y === 1) { + return { + left: { + x: pathPixel.x - 1, + y: pathPixel.y - 1 + }, + right: { + x: pathPixel.x + 1, + y: pathPixel.y + 1 + } + }; + } else if (direction.x === 0 && direction.y === 1) { + return { + left: { + x: pathPixel.x - 1, + y: pathPixel.y + }, + right: { + x: pathPixel.x + 1, + y: pathPixel.y + } + }; + } else if (direction.x === 1 && direction.y === 1) { + return { + left: { + x: pathPixel.x - 1, + y: pathPixel.y + 1 + }, + right: { + x: pathPixel.x + 1, + y: pathPixel.y - 1 + } + }; + } else if (direction.x === 1 && direction.y === 0) { + return { + left: { + x: pathPixel.x, + y: pathPixel.y + 1 + }, + right: { + x: pathPixel.x, + y: pathPixel.y - 1 + } + }; + } else if (direction.x === 1 && direction.y === -1) { + return { + left: { + x: pathPixel.x + 1, + y: pathPixel.y + 1 + }, + right: { + x: pathPixel.x - 1, + y: pathPixel.y - 1 + } + }; + } else if (direction.x === 0 && direction.y === -1) { + return { + left: { + x: pathPixel.x + 1, + y: pathPixel.y + }, + right: { + x: pathPixel.x - 1, + y: pathPixel.y + } + }; + } else if (direction.x === -1 && direction.y === -1) { + return { + left: { + x: pathPixel.x + 1, + y: pathPixel.y - 1 + }, + right: { + x: pathPixel.x - 1, + y: pathPixel.y + 1 + } + }; + } else if (direction.x === -1 && direction.y === 0) { + return { + left: { + x: pathPixel.x, + y: pathPixel.y - 1 + }, + right: { + x: pathPixel.x, + y: pathPixel.y + 1 + } + }; + } + + logger.error("Unable to find left and right paths for flood fill ", pathPixel, nextPathPixel, direction); +} +/** + * @typedef {Object} Node + * @property {number} x - the X position + * @property {number} y - the Y position + * @property {number} segment - The segment index + */ + +/** + * @typedef {Object} SegmentationOperations + * @property {boolean} additive - Whether the operation is additive or not + * @property {Node[]} nodes - The array of nodes + */ + +/** + * Splits the path of nodes into separate add/remove operations. + * + * @param {Object[]} nodes The array of nodes. + * @param {number} segmentIndex The label value to replace. + * @returns {SegmentationOperations[]} An array of operations to perform, + * whether they are `additive` and the + * corresponding `nodes` of the operation. + */ + + +function splitLineIntoSeperateOperations(nodes, segmentIndex) { + // Check whether the first node is inside a segment of the appropriate label or not. + var isLabel = nodes[0].segment === segmentIndex; + var operations = []; + operations.push({ + additive: !isLabel, + nodes: [] + }); + var operationIndex = 0; + + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + + if (isLabel) { + operations[operationIndex].nodes.push(node); + + if (node.segment !== segmentIndex) { + // Start a new operation and include the last two nodes. + operationIndex++; + isLabel = !isLabel; + operations.push({ + additive: true, + nodes: [] + }); + operations[operationIndex].nodes.push(nodes[i - 1]); + operations[operationIndex].nodes.push(node); + } + } else { + operations[operationIndex].nodes.push(node); + + if (node.segment === segmentIndex) { + // Start a new operation and add include the last two nodes. + operationIndex++; + isLabel = !isLabel; + operations.push({ + additive: false, + nodes: [] + }); + operations[operationIndex].nodes.push(nodes[i - 1]); + operations[operationIndex].nodes.push(node); + } + } + } // Trim the first and last entries, as they don't form full operations. + + + operations.pop(); + operations.shift(); + return operations; +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/eraseCircle.js": +/*!******************************************************!*\ + !*** ./tools/segmentation/strategies/eraseCircle.js ***! + \******************************************************/ +/*! exports provided: eraseInsideCircle, eraseOutsideCircle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseInsideCircle", function() { return eraseInsideCircle; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideCircle", function() { return eraseOutsideCircle; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_ellipse__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/ellipse */ "./util/ellipse/index.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_getCircleCoords_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/getCircleCoords.js */ "./util/getCircleCoords.js"); + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_2__["getLogger"])('util:segmentation:operations:eraseInsideCircle'); +/** + * EraseInsideCircle - Erase all pixels labeled with the activeSegmentIndex, + * in the region defined by the circle. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseCircle(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "circleSegmentationMixin") { + logger.error("eraseInsideCircle operation requires circleSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var eventData = evt.detail; + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_3__["getBoundingBoxAroundCircle"])(evt), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + var ellipse = Object(_util_getCircleCoords_js__WEBPACK_IMPORTED_MODULE_4__["default"])(eventData.handles.start, eventData.handles.end); + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_3__["eraseInsideShape"])(evt, operationData, function (point) { + return Object(_util_ellipse__WEBPACK_IMPORTED_MODULE_1__["pointInEllipse"])(ellipse, point); + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_3__["eraseOutsideShape"])(evt, operationData, function (point) { + return Object(_util_ellipse__WEBPACK_IMPORTED_MODULE_1__["pointInEllipse"])(ellipse, point); + }, topLeft, bottomRight); +} +/** + * Erase all pixels inside/outside the region defined by the circle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function eraseInsideCircle(evt, operationData) { + eraseCircle(evt, operationData, true); +} +/** + * Erase all pixels outside the region defined by the circle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseOutsideCircle(evt, operationData) { + eraseCircle(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/eraseFreehand.js": +/*!********************************************************!*\ + !*** ./tools/segmentation/strategies/eraseFreehand.js ***! + \********************************************************/ +/*! exports provided: eraseInsideFreehand, eraseOutsideFreehand */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseInsideFreehand", function() { return eraseInsideFreehand; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideFreehand", function() { return eraseOutsideFreehand; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/isPointInPolygon */ "./util/isPointInPolygon.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('util:segmentation:operations:eraseInsideFreehand'); +/** + * Erase all pixels labeled with the activeSegmentIndex, + * in the region defined by evt.operationData.points. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseFreehand(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var points = operationData.points, + segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "freehandSegmentationMixin") { + logger.error("eraseInsideFreehand operation requires freehandSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var image = evt.detail.image; + var vertices = points.map(function (a) { + return [a.x, a.y]; + }); + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["getBoundingBoxAroundPolygon"])(vertices, image), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["eraseInsideShape"])(evt, operationData, function (point) { + return Object(_util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__["default"])([point.x, point.y], vertices); + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["eraseOutsideShape"])(evt, operationData, function (point) { + return Object(_util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__["default"])([point.x, point.y], vertices); + }, topLeft, bottomRight); +} +/** + * Erase all pixels inside/outside the region defined by `operationData.points`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function eraseInsideFreehand(evt, operationData) { + eraseFreehand(evt, operationData, true); +} +/** + * Erase all pixels outside the region defined by `operationData.points`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseOutsideFreehand(evt, operationData) { + eraseFreehand(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/eraseRectangle.js": +/*!*********************************************************!*\ + !*** ./tools/segmentation/strategies/eraseRectangle.js ***! + \*********************************************************/ +/*! exports provided: eraseInsideRectangle, eraseOutsideRectangle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseInsideRectangle", function() { return eraseInsideRectangle; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideRectangle", function() { return eraseOutsideRectangle; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_1__["getLogger"])('util:segmentation:operations:eraseInsideRectangle'); +/** + * Erase all pixels inside the region defined by the rectangle. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseRectangle(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var points = operationData.points, + segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "rectangleSegmentationMixin") { + logger.error("eraseInsideRectangle operation requires rectangleSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var eventData = evt.detail; // Loop through all pixels in the segmentation data mask + // Obtain the bounding box of the entire drawing so that + // we can subset our search. + + var image = eventData.image; + var vertices = points.map(function (a) { + return [a.x, a.y]; + }); + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_2__["getBoundingBoxAroundPolygon"])(vertices, image), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_2__["eraseInsideShape"])(evt, operationData, function () { + return true; + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_2__["eraseOutsideBoundingBox"])(evt, operationData, topLeft, bottomRight); +} +/** + * Erase all pixels inside/outside the region defined by the rectangle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function eraseInsideRectangle(evt, operationData) { + eraseRectangle(evt, operationData, true); +} +/** + * Erase all pixels outside the region defined by the rectangle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function eraseOutsideRectangle(evt, operationData) { + eraseRectangle(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/fillCircle.js": +/*!*****************************************************!*\ + !*** ./tools/segmentation/strategies/fillCircle.js ***! + \*****************************************************/ +/*! exports provided: fillInsideCircle, fillOutsideCircle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillInsideCircle", function() { return fillInsideCircle; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillOutsideCircle", function() { return fillOutsideCircle; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_ellipse__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/ellipse */ "./util/ellipse/index.js"); +/* harmony import */ var _util_getCircleCoords__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/getCircleCoords */ "./util/getCircleCoords.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_4__["getLogger"])('util:segmentation:operations:fillCircle'); +/** + * Fill all pixels inside/outside the region defined by the circle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillCircle(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "circleSegmentationMixin") { + logger.error("fillInsideCircle operation requires circleSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var eventData = evt.detail; + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["getBoundingBoxAroundCircle"])(evt), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + var ellipse = Object(_util_getCircleCoords__WEBPACK_IMPORTED_MODULE_3__["default"])(eventData.handles.start, eventData.handles.end); + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillInsideShape"])(evt, operationData, function (point) { + return Object(_util_ellipse__WEBPACK_IMPORTED_MODULE_2__["pointInEllipse"])(ellipse, point); + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillOutsideShape"])(evt, operationData, function (point) { + return Object(_util_ellipse__WEBPACK_IMPORTED_MODULE_2__["pointInEllipse"])(ellipse, point); + }, topLeft, bottomRight); +} +/** + * Fill all pixels inside/outside the region defined by the circle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function fillInsideCircle(evt, operationData) { + fillCircle(evt, operationData, true); +} +/** + * Fill all pixels outside the region defined by the circle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillOutsideCircle(evt, operationData) { + fillCircle(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/fillFreehand.js": +/*!*******************************************************!*\ + !*** ./tools/segmentation/strategies/fillFreehand.js ***! + \*******************************************************/ +/*! exports provided: fillInsideFreehand, fillOutsideFreehand */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillInsideFreehand", function() { return fillInsideFreehand; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillOutsideFreehand", function() { return fillOutsideFreehand; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/isPointInPolygon */ "./util/isPointInPolygon.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('util:segmentation:operations:fillInsideFreehand'); +/** + * Fill all pixels inside/outside the region defined by + * `operationData.points` with the `activeSegmentIndex` value. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillFreehand(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var points = operationData.points, + segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "freehandSegmentationMixin") { + logger.error("eraseInsideFreehand operation requires freehandSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } // Obtain the bounding box of the entire drawing so that + // we can subset our search. Outside of the bounding box, + // everything is outside of the polygon. + + + var image = evt.detail.image; + var vertices = points.map(function (a) { + return [a.x, a.y]; + }); + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["getBoundingBoxAroundPolygon"])(vertices, image), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillInsideShape"])(evt, operationData, function (point) { + return Object(_util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__["default"])([point.x, point.y], vertices); + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillOutsideShape"])(evt, operationData, function (point) { + return Object(_util_isPointInPolygon__WEBPACK_IMPORTED_MODULE_2__["default"])([point.x, point.y], vertices); + }, topLeft, bottomRight); +} +/** + * Fill all pixels inside/outside the region defined by `operationData.points`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function fillInsideFreehand(evt, operationData) { + fillFreehand(evt, operationData, true); +} +/** + * Fill all pixels outside the region defined by `operationData.points`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillOutsideFreehand(evt, operationData) { + fillFreehand(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/fillRectangle.js": +/*!********************************************************!*\ + !*** ./tools/segmentation/strategies/fillRectangle.js ***! + \********************************************************/ +/*! exports provided: fillInsideRectangle, fillOutsideRectangle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillInsideRectangle", function() { return fillInsideRectangle; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillOutsideRectangle", function() { return fillOutsideRectangle; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _util_segmentation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../util/segmentation */ "./util/segmentation/index.js"); +/* harmony import */ var _util_logger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../util/logger */ "./util/logger.js"); + + + +var logger = Object(_util_logger__WEBPACK_IMPORTED_MODULE_2__["getLogger"])('util:segmentation:operations:fillInsideRectangle'); +/** + * FillInsideRectangle - Fill all pixels inside/outside the region defined + * by the rectangle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillRectangle(evt, operationData) { + var inside = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var points = operationData.points, + segmentationMixinType = operationData.segmentationMixinType; + + if (segmentationMixinType !== "rectangleSegmentationMixin") { + logger.error("eraseInsideRectangle operation requires rectangleSegmentationMixin operationData, recieved ".concat(segmentationMixinType)); + return; + } + + var image = evt.detail.image; + var vertices = points.map(function (a) { + return [a.x, a.y]; + }); + + var _getBoundingBoxAround = Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["getBoundingBoxAroundPolygon"])(vertices, image), + _getBoundingBoxAround2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_getBoundingBoxAround, 2), + topLeft = _getBoundingBoxAround2[0], + bottomRight = _getBoundingBoxAround2[1]; + + inside ? Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillInsideShape"])(evt, operationData, function () { + return true; + }, topLeft, bottomRight) : Object(_util_segmentation__WEBPACK_IMPORTED_MODULE_1__["fillOutsideBoundingBox"])(evt, operationData, topLeft, bottomRight); +} +/** + * Fill all pixels inside/outside the region defined by the rectangle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + + +function fillInsideRectangle(evt, operationData) { + fillRectangle(evt, operationData, true); +} +/** + * Fill all pixels outside the region defined by the rectangle. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @returns {null} + */ + +function fillOutsideRectangle(evt, operationData) { + fillRectangle(evt, operationData, false); +} + +/***/ }), + +/***/ "./tools/segmentation/strategies/index.js": +/*!************************************************!*\ + !*** ./tools/segmentation/strategies/index.js ***! + \************************************************/ +/*! exports provided: correction, eraseInsideFreehand, eraseOutsideFreehand, eraseInsideRectangle, eraseOutsideRectangle, fillInsideFreehand, fillOutsideFreehand, fillInsideRectangle, fillOutsideRectangle, fillInsideCircle, fillOutsideCircle, eraseInsideCircle, eraseOutsideCircle */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _correction__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./correction */ "./tools/segmentation/strategies/correction.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "correction", function() { return _correction__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _eraseFreehand__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./eraseFreehand */ "./tools/segmentation/strategies/eraseFreehand.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseInsideFreehand", function() { return _eraseFreehand__WEBPACK_IMPORTED_MODULE_1__["eraseInsideFreehand"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideFreehand", function() { return _eraseFreehand__WEBPACK_IMPORTED_MODULE_1__["eraseOutsideFreehand"]; }); + +/* harmony import */ var _eraseRectangle_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./eraseRectangle.js */ "./tools/segmentation/strategies/eraseRectangle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseInsideRectangle", function() { return _eraseRectangle_js__WEBPACK_IMPORTED_MODULE_2__["eraseInsideRectangle"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideRectangle", function() { return _eraseRectangle_js__WEBPACK_IMPORTED_MODULE_2__["eraseOutsideRectangle"]; }); + +/* harmony import */ var _fillFreehand__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./fillFreehand */ "./tools/segmentation/strategies/fillFreehand.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillInsideFreehand", function() { return _fillFreehand__WEBPACK_IMPORTED_MODULE_3__["fillInsideFreehand"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideFreehand", function() { return _fillFreehand__WEBPACK_IMPORTED_MODULE_3__["fillOutsideFreehand"]; }); + +/* harmony import */ var _fillRectangle__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./fillRectangle */ "./tools/segmentation/strategies/fillRectangle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillInsideRectangle", function() { return _fillRectangle__WEBPACK_IMPORTED_MODULE_4__["fillInsideRectangle"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideRectangle", function() { return _fillRectangle__WEBPACK_IMPORTED_MODULE_4__["fillOutsideRectangle"]; }); + +/* harmony import */ var _fillCircle__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./fillCircle */ "./tools/segmentation/strategies/fillCircle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillInsideCircle", function() { return _fillCircle__WEBPACK_IMPORTED_MODULE_5__["fillInsideCircle"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideCircle", function() { return _fillCircle__WEBPACK_IMPORTED_MODULE_5__["fillOutsideCircle"]; }); + +/* harmony import */ var _eraseCircle__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./eraseCircle */ "./tools/segmentation/strategies/eraseCircle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseInsideCircle", function() { return _eraseCircle__WEBPACK_IMPORTED_MODULE_6__["eraseInsideCircle"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideCircle", function() { return _eraseCircle__WEBPACK_IMPORTED_MODULE_6__["eraseOutsideCircle"]; }); + + + + + + + + + +/***/ }), + +/***/ "./util/SaveAs.js": +/*!************************!*\ + !*** ./util/SaveAs.js ***! + \************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Exports an image of the canvas. + * @export @public @method + * @name saveAs + * + * @param {HTMLElement} element The element to export. + * @param {string} filename The name of the exported image. + * @param {string} [mimetype = 'image/png'] The mimetype of the exported image. + * @returns {void} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (element, filename) { + var mimetype = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'image/png'; + var canvas = element.querySelector('canvas'); // If we are using IE, use canvas.msToBlob + + if (canvas.msToBlob) { + var blob = canvas.msToBlob(); + return window.navigator.msSaveBlob(blob, filename); + } // Thanks to Ken Fyrstenber + // http://stackoverflow.com/questions/18480474/how-to-save-an-image-from-canvas + + + var lnk = document.createElement('a'); // The key here is to set the download attribute of the a tag + + lnk.download = filename; // Convert canvas content to data-uri for link. When download + // Attribute is set the content pointed to by link will be + // Pushed as 'download' in HTML5 capable browsers + + lnk.href = canvas.toDataURL(mimetype, 1); // Create a 'fake' click-event to trigger the download + + if (document.createEvent) { + var e = document.createEvent('MouseEvents'); + e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + lnk.dispatchEvent(e); + } else if (lnk.fireEvent) { + lnk.fireEvent('onclick'); + } +}); + +/***/ }), + +/***/ "./util/angleBetweenPoints.js": +/*!************************************!*\ + !*** ./util/angleBetweenPoints.js ***! + \************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Calculates the (interior) angle in degrees from the initial mouse location + * to the current mouse location in relation to the center point. + * @public + * @function angleBetweenPoints + * + * @param {Object} p0 The center point. + * @param {Object} p1 The initial point. + * @param {Object} p2 The final point. + * @returns {Object} { angle, direction } + */ +/* harmony default export */ __webpack_exports__["default"] = (function (p0, p1, p2) { + var p12 = Math.sqrt(Math.pow(p0.x - p1.x, 2) + Math.pow(p0.y - p1.y, 2)); + var p13 = Math.sqrt(Math.pow(p0.x - p2.x, 2) + Math.pow(p0.y - p2.y, 2)); + var p23 = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); + var angle = Math.acos((Math.pow(p12, 2) + Math.pow(p13, 2) - Math.pow(p23, 2)) / (2 * p12 * p13)) * 180 / Math.PI; // The direction of the angle (> 0 clockwise, < 0 anti-clockwise) + + var direction = (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x); + return { + angle: angle, + direction: direction + }; +}); + +/***/ }), + +/***/ "./util/calculateSUV.js": +/*!******************************!*\ + !*** ./util/calculateSUV.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Calculates a Standardized Uptake Value. + * @export @public @method + * @name calculateSUV + * + * @param {Object} image The image. + * @param {number} storedPixelValue The raw pixel value. + * @param {bool} [skipRescale=fale] + * @returns {number} The SUV. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (image, storedPixelValue) { + var skipRescale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var patientStudyModule = cornerstone.metaData.get('patientStudyModule', image.imageId); + var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId); + + if (!patientStudyModule || !seriesModule) { + return; + } + + var modality = seriesModule.modality; // Image must be PET + + if (modality !== 'PT') { + return; + } + + var modalityPixelValue = skipRescale ? storedPixelValue : storedPixelValue * image.slope + image.intercept; + var patientWeight = patientStudyModule.patientWeight; // In kg + + if (!patientWeight) { + return; + } + + var petSequenceModule = cornerstone.metaData.get('petIsotopeModule', image.imageId); + + if (!petSequenceModule) { + return; + } + + var radiopharmaceuticalInfo = petSequenceModule.radiopharmaceuticalInfo; + var startTime = radiopharmaceuticalInfo.radiopharmaceuticalStartTime; + var totalDose = radiopharmaceuticalInfo.radionuclideTotalDose; + var halfLife = radiopharmaceuticalInfo.radionuclideHalfLife; + var seriesAcquisitionTime = seriesModule.seriesTime; + + if (!startTime || !totalDose || !halfLife || !seriesAcquisitionTime) { + return; + } + + var acquisitionTimeInSeconds = fracToDec(seriesAcquisitionTime.fractionalSeconds || 0) + seriesAcquisitionTime.seconds + seriesAcquisitionTime.minutes * 60 + seriesAcquisitionTime.hours * 60 * 60; + var injectionStartTimeInSeconds = fracToDec(startTime.fractionalSeconds || 0) + startTime.seconds + startTime.minutes * 60 + startTime.hours * 60 * 60; + var durationInSeconds = acquisitionTimeInSeconds - injectionStartTimeInSeconds; + var correctedDose = totalDose * Math.exp(-durationInSeconds * Math.log(2) / halfLife); + var suv = modalityPixelValue * patientWeight / correctedDose * 1000; + return suv; +}); +/** + * Returns a decimal value given a fractional value. + * @private + * @method + * @name fracToDec + * + * @param {number} fractionalValue The value to convert. + * @returns {number} The value converted to decimal. + */ + +function fracToDec(fractionalValue) { + return parseFloat(".".concat(fractionalValue)); +} + +/***/ }), + +/***/ "./util/clip.js": +/*!**********************!*\ + !*** ./util/clip.js ***! + \**********************/ +/*! exports provided: clip, clipToBox, clipBoxToDisplayedArea, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clip", function() { return clip; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clipToBox", function() { return clipToBox; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clipBoxToDisplayedArea", function() { return clipBoxToDisplayedArea; }); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + + +/** + * Clips a value to an upper and lower bound. + * @export @public @method + * @name clip + * + * @param {number} val The value to clip. + * @param {number} low The lower bound. + * @param {number} high The upper bound. + * @returns {number} The clipped value. + */ + +function clip(val, low, high) { + return Math.min(Math.max(low, val), high); +} +/** + * Clips a value within a box. + * @export @public @method + * @name clipToBox + * + * @param {Object} point The point to clip + * @param {Object} box The bounding box to clip to. + * @returns {void} + */ + +function clipToBox(point, box) { + // Clip an {x, y} point to a box {top, left, width, height} + var left = box.left || 0; + var top = box.top || 0; + point.x = clip(point.x, left, left + box.width); + point.y = clip(point.y, top, top + box.height); +} +/** + * Returns a new bounding box of rotated text box, relative to the pixel + * coordinate system. It will get the coordinate of the 4 points of the rotated + * text box and calculate the AABB (axis-aligned bounding box - lower and upper + * boundaries for `x` and `y` axes). + * + * @param {HTMLElement} element The element to manipulate pixel positioning + * @param {Object} box - `{ left, top, width, height }` in canvas coordinates + * @returns {Object} - `{ minX, minY, maxX, maxY }` boundaries of the box + */ + +var getBoxPixelBoundaries = function getBoxPixelBoundaries(element, box) { + var toPixel = function toPixel(point) { + return _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone.canvasToPixel(element, point); + }; + + var top = box.top, + left = box.left, + width = box.width, + height = box.height; + var topLeft = toPixel({ + x: left, + y: top + }); + var topRight = toPixel({ + x: left + width, + y: top + }); + var bottomLeft = toPixel({ + x: left, + y: top + height + }); + var bottomRight = toPixel({ + x: left + width, + y: top + height + }); + var points = [topLeft, topRight, bottomLeft, bottomRight]; + var xArray = points.map(function (p) { + return p.x; + }); + var yArray = points.map(function (p) { + return p.y; + }); + return { + minX: Math.min.apply(Math, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(xArray)), + minY: Math.min.apply(Math, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(yArray)), + maxX: Math.max.apply(Math, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(xArray)), + maxY: Math.max.apply(Math, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(yArray)) + }; +}; +/** + * Reposition a box point coordinates in the given axis' upper/lower limits + * + * @param {Object} point `{ x, y }` The coordinate point of the box + * @param {string} axis The axis to be manipulated: `x` or `y` + * @param {number} boxMin The box position's lower value on axis + * @param {number} boxMax The box position's upper value on axis + * @param {number} lowerLimit The lower limit of allowed box position on axis + * @param {number} upperLimit The upper limit of allowed box position on axis + * @returns {void} + */ + + +var clipBoxOnAxis = function clipBoxOnAxis(point, axis, boxMin, boxMax, lowerLimit, upperLimit) { + if (upperLimit - lowerLimit < boxMax - boxMin) { + // Box is bigger than allowed range, leaking both lower/upper boundaries + point[axis] += lowerLimit - boxMin; // Stick to the lower boundary + + point[axis] += (upperLimit - lowerLimit) / 2; // Centralize in range + + point[axis] -= (boxMax - boxMin) / 2; // Translate -1/2 of box's size + } else if (boxMin < lowerLimit) { + // Box leaked lower boundary + point[axis] += lowerLimit - boxMin; // Stick to the lower boundary + } else if (boxMax > upperLimit) { + // Box leaked upper boundary + point[axis] -= boxMax - upperLimit; // Stick to the upper boundary + } +}; +/** + * Clips a box to the viewport's displayed area + * @export @public @method + * @name clipBoxToDisplayedArea + * + * @param {HTMLElement} element The element to manipulate pixel positioning + * @param {Object} box - `{ left, top, width, height }` in canvas coordinates + * @returns {void} + */ + + +function clipBoxToDisplayedArea(element, box) { + var _external$cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone, + pixelToCanvas = _external$cornerstone.pixelToCanvas, + canvasToPixel = _external$cornerstone.canvasToPixel, + getViewport = _external$cornerstone.getViewport, + getEnabledElement = _external$cornerstone.getEnabledElement, + getDisplayedArea = _external$cornerstone.getDisplayedArea; // Transform the position of given box from canvas to pixel coordinates + + var pixelPosition = canvasToPixel(element, { + x: box.left, + y: box.top + }); // Get the rotated corners' position for the box in pixel coordinate system + + var _getBoxPixelBoundarie = getBoxPixelBoundaries(element, box), + minX = _getBoxPixelBoundarie.minX, + minY = _getBoxPixelBoundarie.minY, + maxX = _getBoxPixelBoundarie.maxX, + maxY = _getBoxPixelBoundarie.maxY; // Get the displayed area's top, left, bottom and right boundaries + + + var viewport = getViewport(element); + var enabledElement = getEnabledElement(element); + var defaultDisplayedArea = getDisplayedArea(enabledElement.image, viewport); + + var _ref = viewport.displayedArea ? viewport.displayedArea : defaultDisplayedArea, + tlhc = _ref.tlhc, + brhc = _ref.brhc; + + var top = tlhc.y - 1; + var left = tlhc.x - 1; + var bottom = brhc.y; + var right = brhc.x; // Clip the box on vertical axis + + clipBoxOnAxis(pixelPosition, 'y', minY, maxY, top, bottom); // Clip the box on horizontal axis + + clipBoxOnAxis(pixelPosition, 'x', minX, maxX, left, right); // Transform the box coordinate system back to canvas + + var newCanvasPosition = pixelToCanvas(element, pixelPosition); // Update the box with the new coordinates + + box.top = newCanvasPosition.y; + box.left = newCanvasPosition.x; +} +/* harmony default export */ __webpack_exports__["default"] = (clip); + +/***/ }), + +/***/ "./util/convertToVector3.js": +/*!**********************************!*\ + !*** ./util/convertToVector3.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return convertToVector3; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Convert an Array to a cornerstoneMath.Vector3 + * @export @public @method + * @name convertToVector3 + * + * @param {Array|cornerstoneMath.Vector3} arrayOrVector3 Input array or Vector3 + * @returns {cornerstoneMath.Vector3} + */ + +function convertToVector3(arrayOrVector3) { + var cornerstoneMath = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath; + + if (arrayOrVector3 instanceof cornerstoneMath.Vector3) { + return arrayOrVector3; + } + + var keys = Object.keys(arrayOrVector3); + + if (keys.includes('x') && keys.includes('y') && keys.includes('z')) { + return new cornerstoneMath.Vector3(arrayOrVector3.x, arrayOrVector3.y, arrayOrVector3.z); + } + + return new cornerstoneMath.Vector3(arrayOrVector3[0], arrayOrVector3[1], arrayOrVector3[2]); +} + +/***/ }), + +/***/ "./util/copyPoints.js": +/*!****************************!*\ + !*** ./util/copyPoints.js ***! + \****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Returns a copy of the points object. + * @public + * @function copyPoints + * + * @param {Object} points - The object to copy. + * @returns {Object} - The copy. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (points) { + var page = _copy(points.page); + + var image = _copy(points.image); + + var client = _copy(points.client); + + var canvas = _copy(points.canvas); + + return { + page: page, + image: image, + client: client, + canvas: canvas + }; +}); +/** + * + * @private + * @function _copy + * + * @param {Object} point - { x, y } + * @returns {Object} { x, y } + */ + +function _copy() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + x = _ref.x, + y = _ref.y; + + return { + x: x, + y: y + }; +} + +/***/ }), + +/***/ "./util/debounce.js": +/*!**************************!*\ + !*** ./util/debounce.js ***! + \**************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _isObject_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./isObject.js */ "./util/isObject.js"); + +/** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked, or until the next browser frame is drawn. The debounced function + * comes with a `cancel` method to cancel delayed `func` invocations and a + * `flush` method to immediately invoke them. Provide `options` to indicate + * whether `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. The `func` is invoked with the last arguments provided to the + * debounced function. Subsequent calls to the debounced function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the debounced function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until the next tick, similar to `setTimeout` with a timeout of `0`. + * + * If `wait` is omitted in an environment with `requestAnimationFrame`, `func` + * invocation will be deferred until the next frame is drawn (typically about + * 16ms). + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `debounce` and `throttle`. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] + * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is + * used (if available). + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // Avoid costly calculations while the window size is in flux. + * jQuery(window).on('resize', debounce(calculateLayout, 150)) + * + * // Invoke `sendMail` when clicked, debouncing subsequent calls. + * jQuery(element).on('click', debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })) + * + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. + * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 }) + * const source = new EventSource('/stream') + * jQuery(source).on('message', debounced) + * + * // Cancel the trailing debounced invocation. + * jQuery(window).on('popstate', debounced.cancel) + * + * // Check for pending invocations. + * const status = debounced.pending() ? "Pending..." : "Ready" + */ + +function debounce(func, wait, options) { + var lastArgs, lastThis, maxWait, result, timerId, lastCallTime; + var lastInvokeTime = 0; + var leading = false; + var maxing = false; + var trailing = true; // Bypass `requestAnimationFrame` by explicitly setting `wait=0`. + + var useRAF = !wait && wait !== 0 && typeof window.requestAnimationFrame === 'function'; + + if (typeof func !== 'function') { + throw new TypeError('Expected a function'); + } + + wait = Number(wait) || 0; + + if (Object(_isObject_js__WEBPACK_IMPORTED_MODULE_0__["default"])(options)) { + leading = Boolean(options.leading); + maxing = 'maxWait' in options; + maxWait = maxing ? Math.max(Number(options.maxWait) || 0, wait) : maxWait; + trailing = 'trailing' in options ? Boolean(options.trailing) : trailing; + } + + function invokeFunc(time) { + var args = lastArgs; + var thisArg = lastThis; + lastArgs = lastThis = undefined; + lastInvokeTime = time; + result = func.apply(thisArg, args); + return result; + } + + function startTimer(pendingFunc, wait) { + if (useRAF) { + return window.requestAnimationFrame(pendingFunc); + } + + return setTimeout(pendingFunc, wait); + } + + function cancelTimer(id) { + if (useRAF) { + return window.cancelAnimationFrame(id); + } + + clearTimeout(id); + } + + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time; // Start the timer for the trailing edge. + + timerId = startTimer(timerExpired, wait); // Invoke the leading edge. + + return leading ? invokeFunc(time) : result; + } + + function remainingWait(time) { + var timeSinceLastCall = time - lastCallTime; + var timeSinceLastInvoke = time - lastInvokeTime; + var timeWaiting = wait - timeSinceLastCall; + return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting; + } + + function shouldInvoke(time) { + var timeSinceLastCall = time - lastCallTime; + var timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + + return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; + } + + function timerExpired() { + var time = Date.now(); + + if (shouldInvoke(time)) { + return trailingEdge(time); + } // Restart the timer. + + + timerId = startTimer(timerExpired, remainingWait(time)); + } + + function trailingEdge(time) { + timerId = undefined; // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + + if (trailing && lastArgs) { + return invokeFunc(time); + } + + lastArgs = lastThis = undefined; + return result; + } + + function cancel() { + if (timerId !== undefined) { + cancelTimer(timerId); + } + + lastInvokeTime = 0; + lastArgs = lastCallTime = lastThis = timerId = undefined; + } + + function flush() { + return timerId === undefined ? result : trailingEdge(Date.now()); + } + + function pending() { + return timerId !== undefined; + } + + function debounced() { + var time = Date.now(); + var isInvoking = shouldInvoke(time); + + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + lastArgs = args; + lastThis = this; // eslint-disable-line consistent-this + + lastCallTime = time; + + if (isInvoking) { + if (timerId === undefined) { + return leadingEdge(lastCallTime); + } + + if (maxing) { + // Handle invocations in a tight loop. + timerId = startTimer(timerExpired, wait); + return invokeFunc(lastCallTime); + } + } + + if (timerId === undefined) { + timerId = startTimer(timerExpired, wait); + } + + return result; + } + + debounced.cancel = cancel; + debounced.flush = flush; + debounced.pending = pending; + return debounced; +} + +/* harmony default export */ __webpack_exports__["default"] = (debounce); + +/***/ }), + +/***/ "./util/debugLib/common.js": +/*!*********************************!*\ + !*** ./util/debugLib/common.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + */ +function setup(env) { + createDebug.debug = createDebug; + createDebug.default = createDebug; + createDebug.coerce = coerce; + createDebug.disable = disable; + createDebug.enable = enable; + createDebug.enabled = enabled; + createDebug.humanize = __webpack_require__(/*! ms */ "../node_modules/ms/index.js"); + Object.keys(env).forEach(function (key) { + createDebug[key] = env[key]; + }); + /** + * Active `debug` instances. + */ + + createDebug.instances = []; + /** + * The currently active debug mode names, and names to skip. + */ + + createDebug.names = []; + createDebug.skips = []; + /** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". + */ + + createDebug.formatters = {}; + /** + * Selects a color for a debug namespace + * @param {String} namespace The namespace string for the for the debug instance to be colored + * @returns {Number|String} An ANSI color code for the given namespace + * @api private + */ + + function selectColor(namespace) { + var hash = 0; + + for (var i = 0; i < namespace.length; i++) { + hash = (hash << 5) - hash + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; + } + + createDebug.selectColor = selectColor; + /** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @returns {Function} + * @api public + */ + + function createDebug(namespace) { + var prevTime; + + function debug() { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + // Disabled? + if (!debug.enabled) { + return; + } + + var self = debug; // Set `diff` timestamp + + var curr = Number(new Date()); + var ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + args[0] = createDebug.coerce(args[0]); + + if (typeof args[0] !== 'string') { + // Anything else let's inspect with %O + args.unshift('%O'); + } // Apply any `formatters` transformations + + + var index = 0; + args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) { + // If we encounter an escaped % then don't increase the array index + if (match === '%%') { + return match; + } + + index++; + var formatter = createDebug.formatters[format]; + + if (typeof formatter === 'function') { + var val = args[index]; + match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format` + + args.splice(index, 1); + index--; + } + + return match; + }); // Apply env-specific formatting (colors, etc.) + + createDebug.formatArgs.call(self, args); + var logFn = self.log || createDebug.log; + logFn.apply(self, args); + } + + debug.namespace = namespace; + debug.enabled = createDebug.enabled(namespace); + debug.useColors = createDebug.useColors(); + debug.color = selectColor(namespace); + debug.destroy = destroy; + debug.extend = extend; // Debug.formatArgs = formatArgs; + // debug.rawLog = rawLog; + // env-specific initialization logic for debug instances + + if (typeof createDebug.init === 'function') { + createDebug.init(debug); + } + + createDebug.instances.push(debug); + return debug; + } + + function destroy() { + var index = createDebug.instances.indexOf(this); + + if (index !== -1) { + createDebug.instances.splice(index, 1); + return true; + } + + return false; + } + + function extend(namespace, delimiter) { + var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); + newDebug.log = this.log; + return newDebug; + } + /** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + + + function enable(namespaces) { + createDebug.save(namespaces); + createDebug.names = []; + createDebug.skips = []; + var i; + var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); + var len = split.length; + + for (i = 0; i < len; i++) { + if (!split[i]) { + // Ignore empty strings + continue; + } + + namespaces = split[i].replace(/\*/g, '.*?'); + + if (namespaces[0] === '-') { + createDebug.skips.push(new RegExp("^".concat(namespaces.substr(1), "$"))); + } else { + createDebug.names.push(new RegExp("^".concat(namespaces, "$"))); + } + } + + for (i = 0; i < createDebug.instances.length; i++) { + var instance = createDebug.instances[i]; + instance.enabled = createDebug.enabled(instance.namespace); + } + } + /** + * Disable debug output. + * + * @returns {String} namespaces + * @api public + */ + + + function disable() { + var namespaces = [].concat(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(createDebug.names.map(toNamespace)), _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(createDebug.skips.map(toNamespace).map(function (namespace) { + return "-".concat(namespace); + }))).join(','); + createDebug.enable(''); + return namespaces; + } + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @returns {Boolean} + * @api public + */ + + + function enabled(name) { + if (name[name.length - 1] === '*') { + return true; + } + + var i; + var len; + + for (i = 0, len = createDebug.skips.length; i < len; i++) { + if (createDebug.skips[i].test(name)) { + return false; + } + } + + for (i = 0, len = createDebug.names.length; i < len; i++) { + if (createDebug.names[i].test(name)) { + return true; + } + } + + return false; + } + /** + * Convert regexp to namespace + * + * @param {RegExp} regxep + * @returns {String} namespace + * @api private + */ + + + function toNamespace(regexp) { + return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*'); + } + /** + * Coerce `val`. + * + * @param {Mixed} val + * @returns {Mixed} + * @api private + */ + + + function coerce(val) { + if (val instanceof Error) { + return val.stack || val.message; + } + + return val; + } + + createDebug.enable(createDebug.load()); + return createDebug; +} + +/* harmony default export */ __webpack_exports__["default"] = (setup); + +/***/ }), + +/***/ "./util/debugLib/index.js": +/*!********************************!*\ + !*** ./util/debugLib/index.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* WEBPACK VAR INJECTION */(function(process) {/* harmony import */ var _common_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./common.js */ "./util/debugLib/common.js"); +/* eslint-env browser */ + +/** + * This is the web browser implementation of `debug()`. + */ + +var storage = localstorage(); +var debugLib = { + formatArgs: formatArgs, + save: save, + load: load, + useColors: useColors, + storage: storage +}; +/** + * Colors. + */ + +debugLib.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33']; +/** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ +// eslint-disable-next-line complexity + +function useColors() { + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { + return true; + } // Internet Explorer and Edge do not support colors. + + + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } // Is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + + + return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773 + typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker + typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); +} +/** + * Colorize log arguments if enabled. + * + * @api public + */ + + +function formatArgs(args) { + args[0] = "".concat((this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' '), "+").concat(setupDebug.humanize(this.diff)); + + if (!this.useColors) { + return; + } + + var c = "color: ".concat(this.color); + args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + + var index = 0; + var lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, function (match) { + if (match === '%%') { + return; + } + + index++; + + if (match === '%c') { + // We only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + args.splice(lastC, 0, c); +} +/** + * Invokes `console.debug()` when available. + * No-op when `console.debug` is not a "function". + * If `console.debug` is not available, falls back + * to `console.log`. + * + * @api public + */ + + +debugLib.log = console.debug || console.log || function () {}; +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + + +function save(namespaces) { + try { + if (namespaces) { + debugLib.storage.setItem('debug', namespaces); + } else { + debugLib.storage.removeItem('debug'); + } + } catch (error) {// Swallow + // XXX (@Qix-) should we be logging these? + } +} +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + + +function load() { + var r; + + try { + r = debugLib.storage.getItem('debug'); + } catch (error) { + console.warn(error); + } // Swallow + // XXX (@Qix-) should we be logging these? + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + + + if (!r && typeof process !== 'undefined' && 'env' in process) { + r = process.env.DEBUG; + } + + return r; +} +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + + +function localstorage() { + try { + // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context + // The Browser also has localStorage in the global context. + return localStorage; + } catch (error) {// Swallow + // XXX (@Qix-) should we be logging these? + } +} + +var setupDebug = Object(_common_js__WEBPACK_IMPORTED_MODULE_0__["default"])(debugLib); +var formatters = setupDebug.formatters; +/** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + +formatters.j = function (v) { + try { + return JSON.stringify(v); + } catch (error) { + return "[UnexpectedJSONParseError]: ".concat(error.message); + } +}; + +/* harmony default export */ __webpack_exports__["default"] = (setupDebug); +/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/process/browser.js */ "../node_modules/process/browser.js"))) + +/***/ }), + +/***/ "./util/deepmerge.js": +/*!***************************!*\ + !*** ./util/deepmerge.js ***! + \***************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); + + +var isMergeableObject = function isMergeableObject(val) { + var nonNullObject = val && _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(val) === 'object'; + return nonNullObject && Object.prototype.toString.call(val) !== '[object RegExp]' && Object.prototype.toString.call(val) !== '[object Date]'; +}; + +var emptyTarget = function emptyTarget(val) { + var isEmpty = Array.isArray(val) ? [] : {}; + return isEmpty; +}; + +var cloneIfNecessary = function cloneIfNecessary(value, optionsArgument) { + var clone = optionsArgument && optionsArgument.clone === true; + return clone && isMergeableObject(value) ? deepmerge(emptyTarget(value), value, optionsArgument) : value; +}; + +var defaultArrayMerge = function defaultArrayMerge(target, source, optionsArgument) { + var destination = target.slice(); + source.forEach(function (e, i) { + if (typeof destination[i] === 'undefined') { + destination[i] = cloneIfNecessary(e, optionsArgument); + } else if (isMergeableObject(e)) { + destination[i] = deepmerge(target[i], e, optionsArgument); + } else if (target.indexOf(e) === -1) { + destination.push(cloneIfNecessary(e, optionsArgument)); + } + }); + return destination; +}; + +var mergeObject = function mergeObject(target, source, optionsArgument) { + var destination = {}; + + if (isMergeableObject(target)) { + Object.keys(target).forEach(function (key) { + destination[key] = cloneIfNecessary(target[key], optionsArgument); + }); + } + + Object.keys(source).forEach(function (key) { + if (!isMergeableObject(source[key]) || !target[key]) { + destination[key] = cloneIfNecessary(source[key], optionsArgument); + } else { + destination[key] = deepmerge(target[key], source[key], optionsArgument); + } + }); + return destination; +}; + +var deepmerge = function deepmerge() { + var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var optionsArgument = arguments.length > 2 ? arguments[2] : undefined; + var array = Array.isArray(source); + var options = optionsArgument || { + arrayMerge: defaultArrayMerge + }; + var arrayMerge = options.arrayMerge || defaultArrayMerge; + + if (array) { + return Array.isArray(target) ? arrayMerge(target, source, optionsArgument) : cloneIfNecessary(source, optionsArgument); + } + + var mergedObject = mergeObject(target, source, optionsArgument); + + if (Object.getPrototypeOf(target) !== Object.prototype) { + Object.setPrototypeOf(mergedObject, Object.getPrototypeOf(target)); + } + + return mergedObject; +}; + +/* harmony default export */ __webpack_exports__["default"] = (deepmerge); + +/***/ }), + +/***/ "./util/ellipse/calculateEllipseStatistics.js": +/*!****************************************************!*\ + !*** ./util/ellipse/calculateEllipseStatistics.js ***! + \****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _pointInEllipse_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pointInEllipse.js */ "./util/ellipse/pointInEllipse.js"); + +/** + * Calculates the statistics of an elliptical region of interest. + * + * @private + * @function calculateEllipseStatistics + * + * @param {number[]} sp - Array of the image data's pixel values. + * @param {Object} ellipse - { top, left, height, width } - An object describing the ellipse. + * @returns {Object} { count, mean, variance, stdDev, min, max } + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (sp, ellipse) { + var sum = 0; + var sumSquared = 0; + var count = 0; + var index = 0; + var min = null; + var max = null; + + for (var y = ellipse.top; y < ellipse.top + ellipse.height; y++) { + for (var x = ellipse.left; x < ellipse.left + ellipse.width; x++) { + var point = { + x: x, + y: y + }; + + if (Object(_pointInEllipse_js__WEBPACK_IMPORTED_MODULE_0__["default"])(ellipse, point)) { + if (min === null) { + min = sp[index]; + max = sp[index]; + } + + sum += sp[index]; + sumSquared += sp[index] * sp[index]; + min = Math.min(min, sp[index]); + max = Math.max(max, sp[index]); + count++; + } + + index++; + } + } + + if (count === 0) { + return { + count: count, + mean: 0.0, + variance: 0.0, + stdDev: 0.0, + min: 0.0, + max: 0.0 + }; + } + + var mean = sum / count; + var variance = sumSquared / count - mean * mean; + return { + count: count, + mean: mean, + variance: variance, + stdDev: Math.sqrt(variance), + min: min, + max: max + }; +}); + +/***/ }), + +/***/ "./util/ellipse/index.js": +/*!*******************************!*\ + !*** ./util/ellipse/index.js ***! + \*******************************/ +/*! exports provided: calculateEllipseStatistics, pointInEllipse, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _calculateEllipseStatistics_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./calculateEllipseStatistics.js */ "./util/ellipse/calculateEllipseStatistics.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "calculateEllipseStatistics", function() { return _calculateEllipseStatistics_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _pointInEllipse_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pointInEllipse.js */ "./util/ellipse/pointInEllipse.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "pointInEllipse", function() { return _pointInEllipse_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + + + // Named + + // Default + +/* harmony default export */ __webpack_exports__["default"] = ({ + calculateEllipseStatistics: _calculateEllipseStatistics_js__WEBPACK_IMPORTED_MODULE_0__["default"], + pointInEllipse: _pointInEllipse_js__WEBPACK_IMPORTED_MODULE_1__["default"] +}); + +/***/ }), + +/***/ "./util/ellipse/pointInEllipse.js": +/*!****************************************!*\ + !*** ./util/ellipse/pointInEllipse.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Returns true if a point is within an ellipse + * @export @public @method + * @name pointInEllipse + * + * @param {Object} ellipse Object defining the ellipse. + * @param {Object} location The location of the point. + * @returns {boolean} True if the point is within the ellipse. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (ellipse, location) { + var xRadius = ellipse.width / 2; + var yRadius = ellipse.height / 2; + + if (xRadius <= 0.0 || yRadius <= 0.0) { + return false; + } + + var center = { + x: ellipse.left + xRadius, + y: ellipse.top + yRadius + }; + /* This is a more general form of the circle equation + * + * X^2/a^2 + Y^2/b^2 <= 1 + */ + + var normalized = { + x: location.x - center.x, + y: location.y - center.y + }; + var inEllipse = normalized.x * normalized.x / (xRadius * xRadius) + normalized.y * normalized.y / (yRadius * yRadius) <= 1.0; + return inEllipse; +}); + +/***/ }), + +/***/ "./util/findAndMoveHelpers.js": +/*!************************************!*\ + !*** ./util/findAndMoveHelpers.js ***! + \************************************/ +/*! exports provided: moveHandleNearImagePoint, findHandleDataNearImagePoint, moveAnnotation */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "moveHandleNearImagePoint", function() { return moveHandleNearImagePoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findHandleDataNearImagePoint", function() { return findHandleDataNearImagePoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "moveAnnotation", function() { return moveAnnotation; }); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "../node_modules/@babel/runtime/helpers/defineProperty.js"); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _store_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/index.js */ "./store/index.js"); +/* harmony import */ var _manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../manipulators/getHandleNearImagePoint.js */ "./manipulators/getHandleNearImagePoint.js"); +/* harmony import */ var _manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../manipulators/index.js */ "./manipulators/index.js"); +/* harmony import */ var _getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./getProximityThreshold.js */ "./util/getProximityThreshold.js"); +/* harmony import */ var _events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../events */ "./events.js"); +/* harmony import */ var _triggerEvent__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./triggerEvent */ "./util/triggerEvent.js"); + + +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } + + + + + + + // TODO this should just be in manipulators? They are just manipulator wrappers anyway. + +/** + * Moves a handle near the image point. + * @public + * @function moveHandleNearImagePoint + * @memberof Util + * + * @param {Event} evt The event. + * @param {*} tool The tool + * @param {Object} toolData The toolData that corresponds to the handle. + * @param {Object} handle The handle to be moved. + * @param {string} interactionType + * @returns {undefined} + */ + +var moveHandleNearImagePoint = function moveHandleNearImagePoint(evt, tool, toolData, handle, interactionType) { + toolData.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = true; + + var doneHandler = function doneHandler(success) { + var element = evt.detail.element; + var toolName = toolData.toolType || toolData.toolName; + var modifiedEventData = { + toolName: toolName, + toolType: toolName, + // Deprecation notice: toolType will be replaced by toolName + element: element, + measurementData: _objectSpread({}, toolData, { + active: false + }) + }; + Object(_triggerEvent__WEBPACK_IMPORTED_MODULE_6__["default"])(element, _events__WEBPACK_IMPORTED_MODULE_5__["default"].MEASUREMENT_COMPLETED, modifiedEventData); + }; + + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveHandle"])(evt.detail, tool.name, toolData, handle, tool.options, interactionType, doneHandler); + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); + return; +}; +/** + * Finds the handle near the image point and its corresponding data. + * + * @public + * @function findHandleDataNearImagePoint + * @memberof Util + * + * @param {HTMLElement} element The elment. + * @param {Object} toolState The state of the tool. + * @param {string} toolName The name of the tool the handle corrosponds to. + * @param {Object} coords The coordinates that need to be checked. + * @param {String} [interactionType=mouse] + * @returns {*} + */ + + +var findHandleDataNearImagePoint = function findHandleDataNearImagePoint(element, toolState, toolName, coords) { + var interactionType = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'mouse'; + + for (var i = 0; i < toolState.data.length; i++) { + var data = toolState.data[i]; + var handle = Object(_manipulators_getHandleNearImagePoint_js__WEBPACK_IMPORTED_MODULE_2__["default"])(element, data.handles, coords, Object(_getProximityThreshold_js__WEBPACK_IMPORTED_MODULE_4__["default"])(interactionType, toolName)); + + if (handle) { + return { + handle: handle, + data: data + }; + } + } +}; +/** + * Moves an entire annotation near the click. + * + * @public + * @function moveAnnotation + * @memberof Util + * + * @param {Event} evt The event. + * @param {Object} tool The tool that the annotation belongs to. + * @param {string} tool.name + * @param {Object} [tool.options={}] + * @param {Boolean} [tool.options.preventHandleOutsideImage] + * @param {Boolean} [tool.options.deleteIfHandleOutsideImage] + * @param {Object} annotation The toolData that corresponds to the annotation. + * @param {String} [interactionType=mouse] + * @returns {undefined} + */ + + +var moveAnnotation = function moveAnnotation(evt, tool, annotation) { + var interactionType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse'; + annotation.active = true; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = true; + Object(_manipulators_index_js__WEBPACK_IMPORTED_MODULE_3__["moveAllHandles"])(evt.detail, tool.name, annotation, null, tool.options, interactionType, function () { + annotation.active = false; + _store_index_js__WEBPACK_IMPORTED_MODULE_1__["state"].isToolLocked = false; + }); + evt.stopImmediatePropagation(); + evt.stopPropagation(); + evt.preventDefault(); + return; +}; + + + +/***/ }), + +/***/ "./util/freehand/ClickedLineData.js": +/*!******************************************!*\ + !*** ./util/freehand/ClickedLineData.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ClickedLineData; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * @public + * @name ClickedLineData + * @classdesc Creates an object containing information about the clicked line. + * @property {number} toolIndex ID of the tool that the line corresponds to. + * @property {Object} handleIndexArray An array of the handle indicies that correspond to the line segment. + */ +var ClickedLineData = +/** + * Constructs an object containing information about the clicked line. + * @param {number} toolIndex - The ID of the tool the line corresponds to. + * @param {Object} handleIndexArray - An array of the handle indicies that correspond to the line segment. + */ +function ClickedLineData(toolIndex, handleIndexArray) { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, ClickedLineData); + + this.toolIndex = toolIndex; + this.handleIndexArray = handleIndexArray; +}; + + + +/***/ }), + +/***/ "./util/freehand/FreehandHandleData.js": +/*!*********************************************!*\ + !*** ./util/freehand/FreehandHandleData.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FreehandHandleData; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * @public + * @name FreehandHandleData + * @classdesc Creates a single handle for the freehand tool. + * + * @property {number} x The x position. + * @property {number} y The y position. + * @property {boolean} highlight Whether the handle should be rendered as the highlighted color. + * @property {boolean} active Whether the handle is active. + * @property {Object} lines An array of lines associated with the handle. + */ +var FreehandHandleData = +/** + * Constructs a a single handle for the freehand tool + * + * @param {Object} position - The position of the handle. + * @param {boolean} highlight - whether the handle should be rendered as the highlighted color. + * @param {boolean} active - whether the handle is active. + */ +function FreehandHandleData(position) { + var highlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var active = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FreehandHandleData); + + this.x = position.x; + this.y = position.y; + this.highlight = highlight; + this.active = active; + this.lines = []; +}; + + + +/***/ }), + +/***/ "./util/freehand/FreehandLineFinder.js": +/*!*********************************************!*\ + !*** ./util/freehand/FreehandLineFinder.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return FreehandLineFinder; }); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "../node_modules/@babel/runtime/helpers/classCallCheck.js"); +/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "../node_modules/@babel/runtime/helpers/createClass.js"); +/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _ClickedLineData_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./ClickedLineData.js */ "./util/freehand/ClickedLineData.js"); + + + + + +var distanceThreshold = 10; +/** + * @public + * @class FreehandLineFinder + * @classdesc Class that finds lines of freehand ROIs based on click proximity. + */ + +var FreehandLineFinder = +/*#__PURE__*/ +function () { + /** + * Creates an instance of FreehandLineFinder. + * @param {*} eventData - Data object associated with the event. + * @param {string} toolName - The tool name + * @memberof FreehandLineFinder + */ + function FreehandLineFinder(eventData, toolName) { + _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, FreehandLineFinder); + + this._eventData = eventData; + this._toolName = toolName; + } + /** + * Looks for lines near the mouse cursor. + * + * @public + * @method + * @returns {ClickedLineData} Data object corresponding to the clicked line. + */ + + + _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(FreehandLineFinder, [{ + key: "findLine", + value: function findLine() { + var closestToolIndex = this.findTool(); + + if (closestToolIndex === null) { + return null; + } + + var closeLines = this._getCloseLinesInTool(closestToolIndex); + + if (closeLines) { + var clickedLineData = this._findCorrectLine(closestToolIndex, closeLines); // Note: clickedLineData may be null if no valid projections are found. + + + return clickedLineData; + } // Return null if no valid close lines found. + + + return null; + } + /** + * Looks for tools near the mouse cursor. + * + * @public + * @method + * + * @returns {ClickedLineData} Data object corresponding to the clicked line. + */ + + }, { + key: "findTool", + value: function findTool() { + this._toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(this._eventData.element, this._toolName); + this._mousePoint = this._eventData.currentPoints.canvas; + + if (!this._toolData) { + return null; + } + + var closestHandle = this._nearestHandleToPointAllTools(); + + return closestHandle.toolIndex; + } + /** + * Finds the nearest handle to the mouse cursor for all tools. + * @private + * @method + * @returns {Object} The handle closest to the point. + */ + + }, { + key: "_nearestHandleToPointAllTools", + value: function _nearestHandleToPointAllTools() { + var toolData = this._toolData; + var closestHandle = { + toolIndex: null, + handleIndex: null, + distance: Infinity // Some large number + + }; + + for (var toolIndex = 0; toolIndex < toolData.data.length; toolIndex++) { + var closestHandleForToolI = this._nearestHandleToPoint(toolIndex); + + if (closestHandleForToolI === null) { + continue; + } + + if (closestHandleForToolI.distance < closestHandle.distance) { + closestHandle = closestHandleForToolI; + } + } + + return closestHandle; + } + /** + * Finds the nearest handle to the mouse cursor for a specific tool. + * @private + * @method + * + * @param {number} toolIndex The index of the particular freehand tool. + * @returns {Object} An object containing information about the closest handle. + */ + + }, { + key: "_nearestHandleToPoint", + value: function _nearestHandleToPoint(toolIndex) { + var eventData = this._eventData; + var toolData = this._toolData; + var data = toolData.data[toolIndex]; + var points = data.handles.points; + + if (points === undefined) { + return null; + } + + if (data.visible === false) { + return null; + } + + var closest = { + toolIndex: toolIndex, + handleIndex: null, + distance: Infinity // Some large number + + }; + + for (var i = 0; i < points.length; i++) { + var handleCanvas = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(eventData.element, points[i]); + var handleDistanceFromMousePoint = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstoneMath.point.distance(handleCanvas, this._mousePoint); + + if (handleDistanceFromMousePoint < closest.distance) { + closest.handleIndex = i; + closest.distance = handleDistanceFromMousePoint; + } + } + + return closest; + } + /** + * Finds all the lines close to the mouse point for a particular tool. + * @private + * @method + * + * @param {number} toolIndex The index of the particular freehand tool. + * @returns {Object} An array of lines close to the mouse point. + */ + + }, { + key: "_getCloseLinesInTool", + value: function _getCloseLinesInTool(toolIndex) { + var toolData = this._toolData; + var points = toolData.data[toolIndex].handles.points; + var closeLines = []; + + for (var i = 0; i < points.length; i++) { + var nextIndex = FreehandLineFinder.getNextHandleIndex(i, points.length); + + var d = this._distanceOfPointfromLine(points[i], points[nextIndex]); + + if (d < distanceThreshold) { + closeLines.push([i, nextIndex]); + } + } + + return closeLines; + } + /** + * Finds the line the user clicked on from an array of close lines.\ + * @private + * @method + * + * @param {number} toolIndex The index of the particular freehand tool. + * @param {Object} closeLines An array of lines close to the mouse point. + * @returns {ClickedLineData|null} An instance of ClickedLineData containing information about the line, or null if no line is correct. + */ + + }, { + key: "_findCorrectLine", + value: function _findCorrectLine(toolIndex, closeLines) { + // Test if any candidate lines can be projected onto by the mousePoint + for (var i = 0; i < closeLines.length; i++) { + if (this._pointProjectsToLineSegment(toolIndex, closeLines[i])) { + return new _ClickedLineData_js__WEBPACK_IMPORTED_MODULE_4__["default"](toolIndex, closeLines[i]); + } + } // No valid line found + + + return null; + } + /** + * Returns true if the mouse point projects onto the line segment. + * @private + * @method + * + * @param {number} toolIndex The index of the particular freehand tool. + * @param {Object} handleIndexArray An array of indicies corresponding to the line segment. + * @returns {boolean} True if the mouse point projects onto the line segment + */ + + }, { + key: "_pointProjectsToLineSegment", + value: function _pointProjectsToLineSegment(toolIndex, handleIndexArray) { + var eventData = this._eventData; + var toolData = this._toolData; + var data = toolData.data[toolIndex]; + var points = data.handles.points; + + if (data.handles.points === undefined) { + return; + } + + if (data.visible === false) { + return false; + } + + var handle1 = points[handleIndexArray[0]]; + var handle2 = points[handleIndexArray[1]]; + var p = FreehandLineFinder.getCanvasPointsFromHandles(handle1, handle2, eventData.element); + var r = FreehandLineFinder.getLineAsVector(p); + + var m = this._getLineOriginToMouseAsVector(p); // Project vector m onto r to see if the point is within bounds of line segment + + + var mProj = (m[0] * r[0] + m[1] * r[1]) / r.magnitude; + + if (mProj > 0 && mProj < r.magnitude) { + return true; + } + + return false; + } + /** + * Returns the canvas positions from the handle's pixel positions. + * + * @static + * @public + * @method + * @param {FreehandHandleData} handle1 The first handle. + * @param {FreehandHandleData} handle2 The second handle. + * @param {Object} element The element on which the handles reside. + * @returns {Object} An array contsining the handle positions in canvas coordinates. + */ + + }, { + key: "_getLineOriginToMouseAsVector", + + /** + * Constructs a vector from the direction and magnitude of the line from the the line origin to the mouse cursor. + * @private + * @method + * + * @param {Object} p An array of two points respresenting the line segment. + * @returns {Object} An array containing the x and y components of the vector. + */ + value: function _getLineOriginToMouseAsVector(p) { + var m = [this._mousePoint.x - p[0].x, this._mousePoint.y - p[0].y]; + return m; + } + /** + * Calculates the perpendicular distance of the mouse cursor from a line segment. + * @private + * @method + * + * @param {FreehandHandleData} handle1 The first handle. + * @param {FreehandHandleData} handle2 The first handle. + * @returns {number} The perpendicular distance of the mouse cursor from the line segment. + */ + + }, { + key: "_distanceOfPointfromLine", + value: function _distanceOfPointfromLine(handle1, handle2) { + var eventData = this._eventData; + var p1 = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(eventData.element, handle1); + var p2 = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(eventData.element, handle2); + var pMouse = this._mousePoint; // Perpendicular distance of point from line: + // = 2* area of triangle(p1,p2,pm) / length of triangle's base |p2 - p1| + + var twiceAreaOfTriangle = Math.abs((p2.y - p1.y) * pMouse.x - (p2.x - p1.x) * pMouse.y + p2.x * p1.y - p2.y * p1.x); + var rMagnitude = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstoneMath.point.distance(p1, p2); + var d = twiceAreaOfTriangle / rMagnitude; + return d; + } + /** + * Gets the next handl index from a cyclical array of points. + * + * @static + * @public + * @method + * + * @param {number} currentIndex The current index. + * @param {number} length The number of handles in the polygon. + * @returns {number} The index of the next handle. + */ + + }], [{ + key: "getCanvasPointsFromHandles", + value: function getCanvasPointsFromHandles(handle1, handle2, element) { + var p = []; // Point r from left to right so that we only have one orientation to test. + + if (handle1.x < handle2.x) { + p.push(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(element, handle1)); + p.push(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(element, handle2)); + } else { + p.push(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(element, handle2)); + p.push(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.pixelToCanvas(element, handle1)); + } + + return p; + } + /** + * Converts a line segment to a vector. + * + * @static + * @public + * @method + * @param {Object} p An array of two points respresenting the line segment. + * @returns {Object} An array containing the x and y components of the vector, as well as a magnitude property. + */ + + }, { + key: "getLineAsVector", + value: function getLineAsVector(p) { + var r = [p[1].x - p[0].x, p[1].y - p[0].y]; + r.magnitude = _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstoneMath.point.distance(p[0], p[1]); + return r; + } + }, { + key: "getNextHandleIndex", + value: function getNextHandleIndex(currentIndex, length) { + var nextIndex; + + if (currentIndex < length - 1) { + nextIndex = currentIndex + 1; + } else { + nextIndex = 0; + } + + return nextIndex; + } + }]); + + return FreehandLineFinder; +}(); + + + +/***/ }), + +/***/ "./util/freehand/addLine.js": +/*!**********************************!*\ + !*** ./util/freehand/addLine.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * AddLine - Adds a line to a specifc index of a freehand tool points array. + * + * @param {Object[]} points The array of points. + * @param {Number} insertIndex The index to insert the line. + * @returns {Null} description + */ +/* harmony default export */ __webpack_exports__["default"] = (function (points, insertIndex) { + // Add the line from the inserted handle to the handle after + if (insertIndex === points.length - 1) { + points[insertIndex].lines.push(points[0]); + } else { + points[insertIndex].lines.push(points[insertIndex + 1]); + } +}); + +/***/ }), + +/***/ "./util/freehand/calculateFreehandStatistics.js": +/*!******************************************************!*\ + !*** ./util/freehand/calculateFreehandStatistics.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _pointInFreehand_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pointInFreehand.js */ "./util/freehand/pointInFreehand.js"); + +/** + * Calculates the statistics of all the pixels within the freehand object. + * @export @public @method + * @name calculateFreehandStatistics + * + * @param {Object} sp An array of the pixel data. + * @param {Object} boundingBox Rectangular box enclosing the polygon. + * @param {Object} dataHandles Data object associated with the tool. + * @returns {Object} Object containing the derived statistics. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (sp, boundingBox, dataHandles) { + var statisticsObj = { + count: 0, + mean: 0.0, + variance: 0.0, + stdDev: 0.0 + }; + var sum = getSum(sp, boundingBox, dataHandles); + + if (sum.count === 0) { + return statisticsObj; + } + + statisticsObj.count = sum.count; + statisticsObj.mean = sum.value / sum.count; + statisticsObj.variance = sum.squared / sum.count - statisticsObj.mean * statisticsObj.mean; + statisticsObj.stdDev = Math.sqrt(statisticsObj.variance); + return statisticsObj; +}); +/** + * Calculates the sum, squared sum and count of all pixels within the polygon. + * @private + * @method + * @name getSum + * + * @param {Object} sp An array of the pixel data. + * @param {Object} boundingBox Rectangular box enclosing the polygon. + * @param {Object} dataHandles Data object associated with the tool. + * @returns {Object} Object containing the sum, squared sum and pixel count. + */ + +function getSum(sp, boundingBox, dataHandles) { + var sum = { + value: 0, + squared: 0, + count: 0 + }; + var index = 0; + + for (var y = boundingBox.top; y < boundingBox.top + boundingBox.height; y++) { + for (var x = boundingBox.left; x < boundingBox.left + boundingBox.width; x++) { + var point = { + x: x, + y: y + }; + sumPointIfInFreehand(dataHandles, point, sum, sp[index]); + index++; + } + } + + return sum; +} +/** + * Adds the pixel to the workingSum if it is within the polygon. + * @private + * @method sumPointIfInFreehand + * + * @param {Object} dataHandles Data object associated with the tool. + * @param {Object} point The pixel coordinates. + * @param {Object} workingSum The working sum, squared sum and pixel count. + * @param {Object} pixelValue The pixel value. // @modifies {workingSum} + * @returns {undefined} + */ + + +function sumPointIfInFreehand(dataHandles, point, workingSum, pixelValue) { + if (Object(_pointInFreehand_js__WEBPACK_IMPORTED_MODULE_0__["default"])(dataHandles, point)) { + workingSum.value += pixelValue; + workingSum.squared += pixelValue * pixelValue; + workingSum.count++; + } +} + +/***/ }), + +/***/ "./util/freehand/freehandArea.js": +/*!***************************************!*\ + !*** ./util/freehand/freehandArea.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Calculates the area of a freehand tool polygon. + * @export @public @method + * @name freehandArea + * + * @param {Object} dataHandles Data object associated with the tool. + * @param {Object} scaling Area scaling of image. + * @returns {number} The area of the polygon. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (dataHandles, scaling) { + var freeHandArea = 0; + var j = dataHandles.length - 1; // The last vertex is the previous one to the first + + scaling = scaling || 1; // If scaling is falsy, set scaling to 1 + + for (var i = 0; i < dataHandles.length; i++) { + freeHandArea += (dataHandles[j].x + dataHandles[i].x) * (dataHandles[j].y - dataHandles[i].y); + j = i; // Here j is previous vertex to i + } + + return Math.abs(freeHandArea * scaling / 2.0); +}); + +/***/ }), + +/***/ "./util/freehand/freehandIntersect.js": +/*!********************************************!*\ + !*** ./util/freehand/freehandIntersect.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Orientation algoritm to determine if two lines cross. + * Credit and details: geeksforgeeks.org/check-if-two-given-line-segments-intersect/ + */ + +/** + * Determines whether a new handle causes an intersection of the lines of the polygon. + * @public + * @function newHandle + * + * @param {Object} candidateHandle The new handle to check. + * @param {Object} dataHandles data object associated with the tool. + * @returns {boolean} - Whether the new line intersects with any other lines of the polygon. + */ +function newHandle(candidateHandle, dataHandles) { + // Check if the proposed line will intersect any existent line + var lastHandleId = dataHandles.length - 1; + var lastHandle = getCoords(dataHandles[lastHandleId]); + var newHandle = getCoords(candidateHandle); + return doesIntersectOtherLines(dataHandles, lastHandle, newHandle, [lastHandleId]); +} +/** + * Checks if the last line of a polygon will intersect the other lines of the polgyon. + * @public + * @function end + * + * @param {Object} dataHandles data object associated with the tool. + * @returns {boolean} Whether the last line intersects with any other lines of the polygon. + */ + + +function end(dataHandles) { + var lastHandleId = dataHandles.length - 1; + var lastHandle = getCoords(dataHandles[lastHandleId]); + var firstHandle = getCoords(dataHandles[0]); + return doesIntersectOtherLines(dataHandles, lastHandle, firstHandle, [lastHandleId, 0]); +} +/** + * Checks whether the modification of a handle's position causes intersection of the lines of the polygon. + * @public + * @method modify + * + * @param {Object} dataHandles Data object associated with the tool. + * @param {number} modifiedHandleId The id of the handle being modified. + * @returns {boolean} Whether the modfication causes any intersections. + */ + + +function modify(dataHandles, modifiedHandleId) { + // Check if the modifiedHandle's previous and next lines will intersect any other line in the polygon + var modifiedHandle = getCoords(dataHandles[modifiedHandleId]); // Previous neightbor handle + + var neighborHandleId = modifiedHandleId - 1; + + if (modifiedHandleId === 0) { + neighborHandleId = dataHandles.length - 1; + } + + var neighborHandle = getCoords(dataHandles[neighborHandleId]); + + if (doesIntersectOtherLines(dataHandles, modifiedHandle, neighborHandle, [modifiedHandleId, neighborHandleId])) { + return true; + } // Next neightbor handle + + + if (modifiedHandleId === dataHandles.length - 1) { + neighborHandleId = 0; + } else { + neighborHandleId = modifiedHandleId + 1; + } + + neighborHandle = getCoords(dataHandles[neighborHandleId]); + return doesIntersectOtherLines(dataHandles, modifiedHandle, neighborHandle, [modifiedHandleId, neighborHandleId]); +} +/** + * Checks whether the line (p1,q1) intersects any of the other lines in the polygon. + * @private + * @function doesIntersectOtherLines + * + * @param {Object} dataHandles Data object associated with the tool. + * @param {Object} p1 Coordinates of the start of the line. + * @param {Object} q1 Coordinates of the end of the line. + * @param {Object} ignoredHandleIds Ids of handles to ignore (i.e. lines that share a vertex with the line being tested). + * @returns {boolean} Whether the line intersects any of the other lines in the polygon. + */ + + +function doesIntersectOtherLines(dataHandles, p1, q1, ignoredHandleIds) { + var j = dataHandles.length - 1; + + for (var i = 0; i < dataHandles.length; i++) { + if (ignoredHandleIds.indexOf(i) !== -1 || ignoredHandleIds.indexOf(j) !== -1) { + j = i; + continue; + } + + var p2 = getCoords(dataHandles[j]); + var q2 = getCoords(dataHandles[i]); + + if (doesIntersect(p1, q1, p2, q2)) { + return true; + } + + j = i; + } + + return false; +} +/** + * Checks whether the line (p1,q1) intersects the line (p2,q2) via an orientation algorithm. + * @private + * @function doesIntersect + * + * @param {Object} p1 Coordinates of the start of the line 1. + * @param {Object} q1 Coordinates of the end of the line 1. + * @param {Object} p2 Coordinates of the start of the line 2. + * @param {Object} q2 Coordinates of the end of the line 2. + * @returns {boolean} Whether lines (p1,q1) and (p2,q2) intersect. + */ + + +function doesIntersect(p1, q1, p2, q2) { + var result = false; + var orient = [orientation(p1, q1, p2), orientation(p1, q1, q2), orientation(p2, q2, p1), orientation(p2, q2, q1)]; // General Case + + if (orient[0] !== orient[1] && orient[2] !== orient[3]) { + return true; + } // Special Cases + + + if (orient[0] === 0 && onSegment(p1, p2, q1)) { + // If p1, q1 and p2 are colinear and p2 lies on segment p1q1 + result = true; + } else if (orient[1] === 0 && onSegment(p1, q2, q1)) { + // If p1, q1 and p2 are colinear and q2 lies on segment p1q1 + result = true; + } else if (orient[2] === 0 && onSegment(p2, p1, q2)) { + // If p2, q2 and p1 are colinear and p1 lies on segment p2q2 + result = true; + } else if (orient[3] === 0 && onSegment(p2, q1, q2)) { + // If p2, q2 and q1 are colinear and q1 lies on segment p2q2 + result = true; + } + + return result; +} +/** + * Returns an object with two properties, x and y, from a heavier FreehandHandleData object. + * @private + * @function getCoords + * + * @param {Object} dataHandle Data object associated with a single handle in the freehand tool. + * @returns {Object} An object containing position propeties x and y. + */ + + +function getCoords(dataHandle) { + return { + x: dataHandle.x, + y: dataHandle.y + }; +} +/** + * Checks the orientation of 3 points. + * @private + * @function orientation + * + * @param {Object} p First point. + * @param {Object} q Second point. + * @param {Object} r Third point. + * @returns {number} - 0: Colinear, 1: Clockwise, 2: Anticlockwise + */ + + +function orientation(p, q, r) { + var orientationValue = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); + + if (orientationValue === 0) { + return 0; // Colinear + } + + return orientationValue > 0 ? 1 : 2; +} +/** + * Checks if point q lines on the segment (p,r). + * @private + * @function onSegment + * + * @param {Object} p Point p. + * @param {Object} q Point q. + * @param {Object} r Point r. + * @returns {boolean} - If q lies on line segment (p,r). + */ + + +function onSegment(p, q, r) { + if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y)) { + return true; + } + + return false; +} + +/* harmony default export */ __webpack_exports__["default"] = ({ + newHandle: newHandle, + end: end, + modify: modify +}); + +/***/ }), + +/***/ "./util/freehand/index.js": +/*!********************************!*\ + !*** ./util/freehand/index.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _calculateFreehandStatistics_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./calculateFreehandStatistics.js */ "./util/freehand/calculateFreehandStatistics.js"); +/* harmony import */ var _ClickedLineData_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ClickedLineData.js */ "./util/freehand/ClickedLineData.js"); +/* harmony import */ var _freehandArea_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./freehandArea.js */ "./util/freehand/freehandArea.js"); +/* harmony import */ var _FreehandHandleData_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./FreehandHandleData.js */ "./util/freehand/FreehandHandleData.js"); +/* harmony import */ var _freehandIntersect_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./freehandIntersect.js */ "./util/freehand/freehandIntersect.js"); +/* harmony import */ var _FreehandLineFinder_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./FreehandLineFinder.js */ "./util/freehand/FreehandLineFinder.js"); +/* harmony import */ var _insertOrDelete_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./insertOrDelete.js */ "./util/freehand/insertOrDelete.js"); +/* harmony import */ var _pointInFreehand_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./pointInFreehand.js */ "./util/freehand/pointInFreehand.js"); +/* harmony import */ var _addLine_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./addLine.js */ "./util/freehand/addLine.js"); + + + + + + + + + +/* harmony default export */ __webpack_exports__["default"] = ({ + calculateFreehandStatistics: _calculateFreehandStatistics_js__WEBPACK_IMPORTED_MODULE_0__["default"], + ClickedLineData: _ClickedLineData_js__WEBPACK_IMPORTED_MODULE_1__["default"], + freehandArea: _freehandArea_js__WEBPACK_IMPORTED_MODULE_2__["default"], + FreehandHandleData: _FreehandHandleData_js__WEBPACK_IMPORTED_MODULE_3__["default"], + freehandIntersect: _freehandIntersect_js__WEBPACK_IMPORTED_MODULE_4__["default"], + FreehandLineFinder: _FreehandLineFinder_js__WEBPACK_IMPORTED_MODULE_5__["default"], + insertOrDelete: _insertOrDelete_js__WEBPACK_IMPORTED_MODULE_6__["default"], + pointInFreehand: _pointInFreehand_js__WEBPACK_IMPORTED_MODULE_7__["default"], + addLine: _addLine_js__WEBPACK_IMPORTED_MODULE_8__["default"] +}); + +/***/ }), + +/***/ "./util/freehand/insertOrDelete.js": +/*!*****************************************!*\ + !*** ./util/freehand/insertOrDelete.js ***! + \*****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _FreehandLineFinder_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./FreehandLineFinder.js */ "./util/freehand/FreehandLineFinder.js"); +/* harmony import */ var _FreehandHandleData_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./FreehandHandleData.js */ "./util/freehand/FreehandHandleData.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _addLine_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./addLine.js */ "./util/freehand/addLine.js"); + + + + + +/** + * Inserts or deletes a point from a freehand tool. + * @export @public @method + * @name insertOrDelete + * + * @param {Object} evt The event. + * @param {Object} nearby Object containing information about a nearby handle. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (evt, nearby) { + var eventData = evt.detail; + + if (nearby && nearby.handleNearby !== null) { + var deleteInfo = { + toolIndex: nearby.toolIndex, + handleIndex: nearby.handleNearby + }; + + _deletePoint.call(this, eventData, deleteInfo); + } else { + var freehandLineFinder = new _FreehandLineFinder_js__WEBPACK_IMPORTED_MODULE_0__["default"](eventData, this.name); + var insertInfo = freehandLineFinder.findLine(); + + if (insertInfo) { + _insertPoint.call(this, eventData, insertInfo); + } + } +}); +/** + * Deletes a point from a freehand tool. + * @private + * @method + * + * @param {Object} eventData The data object associated with the event. + * @param {Object} deleteInfo Object containing information about which point to delete. + * @returns {void} + */ + +function _deletePoint(eventData, deleteInfo) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(eventData.element, this.name); + + if (toolData === undefined) { + return; + } + + var deleteHandle = deleteInfo.handleIndex; + var toolIndex = deleteInfo.toolIndex; // Get the toolData from insertInfo + + var data = toolData.data[toolIndex]; + var points = data.handles.points; // Only allow delete if > 3 points + + if (points.length <= 3) { + return; + } // Link the line of the previous handle to the one after handles[deleteHandle]; + + + if (deleteHandle === points.length - 1) { + points[deleteHandle - 1].lines.pop(); + points[deleteHandle - 1].lines.push(points[0]); + } else if (deleteHandle === 0) { + points[points.length - 1].lines.pop(); + points[points.length - 1].lines.push(points[deleteHandle + 1]); + } else { + points[deleteHandle - 1].lines.pop(); + points[deleteHandle - 1].lines.push(points[deleteHandle + 1]); + } // Remove the handle + + + points.splice(deleteHandle, 1); + data.invalidated = true; + data.active = true; + data.highlight = true; // Force onImageRendered to fire + + _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.updateImage(eventData.element); +} +/** + * Inserts a new point into a freehand tool. + * @private + * @method + * + * @param {Object} eventData - The data object associated with the event. + * @param {Object} insertInfo - Object containing information about where to insert the point. + * @returns {void} + */ + + +function _insertPoint(eventData, insertInfo) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(eventData.element, this.name); + + if (toolData === undefined) { + return; + } // Get the toolData from insertInfo + + + var data = toolData.data[insertInfo.toolIndex]; + + var insertIndex = _getInsertionIndex(insertInfo); + + if (insertIndex === Infinity) { + return; + } + + var handleData = new _FreehandHandleData_js__WEBPACK_IMPORTED_MODULE_1__["default"](eventData.currentPoints.image); + var points = data.handles.points; // Add the new handle + + points.splice(insertIndex, 0, handleData); // Add the line from the previous handle to the inserted handle (note the tool is now one increment longer) + + points[insertIndex - 1].lines.pop(); + points[insertIndex - 1].lines.push(eventData.currentPoints.image); + Object(_addLine_js__WEBPACK_IMPORTED_MODULE_4__["default"])(points, insertIndex); + data.active = true; + data.highlight = true; // Force onImageRendered to fire + + data.invalidated = true; + _externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.updateImage(eventData.element); +} +/** + * Gets the handle index of a tool in which to insert the new point. + * @private + * @method + * + * @param {Object} insertInfo - Object containing information about where to insert the point. + * @returns {void} + */ + + +function _getInsertionIndex(insertInfo) { + // Get lowest index that isn't zero + var handleIndexArray = insertInfo.handleIndexArray; + var insertIndex = Infinity; + var arrayContainsZero = handleIndexArray.includes(0); + + for (var i = 0; i < handleIndexArray.length; i++) { + var index = handleIndexArray[i]; + + if (index !== 0 && index < insertIndex) { + insertIndex = index; + } + } // Treat the special case of handleIndexArray === [0,1] || [1,0] + + + if (arrayContainsZero && insertIndex === 1) { + insertIndex = 0; + } // The insertion index shall be just after the lower index + + + insertIndex++; + return insertIndex; +} + +/***/ }), + +/***/ "./util/freehand/pointInFreehand.js": +/*!******************************************!*\ + !*** ./util/freehand/pointInFreehand.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Calculates whether "location" is inside the polygon defined by dataHandles + * by counting the number of times a ray originating from "point" crosses the + * edges of the polygon. Odd === inside, Even === outside. + * @export @public @method + * @name pointInFreehand + * + * @param {Object} dataHandles Data object associated with the tool. + * @param {Object} location The coordinates being queried. + * @returns {boolean} True if the location is inside the polygon defined by dataHandles. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (dataHandles, location) { + var inROI = false; // Cycle round pairs of points + + var j = dataHandles.length - 1; // The last vertex is the previous one to the first + + for (var i = 0; i < dataHandles.length; i++) { + if (rayFromPointCrosssesLine(location, dataHandles[i], dataHandles[j])) { + inROI = !inROI; + } + + j = i; // Here j is previous vertex to i + } + + return inROI; +}); +/** + * Returns true if the y-position yp is enclosed within y-positions y1 and y2. + * @private + * @method + * @name isEnclosedY + * + * @param {number} yp The y position of point p. + * @param {number} y1 The y position of point 1. + * @param {number} y2 The y position of point 2. + * @returns {boolean} True if the y-position yp is enclosed within y-positions y1 and y2. + */ + +function isEnclosedY(yp, y1, y2) { + if (y1 < yp && yp < y2 || y2 < yp && yp < y1) { + return true; + } + + return false; +} +/** + * Returns true if the line segment is to the right of the point. + * @private + * @method + * @name isLineRightOfPoint + * + * @param {Object} point The point being queried. + * @param {Object} lp1 The first point of the line segment. + * @param {Object} lp2 The second point of the line segment. + * @returns {boolean} True if the line is to the right of the point. + */ + + +function isLineRightOfPoint(point, lp1, lp2) { + // If both right of point return true + if (lp1.x > point.x && lp2.x > point.x) { + return true; + } // Catch when line is vertical. + + + if (lp1.x === lp2.x) { + return point.x < lp1.x; + } // Put leftmost point in lp1 + + + if (lp1.x > lp2.x) { + var lptemp = lp1; + lp1 = lp2; + lp2 = lptemp; + } + + var lPointY = lineSegmentAtPoint(point, lp1, lp2); // If the lp1.x and lp2.x enclose point.x check gradient of line and see if + // Point is above or below the line to calculate if it inside. + + if (Math.sign(lPointY.gradient) * point.y > Math.sign(lPointY.gradient) * lPointY.value) { + return true; + } + + return false; +} +/** + * Returns the y value of the line segment at the x value of the point. + * @private + * @method + * @name lineSegmentAtPoint + * + * @param {Object} point The point being queried. + * @param {Object} lp1 The first point of the line segment. + * @param {Object} lp2 The second point of the line segment. + * @returns {Object} An object containing the y value as well as the gradient of the line segment. + */ + + +function lineSegmentAtPoint(point, lp1, lp2) { + var dydx = (lp2.y - lp1.y) / (lp2.x - lp1.x); + var fx = { + value: lp1.y + dydx * (point.x - lp1.x), + gradient: dydx + }; + return fx; +} +/** + * Returns true if a rightwards ray originating from the point crosses the line defined by handleI and handleJ. + * @private + * @method + * @name rayFromPointCrosssesLine + * + * @param {Object} point The point being queried. + * @param {Object} handleI The first handle of the line segment. + * @param {Object} handleJ The second handle of the line segment. + * @returns {boolean} True if a rightwards ray originating from the point crosses the line defined by handleI and handleJ. + */ + + +function rayFromPointCrosssesLine(point, handleI, handleJ) { + if (isEnclosedY(point.y, handleI.y, handleJ.y) && isLineRightOfPoint(point, handleI, handleJ)) { + return true; + } + + return false; +} + +/***/ }), + +/***/ "./util/getActiveTool.js": +/*!*******************************!*\ + !*** ./util/getActiveTool.js ***! + \*******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getActiveTool; }); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store */ "./store/index.js"); +/* harmony import */ var _store_getActiveToolsForElement__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../store/getActiveToolsForElement */ "./store/getActiveToolsForElement.js"); +/* harmony import */ var _store_filterToolsUsableWithMultiPartTools__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../store/filterToolsUsableWithMultiPartTools */ "./store/filterToolsUsableWithMultiPartTools.js"); + + + // Todo: We could simplify this if we only allow one active +// Tool per mouse button mask? + +function getActiveTool(element, buttons) { + var interactionType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'mouse'; + var tools; + + if (interactionType === 'touch') { + tools = Object(_store_getActiveToolsForElement__WEBPACK_IMPORTED_MODULE_1__["default"])(element, _store__WEBPACK_IMPORTED_MODULE_0__["getters"].touchTools()); + tools = tools.filter(function (tool) { + return tool.options.isTouchActive; + }); + } else { + // Filter out disabled, enabled, and passive + tools = Object(_store_getActiveToolsForElement__WEBPACK_IMPORTED_MODULE_1__["default"])(element, _store__WEBPACK_IMPORTED_MODULE_0__["getters"].mouseTools()); // Filter out tools that do not match mouseButtonMask + + tools = tools.filter(function (tool) { + return Array.isArray(tool.options.mouseButtonMask) && buttons && tool.options.mouseButtonMask.includes(buttons) && tool.options.isMouseActive; + }); + + if (_store__WEBPACK_IMPORTED_MODULE_0__["state"].isMultiPartToolActive) { + tools = Object(_store_filterToolsUsableWithMultiPartTools__WEBPACK_IMPORTED_MODULE_2__["default"])(tools); + } + } + + if (tools.length === 0) { + return; + } + + return tools[0]; +} + +/***/ }), + +/***/ "./util/getCircleCoords.js": +/*!*********************************!*\ + !*** ./util/getCircleCoords.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getCircleCoords; }); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules */ "./externalModules.js"); + +/** + * Retrieve the bounds of the circle in image coordinates + * + * @param {*} startHandle + * @param {*} endHandle + * @returns {{ left: number, top: number, width: number, height: number }} + */ + +function getCircleCoords(startHandle, endHandle) { + var distance = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance; + var radius = distance(startHandle, endHandle); + return { + left: Math.floor(Math.min(startHandle.x - radius, endHandle.x)), + top: Math.floor(Math.min(startHandle.y - radius, endHandle.y)), + width: radius * 2, + height: radius * 2 + }; +} + +/***/ }), + +/***/ "./util/getDefault.js": +/*!****************************!*\ + !*** ./util/getDefault.js ***! + \****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Returns the first argument if defined, otherwise returns the second + * + * @param {*} value + * @param {*} defaultValue + * @returns {*} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (value, defaultValue) { + return value === undefined ? defaultValue : value; +}); + +/***/ }), + +/***/ "./util/getKeyPressData.js": +/*!*********************************!*\ + !*** ./util/getKeyPressData.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getKeyPressData; }); +/* harmony import */ var _store___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/ */ "./store/index.js"); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules */ "./externalModules.js"); + + +function getKeyPressData(e) { + var cornerstone = _externalModules__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone; + var element = e.currentTarget; + var enabledElement = cornerstone.getEnabledElement(element); + + if (!enabledElement || !enabledElement.image) { + return; + } + + var currentPointsImage = _store___WEBPACK_IMPORTED_MODULE_0__["default"].state.mousePositionImage; + return { + event: window.event || e, + // Old IE support + element: element, + viewport: cornerstone.getViewport(element), + image: enabledElement.image, + currentPoints: { + image: currentPointsImage, + canvas: cornerstone.pixelToCanvas(element, currentPointsImage) + }, + keyCode: e.keyCode, + which: e.which + }; +} + +/***/ }), + +/***/ "./util/getLuminance.js": +/*!******************************!*\ + !*** ./util/getLuminance.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Returns the luminance of a region. + * @public + * @function getLuminance + * + * @param {HTMLElement} element The element. + * @param {number} x The x position of the top-left corner of the region. + * @param {number} y The y position of the top-left corner of the region. + * @param {number} width The width of the region. + * @param {number} height The height of the region + * @returns {number[]} The luminance. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, x, y, width, height) { + if (!element) { + throw new Error('getLuminance: parameter element must not be undefined'); + } + + x = Math.round(x); + y = Math.round(y); + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + var image = enabledElement.image; + var luminance = []; + var index = 0; + var pixelData = image.getPixelData(); + var spIndex, row, column; + + if (image.color) { + for (row = 0; row < height; row++) { + for (column = 0; column < width; column++) { + spIndex = ((row + y) * image.columns + (column + x)) * 4; + var red = pixelData[spIndex]; + var green = pixelData[spIndex + 1]; + var blue = pixelData[spIndex + 2]; + luminance[index++] = 0.2126 * red + 0.7152 * green + 0.0722 * blue; + } + } + } else { + for (row = 0; row < height; row++) { + for (column = 0; column < width; column++) { + spIndex = (row + y) * image.columns + (column + x); + luminance[index++] = pixelData[spIndex] * image.slope + image.intercept; + } + } + } + + return luminance; +}); + +/***/ }), + +/***/ "./util/getMaxSimultaneousRequests.js": +/*!********************************************!*\ + !*** ./util/getMaxSimultaneousRequests.js ***! + \********************************************/ +/*! exports provided: getDefaultSimultaneousRequests, getMaxSimultaneousRequests, setMaxSimultaneousRequests, getBrowserInfo, isMobileDevice */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDefaultSimultaneousRequests", function() { return getDefaultSimultaneousRequests; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getMaxSimultaneousRequests", function() { return getMaxSimultaneousRequests; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setMaxSimultaneousRequests", function() { return setMaxSimultaneousRequests; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getBrowserInfo", function() { return getBrowserInfo; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMobileDevice", function() { return isMobileDevice; }); +var configMaxSimultaneousRequests; // Maximum concurrent connections to the same server +// Information from http://sgdev-blog.blogspot.fr/2014/01/maximum-concurrent-connection-to-same.html + +var maxSimultaneousRequests = { + default: 6, + IE: { + 9: 6, + 10: 8, + default: 8 + }, + Firefox: { + default: 6 + }, + Opera: { + 10: 8, + 11: 6, + 12: 6, + default: 6 + }, + Chrome: { + default: 6 + }, + Safari: { + default: 6 + } +}; // Browser name / version detection +// +// + +/** + * Browser name / version detection + * http://stackoverflow.com/questions/2400935/browser-detection-in-javascript + * @export @public @method + * @name getBrowserInfo + * + * @returns {string} The name and version of the browser. + */ + +function getBrowserInfo() { + var ua = navigator.userAgent; + var M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; + var tem; + + if (/trident/i.test(M[1])) { + tem = /\brv[ :]+(\d+)/g.exec(ua) || []; + return "IE ".concat(tem[1] || ''); + } + + if (M[1] === 'Chrome') { + tem = ua.match(/\b(OPR|Edge)\/(\d+)/); + + if (tem !== null) { + return tem.slice(1).join(' ').replace('OPR', 'Opera'); + } + } + + M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; + + if ((tem = ua.match(/version\/(\d+)/i)) !== null) { + M.splice(1, 1, tem[1]); + } + + return M.join(' '); +} +/** + * Sets the maximum number of simultaneous requests. + * @export @public @method + * @name setMaxSimultaneousRequests + * + * @param {number} newMaxSimultaneousRequests The value. + * @returns {void} + */ + + +function setMaxSimultaneousRequests(newMaxSimultaneousRequests) { + configMaxSimultaneousRequests = newMaxSimultaneousRequests; +} +/** + * Returns the maximum number of simultaneous requests. + * @export @public @method + * @name getMaxSimultaneousRequests + * + * @returns {number} The maximum number of simultaneous requests + */ + + +function getMaxSimultaneousRequests() { + if (configMaxSimultaneousRequests) { + return configMaxSimultaneousRequests; + } + + return getDefaultSimultaneousRequests(); +} +/** + * Returns the default number of simultaneous requests. + * @export @public @method + * @name getDefaultSimultaneousRequests + * + * @returns {number} The default number of simultaneous requests. + */ + + +function getDefaultSimultaneousRequests() { + var infoString = getBrowserInfo(); + var info = infoString.split(' '); + var browserName = info[0]; + var browserVersion = info[1]; + var browserData = maxSimultaneousRequests[browserName]; + + if (!browserData) { + return maxSimultaneousRequests.default; + } + + if (!browserData[browserVersion]) { + return browserData.default; + } + + return browserData[browserVersion]; +} +/** + * Checks if cornerstoneTools is operating on a mobile device. + * @export @public @method + * @name isMobileDevice + * + * @returns {boolean} True if running on a mobile device. + */ + + +function isMobileDevice() { + var pattern = new RegExp('Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini'); + return pattern.test(navigator.userAgent); +} + + + +/***/ }), + +/***/ "./util/getPixelSpacing.js": +/*!*********************************!*\ + !*** ./util/getPixelSpacing.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getPixelSpacing; }); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules */ "./externalModules.js"); + +function getPixelSpacing(image) { + var imagePlane = _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.metaData.get('imagePlaneModule', image.imageId); + + if (imagePlane) { + return { + rowPixelSpacing: imagePlane.rowPixelSpacing || imagePlane.rowImagePixelSpacing, + colPixelSpacing: imagePlane.columnPixelSpacing || imagePlane.colImagePixelSpacing + }; + } + + return { + rowPixelSpacing: image.rowPixelSpacing, + colPixelSpacing: image.columnPixelSpacing + }; +} + +/***/ }), + +/***/ "./util/getProximityThreshold.js": +/*!***************************************!*\ + !*** ./util/getProximityThreshold.js ***! + \***************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getProximityThreshold; }); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store */ "./store/index.js"); + +/** + * Returns the proximity threshold for the given interaction type, looking first + * at the tool configuration and then at global configuration. + * + * @public + * @function getProximityThreshold + * + * @param {string} interactionType The interaction type (mouse or touch) + * @param {string} toolName The name of the tool + * @returns {Number} The proximity threshold based on the tool + */ + +function getProximityThreshold(interactionType, toolName) { + var clickProximity = _store__WEBPACK_IMPORTED_MODULE_0__["state"].clickProximity, + touchProximity = _store__WEBPACK_IMPORTED_MODULE_0__["state"].touchProximity; + var tool = _store__WEBPACK_IMPORTED_MODULE_0__["state"].tools.find(function (_ref) { + var name = _ref.name; + return name === toolName; + }); + + if (tool && tool.configuration) { + clickProximity = tool.configuration.clickProximity || clickProximity; + touchProximity = tool.configuration.touchProximity || touchProximity; + } + + return interactionType === 'mouse' ? clickProximity : touchProximity; +} + +/***/ }), + +/***/ "./util/getRGBPixels.js": +/*!******************************!*\ + !*** ./util/getRGBPixels.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Gets pixels of an RGB image. + * @export @public @method + * @name getRGBPixels + * + * @param {HTMLElement} element The element. + * @param {number} x The x position of the top-left corner of the region. + * @param {number} y The y position of the top-left corner of the region. + * @param {number} width The width of the region. + * @param {number} height The height of the region + * @returns {number[]} The pixel data. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, x, y, width, height) { + if (!element) { + throw new Error('getRGBPixels: parameter element must not be undefined'); + } + + x = Math.round(x); + y = Math.round(y); + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + var storedPixelData = []; + var index = 0; + var pixelData = enabledElement.image.getPixelData(); + var spIndex, row, column; + + if (enabledElement.image.color) { + for (row = 0; row < height; row++) { + for (column = 0; column < width; column++) { + spIndex = ((row + y) * enabledElement.image.columns + (column + x)) * 4; + var red = pixelData[spIndex]; + var green = pixelData[spIndex + 1]; + var blue = pixelData[spIndex + 2]; + var alpha = pixelData[spIndex + 3]; + storedPixelData[index++] = red; + storedPixelData[index++] = green; + storedPixelData[index++] = blue; + storedPixelData[index++] = alpha; + } + } + } + + return storedPixelData; +}); + +/***/ }), + +/***/ "./util/getROITextBoxCoords.js": +/*!*************************************!*\ + !*** ./util/getROITextBoxCoords.js ***! + \*************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getROITextBoxCoords; }); +/** + * Determine the coordinates that will place the textbox to the right of the + * annotation, taking rotation, hflip, and vflip into account. + * + * @param {Object} viewport - The object that stores rotation, hflip, and vflip. + * @param {Object} handles - The handles of the annotation. + * @returns {Object} - The coordinates for default placement of the textbox + */ +function getROITextBoxCoords(viewport, handles) { + var corners = _determineCorners(handles); + + var centerX = (corners.left.x + corners.right.x) / 2; + var centerY = (corners.top.y + corners.bottom.y) / 2; + var textBox = {}; + + if (viewport.rotation >= 0 && viewport.rotation < 90) { + textBox.x = viewport.hflip ? corners.left.x : corners.right.x; + textBox.y = centerY; + } + + if (viewport.rotation >= 90 && viewport.rotation < 180) { + textBox.x = centerX; + textBox.y = viewport.vflip ? corners.bottom.y : corners.top.y; + } + + if (viewport.rotation >= 180 && viewport.rotation < 270) { + textBox.x = viewport.hflip ? corners.right.x : corners.left.x; + textBox.y = centerY; + } + + if (viewport.rotation >= 270 && viewport.rotation < 360) { + textBox.x = centerX; + textBox.y = viewport.vflip ? corners.top.y : corners.bottom.y; + } + + return textBox; +} +/** + * Determine the handles that have the min/max x and y values. + * + * @param {Object} handles - The handles of the annotation. + * @returns {Object} - The top, left, bottom, and right handles + */ + +function _determineCorners(handles) { + var handlesLeftToRight = [handles.start, handles.end].sort(_compareX); + var handlesTopToBottom = [handles.start, handles.end].sort(_compareY); + var left = handlesLeftToRight[0]; + var right = handlesLeftToRight[handlesLeftToRight.length - 1]; + var top = handlesTopToBottom[0]; + var bottom = handlesTopToBottom[handlesTopToBottom.length - 1]; + return { + top: top, + left: left, + bottom: bottom, + right: right + }; + + function _compareX(a, b) { + return a.x < b.x ? -1 : 1; + } + + function _compareY(a, b) { + return a.y < b.y ? -1 : 1; + } +} + +/***/ }), + +/***/ "./util/isEmptyObject.js": +/*!*******************************!*\ + !*** ./util/isEmptyObject.js ***! + \*******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Helper to determine if an object has no keys and is the correct type (is empty) + * + * @private + * @function isEmptyObject + * @param {Object} obj The object to check + * @returns {Boolean} true if the object is empty + */ +var isEmptyObject = function isEmptyObject(obj) { + return Object.keys(obj).length === 0 && obj.constructor === Object; +}; + +/* harmony default export */ __webpack_exports__["default"] = (isEmptyObject); + +/***/ }), + +/***/ "./util/isObject.js": +/*!**************************!*\ + !*** ./util/isObject.js ***! + \**************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "../node_modules/@babel/runtime/helpers/typeof.js"); +/* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * isObject({}) + * // => true + * + * isObject([1, 2, 3]) + * // => true + * + * isObject(Function) + * // => true + * + * isObject(null) + * // => false + */ +function isObject(value) { + var type = _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(value); + + return value !== null && (type === 'object' || type === 'function'); +} + +/* harmony default export */ __webpack_exports__["default"] = (isObject); + +/***/ }), + +/***/ "./util/isPointInImage.js": +/*!********************************!*\ + !*** ./util/isPointInImage.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return isPointInImage; }); +/** + * Checks if the point is within the image boundaries. + * @param {Object} pixel The pixel. + * @param {number} rows The number of rows. + * @param {number} cols The number of columns. + * @returns {boolean} + */ +function isPointInImage(_ref, rows, cols) { + var x = _ref.x, + y = _ref.y; + return x < cols && x >= 0 && y < rows && y >= 0; +} + +/***/ }), + +/***/ "./util/isPointInPolygon.js": +/*!**********************************!*\ + !*** ./util/isPointInPolygon.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return isPointInPolygon; }); +/** + * Checks whether a point is inside a polygon + * + * {@link https://github.com/substack/point-in-polygon/blob/master/index.js} + * ray-casting algorithm based on + * {@link http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html} + * + * @param {Array} point The point [x1, y1] + * @param {Array} vs The vertices [[x1, y1], [x2, y2], ...] of the Polygon + * @returns {boolean} + */ +function isPointInPolygon(point, vs) { + var x = point[0]; + var y = point[1]; + var inside = false; + + for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) { + var xi = vs[i][0]; + var yi = vs[i][1]; + var xj = vs[j][0]; + var yj = vs[j][1]; + var intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi; + + if (intersect) { + inside = !inside; + } + } + + return inside; +} + +/***/ }), + +/***/ "./util/lineSegDistance.js": +/*!*********************************!*\ + !*** ./util/lineSegDistance.js ***! + \*********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Calculates the distance of a line segment from a point. + * @export @public @method + * @name lineSegDistance + * + * @param {HTMLElement} element The element. + * @param {Object} start The starting position of the line. + * @param {Object} end The end position of the line. + * @param {Object} coords The coordinates of the point. + * @returns {name} The distance between the line and the point. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, start, end, coords) { + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone; + var lineSegment = { + start: cornerstone.pixelToCanvas(element, start), + end: cornerstone.pixelToCanvas(element, end) + }; + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords); +}); + +/***/ }), + +/***/ "./util/logger.js": +/*!************************!*\ + !*** ./util/logger.js ***! + \************************/ +/*! exports provided: getLogger, enable, disable */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLogger", function() { return getLogger; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "enable", function() { return enable; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "disable", function() { return disable; }); +/* harmony import */ var _debugLib_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./debugLib/index.js */ "./util/debugLib/index.js"); + +var BASE_SCOPE = 'cornerstoneTools'; +var baseLogger = Object(_debugLib_index_js__WEBPACK_IMPORTED_MODULE_0__["default"])(BASE_SCOPE); // eslint-disable-next-line no-process-env + +var devMode = "development" === 'development'; // If we're in dev-mode, tell the user how to get logs + +if (devMode && !baseLogger.enabled) { + // eslint-disable-next-line no-console + console.log('%cCornerstone Tools', 'background: #339955; padding: 4px; font-weight: bold; color: white'); // eslint-disable-next-line no-console + + console.info('run %clocalStorage.setItem("debug", "cornerstoneTools")%c to see console output', 'background: #eaeaea; color: #333; font-family: monospace', ''); +} +/** + * @method debug + * Create's a scoped debuging logger + */ + + +var getLogger = function getLogger(scope) { + var log = baseLogger.extend(scope); + return { + log: log, + // eslint-disable-next-line no-console + warn: devMode ? console.warn.bind(console) : log, + // eslint-disable-next-line no-console + error: console.error.bind(console) + }; +}; +/** + * @method enable + * @param {string} scope The scope to enabled + * @returns {void} + */ + +var enable = function enable() { + var scope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "".concat(BASE_SCOPE, ":*"); + return _debugLib_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].enable(scope); +}; +/** + * @method disable + * @param {string} scope + * @returns {string} The previously enabled scope + */ + +var disable = function disable() { + return _debugLib_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].disable(); +}; + +/***/ }), + +/***/ "./util/makeUnselectable.js": +/*!**********************************!*\ + !*** ./util/makeUnselectable.js ***! + \**********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * A helper function to make an element (and its content) being non selectable. + * @export @public @method + * @name makeUnselectable + * + * @param {HTMLElement} element The element to make unselectable + * @param {Boolean} ignorePointerEvents true to make this element also + * ignore events (e.g. mouse click), false otherwise. + * @returns {void} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (element, ignorePointerEvents) { + element.style.webkitUserSelect = 'none'; + element.style.webkitTouchCallout = 'none'; + element.style.mozUserSelect = 'none'; + element.style.msUserSelect = 'none'; + element.style.oUserSelect = 'none'; + element.style.khtmlUserSelect = 'none'; + element.style.userSelect = 'none'; + element.unselectable = 'on'; + + element.oncontextmenu = function () { + return false; + }; + + if (ignorePointerEvents === true) { + element.style.pointerEvents = 'none'; + } +}); + +/***/ }), + +/***/ "./util/numbersWithCommas.js": +/*!***********************************!*\ + !*** ./util/numbersWithCommas.js ***! + \***********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Converts a number to a string with comma separators. + * http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript + * @export @public @method + * @name numbersWithCommas + * + * @param {number} x The number to convert. + * @returns {string} The pretty-printed number as a string. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (x) { + var parts = x.toString().split('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); + return parts.join('.'); +}); + +/***/ }), + +/***/ "./util/pointInsideBoundingBox.js": +/*!****************************************!*\ + !*** ./util/pointInsideBoundingBox.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Returns true if a point is enclosed within a bounding box. + * @export @public @method + * @name pointInsideBoundingBox + * + * @param {Object} handle The handle containing the boundingBox. + * @param {Object} coords The coordinate to check. + * @returns {boolean} True if the point is enclosed within the bounding box. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (handle, coords) { + if (!handle.boundingBox) { + return; + } + + return _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.insideRect(coords, handle.boundingBox); +}); + +/***/ }), + +/***/ "./util/pointProjector.js": +/*!********************************!*\ + !*** ./util/pointProjector.js ***! + \********************************/ +/*! exports provided: projectPatientPointToImagePlane, imagePointToPatientPoint, planePlaneIntersection, rotatePoint */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "projectPatientPointToImagePlane", function() { return projectPatientPointToImagePlane; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "imagePointToPatientPoint", function() { return imagePointToPatientPoint; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "planePlaneIntersection", function() { return planePlaneIntersection; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rotatePoint", function() { return rotatePoint; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/convertToVector3.js */ "./util/convertToVector3.js"); + + +/** + * Projects a patient point to an image point + * @export @public @method + * @name projectPatientPointToImagePlane + * + * @param {Object} patientPoint The patient point. + * @param {Object} imagePlane The image plane used for projection. + * @returns {Object} The projected coordinates. + */ + +function projectPatientPointToImagePlane(patientPoint, imagePlane) { + var rowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.rowCosines); + var columnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.columnCosines); + var imagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.imagePositionPatient); + var point = patientPoint.clone().sub(imagePositionPatient); + var x = rowCosines.dot(point) / imagePlane.columnPixelSpacing; + var y = columnCosines.dot(point) / imagePlane.rowPixelSpacing; + return { + x: x, + y: y + }; +} // + +/** + * Projects an image point to a patient point + * @export @public @method + * @name imagePointToPatientPoint + * + * @param {Object} imagePoint The image point. + * @param {Object} imagePlane The image plane used for projection. + * @returns {Object} The projected coordinates. + */ + +function imagePointToPatientPoint(imagePoint, imagePlane) { + var rowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.rowCosines); + var columnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.columnCosines); + var imagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(imagePlane.imagePositionPatient); + var x = rowCosines.clone().multiplyScalar(imagePoint.x); + x.multiplyScalar(imagePlane.columnPixelSpacing); + var y = columnCosines.clone().multiplyScalar(imagePoint.y); + y.multiplyScalar(imagePlane.rowPixelSpacing); + var patientPoint = x.add(y); + patientPoint.add(imagePositionPatient); + return patientPoint; +} +/** + * Returns a rectangle from the imagePlane. + * @export @public @method + * @name getRectangleFromImagePlane + * + * @param {Object} imagePlane The imagePlane. + * @returns {Object} The rect. + */ + +function getRectangleFromImagePlane(imagePlane) { + // Get the points + var topLeft = imagePointToPatientPoint({ + x: 0, + y: 0 + }, imagePlane); + var topRight = imagePointToPatientPoint({ + x: imagePlane.columns, + y: 0 + }, imagePlane); + var bottomLeft = imagePointToPatientPoint({ + x: 0, + y: imagePlane.rows + }, imagePlane); + var bottomRight = imagePointToPatientPoint({ + x: imagePlane.columns, + y: imagePlane.rows + }, imagePlane); // Get each side as a vector + + var rect = { + top: new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Line3(topLeft, topRight), + left: new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Line3(topLeft, bottomLeft), + right: new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Line3(topRight, bottomRight), + bottom: new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Line3(bottomLeft, bottomRight) + }; + return rect; +} +/** + * Gets all the intersections of a line with a rect. + * @private + * @method + * @name lineRectangleIntersection + * + * @param {Object} line The line to check. + * @param {Object} rect The rect being intersected. + * @returns {Object[]} An array of the intersections. + */ + + +function lineRectangleIntersection(line, rect) { + var intersections = []; + Object.keys(rect).forEach(function (side) { + var segment = rect[side]; + var intersection = line.intersectLine(segment); + + if (intersection) { + intersections.push(intersection); + } + }); + return intersections; +} +/** + * Gets the line of intersection between two planes in patient space. + * @export @public @method + * @name planePlaneIntersection + * + * @param {Object} targetImagePlane The target plane. + * @param {Object} referenceImagePlane The reference plane + * @returns {Object} The intersections. + */ + + +function planePlaneIntersection(targetImagePlane, referenceImagePlane) { + var targetRowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(targetImagePlane.rowCosines); + var targetColumnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(targetImagePlane.columnCosines); + var targetImagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(targetImagePlane.imagePositionPatient); + var referenceRowCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(referenceImagePlane.rowCosines); + var referenceColumnCosines = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(referenceImagePlane.columnCosines); + var referenceImagePositionPatient = Object(_util_convertToVector3_js__WEBPACK_IMPORTED_MODULE_1__["default"])(referenceImagePlane.imagePositionPatient); // First, get the normals of each image plane + + var targetNormal = targetRowCosines.clone().cross(targetColumnCosines); + var targetPlane = new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Plane(); + targetPlane.setFromNormalAndCoplanarPoint(targetNormal, targetImagePositionPatient); + var referenceNormal = referenceRowCosines.clone().cross(referenceColumnCosines); + var referencePlane = new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Plane(); + referencePlane.setFromNormalAndCoplanarPoint(referenceNormal, referenceImagePositionPatient); + var originDirection = referencePlane.clone().intersectPlane(targetPlane); + var origin = originDirection.origin; + var direction = originDirection.direction; // Calculate the longest possible length in the reference image plane (the length of the diagonal) + + var bottomRight = imagePointToPatientPoint({ + x: referenceImagePlane.columns, + y: referenceImagePlane.rows + }, referenceImagePlane); + var distance = referenceImagePositionPatient.distanceTo(bottomRight); // Use this distance to bound the ray intersecting the two planes + + var line = new _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.Line3(); + line.start = origin; + line.end = origin.clone().add(direction.multiplyScalar(distance)); // Find the intersections between this line and the reference image plane's four sides + + var rect = getRectangleFromImagePlane(referenceImagePlane); + var intersections = lineRectangleIntersection(line, rect); // Return the intersections between this line and the reference image plane's sides + // In order to draw the reference line from the target image. + + if (intersections.length !== 2) { + return; + } + + return { + start: intersections[0], + end: intersections[1] + }; +} +/** + * Translate a point using a rotation angle. + * @export @public @method + * @name rotatePoint + * + * @param {Object} point - `{ x, y }` in either pixel or canvas coordinates. + * @param {Object} center - `{ x, y }` in either pixel or canvas coordinates. + * @param {Number} angle - angle in degrees + * @returns {Object} - `{ x, y }` new point translated + */ + +function rotatePoint(point, center, angle) { + var angleRadians = angle * (Math.PI / 180); // Convert to radians + + var rotatedX = Math.cos(angleRadians) * (point.x - center.x) - Math.sin(angleRadians) * (point.y - center.y) + center.x; + var rotatedY = Math.sin(angleRadians) * (point.x - center.x) + Math.cos(angleRadians) * (point.y - center.y) + center.y; + return { + x: rotatedX, + y: rotatedY + }; +} + +/***/ }), + +/***/ "./util/roundToDecimal.js": +/*!********************************!*\ + !*** ./util/roundToDecimal.js ***! + \********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Rounds a number to the specified precision. + * @export @public @method + * @name roundToDecimal + * + * @param {number} value The value to round. + * @param {number} precision The required precision. + * @returns {number} The rounded number. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (value, precision) { + var multiplier = Math.pow(10, precision); + return Math.round(value * multiplier) / multiplier; +}); + +/***/ }), + +/***/ "./util/scroll.js": +/*!************************!*\ + !*** ./util/scroll.js ***! + \************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _scrollToIndex_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./scrollToIndex.js */ "./util/scrollToIndex.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _clip_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./clip.js */ "./util/clip.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); + + + + +/** + * Scrolls through the stack. + * @export @public @method + * @name scroll + * + * @param {HTMLElement} element The element to scroll. + * @param {number} images The number of images to scroll through. + * @param {type} [loop = false] Whether to loop the scrolling. + * @param {type} [allowSkipping = true] Whether frames can be skipped. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, images) { + var loop = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var allowSkipping = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_1__["getToolState"])(element, 'stack'); + + if (!toolData || !toolData.data || !toolData.data.length) { + return; + } + + var stackData = toolData.data[0]; + + if (!stackData.pending) { + stackData.pending = []; + } + + var newImageIdIndex = stackData.currentImageIdIndex + images; + + if (loop) { + var nbImages = stackData.imageIds.length; + newImageIdIndex %= nbImages; + } else { + newImageIdIndex = Object(_clip_js__WEBPACK_IMPORTED_MODULE_2__["default"])(newImageIdIndex, 0, stackData.imageIds.length - 1); + } + + if (allowSkipping) { + Object(_scrollToIndex_js__WEBPACK_IMPORTED_MODULE_0__["default"])(element, newImageIdIndex); + } else { + var pendingEvent = { + index: newImageIdIndex + }; + stackData.pending.push(pendingEvent); + scrollWithoutSkipping(stackData, pendingEvent, element); + } +}); +/** + * Recursively scrolls the stack until the desired image is reached. + * @private + * @method + * @name scrollWithoutSkipping + * + * @param {type} stackData Data object containing information about the stack. + * @param {Object} pendingEvent The event to process next. + * @param {HTMLElement} element The element being scrolled through. + * @returns {void} + */ + +function scrollWithoutSkipping(stackData, pendingEvent, element) { + if (stackData.pending[0] === pendingEvent) { + if (stackData.currentImageIdIndex === pendingEvent.index) { + stackData.pending.splice(stackData.pending.indexOf(pendingEvent), 1); + + if (stackData.pending.length > 0) { + scrollWithoutSkipping(stackData, stackData.pending[0], element); + } + + return; + } + + var newImageHandler = function newImageHandler(event) { + var index = stackData.imageIds.indexOf(event.detail.image.imageId); + + if (index === pendingEvent.index) { + stackData.pending.splice(stackData.pending.indexOf(pendingEvent), 1); + element.removeEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.EVENTS.NEW_IMAGE, newImageHandler); + + if (stackData.pending.length > 0) { + scrollWithoutSkipping(stackData, stackData.pending[0], element); + } + } + }; + + element.addEventListener(_externalModules_js__WEBPACK_IMPORTED_MODULE_3__["default"].cornerstone.EVENTS.NEW_IMAGE, newImageHandler); + Object(_scrollToIndex_js__WEBPACK_IMPORTED_MODULE_0__["default"])(element, pendingEvent.index); + } +} + +/***/ }), + +/***/ "./util/scrollToIndex.js": +/*!*******************************!*\ + !*** ./util/scrollToIndex.js ***! + \*******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../events.js */ "./events.js"); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); +/* harmony import */ var _stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../stateManagement/toolState.js */ "./stateManagement/toolState.js"); +/* harmony import */ var _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../stateManagement/loadHandlerManager.js */ "./stateManagement/loadHandlerManager.js"); +/* harmony import */ var _util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/triggerEvent.js */ "./util/triggerEvent.js"); + + + + + +/** + * Scrolls through the stack to the image index requested. + * @export @public @method + * @name scrollToIndex + * + * @param {type} element The element to scroll through. + * @param {type} newImageIdIndex The target image index. + * @returns {void} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (element, newImageIdIndex) { + var toolData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stack'); + + if (!toolData || !toolData.data || !toolData.data.length) { + return; + } + + var cornerstone = _externalModules_js__WEBPACK_IMPORTED_MODULE_1__["default"].cornerstone; // If we have more than one stack, check if we have a stack renderer defined + + var stackRenderer; + + if (toolData.data.length > 1) { + var stackRendererData = Object(_stateManagement_toolState_js__WEBPACK_IMPORTED_MODULE_2__["getToolState"])(element, 'stackRenderer'); + + if (stackRendererData && stackRendererData.data && stackRendererData.data.length) { + stackRenderer = stackRendererData.data[0]; + } + } + + var stackData = toolData.data[0]; // Allow for negative indexing + + if (newImageIdIndex < 0) { + newImageIdIndex += stackData.imageIds.length; + } + + var startLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_3__["default"].getStartLoadHandler(element); + var endLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_3__["default"].getEndLoadHandler(element); + var errorLoadingHandler = _stateManagement_loadHandlerManager_js__WEBPACK_IMPORTED_MODULE_3__["default"].getErrorLoadingHandler(element); + + function doneCallback(image) { + if (stackData.currentImageIdIndex !== newImageIdIndex) { + return; + } // Check if the element is still enabled in Cornerstone, + // If an error is thrown, stop here. + + + try { + // TODO: Add 'isElementEnabled' to Cornerstone? + cornerstone.getEnabledElement(element); + } catch (error) { + return; + } + + if (stackRenderer) { + stackRenderer.currentImageIdIndex = newImageIdIndex; + stackRenderer.render(element, toolData.data); + } else { + cornerstone.displayImage(element, image); + } + + if (endLoadingHandler) { + endLoadingHandler(element, image); + } + } + + function failCallback(error) { + var imageId = stackData.imageIds[newImageIdIndex]; + + if (errorLoadingHandler) { + errorLoadingHandler(element, imageId, error); + } + } + + if (newImageIdIndex === stackData.currentImageIdIndex) { + return; + } + + if (startLoadingHandler) { + startLoadingHandler(element); + } + + var eventData = { + newImageIdIndex: newImageIdIndex, + direction: newImageIdIndex - stackData.currentImageIdIndex + }; + stackData.currentImageIdIndex = newImageIdIndex; + var newImageId = stackData.imageIds[newImageIdIndex]; // Retry image loading in cases where previous image promise + // Was rejected, if the option is set + + /* + Const config = stackScroll.getConfiguration(); + TODO: Revisit this. It appears that Core's imageCache is not + keeping rejected promises anywhere, so we have no way to know + if something was previously rejected. + if (config && config.retryLoadOnScroll === true) { + } + */ + // Convert the preventCache value in stack data to a boolean + + var preventCache = Boolean(stackData.preventCache); + var imagePromise; + + if (preventCache) { + imagePromise = cornerstone.loadImage(newImageId); + } else { + imagePromise = cornerstone.loadAndCacheImage(newImageId); + } + + imagePromise.then(doneCallback, failCallback); + Object(_util_triggerEvent_js__WEBPACK_IMPORTED_MODULE_4__["default"])(element, _events_js__WEBPACK_IMPORTED_MODULE_0__["default"].STACK_SCROLL, eventData); +}); + +/***/ }), + +/***/ "./util/segmentation/drawBrush.js": +/*!****************************************!*\ + !*** ./util/segmentation/drawBrush.js ***! + \****************************************/ +/*! exports provided: drawBrushPixels */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drawBrushPixels", function() { return drawBrushPixels; }); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _eraseIfSegmentIndex_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./eraseIfSegmentIndex.js */ "./util/segmentation/eraseIfSegmentIndex.js"); + + +/** + * DrawBrushPixels - Adds or removes labels to a labelmap. + * + * @param {number[]} pointerArray The array of pixels to paint. + * @param {Object} labelmap2D The `pixelData` array to paint to. + * @param {number} segmentIndex The segment being drawn. + * @param {number} columns The number of columns in the image. + * @param {boolean} shouldErase = false Whether we should erase rather than color pixels. + * @returns {null} + */ + +function drawBrushPixels(pointerArray, pixelData, segmentIndex, columns) { + var shouldErase = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; + + var getPixelIndex = function getPixelIndex(x, y) { + return y * columns + x; + }; + + pointerArray.forEach(function (point) { + var spIndex = getPixelIndex.apply(void 0, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(point)); + + if (shouldErase) { + Object(_eraseIfSegmentIndex_js__WEBPACK_IMPORTED_MODULE_1__["default"])(spIndex, pixelData, segmentIndex); + } else { + pixelData[spIndex] = segmentIndex; + } + }); +} + + + +/***/ }), + +/***/ "./util/segmentation/eraseIfSegmentIndex.js": +/*!**************************************************!*\ + !*** ./util/segmentation/eraseIfSegmentIndex.js ***! + \**************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return eraseIfSegmentIndex; }); +/** + * If the pixelData for the given pixelIndex is equal to the segmentIndex + * erase it (set it to 0). + * @param {number} pixelIndex The index of the pixel. + * @param {UInt16Array} pixelData The pixelData array. + * @param {number} segmentIndex The segment Index to erase. + */ +function eraseIfSegmentIndex(pixelIndex, pixelData, segmentIndex) { + if (pixelData[pixelIndex] === segmentIndex) { + pixelData[pixelIndex] = 0; + } +} + +/***/ }), + +/***/ "./util/segmentation/eraseOutsideBoundingBox.js": +/*!******************************************************!*\ + !*** ./util/segmentation/eraseOutsideBoundingBox.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return eraseOutsideBoundingBox; }); +/* harmony import */ var _eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./eraseIfSegmentIndex */ "./util/segmentation/eraseIfSegmentIndex.js"); + +/** + * EraseOutsideBoundingBox - Erase all pixels labeled with the activeSegmentIndex, + * outside the bouding box defined by the `topLeft` and `topRight`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + +function eraseOutsideBoundingBox(evt, operationData, topLeft, bottomRight) { + var eventData = evt.detail; + var pixelData = operationData.pixelData, + segmentIndex = operationData.segmentIndex; + var image = eventData.image; + var width = image.width, + height = image.height; // Loop until top of bounding box from top of image, color the entire row + + for (var i = 0; i < width; i++) { + for (var j = 0; j < topLeft[1]; j++) { + Object(_eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_0__["default"])(j * width + i, pixelData, segmentIndex); + } + } // Loop within rows of bounding box, to the left of the box + + + for (var _i = 0; _i < topLeft[0]; _i++) { + for (var _j = topLeft[1]; _j < bottomRight[1]; _j++) { + Object(_eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_0__["default"])(_j * width + _i, pixelData, segmentIndex); + } + } // Loop within rows of bounding box, to the right of the box + + + for (var _i2 = bottomRight[0]; _i2 < width; _i2++) { + for (var _j2 = topLeft[1]; _j2 < bottomRight[1]; _j2++) { + Object(_eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_0__["default"])(_j2 * width + _i2, pixelData, segmentIndex); + } + } // Loop from bottom of bounding box until bottom of image, color entire row + + + for (var _i3 = 0; _i3 < width; _i3++) { + for (var _j3 = bottomRight[1]; _j3 < height; _j3++) { + Object(_eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_0__["default"])(_j3 * width + _i3, pixelData, segmentIndex); + } + } +} + +/***/ }), + +/***/ "./util/segmentation/eraseShape.js": +/*!*****************************************!*\ + !*** ./util/segmentation/eraseShape.js ***! + \*****************************************/ +/*! exports provided: eraseInsideShape, eraseOutsideShape */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseInsideShape", function() { return eraseInsideShape; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideShape", function() { return eraseOutsideShape; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _eraseOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./eraseOutsideBoundingBox */ "./util/segmentation/eraseOutsideBoundingBox.js"); +/* harmony import */ var _isSameSegment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./isSameSegment.js */ "./util/segmentation/isSameSegment.js"); +/* harmony import */ var _logger_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../logger.js */ "./util/logger.js"); + + + + +var logger = Object(_logger_js__WEBPACK_IMPORTED_MODULE_3__["getLogger"])('util:segmentation:operations:eraseOutsideCircle'); +/** + * Erase all pixels labeled with the activeSegmentIndex, + * inside/outside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + +function eraseShape(evt, operationData, pointInShape, topLeft, bottomRight) { + var insideOrOutside = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'inside'; + var width = evt.detail.image.width; + var pixelData = operationData.pixelData, + segmentIndex = operationData.segmentIndex; + + var _topLeft = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(topLeft, 2), + xMin = _topLeft[0], + yMin = _topLeft[1]; + + var _bottomRight = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(bottomRight, 2), + xMax = _bottomRight[0], + yMax = _bottomRight[1]; + + if (insideOrOutside === 'outside') { + Object(_eraseOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, operationData, topLeft, bottomRight); + } + + for (var x = xMin; x < xMax; x++) { + for (var y = yMin; y < yMax; y++) { + var pixelIndex = y * width + x; // If the pixel is the same segmentIndex and is inside the + // Region defined by the array of points, set their value to segmentIndex. + + if (Object(_isSameSegment_js__WEBPACK_IMPORTED_MODULE_2__["default"])(pixelIndex, pixelData, segmentIndex) && pointInShape({ + x: x, + y: y + })) { + pixelData[pixelIndex] = 0; + } + } + } +} +/** + * Erase all pixels labeled with the activeSegmentIndex, + * inside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + + +function eraseInsideShape(evt, operationData, pointInShape, topLeft, bottomRight) { + eraseShape(evt, operationData, pointInShape, topLeft, bottomRight, 'inside'); +} +/** + * Erase all pixels labeled with the activeSegmentIndex, + * outside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + +function eraseOutsideShape(evt, operationData, pointInShape, topLeft, bottomRight) { + eraseShape(evt, operationData, function (point) { + return !pointInShape(point); + }, topLeft, bottomRight, 'outside'); +} + +/***/ }), + +/***/ "./util/segmentation/fillOutsideBoundingBox.js": +/*!*****************************************************!*\ + !*** ./util/segmentation/fillOutsideBoundingBox.js ***! + \*****************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return fillOutsideBoundingBox; }); +/** + * EraseInside - fill all pixels labeled with the activeSegmentIndex, + * outside the bouding box defined by the `topLeft` and `topRight`. + * @param {} evt The Cornerstone event. + * @param {} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ +function fillOutsideBoundingBox(evt, operationData, topLeft, bottomRight) { + var pixelData = operationData.pixelData, + segmentIndex = operationData.segmentIndex; + var _evt$detail$image = evt.detail.image, + width = _evt$detail$image.width, + height = _evt$detail$image.height; // Loop until top of bounding box from top of image, color the entire row + + for (var i = 0; i < width; i++) { + for (var j = 0; j < topLeft[1]; j++) { + pixelData[j * width + i] = segmentIndex; + } + } // Loop within rows of bounding box, to the left of the box + + + for (var _i = 0; _i < topLeft[0]; _i++) { + for (var _j = topLeft[1]; _j < bottomRight[1]; _j++) { + pixelData[_j * width + _i] = segmentIndex; + } + } // Loop within rows of bounding box, to the right of the box + + + for (var _i2 = bottomRight[0]; _i2 < width; _i2++) { + for (var _j2 = topLeft[1]; _j2 < bottomRight[1]; _j2++) { + pixelData[_j2 * width + _i2] = segmentIndex; + } + } // Loop from bottom of bounding box until bottom of image, color entire row + + + for (var _i3 = 0; _i3 < width; _i3++) { + for (var _j3 = bottomRight[1]; _j3 < height; _j3++) { + pixelData[_j3 * width + _i3] = segmentIndex; + } + } +} + +/***/ }), + +/***/ "./util/segmentation/fillShape.js": +/*!****************************************!*\ + !*** ./util/segmentation/fillShape.js ***! + \****************************************/ +/*! exports provided: fillInsideShape, fillOutsideShape */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillInsideShape", function() { return fillInsideShape; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fillOutsideShape", function() { return fillOutsideShape; }); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "../node_modules/@babel/runtime/helpers/slicedToArray.js"); +/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _fillOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./fillOutsideBoundingBox */ "./util/segmentation/fillOutsideBoundingBox.js"); +/* harmony import */ var _logger_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../logger.js */ "./util/logger.js"); + + + +var logger = Object(_logger_js__WEBPACK_IMPORTED_MODULE_2__["getLogger"])('util:segmentation:operations:helpers:fillShape'); +/** + * Fill all pixels labeled with the activeSegmentIndex, + * inside/outside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + +function fillShape(evt, operationData, pointInShape, topLeft, bottomRight) { + var insideOrOutside = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'inside'; + var pixelData = operationData.pixelData, + segmentIndex = operationData.segmentIndex; + + if (pixelData === undefined || segmentIndex === undefined) { + logger.error("fillInsideShape requires operationData to contain pixelData and segmentIndex"); + return; + } + + var width = evt.detail.image.width; + + var _topLeft = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(topLeft, 2), + xMin = _topLeft[0], + yMin = _topLeft[1]; + + var _bottomRight = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(bottomRight, 2), + xMax = _bottomRight[0], + yMax = _bottomRight[1]; + + if (insideOrOutside === 'outside') { + Object(_fillOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_1__["default"])(evt, operationData, topLeft, bottomRight); + } + + for (var x = xMin; x < xMax; x++) { + for (var y = yMin; y < yMax; y++) { + var pixelIndex = y * width + x; // If the pixel is the same segmentIndex and is inside the + // Region defined by the array of points, set their value to segmentIndex. + + if (pointInShape({ + x: x, + y: y + })) { + pixelData[pixelIndex] = segmentIndex; + } + } + } +} +/** + * Fill all pixels labeled with the activeSegmentIndex, + * inside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + + +function fillInsideShape(evt, operationData, pointInShape, topLeft, bottomRight) { + fillShape(evt, operationData, pointInShape, topLeft, bottomRight, 'inside'); +} +/** + * Fill all pixels labeled with the activeSegmentIndex, + * outside the region defined by the shape. + * @param {Object} evt The Cornerstone event. + * @param {Object} operationData An object containing the `pixelData` to + * modify, the `segmentIndex` and the `points` array. + * @param {Object} pointInShape - A function that checks if a point, x,y is within a shape. + * @param {number[]} topLeft The top left of the bounding box. + * @param {number[]} bottomRight The bottom right of the bounding box. + * @returns {null} + */ + +function fillOutsideShape(evt, operationData, pointInShape, topLeft, bottomRight) { + fillShape(evt, operationData, function (point) { + return !pointInShape(point); + }, topLeft, bottomRight, 'outside'); +} + +/***/ }), + +/***/ "./util/segmentation/floodFill.js": +/*!****************************************!*\ + !*** ./util/segmentation/floodFill.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "../node_modules/@babel/runtime/helpers/toConsumableArray.js"); +/* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__); + + +/** + * floodFill.js - Taken from MIT OSS lib - https://github.com/tuzz/n-dimensional-flood-fill + * Refactored to ES6. + * + * @param {function} getter The getter to the elements of your data structure, + * e.g. getter(x,y) for a 2D interprettation of your structure. + * @param {number[]} seed The seed for your fill. The dimensionality is infered + * by the number of dimensions of the seed. + * @param {function} [options.onFlood] An optional callback to execute when each pixel is flooded. + * e.g. onFlood(x,y). + * @param {function} [options.onBoundary] An optional callback to execute whenever a boundary is reached. + * a boundary could be another segmentIndex, or the edge of your + * data structure (i.e. when your getter returns undefined). + * @param {function} [options.equals] An optional equality method for your datastructure. + * Default is simply value1 = value2. + * @param {boolean} [options.diagonals] Whether you allow flooding through diagonals. Defaults to false. + * + * @returns {Object} + */ +/* harmony default export */ __webpack_exports__["default"] = (function (getter, seed) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + + var onFlood = options.onFlood || function () {}; + + var onBoundary = options.onBoundary || function () {}; + + var equals = options.equals || defaultEquals; + var diagonals = options.diagonals || false; + var startNode = get(seed); + var permutations = prunedPermutations(); + var stack = []; + var flooded = []; + var visits = {}; + var bounds = {}; + stack.push({ + currentArgs: seed + }); + + while (stack.length > 0) { + flood(stack.pop()); + } + + return { + flooded: flooded, + boundaries: boundaries() + }; + + function flood(job) { + var getArgs = job.currentArgs; + var prevArgs = job.previousArgs; + + if (visited(getArgs)) { + return; + } + + markAsVisited(getArgs); + + if (member(getArgs)) { + markAsFlooded(getArgs); + pushAdjacent(getArgs); + } else { + markAsBoundary(prevArgs); + } + } + + function visited(key) { + return visits[key] === true; + } + + function markAsVisited(key) { + visits[key] = true; + } + + function member(getArgs) { + var node = safely(get, [getArgs]); + return safely(equals, [node, startNode]); + } + + function markAsFlooded(getArgs) { + flooded.push(getArgs); + onFlood.apply(void 0, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(getArgs)); + } + + function markAsBoundary(prevArgs) { + bounds[prevArgs] = prevArgs; + onBoundary.apply(void 0, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(prevArgs)); + } + + function pushAdjacent(getArgs) { + for (var i = 0; i < permutations.length; i += 1) { + var perm = permutations[i]; + var nextArgs = getArgs.slice(0); + + for (var j = 0; j < getArgs.length; j += 1) { + nextArgs[j] += perm[j]; + } + + stack.push({ + currentArgs: nextArgs, + previousArgs: getArgs + }); + } + } + + function get(getArgs) { + return getter.apply(void 0, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(getArgs)); + } + + function safely(f, args) { + try { + return f.apply(void 0, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(args)); + } catch (error) { + return; + } + } + + function prunedPermutations() { + var permutations = permute(seed.length); + return permutations.filter(function (perm) { + var count = countNonZeroes(perm); + return count !== 0 && (count === 1 || diagonals); + }); + } + + function permute(length) { + var perms = []; + + var permutation = function permutation(string) { + return string.split('').map(function (c) { + return parseInt(c, 10) - 1; + }); + }; + + for (var i = 0; i < Math.pow(3, length); i += 1) { + var string = lpad(i.toString(3), '0', length); + perms.push(permutation(string)); + } + + return perms; + } + + function boundaries() { + var array = []; + + for (var key in bounds) { + if (bounds.hasOwnProperty(key)) { + array.unshift(bounds[key]); + } + } + + return array; + } +}); + +function defaultEquals(a, b) { + return a === b; +} + +function countNonZeroes(array) { + var count = 0; + + for (var i = 0; i < array.length; i += 1) { + if (array[i] !== 0) { + count += 1; + } + } + + return count; +} + +function lpad(string, character, length) { + var array = new Array(length + 1); + var pad = array.join(character); + return (pad + string).slice(-length); +} + +/***/ }), + +/***/ "./util/segmentation/getBoundingBoxAroundCircle.js": +/*!*********************************************************!*\ + !*** ./util/segmentation/getBoundingBoxAroundCircle.js ***! + \*********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getBoundingBoxAroundCircle; }); +/* harmony import */ var _getCircleCoords__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../getCircleCoords */ "./util/getCircleCoords.js"); + +function getBoundingBoxAroundCircle(evt) { + var handles = evt.detail.handles; + var _evt$detail$image = evt.detail.image, + imageWidth = _evt$detail$image.width, + imageHeight = _evt$detail$image.height; + var circleCoordinates = Object(_getCircleCoords__WEBPACK_IMPORTED_MODULE_0__["default"])(handles.start, handles.end); + var xMax = circleCoordinates.width + circleCoordinates.left; + var xMin = circleCoordinates.left; + var yMax = circleCoordinates.top + circleCoordinates.height; + var yMin = circleCoordinates.top; + xMin = Math.floor(xMin); + yMin = Math.floor(yMin); + xMax = Math.floor(xMax); + yMax = Math.floor(yMax); + xMax = Math.min(imageWidth, xMax); + xMin = Math.max(0, xMin); + yMax = Math.min(imageHeight, yMax); + yMin = Math.max(0, yMin); + return [[xMin, yMin], [xMax, yMax]]; +} + +/***/ }), + +/***/ "./util/segmentation/getBoundingBoxAroundPolygon.js": +/*!**********************************************************!*\ + !*** ./util/segmentation/getBoundingBoxAroundPolygon.js ***! + \**********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getBoundingBoxAroundPolygon; }); +function getBoundingBoxAroundPolygon(vertices, image) { + var xMin = Infinity; + var xMax = 0; + var yMin = Infinity; + var yMax = 0; + var width = image.width, + height = image.height; + vertices.forEach(function (v) { + xMin = Math.min(v[0], xMin); + xMax = Math.max(v[0], xMax); + yMin = Math.min(v[1], yMin); + yMax = Math.max(v[1], yMax); + }); + xMin = Math.floor(xMin); + yMin = Math.floor(yMin); + xMax = Math.floor(xMax); + yMax = Math.floor(yMax); + xMax = Math.min(width, xMax); + xMin = Math.max(0, xMin); + yMax = Math.min(height, yMax); + yMin = Math.max(0, yMin); + return [[xMin, yMin], [xMax, yMax]]; +} + +/***/ }), + +/***/ "./util/segmentation/getCircle.js": +/*!****************************************!*\ + !*** ./util/segmentation/getCircle.js ***! + \****************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getCircle; }); +/** + * Gets the pixels within the circle. + * @export @public @method + * @name getCircle + * + * @param {number} radius The radius of the circle. + * @param {number} rows The number of rows. + * @param {number} columns The number of columns. + * @param {number} [xCoord = 0] The x-location of the center of the circle. + * @param {number} [yCoord = 0] The y-location of the center of the circle. + * @returns {Array.number[]} Array of pixels contained within the circle. + */ +function getCircle(radius, rows, columns) { + var xCoord = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; + var yCoord = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + var x0 = Math.floor(xCoord); + var y0 = Math.floor(yCoord); + + if (radius === 1) { + return [[x0, y0]]; + } + + var circleArray = []; + var index = 0; + + for (var y = -radius; y <= radius; y++) { + var _yCoord = y0 + y; + + if (_yCoord > rows || _yCoord < 0) { + continue; + } + + for (var x = -radius; x <= radius; x++) { + var _xCoord = x0 + x; + + if (_xCoord >= columns || _xCoord < 0) { + continue; + } + + if (x * x + y * y < radius * radius) { + circleArray[index++] = [x0 + x, y0 + y]; + } + } + } + + return circleArray; +} + +/***/ }), + +/***/ "./util/segmentation/getDiffBetweenPixelData.js": +/*!******************************************************!*\ + !*** ./util/segmentation/getDiffBetweenPixelData.js ***! + \******************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return getDiffBetweenPixelData; }); +function getDiffBetweenPixelData(previousPixelData, newPixelData) { + var diff = []; + + for (var i = 0; i < previousPixelData.length; i++) { + if (previousPixelData[i] !== newPixelData[i]) { + diff.push([i, previousPixelData[i], newPixelData[i]]); + } + } + + return diff; +} + +/***/ }), + +/***/ "./util/segmentation/getPixelPathBetweenPixels.js": +/*!********************************************************!*\ + !*** ./util/segmentation/getPixelPathBetweenPixels.js ***! + \********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externalModules.js */ "./externalModules.js"); + +var oneOverRoot2 = 1 / Math.sqrt(2); // Cache this to avoid repeated computation. + +var DIRECTIONS = { + up: { + x: 0, + y: 1 + }, + upRight: { + x: oneOverRoot2, + y: oneOverRoot2 + }, + right: { + x: 1, + y: 0 + }, + downRight: { + x: oneOverRoot2, + y: -oneOverRoot2 + }, + down: { + x: 0, + y: 1 + }, + downLeft: { + x: -oneOverRoot2, + y: -oneOverRoot2 + }, + left: { + x: -1, + y: 0 + }, + upLeft: { + x: -oneOverRoot2, + y: oneOverRoot2 + } +}; +/** + * GetPixelPathBetweenPixels - Generates a 1-pixel wide path of pixels between two pixels. + * This is essentially simplified A* pathfinding, as we know there are no "obstacles". + * + * @param {Object} p1 The starting pixel + * @param {Object} p2 The end pixel. + * + * @returns {Object[]} All of the pixels on the shortest path between p1 and p2. + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (p1, p2) { + var p = { + x: p1.x, + y: p1.y + }; + var path = []; + + while (p2.x !== p.x || p2.y !== p.y) { + if (p2.x === p.x) { + // Goal is above or bellow us. + if (p2.y > p.y) { + p.y++; + } else { + p.y--; + } + } else if (p2.y === p.y) { + // Goal is to the left or right of us. + if (p2.x > p.x) { + p.x++; + } else { + p.x--; + } + } else if (p2.y > p.y) { + if (p2.x > p.x) { + // Can go up, right or diagonally up-right towards goal. + moveUpRight(p, p2); + } else { + // Can go up, left, or diagonally up-left towards goal. + moveUpLeft(p, p2); + } + } else if (p2.x > p.x) { + // Can go down, right, or diagonally down-right towards goal. + moveDownRight(p, p2); + } else { + // Can go down, left, or diagonally down-left towards goal. + moveDownLeft(p, p2); + } + + path.push({ + x: p.x, + y: p.y + }); + } + + path.pop(); // Remove last node as is the same as the destination. + + return path; +}); +/** + * MoveUpRight - Moves p up, right or diagonally up right towards p2. + * @param {Object} p + * @param {Object} p2 + * + * @returns {null} + */ + +function moveUpRight(p, p2) { + var unitVector = unitVectorFromPtoP2(p, p2); // Largest dot product is fastest way to travel. + + var dotProducts = [dotProduct2D(unitVector, DIRECTIONS.up), dotProduct2D(unitVector, DIRECTIONS.right), dotProduct2D(unitVector, DIRECTIONS.upRight)]; + var largestIndex = getIndexOfLargestInLengthThreeArray(dotProducts); + + switch (largestIndex) { + case 0: + p.y++; + break; + + case 1: + p.x++; + break; + + case 2: + p.y++; + p.x++; + } +} +/** + * MoveUpLeft - Moves p up, left or diagonally up left towards p2. + * @param {Object} p + * @param {Object} p2 + * + * @returns {null} + */ + + +function moveUpLeft(p, p2) { + var unitVector = unitVectorFromPtoP2(p, p2); // Largest dot product is fastest way to travel. + + var dotProducts = [dotProduct2D(unitVector, DIRECTIONS.up), dotProduct2D(unitVector, DIRECTIONS.left), dotProduct2D(unitVector, DIRECTIONS.upLeft)]; + var largestIndex = getIndexOfLargestInLengthThreeArray(dotProducts); + + switch (largestIndex) { + case 0: + p.y++; + break; + + case 1: + p.x--; + break; + + case 2: + p.y++; + p.x--; + } +} +/** + * MoveDownRight - Moves p down, right or diagonally down right towards p2. + * @param {Object} p + * @param {Object} p2 + * + * @returns {null} + */ + + +function moveDownRight(p, p2) { + var unitVector = unitVectorFromPtoP2(p, p2); // Largest dot product is fastest way to travel. + + var dotProducts = [dotProduct2D(unitVector, DIRECTIONS.down), dotProduct2D(unitVector, DIRECTIONS.right), dotProduct2D(unitVector, DIRECTIONS.downRight)]; + var largestIndex = getIndexOfLargestInLengthThreeArray(dotProducts); + + switch (largestIndex) { + case 0: + p.y--; + break; + + case 1: + p.x++; + break; + + case 2: + p.y--; + p.x++; + } +} +/** + * MoveDownLeft - Moves p down, left or diagonally down left towards p2. + * @param {Object} p + * @param {Object} p2 + * + * @returns {null} + */ + + +function moveDownLeft(p, p2) { + var unitVector = unitVectorFromPtoP2(p, p2); // Largest dot product is fastest way to travel. + + var dotProducts = [dotProduct2D(unitVector, DIRECTIONS.down), dotProduct2D(unitVector, DIRECTIONS.left), dotProduct2D(unitVector, DIRECTIONS.downLeft)]; + var largestIndex = getIndexOfLargestInLengthThreeArray(dotProducts); + + switch (largestIndex) { + case 0: + p.y--; + break; + + case 1: + p.x--; + break; + + case 2: + p.y--; + p.x--; + } +} +/** + * UnitVectorFromPtoP2 - Returns a unit vector pointing from p to p2. + * @param {Object} p + * @param {Object} p2 + * + * @returns {Object} The unit vector. + */ + + +function unitVectorFromPtoP2(p, p2) { + var distance = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstoneMath.point.distance(p, p2); + return { + x: (p2.x - p.x) / distance, + y: (p2.y - p.y) / distance + }; +} + +function dotProduct2D(p, p2) { + return p.x * p2.x + p.y * p2.y; +} +/** + * GetIndexOfLargestInLengthThreeArray - Returns the index of the largest value + * in the 3 element array. + * @param {number[]} array + * @returns {number} + */ + + +function getIndexOfLargestInLengthThreeArray(array) { + var largestIndex = array[0] > array[1] ? 0 : 1; + + if (array[2] > array[largestIndex]) { + largestIndex = 2; + } + + return largestIndex; +} + +/***/ }), + +/***/ "./util/segmentation/index.js": +/*!************************************!*\ + !*** ./util/segmentation/index.js ***! + \************************************/ +/*! exports provided: drawBrushPixels, eraseIfSegmentIndex, eraseOutsideBoundingBox, eraseInsideShape, eraseOutsideShape, fillOutsideBoundingBox, fillInsideShape, fillOutsideShape, floodFill, getBoundingBoxAroundCircle, getBoundingBoxAroundPolygon, getCircle, getPixelPathBetweenPixels, isSameSegment, triggerLabelmapModifiedEvent, getDiffBetweenPixelData */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _drawBrush__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./drawBrush */ "./util/segmentation/drawBrush.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "drawBrushPixels", function() { return _drawBrush__WEBPACK_IMPORTED_MODULE_0__["drawBrushPixels"]; }); + +/* harmony import */ var _eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./eraseIfSegmentIndex */ "./util/segmentation/eraseIfSegmentIndex.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseIfSegmentIndex", function() { return _eraseIfSegmentIndex__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + +/* harmony import */ var _eraseOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./eraseOutsideBoundingBox */ "./util/segmentation/eraseOutsideBoundingBox.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideBoundingBox", function() { return _eraseOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_2__["default"]; }); + +/* harmony import */ var _eraseShape__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./eraseShape */ "./util/segmentation/eraseShape.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseInsideShape", function() { return _eraseShape__WEBPACK_IMPORTED_MODULE_3__["eraseInsideShape"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "eraseOutsideShape", function() { return _eraseShape__WEBPACK_IMPORTED_MODULE_3__["eraseOutsideShape"]; }); + +/* harmony import */ var _fillOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./fillOutsideBoundingBox */ "./util/segmentation/fillOutsideBoundingBox.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideBoundingBox", function() { return _fillOutsideBoundingBox__WEBPACK_IMPORTED_MODULE_4__["default"]; }); + +/* harmony import */ var _fillShape__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./fillShape */ "./util/segmentation/fillShape.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillInsideShape", function() { return _fillShape__WEBPACK_IMPORTED_MODULE_5__["fillInsideShape"]; }); + +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fillOutsideShape", function() { return _fillShape__WEBPACK_IMPORTED_MODULE_5__["fillOutsideShape"]; }); + +/* harmony import */ var _floodFill__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./floodFill */ "./util/segmentation/floodFill.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "floodFill", function() { return _floodFill__WEBPACK_IMPORTED_MODULE_6__["default"]; }); + +/* harmony import */ var _getBoundingBoxAroundCircle__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./getBoundingBoxAroundCircle */ "./util/segmentation/getBoundingBoxAroundCircle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getBoundingBoxAroundCircle", function() { return _getBoundingBoxAroundCircle__WEBPACK_IMPORTED_MODULE_7__["default"]; }); + +/* harmony import */ var _getBoundingBoxAroundPolygon__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./getBoundingBoxAroundPolygon */ "./util/segmentation/getBoundingBoxAroundPolygon.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getBoundingBoxAroundPolygon", function() { return _getBoundingBoxAroundPolygon__WEBPACK_IMPORTED_MODULE_8__["default"]; }); + +/* harmony import */ var _getCircle__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./getCircle */ "./util/segmentation/getCircle.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getCircle", function() { return _getCircle__WEBPACK_IMPORTED_MODULE_9__["default"]; }); + +/* harmony import */ var _getPixelPathBetweenPixels__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./getPixelPathBetweenPixels */ "./util/segmentation/getPixelPathBetweenPixels.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getPixelPathBetweenPixels", function() { return _getPixelPathBetweenPixels__WEBPACK_IMPORTED_MODULE_10__["default"]; }); + +/* harmony import */ var _isSameSegment__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./isSameSegment */ "./util/segmentation/isSameSegment.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isSameSegment", function() { return _isSameSegment__WEBPACK_IMPORTED_MODULE_11__["default"]; }); + +/* harmony import */ var _triggerLabelmapModifiedEvent__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./triggerLabelmapModifiedEvent */ "./util/segmentation/triggerLabelmapModifiedEvent.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "triggerLabelmapModifiedEvent", function() { return _triggerLabelmapModifiedEvent__WEBPACK_IMPORTED_MODULE_12__["default"]; }); + +/* harmony import */ var _getDiffBetweenPixelData__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./getDiffBetweenPixelData */ "./util/segmentation/getDiffBetweenPixelData.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getDiffBetweenPixelData", function() { return _getDiffBetweenPixelData__WEBPACK_IMPORTED_MODULE_13__["default"]; }); + + + + + + + + + + + + + + + + + +/***/ }), + +/***/ "./util/segmentation/isSameSegment.js": +/*!********************************************!*\ + !*** ./util/segmentation/isSameSegment.js ***! + \********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return isSameSegment; }); +/** + * Returns true if the pixelIndex of pixelData is the same as the segmentIndex. + * + * @param {number} pixelIndex The index of the pixel. + * @param {UInt16Array} pixelData The pixelData array. + * @param {number} segmentIndex The segment Index to erase. + * + * @returns {boolean} + */ +function isSameSegment(pixelIndex, pixelData, segmentIndex) { + return pixelData[pixelIndex] === segmentIndex; +} + +/***/ }), + +/***/ "./util/segmentation/triggerLabelmapModifiedEvent.js": +/*!***********************************************************!*\ + !*** ./util/segmentation/triggerLabelmapModifiedEvent.js ***! + \***********************************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return triggerLabelmapModifiedEvent; }); +/* harmony import */ var _externalModules__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externalModules */ "./externalModules.js"); +/* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../events.js */ "./events.js"); +/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store */ "./store/index.js"); + + + +/** + * Triggers the LABELMAP_MODIFIED event for the active element, providing the labelmapIndex that was modified. + * + * @param {HTMLElement} element + * @param {number} labelmapIndex The labelmapIndex. Defaults to the active for that element if not set. + */ + +function triggerLabelmapModifiedEvent(element, labelmapIndex) { + var _getModule = Object(_store__WEBPACK_IMPORTED_MODULE_2__["getModule"])('segmentation'), + getters = _getModule.getters; + + labelmapIndex = labelmapIndex === undefined ? getters.activeLabelmapIndex(element) : labelmapIndex; + _externalModules__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.triggerEvent(element, _events_js__WEBPACK_IMPORTED_MODULE_1__["default"].LABELMAP_MODIFIED, { + labelmapIndex: labelmapIndex + }); +} + +/***/ }), + +/***/ "./util/setContextToDisplayFontSize.js": +/*!*********************************************!*\ + !*** ./util/setContextToDisplayFontSize.js ***! + \*********************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../externalModules.js */ "./externalModules.js"); + +/** + * Sets the canvas context transformation matrix so it is scaled to show text + * more cleanly even if the image is scaled up. See + * https://github.com/cornerstonejs/cornerstoneTools/wiki/DrawingText + * for more information + * @export @public @function + * @name setContextToDisplayFontSize + * + * @param {HTMLElement} enabledElement The cornerstone enabled element. + * @param {CanvasRenderingContext2D} context The canvas context. + * @param {number} fontSize The font size. + * @returns {Object} {fontSize: number, lineHeight: number, fontScale: number} + */ + +/* harmony default export */ __webpack_exports__["default"] = (function (enabledElement, context, fontSize) { + var fontScale = 0.1; + _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.setToPixelCoordinateSystem(enabledElement, context, fontScale); // Return the font size to use + + var scaledFontSize = fontSize / enabledElement.viewport.scale / fontScale; // TODO: actually calculate this? + + var lineHeight = fontSize / enabledElement.viewport.scale / fontScale; + return { + fontSize: scaledFontSize, + lineHeight: lineHeight, + fontScale: fontScale + }; +}); + +/***/ }), + +/***/ "./util/throttle.js": +/*!**************************!*\ + !*** ./util/throttle.js ***! + \**************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _debounce_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./debounce.js */ "./util/debounce.js"); +/* harmony import */ var _isObject_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./isObject.js */ "./util/isObject.js"); + + +/** + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds (or once per browser frame). The throttled function + * comes with a `cancel` method to cancel delayed `func` invocations and a + * `flush` method to immediately invoke them. Provide `options` to indicate + * whether `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. The `func` is invoked with the last arguments provided to the + * throttled function. Subsequent calls to the throttled function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until the next tick, similar to `setTimeout` with a timeout of `0`. + * + * If `wait` is omitted in an environment with `requestAnimationFrame`, `func` + * invocation will be deferred until the next frame is drawn (typically about + * 16ms). + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `throttle` and `debounce`. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to throttle. + * @param {number} [wait=0] + * The number of milliseconds to throttle invocations to; if omitted, + * `requestAnimationFrame` is used (if available). + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new throttled function. + * @example + * + * // Avoid excessively updating the position while scrolling. + * jQuery(window).on('scroll', throttle(updatePosition, 100)) + * + * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. + * const throttled = throttle(renewToken, 300000, { 'trailing': false }) + * jQuery(element).on('click', throttled) + * + * // Cancel the trailing throttled invocation. + * jQuery(window).on('popstate', throttled.cancel) + */ + +function throttle(func, wait, options) { + var leading = true; + var trailing = true; + + if (typeof func !== 'function') { + throw new TypeError('Expected a function'); + } + + if (Object(_isObject_js__WEBPACK_IMPORTED_MODULE_1__["default"])(options)) { + leading = 'leading' in options ? Boolean(options.leading) : leading; + trailing = 'trailing' in options ? Boolean(options.trailing) : trailing; + } + + return Object(_debounce_js__WEBPACK_IMPORTED_MODULE_0__["default"])(func, wait, { + leading: leading, + trailing: trailing, + maxWait: wait + }); +} + +/* harmony default export */ __webpack_exports__["default"] = (throttle); + +/***/ }), + +/***/ "./util/triggerEvent.js": +/*!******************************!*\ + !*** ./util/triggerEvent.js ***! + \******************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return triggerEvent; }); +/** + * Triggers a CustomEvent. + * @public + * @method triggerEvent + * + * @param {EventTarget} el The element or EventTarget to trigger the event upon. + * @param {String} type The event type name. + * @param {Object|null} [detail=null] The event data to be sent. + * @returns {Boolean} The return value is false if at least one event listener called preventDefault(). Otherwise it returns true. + */ +function triggerEvent(el, type) { + var detail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var event; // This check is needed to polyfill CustomEvent on IE11- + + if (typeof window.CustomEvent === 'function') { + event = new CustomEvent(type, { + detail: detail, + cancelable: true + }); + } else { + event = document.createEvent('CustomEvent'); + event.initCustomEvent(type, true, true, detail); + } + + return el.dispatchEvent(event); +} + +/***/ }), + +/***/ "./util/uuidv4.js": +/*!************************!*\ + !*** ./util/uuidv4.js ***! + \************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return uuidv4; }); +function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0; // eslint-disable-line no-bitwise + + var v = c === 'x' ? r : r & 0x3 | 0x8; // eslint-disable-line no-bitwise + + return v.toString(16); + }); +} + +/***/ }), + +/***/ "./util/wait.js": +/*!**********************!*\ + !*** ./util/wait.js ***! + \**********************/ +/*! exports provided: wait, waitForEnabledElementImageToLoad, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wait", function() { return wait; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "waitForEnabledElementImageToLoad", function() { return waitForEnabledElementImageToLoad; }); +/* harmony import */ var _externalModules_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../externalModules.js */ "./externalModules.js"); + +/** + * Waits a set amount of time, then resolves. Can be chained off of to delay + * next call in promise chain. + * @public + * @function wait + * @param {number} ms - number in ms to wait + * @returns {Promise} - A promise that resolves when setTimeout elapses + */ + +var wait = function wait(ms) { + return new Promise(function (resolve) { + return setTimeout(resolve, ms); + }); +}; +/** + * A promise that returns an EnabledElement who's image has loaded, or + * null if the provided element ceases being an enabledElement before an + * image has been loaded. + * @public + * @function waitForEnabledElementImageToLoad + * + * @param {HTMLElement} element - An element that is an EnabledElement + * @returns {EnabledElement} - The enabled element that has loaded an image + */ + +function waitForEnabledElementImageToLoad(element) { + try { + var enabledElement = _externalModules_js__WEBPACK_IMPORTED_MODULE_0__["default"].cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return wait(250).then(function () { + return waitForEnabledElementImageToLoad(element); + }); + } // EnabledElement's image is loaded. + + + return enabledElement; + } catch (ex) { + // Is no longer, or never was an enabled element, stop polling + return null; + } +} +/* harmony default export */ __webpack_exports__["default"] = (wait); + +/***/ }), + +/***/ "./util/zoom/changeViewportScale.js": +/*!******************************************!*\ + !*** ./util/zoom/changeViewportScale.js ***! + \******************************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Changes the scale of the viewport. + * + * @private + * @function changeViewportScale + * + * @param {Object} viewport The viewport to scale. + * @param {number} ticks The change in magnifcation factor. + * @param {Object} scaleLimits The limits in scale. + * @returns {Object} The scaled viewport. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (viewport, ticks, scaleLimits) { + var maxScale = scaleLimits.maxScale, + minScale = scaleLimits.minScale; + var pow = 1.7; + var oldFactor = Math.log(viewport.scale) / Math.log(pow); + var factor = oldFactor + ticks; + var scale = Math.pow(pow, factor); + + if (maxScale && scale > maxScale) { + viewport.scale = maxScale; + } else if (minScale && scale < minScale) { + viewport.scale = minScale; + } else { + viewport.scale = scale; + } + + return viewport; +}); + +/***/ }), + +/***/ "./util/zoom/correctShift.js": +/*!***********************************!*\ + !*** ./util/zoom/correctShift.js ***! + \***********************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/** + * Corrects the shift by accountoing for viewport rotation and flips. + * @export @public @method + * @name correctShift + * + * @param {Object} shift The shift to correct. + * @param {Object} viewportOrientation Object containing information on the viewport orientation. + * @returns {Object} The corrected shift. + */ +/* harmony default export */ __webpack_exports__["default"] = (function (shift, viewportOrientation) { + var hflip = viewportOrientation.hflip, + vflip = viewportOrientation.vflip, + rotation = viewportOrientation.rotation; // Apply Flips + + shift.x *= hflip ? -1 : 1; + shift.y *= vflip ? -1 : 1; // Apply rotations + + if (rotation !== 0) { + var angle = rotation * Math.PI / 180; + var cosA = Math.cos(angle); + var sinA = Math.sin(angle); + var newX = shift.x * cosA - shift.y * sinA; + var newY = shift.x * sinA + shift.y * cosA; + shift.x = newX; + shift.y = newY; + } + + return shift; +}); + +/***/ }), + +/***/ "./util/zoom/index.js": +/*!****************************!*\ + !*** ./util/zoom/index.js ***! + \****************************/ +/*! exports provided: changeViewportScale, correctShift, default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _changeViewportScale_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./changeViewportScale.js */ "./util/zoom/changeViewportScale.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "changeViewportScale", function() { return _changeViewportScale_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }); + +/* harmony import */ var _correctShift_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./correctShift.js */ "./util/zoom/correctShift.js"); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "correctShift", function() { return _correctShift_js__WEBPACK_IMPORTED_MODULE_1__["default"]; }); + + + // Named + + // Default + +/* harmony default export */ __webpack_exports__["default"] = ({ + changeViewportScale: _changeViewportScale_js__WEBPACK_IMPORTED_MODULE_0__["default"], + correctShift: _correctShift_js__WEBPACK_IMPORTED_MODULE_1__["default"] +}); + +/***/ }), + +/***/ "./version.js": +/*!********************!*\ + !*** ./version.js ***! + \********************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony default export */ __webpack_exports__["default"] = ('6.0.7'); + +/***/ }) + +/******/ }); +}); +//# sourceMappingURL=cornerstoneTools.js.map \ No newline at end of file diff --git a/public/static/dicom/js/dicomViewPc.js b/public/static/dicom/js/dicomViewPc.js index 36dd2805..0d241dab 100644 --- a/public/static/dicom/js/dicomViewPc.js +++ b/public/static/dicom/js/dicomViewPc.js @@ -366,8 +366,8 @@ function initConerstone(element) { const TextMarkerTool = cornerstoneTools.TextMarkerTool // set up the markers configuration const configuration = { - markers: ['F5', 'F4', 'F3', 'F2', 'F1'], - current: 'F5', + markers: ['双击修改注释'], + current: '双击修改注释', ascending: true, loop: true, } @@ -443,7 +443,8 @@ function initImgList(data) { //$("#dicom-list").append(''); //$("#dicom-list").append('
'); //$("#dicom-list").append('
'); - $("#dicom-list").append('
'); + // $("#dicom-list").append('

"'+data.seriesList[i].SeriesDesc+'"

'); + $("#dicom-list").append('
'+data.seriesList[i].SeriesDesc+'
'); } } diff --git a/public/static/反转色.jpg b/public/static/反转色.jpg new file mode 100644 index 00000000..8732d140 Binary files /dev/null and b/public/static/反转色.jpg differ diff --git a/public/static/对比度.jpg b/public/static/对比度.jpg new file mode 100644 index 00000000..3dfa40ed Binary files /dev/null and b/public/static/对比度.jpg differ diff --git a/public/static/左键翻页.jpg b/public/static/左键翻页.jpg new file mode 100644 index 00000000..e2fc965a Binary files /dev/null and b/public/static/左键翻页.jpg differ diff --git a/public/static/布局.jpg b/public/static/布局.jpg new file mode 100644 index 00000000..c9a84e82 Binary files /dev/null and b/public/static/布局.jpg differ diff --git a/public/static/布局2x.jpg b/public/static/布局2x.jpg new file mode 100644 index 00000000..4b495797 Binary files /dev/null and b/public/static/布局2x.jpg differ diff --git a/public/static/平移.jpg b/public/static/平移.jpg new file mode 100644 index 00000000..ced31eb7 Binary files /dev/null and b/public/static/平移.jpg differ diff --git a/public/static/探针.jpg b/public/static/探针.jpg new file mode 100644 index 00000000..06543435 Binary files /dev/null and b/public/static/探针.jpg differ diff --git a/public/static/放大镜.jpg b/public/static/放大镜.jpg new file mode 100644 index 00000000..d569a213 Binary files /dev/null and b/public/static/放大镜.jpg differ diff --git a/public/static/方向标记.jpg b/public/static/方向标记.jpg new file mode 100644 index 00000000..a5344de9 Binary files /dev/null and b/public/static/方向标记.jpg differ diff --git a/public/static/旋转.jpg b/public/static/旋转.jpg new file mode 100644 index 00000000..832f983b Binary files /dev/null and b/public/static/旋转.jpg differ diff --git a/public/static/椭圆选区.jpg b/public/static/椭圆选区.jpg new file mode 100644 index 00000000..af20511d Binary files /dev/null and b/public/static/椭圆选区.jpg differ diff --git a/public/static/比例尺.jpg b/public/static/比例尺.jpg new file mode 100644 index 00000000..eec48393 Binary files /dev/null and b/public/static/比例尺.jpg differ diff --git a/public/static/滚轮缩放.jpg b/public/static/滚轮缩放.jpg new file mode 100644 index 00000000..e7f37056 Binary files /dev/null and b/public/static/滚轮缩放.jpg differ diff --git a/public/static/矩形选区.jpg b/public/static/矩形选区.jpg new file mode 100644 index 00000000..0482f915 Binary files /dev/null and b/public/static/矩形选区.jpg differ diff --git a/public/static/科布角.jpg b/public/static/科布角.jpg new file mode 100644 index 00000000..e22b7402 Binary files /dev/null and b/public/static/科布角.jpg differ diff --git a/public/static/箭头注释.jpg b/public/static/箭头注释.jpg new file mode 100644 index 00000000..ae9da098 Binary files /dev/null and b/public/static/箭头注释.jpg differ diff --git a/public/static/缩放.jpg b/public/static/缩放.jpg new file mode 100644 index 00000000..dedf0d88 Binary files /dev/null and b/public/static/缩放.jpg differ diff --git a/public/static/自由选区.jpg b/public/static/自由选区.jpg new file mode 100644 index 00000000..bc7f288a Binary files /dev/null and b/public/static/自由选区.jpg differ diff --git a/public/static/色彩对比.jpg b/public/static/色彩对比.jpg new file mode 100644 index 00000000..7b5d9c0b Binary files /dev/null and b/public/static/色彩对比.jpg differ diff --git a/public/static/角度.jpg b/public/static/角度.jpg new file mode 100644 index 00000000..f24dd195 Binary files /dev/null and b/public/static/角度.jpg differ diff --git a/public/static/选区对比度.jpg b/public/static/选区对比度.jpg new file mode 100644 index 00000000..5153112e Binary files /dev/null and b/public/static/选区对比度.jpg differ diff --git a/public/static/重置.jpg b/public/static/重置.jpg new file mode 100644 index 00000000..68e9f9c2 Binary files /dev/null and b/public/static/重置.jpg differ diff --git a/public/static/长宽尺.jpg b/public/static/长宽尺.jpg new file mode 100644 index 00000000..09f91b72 Binary files /dev/null and b/public/static/长宽尺.jpg differ diff --git a/public/static/长度尺.jpg b/public/static/长度尺.jpg new file mode 100644 index 00000000..4f79d84a Binary files /dev/null and b/public/static/长度尺.jpg differ diff --git a/public/static/鼠标翻页.jpg b/public/static/鼠标翻页.jpg new file mode 100644 index 00000000..e573e4ed Binary files /dev/null and b/public/static/鼠标翻页.jpg differ diff --git a/src/views/dicomForm/dicomViewForm.vue b/src/views/dicomForm/dicomViewForm.vue index 1aaeae11..46028d30 100644 --- a/src/views/dicomForm/dicomViewForm.vue +++ b/src/views/dicomForm/dicomViewForm.vue @@ -503,9 +503,7 @@ const open = async ( examId: string ) => { resetForm() - const Src = `/static/dicom/dicomViewPc1.html?t=${new Date().getTime()}` - // const Src="D:\pacs\vue\FlowVue-1\dist-prod\dicom\dicomViewPc1.html"+"?"+new Date().getTime() - newSrc.value = Src + console.log('orgid' + orgid) console.log('regid' + regid) @@ -537,6 +535,10 @@ const open = async ( //获取登录人信息 getlogininfo() iframeData() + // 延迟1秒后加载iframe + setTimeout(() => { + dataLoaded.value= true; // 确保iframe只在弹窗打开时加载 + }, 800); } finally { formLoading.value = false } @@ -554,18 +556,20 @@ const iframeData = async () => { } // 在存入新数据之前,先删除原有的'data'项 - localStorage.removeItem('data') + localStorage.removeItem("data"); // 将对象转换为JSON字符串 var localStorageData = JSON.stringify(localData) localStorage.setItem('data', localStorageData) + const Src = `/static/dicom/dicomViewPc1.html?t=${new Date().getTime()}` + newSrc.value = Src } else { // 如果status不是success,可以根据需要处理错误情况 console.error('Request did not succeed:', response.data) } - dataLoaded.value = true // 请求完成后,无论成功与否,都设置dataLoaded为true + // dataLoaded.value = true // 请求完成后,无论成功与否,都设置dataLoaded为true } catch (error) { console.error('Error fetching data:', error) - dataLoaded.value = true // 即使发生错误,也设置dataLoaded为true,以便可以显示错误信息 + // dataLoaded.value = true // 即使发生错误,也设置dataLoaded为true,以便可以显示错误信息 } }