@ohif/app 3.13.0-beta.88 → 3.13.0-beta.89

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 (53) hide show
  1. package/dist/{5491.bundle.4866d2ecb20dd089e071.js → 1124.bundle.3c1b947a1884362c1241.js} +376 -222
  2. package/dist/1429.bundle.bd1585628440399e6c3f.js +2079 -0
  3. package/dist/{2108.bundle.142ee8d405727d02b16a.js → 1704.bundle.38d95b81b9e1293e04de.js} +1 -643
  4. package/dist/{7537.bundle.3c7d71348190ed4e9565.js → 1741.bundle.abc3a09729ada4c25685.js} +105024 -55129
  5. package/dist/{1927.bundle.be67b3aafe238ca9f191.js → 1927.bundle.1749aa6ae7b1dd3d06b1.js} +1 -1
  6. package/dist/{6354.bundle.929febcf6d326e582e00.js → 2802.bundle.3d6cc53ef3c69901431d.js} +31 -324
  7. package/dist/{3461.bundle.9bc7ca0f93d754014c23.js → 3461.bundle.2f3e998096ef3fca602b.js} +5 -4
  8. package/dist/{3617.bundle.f408991512372e52c6cf.js → 3617.bundle.f7f53b332f72e9fe6374.js} +2 -2
  9. package/dist/{3754.bundle.477cfd7fc3ff13e9dc67.js → 3754.bundle.2a46971b209140d4cb08.js} +12 -6
  10. package/dist/{9039.bundle.49ab126163ca208e52b3.js → 4335.bundle.69a7cc007e85f043488e.js} +4114 -4263
  11. package/dist/{4579.bundle.1c315389368cc476aed3.js → 451.bundle.6634a9dae2b4f0e9ebc9.js} +83 -30
  12. package/dist/{5028.bundle.4960393948811673d99b.js → 5028.bundle.f483671d94ded4c8f6f3.js} +2 -2
  13. package/dist/{5858.bundle.466e58128de344ab53f3.js → 5858.bundle.c25c73ecbc47b1a69cea.js} +0 -4
  14. package/dist/{6125.bundle.2c6f2ba3bd8e1493e54b.js → 6125.bundle.4e46ecd271f647cb977f.js} +2 -2087
  15. package/dist/{6376.bundle.f5ef0f5465d575d0dbb0.js → 6376.bundle.c7c515ba478be810e03d.js} +6 -3
  16. package/dist/{9567.bundle.ff782480a4c66e306027.js → 650.bundle.5decc3ce72a22162b8f4.js} +3080 -216
  17. package/dist/{7166.bundle.0a84efe4f3e6d0ddcbec.js → 7166.bundle.eeeda537770d73736e46.js} +161 -55
  18. package/dist/{6386.bundle.dc7e3b159d6b4733647f.js → 741.bundle.e47adc12429ee838d3fb.js} +3408 -3722
  19. package/dist/{7431.bundle.a9b4dbf97a8c196efe51.js → 7431.bundle.c3bd9a9f1ea743c81335.js} +61 -60
  20. package/dist/{8305.bundle.8088b210631f2b22899d.js → 8305.bundle.71787ad9e3df5d1dd30d.js} +2 -2
  21. package/dist/{8558.bundle.79c567857e04df2694cc.js → 8558.bundle.00d5dbdf73ca0a44831a.js} +1 -1
  22. package/dist/{8583.bundle.e36ff2fc6ee67e4e4232.js → 8583.bundle.40859ef5654559a1c66b.js} +3 -3
  23. package/dist/{9205.bundle.c974537f15d86687f6d2.js → 9205.bundle.d43cd617e38109746e4d.js} +2257 -2133
  24. package/dist/{4287.bundle.4f28e48c1e39a46dfc87.js → 9400.bundle.a56bfccf2bf7a51ed297.js} +1362 -692
  25. package/dist/{2075.bundle.ba9ac60662f1fa739378.js → 9475.bundle.693fe4de0573042a17f3.js} +203 -156
  26. package/dist/{app.bundle.3b116829d23059e8d9d8.js → app.bundle.93ee83d5e283aa1496da.js} +81239 -52123
  27. package/dist/{compute.bundle.2b82d8a0d1f3b41df1d2.js → compute.bundle.2fc1182cc9b2af5f4a40.js} +3 -15
  28. package/dist/{histogram-worker.bundle.a2a50c4674d99c619ca7.js → histogram-worker.bundle.c81373ef983363586dc5.js} +4 -4
  29. package/dist/index.html +1 -1
  30. package/dist/{interpolation.bundle.35be9e5cf473c6ebd3da.js → interpolation.bundle.a31edd1d26d81ef65b9b.js} +6 -6
  31. package/dist/{polySeg.bundle.ad2080f28d2c471bf208.js → polySeg.bundle.294012e3a5458cd3fecc.js} +3 -15
  32. package/dist/sw.js +1 -1
  33. package/package.json +21 -21
  34. /package/dist/{1459.bundle.23ea55eeadd13d26d6b5.js → 1459.bundle.763540bccf93fda17fff.js} +0 -0
  35. /package/dist/{1933.bundle.5713711c4a8f6518803b.js → 1933.bundle.8d54b74d93a7354925c5.js} +0 -0
  36. /package/dist/{2018.bundle.fee6699868f9e280861c.js → 2018.bundle.7ba8f9afeb48defb425b.js} +0 -0
  37. /package/dist/{213.bundle.3c0a19cba715a9a87151.js → 213.bundle.1a54c6878a493c5b61c5.js} +0 -0
  38. /package/dist/{2424.bundle.1d615d02f985abbbc633.js → 2424.bundle.c6d74f7129108d885a1b.js} +0 -0
  39. /package/dist/{2516.bundle.6b52ced19754035768ae.js → 2516.bundle.28427294c53e067811ca.js} +0 -0
  40. /package/dist/{3138.bundle.451e4105dda240465e6d.js → 3138.bundle.3845b7e06b8ab2564951.js} +0 -0
  41. /package/dist/{4507.bundle.51470574cbf11549ff72.js → 4507.bundle.b658ff59d35614916a2b.js} +0 -0
  42. /package/dist/{4819.bundle.c5e695cd51065d2a1a88.js → 4819.bundle.e28f5f1f0d481e190bb1.js} +0 -0
  43. /package/dist/{5015.bundle.647c560efcc9942bb42c.js → 5015.bundle.455552a6df9b442b3c40.js} +0 -0
  44. /package/dist/{5457.bundle.45b43e0e56637108f8f1.js → 5457.bundle.ee1026db729958b36a2e.js} +0 -0
  45. /package/dist/{5485.bundle.3d2d3a7f37f948da2269.js → 5485.bundle.0ecad3940c321ae65b23.js} +0 -0
  46. /package/dist/{5802.bundle.da6055b6bf1a3db7b6d5.js → 5802.bundle.5e1a7df7ad850a5370f8.js} +0 -0
  47. /package/dist/{5830.bundle.d026ec38980fb12f2518.js → 5830.bundle.8327ccd3c8a6334ac315.js} +0 -0
  48. /package/dist/{6027.bundle.ea7a56c1ebde501ce02d.js → 6027.bundle.f276566b6237d9e16333.js} +0 -0
  49. /package/dist/{7639.bundle.2b4ae693bddf15fb9641.js → 7639.bundle.25e1a86f2248148c35d5.js} +0 -0
  50. /package/dist/{8499.bundle.f94b5427bb2889634aeb.js → 8499.bundle.22f25667db4ab2e59e57.js} +0 -0
  51. /package/dist/{85.bundle.f7cb4cf8432ca6a815c0.js → 85.bundle.2aa39c9bf12258c7ca68.js} +0 -0
  52. /package/dist/{9862.bundle.f92516a34b9cef88c56f.js → 9862.bundle.fb87529360fb93010555.js} +0 -0
  53. /package/dist/{9927.bundle.5cf09e95f0253210d431.js → 9927.bundle.f6e7785bceeeb7a1c62e.js} +0 -0
