Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PT measurement units): Non-SUV scaled, but pre-scaled PTs should show proper units #686

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
58 changes: 31 additions & 27 deletions packages/tools/src/tools/annotation/CircleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ class CircleROITool extends AnnotationTool {

const { centerPointRadius } = this.configuration;

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

// If cachedStats does not exist, or the unit is missing (as part of import/hydration etc.),
// force to recalculate the stats from the points
if (
Expand All @@ -683,14 +691,18 @@ class CircleROITool extends AnnotationTool {
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
);
} else if (annotation.invalidated) {
this._throttledCalculateCachedStats(
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
);
// If the invalidated data is as a result of volumeViewport manipulation
// of the tools, we need to invalidate the related viewports data, so that
Expand Down Expand Up @@ -797,20 +809,7 @@ class CircleROITool extends AnnotationTool {

renderStatus = true;

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

const textLines = this._getTextLines(
data,
targetId,
isPreScaled,
isSuvScaled
);
const textLines = this._getTextLines(data, targetId);
if (!textLines || textLines.length === 0) {
continue;
}
Expand Down Expand Up @@ -854,12 +853,7 @@ class CircleROITool extends AnnotationTool {
return renderStatus;
};

_getTextLines = (
data,
targetId: string,
isPreScaled: boolean,
isSuvScaled: boolean
): string[] => {
_getTextLines = (data, targetId: string): string[] => {
const cachedVolumeStats = data.cachedStats[targetId];
const {
radius,
Expand All @@ -871,10 +865,10 @@ class CircleROITool extends AnnotationTool {
isEmptyArea,
Modality,
areaUnit,
modalityUnit,
} = cachedVolumeStats;

const textLines: string[] = [];
const unit = getModalityUnit(Modality, isPreScaled, isSuvScaled);

if (radius) {
const radiusLine = isEmptyArea
Expand All @@ -891,15 +885,15 @@ class CircleROITool extends AnnotationTool {
}

if (mean) {
textLines.push(`Mean: ${mean.toFixed(2)} ${unit}`);
textLines.push(`Mean: ${mean.toFixed(2)} ${modalityUnit}`);
}

if (max) {
textLines.push(`Max: ${max.toFixed(2)} ${unit}`);
textLines.push(`Max: ${max.toFixed(2)} ${modalityUnit}`);
}

if (stdDev) {
textLines.push(`Std Dev: ${stdDev.toFixed(2)} ${unit}`);
textLines.push(`Std Dev: ${stdDev.toFixed(2)} ${modalityUnit}`);
}

return textLines;
Expand All @@ -909,7 +903,9 @@ class CircleROITool extends AnnotationTool {
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
) => {
const data = annotation.data;
const { viewportId, renderingEngineId } = enabledElement;
Expand Down Expand Up @@ -1037,6 +1033,13 @@ class CircleROITool extends AnnotationTool {
stdDev /= count;
stdDev = Math.sqrt(stdDev);

const modalityUnit = getModalityUnit(
metadata.Modality,
isPreScaled,
isSuvScaled,
annotation.metadata.referencedImageId
);

cachedStats[targetId] = {
Modality: metadata.Modality,
area,
Expand All @@ -1048,6 +1051,7 @@ class CircleROITool extends AnnotationTool {
radius: worldWidth / 2,
radiusUnit: hasPixelSpacing ? 'mm' : 'px',
perimeter: 2 * Math.PI * (worldWidth / 2),
modalityUnit,
};
} else {
this.isHandleOutsideImage = true;
Expand Down
39 changes: 23 additions & 16 deletions packages/tools/src/tools/annotation/DragProbeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,36 @@ class DragProbeTool extends ProbeTool {

const color = this.getStyle('color', styleSpecifier, annotation);

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

if (!data.cachedStats[targetId]) {
data.cachedStats[targetId] = {
Modality: null,
index: null,
value: null,
};

this._calculateCachedStats(annotation, renderingEngine, enabledElement);
this._calculateCachedStats(
annotation,
renderingEngine,
enabledElement,
isPreScaled,
isSuvScaled
jbocce marked this conversation as resolved.
Show resolved Hide resolved
);
} else if (annotation.invalidated) {
this._calculateCachedStats(annotation, renderingEngine, enabledElement);
this._calculateCachedStats(
annotation,
renderingEngine,
enabledElement,
isPreScaled,
isSuvScaled
);
}

// If rendering engine has been destroyed while rendering
Expand All @@ -185,20 +205,7 @@ class DragProbeTool extends ProbeTool {

renderStatus = true;

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

const textLines = this._getTextLines(
data,
targetId,
isPreScaled,
isSuvScaled
);
const textLines = this._getTextLines(data, targetId);
if (textLines) {
const textCanvasCoordinates = [
canvasCoordinates[0] + 6,
Expand Down
59 changes: 31 additions & 28 deletions packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@ class EllipticalROITool extends AnnotationTool {

const { centerPointRadius } = this.configuration;

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

// If cachedStats does not exist, or the unit is missing (as part of import/hydration etc.),
// force to recalculate the stats from the points
if (
Expand All @@ -806,14 +814,18 @@ class EllipticalROITool extends AnnotationTool {
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
);
} else if (annotation.invalidated) {
this._throttledCalculateCachedStats(
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
);
// If the invalidated data is as a result of volumeViewport manipulation
// of the tools, we need to invalidate the related viewports data, so that
Expand Down Expand Up @@ -925,20 +937,7 @@ class EllipticalROITool extends AnnotationTool {

renderStatus = true;

const isPreScaled = isViewportPreScaled(viewport, targetId);

const isSuvScaled = this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
);

const textLines = this._getTextLines(
data,
targetId,
isPreScaled,
isSuvScaled
);
const textLines = this._getTextLines(data, targetId);
if (!textLines || textLines.length === 0) {
continue;
}
Expand Down Expand Up @@ -982,18 +981,12 @@ class EllipticalROITool extends AnnotationTool {
return renderStatus;
};

_getTextLines = (
data,
targetId: string,
isPreScaled: boolean,
isSuvScaled: boolean
): string[] => {
_getTextLines = (data, targetId: string): string[] => {
const cachedVolumeStats = data.cachedStats[targetId];
const { area, mean, stdDev, max, isEmptyArea, Modality, areaUnit } =
const { area, mean, stdDev, max, isEmptyArea, areaUnit, modalityUnit } =
cachedVolumeStats;

const textLines: string[] = [];
const unit = getModalityUnit(Modality, isPreScaled, isSuvScaled);

if (area) {
const areaLine = isEmptyArea
Expand All @@ -1003,15 +996,15 @@ class EllipticalROITool extends AnnotationTool {
}

if (mean) {
textLines.push(`Mean: ${mean.toFixed(2)} ${unit}`);
textLines.push(`Mean: ${mean.toFixed(2)} ${modalityUnit}`);
}

if (max) {
textLines.push(`Max: ${max.toFixed(2)} ${unit}`);
textLines.push(`Max: ${max.toFixed(2)} ${modalityUnit}`);
}

if (stdDev) {
textLines.push(`Std Dev: ${stdDev.toFixed(2)} ${unit}`);
textLines.push(`Std Dev: ${stdDev.toFixed(2)} ${modalityUnit}`);
}

return textLines;
Expand All @@ -1021,7 +1014,9 @@ class EllipticalROITool extends AnnotationTool {
annotation,
viewport,
renderingEngine,
enabledElement
enabledElement,
isPreScaled,
isSuvScaled
) => {
const data = annotation.data;
const { viewportId, renderingEngineId } = enabledElement;
Expand Down Expand Up @@ -1149,6 +1144,13 @@ class EllipticalROITool extends AnnotationTool {
stdDev /= count;
stdDev = Math.sqrt(stdDev);

const modalityUnit = getModalityUnit(
metadata.Modality,
isPreScaled,
isSuvScaled,
annotation.metadata.referencedImageId
);

cachedStats[targetId] = {
Modality: metadata.Modality,
area,
Expand All @@ -1157,6 +1159,7 @@ class EllipticalROITool extends AnnotationTool {
stdDev,
isEmptyArea,
areaUnit: hasPixelSpacing ? 'mm' : 'px',
modalityUnit,
};
} else {
this.isHandleOutsideImage = true;
Expand Down
Loading