@cornerstonejs/core 0.47.0 → 0.47.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.
Files changed (41) hide show
  1. package/dist/cjs/RenderingEngine/StackViewport.d.ts +2 -1
  2. package/dist/cjs/RenderingEngine/StackViewport.js +3 -0
  3. package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
  4. package/dist/cjs/RenderingEngine/VolumeViewport.d.ts +0 -1
  5. package/dist/cjs/RenderingEngine/VolumeViewport.js +10 -21
  6. package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
  7. package/dist/cjs/types/IStackViewport.d.ts +2 -0
  8. package/dist/cjs/utilities/getClosestImageId.d.ts +1 -1
  9. package/dist/cjs/utilities/getClosestImageId.js +3 -2
  10. package/dist/cjs/utilities/getClosestImageId.js.map +1 -1
  11. package/dist/cjs/utilities/getImageLegacy.d.ts +3 -0
  12. package/dist/cjs/utilities/getImageLegacy.js +20 -0
  13. package/dist/cjs/utilities/getImageLegacy.js.map +1 -0
  14. package/dist/cjs/utilities/index.d.ts +2 -1
  15. package/dist/cjs/utilities/index.js +3 -1
  16. package/dist/cjs/utilities/index.js.map +1 -1
  17. package/dist/esm/RenderingEngine/StackViewport.d.ts +2 -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/VolumeViewport.d.ts +0 -1
  21. package/dist/esm/RenderingEngine/VolumeViewport.js +12 -23
  22. package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
  23. package/dist/esm/types/IStackViewport.d.ts +2 -0
  24. package/dist/esm/utilities/getClosestImageId.d.ts +1 -1
  25. package/dist/esm/utilities/getClosestImageId.js +3 -2
  26. package/dist/esm/utilities/getClosestImageId.js.map +1 -1
  27. package/dist/esm/utilities/getImageLegacy.d.ts +3 -0
  28. package/dist/esm/utilities/getImageLegacy.js +15 -0
  29. package/dist/esm/utilities/getImageLegacy.js.map +1 -0
  30. package/dist/esm/utilities/index.d.ts +2 -1
  31. package/dist/esm/utilities/index.js +2 -1
  32. package/dist/esm/utilities/index.js.map +1 -1
  33. package/dist/umd/index.js +1 -1
  34. package/dist/umd/index.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/RenderingEngine/StackViewport.ts +7 -0
  37. package/src/RenderingEngine/VolumeViewport.ts +26 -45
  38. package/src/types/IStackViewport.ts +5 -0
  39. package/src/utilities/getClosestImageId.ts +3 -4
  40. package/src/utilities/getImageLegacy.ts +29 -0
  41. package/src/utilities/index.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "0.47.0",
3
+ "version": "0.47.2",
4
4
  "description": "",
5
5
  "main": "dist/umd/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -43,5 +43,5 @@
43
43
  "type": "individual",
44
44
  "url": "https://ohif.org/donate"
45
45
  },
46
- "gitHead": "2c2efd8536d4af3ede72a47bdab199efe67bb1d3"
46
+ "gitHead": "d0865c2e805bf58d9d6cee290ba39440518b3f8d"
47
47
  }
@@ -508,6 +508,13 @@ class StackViewport extends Viewport implements IStackViewport {
508
508
  return imagePlaneModule.frameOfReferenceUID;
509
509
  };
510
510
 
511
+ /**
512
+ * Returns the raw/loaded image being shown inside the stack viewport.
513
+ */
514
+ public getCornerstoneImage = (): IImage => {
515
+ return this.csImage;
516
+ };
517
+
511
518
  /**
512
519
  * Creates imageMapper based on the provided vtkImageData and also creates
513
520
  * the imageSliceActor and connects it to the imageMapper.
@@ -12,7 +12,7 @@ import type {
12
12
  Point3,
13
13
  } from '../types';
14
14
  import type { ViewportInput } from '../types/IViewport';
15
- import { actorIsA } from '../utilities';
15
+ import { actorIsA, getClosestImageId } from '../utilities';
16
16
  import transformWorldToIndex from '../utilities/transformWorldToIndex';
17
17
  import BaseVolumeViewport from './BaseVolumeViewport';
18
18
 
@@ -336,15 +336,29 @@ class VolumeViewport extends BaseVolumeViewport {
336
336
  }
337
337
 
338
338
  /**
339
- * Uses viewport camera and volume actor to decide if the viewport
340
- * is looking at the volume in the direction of acquisition (imageIds).
341
- * If so, it uses the origin and focalPoint to calculate the slice index.
339
+ * Uses the origin and focalPoint to calculate the slice index.
342
340
  * Todo: This only works if the imageIds are properly sorted
343
341
  *
344
342
  * @returns The slice index
345
343
  */
