@cornerstonejs/core 1.77.3 → 1.77.5

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 (44) hide show
  1. package/dist/cjs/RenderingEngine/BaseVolumeViewport.js +3 -3
  2. package/dist/cjs/RenderingEngine/BaseVolumeViewport.js.map +1 -1
  3. package/dist/cjs/RenderingEngine/StackViewport.d.ts +1 -0
  4. package/dist/cjs/RenderingEngine/StackViewport.js +3 -0
  5. package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
  6. package/dist/cjs/RenderingEngine/VideoViewport.d.ts +1 -0
  7. package/dist/cjs/RenderingEngine/VideoViewport.js +4 -1
  8. package/dist/cjs/RenderingEngine/VideoViewport.js.map +1 -1
  9. package/dist/cjs/RenderingEngine/Viewport.d.ts +1 -0
  10. package/dist/cjs/RenderingEngine/Viewport.js +4 -1
  11. package/dist/cjs/RenderingEngine/Viewport.js.map +1 -1
  12. package/dist/cjs/RenderingEngine/VolumeViewport.d.ts +2 -2
  13. package/dist/cjs/RenderingEngine/VolumeViewport.js +14 -5
  14. package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
  15. package/dist/cjs/types/IViewport.d.ts +1 -0
  16. package/dist/esm/RenderingEngine/BaseVolumeViewport.js +3 -3
  17. package/dist/esm/RenderingEngine/BaseVolumeViewport.js.map +1 -1
  18. package/dist/esm/RenderingEngine/StackViewport.js +3 -0
  19. package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
  20. package/dist/esm/RenderingEngine/VideoViewport.js +4 -1
  21. package/dist/esm/RenderingEngine/VideoViewport.js.map +1 -1
  22. package/dist/esm/RenderingEngine/Viewport.js +4 -1
  23. package/dist/esm/RenderingEngine/Viewport.js.map +1 -1
  24. package/dist/esm/RenderingEngine/VolumeViewport.js +14 -5
  25. package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
  26. package/dist/types/RenderingEngine/StackViewport.d.ts +1 -0
  27. package/dist/types/RenderingEngine/StackViewport.d.ts.map +1 -1
  28. package/dist/types/RenderingEngine/VideoViewport.d.ts +1 -0
  29. package/dist/types/RenderingEngine/VideoViewport.d.ts.map +1 -1
  30. package/dist/types/RenderingEngine/Viewport.d.ts +1 -0
  31. package/dist/types/RenderingEngine/Viewport.d.ts.map +1 -1
  32. package/dist/types/RenderingEngine/VolumeViewport.d.ts +2 -2
  33. package/dist/types/RenderingEngine/VolumeViewport.d.ts.map +1 -1
  34. package/dist/types/types/IViewport.d.ts +1 -0
  35. package/dist/types/types/IViewport.d.ts.map +1 -1
  36. package/dist/umd/index.js +1 -1
  37. package/dist/umd/index.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/RenderingEngine/BaseVolumeViewport.ts +3 -3
  40. package/src/RenderingEngine/StackViewport.ts +8 -0
  41. package/src/RenderingEngine/VideoViewport.ts +5 -1
  42. package/src/RenderingEngine/Viewport.ts +5 -1
  43. package/src/RenderingEngine/VolumeViewport.ts +43 -23
  44. package/src/types/IViewport.ts +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "1.77.3",
3
+ "version": "1.77.5",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "type": "individual",
48
48
  "url": "https://ohif.org/donate"
49
49
  },
50
- "gitHead": "a33572ac280ef5d42b56083161c020d04e4d30c2"
50
+ "gitHead": "8f841470fce4dfe7f865ab4f3a9d657f5629f6f6"
51
51
  }
@@ -614,7 +614,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
614
614
  }
615
615
  const { viewPlaneNormal } = target;
616
616
  const delta =
617
- (viewRefSpecifier.sliceIndex as number) - this.getCurrentImageIdIndex();
617
+ (viewRefSpecifier.sliceIndex as number) - this.getSliceIndex();
618
618
  // Calculate a camera focal point and position
