Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tools/examples/petCt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function setUpToolGroups() {
// Only set CT volume to MIP in the fusion viewport
filterActorUIDsToSetSlabThickness: [ctVolumeId],
});
fusionToolGroup.addTool(RectangleROITool.toolName);
fusionToolGroup.addTool(RectangleROITool.toolName, { volumeId: ptVolumeId });

// Here is the difference in the toolGroups used, that we need to specify the
// volume to use for the WindowLevelTool for the fusion viewports
Expand Down
3 changes: 1 addition & 2 deletions packages/tools/src/tools/annotation/CircleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ class CircleROITool extends AnnotationTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);

const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -623,6 +621,7 @@ class CircleROITool extends AnnotationTool {
const { handles } = data;
const { points, activeHandleIndex } = handles;

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color, lineWidth, lineDash } = this.getAnnotationStyle({
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/CobbAngleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ class CobbAngleTool extends AnnotationTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);
const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -682,6 +681,7 @@ class CobbAngleTool extends AnnotationTool {
const { annotationUID, data } = annotation;
const { points, activeHandleIndex } = data.handles;

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color, lineWidth, lineDash } = this.getAnnotationStyle({
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/DragProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class DragProbeTool extends ProbeTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);
const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -151,6 +150,7 @@ class DragProbeTool extends ProbeTool {
const point = data.handles.points[0];
const canvasCoordinates = viewport.worldToCanvas(point);

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color } = this.getAnnotationStyle({
Expand Down
3 changes: 1 addition & 2 deletions packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,6 @@ class EllipticalROITool extends AnnotationTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);

const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -789,6 +787,7 @@ class EllipticalROITool extends AnnotationTool {
const { handles } = data;
const { points, activeHandleIndex } = handles;

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color, lineWidth, lineDash } = this.getAnnotationStyle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
svgDrawingHelper
) => {
const { data } = <PlanarFreehandROIAnnotation>annotation;
const targetId = this.getTargetId(viewport);
const targetId = this.getTargetId(viewport, data);

const styleSpecifier: AnnotationStyle.StyleSpecifier = {
toolGroupId: this.toolGroupId,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/ProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ class ProbeTool extends AnnotationTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);
const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -452,6 +451,7 @@ class ProbeTool extends AnnotationTool {
const point = data.handles.points[0];
const canvasCoordinates = viewport.worldToCanvas(point);

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color, lineWidth } = this.getAnnotationStyle({
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/RectangleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ class RectangleROITool extends AnnotationTool {
return renderStatus;
}

const targetId = this.getTargetId(viewport);
const renderingEngine = viewport.getRenderingEngine();

const styleSpecifier: StyleSpecifier = {
Expand All @@ -622,6 +621,7 @@ class RectangleROITool extends AnnotationTool {
const { points, activeHandleIndex } = data.handles;
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));

const targetId = this.getTargetId(viewport, data);
styleSpecifier.annotationUID = annotationUID;

const { color, lineWidth, lineDash } = this.getAnnotationStyle({
Expand Down
35 changes: 28 additions & 7 deletions packages/tools/src/tools/base/BaseTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,39 @@ abstract class BaseTool {
/**
* Get the target Id for the viewport which will be used to store the cached
* statistics scoped to that target in the annotations.
* For StackViewport, targetId is the viewportId, but for the volume viewport,
* the targetId will be grabbed from the volumeId if particularly specified
* in the tool configuration, or if not, the first actorUID in the viewport.
* For StackViewport, targetId is usually derived from the imageId.
* For VolumeViewport, it's derived from the volumeId.
* This method allows prioritizing a specific volumeId from the tool's
* configuration if available in the cachedStats.
*
* @param viewport - viewport to get the targetId for
* @param data - Optional: The annotation's data object, containing cachedStats.
* @returns targetId
*/
protected getTargetId(viewport: Types.IViewport): string | undefined {
const targetId = viewport.getViewReferenceId?.();
if (targetId) {
return targetId;
protected getTargetId(
viewport: Types.IViewport,
data?: unknown & { cachedStats?: Record<string, unknown> }
): string | undefined {
const preferredVolumeId = this.configuration?.volumeId; // Get preferred ID from config

// Check if cachedStats is available and contains the preferredVolumeId
if (data?.cachedStats && preferredVolumeId) {
const allTargetIds = Object.keys(data.cachedStats);
const foundTargetId = allTargetIds.find((tId) =>
tId.includes(preferredVolumeId)
);

if (foundTargetId) {
return foundTargetId;
}
}

// If not found or not applicable, use the viewport's default method
const defaultTargetId = viewport.getViewReferenceId?.();
if (defaultTargetId) {
return defaultTargetId;
}

throw new Error(
'getTargetId: viewport must have a getViewReferenceId method'
);
Expand Down
Loading