@cornerstonejs/tools 1.55.0 → 1.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js +15 -7
  2. package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
  3. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js +1 -1
  4. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js.map +1 -1
  5. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +2 -1
  6. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
  7. package/dist/cjs/tools/segmentation/BrushTool.js +1 -1
  8. package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
  9. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.d.ts +3 -2
  10. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js +11 -4
  11. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  12. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js +9 -3
  13. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  14. package/dist/cjs/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
  15. package/dist/cjs/tools/segmentation/strategies/compositions/islandRemoval.js.map +1 -1
  16. package/dist/cjs/tools/segmentation/strategies/compositions/threshold.js +6 -2
  17. package/dist/cjs/tools/segmentation/strategies/compositions/threshold.js.map +1 -1
  18. package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.d.ts +2 -3
  19. package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.js +21 -6
  20. package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.js.map +1 -1
  21. package/dist/cjs/utilities/pointInShapeCallback.js +3 -1
  22. package/dist/cjs/utilities/pointInShapeCallback.js.map +1 -1
  23. package/dist/cjs/utilities/segmentation/floodFill.js +16 -22
  24. package/dist/cjs/utilities/segmentation/floodFill.js.map +1 -1
  25. package/dist/cjs/utilities/segmentation/getSegmentAtLabelmapBorder.js +3 -2
  26. package/dist/cjs/utilities/segmentation/getSegmentAtLabelmapBorder.js.map +1 -1
  27. package/dist/cjs/utilities/segmentation/getSegmentAtWorldPoint.js +3 -2
  28. package/dist/cjs/utilities/segmentation/getSegmentAtWorldPoint.js.map +1 -1
  29. package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +16 -8
  30. package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
  31. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js +1 -1
  32. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js.map +1 -1
  33. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +2 -1
  34. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
  35. package/dist/esm/tools/segmentation/BrushTool.js +1 -1
  36. package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
  37. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +10 -3
  38. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  39. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +9 -3
  40. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  41. package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
  42. package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js.map +1 -1
  43. package/dist/esm/tools/segmentation/strategies/compositions/threshold.js +6 -2
  44. package/dist/esm/tools/segmentation/strategies/compositions/threshold.js.map +1 -1
  45. package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js +21 -6
  46. package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js.map +1 -1
  47. package/dist/esm/utilities/pointInShapeCallback.js +3 -1
  48. package/dist/esm/utilities/pointInShapeCallback.js.map +1 -1
  49. package/dist/esm/utilities/segmentation/floodFill.js +16 -22
  50. package/dist/esm/utilities/segmentation/floodFill.js.map +1 -1
  51. package/dist/esm/utilities/segmentation/getSegmentAtLabelmapBorder.js +3 -2
  52. package/dist/esm/utilities/segmentation/getSegmentAtLabelmapBorder.js.map +1 -1
  53. package/dist/esm/utilities/segmentation/getSegmentAtWorldPoint.js +3 -2
  54. package/dist/esm/utilities/segmentation/getSegmentAtWorldPoint.js.map +1 -1
  55. package/dist/types/eventListeners/segmentation/imageChangeEventListener.d.ts.map +1 -1
  56. package/dist/types/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.d.ts.map +1 -1
  57. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts +3 -2
  58. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts.map +1 -1
  59. package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts.map +1 -1
  60. package/dist/types/tools/segmentation/strategies/compositions/islandRemoval.d.ts.map +1 -1
  61. package/dist/types/tools/segmentation/strategies/compositions/threshold.d.ts.map +1 -1
  62. package/dist/types/tools/segmentation/strategies/utils/getStrategyData.d.ts +2 -3
  63. package/dist/types/tools/segmentation/strategies/utils/getStrategyData.d.ts.map +1 -1
  64. package/dist/types/utilities/pointInShapeCallback.d.ts.map +1 -1
  65. package/dist/types/utilities/segmentation/floodFill.d.ts.map +1 -1
  66. package/dist/types/utilities/segmentation/getSegmentAtLabelmapBorder.d.ts.map +1 -1
  67. package/dist/types/utilities/segmentation/getSegmentAtWorldPoint.d.ts.map +1 -1
  68. package/dist/umd/985.index.js +1 -1
  69. package/dist/umd/985.index.js.map +1 -1
  70. package/dist/umd/index.js +1 -1
  71. package/dist/umd/index.js.map +1 -1
  72. package/package.json +7 -3
  73. package/src/eventListeners/segmentation/imageChangeEventListener.ts +28 -13
  74. package/src/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.ts +1 -1
  75. package/src/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.ts +3 -1
  76. package/src/tools/segmentation/BrushTool.ts +1 -1
  77. package/src/tools/segmentation/strategies/BrushStrategy.ts +25 -4
  78. package/src/tools/segmentation/strategies/compositions/dynamicThreshold.ts +12 -2
  79. package/src/tools/segmentation/strategies/compositions/islandRemoval.ts +1 -2
  80. package/src/tools/segmentation/strategies/compositions/threshold.ts +8 -6
  81. package/src/tools/segmentation/strategies/utils/getStrategyData.ts +20 -5
  82. package/src/utilities/pointInShapeCallback.ts +2 -0
  83. package/src/utilities/segmentation/floodFill.ts +44 -31
  84. package/src/utilities/segmentation/getSegmentAtLabelmapBorder.ts +6 -5
  85. package/src/utilities/segmentation/getSegmentAtWorldPoint.ts +6 -5
