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,205 +0,0 @@
1
- /** @module loaders/resliceLoader
2
- * @desc This file provides functionalities for
3
- * custom Reslice Loader
4
- */
5
-
6
- // external libraries
7
- import cornerstone from "cornerstone-core";
8
- import { default as cornerstoneDICOMImageLoader } from "cornerstone-wado-image-loader";
9
-
10
- // internal libraries
11
- import {
12
- getImageFrame,
13
- getLarvitarImageTracker,
14
- getLarvitarManager
15
- } from "./commonLoader";
16
- import type { Image, ImageFrame, MetaData } from "../types";
17
-
18
- /*
19
- * This module provides the following functions to be exported:
20
- * loadReslicedImage(imageId)
21
- */
22
-
23
- /**
24
- * Custom Loader for DICOMImageLoader
25
- * @instance
26
- * @function loadReslicedImage
27
- * @param {String} imageId The Id of the image
28
- * @returns {Object} custom image object
29
- */
30
- export const loadReslicedImage = function (imageId: string) {
31
- let manager = getLarvitarManager();
32
- let imageTracker = getLarvitarImageTracker();
33
- let seriesId = imageTracker[imageId];
34
- let instance = manager[seriesId].instances[imageId];
35
- var reslicedPixeldata = instance.pixelData;
36
- //@ts-ignore deprecated
37
- return createCustomImage(imageId, instance.metadata, reslicedPixeldata);
38
- };
39
-
40
- /* Internal module functions */
41
-
42
- /**
43
- * Create the custom image object for cornerstone from custom image
44
- * @instance
45
- * @function createCustomImage
46
- * @param {String} imageId The Id of the image
47
- * @param {Object} metadata the metadata object
48
- * @param {Object} pixelData pixel data object
49
- * @param {Object} dataSet dataset object
50
- * @returns {Object} custom image object
51
- */
52
- let createCustomImage = function (
53
- imageId: string,
54
- metadata: MetaData,
55
- pixelData: Uint8ClampedArray,
56
- dataSet?: any // deprecated
57
- ) {
58
- let canvas = window.document.createElement("canvas");
59
- let lastImageIdDrawn = "";
60
-
61
- let imageFrame = getImageFrame(metadata, dataSet) as ImageFrame;
62
-
63
- // This function uses the pixelData received as argument without manipulating
64
- // them: if the image is compressed, the decompress function should be called
65
- // before creating the custom image object (like the multiframe case).
66
- imageFrame.pixelData = pixelData;
67
-
68
- let pixelSpacing = metadata.x00280030;
69
- let rescaleIntercept = metadata.x00281052;
70
- let rescaleSlope = metadata.x00281053;
71
- let windowCenter = metadata.x00281050;
72
- let windowWidth = metadata.x00281051;
73
-
74
- function getSizeInBytes() {
75
- let bytesPerPixel = Math.round(imageFrame.bitsAllocated / 8);
76
- return (
77
- imageFrame.rows *
78
- imageFrame.columns *
79
- bytesPerPixel *
80
- imageFrame.samplesPerPixel
81
- );
82
- }
83
-
84
- let image: Partial<Image> = {
85
- imageId: imageId,
86
- color: cornerstoneDICOMImageLoader.isColorImage(
87
- imageFrame.photometricInterpretation
88
- ),
89
- columnPixelSpacing: pixelSpacing
90
- ? (pixelSpacing as number[])[1]
91
- : undefined,
92
- columns: imageFrame.columns,
93
- height: imageFrame.rows,
94
- intercept: rescaleIntercept ? (rescaleIntercept as number) : 0,
95
- invert: imageFrame.photometricInterpretation === "MONOCHROME1",
96
- minPixelValue: imageFrame.smallestPixelValue,
97
- maxPixelValue: imageFrame.largestPixelValue,
98
- render: undefined, // set below
99
- rowPixelSpacing: pixelSpacing ? (pixelSpacing as number[])[0] : undefined,
100
- rows: imageFrame.rows,
101
- sizeInBytes: getSizeInBytes(),
102
- slope: rescaleSlope ? (rescaleSlope as number) : 1,
103
- width: imageFrame.columns,
104
- windowCenter: windowCenter ? (windowCenter as number) : undefined,
105
- windowWidth: windowWidth ? (windowWidth as number) : undefined,
106
- decodeTimeInMS: undefined,
107
- webWorkerTimeInMS: undefined
108
- };
109
-
110
- // add function to return pixel data
111
- image.getPixelData = function () {
112
- if (!imageFrame.pixelData) {
113
- console.warn('no pixel data for imageId "' + imageId);
114
- return [];
115
- }
116
- return Array.from(imageFrame.pixelData);
117
- };
118
-
119
- // convert color space
120
- if (image.color) {
121
- // setup the canvas context
122
- canvas.height = imageFrame.rows;
123
- canvas.width = imageFrame.columns;
124
-
125
- let context = canvas.getContext("2d");
126
-
127
- if (!context) {
128
- throw new Error("Unable to get canvas context");
129
- }
130
-
131
- let imageData = context.createImageData(
132
- imageFrame.columns,
133
- imageFrame.rows
134
- );
135
- cornerstoneDICOMImageLoader.convertColorSpace(imageFrame, imageData);
136
-
137
- imageFrame.imageData = imageData;
138
- imageFrame.pixelData = imageData.data;
139
- }
140
-
141
- // Setup the renderer TODO check if this is really needed (see comment below)
142
- if (image.color) {
143
- image.render = cornerstone.renderColorImage;
144
- image.getCanvas = function () {
145
- if (lastImageIdDrawn === imageId) {
146
- return canvas;
147
- }
148
-
149
- canvas.height = image.rows || 0;
150
- canvas.width = image.columns || 0;
151
- let context = canvas.getContext("2d");
152
- if (!context) {
153
- throw new Error("Unable to get canvas context");
154
- }
155
- context.putImageData(imageFrame.imageData!, 0, 0);
156
- lastImageIdDrawn = imageId;
157
- return canvas;
158
- };
159
- } else {
160
- image.render = undefined; // will be set at need in cornerstone render pipeline, see drawImageSync.js (line 44)
161
- }
162
-
163
- // calculate min/max to avoid erroneous calculation from getImageFrame function
164
- let minMax = cornerstoneDICOMImageLoader.getMinMax(pixelData);
165
- image.minPixelValue = minMax.min;
166
- image.maxPixelValue = minMax.max;
167
-
168
- // set the ww/wc to cover the dynamic range of the image if no values are supplied
169
- if (image.windowCenter === undefined || image.windowWidth === undefined) {
170
- if (image.color) {
171
- image.windowWidth = 255.0;
172
- image.windowCenter = 127.5;
173
- } else if (
174
- image.maxPixelValue &&
175
- image.minPixelValue &&
176
- image.slope &&
177
- image.intercept
178
- ) {
179
- let maxVoi = image.maxPixelValue * image.slope + image.intercept;
180
- let minVoi = image.minPixelValue * image.slope + image.intercept;
181
- image.windowWidth = maxVoi - minVoi;
182
- image.windowCenter = (maxVoi + minVoi) / 2;
183
- } else {
184
- console.error(
185
- "Unable to calculate default window width/center for imageId: " +
186
- imageId
187
- );
188
- }
189
- }
190
-
191
- // Custom images does not have the "data" attribute becaouse their dataset is
192
- // not available. The "metadata" attribute is used by the storeImageData
193
- // function to store custom image pixelData and metadata.
194
- image.metadata = metadata;
195
-
196
- let promise: Promise<Image> = new Promise(function (resolve) {
197
- resolve(image as Image);
198
- });
199
-
200
- // Return an object containing the Promise to cornerstone so it can setup callbacks to be
201
- // invoked asynchronously for the success/resolve and failure/reject scenarios.
202
- return {
203
- promise
204
- };
205
- };
@@ -1,151 +0,0 @@
1
- /** @module monitors/memory
2
- * @desc This file provides utility functions for
3
- * monitoring memory usage
4
- */
5
-
6
- import {
7
- getLarvitarManager,
8
- removeSeriesFromLarvitarManager
9
- } from "../loaders/commonLoader";
10
- import { clearImageCache } from "../imageRendering";
11
- import store from "../imageStore";
12
-
13
- // Custom types for chrome
14
- interface Performance {
15
- memory?: any;
16
- }
17
-
18
- // global module variables
19
- const backingMemory = 100 * 1048576; // 100 MB
20
- var customMemoryLimit: number | null = null;
21
-
22
- /*
23
- * This module provides the following functions to be exported:
24
- * checkAndClearMemory(bytes, [seriesUUIDs])
25
- * checkMemoryAllocation(bytes)
26
- * getUsedMemory()
27
- * getAvailableMemory()
28
- * setAvailableMemory()
29
- */
30
-
31
- /**
32
- * Check memory allocation and clear memory if needed
33
- * @instance
34
- * @function checkAndClearMemory
35
- * @param {Number} - Number of bytes to allocate
36
- * @param {Array} - Rendered Series ids
37
- */
38
- export const checkAndClearMemory = function (
39
- bytes: number,
40
- renderedSeriesIds: string[]
41
- ) {
42
- const isEnough = checkMemoryAllocation(bytes);
43
- if (isEnough === false) {
44
- const manager = getLarvitarManager();
45
- // get all key of manager and create a list
46
- const seriesIds = Object.keys(manager);
47
- // create a list of non rendered series ids
48
- const nonRenderedSeriesIds = seriesIds.filter(
49
- seriesId => !renderedSeriesIds.includes(seriesId)
50
- );
51
- // remove non rendered series from manager
52
- nonRenderedSeriesIds.forEach(seriesId => {
53
- removeSeriesFromLarvitarManager(seriesId);
54
- clearImageCache(seriesId);
55
- store.removeSeriesId(seriesId);
56
- });
57
- }
58
- };
59
-
60
- /**
61
- * Check memory allocation and returns false if js Heap size has reached its limit
62
- * @instance
63
- * @function checkMemoryAllocation
64
- * @param {Number} - Number of bytes to allocate
65
- * @return {Boolean} - Returns a boolean flag to warn the user about memory allocation limit
66
- */
67
- export const checkMemoryAllocation = function (bytes: number) {
68
- if (checkMemorySupport()) {
69
- let usedMemory = getUsedMemory();
70
- let availableMemory = getAvailableMemory();
71
- let isEnough = availableMemory - bytes - usedMemory > 0 ? true : false;
72
- if (!isEnough) {
73
- console.log("Total Memory Available is: ", getMB(availableMemory), " MB");
74
- console.log("Currently Used Memory is: ", getMB(usedMemory), " MB");
75
- console.log(
76
- "New memory requested allocation is: ",
77
- getMB(usedMemory + bytes),
78
- " MB"
79
- );
80
- }
81
- return isEnough;
82
- } else {
83
- console.warn("Check Memory Allocation is not supported");
84
- return true;
85
- }
86
- };
87
-
88
- /**
89
- * Check performance.memory browser support and returns used Js Heap Size in Mb
90
- * @instance
91
- * @function getUsedMemory
92
- * @return {Number} - Returns used JSHeapSize in bytes or NaN if not supported
93
- */
94
- export const getUsedMemory = function () {
95
- return checkMemorySupport()
96
- ? (performance as Performance).memory.usedJSHeapSize
97
- : NaN;
98
- };
99
-
100
- /**
101
- * Check performance.memory browser support and returns available Js Heap Size in Mb
102
- * @instance
103
- * @function getAvailableMemory
104
- * @return {Number} - Returns available JSHeapSize in bytes or NaN if not supported
105
- */
106
- export const getAvailableMemory = function () {
107
- if (checkMemorySupport()) {
108
- return customMemoryLimit
109
- ? customMemoryLimit
110
- : (performance as Performance).memory.jsHeapSizeLimit - backingMemory;
111
- } else {
112
- return NaN;
113
- }
114
- };
115
-
116
- /**
117
- * Check performance.memory browser support and returns available Js Heap Size in Mb
118
- * @instance
119
- * @function setAvailableMemory
120
- * @param {Number} - Number of GB to set as maximum custom memory limit
121
- */
122
- export const setAvailableMemory = function (value: number) {
123
- customMemoryLimit = value * 1024 * 1024 * 1024;
124
- };
125
-
126
- /* Internal module functions */
127
-
128
- /**
129
- * Check Browser support.
130
- * Firefox and Safari are not supported
131
- * See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory
132
- * @instance
133
- * @function checkMemorySupport
134
- * @return {Boolean} - Returns memory object or false if not supported
135
- */
136
- const checkMemorySupport = function () {
137
- return (performance as Performance).memory
138
- ? (performance as Performance).memory
139
- : false;
140
- };
141
-
142
- /**
143
- * Check Browser support.
144
- * @instance
145
- * @function getMB
146
- * @param {Number} bytes - Memory in bytes
147
- * @return {Number} - Memory in MB
148
- */
149
- const getMB = function (bytes: number) {
150
- return bytes / 1048576;
151
- };
@@ -1,34 +0,0 @@
1
- /** @module monitors/performance
2
- * @desc This file provides utility functions for
3
- * monitoring performance usage
4
- */
5
-
6
- var PERFORMANCE_MONITOR = false;
7
-
8
- /**
9
- * Get performance monitor
10
- * @instance
11
- * @function getPerformanceMonitor
12
- * @returns {Boolean} - Performance monitor status
13
- */
14
- export const getPerformanceMonitor = function () {
15
- return PERFORMANCE_MONITOR;
16
- };
17
-
18
- /**
19
- * Set performance monitor ON
20
- * @instance
21
- * @function activatePerformanceMonitor
22
- */
23
- export const activatePerformanceMonitor = function () {
24
- PERFORMANCE_MONITOR = true;
25
- };
26
-
27
- /**
28
- * Set performance monitor OFF
29
- * @instance
30
- * @function deactivatePerformanceMonitor
31
- */
32
- export const deactivatePerformanceMonitor = function () {
33
- PERFORMANCE_MONITOR = false;
34
- };
@@ -1,54 +0,0 @@
1
- /** @module imaging/parsers/ecg
2
- * @desc This file provides functionalities for
3
- * handling ECG signales in DICOM files
4
- */
5
-
6
- import { DataSet, Element } from "dicom-parser";
7
- import { getSeriesDataFromLarvitarManager } from "../loaders/commonLoader";
8
-
9
- /*
10
- * This module provides the following functions to be exported:
11
- * parseECG(dataSet, tag, nSampling)
12
- */
13
-
14
- /**
15
- * Generate an array of points representing the ECG signal
16
- * @instance
17
- * @function parseECG
18
- * @param {DataSet} dataSet - the DICOM dataset
19
- * @param {String} tag - the tag of the ECG signal
20
- * @param {Number} nSampling - the sampling rate
21
- * @returns {void}
22
- */
23
- export function parseECG(
24
- seriesId: string,
25
- dataSet: DataSet,
26
- tag: string,
27
- nSampling: number = 2
28
- ): void {
29
- const element: Element = dataSet.elements[tag];
30
- let data: Uint8Array = dataSet.byteArray.slice(
31
- element.dataOffset,
32
- element.dataOffset + element.length
33
- );
34
- let points: number[] = [];
35
- const nCountFrom: number = data.length / 2;
36
- const nCountTo: number = Math.floor(0.5 + nCountFrom / nSampling);
37
- let values: number[] = [];
38
- let nFrom: number = 0;
39
- for (let nTo: number = 0; nTo < nCountTo; nTo++) {
40
- let v: number = data[nFrom] + 255 * data[nFrom + 1];
41
- values.push(v);
42
- nFrom += nSampling * 2;
43
- }
44
-
45
- const nMax: number = Math.max(...values);
46
- const nMin: number = Math.min(...values);
47
-
48
- for (let nTo: number = 0; nTo < nCountTo; nTo++) {
49
- let data: number = ((values[nTo] - nMin) / (nMax - nMin)) * 100;
50
- points.push(data);
51
- }
52
- let series = getSeriesDataFromLarvitarManager(seriesId);
53
- series!.ecgData = points;
54
- }