@@ -1,4 +1,4 @@
1
- (globalThis["webpackChunk"] = globalThis["webpackChunk"] || []).push([[9567],{
1
+ (globalThis["webpackChunk"] = globalThis["webpackChunk"] || []).push([[650],{
2
2
 
3
3
  /***/ 75183
4
4
  (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
@@ -930,7 +930,7 @@ function _onKeyUp(evt) {
930
930
  document.removeEventListener('keyup', _onKeyUp);
931
931
  document.removeEventListener('visibilitychange', _onVisibilityChange);
932
932
  state.element.addEventListener('keydown', keyListener);
933
- state = structuredClone(defaultState);
933
+ state = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(defaultState);
934
934
  (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.triggerEvent)(eventDetail.element, _enums_Events__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A.KEY_UP, eventDetail);
935
935
  }
936
936
  function getModifierKey() {
@@ -962,7 +962,10 @@ function getMouseEventPoints(evt, element) {
962
962
  const clientPoint = _clientToPoint(evt);
963
963
  const pagePoint = _pageToPoint(evt);
964
964
  const canvasPoint = _pagePointsToCanvasPoints(elementToUse, pagePoint);
965
- const worldPoint = viewport.canvasToWorld(canvasPoint);
965
+ const worldPoint = getWorldPoint(viewport, canvasPoint);
966
+ if (!worldPoint) {
967
+ return;
968
+ }
966
969
  return {
967
970
  page: pagePoint,
968
971
  client: clientPoint,
@@ -983,6 +986,21 @@ function _pageToPoint(evt) {
983
986
  function _clientToPoint(evt) {
984
987
  return [evt.clientX, evt.clientY];
985
988
  }
989
+ function getWorldPoint(viewport, canvasPoint) {
990
+ try {
991
+ return viewport.canvasToWorld(canvasPoint);
992
+ }
993
+ catch (error) {
994
+ if (isNoMountedDataError(error)) {
995
+ return;
996
+ }
997
+ throw error;
998
+ }
999
+ }
1000
+ function isNoMountedDataError(error) {
1001
+ return (error instanceof Error &&
1002
+ error.message.includes('because no data is mounted'));
1003
+ }
986
1004
 
987
1005
 
988
1006
  /***/ },
@@ -1002,8 +1020,15 @@ function _clientToPoint(evt) {
1002
1020
 
1003
1021
  function mouseDoubleClickListener(evt) {
1004
1022
  const element = evt.currentTarget;
1005
- const { viewportId, renderingEngineId } = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElement)(element);
1023
+ const enabledElement = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElement)(element);
1024
+ if (!enabledElement) {
1025
+ return;
1026
+ }
1027
+ const { viewportId, renderingEngineId } = enabledElement;
1006
1028
  const startPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A)(evt, element);
1029
+ if (!startPoints) {
1030
+ return;
1031
+ }
1007
1032
  const deltaPoints = {
1008
1033
  page: [0, 0],
1009
1034
  client: [0, 0],
@@ -1117,12 +1142,21 @@ function mouseDownListener(evt) {
1117
1142
  state.element = evt.currentTarget;
1118
1143
  state.mouseButton = evt.buttons;
1119
1144
  const enabledElement = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElement)(state.element);
1145
+ if (!enabledElement) {
1146
+ state = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(defaultState);
1147
+ return;
1148
+ }
1120
1149
  const { renderingEngineId, viewportId } = enabledElement;
1121
1150
  state.renderingEngineId = renderingEngineId;
1122
1151
  state.viewportId = viewportId;
1123
1152
  state.preventClickTimeout = setTimeout(_preventClickHandler, state.clickDelay);
1124
- state.element.removeEventListener('mousemove', _mouseMoveListener__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A);
1125
1153
  const startPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A)(evt, state.element);
1154
+ if (!startPoints) {
1155
+ clearTimeout(state.preventClickTimeout);
1156
+ state = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(defaultState);
1157
+ return;
1158
+ }
1159
+ state.element.removeEventListener('mousemove', _mouseMoveListener__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A);
1126
1160
  state.startPoints = _copyPoints(startPoints);
1127
1161
  state.lastPoints = _copyPoints(startPoints);
1128
1162
  document.addEventListener('mouseup', _onMouseUp);
@@ -1155,6 +1189,9 @@ function _onMouseDrag(evt) {
1155
1189
  return;
1156
1190
  }
1157
1191
  const currentPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A)(evt, state.element);
1192
+ if (!currentPoints) {
1193
+ return;
1194
+ }
1158
1195
  const lastPoints = _updateMouseEventsLastPoints(state.element, state.lastPoints);
1159
1196
  const deltaPoints = _getDeltaPoints(currentPoints, lastPoints);
1160
1197
  if (doubleClickState.doubleClickTimeout) {
@@ -1199,6 +1236,10 @@ function _onMouseUp(evt) {
1199
1236
  else {
1200
1237
  const eventName = state.isClickEvent ? MOUSE_CLICK : MOUSE_UP;
1201
1238
  const currentPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A)(evt, state.element);
1239
+ if (!currentPoints) {
1240
+ _cleanUp();
1241
+ return;
1242
+ }
1202
1243
  const deltaPoints = _getDeltaPoints(currentPoints, state.lastPoints);
1203
1244
  const eventDetail = {
1204
1245
  event: evt,
@@ -1220,6 +1261,9 @@ function _onMouseUp(evt) {
1220
1261
  }
1221
1262
  function _onMouseMove(evt) {
1222
1263
  const currentPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A)(evt, state.element);
1264
+ if (!currentPoints) {
1265
+ return;
1266
+ }
1223
1267
  const lastPoints = _updateMouseEventsLastPoints(state.element, state.lastPoints);
1224
1268
  const deltaPoints = _getDeltaPoints(currentPoints, lastPoints);
1225
1269
  if (!_isDragPastDoubleClickTolerance(deltaPoints.canvas)) {
@@ -1257,17 +1301,26 @@ function _cleanUp() {
1257
1301
  state.element?.removeEventListener('mousemove', _onMouseMove);
1258
1302
  state.element?.addEventListener('mousemove', _mouseMoveListener__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A);
1259
1303
  _clearDoubleClickTimeoutAndEvents();
1260
- state = JSON.parse(JSON.stringify(defaultState));
1304
+ state = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(defaultState);
1261
1305
  }
1262
1306
  function _copyPoints(points) {
1263
- return JSON.parse(JSON.stringify(points));
1307
+ return _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(points);
1264
1308
  }
1265
1309
  function _updateMouseEventsLastPoints(element, lastPoints) {
1266
1310
  const { viewport } = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElement)(element) || {};
1267
1311
  if (!viewport) {
1268
1312
  return lastPoints;
1269
1313
  }
1270
- const world = viewport.canvasToWorld(lastPoints.canvas);
1314
+ let world;
1315
+ try {
1316
+ world = viewport.canvasToWorld(lastPoints.canvas);
1317
+ }
1318
+ catch (error) {
1319
+ if (isNoMountedDataError(error)) {
1320
+ return lastPoints;
1321
+ }
1322
+ throw error;
1323
+ }
1271
1324
  return {
1272
1325
  page: lastPoints.page,
1273
1326
  client: lastPoints.client,
@@ -1297,6 +1350,10 @@ function _subtractPoints2D(point0, point1) {
1297
1350
  function _subtractPoints3D(point0, point1) {
1298
1351
  return [point0[0] - point1[0], point0[1] - point1[1], point0[2] - point1[2]];
1299
1352
  }
1353
+ function isNoMountedDataError(error) {
1354
+ return (error instanceof Error &&
1355
+ error.message.includes('because no data is mounted'));
1356
+ }
1300
1357
  function getMouseButton() {
1301
1358
  return state.mouseButton;
1302
1359
  }
@@ -1337,6 +1394,9 @@ function mouseMoveListener(evt) {
1337
1394
  }
1338
1395
  const { renderingEngineId, viewportId } = enabledElement;
1339
1396
  const currentPoints = (0,_getMouseEventPoints__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A)(evt);
1397
+ if (!currentPoints) {
1398
+ return;
1399
+ }
1340
1400
  const eventDetail = {
1341
1401
  renderingEngineId,
1342
1402
  viewportId,
@@ -1435,13 +1495,20 @@ var Touch = __webpack_require__(10401);
1435
1495
 
1436
1496
  function getTouchEventPoints(evt, element) {
1437
1497
  const elementToUse = element || evt.currentTarget;
1498
+ const { viewport } = (0,esm.getEnabledElement)(elementToUse) || {};
1499
+ if (!viewport) {
1500
+ return [];
1501
+ }
1438
1502
  const touches = evt.type === 'touchend' ? evt.changedTouches : evt.touches;
1439
- return Object.keys(touches).map((i) => {
1503
+ return Object.keys(touches)
1504
+ .map((i) => {
1440
1505
  const clientPoint = _clientToPoint(touches[i]);
1441
1506
  const pagePoint = _pageToPoint(touches[i]);
1442
1507
  const canvasPoint = _pagePointsToCanvasPoints(elementToUse, pagePoint);
1443
- const { viewport } = (0,esm.getEnabledElement)(elementToUse);
1444
- const worldPoint = viewport.canvasToWorld(canvasPoint);
1508
+ const worldPoint = getWorldPoint(viewport, canvasPoint);
1509
+ if (!worldPoint) {
1510
+ return;
1511
+ }
1445
1512
  return {
1446
1513
  page: pagePoint,
1447
1514
  client: clientPoint,
@@ -1455,7 +1522,8 @@ function getTouchEventPoints(evt, element) {
1455
1522
  rotationAngle: touches[i].rotationAngle,
1456
1523
  },
1457
1524
  };
1458
- });
1525
+ })
1526
+ .filter(Boolean);
1459
1527
  }
1460
1528
  function _pagePointsToCanvasPoints(element, pagePoint) {
1461
1529
  const rect = element.getBoundingClientRect();
@@ -1470,6 +1538,21 @@ function _pageToPoint(touch) {
1470
1538
  function _clientToPoint(touch) {
1471
1539
  return [touch.clientX, touch.clientY];
1472
1540
  }
1541
+ function getWorldPoint(viewport, canvasPoint) {
1542
+ try {
1543
+ return viewport.canvasToWorld(canvasPoint);
1544
+ }
1545
+ catch (error) {
1546
+ if (isNoMountedDataError(error)) {
1547
+ return;
1548
+ }
1549
+ throw error;
1550
+ }
1551
+ }
1552
+ function isNoMountedDataError(error) {
1553
+ return (error instanceof Error &&
1554
+ error.message.includes('because no data is mounted'));
1555
+ }
1473
1556
 
1474
1557
  // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/touch/index.js
1475
1558
  var touch = __webpack_require__(76260);
@@ -1535,8 +1618,8 @@ const defaultTapState = {
1535
1618
  tapMaxDistance: 24,
1536
1619
  tapToleranceMs: 300,
1537
1620
  };
1538
- let state = JSON.parse(JSON.stringify(defaultState));
1539
- let tapState = JSON.parse(JSON.stringify(defaultTapState));
1621
+ let state = esm.utilities.deepClone(defaultState);
1622
+ let tapState = esm.utilities.deepClone(defaultTapState);
1540
1623
  function triggerEventCallback(ele, name, eventDetail) {
1541
1624
  return (0,esm.triggerEvent)(ele, name, eventDetail);
1542
1625
  }
@@ -1670,7 +1753,7 @@ function _onTouchEnd(evt) {
1670
1753
  };
1671
1754
  triggerEventCallback(eventDetail.element, TOUCH_END, eventDetail);
1672
1755
  _checkTouchTap(evt);
1673
- state = JSON.parse(JSON.stringify(defaultState));
1756
+ state = esm.utilities.deepClone(defaultState);
1674
1757
  document.removeEventListener('touchmove', _onTouchDrag);
1675
1758
  document.removeEventListener('touchend', _onTouchEnd);
1676
1759
  }
@@ -1712,7 +1795,7 @@ function _checkTouchTap(evt) {
1712
1795
  taps: tapState.taps,
1713
1796
  };
1714
1797
  triggerEventCallback(eventDetail.element, TOUCH_TAP, eventDetail);
1715
- tapState = JSON.parse(JSON.stringify(defaultTapState));
1798
+ tapState = esm.utilities.deepClone(defaultTapState);
1716
1799
  }, tapState.tapToleranceMs);
1717
1800
  }
1718
1801
  function _checkTouchSwipe(evt, deltaPoints) {
@@ -1743,9 +1826,22 @@ function _checkTouchSwipe(evt, deltaPoints) {
1743
1826
  }
1744
1827
  }
1745
1828
  function _updateTouchEventsLastPoints(element, lastPoints) {
1746
- const { viewport } = (0,esm.getEnabledElement)(element);
1747
- return lastPoints.map((lp) => {
1748
- const world = viewport.canvasToWorld(lp.canvas);
1829
+ const { viewport } = (0,esm.getEnabledElement)(element) || {};
1830
+ if (!viewport) {
1831
+ return lastPoints;
1832
+ }
1833
+ return lastPoints
1834
+ .map((lp) => {
1835
+ let world;
1836
+ try {
1837
+ world = viewport.canvasToWorld(lp.canvas);
1838
+ }
1839
+ catch (error) {
1840
+ if (touchStartListener_isNoMountedDataError(error)) {
1841
+ return;
1842
+ }
1843
+ throw error;
1844
+ }
1749
1845
  return {
1750
1846
  page: lp.page,
1751
1847
  client: lp.client,
@@ -1753,7 +1849,12 @@ function _updateTouchEventsLastPoints(element, lastPoints) {
1753
1849
  world,
1754
1850
  touch: lp.touch,
1755
1851
  };
1756
- });
1852
+ })
1853
+ .filter(Boolean);
1854
+ }
1855
+ function touchStartListener_isNoMountedDataError(error) {
1856
+ return (error instanceof Error &&
1857
+ error.message.includes('because no data is mounted'));
1757
1858
  }
1758
1859
  /* harmony default export */ const touch_touchStartListener = (touchStartListener);
1759
1860
 
@@ -1838,6 +1939,10 @@ function wheelListener(evt) {
1838
1939
  if (evt.deltaY > -1 && evt.deltaY < 1) {
1839
1940
  return;
1840
1941
  }
1942
+ const points = (0,getMouseEventPoints/* default */.A)(evt);
1943
+ if (!points) {
1944
+ return;
1945
+ }
1841
1946
  evt.preventDefault();
1842
1947
  const { spinX, spinY, pixelX, pixelY } = normalizeWheel(evt);
1843
1948
  const direction = spinY < 0 ? -1 : 1;
@@ -1856,7 +1961,7 @@ function wheelListener(evt) {
1856
1961
  pixelY,
1857
1962
  direction,
1858
1963
  },
1859
- points: (0,getMouseEventPoints/* default */.A)(evt),
1964
+ points,
1860
1965
  };
1861
1966
  (0,esm.triggerEvent)(element, Events/* default */.A.MOUSE_WHEEL, eventDetail);
1862
1967
  }
@@ -1908,6 +2013,334 @@ async function convertStackToVolumeLabelmap(args) {
1908
2013
  }
1909
2014
 
1910
2015
 
2016
+ /***/ },
2017
+
2018
+ /***/ 59452
2019
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2020
+
2021
+ "use strict";
2022
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2023
+ /* harmony export */ DU: () => (/* binding */ getSurfaceRepresentationUID),
2024
+ /* harmony export */ ED: () => (/* binding */ getLabelmapActorEntries),
2025
+ /* harmony export */ Th: () => (/* binding */ getSurfaceActorEntry),
2026
+ /* harmony export */ wV: () => (/* binding */ getLabelmapActorEntry)
2027
+ /* harmony export */ });
2028
+ /* unused harmony export getLabelmapActorUID */
2029
+ /* harmony import */ var _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15327);
2030
+ /* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(29857);
2031
+
2032
+
2033
+ function getActorEntry(viewportId, segmentationId, filterFn) {
2034
+ const enabledElement = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElementByViewportId)(viewportId);
2035
+ if (!enabledElement) {
2036
+ return;
2037
+ }
2038
+ const { renderingEngine, viewport } = enabledElement;
2039
+ if (!renderingEngine || !viewport) {
2040
+ return;
2041
+ }
2042
+ const actors = viewport.getActors();
2043
+ const filteredActors = actors.filter(filterFn);
2044
+ return filteredActors.length > 0 ? filteredActors[0] : undefined;
2045
+ }
2046
+ function getActorEntries(viewportId, filterFn) {
2047
+ const enabledElement = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getEnabledElementByViewportId)(viewportId);
2048
+ if (!enabledElement) {
2049
+ return;
2050
+ }
2051
+ const { renderingEngine, viewport } = enabledElement;
2052
+ if (!renderingEngine || !viewport) {
2053
+ return;
2054
+ }
2055
+ const actors = viewport.getActors();
2056
+ const filteredActors = actors.filter(filterFn);
2057
+ return filteredActors.length > 0 ? filteredActors : undefined;
2058
+ }
2059
+ function getLabelmapActorUID(viewportId, segmentationId) {
2060
+ const actorEntry = getLabelmapActorEntry(viewportId, segmentationId);
2061
+ return actorEntry?.uid;
2062
+ }
2063
+ function getLabelmapActorEntries(viewportId, segmentationId) {
2064
+ return getActorEntries(viewportId, (actor) => actor.representationUID?.startsWith(`${segmentationId}-${_enums__WEBPACK_IMPORTED_MODULE_1__.SegmentationRepresentations.Labelmap}`));
2065
+ }
2066
+ function getLabelmapActorEntry(viewportId, segmentationId, referencedId) {
2067
+ return getActorEntry(viewportId, segmentationId, (actor) => actor.representationUID?.startsWith(`${segmentationId}-${_enums__WEBPACK_IMPORTED_MODULE_1__.SegmentationRepresentations.Labelmap}`) &&
2068
+ (!referencedId || actor.referencedId === referencedId));
2069
+ }
2070
+ function getSurfaceActorEntry(viewportId, segmentationId, segmentIndex) {
2071
+ return getActorEntry(viewportId, segmentationId, (actor) => actor.representationUID ===
2072
+ getSurfaceRepresentationUID(segmentationId, segmentIndex));
2073
+ }
2074
+ function getSurfaceRepresentationUID(segmentationId, segmentIndex) {
2075
+ return `${segmentationId}-${_enums__WEBPACK_IMPORTED_MODULE_1__.SegmentationRepresentations.Surface}-${segmentIndex}`;
2076
+ }
2077
+
2078
+
2079
+ /***/ },
2080
+
2081
+ /***/ 78028
2082
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2083
+
2084
+ "use strict";
2085
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2086
+ /* harmony export */ KM: () => (/* binding */ DIRECTION_ALIGNMENT_TOLERANCE),
2087
+ /* harmony export */ QO: () => (/* binding */ canRenderVolumeViewportLabelmapAsImage),
2088
+ /* harmony export */ bY: () => (/* binding */ shouldUseSliceRendering),
2089
+ /* harmony export */ o: () => (/* binding */ getVolumeViewportLabelmapImageMapperState),
2090
+ /* harmony export */ yc: () => (/* binding */ isSliceRenderingEnabled)
2091
+ /* harmony export */ });
2092
+ /* unused harmony export LABELMAP_IMAGE_MAPPER_URL_PARAM */
2093
+ /* harmony import */ var _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15327);
2094
+ /* harmony import */ var gl_matrix__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3823);
2095
+ /* harmony import */ var _labelmapModel_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(80973);
2096
+
2097
+
2098
+
2099
+ const DIRECTION_ALIGNMENT_TOLERANCE = 0.999;
2100
+ const MINIMUM_SLAB_THICKNESS = 0.1;
2101
+ const SLAB_THICKNESS_EPSILON = 1e-3;
2102
+ const LABELMAP_IMAGE_MAPPER_URL_PARAM = 'labelmapImageMapper';
2103
+ function isSupportedImageMapperBlendMode(blendMode) {
2104
+ return (blendMode === _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.Enums.BlendModes.COMPOSITE ||
2105
+ blendMode === _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.Enums.BlendModes.AVERAGE_INTENSITY_BLEND);
2106
+ }
2107
+ function isPlanarGpuVolumeSliceViewport(viewport) {
2108
+ const compatibilityViewport = viewport;
2109
+ if (compatibilityViewport.type !== _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.Enums.ViewportType.PLANAR_NEXT) {
2110
+ return false;
2111
+ }
2112
+ return (getPlanarPrimaryRenderMode(compatibilityViewport) ===
2113
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ActorRenderMode.VTK_VOLUME_SLICE);
2114
+ }
2115
+ function getPlanarPrimaryRenderMode(viewport) {
2116
+ const primaryDataId = getPlanarPrimaryDataId(viewport);
2117
+ if (primaryDataId) {
2118
+ const renderMode = viewport.getDisplaySetRenderMode?.(primaryDataId);
2119
+ if (renderMode) {
2120
+ return renderMode;
2121
+ }
2122
+ }
2123
+ return viewport.getDefaultActor?.()?.actorMapper?.renderMode;
2124
+ }
2125
+ function getPlanarVolumeSliceMapper(viewport) {
2126
+ const defaultActor = viewport.getDefaultActor?.();
2127
+ return (defaultActor?.actorMapper?.mapper ??
2128
+ defaultActor?.actorMapper?.actor?.getMapper?.());
2129
+ }
2130
+ function getPlanarPrimaryDataId(viewport) {
2131
+ const sourceDataId = viewport.getSourceDataId?.();
2132
+ if (sourceDataId) {
2133
+ return sourceDataId;
2134
+ }
2135
+ const renderModes = viewport._debug?.renderModes;
2136
+ if (!renderModes) {
2137
+ return;
2138
+ }
2139
+ return (Object.entries(renderModes).find(([dataId, renderMode]) => viewport.getDisplaySetRole?.(dataId) === 'source' &&
2140
+ renderMode === _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ActorRenderMode.VTK_VOLUME_SLICE)?.[0] ??
2141
+ Object.entries(renderModes).find(([, renderMode]) => renderMode === _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ActorRenderMode.VTK_VOLUME_SLICE)?.[0]);
2142
+ }
2143
+ function getLabelmapImageMapperCamera(viewport) {
2144
+ const compatibilityViewport = viewport;
2145
+ const resolvedCamera = compatibilityViewport
2146
+ .getResolvedView?.()
2147
+ ?.toICamera?.();
2148
+ if (isLabelmapImageMapperCamera(resolvedCamera)) {
2149
+ return resolvedCamera;
2150
+ }
2151
+ const legacyCamera = compatibilityViewport.getCamera?.();
2152
+ return isLabelmapImageMapperCamera(legacyCamera) ? legacyCamera : undefined;
2153
+ }
2154
+ function isLabelmapImageMapperCamera(camera) {
2155
+ const candidate = camera;
2156
+ return Boolean(candidate &&
2157
+ isPoint3Like(candidate.viewPlaneNormal) &&
2158
+ isPoint3Like(candidate.viewUp));
2159
+ }
2160
+ function isPoint3Like(value) {
2161
+ const candidate = value;
2162
+ return Boolean(candidate &&
2163
+ typeof candidate.length === 'number' &&
2164
+ candidate.length >= 3 &&
2165
+ Number.isFinite(Number(candidate[0])) &&
2166
+ Number.isFinite(Number(candidate[1])) &&
2167
+ Number.isFinite(Number(candidate[2])));
2168
+ }
2169
+ function getPlanarVolumeDataPresentation(viewport) {
2170
+ if (!viewport.getDisplaySetPresentation) {
2171
+ return;
2172
+ }
2173
+ const primaryDataId = getPlanarPrimaryDataId(viewport);
2174
+ return primaryDataId
2175
+ ? viewport.getDisplaySetPresentation(primaryDataId)
2176
+ : undefined;
2177
+ }
2178
+ function getCompatibilityBlendMode(viewport) {
2179
+ if (viewport instanceof _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.VolumeViewport) {
2180
+ return viewport.getBlendMode?.();
2181
+ }
2182
+ if (!isPlanarGpuVolumeSliceViewport(viewport)) {
2183
+ return;
2184
+ }
2185
+ const presentationBlendMode = getPlanarVolumeDataPresentation(viewport)?.blendMode;
2186
+ if (presentationBlendMode !== undefined) {
2187
+ return presentationBlendMode;
2188
+ }
2189
+ return _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.Enums.BlendModes.AVERAGE_INTENSITY_BLEND;
2190
+ }
2191
+ function getCompatibilitySlabThickness(viewport) {
2192
+ if (viewport instanceof _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.VolumeViewport) {
2193
+ return viewport.getSlabThickness?.() ?? MINIMUM_SLAB_THICKNESS;
2194
+ }
2195
+ if (!isPlanarGpuVolumeSliceViewport(viewport)) {
2196
+ return MINIMUM_SLAB_THICKNESS;
2197
+ }
2198
+ const mapperSlabThickness = getPlanarVolumeSliceMapper(viewport)?.getSlabThickness?.();
2199
+ if (typeof mapperSlabThickness === 'number') {
2200
+ return mapperSlabThickness;
2201
+ }
2202
+ return (getPlanarVolumeDataPresentation(viewport)?.slabThickness ??
2203
+ MINIMUM_SLAB_THICKNESS);
2204
+ }
2205
+ function isSliceRenderingEnabled(options) {
2206
+ if (options?.useSliceRendering) {
2207
+ return true;
2208
+ }
2209
+ if (typeof window === 'undefined') {
2210
+ return false;
2211
+ }
2212
+ const params = new URLSearchParams(window.location.search);
2213
+ if (!params.has(LABELMAP_IMAGE_MAPPER_URL_PARAM)) {
2214
+ return false;
2215
+ }
2216
+ const value = params.get(LABELMAP_IMAGE_MAPPER_URL_PARAM);
2217
+ if (value === null || value === '') {
2218
+ return true;
2219
+ }
2220
+ const normalizedValue = value.trim().toLowerCase();
2221
+ return (normalizedValue !== '0' &&
2222
+ normalizedValue !== 'false' &&
2223
+ normalizedValue !== 'off');
2224
+ }
2225
+ function shouldUseSliceRendering(segmentation, options) {
2226
+ if (isSliceRenderingEnabled(options)) {
2227
+ return true;
2228
+ }
2229
+ if (!segmentation?.representationData?.Labelmap) {
2230
+ return false;
2231
+ }
2232
+ const layers = (0,_labelmapModel_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_2__/* .getLabelmaps */ .m)(segmentation);
2233
+ return layers.length > 1 && layers.some((layer) => layer.type === 'stack');
2234
+ }
2235
+ function canRenderVolumeViewportLabelmapAsImage(viewport) {
2236
+ const isLegacyVolumeViewport = viewport instanceof _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.VolumeViewport;
2237
+ const isNextPlanarViewport = isPlanarGpuVolumeSliceViewport(viewport);
2238
+ if (!isLegacyVolumeViewport && !isNextPlanarViewport) {
2239
+ return false;
2240
+ }
2241
+ const blendMode = getCompatibilityBlendMode(viewport);
2242
+ if (isLegacyVolumeViewport && !isSupportedImageMapperBlendMode(blendMode)) {
2243
+ return false;
2244
+ }
2245
+ const slabThickness = getCompatibilitySlabThickness(viewport);
2246
+ if (slabThickness > MINIMUM_SLAB_THICKNESS + SLAB_THICKNESS_EPSILON) {
2247
+ return false;
2248
+ }
2249
+ if (isLegacyVolumeViewport) {
2250
+ try {
2251
+ viewport.getSliceViewInfo();
2252
+ return true;
2253
+ }
2254
+ catch {
2255
+ return false;
2256
+ }
2257
+ }
2258
+ return true;
2259
+ }
2260
+ function getVolumeViewportLabelmapImageMapperState(viewport) {
2261
+ const compatibilityViewport = viewport;
2262
+ const isLegacyVolumeViewport = viewport instanceof _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.VolumeViewport;
2263
+ const isNextPlanarViewport = isPlanarGpuVolumeSliceViewport(viewport);
2264
+ if (!isLegacyVolumeViewport && !isNextPlanarViewport) {
2265
+ return {
2266
+ key: 'unsupported:viewport',
2267
+ sliceIndex: NaN,
2268
+ supported: false,
2269
+ };
2270
+ }
2271
+ const camera = getLabelmapImageMapperCamera(viewport);
2272
+ if (!camera) {
2273
+ return {
2274
+ key: 'unsupported:camera',
2275
+ sliceIndex: NaN,
2276
+ supported: false,
2277
+ };
2278
+ }
2279
+ const { viewPlaneNormal, viewUp } = camera;
2280
+ const normalizedNormal = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.normalize */ .eR.normalize(gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.create */ .eR.create(), viewPlaneNormal);
2281
+ const normalizedViewUp = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.normalize */ .eR.normalize(gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.create */ .eR.create(), viewUp);
2282
+ let sliceIndex;
2283
+ if (isLegacyVolumeViewport) {
2284
+ try {
2285
+ sliceIndex = viewport.getSliceViewInfo().sliceIndex;
2286
+ }
2287
+ catch {
2288
+ sliceIndex = undefined;
2289
+ }
2290
+ }
2291
+ else {
2292
+ sliceIndex = compatibilityViewport.getCurrentImageIdIndex?.();
2293
+ }
2294
+ const blendMode = getCompatibilityBlendMode(viewport);
2295
+ const slabThickness = getCompatibilitySlabThickness(viewport);
2296
+ const orientationKey = [
2297
+ normalizedNormal.map((value) => value.toFixed(3)).join(','),
2298
+ normalizedViewUp.map((value) => value.toFixed(3)).join(','),
2299
+ ].join('|');
2300
+ if (isLegacyVolumeViewport && !isSupportedImageMapperBlendMode(blendMode)) {
2301
+ return {
2302
+ key: `unsupported:blend:${blendMode}:${orientationKey}`,
2303
+ sliceIndex: sliceIndex ?? NaN,
2304
+ supported: false,
2305
+ };
2306
+ }
2307
+ if (slabThickness > MINIMUM_SLAB_THICKNESS + SLAB_THICKNESS_EPSILON) {
2308
+ return {
2309
+ key: `unsupported:slab:${slabThickness.toFixed(3)}:${orientationKey}`,
2310
+ sliceIndex: sliceIndex ?? NaN,
2311
+ supported: false,
2312
+ };
2313
+ }
2314
+ if (isLegacyVolumeViewport) {
2315
+ try {
2316
+ viewport.getSliceViewInfo();
2317
+ }
2318
+ catch {
2319
+ return {
2320
+ key: `unsupported:oblique:${orientationKey}`,
2321
+ sliceIndex: sliceIndex ?? NaN,
2322
+ supported: false,
2323
+ };
2324
+ }
2325
+ }
2326
+ if (isNextPlanarViewport &&
2327
+ getPlanarPrimaryRenderMode(compatibilityViewport) !==
2328
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ActorRenderMode.VTK_VOLUME_SLICE) {
2329
+ return {
2330
+ key: `unsupported:renderMode:${orientationKey}`,
2331
+ sliceIndex: sliceIndex ?? NaN,
2332
+ supported: false,
2333
+ };
2334
+ }
2335
+ return {
2336
+ key: `supported:${orientationKey}:${sliceIndex ?? 0}`,
2337
+ sliceIndex: sliceIndex ?? NaN,
2338
+ supported: true,
2339
+ };
2340
+ }
2341
+
2342
+
2343
+
1911
2344
  /***/ },
1912
2345
 
1913
2346
  /***/ 98149
@@ -1957,97 +2390,415 @@ async function updateStackSegmentationState({ segmentationId, viewportId, imageI
1957
2390
 
1958
2391
  /***/ },
1959
2392
 
1960
- /***/ 25972
2393
+ /***/ 79663
1961
2394
  (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1962
2395
 
1963
2396
  "use strict";
1964
2397
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1965
- /* harmony export */ A: () => (/* binding */ filterMoveableAnnotationTools)
2398
+ /* harmony export */ BS: () => (/* reexport safe */ _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__.BS),
2399
+ /* harmony export */ Hs: () => (/* reexport safe */ _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__.Hs),
2400
+ /* harmony export */ Lp: () => (/* reexport safe */ _labelmapImageReferenceResolver__WEBPACK_IMPORTED_MODULE_6__.A),
2401
+ /* harmony export */ M4: () => (/* reexport safe */ _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__.M4),
2402
+ /* harmony export */ Mx: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.Mx),
2403
+ /* harmony export */ Nf: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.Nf),
2404
+ /* harmony export */ Pi: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.Pi),
2405
+ /* harmony export */ Qk: () => (/* reexport safe */ _labelmapEditTransaction__WEBPACK_IMPORTED_MODULE_5__.Qk),
2406
+ /* harmony export */ Ry: () => (/* reexport safe */ _labelmapEditTransaction__WEBPACK_IMPORTED_MODULE_5__.Ry),
2407
+ /* harmony export */ VQ: () => (/* reexport safe */ _labelmapEditTransaction__WEBPACK_IMPORTED_MODULE_5__.VQ),
2408
+ /* harmony export */ Zs: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.Zs),
2409
+ /* harmony export */ hM: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.hM),
2410
+ /* harmony export */ kL: () => (/* reexport safe */ _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__.kL),
2411
+ /* harmony export */ m: () => (/* reexport safe */ _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__.m),
2412
+ /* harmony export */ r: () => (/* reexport safe */ _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__.r),
2413
+ /* harmony export */ uk: () => (/* reexport safe */ _normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__.uk),
2414
+ /* harmony export */ xS: () => (/* reexport safe */ _labelmapLegacyAdapter__WEBPACK_IMPORTED_MODULE_2__.x)
1966
2415
  /* harmony export */ });
1967
- function filterMoveableAnnotationTools(element, ToolAndAnnotations, canvasCoords, interactionType = 'mouse') {
1968
- const proximity = interactionType === 'touch' ? 36 : 6;
1969
- const moveableAnnotationTools = [];
1970
- ToolAndAnnotations.forEach(({ tool, annotations }) => {
1971
- for (const annotation of annotations) {
1972
- if (annotation.isLocked || !annotation.isVisible) {
1973
- continue;
1974
- }
1975
- const near = tool.isPointNearTool(element, annotation, canvasCoords, proximity, interactionType);
1976
- if (near) {
1977
- moveableAnnotationTools.push({
1978
- tool,
1979
- annotation,
1980
- });
1981
- break;
1982
- }
1983
- }
1984
- });
1985
- return moveableAnnotationTools;
1986
- }
2416
+ /* harmony import */ var _normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(830);
2417
+ /* harmony import */ var _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(80973);
2418
+ /* harmony import */ var _labelmapLegacyAdapter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(91573);
2419
+ /* harmony import */ var _labelmapSegmentBindings__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7296);
2420
+ /* harmony import */ var _privateLabelmap__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(99380);
2421
+ /* harmony import */ var _labelmapEditTransaction__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(72759);
2422
+ /* harmony import */ var _labelmapImageReferenceResolver__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(62851);
2423
+
2424
+
1987
2425
 
1988
2426
 
1989
- /***/ },
1990
2427
 
1991
- /***/ 57725
1992
- (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1993
2428
 
1994
- "use strict";
1995
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1996
- /* harmony export */ A: () => (/* binding */ filterToolsWithAnnotationsForElement)
1997
- /* harmony export */ });
1998
- /* harmony import */ var _stateManagement_annotation_annotationState__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82056);
1999
2429
 
2000
- function filterToolsWithAnnotationsForElement(element, tools) {
2001
- const result = [];
2002
- for (let i = 0; i < tools.length; i++) {
2003
- const tool = tools[i];
2004
- if (!tool) {
2005
- console.warn('undefined tool in filterToolsWithAnnotationsForElement');
2006
- continue;
2007
- }
2008
- let annotations = (0,_stateManagement_annotation_annotationState__WEBPACK_IMPORTED_MODULE_0__.getAnnotations)(tool.constructor.toolName, element);
2009
- if (!annotations?.length) {
2010
- continue;
2011
- }
2012
- if (typeof tool.filterInteractableAnnotationsForElement === 'function') {
2013
- annotations = tool.filterInteractableAnnotationsForElement(element, annotations);
2014
- }
2015
- if (annotations?.length > 0) {
2016
- result.push({ tool, annotations });
2017
- }
2018
- }
2019
- return result;
2020
- }
2021
2430
 
2022
2431
 
2023
2432
  /***/ },
2024
2433
 
2025
- /***/ 35486
2434
+ /***/ 80973
2026
2435
  (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2027
2436
 
2028
2437
  "use strict";
2029
2438
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2030
- /* harmony export */ A: () => (/* binding */ filterToolsWithMoveableHandles)
2439
+ /* harmony export */ $n: () => (/* binding */ removeLabelmap),
2440
+ /* harmony export */ AD: () => (/* binding */ registerLabelmap),
2441
+ /* harmony export */ BS: () => (/* binding */ getLabelmapForVolumeId),
2442
+ /* harmony export */ Hs: () => (/* binding */ getLabelmap),
2443
+ /* harmony export */ M4: () => (/* binding */ getLabelmapForImageId),
2444
+ /* harmony export */ kL: () => (/* binding */ getOrCreateLabelmapVolume),
2445
+ /* harmony export */ m: () => (/* binding */ getLabelmaps)
2031
2446
  /* harmony export */ });
