@ohif/app 3.14.0-beta.70 → 3.14.0-beta.72

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 (23) hide show
  1. package/dist/{1645.bundle.618a2886.js → 1645.bundle.1a86b10e.js} +11 -28
  2. package/dist/{1283.bundle.f2c2bb56.js → 213.bundle.6bbe580b.js} +4743 -390
  3. package/dist/{8199.bundle.25557805.js → 2894.bundle.770d3d9e.js} +1355 -567
  4. package/dist/{3386.bundle.1a446825.js → 3386.bundle.bdaa8014.js} +14 -5
  5. package/dist/{3044.bundle.039294b9.js → 4500.bundle.79728db8.js} +25 -17
  6. package/dist/{2894.bundle.d612efb2.js → 513.bundle.9c0548cf.js} +1 -1
  7. package/dist/{5143.bundle.67167d39.js → 5143.bundle.1ddc3eb4.js} +66 -42
  8. package/dist/{5320.bundle.0c7b2cb7.js → 5320.bundle.43308cb4.js} +18 -27
  9. package/dist/{5989.bundle.f8096a4e.js → 5989.bundle.6da1ff18.js} +19 -28
  10. package/dist/{4018.bundle.48c288e5.js → 6847.bundle.7fd47a86.js} +32 -5
  11. package/dist/{7464.bundle.492c83ce.js → 7464.bundle.36e9c349.js} +1440 -597
  12. package/dist/{1724.bundle.59b20c59.js → 8699.bundle.c00d7ae1.js} +480 -87
  13. package/dist/{9187.bundle.237037e4.js → 9187.bundle.134a42b2.js} +2 -2
  14. package/dist/{9481.bundle.027aa5ca.js → 9481.bundle.65162f9d.js} +2 -2
  15. package/dist/{9620.bundle.67375c83.js → 9620.bundle.e098e167.js} +2 -2
  16. package/dist/{9892.bundle.8c1ccb0e.js → 9892.bundle.fe68e426.js} +3 -3
  17. package/dist/{app.bundle.ca3d1da9.js → app.bundle.58791784.js} +25 -22
  18. package/dist/{compute.bundle.79a2d455.js → compute.bundle.09be4c13.js} +8 -8
  19. package/dist/index.html +1 -1
  20. package/dist/{interpolation.bundle.302d242b.js → interpolation.bundle.1eeebcfe.js} +5 -5
  21. package/dist/{polySeg.bundle.aaf002b1.js → polySeg.bundle.5bc24361.js} +8 -8
  22. package/dist/sw.js +1 -1
  23. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- (globalThis["rspackChunk_ohif_app"] ||= []).push([[1724], {
1
+ (globalThis["rspackChunk_ohif_app"] ||= []).push([[8699], {
2
2
  21094(module) {
3
3
  "use strict";
4
4
 
@@ -392,7 +392,7 @@ function isSlowBuffer (obj) {
392
392
 
393
393
 
394
394
  },
395
- 78151(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
395
+ 3990(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
396
396
  "use strict";
397
397
 
398
398
  // EXPORTS
@@ -405,7 +405,7 @@ __webpack_require__.d(__webpack_exports__, {
405
405
  QX: () => (/* reexport */ adaptersSR)
406
406
  });
407
407
 
408
- // UNUSED EXPORTS: helpers, utilities
408
+ // UNUSED EXPORTS: helpers, utilities, version
409
409
  // NAMESPACE OBJECT: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/Cornerstone/Segmentation.js
410
410
  var Segmentation_namespaceObject = {};
411
411
  __webpack_require__.r(Segmentation_namespaceObject);
@@ -549,6 +549,34 @@ function scoordToWorld(_ref, scoord) {
549
549
 
550
550
 
551
551
 
552
+ // EXTERNAL MODULE: ../../node_modules/@cornerstonejs/metadata/dist/esm/index.js + 29 modules
553
+ var dist_esm = __webpack_require__(86049);
554
+ ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/version.js
555
+ const version = '5.16.0';
556
+
557
+
558
+
559
+ ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/utilities/getWriterHeader.js
560
+
561
+
562
+
563
+ const DEFAULT_WRITER_HEADER = {
564
+ Manufacturer: 'CornerstoneJS',
565
+ ManufacturerModelName: '@cornerstonejs/adapters',
566
+ SoftwareVersions: (/* inlined export .version */"5.16.0")
567
+ };
568
+ const valueOr = (value, fallback) => (0,dist_esm/* .hasNoValue */.Tn)(value) ? fallback : value;
569
+ function getWriterHeader() {
570
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
571
+ return {
572
+ Manufacturer: valueOr(options.Manufacturer, DEFAULT_WRITER_HEADER.Manufacturer),
573
+ ManufacturerModelName: valueOr(options.ManufacturerModelName, DEFAULT_WRITER_HEADER.ManufacturerModelName),
574
+ SoftwareVersions: options.SoftwareVersions === undefined ? DEFAULT_WRITER_HEADER.SoftwareVersions : valueOr(options.SoftwareVersions, [])
575
+ };
576
+ }
577
+
578
+
579
+
552
580
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/Cornerstone/MeasurementReport.js
553
581
 
554
582
 
@@ -558,6 +586,7 @@ function scoordToWorld(_ref, scoord) {
558
586
 
559
587
 
560
588
 
589
+
561
590
  const cs3dLogger = esm.utilities.logger.adaptersLog.getLogger('Cornerstone.MeasurementReport');
562
591
  const TID1500 = dcmjs_es/* .utilities.TID1500 */.BF.TID1500,
563
592
  addAccessors = dcmjs_es/* .utilities.addAccessors */.BF.addAccessors;
@@ -737,7 +766,7 @@ class MeasurementReport {
737
766
  };
738
767
  derivationSourceDataset._meta = _meta;
739
768
  derivationSourceDataset._vrMap = _vrMap;
740
- const report = new StructuredReport([derivationSourceDataset]);
769
+ const report = new StructuredReport([derivationSourceDataset], getWriterHeader(options));
741
770
  const contentItem = tid1500MeasurementReport.contentItem(derivationSourceDataset);
742
771
 
743
772
  // Merge the derived dataset with the content from the Measurement Report
@@ -1855,19 +1884,78 @@ function checkOrientation(multiframe, validOrientations, sourceDataDimensions, t
1855
1884
 
1856
1885
 
1857
1886
 
1858
- // EXTERNAL MODULE: ../../node_modules/@cornerstonejs/metadata/dist/esm/index.js + 29 modules
1859
- var dist_esm = __webpack_require__(76368);
1860
1887
  // EXTERNAL MODULE: ../../node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js
1861
1888
  var objectWithoutProperties = __webpack_require__(39850);
1889
+ ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/Cornerstone3D/Segmentation/sourceFrame.js
1890
+
1891
+
1892
+
1893
+
1894
+ const isEqual = dist_esm/* .utilities.isEqual */.BF.n4,
1895
+ toFiniteVector = dist_esm/* .utilities.toFiniteVector */.BF.w7;
1896
+ const MetadataModules = esm.Enums.MetadataModules;
1897
+ const GEOMETRY_TOLERANCE = 1e-3;
1898
+ const DEFAULT_POSITION = [0, 0, 0];
1899
+ const DEFAULT_ORIENTATION = [1, 0, 0, 0, 1, 0];
1900
+ const DEFAULT_PIXEL_SPACING = [1, 1];
1901
+ function getSourceFrame(image, metadata) {
1902
+ var _metadata$get, _metadata$get2, _toOrientation, _metadata$get3, _metadata$get4, _toFiniteVector;
1903
+ let withPixelMeasures = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1904
+ const imageId = image === null || image === void 0 ? void 0 : image.imageId;
1905
+ const plane = (_metadata$get = metadata === null || metadata === void 0 || (_metadata$get2 = metadata.get) === null || _metadata$get2 === void 0 ? void 0 : _metadata$get2.call(metadata, MetadataModules.IMAGE_PLANE, imageId)) !== null && _metadata$get !== void 0 ? _metadata$get : {};
1906
+ const rowCosines = plane.rowCosines,
1907
+ columnCosines = plane.columnCosines,
1908
+ usingDefaultValues = plane.usingDefaultValues;
1909
+ const notDefault = (value, defaultValue) => usingDefaultValues && isEqual(value, defaultValue) ? undefined : value;
1910
+ const cosineFlags = [plane.isDefaultValueSetForRowCosine, plane.isDefaultValueSetForColumnCosine];
1911
+ const planeOrientation = (_toOrientation = toOrientation(plane.imageOrientationPatient)) !== null && _toOrientation !== void 0 ? _toOrientation : rowCosines && columnCosines ? toOrientation([...rowCosines, ...columnCosines]) : undefined;
1912
+ let position = notDefault(toFiniteVector(plane.imagePositionPatient, 3), DEFAULT_POSITION);
1913
+ let orientation = cosineFlags.some(flag => flag !== undefined) ? cosineFlags.some(Boolean) ? undefined : planeOrientation : notDefault(planeOrientation, DEFAULT_ORIENTATION);
1914
+ if (position && orientation && !withPixelMeasures) {
1915
+ return {
1916
+ position,
1917
+ orientation
1918
+ };
1919
+ }
1920
+ const instance = (_metadata$get3 = metadata === null || metadata === void 0 || (_metadata$get4 = metadata.get) === null || _metadata$get4 === void 0 ? void 0 : _metadata$get4.call(metadata, MetadataModules.IMAGE_DATA, imageId)) !== null && _metadata$get3 !== void 0 ? _metadata$get3 : {};
1921
+ position !== null && position !== void 0 ? position : position = toFiniteVector(instance.ImagePositionPatient, 3);
1922
+ orientation !== null && orientation !== void 0 ? orientation : orientation = toOrientation(instance.ImageOrientationPatient);
1923
+ if (!withPixelMeasures) {
1924
+ return {
1925
+ position,
1926
+ orientation
1927
+ };
1928
+ }
1929
+ return {
1930
+ position,
1931
+ orientation,
1932
+ sliceThickness: [plane.sliceThickness, instance.SliceThickness].map(Number).find(thickness => thickness > 0),
1933
+ pixelSpacing: (_toFiniteVector = toFiniteVector(instance.PixelSpacing, 2)) !== null && _toFiniteVector !== void 0 ? _toFiniteVector : notDefault(toFiniteVector(plane.pixelSpacing, 2), DEFAULT_PIXEL_SPACING)
1934
+ };
1935
+ }
1936
+ const sliceNormal = orientation => {
1937
+ const normal = gl_matrix_esm/* .vec3.cross */.eR.$A([0, 0, 0], orientation.slice(0, 3), orientation.slice(3, 6));
1938
+ return gl_matrix_esm/* .vec3.normalize */.eR.S8(normal, normal);
1939
+ };
1940
+ function toOrientation(values) {
1941
+ const orientation = toFiniteVector(values, 6);
1942
+ return orientation && gl_matrix_esm/* .vec3.length */.eR.Bw(sliceNormal(orientation)) > GEOMETRY_TOLERANCE ? orientation : undefined;
1943
+ }
1944
+
1945
+
1946
+
1862
1947
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/Cornerstone3D/Segmentation/perFrameFunctionalGroups.js
1863
1948
 
1864
1949
 
1865
1950
 
1866
1951
 
1952
+
1953
+
1954
+
1867
1955
  const _excluded = ["SegmentIdentificationSequence"];
1868
1956
  function perFrameFunctionalGroups_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1869
1957
  function perFrameFunctionalGroups_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? perFrameFunctionalGroups_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : perFrameFunctionalGroups_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1870
- const MetadataModules = esm.Enums.MetadataModules;
1958
+ const perFrameFunctionalGroups_MetadataModules = esm.Enums.MetadataModules;
1871
1959
 
1872
1960
  /**
1873
1961
  * Resolves the 1-based DICOM frame number referenced by an imageId.
@@ -1904,7 +1992,7 @@ function getReferencedFrameNumber(imageId, metadata) {
1904
1992
  */
1905
1993
  function getReferencedSourceImageSequenceItem(image, metadata) {
1906
1994
  var _metadata$get;
1907
- const imageData = (metadata === null || metadata === void 0 || (_metadata$get = metadata.get) === null || _metadata$get === void 0 ? void 0 : _metadata$get.call(metadata, MetadataModules.IMAGE_DATA, image === null || image === void 0 ? void 0 : image.imageId)) || {};
1995
+ const imageData = (metadata === null || metadata === void 0 || (_metadata$get = metadata.get) === null || _metadata$get === void 0 ? void 0 : _metadata$get.call(metadata, perFrameFunctionalGroups_MetadataModules.IMAGE_DATA, image === null || image === void 0 ? void 0 : image.imageId)) || {};
1908
1996
  const referencedFrameNumber = getReferencedFrameNumber(image === null || image === void 0 ? void 0 : image.imageId, metadata);
1909
1997
  const item = {
1910
1998
  ReferencedSOPInstanceUID: imageData.SOPInstanceUID
@@ -1930,6 +2018,8 @@ function normalizeSharedFunctionalGroupsSequence(dataset) {
1930
2018
  * sourceImageSequenceItem: { ReferencedSOPInstanceUID: string, ReferencedFrameNumber?: number },
1931
2019
  * planeOrientationSequence?: object,
1932
2020
  * planePositionSequence?: object,
2021
+ * frameContent?: { DimensionIndexValues: number[], StackID?: string, InStackPositionNumber?: number },
2022
+ * pixelMeasuresSequence?: object,
1933
2023
  * }>} frames
1934
2024
  *
1935
2025
  * `referencedSegmentNumber` drives the per-frame `SegmentIdentificationSequence`
@@ -1937,6 +2027,10 @@ function normalizeSharedFunctionalGroupsSequence(dataset) {
1937
2027
  * single frame carries many segment labels as pixel values, so the standard
1938
2028
  * forbids the macro and a fixed `ReferencedSegmentNumber` would be wrong for any
1939
2029
  * label other than the one hard-coded.
2030
+ *
2031
+ * `frameContent` replaces the frame's `FrameContentSequence`. Callers that
2032
+ * build the per-frame groups from scratch (LABELMAP SEGs) must pass it, since
2033
+ * the Frame Content macro is mandatory for every Segmentation frame.
1940
2034
  */
1941
2035
  function applyPerFrameFunctionalGroups(dataset, frames) {
1942
2036
  normalizeSharedFunctionalGroupsSequence(dataset);
@@ -1969,12 +2063,64 @@ function applyPerFrameFunctionalGroups(dataset, frames) {
1969
2063
  if (frame.planePositionSequence) {
1970
2064
  group.PlanePositionSequence = frame.planePositionSequence;
1971
2065
  }
2066
+ if (frame.pixelMeasuresSequence) {
2067
+ group.PixelMeasuresSequence = frame.pixelMeasuresSequence;
2068
+ }
2069
+ if (frame.frameContent) {
2070
+ group.FrameContentSequence = frame.frameContent;
2071
+ }
1972
2072
  return group;
1973
2073
  });
1974
2074
  dataset.PerFrameFunctionalGroupsSequence = nextSequence;
1975
2075
  dataset.NumberOfFrames = nextSequence.length;
1976
2076
  }
1977
2077
 
2078
+ /**
2079
+ * Writes the PlaneOrientationSequence of each frame in the shared group or in
2080
+ * the per-frame groups, never in both (PS3.3 C.7.6.16). When all frames have
2081
+ * one orientation, within GEOMETRY_TOLERANCE, it goes in the shared group
2082
+ * only. Otherwise each frame gets its own orientation in its per-frame group,
2083
+ * and a frame without one keeps its current per-frame orientation, or else the
2084
+ * current shared orientation. When no frame has a known orientation, the
2085
+ * dataset does not change.
2086
+ *
2087
+ * Call it after the per-frame groups are built.
2088
+ *
2089
+ * @param {object} dataset - SEG dataset
2090
+ * @param {Array<number[]|undefined>} frameOrientations - the
2091
+ * ImageOrientationPatient of each frame, or undefined when it is not known
2092
+ */
2093
+ function setPlaneOrientations(dataset, frameOrientations) {
2094
+ var _dataset$PerFrameFunc;
2095
+ normalizeSharedFunctionalGroupsSequence(dataset);
2096
+ const shared = dataset.SharedFunctionalGroupsSequence;
2097
+ const perFrame = (_dataset$PerFrameFunc = dataset.PerFrameFunctionalGroupsSequence) !== null && _dataset$PerFrameFunc !== void 0 ? _dataset$PerFrameFunc : [];
2098
+ const _frameOrientations = (0,slicedToArray/* ["default"] */.A)(frameOrientations, 1),
2099
+ first = _frameOrientations[0];
2100
+ if (!frameOrientations.some(Boolean)) {
2101
+ return;
2102
+ }
2103
+ if (first && frameOrientations.every(orientation => dist_esm/* .utilities.isEqual */.BF.n4(orientation, first, (/* inlined export .GEOMETRY_TOLERANCE */0.001)))) {
2104
+ shared.PlaneOrientationSequence = {
2105
+ ImageOrientationPatient: first
2106
+ };
2107
+ perFrame.forEach(group => delete group.PlaneOrientationSequence);
2108
+ return;
2109
+ }
2110
+ const sharedOrientation = shared.PlaneOrientationSequence;
2111
+ delete shared.PlaneOrientationSequence;
2112
+ perFrame.forEach((group, index) => {
2113
+ const orientation = frameOrientations[index];
2114
+ if (orientation) {
2115
+ group.PlaneOrientationSequence = {
2116
+ ImageOrientationPatient: orientation
2117
+ };
2118
+ } else if (!group.PlaneOrientationSequence && sharedOrientation) {
2119
+ group.PlaneOrientationSequence = sharedOrientation;
2120
+ }
2121
+ });
2122
+ }
2123
+
1978
2124
 
1979
2125
 
1980
2126
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/Cornerstone3D/encodePixelData.js
@@ -2440,6 +2586,11 @@ var Events_Events;
2440
2586
 
2441
2587
 
2442
2588
 
2589
+
2590
+
2591
+
2592
+ function Segmentation_4X_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2593
+ function Segmentation_4X_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? Segmentation_4X_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : Segmentation_4X_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2443
2594
  const Segmentation_4X_cs3dLogger = esm.utilities.logger.adaptersLog.getLogger('Cornerstone.Segmentation_4X');
2444
2595
  const BitArray = dcmjs_es/* .data.BitArray */.p.BitArray,
2445
2596
  Segmentation_4X_DicomMessage = dcmjs_es/* .data.DicomMessage */.p.DicomMessage,
@@ -2481,6 +2632,38 @@ function generateSegmentation(images, inputLabelmaps3D) {
2481
2632
  return fillSegmentation(segmentation, inputLabelmaps3D, userOptions);
2482
2633
  }
2483
2634
 
2635
+ /**
2636
+ * Logs one warning for the SEG frames whose source image has no position or
2637
+ * no orientation. Such a frame keeps the plane value that dcmjs gave it.
2638
+ */
2639
+ function warnMissingPlanes(frameDescriptors, getSource) {
2640
+ const missing = {
2641
+ position: [],
2642
+ orientation: []
2643
+ };
2644
+ frameDescriptors.forEach((desc, frameIndex) => {
2645
+ const source = getSource(desc.sourceFrameIndex);
2646
+ Object.keys(missing).forEach(key => {
2647
+ if (!source[key]) {
2648
+ missing[key].push(frameIndex + 1);
2649
+ }
2650
+ });
2651
+ });
2652
+ const details = [['ImagePositionPatient', missing.position], ['ImageOrientationPatient', missing.orientation]].filter(_ref => {
2653
+ let _ref2 = (0,slicedToArray/* ["default"] */.A)(_ref, 2),
2654
+ frames = _ref2[1];
2655
+ return frames.length;
2656
+ }).map(_ref3 => {
2657
+ let _ref4 = (0,slicedToArray/* ["default"] */.A)(_ref3, 2),
2658
+ name = _ref4[0],
2659
+ frames = _ref4[1];
2660
+ return "no ".concat(name, " for SEG frames ").concat(frames.join(', '));
2661
+ });
2662
+ if (details.length) {
2663
+ Segmentation_4X_cs3dLogger.warn("The source images have ".concat(details.join('; '), ". These frames keep the ") + "values that dcmjs gave them, which can be those of other source images.");
2664
+ }
2665
+ }
2666
+
2484
2667
  /**
2485
2668
  * The segment index of a voxel value of one labelmap3D. A value that is not in
2486
2669
  * `labelmap3D.labelToSegmentIndex` is its own segment index.
@@ -2530,11 +2713,23 @@ function segmentsPresentInFrame(pixelData) {
2530
2713
  * valid RLE-encoded SEG), so it has been dropped rather than fixed. RLE
2531
2714
  * output is now selected via `transferSyntaxUid` (RLE Lossless is the
2532
2715
  * default), and encoding is handled by `encodeFramesToTransferSyntax`.
2716
+ * @param images - The source images, in the order of the derived frames.
2717
+ * @param metadata - A metadata provider for the `imageId` of each image.
2718
+ *
2719
+ * With `images` and `metadata`, each SEG frame gets the source reference, the
2720
+ * position and the orientation of its own source image. dcmjs gives a frame
2721
+ * the position of the referenced multiframe frame with the same index, but it
2722
+ * sorts that multiframe by position, so for a stack in the other scan
2723
+ * direction the frame gets the position of the mirrored slice. dcmjs also
2724
+ * writes one shared orientation, from one source image. A frame without a
2725
+ * source SOP Instance UID throws, so that the per-frame groups always match
2726
+ * the PixelData frames. Without `images` or `metadata`, as from the legacy
2727
+ * `generateSegmentation`, the frames keep the planes of dcmjs.
2533
2728
  *
2534
2729
  * @returns {object} The filled segmentation object.
2535
2730
  */
2536
2731
  function fillSegmentation(segmentation, inputLabelmaps3D) {
2537
- var _segmentation$dataset, _segmentation$dataset2, _ref, _options$transferSynt;
2732
+ var _segmentation$dataset, _segmentation$dataset2, _ref5, _options$transferSynt;
2538
2733
  let userOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2539
2734
  let images = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
2540
2735
  let metadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
@@ -2605,23 +2800,39 @@ function fillSegmentation(segmentation, inputLabelmaps3D) {
2605
2800
  });
2606
2801
  });
2607
2802
  if (frameDescriptors.length && images !== null && images !== void 0 && images.length && metadata) {
2608
- // Every SEG frame must reference a resolvable source SOP Instance UID.
2609
- // Reject rather than silently dropping frames: a dropped frame would make
2610
- // the per-frame functional groups disagree with the encoded PixelData and
2611
- // produce a SEG whose source-image references are unreliable.
2803
+ // Read each source image one time, also when it holds many segments.
2804
+ const sources = new Map();
2805
+ const getSource = sourceFrameIndex => {
2806
+ if (!sources.has(sourceFrameIndex)) {
2807
+ const image = images[sourceFrameIndex];
2808
+ sources.set(sourceFrameIndex, Segmentation_4X_objectSpread(Segmentation_4X_objectSpread({}, getSourceFrame(image, metadata)), {}, {
2809
+ sourceImageSequenceItem: getReferencedSourceImageSequenceItem(image, metadata)
2810
+ }));
2811
+ }
2812
+ return sources.get(sourceFrameIndex);
2813
+ };
2612
2814
  const perFrameInputs = frameDescriptors.map(desc => {
2613
- const sourceImageSequenceItem = getReferencedSourceImageSequenceItem(images[desc.sourceFrameIndex], metadata);
2815
+ const _getSource = getSource(desc.sourceFrameIndex),
2816
+ position = _getSource.position,
2817
+ sourceImageSequenceItem = _getSource.sourceImageSequenceItem;
2818
+
2819
+ // Throw, so that the per-frame groups always match the PixelData frames.
2614
2820
  if (!(sourceImageSequenceItem !== null && sourceImageSequenceItem !== void 0 && sourceImageSequenceItem.ReferencedSOPInstanceUID)) {
2615
2821
  throw new Error("Cannot resolve a source ReferencedSOPInstanceUID for SEG frame " + "(sourceFrameIndex ".concat(desc.sourceFrameIndex, ", segment ") + "".concat(desc.referencedSegmentNumber, "). Refusing to write a SEG with ") + "unreliable source image references.");
2616
2822
  }
2617
2823
  return {
2618
2824
  referencedSegmentNumber: desc.referencedSegmentNumber,
2619
- sourceImageSequenceItem
2825
+ sourceImageSequenceItem,
2826
+ planePositionSequence: position ? {
2827
+ ImagePositionPatient: position
2828
+ } : undefined
2620
2829
  };
2621
2830
  });
2622
2831
  applyPerFrameFunctionalGroups(segmentation.dataset, perFrameInputs);
2832
+ setPlaneOrientations(segmentation.dataset, frameDescriptors.map(desc => getSource(desc.sourceFrameIndex).orientation));
2833
+ warnMissingPlanes(frameDescriptors, getSource);
2623
2834
  }
2624
- const transferSyntaxUid = (_ref = (_options$transferSynt = options.transferSyntaxUid) !== null && _options$transferSynt !== void 0 ? _options$transferSynt : options.transferSyntaxUID) !== null && _ref !== void 0 ? _ref : Segmentation_4X_RLE_LOSSLESS_TRANSFER_SYNTAX_UID;
2835
+ const transferSyntaxUid = (_ref5 = (_options$transferSynt = options.transferSyntaxUid) !== null && _options$transferSynt !== void 0 ? _options$transferSynt : options.transferSyntaxUID) !== null && _ref5 !== void 0 ? _ref5 : Segmentation_4X_RLE_LOSSLESS_TRANSFER_SYNTAX_UID;
2625
2836
  if (transferSyntaxUid === Segmentation_4X_RLE_LOSSLESS_TRANSFER_SYNTAX_UID) {
2626
2837
  const isBinaryBitmap = segmentation.dataset.SegmentationType === 'BINARY' && Number(segmentation.dataset.BitsAllocated) === 1;
2627
2838
  if (isBinaryBitmap) {
@@ -2702,10 +2913,10 @@ function _getSegmentLabelmaps(sources, referencedFrameIndicies) {
2702
2913
  }
2703
2914
  const labelmaps = referencedFrameIndicies.map(frameIndex => {
2704
2915
  let merged;
2705
- sources.forEach(_ref2 => {
2916
+ sources.forEach(_ref6 => {
2706
2917
  var _labelmap3D$labelmaps;
2707
- let labelmap3D = _ref2.labelmap3D,
2708
- labelValue = _ref2.labelValue;
2918
+ let labelmap3D = _ref6.labelmap3D,
2919
+ labelValue = _ref6.labelValue;
2709
2920
  const pixelData = (_labelmap3D$labelmaps = labelmap3D.labelmaps2D[frameIndex]) === null || _labelmap3D$labelmaps === void 0 ? void 0 : _labelmap3D$labelmaps.pixelData;
2710
2921
  if (!pixelData) {
2711
2922
  return;
@@ -2741,9 +2952,12 @@ function _getLabelmapsFromReferencedFrameIndicies(labelmap3D, referencedFrameInd
2741
2952
  * @param {Boolean} isMultiframe Whether the images are multiframe.
2742
2953
  * @returns {Object} The Seg derived dataSet.
2743
2954
  */
2744
- function _createSegFromImages(images, isMultiframe, options) {
2955
+ function _createSegFromImages(images, isMultiframe) {
2956
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
2957
+ includeSliceSpacing: true
2958
+ };
2745
2959
  const multiframe = getDatasetsFromImages(images, isMultiframe);
2746
- return new SegmentationDerivation([multiframe], options);
2960
+ return new SegmentationDerivation([multiframe], Segmentation_4X_objectSpread(Segmentation_4X_objectSpread({}, options), getWriterHeader(options)));
2747
2961
  }
2748
2962
 
2749
2963
  /**
@@ -3163,9 +3377,9 @@ function checkSEGsOverlapping(pixelData, multiframe, imageIds, validOrientations
3163
3377
  frameSegmentsMapping.set(imageIdIndex, [frameSegment]);
3164
3378
  }
3165
3379
  }
3166
- for (let _ref3 of frameSegmentsMapping.entries()) {
3167
- var _ref4 = (0,slicedToArray/* ["default"] */.A)(_ref3, 2);
3168
- let role = _ref4[1];
3380
+ for (let _ref7 of frameSegmentsMapping.entries()) {
3381
+ var _ref8 = (0,slicedToArray/* ["default"] */.A)(_ref7, 2);
3382
+ let role = _ref8[1];
3169
3383
  let temp2DArray = new TypedArrayConstructor(sliceLength).fill(0);
3170
3384
  for (let i = 0; i < role.length; ++i) {
3171
3385
  const frameSegment = role[i];
@@ -3569,10 +3783,10 @@ function getImageIdOfSourceImagebyGeometry(ReferencedSeriesInstanceUID, FrameOfR
3569
3783
  imagePlane
3570
3784
  });
3571
3785
  }
3572
- for (const _ref5 of candidates) {
3573
- const imageId = _ref5.imageId;
3574
- const position = _ref5.position;
3575
- const imagePlane = _ref5.imagePlane;
3786
+ for (const _ref9 of candidates) {
3787
+ const imageId = _ref9.imageId;
3788
+ const position = _ref9.position;
3789
+ const imagePlane = _ref9.imagePlane;
3576
3790
  const rowCosines = dist_esm/* .utilities.toNumber */.BF.Ro(imagePlane === null || imagePlane === void 0 ? void 0 : imagePlane.rowCosines);
3577
3791
  const columnCosines = dist_esm/* .utilities.toNumber */.BF.Ro(imagePlane === null || imagePlane === void 0 ? void 0 : imagePlane.columnCosines);
3578
3792
  if (!rowCosines || !columnCosines) {
@@ -3810,10 +4024,10 @@ function calculateCentroid(imageIdIndexBufferIndex, multiframe, metadataProvider
3810
4024
  let worldYAcc = 0;
3811
4025
  let worldZAcc = 0;
3812
4026
  let count = 0;
3813
- for (const _ref6 of Object.entries(imageIdIndexBufferIndex)) {
3814
- var _ref7 = (0,slicedToArray/* ["default"] */.A)(_ref6, 2);
3815
- const imageIdIndex = _ref7[0];
3816
- const bufferIndices = _ref7[1];
4027
+ for (const _ref0 of Object.entries(imageIdIndexBufferIndex)) {
4028
+ var _ref1 = (0,slicedToArray/* ["default"] */.A)(_ref0, 2);
4029
+ const imageIdIndex = _ref1[0];
4030
+ const bufferIndices = _ref1[1];
3817
4031
  const z = Number(imageIdIndex);
3818
4032
  if (!bufferIndices || bufferIndices.length === 0) {
3819
4033
  continue;
@@ -3880,6 +4094,10 @@ const Segmentation = {
3880
4094
 
3881
4095
 
3882
4096
 
4097
+
4098
+
4099
+ function Segmentation_3X_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4100
+ function Segmentation_3X_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? Segmentation_3X_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : Segmentation_3X_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3883
4101
  const Segmentation_3X_cs3dLogger = esm.utilities.logger.adaptersLog.getLogger('Cornerstone.Segmentation_3X');
3884
4102
  const Segmentation_3X_datasetToBlob = dcmjs_es/* .utilities.datasetToBlob */.BF.datasetToBlob,
3885
4103
  Segmentation_3X_BitArray = dcmjs_es/* .utilities.BitArray */.BF.BitArray,
@@ -4008,9 +4226,12 @@ function _getSegCount(seg, segments) {
4008
4226
  * @param {Boolean} isMultiframe Whether the images are multiframe.
4009
4227
  * @returns {Object} The Seg derived dataSet.
4010
4228
  */
4011
- function Segmentation_3X_createSegFromImages(images, isMultiframe, options) {
4229
+ function Segmentation_3X_createSegFromImages(images, isMultiframe) {
4230
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
4231
+ includeSliceSpacing: true
4232
+ };
4012
4233
  const multiframe = getDatasetsFromImages(images, isMultiframe);
4013
- return new Segmentation_3X_SegmentationDerivation([multiframe], options);
4234
+ return new Segmentation_3X_SegmentationDerivation([multiframe], Segmentation_3X_objectSpread(Segmentation_3X_objectSpread({}, options), getWriterHeader(options)));
4014
4235
  }
4015
4236
 
4016
4237
  /**
@@ -4772,6 +4993,7 @@ class LabelData {
4772
4993
 
4773
4994
 
4774
4995
 
4996
+
4775
4997
  var _MeasurementReport;
4776
4998
  function MeasurementReport_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4777
4999
  function MeasurementReport_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? MeasurementReport_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : MeasurementReport_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -5144,7 +5366,7 @@ class MeasurementReport_MeasurementReport {
5144
5366
  const tid1500MeasurementReport = new MeasurementReport_TID1500MeasurementReport({
5145
5367
  TID1501MeasurementGroups: allMeasurementGroups
5146
5368
  }, options);
5147
- const report = new MeasurementReport_StructuredReport(derivationSourceDatasets, options);
5369
+ const report = new MeasurementReport_StructuredReport(derivationSourceDatasets, MeasurementReport_objectSpread(MeasurementReport_objectSpread({}, options), getWriterHeader(options)));
5148
5370
  const contentItem = tid1500MeasurementReport.contentItem(derivationSourceDatasets, MeasurementReport_objectSpread(MeasurementReport_objectSpread({}, options), {}, {
5149
5371
  sopInstanceUIDsToSeriesInstanceUIDMap
5150
5372
  }));
@@ -6641,14 +6863,27 @@ _UltrasoundDirectional.init('UltrasoundDirectionalTool', UltrasoundDirectional_T
6641
6863
 
6642
6864
 
6643
6865
 
6866
+
6867
+
6868
+
6869
+
6870
+
6871
+
6872
+ const generateSegmentation_excluded = ["SliceThickness", "SpacingBetweenSlices"];
6644
6873
  function generateSegmentation_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6645
6874
  function generateSegmentation_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? generateSegmentation_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : generateSegmentation_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6875
+ const generateSegmentation_isEqual = dist_esm/* .utilities.isEqual */.BF.n4;
6646
6876
  const generateSegmentation_cs3dLogger = esm.utilities.logger.adaptersLog.getLogger('Cornerstone3D.Segmentation.generateSegmentation');
6647
6877
  const generateSegmentation_MetadataModules = esm.Enums.MetadataModules;
6648
6878
  const SEGImageNormalizer = dcmjs_es/* .normalizers.SEGImageNormalizer */.z8.SEGImageNormalizer;
6649
6879
  const generateSegmentation_SegmentationDerivation = dcmjs_es/* .derivations.Segmentation */.h4.Segmentation;
6650
6880
  const LABELMAP_SEG_SOP_CLASS_UID = '1.2.840.10008.5.1.4.1.1.66.7';
6651
6881
  const BITMAP_SEG_SOP_CLASS_UID = '1.2.840.10008.5.1.4.1.1.66.4';
6882
+ const IMAGE_POSITION_PATIENT_TAG = 0x00200032;
6883
+ const PLANE_POSITION_SEQUENCE_TAG = 0x00209113;
6884
+ const STACK_ID_TAG = 0x00209056;
6885
+ const IN_STACK_POSITION_NUMBER_TAG = 0x00209057;
6886
+ const FRAME_CONTENT_SEQUENCE_TAG = 0x00209111;
6652
6887
  function resolveTransferSyntaxUid() {
6653
6888
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6654
6889
  const transferSyntaxUid = options.transferSyntaxUid || options.transferSyntaxUID;
@@ -6749,35 +6984,157 @@ function collectSegmentSequence(labelmap3DArray) {
6749
6984
  return segment;
6750
6985
  });
6751
6986
  }
6752
- function getPlaneSequencesForImage(image, metadata) {
6753
- var _metadata$get;
6754
- const imagePlane = metadata === null || metadata === void 0 || (_metadata$get = metadata.get) === null || _metadata$get === void 0 ? void 0 : _metadata$get.call(metadata, generateSegmentation_MetadataModules.IMAGE_PLANE, image === null || image === void 0 ? void 0 : image.imageId);
6755
- if (!imagePlane) {
6756
- return {};
6757
- }
6758
- const result = {};
6759
- const imagePositionPatient = imagePlane.imagePositionPatient,
6760
- imageOrientationPatient = imagePlane.imageOrientationPatient,
6761
- rowCosines = imagePlane.rowCosines,
6762
- columnCosines = imagePlane.columnCosines;
6763
- if (Array.isArray(imagePositionPatient) && imagePositionPatient.length === 3) {
6764
- result.planePositionSequence = {
6765
- ImagePositionPatient: [...imagePositionPatient]
6766
- };
6767
- }
6768
- let orientation = imageOrientationPatient;
6769
- if ((!Array.isArray(orientation) || orientation.length !== 6) && Array.isArray(rowCosines) && Array.isArray(columnCosines)) {
6770
- orientation = [...rowCosines, ...columnCosines];
6987
+ function getOrientationIndex(orientations, orientation) {
6988
+ let add = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
6989
+ const index = orientations.findIndex(other => generateSegmentation_isEqual(other, orientation, (/* inlined export .GEOMETRY_TOLERANCE */0.001)));
6990
+ return index === -1 && add ? orientations.push(orientation) - 1 : index;
6991
+ }
6992
+ const POSITION_DIMENSION = {
6993
+ DimensionIndexPointer: IMAGE_POSITION_PATIENT_TAG,
6994
+ FunctionalGroupPointer: PLANE_POSITION_SEQUENCE_TAG,
6995
+ DimensionDescriptionLabel: 'ImagePositionPatient'
6996
+ };
6997
+ const STACK_ID_DIMENSION = {
6998
+ DimensionIndexPointer: STACK_ID_TAG,
6999
+ FunctionalGroupPointer: FRAME_CONTENT_SEQUENCE_TAG,
7000
+ DimensionDescriptionLabel: 'StackID'
7001
+ };
7002
+ const IN_STACK_POSITION_DIMENSION = {
7003
+ DimensionIndexPointer: IN_STACK_POSITION_NUMBER_TAG,
7004
+ FunctionalGroupPointer: FRAME_CONTENT_SEQUENCE_TAG,
7005
+ DimensionDescriptionLabel: 'InStackPositionNumber'
7006
+ };
7007
+ function getLabelmapDimensions(frames) {
7008
+ const missing = frames.findIndex(_ref3 => {
7009
+ let position = _ref3.position,
7010
+ orientation = _ref3.orientation;
7011
+ return !position || !orientation;
7012
+ });
7013
+ if (missing !== -1) {
7014
+ throw new Error("Cannot write a LABELMAP SEG: the source image of frame ".concat(missing + 1, " ") + "has no ImagePositionPatient or ImageOrientationPatient.");
6771
7015
  }
6772
- if (Array.isArray(orientation) && orientation.length === 6) {
6773
- result.planeOrientationSequence = {
6774
- ImageOrientationPatient: [...orientation]
6775
- };
7016
+ const orientations = [];
7017
+ const frameOrientations = frames.map(_ref4 => {
7018
+ let orientation = _ref4.orientation;
7019
+ return getOrientationIndex(orientations, orientation);
7020
+ });
7021
+ const normals = orientations.map(sliceNormal);
7022
+ const distances = frames.map((_ref5, index) => {
7023
+ let position = _ref5.position;
7024
+ return gl_matrix_esm/* .vec3.dot */.eR.Om(normals[frameOrientations[index]], position);
7025
+ });
7026
+ const planes = [];
7027
+ let planeStart = 0;
7028
+ frames.map((_, index) => index).sort((a, b) => frameOrientations[a] - frameOrientations[b] || distances[a] - distances[b]).forEach((index, i, sorted) => {
7029
+ var _planes$previous;
7030
+ const previous = sorted[i - 1];
7031
+ const samePlane = i > 0 && frameOrientations[index] === frameOrientations[previous] && distances[index] - planeStart <= (/* inlined export .GEOMETRY_TOLERANCE */0.001);
7032
+ if (!samePlane) {
7033
+ planeStart = distances[index];
7034
+ }
7035
+ planes[index] = samePlane ? planes[previous] : ((_planes$previous = planes[previous]) !== null && _planes$previous !== void 0 ? _planes$previous : -1) + 1;
7036
+ });
7037
+ const planeCounts = [];
7038
+ const orientationStacks = orientations.map(() => []);
7039
+ const stacks = [];
7040
+ frames.forEach((_, index) => {
7041
+ var _planeCounts$planes$i, _stackIndexes$repeat;
7042
+ const repeat = (_planeCounts$planes$i = planeCounts[planes[index]]) !== null && _planeCounts$planes$i !== void 0 ? _planeCounts$planes$i : 0;
7043
+ planeCounts[planes[index]] = repeat + 1;
7044
+ const stackIndexes = orientationStacks[frameOrientations[index]];
7045
+ (_stackIndexes$repeat = stackIndexes[repeat]) !== null && _stackIndexes$repeat !== void 0 ? _stackIndexes$repeat : stackIndexes[repeat] = stacks.push([]) - 1;
7046
+ stacks[stackIndexes[repeat]].push(index);
7047
+ });
7048
+ const frameContents = [];
7049
+ stacks.forEach((stack, stackIndex) => {
7050
+ [...stack].sort((a, b) => planes[a] - planes[b]).forEach((frameIndex, rank) => {
7051
+ frameContents[frameIndex] = stacks.length === 1 ? {
7052
+ DimensionIndexValues: [rank + 1]
7053
+ } : {
7054
+ StackID: String(stackIndex + 1),
7055
+ InStackPositionNumber: rank + 1,
7056
+ DimensionIndexValues: [stackIndex + 1, rank + 1]
7057
+ };
7058
+ });
7059
+ });
7060
+ return {
7061
+ dimensions: stacks.length === 1 ? [POSITION_DIMENSION] : [STACK_ID_DIMENSION, IN_STACK_POSITION_DIMENSION],
7062
+ frameContents,
7063
+ orientations,
7064
+ normals,
7065
+ frameOrientations
7066
+ };
7067
+ }
7068
+ function getSourceSliceSpacings(sourceImages, metadata, orientations, normals) {
7069
+ const distances = orientations.map(() => []);
7070
+ sourceImages.forEach(image => {
7071
+ const _getSourceFrame = getSourceFrame(image, metadata),
7072
+ position = _getSourceFrame.position,
7073
+ orientation = _getSourceFrame.orientation;
7074
+ const index = position && orientation ? getOrientationIndex(orientations, orientation, false) : -1;
7075
+ if (index !== -1) {
7076
+ distances[index].push(gl_matrix_esm/* .vec3.dot */.eR.Om(normals[index], position));
7077
+ }
7078
+ });
7079
+ return distances.map(planes => {
7080
+ planes.sort((a, b) => a - b);
7081
+ const gaps = planes.slice(1).map((distance, index) => distance - planes[index]).filter(gap => gap > (/* inlined export .GEOMETRY_TOLERANCE */0.001));
7082
+ if (!gaps.length) {
7083
+ return undefined;
7084
+ }
7085
+ const mean = gaps.reduce((sum, gap) => sum + gap, 0) / gaps.length;
7086
+ return gaps.every(gap => Math.abs(gap - mean) <= mean * 0.01) ? mean : undefined;
7087
+ });
7088
+ }
7089
+ const PIXEL_MEASURE_KEYS = ['PixelSpacing', 'SliceThickness', 'SpacingBetweenSlices'];
7090
+ const isSameMeasure = (a, b) => a === b || generateSegmentation_isEqual(a, b, (/* inlined export .GEOMETRY_TOLERANCE */0.001));
7091
+ function applyLabelmapPixelMeasures(dataset, frames, frameOrientations, sliceSpacings, includeSliceSpacing) {
7092
+ var _toArray$;
7093
+ const shared = dataset.SharedFunctionalGroupsSequence;
7094
+ const _ref6 = (_toArray$ = toArray(shared.PixelMeasuresSequence)[0]) !== null && _toArray$ !== void 0 ? _toArray$ : {};
7095
+ _ref6.SliceThickness;
7096
+ _ref6.SpacingBetweenSlices;
7097
+ const derived = (0,objectWithoutProperties/* ["default"] */.A)(_ref6, generateSegmentation_excluded);
7098
+ const derivedPixelSpacing = toFiniteVector(derived.PixelSpacing, 2);
7099
+ let spacingMissing = false;
7100
+ const pixelMeasures = frames.map((frame, index) => {
7101
+ var _frame$pixelSpacing, _frame$sliceThickness;
7102
+ const sliceSpacing = sliceSpacings[frameOrientations[index]];
7103
+ const measures = generateSegmentation_objectSpread({}, derived);
7104
+ const pixelSpacing = (_frame$pixelSpacing = frame.pixelSpacing) !== null && _frame$pixelSpacing !== void 0 ? _frame$pixelSpacing : derivedPixelSpacing;
7105
+ if (pixelSpacing) {
7106
+ measures.PixelSpacing = pixelSpacing;
7107
+ }
7108
+ const sliceThickness = (_frame$sliceThickness = frame.sliceThickness) !== null && _frame$sliceThickness !== void 0 ? _frame$sliceThickness : sliceSpacing;
7109
+ if (sliceThickness !== undefined) {
7110
+ measures.SliceThickness = sliceThickness;
7111
+ }
7112
+ if (includeSliceSpacing) {
7113
+ if (sliceSpacing === undefined) {
7114
+ spacingMissing = true;
7115
+ } else {
7116
+ measures.SpacingBetweenSlices = sliceSpacing;
7117
+ }
7118
+ }
7119
+ return measures;
7120
+ });
7121
+ if (spacingMissing) {
7122
+ generateSegmentation_cs3dLogger.warn('generateSegmentation: includeSliceSpacing is set, but the source ' + 'slices are not evenly spaced, there is only one slice, or not all ' + 'source images are loaded; the LABELMAP SEG omits Spacing Between ' + 'Slices.');
7123
+ }
7124
+ const _pixelMeasures = (0,slicedToArray/* ["default"] */.A)(pixelMeasures, 1),
7125
+ first = _pixelMeasures[0];
7126
+ const same = pixelMeasures.every(measures => PIXEL_MEASURE_KEYS.every(key => isSameMeasure(measures[key], first[key])));
7127
+ if (same) {
7128
+ shared.PixelMeasuresSequence = first;
7129
+ return undefined;
6776
7130
  }
6777
- return result;
7131
+ delete shared.PixelMeasuresSequence;
7132
+ return pixelMeasures;
6778
7133
  }
6779
7134
  function fillLabelmapSegmentation(segmentation, inputLabelmaps3D, metadata, images) {
7135
+ var _toArray$0$DimensionO, _toArray$2;
6780
7136
  let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
7137
+ let sourceImages = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : images;
6781
7138
  const labelmap3DArray = toLabelmap3DArray(inputLabelmaps3D);
6782
7139
  const segmentSequence = collectSegmentSequence(labelmap3DArray);
6783
7140
  const validFrameIndices = collectNonEmptyFrameIndices(labelmap3DArray);
@@ -6820,6 +7177,21 @@ function fillLabelmapSegmentation(segmentation, inputLabelmaps3D, metadata, imag
6820
7177
  });
6821
7178
  return frame;
6822
7179
  };
7180
+ const frames = images.map((image, outputIndex) => {
7181
+ const sourceImageSequenceItem = getReferencedSourceImageSequenceItem(image, metadata);
7182
+ if (!(sourceImageSequenceItem !== null && sourceImageSequenceItem !== void 0 && sourceImageSequenceItem.ReferencedSOPInstanceUID)) {
7183
+ throw new Error("Cannot resolve a source ReferencedSOPInstanceUID for labelmap SEG " + "frame ".concat(outputIndex + 1, ". Refusing to write a SEG with unreliable ") + "source image references.");
7184
+ }
7185
+ return generateSegmentation_objectSpread(generateSegmentation_objectSpread({}, getSourceFrame(image, metadata, true)), {}, {
7186
+ sourceImageSequenceItem
7187
+ });
7188
+ });
7189
+ const _getLabelmapDimension = getLabelmapDimensions(frames),
7190
+ dimensions = _getLabelmapDimension.dimensions,
7191
+ frameContents = _getLabelmapDimension.frameContents,
7192
+ orientations = _getLabelmapDimension.orientations,
7193
+ normals = _getLabelmapDimension.normals,
7194
+ frameOrientations = _getLabelmapDimension.frameOrientations;
6823
7195
  const dataset = segmentation.dataset;
6824
7196
  dataset.NumberOfFrames = numberOfFrames;
6825
7197
  dataset.Rows = rows;
@@ -6853,30 +7225,46 @@ function fillLabelmapSegmentation(segmentation, inputLabelmaps3D, metadata, imag
6853
7225
  Value: [LABELMAP_SEG_SOP_CLASS_UID],
6854
7226
  vr: 'UI'
6855
7227
  };
6856
- const sourceImageSequence = images.map(image => getReferencedSourceImageSequenceItem(image, metadata)).filter(item => item.ReferencedSOPInstanceUID);
6857
- if (sourceImageSequence.length) {
6858
- dataset.SourceImageSequence = sourceImageSequence;
6859
- }
6860
- const perFrameInputs = validFrameIndices.map((_, outputIndex) => {
6861
- var _dataset$PerFrameFunc, _dataset$PerFrameFunc2, _planeSequences$plane, _planeSequences$plane2;
6862
- const image = images[outputIndex];
6863
- const sourceImageSequenceItem = getReferencedSourceImageSequenceItem(image, metadata);
6864
- if (!(sourceImageSequenceItem !== null && sourceImageSequenceItem !== void 0 && sourceImageSequenceItem.ReferencedSOPInstanceUID)) {
6865
- throw new Error("Cannot resolve a source ReferencedSOPInstanceUID for labelmap SEG " + "frame ".concat(outputIndex, ". Refusing to write a SEG with unreliable ") + "source image references.");
6866
- }
6867
- const priorGroup = (_dataset$PerFrameFunc = (_dataset$PerFrameFunc2 = dataset.PerFrameFunctionalGroupsSequence) === null || _dataset$PerFrameFunc2 === void 0 ? void 0 : _dataset$PerFrameFunc2[outputIndex]) !== null && _dataset$PerFrameFunc !== void 0 ? _dataset$PerFrameFunc : {};
6868
- const planeSequences = getPlaneSequencesForImage(image, metadata);
7228
+ dataset.SourceImageSequence = frames.map(_ref7 => {
7229
+ let sourceImageSequenceItem = _ref7.sourceImageSequenceItem;
7230
+ return sourceImageSequenceItem;
7231
+ });
7232
+ const dimensionOrganizationUID = (_toArray$0$DimensionO = (_toArray$2 = toArray(dataset.DimensionOrganizationSequence)[0]) === null || _toArray$2 === void 0 ? void 0 : _toArray$2.DimensionOrganizationUID) !== null && _toArray$0$DimensionO !== void 0 ? _toArray$0$DimensionO : dcmjs_es/* .data.DicomMetaDictionary.uid */.p.DicomMetaDictionary.uid();
7233
+ dataset.DimensionOrganizationSequence = {
7234
+ DimensionOrganizationUID: dimensionOrganizationUID
7235
+ };
7236
+ dataset.DimensionIndexSequence = dimensions.map(dimension => generateSegmentation_objectSpread({
7237
+ DimensionOrganizationUID: dimensionOrganizationUID
7238
+ }, dimension));
7239
+ normalizeSharedFunctionalGroupsSequence(dataset);
7240
+ delete dataset.SharedFunctionalGroupsSequence.PlanePositionSequence;
7241
+ const includeSliceSpacing = Boolean(options.includeSliceSpacing);
7242
+ const sliceSpacings = includeSliceSpacing || frames.some(_ref8 => {
7243
+ let sliceThickness = _ref8.sliceThickness;
7244
+ return sliceThickness === undefined;
7245
+ }) ? getSourceSliceSpacings(sourceImages, metadata, orientations, normals) : [];
7246
+ const perFramePixelMeasures = applyLabelmapPixelMeasures(dataset, frames, frameOrientations, sliceSpacings, includeSliceSpacing);
7247
+ dataset.PerFrameFunctionalGroupsSequence = [];
7248
+ applyPerFrameFunctionalGroups(dataset, frames.map((_ref9, index) => {
7249
+ let position = _ref9.position,
7250
+ sourceImageSequenceItem = _ref9.sourceImageSequenceItem;
6869
7251
  return {
6870
7252
  sourceImageSequenceItem,
6871
- planeOrientationSequence: (_planeSequences$plane = planeSequences.planeOrientationSequence) !== null && _planeSequences$plane !== void 0 ? _planeSequences$plane : priorGroup === null || priorGroup === void 0 ? void 0 : priorGroup.PlaneOrientationSequence,
6872
- planePositionSequence: (_planeSequences$plane2 = planeSequences.planePositionSequence) !== null && _planeSequences$plane2 !== void 0 ? _planeSequences$plane2 : priorGroup === null || priorGroup === void 0 ? void 0 : priorGroup.PlanePositionSequence
7253
+ planePositionSequence: {
7254
+ ImagePositionPatient: position
7255
+ },
7256
+ pixelMeasuresSequence: perFramePixelMeasures === null || perFramePixelMeasures === void 0 ? void 0 : perFramePixelMeasures[index],
7257
+ frameContent: frameContents[index]
6873
7258
  };
6874
- });
6875
- applyPerFrameFunctionalGroups(dataset, perFrameInputs);
6876
- const sopInstanceUIDs = new Set(images.map(image => {
6877
- var _metadata$get2;
6878
- return (_metadata$get2 = metadata.get(generateSegmentation_MetadataModules.IMAGE_DATA, image === null || image === void 0 ? void 0 : image.imageId)) === null || _metadata$get2 === void 0 ? void 0 : _metadata$get2.SOPInstanceUID;
6879
- }).filter(Boolean));
7259
+ }));
7260
+ setPlaneOrientations(dataset, frames.map(_ref0 => {
7261
+ let orientation = _ref0.orientation;
7262
+ return orientation;
7263
+ }));
7264
+ const sopInstanceUIDs = new Set(frames.map(_ref1 => {
7265
+ let sourceImageSequenceItem = _ref1.sourceImageSequenceItem;
7266
+ return sourceImageSequenceItem.ReferencedSOPInstanceUID;
7267
+ }));
6880
7268
  const referencedSeriesSequence = dataset.ReferencedSeriesSequence;
6881
7269
  const referencedSeries = Array.isArray(referencedSeriesSequence) ? referencedSeriesSequence[0] : referencedSeriesSequence;
6882
7270
  if (referencedSeries !== null && referencedSeries !== void 0 && referencedSeries.ReferencedInstanceSequence && sopInstanceUIDs.size) {
@@ -6925,7 +7313,7 @@ function generateSegmentation_generateSegmentation(images, labelmaps, metadata)
6925
7313
  const nonEmptyFrameIndices = collectNonEmptyFrameIndices(toLabelmap3DArray(labelmaps));
6926
7314
  const filteredImages = resolveReferencedImagesForExport(images, nonEmptyFrameIndices);
6927
7315
  const segmentation = _createMultiframeSegmentationFromReferencedImages(filteredImages, metadata, options);
6928
- const segmentationResult = fillLabelmapSegmentation(segmentation, labelmaps, metadata, filteredImages, options);
7316
+ const segmentationResult = fillLabelmapSegmentation(segmentation, labelmaps, metadata, filteredImages, options, images.every(image => image === null || image === void 0 ? void 0 : image.imageId) ? images : []);
6929
7317
  const predecessorImageId = options === null || options === void 0 ? void 0 : options.predecessorImageId;
6930
7318
  if (predecessorImageId) {
6931
7319
  const predecessor = metadata.get(generateSegmentation_MetadataModules.PREDECESSOR_SEQUENCE, predecessorImageId);
@@ -6978,7 +7366,7 @@ function _createMultiframeSegmentationFromReferencedImages(images, metadata, opt
6978
7366
  multiframe.PerFrameFunctionalGroupsSequence = [multiframe.PerFrameFunctionalGroupsSequence[0]];
6979
7367
  multiframe.NumberOfFrames = 1;
6980
7368
  }
6981
- return new generateSegmentation_SegmentationDerivation([multiframe], options);
7369
+ return new generateSegmentation_SegmentationDerivation([multiframe], generateSegmentation_objectSpread(generateSegmentation_objectSpread({}, options), getWriterHeader(options)));
6982
7370
  }
6983
7371
 
6984
7372
 
@@ -8241,6 +8629,7 @@ function getStructureSetModule(contour, segment) {
8241
8629
 
8242
8630
 
8243
8631
 
8632
+
8244
8633
  function referencedMetadataProvider_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8245
8634
  function referencedMetadataProvider_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? referencedMetadataProvider_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : referencedMetadataProvider_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8246
8635
  const referencedMetadataProvider_DicomMetaDictionary = dcmjs_es/* ["default"].data.DicomMetaDictionary */.Ay.data.DicomMetaDictionary;
@@ -8342,13 +8731,13 @@ const referencedMetadataProvider_metadataProvider = {
8342
8731
  },
8343
8732
  [referencedMetadataProvider_MetadataModules.NEW_INSTANCE_DATA]: imageId => {
8344
8733
  const studyData = esm.metaData.get(referencedMetadataProvider_MetadataModules.STUDY_DATA, imageId);
8345
- return referencedMetadataProvider_objectSpread(referencedMetadataProvider_objectSpread({}, studyData), {}, {
8734
+ return referencedMetadataProvider_objectSpread(referencedMetadataProvider_objectSpread(referencedMetadataProvider_objectSpread({}, studyData), {}, {
8346
8735
  SeriesNumber: '50000',
8347
8736
  InstanceNumber: '1',
8348
8737
  OperatorsName: '',
8349
8738
  ReferringPhysicianName: '',
8350
- SpecificCharacterSet: 'ISO_IR 192',
8351
- Manufacturer: 'cs3d',
8739
+ SpecificCharacterSet: 'ISO_IR 192'
8740
+ }, getWriterHeader()), {}, {
8352
8741
  SOPInstanceUID: referencedMetadataProvider_DicomMetaDictionary.uid(),
8353
8742
  SeriesInstanceUID: referencedMetadataProvider_DicomMetaDictionary.uid()
8354
8743
  });
@@ -8403,6 +8792,7 @@ function createInstance(instanceKey, studyExemplarImageId, base, options) {
8403
8792
 
8404
8793
 
8405
8794
 
8795
+
8406
8796
  function RTSS_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8407
8797
  function RTSS_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? RTSS_ownKeys(Object(t), !0).forEach(function (r) { (0,defineProperty/* ["default"] */.A)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : RTSS_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8408
8798
  const RTSS_cs3dLogger = esm.utilities.logger.adaptersLog.getLogger('Cornerstone3D.RTStruct.RTSS');
@@ -8521,12 +8911,13 @@ function generateRTSSFromAnnotations(segmentations, annotations, options) {
8521
8911
  }
8522
8912
  function _initializeDataset(segmentation, imgMetadata, options) {
8523
8913
  const studyExemplarImageId = imgMetadata.referencedImageId;
8524
- return createInstance(RTSS_MetadataModules.RTSS_INSTANCE_DATA, studyExemplarImageId, {
8914
+ const writerHeader = getWriterHeader(options);
8915
+ return createInstance(RTSS_MetadataModules.RTSS_INSTANCE_DATA, studyExemplarImageId, RTSS_objectSpread({
8525
8916
  StructureSetLabel: segmentation.label,
8526
8917
  StructureSetName: segmentation.label,
8527
8918
  SeriesDescription: segmentation.label,
8528
8919
  _meta: esm.metaData.get(RTSS_MetadataModules.RTSS_CONTOUR, studyExemplarImageId)
8529
- }, options);
8920
+ }, writerHeader), RTSS_objectSpread(RTSS_objectSpread({}, options), writerHeader));
8530
8921
  }
8531
8922
  function generateRTSSFromContour(segmentations, options) {
8532
8923
  const annotationUIDsMap = segmentations.representationData.Contour.annotationUIDsMap;
@@ -8886,6 +9277,7 @@ const adaptersRT = {
8886
9277
 
8887
9278
 
8888
9279
 
9280
+
8889
9281
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/adapters/dist/esm/adapters/enums/index.js
8890
9282
 
8891
9283
 
@@ -8920,6 +9312,7 @@ const graphicTypeEquals = graphicType => {
8920
9312
 
8921
9313
 
8922
9314
 
9315
+
8923
9316
  },
8924
9317
 
8925
9318
  }]);