@dcmjs-org/dcmjs 1.0.0-beta.17 → 1.0.0-beta.19

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.
@@ -1077,7 +1077,8 @@ var DicomMessage = /*#__PURE__*/function () {
1077
1077
  }
1078
1078
  var length = null,
1079
1079
  vr = null,
1080
- vrType;
1080
+ vrType,
1081
+ wireVrType = null;
1081
1082
  if (implicit) {
1082
1083
  length = stream.readUint32();
1083
1084
  var elementData = DicomMessage.lookupTag(tag);
@@ -1105,6 +1106,7 @@ var DicomMessage = /*#__PURE__*/function () {
1105
1106
  vr = core.ValueRepresentation.createByTypeString(vrType);
1106
1107
  } else {
1107
1108
  vrType = stream.readVR();
1109
+ wireVrType = vrType;
1108
1110
  if (vrType === "UN" && DicomMessage.lookupTag(tag) && DicomMessage.lookupTag(tag).vr) {
1109
1111
  vrType = DicomMessage.lookupTag(tag).vr;
1110
1112
  if (vrType === "xs") {
@@ -1123,13 +1125,19 @@ var DicomMessage = /*#__PURE__*/function () {
1123
1125
  length = stream.readUint16();
1124
1126
  }
1125
1127
  }
1128
+ var readSyntax = syntax;
1129
+ if (!implicit && wireVrType === "UN" && core.isUnSequenceValue(stream.view, stream.offset, length, vr.type)) {
1130
+ vr = core.ValueRepresentation.createByTypeString("SQ");
1131
+ readSyntax = core.IMPLICIT_LITTLE_ENDIAN;
1132
+ stream.setEndian(true); // the items are LE in a BE body too
1133
+ }
1126
1134
  var values = [];
1127
1135
  var rawValues = [];
1128
1136
  if (vr.isBinary() && length > vr.maxLength && !vr.noMultiple) {
1129
1137
  var times = length / vr.maxLength,
1130
1138
  i = 0;
1131
1139
  while (i++ < times) {
1132
- var _vr$read = vr.read(stream, vr.maxLength, syntax, options),
1140
+ var _vr$read = vr.read(stream, vr.maxLength, readSyntax, options),
1133
1141
  rawValue = _vr$read.rawValue,
1134
1142
  value = _vr$read.value;
1135
1143
  rawValues.push(rawValue);
@@ -1140,7 +1148,7 @@ var DicomMessage = /*#__PURE__*/function () {
1140
1148
  var readOptions = vr.type === "SQ" ? _objectSpread2(_objectSpread2({}, options), {}, {
1141
1149
  readItem: readItem
1142
1150
  }) : options;
1143
- var _ref = vr.read(stream, length, syntax, readOptions) || {},
1151
+ var _ref = vr.read(stream, length, readSyntax, readOptions) || {},
1144
1152
  _rawValue = _ref.rawValue,
1145
1153
  _value = _ref.value;
1146
1154
  if (!vr.isBinary() && core.singleVRs.indexOf(vr.type) == -1) {
@@ -2066,12 +2074,14 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2066
2074
  key: "readSequence",
2067
2075
  value: (function () {
2068
2076
  var _readSequence = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(listener, sqTagInfo, options) {
2069
- var length, stream, syntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, _t;
2077
+ var _ref, _sqTagInfo$sequenceRe;
2078
+ var length, stream, readSyntax, endOffset, tagInfo, tag, itemLength, itemUntilOffset, decoder, _t;
2070
2079
  return _regeneratorRuntime().wrap(function (_context6) {
2071
2080
  while (1) switch (_context6.prev = _context6.next) {
2072
2081
  case 0:
2073
2082
  length = sqTagInfo.length;
2074
- stream = this.stream, syntax = this.syntax;
2083
+ stream = this.stream;
2084
+ readSyntax = (_ref = (_sqTagInfo$sequenceRe = sqTagInfo.sequenceReadSyntax) !== null && _sqTagInfo$sequenceRe !== void 0 ? _sqTagInfo$sequenceRe : options === null || options === void 0 ? void 0 : options.readSyntax) !== null && _ref !== void 0 ? _ref : this.syntax;
2075
2085
  endOffset = length === core.UNDEFINED_LENGTH_FIX ? Number.MAX_SAFE_INTEGER : stream.offset + length;
2076
2086
  case 1:
2077
2087
  _t = stream.offset < endOffset;
@@ -2089,7 +2099,9 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2089
2099
  break;
2090
2100
  }
2091
2101
  readLog.debug("readSequence loop", stream.offset, endOffset);
2092
- tagInfo = this.readTagHeader(syntax, options);
2102
+ tagInfo = this.readTagHeader(_objectSpread2(_objectSpread2({}, options), {}, {
2103
+ readSyntax: readSyntax
2104
+ }));
2093
2105
  tag = tagInfo.tag;
2094
2106
  if (!(tag === core.TagHex.Item)) {
2095
2107
  _context6.next = 5;
@@ -2098,12 +2110,17 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2098
2110
  listener.startObject();
2099
2111
  // defined-length item: stop at its own end (see doc comment)
2100
2112
  itemLength = tagInfo.length;
2101
- itemUntilOffset = itemLength === core.UNDEFINED_LENGTH_FIX ? endOffset : Math.min(stream.offset + itemLength, endOffset);
2113
+ itemUntilOffset = itemLength === core.UNDEFINED_LENGTH_FIX ? endOffset : Math.min(stream.offset + itemLength, endOffset); // A SpecificCharacterSet in the item applies only to that
2114
+ // item (PS3.5 7.5.3), but the item is read on this stream:
2115
+ // put back the decoder the item started with.
2116
+ decoder = stream.decoder;
2102
2117
  _context6.next = 4;
2103
2118
  return this.read(listener, _objectSpread2(_objectSpread2({}, options), {}, {
2104
- untilOffset: itemUntilOffset
2119
+ untilOffset: itemUntilOffset,
2120
+ readSyntax: readSyntax
2105
2121
  }));
2106
2122
  case 4:
2123
+ stream.setDecoder(decoder);
2107
2124
  _context6.next = 7;
2108
2125
  break;
2109
2126
  case 5:
@@ -2529,14 +2546,15 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2529
2546
  }, {
2530
2547
  key: "readTagHeader",
2531
2548
  value: function readTagHeader() {
2549
+ var _options$readSyntax;
2532
2550
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
2533
2551
  untilTag: null,
2534
2552
  includeUntilTagValue: false
2535
2553
  };
2536
- var stream = this.stream,
2537
- syntax = this.syntax;
2554
+ var stream = this.stream;
2538
2555
  var untilTag = options.untilTag,
2539
2556
  includeUntilTagValue = options.includeUntilTagValue;
2557
+ var syntax = (_options$readSyntax = options.readSyntax) !== null && _options$readSyntax !== void 0 ? _options$readSyntax : this.syntax;
2540
2558
  var implicit = syntax == core.IMPLICIT_LITTLE_ENDIAN;
2541
2559
  var isLittleEndian = syntax !== core.EXPLICIT_BIG_ENDIAN;
2542
2560
  stream.setEndian(isLittleEndian);
@@ -2556,6 +2574,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2556
2574
  var length = null;
2557
2575
  var vr = null;
2558
2576
  var vrType;
2577
+ var wireVrType = null;
2559
2578
  var isCommand = tagObj.group() === 0;
2560
2579
  if (tagObj.isInstruction()) {
2561
2580
  length = stream.readUint32();
@@ -2590,6 +2609,7 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2590
2609
  } else {
2591
2610
  var _DicomMessage$lookupT;
2592
2611
  vrType = stream.readVR();
2612
+ wireVrType = vrType;
2593
2613
  if (vrType === "UN" && (_DicomMessage$lookupT = DicomMessage.lookupTag(tagObj)) !== null && _DicomMessage$lookupT !== void 0 && _DicomMessage$lookupT.vr) {
2594
2614
  vrType = DicomMessage.lookupTag(tagObj).vr;
2595
2615
  if (vrType === "xs") {
@@ -2609,11 +2629,16 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2609
2629
  length = stream.readUint16();
2610
2630
  }
2611
2631
  }
2632
+ var sequenceReadSyntax;
2633
+ if (!implicit && wireVrType === "UN" && core.isUnSequenceValue(stream.view, stream.offset, length, vr.type)) {
2634
+ vr = core.ValueRepresentation.createByTypeString("SQ");
2635
+ sequenceReadSyntax = core.IMPLICIT_LITTLE_ENDIAN;
2636
+ }
2612
2637
  var punctuatedTag = core.DicomMetaDictionary.punctuateTag(tag);
2613
2638
  var entry = core.DicomMetaDictionary.dictionary[punctuatedTag];
2614
2639
 
2615
2640
  // Include both the string and object values for vr and tag
2616
- var header = {
2641
+ var header = _objectSpread2({
2617
2642
  vrObj: vr,
2618
2643
  vr: vr.type,
2619
2644
  tag: tag,
@@ -2621,7 +2646,9 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2621
2646
  vm: entry === null || entry === void 0 ? void 0 : entry.vm,
2622
2647
  name: entry === null || entry === void 0 ? void 0 : entry.name,
2623
2648
  length: length === core.UNDEFINED_LENGTH ? -1 : length
2624
- };
2649
+ }, sequenceReadSyntax && {
2650
+ sequenceReadSyntax: sequenceReadSyntax
2651
+ });
2625
2652
  return header;
2626
2653
  }
2627
2654
 
@@ -2635,12 +2662,14 @@ var AsyncDicomReader = /*#__PURE__*/function () {
2635
2662
  key: "readSingle",
2636
2663
  value: (function () {
2637
2664
  var _readSingle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(tagInfo, listener, options) {
2665
+ var _options$readSyntax2;
2638
2666
  var length, stream, syntax, vr, values, times, i, _vr$read, value, _vr$read2, _value, delimiterChar, decoder, valuesForListener;
2639
2667
  return _regeneratorRuntime().wrap(function (_context11) {
2640
2668
  while (1) switch (_context11.prev = _context11.next) {
2641
2669
  case 0:
2642
2670
  length = tagInfo.length;
2643
- stream = this.stream, syntax = this.syntax;
2671
+ stream = this.stream;
2672
+ syntax = (_options$readSyntax2 = options === null || options === void 0 ? void 0 : options.readSyntax) !== null && _options$readSyntax2 !== void 0 ? _options$readSyntax2 : this.syntax;
2644
2673
  _context11.next = 1;
2645
2674
  return this.stream.ensureAvailable(length);
2646
2675
  case 1:
@@ -3428,16 +3457,10 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3428
3457
  //
3429
3458
  // shared
3430
3459
  var SpacingBetweenSlices = Math.abs(distance1 - distance0);
3431
- ds.SharedFunctionalGroupsSequence = {
3432
- PlaneOrientationSequence: {
3433
- ImageOrientationPatient: dataset0.ImageOrientationPatient
3434
- },
3435
- PixelMeasuresSequence: {
3436
- PixelSpacing: dataset0.PixelSpacing,
3437
- SpacingBetweenSlices: SpacingBetweenSlices,
3438
- SliceThickness: SpacingBetweenSlices
3439
- }
3440
- };
3460
+ ds.SharedFunctionalGroupsSequence = ImageNormalizer.sharedImagePlaneGroups(dataset0, {
3461
+ SpacingBetweenSlices: SpacingBetweenSlices,
3462
+ SliceThickness: SpacingBetweenSlices
3463
+ });
3441
3464
  ds.ReferencedSeriesSequence = {
3442
3465
  SeriesInstanceUID: dataset0.SeriesInstanceUID,
3443
3466
  ReferencedInstanceSequence: []
@@ -3450,15 +3473,12 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3450
3473
  // and set the referenced series uid
3451
3474
  distanceDatasetPairs.forEach(function (pair) {
3452
3475
  var dataset = pair[1];
3453
- ds.PerFrameFunctionalGroupsSequence.push({
3454
- PlanePositionSequence: {
3455
- ImagePositionPatient: dataset.ImagePositionPatient
3456
- },
3476
+ ds.PerFrameFunctionalGroupsSequence.push(_objectSpread2(_objectSpread2({}, ImageNormalizer.planePositionGroup(dataset)), {}, {
3457
3477
  FrameVOILUTSequence: {
3458
3478
  WindowCenter: dataset.WindowCenter,
3459
3479
  WindowWidth: dataset.WindowWidth
3460
3480
  }
3461
- });
3481
+ }));
3462
3482
  ds.ReferencedSeriesSequence.ReferencedInstanceSequence.push({
3463
3483
  ReferencedSOPClassUID: dataset.SOPClassUID,
3464
3484
  ReferencedSOPInstanceUID: dataset.SOPInstanceUID
@@ -3500,7 +3520,11 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3500
3520
  ds.PresentationLUTShape = "IDENTITY";
3501
3521
  }
3502
3522
  if (!ds.SharedFunctionalGroupsSequence) {
3503
- core.log.error("Can only process multiframe data with SharedFunctionalGroupsSequence");
3523
+ core.log.warn("Missing SharedFunctionalGroupsSequence; using the top-level image plane attributes");
3524
+ ds.SharedFunctionalGroupsSequence = ImageNormalizer.sharedImagePlaneGroups(ds, {
3525
+ SliceThickness: ds.SliceThickness,
3526
+ SpacingBetweenSlices: ds.SpacingBetweenSlices
3527
+ });
3504
3528
  }
3505
3529
 
3506
3530
  // TODO: special case!
@@ -3521,9 +3545,22 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3521
3545
  RescaleSlope: rescaleSlope,
3522
3546
  RescaleType: "US"
3523
3547
  };
3524
- var frameNumber = 1;
3525
- this.datasets.forEach(function (dataset) {
3526
- if (ds.NumberOfFrames === 1) ds.PerFrameFunctionalGroupsSequence = [ds.PerFrameFunctionalGroupsSequence];
3548
+ var frameCount = this.datasets.length;
3549
+ if (!ds.PerFrameFunctionalGroupsSequence) {
3550
+ // One item per declared frame, all at the top-level position
3551
+ frameCount = Math.max(frameCount, Number(ds.NumberOfFrames) || 0);
3552
+ ds.PerFrameFunctionalGroupsSequence = Array.from({
3553
+ length: frameCount
3554
+ }, function () {
3555
+ return ImageNormalizer.planePositionGroup(ds);
3556
+ });
3557
+ } else if (!Array.isArray(ds.PerFrameFunctionalGroupsSequence)) {
3558
+ ds.PerFrameFunctionalGroupsSequence = [ds.PerFrameFunctionalGroupsSequence];
3559
+ }
3560
+ for (var frameNumber = 1; frameNumber <= frameCount; frameNumber++) {
3561
+ var _ds$PerFrameFunctiona, _ref;
3562
+ var dataset = this.datasets[frameNumber - 1] || {};
3563
+ (_ds$PerFrameFunctiona = ds.PerFrameFunctionalGroupsSequence)[_ref = frameNumber - 1] || (_ds$PerFrameFunctiona[_ref] = {});
3527
3564
  ds.PerFrameFunctionalGroupsSequence[frameNumber - 1].FrameContentSequence = {
3528
3565
  FrameAcquisitionDuration: 0,
3529
3566
  StackID: 1,
@@ -3536,8 +3573,7 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3536
3573
  frameContentSequence.FrameAcquisitionDateTime = frameTime;
3537
3574
  frameContentSequence.FrameReferenceDateTime = frameTime;
3538
3575
  }
3539
- frameNumber++;
3540
- });
3576
+ }
3541
3577
 
3542
3578
  //
3543
3579
  // TODO: convert this to shared functional group not top level element
@@ -3622,6 +3658,27 @@ var ImageNormalizer = /*#__PURE__*/function (_Normalizer) {
3622
3658
  value: function vec3Dot(a, b) {
3623
3659
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3624
3660
  }
3661
+ }, {
3662
+ key: "sharedImagePlaneGroups",
3663
+ value: function sharedImagePlaneGroups(dataset, pixelMeasures) {
3664
+ return {
3665
+ PlaneOrientationSequence: {
3666
+ ImageOrientationPatient: dataset.ImageOrientationPatient
3667
+ },
3668
+ PixelMeasuresSequence: _objectSpread2({
3669
+ PixelSpacing: dataset.PixelSpacing
3670
+ }, pixelMeasures)
3671
+ };
3672
+ }
3673
+ }, {
3674
+ key: "planePositionGroup",
3675
+ value: function planePositionGroup(dataset) {
3676
+ return {
3677
+ PlanePositionSequence: {
3678
+ ImagePositionPatient: dataset.ImagePositionPatient
3679
+ }
3680
+ };
3681
+ }
3625
3682
  }]);
3626
3683
  }(Normalizer);
3627
3684
  var MRImageNormalizer = /*#__PURE__*/function (_ImageNormalizer) {
@@ -6410,7 +6467,7 @@ function h(matrix) {
6410
6467
  var _matrix$shape = _slicedToArray(matrix.shape, 2),
6411
6468
  rows = _matrix$shape[0],
6412
6469
  cols = _matrix$shape[1];
6413
- var result = ndarray(new Uint8Array(rows * cols), [rows, cols]);
6470
+ var result = ndarray(new matrix.data.constructor(rows * cols), [rows, cols]);
6414
6471
  for (var i = 0; i < rows; i++) {
6415
6472
  for (var j = 0; j < cols; j++) {
6416
6473
  result.set(i, j, matrix.get(i, cols - 1 - j));
@@ -6429,7 +6486,7 @@ function v(matrix) {
6429
6486
  var _matrix$shape2 = _slicedToArray(matrix.shape, 2),
6430
6487
  rows = _matrix$shape2[0],
6431
6488
  cols = _matrix$shape2[1];
6432
- var result = ndarray(new Uint8Array(rows * cols), [rows, cols]);
6489
+ var result = ndarray(new matrix.data.constructor(rows * cols), [rows, cols]);
6433
6490
  for (var j = 0; j < cols; j++) {
6434
6491
  for (var i = 0; i < rows; i++) {
6435
6492
  result.set(i, j, matrix.get(rows - 1 - i, j));
@@ -6448,7 +6505,7 @@ function rotateMatrix902D (matrix) {
6448
6505
  var _matrix$shape = _slicedToArray(matrix.shape, 2),
6449
6506
  rows = _matrix$shape[0],
6450
6507
  cols = _matrix$shape[1];
6451
- var result = ndarray(new Uint8Array(rows * cols), [cols, rows]);
6508
+ var result = ndarray(new matrix.data.constructor(rows * cols), [cols, rows]);
6452
6509
  var resultColsMinus1 = result.shape[1] - 1;
6453
6510
  for (var i = 0; i < rows; i++) {
6454
6511
  for (var j = 0; j < cols; j++) {
@@ -12730,6 +12787,11 @@ var DICOMMicroscopyViewer = {
12730
12787
  MeasurementReport: MeasurementReport$1
12731
12788
  };
12732
12789
 
12790
+ /**
12791
+ * @deprecated The adapters moved to `@cornerstonejs/adapters`. Import them
12792
+ * from that package. `@dcmjs-org/dcmjs` keeps this export only for
12793
+ * compatibility with 0.x, and a later major release removes it.
12794
+ */
12733
12795
  var adapters = {
12734
12796
  Cornerstone: Cornerstone,
12735
12797
  Cornerstone3D: Cornerstone3D,
@@ -15931,4 +15993,4 @@ exports.derivations = derivations;
15931
15993
  exports.normalizers = normalizers;
15932
15994
  exports.sr = sr;
15933
15995
  exports.utilities = utilities;
15934
- //# sourceMappingURL=dcmjs.shared---E7clvy.cjs.map
15996
+ //# sourceMappingURL=dcmjs.shared-L4OH_Ab_.cjs.map