larvitar 2.0.4 → 2.0.6

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/larvitar.js +5 -3
  3. package/dist/larvitar.js.map +1 -1
  4. package/package.json +6 -2
  5. package/.github/workflows/build-docs.yml +0 -59
  6. package/.github/workflows/codeql-analysis.yml +0 -71
  7. package/.github/workflows/deploy.yml +0 -37
  8. package/.vscode/settings.json +0 -4
  9. package/CODE_OF_CONDUCT.md +0 -76
  10. package/MIGRATION.md +0 -25
  11. package/bundler/webpack.common.js +0 -27
  12. package/bundler/webpack.dev.js +0 -23
  13. package/bundler/webpack.prod.js +0 -19
  14. package/decs.d.ts +0 -12
  15. package/imaging/MetaDataReadable.ts +0 -42
  16. package/imaging/MetaDataTypes.ts +0 -3491
  17. package/imaging/dataDictionary.json +0 -21866
  18. package/imaging/imageAnonymization.ts +0 -135
  19. package/imaging/imageColormaps.ts +0 -217
  20. package/imaging/imageContours.ts +0 -196
  21. package/imaging/imageIo.ts +0 -251
  22. package/imaging/imageLayers.ts +0 -121
  23. package/imaging/imageLoading.ts +0 -299
  24. package/imaging/imageParsing.ts +0 -444
  25. package/imaging/imagePresets.ts +0 -156
  26. package/imaging/imageRendering.ts +0 -1091
  27. package/imaging/imageReslice.ts +0 -87
  28. package/imaging/imageStore.ts +0 -487
  29. package/imaging/imageTags.ts +0 -609
  30. package/imaging/imageTools.js +0 -708
  31. package/imaging/imageUtils.ts +0 -1079
  32. package/imaging/loaders/commonLoader.ts +0 -275
  33. package/imaging/loaders/dicomLoader.ts +0 -66
  34. package/imaging/loaders/fileLoader.ts +0 -71
  35. package/imaging/loaders/multiframeLoader.ts +0 -435
  36. package/imaging/loaders/nrrdLoader.ts +0 -630
  37. package/imaging/loaders/resliceLoader.ts +0 -205
  38. package/imaging/monitors/memory.ts +0 -151
  39. package/imaging/monitors/performance.ts +0 -34
  40. package/imaging/parsers/ecg.ts +0 -54
  41. package/imaging/parsers/nrrd.js +0 -485
  42. package/imaging/tools/README.md +0 -27
  43. package/imaging/tools/custom/4dSliceScrollTool.js +0 -146
  44. package/imaging/tools/custom/BorderMagnifyTool.js +0 -99
  45. package/imaging/tools/custom/contourTool.js +0 -1884
  46. package/imaging/tools/custom/diameterTool.js +0 -141
  47. package/imaging/tools/custom/editMaskTool.js +0 -141
  48. package/imaging/tools/custom/ellipticalRoiOverlayTool.js +0 -534
  49. package/imaging/tools/custom/polygonSegmentationMixin.js +0 -245
  50. package/imaging/tools/custom/polylineScissorsTool.js +0 -59
  51. package/imaging/tools/custom/rectangleRoiOverlayTool.js +0 -564
  52. package/imaging/tools/custom/seedTool.js +0 -342
  53. package/imaging/tools/custom/setLabelMap3D.ts +0 -242
  54. package/imaging/tools/custom/thresholdsBrushTool.js +0 -161
  55. package/imaging/tools/default.ts +0 -594
  56. package/imaging/tools/interaction.ts +0 -266
  57. package/imaging/tools/io.ts +0 -229
  58. package/imaging/tools/main.ts +0 -424
  59. package/imaging/tools/segmentation.ts +0 -532
  60. package/imaging/tools/segmentations.md +0 -38
  61. package/imaging/tools/state.ts +0 -74
  62. package/imaging/tools/strategies/eraseFreehand.js +0 -76
  63. package/imaging/tools/strategies/fillFreehand.js +0 -79
  64. package/imaging/tools/strategies/index.js +0 -2
  65. package/imaging/tools/types.d.ts +0 -243
  66. package/imaging/types.d.ts +0 -200
  67. package/imaging/waveforms/ecg.ts +0 -191
  68. package/index.ts +0 -431
  69. package/jsdoc.json +0 -52
  70. package/rollup.config.js +0 -51
  71. package/template/.gitkeep +0 -0
  72. package/tsconfig.json +0 -102
