Skip to content

Commit

Permalink
cornerstonejs#190 - draw center point of the ellipticalROI tool and m…
Browse files Browse the repository at this point in the history
…ake it configurable
  • Loading branch information
md-prog committed Aug 26, 2022
1 parent 6136293 commit 534a338
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
import {
drawCircle as drawCircleSvg,
drawEllipse as drawEllipseSvg,
drawHandles as drawHandlesSvg,
drawLinkedTextBox as drawLinkedTextBoxSvg,
Expand All @@ -30,6 +31,7 @@ import getWorldWidthAndHeightFromTwoPoints from '../../utilities/planar/getWorld
import {
pointInEllipse,
getCanvasEllipseCorners,
getCanvasEllipseCenter,
} from '../../utilities/math/ellipse';
import {
resetElementCursor,
Expand Down Expand Up @@ -125,6 +127,9 @@ class EllipticalROITool extends AnnotationTool {
configuration: {
shadow: true,
preventHandleOutsideImage: false,
centerPointRadius: 0, // Radius of the circle to draw at the center
// point of the ellipse.
// Set this zero(0) in order not to draw the circle.
},
}
) {
Expand Down Expand Up @@ -757,6 +762,8 @@ class EllipticalROITool extends AnnotationTool {
getCanvasEllipseCorners(canvasCoordinates)
);

const { centerPointRadius } = this.configuration;

// 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 Down Expand Up @@ -868,6 +875,27 @@ class EllipticalROITool extends AnnotationTool {
}
);

// draw center point, if "centerPointRadius" configuration is valid.
const minRadius = Math.min(
Math.abs(canvasCorners[0][0] - canvasCorners[1][0]) / 2, // horizontal radius
Math.abs(canvasCorners[0][1] - canvasCorners[1][1]) / 2 // vertical radius
);
if (centerPointRadius && minRadius > 3 * centerPointRadius) {
const centerPoint = getCanvasEllipseCenter(canvasCoordinates);
drawCircleSvg(
svgDrawingHelper,
annotationUID,
ellipseUID,
centerPoint,
centerPointRadius,
{
color,
lineDash,
lineWidth,
}
);
}

renderStatus = true;

const isPreScaled = isViewportPreScaled(viewport, targetId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Types } from '@cornerstonejs/core';

/**
* It takes the canvas coordinates of the ellipse corners and returns the center point of it
*
* @param ellipseCanvasPoints - The coordinates of the ellipse in the canvas.
* @returns center point.
*/
export default function getCanvasEllipseCenter(ellipseCanvasPoints: Types.Point2[]) : Types.Point2 {
const [bottom, top, left, right] = ellipseCanvasPoints;
const topLeft = [left[0], top[1]];
const bottomRight = [right[0], bottom[1]];
return [(topLeft[0] + bottomRight[0]) / 2, (topLeft[1] + bottomRight[1]) / 2] as Types.Point2;
}
3 changes: 2 additions & 1 deletion packages/tools/src/utilities/math/ellipse/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pointInEllipse from './pointInEllipse';
import getCanvasEllipseCorners from './getCanvasEllipseCorners';
import getCanvasEllipseCenter from './getCanvasEllipseCenter';

export { pointInEllipse, getCanvasEllipseCorners };
export { pointInEllipse, getCanvasEllipseCorners, getCanvasEllipseCenter };

0 comments on commit 534a338

Please sign in to comment.