Skip to content

Commit

Permalink
fix(rt): assign correct imageId for Stack (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
IbrahimCSAE authored May 22, 2024
1 parent 2671f86 commit 4845045
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
9 changes: 8 additions & 1 deletion common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import type { TierResult } from 'detect-gpu';
import { vec3 } from 'gl-matrix';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkAnnotatedCubeActor from '@kitware/vtk.js/Rendering/Core/AnnotatedCubeActor';
import type { vtkCamera } from '@kitware/vtk.js/Rendering/Core/Camera';
import { vtkColorTransferFunction } from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
import { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
import type { vtkObject } from '@kitware/vtk.js/interfaces';
import type { vtkPiecewiseFunction } from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
import type vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';

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

// @public (undocumented)
function getClosestImageIdForStackViewport(viewport: StackViewport, worldPos: Types_2.Point3, viewPlaneNormal: Types_2.Point3): string;

// @public (undocumented)
function getClosestLineSegmentIntersection(points: Types_2.Point2[], p1: Types_2.Point2, q1: Types_2.Point2, closed?: boolean): {
segment: Types_2.Point2;
Expand Down Expand Up @@ -6119,7 +6125,8 @@ declare namespace utilities {
voi,
AnnotationFrameRange as annotationFrameRange,
contourSegmentation,
annotationHydration
annotationHydration,
getClosestImageIdForStackViewport
}
}
export { utilities }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getEnabledElementByIds, Types } from '@cornerstonejs/core';
import {
getEnabledElementByIds,
StackViewport,
Types,
} from '@cornerstonejs/core';

import Representations from '../../../enums/SegmentationRepresentations';
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
Expand Down Expand Up @@ -59,7 +63,7 @@ function removeSegmentationRepresentation(
* @param toolGroupConfig - This is the configuration object for the tool group
*/
async function render(
viewport: Types.IVolumeViewport,
viewport: StackViewport | Types.IVolumeViewport,
representationConfig: ToolGroupSpecificRepresentation,
toolGroupConfig: SegmentationRepresentationConfig
): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/* eslint-disable @typescript-eslint/no-empty-function */

import { addAnnotation } from '../../../../stateManagement';
import { cache, Types, utilities } from '@cornerstonejs/core';
import { cache, Types, utilities, StackViewport } from '@cornerstonejs/core';
import { getClosestImageIdForStackViewport } from '../../../../utilities/annotationHydration';

import {
SegmentationRepresentationConfig,
Expand All @@ -15,7 +16,7 @@ import { addContourSegmentationAnnotation } from '../../../../utilities/contourS
import { validateGeometry } from './utils';

function handleContourSegmentation(
viewport: Types.IVolumeViewport,
viewport: StackViewport | Types.IVolumeViewport,
geometryIds: string[],
annotationUIDsMap: Map<number, Set<string>>,
contourRepresentation: ToolGroupSpecificContourRepresentation,
Expand All @@ -33,7 +34,7 @@ function handleContourSegmentation(
}

function updateContourSets(
viewport: Types.IVolumeViewport,
viewport: Types.IVolumeViewport | StackViewport,
geometryIds: string[],
contourRepresentation: ToolGroupSpecificContourRepresentation,
contourRepresentationConfig: SegmentationRepresentationConfig
Expand Down Expand Up @@ -112,7 +113,7 @@ function updateContourSets(
}

function addContourSetsToElement(
viewport: Types.IVolumeViewport,
viewport: StackViewport | Types.IVolumeViewport,
geometryIds: string[],
contourRepresentation: ToolGroupSpecificContourRepresentation,
contourRepresentationConfig: SegmentationRepresentationConfig
Expand Down Expand Up @@ -166,7 +167,11 @@ function addContourSetsToElement(
isLocked: true,
isVisible: true,
metadata: {
referencedImageId: viewport.getCurrentImageId(),
referencedImageId: getClosestImageIdForStackViewport(
viewport as StackViewport,
points[0],
viewport.getCamera().viewPlaneNormal
),
toolName: 'PlanarFreehandContourSegmentationTool',
FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
viewPlaneNormal: viewport.getCamera().viewPlaneNormal,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/utilities/annotationHydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ function calculateDistanceToImage(

return Math.abs(dot);
}
export { annotationHydration };
export { annotationHydration, getClosestImageIdForStackViewport };
6 changes: 5 additions & 1 deletion packages/tools/src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import { pointToString } from './pointToString';
import annotationFrameRange from './annotationFrameRange';
import pointInSurroundingSphereCallback from './pointInSurroundingSphereCallback';
import getViewportForAnnotation from './getViewportForAnnotation';
import { annotationHydration } from './annotationHydration';
import {
annotationHydration,
getClosestImageIdForStackViewport,
} from './annotationHydration';
// name spaces
import * as contours from './contours';
import * as segmentation from './segmentation';
Expand Down Expand Up @@ -98,4 +101,5 @@ export {
annotationFrameRange,
contourSegmentation,
annotationHydration,
getClosestImageIdForStackViewport,
};

0 comments on commit 4845045

Please sign in to comment.