2032
- function filterToolsWithMoveableHandles(element, ToolAndAnnotations, canvasCoords, interactionType = 'mouse') {
2033
- const proximity = interactionType === 'touch' ? 36 : 6;
2034
- const toolsWithMoveableHandles = [];
2035
- ToolAndAnnotations.forEach(({ tool, annotations }) => {
2036
- for (const annotation of annotations) {
2037
- if (annotation.isLocked || !annotation.isVisible) {
2038
- continue;
2039
- }
2040
- const handle = tool.getHandleNearImagePoint(element, annotation, canvasCoords, proximity);
2041
- if (handle) {
2042
- toolsWithMoveableHandles.push({
2043
- tool,
2044
- annotation,
2045
- handle,
2046
- });
2047
- break;
2048
- }
2049
- }
2050
- });
2447
+ /* unused harmony exports getConstructorNameForLabelmap, getLabelmapDataById, getLabelmapIds, getScalarArrayLengthFromLabelmap */
2448
+ /* unused harmony import specifier */ var cache;
2449
+ /* unused harmony import specifier */ var ensureLabelmapState;
2450
+ /* harmony import */ var _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15327);
2451
+ /* harmony import */ var _normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(830);
2452
+ /* harmony import */ var _labelmapImageIdMapping__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(52133);
2453
+
2454
+
2455
+
2456
+ function getLabelmap(segmentation, labelmapId) {
2457
+ return (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_1__/* .ensureLabelmapState */ .uk)(segmentation)?.labelmaps?.[labelmapId];
2458
+ }
2459
+ function getLabelmaps(segmentation) {
2460
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_1__/* .ensureLabelmapState */ .uk)(segmentation);
2461
+ if (!labelmapState) {
2462
+ return [];
2463
+ }
2464
+ return Object.values(labelmapState.labelmaps);
2465
+ }
2466
+ function registerLabelmap(segmentation, layer) {
2467
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_1__/* .ensureLabelmapState */ .uk)(segmentation);
2468
+ if (!labelmapState) {
2469
+ return;
2470
+ }
2471
+ labelmapState.labelmaps[layer.labelmapId] = layer;
2472
+ }
2473
+ function removeLabelmap(segmentation, labelmapId) {
2474
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_1__/* .ensureLabelmapState */ .uk)(segmentation);
2475
+ if (!labelmapState) {
2476
+ return;
2477
+ }
2478
+ const layer = labelmapState.labelmaps[labelmapId];
2479
+ if (layer?.geometryVolumeId && _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(layer.geometryVolumeId)) {
2480
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.removeVolumeLoadObject(layer.geometryVolumeId);
2481
+ }
2482
+ delete labelmapState.labelmaps[labelmapId];
2483
+ }
2484
+ function getOrCreateLabelmapVolume(layer) {
2485
+ const mergedVolume = getOrCreateMergedStackLabelmapVolume(layer);
2486
+ if (mergedVolume) {
2487
+ return mergedVolume;
2488
+ }
2489
+ const existingVolumeId = layer.volumeId ?? layer.geometryVolumeId;
2490
+ if (existingVolumeId) {
2491
+ const cachedVolume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(existingVolumeId);
2492
+ if (cachedVolume) {
2493
+ return cachedVolume;
2494
+ }
2495
+ }
2496
+ const imageIds = layer.imageIds ?? [];
2497
+ if (!imageIds.length) {
2498
+ return;
2499
+ }
2500
+ const volumeId = layer.volumeId ?? layer.geometryVolumeId ?? `${layer.labelmapId}-geometry`;
2501
+ if (!layer.volumeId) {
2502
+ layer.geometryVolumeId = volumeId;
2503
+ }
2504
+ const cachedVolume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(volumeId);
2505
+ if (cachedVolume) {
2506
+ return cachedVolume;
2507
+ }
2508
+ return _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, imageIds);
2509
+ }
2510
+ function getOrCreateMergedStackLabelmapVolume(layer) {
2511
+ if (layer.volumeId || !hasDuplicateReferencedImageIds(layer)) {
2512
+ return;
2513
+ }
2514
+ const volumeId = layer.geometryVolumeId ?? `${layer.labelmapId}-geometry`;
2515
+ const cachedVolume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(volumeId);
2516
+ if (cachedVolume) {
2517
+ return cachedVolume;
2518
+ }
2519
+ const imageIdsByReferencedImageId = new Map();
2520
+ (0,_labelmapImageIdMapping__WEBPACK_IMPORTED_MODULE_2__/* .forEachLabelmapImageReference */ .Zd)(layer, (referencedImageId, imageId) => {
2521
+ const imageIdsForReference = imageIdsByReferencedImageId.get(referencedImageId) ?? [];
2522
+ imageIdsForReference.push(imageId);
2523
+ imageIdsByReferencedImageId.set(referencedImageId, imageIdsForReference);
2524
+ });
2525
+ const mergedReferencedImageIds = Array.from(imageIdsByReferencedImageId.keys());
2526
+ if (!mergedReferencedImageIds.length) {
2527
+ return;
2528
+ }
2529
+ let mergedImageIndex = 0;
2530
+ const mergedImages = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.imageLoader.createAndCacheDerivedImages(mergedReferencedImageIds, {
2531
+ getDerivedImageId: () => `${volumeId}-image-${mergedImageIndex++}`,
2532
+ targetBuffer: { type: 'Uint8Array' },
2533
+ });
2534
+ mergedImages.forEach((mergedImage) => {
2535
+ const sourceImageIds = imageIdsByReferencedImageId.get(mergedImage.referencedImageId);
2536
+ if (!sourceImageIds?.length) {
2537
+ return;
2538
+ }
2539
+ const targetVoxelManager = mergedImage.voxelManager;
2540
+ const scalarDataLength = targetVoxelManager.getScalarDataLength();
2541
+ sourceImageIds.forEach((sourceImageId) => {
2542
+ const sourceImage = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getImage(sourceImageId);
2543
+ const sourceVoxelManager = sourceImage?.voxelManager;
2544
+ if (!sourceVoxelManager) {
2545
+ return;
2546
+ }
2547
+ const sourceScalarDataLength = sourceVoxelManager.getScalarDataLength();
2548
+ const length = Math.min(scalarDataLength, sourceScalarDataLength);
2549
+ for (let index = 0; index < length; index++) {
2550
+ const value = Number(sourceVoxelManager.getAtIndex(index));
2551
+ if (value !== 0) {
2552
+ targetVoxelManager.setAtIndex(index, value);
2553
+ }
2554
+ }
2555
+ });
2556
+ });
2557
+ layer.geometryVolumeId = volumeId;
2558
+ return _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, mergedImages.map((image) => image.imageId));
2559
+ }
2560
+ function hasDuplicateReferencedImageIds(layer) {
2561
+ return (0,_labelmapImageIdMapping__WEBPACK_IMPORTED_MODULE_2__/* .hasMultipleLabelmapImagesPerReferencedImageId */ .dm)(layer);
2562
+ }
2563
+ function getLabelmapIds(segmentation) {
2564
+ return getLabelmaps(segmentation).map((layer) => layer.labelmapId);
2565
+ }
2566
+ function getLabelmapDataById(segmentation, labelmapId) {
2567
+ const labelmapState = ensureLabelmapState(segmentation);
2568
+ const layer = labelmapState?.labelmaps?.[labelmapId];
2569
+ if (!labelmapState || !layer) {
2570
+ return;
2571
+ }
2572
+ return {
2573
+ volumeId: layer.volumeId,
2574
+ referencedVolumeId: layer.referencedVolumeId,
2575
+ imageIds: layer.imageIds,
2576
+ referencedImageIds: layer.referencedImageIds,
2577
+ sourceRepresentationName: labelmapState.sourceRepresentationName,
2578
+ primaryLabelmapId: labelmapId,
2579
+ labelmaps: {
2580
+ [labelmapId]: layer,
2581
+ },
2582
+ segmentBindings: Object.fromEntries(Object.entries(labelmapState.segmentBindings).filter(([, binding]) => binding.labelmapId === labelmapId)),
2583
+ };
2584
+ }
2585
+ function getScalarArrayLengthFromLabelmap(layer) {
2586
+ if (layer.volumeId) {
2587
+ return cache.getVolume(layer.volumeId)?.voxelManager?.getScalarDataLength();
2588
+ }
2589
+ const firstImageId = layer.imageIds?.[0];
2590
+ const firstImage = firstImageId ? cache.getImage(firstImageId) : null;
2591
+ if (!firstImage || !layer.imageIds?.length) {
2592
+ return 0;
2593
+ }
2594
+ return firstImage.voxelManager.getScalarDataLength() * layer.imageIds.length;
2595
+ }
2596
+ function getConstructorNameForLabelmap(layer) {
2597
+ if (layer.volumeId) {
2598
+ return cache.getVolume(layer.volumeId)?.voxelManager?.getConstructor()
2599
+ ?.name;
2600
+ }
2601
+ const imageId = layer.imageIds?.[0];
2602
+ return imageId
2603
+ ? cache.getImage(imageId)?.voxelManager?.getConstructor()?.name
2604
+ : undefined;
2605
+ }
2606
+ function getLabelmapForImageId(segmentation, imageId) {
2607
+ return getLabelmaps(segmentation).find((layer) => layer.imageIds?.includes(imageId));
2608
+ }
2609
+ function getLabelmapForVolumeId(segmentation, volumeId) {
2610
+ return getLabelmaps(segmentation).find((layer) => layer.volumeId === volumeId || layer.geometryVolumeId === volumeId);
2611
+ }
2612
+
2613
+
2614
+
2615
+ /***/ },
2616
+
2617
+ /***/ 7296
2618
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2619
+
2620
+ "use strict";
2621
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2622
+ /* harmony export */ I3: () => (/* binding */ getSegmentsOnLabelmap),
2623
+ /* harmony export */ Mx: () => (/* binding */ getSegmentIndexForLabelValue),
2624
+ /* harmony export */ Nf: () => (/* binding */ resolveLabelmapForSegment),
2625
+ /* harmony export */ Pi: () => (/* binding */ removeSegmentBinding),
2626
+ /* harmony export */ Zs: () => (/* binding */ setSegmentBinding),
2627
+ /* harmony export */ hM: () => (/* binding */ getSegmentBinding),
2628
+ /* harmony export */ r: () => (/* binding */ getLabelmapForSegment)
2629
+ /* harmony export */ });
2630
+ /* unused harmony export getLabelValueForSegment */
2631
+ /* harmony import */ var _normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(830);
2632
+ /* harmony import */ var _labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(80973);
2633
+ /* harmony import */ var _labelmapLegacyAdapter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(91573);
2634
+
2635
+
2636
+
2637
+ function getSegmentBinding(segmentation, segmentIndex) {
2638
+ return (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__/* .ensureLabelmapState */ .uk)(segmentation)?.segmentBindings?.[segmentIndex];
2639
+ }
2640
+ function setSegmentBinding(segmentation, segmentIndex, binding) {
2641
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__/* .ensureLabelmapState */ .uk)(segmentation);
2642
+ if (!labelmapState) {
2643
+ return;
2644
+ }
2645
+ const previousBinding = labelmapState.segmentBindings[segmentIndex];
2646
+ if (previousBinding) {
2647
+ const previousLayer = labelmapState.labelmaps[previousBinding.labelmapId];
2648
+ if (previousLayer?.labelToSegmentIndex) {
2649
+ delete previousLayer.labelToSegmentIndex[previousBinding.labelValue];
2650
+ }
2651
+ }
2652
+ labelmapState.segmentBindings[segmentIndex] = binding;
2653
+ const layer = labelmapState.labelmaps[binding.labelmapId];
2654
+ if (layer) {
2655
+ layer.labelToSegmentIndex ||= {};
2656
+ layer.labelToSegmentIndex[binding.labelValue] = segmentIndex;
2657
+ }
2658
+ }
2659
+ function getSegmentsOnLabelmap(segmentation, labelmapId) {
2660
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__/* .ensureLabelmapState */ .uk)(segmentation);
2661
+ if (!labelmapState) {
2662
+ return [];
2663
+ }
2664
+ return Object.entries(labelmapState.segmentBindings)
2665
+ .filter(([, binding]) => binding.labelmapId === labelmapId)
2666
+ .map(([segmentIndex]) => Number(segmentIndex))
2667
+ .sort((a, b) => a - b);
2668
+ }
2669
+ function getSegmentIndexForLabelValue(segmentation, labelmapId, labelValue) {
2670
+ const layer = (0,_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__/* .getLabelmap */ .Hs)(segmentation, labelmapId);
2671
+ if (!layer || labelValue == null) {
2672
+ return;
2673
+ }
2674
+ return layer.labelToSegmentIndex?.[labelValue] ?? labelValue;
2675
+ }
2676
+ function getLabelValueForSegment(segmentation, segmentIndex) {
2677
+ return (getSegmentBinding(segmentation, segmentIndex)?.labelValue ?? segmentIndex);
2678
+ }
2679
+ function getLabelmapForSegment(segmentation, segmentIndex) {
2680
+ const binding = getSegmentBinding(segmentation, segmentIndex);
2681
+ if (!binding) {
2682
+ return;
2683
+ }
2684
+ return (0,_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__/* .getLabelmap */ .Hs)(segmentation, binding.labelmapId);
2685
+ }
2686
+ function resolveLabelmapForSegment(segmentation, segmentIndex) {
2687
+ return (getLabelmapForSegment(segmentation, segmentIndex) ??
2688
+ (0,_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__/* .getLabelmaps */ .m)(segmentation)[0]);
2689
+ }
2690
+ function removeSegmentBinding(segmentation, segmentIndex) {
2691
+ const labelmapState = (0,_normalizeLabelmapSegmentationData__WEBPACK_IMPORTED_MODULE_0__/* .ensureLabelmapState */ .uk)(segmentation);
2692
+ const binding = labelmapState?.segmentBindings?.[segmentIndex];
2693
+ if (!labelmapState || !binding) {
2694
+ return;
2695
+ }
2696
+ const layer = labelmapState.labelmaps[binding.labelmapId];
2697
+ if (layer?.labelToSegmentIndex) {
2698
+ delete layer.labelToSegmentIndex[binding.labelValue];
2699
+ }
2700
+ delete labelmapState.segmentBindings[segmentIndex];
2701
+ if (getSegmentsOnLabelmap(segmentation, binding.labelmapId).length === 0) {
2702
+ (0,_labelmapLayerStore__WEBPACK_IMPORTED_MODULE_1__/* .removeLabelmap */ .$n)(segmentation, binding.labelmapId);
2703
+ }
2704
+ (0,_labelmapLegacyAdapter__WEBPACK_IMPORTED_MODULE_2__/* .syncLegacyLabelmapData */ .x)(segmentation);
2705
+ }
2706
+
2707
+
2708
+
2709
+ /***/ },
2710
+
2711
+ /***/ 25972
2712
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2713
+
2714
+ "use strict";
2715
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2716
+ /* harmony export */ A: () => (/* binding */ filterMoveableAnnotationTools)
2717
+ /* harmony export */ });
2718
+ function filterMoveableAnnotationTools(element, ToolAndAnnotations, canvasCoords, interactionType = 'mouse') {
2719
+ const proximity = interactionType === 'touch' ? 36 : 6;
2720
+ const moveableAnnotationTools = [];
2721
+ ToolAndAnnotations.forEach(({ tool, annotations }) => {
2722
+ for (const annotation of annotations) {
2723
+ if (annotation.isLocked || !annotation.isVisible) {
2724
+ continue;
2725
+ }
2726
+ const near = tool.isPointNearTool(element, annotation, canvasCoords, proximity, interactionType);
2727
+ if (near) {
2728
+ moveableAnnotationTools.push({
2729
+ tool,
2730
+ annotation,
2731
+ });
2732
+ break;
2733
+ }
2734
+ }
2735
+ });
2736
+ return moveableAnnotationTools;
2737
+ }
2738
+
2739
+
2740
+ /***/ },
2741
+
2742
+ /***/ 57725
2743
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2744
+
2745
+ "use strict";
2746
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2747
+ /* harmony export */ A: () => (/* binding */ filterToolsWithAnnotationsForElement)
2748
+ /* harmony export */ });
2749
+ /* harmony import */ var _stateManagement_annotation_annotationState__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82056);
2750
+
2751
+ function filterToolsWithAnnotationsForElement(element, tools) {
2752
+ const result = [];
2753
+ for (let i = 0; i < tools.length; i++) {
2754
+ const tool = tools[i];
2755
+ if (!tool) {
2756
+ console.warn('undefined tool in filterToolsWithAnnotationsForElement');
2757
+ continue;
2758
+ }
2759
+ let annotations = (0,_stateManagement_annotation_annotationState__WEBPACK_IMPORTED_MODULE_0__.getAnnotations)(tool.constructor.toolName, element);
2760
+ if (!annotations?.length) {
2761
+ continue;
2762
+ }
2763
+ if (typeof tool.filterInteractableAnnotationsForElement === 'function') {
2764
+ annotations = tool.filterInteractableAnnotationsForElement(element, annotations);
2765
+ }
2766
+ if (annotations?.length > 0) {
2767
+ result.push({ tool, annotations });
2768
+ }
2769
+ }
2770
+ return result;
2771
+ }
2772
+
2773
+
2774
+ /***/ },
2775
+
2776
+ /***/ 35486
2777
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2778
+
2779
+ "use strict";
2780
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2781
+ /* harmony export */ A: () => (/* binding */ filterToolsWithMoveableHandles)
2782
+ /* harmony export */ });
2783
+ function filterToolsWithMoveableHandles(element, ToolAndAnnotations, canvasCoords, interactionType = 'mouse') {
2784
+ const proximity = interactionType === 'touch' ? 36 : 6;
2785
+ const toolsWithMoveableHandles = [];
2786
+ ToolAndAnnotations.forEach(({ tool, annotations }) => {
2787
+ for (const annotation of annotations) {
2788
+ if (annotation.isLocked || !annotation.isVisible) {
2789
+ continue;
2790
+ }
2791
+ const handle = tool.getHandleNearImagePoint(element, annotation, canvasCoords, proximity);
2792
+ if (handle) {
2793
+ toolsWithMoveableHandles.push({
2794
+ tool,
2795
+ annotation,
2796
+ handle,
2797
+ });
2798
+ break;
2799
+ }
2800
+ }
2801
+ });
2051
2802
  return toolsWithMoveableHandles;
2052
2803
  }
2053
2804
 
@@ -2079,7 +2830,6 @@ class CircleSculptCursor {
2079
2830
  maxToolSize: null,
2080
2831
  };
2081
2832
  }
2082
- static { this.shapeName = 'Circle'; }
2083
2833
  renderShape(svgDrawingHelper, canvasLocation, options) {
2084
2834
  const circleUID = '0';
2085
2835
  (0,_drawingSvg__WEBPACK_IMPORTED_MODULE_3__.drawCircle)(svgDrawingHelper, 'SculptorTool', circleUID, canvasLocation, this.toolInfo.toolSize, options);
@@ -2142,6 +2892,7 @@ class CircleSculptCursor {
2142
2892
  return gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.distance */ .eR.distance(point, mousePoint) < this.toolInfo.radius;
2143
2893
  }
2144
2894
  }
2895
+ CircleSculptCursor.shapeName = 'Circle';
2145
2896
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (CircleSculptCursor);
2146
2897
 
2147
2898
 
