Skip to content

Commit

Permalink
feat: Livewire editing (#1035)
Browse files Browse the repository at this point in the history
* Added contour roi interpolation tool

* Generated documentation and minor updates

* Test file updated and minor documentation updation

* Added interpolated annotations remove event type

* fix: Inter-slice interpolation working with master

* Reduction of required code to be closer to original

* feat: Contour segmentation interpolation - basically working

* Compile fixes

* fix: build issues

* fix: Integration tests

* fix: Autogenerated outline dash/fill styles

* fix: Allow contour interpolation to be done on any contour segmentation

* Remove ContourROITool in favour of configuration

* feat: Add livewire interpolation example

* feat: Add spline interpolation

* fix: Generate handles for spline interpolation

* fix: Make livewire fire the right annotation completed event

* fix: Numerous fixes for annotation update notification

* Change to use getTargetId

* Fix some docs and minor issues

* PR review changes

* Use the points array for conversion to/from xyz

* Accept all the autogenerated contours

* Fix the livewire interpolation

* feat: Add contour removal for segments that have a very high cost

* feat: Add basic edit capabilities to central handles of livewire

* fix: Livewire editing

* Fix the merge

* fix: Hang when edit point is outside image data

* Fix clockwise/anti-clockwise livewire annotations

* PR comments

* Renamed left/right as previous/next as per PR request

---------
  • Loading branch information
wayfarer3130 authored Jan 25, 2024
1 parent c405ce8 commit 655a241
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 103 deletions.
15 changes: 13 additions & 2 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ declare namespace contours {
generateContourSetsFromLabelmap,
AnnotationToPointData,
interpolation,
acceptAutogeneratedInterpolations
acceptAutogeneratedInterpolations,
findHandlePolylineIndex
}
}

Expand Down Expand Up @@ -2103,6 +2104,9 @@ function filterViewportsWithToolEnabled(viewports: Array<Types_2.IViewport>, too
// @public (undocumented)
function findClosestPoint(sourcePoints: Array<Types_2.Point2>, targetPoint: Types_2.Point2): Types_2.Point2;

// @public (undocumented)
function findHandlePolylineIndex(annotation: ContourAnnotation, handleIndex: number): number;

// @public (undocumented)
function floodFill(getter: FloodFillGetter, seed: Types_2.Point2 | Types_2.Point3, options?: FloodFillOptions): FloodFillResult;

Expand Down Expand Up @@ -3057,11 +3061,15 @@ export class LivewireContourTool extends ContourSegmentationBaseTool {
lastCanvasPoint?: Types_2.Point2;
confirmedPath?: LivewirePath;
currentPath?: LivewirePath;
confirmedPathRight?: LivewirePath;
closed?: boolean;
worldToSlice?: (point: Types_2.Point3) => Types_2.Point2;
sliceToWorld?: (point: Types_2.Point2) => Types_2.Point3;
originalPath?: Types_2.Point3[];
} | null;
// (undocumented)
editHandle(worldPos: Types_2.Point3, element: any, annotation: any, handleIndex: number): void;
// (undocumented)
_endCallback: (evt: EventTypes_2.InteractionEventType) => void;
// (undocumented)
handleSelectedCallback: (evt: EventTypes_2.InteractionEventType, annotation: LivewireContourAnnotation, handle: ToolHandle) => void;
Expand All @@ -3086,6 +3094,8 @@ export class LivewireContourTool extends ContourSegmentationBaseTool {
svgDrawingHelper: SVGDrawingHelper;
}): boolean;
// (undocumented)
protected setupBaseEditData(worldPos: any, element: any, annotation: any, rightPos?: any): void;
// (undocumented)
static toolName: string;
// (undocumented)
toolSelectedCallback: (evt: EventTypes_2.InteractionEventType, annotation: LivewireContourAnnotation) => void;
Expand Down Expand Up @@ -5151,7 +5161,8 @@ declare namespace ToolSpecificAnnotationTypes {
ReferenceCursor,
ReferenceLineAnnotation,
ScaleOverlayAnnotation,
VideoRedactionAnnotation
VideoRedactionAnnotation,
ContourAnnotation
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const interpolationTools = new Map<string, any>();
const configuration = {
interpolation: { enabled: true },
};
interpolationTools.set('LivewireInterpolation', {
baseTool: LivewireContourSegmentationTool.toolName,
configuration,
});
interpolationTools.set('FreeformInterpolation', {
baseTool: PlanarFreehandContourSegmentationTool.toolName,
configuration,
Expand All @@ -57,10 +61,6 @@ interpolationTools.set('SplineInterpolation', {
baseTool: SplineContourSegmentationTool.toolName,
configuration,
});
interpolationTools.set('LivewireInterpolation', {
baseTool: LivewireContourSegmentationTool.toolName,
configuration,
});
const interpolationToolName = [...interpolationTools.keys()][0];

const segmentIndexes = [1, 2, 3, 4, 5];
Expand All @@ -71,7 +71,7 @@ setTitleAndDescription(
'Here we demonstrate how to use the Contour Freehand Annotation Tool to draw 2D closed ROIs'
);

const size = '500px';
const size = '800px';
const content = document.getElementById('content');
const viewportGrid = document.createElement('div');

Expand Down Expand Up @@ -305,7 +305,8 @@ async function run() {
);

// Set the stack on the viewport
stackViewport.setStack(stackImageIds);
await stackViewport.setStack(stackImageIds);
stackViewport.setDisplayArea({ imageArea: [0.9, 0.9] });

// Set the volume to load
volume.load();
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/tools/annotation/EllipticalROITool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ class EllipticalROITool extends AnnotationTool {

if (this._isInsideVolume(worldPos1Index, worldPos2Index, dimensions)) {
this.isHandleOutsideImage = false;

const iMin = Math.min(worldPos1Index[0], worldPos2Index[0]);
const iMax = Math.max(worldPos1Index[0], worldPos2Index[0]);

Expand Down
Loading

0 comments on commit 655a241

Please sign in to comment.