larvitar 2.0.5 → 2.0.7

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 (77) hide show
  1. package/README.md +2 -2
  2. package/dist/imaging/imageRendering.d.ts +1 -71
  3. package/dist/imaging/imageStore.d.ts +5 -0
  4. package/dist/imaging/loaders/commonLoader.d.ts +4 -4
  5. package/dist/imaging/loaders/nrrdLoader.d.ts +1 -51
  6. package/dist/larvitar.js +13 -1
  7. package/dist/larvitar.js.map +1 -1
  8. package/imaging/tools/types.d.ts +19 -19
  9. package/imaging/types.d.ts +110 -2
  10. package/package.json +7 -2
  11. package/.github/workflows/build-docs.yml +0 -59
  12. package/.github/workflows/codeql-analysis.yml +0 -71
  13. package/.github/workflows/deploy.yml +0 -37
  14. package/.vscode/settings.json +0 -4
  15. package/CODE_OF_CONDUCT.md +0 -76
  16. package/MIGRATION.md +0 -25
  17. package/bundler/webpack.common.js +0 -27
  18. package/bundler/webpack.dev.js +0 -23
  19. package/bundler/webpack.prod.js +0 -19
  20. package/decs.d.ts +0 -12
  21. package/dist/imaging/MetaDataReadable.d.ts +0 -41
  22. package/dist/imaging/MetaDataTypes.d.ts +0 -3489
  23. package/imaging/dataDictionary.json +0 -21866
  24. package/imaging/imageAnonymization.ts +0 -135
  25. package/imaging/imageColormaps.ts +0 -217
  26. package/imaging/imageContours.ts +0 -196
  27. package/imaging/imageIo.ts +0 -251
  28. package/imaging/imageLayers.ts +0 -121
  29. package/imaging/imageLoading.ts +0 -299
  30. package/imaging/imageParsing.ts +0 -444
  31. package/imaging/imagePresets.ts +0 -156
  32. package/imaging/imageRendering.ts +0 -1091
  33. package/imaging/imageReslice.ts +0 -87
  34. package/imaging/imageStore.ts +0 -487
  35. package/imaging/imageTags.ts +0 -609
  36. package/imaging/imageTools.js +0 -708
  37. package/imaging/imageUtils.ts +0 -1079
  38. package/imaging/loaders/commonLoader.ts +0 -275
  39. package/imaging/loaders/dicomLoader.ts +0 -66
  40. package/imaging/loaders/fileLoader.ts +0 -71
  41. package/imaging/loaders/multiframeLoader.ts +0 -435
  42. package/imaging/loaders/nrrdLoader.ts +0 -630
  43. package/imaging/loaders/resliceLoader.ts +0 -205
  44. package/imaging/monitors/memory.ts +0 -151
  45. package/imaging/monitors/performance.ts +0 -34
  46. package/imaging/parsers/ecg.ts +0 -54
  47. package/imaging/parsers/nrrd.js +0 -485
  48. package/imaging/tools/custom/4dSliceScrollTool.js +0 -146
  49. package/imaging/tools/custom/BorderMagnifyTool.js +0 -99
  50. package/imaging/tools/custom/contourTool.js +0 -1884
  51. package/imaging/tools/custom/diameterTool.js +0 -141
  52. package/imaging/tools/custom/editMaskTool.js +0 -141
  53. package/imaging/tools/custom/ellipticalRoiOverlayTool.js +0 -534
  54. package/imaging/tools/custom/polygonSegmentationMixin.js +0 -245
  55. package/imaging/tools/custom/polylineScissorsTool.js +0 -59
  56. package/imaging/tools/custom/rectangleRoiOverlayTool.js +0 -564
  57. package/imaging/tools/custom/seedTool.js +0 -342
  58. package/imaging/tools/custom/setLabelMap3D.ts +0 -242
  59. package/imaging/tools/custom/thresholdsBrushTool.js +0 -161
  60. package/imaging/tools/default.ts +0 -594
  61. package/imaging/tools/interaction.ts +0 -266
  62. package/imaging/tools/io.ts +0 -229
  63. package/imaging/tools/main.ts +0 -427
  64. package/imaging/tools/segmentation.ts +0 -532
  65. package/imaging/tools/segmentations.md +0 -38
  66. package/imaging/tools/state.ts +0 -74
  67. package/imaging/tools/strategies/eraseFreehand.js +0 -76
  68. package/imaging/tools/strategies/fillFreehand.js +0 -79
  69. package/imaging/tools/strategies/index.js +0 -2
  70. package/imaging/waveforms/ecg.ts +0 -191
  71. package/index.ts +0 -431
  72. package/jsdoc.json +0 -52
  73. package/rollup.config.js +0 -51
  74. package/template/.gitkeep +0 -0
  75. package/tsconfig.json +0 -102
  76. /package/imaging/{MetaDataReadable.ts → MetaDataReadable.d.ts} +0 -0
  77. /package/imaging/{MetaDataTypes.ts → MetaDataTypes.d.ts} +0 -0