@@ -2176,7 +2927,6 @@ class CircleSculptCursor {
2176
2927
 
2177
2928
  const { transformWorldToIndex, transformIndexToWorld } = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities;
2178
2929
  class GrowCutBaseTool extends _base__WEBPACK_IMPORTED_MODULE_1__/* .BaseTool */ .oS {
2179
- static { this.lastGrowCutCommand = null; }
2180
2930
  constructor(toolProps, defaultToolProps) {
2181
2931
  const baseToolProps = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepMerge({
2182
2932
  configuration: {
@@ -2354,96 +3104,2128 @@ class GrowCutBaseTool extends _base__WEBPACK_IMPORTED_MODULE_1__/* .BaseTool */
2354
3104
  ? imageVolume.volumeId
2355
3105
  : (await _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, referencedImageIds)).volumeId;
2356
3106
  }
2357
- return {
2358
- segmentationId,
2359
- segmentIndex,
2360
- labelmapVolumeId,
2361
- referencedVolumeId,
2362
- };
3107
+ return {
3108
+ segmentationId,
3109
+ segmentIndex,
3110
+ labelmapVolumeId,
3111
+ referencedVolumeId,
3112
+ };
3113
+ }
3114
+ _createFakeVolume(imageIds) {
3115
+ const volumeId = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.generateVolumeId(imageIds);
3116
+ const cachedVolume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(volumeId);
3117
+ if (cachedVolume) {
3118
+ return cachedVolume;
3119
+ }
3120
+ const volumeProps = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.generateVolumePropsFromImageIds(imageIds, volumeId);
3121
+ const spacing = volumeProps.spacing;
3122
+ if (spacing[2] === 0) {
3123
+ spacing[2] = 1;
3124
+ }
3125
+ const derivedVolume = new _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ImageVolume({
3126
+ volumeId,
3127
+ dataType: volumeProps.dataType,
3128
+ metadata: _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.deepClone(volumeProps.metadata),
3129
+ dimensions: volumeProps.dimensions,
3130
+ spacing: volumeProps.spacing,
3131
+ origin: volumeProps.origin,
3132
+ direction: volumeProps.direction,
3133
+ referencedVolumeId: volumeProps.referencedVolumeId,
3134
+ imageIds: volumeProps.imageIds,
3135
+ referencedImageIds: volumeProps.referencedImageIds,
3136
+ });
3137
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.putVolumeSync(volumeId, derivedVolume);
3138
+ return derivedVolume;
3139
+ }
3140
+ _isOrthogonalView(viewport, referencedVolumeId) {
3141
+ const volume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(referencedVolumeId);
3142
+ const volumeImageData = volume.imageData;
3143
+ const camera = viewport.getCamera();
3144
+ const { ijkVecColDir, ijkVecSliceDir } = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.getVolumeDirectionVectors(volumeImageData, camera);
3145
+ return [ijkVecColDir, ijkVecSliceDir].every((vec) => _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[0]), 1) ||
3146
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[1]), 1) ||
3147
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[2]), 1));
3148
+ }
3149
+ getRemoveIslandData(_growCutData) {
3150
+ return;
3151
+ }
3152
+ _removeIslands(growCutData) {
3153
+ const { islandRemoval: config } = this.configuration;
3154
+ if (!config.enabled) {
3155
+ return;
3156
+ }
3157
+ const { segmentation: { segmentIndex, labelmapVolumeId }, renderingEngineId, viewportId, } = growCutData;
3158
+ const labelmap = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(labelmapVolumeId);
3159
+ const removeIslandData = this.getRemoveIslandData(growCutData);
3160
+ if (!removeIslandData) {
3161
+ return;
3162
+ }
3163
+ const [width, height] = labelmap.dimensions;
3164
+ const numPixelsPerSlice = width * height;
3165
+ const { worldIslandPoints = [], islandPointIndexes = [] } = removeIslandData;
3166
+ let ijkIslandPoints = [...(removeIslandData?.ijkIslandPoints ?? [])];
3167
+ const renderingEngine = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getRenderingEngine)(renderingEngineId);
3168
+ const viewport = renderingEngine.getViewport(viewportId);
3169
+ const { voxelManager } = labelmap;
3170
+ const islandRemoval = new _utilities_segmentation_islandRemoval__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .A();
3171
+ ijkIslandPoints = ijkIslandPoints.concat(worldIslandPoints.map((worldPoint) => transformWorldToIndex(labelmap.imageData, worldPoint)));
3172
+ ijkIslandPoints = ijkIslandPoints.concat(islandPointIndexes.map((pointIndex) => {
3173
+ const x = pointIndex % width;
3174
+ const y = Math.floor(pointIndex / width) % height;
3175
+ const z = Math.floor(pointIndex / numPixelsPerSlice);
3176
+ return [x, y, z];
3177
+ }));
3178
+ islandRemoval.initialize(viewport, voxelManager, {
3179
+ points: ijkIslandPoints,
3180
+ previewSegmentIndex: segmentIndex,
3181
+ segmentIndex,
3182
+ });
3183
+ islandRemoval.floodFillSegmentIsland();
3184
+ islandRemoval.removeExternalIslands();
3185
+ islandRemoval.removeInternalIslands();
3186
+ }
3187
+ getSegmentStyle({ segmentationId, viewportId, segmentIndex }) {
3188
+ return (0,_utilities_segmentation_getSVGStyleForSegment__WEBPACK_IMPORTED_MODULE_6__/* .getSVGStyleForSegment */ .u)({
3189
+ segmentationId,
3190
+ segmentIndex,
3191
+ viewportId,
3192
+ });
3193
+ }
3194
+ }
3195
+ GrowCutBaseTool.lastGrowCutCommand = null;
3196
+ GrowCutBaseTool.toolName = 'GrowCutBaseTool';
3197
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (GrowCutBaseTool);
3198
+
3199
+
3200
+ /***/ },
3201
+
3202
+ /***/ 92300
3203
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
3204
+
3205
+ "use strict";
3206
+
3207
+ // EXPORTS
3208
+ __webpack_require__.d(__webpack_exports__, {
3209
+ A: () => (/* binding */ contourDisplay)
3210
+ });
3211
+
3212
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/core/dist/esm/index.js + 1 modules
3213
+ var esm = __webpack_require__(15327);
3214
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/enums/SegmentationRepresentations.js
3215
+ var SegmentationRepresentations = __webpack_require__(18682);
3216
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/annotation/annotationState.js
3217
+ var annotationState = __webpack_require__(82056);
3218
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/annotationHydration.js
3219
+ var annotationHydration = __webpack_require__(64485);
3220
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/contourSegmentation/index.js + 1 modules
3221
+ var contourSegmentation = __webpack_require__(56534);
3222
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/Core/CellArray.js
3223
+ var CellArray = __webpack_require__(32461);
3224
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/Core/Points.js
3225
+ var Points = __webpack_require__(74973);
3226
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/DataModel/PolyData.js + 7 modules
3227
+ var PolyData = __webpack_require__(27480);
3228
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Contour/contourHandler/utils.js
3229
+ /* unused harmony import specifier */ var Enums;
3230
+ /* unused harmony import specifier */ var vtkCellArray;
3231
+ /* unused harmony import specifier */ var vtkPoints;
3232
+ /* unused harmony import specifier */ var vtkPolyData;
3233
+
3234
+
3235
+
3236
+
3237
+ function validateGeometry(geometry) {
3238
+ if (!geometry) {
3239
+ throw new Error(`No contours found for geometryId ${geometry.id}`);
3240
+ }
3241
+ const geometryId = geometry.id;
3242
+ if (geometry.type !== esm.Enums.GeometryType.CONTOUR) {
3243
+ throw new Error(`Geometry type ${geometry.type} not supported for rendering.`);
3244
+ }
3245
+ if (!geometry.data) {
3246
+ console.warn(`No contours found for geometryId ${geometryId}. Skipping render.`);
3247
+ return;
3248
+ }
3249
+ }
3250
+ function getPolyData(contourSet) {
3251
+ const pointArray = [];
3252
+ const points = vtkPoints.newInstance();
3253
+ const lines = vtkCellArray.newInstance();
3254
+ let pointIndex = 0;
3255
+ contourSet.contours.forEach((contour) => {
3256
+ const pointList = contour.points;
3257
+ const flatPoints = contour.flatPointsArray;
3258
+ const type = contour.type;
3259
+ const pointIndexes = pointList.map((_, pointListIndex) => pointListIndex + pointIndex);
3260
+ if (type === Enums.ContourType.CLOSED_PLANAR) {
3261
+ pointIndexes.push(pointIndexes[0]);
3262
+ }
3263
+ const linePoints = Float32Array.from(flatPoints);
3264
+ pointArray.push(...linePoints);
3265
+ lines.insertNextCell([...pointIndexes]);
3266
+ pointIndex = pointIndex + pointList.length;
3267
+ });
3268
+ points.setData(pointArray, 3);
3269
+ const polygon = vtkPolyData.newInstance();
3270
+ polygon.setPoints(points);
3271
+ polygon.setLines(lines);
3272
+ return polygon;
3273
+ }
3274
+
3275
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/enums/index.js + 3 modules
3276
+ var enums = __webpack_require__(29857);
3277
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/SegmentationStyle.js
3278
+ var SegmentationStyle = __webpack_require__(92686);
3279
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js
3280
+
3281
+
3282
+
3283
+
3284
+
3285
+
3286
+
3287
+ function handleContourSegmentation(viewport, geometryIds, annotationUIDsMap, contourRepresentation) {
3288
+ if (annotationUIDsMap.size) {
3289
+ viewport.render();
3290
+ }
3291
+ else {
3292
+ addContourSetsToElement(viewport, geometryIds, contourRepresentation);
3293
+ }
3294
+ }
3295
+ function addContourSetsToElement(viewport, geometryIds, contourRepresentation) {
3296
+ const { segmentationId } = contourRepresentation;
3297
+ const segmentSpecificMap = new Map();
3298
+ geometryIds.forEach((geometryId) => {
3299
+ const geometry = esm.cache.getGeometry(geometryId);
3300
+ if (!geometry) {
3301
+ console.warn(`No geometry found for geometryId ${geometryId}. Skipping render.`);
3302
+ return;
3303
+ }
3304
+ const segmentIndex = geometry.data.segmentIndex;
3305
+ validateGeometry(geometry);
3306
+ const segmentSpecificConfig = SegmentationStyle/* segmentationStyle */.Y.getStyle({
3307
+ viewportId: viewport.id,
3308
+ segmentationId,
3309
+ type: enums.SegmentationRepresentations.Contour,
3310
+ segmentIndex,
3311
+ });
3312
+ const contourSet = geometry.data;
3313
+ const viewPlaneNormal = viewport.getCamera().viewPlaneNormal;
3314
+ contourSet.contours.forEach((contour) => {
3315
+ const { points, color, id } = contour;
3316
+ const referencedImageId = (0,annotationHydration/* getClosestImageIdForStackViewport */.x)(viewport, points[0], viewPlaneNormal);
3317
+ const contourSegmentationAnnotation = {
3318
+ annotationUID: esm.utilities.uuidv4(),
3319
+ data: {
3320
+ contour: {
3321
+ closed: true,
3322
+ polyline: points,
3323
+ },
3324
+ segmentation: {
3325
+ segmentationId,
3326
+ segmentIndex,
3327
+ color,
3328
+ id,
3329
+ },
3330
+ handles: {},
3331
+ },
3332
+ handles: {},
3333
+ highlighted: false,
3334
+ autoGenerated: false,
3335
+ invalidated: false,
3336
+ isLocked: true,
3337
+ isVisible: true,
3338
+ metadata: {
3339
+ referencedImageId,
3340
+ toolName: 'PlanarFreehandContourSegmentationTool',
3341
+ FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
3342
+ viewPlaneNormal: viewport.getCamera().viewPlaneNormal,
3343
+ },
3344
+ };
3345
+ const annotationGroupSelector = viewport.element;
3346
+ (0,annotationState.addAnnotation)(contourSegmentationAnnotation, annotationGroupSelector);
3347
+ (0,contourSegmentation.addContourSegmentationAnnotation)(contourSegmentationAnnotation);
3348
+ });
3349
+ if (segmentSpecificConfig) {
3350
+ segmentSpecificMap.set(segmentIndex, segmentSpecificConfig);
3351
+ }
3352
+ });
3353
+ viewport.render();
3354
+ }
3355
+
3356
+
3357
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getSegmentation.js
3358
+ var getSegmentation = __webpack_require__(33283);
3359
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/index.js
3360
+ var stateManagement = __webpack_require__(6802);
3361
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Contour/removeContourFromElement.js
3362
+ /* unused harmony import specifier */ var removeContourFromElement_getSegmentation;
3363
+ /* unused harmony import specifier */ var removeAnnotation;
3364
+
3365
+
3366
+ function removeContourFromElement(viewportId, segmentationId, removeFromCache = false) {
3367
+ const segmentation = removeContourFromElement_getSegmentation(segmentationId);
3368
+ const { annotationUIDsMap } = segmentation.representationData.Contour;
3369
+ annotationUIDsMap.forEach((annotationSet) => {
3370
+ annotationSet.forEach((annotationUID) => {
3371
+ removeAnnotation(annotationUID);
3372
+ });
3373
+ });
3374
+ }
3375
+ /* harmony default export */ const Contour_removeContourFromElement = ((/* unused pure expression or super */ null && (removeContourFromElement)));
3376
+
3377
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/config.js
3378
+ var config = __webpack_require__(36625);
3379
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/segmentation/computeAndAddRepresentation.js
3380
+ var computeAndAddRepresentation = __webpack_require__(27479);
3381
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js
3382
+ var getUniqueSegmentIndices = __webpack_require__(25758);
3383
+ // EXTERNAL MODULE: ../../../node_modules/gl-matrix/esm/index.js + 1 modules
3384
+ var gl_matrix_esm = __webpack_require__(3823);
3385
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Contour/contourDisplay.js
3386
+
3387
+
3388
+
3389
+
3390
+
3391
+
3392
+
3393
+
3394
+
3395
+
3396
+ const polySegConversionInProgressForViewportId = new Map();
3397
+ const processedViewportSegmentations = new Map();
3398
+ function removeRepresentation(viewportId, segmentationId, renderImmediate = false) {
3399
+ const enabledElement = (0,esm.getEnabledElementByViewportId)(viewportId);
3400
+ if (!enabledElement) {
3401
+ return;
3402
+ }
3403
+ const { viewport } = enabledElement;
3404
+ if (!renderImmediate) {
3405
+ return;
3406
+ }
3407
+ viewport.render();
3408
+ }
3409
+ async function render(viewport, contourRepresentation) {
3410
+ const { segmentationId } = contourRepresentation;
3411
+ const segmentation = (0,getSegmentation/* getSegmentation */.T)(segmentationId);
3412
+ if (!segmentation) {
3413
+ return;
3414
+ }
3415
+ let contourData = segmentation.representationData[SegmentationRepresentations/* default */.A.Contour];
3416
+ const polySeg = (0,config/* getPolySeg */.Qy)();
3417
+ if (!contourData &&
3418
+ (0,config/* getPolySeg */.Qy)()?.canComputeRequestedRepresentation(segmentationId, SegmentationRepresentations/* default */.A.Contour) &&
3419
+ !polySegConversionInProgressForViewportId.get(viewport.id)) {
3420
+ polySegConversionInProgressForViewportId.set(viewport.id, true);
3421
+ try {
3422
+ contourData = await (0,computeAndAddRepresentation/* computeAndAddRepresentation */.d)(segmentationId, SegmentationRepresentations/* default */.A.Contour, () => polySeg.computeContourData(segmentationId, { viewport }));
3423
+ }
3424
+ catch (error) {
3425
+ console.warn('Unable to compute contour data for segmentationId', segmentationId, error);
3426
+ }
3427
+ polySegConversionInProgressForViewportId.set(viewport.id, false);
3428
+ }
3429
+ else if (!contourData && !(0,config/* getPolySeg */.Qy)()) {
3430
+ console.debug(`No contour data found for segmentationId ${segmentationId} and PolySeg add-on is not configured. Unable to convert from other representations to contour. Please register PolySeg using cornerstoneTools.init({ addons: { polySeg } }) to enable automatic conversion.`);
3431
+ }
3432
+ if (!contourData) {
3433
+ return;
3434
+ }
3435
+ if (!contourData.geometryIds?.length) {
3436
+ return;
3437
+ }
3438
+ let hasContourDataButNotMatchingViewport = false;
3439
+ const viewportNormal = viewport.getCamera().viewPlaneNormal;
3440
+ if (contourData.annotationUIDsMap) {
3441
+ hasContourDataButNotMatchingViewport = !_checkContourNormalsMatchViewport(contourData.annotationUIDsMap, viewportNormal);
3442
+ }
3443
+ if (contourData.geometryIds.length > 0) {
3444
+ hasContourDataButNotMatchingViewport = !_checkContourGeometryMatchViewport(contourData.geometryIds, viewportNormal);
3445
+ }
3446
+ const viewportProcessed = processedViewportSegmentations.get(viewport.id) || new Set();
3447
+ if (hasContourDataButNotMatchingViewport &&
3448
+ !polySegConversionInProgressForViewportId.get(viewport.id) &&
3449
+ !viewportProcessed.has(segmentationId) &&
3450
+ viewport.viewportStatus === esm.Enums.ViewportStatus.RENDERED) {
3451
+ polySegConversionInProgressForViewportId.set(viewport.id, true);
3452
+ const segmentIndices = (0,getUniqueSegmentIndices/* getUniqueSegmentIndices */.O)(segmentationId);
3453
+ const surfacesInfo = await polySeg.computeSurfaceData(segmentationId, {
3454
+ segmentIndices,
3455
+ viewport,
3456
+ });
3457
+ const geometryIds = surfacesInfo.geometryIds;
3458
+ const pointsAndPolys = [];
3459
+ for (const geometryId of geometryIds.values()) {
3460
+ const geometry = esm.cache.getGeometry(geometryId);
3461
+ const data = geometry.data;
3462
+ pointsAndPolys.push({
3463
+ points: data.points,
3464
+ polys: data.polys,
3465
+ segmentIndex: data.segmentIndex,
3466
+ id: data.segmentIndex,
3467
+ });
3468
+ }
3469
+ const polyDataCache = await polySeg.clipAndCacheSurfacesForViewport(pointsAndPolys, viewport);
3470
+ const rawResults = polySeg.extractContourData(polyDataCache);
3471
+ const annotationUIDsMap = polySeg.createAndAddContourSegmentationsFromClippedSurfaces(rawResults, viewport, segmentationId);
3472
+ contourData.annotationUIDsMap = new Map([
3473
+ ...contourData.annotationUIDsMap,
3474
+ ...annotationUIDsMap,
3475
+ ]);
3476
+ viewportProcessed.add(segmentationId);
3477
+ processedViewportSegmentations.set(viewport.id, viewportProcessed);
3478
+ polySegConversionInProgressForViewportId.set(viewport.id, false);
3479
+ }
3480
+ handleContourSegmentation(viewport, contourData.geometryIds, contourData.annotationUIDsMap, contourRepresentation);
3481
+ }
3482
+ function _checkContourGeometryMatchViewport(geometryIds, viewportNormal) {
3483
+ let validGeometry = null;
3484
+ let geometryData = null;
3485
+ for (const geometryId of geometryIds) {
3486
+ const geometry = esm.cache.getGeometry(geometryId);
3487
+ if (!geometry) {
3488
+ continue;
3489
+ }
3490
+ const data = geometry.data;
3491
+ if (data.contours?.[0]?.points?.length >= 3) {
3492
+ validGeometry = geometry;
3493
+ geometryData = data;
3494
+ break;
3495
+ }
3496
+ }
3497
+ if (!validGeometry || !geometryData) {
3498
+ return false;
3499
+ }
3500
+ const contours = geometryData.contours;
3501
+ const { points } = contours[0];
3502
+ const [point] = points;
3503
+ const delta = gl_matrix_esm/* vec3.create */.eR.create();
3504
+ const { length } = points;
3505
+ const increment = Math.ceil(length / 25);
3506
+ for (let i = 1; i < length; i += increment) {
3507
+ const point2 = points[i];
3508
+ gl_matrix_esm/* vec3.sub */.eR.sub(delta, point, point2);
3509
+ gl_matrix_esm/* vec3.normalize */.eR.normalize(delta, delta);
3510
+ if (gl_matrix_esm/* vec3.dot */.eR.dot(viewportNormal, delta) > 0.1) {
3511
+ return false;
3512
+ }
3513
+ }
3514
+ return true;
3515
+ }
3516
+ function _checkContourNormalsMatchViewport(annotationUIDsMap, viewportNormal) {
3517
+ const annotationUIDs = Array.from(annotationUIDsMap.values())
3518
+ .flat()
3519
+ .map((uidSet) => Array.from(uidSet))
3520
+ .flat();
3521
+ const randomAnnotationUIDs = esm.utilities.getRandomSampleFromArray(annotationUIDs, 3);
3522
+ for (const annotationUID of randomAnnotationUIDs) {
3523
+ const annotation = (0,annotationState.getAnnotation)(annotationUID);
3524
+ if (annotation?.metadata) {
3525
+ if (!annotation.metadata.viewPlaneNormal) {
3526
+ continue;
3527
+ }
3528
+ const annotationNormal = annotation.metadata.viewPlaneNormal;
3529
+ const dotProduct = Math.abs(viewportNormal[0] * annotationNormal[0] +
3530
+ viewportNormal[1] * annotationNormal[1] +
3531
+ viewportNormal[2] * annotationNormal[2]);
3532
+ if (Math.abs(dotProduct - 1) > 0.01) {
3533
+ return false;
3534
+ }
3535
+ }
3536
+ }
3537
+ return true;
3538
+ }
3539
+ function getUpdateFunction(viewport) {
3540
+ return null;
3541
+ }
3542
+ /* harmony default export */ const contourDisplay = ({
3543
+ getUpdateFunction,
3544
+ render,
3545
+ removeRepresentation,
3546
+ });
3547
+
3548
+
3549
+ /***/ },
3550
+
3551
+ /***/ 21924
3552
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
3553
+
3554
+ "use strict";
3555
+
3556
+ // EXPORTS
3557
+ __webpack_require__.d(__webpack_exports__, {
3558
+ Ay: () => (/* binding */ labelmapDisplay)
3559
+ });
3560
+
3561
+ // UNUSED EXPORTS: MAX_NUMBER_COLORS, removeRepresentation, render
3562
+
3563
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/core/dist/esm/index.js + 1 modules
3564
+ var esm = __webpack_require__(15327);
3565
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getSegmentation.js
3566
+ var getSegmentation = __webpack_require__(33283);
3567
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/enums/SegmentationRepresentations.js
3568
+ var SegmentationRepresentations = __webpack_require__(18682);
3569
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.js
3570
+ var getSegmentationActor = __webpack_require__(59452);
3571
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/config.js
3572
+ var config = __webpack_require__(36625);
3573
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/segmentation/computeAndAddRepresentation.js
3574
+ var computeAndAddRepresentation = __webpack_require__(27479);
3575
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js
3576
+ var triggerSegmentationEvents = __webpack_require__(49906);
3577
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/SegmentationStateManager.js
3578
+ var SegmentationStateManager = __webpack_require__(59475);
3579
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/removeLabelmapRepresentationData.js
3580
+ var removeLabelmapRepresentationData = __webpack_require__(24393);
3581
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Rendering/Core/ImageMapper.js
3582
+ var ImageMapper = __webpack_require__(23549);
3583
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Rendering/Core/ImageSlice.js
3584
+ var ImageSlice = __webpack_require__(94848);
3585
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/labelmapImageMapperSupport.js
3586
+ var labelmapImageMapperSupport = __webpack_require__(78028);
3587
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/labelmapSegmentationState.js
3588
+ var labelmapSegmentationState = __webpack_require__(90660);
3589
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRepresentationUID.js
3590
+ var labelmapRepresentationUID = __webpack_require__(5959);
3591
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/Core/DataArray.js
3592
+ var DataArray = __webpack_require__(445);
3593
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/DataModel/ImageData.js
3594
+ var ImageData = __webpack_require__(26393);
3595
+ // EXTERNAL MODULE: ../../../node_modules/gl-matrix/esm/index.js + 1 modules
3596
+ var gl_matrix_esm = __webpack_require__(3823);
3597
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/volumeLabelmapSliceData.js
3598
+
3599
+
3600
+
3601
+
3602
+
3603
+
3604
+ const PLANAR_OVERLAY_DEPTH_EPSILON = 1e-4;
3605
+ function applyPlanarOverlayDepthOffset(actor, viewPlaneNormal, overlayOrder) {
3606
+ if (overlayOrder <= 0) {
3607
+ actor.setPosition(0, 0, 0);
3608
+ return;
3609
+ }
3610
+ const [x, y, z] = gl_matrix_esm/* vec3.normalize */.eR.normalize(gl_matrix_esm/* vec3.create */.eR.create(), viewPlaneNormal);
3611
+ const offset = overlayOrder * PLANAR_OVERLAY_DEPTH_EPSILON;
3612
+ actor.setPosition(x * offset, y * offset, z * offset);
3613
+ }
3614
+ function matchAxis(vector, axes) {
3615
+ let bestAxis = -1;
3616
+ let bestDot = 0;
3617
+ axes.forEach((axisVector, axis) => {
3618
+ const dot = gl_matrix_esm/* vec3.dot */.eR.dot(vector, axisVector);
3619
+ if (Math.abs(dot) > Math.abs(bestDot)) {
3620
+ bestAxis = axis;
3621
+ bestDot = dot;
3622
+ }
3623
+ });
3624
+ if (bestAxis === -1 || Math.abs(bestDot) < labelmapImageMapperSupport/* DIRECTION_ALIGNMENT_TOLERANCE */.KM) {
3625
+ return;
3626
+ }
3627
+ return {
3628
+ axis: bestAxis,
3629
+ sign: bestDot >= 0 ? 1 : -1,
3630
+ };
3631
+ }
3632
+ function getSliceRenderingCamera(viewport) {
3633
+ const resolvedCamera = viewport.getResolvedView?.()?.toICamera?.();
3634
+ const normalizedResolvedCamera = normalizeSliceRenderingCamera(resolvedCamera);
3635
+ if (normalizedResolvedCamera) {
3636
+ return normalizedResolvedCamera;
3637
+ }
3638
+ const legacyCamera = viewport.getCamera?.();
3639
+ const normalizedLegacyCamera = normalizeSliceRenderingCamera(legacyCamera);
3640
+ return normalizedLegacyCamera;
3641
+ }
3642
+ function normalizeSliceRenderingCamera(camera) {
3643
+ const candidate = camera;
3644
+ const focalPoint = toPoint3(candidate?.focalPoint);
3645
+ const viewPlaneNormal = toPoint3(candidate?.viewPlaneNormal);
3646
+ const viewUp = toPoint3(candidate?.viewUp);
3647
+ if (!focalPoint || !viewPlaneNormal || !viewUp) {
3648
+ return;
3649
+ }
3650
+ return {
3651
+ focalPoint,
3652
+ viewPlaneNormal,
3653
+ viewUp,
3654
+ };
3655
+ }
3656
+ function toPoint3(value) {
3657
+ const candidate = value;
3658
+ if (!candidate || typeof candidate.length !== 'number') {
3659
+ return;
3660
+ }
3661
+ if (candidate.length < 3) {
3662
+ return;
3663
+ }
3664
+ const point = [
3665
+ Number(candidate[0]),
3666
+ Number(candidate[1]),
3667
+ Number(candidate[2]),
3668
+ ];
3669
+ return point.every(Number.isFinite) ? point : undefined;
3670
+ }
3671
+ function getVolumeAxes(volume) {
3672
+ const { direction } = volume;
3673
+ return [
3674
+ [direction[0], direction[1], direction[2]],
3675
+ [direction[3], direction[4], direction[5]],
3676
+ [direction[6], direction[7], direction[8]],
3677
+ ];
3678
+ }
3679
+ function getSliceState(viewport, volume) {
3680
+ const camera = getSliceRenderingCamera(viewport);
3681
+ if (!camera) {
3682
+ return;
3683
+ }
3684
+ const { viewPlaneNormal, viewUp, focalPoint } = camera;
3685
+ const xDirection = gl_matrix_esm/* vec3.normalize */.eR.normalize(gl_matrix_esm/* vec3.create */.eR.create(), gl_matrix_esm/* vec3.cross */.eR.cross(gl_matrix_esm/* vec3.create */.eR.create(), viewPlaneNormal, viewUp));
3686
+ const yDirection = gl_matrix_esm/* vec3.normalize */.eR.normalize(gl_matrix_esm/* vec3.create */.eR.create(), viewUp);
3687
+ const axes = getVolumeAxes(volume);
3688
+ const xAxis = matchAxis(xDirection, axes);
3689
+ const yAxis = matchAxis(yDirection, axes);
3690
+ const sliceAxis = matchAxis(viewPlaneNormal, axes);
3691
+ if (!xAxis || !yAxis || !sliceAxis) {
3692
+ return;
3693
+ }
3694
+ const distinctAxes = new Set([xAxis.axis, yAxis.axis, sliceAxis.axis]);
3695
+ if (distinctAxes.size !== 3) {
3696
+ return;
3697
+ }
3698
+ const continuousIndex = esm.utilities.transformWorldToIndexContinuous(volume.imageData, focalPoint);
3699
+ const sliceIndex = Math.floor(continuousIndex[sliceAxis.axis] + 0.5 - 1e-6);
3700
+ if (sliceIndex < 0 || sliceIndex >= volume.dimensions[sliceAxis.axis]) {
3701
+ return;
3702
+ }
3703
+ return {
3704
+ key: [
3705
+ sliceAxis.axis,
3706
+ sliceIndex,
3707
+ xAxis.axis,
3708
+ xAxis.sign,
3709
+ yAxis.axis,
3710
+ yAxis.sign,
3711
+ ].join(':'),
3712
+ xAxis: xAxis.axis,
3713
+ xSign: xAxis.sign,
3714
+ yAxis: yAxis.axis,
3715
+ ySign: yAxis.sign,
3716
+ sliceAxis: sliceAxis.axis,
3717
+ sliceIndex,
3718
+ };
3719
+ }
3720
+ function createSliceImageData(volume, viewport) {
3721
+ const state = getSliceState(viewport, volume);
3722
+ if (!state) {
3723
+ return;
3724
+ }
3725
+ const axisVectors = getVolumeAxes(volume);
3726
+ const { dimensions, spacing, voxelManager } = volume;
3727
+ const width = dimensions[state.xAxis];
3728
+ const height = dimensions[state.yAxis];
3729
+ const SliceDataConstructor = voxelManager.getConstructor();
3730
+ const pixelData = new SliceDataConstructor(width * height);
3731
+ const ijk = [0, 0, 0];
3732
+ ijk[state.sliceAxis] = state.sliceIndex;
3733
+ const xStart = state.xSign > 0 ? 0 : width - 1;
3734
+ const xStep = state.xSign > 0 ? 1 : -1;
3735
+ const yStart = state.ySign > 0 ? 0 : height - 1;
3736
+ const yStep = state.ySign > 0 ? 1 : -1;
3737
+ for (let y = 0, srcY = yStart; y < height; y++, srcY += yStep) {
3738
+ ijk[state.yAxis] = srcY;
3739
+ const rowOffset = y * width;
3740
+ for (let x = 0, srcX = xStart; x < width; x++, srcX += xStep) {
3741
+ ijk[state.xAxis] = srcX;
3742
+ pixelData[rowOffset + x] = Number(voxelManager.getAtIJK(ijk[0], ijk[1], ijk[2]));
3743
+ }
3744
+ }
3745
+ const originIndex = [0, 0, 0];
3746
+ originIndex[state.sliceAxis] = state.sliceIndex;
3747
+ originIndex[state.xAxis] = state.xSign > 0 ? 0 : width - 1;
3748
+ originIndex[state.yAxis] = state.ySign > 0 ? 0 : height - 1;
3749
+ const xDirection = axisVectors[state.xAxis].map((value) => value * state.xSign);
3750
+ const yDirection = axisVectors[state.yAxis].map((value) => value * state.ySign);
3751
+ const camera = getSliceRenderingCamera(viewport);
3752
+ if (!camera) {
3753
+ return;
3754
+ }
3755
+ const zDirection = gl_matrix_esm/* vec3.normalize */.eR.normalize(gl_matrix_esm/* vec3.create */.eR.create(), camera.viewPlaneNormal);
3756
+ const dataType = DataArray/* default */.Ay.getDataType(pixelData);
3757
+ const scalarArray = DataArray/* default.newInstance */.Ay.newInstance({
3758
+ dataType,
3759
+ name: 'Pixels',
3760
+ numberOfComponents: 1,
3761
+ values: pixelData,
3762
+ });
3763
+ const imageData = ImageData/* default.newInstance */.Ay.newInstance();
3764
+ imageData.set({ dataType, numberOfComponents: 1 }, true);
3765
+ imageData.setDimensions(width, height, 1);
3766
+ imageData.setSpacing([spacing[state.xAxis], spacing[state.yAxis], 1]);
3767
+ imageData.setDirection(new Float32Array([
3768
+ ...xDirection,
3769
+ ...yDirection,
3770
+ zDirection[0],
3771
+ zDirection[1],
3772
+ zDirection[2],
3773
+ ]));
3774
+ imageData.setOrigin(esm.utilities.transformIndexToWorld(volume.imageData, originIndex));
3775
+ imageData.getPointData().setScalars(scalarArray);
3776
+ imageData.modified();
3777
+ return {
3778
+ imageData,
3779
+ state,
3780
+ };
3781
+ }
3782
+
3783
+
3784
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/volumeLabelmapImageMapper.js
3785
+
3786
+
3787
+
3788
+
3789
+
3790
+
3791
+
3792
+ const OVERLAY_RENDERER_SUFFIX = 'labelmap-image-mapper-overlay';
3793
+ function isPlanarSliceRenderingViewport(viewport) {
3794
+ const compatibilityViewport = viewport;
3795
+ return (compatibilityViewport.type === esm.Enums.ViewportType.PLANAR_NEXT &&
3796
+ typeof compatibilityViewport.addImages === 'function' &&
3797
+ typeof compatibilityViewport.getCurrentImageId === 'function' &&
3798
+ typeof compatibilityViewport.render === 'function');
3799
+ }
3800
+ function createActorEntry(args) {
3801
+ const mapper = ImageMapper/* default.newInstance */.Ay.newInstance();
3802
+ mapper.setInputData(args.imageData);
3803
+ const actor = ImageSlice/* default.newInstance */.Ay.newInstance();
3804
+ actor.setMapper(mapper);
3805
+ return {
3806
+ uid: args.representationUID,
3807
+ actor,
3808
+ actorMapper: {
3809
+ actor,
3810
+ mapper,
3811
+ renderMode: esm.ActorRenderMode.VTK_IMAGE,
3812
+ },
3813
+ referencedId: args.referencedId,
3814
+ representationUID: args.representationUID,
3815
+ };
3816
+ }
3817
+ function getOverlayRendererId(viewportId) {
3818
+ return `${viewportId}::${OVERLAY_RENDERER_SUFFIX}`;
3819
+ }
3820
+ function getOrCreateOverlayRenderer(viewport) {
3821
+ const renderingEngine = viewport.getRenderingEngine();
3822
+ const offscreenMultiRenderWindow = renderingEngine.getOffscreenMultiRenderWindow(viewport.id);
3823
+ const overlayRendererId = getOverlayRendererId(viewport.id);
3824
+ const baseRenderer = viewport.getRenderer();
3825
+ const baseViewport = baseRenderer.getViewport();
3826
+ let overlayRenderer = offscreenMultiRenderWindow.getRenderer(overlayRendererId);
3827
+ if (!overlayRenderer) {
3828
+ const renderWindow = offscreenMultiRenderWindow.getRenderWindow();
3829
+ if (renderWindow.getNumberOfLayers() < 2) {
3830
+ renderWindow.setNumberOfLayers(2);
3831
+ }
3832
+ offscreenMultiRenderWindow.addRenderer({
3833
+ viewport: baseViewport,
3834
+ id: overlayRendererId,
3835
+ background: [0, 0, 0],
3836
+ });
3837
+ overlayRenderer = offscreenMultiRenderWindow.getRenderer(overlayRendererId);
3838
+ overlayRenderer.setLayer(1);
3839
+ overlayRenderer.setPreserveDepthBuffer(false);
3840
+ }
3841
+ overlayRenderer.setActiveCamera(baseRenderer.getActiveCamera());
3842
+ overlayRenderer.setViewport(baseViewport[0], baseViewport[1], baseViewport[2], baseViewport[3]);
3843
+ return overlayRenderer;
3844
+ }
3845
+ function moveActorToOverlayRenderer(viewport, actorEntry) {
3846
+ const baseRenderer = viewport.getRenderer();
3847
+ const overlayRenderer = getOrCreateOverlayRenderer(viewport);
3848
+ baseRenderer.removeActor(actorEntry.actor);
3849
+ overlayRenderer.addActor(actorEntry.actor);
3850
+ }
3851
+ function getVolumeLabelmapImageMapperRepresentationUIDs(viewport, segmentationId, segmentation) {
3852
+ if (!(0,labelmapImageMapperSupport/* canRenderVolumeViewportLabelmapAsImage */.QO)(viewport)) {
3853
+ return [];
3854
+ }
3855
+ const useStablePlanarUID = isPlanarSliceRenderingViewport(viewport);
3856
+ return (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation)
3857
+ .map((layer) => {
3858
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
3859
+ if (!volume) {
3860
+ return;
3861
+ }
3862
+ const state = getSliceState(viewport, volume);
3863
+ if (!state) {
3864
+ return;
3865
+ }
3866
+ return (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
3867
+ segmentationId,
3868
+ referencedId: layer.labelmapId,
3869
+ ...(useStablePlanarUID ? {} : { sliceStateKey: state.key }),
3870
+ });
3871
+ })
3872
+ .filter((value) => !!value);
3873
+ }
3874
+ async function addVolumeLabelmapImageMapperActors(args) {
3875
+ const { viewport, segmentation, segmentationId } = args;
3876
+ if (!(0,labelmapImageMapperSupport/* canRenderVolumeViewportLabelmapAsImage */.QO)(viewport)) {
3877
+ return;
3878
+ }
3879
+ if (isPlanarSliceRenderingViewport(viewport)) {
3880
+ await addPlanarLabelmapImageMapperActors({
3881
+ viewport,
3882
+ segmentation,
3883
+ segmentationId,
3884
+ });
3885
+ return;
3886
+ }
3887
+ (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation).forEach((layer) => {
3888
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
3889
+ if (!volume) {
3890
+ return;
3891
+ }
3892
+ const sliceData = createSliceImageData(volume, viewport);
3893
+ if (!sliceData) {
3894
+ return;
3895
+ }
3896
+ const representationUID = (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
3897
+ segmentationId,
3898
+ referencedId: layer.labelmapId,
3899
+ sliceStateKey: sliceData.state.key,
3900
+ });
3901
+ const actorEntry = createActorEntry({
3902
+ imageData: sliceData.imageData,
3903
+ referencedId: layer.labelmapId,
3904
+ representationUID,
3905
+ });
3906
+ viewport.addActor(actorEntry);
3907
+ moveActorToOverlayRenderer(viewport, actorEntry);
3908
+ });
3909
+ }
3910
+ function updateVolumeLabelmapImageMapperActors(args) {
3911
+ const { viewport, segmentation, segmentationId, actorEntries } = args;
3912
+ if (!(0,labelmapImageMapperSupport/* canRenderVolumeViewportLabelmapAsImage */.QO)(viewport)) {
3913
+ return;
3914
+ }
3915
+ if (isPlanarSliceRenderingViewport(viewport)) {
3916
+ updatePlanarLabelmapImageMapperActors({
3917
+ viewport,
3918
+ segmentation,
3919
+ segmentationId,
3920
+ actorEntries,
3921
+ });
3922
+ return;
3923
+ }
3924
+ const actorEntriesByLabelmapId = new Map((actorEntries ?? viewport.getActors())
3925
+ .filter((actorEntry) => (0,labelmapRepresentationUID/* isLabelmapRepresentationUID */.qV)(actorEntry.representationUID, segmentationId))
3926
+ .map((actorEntry) => [actorEntry.referencedId, actorEntry]));
3927
+ (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation).forEach((layer) => {
3928
+ const actorEntry = actorEntriesByLabelmapId.get(layer.labelmapId);
3929
+ if (!actorEntry) {
3930
+ return;
3931
+ }
3932
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
3933
+ if (!volume) {
3934
+ return;
3935
+ }
3936
+ const sliceData = createSliceImageData(volume, viewport);
3937
+ if (!sliceData) {
3938
+ return;
3939
+ }
3940
+ const mapper = actorEntry.actor.getMapper();
3941
+ mapper.setInputData(sliceData.imageData);
3942
+ mapper.modified();
3943
+ actorEntry.actor.modified?.();
3944
+ });
3945
+ }
3946
+ function removeVolumeLabelmapImageMapperActors(viewport, segmentationId) {
3947
+ if (!(viewport.type === esm.Enums.ViewportType.ORTHOGRAPHIC)) {
3948
+ return;
3949
+ }
3950
+ if (!(0,labelmapImageMapperSupport/* canRenderVolumeViewportLabelmapAsImage */.QO)(viewport)) {
3951
+ return;
3952
+ }
3953
+ const renderingEngine = viewport.getRenderingEngine();
3954
+ const offscreenMultiRenderWindow = renderingEngine.getOffscreenMultiRenderWindow(viewport.id);
3955
+ const overlayRenderer = offscreenMultiRenderWindow.getRenderer(getOverlayRendererId(viewport.id));
3956
+ if (!overlayRenderer) {
3957
+ return;
3958
+ }
3959
+ viewport
3960
+ .getActors()
3961
+ .filter((actorEntry) => (0,labelmapRepresentationUID/* isLabelmapRepresentationUID */.qV)(actorEntry.representationUID, segmentationId))
3962
+ .forEach((actorEntry) => {
3963
+ overlayRenderer.removeActor(actorEntry.actor);
3964
+ });
3965
+ if (!overlayRenderer.getActors().length) {
3966
+ offscreenMultiRenderWindow.removeRenderer(getOverlayRendererId(viewport.id));
3967
+ }
3968
+ }
3969
+ function getLabelmapForActorReference(segmentation, referencedId) {
3970
+ if (!referencedId) {
3971
+ return;
3972
+ }
3973
+ return ((0,labelmapSegmentationState/* getLabelmap */.Hs)(segmentation, referencedId) ??
3974
+ (0,labelmapSegmentationState/* getLabelmapForImageId */.M4)(segmentation, referencedId) ??
3975
+ (0,labelmapSegmentationState/* getLabelmapForVolumeId */.BS)(segmentation, referencedId) ??
3976
+ (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation).find((layer) => layer.volumeId === referencedId));
3977
+ }
3978
+ async function addPlanarLabelmapImageMapperActors(args) {
3979
+ const { viewport, segmentation, segmentationId } = args;
3980
+ for (const [index, layer] of (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation).entries()) {
3981
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
3982
+ if (!volume) {
3983
+ continue;
3984
+ }
3985
+ const sliceData = createSliceImageData(volume, viewport);
3986
+ if (!sliceData) {
3987
+ continue;
3988
+ }
3989
+ const currentImageId = viewport.getCurrentImageId() ??
3990
+ volume.imageIds[Math.min(Math.max(sliceData.state.sliceIndex, 0), Math.max(volume.imageIds.length - 1, 0))];
3991
+ if (!currentImageId) {
3992
+ continue;
3993
+ }
3994
+ const representationUID = (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
3995
+ segmentationId,
3996
+ referencedId: layer.labelmapId,
3997
+ });
3998
+ await viewport.addImages([
3999
+ {
4000
+ dataId: representationUID,
4001
+ imageId: currentImageId,
4002
+ imageData: sliceData.imageData,
4003
+ reference: {
4004
+ kind: 'segmentation',
4005
+ segmentationId,
4006
+ representationUID,
4007
+ labelmapId: layer.labelmapId,
4008
+ },
4009
+ useWorldCoordinateImageData: true,
4010
+ callback: ({ imageActor }) => {
4011
+ const mapper = imageActor.getMapper();
4012
+ const camera = getSliceRenderingCamera(viewport);
4013
+ mapper.setInputData(sliceData.imageData);
4014
+ mapper.modified();
4015
+ if (camera) {
4016
+ applyPlanarOverlayDepthOffset(imageActor, camera.viewPlaneNormal, index + 1);
4017
+ }
4018
+ },
4019
+ },
4020
+ ]);
4021
+ }
4022
+ viewport.render();
4023
+ }
4024
+ function updatePlanarLabelmapImageMapperActors(args) {
4025
+ const { viewport, segmentation, segmentationId, actorEntries } = args;
4026
+ const actorEntriesByLabelmapId = new Map((actorEntries ?? viewport.getActors())
4027
+ .filter((actorEntry) => (0,labelmapRepresentationUID/* isLabelmapRepresentationUID */.qV)(actorEntry.representationUID, segmentationId))
4028
+ .map((actorEntry) => [actorEntry.referencedId, actorEntry]));
4029
+ (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation).forEach((layer, index) => {
4030
+ const actorEntry = actorEntriesByLabelmapId.get(layer.labelmapId);
4031
+ if (!actorEntry) {
4032
+ return;
4033
+ }
4034
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
4035
+ if (!volume) {
4036
+ return;
4037
+ }
4038
+ const sliceData = createSliceImageData(volume, viewport);
4039
+ if (!sliceData) {
4040
+ return;
4041
+ }
4042
+ const mapper = actorEntry.actor.getMapper();
4043
+ mapper.setInputData(sliceData.imageData);
4044
+ mapper.modified();
4045
+ const camera = getSliceRenderingCamera(viewport);
4046
+ if (camera) {
4047
+ applyPlanarOverlayDepthOffset(actorEntry.actor, camera.viewPlaneNormal, index + 1);
4048
+ }
4049
+ actorEntry.actor.modified?.();
4050
+ });
4051
+ }
4052
+
4053
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/removeLabelmapRepresentationFromViewport.js
4054
+
4055
+
4056
+
4057
+ function removeLabelmapRepresentationFromViewport(viewport, segmentationId) {
4058
+ removeVolumeLabelmapImageMapperActors(viewport, segmentationId);
4059
+ const labelmapActorEntries = (0,getSegmentationActor/* getLabelmapActorEntries */.ED)(viewport.id, segmentationId) ?? [];
4060
+ const legacyActorEntryUIDs = [];
4061
+ labelmapActorEntries.forEach((actorEntry) => {
4062
+ if ((0,removeLabelmapRepresentationData/* default */.A)(viewport, segmentationId, actorEntry)) {
4063
+ return;
4064
+ }
4065
+ legacyActorEntryUIDs.push(actorEntry.uid);
4066
+ });
4067
+ if (legacyActorEntryUIDs.length) {
4068
+ viewport.removeActors(legacyActorEntryUIDs);
4069
+ }
4070
+ }
4071
+
4072
+
4073
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/createLabelmapRenderPlan.js
4074
+
4075
+
4076
+ function createLabelmapRenderPlan({ isVolumeImageMapper, kind, renderMode, segmentationId, unsupportedStateKey, updateAfterMount = true, useSliceRendering, viewport, canRenderCurrentViewport = () => kind !== 'unsupported', getExpectedRepresentationUIDs = () => [], mount = async () => undefined, update = () => undefined, }) {
4077
+ const remove = () => removeLabelmapRepresentationFromViewport(viewport, segmentationId);
4078
+ const needsRemount = (actorEntries) => haveActorUIDsChanged(actorEntries, getExpectedRepresentationUIDs());
4079
+ return {
4080
+ kind,
4081
+ renderMode,
4082
+ useSliceRendering,
4083
+ isVolumeImageMapper,
4084
+ unsupportedStateKey,
4085
+ getExpectedRepresentationUIDs,
4086
+ mount,
4087
+ needsRemount,
4088
+ remove,
4089
+ update,
4090
+ reconcile: async ({ actorEntries, labelMapData }) => {
4091
+ if (!canRenderCurrentViewport()) {
4092
+ return actorEntries;
4093
+ }
4094
+ let nextActorEntries = actorEntries;
4095
+ if (needsRemount(nextActorEntries) && nextActorEntries?.length) {
4096
+ remove();
4097
+ nextActorEntries = undefined;
4098
+ }
4099
+ const mounted = !nextActorEntries?.length;
4100
+ if (mounted) {
4101
+ await mount({ labelMapData });
4102
+ }
4103
+ nextActorEntries = (0,getSegmentationActor/* getLabelmapActorEntries */.ED)(viewport.id, segmentationId);
4104
+ if (nextActorEntries?.length && (!mounted || updateAfterMount)) {
4105
+ update({ actorEntries: nextActorEntries });
4106
+ }
4107
+ return nextActorEntries;
4108
+ },
4109
+ };
4110
+ }
4111
+ function haveActorUIDsChanged(actorEntries, expectedRepresentationUIDs) {
4112
+ const actualUIDs = new Set((actorEntries ?? []).map((entry) => entry.representationUID));
4113
+ const expectedUIDs = new Set(expectedRepresentationUIDs);
4114
+ if (actualUIDs.size !== expectedUIDs.size) {
4115
+ return true;
4116
+ }
4117
+ for (const expectedUID of expectedUIDs) {
4118
+ if (!actualUIDs.has(expectedUID)) {
4119
+ return true;
4120
+ }
4121
+ }
4122
+ return false;
4123
+ }
4124
+
4125
+
4126
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/getViewportLabelmapRenderMode.js
4127
+ var getViewportLabelmapRenderMode = __webpack_require__(33214);
4128
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/enums/index.js + 3 modules
4129
+ var enums = __webpack_require__(29857);
4130
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/addVolumesAsIndependentComponents.js
4131
+
4132
+
4133
+
4134
+ const internalCache = new Map();
4135
+ const load = ({ cfun, ofun, actor }) => {
4136
+ actor.getProperty().setRGBTransferFunction(1, cfun);
4137
+ actor.getProperty().setScalarOpacity(1, ofun);
4138
+ };
4139
+ async function addVolumesAsIndependentComponents({ viewport, volumeInputs, segmentationId, }) {
4140
+ const defaultActor = viewport.getDefaultActor();
4141
+ const { actor } = defaultActor;
4142
+ const { uid } = defaultActor;
4143
+ const referenceVolumeId = viewport.getVolumeId();
4144
+ if (internalCache.get(uid)?.added) {
4145
+ return {
4146
+ uid,
4147
+ actor,
4148
+ };
4149
+ }
4150
+ const volumeInputArray = volumeInputs;
4151
+ const firstImageVolume = esm.cache.getVolume(volumeInputArray[0].volumeId);
4152
+ if (!firstImageVolume) {
4153
+ throw new Error(`imageVolume with id: ${firstImageVolume.volumeId} does not exist`);
4154
+ }
4155
+ const { volumeId } = volumeInputArray[0];
4156
+ const segImageVolume = await esm.volumeLoader.loadVolume(volumeId);
4157
+ if (!segImageVolume) {
4158
+ throw new Error(`segImageVolume with id: ${segImageVolume.volumeId} does not exist`);
4159
+ }
4160
+ const segVoxelManager = segImageVolume.voxelManager;
4161
+ const segData = segVoxelManager.getCompleteScalarDataArray();
4162
+ const { imageData: segImageData } = segImageVolume;
4163
+ const baseVolume = esm.cache.getVolume(referenceVolumeId);
4164
+ const volumeTexture = baseVolume.vtkOpenGLTexture;
4165
+ const hasPendingFrames = volumeTexture.hasUpdatedFrames();
4166
+ if (hasPendingFrames) {
4167
+ return;
4168
+ }
4169
+ const baseVoxelManager = baseVolume.voxelManager;
4170
+ const baseData = baseVoxelManager.getCompleteScalarDataArray();
4171
+ const newComp = 2;
4172
+ const cubeData = new Float32Array(newComp * baseVolume.voxelManager.getScalarDataLength());
4173
+ const dims = segImageData.getDimensions();
4174
+ for (let z = 0; z < dims[2]; ++z) {
4175
+ for (let y = 0; y < dims[1]; ++y) {
4176
+ for (let x = 0; x < dims[0]; ++x) {
4177
+ const iTuple = x + dims[0] * (y + dims[1] * z);
4178
+ cubeData[iTuple * newComp + 0] = baseData[iTuple];
4179
+ cubeData[iTuple * newComp + 1] = segData[iTuple];
4180
+ }
4181
+ }
4182
+ }
4183
+ viewport.removeActors([uid]);
4184
+ const oldMapper = actor.getMapper();
4185
+ const mapper = (0,esm.convertMapperToNotSharedMapper)(oldMapper);
4186
+ actor.setMapper(mapper);
4187
+ mapper.setBlendMode(esm.Enums.BlendModes.LABELMAP_EDGE_PROJECTION_BLEND);
4188
+ const arrayAgain = mapper.getInputData().getPointData().getArray(0);
4189
+ arrayAgain.setData(cubeData);
4190
+ arrayAgain.setNumberOfComponents(2);
4191
+ const oldColorMixPreset = actor.getProperty().getColorMixPreset();
4192
+ actor.getProperty().setColorMixPreset(1);
4193
+ const oldForceNearestInterpolation = actor
4194
+ .getProperty()
4195
+ .getForceNearestInterpolation(1);
4196
+ actor.getProperty().setForceNearestInterpolation(1, true);
4197
+ const oldIndependentComponents = actor
4198
+ .getProperty()
4199
+ .getIndependentComponents();
4200
+ actor.getProperty().setIndependentComponents(true);
4201
+ viewport.addActor({
4202
+ ...defaultActor,
4203
+ representationUID: `${segmentationId}-${enums.SegmentationRepresentations.Labelmap}`,
4204
+ });
4205
+ internalCache.set(uid, {
4206
+ added: true,
4207
+ segmentationRepresentationUID: `${segmentationId}`,
4208
+ originalBlendMode: viewport.getBlendMode(),
4209
+ });
4210
+ const oldPreLoad = actor.get('preLoad');
4211
+ actor.set({
4212
+ preLoad: load,
4213
+ });
4214
+ function onSegmentationDataModified(evt) {
4215
+ const { segmentationId } = evt.detail;
4216
+ const { representationData } = (0,getSegmentation/* getSegmentation */.T)(segmentationId);
4217
+ const { volumeId: segVolumeId } = representationData.Labelmap;
4218
+ if (segVolumeId !== segImageVolume.volumeId) {
4219
+ return;
4220
+ }
4221
+ const segmentationVolume = esm.cache.getVolume(segVolumeId);
4222
+ const segVoxelManager = segmentationVolume.voxelManager;
4223
+ const imageData = mapper.getInputData();
4224
+ const array = imageData.getPointData().getArray(0);
4225
+ const baseData = array.getData();
4226
+ const newComp = 2;
4227
+ const dims = segImageData.getDimensions();
4228
+ const slices = Array.from({ length: dims[2] }, (_, i) => i);
4229
+ for (const z of slices) {
4230
+ for (let y = 0; y < dims[1]; ++y) {
4231
+ for (let x = 0; x < dims[0]; ++x) {
4232
+ const iTuple = x + dims[0] * (y + dims[1] * z);
4233
+ baseData[iTuple * newComp + 1] = segVoxelManager.getAtIndex(iTuple);
4234
+ }
4235
+ }
4236
+ }
4237
+ array.setData(baseData);
4238
+ imageData.modified();
4239
+ viewport.render();
4240
+ }
4241
+ esm.eventTarget.addEventListenerDebounced(enums.Events.SEGMENTATION_DATA_MODIFIED, onSegmentationDataModified, 200);
4242
+ function onSegmentationRepresentationRemoved(evt) {
4243
+ if (evt.detail.viewportId !== viewport.id) {
4244
+ return;
4245
+ }
4246
+ esm.eventTarget.removeEventListener(enums.Events.SEGMENTATION_DATA_MODIFIED, onSegmentationDataModified);
4247
+ esm.eventTarget.removeEventListener(enums.Events.SEGMENTATION_REPRESENTATION_REMOVED, onSegmentationRepresentationRemoved);
4248
+ const actorEntry = viewport.getActor(uid);
4249
+ if (actorEntry) {
4250
+ viewport.removeActors([uid]);
4251
+ }
4252
+ internalCache.delete(uid);
4253
+ if (viewport.isDisabled) {
4254
+ return;
4255
+ }
4256
+ actor.setMapper(oldMapper);
4257
+ actor.getProperty().setColorMixPreset(oldColorMixPreset);
4258
+ actor
4259
+ .getProperty()
4260
+ .setForceNearestInterpolation(1, oldForceNearestInterpolation);
4261
+ actor.getProperty().setIndependentComponents(oldIndependentComponents);
4262
+ viewport.addActor({
4263
+ ...defaultActor,
4264
+ });
4265
+ actor.set(oldPreLoad);
4266
+ viewport.render();
4267
+ }
4268
+ esm.eventTarget.addEventListener(enums.Events.SEGMENTATION_REPRESENTATION_REMOVED, onSegmentationRepresentationRemoved);
4269
+ return {
4270
+ uid,
4271
+ actor,
4272
+ };
4273
+ }
4274
+
4275
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/planarGenericVolumeLabelmap.js
4276
+
4277
+
4278
+ function isPlanarNextVolumeViewport(viewport) {
4279
+ const genericViewport = viewport;
4280
+ return (genericViewport.type === esm.Enums.ViewportType.PLANAR_NEXT &&
4281
+ typeof genericViewport.getVolumeId === 'function' &&
4282
+ typeof genericViewport.getViewReference === 'function' &&
4283
+ typeof genericViewport.getViewState === 'function' &&
4284
+ typeof genericViewport.addDisplaySet === 'function' &&
4285
+ typeof genericViewport.setDisplaySetPresentation === 'function' &&
4286
+ typeof genericViewport.setViewReference === 'function');
4287
+ }
4288
+ async function addLabelmapToPlanarGenericViewport(args) {
4289
+ const { blendMode, labelmapLayers, segmentationId, viewport, visibility } = args;
4290
+ const sourceVolumeRenderMode = getPlanarNextVolumeRenderMode(viewport);
4291
+ if (!sourceVolumeRenderMode) {
4292
+ return;
4293
+ }
4294
+ const sourceVolumeId = viewport.getVolumeId();
4295
+ const sourceViewReference = sourceVolumeId
4296
+ ? viewport.getViewReference({ volumeId: sourceVolumeId })
4297
+ : viewport.getViewReference();
4298
+ const requestedOrientation = viewport.getViewState().orientation;
4299
+ const currentImageIdIndex = Math.max(0, viewport.getCurrentImageIdIndex?.() ?? 0);
4300
+ let firstActorEntry;
4301
+ for (const layer of labelmapLayers) {
4302
+ if (!layer.volumeId) {
4303
+ continue;
4304
+ }
4305
+ const volume = esm.cache.getVolume(layer.volumeId);
4306
+ if (!volume) {
4307
+ throw new Error(`imageVolume with id: ${layer.volumeId} does not exist, you need to create/allocate the volume first`);
4308
+ }
4309
+ const representationUID = (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
4310
+ segmentationId,
4311
+ referencedId: layer.labelmapId,
4312
+ });
4313
+ const dataId = representationUID;
4314
+ esm.utilities.genericViewportDataSetMetadataProvider.add(dataId, {
4315
+ kind: 'planar',
4316
+ imageIds: volume.imageIds,
4317
+ initialImageIdIndex: Math.min(currentImageIdIndex, Math.max(volume.imageIds.length - 1, 0)),
4318
+ reference: {
4319
+ kind: 'segmentation',
4320
+ segmentationId,
4321
+ representationUID,
4322
+ labelmapId: layer.labelmapId,
4323
+ },
4324
+ volumeId: layer.volumeId,
4325
+ });
4326
+ await viewport.addDisplaySet(dataId, {
4327
+ orientation: requestedOrientation,
4328
+ role: 'overlay',
4329
+ });
4330
+ viewport.setDisplaySetPresentation(dataId, {
4331
+ blendMode,
4332
+ visible: visibility,
4333
+ });
4334
+ firstActorEntry ||= viewport
4335
+ .getActors?.()
4336
+ .find((actorEntry) => actorEntry.representationUID === representationUID);
4337
+ }
4338
+ viewport.setViewReference(sourceViewReference);
4339
+ viewport.render?.();
4340
+ if (firstActorEntry) {
4341
+ return {
4342
+ uid: firstActorEntry.uid,
4343
+ actor: firstActorEntry.actor,
4344
+ };
4345
+ }
4346
+ }
4347
+ function getPlanarNextVolumeRenderMode(viewport) {
4348
+ const renderMode = viewport.getDefaultActor?.()?.actorMapper?.renderMode;
4349
+ if (renderMode === esm.ActorRenderMode.CPU_VOLUME ||
4350
+ renderMode === esm.ActorRenderMode.VTK_VOLUME_SLICE) {
4351
+ return renderMode;
4352
+ }
4353
+ }
4354
+
4355
+
4356
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/legacyVolumePlan.js
4357
+
4358
+
4359
+
4360
+
4361
+
4362
+
4363
+
4364
+ const { uuidv4 } = esm.utilities;
4365
+ function createLegacyVolumeLabelmapPlan({ config, isVolumeImageMapper, renderMode, segmentation, segmentationId, useSliceRendering, viewport, }) {
4366
+ return createLabelmapRenderPlan({
4367
+ isVolumeImageMapper,
4368
+ kind: 'legacy-volume',
4369
+ renderMode,
4370
+ segmentationId,
4371
+ useSliceRendering,
4372
+ viewport,
4373
+ getExpectedRepresentationUIDs: () => getExpectedVolumeLabelmapRepresentationUIDs(segmentation, segmentationId),
4374
+ mount: ({ labelMapData }) => mountLegacyVolumeLabelmap({
4375
+ config,
4376
+ labelMapData,
4377
+ segmentation,
4378
+ segmentationId,
4379
+ viewport,
4380
+ }),
4381
+ });
4382
+ }
4383
+ function getExpectedVolumeLabelmapRepresentationUIDs(segmentation, segmentationId) {
4384
+ return (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation)
4385
+ .filter(canResolveLayerAsVolume)
4386
+ .map((layer) => (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
4387
+ segmentationId,
4388
+ referencedId: layer.labelmapId,
4389
+ }));
4390
+ }
4391
+ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, segmentationId, viewport, }) {
4392
+ const { id: viewportId } = viewport;
4393
+ const visibility = true;
4394
+ const immediateRender = false;
4395
+ const suppressEvents = true;
4396
+ const volumeCompatibleViewport = viewport;
4397
+ const labelmapLayers = getVolumeBackedLabelmapLayers(segmentation);
4398
+ if (!labelmapLayers.length) {
4399
+ const volumeLabelMapData = labelMapData;
4400
+ const volumeId = ensureVolumeHasVolumeId(volumeLabelMapData, segmentation);
4401
+ if (!esm.cache.getVolume(volumeId)) {
4402
+ await handleMissingVolume(labelMapData);
4403
+ }
4404
+ labelmapLayers.push({
4405
+ labelmapId: volumeId,
4406
+ type: 'volume',
4407
+ volumeId,
4408
+ imageIds: esm.cache.getVolume(volumeId)?.imageIds,
4409
+ });
4410
+ }
4411
+ let blendMode = config?.blendMode ?? esm.Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
4412
+ let useIndependentComponents = blendMode === esm.Enums.BlendModes.LABELMAP_EDGE_PROJECTION_BLEND;
4413
+ if (useIndependentComponents) {
4414
+ const referenceVolumeId = volumeCompatibleViewport.getVolumeId?.();
4415
+ const baseVolume = esm.cache.getVolume(referenceVolumeId);
4416
+ const segVolume = esm.cache.getVolume(labelmapLayers[0]?.volumeId);
4417
+ const segDims = segVolume.dimensions;
4418
+ const refDims = baseVolume.dimensions;
4419
+ if (segDims[0] !== refDims[0] ||
4420
+ segDims[1] !== refDims[1] ||
4421
+ segDims[2] !== refDims[2]) {
4422
+ useIndependentComponents = false;
4423
+ blendMode = esm.Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
4424
+ console.debug('Dimensions mismatch - falling back to regular volume addition');
4425
+ }
4426
+ }
4427
+ const volumeInputs = labelmapLayers.map((layer) => ({
4428
+ volumeId: layer.volumeId,
4429
+ visibility,
4430
+ representationUID: (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
4431
+ segmentationId,
4432
+ referencedId: layer.labelmapId,
4433
+ }),
4434
+ useIndependentComponents,
4435
+ blendMode,
4436
+ }));
4437
+ if (isPlanarNextVolumeViewport(viewport)) {
4438
+ return addLabelmapToPlanarGenericViewport({
4439
+ blendMode,
4440
+ labelmapLayers,
4441
+ segmentationId,
4442
+ viewport,
4443
+ visibility,
4444
+ });
4445
+ }
4446
+ if (!volumeInputs[0].useIndependentComponents) {
4447
+ await (0,esm.addVolumesToViewports)(viewport.getRenderingEngine(), volumeInputs, [viewportId], immediateRender, suppressEvents);
4448
+ (0,triggerSegmentationEvents.triggerSegmentationDataModified)(segmentationId);
4449
+ return;
4450
+ }
4451
+ return addVolumesAsIndependentComponents({
4452
+ viewport: volumeCompatibleViewport,
4453
+ volumeInputs,
4454
+ segmentationId,
4455
+ });
4456
+ }
4457
+ function canResolveLayerAsVolume(layer) {
4458
+ return Boolean(layer.volumeId || layer.geometryVolumeId || layer.imageIds?.length);
4459
+ }
4460
+ function getVolumeBackedLabelmapLayers(segmentation) {
4461
+ return (0,labelmapSegmentationState/* getLabelmaps */.m)(segmentation)
4462
+ .map((layer) => {
4463
+ if (layer.volumeId) {
4464
+ return layer;
4465
+ }
4466
+ const volume = (0,labelmapSegmentationState/* getOrCreateLabelmapVolume */.kL)(layer);
4467
+ if (!volume?.volumeId) {
4468
+ return;
4469
+ }
4470
+ return {
4471
+ ...layer,
4472
+ volumeId: volume.volumeId,
4473
+ };
4474
+ })
4475
+ .filter((layer) => Boolean(layer));
4476
+ }
4477
+ function ensureVolumeHasVolumeId(labelMapData, segmentation) {
4478
+ let { volumeId } = labelMapData;
4479
+ if (!volumeId) {
4480
+ volumeId = uuidv4();
4481
+ segmentation.representationData.Labelmap = {
4482
+ ...segmentation.representationData.Labelmap,
4483
+ volumeId,
4484
+ };
4485
+ labelMapData.volumeId = volumeId;
4486
+ (0,triggerSegmentationEvents.triggerSegmentationModified)(segmentation.segmentationId);
4487
+ }
4488
+ return volumeId;
4489
+ }
4490
+ async function handleMissingVolume(labelMapData) {
4491
+ const stackData = labelMapData;
4492
+ const hasImageIds = stackData.imageIds.length > 0;
4493
+ if (!hasImageIds) {
4494
+ throw new Error('cannot create labelmap, no imageIds found for the volume labelmap');
4495
+ }
4496
+ const volume = await esm.volumeLoader.createAndCacheVolumeFromImages(labelMapData.volumeId ?? uuidv4(), stackData.imageIds);
4497
+ return volume;
4498
+ }
4499
+
4500
+
4501
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getCurrentLabelmapImageIdForViewport.js
4502
+ var getCurrentLabelmapImageIdForViewport = __webpack_require__(97577);
4503
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.js
4504
+ var syncStackLabelmapActors = __webpack_require__(48969);
4505
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/stackImagePlan.js
4506
+
4507
+
4508
+
4509
+
4510
+
4511
+ function createStackImageLabelmapPlan({ isVolumeImageMapper, renderMode, segmentationId, useSliceRendering, viewport, }) {
4512
+ return createLabelmapRenderPlan({
4513
+ isVolumeImageMapper,
4514
+ kind: 'legacy-stack-image',
4515
+ renderMode,
4516
+ segmentationId,
4517
+ updateAfterMount: false,
4518
+ useSliceRendering,
4519
+ viewport,
4520
+ canRenderCurrentViewport: () => hasCurrentStackLabelmapImageIds(viewport, segmentationId),
4521
+ getExpectedRepresentationUIDs: () => getExpectedStackLabelmapRepresentationUIDs(viewport, segmentationId),
4522
+ mount: () => mountStackLabelmapActors(viewport, segmentationId),
4523
+ update: () => (0,syncStackLabelmapActors/* syncStackLabelmapActors */.k)(viewport, segmentationId),
4524
+ });
4525
+ }
4526
+ function hasCurrentStackLabelmapImageIds(viewport, segmentationId) {
4527
+ return !!(0,getCurrentLabelmapImageIdForViewport/* getCurrentLabelmapImageIdsForViewport */.aF)(viewport.id, segmentationId)
4528
+ ?.length;
4529
+ }
4530
+ function getExpectedStackLabelmapRepresentationUIDs(viewport, segmentationId) {
4531
+ return ((0,getCurrentLabelmapImageIdForViewport/* getCurrentLabelmapImageIdsForViewport */.aF)(viewport.id, segmentationId)?.map((imageId) => (0,labelmapRepresentationUID/* createLabelmapRepresentationUID */.Ox)({
4532
+ segmentationId,
4533
+ referencedId: imageId,
4534
+ })) ?? []);
4535
+ }
4536
+ async function mountStackLabelmapActors(viewport, segmentationId) {
4537
+ (0,syncStackLabelmapActors/* syncStackLabelmapActors */.k)(viewport, segmentationId);
4538
+ (0,triggerSegmentationEvents.triggerSegmentationDataModified)(segmentationId);
4539
+ }
4540
+
4541
+
4542
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/volumeSliceImageMapperPlan.js
4543
+
4544
+
4545
+
4546
+ function createVolumeSliceImageMapperPlan({ isVolumeImageMapper, renderMode, segmentation, segmentationId, useSliceRendering, viewport, }) {
4547
+ return createLabelmapRenderPlan({
4548
+ isVolumeImageMapper,
4549
+ kind: 'volume-slice-image-mapper',
4550
+ renderMode,
4551
+ segmentationId,
4552
+ useSliceRendering,
4553
+ viewport,
4554
+ getExpectedRepresentationUIDs: () => getVolumeLabelmapImageMapperRepresentationUIDs(viewport, segmentationId, segmentation),
4555
+ mount: () => mountVolumeLabelmapImageMapper({
4556
+ viewport,
4557
+ segmentation,
4558
+ segmentationId,
4559
+ }),
4560
+ update: ({ actorEntries }) => updateVolumeLabelmapImageMapperActors({
4561
+ viewport,
4562
+ segmentation,
4563
+ segmentationId,
4564
+ actorEntries,
4565
+ }),
4566
+ });
4567
+ }
4568
+ async function mountVolumeLabelmapImageMapper({ viewport, segmentation, segmentationId, }) {
4569
+ await addVolumeLabelmapImageMapperActors({
4570
+ viewport,
4571
+ segmentation,
4572
+ segmentationId,
4573
+ });
4574
+ (0,triggerSegmentationEvents.triggerSegmentationDataModified)(segmentationId);
4575
+ }
4576
+
4577
+
4578
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/resolveLabelmapRenderPlan.js
4579
+
4580
+
4581
+
4582
+
4583
+
4584
+
4585
+ function resolveLabelmapRenderPlan({ viewport, segmentation, representation, }) {
4586
+ const { segmentationId, config } = representation;
4587
+ const useSliceRendering = (0,labelmapImageMapperSupport/* shouldUseSliceRendering */.bY)(segmentation, config);
4588
+ const renderMode = (0,getViewportLabelmapRenderMode/* default */.A)(viewport, {
4589
+ useSliceRendering,
4590
+ });
4591
+ const isVolumeImageMapper = useSliceRendering && (0,labelmapImageMapperSupport/* canRenderVolumeViewportLabelmapAsImage */.QO)(viewport);
4592
+ if (renderMode === 'unsupported') {
4593
+ return createLabelmapRenderPlan({
4594
+ isVolumeImageMapper,
4595
+ kind: 'unsupported',
4596
+ renderMode,
4597
+ segmentationId,
4598
+ unsupportedStateKey: useSliceRendering
4599
+ ? (0,labelmapImageMapperSupport/* getVolumeViewportLabelmapImageMapperState */.o)(viewport).key
4600
+ : undefined,
4601
+ useSliceRendering,
4602
+ viewport,
4603
+ });
4604
+ }
4605
+ if (isVolumeImageMapper) {
4606
+ return createVolumeSliceImageMapperPlan({
4607
+ isVolumeImageMapper,
4608
+ renderMode,
4609
+ segmentation,
4610
+ segmentationId,
4611
+ useSliceRendering,
4612
+ viewport,
4613
+ });
4614
+ }
4615
+ if (renderMode === 'volume') {
4616
+ return createLegacyVolumeLabelmapPlan({
4617
+ config,
4618
+ isVolumeImageMapper,
4619
+ renderMode,
4620
+ segmentation,
4621
+ segmentationId,
4622
+ useSliceRendering,
4623
+ viewport,
4624
+ });
4625
+ }
4626
+ return createStackImageLabelmapPlan({
4627
+ isVolumeImageMapper,
4628
+ renderMode,
4629
+ segmentationId,
4630
+ useSliceRendering,
4631
+ viewport,
4632
+ });
4633
+ }
4634
+
4635
+
4636
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/index.js
4637
+
4638
+
4639
+
4640
+
4641
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan.js
4642
+
4643
+
4644
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/DataModel/PiecewiseFunction.js
4645
+ var PiecewiseFunction = __webpack_require__(30678);
4646
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Rendering/Core/ColorTransferFunction.js + 1 modules
4647
+ var ColorTransferFunction = __webpack_require__(12408);
4648
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/activeSegmentation.js + 1 modules
4649
+ var segmentation_activeSegmentation = __webpack_require__(26228);
4650
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getActiveSegmentIndex.js
4651
+ var getActiveSegmentIndex = __webpack_require__(60740);
4652
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getColorLUT.js
4653
+ var getColorLUT = __webpack_require__(50409);
4654
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/internalGetHiddenSegmentIndices.js
4655
+ var internalGetHiddenSegmentIndices = __webpack_require__(47098);
4656
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/SegmentationStyle.js
4657
+ var SegmentationStyle = __webpack_require__(92686);
4658
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapActorStyle.js
4659
+
4660
+
4661
+
4662
+
4663
+
4664
+
4665
+
4666
+
4667
+
4668
+
4669
+
4670
+
4671
+ const actorTransferFunctions = new WeakMap();
4672
+ const MAX_NUMBER_COLORS = 255;
4673
+ function setLabelmapColorAndOpacity(viewportId, labelmapActorEntry, segmentationRepresentation) {
4674
+ const { segmentationId } = segmentationRepresentation;
4675
+ const { colorLUTIndex } = segmentationRepresentation;
4676
+ const activeSegmentation = (0,segmentation_activeSegmentation.getActiveSegmentation)(viewportId);
4677
+ const isActiveLabelmap = activeSegmentation?.segmentationId === segmentationId;
4678
+ const labelmapStyle = SegmentationStyle/* segmentationStyle */.Y.getStyle({
4679
+ viewportId,
4680
+ type: SegmentationRepresentations/* default */.A.Labelmap,
4681
+ segmentationId,
4682
+ });
4683
+ const renderInactiveSegmentations = SegmentationStyle/* segmentationStyle */.Y.getRenderInactiveSegmentations(viewportId);
4684
+ const colorLUT = (0,getColorLUT/* getColorLUT */.B)(colorLUTIndex);
4685
+ const segmentation = (0,getSegmentation/* getSegmentation */.T)(segmentationId);
4686
+ const layer = getLabelmapForActorReference(segmentation, labelmapActorEntry.referencedId);
4687
+ const layerBindings = Object.keys(segmentation.segments)
4688
+ .map(Number)
4689
+ .map((segmentIndex) => ({
4690
+ segmentIndex,
4691
+ binding: (0,labelmapSegmentationState/* getSegmentBinding */.hM)(segmentation, segmentIndex),
4692
+ }))
4693
+ .filter((entry) => !layer || entry.binding?.labelmapId === layer.labelmapId);
4694
+ const maxLabelValue = Math.max(1, ...layerBindings.map((entry) => entry.binding?.labelValue ?? entry.segmentIndex));
4695
+ const numColors = Math.max(colorLUT.length, maxLabelValue + 1);
4696
+ const labelValueEntries = Array.from({ length: numColors - 1 }, (_, index) => {
4697
+ const labelValue = index + 1;
4698
+ const segmentIndex = layer?.labelToSegmentIndex?.[labelValue] ?? labelValue;
4699
+ return {
4700
+ labelValue,
4701
+ segmentIndex,
4702
+ };
4703
+ });
4704
+ const { outlineWidth, renderOutline, outlineOpacity, activeSegmentOutlineWidthDelta, } = getLabelmapConfig(labelmapStyle, isActiveLabelmap);
4705
+ const segmentsHidden = (0,internalGetHiddenSegmentIndices/* internalGetHiddenSegmentIndices */.s)(viewportId, {
4706
+ segmentationId,
4707
+ type: SegmentationRepresentations/* default */.A.Labelmap,
4708
+ });
4709
+ const labelmapActor = labelmapActorEntry.actor;
4710
+ const { cfun, ofun } = getOrCreateTransferFunctions(labelmapActor);
4711
+ cfun.removeAllPoints();
4712
+ ofun.removeAllPoints();
4713
+ const colorNodes = [
4714
+ { x: 0, r: 0, g: 0, b: 0, midpoint: 0.5, sharpness: 1.0 },
4715
+ ];
4716
+ const opacityNodes = [{ x: 0, y: 0, midpoint: 0.5, sharpness: 1.0 }];
4717
+ labelValueEntries.forEach(({ labelValue, segmentIndex }) => {
4718
+ const segmentColor = colorLUT[segmentIndex];
4719
+ if (!segmentColor) {
4720
+ return;
4721
+ }
4722
+ const perSegmentStyle = SegmentationStyle/* segmentationStyle */.Y.getStyle({
4723
+ viewportId,
4724
+ type: SegmentationRepresentations/* default */.A.Labelmap,
4725
+ segmentationId,
4726
+ segmentIndex,
4727
+ });
4728
+ const { fillAlpha, renderFill } = getLabelmapConfig(labelmapStyle, isActiveLabelmap, perSegmentStyle);
4729
+ colorNodes.push({
4730
+ x: labelValue,
4731
+ r: segmentColor[0] / MAX_NUMBER_COLORS,
4732
+ g: segmentColor[1] / MAX_NUMBER_COLORS,
4733
+ b: segmentColor[2] / MAX_NUMBER_COLORS,
4734
+ midpoint: 0.5,
4735
+ sharpness: 1.0,
4736
+ });
4737
+ if (renderFill) {
4738
+ const segmentOpacity = segmentsHidden.has(segmentIndex)
4739
+ ? 0
4740
+ : (segmentColor[3] / 255) * fillAlpha;
4741
+ opacityNodes.push({
4742
+ x: labelValue,
4743
+ y: segmentOpacity,
4744
+ midpoint: 0.5,
4745
+ sharpness: 1.0,
4746
+ });
4747
+ }
4748
+ else {
4749
+ opacityNodes.push({
4750
+ x: labelValue,
4751
+ y: 0.01,
4752
+ midpoint: 0.5,
4753
+ sharpness: 1.0,
4754
+ });
4755
+ }
4756
+ });
4757
+ cfun.setNodes(colorNodes);
4758
+ ofun.setNodes(opacityNodes);
4759
+ ofun.setClamping(false);
4760
+ const actorMapper = labelmapActorEntry.actorMapper;
4761
+ const labelmapMapper = actorMapper?.mapper
4762
+ ? actorMapper.mapper
4763
+ : labelmapActor.getMapper();
4764
+ const { preLoad } = labelmapActor.get?.('preLoad') || { preLoad: null };
4765
+ if (preLoad) {
4766
+ preLoad({ cfun, ofun, actor: labelmapActor });
4767
+ }
4768
+ else {
4769
+ labelmapActor.getProperty().setRGBTransferFunction(0, cfun);
4770
+ labelmapActor.getProperty().setScalarOpacity(0, ofun);
4771
+ labelmapActor.getProperty().setInterpolationTypeToNearest();
4772
+ }
4773
+ if (labelmapActorEntry.actorMapper?.renderMode === esm.ActorRenderMode.VTK_IMAGE ||
4774
+ labelmapActorEntry.actorMapper?.renderMode ===
4775
+ esm.ActorRenderMode.VTK_VOLUME_SLICE) {
4776
+ const imageSlice = labelmapActor;
4777
+ imageSlice.setForceTranslucent(true);
4778
+ imageSlice.setForceOpaque(false);
4779
+ imageSlice.getProperty().setUseLookupTableScalarRange(true);
4780
+ }
4781
+ if (renderOutline) {
4782
+ labelmapActor.getProperty().setUseLabelOutline(renderOutline);
4783
+ labelmapActor.getProperty().setLabelOutlineOpacity(outlineOpacity);
4784
+ const activeSegmentIndex = (0,getActiveSegmentIndex/* getActiveSegmentIndex */.Q)(segmentationRepresentation.segmentationId);
4785
+ const outlineWidths = new Array(numColors - 1).fill(0);
4786
+ labelValueEntries.forEach(({ labelValue, segmentIndex }) => {
4787
+ const isHidden = segmentsHidden.has(segmentIndex);
4788
+ if (isHidden) {
4789
+ return;
4790
+ }
4791
+ outlineWidths[labelValue - 1] =
4792
+ segmentIndex === activeSegmentIndex
4793
+ ? outlineWidth + activeSegmentOutlineWidthDelta
4794
+ : outlineWidth;
4795
+ });
4796
+ labelmapActor.getProperty().setLabelOutlineThickness(outlineWidths);
4797
+ labelmapActor.modified();
4798
+ labelmapActor.getProperty().modified();
4799
+ labelmapMapper?.modified?.();
4800
+ }
4801
+ else {
4802
+ labelmapActor
4803
+ .getProperty()
4804
+ .setLabelOutlineThickness(new Array(numColors - 1).fill(0));
4805
+ }
4806
+ const visible = isActiveLabelmap || renderInactiveSegmentations;
4807
+ labelmapActor.setVisibility(visible);
4808
+ labelmapActor.modified();
4809
+ labelmapActor.getProperty().modified();
4810
+ labelmapMapper?.modified?.();
4811
+ }
4812
+ function getOrCreateTransferFunctions(actor) {
4813
+ const existing = actorTransferFunctions.get(actor);
4814
+ if (existing) {
4815
+ return existing;
4816
+ }
4817
+ const cfun = ColorTransferFunction/* default.newInstance */.Ay.newInstance();
4818
+ const ofun = PiecewiseFunction/* default.newInstance */.Ay.newInstance();
4819
+ ofun.addPoint(0, 0);
4820
+ const created = { cfun, ofun };
4821
+ actorTransferFunctions.set(actor, created);
4822
+ return created;
4823
+ }
4824
+ function getLabelmapConfig(labelmapConfig, isActiveLabelmap, segmentsLabelmapConfig) {
4825
+ const segmentLabelmapConfig = segmentsLabelmapConfig || {};
4826
+ const configToUse = {
4827
+ ...labelmapConfig,
4828
+ ...segmentLabelmapConfig,
4829
+ };
4830
+ return {
4831
+ fillAlpha: isActiveLabelmap
4832
+ ? configToUse.fillAlpha
4833
+ : configToUse.fillAlphaInactive,
4834
+ outlineWidth: isActiveLabelmap
4835
+ ? configToUse.outlineWidth
4836
+ : configToUse.outlineWidthInactive,
4837
+ renderFill: isActiveLabelmap
4838
+ ? configToUse.renderFill
4839
+ : configToUse.renderFillInactive,
4840
+ renderOutline: isActiveLabelmap
4841
+ ? configToUse.renderOutline
4842
+ : configToUse.renderOutlineInactive,
4843
+ outlineOpacity: isActiveLabelmap
4844
+ ? configToUse.outlineOpacity
4845
+ : configToUse.outlineOpacityInactive,
4846
+ activeSegmentOutlineWidthDelta: configToUse.activeSegmentOutlineWidthDelta,
4847
+ };
4848
+ }
4849
+
4850
+
4851
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js
4852
+
4853
+
4854
+
4855
+
4856
+
4857
+
4858
+
4859
+
4860
+
4861
+
4862
+
4863
+ const unsupportedImageMapperStates = new Map();
4864
+ let polySegConversionInProgress = false;
4865
+ function removeRepresentation(viewportId, segmentationId, renderImmediate = false) {
4866
+ clearUnsupportedImageMapperError(viewportId, segmentationId);
4867
+ const enabledElement = (0,esm.getEnabledElementByViewportId)(viewportId);
4868
+ if (!enabledElement) {
4869
+ return;
4870
+ }
4871
+ const { viewport } = enabledElement;
4872
+ removeLabelmapRepresentationFromViewport(viewport, segmentationId);
4873
+ if (!renderImmediate) {
4874
+ return;
4875
+ }
4876
+ viewport.render();
4877
+ }
4878
+ async function render(viewport, representation) {
4879
+ const { segmentationId } = representation;
4880
+ const segmentation = (0,getSegmentation/* getSegmentation */.T)(segmentationId);
4881
+ if (!segmentation) {
4882
+ console.warn('No segmentation found for segmentationId: ', segmentationId);
4883
+ return;
4884
+ }
4885
+ let labelmapData = segmentation.representationData[SegmentationRepresentations/* default */.A.Labelmap];
4886
+ let labelmapActorEntries = (0,getSegmentationActor/* getLabelmapActorEntries */.ED)(viewport.id, segmentationId);
4887
+ if (!labelmapData &&
4888
+ (0,config/* getPolySeg */.Qy)()?.canComputeRequestedRepresentation(segmentationId, SegmentationRepresentations/* default */.A.Labelmap) &&
4889
+ !polySegConversionInProgress) {
4890
+ polySegConversionInProgress = true;
4891
+ const polySeg = (0,config/* getPolySeg */.Qy)();
4892
+ labelmapData = await (0,computeAndAddRepresentation/* computeAndAddRepresentation */.d)(segmentationId, SegmentationRepresentations/* default */.A.Labelmap, () => polySeg.computeLabelmapData(segmentationId, {
4893
+ viewport: viewport,
4894
+ }), () => {
4895
+ SegmentationStateManager/* defaultSegmentationStateManager */._6.processLabelmapRepresentationAddition(viewport.id, segmentationId);
4896
+ setTimeout(() => {
4897
+ (0,triggerSegmentationEvents.triggerSegmentationDataModified)(segmentationId);
4898
+ }, 0);
4899
+ });
4900
+ if (!labelmapData) {
4901
+ throw new Error(`No labelmap data found for segmentationId ${segmentationId}.`);
4902
+ }
4903
+ polySegConversionInProgress = false;
2363
4904
  }
2364
- _createFakeVolume(imageIds) {
2365
- const volumeId = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.generateVolumeId(imageIds);
2366
- const cachedVolume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(volumeId);
2367
- if (cachedVolume) {
2368
- return cachedVolume;
4905
+ else if (!labelmapData && !(0,config/* getPolySeg */.Qy)()) {
4906
+ console.debug(`No labelmap data found for segmentationId ${segmentationId} and PolySeg add-on is not configured. Unable to convert from other representations to labelmap. Please register PolySeg using cornerstoneTools.init({ addons: { polySeg } }) to enable automatic conversion.`);
4907
+ }
4908
+ if (!labelmapData) {
4909
+ return;
4910
+ }
4911
+ const renderPlan = resolveLabelmapRenderPlan({
4912
+ viewport,
4913
+ segmentation,
4914
+ representation,
4915
+ });
4916
+ if (renderPlan.kind === 'unsupported') {
4917
+ if (labelmapActorEntries?.length) {
4918
+ renderPlan.remove();
2369
4919
  }
2370
- const volumeProps = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.generateVolumePropsFromImageIds(imageIds, volumeId);
2371
- const spacing = volumeProps.spacing;
2372
- if (spacing[2] === 0) {
2373
- spacing[2] = 1;
4920
+ if (renderPlan.unsupportedStateKey) {
4921
+ reportUnsupportedImageMapperError(viewport.id, segmentationId, renderPlan.unsupportedStateKey);
2374
4922
  }
2375
- const derivedVolume = new _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.ImageVolume({
2376
- volumeId,
2377
- dataType: volumeProps.dataType,
2378
- metadata: structuredClone(volumeProps.metadata),
2379
- dimensions: volumeProps.dimensions,
2380
- spacing: volumeProps.spacing,
2381
- origin: volumeProps.origin,
2382
- direction: volumeProps.direction,
2383
- referencedVolumeId: volumeProps.referencedVolumeId,
2384
- imageIds: volumeProps.imageIds,
2385
- referencedImageIds: volumeProps.referencedImageIds,
2386
- });
2387
- _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.putVolumeSync(volumeId, derivedVolume);
2388
- return derivedVolume;
4923
+ return;
2389
4924
  }
2390
- _isOrthogonalView(viewport, referencedVolumeId) {
2391
- const volume = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(referencedVolumeId);
2392
- const volumeImageData = volume.imageData;
2393
- const camera = viewport.getCamera();
2394
- const { ijkVecColDir, ijkVecSliceDir } = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.getVolumeDirectionVectors(volumeImageData, camera);
2395
- return [ijkVecColDir, ijkVecSliceDir].every((vec) => _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[0]), 1) ||
2396
- _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[1]), 1) ||
2397
- _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.isEqual(Math.abs(vec[2]), 1));
4925
+ clearUnsupportedImageMapperError(viewport.id, segmentationId);
4926
+ labelmapActorEntries = await renderPlan.reconcile({
4927
+ actorEntries: labelmapActorEntries,
4928
+ labelMapData: labelmapData,
4929
+ });
4930
+ if (!labelmapActorEntries?.length) {
4931
+ return;
2398
4932
  }
2399
- getRemoveIslandData(_growCutData) {
4933
+ for (const labelmapActorEntry of labelmapActorEntries) {
4934
+ setLabelmapColorAndOpacity(viewport.id, labelmapActorEntry, representation);
4935
+ }
4936
+ }
4937
+ function getUpdateFunction(_viewport) {
4938
+ return;
4939
+ }
4940
+ function getUnsupportedImageMapperStateKey(viewportId, segmentationId) {
4941
+ return `${viewportId}:${segmentationId}`;
4942
+ }
4943
+ function clearUnsupportedImageMapperError(viewportId, segmentationId) {
4944
+ unsupportedImageMapperStates.delete(getUnsupportedImageMapperStateKey(viewportId, segmentationId));
4945
+ }
4946
+ function reportUnsupportedImageMapperError(viewportId, segmentationId, stateKey) {
4947
+ const cacheKey = getUnsupportedImageMapperStateKey(viewportId, segmentationId);
4948
+ const previousStateKey = unsupportedImageMapperStates.get(cacheKey);
4949
+ if (previousStateKey === stateKey) {
2400
4950
  return;
2401
4951
  }
2402
- _removeIslands(growCutData) {
2403
- const { islandRemoval: config } = this.configuration;
2404
- if (!config.enabled) {
4952
+ unsupportedImageMapperStates.set(cacheKey, stateKey);
4953
+ esm.eventTarget.dispatchEvent(new CustomEvent(esm.Enums.Events.ERROR_EVENT, {
4954
+ detail: {
4955
+ type: 'Segmentation',
4956
+ message: 'Labelmap image-mapper rendering is only supported on legacy orthographic single-slice volume viewports.',
4957
+ },
4958
+ cancelable: true,
4959
+ }));
4960
+ }
4961
+ /* harmony default export */ const labelmapDisplay = ({
4962
+ getUpdateFunction,
4963
+ render,
4964
+ removeRepresentation,
4965
+ });
4966
+
4967
+
4968
+
4969
+ /***/ },
4970
+
4971
+ /***/ 5959
4972
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
4973
+
4974
+ "use strict";
4975
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4976
+ /* harmony export */ Ox: () => (/* binding */ createLabelmapRepresentationUID),
4977
+ /* harmony export */ qV: () => (/* binding */ isLabelmapRepresentationUID)
4978
+ /* harmony export */ });
4979
+ /* unused harmony export getLabelmapRepresentationPrefix */
4980
+ /* harmony import */ var _enums__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(29857);
4981
+
4982
+ function getLabelmapRepresentationPrefix(segmentationId) {
4983
+ return `${segmentationId}-${_enums__WEBPACK_IMPORTED_MODULE_0__.SegmentationRepresentations.Labelmap}`;
4984
+ }
4985
+ function createLabelmapRepresentationUID({ segmentationId, referencedId, sliceStateKey, }) {
4986
+ return [
4987
+ getLabelmapRepresentationPrefix(segmentationId),
4988
+ referencedId,
4989
+ sliceStateKey,
4990
+ ]
4991
+ .filter(Boolean)
4992
+ .join('-');
4993
+ }
4994
+ function isLabelmapRepresentationUID(representationUID, segmentationId) {
4995
+ return (typeof representationUID === 'string' &&
4996
+ representationUID.startsWith(getLabelmapRepresentationPrefix(segmentationId)));
4997
+ }
4998
+
4999
+
5000
+
5001
+ /***/ },
5002
+
5003
+ /***/ 24393
5004
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5005
+
5006
+ "use strict";
5007
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5008
+ /* harmony export */ A: () => (__WEBPACK_DEFAULT_EXPORT__)
5009
+ /* harmony export */ });
5010
+ /* harmony import */ var _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15327);
5011
+ /* harmony import */ var _labelmapRepresentationUID__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5959);
5012
+
5013
+
5014
+ function removeLabelmapRepresentationData(viewport, segmentationId, actorEntry) {
5015
+ const representationUID = actorEntry.representationUID;
5016
+ if (!(0,_labelmapRepresentationUID__WEBPACK_IMPORTED_MODULE_1__/* .isLabelmapRepresentationUID */ .qV)(representationUID, segmentationId)) {
5017
+ return false;
5018
+ }
5019
+ const dataViewport = viewport;
5020
+ if (typeof dataViewport.removeData !== 'function') {
5021
+ return false;
5022
+ }
5023
+ _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.utilities.genericViewportDataSetMetadataProvider.remove(representationUID);
5024
+ dataViewport.removeData(representationUID);
5025
+ return true;
5026
+ }
5027
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (removeLabelmapRepresentationData);
5028
+
5029
+
5030
+ /***/ },
5031
+
5032
+ /***/ 94895
5033
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5034
+
5035
+ "use strict";
5036
+
5037
+ // EXPORTS
5038
+ __webpack_require__.d(__webpack_exports__, {
5039
+ Ay: () => (/* binding */ surfaceDisplay)
5040
+ });
5041
+
5042
+ // UNUSED EXPORTS: getUpdateFunction, removeRepresentation, render
5043
+
5044
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/core/dist/esm/index.js + 1 modules
5045
+ var esm = __webpack_require__(15327);
5046
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/enums/SegmentationRepresentations.js
5047
+ var SegmentationRepresentations = __webpack_require__(18682);
5048
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Surface/removeSurfaceFromElement.js
5049
+
5050
+ function removeSurfaceFromElement(element, segmentationId) {
5051
+ const enabledElement = (0,esm.getEnabledElement)(element);
5052
+ const { viewport } = enabledElement;
5053
+ const actorEntries = viewport.getActors();
5054
+ const filteredSurfaceActors = actorEntries.filter((actor) => actor.representationUID &&
5055
+ typeof actor.representationUID === 'string' &&
5056
+ actor.representationUID.startsWith(segmentationId));
5057
+ viewport.removeActors(filteredSurfaceActors.map((actor) => actor.uid));
5058
+ }
5059
+ /* harmony default export */ const Surface_removeSurfaceFromElement = (removeSurfaceFromElement);
5060
+
5061
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Rendering/Core/Mapper.js + 1 modules
5062
+ var Mapper = __webpack_require__(81418);
5063
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Rendering/Core/Actor.js
5064
+ var Actor = __webpack_require__(44404);
5065
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/DataModel/PolyData.js + 7 modules
5066
+ var PolyData = __webpack_require__(27480);
5067
+ // EXTERNAL MODULE: ../../../node_modules/@kitware/vtk.js/Common/Core/CellArray.js
5068
+ var CellArray = __webpack_require__(32461);
5069
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.js
5070
+ var getSegmentationActor = __webpack_require__(59452);
5071
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js
5072
+
5073
+
5074
+
5075
+
5076
+
5077
+
5078
+ function addOrUpdateSurfaceToElement(viewport, surface, segmentationId) {
5079
+ const surfaceActorEntry = (0,getSegmentationActor/* getSurfaceActorEntry */.Th)(viewport.id, segmentationId, surface.segmentIndex);
5080
+ const surfaceActor = surfaceActorEntry?.actor;
5081
+ const isVisible = surface.visible;
5082
+ if (surfaceActor) {
5083
+ surfaceActor.setVisibility(isVisible);
5084
+ if (!isVisible) {
2405
5085
  return;
2406
5086
  }
2407
- const { segmentation: { segmentIndex, labelmapVolumeId }, renderingEngineId, viewportId, } = growCutData;
2408
- const labelmap = _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.cache.getVolume(labelmapVolumeId);
2409
- const removeIslandData = this.getRemoveIslandData(growCutData);
2410
- if (!removeIslandData) {
5087
+ const surfaceMapper = surfaceActor.getMapper();
5088
+ const currentPolyData = surfaceMapper.getInputData();
5089
+ const newPoints = surface.points;
5090
+ const newPolys = surface.polys;
5091
+ const currentPoints = currentPolyData.getPoints().getData();
5092
+ const currentPolys = currentPolyData.getPolys().getData();
5093
+ if (newPoints.length === currentPoints.length &&
5094
+ newPolys.length === currentPolys.length) {
2411
5095
  return;
2412
5096
  }
2413
- const [width, height] = labelmap.dimensions;
2414
- const numPixelsPerSlice = width * height;
2415
- const { worldIslandPoints = [], islandPointIndexes = [] } = removeIslandData;
2416
- let ijkIslandPoints = [...(removeIslandData?.ijkIslandPoints ?? [])];
2417
- const renderingEngine = (0,_cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__.getRenderingEngine)(renderingEngineId);
2418
- const viewport = renderingEngine.getViewport(viewportId);
2419
- const { voxelManager } = labelmap;
2420
- const islandRemoval = new _utilities_segmentation_islandRemoval__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .A();
2421
- ijkIslandPoints = ijkIslandPoints.concat(worldIslandPoints.map((worldPoint) => transformWorldToIndex(labelmap.imageData, worldPoint)));
2422
- ijkIslandPoints = ijkIslandPoints.concat(islandPointIndexes.map((pointIndex) => {
2423
- const x = pointIndex % width;
2424
- const y = Math.floor(pointIndex / width) % height;
2425
- const z = Math.floor(pointIndex / numPixelsPerSlice);
2426
- return [x, y, z];
2427
- }));
2428
- islandRemoval.initialize(viewport, voxelManager, {
2429
- points: ijkIslandPoints,
2430
- previewSegmentIndex: segmentIndex,
2431
- segmentIndex,
5097
+ const polyData = PolyData/* default.newInstance */.Ay.newInstance();
5098
+ polyData.getPoints().setData(newPoints, 3);
5099
+ const triangles = CellArray/* default.newInstance */.Ay.newInstance({
5100
+ values: Float32Array.from(newPolys),
2432
5101
  });
2433
- islandRemoval.floodFillSegmentIsland();
2434
- islandRemoval.removeExternalIslands();
2435
- islandRemoval.removeInternalIslands();
5102
+ polyData.setPolys(triangles);
5103
+ surfaceMapper.setInputData(polyData);
5104
+ surfaceMapper.modified();
5105
+ viewport.getRenderer().resetCameraClippingRange();
5106
+ return;
2436
5107
  }
2437
- getSegmentStyle({ segmentationId, viewportId, segmentIndex }) {
2438
- return (0,_utilities_segmentation_getSVGStyleForSegment__WEBPACK_IMPORTED_MODULE_6__/* .getSVGStyleForSegment */ .u)({
5108
+ const points = surface.points;
5109
+ const polys = surface.polys;
5110
+ const color = surface.color;
5111
+ const surfacePolyData = PolyData/* default.newInstance */.Ay.newInstance();
5112
+ surfacePolyData.getPoints().setData(points, 3);
5113
+ const triangles = CellArray/* default.newInstance */.Ay.newInstance({
5114
+ values: Float32Array.from(polys),
5115
+ });
5116
+ surfacePolyData.setPolys(triangles);
5117
+ const mapper = Mapper/* default.newInstance */.Ay.newInstance({});
5118
+ let clippingFilter;
5119
+ mapper.setInputData(surfacePolyData);
5120
+ const actor = Actor/* default.newInstance */.Ay.newInstance();
5121
+ actor.setMapper(mapper);
5122
+ actor.getProperty().setColor(color[0] / 255, color[1] / 255, color[2] / 255);
5123
+ actor.getProperty().setLineWidth(2);
5124
+ const representationUID = (0,getSegmentationActor/* getSurfaceRepresentationUID */.DU)(segmentationId, surface.segmentIndex);
5125
+ viewport.addActor({
5126
+ uid: esm.utilities.uuidv4(),
5127
+ actor: actor,
5128
+ clippingFilter,
5129
+ representationUID,
5130
+ });
5131
+ viewport.resetCamera();
5132
+ viewport.getRenderer().resetCameraClippingRange();
5133
+ viewport.render();
5134
+ }
5135
+ /* harmony default export */ const Surface_addOrUpdateSurfaceToElement = (addOrUpdateSurfaceToElement);
5136
+
5137
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getSegmentation.js
5138
+ var getSegmentation = __webpack_require__(33283);
5139
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/getColorLUT.js
5140
+ var getColorLUT = __webpack_require__(50409);
5141
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/config.js
5142
+ var config = __webpack_require__(36625);
5143
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/utilities/segmentation/computeAndAddRepresentation.js
5144
+ var computeAndAddRepresentation = __webpack_require__(27479);
5145
+ // EXTERNAL MODULE: ../../../node_modules/@cornerstonejs/tools/dist/esm/stateManagement/segmentation/helpers/internalGetHiddenSegmentIndices.js
5146
+ var internalGetHiddenSegmentIndices = __webpack_require__(47098);
5147
+ ;// ../../../node_modules/@cornerstonejs/tools/dist/esm/tools/displayTools/Surface/surfaceDisplay.js
5148
+
5149
+
5150
+
5151
+
5152
+
5153
+
5154
+
5155
+
5156
+
5157
+ function removeRepresentation(viewportId, segmentationId, renderImmediate = false) {
5158
+ const enabledElement = (0,esm.getEnabledElementByViewportId)(viewportId);
5159
+ if (!enabledElement) {
5160
+ return;
5161
+ }
5162
+ const { viewport } = enabledElement;
5163
+ Surface_removeSurfaceFromElement(viewport.element, segmentationId);
5164
+ if (!renderImmediate) {
5165
+ return;
5166
+ }
5167
+ viewport.render();
5168
+ }
5169
+ async function render(viewport, representation) {
5170
+ const { segmentationId, type } = representation;
5171
+ const segmentation = (0,getSegmentation/* getSegmentation */.T)(segmentationId);
5172
+ if (!segmentation) {
5173
+ return;
5174
+ }
5175
+ let SurfaceData = segmentation.representationData[SegmentationRepresentations/* default */.A.Surface];
5176
+ if (!SurfaceData &&
5177
+ (0,config/* getPolySeg */.Qy)()?.canComputeRequestedRepresentation(segmentationId, SegmentationRepresentations/* default */.A.Surface)) {
5178
+ const polySeg = (0,config/* getPolySeg */.Qy)();
5179
+ SurfaceData = await (0,computeAndAddRepresentation/* computeAndAddRepresentation */.d)(segmentationId, SegmentationRepresentations/* default */.A.Surface, () => polySeg.computeSurfaceData(segmentationId, { viewport }));
5180
+ if (!SurfaceData) {
5181
+ throw new Error(`No Surface data found for segmentationId ${segmentationId} even we tried to compute it`);
5182
+ }
5183
+ }
5184
+ else if (!SurfaceData && !(0,config/* getPolySeg */.Qy)()) {
5185
+ console.debug(`No surface data found for segmentationId ${segmentationId} and PolySeg add-on is not configured. Unable to convert from other representations to surface. Please register PolySeg using cornerstoneTools.init({ addons: { polySeg } }) to enable automatic conversion.`);
5186
+ }
5187
+ if (!SurfaceData) {
5188
+ console.warn(`No Surface data found for segmentationId ${segmentationId}. Skipping render.`);
5189
+ return;
5190
+ }
5191
+ const { geometryIds } = SurfaceData;
5192
+ if (!geometryIds?.size) {
5193
+ console.warn(`No Surfaces found for segmentationId ${segmentationId}. Skipping render.`);
5194
+ }
5195
+ const { colorLUTIndex } = representation;
5196
+ const colorLUT = (0,getColorLUT/* getColorLUT */.B)(colorLUTIndex);
5197
+ const surfaces = [];
5198
+ geometryIds.forEach((geometryId) => {
5199
+ const geometry = esm.cache.getGeometry(geometryId);
5200
+ if (!geometry?.data) {
5201
+ console.warn(`No Surfaces found for geometryId ${geometryId}. Skipping render.`);
5202
+ return;
5203
+ }
5204
+ const { segmentIndex } = geometry.data;
5205
+ const hiddenSegments = (0,internalGetHiddenSegmentIndices/* internalGetHiddenSegmentIndices */.s)(viewport.id, {
2439
5206
  segmentationId,
2440
- segmentIndex,
2441
- viewportId,
5207
+ type,
2442
5208
  });
2443
- }
5209
+ const isHidden = hiddenSegments.has(segmentIndex);
5210
+ const surface = geometry.data;
5211
+ const color = colorLUT[segmentIndex];
5212
+ surface.color = color.slice(0, 3);
5213
+ surface.visible = !isHidden;
5214
+ surfaces.push(surface);
5215
+ Surface_addOrUpdateSurfaceToElement(viewport, surface, segmentationId);
5216
+ });
5217
+ viewport.render();
2444
5218
  }
2445
- GrowCutBaseTool.toolName = 'GrowCutBaseTool';
2446
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (GrowCutBaseTool);
5219
+ function getUpdateFunction(viewport) {
5220
+ const polySeg = (0,config/* getPolySeg */.Qy)();
5221
+ return (segmentationId) => polySeg.updateSurfaceData(segmentationId, { viewport });
5222
+ }
5223
+ /* harmony default export */ const surfaceDisplay = ({
5224
+ getUpdateFunction,
5225
+ render,
5226
+ removeRepresentation,
5227
+ });
5228
+
2447
5229
 
2448
5230
 
2449
5231
  /***/ },
@@ -2502,6 +5284,84 @@ function eraseOutsideRectangle(enabledElement, operationData) {
2502
5284
  }
2503
5285
 
2504
5286
 
5287
+ /***/ },
5288
+
5289
+ /***/ 88557
5290
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5291
+
5292
+ "use strict";
5293
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5294
+ /* harmony export */ A: () => (__WEBPACK_DEFAULT_EXPORT__),
5295
+ /* harmony export */ c: () => (/* binding */ getCenterAndRadiusInCanvas)
5296
+ /* harmony export */ });
5297
+ /* harmony import */ var _cornerstonejs_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15327);
5298
+ /* harmony import */ var gl_matrix__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3823);
5299
+
5300
+
5301
+ const EPSILON = 1e-4;
5302
+ function getCenterAndRadiusInCanvas(points, viewport) {
5303
+ const canvasPoints = points.map((p) => viewport.worldToCanvas(p));
5304
+ const [cBottom, cTop, cLeft, cRight] = canvasPoints;
5305
+ const center = [
5306
+ (cBottom[0] + cTop[0]) / 2,
5307
+ (cBottom[1] + cTop[1]) / 2,
5308
+ ];
5309
+ const worldHeight = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.distance */ .eR.distance(points[0], points[1]);
5310
+ const worldWidth = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec3.distance */ .eR.distance(points[2], points[3]);
5311
+ const canvasHeight = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec2.distance */ .Zc.distance(cBottom, cTop);
5312
+ const canvasWidth = gl_matrix__WEBPACK_IMPORTED_MODULE_1__/* .vec2.distance */ .Zc.distance(cLeft, cRight);
5313
+ const scaleX = canvasWidth / worldWidth;
5314
+ const scaleY = canvasHeight / worldHeight;
5315
+ const worldRadius = worldHeight / 2;
5316
+ const radius = Math.abs(scaleX - scaleY) > EPSILON
5317
+ ? worldRadius * Math.min(scaleX, scaleY)
5318
+ : canvasHeight / 2;
5319
+ return {
5320
+ center: center,
5321
+ radius: Math.round(radius),
5322
+ };
5323
+ }
5324
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (getCenterAndRadiusInCanvas);
5325
+
5326
+
5327
+ /***/ },
5328
+
5329
+ /***/ 77671
5330
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5331
+
5332
+ "use strict";
5333
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5334
+ /* harmony export */ A: () => (/* binding */ getEllipseWorldCoordinates)
5335
+ /* harmony export */ });
5336
+ /* harmony import */ var gl_matrix__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3823);
5337
+
5338
+ function getEllipseWorldCoordinates(points, viewport) {
5339
+ const camera = viewport.getCamera();
5340
+ const { viewUp, viewPlaneNormal } = camera;
5341
+ const viewRight = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.create */ .eR.create();
5342
+ gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.cross */ .eR.cross(viewRight, viewUp, viewPlaneNormal);
5343
+ const [centerWorld, endWorld] = points;
5344
+ const centerToEndDistance = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.distance */ .eR.distance(centerWorld, endWorld);
5345
+ const bottomWorld = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.create */ .eR.create();
5346
+ const topWorld = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.create */ .eR.create();
5347
+ const leftWorld = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.create */ .eR.create();
5348
+ const rightWorld = gl_matrix__WEBPACK_IMPORTED_MODULE_0__/* .vec3.create */ .eR.create();
5349
+ for (let i = 0; i <= 2; i++) {
5350
+ bottomWorld[i] = centerWorld[i] - viewUp[i] * centerToEndDistance;
5351
+ topWorld[i] = centerWorld[i] + viewUp[i] * centerToEndDistance;
5352
+ leftWorld[i] = centerWorld[i] - viewRight[i] * centerToEndDistance;
5353
+ rightWorld[i] = centerWorld[i] + viewRight[i] * centerToEndDistance;
5354
+ }
5355
+ const ellipseWorldCoordinates = [
5356
+ bottomWorld,
5357
+ topWorld,
5358
+ leftWorld,
5359
+ rightWorld,
5360
+ ];
5361
+ return ellipseWorldCoordinates;
5362
+ }
5363
+
5364
+
2505
5365
  /***/ },
