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.
- package/README.md +2 -2
- package/dist/imaging/imageRendering.d.ts +1 -71
- package/dist/imaging/imageStore.d.ts +5 -0
- package/dist/imaging/loaders/commonLoader.d.ts +4 -4
- package/dist/imaging/loaders/nrrdLoader.d.ts +1 -51
- package/dist/larvitar.js +13 -1
- package/dist/larvitar.js.map +1 -1
- package/imaging/tools/types.d.ts +19 -19
- package/imaging/types.d.ts +110 -2
- package/package.json +7 -2
- package/.github/workflows/build-docs.yml +0 -59
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.github/workflows/deploy.yml +0 -37
- package/.vscode/settings.json +0 -4
- package/CODE_OF_CONDUCT.md +0 -76
- package/MIGRATION.md +0 -25
- package/bundler/webpack.common.js +0 -27
- package/bundler/webpack.dev.js +0 -23
- package/bundler/webpack.prod.js +0 -19
- package/decs.d.ts +0 -12
- package/dist/imaging/MetaDataReadable.d.ts +0 -41
- package/dist/imaging/MetaDataTypes.d.ts +0 -3489
- package/imaging/dataDictionary.json +0 -21866
- package/imaging/imageAnonymization.ts +0 -135
- package/imaging/imageColormaps.ts +0 -217
- package/imaging/imageContours.ts +0 -196
- package/imaging/imageIo.ts +0 -251
- package/imaging/imageLayers.ts +0 -121
- package/imaging/imageLoading.ts +0 -299
- package/imaging/imageParsing.ts +0 -444
- package/imaging/imagePresets.ts +0 -156
- package/imaging/imageRendering.ts +0 -1091
- package/imaging/imageReslice.ts +0 -87
- package/imaging/imageStore.ts +0 -487
- package/imaging/imageTags.ts +0 -609
- package/imaging/imageTools.js +0 -708
- package/imaging/imageUtils.ts +0 -1079
- package/imaging/loaders/commonLoader.ts +0 -275
- package/imaging/loaders/dicomLoader.ts +0 -66
- package/imaging/loaders/fileLoader.ts +0 -71
- package/imaging/loaders/multiframeLoader.ts +0 -435
- package/imaging/loaders/nrrdLoader.ts +0 -630
- package/imaging/loaders/resliceLoader.ts +0 -205
- package/imaging/monitors/memory.ts +0 -151
- package/imaging/monitors/performance.ts +0 -34
- package/imaging/parsers/ecg.ts +0 -54
- package/imaging/parsers/nrrd.js +0 -485
- package/imaging/tools/custom/4dSliceScrollTool.js +0 -146
- package/imaging/tools/custom/BorderMagnifyTool.js +0 -99
- package/imaging/tools/custom/contourTool.js +0 -1884
- package/imaging/tools/custom/diameterTool.js +0 -141
- package/imaging/tools/custom/editMaskTool.js +0 -141
- package/imaging/tools/custom/ellipticalRoiOverlayTool.js +0 -534
- package/imaging/tools/custom/polygonSegmentationMixin.js +0 -245
- package/imaging/tools/custom/polylineScissorsTool.js +0 -59
- package/imaging/tools/custom/rectangleRoiOverlayTool.js +0 -564
- package/imaging/tools/custom/seedTool.js +0 -342
- package/imaging/tools/custom/setLabelMap3D.ts +0 -242
- package/imaging/tools/custom/thresholdsBrushTool.js +0 -161
- package/imaging/tools/default.ts +0 -594
- package/imaging/tools/interaction.ts +0 -266
- package/imaging/tools/io.ts +0 -229
- package/imaging/tools/main.ts +0 -427
- package/imaging/tools/segmentation.ts +0 -532
- package/imaging/tools/segmentations.md +0 -38
- package/imaging/tools/state.ts +0 -74
- package/imaging/tools/strategies/eraseFreehand.js +0 -76
- package/imaging/tools/strategies/fillFreehand.js +0 -79
- package/imaging/tools/strategies/index.js +0 -2
- package/imaging/waveforms/ecg.ts +0 -191
- package/index.ts +0 -431
- package/jsdoc.json +0 -52
- package/rollup.config.js +0 -51
- package/template/.gitkeep +0 -0
- package/tsconfig.json +0 -102
- /package/imaging/{MetaDataReadable.ts → MetaDataReadable.d.ts} +0 -0
- /package/imaging/{MetaDataTypes.ts → MetaDataTypes.d.ts} +0 -0
package/imaging/imageTools.js
DELETED
|
@@ -1,708 +0,0 @@
|
|
|
1
|
-
/** @module imaging/imageTools
|
|
2
|
-
* @desc This file provides functionalities for
|
|
3
|
-
* interacting with cornerstone tools
|
|
4
|
-
* DEPRECATION WARNING: these are legacy functions
|
|
5
|
-
* that will be removed soon. Use the corresponding
|
|
6
|
-
* functions in /tools/main.js instead.
|
|
7
|
-
* For this reason, this file will not be translated to TypeScript.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// external libraries
|
|
11
|
-
import cornerstone from "cornerstone-core";
|
|
12
|
-
import cornerstoneTools from "cornerstone-tools";
|
|
13
|
-
import { each, extend, filter, remove, cloneDeep } from "lodash";
|
|
14
|
-
|
|
15
|
-
// internal libraries
|
|
16
|
-
import { DEFAULT_TOOLS } from "./tools/default";
|
|
17
|
-
// import { SeedsTool } from "./tools/custom/seedTool";
|
|
18
|
-
import { ContoursTool } from "./tools/custom/contourTool";
|
|
19
|
-
import { EditMaskTool } from "./tools/custom/editMaskTool";
|
|
20
|
-
import { DiameterTool } from "./tools/custom/diameterTool";
|
|
21
|
-
import { getImageIdFromSlice } from "./loaders/nrrdLoader";
|
|
22
|
-
import { getSeriesDataFromLarvitarManager } from "./loaders/commonLoader";
|
|
23
|
-
import { parseContours } from "./imageContours";
|
|
24
|
-
import { isElement } from "./imageUtils";
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
* This module provides the following functions to be exported:
|
|
28
|
-
* csToolsCreateStack(element)
|
|
29
|
-
* addDefaultTools(toolToActivate)
|
|
30
|
-
* clearMeasurements()
|
|
31
|
-
* addContoursTool(rawContours, maskName)
|
|
32
|
-
* addMaskEditingTool(seriesId,mask,setConfig,callback, targetViewport)
|
|
33
|
-
* getCurrentMaskData(viewportId)
|
|
34
|
-
* addStackStateToElement(seriesId, element)
|
|
35
|
-
* addSeedsTool(preLoadSeeds, initViewport)
|
|
36
|
-
* addDiameterTool(targetElementId, diameters, seriesId)
|
|
37
|
-
* setToolActive(toolName, options, activeViewport, viewports)
|
|
38
|
-
* setToolDisabled(toolName, options, activeViewport, viewports)
|
|
39
|
-
* setToolEnabled(toolName, options, activeViewport, viewports)
|
|
40
|
-
* setToolPassive(toolName, options, activeViewport, viewports)
|
|
41
|
-
* getToolState(toolName)
|
|
42
|
-
* updateDiameterTool(diameterId, value, seriesId)
|
|
43
|
-
* addToolStateSingleSlice(element, toolType, data, slice, seriesId)
|
|
44
|
-
* clearToolStateByName(toolName, options)
|
|
45
|
-
* clearCornerstoneElements()
|
|
46
|
-
* syncToolStack(srcSliceNumber, toolName, viewport, seriesId)
|
|
47
|
-
* updateStackToolState(element, imageIndex)
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Add all default tools, as listed in tools/default.js
|
|
52
|
-
* @function addDefaultTools
|
|
53
|
-
* @deprecated (OBSOLETE)
|
|
54
|
-
*/
|
|
55
|
-
export const addDefaultTools = function (toolToActivate) {
|
|
56
|
-
// for each default tool
|
|
57
|
-
each(DEFAULT_TOOLS, tool => {
|
|
58
|
-
// check if already added
|
|
59
|
-
if (!isToolMissing(tool.name)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let configuration = tool.configuration;
|
|
64
|
-
let toolClass = cornerstoneTools[tool.class];
|
|
65
|
-
|
|
66
|
-
// check target viewports and call add tool with options
|
|
67
|
-
if (tool.viewports == "all") {
|
|
68
|
-
cornerstoneTools.addTool(toolClass, { configuration });
|
|
69
|
-
} else {
|
|
70
|
-
// call add tool for element for each element
|
|
71
|
-
each(tool.viewports, targetElement => {
|
|
72
|
-
cornerstoneTools.addToolForElement(
|
|
73
|
-
targetElement,
|
|
74
|
-
toolClass,
|
|
75
|
-
configuration
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let elements = cornerstone.getEnabledElements();
|
|
81
|
-
|
|
82
|
-
// if sync tool, enable
|
|
83
|
-
if (tool.sync) {
|
|
84
|
-
const synchronizer = new cornerstoneTools.Synchronizer(
|
|
85
|
-
"cornerstoneimagerendered",
|
|
86
|
-
cornerstoneTools[tool.sync]
|
|
87
|
-
);
|
|
88
|
-
elements.forEach(element => {
|
|
89
|
-
synchronizer.add(element.element);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
synchronizer.enabled = true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (tool.defaultActive || tool.name == toolToActivate) {
|
|
96
|
-
setToolActive(tool.name, tool.options);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// set wheel scroll active
|
|
101
|
-
setToolActive("StackScrollMouseWheel", {
|
|
102
|
-
loop: false, // default false
|
|
103
|
-
allowSkipping: false, // default true
|
|
104
|
-
invert: false
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Add Diameter tool
|
|
110
|
-
* @function addDiameterTool
|
|
111
|
-
* @param {String} elementId - The target hmtl element id or its DOM HTMLElement
|
|
112
|
-
* @param {Array} diameters - The array of diameter objects.
|
|
113
|
-
* @param {String} seriesId - The id of the target serie.
|
|
114
|
-
*/
|
|
115
|
-
export const addDiameterTool = function (elementId, diameters, seriesId) {
|
|
116
|
-
if (isToolMissing("Diameter")) {
|
|
117
|
-
let element = isElement(elementId)
|
|
118
|
-
? elementId
|
|
119
|
-
: document.getElementById(elementId);
|
|
120
|
-
cornerstoneTools.addToolForElement(element, DiameterTool, {
|
|
121
|
-
dataArray: diameters,
|
|
122
|
-
seriesId: seriesId
|
|
123
|
-
});
|
|
124
|
-
setToolPassive("Diameter");
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Add Contour tool
|
|
130
|
-
* @function addContoursTool
|
|
131
|
-
* @param {Object} rawContours - The contours object (generated from a segmentation mask).
|
|
132
|
-
* @param {String} maskName - The name tag that identify the mask
|
|
133
|
-
*/
|
|
134
|
-
export const addContoursTool = function (rawContours, maskName) {
|
|
135
|
-
var pointBatchSize = 2;
|
|
136
|
-
console.time("...parsing contours");
|
|
137
|
-
var contoursParsedData = parseContours(rawContours, pointBatchSize, maskName);
|
|
138
|
-
console.timeEnd("...parsing contours");
|
|
139
|
-
cornerstoneTools.addTool(ContoursTool, {
|
|
140
|
-
contoursParsedData,
|
|
141
|
-
maskName
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Add mask editing tool
|
|
147
|
-
* @function addMaskEditingTool
|
|
148
|
-
* @param {Array} mask - The mask data.
|
|
149
|
-
* @param {Function} callback - The tool initialization callback
|
|
150
|
-
* @param {String} targetViewport - The target hmtl element id.
|
|
151
|
-
*/
|
|
152
|
-
export const addMaskEditingTool = function (mask, callback, targetViewport) {
|
|
153
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
154
|
-
|
|
155
|
-
each(enabledElements, el => {
|
|
156
|
-
if (el.element.id == targetViewport) {
|
|
157
|
-
cornerstoneTools.addToolForElement(el.element, EditMaskTool, {
|
|
158
|
-
mask: mask,
|
|
159
|
-
initCallback: callback,
|
|
160
|
-
configuration: { alwaysEraseOnClick: false }
|
|
161
|
-
});
|
|
162
|
-
cornerstoneTools.setToolEnabledForElement(el.element, "EditMask", {
|
|
163
|
-
mouseButtonMask: 1
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
let defaultConfig = {
|
|
169
|
-
radius: 5,
|
|
170
|
-
fillAlpha: 0.5
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
setSegmentationConfig(defaultConfig);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Modify configuration for cornerstone tools segmentation module
|
|
178
|
-
* @function setSegmentationConfig
|
|
179
|
-
* @param {Object} config - The custom configuration.
|
|
180
|
-
* @example
|
|
181
|
-
* Example of custom configuration
|
|
182
|
-
* config = {
|
|
183
|
-
renderOutline: true,
|
|
184
|
-
renderFill: true,
|
|
185
|
-
shouldRenderInactiveLabelmaps: true,
|
|
186
|
-
radius: 10,
|
|
187
|
-
minRadius: 1,
|
|
188
|
-
maxRadius: 50,
|
|
189
|
-
segmentsPerLabelmap: 65535,
|
|
190
|
-
fillAlpha: 0.7,
|
|
191
|
-
fillAlphaInactive: 0.1,
|
|
192
|
-
outlineAlpha: 0.7,
|
|
193
|
-
outlineAlphaInactive: 0.35,
|
|
194
|
-
outlineWidth: 3,
|
|
195
|
-
storeHistory: true
|
|
196
|
-
};
|
|
197
|
-
*/
|
|
198
|
-
export const setSegmentationConfig = function (config) {
|
|
199
|
-
let { configuration } = cornerstoneTools.getModule("segmentation");
|
|
200
|
-
extend(configuration, config);
|
|
201
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
202
|
-
each(enabledElements, el => {
|
|
203
|
-
cornerstone.updateImage(el.element);
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Get mask editing tool current data from state
|
|
209
|
-
* @function getCurrentMaskData
|
|
210
|
-
* @param {String} viewportId - The target hmtl element id.
|
|
211
|
-
* @return {Array} labelmap3D - The mask array
|
|
212
|
-
*/
|
|
213
|
-
export const getCurrentMaskData = function (viewportId) {
|
|
214
|
-
const { getters } = cornerstoneTools.getModule("segmentation");
|
|
215
|
-
let enabledElement = cornerstone
|
|
216
|
-
.getEnabledElements()
|
|
217
|
-
.filter(e => e.element.id == viewportId)
|
|
218
|
-
.pop();
|
|
219
|
-
|
|
220
|
-
const { labelmap3D } = getters.labelmap2D(enabledElement.element);
|
|
221
|
-
return labelmap3D;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Add Stack State to a single hmtl element
|
|
226
|
-
* @function addStackStateToElement
|
|
227
|
-
* @param {String} seriesId - The id of the target serie.
|
|
228
|
-
* @param {HTMLElement} element - The target hmtl element.
|
|
229
|
-
*/
|
|
230
|
-
export const addStackStateToElement = function (seriesId, element) {
|
|
231
|
-
// Define the Stack object
|
|
232
|
-
const stack = getSeriesDataFromLarvitarManager(seriesId)[element.id];
|
|
233
|
-
// Add the stack tool state to the enabled element
|
|
234
|
-
cornerstoneTools.addStackStateManager(element, ["stack"]);
|
|
235
|
-
cornerstoneTools.addToolState(element, "stack", stack);
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Add seeds tool
|
|
240
|
-
* @function addSeedsTool
|
|
241
|
-
* @param {Array} preLoadSeeds - The array of seeds to load as initialization.
|
|
242
|
-
* @param {String} initViewport - The hmtl element id to be used for tool initialization.
|
|
243
|
-
*/
|
|
244
|
-
export const addSeedsTool = function (preLoadSeeds, initViewport) {
|
|
245
|
-
if (isToolMissing("Seeds")) {
|
|
246
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
247
|
-
each(enabledElements, el => {
|
|
248
|
-
let initialize = el.element.id == initViewport;
|
|
249
|
-
cornerstoneTools.addToolForElement(el.element, SeedsTool, {
|
|
250
|
-
preLoadSeeds,
|
|
251
|
-
initialize,
|
|
252
|
-
initViewport
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
setToolEnabled("Seeds");
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Delete all measurements from tools state, for tools that have the "cleaneable" prop set to true in tools/default.js
|
|
261
|
-
* @function clearMeasurements
|
|
262
|
-
*/
|
|
263
|
-
export const clearMeasurements = function () {
|
|
264
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
265
|
-
let clenableTools = filter(DEFAULT_TOOLS, "cleanable");
|
|
266
|
-
|
|
267
|
-
each(enabledElements, el => {
|
|
268
|
-
each(clenableTools, function (tool) {
|
|
269
|
-
cornerstoneTools.clearToolState(el.element, tool.name);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
each(enabledElements, el => {
|
|
273
|
-
cornerstone.updateImage(el.element);
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Set Tool "active" on all elements (ie, rendered and manipulable) & refresh cornerstone elements
|
|
279
|
-
* @function setToolActive
|
|
280
|
-
* @param {String} toolName - The tool name.
|
|
281
|
-
* @param {Object} options - The custom options. @default from tools/default.js
|
|
282
|
-
* @param {String} activeViewport - The active viewport (if "all", viewports array will be used)
|
|
283
|
-
* @param {Array} viewports - The hmtl element id to be used for tool initialization.
|
|
284
|
-
* @deprecated (OBSOLETE)
|
|
285
|
-
*/
|
|
286
|
-
export const setToolActive = function (
|
|
287
|
-
toolName,
|
|
288
|
-
options,
|
|
289
|
-
activeViewport,
|
|
290
|
-
viewports
|
|
291
|
-
) {
|
|
292
|
-
let defaultOpt = DEFAULT_TOOLS[toolName]?.options || {};
|
|
293
|
-
extend(defaultOpt, options);
|
|
294
|
-
cornerstoneTools.setToolActive(toolName, defaultOpt);
|
|
295
|
-
if (activeViewport == "all") {
|
|
296
|
-
each(viewports, function (elementId) {
|
|
297
|
-
let el = document.getElementById(elementId);
|
|
298
|
-
if (el) {
|
|
299
|
-
cornerstone.updateImage(el);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
} else {
|
|
303
|
-
let el = document.getElementById(activeViewport);
|
|
304
|
-
if (el) {
|
|
305
|
-
cornerstone.updateImage(el);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Set Tool "disabled" on all elements (ie, not rendered) & refresh cornerstone elements
|
|
312
|
-
* @function setToolDisabled
|
|
313
|
-
* @param {String} toolName - The tool name.
|
|
314
|
-
* @param {String} activeViewport - The active viewport (if "all", viewports array will be used)
|
|
315
|
-
* @param {Array} viewports - The hmtl element id to be used for tool initialization.
|
|
316
|
-
* @deprecated (OBSOLETE)
|
|
317
|
-
*/
|
|
318
|
-
export const setToolDisabled = function (toolName, activeViewport, viewports) {
|
|
319
|
-
cornerstoneTools.setToolDisabled(toolName);
|
|
320
|
-
if (activeViewport == "all") {
|
|
321
|
-
each(viewports, function (elementId) {
|
|
322
|
-
let el = document.getElementById(elementId);
|
|
323
|
-
if (el) {
|
|
324
|
-
cornerstone.updateImage(el);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
} else {
|
|
328
|
-
let el = document.getElementById(activeViewport);
|
|
329
|
-
if (el) {
|
|
330
|
-
cornerstone.updateImage(el);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Set Tool "enabled" on all elements (ie, rendered but not manipulable) & refresh cornerstone elements
|
|
337
|
-
* @function setToolEnabled
|
|
338
|
-
* @param {String} toolName - The tool name.
|
|
339
|
-
* @param {String} activeViewport - The active viewport (if "all", viewports array will be used)
|
|
340
|
-
* @param {Array} viewports - The hmtl element id to be used for tool initialization.
|
|
341
|
-
* @deprecated (OBSOLETE)
|
|
342
|
-
*/
|
|
343
|
-
export const setToolEnabled = function (toolName, activeViewport, viewports) {
|
|
344
|
-
cornerstoneTools.setToolEnabled(toolName);
|
|
345
|
-
if (activeViewport == "all") {
|
|
346
|
-
each(viewports, function (elementId) {
|
|
347
|
-
let el = document.getElementById(elementId);
|
|
348
|
-
if (el) {
|
|
349
|
-
cornerstone.updateImage(el);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
} else {
|
|
353
|
-
let el = document.getElementById(activeViewport);
|
|
354
|
-
if (el) {
|
|
355
|
-
cornerstone.updateImage(el);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Set Tool "enabled" on all elements (ie, rendered and manipulable passively) & refresh cornerstone elements
|
|
362
|
-
* @function setToolPassive
|
|
363
|
-
* @param {String} toolName - The tool name.
|
|
364
|
-
* @param {String} activeViewport - The active viewport (if "all", viewports array will be used)
|
|
365
|
-
* @param {Array} viewports - The hmtl element id to be used for tool initialization.
|
|
366
|
-
* @deprecated (OBSOLETE)
|
|
367
|
-
*/
|
|
368
|
-
export const setToolPassive = function (toolName, activeViewport, viewports) {
|
|
369
|
-
cornerstoneTools.setToolPassive(toolName);
|
|
370
|
-
if (activeViewport == "all") {
|
|
371
|
-
each(viewports, function (elementId) {
|
|
372
|
-
let el = document.getElementById(elementId);
|
|
373
|
-
if (el) {
|
|
374
|
-
cornerstone.updateImage(el);
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
} else {
|
|
378
|
-
let el = document.getElementById(activeViewport);
|
|
379
|
-
if (el) {
|
|
380
|
-
cornerstone.updateImage(el);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Get tool data for all enabled elements
|
|
387
|
-
* @function getToolState
|
|
388
|
-
* @param {String} toolName - The tool name.
|
|
389
|
-
* @return {Object} - Tool data grouped by element id
|
|
390
|
-
*/
|
|
391
|
-
export const getToolState = function (toolName) {
|
|
392
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
393
|
-
let toolData = {};
|
|
394
|
-
each(enabledElements, el => {
|
|
395
|
-
toolData[el.element.id] = cornerstoneTools.getToolState(
|
|
396
|
-
el.element,
|
|
397
|
-
toolName
|
|
398
|
-
);
|
|
399
|
-
});
|
|
400
|
-
return toolData;
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Clear tool data for a subset of seeds
|
|
405
|
-
* @function clearToolStateByName
|
|
406
|
-
* @param {String} toolName - The tool name.
|
|
407
|
-
* @param {Object} options - Props used to select the data to delete (at the moment only {name : "targetName"} is implemented)
|
|
408
|
-
*/
|
|
409
|
-
export const clearToolStateByName = function (toolName, options) {
|
|
410
|
-
let enabledElements = cornerstone.getEnabledElements();
|
|
411
|
-
each(enabledElements, el => {
|
|
412
|
-
const toolStateManager = el.toolStateManager;
|
|
413
|
-
let imageIds = Object.keys(toolStateManager.toolState);
|
|
414
|
-
each(imageIds, imageId => {
|
|
415
|
-
let toolData = toolStateManager.toolState[imageId];
|
|
416
|
-
if (toolData[toolName]) {
|
|
417
|
-
remove(toolData[toolName].data, singleData => {
|
|
418
|
-
return singleData.name == options.name;
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
each(enabledElements, el => {
|
|
424
|
-
cornerstone.updateImage(el.element);
|
|
425
|
-
});
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Update diameter tool with new value (removing old one)
|
|
430
|
-
* @function updateDiameterTool
|
|
431
|
-
* @param {String | Number} diameterId - The id that identify the diameter data.
|
|
432
|
-
* @param {Object} value - The object representing the new diameter data.
|
|
433
|
-
* @param {String} seriesId - The target serie id.
|
|
434
|
-
* @param {String} viewportId - The viewport id.
|
|
435
|
-
*/
|
|
436
|
-
export const updateDiameterTool = function (
|
|
437
|
-
diameterId,
|
|
438
|
-
value,
|
|
439
|
-
seriesId,
|
|
440
|
-
viewportId
|
|
441
|
-
) {
|
|
442
|
-
// clear target diameter
|
|
443
|
-
if (!diameterId) {
|
|
444
|
-
console.warn("no diameterId, return");
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
clearToolStateByName("Diameter", {
|
|
449
|
-
name: diameterId
|
|
450
|
-
});
|
|
451
|
-
// insert new one
|
|
452
|
-
let data = {
|
|
453
|
-
toolType: "Diameter",
|
|
454
|
-
name: diameterId,
|
|
455
|
-
isCreating: true,
|
|
456
|
-
visible: true,
|
|
457
|
-
active: false,
|
|
458
|
-
invalidated: false,
|
|
459
|
-
handles: {
|
|
460
|
-
start: {
|
|
461
|
-
x: value.tool.x1,
|
|
462
|
-
y: value.tool.y1,
|
|
463
|
-
index: 0,
|
|
464
|
-
drawnIndependently: false,
|
|
465
|
-
allowedOutsideImage: false,
|
|
466
|
-
highlight: true,
|
|
467
|
-
active: false
|
|
468
|
-
},
|
|
469
|
-
end: {
|
|
470
|
-
x: value.tool.x2,
|
|
471
|
-
y: value.tool.y2,
|
|
472
|
-
index: 1,
|
|
473
|
-
drawnIndependently: false,
|
|
474
|
-
allowedOutsideImage: false,
|
|
475
|
-
highlight: true,
|
|
476
|
-
active: false
|
|
477
|
-
},
|
|
478
|
-
perpendicularStart: {
|
|
479
|
-
x: value.tool.x3,
|
|
480
|
-
y: value.tool.y3,
|
|
481
|
-
index: 2,
|
|
482
|
-
drawnIndependently: false,
|
|
483
|
-
allowedOutsideImage: false,
|
|
484
|
-
highlight: true,
|
|
485
|
-
active: false,
|
|
486
|
-
locked: false
|
|
487
|
-
},
|
|
488
|
-
perpendicularEnd: {
|
|
489
|
-
x: value.tool.x4,
|
|
490
|
-
y: value.tool.y4,
|
|
491
|
-
index: 3,
|
|
492
|
-
drawnIndependently: false,
|
|
493
|
-
allowedOutsideImage: false,
|
|
494
|
-
highlight: true,
|
|
495
|
-
active: false
|
|
496
|
-
},
|
|
497
|
-
textBox: {
|
|
498
|
-
x: value.tool.value_max,
|
|
499
|
-
y: value.tool.value_min,
|
|
500
|
-
index: null,
|
|
501
|
-
drawnIndependently: true,
|
|
502
|
-
allowedOutsideImage: true,
|
|
503
|
-
highlight: false,
|
|
504
|
-
active: false,
|
|
505
|
-
hasMoved: true,
|
|
506
|
-
movesIndependently: false,
|
|
507
|
-
hasBoundingBox: true,
|
|
508
|
-
boundingBox: {
|
|
509
|
-
width: 59.6484375,
|
|
510
|
-
height: 47,
|
|
511
|
-
left: 165.02487562189057,
|
|
512
|
-
top: 240.53482587064684
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
longestDiameter: value.tool.value_max.toString(),
|
|
517
|
-
shortestDiameter: value.tool.value_min.toString()
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
let sliceNumber = value.tool.slice;
|
|
521
|
-
let enabledElement = cornerstone
|
|
522
|
-
.getEnabledElements()
|
|
523
|
-
.filter(el => el.element.id == viewportId)
|
|
524
|
-
.pop();
|
|
525
|
-
|
|
526
|
-
// add to master viewport
|
|
527
|
-
addToolStateSingleSlice(
|
|
528
|
-
enabledElement.element,
|
|
529
|
-
"Diameter",
|
|
530
|
-
data,
|
|
531
|
-
sliceNumber,
|
|
532
|
-
seriesId
|
|
533
|
-
);
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Add tool data for a single target slice
|
|
538
|
-
* @function addToolStateSingleSlice
|
|
539
|
-
* @param {HTMLElement} element - The target hmtl element.
|
|
540
|
-
* @param {String} toolName - The tool name.
|
|
541
|
-
* @param {Object | Array} data - The tool data to add (tool-specific)
|
|
542
|
-
* @param {Number} slice - The target slice to put the data in.
|
|
543
|
-
* @param {String} seriesId - The target serie id.
|
|
544
|
-
*/
|
|
545
|
-
export const addToolStateSingleSlice = function (
|
|
546
|
-
element,
|
|
547
|
-
toolName,
|
|
548
|
-
data,
|
|
549
|
-
slice,
|
|
550
|
-
seriesId
|
|
551
|
-
) {
|
|
552
|
-
const enabledElement = cornerstone.getEnabledElement(element);
|
|
553
|
-
|
|
554
|
-
if (!enabledElement.image) {
|
|
555
|
-
console.warn("no image");
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
let targetImageId = getImageIdFromSlice(slice, element.id, seriesId);
|
|
560
|
-
|
|
561
|
-
if (enabledElement.toolStateManager === undefined) {
|
|
562
|
-
console.warn("State Manager undefined");
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
let toolState = enabledElement.toolStateManager.toolState;
|
|
566
|
-
|
|
567
|
-
if (toolState.hasOwnProperty(targetImageId) === false) {
|
|
568
|
-
toolState[targetImageId] = {};
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
const imageIdToolState = toolState[targetImageId];
|
|
572
|
-
|
|
573
|
-
// If we don't have tool state for this type of tool, add an empty object
|
|
574
|
-
if (imageIdToolState.hasOwnProperty(toolName) === false) {
|
|
575
|
-
imageIdToolState[toolName] = {
|
|
576
|
-
data: []
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
const toolData = imageIdToolState[toolName];
|
|
581
|
-
|
|
582
|
-
// if an array is provided, override data
|
|
583
|
-
// if (Array.isArray(data)) {
|
|
584
|
-
// toolData.data = data;
|
|
585
|
-
// } else {
|
|
586
|
-
// toolData.data.push(data);
|
|
587
|
-
// }
|
|
588
|
-
|
|
589
|
-
// This implementation works better
|
|
590
|
-
let singledata = typeof data.pop == "function" ? data.pop() : data;
|
|
591
|
-
// remove old data for this id (avoid doubling contours) // TODO generalize
|
|
592
|
-
if (toolName == "ContoursTool") {
|
|
593
|
-
remove(toolData.data, entry => entry && entry.id == singledata.id);
|
|
594
|
-
}
|
|
595
|
-
toolData.data.push(singledata);
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Clear tool state and disable all cornerstone elements
|
|
600
|
-
* @function clearCornerstoneElements
|
|
601
|
-
*/
|
|
602
|
-
export const clearCornerstoneElements = function () {
|
|
603
|
-
var enabledElements = cornerstone.getEnabledElements();
|
|
604
|
-
var inMemElements = cloneDeep(enabledElements); // copy before modifying
|
|
605
|
-
each(inMemElements, el => {
|
|
606
|
-
each(DEFAULT_TOOLS, function (tool) {
|
|
607
|
-
if (tool.cleanable) {
|
|
608
|
-
cornerstoneTools.clearToolState(el.element, tool.name);
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
cornerstone.disable(el.element);
|
|
612
|
-
});
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Sync the cornerstone tools stack given a slice as data source
|
|
617
|
-
* @function syncToolStack
|
|
618
|
-
* @param {Number} srcSliceNumber - The slice to be used as data source.
|
|
619
|
-
* @param {String} toolName - The name of the tool to sync.
|
|
620
|
-
* @param {String} viewport - The target viewport id.
|
|
621
|
-
* @param {String} seriesId - The target serie id.
|
|
622
|
-
*/
|
|
623
|
-
export const syncToolStack = function (
|
|
624
|
-
srcSliceNumber,
|
|
625
|
-
toolName,
|
|
626
|
-
viewport,
|
|
627
|
-
seriesId
|
|
628
|
-
) {
|
|
629
|
-
// get the imageIds array
|
|
630
|
-
let seriesData = getSeriesDataFromLarvitarManager(seriesId);
|
|
631
|
-
let imageIds = seriesData[viewport].imageIds;
|
|
632
|
-
|
|
633
|
-
// get the tool state of source imageId
|
|
634
|
-
let element = document.getElementById(viewport);
|
|
635
|
-
let enabledElement = cornerstone.getEnabledElement(element);
|
|
636
|
-
let srcImageId = getImageIdFromSlice(srcSliceNumber, viewport, seriesId);
|
|
637
|
-
let srcImageToolState =
|
|
638
|
-
enabledElement.toolStateManager.toolState[srcImageId][toolName];
|
|
639
|
-
|
|
640
|
-
each(Object.keys(imageIds), sliceNumber => {
|
|
641
|
-
if (sliceNumber == srcSliceNumber) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
each(srcImageToolState, data => {
|
|
645
|
-
addToolStateSingleSlice(element, toolName, data, sliceNumber, seriesId);
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Update slice index in cornerstone tools stack state
|
|
652
|
-
* @function updateStackToolState
|
|
653
|
-
* @param {String} elementId - The html div id used for rendering or its DOM HTMLElement
|
|
654
|
-
* @param {Number} imageIndex - The new imageIndex value.
|
|
655
|
-
*/
|
|
656
|
-
export const updateStackToolState = function (elementId, imageIndex) {
|
|
657
|
-
let element = isElement(elementId)
|
|
658
|
-
? elementId
|
|
659
|
-
: document.getElementById(elementId);
|
|
660
|
-
if (!element) {
|
|
661
|
-
console.error("invalid html element: " + elementId);
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
let enabledElement = cornerstone.getEnabledElement(element);
|
|
665
|
-
if (!enabledElement.toolStateManager) {
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
let stackState = enabledElement.toolStateManager.toolState["stack"];
|
|
669
|
-
if (!stackState) {
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
// READY for different segmentations data (data[segmentation_label_id])
|
|
673
|
-
stackState.data[0].currentImageIdIndex = imageIndex;
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
/** @inner Internal module functions */
|
|
677
|
-
|
|
678
|
-
/**
|
|
679
|
-
* Check if a tool has already been added
|
|
680
|
-
* @function isToolMissing
|
|
681
|
-
* @param {String} toolName - The tool name.
|
|
682
|
-
* @param {Array} _viewports - The viewports to check.
|
|
683
|
-
*/
|
|
684
|
-
const isToolMissing = function (toolName, _viewports) {
|
|
685
|
-
let isToolMissing = false;
|
|
686
|
-
|
|
687
|
-
if (_viewports) {
|
|
688
|
-
each(_viewports, function (viewport) {
|
|
689
|
-
let element = cornerstone.getEnabledElement(
|
|
690
|
-
document.getElementById(viewport)
|
|
691
|
-
);
|
|
692
|
-
let added = cornerstoneTools.getToolForElement(element, toolName);
|
|
693
|
-
if (added === undefined) {
|
|
694
|
-
isToolMissing = true;
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
} else {
|
|
698
|
-
let elements = cornerstone.getEnabledElements();
|
|
699
|
-
each(elements, function (element) {
|
|
700
|
-
let added = cornerstoneTools.getToolForElement(element, toolName);
|
|
701
|
-
if (added === undefined) {
|
|
702
|
-
isToolMissing = true;
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
return isToolMissing;
|
|
708
|
-
};
|