@@ -1,427 +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: ToolConfig | {} = DEFAULT_TOOLS[toolName]
142
- ? DEFAULT_TOOLS[toolName]
143
- : {};
144
- extend(defaultConfig, customConfig);
145
-
146
- if (isToolMissing(toolName)) {
147
- const toolClassName: string | undefined =
148
- "class" in defaultConfig ? defaultConfig.class : undefined;
149
-
150
- if (!toolClassName) {
151
- throw new Error(
152
- `Tool ${toolName} class not found. Please check tools/default or pass a valid tool class name in the configuration object.`
153
- );
154
- }
155
-
156
- const toolClass = cornerstoneTools[toolClassName] || dvTools[toolClassName];
157
-
158
- if (targetElementId) {
159
- let element = document.getElementById(targetElementId);
160
- cornerstoneTools.addToolForElement(element, toolClass, defaultConfig);
161
- } else {
162
- cornerstoneTools.addTool(toolClass, defaultConfig);
163
- }
164
- }
165
- };
166
-
167
- /**
168
- * Add all default tools, as listed in tools/default.js
169
- * @function addDefaultTools
170
- */
171
- export const addDefaultTools = function (elementId: string) {
172
- let elements = cornerstone.getEnabledElements();
173
-
174
- if (elements.length == 0) {
175
- let element = document.getElementById(elementId);
176
- if (!element) {
177
- throw new Error(
178
- `Element with id ${elementId} not found. Cannot add default tools.`
179
- );
180
- }
181
- cornerstone.enable(element);
182
- }
183
-
184
- // for each default tool
185
- each(DEFAULT_TOOLS, tool => {
186
- // check if already added
187
- if (!isToolMissing(tool.name)) {
188
- return;
189
- }
190
- // check target viewports and call add tool with options
191
- if (tool.viewports == "all") {
192
- addTool(tool.name, tool.configuration);
193
- } else {
194
- // call add tool for element for each element
195
- each(tool.viewports, targetElementId => {
196
- addTool(tool.name, tool.configuration, targetElementId);
197
- });
198
- }
199
-
200
- // if sync tool, enable
201
- if (tool.sync) {
202
- const synchronizer = new cornerstoneTools.Synchronizer(
203
- "cornerstoneimagerendered",
204
- cornerstoneTools[tool.sync]
205
- );
206
- elements.forEach(element => {
207
- synchronizer.add(element.element);
208
- });
209
-
210
- synchronizer.enabled = true;
211
- }
212
-
213
- if (tool.defaultActive) {
214
- setToolActive(tool.name, tool.options, [], true);
215
- }
216
- });
217
- };
218
-
219
- /**
220
- * Try to update image, catching errors if image is not loaded yet
221
- * @param {HTMLObject} element
222
- */
223
- function tryUpdateImage(element: HTMLElement) {
224
- try {
225
- cornerstone.updateImage(element);
226
- } catch (err) {
227
- // console.warn("updateImage: image has not been loaded yet:", element.id);
228
- }
229
- }
230
-
231
- /**
232
- * Set Tool "active" on all elements (ie, rendered and manipulable) & refresh cornerstone elements
233
- * @function setToolActive
234
- * @param {String} toolName - The tool name.
235
- * @param {Object} options - The custom options. @default from tools/default.js
236
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
237
- * @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.
238
- */
239
- const setToolActive = function (
240
- toolName: string,
241
- options?: Partial<ToolConfig["options"]>,
242
- viewports?: string[],
243
- doNotSetInStore?: boolean
244
- ) {
245
- let defaultOpt = { ...DEFAULT_TOOLS[toolName]?.options }; // deep copy obj because otherwise cornerstone tools will modify it
246
-
247
- extend(defaultOpt, options);
248
-
249
- if (viewports && viewports.length > 0) {
250
- // activate and update only for "viewports"
251
- each(viewports, function (elementId) {
252
- let el = document.getElementById(elementId);
253
- cornerstoneTools.setToolActiveForElement(el, toolName, defaultOpt);
254
- if (el) {
255
- tryUpdateImage(el);
256
- }
257
- });
258
- } else {
259
- // activate and update all
260
- cornerstoneTools.setToolActive(toolName, defaultOpt);
261
- let enabledElements = cornerstone.getEnabledElements();
262
- each(enabledElements, enel => {
263
- tryUpdateImage(enel.element);
264
- });
265
- }
266
-
267
- // set active tool in larvitar store
268
- // mouseButtonMask is now an array, thanks to cs tools "setToolActiveForElement",
269
- // but only if it has a rendered image in the viewport (!)
270
- // so we must check the type anyway for type coherence
271
- if (!doNotSetInStore && defaultOpt.mouseButtonMask) {
272
- if (typeof defaultOpt.mouseButtonMask == "number") {
273
- defaultOpt.mouseButtonMask = [defaultOpt.mouseButtonMask];
274
- }
275
- if (defaultOpt.mouseButtonMask.includes(1)) {
276
- setStore(["leftActiveTool", toolName]);
277
- }
278
- if (defaultOpt.mouseButtonMask.includes(2)) {
279
- setStore(["rightActiveTool", toolName]);
280
- }
281
- }
282
- };
283
-
284
- /**
285
- * Set Tool "disabled" on all elements (ie, not rendered) & refresh cornerstone elements
286
- * @function setToolDisabled
287
- * @param {String} toolName - The tool name.
288
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
289
- * @param {Boolean} resetCursor - Flag to restore native cursor. @default true
290
- */
291
- const setToolDisabled = function (
292
- toolName: string,
293
- viewports?: string[],
294
- resetCursor = true
295
- ) {
296
- if (viewports && viewports.length > 0) {
297
- // disable and update only for "viewports"
298
- each(viewports, function (elementId) {
299
- let el = document.getElementById(elementId);
300
- if (!el) {
301
- console.warn("setToolDisabled: element not found:", elementId);
302
- return;
303
- }
304
- cornerstoneTools.setToolDisabledForElement(el, toolName);
305
- if (resetCursor && el && el.style) {
306
- // restore native cursor
307
- el.style.cursor = "initial";
308
- tryUpdateImage(el);
309
- }
310
- });
311
- } else {
312
- // disable and update all
313
- cornerstoneTools.setToolDisabled(toolName);
314
- let enabledElements = cornerstone.getEnabledElements();
315
- each(enabledElements, enel => {
316
- if (resetCursor) {
317
- // restore native cursor
318
- enel.element.style.cursor = "initial";
319
- tryUpdateImage(enel.element);
320
- }
321
- });
322
- }
323
- };
324
-
325
- /**
326
- * Set Tool "enabled" on all elements (ie, rendered but not manipulable) & refresh cornerstone elements
327
- * @function setToolEnabled
328
- * @param {String} toolName - The tool name.
329
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
330
- * @param {Boolean} resetCursor - Flag to restore native cursor. @default true
331
- */
332
- const setToolEnabled = function (
333
- toolName: string,
334
- viewports?: string[],
335
- resetCursor = true
336
- ) {
337
- if (viewports && viewports.length > 0) {
338
- // enable and update only for "viewports"
339
- each(viewports, function (elementId) {
340
- let el = document.getElementById(elementId);
341
- if (!el) {
342
- console.warn("setToolDisabled: element not found:", elementId);
343
- return;
344
- }
345
- cornerstoneTools.setToolEnabledForElement(el, toolName);
346
- if (resetCursor && el && el.style) {
347
- // restore native cursor
348
- el.style.cursor = "initial";
349
- tryUpdateImage(el);
350
- }
351
- });
352
- } else {
353
- // enable and update all
354
- cornerstoneTools.setToolEnabled(toolName);
355
- let enabledElements = cornerstone.getEnabledElements();
356
- each(enabledElements, enel => {
357
- if (resetCursor) {
358
- // restore native cursor
359
- enel.element.style.cursor = "initial";
360
- tryUpdateImage(enel.element);
361
- }
362
- });
363
- }
364
- };
365
-
366
- /**
367
- * Set Tool "enabled" on all elements (ie, rendered and manipulable passively) & refresh cornerstone elements
368
- * @function setToolPassive
369
- * @param {String} toolName - The tool name.
370
- * @param {Array} viewports - The hmtl element id to be used for tool initialization.
371
- */
372
- const setToolPassive = function (toolName: string, viewports?: string[]) {
373
- if (viewports && viewports.length > 0) {
374
- // activate and update only for "viewports"
375
- each(viewports, function (elementId) {
376
- let el = document.getElementById(elementId);
377
- if (!el) {
378
- console.warn("setToolDisabled: element not found:", elementId);
379
- return;
380
- }
381
- cornerstoneTools.setToolPassiveForElement(el, toolName);
382
- tryUpdateImage(el);
383
- });
384
- } else {
385
- // activate and update all
386
- cornerstoneTools.setToolPassive(toolName);
387
- let enabledElements = cornerstone.getEnabledElements();
388
- each(enabledElements, enel => {
389
- tryUpdateImage(enel.element);
390
- });
391
- }
392
- };
393
-
394
- /** @inner Internal module functions */
395
-
396
- /**
397
- * Set cornerstone tools custom configuration (extend default configuration)
398
- * @function setToolsStyle
399
- * @param {Object} style - the style object (see tools/defaults.js)
400
- */
401
- const setToolsStyle = function (style?: ToolStyle) {
402
- extend(DEFAULT_STYLE, style);
403
-
404
- let fontFamily = DEFAULT_STYLE.fontFamily;
405
- let fontSize = DEFAULT_STYLE.fontSize;
406
-
407
- cornerstoneTools.toolStyle.setToolWidth(DEFAULT_STYLE.width);
408
- cornerstoneTools.toolColors.setToolColor(DEFAULT_STYLE.color);
409
- cornerstoneTools.toolColors.setActiveColor(DEFAULT_STYLE.activeColor);
410
- cornerstoneTools.toolColors.setFillColor(DEFAULT_STYLE.fillColor); // used only by FreehandRoiTool inside handles
411
- cornerstoneTools.textStyle.setFont(`${fontSize}px ${fontFamily}`);
412
- cornerstoneTools.textStyle.setBackgroundColor(DEFAULT_STYLE.backgroundColor);
413
- };
414
-
415
- export {
416
- initializeCSTools,
417
- setToolsStyle,
418
- csToolsCreateStack,
419
- addTool,
420
- setToolActive,
421
- setToolEnabled,
422
- setToolDisabled,
423
- setToolPassive,
424
- saveAnnotations,
425
- loadAnnotations,
426
- exportAnnotations
427
- };