@cornerstonejs/core 3.9.0 → 3.9.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.
@@ -159,7 +159,7 @@ class RenderingEngine {
159
159
  }
160
160
  }
161
161
  getViewport(viewportId) {
162
- return this._viewports.get(viewportId);
162
+ return this._viewports?.get(viewportId);
163
163
  }
164
164
  getViewports() {
165
165
  this._throwIfDestroyed();
@@ -1651,7 +1651,7 @@ class StackViewport extends Viewport {
1651
1651
  const imageIds = this.getImageIds();
1652
1652
  const imageData = this.getImageData();
1653
1653
  const { direction, spacing } = imageData;
1654
- const imageId = getClosestImageId({ direction: direction, spacing, imageIds }, worldPos, this.getCamera().viewPlaneNormal);
1654
+ const imageId = getClosestImageId({ direction, spacing, imageIds }, worldPos, this.getCamera().viewPlaneNormal, { ignoreSpacing: true });
1655
1655
  const index = imageIds.indexOf(imageId);
1656
1656
  if (index === -1) {
1657
1657
  return false;
@@ -4,4 +4,6 @@ export default function getClosestImageId(imageVolume: IImageVolume | {
4
4
  direction: mat3;
5
5
  spacing: Point3;
6
6
  imageIds: string[];
7
- }, worldPos: Point3, viewPlaneNormal: Point3): string;
7
+ }, worldPos: Point3, viewPlaneNormal: Point3, options?: {
8
+ ignoreSpacing?: boolean;
9
+ }): string | undefined;
@@ -2,28 +2,51 @@ import { vec3 } from 'gl-matrix';
2
2
  import * as metaData from '../metaData';
3
3
  import getSpacingInNormalDirection from './getSpacingInNormalDirection';
4
4
  import { EPSILON } from '../constants';
5
- export default function getClosestImageId(imageVolume, worldPos, viewPlaneNormal) {
5
+ export default function getClosestImageId(imageVolume, worldPos, viewPlaneNormal, options) {
6
6
  const { direction, spacing, imageIds } = imageVolume;
7
- if (!imageIds.length) {
7
+ const { ignoreSpacing = false } = options || {};
8
+ if (!imageIds?.length) {
8
9
  return;
9
10
  }
10
11
  const kVector = direction.slice(6, 9);
11
- const dotProducts = vec3.dot(kVector, viewPlaneNormal);
12
- if (Math.abs(dotProducts) < 1 - EPSILON) {
12
+ const dotProduct = vec3.dot(kVector, viewPlaneNormal);
13
+ if (Math.abs(dotProduct) < 1 - EPSILON) {
14
+ console.debug('View plane normal is not parallel to the image scan axis. Unable to find closest imageId.');
13
15
  return;
14
16
  }
15
- const spacingInNormalDirection = getSpacingInNormalDirection({ direction, spacing }, viewPlaneNormal);
16
- const halfSpacingInNormalDirection = spacingInNormalDirection / 2;
17
- let imageIdForTool;
17
+ let halfSpacingInNormalDirection;
18
+ if (!ignoreSpacing) {
19
+ const spacingInNormalDirection = getSpacingInNormalDirection({ direction, spacing }, viewPlaneNormal);
20
+ halfSpacingInNormalDirection = spacingInNormalDirection / 2;
21
+ }
22
+ let closestImageId;
23
+ let minDistance = Infinity;
18
24
  for (let i = 0; i < imageIds.length; i++) {
19
25
  const imageId = imageIds[i];
20
- const { imagePositionPatient } = metaData.get('imagePlaneModule', imageId);
26
+ const imagePlaneModule = metaData.get('imagePlaneModule', imageId);
27
+ if (!imagePlaneModule?.imagePositionPatient) {
28
+ console.warn(`Missing imagePositionPatient for imageId: ${imageId}`);
29
+ continue;
30
+ }
31
+ const { imagePositionPatient } = imagePlaneModule;
21
32
  const dir = vec3.create();
22
33
  vec3.sub(dir, worldPos, imagePositionPatient);
23
- const dot = vec3.dot(dir, viewPlaneNormal);
24
- if (Math.abs(dot) < halfSpacingInNormalDirection) {
25
- imageIdForTool = imageId;
34
+ const distance = Math.abs(vec3.dot(dir, viewPlaneNormal));
35
+ if (ignoreSpacing) {
36
+ if (distance < minDistance) {
37
+ minDistance = distance;
38
+ closestImageId = imageId;
39
+ }
26
40
  }
41
+ else {
42
+ if (distance < halfSpacingInNormalDirection && distance < minDistance) {
43
+ minDistance = distance;
44
+ closestImageId = imageId;
45
+ }
46
+ }
47
+ }
48
+ if (closestImageId === undefined) {
49
+ console.debug('No imageId found within the specified criteria (half spacing or absolute closest).');
27
50
  }
28
- return imageIdForTool;
51
+ return closestImageId;
29
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "Cornerstone3D Core",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -91,5 +91,5 @@
91
91
  "type": "individual",
92
92
  "url": "https://ohif.org/donate"
93
93
  },
94
- "gitHead": "e44475d4c419201d7042d4648c0335d1b2eebe41"
94
+ "gitHead": "0511bf112a469f5ca8888a923947dda2a5525104"
95
95
  }