619
619
  const { sliceRangeInfo } = getVolumeViewportScrollInfo(
620
620
  this,
@@ -657,7 +657,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
657
657
  if (options?.withNavigation) {
658
658
  return true;
659
659
  }
660
- const currentSliceIndex = this.getCurrentImageIdIndex();
660
+ const currentSliceIndex = this.getSliceIndex();
661
661
  const { sliceIndex } = viewRef;
662
662
  if (Array.isArray(sliceIndex)) {
663
663
  return (
@@ -1757,7 +1757,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
1757
1757
  )?.uid;
1758
1758
  }
1759
1759
 
1760
- const currentIndex = this.getCurrentImageIdIndex();
1760
+ const currentIndex = this.getSliceIndex();
1761
1761
  sliceIndex ??= currentIndex;
1762
1762
  const { viewPlaneNormal, focalPoint } = this.getCamera();
1763
1763
  const querySeparator = volumeId.indexOf('?') > -1 ? '&' : '?';
@@ -2880,6 +2880,14 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
2880
2880
  return this.currentImageIdIndex;
2881
2881
  };
2882
2882
 
2883
+ /**
2884
+ * returns the slice index of the view
2885
+ * @returns slice index
2886
+ */
2887
+ public getSliceIndex = (): number => {
2888
+ return this.currentImageIdIndex;
2889
+ };
2890
+
2883
2891
  /**
2884
2892
  * Checks to see if this target is or could be shown in this viewport
2885
2893
  */
