@cornerstonejs/core 5.10.8 → 5.10.10

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.
@@ -1,6 +1,6 @@
1
1
  import type { vtkImageData as vtkImageDataType } from '@kitware/vtk.js/Common/DataModel/ImageData';
2
2
  import { mat4 } from 'gl-matrix';
3
- import type { ActorEntry, CPUIImageData, ICamera, IImage, IImageData, IImagesLoader, IStackInput, ImageLoadListener, Mat3, Point2, Point3, Scaling, StackViewportProperties, ViewReference, ViewReferenceSpecifier, ReferenceCompatibleOptions, ViewportInput, ImagePixelModule, ImagePlaneModule } from '../types/index.js';
3
+ import type { ActorEntry, CPUIImageData, ICamera, IImage, IImageData, IImagesLoader, IStackInput, ImageLoadListener, Mat3, Point2, Point3, Scaling, StackViewportProperties, ViewReference, ViewReferenceSpecifier, ReferenceCompatibleOptions, ViewportInput, ImagePixelModule, ImagePlaneModule, ResetCameraOptions, SetAspectRatioOptions } from '../types/index.js';
4
4
  import Viewport from './Viewport.js';
5
5
  import { InterpolationType, RequestType, ViewportStatus } from '../enums/index.js';
6
6
  import type vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