@@ -1 +1 @@
1
- {"version":3,"file":"985.index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,8CAA+CA,QAAQ,yCAA0CA,QAAQ,uBAAwBA,QAAQ,cACjJ,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,6CAA8C,wCAAyC,sBAAuB,aAAcJ,GAC1G,iBAAZC,QACdA,QAA4B,mBAAID,EAAQG,QAAQ,8CAA+CA,QAAQ,yCAA0CA,QAAQ,uBAAwBA,QAAQ,cAEzLJ,EAAyB,mBAAIC,EAAQD,EAAK,8CAA+CA,EAAK,yCAA0CA,EAAoB,cAAGA,EAAa,OAC7K,CATD,CASGO,MAAM,CAACC,EAAkCC,EAAkCC,EAAkCC,I,uBCT5GC,ECAAC,E,oFCGJ,MAAM,QAAEC,GAAYC,EAAAA,UAqGb,SAASC,EACdC,EACAC,GAEA,OAlGF,SACED,EACAE,GAEa,IAAAC,EAAA,IADbC,EAAOC,UAAAC,O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A,QAAQ,QAAS,IAAIA,QAAQ,YAAa,KACpFhD,EAAoBjM,EAAIyO,C,WCdxB,IAAIS,EAAkB,CACrB,IAAK,GAkBNjD,EAAoB0B,EAAE5N,EAAI,CAAC8N,EAASpD,KAE/ByE,EAAgBrB,IAElBa,cAAczC,EAAoBjM,EAAIiM,EAAoB8B,EAAEF,GAE9D,EAGD,IAAIsB,EAAqB9Q,KAAqC,+BAAIA,KAAqC,gCAAK,GACxG+Q,EAA6BD,EAAmB7L,KAAK+L,KAAKF,GAC9DA,EAAmB7L,KAzBCyF,IACnB,IAAI0D,EAAW1D,EAAK,GAChBuG,EAAcvG,EAAK,GACnBwG,EAAUxG,EAAK,GACnB,IAAI,IAAImD,KAAYoD,EAChBrD,EAAoBuB,EAAE8B,EAAapD,KACrCD,EAAoBI,EAAEH,GAAYoD,EAAYpD,IAIhD,IADGqD,GAASA,EAAQtD,GACdQ,EAASpN,QACd6P,EAAgBzC,EAAS+C,OAAS,EACnCJ,EAA2BrG,EAAK,C,KpBrB7BpK,EAAOsN,EAAoBK,EAC/BL,EAAoBK,EAAI,IAChBL,EAAoB2B,EAAE,IAAInH,KAAK9H,GqBDbsN,EAAoBK,G","sources":["webpack://cornerstoneTools3D/webpack/universalModuleDefinition","webpack://cornerstoneTools3D/webpack/runtime/chunk loaded","webpack://cornerstoneTools3D/webpack/runtime/startup chunk dependencies","webpack://cornerstoneTools3D/./src/utilities/boundingBox/getBoundingBoxAroundShape.ts","webpack://cornerstoneTools3D/./src/utilities/pointInShapeCallback.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/isPointInsidePolyline3D.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/containsPoint.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/isClosed.ts","webpack://cornerstoneTools3D/./src/utilities/math/point/distanceToPointSquared.ts","webpack://cornerstoneTools3D/./src/workers/polySegConverters.js","webpack://cornerstoneTools3D/external umd \"@kitware/vtk.js/Common/Core/DataArray\"","webpack://cornerstoneTools3D/external umd \"@kitware/vtk.js/Common/DataModel/ImageData\"","webpack://cornerstoneTools3D/external umd {\"root\":\"cornerstone3D\",\"commonjs\":\"@cornerstonejs/core\",\"commonjs2\":\"@cornerstonejs/core\",\"amd\":\"@cornerstonejs/core\"}","webpack://cornerstoneTools3D/external umd {\"root\":\"window\",\"commonjs\":\"gl-matrix\",\"commonjs2\":\"gl-matrix\",\"amd\":\"gl-matrix\"}","webpack://cornerstoneTools3D/webpack/bootstrap","webpack://cornerstoneTools3D/webpack/runtime/compat get default export","webpack://cornerstoneTools3D/webpack/runtime/define property getters","webpack://cornerstoneTools3D/webpack/runtime/ensure chunk","webpack://cornerstoneTools3D/webpack/runtime/get javascript chunk filename","webpack://cornerstoneTools3D/webpack/runtime/global","webpack://cornerstoneTools3D/webpack/runtime/hasOwnProperty shorthand","webpack://cornerstoneTools3D/webpack/runtime/publicPath","webpack://cornerstoneTools3D/webpack/runtime/importScripts chunk loading","webpack://cornerstoneTools3D/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@kitware/vtk.js/Common/DataModel/ImageData\"), require(\"@kitware/vtk.js/Common/Core/DataArray\"), require(\"@cornerstonejs/core\"), require(\"gl-matrix\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@kitware/vtk.js/Common/DataModel/ImageData\", \"@kitware/vtk.js/Common/Core/DataArray\", \"@cornerstonejs/core\", \"gl-matrix\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"cornerstoneTools3D\"] = factory(require(\"@kitware/vtk.js/Common/DataModel/ImageData\"), require(\"@kitware/vtk.js/Common/Core/DataArray\"), require(\"@cornerstonejs/core\"), require(\"gl-matrix\"));\n\telse\n\t\troot[\"cornerstoneTools3D\"] = factory(root[\"@kitware/vtk.js/Common/DataModel/ImageData\"], root[\"@kitware/vtk.js/Common/Core/DataArray\"], root[\"cornerstone3D\"], root[\"window\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__283__, __WEBPACK_EXTERNAL_MODULE__785__, __WEBPACK_EXTERNAL_MODULE__953__, __WEBPACK_EXTERNAL_MODULE__976__) => {\nreturn ","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar chunkIds = deferred[i][0];\n\t\tvar fn = deferred[i][1];\n\t\tvar priority = deferred[i][2];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","var next = __webpack_require__.x;\n__webpack_require__.x = () => {\n\treturn __webpack_require__.e(78).then(next);\n};","import type { Types } from '@cornerstonejs/core';\nimport { CONSTANTS } from '@cornerstonejs/core';\n\nconst { EPSILON } = CONSTANTS;\n\n/** Bounding box type */\ntype BoundingBox =\n | [Types.Point2, Types.Point2, null]\n | [Types.Point2, Types.Point2, Types.Point2];\n\nfunction calculateBoundingBox(\n points,\n dimensions,\n isWorld = false\n): BoundingBox {\n let xMin = Infinity;\n let xMax = isWorld ? -Infinity : 0;\n let yMin = Infinity;\n let yMax = isWorld ? -Infinity : 0;\n let zMin = Infinity;\n let zMax = isWorld ? -Infinity : 0;\n\n const is3D = points[0]?.length === 3;\n\n // use for loop for performance\n for (let i = 0; i < points.length; i++) {\n const p = points[i];\n xMin = Math.min(p[0], xMin);\n xMax = Math.max(p[0], xMax);\n yMin = Math.min(p[1], yMin);\n yMax = Math.max(p[1], yMax);\n\n if (is3D) {\n zMin = Math.min(p[2] ?? zMin, zMin);\n zMax = Math.max(p[2] ?? zMax, zMax);\n }\n }\n\n if (dimensions) {\n xMin = Math.max(isWorld ? dimensions[0] + EPSILON : 0, xMin);\n xMax = Math.min(\n isWorld ? dimensions[0] - EPSILON : dimensions[0] - 1,\n xMax\n );\n yMin = Math.max(isWorld ? dimensions[1] + EPSILON : 0, yMin);\n yMax = Math.min(\n isWorld ? dimensions[1] - EPSILON : dimensions[1] - 1,\n yMax\n );\n\n if (is3D && dimensions.length === 3) {\n zMin = Math.max(isWorld ? dimensions[2] + EPSILON : 0, zMin);\n zMax = Math.min(\n isWorld ? dimensions[2] - EPSILON : dimensions[2] - 1,\n zMax\n );\n }\n } else if (!isWorld) {\n // still need to bound to 0 and Infinity if no dimensions are provided for ijk\n xMin = Math.max(0, xMin);\n xMax = Math.min(Infinity, xMax);\n yMin = Math.max(0, yMin);\n yMax = Math.min(Infinity, yMax);\n\n if (is3D) {\n zMin = Math.max(0, zMin);\n zMax = Math.min(Infinity, zMax);\n }\n }\n\n return is3D\n ? [\n [xMin, xMax],\n [yMin, yMax],\n [zMin, zMax],\n ]\n : [[xMin, xMax], [yMin, yMax], null];\n}\n\n/**\n * With a given vertices (points) coordinates in 2D or 3D in IJK, it calculates the minimum and maximum\n * coordinate in each axis, and returns them. If clipBounds are provided it also\n * clip the min, max to the provided width, height and depth\n *\n * @param points - shape corner points coordinates either in IJK (image coordinate)\n * @param dimensions - bounds to clip the min, max\n * @returns [[xMin,xMax],[yMin,yMax], [zMin,zMax]]\n */\nexport function getBoundingBoxAroundShapeIJK(\n points: Types.Point2[] | Types.Point3[],\n dimensions?: Types.Point2 | Types.Point3\n): BoundingBox {\n return calculateBoundingBox(points, dimensions, false);\n}\n\n/**\n * With a given vertices (points) coordinates in 2D or 3D in World Coordinates, it calculates the minimum and maximum\n * coordinate in each axis, and returns them. If clipBounds are provided it also\n * clip the min, max to the provided width, height and depth\n *\n * @param points - shape corner points coordinates either in IJK (image coordinate)\n * @param clipBounds - bounds to clip the min, max\n * @returns [[xMin,xMax],[yMin,yMax], [zMin,zMax]]\n */\nexport function getBoundingBoxAroundShapeWorld(\n points: Types.Point2[] | Types.Point3[],\n clipBounds?: Types.Point2 | Types.Point3\n): BoundingBox {\n return calculateBoundingBox(points, clipBounds, true);\n}\n","import { vec3 } from 'gl-matrix';\nimport type { Types } from '@cornerstonejs/core';\nimport type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';\nimport BoundsIJK from '../types/BoundsIJK';\n\nexport type PointInShape = {\n value: number;\n index: number;\n pointIJK: vec3;\n pointLPS: vec3;\n};\n\nexport type PointInShapeCallback = ({\n value,\n index,\n pointIJK,\n pointLPS,\n}: {\n value: number;\n index: number;\n pointIJK: vec3;\n pointLPS: vec3;\n}) => void;\n\nexport type ShapeFnCriteria = (pointLPS: vec3, pointIJK: vec3) => boolean;\n\n/**\n * For each point in the image (If boundsIJK is not provided, otherwise, for each\n * point in the provided bounding box), It runs the provided callback IF the point\n * passes the provided criteria to be inside the shape (which is defined by the\n * provided pointInShapeFn)\n *\n * @param imageData - The image data object.\n * @param dimensions - The dimensions of the image.\n * @param pointInShapeFn - A function that takes a point in LPS space and returns\n * true if the point is in the shape and false if it is not.\n * @param callback - A function that will be called for\n * every point in the shape.\n * @param boundsIJK - The bounds of the volume in IJK coordinates.\n */\nexport default function pointInShapeCallback(\n imageData: vtkImageData | Types.CPUImageData,\n pointInShapeFn: ShapeFnCriteria,\n callback?: PointInShapeCallback,\n boundsIJK?: BoundsIJK\n): Array<PointInShape> {\n let iMin, iMax, jMin, jMax, kMin, kMax;\n\n let scalarData;\n\n // if getScalarData is a method on imageData\n if ((imageData as Types.CPUImageData).getScalarData) {\n scalarData = (imageData as Types.CPUImageData).getScalarData();\n } else {\n scalarData = (imageData as vtkImageData)\n .getPointData()\n .getScalars()\n .getData();\n }\n\n const dimensions = imageData.getDimensions();\n\n if (!boundsIJK) {\n iMin = 0;\n iMax = dimensions[0];\n jMin = 0;\n jMax = dimensions[1];\n kMin = 0;\n kMax = dimensions[2];\n } else {\n [[iMin, iMax], [jMin, jMax], [kMin, kMax]] = boundsIJK;\n }\n\n const start = vec3.fromValues(iMin, jMin, kMin);\n\n const direction = imageData.getDirection();\n const rowCosines = direction.slice(0, 3);\n const columnCosines = direction.slice(3, 6);\n const scanAxisNormal = direction.slice(6, 9);\n\n const spacing = imageData.getSpacing();\n const [rowSpacing, columnSpacing, scanAxisSpacing] = spacing;\n\n // @ts-ignore will be fixed in vtk-master\n const worldPosStart = imageData.indexToWorld(start);\n\n const rowStep = vec3.fromValues(\n rowCosines[0] * rowSpacing,\n rowCosines[1] * rowSpacing,\n rowCosines[2] * rowSpacing\n );\n\n const columnStep = vec3.fromValues(\n columnCosines[0] * columnSpacing,\n columnCosines[1] * columnSpacing,\n columnCosines[2] * columnSpacing\n );\n\n const scanAxisStep = vec3.fromValues(\n scanAxisNormal[0] * scanAxisSpacing,\n scanAxisNormal[1] * scanAxisSpacing,\n scanAxisNormal[2] * scanAxisSpacing\n );\n\n const xMultiple =\n scalarData.length / dimensions[2] / dimensions[1] / dimensions[0];\n const yMultiple = dimensions[0] * xMultiple;\n const zMultiple = dimensions[1] * yMultiple;\n\n const pointsInShape: Array<PointInShape> = [];\n\n const currentPos = vec3.clone(worldPosStart);\n\n for (let k = kMin; k <= kMax; k++) {\n const startPosJ = vec3.clone(currentPos);\n\n for (let j = jMin; j <= jMax; j++) {\n const startPosI = vec3.clone(currentPos);\n\n for (let i = iMin; i <= iMax; i++) {\n const pointIJK: Types.Point3 = [i, j, k];\n\n // The current world position (pointLPS) is now in currentPos\n if (pointInShapeFn(currentPos as Types.Point3, pointIJK)) {\n const index = k * zMultiple + j * yMultiple + i * xMultiple;\n let value;\n if (xMultiple > 2) {\n value = [\n scalarData[index],\n scalarData[index + 1],\n scalarData[index + 2],\n ];\n } else {\n value = scalarData[index];\n }\n\n pointsInShape.push({ value, index, pointIJK, pointLPS: currentPos });\n if (callback) {\n callback({ value, index, pointIJK, pointLPS: currentPos });\n }\n }\n\n // Increment currentPos by rowStep for the next iteration\n vec3.add(currentPos, currentPos, rowStep);\n }\n\n // Reset currentPos to the start of the next J line and increment by columnStep\n vec3.copy(currentPos, startPosI);\n vec3.add(currentPos, currentPos, columnStep);\n }\n\n // Reset currentPos to the start of the next K slice and increment by scanAxisStep\n vec3.copy(currentPos, startPosJ);\n vec3.add(currentPos, currentPos, scanAxisStep);\n }\n\n return pointsInShape;\n}\n","import type { Types } from '@cornerstonejs/core';\nimport containsPoint from './containsPoint';\n\n/**\n * Determines whether a 3D point is inside a polyline in 3D space.\n *\n * The algorithm works by reducing the polyline and point to 2D space, and then\n * using the 2D algorithm to determine whether the point is inside the polyline.\n *\n * @param point - The 3D point to test.\n * @param polyline - The polyline represented as an array of 3D points.\n * @returns A boolean indicating whether the point is inside the polyline.\n * @throws An error if a shared dimension index cannot be found for the polyline points.\n */\nexport function isPointInsidePolyline3D(\n point: Types.Point3,\n polyline: Types.Point3[]\n) {\n // Todo: handle oblique planes\n\n // We need to reduce one dimension to 2D, so basically\n // we need to find the dimension index that is shared by all points\n // Use the first three points, two is enough but three is more robust\n let sharedDimensionIndex;\n\n const testPoints = polyline.slice(0, 3);\n for (let i = 0; i < 3; i++) {\n if (testPoints.every((point, index, array) => point[i] === array[0][i])) {\n sharedDimensionIndex = i;\n break;\n }\n }\n\n if (sharedDimensionIndex === undefined) {\n throw new Error(\n 'Cannot find a shared dimension index for polyline, probably oblique plane'\n );\n }\n\n // convert polyline list and point to 2D\n const points2D = [] as Types.Point2[];\n\n for (let i = 0; i < polyline.length; i++) {\n points2D.push([\n polyline[i][(sharedDimensionIndex + 1) % 3],\n polyline[i][(sharedDimensionIndex + 2) % 3],\n ]);\n }\n\n const point2D = [\n point[(sharedDimensionIndex + 1) % 3],\n point[(sharedDimensionIndex + 2) % 3],\n ] as Types.Point2;\n\n return containsPoint(points2D, point2D);\n}\n","import type { Types } from '@cornerstonejs/core';\nimport isClosed from './isClosed';\n\n/**\n * Checks if a 2D point is inside the polyline.\n *\n * A point is inside a curve/polygon if the number of intersections between the horizontal\n * ray emanating from the given point and to the right and the line segments is odd.\n * https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html\n *\n * Note that a point on the polyline is considered inside.\n *\n * @param polyline - Polyline points (2D)\n * @param point - 2D Point\n * @returns True if the point is inside the polyline or false otherwise\n */\nexport default function containsPoint(\n polyline: Types.Point2[],\n point: Types.Point2,\n closed?: boolean\n): boolean {\n if (polyline.length < 3) {\n return false;\n }\n\n const numPolylinePoints = polyline.length;\n let numIntersections = 0;\n\n // Test intersection against [end, start] line segment if it should be closed\n const shouldClose = !(closed === undefined ? isClosed(polyline) : closed);\n const maxSegmentIndex = polyline.length - (shouldClose ? 1 : 2);\n\n for (let i = 0; i <= maxSegmentIndex; i++) {\n const p1 = polyline[i];\n\n // Calculating the next point index without using % (mod) operator like in\n // `(i + 1) % numPolylinePoints` to make it 20% faster\n const p2Index = i === numPolylinePoints - 1 ? 0 : i + 1;\n const p2 = polyline[p2Index];\n\n // Calculating min/max without using Math.min/max to make it ~3% faster\n const maxX = p1[0] >= p2[0] ? p1[0] : p2[0];\n const maxY = p1[1] >= p2[1] ? p1[1] : p2[1];\n const minY = p1[1] <= p2[1] ? p1[1] : p2[1];\n\n const mayIntersectLineSegment =\n point[0] <= maxX && point[1] >= minY && point[1] < maxY;\n\n if (mayIntersectLineSegment) {\n const isVerticalLine = p1[0] === p2[0];\n let intersects = isVerticalLine;\n\n if (!intersects) {\n const xIntersection =\n ((point[1] - p1[1]) * (p2[0] - p1[0])) / (p2[1] - p1[1]) + p1[0];\n\n intersects = point[0] <= xIntersection;\n }\n\n numIntersections += intersects ? 1 : 0;\n }\n }\n\n return !!(numIntersections % 2);\n}\n","import { glMatrix } from 'gl-matrix';\nimport type { Types } from '@cornerstonejs/core';\nimport * as math from '..';\n\n/**\n * A polyline is considered closed if the start and end points are at the same position\n *\n * @param polyline - Polyline points (2D)\n * @returns True if the polyline is already closed or false otherwise\n */\nexport default function isClosed(polyline: Types.Point2[]): boolean {\n if (polyline.length < 3) {\n return false;\n }\n\n const numPolylinePoints = polyline.length;\n\n const firstPoint = polyline[0];\n const lastPoint = polyline[numPolylinePoints - 1];\n const distFirstToLastPoints = math.point.distanceToPointSquared(\n firstPoint,\n lastPoint\n );\n\n return glMatrix.equals(0, distFirstToLastPoints);\n}\n","import type { Types } from '@cornerstonejs/core';\n\ntype Point = Types.Point2 | Types.Point3;\n\n/**\n * Calculates the distance squared of a point to another point\n *\n * @param p1 - x,y or x,y,z of the point\n * @param p2 - x,y or x,y,z of the point\n * @returns distance\n */\nexport default function distanceToPointSquared(p1: Point, p2: Point): number {\n if (p1.length !== p2.length) {\n throw Error('Both points should have the same dimensionality');\n }\n\n const [x1, y1, z1 = 0] = p1;\n const [x2, y2, z2 = 0] = p2;\n const dx = x2 - x1;\n const dy = y2 - y1;\n const dz = z2 - z1;\n\n // Time to square 10M numbers:\n // (n * n) = 161ms | (n ** 2) = 199ms | Math.pow(n, 2) = 29529ms\n return dx * dx + dy * dy + dz * dz;\n}\n","import { expose } from 'comlink';\nimport vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';\nimport vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';\nimport ICRPolySeg from '@icr/polyseg-wasm';\nimport { utilities } from '@cornerstonejs/core';\nimport { getBoundingBoxAroundShapeWorld } from '../utilities/boundingBox';\nimport { pointInShapeCallback } from '../utilities';\nimport { isPointInsidePolyline3D } from '../utilities/math/polyline';\n\n/**\n * Object containing methods for converting between different representations of\n * segmentations (e.g., contour, labelmap, surface, etc.) These logics\n * are used in a webworker to avoid blocking the main thread. You can\n * search for workerManager.executeTask('polySeg', ...) to see\n * how these methods are used.\n *\n * See also the webworker docs at packages/docs/docs/concepts/cornerstone-core/web-worker.md\n * to learn more about how to use webworkers in the context of Cornerstone.\n */\nconst polySegConverters = {\n /**\n * The polySeg instance that is used to convert between different representations\n */\n polySeg: null,\n /**\n * Utilities to keep track of the initialization state of the polySeg instance\n * and avoid initializing it multiple times\n */\n polySegInitializing: false,\n polySegInitializingPromise: null,\n /**\n * This method initializes the polySeg instance and sets it to this.polySeg\n */\n async initializePolySeg(progressCallback) {\n if (this.polySegInitializing) {\n await this.polySegInitializingPromise;\n return;\n }\n\n if (this.polySeg?.instance) {\n return;\n }\n\n this.polySegInitializing = true;\n this.polySegInitializingPromise = new Promise((resolve) => {\n this.polySeg = new ICRPolySeg();\n this.polySeg\n .initialize({\n updateProgress: progressCallback,\n })\n .then(() => {\n this.polySegInitializing = false;\n resolve();\n });\n });\n\n await this.polySegInitializingPromise;\n },\n /**\n * Converts a contour to a surface using the PolySeg library.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.polylines - The polylines representing the contour.\n * @param {Array} args.numPointsArray - The number of points in each polyline.\n * @param {...Function} callbacks - Optional callback functions.\n * @returns {Promise} - A promise that resolves to the converted surface.\n */\n async convertContourToSurface(args, ...callbacks) {\n const { polylines, numPointsArray } = args;\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n const results = await this.polySeg.instance.convertContourRoiToSurface(\n polylines,\n numPointsArray\n );\n\n return results;\n },\n /**\n * Converts a labelmap to a surface using the specified arguments.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.scalarData - The scalar data of the labelmap.\n * @param {Array} args.dimensions - The dimensions of the labelmap.\n * @param {Array} args.spacing - The spacing of the labelmap.\n * @param {Array} args.direction - The direction of the labelmap.\n * @param {Array} args.origin - The origin of the labelmap.\n * @param {number} args.segmentIndex - The segment index of the labelmap.\n * @param {Function} progressCallback - The callback function for progress updates.\n * @returns {Promise} - A promise that resolves with the converted surface results.\n */\n async convertLabelmapToSurface(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const results = this.polySeg.instance.convertLabelmapToSurface(\n args.scalarData,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin,\n [args.segmentIndex]\n );\n return results;\n },\n /**\n * Converts a contour to a volume labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.segmentIndices - The indices of the segments.\n * @param {Array} args.scalarData - The scalar data.\n * @param {Map} args.annotationUIDsInSegmentMap - The map of annotation UIDs in segment.\n * @param {Array} args.dimensions - The dimensions of the image data.\n * @param {Array} args.origin - The origin of the image data.\n * @param {Array} args.direction - The direction of the image data.\n * @param {Array} args.spacing - The spacing of the image data.\n * @param {...Function} callbacks - Optional callbacks.\n * @param {Function} callbacks[0] - The progress callback.\n * @returns {Array} - The scalar data of the segmentation voxel manager.\n */\n async convertContourToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n const polySeg = await new ICRPolySeg();\n await polySeg.initialize({\n updateProgress: progressCallback,\n });\n\n const {\n segmentIndices,\n scalarData,\n annotationUIDsInSegmentMap,\n dimensions,\n origin,\n direction,\n spacing,\n } = args;\n\n const segmentationVoxelManager =\n utilities.VoxelManager.createVolumeVoxelManager(dimensions, scalarData);\n\n const imageData = vtkImageData.newInstance();\n imageData.setDimensions(dimensions);\n imageData.setOrigin(origin);\n imageData.setDirection(direction);\n imageData.setSpacing(spacing);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: scalarData,\n });\n\n imageData.getPointData().setScalars(scalarArray);\n\n imageData.modified();\n\n for (const index of segmentIndices) {\n const annotations = annotationUIDsInSegmentMap.get(index);\n\n for (const annotation of annotations) {\n const bounds = getBoundingBoxAroundShapeWorld(\n annotation.data.contour.polyline\n );\n\n const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [\n bounds[0][0],\n bounds[1][0],\n bounds[2][0],\n ]);\n\n const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [\n bounds[0][1],\n bounds[1][1],\n bounds[2][1],\n ]);\n\n // Run the pointInShapeCallback for the combined bounding box\n pointInShapeCallback(\n imageData,\n (pointLPS) => {\n // Check if the point is inside any of the polylines for this segment\n return isPointInsidePolyline3D(\n pointLPS,\n annotation.data.contour.polyline\n );\n },\n ({ pointIJK }) => {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, index);\n },\n [\n [iMin, iMax],\n [jMin, jMax],\n [kMin, kMax],\n ]\n );\n }\n }\n\n return segmentationVoxelManager.scalarData;\n },\n /**\n * Converts a contour to a stack labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} callbacks - Optional callbacks for progress updates.\n * @returns {Promise<Object>} - The converted segmentations information.\n */\n async convertContourToStackLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n const polySeg = await new ICRPolySeg();\n await polySeg.initialize({\n updateProgress: progressCallback,\n });\n\n const { segmentationsInfo, annotationUIDsInSegmentMap, segmentIndices } =\n args;\n\n const segmentationVoxelManagers = new Map();\n\n segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {\n const { dimensions, scalarData, direction, spacing, origin } =\n segmentationInfo;\n const manager = utilities.VoxelManager.createVolumeVoxelManager(\n dimensions,\n scalarData\n );\n\n const imageData = vtkImageData.newInstance();\n imageData.setDimensions(dimensions);\n imageData.setOrigin(origin);\n imageData.setDirection(direction);\n imageData.setSpacing(spacing);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: scalarData,\n });\n\n imageData.getPointData().setScalars(scalarArray);\n\n imageData.modified();\n\n segmentationVoxelManagers.set(referencedImageId, { manager, imageData });\n });\n\n for (const index of segmentIndices) {\n const annotations = annotationUIDsInSegmentMap.get(index);\n\n for (const annotation of annotations) {\n if (!annotation?.data) {\n continue;\n }\n const bounds = getBoundingBoxAroundShapeWorld(\n annotation.data.contour.polyline\n );\n\n const { referencedImageId } = annotation.metadata;\n\n const { manager: segmentationVoxelManager, imageData } =\n segmentationVoxelManagers.get(referencedImageId);\n\n const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [\n bounds[0][0],\n bounds[1][0],\n bounds[2][0],\n ]);\n\n const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [\n bounds[0][1],\n bounds[1][1],\n bounds[2][1],\n ]);\n\n // Run the pointInShapeCallback for the combined bounding box\n pointInShapeCallback(\n imageData,\n (pointLPS) => {\n // Check if the point is inside any of the polylines for this segment\n return isPointInsidePolyline3D(\n pointLPS,\n annotation.data.contour.polyline\n );\n },\n ({ pointIJK }) => {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, index);\n },\n [\n [iMin, iMax],\n [jMin, jMax],\n [kMin, kMax],\n ]\n );\n }\n }\n\n segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {\n const { manager: segmentationVoxelManager } =\n segmentationVoxelManagers.get(referencedImageId);\n\n segmentationInfo.scalarData = segmentationVoxelManager.scalarData;\n });\n return segmentationsInfo;\n },\n /**\n * Converts a surface to a volume labelmap.\n *\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.points - The points defining the surface.\n * @param {Array} args.polys - The polygons defining the surface.\n * @param {Array} args.dimensions - The dimensions of the volume.\n * @param {Array} args.spacing - The spacing between voxels in the volume.\n * @param {Array} args.direction - The direction of the volume.\n * @param {Array} args.origin - The origin of the volume.\n * @param {Function} progressCallback - The callback function for reporting progress.\n * @returns {Promise} - A promise that resolves with the converted labelmap.\n */\n async convertSurfaceToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const results = this.polySeg.instance.convertSurfaceToLabelmap(\n args.points,\n args.polys,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin\n );\n\n return results;\n },\n /**\n * Converts surfaces to a volume labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Map} args.segmentsInfo - A map containing information about the segments.\n * @param {Function} progressCallback - A callback function for reporting progress.\n * @returns {Uint8Array} - The resulting volume labelmap.\n */\n async convertSurfacesToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const { segmentsInfo } = args;\n\n const promises = Array.from(segmentsInfo.keys()).map((segmentIndex) => {\n const { points, polys } = segmentsInfo.get(segmentIndex);\n const result = this.polySeg.instance.convertSurfaceToLabelmap(\n points,\n polys,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin\n );\n\n return {\n ...result,\n segmentIndex,\n };\n });\n\n const results = await Promise.all(promises);\n\n const targetImageData = vtkImageData.newInstance();\n targetImageData.setDimensions(args.dimensions);\n targetImageData.setOrigin(args.origin);\n targetImageData.setSpacing(args.spacing);\n targetImageData.setDirection(args.direction);\n\n const totalSize =\n args.dimensions[0] * args.dimensions[1] * args.dimensions[2];\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: new Uint8Array(totalSize),\n });\n\n targetImageData.getPointData().setScalars(scalarArray);\n targetImageData.modified();\n\n // we need to then consolidate the results into a single volume\n // by looping into each voxel with pointInShapeCallback\n // and check if the voxel is inside any of the reconstructed\n // labelmaps\n\n const segmentationVoxelManager =\n utilities.VoxelManager.createVolumeVoxelManager(\n args.dimensions,\n targetImageData.getPointData().getScalars().getData()\n );\n\n const outputVolumesInfo = results.map((result) => {\n const { data, dimensions, direction, origin, spacing } = result;\n const volume = vtkImageData.newInstance();\n volume.setDimensions(dimensions);\n volume.setOrigin(origin);\n volume.setSpacing(spacing);\n volume.setDirection(direction);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: data,\n });\n\n volume.getPointData().setScalars(scalarArray);\n\n volume.modified();\n\n const voxelManager = utilities.VoxelManager.createVolumeVoxelManager(\n dimensions,\n data\n );\n\n const extent = volume.getExtent(); // e.g., [0, 176, 0, 268, 0, 337] for dimensions of [177, 269, 338]\n\n return {\n volume,\n voxelManager,\n extent,\n scalarData: data,\n segmentIndex: result.segmentIndex,\n };\n });\n\n pointInShapeCallback(\n targetImageData,\n () => true, // we want to loop into all voxels\n ({ pointIJK, pointLPS }) => {\n // Check if the point is inside any of the reconstructed labelmaps\n // Todo: we can optimize this by returning early if the bounding box\n // of the point is outside the bounding box of the labelmap\n\n try {\n for (const volumeInfo of outputVolumesInfo) {\n const { volume, extent, voxelManager, segmentIndex } = volumeInfo;\n\n const index = volume.worldToIndex(pointLPS);\n\n // check if the ijk point is inside the volume\n if (\n index[0] < extent[0] ||\n index[0] > extent[1] ||\n index[1] < extent[2] ||\n index[1] > extent[3] ||\n index[2] < extent[4] ||\n index[2] > extent[5]\n ) {\n continue;\n }\n\n const roundedIndex = index.map(Math.round);\n const value = voxelManager.getAtIJK(...roundedIndex);\n if (value > 0) {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, segmentIndex);\n break;\n }\n }\n } catch (error) {\n // right now there is weird error if the point is outside the volume\n }\n }\n );\n\n return segmentationVoxelManager.scalarData;\n },\n};\n\nexpose(polySegConverters);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__785__;","module.exports = __WEBPACK_EXTERNAL_MODULE__283__;","module.exports = __WEBPACK_EXTERNAL_MODULE__953__;","module.exports = __WEBPACK_EXTERNAL_MODULE__976__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n// the startup function\n__webpack_require__.x = () => {\n\t// Load entry module and return exports\n\t// This entry module depends on other loaded chunks and execution need to be delayed\n\tvar __webpack_exports__ = __webpack_require__.O(undefined, [78], () => (__webpack_require__(248)))\n\t__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n\treturn __webpack_exports__;\n};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.f = {};\n// This file contains only the entry chunk.\n// The chunk loading function for additional chunks\n__webpack_require__.e = (chunkId) => {\n\treturn Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {\n\t\t__webpack_require__.f[key](chunkId, promises);\n\t\treturn promises;\n\t}, []));\n};","// This function allow to reference async chunks and sibling chunks for the entrypoint\n__webpack_require__.u = (chunkId) => {\n\t// return url for filenames based on template\n\treturn \"\" + chunkId + \".index.js\";\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","var scriptUrl;\nif (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + \"\";\nvar document = __webpack_require__.g.document;\nif (!scriptUrl && document) {\n\tif (document.currentScript)\n\t\tscriptUrl = document.currentScript.src;\n\tif (!scriptUrl) {\n\t\tvar scripts = document.getElementsByTagName(\"script\");\n\t\tif(scripts.length) {\n\t\t\tvar i = scripts.length - 1;\n\t\t\twhile (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;\n\t\t}\n\t}\n}\n// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration\n// or pass an empty string (\"\") and set the __webpack_public_path__ variable from your code to use your own logic.\nif (!scriptUrl) throw new Error(\"Automatic publicPath is not supported in this browser\");\nscriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\?.*$/, \"\").replace(/\\/[^\\/]+$/, \"/\");\n__webpack_require__.p = scriptUrl;","// no baseURI\n\n// object to store loaded chunks\n// \"1\" means \"already loaded\"\nvar installedChunks = {\n\t985: 1\n};\n\n// importScripts chunk loading\nvar installChunk = (data) => {\n\tvar chunkIds = data[0];\n\tvar moreModules = data[1];\n\tvar runtime = data[2];\n\tfor(var moduleId in moreModules) {\n\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t}\n\t}\n\tif(runtime) runtime(__webpack_require__);\n\twhile(chunkIds.length)\n\t\tinstalledChunks[chunkIds.pop()] = 1;\n\tparentChunkLoadingFunction(data);\n};\n__webpack_require__.f.i = (chunkId, promises) => {\n\t// \"1\" is the signal for \"already loaded\"\n\tif(!installedChunks[chunkId]) {\n\t\tif(true) { // all chunks have JS\n\t\t\timportScripts(__webpack_require__.p + __webpack_require__.u(chunkId));\n\t\t}\n\t}\n};\n\nvar chunkLoadingGlobal = self[\"webpackChunkcornerstoneTools3D\"] = self[\"webpackChunkcornerstoneTools3D\"] || [];\nvar parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);\nchunkLoadingGlobal.push = installChunk;\n\n// no HMR\n\n// no HMR manifest","// run startup\nvar __webpack_exports__ = __webpack_require__.x();\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__283__","__WEBPACK_EXTERNAL_MODULE__785__","__WEBPACK_EXTERNAL_MODULE__953__","__WEBPACK_EXTERNAL_MODULE__976__","deferred","next","EPSILON","CONSTANTS","getBoundingBoxAroundShapeWorld","points","clipBounds","dimensions","_points$","isWorld","arguments","length","undefined","xMin","Infinity","xMax","yMin","yMax","zMin","zMax","is3D","i","p","_p$","_p$2","Math","min","max","calculateBoundingBox","pointInShapeCallback","imageData","pointInShapeFn","callback","boundsIJK","iMin","iMax","jMin","jMax","kMin","kMax","scalarData","getScalarData","getPointData","getScalars","getData","getDimensions","start","vec3","direction","getDirection","rowCosines","slice","columnCosines","scanAxisNormal","spacing","getSpacing","rowSpacing","columnSpacing","scanAxisSpacing","worldPosStart","indexToWorld","rowStep","columnStep","scanAxisStep","xMultiple","yMultiple","zMultiple","pointsInShape","currentPos","k","startPosJ","j","startPosI","pointIJK","index","value","push","pointLPS","isPointInsidePolyline3D","point","polyline","sharedDimensionIndex","testPoints","every","array","Error","points2D","closed","numPolylinePoints","numIntersections","shouldClose","distFirstToLastPoints","p1","p2","x1","y1","z1","x2","y2","z2","dx","dy","dz","math","glMatrix","isClosed","maxSegmentIndex","maxX","maxY","minY","intersects","xIntersection","containsPoint","polySegConverters","polySeg","polySegInitializing","polySegInitializingPromise","initializePolySeg","progressCallback","_this$polySeg","this","instance","Promise","resolve","ICRPolySeg","initialize","updateProgress","then","convertContourToSurface","args","polylines","numPointsArray","_len","callbacks","Array","_key","convertContourRoiToSurface","convertLabelmapToSurface","_len2","_key2","origin","segmentIndex","convertContourToVolumeLabelmap","_len3","_key3","segmentIndices","annotationUIDsInSegmentMap","segmentationVoxelManager","utilities","vtkImageData","setDimensions","setOrigin","setDirection","setSpacing","scalarArray","vtkDataArray","name","numberOfComponents","values","setScalars","modified","annotations","get","annotation","bounds","data","contour","_ref","setAtIJKPoint","convertContourToStackLabelmap","_len4","_key4","segmentationsInfo","segmentationVoxelManagers","Map","forEach","segmentationInfo","referencedImageId","manager","set","metadata","_ref2","convertSurfaceToVolumeLabelmap","_len5","_key5","convertSurfaceToLabelmap","polys","convertSurfacesToVolumeLabelmap","_len6","_key6","segmentsInfo","promises","from","keys","map","results","all","targetImageData","totalSize","Uint8Array","outputVolumesInfo","result","volume","voxelManager","extent","getExtent","_ref3","volumeInfo","worldToIndex","roundedIndex","round","getAtIJK","error","expose","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","m","x","__webpack_exports__","O","chunkIds","fn","priority","notFulfilled","fulfilled","Object","key","splice","r","n","getter","__esModule","d","a","definition","o","defineProperty","enumerable","f","e","chunkId","reduce","u","g","globalThis","Function","window","obj","prop","prototype","hasOwnProperty","call","scriptUrl","importScripts","location","document","currentScript","src","scripts","getElementsByTagName","replace","installedChunks","chunkLoadingGlobal","parentChunkLoadingFunction","bind","moreModules","runtime","pop"],"sourceRoot":""}
1
+ {"version":3,"file":"985.index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,8CAA+CA,QAAQ,yCAA0CA,QAAQ,uBAAwBA,QAAQ,cACjJ,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,6CAA8C,wCAAyC,sBAAuB,aAAcJ,GAC1G,iBAAZC,QACdA,QAA4B,mBAAID,EAAQG,QAAQ,8CAA+CA,QAAQ,yCAA0CA,QAAQ,uBAAwBA,QAAQ,cAEzLJ,EAAyB,mBAAIC,EAAQD,EAAK,8CAA+CA,EAAK,yCAA0CA,EAAoB,cAAGA,EAAa,OAC7K,CATD,CASGO,MAAM,CAACC,EAAkCC,EAAkCC,EAAkCC,I,uBCT5GC,ECAAC,E,oFCGJ,MAAM,QAAEC,GAAYC,EAAAA,UAqGb,SAASC,EACdC,EACAC,GAEA,OAlGF,SACED,EACAE,GAEa,IAAAC,EAAA,IADbC,EAAOC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,IAAAA,UAAA,GAEHG,EAAOC,IACPC,EAAON,GAAU,IAAY,EAC7BO,EAAOF,IACPG,EAAOR,GAAU,IAAY,EAC7B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ACrB,IAAK,GAkBNjD,EAAoB0B,EAAE7N,EAAI,CAAC+N,EAASpD,KAE/ByE,EAAgBrB,IAElBa,cAAczC,EAAoBlM,EAAIkM,EAAoB8B,EAAEF,GAE9D,EAGD,IAAIsB,EAAqB/Q,KAAqC,+BAAIA,KAAqC,gCAAK,GACxGgR,EAA6BD,EAAmB7L,KAAK+L,KAAKF,GAC9DA,EAAmB7L,KAzBCyF,IACnB,IAAI0D,EAAW1D,EAAK,GAChBuG,EAAcvG,EAAK,GACnBwG,EAAUxG,EAAK,GACnB,IAAI,IAAImD,KAAYoD,EAChBrD,EAAoBuB,EAAE8B,EAAapD,KACrCD,EAAoBI,EAAEH,GAAYoD,EAAYpD,IAIhD,IADGqD,GAASA,EAAQtD,GACdQ,EAASrN,QACd8P,EAAgBzC,EAAS+C,OAAS,EACnCJ,EAA2BrG,EAAK,C,KpBrB7BrK,EAAOuN,EAAoBK,EAC/BL,EAAoBK,EAAI,IAChBL,EAAoB2B,EAAE,IAAInH,KAAK/H,GqBDbuN,EAAoBK,G","sources":["webpack://cornerstoneTools3D/webpack/universalModuleDefinition","webpack://cornerstoneTools3D/webpack/runtime/chunk loaded","webpack://cornerstoneTools3D/webpack/runtime/startup chunk dependencies","webpack://cornerstoneTools3D/./src/utilities/boundingBox/getBoundingBoxAroundShape.ts","webpack://cornerstoneTools3D/./src/utilities/pointInShapeCallback.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/isPointInsidePolyline3D.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/containsPoint.ts","webpack://cornerstoneTools3D/./src/utilities/math/polyline/isClosed.ts","webpack://cornerstoneTools3D/./src/utilities/math/point/distanceToPointSquared.ts","webpack://cornerstoneTools3D/./src/workers/polySegConverters.js","webpack://cornerstoneTools3D/external umd \"@kitware/vtk.js/Common/Core/DataArray\"","webpack://cornerstoneTools3D/external umd \"@kitware/vtk.js/Common/DataModel/ImageData\"","webpack://cornerstoneTools3D/external umd {\"root\":\"cornerstone3D\",\"commonjs\":\"@cornerstonejs/core\",\"commonjs2\":\"@cornerstonejs/core\",\"amd\":\"@cornerstonejs/core\"}","webpack://cornerstoneTools3D/external umd {\"root\":\"window\",\"commonjs\":\"gl-matrix\",\"commonjs2\":\"gl-matrix\",\"amd\":\"gl-matrix\"}","webpack://cornerstoneTools3D/webpack/bootstrap","webpack://cornerstoneTools3D/webpack/runtime/compat get default export","webpack://cornerstoneTools3D/webpack/runtime/define property getters","webpack://cornerstoneTools3D/webpack/runtime/ensure chunk","webpack://cornerstoneTools3D/webpack/runtime/get javascript chunk filename","webpack://cornerstoneTools3D/webpack/runtime/global","webpack://cornerstoneTools3D/webpack/runtime/hasOwnProperty shorthand","webpack://cornerstoneTools3D/webpack/runtime/publicPath","webpack://cornerstoneTools3D/webpack/runtime/importScripts chunk loading","webpack://cornerstoneTools3D/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@kitware/vtk.js/Common/DataModel/ImageData\"), require(\"@kitware/vtk.js/Common/Core/DataArray\"), require(\"@cornerstonejs/core\"), require(\"gl-matrix\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@kitware/vtk.js/Common/DataModel/ImageData\", \"@kitware/vtk.js/Common/Core/DataArray\", \"@cornerstonejs/core\", \"gl-matrix\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"cornerstoneTools3D\"] = factory(require(\"@kitware/vtk.js/Common/DataModel/ImageData\"), require(\"@kitware/vtk.js/Common/Core/DataArray\"), require(\"@cornerstonejs/core\"), require(\"gl-matrix\"));\n\telse\n\t\troot[\"cornerstoneTools3D\"] = factory(root[\"@kitware/vtk.js/Common/DataModel/ImageData\"], root[\"@kitware/vtk.js/Common/Core/DataArray\"], root[\"cornerstone3D\"], root[\"window\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__283__, __WEBPACK_EXTERNAL_MODULE__785__, __WEBPACK_EXTERNAL_MODULE__953__, __WEBPACK_EXTERNAL_MODULE__976__) => {\nreturn ","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar chunkIds = deferred[i][0];\n\t\tvar fn = deferred[i][1];\n\t\tvar priority = deferred[i][2];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","var next = __webpack_require__.x;\n__webpack_require__.x = () => {\n\treturn __webpack_require__.e(78).then(next);\n};","import type { Types } from '@cornerstonejs/core';\nimport { CONSTANTS } from '@cornerstonejs/core';\n\nconst { EPSILON } = CONSTANTS;\n\n/** Bounding box type */\ntype BoundingBox =\n | [Types.Point2, Types.Point2, null]\n | [Types.Point2, Types.Point2, Types.Point2];\n\nfunction calculateBoundingBox(\n points,\n dimensions,\n isWorld = false\n): BoundingBox {\n let xMin = Infinity;\n let xMax = isWorld ? -Infinity : 0;\n let yMin = Infinity;\n let yMax = isWorld ? -Infinity : 0;\n let zMin = Infinity;\n let zMax = isWorld ? -Infinity : 0;\n\n const is3D = points[0]?.length === 3;\n\n // use for loop for performance\n for (let i = 0; i < points.length; i++) {\n const p = points[i];\n xMin = Math.min(p[0], xMin);\n xMax = Math.max(p[0], xMax);\n yMin = Math.min(p[1], yMin);\n yMax = Math.max(p[1], yMax);\n\n if (is3D) {\n zMin = Math.min(p[2] ?? zMin, zMin);\n zMax = Math.max(p[2] ?? zMax, zMax);\n }\n }\n\n if (dimensions) {\n xMin = Math.max(isWorld ? dimensions[0] + EPSILON : 0, xMin);\n xMax = Math.min(\n isWorld ? dimensions[0] - EPSILON : dimensions[0] - 1,\n xMax\n );\n yMin = Math.max(isWorld ? dimensions[1] + EPSILON : 0, yMin);\n yMax = Math.min(\n isWorld ? dimensions[1] - EPSILON : dimensions[1] - 1,\n yMax\n );\n\n if (is3D && dimensions.length === 3) {\n zMin = Math.max(isWorld ? dimensions[2] + EPSILON : 0, zMin);\n zMax = Math.min(\n isWorld ? dimensions[2] - EPSILON : dimensions[2] - 1,\n zMax\n );\n }\n } else if (!isWorld) {\n // still need to bound to 0 and Infinity if no dimensions are provided for ijk\n xMin = Math.max(0, xMin);\n xMax = Math.min(Infinity, xMax);\n yMin = Math.max(0, yMin);\n yMax = Math.min(Infinity, yMax);\n\n if (is3D) {\n zMin = Math.max(0, zMin);\n zMax = Math.min(Infinity, zMax);\n }\n }\n\n return is3D\n ? [\n [xMin, xMax],\n [yMin, yMax],\n [zMin, zMax],\n ]\n : [[xMin, xMax], [yMin, yMax], null];\n}\n\n/**\n * With a given vertices (points) coordinates in 2D or 3D in IJK, it calculates the minimum and maximum\n * coordinate in each axis, and returns them. If clipBounds are provided it also\n * clip the min, max to the provided width, height and depth\n *\n * @param points - shape corner points coordinates either in IJK (image coordinate)\n * @param dimensions - bounds to clip the min, max\n * @returns [[xMin,xMax],[yMin,yMax], [zMin,zMax]]\n */\nexport function getBoundingBoxAroundShapeIJK(\n points: Types.Point2[] | Types.Point3[],\n dimensions?: Types.Point2 | Types.Point3\n): BoundingBox {\n return calculateBoundingBox(points, dimensions, false);\n}\n\n/**\n * With a given vertices (points) coordinates in 2D or 3D in World Coordinates, it calculates the minimum and maximum\n * coordinate in each axis, and returns them. If clipBounds are provided it also\n * clip the min, max to the provided width, height and depth\n *\n * @param points - shape corner points coordinates either in IJK (image coordinate)\n * @param clipBounds - bounds to clip the min, max\n * @returns [[xMin,xMax],[yMin,yMax], [zMin,zMax]]\n */\nexport function getBoundingBoxAroundShapeWorld(\n points: Types.Point2[] | Types.Point3[],\n clipBounds?: Types.Point2 | Types.Point3\n): BoundingBox {\n return calculateBoundingBox(points, clipBounds, true);\n}\n","import { vec3 } from 'gl-matrix';\nimport type { Types } from '@cornerstonejs/core';\nimport type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';\nimport BoundsIJK from '../types/BoundsIJK';\n\nexport type PointInShape = {\n value: number;\n index: number;\n pointIJK: vec3;\n pointLPS: vec3;\n};\n\nexport type PointInShapeCallback = ({\n value,\n index,\n pointIJK,\n pointLPS,\n}: {\n value: number;\n index: number;\n pointIJK: vec3;\n pointLPS: vec3;\n}) => void;\n\nexport type ShapeFnCriteria = (pointLPS: vec3, pointIJK: vec3) => boolean;\n\n/**\n * For each point in the image (If boundsIJK is not provided, otherwise, for each\n * point in the provided bounding box), It runs the provided callback IF the point\n * passes the provided criteria to be inside the shape (which is defined by the\n * provided pointInShapeFn)\n *\n * @param imageData - The image data object.\n * @param dimensions - The dimensions of the image.\n * @param pointInShapeFn - A function that takes a point in LPS space and returns\n * true if the point is in the shape and false if it is not.\n * @param callback - A function that will be called for\n * every point in the shape.\n * @param boundsIJK - The bounds of the volume in IJK coordinates.\n */\nexport default function pointInShapeCallback(\n imageData: vtkImageData | Types.CPUImageData,\n pointInShapeFn: ShapeFnCriteria,\n callback?: PointInShapeCallback,\n boundsIJK?: BoundsIJK\n): Array<PointInShape> {\n let iMin, iMax, jMin, jMax, kMin, kMax;\n\n let scalarData;\n const { numComps } = imageData as any;\n\n // if getScalarData is a method on imageData\n if ((imageData as Types.CPUImageData).getScalarData) {\n scalarData = (imageData as Types.CPUImageData).getScalarData();\n } else {\n scalarData = (imageData as vtkImageData)\n .getPointData()\n .getScalars()\n .getData();\n }\n\n const dimensions = imageData.getDimensions();\n\n if (!boundsIJK) {\n iMin = 0;\n iMax = dimensions[0];\n jMin = 0;\n jMax = dimensions[1];\n kMin = 0;\n kMax = dimensions[2];\n } else {\n [[iMin, iMax], [jMin, jMax], [kMin, kMax]] = boundsIJK;\n }\n\n const start = vec3.fromValues(iMin, jMin, kMin);\n\n const direction = imageData.getDirection();\n const rowCosines = direction.slice(0, 3);\n const columnCosines = direction.slice(3, 6);\n const scanAxisNormal = direction.slice(6, 9);\n\n const spacing = imageData.getSpacing();\n const [rowSpacing, columnSpacing, scanAxisSpacing] = spacing;\n\n // @ts-ignore will be fixed in vtk-master\n const worldPosStart = imageData.indexToWorld(start);\n\n const rowStep = vec3.fromValues(\n rowCosines[0] * rowSpacing,\n rowCosines[1] * rowSpacing,\n rowCosines[2] * rowSpacing\n );\n\n const columnStep = vec3.fromValues(\n columnCosines[0] * columnSpacing,\n columnCosines[1] * columnSpacing,\n columnCosines[2] * columnSpacing\n );\n\n const scanAxisStep = vec3.fromValues(\n scanAxisNormal[0] * scanAxisSpacing,\n scanAxisNormal[1] * scanAxisSpacing,\n scanAxisNormal[2] * scanAxisSpacing\n );\n\n const xMultiple =\n numComps ||\n scalarData.length / dimensions[2] / dimensions[1] / dimensions[0];\n const yMultiple = dimensions[0] * xMultiple;\n const zMultiple = dimensions[1] * yMultiple;\n\n const pointsInShape: Array<PointInShape> = [];\n\n const currentPos = vec3.clone(worldPosStart);\n\n for (let k = kMin; k <= kMax; k++) {\n const startPosJ = vec3.clone(currentPos);\n\n for (let j = jMin; j <= jMax; j++) {\n const startPosI = vec3.clone(currentPos);\n\n for (let i = iMin; i <= iMax; i++) {\n const pointIJK: Types.Point3 = [i, j, k];\n\n // The current world position (pointLPS) is now in currentPos\n if (pointInShapeFn(currentPos as Types.Point3, pointIJK)) {\n const index = k * zMultiple + j * yMultiple + i * xMultiple;\n let value;\n if (xMultiple > 2) {\n value = [\n scalarData[index],\n scalarData[index + 1],\n scalarData[index + 2],\n ];\n } else {\n value = scalarData[index];\n }\n\n pointsInShape.push({ value, index, pointIJK, pointLPS: currentPos });\n if (callback) {\n callback({ value, index, pointIJK, pointLPS: currentPos });\n }\n }\n\n // Increment currentPos by rowStep for the next iteration\n vec3.add(currentPos, currentPos, rowStep);\n }\n\n // Reset currentPos to the start of the next J line and increment by columnStep\n vec3.copy(currentPos, startPosI);\n vec3.add(currentPos, currentPos, columnStep);\n }\n\n // Reset currentPos to the start of the next K slice and increment by scanAxisStep\n vec3.copy(currentPos, startPosJ);\n vec3.add(currentPos, currentPos, scanAxisStep);\n }\n\n return pointsInShape;\n}\n","import type { Types } from '@cornerstonejs/core';\nimport containsPoint from './containsPoint';\n\n/**\n * Determines whether a 3D point is inside a polyline in 3D space.\n *\n * The algorithm works by reducing the polyline and point to 2D space, and then\n * using the 2D algorithm to determine whether the point is inside the polyline.\n *\n * @param point - The 3D point to test.\n * @param polyline - The polyline represented as an array of 3D points.\n * @returns A boolean indicating whether the point is inside the polyline.\n * @throws An error if a shared dimension index cannot be found for the polyline points.\n */\nexport function isPointInsidePolyline3D(\n point: Types.Point3,\n polyline: Types.Point3[]\n) {\n // Todo: handle oblique planes\n\n // We need to reduce one dimension to 2D, so basically\n // we need to find the dimension index that is shared by all points\n // Use the first three points, two is enough but three is more robust\n let sharedDimensionIndex;\n\n const testPoints = polyline.slice(0, 3);\n for (let i = 0; i < 3; i++) {\n if (testPoints.every((point, index, array) => point[i] === array[0][i])) {\n sharedDimensionIndex = i;\n break;\n }\n }\n\n if (sharedDimensionIndex === undefined) {\n throw new Error(\n 'Cannot find a shared dimension index for polyline, probably oblique plane'\n );\n }\n\n // convert polyline list and point to 2D\n const points2D = [] as Types.Point2[];\n\n for (let i = 0; i < polyline.length; i++) {\n points2D.push([\n polyline[i][(sharedDimensionIndex + 1) % 3],\n polyline[i][(sharedDimensionIndex + 2) % 3],\n ]);\n }\n\n const point2D = [\n point[(sharedDimensionIndex + 1) % 3],\n point[(sharedDimensionIndex + 2) % 3],\n ] as Types.Point2;\n\n return containsPoint(points2D, point2D);\n}\n","import type { Types } from '@cornerstonejs/core';\nimport isClosed from './isClosed';\n\n/**\n * Checks if a 2D point is inside the polyline.\n *\n * A point is inside a curve/polygon if the number of intersections between the horizontal\n * ray emanating from the given point and to the right and the line segments is odd.\n * https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html\n *\n * Note that a point on the polyline is considered inside.\n *\n * @param polyline - Polyline points (2D)\n * @param point - 2D Point\n * @returns True if the point is inside the polyline or false otherwise\n */\nexport default function containsPoint(\n polyline: Types.Point2[],\n point: Types.Point2,\n closed?: boolean\n): boolean {\n if (polyline.length < 3) {\n return false;\n }\n\n const numPolylinePoints = polyline.length;\n let numIntersections = 0;\n\n // Test intersection against [end, start] line segment if it should be closed\n const shouldClose = !(closed === undefined ? isClosed(polyline) : closed);\n const maxSegmentIndex = polyline.length - (shouldClose ? 1 : 2);\n\n for (let i = 0; i <= maxSegmentIndex; i++) {\n const p1 = polyline[i];\n\n // Calculating the next point index without using % (mod) operator like in\n // `(i + 1) % numPolylinePoints` to make it 20% faster\n const p2Index = i === numPolylinePoints - 1 ? 0 : i + 1;\n const p2 = polyline[p2Index];\n\n // Calculating min/max without using Math.min/max to make it ~3% faster\n const maxX = p1[0] >= p2[0] ? p1[0] : p2[0];\n const maxY = p1[1] >= p2[1] ? p1[1] : p2[1];\n const minY = p1[1] <= p2[1] ? p1[1] : p2[1];\n\n const mayIntersectLineSegment =\n point[0] <= maxX && point[1] >= minY && point[1] < maxY;\n\n if (mayIntersectLineSegment) {\n const isVerticalLine = p1[0] === p2[0];\n let intersects = isVerticalLine;\n\n if (!intersects) {\n const xIntersection =\n ((point[1] - p1[1]) * (p2[0] - p1[0])) / (p2[1] - p1[1]) + p1[0];\n\n intersects = point[0] <= xIntersection;\n }\n\n numIntersections += intersects ? 1 : 0;\n }\n }\n\n return !!(numIntersections % 2);\n}\n","import { glMatrix } from 'gl-matrix';\nimport type { Types } from '@cornerstonejs/core';\nimport * as math from '..';\n\n/**\n * A polyline is considered closed if the start and end points are at the same position\n *\n * @param polyline - Polyline points (2D)\n * @returns True if the polyline is already closed or false otherwise\n */\nexport default function isClosed(polyline: Types.Point2[]): boolean {\n if (polyline.length < 3) {\n return false;\n }\n\n const numPolylinePoints = polyline.length;\n\n const firstPoint = polyline[0];\n const lastPoint = polyline[numPolylinePoints - 1];\n const distFirstToLastPoints = math.point.distanceToPointSquared(\n firstPoint,\n lastPoint\n );\n\n return glMatrix.equals(0, distFirstToLastPoints);\n}\n","import type { Types } from '@cornerstonejs/core';\n\ntype Point = Types.Point2 | Types.Point3;\n\n/**\n * Calculates the distance squared of a point to another point\n *\n * @param p1 - x,y or x,y,z of the point\n * @param p2 - x,y or x,y,z of the point\n * @returns distance\n */\nexport default function distanceToPointSquared(p1: Point, p2: Point): number {\n if (p1.length !== p2.length) {\n throw Error('Both points should have the same dimensionality');\n }\n\n const [x1, y1, z1 = 0] = p1;\n const [x2, y2, z2 = 0] = p2;\n const dx = x2 - x1;\n const dy = y2 - y1;\n const dz = z2 - z1;\n\n // Time to square 10M numbers:\n // (n * n) = 161ms | (n ** 2) = 199ms | Math.pow(n, 2) = 29529ms\n return dx * dx + dy * dy + dz * dz;\n}\n","import { expose } from 'comlink';\nimport vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';\nimport vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';\nimport ICRPolySeg from '@icr/polyseg-wasm';\nimport { utilities } from '@cornerstonejs/core';\nimport { getBoundingBoxAroundShapeWorld } from '../utilities/boundingBox';\nimport { pointInShapeCallback } from '../utilities';\nimport { isPointInsidePolyline3D } from '../utilities/math/polyline';\n\n/**\n * Object containing methods for converting between different representations of\n * segmentations (e.g., contour, labelmap, surface, etc.) These logics\n * are used in a webworker to avoid blocking the main thread. You can\n * search for workerManager.executeTask('polySeg', ...) to see\n * how these methods are used.\n *\n * See also the webworker docs at packages/docs/docs/concepts/cornerstone-core/web-worker.md\n * to learn more about how to use webworkers in the context of Cornerstone.\n */\nconst polySegConverters = {\n /**\n * The polySeg instance that is used to convert between different representations\n */\n polySeg: null,\n /**\n * Utilities to keep track of the initialization state of the polySeg instance\n * and avoid initializing it multiple times\n */\n polySegInitializing: false,\n polySegInitializingPromise: null,\n /**\n * This method initializes the polySeg instance and sets it to this.polySeg\n */\n async initializePolySeg(progressCallback) {\n if (this.polySegInitializing) {\n await this.polySegInitializingPromise;\n return;\n }\n\n if (this.polySeg?.instance) {\n return;\n }\n\n this.polySegInitializing = true;\n this.polySegInitializingPromise = new Promise((resolve) => {\n this.polySeg = new ICRPolySeg();\n this.polySeg\n .initialize({\n updateProgress: progressCallback,\n })\n .then(() => {\n this.polySegInitializing = false;\n resolve();\n });\n });\n\n await this.polySegInitializingPromise;\n },\n /**\n * Converts a contour to a surface using the PolySeg library.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.polylines - The polylines representing the contour.\n * @param {Array} args.numPointsArray - The number of points in each polyline.\n * @param {...Function} callbacks - Optional callback functions.\n * @returns {Promise} - A promise that resolves to the converted surface.\n */\n async convertContourToSurface(args, ...callbacks) {\n const { polylines, numPointsArray } = args;\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n const results = await this.polySeg.instance.convertContourRoiToSurface(\n polylines,\n numPointsArray\n );\n\n return results;\n },\n /**\n * Converts a labelmap to a surface using the specified arguments.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.scalarData - The scalar data of the labelmap.\n * @param {Array} args.dimensions - The dimensions of the labelmap.\n * @param {Array} args.spacing - The spacing of the labelmap.\n * @param {Array} args.direction - The direction of the labelmap.\n * @param {Array} args.origin - The origin of the labelmap.\n * @param {number} args.segmentIndex - The segment index of the labelmap.\n * @param {Function} progressCallback - The callback function for progress updates.\n * @returns {Promise} - A promise that resolves with the converted surface results.\n */\n async convertLabelmapToSurface(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const results = this.polySeg.instance.convertLabelmapToSurface(\n args.scalarData,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin,\n [args.segmentIndex]\n );\n return results;\n },\n /**\n * Converts a contour to a volume labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.segmentIndices - The indices of the segments.\n * @param {Array} args.scalarData - The scalar data.\n * @param {Map} args.annotationUIDsInSegmentMap - The map of annotation UIDs in segment.\n * @param {Array} args.dimensions - The dimensions of the image data.\n * @param {Array} args.origin - The origin of the image data.\n * @param {Array} args.direction - The direction of the image data.\n * @param {Array} args.spacing - The spacing of the image data.\n * @param {...Function} callbacks - Optional callbacks.\n * @param {Function} callbacks[0] - The progress callback.\n * @returns {Array} - The scalar data of the segmentation voxel manager.\n */\n async convertContourToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n const polySeg = await new ICRPolySeg();\n await polySeg.initialize({\n updateProgress: progressCallback,\n });\n\n const {\n segmentIndices,\n scalarData,\n annotationUIDsInSegmentMap,\n dimensions,\n origin,\n direction,\n spacing,\n } = args;\n\n const segmentationVoxelManager =\n utilities.VoxelManager.createVolumeVoxelManager(dimensions, scalarData);\n\n const imageData = vtkImageData.newInstance();\n imageData.setDimensions(dimensions);\n imageData.setOrigin(origin);\n imageData.setDirection(direction);\n imageData.setSpacing(spacing);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: scalarData,\n });\n\n imageData.getPointData().setScalars(scalarArray);\n\n imageData.modified();\n\n for (const index of segmentIndices) {\n const annotations = annotationUIDsInSegmentMap.get(index);\n\n for (const annotation of annotations) {\n const bounds = getBoundingBoxAroundShapeWorld(\n annotation.data.contour.polyline\n );\n\n const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [\n bounds[0][0],\n bounds[1][0],\n bounds[2][0],\n ]);\n\n const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [\n bounds[0][1],\n bounds[1][1],\n bounds[2][1],\n ]);\n\n // Run the pointInShapeCallback for the combined bounding box\n pointInShapeCallback(\n imageData,\n (pointLPS) => {\n // Check if the point is inside any of the polylines for this segment\n return isPointInsidePolyline3D(\n pointLPS,\n annotation.data.contour.polyline\n );\n },\n ({ pointIJK }) => {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, index);\n },\n [\n [iMin, iMax],\n [jMin, jMax],\n [kMin, kMax],\n ]\n );\n }\n }\n\n return segmentationVoxelManager.scalarData;\n },\n /**\n * Converts a contour to a stack labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} callbacks - Optional callbacks for progress updates.\n * @returns {Promise<Object>} - The converted segmentations information.\n */\n async convertContourToStackLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n const polySeg = await new ICRPolySeg();\n await polySeg.initialize({\n updateProgress: progressCallback,\n });\n\n const { segmentationsInfo, annotationUIDsInSegmentMap, segmentIndices } =\n args;\n\n const segmentationVoxelManagers = new Map();\n\n segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {\n const { dimensions, scalarData, direction, spacing, origin } =\n segmentationInfo;\n const manager = utilities.VoxelManager.createVolumeVoxelManager(\n dimensions,\n scalarData\n );\n\n const imageData = vtkImageData.newInstance();\n imageData.setDimensions(dimensions);\n imageData.setOrigin(origin);\n imageData.setDirection(direction);\n imageData.setSpacing(spacing);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: scalarData,\n });\n\n imageData.getPointData().setScalars(scalarArray);\n\n imageData.modified();\n\n segmentationVoxelManagers.set(referencedImageId, { manager, imageData });\n });\n\n for (const index of segmentIndices) {\n const annotations = annotationUIDsInSegmentMap.get(index);\n\n for (const annotation of annotations) {\n if (!annotation?.data) {\n continue;\n }\n const bounds = getBoundingBoxAroundShapeWorld(\n annotation.data.contour.polyline\n );\n\n const { referencedImageId } = annotation.metadata;\n\n const { manager: segmentationVoxelManager, imageData } =\n segmentationVoxelManagers.get(referencedImageId);\n\n const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [\n bounds[0][0],\n bounds[1][0],\n bounds[2][0],\n ]);\n\n const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [\n bounds[0][1],\n bounds[1][1],\n bounds[2][1],\n ]);\n\n // Run the pointInShapeCallback for the combined bounding box\n pointInShapeCallback(\n imageData,\n (pointLPS) => {\n // Check if the point is inside any of the polylines for this segment\n return isPointInsidePolyline3D(\n pointLPS,\n annotation.data.contour.polyline\n );\n },\n ({ pointIJK }) => {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, index);\n },\n [\n [iMin, iMax],\n [jMin, jMax],\n [kMin, kMax],\n ]\n );\n }\n }\n\n segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {\n const { manager: segmentationVoxelManager } =\n segmentationVoxelManagers.get(referencedImageId);\n\n segmentationInfo.scalarData = segmentationVoxelManager.scalarData;\n });\n return segmentationsInfo;\n },\n /**\n * Converts a surface to a volume labelmap.\n *\n * @param {Object} args - The arguments for the conversion.\n * @param {Array} args.points - The points defining the surface.\n * @param {Array} args.polys - The polygons defining the surface.\n * @param {Array} args.dimensions - The dimensions of the volume.\n * @param {Array} args.spacing - The spacing between voxels in the volume.\n * @param {Array} args.direction - The direction of the volume.\n * @param {Array} args.origin - The origin of the volume.\n * @param {Function} progressCallback - The callback function for reporting progress.\n * @returns {Promise} - A promise that resolves with the converted labelmap.\n */\n async convertSurfaceToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const results = this.polySeg.instance.convertSurfaceToLabelmap(\n args.points,\n args.polys,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin\n );\n\n return results;\n },\n /**\n * Converts surfaces to a volume labelmap.\n * @param {Object} args - The arguments for the conversion.\n * @param {Map} args.segmentsInfo - A map containing information about the segments.\n * @param {Function} progressCallback - A callback function for reporting progress.\n * @returns {Uint8Array} - The resulting volume labelmap.\n */\n async convertSurfacesToVolumeLabelmap(args, ...callbacks) {\n const [progressCallback] = callbacks;\n await this.initializePolySeg(progressCallback);\n\n const { segmentsInfo } = args;\n\n const promises = Array.from(segmentsInfo.keys()).map((segmentIndex) => {\n const { points, polys } = segmentsInfo.get(segmentIndex);\n const result = this.polySeg.instance.convertSurfaceToLabelmap(\n points,\n polys,\n args.dimensions,\n args.spacing,\n args.direction,\n args.origin\n );\n\n return {\n ...result,\n segmentIndex,\n };\n });\n\n const results = await Promise.all(promises);\n\n const targetImageData = vtkImageData.newInstance();\n targetImageData.setDimensions(args.dimensions);\n targetImageData.setOrigin(args.origin);\n targetImageData.setSpacing(args.spacing);\n targetImageData.setDirection(args.direction);\n\n const totalSize =\n args.dimensions[0] * args.dimensions[1] * args.dimensions[2];\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: new Uint8Array(totalSize),\n });\n\n targetImageData.getPointData().setScalars(scalarArray);\n targetImageData.modified();\n\n // we need to then consolidate the results into a single volume\n // by looping into each voxel with pointInShapeCallback\n // and check if the voxel is inside any of the reconstructed\n // labelmaps\n\n const segmentationVoxelManager =\n utilities.VoxelManager.createVolumeVoxelManager(\n args.dimensions,\n targetImageData.getPointData().getScalars().getData()\n );\n\n const outputVolumesInfo = results.map((result) => {\n const { data, dimensions, direction, origin, spacing } = result;\n const volume = vtkImageData.newInstance();\n volume.setDimensions(dimensions);\n volume.setOrigin(origin);\n volume.setSpacing(spacing);\n volume.setDirection(direction);\n\n const scalarArray = vtkDataArray.newInstance({\n name: 'Pixels',\n numberOfComponents: 1,\n values: data,\n });\n\n volume.getPointData().setScalars(scalarArray);\n\n volume.modified();\n\n const voxelManager = utilities.VoxelManager.createVolumeVoxelManager(\n dimensions,\n data\n );\n\n const extent = volume.getExtent(); // e.g., [0, 176, 0, 268, 0, 337] for dimensions of [177, 269, 338]\n\n return {\n volume,\n voxelManager,\n extent,\n scalarData: data,\n segmentIndex: result.segmentIndex,\n };\n });\n\n pointInShapeCallback(\n targetImageData,\n () => true, // we want to loop into all voxels\n ({ pointIJK, pointLPS }) => {\n // Check if the point is inside any of the reconstructed labelmaps\n // Todo: we can optimize this by returning early if the bounding box\n // of the point is outside the bounding box of the labelmap\n\n try {\n for (const volumeInfo of outputVolumesInfo) {\n const { volume, extent, voxelManager, segmentIndex } = volumeInfo;\n\n const index = volume.worldToIndex(pointLPS);\n\n // check if the ijk point is inside the volume\n if (\n index[0] < extent[0] ||\n index[0] > extent[1] ||\n index[1] < extent[2] ||\n index[1] > extent[3] ||\n index[2] < extent[4] ||\n index[2] > extent[5]\n ) {\n continue;\n }\n\n const roundedIndex = index.map(Math.round);\n const value = voxelManager.getAtIJK(...roundedIndex);\n if (value > 0) {\n segmentationVoxelManager.setAtIJKPoint(pointIJK, segmentIndex);\n break;\n }\n }\n } catch (error) {\n // right now there is weird error if the point is outside the volume\n }\n }\n );\n\n return segmentationVoxelManager.scalarData;\n },\n};\n\nexpose(polySegConverters);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__785__;","module.exports = __WEBPACK_EXTERNAL_MODULE__283__;","module.exports = __WEBPACK_EXTERNAL_MODULE__953__;","module.exports = __WEBPACK_EXTERNAL_MODULE__976__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n// the startup function\n__webpack_require__.x = () => {\n\t// Load entry module and return exports\n\t// This entry module depends on other loaded chunks and execution need to be delayed\n\tvar __webpack_exports__ = __webpack_require__.O(undefined, [78], () => (__webpack_require__(248)))\n\t__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n\treturn __webpack_exports__;\n};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.f = {};\n// This file contains only the entry chunk.\n// The chunk loading function for additional chunks\n__webpack_require__.e = (chunkId) => {\n\treturn Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {\n\t\t__webpack_require__.f[key](chunkId, promises);\n\t\treturn promises;\n\t}, []));\n};","// This function allow to reference async chunks and sibling chunks for the entrypoint\n__webpack_require__.u = (chunkId) => {\n\t// return url for filenames based on template\n\treturn \"\" + chunkId + \".index.js\";\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","var scriptUrl;\nif (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + \"\";\nvar document = __webpack_require__.g.document;\nif (!scriptUrl && document) {\n\tif (document.currentScript)\n\t\tscriptUrl = document.currentScript.src;\n\tif (!scriptUrl) {\n\t\tvar scripts = document.getElementsByTagName(\"script\");\n\t\tif(scripts.length) {\n\t\t\tvar i = scripts.length - 1;\n\t\t\twhile (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;\n\t\t}\n\t}\n}\n// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration\n// or pass an empty string (\"\") and set the __webpack_public_path__ variable from your code to use your own logic.\nif (!scriptUrl) throw new Error(\"Automatic publicPath is not supported in this browser\");\nscriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\?.*$/, \"\").replace(/\\/[^\\/]+$/, \"/\");\n__webpack_require__.p = scriptUrl;","// no baseURI\n\n// object to store loaded chunks\n// \"1\" means \"already loaded\"\nvar installedChunks = {\n\t985: 1\n};\n\n// importScripts chunk loading\nvar installChunk = (data) => {\n\tvar chunkIds = data[0];\n\tvar moreModules = data[1];\n\tvar runtime = data[2];\n\tfor(var moduleId in moreModules) {\n\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t}\n\t}\n\tif(runtime) runtime(__webpack_require__);\n\twhile(chunkIds.length)\n\t\tinstalledChunks[chunkIds.pop()] = 1;\n\tparentChunkLoadingFunction(data);\n};\n__webpack_require__.f.i = (chunkId, promises) => {\n\t// \"1\" is the signal for \"already loaded\"\n\tif(!installedChunks[chunkId]) {\n\t\tif(true) { // all chunks have JS\n\t\t\timportScripts(__webpack_require__.p + __webpack_require__.u(chunkId));\n\t\t}\n\t}\n};\n\nvar chunkLoadingGlobal = self[\"webpackChunkcornerstoneTools3D\"] = self[\"webpackChunkcornerstoneTools3D\"] || [];\nvar parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);\nchunkLoadingGlobal.push = installChunk;\n\n// no HMR\n\n// no HMR manifest","// run startup\nvar __webpack_exports__ = __webpack_require__.x();\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__283__","__WEBPACK_EXTERNAL_MODULE__785__","__WEBPACK_EXTERNAL_MODULE__953__","__WEBPACK_EXTERNAL_MODULE__976__","deferred","next","EPSILON","CONSTANTS","getBoundingBoxAroundShapeWorld","points","clipBounds","dimensions","_points$","isWorld","arguments","length","undefined","xMin","Infinity","xMax","yMin","yMax","zMin","zMax","is3D","i","p","_p$","_p$2","Math","min","max","calculateBoundingBox","pointInShapeCallback","imageData","pointInShapeFn","callback","boundsIJK","iMin","iMax","jMin","jMax","kMin","kMax","scalarData","numComps","getScalarData","getPointData","getScalars","getData","getDimensions","start","vec3","direction","getDirection","rowCosines","slice","columnCosines","scanAxisNormal","spacing","getSpacing","rowSpacing","columnSpacing","scanAxisSpacing","worldPosStart","indexToWorld","rowStep","columnStep","scanAxisStep","xMultiple","yMultiple","zMultiple","pointsInShape","currentPos","k","startPosJ","j","startPosI","pointIJK","index","value","push","pointLPS","isPointInsidePolyline3D","point","polyline","sharedDimensionIndex","testPoints","every","array","Error","points2D","closed","numPolylinePoints","numIntersections","shouldClose","distFirstToLastPoints","p1","p2","x1","y1","z1","x2","y2","z2","dx","dy","dz","math","glMatrix","isClosed","maxSegmentIndex","maxX","maxY","minY","intersects","xIntersection","containsPoint","polySegConverters","polySeg","polySegInitializing","polySegInitializingPromise","initializePolySeg","progressCallback","_this$polySeg","this","instance","Promise","resolve","ICRPolySeg","initialize","updateProgress","then","convertContourToSurface","args","polylines","numPointsArray","_len","callbacks","Array","_key","convertContourRoiToSurface","convertLabelmapToSurface","_len2","_key2","origin","segmentIndex","convertContourToVolumeLabelmap","_len3","_key3","segmentIndices","annotationUIDsInSegmentMap","segmentationVoxelManager","utilities","vtkImageData","setDimensions","setOrigin","setDirection","setSpacing","scalarArray","vtkDataArray","name","numberOfComponents","values","setScalars","modified","annotations","get","annotation","bounds","data","contour","_ref","setAtIJKPoint","convertContourToStackLabelmap","_len4","_key4","segmentationsInfo","segmentationVoxelManagers","Map","forEach","segmentationInfo","referencedImageId","manager","set","metadata","_ref2","convertSurfaceToVolumeLabelmap","_len5","_key5","convertSurfaceToLabelmap","polys","convertSurfacesToVolumeLabelmap","_len6","_key6","segmentsInfo","promises","from","keys","map","results","all","targetImageData","totalSize","Uint8Array","outputVolumesInfo","result","volume","voxelManager","extent","getExtent","_ref3","volumeInfo","worldToIndex","roundedIndex","round","getAtIJK","error","expose","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","m","x","__webpack_exports__","O","chunkIds","fn","priority","notFulfilled","fulfilled","Object","key","splice","r","n","getter","__esModule","d","a","definition","o","defineProperty","enumerable","f","e","chunkId","reduce","u","g","globalThis","Function","window","obj","prop","prototype","hasOwnProperty","call","scriptUrl","importScripts","location","document","currentScript","src","scripts","getElementsByTagName","replace","installedChunks","chunkLoadingGlobal","parentChunkLoadingFunction","bind","moreModules","runtime","pop"],"sourceRoot":""}