@cornerstonejs/adapters 1.56.2 → 1.57.1

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.
@@ -5072,6 +5072,7 @@ var Events$2;
5072
5072
  Events["CAMERA_MODIFIED"] = "CORNERSTONE_CAMERA_MODIFIED";
5073
5073
  Events["CAMERA_RESET"] = "CORNERSTONE_CAMERA_RESET";
5074
5074
  Events["VOI_MODIFIED"] = "CORNERSTONE_VOI_MODIFIED";
5075
+ Events["PRESET_MODIFIED"] = "CORNERSTONE_VIEWPORT_RENDERING_PRESET_MODIFIED";
5075
5076
  Events["DISPLAY_AREA_MODIFIED"] = "CORNERSTONE_DISPLAY_AREA_MODIFIED";
5076
5077
  Events["ELEMENT_DISABLED"] = "CORNERSTONE_ELEMENT_DISABLED";
5077
5078
  Events["ELEMENT_ENABLED"] = "CORNERSTONE_ELEMENT_ENABLED";
@@ -38139,24 +38140,26 @@ function applyPreset(actor, preset) {
38139
38140
  normPoints.push([value, opacity]);
38140
38141
  }
38141
38142
  applyPointsToPiecewiseFunction(normPoints, shiftRange, ofun);
38142
- actor.getProperty().setScalarOpacity(0, ofun);
38143
+ const property = actor.getProperty();
38144
+ property.setScalarOpacity(0, ofun);
38143
38145
  const [gradientMinValue, gradientMinOpacity, gradientMaxValue, gradientMaxOpacity] = preset.gradientOpacity.split(' ').splice(1).map(parseFloat);
38144
- actor.getProperty().setUseGradientOpacity(0, true);
38145
- actor.getProperty().setGradientOpacityMinimumValue(0, gradientMinValue);
38146
- actor.getProperty().setGradientOpacityMinimumOpacity(0, gradientMinOpacity);
38147
- actor.getProperty().setGradientOpacityMaximumValue(0, gradientMaxValue);
38148
- actor.getProperty().setGradientOpacityMaximumOpacity(0, gradientMaxOpacity);
38146
+ property.setUseGradientOpacity(0, true);
38147
+ property.setGradientOpacityMinimumValue(0, gradientMinValue);
38148
+ property.setGradientOpacityMinimumOpacity(0, gradientMinOpacity);
38149
+ property.setGradientOpacityMaximumValue(0, gradientMaxValue);
38150
+ property.setGradientOpacityMaximumOpacity(0, gradientMaxOpacity);
38149
38151
  if (preset.interpolation === '1') {
38150
- actor.getProperty().setInterpolationTypeToFastLinear();
38152
+ property.setInterpolationTypeToFastLinear();
38151
38153
  }
38154
+ property.setShade(preset.shade === '1');
38152
38155
  const ambient = parseFloat(preset.ambient);
38153
38156
  const diffuse = parseFloat(preset.diffuse);
38154
38157
  const specular = parseFloat(preset.specular);
38155
38158
  const specularPower = parseFloat(preset.specularPower);
38156
- actor.getProperty().setAmbient(ambient);
38157
- actor.getProperty().setDiffuse(diffuse);
38158
- actor.getProperty().setSpecular(specular);
38159
- actor.getProperty().setSpecularPower(specularPower);
38159
+ property.setAmbient(ambient);
38160
+ property.setDiffuse(diffuse);
38161
+ property.setSpecular(specular);
38162
+ property.setSpecularPower(specularPower);
38160
38163
  }
