Skip to content

Commit

Permalink
save/restore compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
IbrahimCSAE committed Mar 17, 2023
1 parent 331e044 commit e886971
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/adapters/src/adapters/Cornerstone3D/EllipticalROI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,27 @@ class EllipticalROI {
static getTID300RepresentationArguments(tool, worldToImageCoords) {
const { data, finding, findingSites, metadata } = tool;
const { cachedStats = {}, handles } = data;

const rotation = data.initialRotation || 0;
const { referencedImageId } = metadata;

if (!referencedImageId) {
throw new Error(
"EllipticalROI.getTID300RepresentationArguments: referencedImageId is not defined"
);
}

const top = worldToImageCoords(referencedImageId, handles.points[0]);
const bottom = worldToImageCoords(referencedImageId, handles.points[1]);
const left = worldToImageCoords(referencedImageId, handles.points[2]);
const right = worldToImageCoords(referencedImageId, handles.points[3]);
let top, bottom, left, right;
// this way when it's restored we can assume the initial rotation is 0.
if (rotation == 90 || rotation == 270) {
bottom = worldToImageCoords(referencedImageId, handles.points[2]);
top = worldToImageCoords(referencedImageId, handles.points[3]);
left = worldToImageCoords(referencedImageId, handles.points[0]);
right = worldToImageCoords(referencedImageId, handles.points[1]);
} else {
top = worldToImageCoords(referencedImageId, handles.points[0]);
bottom = worldToImageCoords(referencedImageId, handles.points[1]);
left = worldToImageCoords(referencedImageId, handles.points[2]);
right = worldToImageCoords(referencedImageId, handles.points[3]);
}

// find the major axis and minor axis
const topBottomLength = Math.abs(top[1] - bottom[1]);
Expand Down
4 changes: 3 additions & 1 deletion packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ class EllipticalROITool extends AnnotationTool {
viewport.worldToCanvas(p)
) as [Types.Point2, Types.Point2, Types.Point2, Types.Point2];

const rotation = Math.abs(viewport.getRotation() - data.initialRotation);
const rotation = Math.abs(
viewport.getRotation() - (data.initialRotation || 0)
);
let canvasCorners;

if (rotation == 90 || rotation == 270) {
Expand Down

0 comments on commit e886971

Please sign in to comment.