larvitar 0.18.2 → 1.2.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.
- package/.github/workflows/deploy.yml +3 -12
- package/MIGRATION.md +25 -0
- package/README.md +28 -27
- package/docs/documentation/Mixins.polygonSegmentationMixin%20-%20segmentation%20operations%20for%20polyline.html +171 -0
- package/docs/documentation/Tools.Annotation.ContoursTool.html +218 -0
- package/docs/documentation/Tools.Annotation.DiameterTool.html +219 -0
- package/docs/documentation/Tools.Annotation.SeedsTool.html +214 -0
- package/docs/documentation/Tools.Brush.BrushTool.html +218 -0
- package/docs/documentation/Tools.Brush.ThresholdsBrushTool.html +218 -0
- package/docs/documentation/Tools.PolylineScissorsTool.html +218 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/documentation/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/documentation/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/documentation/global.html +1303 -0
- package/docs/documentation/imageAnonymization.js.html +245 -0
- package/docs/documentation/imageColormaps.js.html +283 -0
- package/docs/documentation/imageContours.js.html +278 -0
- package/docs/documentation/imageIo.js.html +291 -0
- package/docs/documentation/imageLayers.js.html +188 -0
- package/docs/documentation/imageLoading.js.html +297 -0
- package/docs/documentation/imageParsing.js.html +385 -0
- package/docs/documentation/imagePresets.js.html +207 -0
- package/docs/documentation/imageRendering.js.html +849 -0
- package/docs/documentation/imageReslice.js.html +162 -0
- package/docs/documentation/imageStore.js.html +360 -0
- package/docs/documentation/imageTools.js.html +784 -0
- package/docs/documentation/imageUtils.js.html +1609 -0
- package/docs/documentation/image_colormaps.js.html +283 -0
- package/docs/documentation/image_contours.js.html +279 -0
- package/docs/documentation/image_io.js.html +288 -0
- package/docs/documentation/image_layers.js.html +188 -0
- package/docs/documentation/image_loading.js.html +294 -0
- package/docs/documentation/image_parsing.js.html +391 -0
- package/docs/documentation/image_presets.js.html +207 -0
- package/docs/documentation/image_rendering.js.html +845 -0
- package/docs/documentation/image_reslice.js.html +164 -0
- package/docs/documentation/image_store.js.html +359 -0
- package/docs/documentation/image_tools.js.html +792 -0
- package/docs/documentation/image_utils.js.html +1609 -0
- package/docs/documentation/index.html +175 -0
- package/docs/documentation/loaders_commonLoader.js.html +306 -0
- package/docs/documentation/loaders_dicomLoader.js.html +130 -0
- package/docs/documentation/loaders_fileLoader.js.html +155 -0
- package/docs/documentation/loaders_multiframeLoader.js.html +443 -0
- package/docs/documentation/loaders_niftiLoader.js.html +150 -0
- package/docs/documentation/loaders_nrrdLoader.js.html +545 -0
- package/docs/documentation/loaders_resliceLoader.js.html +258 -0
- package/docs/documentation/module-imaging_contours.html +954 -0
- package/docs/documentation/module-imaging_imageAnonymization.html +544 -0
- package/docs/documentation/module-imaging_imageColormaps.html +1012 -0
- package/docs/documentation/module-imaging_imageContours.html +954 -0
- package/docs/documentation/module-imaging_imageIo.html +1057 -0
- package/docs/documentation/module-imaging_imageLayers.html +904 -0
- package/docs/documentation/module-imaging_imageLoading.html +1301 -0
- package/docs/documentation/module-imaging_imageParsing.html +1356 -0
- package/docs/documentation/module-imaging_imagePresets.html +679 -0
- package/docs/documentation/module-imaging_imageRendering.html +3223 -0
- package/docs/documentation/module-imaging_imageReslice.html +413 -0
- package/docs/documentation/module-imaging_imageStore-Larvitar_Store.html +284 -0
- package/docs/documentation/module-imaging_imageStore.html +1560 -0
- package/docs/documentation/module-imaging_imageTools.html +3617 -0
- package/docs/documentation/module-imaging_imageUtils.html +7253 -0
- package/docs/documentation/module-imaging_io.html +1057 -0
- package/docs/documentation/module-imaging_layers.html +904 -0
- package/docs/documentation/module-imaging_loading.html +1301 -0
- package/docs/documentation/module-imaging_parsing.html +1375 -0
- package/docs/documentation/module-imaging_presets.html +679 -0
- package/docs/documentation/module-imaging_rendering.html +8094 -0
- package/docs/documentation/module-imaging_reslice.html +411 -0
- package/docs/documentation/module-imaging_store-Larvitar_Store.html +284 -0
- package/docs/documentation/module-imaging_store.html +1537 -0
- package/docs/documentation/module-imaging_strategies_eraseFreehand.html +708 -0
- package/docs/documentation/module-imaging_strategies_fillFreehand.html +708 -0
- package/docs/documentation/module-imaging_tools.html +3617 -0
- package/docs/documentation/module-imaging_tools_custom_contourTool.html +207 -0
- package/docs/documentation/module-imaging_tools_custom_diameterTool.html +205 -0
- package/docs/documentation/module-imaging_tools_custom_editMaskTool.html +205 -0
- package/docs/documentation/module-imaging_tools_custom_polygonScissorsTool.html +203 -0
- package/docs/documentation/module-imaging_tools_custom_thresholdBrushTool.html +684 -0
- package/docs/documentation/module-imaging_tools_default.html +205 -0
- package/docs/documentation/module-imaging_tools_interaction.html +530 -0
- package/docs/documentation/module-imaging_tools_io.html +832 -0
- package/docs/documentation/module-imaging_tools_main.html +2028 -0
- package/docs/documentation/module-imaging_tools_polygonSegmentationMixin.html +567 -0
- package/docs/documentation/module-imaging_tools_segmentation.html +3586 -0
- package/docs/documentation/module-imaging_tools_state.html +494 -0
- package/docs/documentation/module-imaging_utils.html +7253 -0
- package/docs/documentation/module-loaders_commonLoader.html +1313 -0
- package/docs/documentation/module-loaders_dicomLoader.html +522 -0
- package/docs/documentation/module-loaders_fileLoader.html +593 -0
- package/docs/documentation/module-loaders_multiframeLoader.html +1169 -0
- package/docs/documentation/module-loaders_niftiLoader.html +565 -0
- package/docs/documentation/module-loaders_nrrdLoader.html +1459 -0
- package/docs/documentation/module-loaders_resliceLoader.html +590 -0
- package/docs/documentation/module-monitors_memory.html +980 -0
- package/docs/documentation/module-tools_default.html +740 -0
- package/docs/documentation/module.exports_module.exports.html +203 -0
- package/docs/documentation/monitors_memory.js.html +189 -0
- package/docs/documentation/parsers_nrrd.js.html +569 -0
- package/docs/documentation/scripts/collapse.js +20 -0
- package/docs/documentation/scripts/linenumber.js +25 -0
- package/docs/documentation/scripts/nav.js +12 -0
- package/docs/documentation/scripts/polyfill.js +4 -0
- package/docs/documentation/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/documentation/scripts/prettify/lang-css.js +2 -0
- package/docs/documentation/scripts/prettify/prettify.js +28 -0
- package/docs/documentation/scripts/search.js +83 -0
- package/docs/documentation/styles/jsdoc.css +765 -0
- package/docs/documentation/styles/prettify.css +80 -0
- package/docs/documentation/tools_contourTool.js.html +1963 -0
- package/docs/documentation/tools_custom_contourTool.js.html +1968 -0
- package/docs/documentation/tools_custom_diameterTool.js.html +225 -0
- package/docs/documentation/tools_custom_editMaskTool.js.html +225 -0
- package/docs/documentation/tools_custom_polylineScissorsTool.js.html +143 -0
- package/docs/documentation/tools_custom_thresholdsBrushTool.js.html +245 -0
- package/docs/documentation/tools_default.js.html +576 -0
- package/docs/documentation/tools_diameterTool.js.html +219 -0
- package/docs/documentation/tools_editMaskTool.js.html +219 -0
- package/docs/documentation/tools_interaction.js.html +258 -0
- package/docs/documentation/tools_io.js.html +297 -0
- package/docs/documentation/tools_main.js.html +443 -0
- package/docs/documentation/tools_polygonSegmentationMixin.js.html +329 -0
- package/docs/documentation/tools_polylineScissorsTool.js.html +136 -0
- package/docs/documentation/tools_seedTool.js.html +423 -0
- package/docs/documentation/tools_segmentation.js.html +558 -0
- package/docs/documentation/tools_state.js.html +163 -0
- package/docs/documentation/tools_strategies_eraseFreehand.js.html +160 -0
- package/docs/documentation/tools_strategies_fillFreehand.js.html +163 -0
- package/docs/documentation/tools_thresholdsBrushTool.js.html +239 -0
- package/docs/documentation/tools_tools.default.js.html +569 -0
- package/docs/documentation/tools_tools.interaction.js.html +251 -0
- package/docs/documentation/tools_tools.io.js.html +288 -0
- package/docs/documentation/tools_tools.main.js.html +442 -0
- package/docs/documentation/tools_tools.segmentation.js.html +445 -0
- package/docs/documentation/tools_tools.state.js.html +157 -0
- package/docs/examples/base.html +170 -0
- package/docs/examples/colorMaps.html +181 -0
- package/docs/examples/defaultTools.html +246 -0
- package/docs/examples/demo/anon1 +0 -0
- package/docs/examples/demo/anon10 +0 -0
- package/docs/examples/demo/anon11 +0 -0
- package/docs/examples/demo/anon12 +0 -0
- package/docs/examples/demo/anon13 +0 -0
- package/docs/examples/demo/anon14 +0 -0
- package/docs/examples/demo/anon15 +0 -0
- package/docs/examples/demo/anon16 +0 -0
- package/docs/examples/demo/anon17 +0 -0
- package/docs/examples/demo/anon18 +0 -0
- package/docs/examples/demo/anon19 +0 -0
- package/docs/examples/demo/anon2 +0 -0
- package/docs/examples/demo/anon20 +0 -0
- package/docs/examples/demo/anon21 +0 -0
- package/docs/examples/demo/anon22 +0 -0
- package/docs/examples/demo/anon23 +0 -0
- package/docs/examples/demo/anon24 +0 -0
- package/docs/examples/demo/anon3 +0 -0
- package/docs/examples/demo/anon4 +0 -0
- package/docs/examples/demo/anon5 +0 -0
- package/docs/examples/demo/anon6 +0 -0
- package/docs/examples/demo/anon7 +0 -0
- package/docs/examples/demo/anon8 +0 -0
- package/docs/examples/demo/anon9 +0 -0
- package/docs/examples/demo/example.nrrd +0 -0
- package/docs/examples/demo/segmentation.nrrd +0 -0
- package/docs/examples/demo/xa_integris.dcm +0 -0
- package/docs/examples/index.html +129 -0
- package/docs/examples/larvitar.js +108623 -0
- package/docs/examples/layers.html +250 -0
- package/docs/examples/masks.html +273 -0
- package/docs/examples/multiframe.html +200 -0
- package/docs/examples/nrrd.html +96 -0
- package/docs/examples/reslice.html +174 -0
- package/docs/index.html +92 -0
- package/imaging/dataDictionary.json +21865 -21865
- package/imaging/imageAnonymization.js +161 -0
- package/imaging/{image_colormaps.js → imageColormaps.js} +2 -2
- package/imaging/{image_contours.js → imageContours.js} +1 -2
- package/imaging/{image_io.js → imageIo.js} +18 -15
- package/imaging/{image_layers.js → imageLayers.js} +2 -2
- package/imaging/{image_loading.js → imageLoading.js} +9 -6
- package/imaging/imageParsing.js +301 -0
- package/imaging/{image_presets.js → imagePresets.js} +2 -2
- package/imaging/{image_rendering.js → imageRendering.js} +36 -32
- package/imaging/imageReslice.js +78 -0
- package/imaging/{image_store.js → imageStore.js} +8 -7
- package/imaging/{image_tools.js → imageTools.js} +15 -23
- package/imaging/{image_utils.js → imageUtils.js} +1 -1
- package/imaging/loaders/commonLoader.js +1 -1
- package/imaging/loaders/dicomLoader.js +1 -1
- package/imaging/loaders/fileLoader.js +2 -2
- package/imaging/loaders/multiframeLoader.js +6 -2
- package/imaging/loaders/nrrdLoader.js +11 -7
- package/imaging/tools/{contourTool.js → custom/contourTool.js} +25 -20
- package/imaging/tools/{diameterTool.js → custom/diameterTool.js} +9 -3
- package/imaging/tools/{editMaskTool.js → custom/editMaskTool.js} +7 -1
- package/imaging/tools/{polylineScissorsTool.js → custom/polylineScissorsTool.js} +12 -5
- package/imaging/tools/{seedTool.js → custom/seedTool.js} +3 -3
- package/imaging/tools/{thresholdsBrushTool.js → custom/thresholdsBrushTool.js} +7 -1
- package/imaging/tools/{tools.default.js → default.js} +10 -3
- package/imaging/tools/{tools.interaction.js → interaction.js} +13 -6
- package/imaging/tools/{tools.io.js → io.js} +15 -6
- package/imaging/tools/{tools.main.js → main.js} +16 -14
- package/imaging/tools/polygonSegmentationMixin.js +8 -4
- package/imaging/tools/{tools.segmentation.js → segmentation.js} +171 -58
- package/imaging/tools/segmentations.md +38 -0
- package/imaging/tools/setLabelMap3D.js +248 -0
- package/imaging/tools/{tools.state.js → state.js} +7 -1
- package/imaging/tools/strategies/eraseFreehand.js +8 -9
- package/imaging/tools/strategies/fillFreehand.js +8 -9
- package/index.js +44 -39
- package/modules/vuex/larvitar.js +13 -3
- package/package.json +13 -10
- package/imaging/image_parsing.js +0 -307
- package/imaging/image_reslice.js +0 -80
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { updateViewportData } from "../image_rendering";
|
|
1
|
+
/** @module imaging/tools/interaction
|
|
2
|
+
* @desc This file provides functionalities for
|
|
3
|
+
* tools interactions
|
|
4
|
+
*/
|
|
6
5
|
|
|
6
|
+
// external libraries
|
|
7
7
|
import { throttle } from "lodash";
|
|
8
8
|
import * as keyCodes from "keycode-js";
|
|
9
9
|
|
|
10
|
+
// internal libraries
|
|
11
|
+
import { DEFAULT_MOUSE_KEYS } from "./default";
|
|
12
|
+
import { setToolActive } from "./main";
|
|
13
|
+
import { isElement } from "../imageUtils";
|
|
14
|
+
import { larvitar_store } from "../imageStore";
|
|
15
|
+
import { updateViewportData } from "../imageRendering";
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
18
|
* TOOLS INTERACTIONS TODOS:
|
|
12
19
|
* - enable touch controls
|
|
@@ -21,7 +28,7 @@ import * as keyCodes from "keycode-js";
|
|
|
21
28
|
* - "restore previous active tool" instead of passed "default" tool
|
|
22
29
|
* - manage left button (an idea could be to cycle over object keys for both buttons)
|
|
23
30
|
* - possibility to change modifier keys
|
|
24
|
-
* @param {Object} config - see tools
|
|
31
|
+
* @param {Object} config - see tools/default
|
|
25
32
|
* @param {Array} viewports - The hmtl element ids to be used for tool activation.
|
|
26
33
|
*/
|
|
27
34
|
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
/** @module imaging/tools/io
|
|
2
|
+
* @desc This file provides functionalities for
|
|
3
|
+
* tools input/output
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// external libraries
|
|
1
7
|
import cornerstone from "cornerstone-core";
|
|
2
8
|
import cornerstoneTools from "cornerstone-tools";
|
|
3
9
|
import { each, map, assign, invert } from "lodash";
|
|
4
10
|
import { unparse } from "papaparse";
|
|
5
11
|
|
|
6
|
-
|
|
12
|
+
// internal libraries
|
|
13
|
+
import { setToolEnabled } from "../imageTools";
|
|
7
14
|
|
|
8
15
|
// DEV
|
|
9
16
|
// import { saved_state_2 } from "./cstools_state_example.js";
|
|
@@ -13,7 +20,7 @@ import { setToolEnabled } from "../image_tools";
|
|
|
13
20
|
* Load annotation from json object
|
|
14
21
|
* @param {Object} jsonData - The previously saved tools state
|
|
15
22
|
*/
|
|
16
|
-
export const loadAnnotations = function(jsonData) {
|
|
23
|
+
export const loadAnnotations = function (jsonData) {
|
|
17
24
|
// DEV
|
|
18
25
|
// if (!jsonData) {
|
|
19
26
|
// jsonData = saved_state_2;
|
|
@@ -52,8 +59,9 @@ export const loadAnnotations = function(jsonData) {
|
|
|
52
59
|
* @param {bool} download - True to download json
|
|
53
60
|
* @param {string} filename - The json file name, @default state.json
|
|
54
61
|
*/
|
|
55
|
-
export const saveAnnotations = function(toDownload, filename = "state.json") {
|
|
56
|
-
let currentToolState =
|
|
62
|
+
export const saveAnnotations = function (toDownload, filename = "state.json") {
|
|
63
|
+
let currentToolState =
|
|
64
|
+
cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
|
57
65
|
if (toDownload) {
|
|
58
66
|
// Convert JSON Array to string.
|
|
59
67
|
var json_string = JSON.stringify(currentToolState);
|
|
@@ -67,11 +75,12 @@ export const saveAnnotations = function(toDownload, filename = "state.json") {
|
|
|
67
75
|
* Save annotation from current stack, download as csv file
|
|
68
76
|
* containing only useful informations for user
|
|
69
77
|
*/
|
|
70
|
-
export const exportAnnotations = function(
|
|
78
|
+
export const exportAnnotations = function (
|
|
71
79
|
fileManager,
|
|
72
80
|
filename = "annotations.csv"
|
|
73
81
|
) {
|
|
74
|
-
let currentToolState =
|
|
82
|
+
let currentToolState =
|
|
83
|
+
cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
|
75
84
|
let csvdata = generateCSV(fileManager, currentToolState);
|
|
76
85
|
let csvstring = unparse(csvdata);
|
|
77
86
|
download(csvstring, filename);
|
|
@@ -1,34 +1,36 @@
|
|
|
1
|
+
/** @module imaging/tools/main
|
|
2
|
+
* @desc This file provides functionalities
|
|
3
|
+
* for initializing tools and stacks
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
// external libraries
|
|
2
7
|
import cornerstone from "cornerstone-core";
|
|
3
8
|
import cornerstoneTools from "cornerstone-tools/dist/cornerstoneTools.js";
|
|
4
9
|
import cornerstoneMath from "cornerstone-math";
|
|
5
|
-
|
|
10
|
+
import Hammer from "hammerjs";
|
|
6
11
|
import { each, extend } from "lodash";
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
loadAnnotations,
|
|
11
|
-
exportAnnotations
|
|
12
|
-
} from "./tools.io";
|
|
13
|
+
// internal libraries
|
|
14
|
+
import { saveAnnotations, loadAnnotations, exportAnnotations } from "./io";
|
|
13
15
|
import {
|
|
14
16
|
DEFAULT_TOOLS,
|
|
15
17
|
DEFAULT_STYLE,
|
|
16
18
|
DEFAULT_SETTINGS,
|
|
17
19
|
dvTools
|
|
18
|
-
} from "./
|
|
19
|
-
import { larvitar_store } from "../
|
|
20
|
+
} from "./default";
|
|
21
|
+
import { larvitar_store } from "../imageStore";
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Initialize cornerstone tools with default configuration (extended with custom configuration)
|
|
23
25
|
* @function initializeCSTools
|
|
24
|
-
* @param {Object} settings - the settings object (see tools
|
|
25
|
-
* @param {Object} settings - the style object (see tools
|
|
26
|
+
* @param {Object} settings - the settings object (see tools/default.js)
|
|
27
|
+
* @param {Object} settings - the style object (see tools/default.js)
|
|
26
28
|
* @example larvitar.initializeCSTools({showSVGCursors:false}, {color: "0000FF"});
|
|
27
29
|
*/
|
|
28
30
|
const initializeCSTools = function (settings, style) {
|
|
29
31
|
cornerstoneTools.external.cornerstone = cornerstone;
|
|
30
32
|
cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
|
|
31
|
-
|
|
33
|
+
cornerstoneTools.external.Hammer = Hammer;
|
|
32
34
|
extend(DEFAULT_SETTINGS, settings);
|
|
33
35
|
|
|
34
36
|
// hack to fix warning on init() - but breaks labelmap 0 auto generation
|
|
@@ -136,7 +138,7 @@ const addTool = function (toolName, customConfig, targetElementId) {
|
|
|
136
138
|
};
|
|
137
139
|
|
|
138
140
|
/**
|
|
139
|
-
* Add all default tools, as listed in tools
|
|
141
|
+
* Add all default tools, as listed in tools/default.js
|
|
140
142
|
* @function addDefaultTools
|
|
141
143
|
*/
|
|
142
144
|
export const addDefaultTools = function (elementId) {
|
|
@@ -199,7 +201,7 @@ function tryUpdateImage(element) {
|
|
|
199
201
|
* Set Tool "active" on all elements (ie, rendered and manipulable) & refresh cornerstone elements
|
|
200
202
|
* @function setToolActive
|
|
201
203
|
* @param {String} toolName - The tool name.
|
|
202
|
-
* @param {Object} options - The custom options. @default from tools
|
|
204
|
+
* @param {Object} options - The custom options. @default from tools/default.js
|
|
203
205
|
* @param {Array} viewports - The hmtl element id to be used for tool initialization.
|
|
204
206
|
* @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.
|
|
205
207
|
*/
|
|
@@ -326,7 +328,7 @@ const setToolPassive = function (toolName, viewports) {
|
|
|
326
328
|
/**
|
|
327
329
|
* Set cornerstone tools custom configuration (extend default configuration)
|
|
328
330
|
* @function setToolsStyle
|
|
329
|
-
* @param {Object} style - the style object (see tools
|
|
331
|
+
* @param {Object} style - the style object (see tools/defaults.js)
|
|
330
332
|
*/
|
|
331
333
|
const setToolsStyle = function (style) {
|
|
332
334
|
extend(DEFAULT_STYLE, style);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/** @module imaging/tools/polygonSegmentationMixin
|
|
2
|
+
* @desc This file ovverides `freehandSegmentationMixin`'s
|
|
3
|
+
* `renderToolData` method
|
|
4
|
+
*/
|
|
2
5
|
|
|
6
|
+
// external libraries
|
|
7
|
+
import cornerstoneTools from "cornerstone-tools";
|
|
3
8
|
const external = cornerstoneTools.external;
|
|
4
9
|
const draw = cornerstoneTools.importInternal("drawing/draw");
|
|
5
10
|
const drawJoinedLines = cornerstoneTools.importInternal(
|
|
@@ -147,9 +152,8 @@ function _applyStrategy(evt) {
|
|
|
147
152
|
const points = this.handles.points;
|
|
148
153
|
const { element } = evt.detail;
|
|
149
154
|
|
|
150
|
-
const { labelmap2D, labelmap3D, currentImageIdIndex } =
|
|
151
|
-
element
|
|
152
|
-
);
|
|
155
|
+
const { labelmap2D, labelmap3D, currentImageIdIndex } =
|
|
156
|
+
getters.labelmap2D(element);
|
|
153
157
|
|
|
154
158
|
const pixelData = labelmap2D.pixelData;
|
|
155
159
|
const previousPixeldata = pixelData.slice();
|
|
@@ -1,33 +1,23 @@
|
|
|
1
|
+
/** @module imaging/tools/segmentation
|
|
2
|
+
* @desc This file provides functionalities
|
|
3
|
+
* for handling masks and luts
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
// external libraries
|
|
2
7
|
import cornerstone from "cornerstone-core";
|
|
3
8
|
import cornerstoneTools from "cornerstone-tools/dist/cornerstoneTools.js";
|
|
4
|
-
|
|
5
|
-
import { setToolActive, setToolDisabled } from "./tools.main";
|
|
6
|
-
// utils
|
|
7
|
-
import { cloneDeep, extend, values } from "lodash";
|
|
8
|
-
|
|
9
|
+
import { cloneDeep, extend, values, sum } from "lodash";
|
|
9
10
|
const segModule = cornerstoneTools.getModule("segmentation");
|
|
10
|
-
const setters = segModule
|
|
11
|
-
const getters = segModule.getters;
|
|
11
|
+
const { getters, setters } = segModule;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// internal libraries
|
|
14
|
+
import { setToolActive, setToolDisabled } from "./main";
|
|
15
|
+
import { isElement } from "../imageUtils";
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* NOTES ON CS TOOLS SEGMENTATION MODULE
|
|
24
|
-
* The value in the mask (binary) define which color will be used from the LUT map
|
|
25
|
-
* The different masks are 'labelmap', while different values in the same mask are 'segments'
|
|
26
|
-
* Segments get the color from the lutmap (up to 2^16 segments) and can be shown/hidden one by one
|
|
27
|
-
* > setters.toggleSegmentVisibility(htmlelement,segmentvalue,labelmapid)
|
|
28
|
-
* > setters.colorForSegmentIndexOfColorLUT(colorLutIndex, segmentValue, colorRGBAarray)
|
|
29
|
-
* Labelmaps are linked to a colormap and can be active / inactive
|
|
30
|
-
* */
|
|
17
|
+
// custom code
|
|
18
|
+
import { setLabelmap3DForElement } from "./setLabelMap3D";
|
|
19
|
+
// override function
|
|
20
|
+
setters.labelmap3DForElement = setLabelmap3DForElement;
|
|
31
21
|
|
|
32
22
|
// General segmentation cs tools module configuration
|
|
33
23
|
const config = {
|
|
@@ -145,53 +135,153 @@ function generateUniformLUT(hex_color, opacity) {
|
|
|
145
135
|
return lut;
|
|
146
136
|
}
|
|
147
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Set color for label
|
|
140
|
+
* @param {Number} labelId
|
|
141
|
+
* @param {String} color in hex format
|
|
142
|
+
*/
|
|
143
|
+
export function setLabelColor(labelId, color) {
|
|
144
|
+
let volumeId = 0; // TODO MULTIVOLUME
|
|
145
|
+
let rgb = hexToRgb(color);
|
|
146
|
+
let rgba = [...rgb, 128];
|
|
147
|
+
setters.colorForSegmentIndexOfColorLUT(volumeId, labelId, rgba);
|
|
148
|
+
// force render ? depends on image visualization (render all ?)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get color from label
|
|
153
|
+
* @param {Number} labelId
|
|
154
|
+
* @returns {String} Color in hex format
|
|
155
|
+
*/
|
|
156
|
+
export function getLabelColor(labelId) {
|
|
157
|
+
let volumeId = 0; // TODO MULTIVOLUME
|
|
158
|
+
let rgba = getters.colorForSegmentIndexColorLUT(volumeId, labelId);
|
|
159
|
+
return rgbToHex(rgba);
|
|
160
|
+
}
|
|
161
|
+
|
|
148
162
|
/**
|
|
149
163
|
* A function to group all settings to load before masks
|
|
150
|
-
*
|
|
164
|
+
* @param {Object} customConfig - Object containing override values for segmentation module config
|
|
151
165
|
*/
|
|
152
|
-
export function initSegmentationModule() {
|
|
166
|
+
export function initSegmentationModule(customConfig) {
|
|
153
167
|
// set configuration
|
|
154
168
|
segModule.configuration = cloneDeep(config);
|
|
169
|
+
extend(segModule.configuration, customConfig);
|
|
155
170
|
}
|
|
156
171
|
|
|
157
172
|
/**
|
|
158
173
|
* Add segmentation mask to segmentation module
|
|
159
|
-
* @param {
|
|
174
|
+
* @param {Object} maskProps - The mask properties (labelId, color and opacity)
|
|
160
175
|
* @param {TypedArray} - The mask data array
|
|
176
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
177
|
+
* @returns {Promise} - Return a promise which will resolve when segmentation mask is added
|
|
161
178
|
*/
|
|
162
|
-
export function addSegmentationMask(props, data, elementId
|
|
163
|
-
let
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
export function addSegmentationMask(props, data, elementId) {
|
|
180
|
+
let promise = new Promise(async resolve => {
|
|
181
|
+
let element = isElement(elementId)
|
|
182
|
+
? elementId
|
|
183
|
+
: document.getElementById(elementId);
|
|
184
|
+
if (!element) {
|
|
185
|
+
console.error("invalid html element: " + elementId);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const res = await setters.labelmap3DForElement(
|
|
190
|
+
element,
|
|
191
|
+
data.buffer,
|
|
192
|
+
props.labelId
|
|
193
|
+
);
|
|
194
|
+
// if user set a color property, use that color for all segments on the labelmap
|
|
195
|
+
let lut = props.color
|
|
196
|
+
? generateUniformLUT(props.color, props.opacity)
|
|
197
|
+
: generateLUT(props.opacity);
|
|
198
|
+
setters.colorLUT(props.labelId, lut);
|
|
199
|
+
// bind labelmap to colorLUT
|
|
200
|
+
let labelmap3d = getters.labelmap3D(element, props.labelId);
|
|
201
|
+
setters.colorLUTIndexForLabelmap3D(labelmap3d, props.labelId);
|
|
202
|
+
resolve();
|
|
203
|
+
});
|
|
204
|
+
return promise;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Set a new mask slice into the labelmap buffer
|
|
209
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
210
|
+
* @param {Number} sliceIndex - the index of the new mask slice
|
|
211
|
+
* @param {ArrayBuffer} pixelData - the pixelData array
|
|
212
|
+
*/
|
|
213
|
+
export function loadMaskSlice(elementId, sliceIndex, pixelData) {
|
|
214
|
+
// optimization: if pixelData contains no labels, return
|
|
215
|
+
if (sum(pixelData) === 0) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let element = isElement(elementId)
|
|
220
|
+
? elementId
|
|
221
|
+
: document.getElementById(elementId);
|
|
222
|
+
if (!element) {
|
|
223
|
+
console.error("invalid html element: " + elementId);
|
|
224
|
+
return;
|
|
175
225
|
}
|
|
226
|
+
let volumeId = 0; // TODO for multivolume
|
|
227
|
+
// get labelmap buffer
|
|
228
|
+
let labelmaps2D = getters.labelmap3D(element, volumeId).labelmaps2D;
|
|
229
|
+
|
|
230
|
+
// add if not alresdy present
|
|
231
|
+
if (!labelmaps2D[sliceIndex]) {
|
|
232
|
+
labelmaps2D[sliceIndex] = {};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
labelmaps2D[sliceIndex].pixelData = pixelData;
|
|
236
|
+
setters.updateSegmentsOnLabelmap2D(labelmaps2D[sliceIndex]);
|
|
237
|
+
cornerstone.updateImage(element);
|
|
176
238
|
}
|
|
177
239
|
|
|
178
240
|
/**
|
|
179
241
|
* Activate a specific labelmap through its labelId
|
|
180
242
|
* @param {Number} labelId - The labelmap id to activate
|
|
181
|
-
* @param {String} elementId - The target html element
|
|
243
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
182
244
|
*/
|
|
183
245
|
export function setActiveLabelmap(labelId, elementId) {
|
|
184
|
-
let element =
|
|
246
|
+
let element = isElement(elementId)
|
|
247
|
+
? elementId
|
|
248
|
+
: document.getElementById(elementId);
|
|
249
|
+
if (!element) {
|
|
250
|
+
console.error("invalid html element: " + elementId);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
185
253
|
setters.activeLabelmapIndex(element, labelId);
|
|
186
254
|
}
|
|
187
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Get active labelmap for target element
|
|
258
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
259
|
+
* @returns {Object} The active labelmap object that contains the buffer
|
|
260
|
+
*/
|
|
261
|
+
export function getActiveLabelmapBuffer(elementId) {
|
|
262
|
+
let element = isElement(elementId)
|
|
263
|
+
? elementId
|
|
264
|
+
: document.getElementById(elementId);
|
|
265
|
+
if (!element) {
|
|
266
|
+
console.error("invalid html element: " + elementId);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
return getters.activeLabelmapBuffer(element);
|
|
270
|
+
}
|
|
271
|
+
|
|
188
272
|
/**
|
|
189
273
|
* Activate a specific segment through its index
|
|
190
274
|
* @param {Number} segmentIndex - The segment index to activate
|
|
191
|
-
* @param {String} elementId - The target html element
|
|
275
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
192
276
|
*/
|
|
193
277
|
export function setActiveSegment(segmentIndex, elementId) {
|
|
194
|
-
let element =
|
|
278
|
+
let element = isElement(elementId)
|
|
279
|
+
? elementId
|
|
280
|
+
: document.getElementById(elementId);
|
|
281
|
+
if (!element) {
|
|
282
|
+
console.error("invalid html element: " + elementId);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
195
285
|
setters.activeSegmentIndex(element, segmentIndex);
|
|
196
286
|
}
|
|
197
287
|
|
|
@@ -213,6 +303,24 @@ export function setInactiveLabelOpacity(opacity) {
|
|
|
213
303
|
forceRender();
|
|
214
304
|
}
|
|
215
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Toggle mask visibility
|
|
308
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
309
|
+
* @param {Number} labelId - The id of the mask label
|
|
310
|
+
*/
|
|
311
|
+
export function toggleVisibility(elementId, labelId) {
|
|
312
|
+
let element = isElement(elementId)
|
|
313
|
+
? elementId
|
|
314
|
+
: document.getElementById(elementId);
|
|
315
|
+
if (!element) {
|
|
316
|
+
console.error("invalid html element: " + elementId);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
let volumeId = 0; // TODO MULTIVOLUME
|
|
320
|
+
setters.toggleSegmentVisibility(element, labelId, volumeId);
|
|
321
|
+
cornerstone.updateImage(element);
|
|
322
|
+
}
|
|
323
|
+
|
|
216
324
|
/**
|
|
217
325
|
* Toggle between 'contours mode' and 'filled mode'
|
|
218
326
|
* @param {Bool} toggle - Contour mode enabled if true
|
|
@@ -236,9 +344,7 @@ export function toggleContourMode(toggle) {
|
|
|
236
344
|
|
|
237
345
|
/**
|
|
238
346
|
* Set mask appearance props
|
|
239
|
-
* @param {
|
|
240
|
-
* @param {Integer} mode - [0=filled, 1=contour, 2=hidden]
|
|
241
|
-
* @param {Float} alpha - Opacity value (if mode=0), between 0 and 1
|
|
347
|
+
* @param {Object} maskProps - The mask appearance props (labelId, visualization [0=filled, 1=contour, 2=hidden], opacity (if mode=0), between 0 and 1)
|
|
242
348
|
*/
|
|
243
349
|
export function setMaskProps(props) {
|
|
244
350
|
// Lut index and segment values are hardcoded because they will depend on design choices:
|
|
@@ -299,6 +405,7 @@ export function clearSegmentationState() {
|
|
|
299
405
|
/**
|
|
300
406
|
* Enable brushing
|
|
301
407
|
* @param {Number} dimension - The initial brush radius
|
|
408
|
+
* @param {Array} thresholds - The threshold values (min and max)
|
|
302
409
|
*/
|
|
303
410
|
export function enableBrushTool(dimension, thresholds) {
|
|
304
411
|
segModule.configuration.radius = dimension;
|
|
@@ -324,35 +431,41 @@ export function setBrushProps(props) {
|
|
|
324
431
|
forceRender();
|
|
325
432
|
}
|
|
326
433
|
|
|
327
|
-
/**
|
|
328
|
-
* Retrieve the buffer that represents the current active mask
|
|
329
|
-
*/
|
|
330
|
-
export function getActiveLabelmapBuffer() {
|
|
331
|
-
let element = document.getElementById("axial");
|
|
332
|
-
let object = segModule.getters.activeLabelmapBuffer(element);
|
|
333
|
-
return object.buffer;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
434
|
/**
|
|
337
435
|
* Undo last brush operation (stroke)
|
|
436
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
338
437
|
*/
|
|
339
438
|
export function undoLastStroke(elementId) {
|
|
340
|
-
let element =
|
|
439
|
+
let element = isElement(elementId)
|
|
440
|
+
? elementId
|
|
441
|
+
: document.getElementById(elementId);
|
|
442
|
+
if (!element) {
|
|
443
|
+
console.error("invalid html element: " + elementId);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
341
446
|
let activeLabelMapIndex = segModule.getters.activeLabelmapIndex(element);
|
|
342
447
|
setters.undo(element, activeLabelMapIndex);
|
|
343
448
|
}
|
|
344
449
|
|
|
345
450
|
/**
|
|
346
451
|
* Redo last brush operation (stroke)
|
|
452
|
+
* @param {String} elementId - The target html element Id or its DOM HTMLElement
|
|
347
453
|
*/
|
|
348
454
|
export function redoLastStroke(elementId) {
|
|
349
|
-
let element =
|
|
455
|
+
let element = isElement(elementId)
|
|
456
|
+
? elementId
|
|
457
|
+
: document.getElementById(elementId);
|
|
458
|
+
if (!element) {
|
|
459
|
+
console.error("invalid html element: " + elementId);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
350
462
|
let activeLabelMapIndex = segModule.getters.activeLabelmapIndex(element);
|
|
351
463
|
setters.redo(element, activeLabelMapIndex);
|
|
352
464
|
}
|
|
353
465
|
|
|
354
466
|
/**
|
|
355
467
|
* Delete mask from state
|
|
468
|
+
* @param {Number} labelId - The labelmap id to activate
|
|
356
469
|
*/
|
|
357
470
|
export function deleteMask(labelId) {
|
|
358
471
|
let masks = values(segModule.state.series)[0].labelmaps3D;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
This guide explains the key concepts of Larvitar **segmentation masks management**, based on cornerstone tools's **segmentation module**.
|
|
4
|
+
|
|
5
|
+
# Definitions
|
|
6
|
+
|
|
7
|
+
- _segmentation mask_ or just _mask_: the set of pixels that belongs to a specific structure
|
|
8
|
+
- _volume_: a buffer containing one or more segmentations
|
|
9
|
+
- _label_: the value inside a volume that identifies a specific segmentation
|
|
10
|
+
|
|
11
|
+
# CS tools
|
|
12
|
+
|
|
13
|
+
## Segmentation module structure
|
|
14
|
+
|
|
15
|
+
In cs tools world, the different volumes are defined _labelmaps_, while the different labels in a volume are _segments_. Labelmaps can support up to 2^16 segments.
|
|
16
|
+
The values in the volume (ie, labels) define which color will be used from the LUT map: in fact, segments get the color from the lutmap and can be shown/hidden one by one.
|
|
17
|
+
Each labelmaps can be linked to a different colormap and has a active / inactive property that affects the rendering style (see configuration).
|
|
18
|
+
|
|
19
|
+
> setters.toggleSegmentVisibility(htmlelement,segmentvalue,labelmapid)
|
|
20
|
+
> setters.colorForSegmentIndexOfColorLUT(colorLutIndex, segmentValue, colorRGBAarray)
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
TODO
|
|
25
|
+
|
|
26
|
+
# Larvitar segmentation management
|
|
27
|
+
|
|
28
|
+
TODO
|
|
29
|
+
|
|
30
|
+
# Larvitar segmentation API
|
|
31
|
+
|
|
32
|
+
TODO
|
|
33
|
+
|
|
34
|
+
# Customization
|
|
35
|
+
|
|
36
|
+
Some function in larvitar overrides the default behaviour of cornerstone tools, here is a list of them:
|
|
37
|
+
|
|
38
|
+
- `setters.labelmap3DForElement` is overridden to have a non-blocking behaviour, the custom code is in ./setLabelMap3D.js, same as original code in cs tools repo.
|