Skip to content

Commit 4845045

Browse files
authored
fix(rt): assign correct imageId for Stack (#1269)
1 parent 2671f86 commit 4845045

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

common/reviews/api/tools.api.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import type { TierResult } from 'detect-gpu';
1313
import { vec3 } from 'gl-matrix';
1414
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
1515
import vtkAnnotatedCubeActor from '@kitware/vtk.js/Rendering/Core/AnnotatedCubeActor';
16+
import type { vtkCamera } from '@kitware/vtk.js/Rendering/Core/Camera';
1617
import { vtkColorTransferFunction } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
1718
import { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
1819
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
20+
import type { vtkObject } from '@kitware/vtk.js/interfaces';
1921
import type { vtkPiecewiseFunction } from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
22+
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
2023
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
2124
import type vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
2225

@@ -2585,6 +2588,9 @@ function getCanvasEllipseCorners(ellipseCanvasPoints: CanvasCoordinates): Array<
25852588
// @public (undocumented)
25862589
function getChildAnnotations(annotation: Annotation): Annotation[];
25872590

2591+
// @public (undocumented)
2592+
function getClosestImageIdForStackViewport(viewport: StackViewport, worldPos: Types_2.Point3, viewPlaneNormal: Types_2.Point3): string;
2593+
25882594
// @public (undocumented)
25892595
function getClosestLineSegmentIntersection(points: Types_2.Point2[], p1: Types_2.Point2, q1: Types_2.Point2, closed?: boolean): {
25902596
segment: Types_2.Point2;
@@ -6119,7 +6125,8 @@ declare namespace utilities {
61196125
voi,
61206126
AnnotationFrameRange as annotationFrameRange,
61216127
contourSegmentation,
6122-
annotationHydration
6128+
annotationHydration,
6129+
getClosestImageIdForStackViewport
61236130
}
61246131
}
61256132
export { utilities }

packages/tools/src/tools/displayTools/Contour/contourDisplay.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getEnabledElementByIds, Types } from '@cornerstonejs/core';
1+
import {
2+
getEnabledElementByIds,
3+
StackViewport,
4+
Types,
5+
} from '@cornerstonejs/core';
26

37
import Representations from '../../../enums/SegmentationRepresentations';
48
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
@@ -59,7 +63,7 @@ function removeSegmentationRepresentation(
5963
* @param toolGroupConfig - This is the configuration object for the tool group
6064
*/
6165
async function render(
62-
viewport: Types.IVolumeViewport,
66+
viewport: StackViewport | Types.IVolumeViewport,
6367
representationConfig: ToolGroupSpecificRepresentation,
6468
toolGroupConfig: SegmentationRepresentationConfig
6569
): Promise<void> {

packages/tools/src/tools/displayTools/Contour/contourHandler/handleContourSegmentation.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/* eslint-disable @typescript-eslint/no-empty-function */
33

44
import { addAnnotation } from '../../../../stateManagement';
5-
import { cache, Types, utilities } from '@cornerstonejs/core';
5+
import { cache, Types, utilities, StackViewport } from '@cornerstonejs/core';
6+
import { getClosestImageIdForStackViewport } from '../../../../utilities/annotationHydration';
67

78
import {
89
SegmentationRepresentationConfig,
@@ -15,7 +16,7 @@ import { addContourSegmentationAnnotation } from '../../../../utilities/contourS
1516
import { validateGeometry } from './utils';
1617

1718
function handleContourSegmentation(
18-
viewport: Types.IVolumeViewport,
19+
viewport: StackViewport | Types.IVolumeViewport,
1920
geometryIds: string[],
2021
annotationUIDsMap: Map<number, Set<string>>,
2122
contourRepresentation: ToolGroupSpecificContourRepresentation,
@@ -33,7 +34,7 @@ function handleContourSegmentation(
3334
}
3435

3536
function updateContourSets(
36-
viewport: Types.IVolumeViewport,
37+
viewport: Types.IVolumeViewport | StackViewport,
3738
geometryIds: string[],
3839
contourRepresentation: ToolGroupSpecificContourRepresentation,
3940
contourRepresentationConfig: SegmentationRepresentationConfig
@@ -112,7 +113,7 @@ function updateContourSets(
112113
}
113114

114115
function addContourSetsToElement(
115-
viewport: Types.IVolumeViewport,
116+
viewport: StackViewport | Types.IVolumeViewport,
116117
geometryIds: string[],
117118
contourRepresentation: ToolGroupSpecificContourRepresentation,
118119
contourRepresentationConfig: SegmentationRepresentationConfig
@@ -166,7 +167,11 @@ function addContourSetsToElement(
166167
isLocked: true,
167168
isVisible: true,
168169
metadata: {
169-
referencedImageId: viewport.getCurrentImageId(),
170+
referencedImageId: getClosestImageIdForStackViewport(
171+
viewport as StackViewport,
172+
points[0],
173+
viewport.getCamera().viewPlaneNormal
174+
),
170175
toolName: 'PlanarFreehandContourSegmentationTool',
171176
FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
172177
viewPlaneNormal: viewport.getCamera().viewPlaneNormal,

packages/tools/src/utilities/annotationHydration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ function calculateDistanceToImage(
140140

141141
return Math.abs(dot);
142142
}
143-
export { annotationHydration };
143+
export { annotationHydration, getClosestImageIdForStackViewport };

packages/tools/src/utilities/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import { pointToString } from './pointToString';
2828
import annotationFrameRange from './annotationFrameRange';
2929
import pointInSurroundingSphereCallback from './pointInSurroundingSphereCallback';
3030
import getViewportForAnnotation from './getViewportForAnnotation';
31-
import { annotationHydration } from './annotationHydration';
31+
import {
32+
annotationHydration,
33+
getClosestImageIdForStackViewport,
34+
} from './annotationHydration';
3235
// name spaces
3336
import * as contours from './contours';
3437
import * as segmentation from './segmentation';
@@ -98,4 +101,5 @@ export {
98101
annotationFrameRange,
99102
contourSegmentation,
100103
annotationHydration,
104+
getClosestImageIdForStackViewport,
101105
};

0 commit comments

Comments
 (0)