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(CircleROITool) Issue 1489 - CircleROITool fires unnecessary ANNOTATION_MODIFIED events when any part of the annotation is outside the image #1518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
181 changes: 87 additions & 94 deletions packages/tools/src/tools/annotation/CircleROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,106 +899,99 @@ class CircleROITool extends AnnotationTool {
pos2Index[1] = Math.floor(pos2Index[1]);
pos2Index[2] = Math.floor(pos2Index[2]);

// Check if one of the indexes are inside the volume, this then gives us
// Some area to do stats over.

if (this._isInsideVolume(pos1Index, pos2Index, dimensions)) {
const iMin = Math.min(pos1Index[0], pos2Index[0]);
const iMax = Math.max(pos1Index[0], pos2Index[0]);

const jMin = Math.min(pos1Index[1], pos2Index[1]);
const jMax = Math.max(pos1Index[1], pos2Index[1]);

const kMin = Math.min(pos1Index[2], pos2Index[2]);
const kMax = Math.max(pos1Index[2], pos2Index[2]);

const boundsIJK = [
[iMin, iMax],
[jMin, jMax],
[kMin, kMax],
] as [Types.Point2, Types.Point2, Types.Point2];

const center = [
(topLeftWorld[0] + bottomRightWorld[0]) / 2,
(topLeftWorld[1] + bottomRightWorld[1]) / 2,
(topLeftWorld[2] + bottomRightWorld[2]) / 2,
] as Types.Point3;

const ellipseObj = {
center,
xRadius: Math.abs(topLeftWorld[0] - bottomRightWorld[0]) / 2,
yRadius: Math.abs(topLeftWorld[1] - bottomRightWorld[1]) / 2,
zRadius: Math.abs(topLeftWorld[2] - bottomRightWorld[2]) / 2,
};
const iMin = Math.min(pos1Index[0], pos2Index[0]);
const iMax = Math.max(pos1Index[0], pos2Index[0]);

const { worldWidth, worldHeight } = getWorldWidthAndHeightFromTwoPoints(
viewPlaneNormal,
viewUp,
worldPos1,
worldPos2
);
const isEmptyArea = worldWidth === 0 && worldHeight === 0;
const handles = [pos1Index, pos2Index];
const { scale, units, areaUnits } = getCalibratedLengthUnitsAndScale(
image,
handles
);
const aspect = getCalibratedAspect(image);
const area = Math.abs(
Math.PI *
(worldWidth / scale / 2) *
(worldHeight / aspect / scale / 2)
);
const jMin = Math.min(pos1Index[1], pos2Index[1]);
const jMax = Math.max(pos1Index[1], pos2Index[1]);

const modalityUnitOptions = {
isPreScaled: isViewportPreScaled(viewport, targetId),
isSuvScaled: this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
),
};
const kMin = Math.min(pos1Index[2], pos2Index[2]);
const kMax = Math.max(pos1Index[2], pos2Index[2]);

const modalityUnit = getModalityUnit(
metadata.Modality,
annotation.metadata.referencedImageId,
modalityUnitOptions
);
const boundsIJK = [
[iMin, iMax],
[jMin, jMax],
[kMin, kMax],
] as [Types.Point2, Types.Point2, Types.Point2];

const pointsInShape = pointInShapeCallback(
imageData,
(pointLPS) =>
pointInEllipse(ellipseObj, pointLPS, {
fast: true,
}),
this.configuration.statsCalculator.statsCallback,
boundsIJK
);
const center = [
(topLeftWorld[0] + bottomRightWorld[0]) / 2,
(topLeftWorld[1] + bottomRightWorld[1]) / 2,
(topLeftWorld[2] + bottomRightWorld[2]) / 2,
] as Types.Point3;

const stats = this.configuration.statsCalculator.getStatistics();

cachedStats[targetId] = {
Modality: metadata.Modality,
area,
mean: stats.mean?.value,
max: stats.max?.value,
stdDev: stats.stdDev?.value,
statsArray: stats.array,
pointsInShape: pointsInShape,
isEmptyArea,
areaUnit: areaUnits,
radius: worldWidth / 2 / scale,
radiusUnit: units,
perimeter: (2 * Math.PI * (worldWidth / 2)) / scale,
modalityUnit,
};
} else {
this.isHandleOutsideImage = true;
const ellipseObj = {
center,
xRadius: Math.abs(topLeftWorld[0] - bottomRightWorld[0]) / 2,
yRadius: Math.abs(topLeftWorld[1] - bottomRightWorld[1]) / 2,
zRadius: Math.abs(topLeftWorld[2] - bottomRightWorld[2]) / 2,
};

cachedStats[targetId] = {
Modality: metadata.Modality,
};
}
const { worldWidth, worldHeight } = getWorldWidthAndHeightFromTwoPoints(
viewPlaneNormal,
viewUp,
worldPos1,
worldPos2
);
const isEmptyArea = worldWidth === 0 && worldHeight === 0;
const handles = [pos1Index, pos2Index];
const { scale, units, areaUnits } = getCalibratedLengthUnitsAndScale(
image,
handles
);
const aspect = getCalibratedAspect(image);
const area = Math.abs(
Math.PI * (worldWidth / scale / 2) * (worldHeight / aspect / scale / 2)
);

const modalityUnitOptions = {
isPreScaled: isViewportPreScaled(viewport, targetId),
isSuvScaled: this.isSuvScaled(
viewport,
targetId,
annotation.metadata.referencedImageId
),
};

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

const pointsInShape = pointInShapeCallback(
imageData,
(pointLPS) =>
pointInEllipse(ellipseObj, pointLPS, {
fast: true,
}),
this.configuration.statsCalculator.statsCallback,
boundsIJK
);

const stats = this.configuration.statsCalculator.getStatistics();

cachedStats[targetId] = {
Modality: metadata.Modality,
area,
mean: stats.mean?.value,
max: stats.max?.value,
stdDev: stats.stdDev?.value,
statsArray: stats.array,
pointsInShape: pointsInShape,
isEmptyArea,
areaUnit: areaUnits,
radius: worldWidth / 2 / scale,
radiusUnit: units,
perimeter: (2 * Math.PI * (worldWidth / 2)) / scale,
modalityUnit,
};

this.isHandleOutsideImage = !this._isInsideVolume(
pos1Index,
pos2Index,
dimensions
);
}

annotation.invalidated = false;
Expand Down