@cornerstonejs/core 0.47.0 → 0.47.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "0.47.0",
3
+ "version": "0.47.1",
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": "fe634bf0a19f588638aaa21d4bcbbc8df33897b3"
47
47
  }
@@ -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;
@@ -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