Skip to content
Merged
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
1 change: 0 additions & 1 deletion common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,6 @@ export class PlanarFreehandContourSegmentationTool extends PlanarFreehandROITool
type PlanarFreehandROIAnnotation = ContourAnnotation & {
data: {
label?: string;
isOpenContour?: boolean;
isOpenUShapeContour?: boolean;
openUShapeContourVectorToPeak?: Types_2.Point3[];
cachedStats?: ROICachedStats;
Expand Down
28 changes: 22 additions & 6 deletions packages/adapters/src/adapters/Cornerstone3D/PlanarFreehandROI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PlanarFreehandROI {
imageToWorldCoords,
metadata
) {
const { defaultState, SCOORDGroup, ReferencedFrameNumber } =
const { defaultState, NUMGroup, SCOORDGroup, ReferencedFrameNumber } =
MeasurementReport.getSetupMeasurementData(
MeasurementGroup,
sopInstanceUIDToImageIdMap,
Expand Down Expand Up @@ -79,15 +79,21 @@ class PlanarFreehandROI {
const state = defaultState;

state.annotation.data = {
polyline: worldCoords,
isOpenContour,
contour: { polyline: worldCoords, closed: !isOpenContour },
handles: {
points,
activeHandleIndex: null,
textBox: {
hasMoved: false
}
},
cachedStats: {
[`imageId:${referencedImageId}`]: {
area: NUMGroup
? NUMGroup.MeasuredValueSequence.NumericValue
: null
}
},
frameNumber: ReferencedFrameNumber
};

Expand All @@ -96,7 +102,9 @@ class PlanarFreehandROI {

static getTID300RepresentationArguments(tool, worldToImageCoords) {
const { data, finding, findingSites, metadata } = tool;
const { isOpenContour, polyline } = data;

const { polyline, closed } = data.contour;
const isOpenContour = closed !== true;

const { referencedImageId } = metadata;

Expand All @@ -118,13 +126,21 @@ class PlanarFreehandROI {
points.push([firstPoint[0], firstPoint[1]]);
}

const area = 0; // TODO -> The tool doesn't have these stats yet.
const perimeter = 0;
const { area, areaUnit, modalityUnit, perimeter, mean, max, stdDev } =
data.cachedStats[`imageId:${referencedImageId}`] || {};

return {
points,
area,
modalityUnit,
areaUnit,
perimeter,
unit: modalityUnit,
/** Present in cachedStats but not being used by TID300 polyline in dcmjs */
mean,
max,
stdDev,
/** Other */
trackingIdentifierTextValue,
finding,
findingSites: findingSites || []
Expand Down
57 changes: 46 additions & 11 deletions packages/tools/src/tools/annotation/PlanarFreehandROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ const { pointCanProjectOnLine } = polyline;
const { EPSILON } = CONSTANTS;

const PARALLEL_THRESHOLD = 1 - EPSILON;

function calculatePerimeter(polyline, closed) {
let perimeter = 0;

for (let i = 0; i < polyline.length - 1; i++) {
const point1 = polyline[i];
const point2 = polyline[i + 1];

perimeter += Math.sqrt(
Math.pow(point2[0] - point1[0], 2) + Math.pow(point2[1] - point1[1], 2)
);
}

if (closed) {
const firstPoint = polyline[0];
const lastPoint = polyline[polyline.length - 1];
perimeter += Math.sqrt(
Math.pow(lastPoint[0] - firstPoint[0], 2) +
Math.pow(lastPoint[1] - firstPoint[1], 2)
);
}

return perimeter;
}

/**
* PlanarFreehandROITool lets you draw annotations that define an arbitrarily drawn region.
* You can use the PlanarFreehandROITool in all perpendicular views (axial, sagittal, coronal),
Expand Down Expand Up @@ -243,7 +268,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
*/
epsilon: 0.1,
},
calculateStats: false,
calculateStats: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we set it back to false, it is brutal to calculate stats on each frame

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stats were not being calculated / displayed. Maybe the problem is the tool implementation or when the stats are calculated?

getTextLines: defaultGetTextLines,
statsCalculator: BasicStatsCalculator,
},
Expand Down Expand Up @@ -294,7 +319,9 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
);

this.activateDraw(evt, annotation, viewportIdsToRender);

evt.preventDefault();

triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);

return annotation;
Expand Down Expand Up @@ -350,6 +377,8 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
} else {
this.activateOpenContourEdit(evt, annotation, viewportIdsToRender);
}

evt.preventDefault();
};

/**
Expand Down Expand Up @@ -536,16 +565,21 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
annotation.data.handles.points.length = 0;
};

return <PlanarFreehandROIAnnotation>csUtils.deepMerge(contourAnnotation, {
data: {
contour: {
polyline: [<Types.Point3>[...worldPos]],
const annotation = <PlanarFreehandROIAnnotation>csUtils.deepMerge(
contourAnnotation,
{
data: {
contour: {
polyline: [<Types.Point3>[...worldPos]],
},
label: '',
cachedStats: {},
},
label: '',
cachedStats: {},
},
onInterpolationComplete,
});
onInterpolationComplete,
}
);

return annotation;
}

protected getAnnotationStyle(context) {
Expand Down Expand Up @@ -682,7 +716,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
) => {
const { data } = annotation;
const { cachedStats } = data;
const { polyline: points } = data.contour;
const { polyline: points, closed } = data.contour;

const targetIds = Object.keys(cachedStats);

Expand Down Expand Up @@ -835,6 +869,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
cachedStats[targetId] = {
Modality: metadata.Modality,
area,
perimeter: calculatePerimeter(canvasCoordinates, closed),
mean: stats.mean?.value,
max: stats.max?.value,
stdDev: stats.stdDev?.value,
Expand Down
1 change: 0 additions & 1 deletion packages/tools/src/types/ToolSpecificAnnotationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export interface CircleROIStartEndThresholdAnnotation extends Annotation {
export type PlanarFreehandROIAnnotation = ContourAnnotation & {
data: {
label?: string;
isOpenContour?: boolean;
isOpenUShapeContour?: boolean;
// Present if isOpenUShapeContour is true:
openUShapeContourVectorToPeak?: Types.Point3[];
Expand Down