38161
38164
  function getShiftRange(colorTransferArray) {
38162
38165
  let min = Infinity;
@@ -40953,7 +40956,7 @@ class Viewport {
40953
40956
  getCurrentImageIdIndex() {
40954
40957
  throw new Error('Not implemented');
40955
40958
  }
40956
- getTargetId(specifier) {
40959
+ getReferenceId(specifier) {
40957
40960
  return null;
40958
40961
  }
40959
40962
  setPan(pan, storeAsInitialCamera = false) {
@@ -41230,6 +41233,32 @@ class Viewport {
41230
41233
  heightWorld: maxY - minY
41231
41234
  };
41232
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
+ }
41233
41262
  _shouldUseNativeDataType() {
41234
41263
  const {
41235
41264
  useNorm16Texture,
@@ -41710,6 +41739,32 @@ class BaseVolumeViewport extends Viewport$1 {
41710
41739
  this.resetToDefaultProperties(volumeId);
41711
41740
  }
41712
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
+ }
41713
41768
  setProperties({
41714
41769
  voiRange,
41715
41770
  VOILUTFunction,
@@ -41786,7 +41841,7 @@ class BaseVolumeViewport extends Viewport$1 {
41786
41841
  }
41787
41842
  this.render();
41788
41843
  }
41789
- setPreset(presetName, volumeId, suppressEvents) {
41844
+ setPreset(presetNameOrObj, volumeId, suppressEvents) {
41790
41845
  const applicableVolumeActorInfo = this._getApplicableVolumeActor(volumeId);
41791
41846
  if (!applicableVolumeActorInfo) {
41792
41847
  return;
@@ -41794,14 +41849,24 @@ class BaseVolumeViewport extends Viewport$1 {
41794
41849
  const {
41795
41850
  volumeActor
41796
41851
  } = applicableVolumeActorInfo;
41797
- const preset = VIEWPORT_PRESETS.find(preset => {
41798
- return preset.name === presetName;
41799
- });
41852
+ let preset = presetNameOrObj;
41853
+ if (typeof preset === 'string') {
41854
+ preset = VIEWPORT_PRESETS.find(preset => {
41855
+ return preset.name === presetNameOrObj;
41856
+ });
41857
+ }
41800
41858
  if (!preset) {
41801
41859
  return;
41802
41860
  }
41803
41861
  applyPreset(volumeActor, preset);
41804
- this.viewportProperties.preset = presetName;
41862
+ if (!suppressEvents) {
41863
+ triggerEvent(this.element, EVENTS.PRESET_MODIFIED, {
41864
+ viewportId: this.id,
41865
+ volumeId: applicableVolumeActorInfo.volumeId,
41866
+ actor: volumeActor,
41867
+ presetName: preset.name
41868
+ });
41869
+ }
41805
41870
  }
41806
41871
  async setVolumes(volumeInputArray, immediate = false, suppressEvents = false) {
41807
41872
  const firstImageVolume = cache$1.getVolume(volumeInputArray[0].volumeId);
@@ -42004,10 +42069,20 @@ class BaseVolumeViewport extends Viewport$1 {
42004
42069
  const voxelIndex = index[2] * dimensions[0] * dimensions[1] + index[1] * dimensions[0] + index[0];
42005
42070
  return volume.getScalarData()[voxelIndex];
42006
42071
  }
42007
- 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 = {}) {
42008
42083
  let {
42009
42084
  volumeId,
42010
- sliceIndex
42085
+ sliceIndex: sliceIndex
42011
42086
  } = specifier;
42012
42087
  if (!volumeId) {
42013
42088
  const actorEntries = this.getActors();
@@ -46154,11 +46229,52 @@ class StackViewport extends Viewport$1 {
46154
46229
  }
46155
46230
  return voiLUTFunction;
46156
46231
  }
46157
- getTargetId(specifier = {}) {
46232
+ isReferenceViewable(viewRef, options = {}) {
46233
+ if (!super.isReferenceViewable(viewRef, options)) {
46234
+ return false;
46235
+ }
46236
+ let {
46237
+ imageURI
46238
+ } = options;
46239
+ const {
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 = {}) {
46158
46271
  const {
46159
- sliceIndex: imageIdIndex = this.currentImageIdIndex
46272
+ sliceIndex = this.currentImageIdIndex
46160
46273
  } = specifier;
46161
- 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]}`;
46162
46278
  }
46163
46279
  getCPUFallbackError(method) {
46164
46280
  return new Error(`method ${method} cannot be used during CPU Fallback mode`);
@@ -46598,6 +46714,14 @@ class VideoViewport extends Viewport$1 {
46598
46714
  time: this.videoElement.currentTime,
46599
46715
  duration: this.videoElement.duration
46600
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
+ });
46601
46725
  const frame = this.getFrameNumber();
46602
46726
  if (this.isPlaying) {
46603
46727
  if (frame < this.frameRange[0]) {
@@ -46997,16 +47121,67 @@ class VideoViewport extends Viewport$1 {
46997
47121
  const current = this.imageId.replace('/frames/1', this.isPlaying ? `/frames/${this.frameRange[0]}-${this.frameRange[1]}` : `/frames/${this.getFrameNumber()}`);
46998
47122
  return current;
46999
47123
  }
47000
- getTargetId(specifier = {}) {
47124
+ getReferenceId(specifier = {}) {
47001
47125
  const {
47002
- sliceIndex
47126
+ sliceIndex: sliceIndex
47003
47127
  } = specifier;
47004
47128
  if (sliceIndex === undefined) {
47005
47129
  return `videoId:${this.getCurrentImageId()}`;
47006
47130
  }
47131
+ if (Array.isArray(sliceIndex)) {
47132
+ return `videoId:${this.imageId.substring(0, this.imageId.length - 1)}${sliceIndex[0] + 1}-${sliceIndex[1] + 1}`;
47133
+ }
47007
47134
  const baseTarget = this.imageId.replace('/frames/1', `/frames/${1 + sliceIndex}`);
47008
47135
  return `videoId:${baseTarget}`;
47009
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
+ }
47010
47185
  getFrameNumber() {
47011
47186
  return 1 + this.getCurrentImageIdIndex();
47012
47187
  }
@@ -49195,8 +49370,11 @@ function getInterpolationData(viewportData, filterParams = []) {
49195
49370
  } = viewportData;
49196
49371
  const interpolationDatas = new Map();
49197
49372
  const annotations = getAnnotations(annotation.metadata.toolName, viewport.element);
49373
+ if (!annotations) {
49374
+ return interpolationDatas;
49375
+ }
49198
49376
  for (let i = 0; i < sliceData.numberOfSlices; i++) {
49199
- const imageAnnotations = annotations.filter(x => x.metadata.referencedSliceIndex === i);
49377
+ const imageAnnotations = annotations.filter(x => x.metadata.sliceIndex === i);
49200
49378
  if (!imageAnnotations?.length) {
49201
49379
  continue;
49202
49380
  }
@@ -49273,6 +49451,10 @@ function findAnnotationsForInterpolation(toolData, viewportData) {
49273
49451
  value: viewportData.interpolationUID
49274
49452
  }]);
49275
49453
  const rangeToInterpolate = getRangeToInterpolate(interpolationData);
49454
+ if (!rangeToInterpolate) {
49455
+ console.warn('No annotations found to interpolate', interpolationData);
49456
+ return;
49457
+ }
49276
49458
  const sliceEdited = _getSlicePositionOfToolData(interpolationData, toolData.annotationUID);
49277
49459
  const interpolationList = [];
49278
49460
  for (let i = rangeToInterpolate[0] + 1; i < rangeToInterpolate[1]; i++) {
@@ -49571,7 +49753,10 @@ function startInterpolation(viewportData) {
49571
49753
  const {
49572
49754
  interpolationData,
49573
49755
  interpolationList
49574
- } = findAnnotationsForInterpolation(toolData, viewportData);
49756
+ } = findAnnotationsForInterpolation(toolData, viewportData) || {};
49757
+ if (!interpolationData || !interpolationList) {
49758
+ return;
49759
+ }
49575
49760
  const eventData = {
49576
49761
  toolName: toolData.metadata.toolName,
49577
49762
  toolType: toolData.metadata.toolName,
@@ -49628,11 +49813,11 @@ function _addInterpolatedContour(interpolated3DPoints, handlePoints, sliceIndex,
49628
49813
  viewport
49629
49814
  } = eventData;
49630
49815
  const interpolatedAnnotation = createPolylineToolData(points, handlePoints, referencedToolData);
49631
- const targetId = viewport.getTargetId({
49816
+ const targetId = viewport.getReferenceId({
49632
49817
  sliceIndex
49633
49818
  });
49634
49819
  interpolatedAnnotation.metadata.referencedImageId = targetId;
49635
- interpolatedAnnotation.metadata.referencedSliceIndex = sliceIndex;
49820
+ interpolatedAnnotation.metadata.sliceIndex = sliceIndex;
49636
49821
  addAnnotation(interpolatedAnnotation, viewport.element);
49637
49822
  referencedToolData.onInterpolationComplete?.(interpolatedAnnotation, referencedToolData);
49638
49823
  }
@@ -49644,7 +49829,7 @@ function _editInterpolatedContour(interpolated3DPoints, handlePoints, sliceIndex
49644
49829
  let toolDataIndex;
49645
49830
  for (let i = 0; i < annotations.length; i++) {
49646
49831
  const annotation = annotations[i];
49647
- if (annotation.interpolationUID === referencedToolData.interpolationUID && annotation.metadata.referencedSliceIndex === sliceIndex) {
49832
+ if (annotation.interpolationUID === referencedToolData.interpolationUID && annotation.metadata.sliceIndex === sliceIndex) {
49648
49833
  toolDataIndex = i;
49649
49834
  break;
49650
49835
  }
@@ -49871,7 +50056,7 @@ function deleteRelatedAnnotations(viewportData) {
49871
50056
  key: 'interpolationUID',
49872
50057
  value: viewportData.interpolationUID
49873
50058
  }]);
49874
- const referencedSliceIndex = annotation.metadata.referencedSliceIndex;
50059
+ const referencedSliceIndex = annotation.metadata.sliceIndex;
49875
50060
  let minInterpolation = -1;
49876
50061
  let maxInterpolation = viewportData.sliceData.numberOfSlices;
49877
50062
  for (const [sliceIndex, annotations] of interpolationAnnotations.entries()) {
@@ -49915,7 +50100,7 @@ function deleteRelatedAnnotations(viewportData) {
49915
50100
  viewport: viewportData.viewport,
49916
50101
  sliceData: {
49917
50102
  numberOfSlices: viewportData.sliceData.numberOfSlices,
49918
- imageIndex: nextAnnotation.metadata.referencedSliceIndex
50103
+ imageIndex: nextAnnotation.metadata.sliceIndex
49919
50104
  },
49920
50105
  annotation: nextAnnotation,
49921
50106
  interpolationUID: nextAnnotation.interpolationUID
@@ -49961,7 +50146,7 @@ class InterpolationManager {
49961
50146
  if (segmentIndex && segmentIndex !== data.segmentation.segmentIndex) {
49962
50147
  continue;
49963
50148
  }
49964
- if (sliceIndex !== undefined && metadata && sliceIndex !== metadata.referencedSliceIndex) {
50149
+ if (sliceIndex !== undefined && metadata && sliceIndex !== metadata.sliceIndex) {
49965
50150
  continue;
49966
50151
  }
49967
50152
  if (segmentationId && segmentationId !== data.segmentation.segmentationId) {