Skip to content

Commit

Permalink
feat: Add undo/redo to annotation tools and labelmaps (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 authored Dec 5, 2024
1 parent d386daf commit 846d2a0
Show file tree
Hide file tree
Showing 51 changed files with 1,283 additions and 285 deletions.
33 changes: 19 additions & 14 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ function deepEqual(obj1: unknown, obj2: unknown): boolean;
const deepMerge: (target?: {}, source?: {}, optionsArgument?: any) => any;

// @public (undocumented)
const DefaultHistoryMemo: HistoryMemo_2;
const DefaultHistoryMemo: HistoryMemo;

// @public (undocumented)
interface DicomDateObject {
Expand Down Expand Up @@ -1416,17 +1416,8 @@ function hexToRgb(hex: any): {
b: number;
};

declare namespace HistoryMemo {
export {
Memo,
Memoable,
HistoryMemo_2 as HistoryMemo,
DefaultHistoryMemo
}
}

// @public (undocumented)
class HistoryMemo_2 {
class HistoryMemo {
constructor(label?: string, size?: number);
// (undocumented)
readonly label: any;
Expand All @@ -1441,6 +1432,15 @@ class HistoryMemo_2 {
undo(items?: number): void;
}

declare namespace HistoryMemo_2 {
export {
Memo,
Memoable,
HistoryMemo,
DefaultHistoryMemo
}
}

// @public (undocumented)
type IBaseVolumeViewport = BaseVolumeViewport;

Expand Down Expand Up @@ -2567,6 +2567,7 @@ type Mat3 = [number, number, number, number, number, number, number, number, num
// @public (undocumented)
type Memo = {
restoreMemo: (undo?: boolean) => void;
commitMemo?: () => boolean;
};

// @public (undocumented)
Expand Down Expand Up @@ -2784,7 +2785,7 @@ class PointsManager<T> {
// (undocumented)
static create2(initialSize?: number): PointsManager<Point2>;
// (undocumented)
static create3(initialSize?: number): PointsManager<Point3>;
static create3(initialSize?: number, points?: Point3[]): PointsManager<Point3>;
// (undocumented)
data: Float32Array;
// (undocumented)
Expand Down Expand Up @@ -3883,7 +3884,11 @@ declare namespace Types {
IBaseVolumeViewport,
GeometryLoaderFn,
ScrollOptions_2 as ScrollOptions,
JumpToSliceOptions
JumpToSliceOptions,
Memo,
HistoryMemo,
VoxelManager,
RLEVoxelMap
}
}
export { Types }
Expand Down Expand Up @@ -3962,7 +3967,7 @@ declare namespace utilities {
isValidVolume,
metadataProvider_2 as genericMetadataProvider,
isVideoTransferSyntax,
HistoryMemo,
HistoryMemo_2 as HistoryMemo,
generateVolumePropsFromImageIds,
getBufferConfiguration,
VoxelManager,
Expand Down
129 changes: 114 additions & 15 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export abstract class AnnotationDisplayTool extends BaseTool {
// (undocumented)
protected createAnnotation(evt: EventTypes_2.InteractionEventType): Annotation;
// (undocumented)
filterInteractableAnnotationsForElement(element: HTMLDivElement, annotations: Annotations): Annotations | undefined;
filterInteractableAnnotationsForElement(element: HTMLDivElement, annotations: Annotations): Annotations;
// (undocumented)
protected getReferencedImageId(viewport: Types_2.IViewport, worldPos: Types_2.Point3, viewPlaneNormal: Types_2.Point3, viewUp?: Types_2.Point3): string;
// (undocumented)
Expand Down Expand Up @@ -510,6 +510,39 @@ export abstract class AnnotationTool extends AnnotationDisplayTool {
// (undocumented)
static createAnnotationForViewport(viewport: any, ...annotationBaseData: any[]): Annotation;
// (undocumented)
static createAnnotationMemo(element: any, annotation: Annotation, options?: {
newAnnotation?: boolean;
deleting?: boolean;
}): {
restoreMemo: () => void;
};
// (undocumented)
protected static createAnnotationState(annotation: Annotation, deleting?: boolean): {
annotationUID: string;
data: {
[key: string]: unknown;
handles?: {
points?: Types_2.Point3[];
activeHandleIndex?: number | null;
textBox?: {
hasMoved?: boolean;
worldPosition?: Types_2.Point3;
worldBoundingBox?: {
topLeft: Types_2.Point3;
topRight: Types_2.Point3;
bottomLeft: Types_2.Point3;
bottomRight: Types_2.Point3;
};
};
[key: string]: unknown;
};
cachedStats?: Record<string, unknown>;
};
deleting: boolean;
};
// (undocumented)
protected createMemo(element: any, annotation: any, options?: any): void;
// (undocumented)
protected getAnnotationStyle(context: {
annotation: Annotation;
styleSpecifier: StyleSpecifier;
Expand Down Expand Up @@ -667,6 +700,8 @@ export abstract class BaseTool {
};
};
// (undocumented)
doneEditMemo(): void;
// (undocumented)
protected getTargetId(viewport: Types_2.IViewport): string | undefined;
// (undocumented)
protected getTargetImageData(targetId: string): Types_2.IImageData | Types_2.CPUIImageData;
Expand Down Expand Up @@ -915,6 +950,8 @@ enum ChangeTypes {
// (undocumented)
HandlesUpdated = "HandlesUpdated",
// (undocumented)
History = "History",
// (undocumented)
InitialSetup = "InitialSetup",
// (undocumented)
Interaction = "Interaction",
Expand Down Expand Up @@ -1185,7 +1222,7 @@ export class CircleROITool extends AnnotationTool {
}

// @public (undocumented)
export class CircleScissorsTool extends BaseTool {
export class CircleScissorsTool extends LabelmapBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
_activateDraw: (element: any) => void;
Expand All @@ -1209,6 +1246,7 @@ export class CircleScissorsTool extends BaseTool {
hasMoved?: boolean;
imageId: string;
centerCanvas?: Array<number>;
memo?: LabelmapMemo_2;
} | null;
// (undocumented)
_endCallback: (evt: EventTypes_2.InteractionEventType) => void;
Expand Down Expand Up @@ -1322,6 +1360,8 @@ export class CobbAngleTool extends AnnotationTool {
isNearSecondLine: boolean;
};
// (undocumented)
_dragCallback: (evt: EventTypes_2.MouseDragEventType | EventTypes_2.MouseMoveEventType) => void;
// (undocumented)
editData: {
annotation: Annotation;
viewportIdsToRender: string[];
Expand All @@ -1333,6 +1373,8 @@ export class CobbAngleTool extends AnnotationTool {
isNearSecondLine?: boolean;
} | null;
// (undocumented)
_endCallback: (evt: EventTypes_2.MouseUpEventType | EventTypes_2.MouseClickEventType) => void;
// (undocumented)
getArcsStartEndPoints: ({ firstLine, secondLine, mid1, mid2, }: {
firstLine: any;
secondLine: any;
Expand All @@ -1357,10 +1399,6 @@ export class CobbAngleTool extends AnnotationTool {
// (undocumented)
_mouseDownCallback: (evt: EventTypes_2.MouseUpEventType | EventTypes_2.MouseClickEventType) => void;
// (undocumented)
_mouseDragCallback: (evt: EventTypes_2.MouseDragEventType | EventTypes_2.MouseMoveEventType) => void;
// (undocumented)
_mouseUpCallback: (evt: EventTypes_2.MouseUpEventType | EventTypes_2.MouseClickEventType) => void;
// (undocumented)
renderAnnotation: (enabledElement: Types_2.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
// (undocumented)
_throttledCalculateCachedStats: Function;
Expand Down Expand Up @@ -1542,10 +1580,12 @@ type ContourAnnotationCompletedEventDetail = AnnotationCompletedEventDetail & {
// @public (undocumented)
type ContourAnnotationData = {
data: {
cachedStats?: Record<string, unknown>;
contour: {
polyline: Types_2.Point3[];
closed: boolean;
windingDirection?: ContourWindingDirection;
pointsManager?: Types_2.IPointsManager<Types_2.Point3>;
};
};
onInterpolationComplete?: () => void;
Expand Down Expand Up @@ -1636,6 +1676,23 @@ function createCameraPositionSynchronizer(synchronizerName: string): Synchronize
// @public (undocumented)
function createImageSliceSynchronizer(synchronizerName: string): Synchronizer;

// @public (undocumented)
function createLabelmapMemo<T>(segmentationId: string, segmentationVoxelManager: Types_2.IVoxelManager<T>, preview?: InitializedOperationData): {
segmentationId: string;
restoreMemo: typeof restoreMemo;
commitMemo: typeof commitMemo;
segmentationVoxelManager: Types_2.IVoxelManager<number>;
voxelManager: Types_2.IVoxelManager<number>;
memo: LabelmapMemo_2;
preview: InitializedOperationData;
} | {
segmentationId: string;
restoreMemo: typeof restoreMemo;
commitMemo: typeof commitMemo;
segmentationVoxelManager: Types_2.IVoxelManager<T>;
voxelManager: utilities_2.VoxelManager<T>;
};

// @public (undocumented)
function createLabelmapVolumeForViewport(input: {
viewportId: string;
Expand All @@ -1655,6 +1712,26 @@ function createPresentationViewSynchronizer(synchronizerName: string, options?:
// @public (undocumented)
function createPresentationViewSynchronizer_2(synchronizerName: string): Synchronizer;

// @public (undocumented)
function createPreviewMemo(segmentationId: string, preview: InitializedOperationData): {
segmentationId: string;
restoreMemo: typeof restoreMemo;
commitMemo: typeof commitMemo;
segmentationVoxelManager: Types_2.IVoxelManager<number>;
voxelManager: Types_2.IVoxelManager<number>;
memo: LabelmapMemo_2;
preview: InitializedOperationData;
};

// @public (undocumented)
function createRleMemo<T>(segmentationId: string, segmentationVoxelManager: Types_2.IVoxelManager<T>): {
segmentationId: string;
restoreMemo: typeof restoreMemo;
commitMemo: typeof commitMemo;
segmentationVoxelManager: Types_2.IVoxelManager<T>;
voxelManager: utilities_2.VoxelManager<T>;
};

// @public (undocumented)
const createStackImageSynchronizer: typeof createImageSliceSynchronizer;

Expand Down Expand Up @@ -3259,6 +3336,25 @@ type KeyUpEventDetail = KeyDownEventDetail;
// @public (undocumented)
type KeyUpEventType = Types_2.CustomEventType<KeyUpEventDetail>;

declare namespace LabelmapMemo {
export {
createLabelmapMemo,
restoreMemo,
createRleMemo,
createPreviewMemo,
LabelmapMemo_2 as LabelmapMemo
}
}

// @public (undocumented)
type LabelmapMemo_2 = Types_2.Memo & {
segmentationVoxelManager: Types_2.IVoxelManager<number>;
voxelManager: Types_2.IVoxelManager<number>;
redoVoxelManager?: Types_2.IVoxelManager<number>;
undoVoxelManager?: Types_2.IVoxelManager<number>;
memo?: LabelmapMemo_2;
};

// @public (undocumented)
type LabelmapStyle = BaseLabelmapStyle & InactiveLabelmapStyle;

Expand All @@ -3279,6 +3375,7 @@ type LabelmapToolOperationData = {
};
preview: any;
toolGroupId: string;
createMemo: (segmentId: any, segmentVoxels: any, previewVoxels?: any, previewMemo?: any) => LabelmapMemo_2;
};

// @public (undocumented)
Expand Down Expand Up @@ -3803,8 +3900,6 @@ export class PanTool extends BaseTool {
// (undocumented)
mouseDragCallback(evt: EventTypes_2.InteractionEventType): void;
// (undocumented)
preMouseDownCallback: (evt: EventTypes_2.InteractionEventType) => boolean;
// (undocumented)
static toolName: any;
// (undocumented)
touchDragCallback(evt: EventTypes_2.InteractionEventType): void;
Expand Down Expand Up @@ -4427,7 +4522,7 @@ declare namespace rectangleROITool {
}

// @public (undocumented)
export class RectangleScissorsTool extends BaseTool {
export class RectangleScissorsTool extends LabelmapBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
_activateDraw: (element: any) => void;
Expand Down Expand Up @@ -4666,6 +4761,9 @@ function resetElementCursor(element: HTMLDivElement): void;
// @public (undocumented)
function resetToGlobalStyle(): void;

// @public (undocumented)
function restoreMemo(isUndo?: boolean): void;

// @public (undocumented)
interface ROICachedStats {
// (undocumented)
Expand Down Expand Up @@ -4864,7 +4962,8 @@ declare namespace segmentation_2 {
getSegmentIndexAtLabelmapBorder,
getHoveredContourSegmentationAnnotation,
getBrushToolInstances,
growCut
growCut,
LabelmapMemo
}
}

Expand Down Expand Up @@ -5118,7 +5217,7 @@ type SphereInfo = {
};

// @public (undocumented)
export class SphereScissorsTool extends BaseTool {
export class SphereScissorsTool extends LabelmapBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
_activateDraw: (element: any) => void;
Expand Down Expand Up @@ -6251,6 +6350,8 @@ export class VideoRedactionTool extends AnnotationTool {
// (undocumented)
_deactivateModify: (element: any) => void;
// (undocumented)
_dragCallback: (evt: any) => void;
// (undocumented)
editData: {
annotation: Annotation;
viewportUIDsToRender: string[];
Expand All @@ -6259,6 +6360,8 @@ export class VideoRedactionTool extends AnnotationTool {
hasMoved?: boolean;
} | null;
// (undocumented)
_endCallback: (evt: any) => void;
// (undocumented)
getHandleNearImagePoint: (element: any, annotation: any, canvasCoords: any, proximity: any) => any;
// (undocumented)
_getImageVolumeFromTargetUID(targetUID: any, renderingEngine: any): {
Expand Down Expand Up @@ -6287,10 +6390,6 @@ export class VideoRedactionTool extends AnnotationTool {
// (undocumented)
isPointNearTool: (element: any, annotation: any, canvasCoords: any, proximity: any) => boolean;
// (undocumented)
_mouseDragCallback: (evt: any) => void;
// (undocumented)
_mouseUpCallback: (evt: any) => void;
// (undocumented)
renderAnnotation: (enabledElement: Types_2.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
// (undocumented)
_throttledCalculateCachedStats: Function;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ import type ICachedGeometry from './ICachedGeometry';
import type { IContourSet } from './IContourSet';
import type { IContour } from './IContour';
import type RGB from './RGB';
import type { Memo, HistoryMemo } from '../utilities/historyMemo';
import type { VoxelManager } from '../utilities/VoxelManager';
import type RLEVoxelMap from '../utilities/RLEVoxelMap';
import type { ColormapPublic, ColormapRegistration } from './Colormap';
import type { ViewportProperties } from './ViewportProperties';
import type {
Expand Down Expand Up @@ -300,4 +303,8 @@ export type {
GeometryLoaderFn,
ScrollOptions,
JumpToSliceOptions,
Memo,
HistoryMemo,
VoxelManager,
RLEVoxelMap,
};
Loading

0 comments on commit 846d2a0

Please sign in to comment.