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

feat: Added contour roi interpolation tool #966

Closed
Show file tree
Hide file tree
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
81 changes: 79 additions & 2 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare namespace activeSegmentation {
}

// @public (undocumented)
function addAnnotation(annotation: Annotation, annotationGroupSelector: AnnotationGroupSelector): string;
function addAnnotation(annotation: Annotation, annotationGroupSelector: AnnotationGroupSelector, suppressEvents?: boolean): string;

// @public (undocumented)
const addCanvasPointsToArray: (element: HTMLDivElement, canvasPoints: Types_2.Point2[], newCanvasPoint: Types_2.Point2, commonData: PlanarFreehandROICommonData) => number;
Expand Down Expand Up @@ -216,6 +216,7 @@ type Annotation = {
isLocked?: boolean;
isVisible?: boolean;
invalidated?: boolean;
autoGenerated?: boolean;
metadata: {
cameraPosition?: Types_2.Point3;
cameraFocalPoint?: Types_2.Point3;
Expand Down Expand Up @@ -342,6 +343,38 @@ type AnnotationGroupSelector = HTMLDivElement | string;
// @public (undocumented)
type AnnotationHandle = Types_2.Point3;

// @public (undocumented)
type AnnotationInterpolationCompletedEventDetail = {
annotation: InterpolationROIAnnotation;
element: HTMLDivElement;
viewportId: string;
renderingEngineId: string;
};

// @public (undocumented)
type AnnotationInterpolationCompletedEventType = Types_2.CustomEventType<AnnotationInterpolationCompletedEventDetail>;

// @public (undocumented)
type AnnotationInterpolationRemovedEventDetail = {
annotations: Array<InterpolationROIAnnotation>;
element: HTMLDivElement;
viewportId: string;
renderingEngineId: string;
};

// @public (undocumented)
type AnnotationInterpolationRemovedEventType = Types_2.CustomEventType<AnnotationInterpolationRemovedEventDetail>;

// @public (undocumented)
type AnnotationLabelChangeEventDetail = {
annotation: Annotation;
viewportId: string;
renderingEngineId: string;
};

// @public (undocumented)
type AnnotationLabelChangeEventType = Types_2.CustomEventType<AnnotationLabelChangeEventDetail>;

// @public (undocumented)
type AnnotationLockChangeEventDetail = {
added: Array<Annotation>;
Expand Down Expand Up @@ -415,6 +448,8 @@ type AnnotationStyle_2 = {

// @public (undocumented)
enum AnnotationStyleStates {
// (undocumented)
AutoGenerated = "AutoGenerated",
// (undocumented)
Default = "",
// (undocumented)
Expand Down Expand Up @@ -1243,6 +1278,15 @@ declare namespace CONSTANTS {
}
export { CONSTANTS }

// @public (undocumented)
export class ContourROITool extends PlanarFreehandROITool {
constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
// (undocumented)
addNewAnnotation: (evt: EventTypes_2.InteractionEventType) => InterpolationROIAnnotation;
// (undocumented)
getSliceData(viewport: any, referencedImageId: any): Types_2.ImageSliceData;
}

// @public (undocumented)
type ContourSegmentationData = {
geometryIds: string[];
Expand Down Expand Up @@ -1742,6 +1786,10 @@ enum Events {
// (undocumented)
ANNOTATION_COMPLETED = "CORNERSTONE_TOOLS_ANNOTATION_COMPLETED",
// (undocumented)
ANNOTATION_INTERPOLATION_PROCESS_COMPLETED = "CORNERSTONE_TOOLS_ANNOTATION_INTERPOLATION_PROCESS_COMPLETED",
// (undocumented)
ANNOTATION_LABEL_CHANGE = "CORNERSTONE_TOOLS_ANNOTATION_LABEL_CHANGE",
// (undocumented)
ANNOTATION_LOCK_CHANGE = "CORNERSTONE_TOOLS_ANNOTATION_LOCK_CHANGE",
// (undocumented)
ANNOTATION_MODIFIED = "CORNERSTONE_TOOLS_ANNOTATION_MODIFIED",
Expand All @@ -1754,6 +1802,8 @@ enum Events {
// (undocumented)
ANNOTATION_VISIBILITY_CHANGE = "CORNERSTONE_TOOLS_ANNOTATION_VISIBILITY_CHANGE",
// (undocumented)
INTERPOLATED_ANNOTATIONS_REMOVED = "CORNERSTONE_TOOLS_INTERPOLATED_ANNOTATIONS_REMOVED",
// (undocumented)
KEY_DOWN = "CORNERSTONE_TOOLS_KEY_DOWN",
// (undocumented)
KEY_UP = "CORNERSTONE_TOOLS_KEY_UP",
Expand Down Expand Up @@ -1841,6 +1891,12 @@ declare namespace EventTypes_2 {
AnnotationVisibilityChangeEventDetail,
AnnotationLockChangeEventType,
AnnotationVisibilityChangeEventType,
AnnotationLabelChangeEventDetail,
AnnotationLabelChangeEventType,
AnnotationInterpolationCompletedEventDetail,
AnnotationInterpolationCompletedEventType,
AnnotationInterpolationRemovedEventDetail,
AnnotationInterpolationRemovedEventType,
SegmentationDataModifiedEventType,
SegmentationRepresentationModifiedEventDetail,
SegmentationRepresentationModifiedEventType,
Expand Down Expand Up @@ -2264,6 +2320,24 @@ type InteractionTypes = 'Mouse' | 'Touch';
// @public (undocumented)
function interpolateAnnotation(enabledElement: Types_2.IEnabledElement, annotation: PlanarFreehandROIAnnotation, knotsRatioPercentage: number): boolean;

// @public (undocumented)
interface InterpolationROIAnnotation extends PlanarFreehandROIAnnotation {
// (undocumented)
interpolationUID?: string;
// (undocumented)
metadata: {
cameraPosition?: Types_2.Point3;
cameraFocalPoint?: Types_2.Point3;
viewPlaneNormal?: Types_2.Point3;
viewUp?: Types_2.Point3;
annotationUID?: string;
FrameOfReferenceUID: string;
referencedImageId?: string;
toolName: string;
referencedSliceIndex?: number;
};
}

// @public (undocumented)
function intersectLine(line1Start: Types_2.Point2, line1End: Types_2.Point2, line2Start: Types_2.Point2, line2End: Types_2.Point2): number[];

Expand Down Expand Up @@ -3216,6 +3290,8 @@ interface PlanarFreehandROIAnnotation extends Annotation {
export class PlanarFreehandROITool extends AnnotationTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
protected activateDraw: (evt: EventTypes_2.InteractionEventType, annotation: PlanarFreehandROIAnnotation, viewportIdsToRender: string[]) => void;
// (undocumented)
addNewAnnotation: (evt: EventTypes_2.InteractionEventType) => PlanarFreehandROIAnnotation;
// (undocumented)
_calculateCachedStats: (annotation: any, viewport: any, renderingEngine: any, enabledElement: any) => any;
Expand Down Expand Up @@ -3834,7 +3910,7 @@ function registerCursor(toolName: string, iconContent: string, viewBox: {
function removeAllAnnotations(): void;

// @public (undocumented)
function removeAnnotation(annotationUID: string): void;
function removeAnnotation(annotationUID: string, suppressEvents?: boolean): void;

// @public (undocumented)
function removeColorLUT(colorLUTIndex: number): void;
Expand Down Expand Up @@ -4810,6 +4886,7 @@ declare namespace ToolSpecificAnnotationTypes {
RectangleROIThresholdAnnotation,
RectangleROIStartEndThresholdAnnotation,
PlanarFreehandROIAnnotation,
InterpolationROIAnnotation,
ArrowAnnotation,
AngleAnnotation,
UltrasoundDirectionalAnnotation,
Expand Down
82 changes: 82 additions & 0 deletions packages/adapters/src/adapters/Cornerstone/ContourRoi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { utilities } from "dcmjs";

import MeasurementReport from "./MeasurementReport";
import CORNERSTONE_4_TAG from "./cornerstone4Tag";

const { Polyline: TID300Polyline } = utilities.TID300;

class ContourRoi {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this differ from FreehandROI? Would like to end up with just a single representation for both types if we can figure that out.

static getMeasurementData(MeasurementGroup) {
const { defaultState, SCOORDGroup, NUMGroup } =
MeasurementReport.getSetupMeasurementData(MeasurementGroup);

const state = {
...defaultState,
toolType: ContourRoi.toolType,
handles: {
points: [],
textBox: {
active: false,
hasMoved: false,
movesIndependently: false,
drawnIndependently: true,
allowedOutsideImage: true,
hasBoundingBox: true
}
},
cachedStats: {
area: NUMGroup ? NUMGroup.MeasuredValueSequence.NumericValue : 0
},
color: undefined,
invalidated: true
};
const { GraphicData } = SCOORDGroup;
for (let i = 0; i < GraphicData.length; i += 2) {
state.handles.points.push({
x: GraphicData[i],
y: GraphicData[i + 1]
});
}

return state;
}

static getTID300RepresentationArguments(tool) {
const { handles, finding, findingSites, cachedStats = {} } = tool;
const { points } = handles;
const { area = 0, perimeter = 0 } = cachedStats;

const trackingIdentifierTextValue =
"cornerstoneTools@^4.0.0:FreehandRoi";

return {
points,
area,
perimeter,
trackingIdentifierTextValue,
finding,
findingSites: findingSites || []
};
}
}

ContourRoi.toolType = "ContourRoi";
ContourRoi.utilityToolType = "ContourRoi";
ContourRoi.TID300Representation = TID300Polyline;
ContourRoi.isValidCornerstoneTrackingIdentifier = TrackingIdentifier => {
if (!TrackingIdentifier.includes(":")) {
return false;
}

const [cornerstone4Tag, toolType] = TrackingIdentifier.split(":");

if (cornerstone4Tag !== CORNERSTONE_4_TAG) {
return false;
}

return toolType === ContourRoi.toolType;
};

MeasurementReport.registerTool(ContourRoi);

export default ContourRoi;
5 changes: 4 additions & 1 deletion packages/adapters/src/adapters/Cornerstone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ArrowAnnotate from "./ArrowAnnotate";
import CobbAngle from "./CobbAngle";
import Angle from "./Angle";
import RectangleRoi from "./RectangleRoi";
import ContourRoi from "./ContourRoi";

// Segmentation
import Segmentation from "./Segmentation";

Expand All @@ -21,7 +23,8 @@ const CornerstoneSR = {
MeasurementReport,
CobbAngle,
Angle,
RectangleRoi
RectangleRoi,
ContourRoi
};

const CornerstoneSEG = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ You can get/add annotations using the following API:

```js
// Adds annotation
cornerstone3DTools.annotations.state.addAnnotation(element, annotation);
cornerstone3DTools.annotations.state.addAnnotation(
annotation,
element,
suppressEvents
);

// Remove the annotations given the annotation reference.
cornerstone3DTools.annotations.state.removeAnnotation(element, annotationUID);
cornerstone3DTools.annotations.state.removeAnnotation(
annotationUID,
suppressEvents
);

// Returns the full annotations for a given Tool
cornerstone3DTools.annotations.state.getAnnotations(element, toolName);
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/docs/how-to-guides/custom-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ create Annotations for the interaction. Example `AnnotationTool`s include:
- Length
- Probe
- RectangleROI
- PlanarFreehandROI
- ContourROI

## Next steps

Expand Down
Loading