@cornerstonejs/adapters 1.57.0 → 1.57.2

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.
@@ -40956,7 +40956,7 @@ class Viewport {
40956
40956
  getCurrentImageIdIndex() {
40957
40957
  throw new Error('Not implemented');
40958
40958
  }
40959
- getTargetId(specifier) {
40959
+ getReferenceId(specifier) {
40960
40960
  return null;
40961
40961
  }
40962
40962
  setPan(pan, storeAsInitialCamera = false) {
@@ -41233,6 +41233,32 @@ class Viewport {
41233
41233
  heightWorld: maxY - minY
41234
41234
  };
41235
41235
  }
41236
+ getViewReference(viewRefSpecifier = {}) {
41237
+ const {
41238
+ focalPoint: cameraFocalPoint,
41239
+ viewPlaneNormal
41240
+ } = this.getCamera();
41241
+ const target = {
41242
+ FrameOfReferenceUID: this.getFrameOfReferenceUID(),
41243
+ cameraFocalPoint,
41244
+ viewPlaneNormal,
41245
+ sliceIndex: viewRefSpecifier.sliceIndex ?? this.getCurrentImageIdIndex()
41246
+ };
41247
+ return target;
41248
+ }
41249
+ isReferenceViewable(viewRef, options) {
41250
+ if (viewRef.FrameOfReferenceUID && viewRef.FrameOfReferenceUID !== this.getFrameOfReferenceUID()) {
41251
+ return false;
41252
+ }
41253
+ const {
41254
+ viewPlaneNormal
41255
+ } = viewRef;
41256
+ const camera = this.getCamera();
41257
+ if (!isEqual$2(viewPlaneNormal, camera.viewPlaneNormal) && !isEqual$2(vec3.negate(camera.viewPlaneNormal, camera.viewPlaneNormal), viewPlaneNormal)) {
41258
+ return options?.asVolume === true;
41259
+ }
41260
+ return true;
41261
+ }
41236
41262
  _shouldUseNativeDataType() {
41237
41263
  const {
41238
41264
  useNorm16Texture,
@@ -41713,6 +41739,32 @@ class BaseVolumeViewport extends Viewport$1 {
41713
41739
  this.resetToDefaultProperties(volumeId);
41714
41740
  }
41715
41741
  }
41742
+ getViewReference(viewRefSpecifier = {}) {
41743
+ const target = super.getViewReference(viewRefSpecifier);
41744
+ if (viewRefSpecifier?.forFrameOfReference !== false) {
41745
+ target.volumeId = this.getVolumeId(viewRefSpecifier);
41746
+ }
41747
+ return {
41748
+ ...target,
41749
+ sliceIndex: this.getCurrentImageIdIndex()
41750
+ };
41751
+ }
41752
+ isReferenceViewable(viewRef, options) {
41753
+ if (!super.isReferenceViewable(viewRef, options)) {
41754
+ return false;
41755
+ }
41756
+ if (options?.withNavigation) {
41757
+ return true;
41758
+ }
41759
+ const currentSliceIndex = this.getCurrentImageIdIndex();
41760
+ const {
41761
+ sliceIndex
41762
+ } = viewRef;
41763
+ if (Array.isArray(sliceIndex)) {
41764
+ return sliceIndex[0] <= currentSliceIndex && currentSliceIndex <= sliceIndex[1];
41765
+ }
41766
+ return sliceIndex === undefined || sliceIndex === currentSliceIndex;
41767
+ }
41716
41768
  setProperties({
41717
41769
  voiRange,
41718
41770
  VOILUTFunction,
@@ -42017,10 +42069,20 @@ class BaseVolumeViewport extends Viewport$1 {
42017
42069
  const voxelIndex = index[2] * dimensions[0] * dimensions[1] + index[1] * dimensions[0] + index[0];
42018
42070
  return volume.getScalarData()[voxelIndex];
42019
42071
  }
42020
- getTargetId(specifier = {}) {
42072
+ getVolumeId(specifier) {
42073
+ if (!specifier?.volumeId) {
42074
+ const actorEntries = this.getActors();
42075
+ if (!actorEntries) {
42076
+ return;
42077
+ }
42078
+ return actorEntries.find(actorEntry => actorEntry.actor.getClassName() === 'vtkVolume')?.uid;
42079
+ }
42080
+ return specifier.volumeId;
42081
+ }
42082
+ getReferenceId(specifier = {}) {
42021
42083
  let {
42022
42084
  volumeId,
42023
- sliceIndex
42085
+ sliceIndex: sliceIndex
42024
42086
  } = specifier;
42025
42087
  if (!volumeId) {
42026
42088
  const actorEntries = this.getActors();
@@ -46167,11 +46229,52 @@ class StackViewport extends Viewport$1 {
46167
46229
  }
46168
46230
  return voiLUTFunction;
46169
46231
  }
46170
- getTargetId(specifier = {}) {
46232
+ isReferenceViewable(viewRef, options = {}) {
46233
+ if (!super.isReferenceViewable(viewRef, options)) {
46234
+ return false;
46235
+ }
46236
+ let {
46237
+ imageURI
46238
+ } = options;
46171
46239
  const {
46172
- sliceIndex: imageIdIndex = this.currentImageIdIndex
46240
+ referencedImageId,
46241
+ sliceIndex
46242
+ } = viewRef;
46243
+ if (viewRef.volumeId && !referencedImageId) {
46244
+ return options.asVolume === true;
46245
+ }
46246
+ let testIndex = this.getCurrentImageIdIndex();
46247
+ if (options.withNavigation && typeof sliceIndex === 'number') {
46248
+ testIndex = sliceIndex;
46249
+ }
46250
+ const imageId = this.imageIds[testIndex];
46251
+ if (!imageId) {
46252
+ return false;
46253
+ }
46254
+ if (!imageURI) {
46255
+ const colonIndex = imageId.indexOf(':');
46256
+ imageURI = imageId.substring(colonIndex + 1);
46257
+ }
46258
+ return referencedImageId.endsWith(imageURI);
46259
+ }
46260
+ getViewReference(viewRefSpecifier = {}) {
46261
+ const {
46262
+ sliceIndex = this.currentImageIdIndex
46263
+ } = viewRefSpecifier;
46264
+ return {
46265
+ ...super.getViewReference(viewRefSpecifier),
46266
+ referencedImageId: `${this.imageIds[sliceIndex]}`,
46267
+ sliceIndex: sliceIndex
46268
+ };
46269
+ }
46270
+ getReferenceId(specifier = {}) {
46271
+ const {
46272
+ sliceIndex = this.currentImageIdIndex
46173
46273
  } = specifier;
46174
- return `imageId:${this.imageIds[imageIdIndex]}`;
46274
+ if (Array.isArray(sliceIndex)) {
46275
+ throw new Error('Use of slice ranges for stacks not supported');
46276
+ }
46277
+ return `imageId:${this.imageIds[sliceIndex]}`;
46175
46278
  }
46176
46279
  getCPUFallbackError(method) {
46177
46280
  return new Error(`method ${method} cannot be used during CPU Fallback mode`);
@@ -46611,6 +46714,14 @@ class VideoViewport extends Viewport$1 {
46611
46714
  time: this.videoElement.currentTime,
46612
46715
  duration: this.videoElement.duration
46613
46716
  });
46717
+ triggerEvent(this.element, EVENTS.IMAGE_RENDERED, {
46718
+ element: this.element,
46719
+ viewportId: this.id,
46720
+ viewport: this,
46721
+ renderingEngineId: this.renderingEngineId,
46722
+ time: this.videoElement.currentTime,
46723
+ duration: this.videoElement.duration
46724
+ });
46614
46725
  const frame = this.getFrameNumber();
46615
46726
  if (this.isPlaying) {
46616
46727
  if (frame < this.frameRange[0]) {
@@ -47010,16 +47121,67 @@ class VideoViewport extends Viewport$1 {
47010
47121
  const current = this.imageId.replace('/frames/1', this.isPlaying ? `/frames/${this.frameRange[0]}-${this.frameRange[1]}` : `/frames/${this.getFrameNumber()}`);
47011
47122
  return current;
47012
47123
  }
47013
- getTargetId(specifier = {}) {
47124
+ getReferenceId(specifier = {}) {
47014
47125
  const {
47015
- sliceIndex
47126
+ sliceIndex: sliceIndex
47016
47127
  } = specifier;
47017
47128
  if (sliceIndex === undefined) {
47018
47129
  return `videoId:${this.getCurrentImageId()}`;
47019
47130
  }
47131
+ if (Array.isArray(sliceIndex)) {
47132
+ return `videoId:${this.imageId.substring(0, this.imageId.length - 1)}${sliceIndex[0] + 1}-${sliceIndex[1] + 1}`;
47133
+ }
47020
47134
  const baseTarget = this.imageId.replace('/frames/1', `/frames/${1 + sliceIndex}`);
47021
47135
  return `videoId:${baseTarget}`;
47022
47136
  }
47137
+ isReferenceViewable(viewRef, options = {}) {
47138
+ let {
47139
+ imageURI
47140
+ } = options;
47141
+ const {
47142
+ referencedImageId,
47143
+ sliceIndex: sliceIndex
47144
+ } = viewRef;
47145
+ if (!super.isReferenceViewable(viewRef)) {
47146
+ return false;
47147
+ }
47148
+ const imageId = this.getCurrentImageId();
47149
+ if (!imageURI) {
47150
+ const colonIndex = imageId.indexOf(':');
47151
+ imageURI = imageId.substring(colonIndex + 1, imageId.length - 1);
47152
+ }
47153
+ if (options.withNavigation) {
47154
+ return true;
47155
+ }
47156
+ const currentIndex = this.getCurrentImageIdIndex();
47157
+ if (Array.isArray(sliceIndex)) {
47158
+ return currentIndex >= sliceIndex[0] && currentIndex <= sliceIndex[1];
47159
+ }
47160
+ if (sliceIndex !== undefined) {
47161
+ return currentIndex === sliceIndex;
47162
+ }
47163
+ if (!referencedImageId) {
47164
+ return false;
47165
+ }
47166
+ const match = referencedImageId.match(VideoViewport.frameRangeExtractor);
47167
+ if (!match || !match[2]) {
47168
+ return true;
47169
+ }
47170
+ const range = match[2].split('-').map(it => Number(it));
47171
+ const frame = currentIndex + 1;
47172
+ return range[0] <= frame && frame <= (range[1] ?? range[0]);
47173
+ }
47174
+ getViewReference(viewRefSpecifier) {
47175
+ let sliceIndex = viewRefSpecifier?.sliceIndex;
47176
+ if (!sliceIndex) {
47177
+ sliceIndex = this.isPlaying ? [this.frameRange[0] - 1, this.frameRange[1] - 1] : this.getCurrentImageIdIndex();
47178
+ }
47179
+ return {
47180
+ ...super.getViewReference(viewRefSpecifier),
47181
+ referencedImageId: this.getReferenceId(viewRefSpecifier),
47182
+ sliceIndex: sliceIndex
47183
+ };
47184
+ }
47023
47185
  getFrameNumber() {
47024
47186
  return 1 + this.getCurrentImageIdIndex();
47025
47187
  }
@@ -49208,8 +49370,11 @@ function getInterpolationData(viewportData, filterParams = []) {
49208
49370
  } = viewportData;
49209
49371
  const interpolationDatas = new Map();
49210
49372
  const annotations = getAnnotations(annotation.metadata.toolName, viewport.element);
49373
+ if (!annotations) {
49374
+ return interpolationDatas;
49375
+ }
49211
49376
  for (let i = 0; i < sliceData.numberOfSlices; i++) {
49212
- const imageAnnotations = annotations.filter(x => x.metadata.referencedSliceIndex === i);
49377
+ const imageAnnotations = annotations.filter(x => x.metadata.sliceIndex === i);
49213
49378
  if (!imageAnnotations?.length) {
49214
49379
  continue;
49215
49380
  }
@@ -49286,6 +49451,10 @@ function findAnnotationsForInterpolation(toolData, viewportData) {
49286
49451
  value: viewportData.interpolationUID
49287
49452
  }]);
49288
49453
  const rangeToInterpolate = getRangeToInterpolate(interpolationData);
49454
+ if (!rangeToInterpolate) {
49455
+ console.warn('No annotations found to interpolate', interpolationData);
49456
+ return;
49457
+ }
49289
49458
  const sliceEdited = _getSlicePositionOfToolData(interpolationData, toolData.annotationUID);
49290
49459
  const interpolationList = [];
49291
49460
  for (let i = rangeToInterpolate[0] + 1; i < rangeToInterpolate[1]; i++) {
@@ -49584,7 +49753,10 @@ function startInterpolation(viewportData) {
49584
49753
  const {
49585
49754
  interpolationData,
49586
49755
  interpolationList
49587
- } = findAnnotationsForInterpolation(toolData, viewportData);
49756
+ } = findAnnotationsForInterpolation(toolData, viewportData) || {};
49757
+ if (!interpolationData || !interpolationList) {
49758
+ return;
49759
+ }
49588
49760
  const eventData = {
49589
49761
  toolName: toolData.metadata.toolName,
49590
49762
  toolType: toolData.metadata.toolName,
@@ -49641,11 +49813,11 @@ function _addInterpolatedContour(interpolated3DPoints, handlePoints, sliceIndex,
49641
49813
  viewport
49642
49814
  } = eventData;
49643
49815
  const interpolatedAnnotation = createPolylineToolData(points, handlePoints, referencedToolData);
49644
- const targetId = viewport.getTargetId({
49816
+ const targetId = viewport.getReferenceId({
49645
49817
  sliceIndex
49646
49818
  });
49647
49819
  interpolatedAnnotation.metadata.referencedImageId = targetId;
49648
- interpolatedAnnotation.metadata.referencedSliceIndex = sliceIndex;
49820
+ interpolatedAnnotation.metadata.sliceIndex = sliceIndex;
49649
49821
  addAnnotation(interpolatedAnnotation, viewport.element);
49650
49822
  referencedToolData.onInterpolationComplete?.(interpolatedAnnotation, referencedToolData);
49651
49823
  }
@@ -49657,7 +49829,7 @@ function _editInterpolatedContour(interpolated3DPoints, handlePoints, sliceIndex
49657
49829
  let toolDataIndex;
49658
49830
  for (let i = 0; i < annotations.length; i++) {
49659
49831
  const annotation = annotations[i];
49660
- if (annotation.interpolationUID === referencedToolData.interpolationUID && annotation.metadata.referencedSliceIndex === sliceIndex) {
49832
+ if (annotation.interpolationUID === referencedToolData.interpolationUID && annotation.metadata.sliceIndex === sliceIndex) {
49661
49833
  toolDataIndex = i;
49662
49834
  break;
49663
49835
  }
@@ -49884,7 +50056,7 @@ function deleteRelatedAnnotations(viewportData) {
49884
50056
  key: 'interpolationUID',
49885
50057
  value: viewportData.interpolationUID
49886
50058
  }]);
49887
- const referencedSliceIndex = annotation.metadata.referencedSliceIndex;
50059
+ const referencedSliceIndex = annotation.metadata.sliceIndex;
49888
50060
  let minInterpolation = -1;
49889
50061
  let maxInterpolation = viewportData.sliceData.numberOfSlices;
49890
50062
  for (const [sliceIndex, annotations] of interpolationAnnotations.entries()) {
@@ -49928,7 +50100,7 @@ function deleteRelatedAnnotations(viewportData) {
49928
50100
  viewport: viewportData.viewport,
49929
50101
  sliceData: {
49930
50102
  numberOfSlices: viewportData.sliceData.numberOfSlices,
49931
- imageIndex: nextAnnotation.metadata.referencedSliceIndex
50103
+ imageIndex: nextAnnotation.metadata.sliceIndex
49932
50104
  },
49933
50105
  annotation: nextAnnotation,
49934
50106
  interpolationUID: nextAnnotation.interpolationUID
@@ -49974,7 +50146,7 @@ class InterpolationManager {
49974
50146
  if (segmentIndex && segmentIndex !== data.segmentation.segmentIndex) {
49975
50147
  continue;
49976
50148
  }
49977
- if (sliceIndex !== undefined && metadata && sliceIndex !== metadata.referencedSliceIndex) {
50149
+ if (sliceIndex !== undefined && metadata && sliceIndex !== metadata.sliceIndex) {
49978
50150
  continue;
49979
50151
  }
49980
50152
  if (segmentationId && segmentationId !== data.segmentation.segmentationId) {