346
344
  public getCurrentImageIdIndex = (): number | undefined => {
347
- return this._getImageIdIndex();
345
+ const { viewPlaneNormal, focalPoint } = this.getCamera();
346
+
347
+ // Todo: handle scenario of fusion of multiple volumes
348
+ // we cannot only check number of actors, because we might have
349
+ // segmentations ...
350
+ const { origin, spacing } = this.getImageData();
351
+
352
+ // how many steps are from the origin to the focal point in the
353
+ // normal direction
354
+ const spacingInNormal = spacing[2];
355
+ const sub = vec3.create();
356
+ vec3.sub(sub, focalPoint, origin);
357
+ const distance = vec3.dot(sub, viewPlaneNormal);
358
+
359
+ // divide by the spacing in the normal direction to get the
360
+ // number of steps, and subtract 1 to get the index
361
+ return Math.round(Math.abs(distance) / spacingInNormal);
348
362
  };
349
363
 
350
364
  /**
@@ -356,10 +370,12 @@ class VolumeViewport extends BaseVolumeViewport {
356
370
  * @returns ImageId
357
371
  */
358
372
  public getCurrentImageId = (): string | undefined => {
359
- const index = this._getImageIdIndex();
360
-
361
- if (isNaN(index)) {
362
- return;
373
+ if (this.getActors().length > 1) {
374
+ console.warn(
375
+ `Using the first/default actor of ${
376
+ this.getActors().length
377
+ } actors for getCurrentImageId.`
378
+ );
363
379
  }
364
380
 
365
381
  const actorEntry = this.getDefaultActor();
@@ -374,44 +390,9 @@ class VolumeViewport extends BaseVolumeViewport {
374
390
  return;
375
391
  }
376
392
 
377
- const imageIds = volume.imageIds;
378
-
379
- return imageIds[index];
380
- };
381
-
382
- private _getImageIdIndex = () => {
383
393
  const { viewPlaneNormal, focalPoint } = this.getCamera();
384
394
 
385
- // Todo: handle scenario of fusion of multiple volumes
386
- // we cannot only check number of actors, because we might have
387
- // segmentations ...
388
- const { direction, origin, spacing } = this.getImageData();
389
-
390
- // get the last 3 components of the direction - axis normal
391
- const dir = direction.slice(direction.length - 3);
392
-
393
- const dot = Math.abs(
394
- dir[0] * viewPlaneNormal[0] +
395
- dir[1] * viewPlaneNormal[1] +
396
- dir[2] * viewPlaneNormal[2]
397
- );
398
-
399
- // if dot is not 1 or -1 return null since it means
400
- // viewport is not looking at the image acquisition plane
401
- if (dot - 1 > EPSILON) {
402
- return;
403
- }
404
-
405
- // how many steps are from the origin to the focal point in the
406
- // normal direction
407
- const spacingInNormal = spacing[2];
408
- const sub = vec3.create();
409
- vec3.sub(sub, focalPoint, origin);
410
- const distance = vec3.dot(sub, viewPlaneNormal);
411
-
412
- // divide by the spacing in the normal direction to get the
413
- // number of steps, and subtract 1 to get the index
414
- return Math.round(Math.abs(distance) / spacingInNormal);
395
+ return getClosestImageId(volume, focalPoint, viewPlaneNormal);
415
396
  };
416
397
 
417
398
  getRotation = (): number => 0;
@@ -8,6 +8,7 @@ import Point3 from './Point3';
8
8
  import { Scaling } from './ScalingParameters';
9
9
  import StackViewportProperties from './StackViewportProperties';
10
10
  import { ColormapRegistration } from './Colormap';
11
+ import IImage from './IImage';
11
12
 
12
13
  /**
13
14
  * Interface for Stack Viewport
@@ -84,6 +85,10 @@ export default interface IStackViewport extends IViewport {
84
85
  * image scalar data, vtkImageData object, metadata, and scaling (e.g., PET suvbw)
85
86
  */
86
87
  getImageData(): IImageData | CPUIImageData;
88
+ /**
89
+ * Returns the raw/loaded image being shown inside the stack viewport.
90
+ */
91
+ getCornerstoneImage: () => IImage;
87
92
  /**
88
93
  * Reset the viewport properties to the default values
89
94
  */
@@ -3,6 +3,7 @@ import * as metaData from '../metaData';
3
3
  import type { IImageVolume, Point3 } from '../types';
4
4
 
5
5
  import getSpacingInNormalDirection from './getSpacingInNormalDirection';
6
+ import { EPSILON } from '../constants';
6
7
 
7
8
  /**
8
9
  * Given an image, a point in space and the viewPlaneNormal it returns the
@@ -11,15 +12,13 @@ import getSpacingInNormalDirection from './getSpacingInNormalDirection';
11
12
  * @param imageVolume - The image volume
12
13
  * @param worldPos - The position in the world coordinate system (from mouse click)
13
14
  * @param viewPlaneNormal - The normal vector of the viewport
14
- * @param viewUp - The viewUp vector of the camera.
15
15
  *
16
16
  * @returns The imageId for the tool.
17
17
  */
18
18
  export default function getClosestImageId(
19
19
  imageVolume: IImageVolume,
20
20
  worldPos: Point3,
21
- viewPlaneNormal: Point3,
22
- viewUp: Point3
21
+ viewPlaneNormal: Point3
23
22
  ): string {
24
23
  if (!imageVolume) {
25
24
  return;
@@ -39,7 +38,7 @@ export default function getClosestImageId(
39
38
 
40
39
  // 2.a if imagePlane is not parallel to the camera: tool is not drawn on an
41
40
  // imaging plane, return
42
- if (Math.abs(dotProducts) < 0.99) {
41
+ if (Math.abs(dotProducts) < 1 - EPSILON) {
43
42
  return;
44
43
  }
45
44
 
@@ -0,0 +1,29 @@
1
+ import { StackViewport, Types } from '..';
2
+ import getEnabledElement from '../getEnabledElement';
3
+
4
+ /**
5
+ * Gets the IImage rendered by the given element. This is provided as a
6
+ * convenience for the legacy cornerstone getImage function. However it is
7
+ * encouraged for IStackViewport.getImage to be used instead.
8
+ * @param element - the element rendering/containing the image
9
+ * @returns the image
10
+ */
11
+ function getImageLegacy(element: HTMLDivElement): Types.IImage | undefined {
12
+ const enabledElement = getEnabledElement(element);
13
+
14
+ if (!enabledElement) {
15
+ return;
16
+ }
17
+
18
+ const { viewport } = enabledElement;
19
+
20
+ if (!(viewport instanceof StackViewport)) {
21
+ throw new Error(
22
+ `An image can only be fetched for a stack viewport and not for a viewport of type: ${viewport.type}`
23
+ );
24
+ }
25
+
26
+ return viewport.getCornerstoneImage();
27
+ }
28
+
29
+ export default getImageLegacy;
@@ -45,6 +45,7 @@ import deepMerge from './deepMerge';
45
45
  import getScalingParameters from './getScalingParameters';
46
46
  import getScalarDataType from './getScalarDataType';
47
47
  import isPTPrescaledWithSUV from './isPTPrescaledWithSUV';
48
+ import getImageLegacy from './getImageLegacy';
48
49
 
49
50
  // name spaces
50
51
  import * as planar from './planar';
@@ -103,4 +104,5 @@ export {
103
104
  getScalingParameters,
104
105
  getScalarDataType,
105
106
  colormap,
107
+ getImageLegacy,
106
108
  };