2506
5366
 
2507
5367
  /***/ 39848
@@ -3576,6 +6436,30 @@ function smoothAnnotation(annotation, options) {
3576
6436
  }
3577
6437
 
3578
6438
 
6439
+ /***/ },
6440
+
6441
+ /***/ 27479
6442
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6443
+
6444
+ "use strict";
6445
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6446
+ /* harmony export */ d: () => (/* binding */ computeAndAddRepresentation)
6447
+ /* harmony export */ });
6448
+ /* harmony import */ var _stateManagement_segmentation_internalAddRepresentationData__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(44188);
6449
+
6450
+ async function computeAndAddRepresentation(segmentationId, type, computeFunction, onComputationComplete) {
6451
+ const data = await computeFunction();
6452
+ (0,_stateManagement_segmentation_internalAddRepresentationData__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)({
6453
+ segmentationId,
6454
+ type,
6455
+ data,
6456
+ });
6457
+ onComputationComplete?.();
6458
+ return data;
6459
+ }
6460
+
6461
+
6462
+
3579
6463
  /***/ },
3580
6464
 
3581
6465
  /***/ 10564
@@ -4622,8 +7506,7 @@ const DEFAULT_VALUES = {
4622
7506
 
4623
7507
  // ----------------------------------------------------------------------------
4624
7508
 
4625
- function extend(publicAPI, model) {
4626
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7509
+ function extend(publicAPI, model, initialValues = {}) {
4627
7510
  Object.assign(model, DEFAULT_VALUES, initialValues);
4628
7511
 
4629
7512
  // Build VTK API
@@ -4956,8 +7839,7 @@ const Picker_DEFAULT_VALUES = {
4956
7839
  };
4957
7840
 
4958
7841
  // ----------------------------------------------------------------------------
4959
- function Picker_extend(publicAPI, model) {
4960
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7842
+ function Picker_extend(publicAPI, model, initialValues = {}) {
4961
7843
  Object.assign(model, Picker_DEFAULT_VALUES, initialValues);
4962
7844
 
4963
7845
  // Inheritance
@@ -5097,11 +7979,8 @@ function vtkBox(publicAPI, model) {
5097
7979
  model.classHierarchy.push('vtkBox');
5098
7980
 
5099
7981
  // TODO: replace with macro.setArray ?
5100
- publicAPI.setBounds = function () {
7982
+ publicAPI.setBounds = (...bounds) => {
5101
7983
  let boundsArray = [];
5102
- for (var _len = arguments.length, bounds = new Array(_len), _key = 0; _key < _len; _key++) {
5103
- bounds[_key] = arguments[_key];
5104
- }
5105
7984
  if (Array.isArray(bounds[0])) {
5106
7985
  boundsArray = bounds[0];
5107
7986
  } else {
@@ -5115,7 +7994,7 @@ function vtkBox(publicAPI, model) {
5115
7994
  }
5116
7995
  BoundingBox/* default.setBounds */.Ay.setBounds(model.bbox, boundsArray);
5117
7996
  };
5118
- publicAPI.getBounds = () => model.bbox;
7997
+ publicAPI.getBounds = () => [...model.bbox];
5119
7998
  publicAPI.evaluateFunction = (x, y, z) => {
5120
7999
  const point = Array.isArray(x) ? x : [x, y, z];
5121
8000
  let diff;
@@ -5164,13 +8043,13 @@ function vtkBox(publicAPI, model) {
5164
8043
  }
5165
8044
  return distance;
5166
8045
  };
5167
- publicAPI.addBounds = function () {
8046
+ publicAPI.addBounds = (...bounds) => {
5168
8047
  let boundsArray = [];
5169
- if (Array.isArray(arguments.length <= 0 ? undefined : arguments[0])) {
5170
- boundsArray = arguments.length <= 0 ? undefined : arguments[0];
8048
+ if (Array.isArray(bounds[0])) {
8049
+ boundsArray = bounds[0];
5171
8050
  } else {
5172
- for (let i = 0; i < arguments.length; i++) {
5173
- boundsArray.push(i < 0 || arguments.length <= i ? undefined : arguments[i]);
8051
+ for (let i = 0; i < bounds.length; i++) {
8052
+ boundsArray.push(bounds[i]);
5174
8053
  }
5175
8054
  }
5176
8055
  if (boundsArray.length !== 6) {
@@ -5193,8 +8072,7 @@ const Box_DEFAULT_VALUES = {
5193
8072
 
5194
8073
  // ----------------------------------------------------------------------------
5195
8074
 
5196
- function Box_extend(publicAPI, model) {
5197
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
8075
+ function Box_extend(publicAPI, model, initialValues = {}) {
5198
8076
  Object.assign(model, Box_DEFAULT_VALUES, initialValues);
5199
8077
 
5200
8078
  // Object methods
@@ -5603,7 +8481,6 @@ function vtkCellPicker(publicAPI, model) {
5603
8481
  }
5604
8482
  /* eslint-enable no-continue */
5605
8483
  }
5606
-
5607
8484
  if (minCellId >= 0 && tMin < model.globalTMin) {
5608
8485
  resetPickInfo();
5609
8486
  const nbPointsInCell = minCell.getNumberOfPoints();
@@ -5673,8 +8550,7 @@ const CellPicker_DEFAULT_VALUES = {
5673
8550
 
5674
8551
  // ----------------------------------------------------------------------------
5675
8552
 
5676
- function CellPicker_extend(publicAPI, model) {
5677
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
8553
+ function CellPicker_extend(publicAPI, model, initialValues = {}) {
5678
8554
  Object.assign(model, CellPicker_DEFAULT_VALUES, initialValues);
5679
8555
 
5680
8556
  // Inheritance
@@ -7171,8 +10047,7 @@ class Widget {
7171
10047
  * @param canvas The HTML canvas to convert
7172
10048
  * @param boundingBox A bounding box of type [top, left, width, height]
7173
10049
  */
7174
- function canvasToImageData(canvas) {
7175
- let boundingBox = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0, 0];
10050
+ function canvasToImageData(canvas, boundingBox = [0, 0, 0, 0]) {
7176
10051
  const [top, left, width, height] = boundingBox;
7177
10052
  const ctxt = canvas.getContext('2d');
7178
10053
  const idata = ctxt.getImageData(top, left, width || canvas.width, height || canvas.height);
@@ -7194,12 +10069,11 @@ function canvasToImageData(canvas) {
7194
10069
  /**
7195
10070
  * Converts an Image object to a vtkImageData.
7196
10071
  */
7197
- function imageToImageData(image) {
7198
- let transform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
7199
- flipX: false,
7200
- flipY: false,
7201
- rotate: 0
7202
- };
10072
+ function imageToImageData(image, transform = {
10073
+ flipX: false,
10074
+ flipY: false,
10075
+ rotate: 0
10076
+ }) {
7203
10077
  const canvas = document.createElement('canvas');
7204
10078
  canvas.width = image.width;
7205
10079
  canvas.height = image.height;
@@ -7423,8 +10297,7 @@ const DEFAULT_VALUES = {
7423
10297
 
7424
10298
  // ----------------------------------------------------------------------------
7425
10299
 
7426
- function extend(publicAPI, model) {
7427
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10300
+ function extend(publicAPI, model, initialValues = {}) {
7428
10301
  Object.assign(model, DEFAULT_VALUES, initialValues);
7429
10302
 
7430
10303
  // Build VTK API
@@ -7725,8 +10598,7 @@ const DEFAULT_VALUES = {
7725
10598
 
7726
10599
  // ----------------------------------------------------------------------------
7727
10600
 
7728
- function extend(publicAPI, model) {
7729
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10601
+ function extend(publicAPI, model, initialValues = {}) {
7730
10602
  Object.assign(model, DEFAULT_VALUES, initialValues);
7731
10603
 
7732
10604
  // Build VTK API
@@ -7922,8 +10794,7 @@ function vtkAnnotatedCubeActor(publicAPI, model) {
7922
10794
 
7923
10795
  // private methods
7924
10796
 
7925
- function updateFaceTexture(faceName) {
7926
- let newProp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
10797
+ function updateFaceTexture(faceName, newProp = null) {
7927
10798
  if (newProp) {
7928
10799
  Object.assign(model[`${faceName}FaceProperty`], newProp);
7929
10800
  }
@@ -8037,8 +10908,7 @@ const DEFAULT_VALUES = {
8037
10908
 
8038
10909
  // ----------------------------------------------------------------------------
8039
10910
 
8040
- function extend(publicAPI, model) {
8041
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10911
+ function extend(publicAPI, model, initialValues = {}) {
8042
10912
  Object.assign(model, DEFAULT_VALUES, initialValues);
8043
10913
 
8044
10914
  // Inheritance
@@ -8294,8 +11164,7 @@ const DEFAULT_VALUES = {
8294
11164
 
8295
11165
  // ----------------------------------------------------------------------------
8296
11166
 
8297
- function extend(publicAPI, model) {
8298
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11167
+ function extend(publicAPI, model, initialValues = {}) {
8299
11168
  Object.assign(model, DEFAULT_VALUES, initialValues);
8300
11169
 
8301
11170
  // Build VTK API
@@ -8408,8 +11277,7 @@ const ConeSource_DEFAULT_VALUES = {
8408
11277
 
8409
11278
  // ----------------------------------------------------------------------------
8410
11279
 
8411
- function ConeSource_extend(publicAPI, model) {
8412
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11280
+ function ConeSource_extend(publicAPI, model, initialValues = {}) {
8413
11281
  Object.assign(model, ConeSource_DEFAULT_VALUES, initialValues);
8414
11282
 
8415
11283
  // Build VTK API
@@ -8607,8 +11475,7 @@ const CylinderSource_DEFAULT_VALUES = {
8607
11475
 
8608
11476
  // ----------------------------------------------------------------------------
8609
11477
 
8610
- function CylinderSource_extend(publicAPI, model) {
8611
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11478
+ function CylinderSource_extend(publicAPI, model, initialValues = {}) {
8612
11479
  Object.assign(model, CylinderSource_DEFAULT_VALUES, initialValues);
8613
11480
 
8614
11481
  // Build VTK API
@@ -8709,8 +11576,7 @@ const ArrowSource_DEFAULT_VALUES = {
8709
11576
 
8710
11577
  // ----------------------------------------------------------------------------
8711
11578
 
8712
- function ArrowSource_extend(publicAPI, model) {
8713
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11579
+ function ArrowSource_extend(publicAPI, model, initialValues = {}) {
8714
11580
  Object.assign(model, ArrowSource_DEFAULT_VALUES, initialValues);
8715
11581
 
8716
11582
  // Build VTK API
@@ -8750,8 +11616,7 @@ function centerDataSet(ds) {
8750
11616
  const center = [-(bounds[0] + bounds[1]) * 0.5, -(bounds[2] + bounds[3]) * 0.5, -(bounds[4] + bounds[5]) * 0.5];
8751
11617
  MatrixBuilder/* default */.A.buildFromDegree().translate(...center).apply(ds.getPoints().getData());
8752
11618
  }
8753
- function shiftDataset(ds, axis) {
8754
- let invert = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
11619
+ function shiftDataset(ds, axis, invert = false) {
8755
11620
  const bounds = ds.getPoints().getBounds();
8756
11621
  const center = [0, 0, 0];
8757
11622
  if (invert) {
@@ -8897,8 +11762,7 @@ function defaultValues(initialValues) {
8897
11762
 
8898
11763
  // ----------------------------------------------------------------------------
8899
11764
 
8900
- function AxesActor_extend(publicAPI, model) {
8901
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11765
+ function AxesActor_extend(publicAPI, model, initialValues = {}) {
8902
11766
  // Inheritance
8903
11767
  Actor/* default.extend */.Ay.extend(publicAPI, model, defaultValues(initialValues));
8904
11768
  macros2.m.setGet(publicAPI, model, ['config', 'xConfig', 'yConfig', 'zConfig']);