larvitar 1.5.13 → 2.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.
Files changed (103) hide show
  1. package/.vscode/settings.json +4 -0
  2. package/README.md +78 -48
  3. package/bundler/webpack.common.js +27 -0
  4. package/bundler/webpack.dev.js +23 -0
  5. package/bundler/webpack.prod.js +19 -0
  6. package/decs.d.ts +12 -0
  7. package/dist/imaging/MetaDataReadable.d.ts +39 -0
  8. package/dist/imaging/MetaDataTypes.d.ts +3488 -0
  9. package/dist/imaging/imageAnonymization.d.ts +12 -0
  10. package/dist/imaging/imageColormaps.d.ts +47 -0
  11. package/dist/imaging/imageContours.d.ts +18 -0
  12. package/dist/imaging/imageIo.d.ts +42 -0
  13. package/dist/imaging/imageLayers.d.ts +56 -0
  14. package/dist/imaging/imageLoading.d.ts +65 -0
  15. package/dist/imaging/imageParsing.d.ts +46 -0
  16. package/dist/imaging/imagePresets.d.ts +43 -0
  17. package/dist/imaging/imageRendering.d.ts +238 -0
  18. package/dist/imaging/imageReslice.d.ts +14 -0
  19. package/dist/imaging/imageStore.d.ts +121 -0
  20. package/dist/imaging/imageTags.d.ts +22 -0
  21. package/dist/imaging/imageTools.d.ts +20 -0
  22. package/dist/imaging/imageUtils.d.ts +165 -0
  23. package/dist/imaging/loaders/commonLoader.d.ts +103 -0
  24. package/dist/imaging/loaders/dicomLoader.d.ts +29 -0
  25. package/dist/imaging/loaders/fileLoader.d.ts +33 -0
  26. package/dist/imaging/loaders/multiframeLoader.d.ts +37 -0
  27. package/dist/imaging/loaders/nrrdLoader.d.ts +112 -0
  28. package/dist/imaging/loaders/resliceLoader.d.ts +15 -0
  29. package/dist/imaging/monitors/memory.d.ts +41 -0
  30. package/dist/imaging/monitors/performance.d.ts +23 -0
  31. package/dist/imaging/parsers/ecg.d.ts +15 -0
  32. package/dist/imaging/parsers/nrrd.d.ts +3 -0
  33. package/dist/imaging/tools/custom/4dSliceScrollTool.d.ts +12 -0
  34. package/dist/imaging/tools/custom/contourTool.d.ts +409 -0
  35. package/dist/imaging/tools/custom/diameterTool.d.ts +18 -0
  36. package/dist/imaging/tools/custom/editMaskTool.d.ts +22 -0
  37. package/dist/imaging/tools/custom/ellipticalRoiOverlayTool.d.ts +45 -0
  38. package/dist/imaging/tools/custom/polygonSegmentationMixin.d.ts +54 -0
  39. package/dist/imaging/tools/custom/polylineScissorsTool.d.ts +11 -0
  40. package/dist/imaging/tools/custom/rectangleRoiOverlayTool.d.ts +45 -0
  41. package/dist/imaging/tools/custom/seedTool.d.ts +0 -0
  42. package/dist/imaging/tools/custom/setLabelMap3D.d.ts +39 -0
  43. package/dist/imaging/tools/custom/thresholdsBrushTool.d.ts +19 -0
  44. package/dist/imaging/tools/default.d.ts +53 -0
  45. package/dist/imaging/tools/interaction.d.ts +30 -0
  46. package/dist/imaging/tools/io.d.ts +38 -0
  47. package/dist/imaging/tools/main.d.ts +81 -0
  48. package/dist/imaging/tools/segmentation.d.ts +125 -0
  49. package/dist/imaging/tools/state.d.ts +17 -0
  50. package/dist/imaging/tools/strategies/eraseFreehand.d.ts +16 -0
  51. package/dist/imaging/tools/strategies/fillFreehand.d.ts +16 -0
  52. package/dist/imaging/tools/strategies/index.d.ts +2 -0
  53. package/dist/index.d.ts +34 -0
  54. package/dist/larvitar.js +89801 -0
  55. package/dist/larvitar.js.map +1 -0
  56. package/imaging/MetaDataReadable.ts +40 -0
  57. package/imaging/MetaDataTypes.ts +3490 -0
  58. package/imaging/dataDictionary.json +5328 -5328
  59. package/imaging/{imageAnonymization.js → imageAnonymization.ts} +41 -13
  60. package/imaging/{imageColormaps.js → imageColormaps.ts} +48 -30
  61. package/imaging/{imageContours.js → imageContours.ts} +24 -22
  62. package/imaging/{imageIo.js → imageIo.ts} +89 -52
  63. package/imaging/{imageLayers.js → imageLayers.ts} +31 -14
  64. package/imaging/{imageLoading.js → imageLoading.ts} +108 -45
  65. package/imaging/{imageParsing.js → imageParsing.ts} +158 -80
  66. package/imaging/{imagePresets.js → imagePresets.ts} +44 -11
  67. package/imaging/imageRendering.ts +1091 -0
  68. package/imaging/{imageReslice.js → imageReslice.ts} +18 -9
  69. package/imaging/imageStore.ts +487 -0
  70. package/imaging/imageTags.ts +609 -0
  71. package/imaging/imageTools.js +2 -1
  72. package/imaging/{imageUtils.js → imageUtils.ts} +211 -701
  73. package/imaging/loaders/{commonLoader.js → commonLoader.ts} +73 -24
  74. package/imaging/loaders/{dicomLoader.js → dicomLoader.ts} +25 -5
  75. package/imaging/loaders/{fileLoader.js → fileLoader.ts} +5 -5
  76. package/imaging/loaders/{multiframeLoader.js → multiframeLoader.ts} +145 -90
  77. package/imaging/loaders/{nrrdLoader.js → nrrdLoader.ts} +230 -64
  78. package/imaging/loaders/{resliceLoader.js → resliceLoader.ts} +51 -20
  79. package/imaging/monitors/{memory.js → memory.ts} +54 -8
  80. package/imaging/monitors/performance.ts +34 -0
  81. package/imaging/parsers/ecg.ts +51 -0
  82. package/imaging/tools/README.md +27 -0
  83. package/imaging/tools/custom/4dSliceScrollTool.js +47 -46
  84. package/imaging/tools/custom/ellipticalRoiOverlayTool.js +534 -0
  85. package/imaging/tools/custom/polylineScissorsTool.js +1 -1
  86. package/imaging/tools/custom/rectangleRoiOverlayTool.js +564 -0
  87. package/imaging/tools/{setLabelMap3D.js → custom/setLabelMap3D.ts} +19 -25
  88. package/imaging/tools/{default.js → default.ts} +114 -30
  89. package/imaging/tools/{interaction.js → interaction.ts} +42 -23
  90. package/imaging/tools/{io.js → io.ts} +47 -31
  91. package/imaging/tools/{main.js → main.ts} +105 -40
  92. package/imaging/tools/{segmentation.js → segmentation.ts} +95 -68
  93. package/imaging/tools/{state.js → state.ts} +7 -12
  94. package/imaging/tools/types.d.ts +243 -0
  95. package/imaging/types.d.ts +197 -0
  96. package/{index.js → index.ts} +43 -14
  97. package/jsdoc.json +1 -1
  98. package/package.json +32 -14
  99. package/tsconfig.json +102 -0
  100. package/imaging/imageRendering.js +0 -860
  101. package/imaging/imageStore.js +0 -322
  102. package/modules/vuex/larvitar.js +0 -187
  103. /package/imaging/tools/{polygonSegmentationMixin.js → custom/polygonSegmentationMixin.js} +0 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  // external libraries
