|
| 1 | +<div style="text-align: center;"> |
| 2 | + <img src="https://assets.pokemon.com/assets/cms2/img/pokedex/full/246.png" alt="Larvitar" height="200" /> |
| 3 | +</div> |
| 4 | + |
| 5 | +## Introduction: default Tools |
| 6 | + |
| 7 | +In `default.ts` the list of Larvitar default tools is exported as `DEFAULT_TOOLS`, along with their default configuration, that extendes the cornerstoneTools configuration with these properties: |
| 8 | + |
| 9 | +- **Name:** String representing the tool's name. |
| 10 | +- **Viewports:** Specifies the viewports targeted by the tool (`"all"` or an array of specific viewports). |
| 11 | +- **Configuration:** Configuration options defined as an object. |
| 12 | +- **Options:** Additional options defined as an object. |
| 13 | +- **Class:** The corresponding Cornerstone tool library class (e.g., `"LengthTool"` for the length measurement tool). |
| 14 | +- **Sync:** Synchronization behavior for the tool. |
| 15 | +- **Cleanable:** if true, this tool will be removed when calling `"no tools"`, |
| 16 | +- **DefaultActive:** if true, this tool will be activated when calling `addDefaultTools`, |
| 17 | +- **Shortcut:** keyboard shortcut [not implemented], |
| 18 | +- **Type:** tool category inside Larvitar (one of: `"utils", "annotation", "segmentation", "overlay"`), |
| 19 | +- **Description:** a string that describes the tool (eg to be shown in a tooltip) |
| 20 | + |
| 21 | +These tools are either cornerstone-customized tools or fully custom tools (e.g., `watershedSegmentationTool`) and can be added to the viewport through `addDefaultTools`. |
| 22 | + |
| 23 | +### Example: Tool Definition |
| 24 | + |
| 25 | +```typescript |
| 26 | +Zoom: { |
| 27 | + name: "Zoom", |
| 28 | + viewports: "all", |
| 29 | + configuration: { |
| 30 | + invert: false, |
| 31 | + preventZoomOutsideImage: false, |
| 32 | + minScale: 0.01, |
| 33 | + maxScale: 25.0 |
| 34 | + }, |
| 35 | + options: { |
| 36 | + mouseButtonMask: 2, |
| 37 | + supportedInteractionTypes: ["Mouse", "Touch"], |
| 38 | + defaultStrategy: "default" // can be 'default', 'translate' or 'zoomToCenter' |
| 39 | + }, |
| 40 | + cleanable: false, |
| 41 | + class: "ZoomTool", |
| 42 | + defaultActive: true, |
| 43 | + description: "Zoom image at mouse position", |
| 44 | + shortcut: "ctrl-z", |
| 45 | + type: "utils" |
| 46 | + } |
| 47 | +``` |
| 48 | + |
| 49 | +### Example: Default Tools Activation |
| 50 | + |
| 51 | +```typescript |
| 52 | +store.addViewport("viewer"); |
| 53 | +initializeCSTools(); |
| 54 | +addDefaultTools(); |
| 55 | +setToolActive("Wwwc"); //explicitly set the active tool. If not, default active is StackScroll |
| 56 | +``` |
| 57 | + |
| 58 | +## Introduction: custom Tools |
| 59 | + |
| 60 | +User can add custom tools calling `registerExternalTool`. The tool will be registered in the dvTools object and in `DEFAULT_TOOLS` array. If done **before** adding the tools with `addDefaultTools`, the tool will be added automatically along with the default ones. Otherwise, the user can simply add its tool using `addTool`. |
| 61 | + |
| 62 | +### Example: Custom Tools Registration |
| 63 | + |
| 64 | +```typescript |
| 65 | +initializeCSTools(); |
| 66 | +store.addViewport("viewer"); |
| 67 | +registerExternalTool("customTool"); |
| 68 | +addTool("customTool"); //or directly use addDefaultTools(); |
| 69 | +setToolActive("customTool"); |
| 70 | +``` |
| 71 | + |
| 72 | +## API Reference |
| 73 | + |
| 74 | +### `getDefaultToolsByType` |
| 75 | + |
| 76 | +Gets available tools by type, which is useful for populating menus. |
| 77 | + |
| 78 | +#### Syntax |
| 79 | + |
| 80 | +```typescript |
| 81 | +getDefaultToolsByType(type: NonNullable<ToolConfig["type"]>): ToolConfig[] |
| 82 | +``` |
| 83 | + |
| 84 | +#### Parameters |
| 85 | + |
| 86 | +| Parameter | Type | Description | |
| 87 | +| --------- | ------------------------------- | ------------------------------------------------------------- | |
| 88 | +| `type` | NonNullable<ToolConfig["type"]> | The type of tool to filter and return from the list of tools. | |
| 89 | + |
| 90 | +#### Returns |
| 91 | + |
| 92 | +`ToolConfig[]` – An array of tool configurations that match the specified type. |
| 93 | + |
| 94 | +### `setDefaultToolsProps` |
| 95 | + |
| 96 | +Overrides the default properties of tools. |
| 97 | + |
| 98 | +#### Syntax |
| 99 | + |
| 100 | +```typescript |
| 101 | +setDefaultToolsProps(newProps: Partial<ToolConfig>[]): void |
| 102 | +``` |
| 103 | + |
| 104 | +#### Parameters |
| 105 | + |
| 106 | +| Parameter | Type | Description | |
| 107 | +| ---------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | |
| 108 | +| `newProps` | Partial<ToolConfig [] > | An array of objects representing the properties to be overridden for the default tools. The "name" property is mandatory for each object. | |
| 109 | + |
| 110 | +#### Returns |
| 111 | + |
| 112 | +`void` – The function does not return a value. It directly modifies the DEFAULT_TOOLS object with the new properties. |
| 113 | + |
| 114 | +### `registerExternalTool` |
| 115 | + |
| 116 | +Overrides the default properties of tools. |
| 117 | +NOTE: |
| 118 | + |
| 119 | +- if toolName is already existent in `DEFAULT_TOOLS`, it will ovverride the tool |
| 120 | +- toolClass must be a valid cornerstone tool |
| 121 | + |
| 122 | +#### Syntax |
| 123 | + |
| 124 | +```typescript |
| 125 | +registerExternalTool(toolName: string, toolClass: any): void |
| 126 | +``` |
| 127 | + |
| 128 | +#### Parameters |
| 129 | + |
| 130 | +| Parameter | Type | Description | |
| 131 | +| ----------- | ------ | -------------------- | |
| 132 | +| `toolName` | string | The name of the tool | |
| 133 | +| `toolClass` | string | The tool class | |
| 134 | + |
| 135 | +#### Returns |
| 136 | + |
| 137 | +`void` – The function does not return a value. It directly modifies the DEFAULT_TOOLS and dvTools objects with the new tool. |
| 138 | + |
| 139 | +```typescript |
| 140 | +dvTools[toolClass.name] = toolClass; |
| 141 | +DEFAULT_TOOLS[toolName] = { |
| 142 | + name: toolName, |
| 143 | + class: toolClass.name, |
| 144 | + viewports: "all", |
| 145 | + configuration: {}, |
| 146 | + options: { mouseButtonMask: 1 }, |
| 147 | + defaultActive: false |
| 148 | +}; |
| 149 | +``` |
| 150 | + |
| 151 | +### `addDefaultTools` |
| 152 | + |
| 153 | +Add all default tools, as listed in `DEFAULT_TOOLS` |
| 154 | + |
| 155 | +#### Syntax |
| 156 | + |
| 157 | +```typescript |
| 158 | +addDefaultTools(elementId: string): void |
| 159 | +``` |
| 160 | + |
| 161 | +#### Parameters |
| 162 | + |
| 163 | +| Parameter | Type | Description | |
| 164 | +| ---------- | ------ | ------------------------------------------------------------------------------ | |
| 165 | +| `toolName` | string | The id of the cornerstone Enabled Element on which the tools will be activated | |
| 166 | + |
| 167 | +#### Returns |
| 168 | + |
| 169 | +`void` |
| 170 | + |
| 171 | +## Constants |
| 172 | + |
| 173 | +### `dvTools` |
| 174 | + |
| 175 | +Contains a set of custom tools that are used for various processing tasks. The tools are accessible by their respective names and can be extended or modified as needed. |
| 176 | + |
| 177 | +#### Syntax |
| 178 | + |
| 179 | +```typescript |
| 180 | +const dvTools: { |
| 181 | + [key: string]: any; |
| 182 | +} = { |
| 183 | + ..., |
| 184 | + OverlayTool: OverlayTool |
| 185 | +}; |
| 186 | +``` |
| 187 | + |
| 188 | +### `DEFAULT_STYLE` |
| 189 | + |
| 190 | +specifies the default visual settings for tools, such as line width, colors, font family, font size, and background color. These can be customized to fit the application's design needs. |
| 191 | + |
| 192 | +#### Syntax |
| 193 | + |
| 194 | +```typescript |
| 195 | +const DEFAULT_STYLE: ToolStyle = { |
| 196 | + width: 1, |
| 197 | + color: "#02FAE5", |
| 198 | + activeColor: "#00FF00", |
| 199 | + fillColor: "#0000FF", |
| 200 | + fontFamily: "Roboto", |
| 201 | + fontSize: 18, |
| 202 | + backgroundColor: "rgba(1, 1, 1, 0.7)" |
| 203 | +}; |
| 204 | +``` |
| 205 | + |
| 206 | +### `DEFAULT_SETTINGS` |
| 207 | + |
| 208 | +defines the default behavior of tools, such as whether mouse and touch interactions are enabled, SVG cursors are shown, and whether global tool synchronization is active. It also includes settings like auto-resizing viewports and line dash styles. |
| 209 | + |
| 210 | +#### Syntax |
| 211 | + |
| 212 | +```typescript |
| 213 | +const DEFAULT_SETTINGS: ToolSettings = { |
| 214 | + mouseEnabled: true, |
| 215 | + touchEnabled: true, |
| 216 | + showSVGCursors: true, |
| 217 | + globalToolSyncEnabled: false, |
| 218 | + autoResizeViewports: true, |
| 219 | + lineDash: [4, 4] |
| 220 | +}; |
| 221 | +``` |
| 222 | + |
| 223 | +### `DEFAULT_MOUSE_KEYS` |
| 224 | + |
| 225 | +configures default interactions for the tools. It includes mouse button mappings (e.g., shift + left mouse button for zoom), right mouse button bindings, and keyboard shortcuts. These defaults can be customized to change the behavior of the tools. |
| 226 | + |
| 227 | +#### Syntax |
| 228 | + |
| 229 | +```typescript |
| 230 | +const DEFAULT_MOUSE_KEYS: ToolMouseKeys = { |
| 231 | + debug: true, // log changes |
| 232 | + mouse_button_left: { |
| 233 | + shift: "Zoom", |
| 234 | + ctrl: "Pan", |
| 235 | + default: "Wwwc" |
| 236 | + }, |
| 237 | + mouse_button_right: { |
| 238 | + shift: "Zoom", |
| 239 | + ctrl: "Pan", |
| 240 | + default: "Wwwc" |
| 241 | + }, |
| 242 | + keyboard_shortcuts: { |
| 243 | + // alt key + letter |
| 244 | + KEY_R: "Rotate", |
| 245 | + KEY_A: "Angle", |
| 246 | + KEY_L: "Length" |
| 247 | + } |
| 248 | +}; |
| 249 | +``` |
| 250 | + |
| 251 | +<br></br> |
| 252 | + |
| 253 | +<div style="text-align: center;"> |
| 254 | + <img src="https://press.r1-it.storage.cloud.it/logo_trasparent.png" alt="D/Vision Lab" height="200" /> |
| 255 | +</div> |
| 256 | +``` |
0 commit comments