@@ -735,7 +735,7 @@ class VideoViewport extends Viewport implements IVideoViewport {
735
735
  if (options.withNavigation) {
736
736
  return true;
737
737
  }
738
- const currentIndex = this.getCurrentImageIdIndex();
738
+ const currentIndex = this.getSliceIndex();
739
739
  if (Array.isArray(sliceIndex)) {
740
740
  return currentIndex >= sliceIndex[0] && currentIndex <= sliceIndex[1];
741
741
  }
@@ -786,6 +786,10 @@ class VideoViewport extends Viewport implements IVideoViewport {
786
786
  return Math.round(this.videoElement.currentTime * this.fps);
787
787
  }
788
788
 
789
+ public getSliceIndex() {
790
+ return this.getCurrentImageIdIndex();
791
+ }
792
+
789
793
  public getCamera(): ICamera {
790
794
  const { parallelScale } = this.videoCamera;
791
795
 
@@ -1097,6 +1097,10 @@ class Viewport implements IViewport {
1097
1097
  throw new Error('Not implemented');
1098
1098
  }
1099
1099
 
1100
+ public getSliceIndex(): number {
1101
+ throw new Error('Not implemented');
1102
+ }
1103
+
1100
1104
  /**
1101
1105
  * Gets a referenced image url of some sort - could be a real image id, or
1102
1106
  * could be a URL with parameters. Regardless it refers to the currently displaying
@@ -1611,7 +1615,7 @@ class Viewport implements IViewport {
1611
1615
  cameraFocalPoint,
1612
1616
  viewPlaneNormal,
1613
1617
  viewUp,
1614
- sliceIndex: viewRefSpecifier.sliceIndex ?? this.getCurrentImageIdIndex(),
1618
+ sliceIndex: viewRefSpecifier.sliceIndex ?? this.getSliceIndex(),
1615
1619
  };
1616
1620
  return target;
1617
1621
  }
@@ -29,7 +29,7 @@ import setDefaultVolumeVOI from './helpers/setDefaultVolumeVOI';
29
29
  import { setTransferFunctionNodes } from '../utilities/transferFunctionUtils';
30
30
  import { ImageActor } from '../types/IActor';
31
31
  import getImageSliceDataForVolumeViewport from '../utilities/getImageSliceDataForVolumeViewport';
32
- import getVolumeViewportScrollInfo from '../utilities/getVolumeViewportScrollInfo';
32
+ import { vec3 } from 'gl-matrix';
33
33
 
34
34
  /**
35
35
  * An object representing a VolumeViewport. VolumeViewports are used to render
@@ -92,15 +92,6 @@ class VolumeViewport extends BaseVolumeViewport {
92
92
  return numberOfSlices;
93
93
  };
94
94
 
95
- /**
96
- * Returns the image index associated with the volume viewport.
97
- * @returns The image index.
98
- */
99
- public getSliceIndex = (): number => {
100
- const { imageIndex } = getImageSliceDataForVolumeViewport(this);
101
- return imageIndex;
102
- };
103
-
104
95
  /**
105
96
  * Creates and adds volume actors for all volumes defined in the `volumeInputArray`.
106
97
  * For each entry, if a `callback` is supplied, it will be called with the new volume actor as input.
@@ -387,23 +378,52 @@ class VolumeViewport extends BaseVolumeViewport {
387
378
  }
388
379
 
389
380
  /**
390
- * Uses the slice range information to compute the current image id index.
391
- * Note that this may be offset from the origin location, or opposite in
392
- * direction to the distance from the origin location, as the index is a
393
- * complete index from minimum to maximum.
381
+ * Returns the imageId index of the current slice in the volume viewport.
382
+ * Note: this is not guaranteed to be the same as the slice index in the view
383
+ * To get the slice index in the view (scroll position), use getSliceIndex()
384
+ *
385
+ * In future we will even delete this method as it should not be used
386
+ * at all.
394
387
  *
395
388
  * @returns The slice index in the direction of the view
396
389
  */
397
- public getCurrentImageIdIndex = (
398
- volumeId?: string,
399
- useSlabThickness = true
400
- ): number => {
401
- const { currentStepIndex } = getVolumeViewportScrollInfo(
402
- this,
403
- volumeId || this.getVolumeId(),
404
- useSlabThickness
390
+ public getCurrentImageIdIndex = (volumeId?: string): number => {
391
+ const { viewPlaneNormal, focalPoint } = this.getCamera();
392
+
393
+ const imageData = this.getImageData(volumeId);
394
+
395
+ if (!imageData) {
396
+ return;
397
+ }
398
+
399
+ const { origin, direction, spacing } = imageData;
400
+
401
+ const spacingInNormal = getSpacingInNormalDirection(
402
+ { direction, spacing },
403
+ viewPlaneNormal
405
404
  );
406
- return currentStepIndex;
405
+ const sub = vec3.create();
406
+ vec3.sub(sub, focalPoint, origin);
407
+ const distance = vec3.dot(sub, viewPlaneNormal);
408
+
409
+ // divide by the spacing in the normal direction to get the
410
+ // number of steps, and subtract 1 to get the index
411
+ return Math.round(Math.abs(distance) / spacingInNormal);
412
+ };
413
+
414
+ /**
415
+ * Returns the image index associated with the volume viewport in the current view, the difference
416
+ * between this method and getCurrentImageIdIndex is that this method returns the index of the
417
+ * slice in the volume in view direction so at the top (scrollbar top) of the viewport the index
418
+ * will be 0 and at the bottom (scrollbar bottom) the index will be the number of slices - 1.
419
+ * But the getCurrentImageIdIndex returns the index of current image in the imageIds
420
+ * which is not guaranteed to be the same as the slice index in the view.
421
+ *
422
+ * @returns The image index.
423
+ */
424
+ public getSliceIndex = (): number => {
425
+ const { imageIndex } = getImageSliceDataForVolumeViewport(this);
426
+ return imageIndex;
407
427
  };
408
428
 
409
429
  /**
@@ -333,8 +333,10 @@ interface IViewport {
333
333
  ): boolean;
334
334
  /** Gets the number of slices in the current camera orientation */
335
335
  getNumberOfSlices(): number;
336
- /** Gets the current slice in the current camera orientation */
336
+ /** Gets the index of the current image, it is not guaranteed to be the slice index in the view, use getSliceIndex for positional information */
337
337
  getCurrentImageIdIndex(): number;
338
+ /** gets the positional slice location in the view, similar to scrollbar, the top image is 0, the bottom is getNumberOfSlices - 1 */
339
+ getSliceIndex(): number;
338
340
  /**
339
341
  * Gets a referenced image url of some sort - could be a real image id, or
340
342
  * could be a URL with parameters. Regardless it refers to the currently displaying