7
7
  import cornerstone from "cornerstone-core";
8
- import cornerstoneTools from "cornerstone-tools/dist/cornerstoneTools.js";
8
+ import cornerstoneTools from "cornerstone-tools";
9
9
  import cornerstoneMath from "cornerstone-math";
10
10
  import Hammer from "hammerjs";
11
11
  import { each, extend } from "lodash";
@@ -18,7 +18,8 @@ import {
18
18
  DEFAULT_SETTINGS,
19
19
  dvTools
20
20
  } from "./default";
21
- import { larvitar_store } from "../imageStore";
21
+ import { set as setStore } from "../imageStore";
22
+ import type { ToolConfig, ToolSettings, ToolStyle } from "./types";
22
23
 
23
24
  /**
24
25
  * Initialize cornerstone tools with default configuration (extended with custom configuration)
@@ -27,7 +28,10 @@ import { larvitar_store } from "../imageStore";
27
28
  * @param {Object} settings - the style object (see tools/default.js)
28
29
  * @example larvitar.initializeCSTools({showSVGCursors:false}, {color: "0000FF"});
29
30
  */
30
- const initializeCSTools = function (settings, style) {
31
+ const initializeCSTools = function (
32
+ settings?: ToolSettings,
33
+ style?: ToolStyle
34
+ ) {
31
35
  cornerstoneTools.external.cornerstone = cornerstone;
32
36
  cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
33
37
  cornerstoneTools.external.Hammer = Hammer;
@@ -47,10 +51,14 @@ const initializeCSTools = function (settings, style) {
47
51
  * Create stack object to sync stack tools
48
52
  * @function csToolsCreateStack
49
53
  * @param {HTMLElement} element - The target hmtl element.
50
- * @param {Array} imageIds - Stack image ids.
54
+ * @param {Array?} imageIds - Stack image ids.
51
55
  * @param {String} currentImageId - The current image id.
52
56
  */
53
- const csToolsCreateStack = function (element, imageIds, currentImageIndex) {
57
+ const csToolsCreateStack = function (
58
+ element: HTMLElement,
59
+ imageIds?: string[],
60
+ currentImageIndex?: number
61
+ ) {
54
62
  let stack;
55
63
  if (imageIds) {
56
64
  stack = {
@@ -70,7 +78,11 @@ const csToolsCreateStack = function (element, imageIds, currentImageIndex) {
70
78
  cornerstoneTools.addToolState(element, "stack", stack);
71
79
  };
72
80
 
73
- export function csToolsUpdateImageIds(elementId, imageIds, imageIdIndex) {
81
+ export function csToolsUpdateImageIds(
82
+ elementId: string,
83
+ imageIds: string[],
84
+ imageIdIndex: number
85
+ ) {
74
86
  const element = document.getElementById(elementId);
75
87
  if (element) {
76
88
  const stackState = cornerstoneTools.getToolState(element, "stack");
@@ -88,7 +100,7 @@ export function csToolsUpdateImageIds(elementId, imageIds, imageIdIndex) {
88
100
  * @param {String} elementId - The target html element id
89
101
  * @param {String} imageId - The imageId in the form xxxxxx//:imageIndex
90
102
  */
91
- export function csToolsUpdateImageIndex(elementId, imageId) {
103
+ export function csToolsUpdateImageIndex(elementId: string, imageId: string) {
92
104
  let currentImageIdIndex = parseInt(imageId.split(":")[1]);
93
105
  const element = document.getElementById(elementId);
94
106
  const stackState = cornerstoneTools.getToolState(element, "stack");
@@ -100,7 +112,7 @@ export function csToolsUpdateImageIndex(elementId, imageId) {
100
112
  *
101
113
  * @param {*} toolName
102
114
  */
103
- const isToolMissing = function (toolName) {
115
+ const isToolMissing = function (toolName: string) {
104
116
  let elements = cornerstone.getEnabledElements();
105
117
  let isToolMissing = false;
106
118
  // TODO check only target viewports
@@ -120,14 +132,26 @@ const isToolMissing = function (toolName) {
120
132
  * @param {*} targetElementId
121
133
  * @example larvitar.addTool("ScaleOverlay", {configuration:{minorTickLength: 10, majorTickLength: 25}}, "viewer")
122
134
  */
123
- const addTool = function (toolName, customConfig, targetElementId) {
135
+ const addTool = function (
136
+ toolName: string,
137
+ customConfig: Partial<ToolConfig>,
138
+ targetElementId?: string
139
+ ) {
124
140
  // extend defaults with user custom props
125
- let defaultConfig = DEFAULT_TOOLS[toolName];
141
+ let defaultConfig = DEFAULT_TOOLS[toolName] || {};
126
142
  extend(defaultConfig, customConfig);
127
143
 
128
144
  if (isToolMissing(toolName)) {
129
- const toolClassName = DEFAULT_TOOLS[toolName].class;
145
+ const toolClassName = defaultConfig.class;
146
+
147
+ if (!toolClassName) {
148
+ throw new Error(
149
+ `Tool ${toolName} class not found. Please check tools/default or pass a valid tool class name in the configuration object.`
150
+ );
151
+ }
152
+
130
153
  const toolClass = cornerstoneTools[toolClassName] || dvTools[toolClassName];
154
+
131
155
  if (targetElementId) {
132
156
  let element = document.getElementById(targetElementId);
133
157
  cornerstoneTools.addToolForElement(element, toolClass, defaultConfig);
@@ -141,11 +165,16 @@ const addTool = function (toolName, customConfig, targetElementId) {
141
165
  * Add all default tools, as listed in tools/default.js
142
166
  * @function addDefaultTools
143
167
  */
144
- export const addDefaultTools = function (elementId) {
168
+ export const addDefaultTools = function (elementId: string) {
145
169
  let elements = cornerstone.getEnabledElements();
146
170
 
147
171
  if (elements.length == 0) {
148
172
  let element = document.getElementById(elementId);
173
+ if (!element) {
174
+ throw new Error(
175
+ `Element with id ${elementId} not found. Cannot add default tools.`
176
+ );
177
+ }
149
178
  cornerstone.enable(element);
150
179
  }
151
180
 
@@ -155,7 +184,6 @@ export const addDefaultTools = function (elementId) {
155
184
  if (!isToolMissing(tool.name)) {
156
185
  return;
157
186
  }
158
-
159
187
  // check target viewports and call add tool with options
160
188
  if (tool.viewports == "all") {
161
189
  addTool(tool.name, tool.configuration);
@@ -189,7 +217,7 @@ export const addDefaultTools = function (elementId) {
189
217
  * Try to update image, catching errors if image is not loaded yet
190
218
  * @param {HTMLObject} element
191
219
  */
192
- function tryUpdateImage(element) {
220
+ function tryUpdateImage(element: HTMLElement) {
193
221
  try {
194
222
  cornerstone.updateImage(element);
195
223
  } catch (err) {
@@ -205,8 +233,13 @@ function tryUpdateImage(element) {
205
233
  * @param {Array} viewports - The hmtl element id to be used for tool initialization.
206
234
  * @param {Boolean} doNotSetInStore - Flag to avoid setting in store (useful on tools initialization eg in addDefaultTools). NOTE: This is just a hack, we must rework tools/ui sync.
207
235
  */
208
- const setToolActive = function (toolName, options, viewports, doNotSetInStore) {
209
- let defaultOpt = { ...DEFAULT_TOOLS[toolName].options }; // deep copy obj because otherwise cornerstone tools will modify it
236
+ const setToolActive = function (
237
+ toolName: string,
238
+ options?: Partial<ToolConfig["options"]>,
239
+ viewports?: string[],
240
+ doNotSetInStore?: boolean
241
+ ) {
242
+ let defaultOpt = { ...DEFAULT_TOOLS[toolName]?.options }; // deep copy obj because otherwise cornerstone tools will modify it
210
243
 
211
244
  extend(defaultOpt, options);
212
245
 
@@ -215,7 +248,9 @@ const setToolActive = function (toolName, options, viewports, doNotSetInStore) {
215
248
  each(viewports, function (elementId) {
216
249
  let el = document.getElementById(elementId);
217
250
  cornerstoneTools.setToolActiveForElement(el, toolName, defaultOpt);
218
- tryUpdateImage(el);
251
+ if (el) {
252
+ tryUpdateImage(el);
253
+ }
219
254
  });
220
255
  } else {
221
256
  // activate and update all
@@ -235,10 +270,10 @@ const setToolActive = function (toolName, options, viewports, doNotSetInStore) {
235
270
  defaultOpt.mouseButtonMask = [defaultOpt.mouseButtonMask];
236
271
  }
237
272
  if (defaultOpt.mouseButtonMask.includes(1)) {
238
- larvitar_store.set("leftActiveTool", toolName);
273
+ setStore(["leftActiveTool", toolName]);
239
274
  }
240
275
  if (defaultOpt.mouseButtonMask.includes(2)) {
241
- larvitar_store.set("rightActiveTool", toolName);
276
+ setStore(["rightActiveTool", toolName]);
242
277
  }
243
278
  }
244
279
  };
@@ -248,25 +283,38 @@ const setToolActive = function (toolName, options, viewports, doNotSetInStore) {
248
283
  * @function setToolDisabled
249
284
  * @param {String} toolName - The tool name.
250
285
  * @param {Array} viewports - The hmtl element id to be used for tool initialization.
286
+ * @param {Boolean} resetCursor - Flag to restore native cursor. @default true
251
287
  */
252
- const setToolDisabled = function (toolName, viewports) {
288
+ const setToolDisabled = function (
289
+ toolName: string,
290
+ viewports?: string[],
291
+ resetCursor = true
292
+ ) {
253
293
  if (viewports && viewports.length > 0) {
254
- // activate and update only for "viewports"
294
+ // disable and update only for "viewports"
255
295
  each(viewports, function (elementId) {
256
296
  let el = document.getElementById(elementId);
297
+ if (!el) {
298
+ console.warn("setToolDisabled: element not found:", elementId);
299
+ return;
300
+ }
257
301
  cornerstoneTools.setToolDisabledForElement(el, toolName);
258
- // restore native cursor
259
- el.style.cursor = "initial";
260
- tryUpdateImage(el);
302
+ if (resetCursor && el && el.style) {
303
+ // restore native cursor
304
+ el.style.cursor = "initial";
305
+ tryUpdateImage(el);
306
+ }
261
307
  });
262
308
  } else {
263
- // activate and update all
309
+ // disable and update all
264
310
  cornerstoneTools.setToolDisabled(toolName);
265
311
  let enabledElements = cornerstone.getEnabledElements();
266
312
  each(enabledElements, enel => {
267
- // restore native cursor
268
- enel.element.style.cursor = "initial";
269
- tryUpdateImage(enel.element);
313
+ if (resetCursor) {
314
+ // restore native cursor
315
+ enel.element.style.cursor = "initial";
316
+ tryUpdateImage(enel.element);
317
+ }
270
318
  });
271
319
  }
272
320
  };
@@ -276,25 +324,38 @@ const setToolDisabled = function (toolName, viewports) {
276
324
  * @function setToolEnabled
277
325
  * @param {String} toolName - The tool name.
278
326
  * @param {Array} viewports - The hmtl element id to be used for tool initialization.
327
+ * @param {Boolean} resetCursor - Flag to restore native cursor. @default true
279
328
  */
280
- const setToolEnabled = function (toolName, viewports) {
329
+ const setToolEnabled = function (
330
+ toolName: string,
331
+ viewports?: string[],
332
+ resetCursor = true
333
+ ) {
281
334
  if (viewports && viewports.length > 0) {
282
- // activate and update only for "viewports"
335
+ // enable and update only for "viewports"
283
336
  each(viewports, function (elementId) {
284
337
  let el = document.getElementById(elementId);
338
+ if (!el) {
339
+ console.warn("setToolDisabled: element not found:", elementId);
340
+ return;
341
+ }
285
342
  cornerstoneTools.setToolEnabledForElement(el, toolName);
286
- // restore native cursor
287
- el.style.cursor = "initial";
288
- tryUpdateImage(el);
343
+ if (resetCursor && el && el.style) {
344
+ // restore native cursor
345
+ el.style.cursor = "initial";
346
+ tryUpdateImage(el);
347
+ }
289
348
  });
290
349
  } else {
291
- // activate and update all
350
+ // enable and update all
292
351
  cornerstoneTools.setToolEnabled(toolName);
293
352
  let enabledElements = cornerstone.getEnabledElements();
294
353
  each(enabledElements, enel => {
295
- // restore native cursor
296
- enel.element.style.cursor = "initial";
297
- tryUpdateImage(enel.element);
354
+ if (resetCursor) {
355
+ // restore native cursor
356
+ enel.element.style.cursor = "initial";
357
+ tryUpdateImage(enel.element);
358
+ }
298
359
  });
299
360
  }
300
361
  };
@@ -305,11 +366,15 @@ const setToolEnabled = function (toolName, viewports) {
305
366
  * @param {String} toolName - The tool name.
306
367
  * @param {Array} viewports - The hmtl element id to be used for tool initialization.
307
368
  */
308
- const setToolPassive = function (toolName, viewports) {
369
+ const setToolPassive = function (toolName: string, viewports?: string[]) {
309
370
  if (viewports && viewports.length > 0) {
310
371
  // activate and update only for "viewports"
311
372
  each(viewports, function (elementId) {
312
373
  let el = document.getElementById(elementId);
374
+ if (!el) {
375
+ console.warn("setToolDisabled: element not found:", elementId);
376
+ return;
377
+ }
313
378
  cornerstoneTools.setToolPassiveForElement(el, toolName);
314
379
  tryUpdateImage(el);
315
380
  });
@@ -330,7 +395,7 @@ const setToolPassive = function (toolName, viewports) {
330
395
  * @function setToolsStyle
331
396
  * @param {Object} style - the style object (see tools/defaults.js)
332
397
  */
333
- const setToolsStyle = function (style) {
398
+ const setToolsStyle = function (style?: ToolStyle) {
334
399
  extend(DEFAULT_STYLE, style);
335
400
 
336
401
  let fontFamily = DEFAULT_STYLE.fontFamily;
@@ -339,7 +404,7 @@ const setToolsStyle = function (style) {
339
404
  cornerstoneTools.toolStyle.setToolWidth(DEFAULT_STYLE.width);
340
405
  cornerstoneTools.toolColors.setToolColor(DEFAULT_STYLE.color);
341
406
  cornerstoneTools.toolColors.setActiveColor(DEFAULT_STYLE.activeColor);
342
- cornerstoneTools.toolColors.setFillColor(DEFAULT_STYLE.fillColor); // used only by FreehandRoiTool indide handles
407
+ cornerstoneTools.toolColors.setFillColor(DEFAULT_STYLE.fillColor); // used only by FreehandRoiTool inside handles
343
408
  cornerstoneTools.textStyle.setFont(`${fontSize}px ${fontFamily}`);
344
409
  cornerstoneTools.textStyle.setBackgroundColor(DEFAULT_STYLE.backgroundColor);
345
410
  };