copper3d 2.2.3 → 3.0.0
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.
- package/README.md +1056 -5
- package/dist/Scene/copperScene.d.ts +3 -0
- package/dist/Scene/copperScene.js +13 -0
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Utils/segmentation/CommToolsData.d.ts +109 -6
- package/dist/Utils/segmentation/CommToolsData.js +314 -50
- package/dist/Utils/segmentation/CommToolsData.js.map +1 -1
- package/dist/Utils/segmentation/DragOperator.d.ts +13 -7
- package/dist/Utils/segmentation/DragOperator.js +51 -165
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/DrawToolCore.d.ts +57 -76
- package/dist/Utils/segmentation/DrawToolCore.js +368 -878
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +277 -15
- package/dist/Utils/segmentation/NrrdTools.js +594 -232
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/core/MaskVolume.d.ts +477 -0
- package/dist/Utils/segmentation/core/MaskVolume.js +1238 -0
- package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -0
- package/dist/Utils/segmentation/core/MigrationUtils.d.ts +97 -0
- package/dist/Utils/segmentation/core/MigrationUtils.js +163 -0
- package/dist/Utils/segmentation/core/MigrationUtils.js.map +1 -0
- package/dist/Utils/segmentation/core/UndoManager.d.ts +47 -0
- package/dist/Utils/segmentation/core/UndoManager.js +86 -0
- package/dist/Utils/segmentation/core/UndoManager.js.map +1 -0
- package/dist/Utils/segmentation/core/index.d.ts +76 -0
- package/dist/Utils/segmentation/core/index.js +75 -0
- package/dist/Utils/segmentation/core/index.js.map +1 -0
- package/dist/Utils/segmentation/core/types.d.ts +106 -0
- package/dist/Utils/segmentation/core/types.js +98 -0
- package/dist/Utils/segmentation/core/types.js.map +1 -0
- package/dist/Utils/segmentation/coreTools/coreType.d.ts +55 -36
- package/dist/Utils/segmentation/coreTools/coreType.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/gui.d.ts +6 -16
- package/dist/Utils/segmentation/coreTools/gui.js +23 -27
- package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
- package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +144 -0
- package/dist/Utils/segmentation/eventRouter/EventRouter.js +369 -0
- package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -0
- package/dist/Utils/segmentation/eventRouter/index.d.ts +7 -0
- package/dist/Utils/segmentation/eventRouter/index.js +7 -0
- package/dist/Utils/segmentation/eventRouter/index.js.map +1 -0
- package/dist/Utils/segmentation/eventRouter/types.d.ts +70 -0
- package/dist/Utils/segmentation/eventRouter/types.js +7 -0
- package/dist/Utils/segmentation/eventRouter/types.js.map +1 -0
- package/dist/Utils/segmentation/tools/BaseTool.d.ts +25 -0
- package/dist/Utils/segmentation/tools/BaseTool.js +18 -0
- package/dist/Utils/segmentation/tools/BaseTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/ContrastTool.d.ts +26 -0
- package/dist/Utils/segmentation/tools/ContrastTool.js +118 -0
- package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +30 -0
- package/dist/Utils/segmentation/tools/CrosshairTool.js +157 -0
- package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +44 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js +170 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/EraserTool.d.ts +16 -0
- package/dist/Utils/segmentation/tools/EraserTool.js +92 -0
- package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +65 -0
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js +174 -0
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -0
- package/dist/Utils/segmentation/tools/SphereTool.d.ts +38 -0
- package/dist/Utils/segmentation/tools/SphereTool.js +193 -0
- package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/ZoomTool.d.ts +20 -0
- package/dist/Utils/segmentation/tools/ZoomTool.js +59 -0
- package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/index.d.ts +22 -0
- package/dist/Utils/segmentation/tools/index.js +23 -0
- package/dist/Utils/segmentation/tools/index.js.map +1 -0
- package/dist/bundle.esm.js +4740 -1979
- package/dist/bundle.umd.js +4743 -1978
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/types/Renderer/copperRenderer.d.ts +1 -1
- package/dist/types/Renderer/copperRendererOnDemond.d.ts +1 -1
- package/dist/types/Scene/copperScene.d.ts +3 -0
- package/dist/types/Utils/segmentation/CommToolsData.d.ts +109 -6
- package/dist/types/Utils/segmentation/DragOperator.d.ts +13 -7
- package/dist/types/Utils/segmentation/DrawToolCore.d.ts +57 -76
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +277 -15
- package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +477 -0
- package/dist/types/Utils/segmentation/core/MigrationUtils.d.ts +97 -0
- package/dist/types/Utils/segmentation/core/UndoManager.d.ts +47 -0
- package/dist/types/Utils/segmentation/core/index.d.ts +76 -0
- package/dist/types/Utils/segmentation/core/types.d.ts +106 -0
- package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +55 -36
- package/dist/types/Utils/segmentation/coreTools/gui.d.ts +6 -16
- package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +144 -0
- package/dist/types/Utils/segmentation/eventRouter/index.d.ts +7 -0
- package/dist/types/Utils/segmentation/eventRouter/types.d.ts +70 -0
- package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +25 -0
- package/dist/types/Utils/segmentation/tools/ContrastTool.d.ts +26 -0
- package/dist/types/Utils/segmentation/tools/CrosshairTool.d.ts +30 -0
- package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +44 -0
- package/dist/types/Utils/segmentation/tools/EraserTool.d.ts +16 -0
- package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +65 -0
- package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +38 -0
- package/dist/types/Utils/segmentation/tools/ZoomTool.d.ts +20 -0
- package/dist/types/Utils/segmentation/tools/index.d.ts +22 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/types/types.d.ts +3 -3
- package/dist/types/types.d.ts +3 -3
- package/package.json +1 -1
- package/dist/Utils/segmentation/coreTools/archive.d.ts +0 -1
- package/dist/Utils/segmentation/coreTools/archive.js +0 -23
- package/dist/Utils/segmentation/coreTools/archive.js.map +0 -1
- package/dist/types/Utils/segmentation/coreTools/archive.d.ts +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventRouter - Centralized Event Management
|
|
3
|
+
*
|
|
4
|
+
* Consolidates keyboard, pointer, and wheel event handling from
|
|
5
|
+
* DrawToolCore.ts and DragOperator.ts into a single unified system.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Single point of event registration/cleanup
|
|
9
|
+
* - Mode-based event routing (draw, drag, contrast, crosshair, etc.)
|
|
10
|
+
* - Prevents memory leaks through proper handler cleanup
|
|
11
|
+
* - Eliminates duplicate keyboard listeners between DrawToolCore and DragOperator
|
|
12
|
+
*/
|
|
13
|
+
import type { InteractionMode, GuiTool, KeyboardHandler, PointerHandler, WheelHandler, ModeChangeCallback, EventRouterConfig, KeyboardSettings, InteractionState } from './types';
|
|
14
|
+
export declare class EventRouter {
|
|
15
|
+
private container;
|
|
16
|
+
private canvas;
|
|
17
|
+
private mode;
|
|
18
|
+
private guiTool;
|
|
19
|
+
private state;
|
|
20
|
+
private keyboardSettings;
|
|
21
|
+
/** When false, contrast key (Ctrl/Meta) is ignored for mode switching. */
|
|
22
|
+
private contrastEnabled;
|
|
23
|
+
private onModeChange?;
|
|
24
|
+
private modeChangeSubscribers;
|
|
25
|
+
private keydownHandler?;
|
|
26
|
+
private keyupHandler?;
|
|
27
|
+
private pointerDownHandler?;
|
|
28
|
+
private pointerMoveHandler?;
|
|
29
|
+
private pointerUpHandler?;
|
|
30
|
+
private pointerLeaveHandler?;
|
|
31
|
+
private wheelHandler?;
|
|
32
|
+
private boundKeyDown;
|
|
33
|
+
private boundKeyUp;
|
|
34
|
+
private boundPointerDown;
|
|
35
|
+
private boundPointerMove;
|
|
36
|
+
private boundPointerUp;
|
|
37
|
+
private boundPointerLeave;
|
|
38
|
+
private boundWheel;
|
|
39
|
+
private boundContextMenu;
|
|
40
|
+
private isBound;
|
|
41
|
+
constructor(config: EventRouterConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Bind all event listeners to DOM elements.
|
|
44
|
+
* Call this after setting handlers.
|
|
45
|
+
*/
|
|
46
|
+
bindAll(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Remove all event listeners from DOM elements.
|
|
49
|
+
* Call this on cleanup to prevent memory leaks.
|
|
50
|
+
*/
|
|
51
|
+
unbindAll(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get the current interaction mode.
|
|
54
|
+
*/
|
|
55
|
+
getMode(): InteractionMode;
|
|
56
|
+
/**
|
|
57
|
+
* Set the interaction mode directly.
|
|
58
|
+
*/
|
|
59
|
+
setMode(mode: InteractionMode): void;
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to mode change events.
|
|
62
|
+
* Returns an unsubscribe function.
|
|
63
|
+
*/
|
|
64
|
+
subscribeModeChange(callback: ModeChangeCallback): () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current GUI tool selection.
|
|
67
|
+
*/
|
|
68
|
+
getGuiTool(): GuiTool;
|
|
69
|
+
/**
|
|
70
|
+
* Set the GUI tool (from UI buttons).
|
|
71
|
+
*/
|
|
72
|
+
setGuiTool(tool: GuiTool): void;
|
|
73
|
+
/**
|
|
74
|
+
* Toggle crosshair mode.
|
|
75
|
+
*/
|
|
76
|
+
toggleCrosshair(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Check if crosshair mode is enabled.
|
|
79
|
+
*/
|
|
80
|
+
isCrosshairEnabled(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get current interaction state.
|
|
83
|
+
*/
|
|
84
|
+
getState(): Readonly<InteractionState>;
|
|
85
|
+
isShiftHeld(): boolean;
|
|
86
|
+
isCtrlHeld(): boolean;
|
|
87
|
+
isLeftButtonDown(): boolean;
|
|
88
|
+
isRightButtonDown(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Update keyboard settings.
|
|
91
|
+
*/
|
|
92
|
+
setKeyboardSettings(settings: Partial<KeyboardSettings>): void;
|
|
93
|
+
getKeyboardSettings(): KeyboardSettings;
|
|
94
|
+
/**
|
|
95
|
+
* Enable or disable the contrast shortcut (Ctrl/Meta key).
|
|
96
|
+
*
|
|
97
|
+
* When disabled:
|
|
98
|
+
* - `ctrlHeld` state is never set to true
|
|
99
|
+
* - The mode will not be changed to `'contrast'` via key events
|
|
100
|
+
* - If the mode is currently `'contrast'` it is reset to `'idle'`
|
|
101
|
+
*
|
|
102
|
+
* The external keydown/keyup handlers are still called regardless
|
|
103
|
+
* of this flag so other Ctrl-based shortcuts (e.g. Ctrl+Z undo)
|
|
104
|
+
* continue to work normally.
|
|
105
|
+
*/
|
|
106
|
+
setContrastEnabled(enabled: boolean): void;
|
|
107
|
+
/** Whether the contrast shortcut is currently enabled. */
|
|
108
|
+
isContrastEnabled(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Register the keydown handler (from DrawToolCore/DragOperator).
|
|
111
|
+
*/
|
|
112
|
+
setKeydownHandler(handler: KeyboardHandler): void;
|
|
113
|
+
/**
|
|
114
|
+
* Register the keyup handler.
|
|
115
|
+
*/
|
|
116
|
+
setKeyupHandler(handler: KeyboardHandler): void;
|
|
117
|
+
/**
|
|
118
|
+
* Register pointer down handler.
|
|
119
|
+
*/
|
|
120
|
+
setPointerDownHandler(handler: PointerHandler): void;
|
|
121
|
+
/**
|
|
122
|
+
* Register pointer move handler.
|
|
123
|
+
*/
|
|
124
|
+
setPointerMoveHandler(handler: PointerHandler): void;
|
|
125
|
+
/**
|
|
126
|
+
* Register pointer up handler.
|
|
127
|
+
*/
|
|
128
|
+
setPointerUpHandler(handler: PointerHandler): void;
|
|
129
|
+
/**
|
|
130
|
+
* Register pointer leave handler.
|
|
131
|
+
*/
|
|
132
|
+
setPointerLeaveHandler(handler: PointerHandler): void;
|
|
133
|
+
/**
|
|
134
|
+
* Register wheel handler.
|
|
135
|
+
*/
|
|
136
|
+
setWheelHandler(handler: WheelHandler): void;
|
|
137
|
+
private handleKeyDown;
|
|
138
|
+
private handleKeyUp;
|
|
139
|
+
private handlePointerDown;
|
|
140
|
+
private handlePointerMove;
|
|
141
|
+
private handlePointerUp;
|
|
142
|
+
private handlePointerLeave;
|
|
143
|
+
private handleWheel;
|
|
144
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventRouter - Centralized Event Management
|
|
3
|
+
*
|
|
4
|
+
* Consolidates keyboard, pointer, and wheel event handling from
|
|
5
|
+
* DrawToolCore.ts and DragOperator.ts into a single unified system.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Single point of event registration/cleanup
|
|
9
|
+
* - Mode-based event routing (draw, drag, contrast, crosshair, etc.)
|
|
10
|
+
* - Prevents memory leaks through proper handler cleanup
|
|
11
|
+
* - Eliminates duplicate keyboard listeners between DrawToolCore and DragOperator
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Default keyboard settings matching nrrd_states.keyboardSettings
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_KEYBOARD_SETTINGS = {
|
|
17
|
+
draw: 'Shift',
|
|
18
|
+
undo: 'z',
|
|
19
|
+
redo: 'y',
|
|
20
|
+
contrast: ['Control', 'Meta'],
|
|
21
|
+
crosshair: 'c',
|
|
22
|
+
mouseWheel: 'Scroll:Zoom'
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Drawing tools that can be used with Shift+drag
|
|
26
|
+
*/
|
|
27
|
+
const DRAWING_TOOLS = new Set(['pencil', 'brush', 'eraser']);
|
|
28
|
+
export class EventRouter {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
// === State ===
|
|
31
|
+
this.mode = 'idle';
|
|
32
|
+
this.guiTool = 'pencil';
|
|
33
|
+
this.state = {
|
|
34
|
+
shiftHeld: false,
|
|
35
|
+
ctrlHeld: false,
|
|
36
|
+
leftButtonDown: false,
|
|
37
|
+
rightButtonDown: false,
|
|
38
|
+
crosshairEnabled: false,
|
|
39
|
+
};
|
|
40
|
+
// === Configuration ===
|
|
41
|
+
this.keyboardSettings = DEFAULT_KEYBOARD_SETTINGS;
|
|
42
|
+
/** When false, contrast key (Ctrl/Meta) is ignored for mode switching. */
|
|
43
|
+
this.contrastEnabled = true;
|
|
44
|
+
this.modeChangeSubscribers = [];
|
|
45
|
+
// === Binding state ===
|
|
46
|
+
this.isBound = false;
|
|
47
|
+
this.container = config.container;
|
|
48
|
+
this.canvas = config.canvas;
|
|
49
|
+
this.onModeChange = config.onModeChange;
|
|
50
|
+
// Bind internal handlers
|
|
51
|
+
this.boundKeyDown = this.handleKeyDown.bind(this);
|
|
52
|
+
this.boundKeyUp = this.handleKeyUp.bind(this);
|
|
53
|
+
this.boundPointerDown = this.handlePointerDown.bind(this);
|
|
54
|
+
this.boundPointerMove = this.handlePointerMove.bind(this);
|
|
55
|
+
this.boundPointerUp = this.handlePointerUp.bind(this);
|
|
56
|
+
this.boundPointerLeave = this.handlePointerLeave.bind(this);
|
|
57
|
+
this.boundWheel = this.handleWheel.bind(this);
|
|
58
|
+
this.boundContextMenu = (e) => e.preventDefault();
|
|
59
|
+
}
|
|
60
|
+
// ========================================
|
|
61
|
+
// Lifecycle Methods
|
|
62
|
+
// ========================================
|
|
63
|
+
/**
|
|
64
|
+
* Bind all event listeners to DOM elements.
|
|
65
|
+
* Call this after setting handlers.
|
|
66
|
+
*/
|
|
67
|
+
bindAll() {
|
|
68
|
+
if (this.isBound) {
|
|
69
|
+
console.warn('EventRouter: Already bound, call unbindAll() first');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Keyboard events on container
|
|
73
|
+
this.container.addEventListener('keydown', this.boundKeyDown);
|
|
74
|
+
this.container.addEventListener('keyup', this.boundKeyUp);
|
|
75
|
+
// Pointer events on canvas
|
|
76
|
+
this.canvas.addEventListener('pointerdown', this.boundPointerDown, true);
|
|
77
|
+
this.canvas.addEventListener('pointermove', this.boundPointerMove);
|
|
78
|
+
this.canvas.addEventListener('pointerup', this.boundPointerUp);
|
|
79
|
+
this.canvas.addEventListener('pointerleave', this.boundPointerLeave);
|
|
80
|
+
// Wheel event on canvas
|
|
81
|
+
this.canvas.addEventListener('wheel', this.boundWheel, { passive: false });
|
|
82
|
+
// Disable right-click context menu
|
|
83
|
+
this.canvas.addEventListener('contextmenu', this.boundContextMenu);
|
|
84
|
+
this.isBound = true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove all event listeners from DOM elements.
|
|
88
|
+
* Call this on cleanup to prevent memory leaks.
|
|
89
|
+
*/
|
|
90
|
+
unbindAll() {
|
|
91
|
+
if (!this.isBound) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Keyboard events
|
|
95
|
+
this.container.removeEventListener('keydown', this.boundKeyDown);
|
|
96
|
+
this.container.removeEventListener('keyup', this.boundKeyUp);
|
|
97
|
+
// Pointer events
|
|
98
|
+
this.canvas.removeEventListener('pointerdown', this.boundPointerDown, true);
|
|
99
|
+
this.canvas.removeEventListener('pointermove', this.boundPointerMove);
|
|
100
|
+
this.canvas.removeEventListener('pointerup', this.boundPointerUp);
|
|
101
|
+
this.canvas.removeEventListener('pointerleave', this.boundPointerLeave);
|
|
102
|
+
// Wheel event
|
|
103
|
+
this.canvas.removeEventListener('wheel', this.boundWheel);
|
|
104
|
+
// Context menu
|
|
105
|
+
this.canvas.removeEventListener('contextmenu', this.boundContextMenu);
|
|
106
|
+
this.isBound = false;
|
|
107
|
+
}
|
|
108
|
+
// ========================================
|
|
109
|
+
// Mode Management
|
|
110
|
+
// ========================================
|
|
111
|
+
/**
|
|
112
|
+
* Get the current interaction mode.
|
|
113
|
+
*/
|
|
114
|
+
getMode() {
|
|
115
|
+
return this.mode;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set the interaction mode directly.
|
|
119
|
+
*/
|
|
120
|
+
setMode(mode) {
|
|
121
|
+
if (this.mode === mode)
|
|
122
|
+
return;
|
|
123
|
+
const prevMode = this.mode;
|
|
124
|
+
this.mode = mode;
|
|
125
|
+
// Notify primary callback
|
|
126
|
+
if (this.onModeChange) {
|
|
127
|
+
this.onModeChange(prevMode, mode);
|
|
128
|
+
}
|
|
129
|
+
// Notify all subscribers
|
|
130
|
+
for (const subscriber of this.modeChangeSubscribers) {
|
|
131
|
+
subscriber(prevMode, mode);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Subscribe to mode change events.
|
|
136
|
+
* Returns an unsubscribe function.
|
|
137
|
+
*/
|
|
138
|
+
subscribeModeChange(callback) {
|
|
139
|
+
this.modeChangeSubscribers.push(callback);
|
|
140
|
+
return () => {
|
|
141
|
+
const index = this.modeChangeSubscribers.indexOf(callback);
|
|
142
|
+
if (index >= 0) {
|
|
143
|
+
this.modeChangeSubscribers.splice(index, 1);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get the current GUI tool selection.
|
|
149
|
+
*/
|
|
150
|
+
getGuiTool() {
|
|
151
|
+
return this.guiTool;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set the GUI tool (from UI buttons).
|
|
155
|
+
*/
|
|
156
|
+
setGuiTool(tool) {
|
|
157
|
+
this.guiTool = tool;
|
|
158
|
+
// Reset to idle when switching tools
|
|
159
|
+
if (tool === 'sphere' || tool === 'calculator') {
|
|
160
|
+
this.state.crosshairEnabled = false;
|
|
161
|
+
this.setMode('idle');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Toggle crosshair mode.
|
|
166
|
+
*/
|
|
167
|
+
toggleCrosshair() {
|
|
168
|
+
if (!DRAWING_TOOLS.has(this.guiTool))
|
|
169
|
+
return;
|
|
170
|
+
if (this.state.shiftHeld || this.state.ctrlHeld)
|
|
171
|
+
return;
|
|
172
|
+
this.state.crosshairEnabled = !this.state.crosshairEnabled;
|
|
173
|
+
this.setMode(this.state.crosshairEnabled ? 'crosshair' : 'idle');
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Check if crosshair mode is enabled.
|
|
177
|
+
*/
|
|
178
|
+
isCrosshairEnabled() {
|
|
179
|
+
return this.state.crosshairEnabled;
|
|
180
|
+
}
|
|
181
|
+
// ========================================
|
|
182
|
+
// State Queries
|
|
183
|
+
// ========================================
|
|
184
|
+
/**
|
|
185
|
+
* Get current interaction state.
|
|
186
|
+
*/
|
|
187
|
+
getState() {
|
|
188
|
+
return Object.assign({}, this.state);
|
|
189
|
+
}
|
|
190
|
+
isShiftHeld() {
|
|
191
|
+
return this.state.shiftHeld;
|
|
192
|
+
}
|
|
193
|
+
isCtrlHeld() {
|
|
194
|
+
return this.state.ctrlHeld;
|
|
195
|
+
}
|
|
196
|
+
isLeftButtonDown() {
|
|
197
|
+
return this.state.leftButtonDown;
|
|
198
|
+
}
|
|
199
|
+
isRightButtonDown() {
|
|
200
|
+
return this.state.rightButtonDown;
|
|
201
|
+
}
|
|
202
|
+
// ========================================
|
|
203
|
+
// Configuration
|
|
204
|
+
// ========================================
|
|
205
|
+
/**
|
|
206
|
+
* Update keyboard settings.
|
|
207
|
+
*/
|
|
208
|
+
setKeyboardSettings(settings) {
|
|
209
|
+
this.keyboardSettings = Object.assign(Object.assign({}, this.keyboardSettings), settings);
|
|
210
|
+
}
|
|
211
|
+
getKeyboardSettings() {
|
|
212
|
+
return Object.assign({}, this.keyboardSettings);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Enable or disable the contrast shortcut (Ctrl/Meta key).
|
|
216
|
+
*
|
|
217
|
+
* When disabled:
|
|
218
|
+
* - `ctrlHeld` state is never set to true
|
|
219
|
+
* - The mode will not be changed to `'contrast'` via key events
|
|
220
|
+
* - If the mode is currently `'contrast'` it is reset to `'idle'`
|
|
221
|
+
*
|
|
222
|
+
* The external keydown/keyup handlers are still called regardless
|
|
223
|
+
* of this flag so other Ctrl-based shortcuts (e.g. Ctrl+Z undo)
|
|
224
|
+
* continue to work normally.
|
|
225
|
+
*/
|
|
226
|
+
setContrastEnabled(enabled) {
|
|
227
|
+
this.contrastEnabled = enabled;
|
|
228
|
+
if (!enabled && this.mode === 'contrast') {
|
|
229
|
+
this.state.ctrlHeld = false;
|
|
230
|
+
this.setMode('idle');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** Whether the contrast shortcut is currently enabled. */
|
|
234
|
+
isContrastEnabled() {
|
|
235
|
+
return this.contrastEnabled;
|
|
236
|
+
}
|
|
237
|
+
// ========================================
|
|
238
|
+
// Handler Registration
|
|
239
|
+
// ========================================
|
|
240
|
+
/**
|
|
241
|
+
* Register the keydown handler (from DrawToolCore/DragOperator).
|
|
242
|
+
*/
|
|
243
|
+
setKeydownHandler(handler) {
|
|
244
|
+
this.keydownHandler = handler;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Register the keyup handler.
|
|
248
|
+
*/
|
|
249
|
+
setKeyupHandler(handler) {
|
|
250
|
+
this.keyupHandler = handler;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Register pointer down handler.
|
|
254
|
+
*/
|
|
255
|
+
setPointerDownHandler(handler) {
|
|
256
|
+
this.pointerDownHandler = handler;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Register pointer move handler.
|
|
260
|
+
*/
|
|
261
|
+
setPointerMoveHandler(handler) {
|
|
262
|
+
this.pointerMoveHandler = handler;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Register pointer up handler.
|
|
266
|
+
*/
|
|
267
|
+
setPointerUpHandler(handler) {
|
|
268
|
+
this.pointerUpHandler = handler;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Register pointer leave handler.
|
|
272
|
+
*/
|
|
273
|
+
setPointerLeaveHandler(handler) {
|
|
274
|
+
this.pointerLeaveHandler = handler;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Register wheel handler.
|
|
278
|
+
*/
|
|
279
|
+
setWheelHandler(handler) {
|
|
280
|
+
this.wheelHandler = handler;
|
|
281
|
+
}
|
|
282
|
+
// ========================================
|
|
283
|
+
// Internal Event Handlers
|
|
284
|
+
// ========================================
|
|
285
|
+
handleKeyDown(ev) {
|
|
286
|
+
// Update state based on modifier keys
|
|
287
|
+
if (ev.key === this.keyboardSettings.draw) {
|
|
288
|
+
this.state.shiftHeld = true;
|
|
289
|
+
if (DRAWING_TOOLS.has(this.guiTool) && !this.state.ctrlHeld) {
|
|
290
|
+
this.setMode('draw');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (this.contrastEnabled && this.keyboardSettings.contrast.includes(ev.key)) {
|
|
294
|
+
this.state.ctrlHeld = true;
|
|
295
|
+
}
|
|
296
|
+
// Route to external handler
|
|
297
|
+
if (this.keydownHandler) {
|
|
298
|
+
this.keydownHandler(ev);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
handleKeyUp(ev) {
|
|
302
|
+
// Update state based on modifier keys
|
|
303
|
+
if (ev.key === this.keyboardSettings.draw) {
|
|
304
|
+
this.state.shiftHeld = false;
|
|
305
|
+
if (this.mode === 'draw') {
|
|
306
|
+
this.setMode('idle');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (this.keyboardSettings.contrast.includes(ev.key)) {
|
|
310
|
+
this.state.ctrlHeld = false;
|
|
311
|
+
// Do NOT auto-exit contrast mode here. Contrast is a toggle
|
|
312
|
+
// (press Ctrl once → enter, press again → exit), not a hold.
|
|
313
|
+
// DrawToolCore's keyupHandler manages the toggle exclusively.
|
|
314
|
+
// Auto-exiting here would conflict with it (EventRouter exits,
|
|
315
|
+
// then DrawToolCore immediately re-enters → stuck in contrast).
|
|
316
|
+
}
|
|
317
|
+
// Route to external handler
|
|
318
|
+
if (this.keyupHandler) {
|
|
319
|
+
this.keyupHandler(ev);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
handlePointerDown(ev) {
|
|
323
|
+
if (ev.button === 0) {
|
|
324
|
+
this.state.leftButtonDown = true;
|
|
325
|
+
}
|
|
326
|
+
else if (ev.button === 2) {
|
|
327
|
+
this.state.rightButtonDown = true;
|
|
328
|
+
this.setMode('pan');
|
|
329
|
+
}
|
|
330
|
+
// Route to external handler
|
|
331
|
+
if (this.pointerDownHandler) {
|
|
332
|
+
this.pointerDownHandler(ev);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
handlePointerMove(ev) {
|
|
336
|
+
// Route to external handler
|
|
337
|
+
if (this.pointerMoveHandler) {
|
|
338
|
+
this.pointerMoveHandler(ev);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
handlePointerUp(ev) {
|
|
342
|
+
if (ev.button === 0) {
|
|
343
|
+
this.state.leftButtonDown = false;
|
|
344
|
+
}
|
|
345
|
+
else if (ev.button === 2) {
|
|
346
|
+
this.state.rightButtonDown = false;
|
|
347
|
+
if (this.mode === 'pan') {
|
|
348
|
+
this.setMode('idle');
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Route to external handler
|
|
352
|
+
if (this.pointerUpHandler) {
|
|
353
|
+
this.pointerUpHandler(ev);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
handlePointerLeave(ev) {
|
|
357
|
+
// Route to external handler
|
|
358
|
+
if (this.pointerLeaveHandler) {
|
|
359
|
+
this.pointerLeaveHandler(ev);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
handleWheel(ev) {
|
|
363
|
+
// Route to external handler
|
|
364
|
+
if (this.wheelHandler) {
|
|
365
|
+
this.wheelHandler(ev);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=EventRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventRouter.js","sourceRoot":"","sources":["../../../../src/Utils/segmentation/eventRouter/EventRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAcH;;GAEG;AACH,MAAM,yBAAyB,GAAqB;IAChD,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,GAAG;IACd,UAAU,EAAE,aAAa;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,aAAa,GAAiB,IAAI,GAAG,CAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEpF,MAAM,OAAO,WAAW;IAgDpB,YAAY,MAAyB;QA3CrC,gBAAgB;QACR,SAAI,GAAoB,MAAM,CAAC;QAC/B,YAAO,GAAY,QAAQ,CAAC;QAC5B,UAAK,GAAqB;YAC9B,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,KAAK;YACf,cAAc,EAAE,KAAK;YACrB,eAAe,EAAE,KAAK;YACtB,gBAAgB,EAAE,KAAK;SAC1B,CAAC;QAEF,wBAAwB;QAChB,qBAAgB,GAAqB,yBAAyB,CAAC;QAEvE,0EAA0E;QAClE,oBAAe,GAAY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ACJ;QAED,4BAA4B;QAC5B,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;SAC7B;IACL,CAAC;IAEO,kBAAkB,CAAC,EAAgB;QACvC,4BAA4B;QAC5B,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC1B,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;SAChC;IACL,CAAC;IAEO,WAAW,CAAC,EAAc;QAC9B,4BAA4B;QAC5B,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;SACzB;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Router Module
|
|
3
|
+
*
|
|
4
|
+
* Exports centralized event handling components for the segmentation module.
|
|
5
|
+
*/
|
|
6
|
+
export { EventRouter } from './EventRouter';
|
|
7
|
+
export type { InteractionMode, GuiTool, KeyboardHandler, PointerHandler, WheelHandler, ModeChangeCallback, EventRouterConfig, KeyboardSettings, InteractionState } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Utils/segmentation/eventRouter/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Router Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for centralized event handling in the segmentation module.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Interaction modes representing the current operational state.
|
|
8
|
+
*
|
|
9
|
+
* - `idle`: Default state, allows navigation (drag slice, wheel zoom)
|
|
10
|
+
* - `draw`: Shift held, left-drag paints (pencil/brush/eraser)
|
|
11
|
+
* - `drag`: Left-drag changes slices
|
|
12
|
+
* - `contrast`: Ctrl held, left-drag adjusts window/level
|
|
13
|
+
* - `crosshair`: Crosshair mode enabled (C key toggle)
|
|
14
|
+
* - `sphere`: Sphere placement tool active
|
|
15
|
+
* - `calculator`: Distance calculator tool active
|
|
16
|
+
* - `pan`: Right-drag panning the canvas
|
|
17
|
+
*/
|
|
18
|
+
export type InteractionMode = 'idle' | 'draw' | 'drag' | 'contrast' | 'crosshair' | 'sphere' | 'calculator' | 'pan';
|
|
19
|
+
/**
|
|
20
|
+
* GUI tool selection (set from UI buttons)
|
|
21
|
+
*/
|
|
22
|
+
export type GuiTool = 'pencil' | 'brush' | 'eraser' | 'sphere' | 'calculator';
|
|
23
|
+
/**
|
|
24
|
+
* Keyboard event handler type
|
|
25
|
+
*/
|
|
26
|
+
export type KeyboardHandler = (ev: KeyboardEvent) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Pointer event handler type
|
|
29
|
+
*/
|
|
30
|
+
export type PointerHandler = (ev: PointerEvent) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Wheel event handler type
|
|
33
|
+
*/
|
|
34
|
+
export type WheelHandler = (ev: WheelEvent) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Mode change callback - called when interaction mode changes
|
|
37
|
+
*/
|
|
38
|
+
export type ModeChangeCallback = (prevMode: InteractionMode, newMode: InteractionMode) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for EventRouter initialization
|
|
41
|
+
*/
|
|
42
|
+
export interface EventRouterConfig {
|
|
43
|
+
/** Container element to attach keyboard events */
|
|
44
|
+
container: HTMLElement;
|
|
45
|
+
/** Canvas element to attach pointer/wheel events */
|
|
46
|
+
canvas: HTMLCanvasElement;
|
|
47
|
+
/** Optional callback when mode changes */
|
|
48
|
+
onModeChange?: ModeChangeCallback;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Keyboard settings from nrrd_states
|
|
52
|
+
*/
|
|
53
|
+
export interface KeyboardSettings {
|
|
54
|
+
draw: string;
|
|
55
|
+
undo: string;
|
|
56
|
+
redo: string;
|
|
57
|
+
contrast: string[];
|
|
58
|
+
crosshair: string;
|
|
59
|
+
mouseWheel: 'Scroll:Zoom' | 'Scroll:Slice';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* State flags tracked by EventRouter
|
|
63
|
+
*/
|
|
64
|
+
export interface InteractionState {
|
|
65
|
+
shiftHeld: boolean;
|
|
66
|
+
ctrlHeld: boolean;
|
|
67
|
+
leftButtonDown: boolean;
|
|
68
|
+
rightButtonDown: boolean;
|
|
69
|
+
crosshairEnabled: boolean;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/Utils/segmentation/eventRouter/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseTool - Abstract base for extracted DrawToolCore tools
|
|
3
|
+
*
|
|
4
|
+
* Provides shared access to the legacy state objects (nrrd_states,
|
|
5
|
+
* gui_states, protectedData) via a ToolContext interface.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is for the OLD DrawToolCore system.
|
|
8
|
+
* The new SegmentationManager system has its own tools in manager/tools/.
|
|
9
|
+
*/
|
|
10
|
+
import type { INrrdStates, IGUIStates, IProtected, ICursorPage } from "../coreTools/coreType";
|
|
11
|
+
/**
|
|
12
|
+
* Shared context injected into every legacy tool.
|
|
13
|
+
* References are shared (not copied), so tools see the same state.
|
|
14
|
+
*/
|
|
15
|
+
export interface ToolContext {
|
|
16
|
+
nrrd_states: INrrdStates;
|
|
17
|
+
gui_states: IGUIStates;
|
|
18
|
+
protectedData: IProtected;
|
|
19
|
+
cursorPage: ICursorPage;
|
|
20
|
+
}
|
|
21
|
+
export declare abstract class BaseTool {
|
|
22
|
+
protected ctx: ToolContext;
|
|
23
|
+
constructor(ctx: ToolContext);
|
|
24
|
+
setContext(ctx: ToolContext): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseTool - Abstract base for extracted DrawToolCore tools
|
|
3
|
+
*
|
|
4
|
+
* Provides shared access to the legacy state objects (nrrd_states,
|
|
5
|
+
* gui_states, protectedData) via a ToolContext interface.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is for the OLD DrawToolCore system.
|
|
8
|
+
* The new SegmentationManager system has its own tools in manager/tools/.
|
|
9
|
+
*/
|
|
10
|
+
export class BaseTool {
|
|
11
|
+
constructor(ctx) {
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
}
|
|
14
|
+
setContext(ctx) {
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=BaseTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseTool.js","sourceRoot":"","sources":["../../../../src/Utils/segmentation/tools/BaseTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,MAAM,OAAgB,QAAQ;IAG5B,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,UAAU,CAAC,GAAgB;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF"}
|