@cornerstonejs/tools 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { eventTarget, triggerEvent } from '@cornerstonejs/core';
2
2
  import { Events } from '../../enums';
3
- import { getAnnotation } from './getAnnotation';
3
+ import { getAnnotation } from './annotationState';
4
4
  const globalLockedAnnotationUIDsSet = new Set();
5
5
  function setAnnotationLocked(annotationUID, locked = true) {
6
6
  const detail = makeEventDetail();
@@ -1,6 +1,6 @@
1
1
  import { eventTarget, triggerEvent } from '@cornerstonejs/core';
2
2
  import { Events } from '../../enums';
3
- import { getAnnotation } from './getAnnotation';
3
+ import { getAnnotation } from './annotationState';
4
4
  const selectedAnnotationUIDs = new Set();
5
5
  function setAnnotationSelected(annotationUID, selected = true, preserveSelected = false) {
6
6
  if (selected) {
@@ -1,10 +1,9 @@
1
1
  import type { Annotations, Annotation } from '../../types/AnnotationTypes';
2
- import type { AnnotationGroupSelector } from '../../types';
3
- import { getAnnotation } from './getAnnotation';
4
- declare function getAnnotationManager(): import("./FrameOfReferenceSpecificAnnotationManager").default;
5
- declare function setAnnotationManager(annotationManager: any): void;
6
- declare function resetAnnotationManager(): void;
2
+ import type { AnnotationGroupSelector, IAnnotationManager } from '../../types';
3
+ declare function getAnnotationManager(): any;
4
+ declare function setAnnotationManager(annotationManager: IAnnotationManager): void;
7
5
  declare function getAnnotations(toolName: string, annotationGroupSelector: AnnotationGroupSelector): Annotations;
6
+ declare function getAnnotation(annotationUID: string): Annotation;
8
7
  declare function getAllAnnotations(): Annotations;
9
8
  declare function clearParentAnnotation(annotation: Annotation): void;
10
9
  declare function addChildAnnotation(parentAnnotation: Annotation, childAnnotation: Annotation): void;
@@ -16,4 +15,4 @@ declare function removeAnnotation(annotationUID: string): void;
16
15
  declare function removeAllAnnotations(): void;
17
16
  declare function removeAnnotations(toolName: string, annotationGroupSelector: AnnotationGroupSelector): void;
18
17
  declare function invalidateAnnotation(annotation: Annotation): void;
19
- export { getAllAnnotations, getAnnotations, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, addAnnotation, removeAnnotation, removeAnnotations, removeAllAnnotations, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, getAnnotation, };
18
+ export { getAllAnnotations, getAnnotations, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, addAnnotation, removeAnnotation, removeAnnotations, removeAllAnnotations, setAnnotationManager, getAnnotationManager, invalidateAnnotation, getAnnotation, };
@@ -1,36 +1,21 @@
1
1
  import { utilities as csUtils } from '@cornerstonejs/core';
2
- import { defaultFrameOfReferenceSpecificAnnotationManager } from './FrameOfReferenceSpecificAnnotationManager';
3
- import { getAnnotation } from './getAnnotation';
4
2
  import { triggerAnnotationAddedForElement, triggerAnnotationAddedForFOR, triggerAnnotationRemoved, } from './helpers/state';
5
- import { checkAndSetAnnotationLocked } from './annotationLocking';
6
- import { checkAndDefineCachedStatsProperty, checkAndDefineTextBoxProperty, } from './utilities/defineProperties';
7
- import { checkAndSetAnnotationVisibility } from './annotationVisibility';
8
- let defaultManager = defaultFrameOfReferenceSpecificAnnotationManager;
9
- const preprocessingFn = (annotation) => {
10
- annotation = checkAndDefineTextBoxProperty(annotation);
11
- annotation = checkAndDefineCachedStatsProperty(annotation);
12
- const uid = annotation.annotationUID;
13
- const isLocked = checkAndSetAnnotationLocked(uid);
14
- annotation.isLocked = isLocked;
15
- const isVisible = checkAndSetAnnotationVisibility(uid);
16
- annotation.isVisible = isVisible;
17
- return annotation;
18
- };
19
- defaultManager.setPreprocessingFn(preprocessingFn);
3
+ let defaultManager;
20
4
  function getAnnotationManager() {
21
5
  return defaultManager;
22
6
  }
23
7
  function setAnnotationManager(annotationManager) {
24
8
  defaultManager = annotationManager;
25
9
  }
26
- function resetAnnotationManager() {
27
- defaultManager = defaultFrameOfReferenceSpecificAnnotationManager;
28
- }
29
10
  function getAnnotations(toolName, annotationGroupSelector) {
30
11
  const manager = getAnnotationManager();
31
12
  const groupKey = manager.getGroupKey(annotationGroupSelector);
32
13
  return manager.getAnnotations(groupKey, toolName);
33
14
  }
15
+ function getAnnotation(annotationUID) {
16
+ const manager = getAnnotationManager();
17
+ return manager.getAnnotation(annotationUID);
18
+ }
34
19
  function getAllAnnotations() {
35
20
  const manager = getAnnotationManager();
36
21
  return manager.getAllAnnotations();
@@ -130,4 +115,4 @@ function invalidateAnnotation(annotation) {
130
115
  : undefined;
131
116
  }
132
117
  }
133
- export { getAllAnnotations, getAnnotations, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, addAnnotation, removeAnnotation, removeAnnotations, removeAllAnnotations, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, getAnnotation, };
118
+ export { getAllAnnotations, getAnnotations, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, addAnnotation, removeAnnotation, removeAnnotations, removeAllAnnotations, setAnnotationManager, getAnnotationManager, invalidateAnnotation, getAnnotation, };
@@ -1,7 +1,7 @@
1
1
  import { eventTarget, triggerEvent } from '@cornerstonejs/core';
2
2
  import { Events } from '../../enums';
3
3
  import { isAnnotationSelected, deselectAnnotation, } from './annotationSelection';
4
- import { getAnnotation } from './getAnnotation';
4
+ import { getAnnotation } from './annotationState';
5
5
  const globalHiddenAnnotationUIDsSet = new Set();
6
6
  function setAnnotationVisibility(annotationUID, visible = true) {
7
7
  const detail = makeEventDetail();
@@ -1,8 +1,27 @@
1
1
  import * as config from './config';
2
2
  import * as locking from './annotationLocking';
3
3
  import * as selection from './annotationSelection';
4
- import * as state from './annotationState';
4
+ import * as annotationState from './annotationState';
5
5
  import * as visibility from './annotationVisibility';
6
6
  import FrameOfReferenceSpecificAnnotationManager from './FrameOfReferenceSpecificAnnotationManager';
7
7
  import AnnotationGroup from './AnnotationGroup';
8
+ import { resetAnnotationManager } from './resetAnnotationManager';
9
+ declare const state: {
10
+ resetAnnotationManager: typeof resetAnnotationManager;
11
+ getAllAnnotations: typeof annotationState.getAllAnnotations;
12
+ getAnnotations: typeof annotationState.getAnnotations;
13
+ getParentAnnotation: typeof annotationState.getParentAnnotation;
14
+ getChildAnnotations: typeof annotationState.getChildAnnotations;
15
+ clearParentAnnotation: typeof annotationState.clearParentAnnotation;
16
+ addChildAnnotation: typeof annotationState.addChildAnnotation;
17
+ getNumberOfAnnotations: typeof annotationState.getNumberOfAnnotations;
18
+ addAnnotation: typeof annotationState.addAnnotation;
19
+ removeAnnotation: typeof annotationState.removeAnnotation;
20
+ removeAnnotations: typeof annotationState.removeAnnotations;
21
+ removeAllAnnotations: typeof annotationState.removeAllAnnotations;
22
+ setAnnotationManager: typeof annotationState.setAnnotationManager;
23
+ getAnnotationManager: typeof annotationState.getAnnotationManager;
24
+ invalidateAnnotation: typeof annotationState.invalidateAnnotation;
25
+ getAnnotation: typeof annotationState.getAnnotation;
26
+ };
8
27
  export { config, locking, selection, state, visibility, FrameOfReferenceSpecificAnnotationManager, AnnotationGroup, };
@@ -1,8 +1,13 @@
1
1
  import * as config from './config';
2
2
  import * as locking from './annotationLocking';
3
3
  import * as selection from './annotationSelection';
4
- import * as state from './annotationState';
4
+ import * as annotationState from './annotationState';
5
5
  import * as visibility from './annotationVisibility';
6
6
  import FrameOfReferenceSpecificAnnotationManager from './FrameOfReferenceSpecificAnnotationManager';
7
7
  import AnnotationGroup from './AnnotationGroup';
8
+ import { resetAnnotationManager } from './resetAnnotationManager';
9
+ const state = {
10
+ ...annotationState,
11
+ resetAnnotationManager,
12
+ };
8
13
  export { config, locking, selection, state, visibility, FrameOfReferenceSpecificAnnotationManager, AnnotationGroup, };
@@ -0,0 +1 @@
1
+ export declare function resetAnnotationManager(): void;
@@ -0,0 +1,21 @@
1
+ import { checkAndDefineCachedStatsProperty, checkAndDefineTextBoxProperty, } from './utilities/defineProperties';
2
+ import { checkAndSetAnnotationLocked } from './annotationLocking';
3
+ import { checkAndSetAnnotationVisibility } from './annotationVisibility';
4
+ import { defaultFrameOfReferenceSpecificAnnotationManager } from './FrameOfReferenceSpecificAnnotationManager';
5
+ import { setAnnotationManager } from './annotationState';
6
+ const defaultManager = defaultFrameOfReferenceSpecificAnnotationManager;
7
+ const preprocessingFn = (annotation) => {
8
+ annotation = checkAndDefineTextBoxProperty(annotation);
9
+ annotation = checkAndDefineCachedStatsProperty(annotation);
10
+ const uid = annotation.annotationUID;
11
+ const isLocked = checkAndSetAnnotationLocked(uid);
12
+ annotation.isLocked = isLocked;
13
+ const isVisible = checkAndSetAnnotationVisibility(uid);
14
+ annotation.isVisible = isVisible;
15
+ return annotation;
16
+ };
17
+ defaultManager.setPreprocessingFn(preprocessingFn);
18
+ setAnnotationManager(defaultManager);
19
+ export function resetAnnotationManager() {
20
+ setAnnotationManager(defaultManager);
21
+ }
@@ -13,6 +13,6 @@ import { clearParentAnnotation } from './annotation/annotationState';
13
13
  import { addChildAnnotation } from './annotation/annotationState';
14
14
  import { setAnnotationManager } from './annotation/annotationState';
15
15
  import { getAnnotationManager } from './annotation/annotationState';
16
- import { resetAnnotationManager } from './annotation/annotationState';
16
+ import { resetAnnotationManager } from './annotation/resetAnnotationManager';
17
17
  import { invalidateAnnotation } from './annotation/annotationState';
18
18
  export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation };
@@ -1,5 +1,6 @@
1
1
  import FrameOfReferenceSpecificAnnotationManager, { defaultFrameOfReferenceSpecificAnnotationManager, } from './annotation/FrameOfReferenceSpecificAnnotationManager';
2
2
  import * as annotationLocking from './annotation/annotationLocking';
3
3
  import * as annotationSelection from './annotation/annotationSelection';
4
- import { getAnnotations, addAnnotation, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, } from './annotation/annotationState';
4
+ import { getAnnotations, addAnnotation, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, setAnnotationManager, getAnnotationManager, invalidateAnnotation, } from './annotation/annotationState';
5
+ import { resetAnnotationManager } from './annotation/resetAnnotationManager';
5
6
  export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, };
@@ -5,6 +5,7 @@ declare class PanTool extends BaseTool {
5
5
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
6
6
  touchDragCallback(evt: EventTypes.InteractionEventType): void;
7
7
  mouseDragCallback(evt: EventTypes.InteractionEventType): void;
8
+ preMouseDownCallback: (evt: EventTypes.InteractionEventType) => boolean;
8
9
  _dragCallback(evt: EventTypes.InteractionEventType): void;
9
10
  }
10
11
  export default PanTool;
@@ -5,6 +5,10 @@ class PanTool extends BaseTool {
5
5
  supportedInteractionTypes: ['Mouse', 'Touch'],
6
6
  }) {
7
7
  super(toolProps, defaultToolProps);
8
+ this.preMouseDownCallback = (evt) => {
9
+ this.memo = null;
10
+ return false;
11
+ };
8
12
  }
9
13
  touchDragCallback(evt) {
10
14
  this._dragCallback(evt);
@@ -15,6 +19,7 @@ class PanTool extends BaseTool {
15
19
  _dragCallback(evt) {
16
20
  const { element, deltaPoints } = evt.detail;
17
21
  const enabledElement = getEnabledElement(element);
22
+ this.memo ||= PanTool.createZoomPanMemo(enabledElement.viewport);
18
23
  const deltaPointsWorld = deltaPoints.world;
19
24
  if (deltaPointsWorld[0] === 0 &&
20
25
  deltaPointsWorld[1] === 0 &&
@@ -23,6 +23,7 @@ class ZoomTool extends BaseTool {
23
23
  const camera = enabledElement.viewport.getCamera();
24
24
  const { focalPoint } = camera;
25
25
  this.initialMousePosWorld = worldPos;
26
+ this.memo = null;
26
27
  let dirVec = vec3.fromValues(focalPoint[0] - worldPos[0], focalPoint[1] - worldPos[1], focalPoint[2] - worldPos[2]);
27
28
  dirVec = vec3.normalize(vec3.create(), dirVec);
28
29
  this.dirVec = dirVec;
@@ -145,6 +146,7 @@ class ZoomTool extends BaseTool {
145
146
  const enabledElement = getEnabledElement(element);
146
147
  const { viewport } = enabledElement;
147
148
  const camera = viewport.getCamera();
149
+ this.memo ||= ZoomTool.createZoomPanMemo(viewport);
148
150
  if (camera.parallelProjection) {
149
151
  this._dragParallelProjection(evt, viewport, camera);
150
152
  }
@@ -21,6 +21,16 @@ class LengthTool extends AnnotationTool {
21
21
  configuration: {
22
22
  preventHandleOutsideImage: false,
23
23
  getTextLines: defaultGetTextLines,
24
+ actions: {
25
+ undo: {
26
+ method: 'undo',
27
+ bindings: [{ key: 'z' }],
28
+ },
29
+ redo: {
30
+ method: 'redo',
31
+ bindings: [{ key: 'y' }],
32
+ },
33
+ },
24
34
  },
25
35
  }) {
26
36
  super(toolProps, defaultToolProps);
@@ -51,7 +51,7 @@ declare class LivewireContourTool extends ContourSegmentationBaseTool {
51
51
  renderAnnotation(enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper): boolean;
52
52
  protected isContourSegmentationTool(): boolean;
53
53
  protected createAnnotation(evt: EventTypes.InteractionEventType): import("../../types").ContourAnnotation;
54
- undo(element: any, config: any, evt: any): void;
54
+ cancelInProgress(element: any, config: any, evt: any): void;
55
55
  protected renderAnnotationInstance(renderContext: {
56
56
  enabledElement: Types.IEnabledElement;
57
57
  targetId: string;
@@ -37,8 +37,8 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
37
37
  epsilon: 0.1,
38
38
  },
39
39
  actions: {
40
- undo: {
41
- method: 'undo',
40
+ cancelInProgress: {
41
+ method: 'cancelInProgress',
42
42
  bindings: [
43
43
  {
44
44
  key: 'Escape',
@@ -576,8 +576,9 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
576
576
  });
577
577
  return annotation;
578
578
  }
579
- undo(element, config, evt) {
579
+ cancelInProgress(element, config, evt) {
580
580
  if (!this.editData) {
581
+ this.undo();
581
582
  return;
582
583
  }
583
584
  this._endCallback(evt, true);
@@ -1,3 +1,4 @@
1
+ import { utilities } from '@cornerstonejs/core';
1
2
  import type { Types } from '@cornerstonejs/core';
2
3
  import ToolModes from '../../enums/ToolModes';
3
4
  import type StrategyCallbacks from '../../enums/StrategyCallbacks';
@@ -8,6 +9,7 @@ declare abstract class BaseTool {
8
9
  configuration: Record<string, any>;
9
10
  toolGroupId: string;
10
11
  mode: ToolModes;
12
+ protected memo: utilities.HistoryMemo.Memo;
11
13
  constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
12
14
  getToolName(): string;
13
15
  applyActiveStrategy(enabledElement: Types.IEnabledElement, operationData: unknown): any;
@@ -16,5 +18,10 @@ declare abstract class BaseTool {
16
18
  setActiveStrategy(strategyName: string): void;
17
19
  protected getTargetImageData(targetId: string): Types.IImageData | Types.CPUIImageData;
18
20
  protected getTargetId(viewport: Types.IViewport): string | undefined;
21
+ undo(): void;
22
+ redo(): void;
23
+ static createZoomPanMemo(viewport: any): {
24
+ restoreMemo: () => void;
25
+ };
19
26
  }
20
27
  export default BaseTool;
@@ -1,5 +1,6 @@
1
1
  import { utilities, BaseVolumeViewport } from '@cornerstonejs/core';
2
2
  import ToolModes from '../../enums/ToolModes';
3
+ const { DefaultHistoryMemo } = utilities.HistoryMemo;
3
4
  class BaseTool {
4
5
  constructor(toolProps, defaultToolProps) {
5
6
  const initialProps = utilities.deepMerge(defaultToolProps, toolProps);
@@ -78,6 +79,32 @@ class BaseTool {
78
79
  }
79
80
  throw new Error('getTargetId: viewport must have a getViewReferenceId method');
80
81
  }
82
+ undo() {
83
+ DefaultHistoryMemo.undo();
84
+ this.memo = null;
85
+ }
86
+ redo() {
87
+ DefaultHistoryMemo.redo();
88
+ }
89
+ static createZoomPanMemo(viewport) {
90
+ const state = {
91
+ pan: viewport.getPan(),
92
+ zoom: viewport.getZoom(),
93
+ };
94
+ const zoomPanMemo = {
95
+ restoreMemo: () => {
96
+ const currentPan = viewport.getPan();
97
+ const currentZoom = viewport.getZoom();
98
+ viewport.setZoom(state.zoom);
99
+ viewport.setPan(state.pan);
100
+ viewport.render();
101
+ state.pan = currentPan;
102
+ state.zoom = currentZoom;
103
+ },
104
+ };
105
+ DefaultHistoryMemo.push(zoomPanMemo);
106
+ return zoomPanMemo;
107
+ }
81
108
  }
82
109
  BaseTool.toolName = 'BaseTool';
83
110
  export default BaseTool;
@@ -30,7 +30,7 @@ const sphereComposition = {
30
30
  };
31
31
  const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics);
32
32
  const fillInsideSphere = SPHERE_STRATEGY.strategyFunction;
33
- const SPHERE_THRESHOLD_STRATEGY = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
33
+ const SPHERE_THRESHOLD_STRATEGY = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold);
34
34
  const SPHERE_THRESHOLD_STRATEGY_ISLAND = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
35
35
  const thresholdInsideSphere = SPHERE_THRESHOLD_STRATEGY.strategyFunction;
36
36
  const thresholdInsideSphereIsland = SPHERE_THRESHOLD_STRATEGY_ISLAND.strategyFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.4.0",
107
+ "@cornerstonejs/core": "^2.5.1",
108
108
  "@kitware/vtk.js": "32.1.1",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "70fc2826230875c1c5f3533953fac9a3025833c0"
126
+ "gitHead": "e7fb3e73be741795eb832b885b98de9a03fbaffd"
127
127
  }
@@ -1,2 +0,0 @@
1
- import type { Annotation } from '../../types';
2
- export declare function getAnnotation(annotationUID: string): Annotation;
@@ -1,6 +0,0 @@
1
- import { defaultFrameOfReferenceSpecificAnnotationManager } from './FrameOfReferenceSpecificAnnotationManager';
2
- export function getAnnotation(annotationUID) {
3
- const manager = defaultFrameOfReferenceSpecificAnnotationManager;
4
- const annotation = manager.getAnnotation(annotationUID);
5
- return annotation;
6
- }