@@ -1,424 +0,0 @@
1
- /** @module imaging/tools/main
2
- * @desc This file provides functionalities
3
- * for initializing tools and stacks
4
- */
5
-
6
- // external libraries
7
- import cornerstone from "cornerstone-core";
8
- import cornerstoneTools from "cornerstone-tools";
9
- import cornerstoneMath from "cornerstone-math";
10
- import Hammer from "hammerjs";
11
- import { each, extend } from "lodash";
12
-
13
- // internal libraries
14
- import { saveAnnotations, loadAnnotations, exportAnnotations } from "./io";
15
- import {
16
- DEFAULT_TOOLS,
17
- DEFAULT_STYLE,
18
- DEFAULT_SETTINGS,
19
- dvTools
20
- } from "./default";
21
- import { set as setStore } from "../imageStore";
22
- import type { ToolConfig, ToolSettings, ToolStyle } from "./types";
23
-
24
- /**
25
- * Initialize cornerstone tools with default configuration (extended with custom configuration)
26
- * @function initializeCSTools
27
- * @param {Object} settings - the settings object (see tools/default.js)
28
- * @param {Object} settings - the style object (see tools/default.js)
29
- * @example larvitar.initializeCSTools({showSVGCursors:false}, {color: "0000FF"});
30
- */
31
- const initializeCSTools = function (
32
- settings?: ToolSettings,
33
- style?: ToolStyle
34
- ) {
35
- cornerstoneTools.external.cornerstone = cornerstone;
36
- cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
37
- cornerstoneTools.external.Hammer = Hammer;
38
- extend(DEFAULT_SETTINGS, settings);
39
-
40
- // hack to fix warning on init() - but breaks labelmap 0 auto generation
41
- // see https://github.com/cornerstonejs/cornerstoneTools/issues/1395
42
- cornerstoneTools.getModule(
43
- "segmentation"
44
- ).configuration.segmentsPerLabelmap = 0;
45
-
46
- cornerstoneTools.init(DEFAULT_SETTINGS);
47
- setToolsStyle(style);
48
- };
49
-
50
- /**
51
- * Create stack object to sync stack tools
52
- * @function csToolsCreateStack
53
- * @param {HTMLElement} element - The target hmtl element.
54
- * @param {Array?} imageIds - Stack image ids.
55
- * @param {String} currentImageId - The current image id.
56
- */
57
- const csToolsCreateStack = function (
58
- element: HTMLElement,
59
- imageIds?: string[],
60
- currentImageIndex?: number
61
- ) {
62
- let stack;
63
- if (imageIds) {
64
- stack = {
65
- currentImageIdIndex: currentImageIndex,
66
- imageIds: imageIds
67
- };
68
- } else {
69
- stack = {
70
- currentImageIdIndex: 0,
71
- imageIds: "imageLoader://0"
72
- };
73
- if (cornerstone.getEnabledElements().length == 0) {
74
- cornerstone.enable(element);
75
- }
76
- }
77
- cornerstoneTools.addStackStateManager(element, ["stack"]);
78
- cornerstoneTools.addToolState(element, "stack", stack);
79
- };
80
-
81
- export function csToolsUpdateImageIds(
82
- elementId: string,
83
- imageIds: string[],
84
- imageIdIndex: number
85
- ) {
86
- const element = document.getElementById(elementId);
87
- if (element) {
88
- const stackState = cornerstoneTools.getToolState(element, "stack");
89
- const stackData = stackState.data[0];
90
- stackData.imageIds = imageIds;
91
- stackData.currentImageIdIndex =
92
- stackData.currentImageIdIndex < imageIdIndex
93
- ? stackData.currentImageIdIndex
94
- : (stackData.currentImageIdIndex += 1);
95
- }
96
- }
97
-
98
- /**
99
- * Update currentImageIdIndex in cs tools stack
100
- * @param {String} elementId - The target html element id
101
- * @param {String} imageId - The imageId in the form xxxxxx//:imageIndex
102
- */
103
- export function csToolsUpdateImageIndex(elementId: string, imageId: string) {
104
- let currentImageIdIndex = parseInt(imageId.split(":")[1]);
105
- const element = document.getElementById(elementId);
106
- const stackState = cornerstoneTools.getToolState(element, "stack");
107
- const stackData = stackState.data[0];
108
- stackData.currentImageIdIndex = currentImageIdIndex;
109
- }
110
-
111
- /**
112
- *
113
- * @param {*} toolName
114
- */
115
- const isToolMissing = function (toolName: string) {
116
- let elements = cornerstone.getEnabledElements();
117
- let isToolMissing = false;
118
- // TODO check only target viewports
119
- each(elements, function (el) {
120
- let added = cornerstoneTools.getToolForElement(el.element, toolName);
121
- if (added === undefined) {
122
- isToolMissing = true;
123
- }
124
- });
125
-
126
- return isToolMissing;
127
- };
128
-
129
- /**
130
- * Add a cornerstone tool (grab it from original library or dvision custom tools)
131
- * @param {*} toolName
132
- * @param {*} targetElementId
133
- * @example larvitar.addTool("ScaleOverlay", {configuration:{minorTickLength: 10, majorTickLength: 25}}, "viewer")
134
- */
135
- const addTool = function (
136
- toolName: string,
137
- customConfig: Partial<ToolConfig>,
138
- targetElementId?: string
139
- ) {
140
- // extend defaults with user custom props
141
- let defaultConfig = DEFAULT_TOOLS[toolName];
142
- extend(defaultConfig, customConfig);
143
-
144
- if (isToolMissing(toolName)) {
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
-
153
- const toolClass = cornerstoneTools[toolClassName] || dvTools[toolClassName];
154
-
155
- if (targetElementId) {
156
- let element = document.getElementById(targetElementId);
157
- cornerstoneTools.addToolForElement(element, toolClass, defaultConfig);
158
- } else {
159
- cornerstoneTools.addTool(toolClass, defaultConfig);
160
- }
161
- }
162
- };
163
-
164
- /**
165
- * Add all default tools, as listed in tools/default.js
166
- * @function addDefaultTools
167
- */
168
- export const addDefaultTools = function (elementId: string) {
169
- let elements = cornerstone.getEnabledElements();
170
-
171
- if (elements.length == 0) {
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
- }
178
- cornerstone.enable(element);
179
- }
180
-
181
- // for each default tool
182
- each(DEFAULT_TOOLS, tool => {
183
- // check if already added
184
- if (!isToolMissing(tool.name)) {
185
- return;
186
- }
187
- // check target viewports and call add tool with options
188
- if (tool.viewports == "all") {
189
- addTool(tool.name, tool.configuration);
190
- } else {
191
- // call add tool for element for each element
192
- each(tool.viewports, targetElementId => {
193
- addTool(tool.name, tool.configuration, targetElementId);
194
- });
195
- }
196
-
197
- // if sync tool, enable
198
- if (tool.sync) {
199
- const synchronizer = new cornerstoneTools.Synchronizer(
200
- "cornerstoneimagerendered",
201
- cornerstoneTools[tool.sync]
202
- );
203
- elements.forEach(element => {
204
- synchronizer.add(element.element);
205
- });
206
-
207
- synchronizer.enabled = true;
208
- }
209
-
210
- if (tool.defaultActive) {
211
- setToolActive(tool.name, tool.options, [], true);
212
- }
213
- });
214
- };
215
-
216
- /**
217
- * Try to update image, catching errors if image is not loaded yet
218
- * @param {HTMLObject} element
219
- */
220
- function tryUpdateImage(element: HTMLElement) {
221
- try {
222
- cornerstone.updateImage(element);
223
- } catch (err) {
224
- // console.warn("updateImage: image has not been loaded yet:", element.id);
225
- }
226
- }
227
-
228
- /**
229
- * Set Tool "active" on all elements (ie, rendered and manipulable) & refresh cornerstone elements
230
- * @function setToolActive
231
- * @param {String} toolName - The tool name.
232
- * @param {Object} options - The custom options. @default from tools/default.js
233
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
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.
235
- */
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
243
-
244
- extend(defaultOpt, options);
245
-
246
- if (viewports && viewports.length > 0) {
247
- // activate and update only for "viewports"
248
- each(viewports, function (elementId) {
249
- let el = document.getElementById(elementId);
250
- cornerstoneTools.setToolActiveForElement(el, toolName, defaultOpt);
251
- if (el) {
252
- tryUpdateImage(el);
253
- }
254
- });
255
- } else {
256
- // activate and update all
257
- cornerstoneTools.setToolActive(toolName, defaultOpt);
258
- let enabledElements = cornerstone.getEnabledElements();
259
- each(enabledElements, enel => {
260
- tryUpdateImage(enel.element);
261
- });
262
- }
263
-
264
- // set active tool in larvitar store
265
- // mouseButtonMask is now an array, thanks to cs tools "setToolActiveForElement",
266
- // but only if it has a rendered image in the viewport (!)
267
- // so we must check the type anyway for type coherence
268
- if (!doNotSetInStore && defaultOpt.mouseButtonMask) {
269
- if (typeof defaultOpt.mouseButtonMask == "number") {
270
- defaultOpt.mouseButtonMask = [defaultOpt.mouseButtonMask];
271
- }
272
- if (defaultOpt.mouseButtonMask.includes(1)) {
273
- setStore(["leftActiveTool", toolName]);
274
- }
275
- if (defaultOpt.mouseButtonMask.includes(2)) {
276
- setStore(["rightActiveTool", toolName]);
277
- }
278
- }
279
- };
280
-
281
- /**
282
- * Set Tool "disabled" on all elements (ie, not rendered) & refresh cornerstone elements
283
- * @function setToolDisabled
284
- * @param {String} toolName - The tool name.
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
287
- */
288
- const setToolDisabled = function (
289
- toolName: string,
290
- viewports?: string[],
291
- resetCursor = true
292
- ) {
293
- if (viewports && viewports.length > 0) {
294
- // disable and update only for "viewports"
295
- each(viewports, function (elementId) {
296
- let el = document.getElementById(elementId);
297
- if (!el) {
298
- console.warn("setToolDisabled: element not found:", elementId);
299
- return;
300
- }
301
- cornerstoneTools.setToolDisabledForElement(el, toolName);
302
- if (resetCursor && el && el.style) {
303
- // restore native cursor
304
- el.style.cursor = "initial";
305
- tryUpdateImage(el);
306
- }
307
- });
308
- } else {
309
- // disable and update all
310
- cornerstoneTools.setToolDisabled(toolName);
311
- let enabledElements = cornerstone.getEnabledElements();
312
- each(enabledElements, enel => {
313
- if (resetCursor) {
314
- // restore native cursor
315
- enel.element.style.cursor = "initial";
316
- tryUpdateImage(enel.element);
317
- }
318
- });
319
- }
320
- };
321
-
322
- /**
323
- * Set Tool "enabled" on all elements (ie, rendered but not manipulable) & refresh cornerstone elements
324
- * @function setToolEnabled
325
- * @param {String} toolName - The tool name.
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
328
- */
329
- const setToolEnabled = function (
330
- toolName: string,
331
- viewports?: string[],
332
- resetCursor = true
333
- ) {
334
- if (viewports && viewports.length > 0) {
335
- // enable and update only for "viewports"
336
- each(viewports, function (elementId) {
337
- let el = document.getElementById(elementId);
338
- if (!el) {
339
- console.warn("setToolDisabled: element not found:", elementId);
340
- return;
341
- }
342
- cornerstoneTools.setToolEnabledForElement(el, toolName);
343
- if (resetCursor && el && el.style) {
344
- // restore native cursor
345
- el.style.cursor = "initial";
346
- tryUpdateImage(el);
347
- }
348
- });
349
- } else {
350
- // enable and update all
351
- cornerstoneTools.setToolEnabled(toolName);
352
- let enabledElements = cornerstone.getEnabledElements();
353
- each(enabledElements, enel => {
354
- if (resetCursor) {
355
- // restore native cursor
356
- enel.element.style.cursor = "initial";
357
- tryUpdateImage(enel.element);
358
- }
359
- });
360
- }
361
- };
362
-
363
- /**
364
- * Set Tool "enabled" on all elements (ie, rendered and manipulable passively) & refresh cornerstone elements
365
- * @function setToolPassive
366
- * @param {String} toolName - The tool name.
367
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
368
- */
369
- const setToolPassive = function (toolName: string, viewports?: string[]) {
370
- if (viewports && viewports.length > 0) {
371
- // activate and update only for "viewports"
372
- each(viewports, function (elementId) {
373
- let el = document.getElementById(elementId);
374
- if (!el) {
375
- console.warn("setToolDisabled: element not found:", elementId);
376
- return;
377
- }
378
- cornerstoneTools.setToolPassiveForElement(el, toolName);
379
- tryUpdateImage(el);
380
- });
381
- } else {
382
- // activate and update all
383
- cornerstoneTools.setToolPassive(toolName);
384
- let enabledElements = cornerstone.getEnabledElements();
385
- each(enabledElements, enel => {
386
- tryUpdateImage(enel.element);
387
- });
388
- }
389
- };
390
-
391
- /** @inner Internal module functions */
392
-
393
- /**
394
- * Set cornerstone tools custom configuration (extend default configuration)
395
- * @function setToolsStyle
396
- * @param {Object} style - the style object (see tools/defaults.js)
397
- */
398
- const setToolsStyle = function (style?: ToolStyle) {
399
- extend(DEFAULT_STYLE, style);
400
-
401
- let fontFamily = DEFAULT_STYLE.fontFamily;
402
- let fontSize = DEFAULT_STYLE.fontSize;
403
-
404
- cornerstoneTools.toolStyle.setToolWidth(DEFAULT_STYLE.width);
405
- cornerstoneTools.toolColors.setToolColor(DEFAULT_STYLE.color);
406
- cornerstoneTools.toolColors.setActiveColor(DEFAULT_STYLE.activeColor);
407
- cornerstoneTools.toolColors.setFillColor(DEFAULT_STYLE.fillColor); // used only by FreehandRoiTool inside handles
408
- cornerstoneTools.textStyle.setFont(`${fontSize}px ${fontFamily}`);
409
- cornerstoneTools.textStyle.setBackgroundColor(DEFAULT_STYLE.backgroundColor);
410
- };
411
-
412
- export {
413
- initializeCSTools,
414
- setToolsStyle,
415
- csToolsCreateStack,
416
- addTool,
417
- setToolActive,
418
- setToolEnabled,
419
- setToolDisabled,
420
- setToolPassive,
421
- saveAnnotations,
422
- loadAnnotations,
423
- exportAnnotations
424
- };