@@ -59,12 +59,8 @@ declare class StackViewport extends Viewport {
59
59
  setCamera: (cameraInterface: ICamera, storeAsInitialCamera?: boolean) => void;
60
60
  getRotation: () => number;
61
61
  unsetColormap: () => void;
62
- resetCamera: (options?: {
63
- resetPan?: boolean;
64
- resetZoom?: boolean;
65
- resetToCenter?: boolean;
62
+ resetCamera: (options?: ResetCameraOptions & {
66
63
  suppressEvents?: boolean;
67
- resetAspectRatio?: boolean;
68
64
  }) => boolean;
69
65
  canvasToWorld: (canvasPos: Point2) => Point3;
70
66
  worldToCanvas: (worldPos: Point3) => Point2;
@@ -106,13 +102,14 @@ declare class StackViewport extends Viewport {
106
102
  private _setPropertiesFromCache;
107
103
  private getCameraCPU;
108
104
  private setAspectRatioForViewport;
105
+ private getFitParallelScaleCPU;
109
106
  private setCameraCPU;
110
107
  private getPanCPU;
111
108
  private setPanCPU;
112
109
  private getZoomCPU;
113
110
  private setZoomCPU;
114
111
  getAspectRatioCPU(): Point2;
115
- setAspectRatioCPU(value: Point2, isFitViewportAfterStretch?: boolean, storeAsInitialCamera?: boolean): void;
112
+ setAspectRatioCPU(value: Point2, options?: SetAspectRatioOptions): void;
116
113
  private setFlipCPU;
117
114
  private getRotationCPU;
118
115
  private getRotationGPU;
@@ -46,6 +46,7 @@ import uuidv4 from '../utilities/uuidv4.js';
46
46
  import getSpacingInNormalDirection from '../utilities/getSpacingInNormalDirection.js';
47
47
  import getClosestImageId from '../utilities/getClosestImageId.js';
48
48
  import { adjustInitialViewUp } from '../utilities/adjustInitialViewUp.js';
49
+ import { getNormalizedAspectRatio } from '../utilities/getNormalizedAspectRatio.js';
49
50
  import { isContextPoolRenderingEngine } from './helpers/isContextPoolRenderingEngine.js';
50
51
  import { createSharpeningRenderPass, createSmoothingRenderPass, } from './renderPasses/index.js';
51
52
  const log = coreLog.getLogger('RenderingEngine', 'StackViewport');
@@ -425,13 +426,12 @@ class StackViewport extends Viewport {
425
426
  },
426
427
  resetCamera: {
427
428
  cpu: (options = {}) => {
428
- const { resetPan = true, resetZoom = true } = options;
429
- this.resetCameraCPU({ resetPan, resetZoom });
429
+ const { resetPan = true, resetZoom = true, resetAspectRatio = true, } = options;
430
+ this.resetCameraCPU({ resetPan, resetZoom, resetAspectRatio });
430
431
  return true;
431
432
  },
432
433
  gpu: (options = {}) => {
433
- const { resetPan = true, resetZoom = true, resetAspectRatio = true, } = options;
434
- this.resetCameraGPU({ resetPan, resetZoom, resetAspectRatio });
434
+ this.resetCameraGPU(options);
435
435
  return true;
436
436
  },
437
437
  },
@@ -858,40 +858,28 @@ class StackViewport extends Viewport {
858
858
  flipVertical: this.flipVertical,
859
859
  };
860
860
  }
861
- setAspectRatioForViewport(aspectRatio, isFitViewportAfterStretch = true) {
862
- const { viewport, image } = this._cpuFallbackEnabledElement;
863
- if (!isFitViewportAfterStretch) {
864
- viewport.aspectRatio = aspectRatio;
865
- return;
866
- }
861
+ setAspectRatioForViewport(aspectRatio) {
862
+ const { viewport } = this._cpuFallbackEnabledElement;
863
+ viewport.aspectRatio = aspectRatio;
864
+ }
865
+ getFitParallelScaleCPU(ratioValue) {
866
+ const { image } = this._cpuFallbackEnabledElement;
867
867
  const { clientWidth, clientHeight } = this.element;
868
868
  const { rowPixelSpacing, columnPixelSpacing, width, height } = image;
869
- const getRatioValue = ([x, y]) => x / y;
870
- const oldRatioValue = getRatioValue(viewport.aspectRatio || [1, 1]);
871
- const newRatioValue = getRatioValue(aspectRatio);
872
869
  const canvasRatio = clientWidth / clientHeight;
873
870
  const baseHeight = clientHeight * rowPixelSpacing * 0.5;
874
- const calculateFitParallelScale = (rVal) => {
875
- const effectiveWidth = width * columnPixelSpacing * rVal;
876
- const effectiveHeight = height * rowPixelSpacing;
877
- if (effectiveWidth / effectiveHeight > canvasRatio) {
878
- return baseHeight / (clientWidth / effectiveWidth);
879
- }
880
- const fitPScale = effectiveHeight * 0.5;
881
- return rVal < 1 ? fitPScale / rVal : fitPScale;
882
- };
883
- const ratioFactor = calculateFitParallelScale(newRatioValue) /
884
- calculateFitParallelScale(oldRatioValue);
885
- viewport.aspectRatio = aspectRatio;
886
- if (viewport.parallelScale) {
887
- viewport.parallelScale *= ratioFactor;
888
- viewport.scale = baseHeight / viewport.parallelScale;
871
+ const effectiveWidth = width * columnPixelSpacing * ratioValue;
872
+ const effectiveHeight = height * rowPixelSpacing;
873
+ if (effectiveWidth / effectiveHeight > canvasRatio) {
874
+ return baseHeight / (clientWidth / effectiveWidth);
889
875
  }
876
+ const fitParallelScale = effectiveHeight * 0.5;
877
+ return ratioValue < 1 ? fitParallelScale / ratioValue : fitParallelScale;
890
878
  }
891
879
  setCameraCPU(cameraInterface) {
892
880
  const { viewport, image } = this._cpuFallbackEnabledElement;
893
881
  const previousCamera = this.getCameraCPU();
894
- const { focalPoint, parallelScale, scale, flipHorizontal, flipVertical, aspectRatio, isFitViewportAfterStretch, } = cameraInterface;
882
+ const { focalPoint, parallelScale, scale, flipHorizontal, flipVertical, aspectRatio, } = cameraInterface;
895
883
  const { clientHeight } = this.element;
896
884
  if (focalPoint) {
897
885
  const focalPointCanvas = this.worldToCanvasCPU(focalPoint);
@@ -916,7 +904,7 @@ class StackViewport extends Viewport {
916
904
  viewport.parallelScale = (clientHeight * rowPixelSpacing * 0.5) / scale;
917
905
  }
918
906
  if (aspectRatio) {
919
- this.setAspectRatioForViewport(aspectRatio, isFitViewportAfterStretch);
907
+ this.setAspectRatioForViewport(aspectRatio);
920
908
  }
921
909
  if (flipHorizontal !== undefined || flipVertical !== undefined) {
922
910
  this.setFlipCPU({ flipHorizontal, flipVertical });
@@ -954,7 +942,8 @@ class StackViewport extends Viewport {
954
942
  const { aspectRatio } = this.getCameraCPU();
955
943
  return aspectRatio ?? this.options?.aspectRatio ?? [1, 1];
956
944
  }
957
- setAspectRatioCPU(value, isFitViewportAfterStretch = true, storeAsInitialCamera = false) {
945
+ setAspectRatioCPU(value, options = {}) {
946
+ const { fit = false, storeAsInitialCamera = false } = options;
958
947
  const camera = this.getCameraCPU();
959
948
  if (storeAsInitialCamera) {
960
949
  this.options.aspectRatio = value;
@@ -962,8 +951,14 @@ class StackViewport extends Viewport {
962
951
  this.setCameraCPU({
963
952
  ...camera,
964
953
  aspectRatio: value,
965
- isFitViewportAfterStretch,
966
954
  });
955
+ if (fit) {
956
+ this.resetCameraCPU({
957
+ resetPan: false,
958
+ resetZoom: true,
959
+ resetAspectRatio: false,
960
+ });
961
+ }
967
962
  }
968
963
  setFlipCPU({ flipHorizontal, flipVertical }) {
969
964
  const { viewport } = this._cpuFallbackEnabledElement;
@@ -1752,19 +1747,30 @@ class StackViewport extends Viewport {
1752
1747
  }
1753
1748
  return imageId;
1754
1749
  }
1755
- resetCameraCPU({ resetPan = true, resetZoom = true, }) {
1750
+ resetCameraCPU({ resetPan = true, resetZoom = true, resetAspectRatio = true, }) {
1756
1751
  const { image } = this._cpuFallbackEnabledElement;
1757
1752
  if (!image) {
1758
1753
  return;
1759
1754
  }
1755
+ const targetAspectRatio = resetAspectRatio
1756
+ ? this.options?.aspectRatio || [1, 1]
1757
+ : this.getAspectRatioCPU();
1760
1758
  resetCamera(this._cpuFallbackEnabledElement, resetPan, resetZoom);
1761
- const { scale } = this._cpuFallbackEnabledElement.viewport;
1759
+ let { scale } = this._cpuFallbackEnabledElement.viewport;
1760
+ if (resetZoom) {
1761
+ const [stretchX, stretchY] = getNormalizedAspectRatio(targetAspectRatio);
1762
+ const stretchRatio = stretchX / stretchY;
1763
+ scale /=
1764
+ this.getFitParallelScaleCPU(stretchRatio) /
1765
+ this.getFitParallelScaleCPU(1);
1766
+ }
1762
1767
  const { clientWidth, clientHeight } = this.element;
1763
1768
  const center = [clientWidth / 2, clientHeight / 2];
1764
1769
  const centerWorld = this.canvasToWorldCPU(center);
1765
1770
  this.setCameraCPU({
1766
1771
  focalPoint: centerWorld,
1767
1772
  scale,
1773
+ aspectRatio: targetAspectRatio,
1768
1774
  });
1769
1775
  }
1770
1776
  resetCameraGPU(resetOptions) {
@@ -3,7 +3,7 @@ import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
3
3
  import type { mat4 } from 'gl-matrix';
4
4
  import ViewportStatus from '../enums/ViewportStatus.js';
5
5
  import ViewportType from '../enums/ViewportType.js';
6
- import type { ICamera, ActorEntry, IRenderingEngine, ViewportInputOptions, Point2, Point3, FlipDirection, DisplayArea, ViewPresentation, ViewReference, ViewportProperties, ImageActor } from '../types/index.js';
6
+ import type { ICamera, ResetCameraOptions, SetAspectRatioOptions, ActorEntry, IRenderingEngine, ViewportInputOptions, Point2, Point3, FlipDirection, DisplayArea, ViewPresentation, ViewReference, ViewportProperties, ImageActor } from '../types/index.js';
7
7
  import type { ViewportInput, ViewReferenceSpecifier, ReferenceCompatibleOptions, ViewPresentationSelector, DataSetOptions, PlaneRestriction, RenderingEngineResizeOptions } from '../types/IViewport.js';
8
8
  import type { vtkSlabCamera } from './vtkClasses/vtkSlabCamera.js';
9
9
  import type IImageCalibration from '../types/IImageCalibration.js';
@@ -96,7 +96,7 @@ declare class Viewport {
96
96
  }): void;
97
97
  addActor(actorEntry: ActorEntry): void;
98
98
  removeAllActors(): void;
99
- protected resetCameraNoEvent(): void;
99
+ protected resetCameraNoEvent(options?: ResetCameraOptions): void;
100
100
  protected setCameraNoEvent(camera: ICamera): void;
101
101
  private _getViewImageDataIntersections;
102
102
  protected setInterpolationType(_interpolationType: InterpolationType, _arg?: any): void;
@@ -104,6 +104,14 @@ declare class Viewport {
104
104
  protected setDisplayAreaScale(displayArea: DisplayArea): void;
105
105
  protected setDisplayAreaFit(displayArea: DisplayArea): void;
106
106
  getDisplayArea(): DisplayArea | undefined;
107
+ protected getWorldSizeInView(bounds?: number[]): {
108
+ widthWorld: number;
109
+ heightWorld: number;
110
+ };
111
+ protected getFitParallelScale(worldSize: {
112
+ widthWorld: number;
113
+ heightWorld: number;
114
+ }, aspectRatio: Point2): number;
107
115
  resetCamera(options?: {
108
116
  resetPan?: boolean;
109
117
  resetZoom?: boolean;
@@ -119,16 +127,16 @@ declare class Viewport {
119
127
  getImageData(): any;
120
128
  getViewReferenceId(_specifier?: ViewReferenceSpecifier): string;
121
129
  setPan(pan: Point2, storeAsInitialCamera?: boolean): void;
130
+ protected getComparableParallelScale(compareCamera: ICamera): number;
122
131
  getZoom(compareCamera?: ICamera<number>): number;
123
132
  setZoom(value: number, storeAsInitialCamera?: boolean): void;
124
133
  getAspectRatio(): Point2;
125
- setAspectRatio(value: Point2, isFitViewportAfterStretch?: boolean, storeAsInitialCamera?: boolean): void;
134
+ setAspectRatio(value: Point2, options?: SetAspectRatioOptions): void;
126
135
  private _getFocalPointForViewPlaneReset;
127
136
  getCanvas(): HTMLCanvasElement;
128
137
  protected getVtkActiveCamera(): vtkCamera | vtkSlabCamera;
129
138
  protected getCameraNoRotation(): ICamera;
130
139
  getCamera(): ICamera;
131
- private setAspectRatioForVTKCamera;
132
140
  setCamera(cameraInterface: ICamera, storeAsInitialCamera?: boolean): void;
133
141
  triggerCameraModifiedEventIfNecessary(previousCamera: ICamera, updatedCamera: ICamera): void;
134
142
  updateCameraClippingPlanesAndRange(): void;
@@ -18,6 +18,7 @@ import { deepClone } from '../utilities/deepClone.js';
18
18
  import { updatePlaneRestriction } from '../utilities/updatePlaneRestriction.js';
19
19
  import { isPlaneDepthViewable } from '../utilities/voxelSlab/isPlaneDepthViewable.js';
20
20
  import { getCubeSizeInView } from '../utilities/getPlaneCubeIntersectionDimensions.js';
21
+ import { getNormalizedAspectRatio } from '../utilities/getNormalizedAspectRatio.js';
21
22
  import { getConfiguration } from '../init.js';
22
23
  const log = coreLog.getLogger('RenderingEngine', 'Viewport');
23
24
  class Viewport {
@@ -159,6 +160,13 @@ class Viewport {
159
160
  if (this.options?.displayArea) {
160
161
  this.setDisplayArea(this.options?.displayArea);
161
162
  }
163
+ if (this.options?.aspectRatio) {
164
+ const zoom = this.initialCamera?.parallelScale ? this.getZoom() : null;
165
+ this.setAspectRatio(this.options.aspectRatio);
166
+ if (zoom) {
167
+ this.setZoom(zoom);
168
+ }
169
+ }
162
170
  if (immediate) {
163
171
  this.render();
164
172
  }
@@ -363,10 +371,10 @@ class Viewport {
363
371
  });
364
372
  return;
365
373
  }
366
- resetCameraNoEvent() {
374
+ resetCameraNoEvent(options) {
367
375
  const savedValue = this._suppressCameraModifiedEvents;
368
376
  this._suppressCameraModifiedEvents = true;
369
- this.resetCamera();
377
+ this.resetCamera(options);
370
378
  this._suppressCameraModifiedEvents = savedValue;
371
379
  }
372
380
  setCameraNoEvent(camera) {
@@ -514,6 +522,39 @@ class Viewport {
514
522
  getDisplayArea() {
515
523
  return this.options?.displayArea;
516
524
  }
525
+ getWorldSizeInView(bounds) {
526
+ const imageData = this.getDefaultImageData();
527
+ const activeCamera = this.getVtkActiveCamera();
528
+ const viewPlaneNormal = activeCamera.getViewPlaneNormal();
529
+ const viewUp = activeCamera.getViewUp();
530
+ if (imageData) {
531
+ return getCubeSizeInView(imageData, viewPlaneNormal, viewUp);
532
+ }
533
+ let boundsToUse = bounds;
534
+ if (!boundsToUse) {
535
+ const defaultActor = this.getDefaultActor();
536
+ boundsToUse =
537
+ defaultActor && isImageActor(defaultActor)
538
+ ? defaultActor.actor.getMapper().getInputData().getBounds()
539
+ : this.getRenderer().computeVisiblePropBounds();
540
+ }
541
+ return this._getWorldDistanceViewUpAndViewRight(boundsToUse, viewUp, viewPlaneNormal);
542
+ }
543
+ getFitParallelScale(worldSize, aspectRatio) {
544
+ const { widthWorld, heightWorld } = worldSize;
545
+ const [stretchX, stretchY] = getNormalizedAspectRatio(aspectRatio);
546
+ const stretchRatio = stretchX / stretchY;
547
+ const boundsAspectRatio = (widthWorld * stretchRatio) / heightWorld;
548
+ const canvasAspectRatio = this.sWidth / this.sHeight;
549
+ const scaleFactor = boundsAspectRatio / canvasAspectRatio;
550
+ let parallelScale = scaleFactor < 1
551
+ ? (this.insetImageMultiplier * heightWorld) / 2
552
+ : (this.insetImageMultiplier * heightWorld * scaleFactor) / 2;
553
+ if (stretchRatio < 1) {
554
+ parallelScale /= stretchRatio;
555
+ }
556
+ return parallelScale;
557
+ }
517
558
  resetCamera(options) {
518
559
  const { resetPan = true, resetZoom = true, resetToCenter = true, storeAsInitialCamera = true, resetAspectRatio = true, } = options || {};
519
560
  const renderer = this.getRenderer();
@@ -545,16 +586,11 @@ class Viewport {
545
586
  const idx = [middleIJK[0], middleIJK[1], middleIJK[2]];
546
587
  imageData.indexToWorld(idx, focalPoint);
547
588
  }
548
- const { widthWorld, heightWorld } = imageData
549
- ? getCubeSizeInView(imageData, viewPlaneNormal, viewUp)
550
- : this._getWorldDistanceViewUpAndViewRight(bounds, viewUp, viewPlaneNormal);
551
- const canvasSize = [this.sWidth, this.sHeight];
552
- const boundsAspectRatio = widthWorld / heightWorld;
553
- const canvasAspectRatio = canvasSize[0] / canvasSize[1];
554
- const scaleFactor = boundsAspectRatio / canvasAspectRatio;
555
- const parallelScale = scaleFactor < 1
556
- ? (this.insetImageMultiplier * heightWorld) / 2
557
- : (this.insetImageMultiplier * heightWorld * scaleFactor) / 2;
589
+ const worldSize = this.getWorldSizeInView(bounds);
590
+ const targetAspectRatio = resetAspectRatio
591
+ ? this.options?.aspectRatio || [1, 1]
592
+ : this.getAspectRatio();
593
+ const parallelScale = this.getFitParallelScale(worldSize, targetAspectRatio);
558
594
  const radius = Viewport.boundsRadius(bounds) *
559
595
  (this.type === ViewportType.VOLUME_3D ? 10 : 1);
560
596
  const distance = this.insetImageMultiplier * radius;
@@ -574,9 +610,6 @@ class Viewport {
574
610
  ];
575
611
  activeCamera.setPhysicalScale(radius);
576
612
  activeCamera.setPhysicalTranslation(-focalPointToSet[0], -focalPointToSet[1], -focalPointToSet[2]);
577
- const targetAspectRatio = resetAspectRatio
578
- ? this.options?.aspectRatio || [1, 1]
579
- : this.getAspectRatio();
580
613
  this.setCamera({
581
614
  parallelScale: resetZoom ? parallelScale : previousCamera.parallelScale,
582
615
  focalPoint: focalPointToSet,
@@ -585,7 +618,6 @@ class Viewport {
585
618
  viewUp: viewUpToSet,
586
619
  clippingRange: clippingRangeToUse,
587
620
  aspectRatio: targetAspectRatio,
588
- isFitViewportAfterStretch: false,
589
621
  });
590
622
  const modifiedCamera = this.getCamera();
591
623
  this.setFitToCanvasCamera(this.getCamera());
@@ -659,17 +691,44 @@ class Viewport {
659
691
  position: newPosition,
660
692
  }, storeAsInitialCamera);
661
693
  }
694
+ getComparableParallelScale(compareCamera) {
695
+ const { parallelScale } = compareCamera || {};
696
+ if (!parallelScale) {
697
+ return parallelScale;
698
+ }
699
+ const currentAspectRatio = this.getAspectRatio();
700
+ const compareAspectRatio = compareCamera.aspectRatio ?? currentAspectRatio;
701
+ const getStretchRatio = (value) => {
702
+ const [stretchX, stretchY] = getNormalizedAspectRatio(value);
703
+ return stretchX / stretchY;
704
+ };
705
+ if (isEqual(getStretchRatio(currentAspectRatio), getStretchRatio(compareAspectRatio))) {
706
+ return parallelScale;
707
+ }
708
+ const worldSize = this.getWorldSizeInView();
709
+ if (!worldSize?.heightWorld) {
710
+ return parallelScale;
711
+ }
712
+ const ratioFactor = this.getFitParallelScale(worldSize, currentAspectRatio) /
713
+ this.getFitParallelScale(worldSize, compareAspectRatio);
714
+ return Number.isFinite(ratioFactor) && ratioFactor
715
+ ? parallelScale * ratioFactor
716
+ : parallelScale;
717
+ }
662
718
  getZoom(compareCamera = this.initialCamera) {
663
719
  if (!compareCamera) {
664
720
  return 1;
665
721
  }
666
722
  const activeCamera = this.getVtkActiveCamera();
667
- const { parallelScale: initialParallelScale } = compareCamera;
668
- return initialParallelScale / activeCamera.getParallelScale();
723
+ return (this.getComparableParallelScale(compareCamera) /
724
+ activeCamera.getParallelScale());
669
725
  }
670
726
  setZoom(value, storeAsInitialCamera = false) {
671
727
  const camera = this.getCamera();
672
- const { parallelScale: initialParallelScale } = this.initialCamera;
728
+ const initialParallelScale = this.getComparableParallelScale(this.initialCamera);
729
+ if (!initialParallelScale) {
730
+ return;
731
+ }
673
732
  const parallelScale = initialParallelScale / value;
674
733
  if (camera.parallelScale === parallelScale && !storeAsInitialCamera) {
675
734
  return;
@@ -683,16 +742,23 @@ class Viewport {
683
742
  const { aspectRatio } = this.getCamera();
684
743
  return aspectRatio ?? this.options?.aspectRatio ?? [1, 1];
685
744
  }
686
- setAspectRatio(value, isFitViewportAfterStretch = true, storeAsInitialCamera = false) {
745
+ setAspectRatio(value, options = {}) {
746
+ const { fit = false, storeAsInitialCamera = false } = options;
687
747
  const camera = this.getCamera();
688
748
  if (storeAsInitialCamera) {
689
749
  this.options.aspectRatio = value;
690
750
  }
691
- this.setCamera({
751
+ const cameraToSet = {
692
752
  ...camera,
693
753
  aspectRatio: value,
694
- isFitViewportAfterStretch,
695
- }, storeAsInitialCamera);
754
+ };
755
+ if (fit) {
756
+ const worldSize = this.getWorldSizeInView();
757
+ if (worldSize?.heightWorld) {
758
+ cameraToSet.parallelScale = this.getFitParallelScale(worldSize, value);
759
+ }
760
+ }
761
+ this.setCamera(cameraToSet, storeAsInitialCamera);
696
762
  }
697
763
  _getFocalPointForViewPlaneReset(imageData) {
698
764
  const { focalPoint, viewPlaneNormal: normal } = this.getCamera();
@@ -752,56 +818,11 @@ class Viewport {
752
818
  rotation: this.getRotation(),
753
819
  };
754
820
  }
755
- setAspectRatioForVTKCamera(aspectRatio, isFitViewportAfterStretch = true) {
756
- const vtkCamera = this.getVtkActiveCamera();
757
- if (!isFitViewportAfterStretch) {
758
- vtkCamera.setAspectRatio(aspectRatio);
759
- return;
760
- }
761
- const currentAspect = vtkCamera.getAspectRatio() || [1, 1];
762
- if (currentAspect[0] === aspectRatio[0] &&
763
- currentAspect[1] === aspectRatio[1]) {
764
- return;
765
- }
766
- const getRatioValue = ([x, y]) => x / y;
767
- const oldRatioValue = getRatioValue(currentAspect);
768
- const newRatioValue = getRatioValue(aspectRatio);
769
- vtkCamera.setAspectRatio(aspectRatio);
770
- const imageData = this.getDefaultImageData();
771
- if (!imageData)
772
- return;
773
- const getFitScale = (rVal) => {
774
- const { widthWorld, heightWorld } = getCubeSizeInView(imageData, vtkCamera.getViewPlaneNormal(), vtkCamera.getViewUp());
775
- const canvasAspectRatio = this.sWidth / this.sHeight;
776
- const effectiveWidth = widthWorld * rVal;
777
- const effectiveImageRatio = effectiveWidth / heightWorld;
778
- let fitScale = effectiveImageRatio > canvasAspectRatio
779
- ? effectiveWidth / (2 * canvasAspectRatio)
780
- : heightWorld / 2;
781
- if (rVal < 1)
782
- fitScale /= rVal;
783
- return fitScale;
784
- };
785
- const ratioFactor = getFitScale(newRatioValue) / getFitScale(oldRatioValue);
786
- vtkCamera.setParallelScale(vtkCamera.getParallelScale() * ratioFactor);
787
- if (this.initialCamera?.parallelScale) {
788
- this.initialCamera = {
789
- ...this.initialCamera,
790
- parallelScale: this.initialCamera.parallelScale * ratioFactor,
791
- };
792
- }
793
- if (this.fitToCanvasCamera?.parallelScale) {
794
- this.fitToCanvasCamera = {
795
- ...this.fitToCanvasCamera,
796
- parallelScale: this.fitToCanvasCamera.parallelScale * ratioFactor,
797
- };
798
- }
799
- }
800
821
  setCamera(cameraInterface, storeAsInitialCamera = false) {
801
822
  const vtkCamera = this.getVtkActiveCamera();
802
823
  const previousCamera = this.getCamera();
803
824
  const updatedCamera = Object.assign({}, previousCamera, cameraInterface);
804
- const { viewUp, viewPlaneNormal, position, focalPoint, parallelScale, viewAngle, flipHorizontal, flipVertical, clippingRange, aspectRatio, isFitViewportAfterStretch, } = cameraInterface;
825
+ const { viewUp, viewPlaneNormal, position, focalPoint, parallelScale, viewAngle, flipHorizontal, flipVertical, clippingRange, aspectRatio, } = cameraInterface;
805
826
  if (flipHorizontal !== undefined) {
806
827
  const flipH = (flipHorizontal && !this.flipHorizontal) ||
807
828
  (!flipHorizontal && this.flipHorizontal);
@@ -838,7 +859,7 @@ class Viewport {
838
859
  vtkCamera.setClippingRange(clippingRange);
839
860
  }
840
861
  if (aspectRatio) {
841
- this.setAspectRatioForVTKCamera(aspectRatio, isFitViewportAfterStretch);
862
+ vtkCamera.setAspectRatio(aspectRatio);
842
863
  }
843
864
  const prevFocalPoint = previousCamera.focalPoint;
844
865
  const prevViewUp = previousCamera.viewUp;
@@ -1109,8 +1130,8 @@ class Viewport {
1109
1130
  if (displayArea !== this.getDisplayArea()) {
1110
1131
  this.setDisplayArea(displayArea);
1111
1132
  }
1112
- this.setZoom(zoom);
1113
1133
  this.setAspectRatio(aspectRatio);
1134
+ this.setZoom(zoom);
1114
1135
  if (pan) {
1115
1136
  const [aspectX, aspectY] = aspectRatio;
1116
1137
  this.setPan([pan[0] * zoom * aspectX, pan[1] * zoom * aspectY]);
@@ -291,12 +291,18 @@ class VolumeViewport extends BaseVolumeViewport {
291
291
  }
292
292
  }
293
293
  resetCamera(options) {
294
- const { resetPan = true, resetZoom = true, resetRotation = true, resetToCenter = true, suppressEvents = false, resetOrientation = true, resetAspectRatio = true, } = options || {};
294
+ const { resetPan = true, resetZoom = true, resetRotation = true, resetToCenter = true, suppressEvents = false, resetOrientation = true, resetAspectRatio = true, storeAsInitialCamera = true, } = options || {};
295
295
  const { orientation } = this.viewportProperties;
296
296
  if (orientation && resetOrientation) {
297
297
  this.applyViewOrientation(orientation, false);
298
298
  }
299
- super.resetCamera({ resetPan, resetZoom, resetToCenter, resetAspectRatio });
299
+ super.resetCamera({
300
+ resetPan,
301
+ resetZoom,
302
+ resetToCenter,
303
+ resetAspectRatio,
304
+ storeAsInitialCamera,
305
+ });
300
306
  const activeCamera = this.getVtkActiveCamera();
301
307
  const viewPlaneNormal = activeCamera.getViewPlaneNormal();
302
308
  const focalPoint = activeCamera.getFocalPoint();
@@ -1,16 +1,13 @@
1
1
  import type { BlendModes } from '../enums/index.js';
2
2
  import type { ViewportInput } from '../types/IViewport.js';
3
+ import type { ResetCameraOptions } from '../types/ICamera.js';
3
4
  import BaseVolumeViewport from './BaseVolumeViewport.js';
4
5
  declare class VolumeViewport3D extends BaseVolumeViewport {
5
6
  constructor(props: ViewportInput);
6
7
  setSampleDistanceMultiplier: (multiplier: number) => void;
7
8
  getNumberOfSlices: () => number;
8
9
  isInAcquisitionPlane(): boolean;
9
- resetCamera({ resetPan, resetZoom, resetToCenter, }?: {
10
- resetPan?: boolean;
11
- resetZoom?: boolean;
12
- resetToCenter?: boolean;
13
- }): boolean;
10
+ resetCamera({ resetPan, resetZoom, resetToCenter, resetAspectRatio, storeAsInitialCamera, }?: ResetCameraOptions): boolean;
14
11
  getRotation: () => number;
15
12
  getCurrentImageIdIndex: () => number;
16
13
  getCurrentImageId: () => string;
@@ -60,8 +60,14 @@ class VolumeViewport3D extends BaseVolumeViewport {
60
60
  isInAcquisitionPlane() {
61
61
  return false;
62
62
  }
63
- resetCamera({ resetPan = true, resetZoom = true, resetToCenter = true, } = {}) {
64
- super.resetCamera({ resetPan, resetZoom, resetToCenter });
63
+ resetCamera({ resetPan = true, resetZoom = true, resetToCenter = true, resetAspectRatio = true, storeAsInitialCamera = true, } = {}) {
64
+ super.resetCamera({
65
+ resetPan,
66
+ resetZoom,
67
+ resetToCenter,
68
+ resetAspectRatio,
69
+ storeAsInitialCamera,
70
+ });
65
71
  const activeCamera = this.getVtkActiveCamera();
66
72
  if (activeCamera.getParallelProjection()) {
67
73
  activeCamera.setClippingRange(-RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE, RENDERING_DEFAULTS.MAXIMUM_RAY_DISTANCE);
@@ -15,12 +15,6 @@ function extendedVtkCamera(publicAPI, model) {
15
15
  }
16
16
  return matrix;
17
17
  };
18
- publicAPI.getAspectRatio = () => {
19
- return model.aspectRatio;
20
- };
21
- publicAPI.setAspectRatio = (aspectRatio) => {
22
- model.aspectRatio = aspectRatio;
23
- };
24
18
  }
25
19
  const DEFAULT_VALUES = {
26
20
  aspectRatio: [1, 1],
@@ -14,12 +14,16 @@ interface ICamera<TScale = number> {
14
14
  flipVertical?: boolean;
15
15
  clippingRange?: Point2;
16
16
  aspectRatio?: Point2;
17
- isFitViewportAfterStretch?: boolean;
18
17
  }
19
18
  interface ResetCameraOptions {
20
19
  resetPan?: boolean;
21
20
  resetZoom?: boolean;
22
21
  resetToCenter?: boolean;
23
22
  resetAspectRatio?: boolean;
23
+ storeAsInitialCamera?: boolean;
24
24
  }
25
- export type { ICamera as default, ResetCameraOptions };
25
+ interface SetAspectRatioOptions {
26
+ fit?: boolean;
27
+ storeAsInitialCamera?: boolean;
28
+ }
29
+ export type { ICamera as default, ResetCameraOptions, SetAspectRatioOptions };
@@ -111,10 +111,10 @@ import type GeometryLoaderFn from './GeometryLoaderFn.js';
111
111
  import type { RenderingEngineModeType } from './RenderingEngineMode.js';
112
112
  import type { VtkOffscreenMultiRenderWindow } from './VtkOffscreenMultiRenderWindow.js';
113
113
  import type { ViewportDataReference } from '../RenderingEngine/GenericViewport/index.js';
114
- import type { ResetCameraOptions } from './ICamera.js';
114
+ import type { ResetCameraOptions, SetAspectRatioOptions } from './ICamera.js';
115
115
  import type { ViewportType, ViewportTypeConstants, ViewportTypeRegistry } from './ViewportTypeRegistry.js';
116
116
  import type { EffectiveRenderBackend, RenderBackendConstants, RenderBackendRegistry } from './RenderBackendRegistry.js';
117
117
  export type * from './MetadataModuleTypes.js';
118
118
  export type * from './InstanceTypes.js';
119
- export type { Cornerstone3DConfig, IBaseStreamingImageVolume, ICamera, ResetCameraOptions, IStackViewport, IVideoViewport, IECGViewport, IWSIViewport, IVolumeViewport, IEnabledElement, ICache, IVolume, IViewportId, IImageVolume, ImageVolumeProps, IDynamicImageVolume, IRenderingEngine, ScalingParameters, ScalingDescriptor, PTScaling, IPointsManager, PolyDataPointConfiguration, Scaling, IStreamingImageVolume, IImage, IImageData, IImageCalibration, CPUIImageData, CPUImageData, EventTypes, ImageLoaderFn, VolumeLoaderFn, IRegisterImageLoader, IStreamingVolumeProperties, IViewport, IGenericViewport, ViewportContentMode, ViewReference, DataSetOptions as ImageSetOptions, ViewPresentation, ViewPresentationSelector, ReferenceCompatibleOptions, ViewReferenceSpecifier, RenderingEngineResizeOptions, StackViewportProperties, VolumeViewportProperties, ViewportProperties, PublicViewportInput, VolumeActor, Actor, ActorEntry, ActorMapperProxy, ImageActor, ICanvasActor, IImageLoadObject, IVolumeLoadObject, IVolumeInput, VolumeInputCallback, IStackInput, StackInputCallback, ViewportPreset, Metadata, OrientationVectors, AABB2, AABB3, Point2, Point3, PointsXYZ, Point4, Mat3, Plane, ViewportInputOptions, VideoViewportProperties, WSIViewportProperties, VOIRange, VOI, DisplayArea, FlipDirection, ICachedImage, ICachedVolume, CPUFallbackEnabledElement, CPUFallbackViewport, CPUFallbackTransform, CPUFallbackColormapData, CPUFallbackViewportDisplayedArea, CPUFallbackColormapsData, CPUFallbackColormap, TransformMatrix2D, CPUFallbackLookupTable, CPUFallbackLUT, CPUFallbackRenderingTools, CustomEventType, ActorSliceRange, ImageSliceData, IGeometry, IGeometryLoadObject, ICachedGeometry, PublicContourSetData, ContourSetData, ContourData, IContourSet, IContour, PublicSurfaceData, SurfaceData, ISurface, PublicMeshData, MeshData, IMesh, RGB, ColormapPublic, ColormapRegistration, PixelDataTypedArray, PixelDataTypedArrayString, ImagePixelModule, ImagePlaneModule, AffineMatrix, ImageLoadListener, InternalVideoCamera, VideoViewportInput, InternalECGCamera, ECGViewportInput, ECGChannel, ECGWaveformData, ECGViewportProperties, BoundsIJK, BoundsLPS, Color, ColorLUT, VolumeProps, IImageFrame, LocalVolumeOptions, IVoxelManager, IRLEVoxelMap, RLERun, ViewportInput, ImageLoadRequests, IBaseVolumeViewport, GeometryLoaderFn, ScrollOptions, JumpToSliceOptions, Memo, HistoryMemo, VoxelManager, RLEVoxelMap, RenderingEngineModeType, VtkOffscreenMultiRenderWindow, ViewportDataReference, ViewportType, ViewportTypeRegistry, ViewportTypeConstants, EffectiveRenderBackend, RenderBackendRegistry, RenderBackendConstants, };
119
+ export type { Cornerstone3DConfig, IBaseStreamingImageVolume, ICamera, ResetCameraOptions, SetAspectRatioOptions, IStackViewport, IVideoViewport, IECGViewport, IWSIViewport, IVolumeViewport, IEnabledElement, ICache, IVolume, IViewportId, IImageVolume, ImageVolumeProps, IDynamicImageVolume, IRenderingEngine, ScalingParameters, ScalingDescriptor, PTScaling, IPointsManager, PolyDataPointConfiguration, Scaling, IStreamingImageVolume, IImage, IImageData, IImageCalibration, CPUIImageData, CPUImageData, EventTypes, ImageLoaderFn, VolumeLoaderFn, IRegisterImageLoader, IStreamingVolumeProperties, IViewport, IGenericViewport, ViewportContentMode, ViewReference, DataSetOptions as ImageSetOptions, ViewPresentation, ViewPresentationSelector, ReferenceCompatibleOptions, ViewReferenceSpecifier, RenderingEngineResizeOptions, StackViewportProperties, VolumeViewportProperties, ViewportProperties, PublicViewportInput, VolumeActor, Actor, ActorEntry, ActorMapperProxy, ImageActor, ICanvasActor, IImageLoadObject, IVolumeLoadObject, IVolumeInput, VolumeInputCallback, IStackInput, StackInputCallback, ViewportPreset, Metadata, OrientationVectors, AABB2, AABB3, Point2, Point3, PointsXYZ, Point4, Mat3, Plane, ViewportInputOptions, VideoViewportProperties, WSIViewportProperties, VOIRange, VOI, DisplayArea, FlipDirection, ICachedImage, ICachedVolume, CPUFallbackEnabledElement, CPUFallbackViewport, CPUFallbackTransform, CPUFallbackColormapData, CPUFallbackViewportDisplayedArea, CPUFallbackColormapsData, CPUFallbackColormap, TransformMatrix2D, CPUFallbackLookupTable, CPUFallbackLUT, CPUFallbackRenderingTools, CustomEventType, ActorSliceRange, ImageSliceData, IGeometry, IGeometryLoadObject, ICachedGeometry, PublicContourSetData, ContourSetData, ContourData, IContourSet, IContour, PublicSurfaceData, SurfaceData, ISurface, PublicMeshData, MeshData, IMesh, RGB, ColormapPublic, ColormapRegistration, PixelDataTypedArray, PixelDataTypedArrayString, ImagePixelModule, ImagePlaneModule, AffineMatrix, ImageLoadListener, InternalVideoCamera, VideoViewportInput, InternalECGCamera, ECGViewportInput, ECGChannel, ECGWaveformData, ECGViewportProperties, BoundsIJK, BoundsLPS, Color, ColorLUT, VolumeProps, IImageFrame, LocalVolumeOptions, IVoxelManager, IRLEVoxelMap, RLERun, ViewportInput, ImageLoadRequests, IBaseVolumeViewport, GeometryLoaderFn, ScrollOptions, JumpToSliceOptions, Memo, HistoryMemo, VoxelManager, RLEVoxelMap, RenderingEngineModeType, VtkOffscreenMultiRenderWindow, ViewportDataReference, ViewportType, ViewportTypeRegistry, ViewportTypeConstants, EffectiveRenderBackend, RenderBackendRegistry, RenderBackendConstants, };
120
120
  export { ActorRenderMode };
@@ -1 +1 @@
1
- export declare const version = "5.10.8";
1
+ export declare const version = "5.10.10";
@@ -1 +1 @@
1
- export const version = '5.10.8';
1
+ export const version = '5.10.10';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "5.10.8",
3
+ "version": "5.10.10",
4
4
  "description": "Cornerstone3D Core",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -85,18 +85,18 @@
85
85
  "prepublishOnly": "pnpm run build"
86
86
  },
87
87
  "dependencies": {
88
- "@cornerstonejs/utils": "5.10.8",
88
+ "@cornerstonejs/utils": "5.10.10",
89
89
  "@kitware/vtk.js": "36.4.1",
90
90
  "comlink": "4.4.2",
91
91
  "gl-matrix": "3.4.3",
92
92
  "loglevel": "1.9.2"
93
93
  },
94
94
  "devDependencies": {
95
- "@cornerstonejs/metadata": "5.10.8"
95
+ "@cornerstonejs/metadata": "5.10.10"
96
96
  },
97
97
  "peerDependencies": {
98
- "@cornerstonejs/metadata": "5.10.8",
99
- "@cornerstonejs/utils": "5.10.8"
98
+ "@cornerstonejs/metadata": "5.10.10",
99
+ "@cornerstonejs/utils": "5.10.10"
100
100
  },
101
101
  "contributors": [
102
102
  {