dwv 0.37.0-beta.8 → 0.37.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.
Files changed (98) hide show
  1. package/dist/assets/workers/jpeg2000.worker.min.js +1 -1
  2. package/dist/assets/workers/jpeg2000.worker.min.js.map +1 -1
  3. package/dist/assets/workers/jpegbaseline.worker.min.js +1 -1
  4. package/dist/assets/workers/jpegbaseline.worker.min.js.map +1 -1
  5. package/dist/assets/workers/jpegloss.worker.min.js +1 -1
  6. package/dist/assets/workers/jpegloss.worker.min.js.map +1 -1
  7. package/dist/assets/workers/labeling.worker.min.js +1 -1
  8. package/dist/assets/workers/labeling.worker.min.js.map +1 -1
  9. package/dist/assets/workers/resampling.worker.min.js +1 -1
  10. package/dist/assets/workers/resampling.worker.min.js.map +1 -1
  11. package/dist/assets/workers/rle.worker.min.js +1 -1
  12. package/dist/assets/workers/rle.worker.min.js.map +1 -1
  13. package/dist/dwv.d.ts +1333 -314
  14. package/dist/dwv.min.js +1 -1
  15. package/dist/dwv.min.js.map +1 -1
  16. package/dist/dwv.node.min.js +1 -1
  17. package/dist/dwv.node.min.js.map +1 -1
  18. package/package.json +21 -23
  19. package/readme.md +7 -3
  20. package/dev/bench/bench.html +0 -94
  21. package/dev/bench/bench.js +0 -316
  22. package/dev/bench/benchFunctionRunner.js +0 -83
  23. package/dev/bench/dataRunner.js +0 -171
  24. package/dev/bench/gui.js +0 -184
  25. package/dev/bench/listen.js +0 -70
  26. package/dev/bench/parsers/dwv-current.html +0 -45
  27. package/dev/bench/parsers/dwv-previous.html +0 -45
  28. package/dev/dicom/binaryPixGenerator.js +0 -108
  29. package/dev/dicom/dicomGenerator.js +0 -215
  30. package/dev/dicom/filePixGenerator.js +0 -96
  31. package/dev/dicom/gradSquarePixGenerator.js +0 -107
  32. package/dev/dicom/mprPixGenerator.js +0 -247
  33. package/dev/dicom/pages/anonymiser.html +0 -86
  34. package/dev/dicom/pages/anonymiser.js +0 -154
  35. package/dev/dicom/pages/diff.html +0 -34
  36. package/dev/dicom/pages/diff.js +0 -97
  37. package/dev/dicom/pages/generator.html +0 -92
  38. package/dev/dicom/pages/generator.js +0 -329
  39. package/dev/dicom/pages/synthetic-data.html +0 -19
  40. package/dev/dicom/pages/synthetic-data.js +0 -164
  41. package/dev/dicom/squarePixGenerator.js +0 -233
  42. package/dev/favicon.ico +0 -0
  43. package/dev/image/pages/colourmaps.html +0 -16
  44. package/dev/image/pages/colourmaps.js +0 -65
  45. package/dev/index.html +0 -38
  46. package/dev/pacs/dcmweb.html +0 -80
  47. package/dev/pacs/dcmweb.js +0 -577
  48. package/dev/pacs/images/acute_leukemia.png +0 -0
  49. package/dev/pacs/images/babymri-dcmdir.png +0 -0
  50. package/dev/pacs/images/babymri-rect.png +0 -0
  51. package/dev/pacs/images/babymri-zip.png +0 -0
  52. package/dev/pacs/images/babymri.png +0 -0
  53. package/dev/pacs/images/brainmri-png.png +0 -0
  54. package/dev/pacs/images/brainpet-jpg.png +0 -0
  55. package/dev/pacs/images/cerebrix.png +0 -0
  56. package/dev/pacs/images/goudurix.png +0 -0
  57. package/dev/pacs/images/multiframe-test1.png +0 -0
  58. package/dev/pacs/images/toutatix.png +0 -0
  59. package/dev/pacs/images/us.png +0 -0
  60. package/dev/pacs/index.html +0 -97
  61. package/dev/pacs/index.js +0 -287
  62. package/dev/pacs/overlays.js +0 -51
  63. package/dev/pacs/viewer.html +0 -401
  64. package/dev/pacs/viewer.js +0 -1275
  65. package/dev/pacs/viewer.rendertest.js +0 -96
  66. package/dev/pacs/viewer.ui.annot.js +0 -607
  67. package/dev/pacs/viewer.ui.brush.js +0 -181
  68. package/dev/pacs/viewer.ui.datatable.js +0 -674
  69. package/dev/pacs/viewer.ui.draw.js +0 -141
  70. package/dev/pacs/viewer.ui.icons.js +0 -88
  71. package/dev/pacs/viewer.ui.js +0 -198
  72. package/dev/pacs/viewer.ui.segment.js +0 -1369
  73. package/dev/visual/appgui.js +0 -125
  74. package/dev/visual/images/dicompyler-ct.0.jpg +0 -0
  75. package/dev/visual/images/gdcm-CR-MONO1-10-chest.jpg +0 -0
  76. package/dev/visual/images/gdcm-CT-MONO2-8-abdo.jpg +0 -0
  77. package/dev/visual/images/gdcm-US-RGB-8-epicard.jpg +0 -0
  78. package/dev/visual/images/gdcm-US-RGB-8-esopecho.jpg +0 -0
  79. package/dev/visual/images/leadtools-8BitsJpegLossyGrayScale.jpg +0 -0
  80. package/dev/visual/images/leadtools-flowers-16-mono2-rle.jpg +0 -0
  81. package/dev/visual/images/leadtools-flowers-8-mono2-rle.jpg +0 -0
  82. package/dev/visual/images/nema-ct1_j2ki.jpg +0 -0
  83. package/dev/visual/images/nema-ct1_jpll.jpg +0 -0
  84. package/dev/visual/images/nema-mr1_jply.jpg +0 -0
  85. package/dev/visual/images/nema-nm1_j2kr.jpg +0 -0
  86. package/dev/visual/images/nema-nm1_jpll.jpg +0 -0
  87. package/dev/visual/images/nema-nm1_jply.jpg +0 -0
  88. package/dev/visual/images/nema-us1_j2ki.jpg +0 -0
  89. package/dev/visual/images/nema-vl2_j2kr.jpg +0 -0
  90. package/dev/visual/images/osirix-cerebrix.jpg +0 -0
  91. package/dev/visual/images/osirix-goudurix.jpg +0 -0
  92. package/dev/visual/images/osirix-toutatix-100.jpg +0 -0
  93. package/dev/visual/index-jpeg.js +0 -104
  94. package/dev/visual/index-jpeg2000.js +0 -103
  95. package/dev/visual/index-rle.js +0 -70
  96. package/dev/visual/index.html +0 -20
  97. package/dev/visual/index.js +0 -123
  98. package/dev/visual/style.css +0 -37
@@ -1,96 +0,0 @@
1
- /**
2
- * Setup test line.
3
- *
4
- * @param {object} app The associated application.
5
- */
6
- export function setupRenderTests(app) {
7
- const renderTestButton = document.createElement('button');
8
- renderTestButton.onclick = getRunRenderTest(app);
9
- renderTestButton.appendChild(document.createTextNode('render test'));
10
-
11
- const testsDiv = document.getElementById('tests');
12
- testsDiv.appendChild(renderTestButton);
13
- };
14
-
15
- /**
16
- * Run render tests.
17
- *
18
- * @param {object} app The associated application.
19
- * @returns {Function} The run render text function.
20
- */
21
- function getRunRenderTest(app) {
22
- return function () {
23
- const numberOfRun = 20;
24
- const stgCtrl = app.getStageController();
25
- // default to first layer group
26
- stgCtrl.setActiveLayerGroup(0);
27
-
28
- const vl = stgCtrl.getActiveLayerGroup().getActiveViewLayer();
29
- if (typeof vl === 'undefined') {
30
- return;
31
- }
32
- const vc = vl.getViewController();
33
- const runner = function () {
34
- vc.getPositionHelper().incrementPositionAlongScroll();
35
- };
36
-
37
- let startTime;
38
- const timings = [];
39
- const onRenderStart = function (/*event*/) {
40
- startTime = performance.now();
41
- };
42
- const onRenderEnd = function (/*event*/) {
43
- const endTime = performance.now();
44
- timings.push(endTime - startTime);
45
-
46
- if (timings.length < numberOfRun) {
47
- setTimeout(() => {
48
- runner();
49
- }, 100);
50
- } else {
51
- console.log('Stats:', getBasicStats(timings));
52
- // clean up
53
- app.removeEventListener('renderstart', onRenderStart);
54
- app.removeEventListener('renderend', onRenderEnd);
55
- }
56
- };
57
-
58
- // setup
59
- app.addEventListener('renderstart', onRenderStart);
60
- app.addEventListener('renderend', onRenderEnd);
61
-
62
- // start
63
- runner();
64
- };
65
- }
66
-
67
- /**
68
- * Get basic stats for an array.
69
- *
70
- * @param {Array} array Input array.
71
- * @returns {object} Min, max, mean and standard deviation.
72
- */
73
- function getBasicStats(array) {
74
- let min = array[0];
75
- let max = min;
76
- let sum = 0;
77
- let sumSqr = 0;
78
- const length = array.length;
79
- for (let i = 0; i < length; ++i) {
80
- const val = array[i];
81
- if (val < min) {
82
- min = val;
83
- } else if (val > max) {
84
- max = val;
85
- }
86
- sum += val;
87
- sumSqr += val * val;
88
- }
89
-
90
- const mean = sum / length;
91
- // see http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
92
- const variance = sumSqr / length - mean * mean;
93
- const stdDev = Math.sqrt(variance);
94
-
95
- return {min, max, mean, stdDev};
96
- }
@@ -1,607 +0,0 @@
1
- import {DrawController} from '../../src/app/drawController.js';
2
- import {
3
- AnnotationGroupFactory
4
- } from '../../src/image/annotationGroupFactory.js';
5
- import {
6
- getUID,
7
- DicomWriter
8
- } from '../../src/dicom/dicomWriter.js';
9
- import {i18n} from '../../src/utils/i18n.js';
10
- import {
11
- getIconElement,
12
- getButton,
13
- setButtonPressed,
14
- isButtonPressed
15
- } from './viewer.ui.icons.js';
16
-
17
- /**
18
- * @import {App} from '../../src/app/application.js';
19
- * @import {Annotation} from '../../src/image/annotation.js';
20
- * @import {AnnotationGroup} from '../../src/image/annotationGroup.js';
21
- */
22
-
23
- /**
24
- * Get the annotation group divId.
25
- *
26
- * @param {string} dataId The data ID.
27
- * @returns {string} The divId.
28
- */
29
- function getAnnotationGroupDivId(dataId) {
30
- return `annotationgroup${dataId}`;
31
- }
32
-
33
- /**
34
- * Get the annotation divId.
35
- *
36
- * @param {Annotation} annotation The annotation.
37
- * @param {string} dataId The data ID.
38
- * @returns {string} The divId.
39
- */
40
- function getAnnotationDivId(annotation, dataId) {
41
- const prefix = getAnnotationGroupDivId(dataId);
42
- const suffix = `annotation${annotation.trackingUid}`;
43
- return `${prefix}-${suffix}`;
44
- }
45
-
46
- /**
47
- * Split a divId to get dataId and annotationId.
48
- *
49
- * @param {string} divId The divId.
50
- * @returns {object} The data and annotation ID.
51
- */
52
- function splitAnnotationDivId(divId) {
53
- const split = divId.split('-');
54
- const prefixStrSize = 'annotationgroup'.length;
55
- const suffixStrSize = 'annotation'.length;
56
- return {
57
- dataId: split[0].substring(prefixStrSize),
58
- annotationId: split[1].substring(suffixStrSize)
59
- };
60
- }
61
-
62
- /**
63
- * Annotation UI.
64
- */
65
- export class AnnotationUI {
66
-
67
- /**
68
- * The associated application.
69
- *
70
- * @type {App}
71
- */
72
- #app;
73
-
74
- /**
75
- * The root document.
76
- *
77
- * @type {Document}
78
- */
79
- #rootDoc = document;
80
-
81
- /**
82
- * @param {App} app The associated application.
83
- * @param {Document} [rootDoc] Optional root document,
84
- * defaults to `window.document`.
85
- */
86
- constructor(app, rootDoc) {
87
- this.#app = app;
88
- if (typeof rootDoc !== 'undefined') {
89
- this.#rootDoc = rootDoc;
90
- }
91
- }
92
-
93
- /**
94
- * Bind app to ui.
95
- */
96
- registerListeners() {
97
- this.#app.addEventListener('dataadd', this.#onDataAdd);
98
- this.#app.addEventListener('drawlayeradd', this.#onDrawLayerAdd);
99
- this.#app.addEventListener('annotationadd', this.#onAnnotationAdd);
100
- this.#app.addEventListener('annotationupdate', this.#onAnnotationUpdate);
101
- this.#app.addEventListener('annotationremove', this.#onAnnotationRemove);
102
- };
103
-
104
- /**
105
- * Setup the container div.
106
- */
107
- #setupContainerDiv() {
108
- // fieldset
109
- const legend = document.createElement('legend');
110
- legend.appendChild(document.createTextNode('Annotation Groups'));
111
-
112
- const fieldset = document.createElement('fieldset');
113
- fieldset.id = 'annotationgroups-fieldset';
114
- fieldset.appendChild(legend);
115
-
116
- // main div
117
- const line = document.createElement('div');
118
- line.id = 'annotationgroups-line';
119
- line.className = 'line';
120
- line.appendChild(fieldset);
121
-
122
- // insert
123
- const detailsEl = this.#rootDoc.getElementById('layersdetails');
124
- detailsEl.parentElement.insertBefore(line, detailsEl);
125
- }
126
-
127
- /**
128
- * Get the container div.
129
- *
130
- * @returns {HTMLDivElement} The element.
131
- */
132
- #getContainerDiv() {
133
- return this.#rootDoc.getElementById('annotationgroups-fieldset');
134
- }
135
-
136
- /**
137
- * Setup the html for the annotation list.
138
- */
139
- #setupHtml() {
140
- // add annotation group button
141
- const addItem = document.createElement('li');
142
- addItem.id = 'addannotationgroupitem';
143
- const addAnnotationGroupButton = document.createElement('button');
144
- addAnnotationGroupButton.appendChild(
145
- document.createTextNode('Add annotation group'));
146
- addAnnotationGroupButton.onclick = () => {
147
- const divId = 'layerGroup0';
148
- const stgCtrl = this.#app.getStageController();
149
- const layerGroup = stgCtrl.getLayerGroupByDivId(divId);
150
- // add annotation group
151
- const viewLayer = layerGroup.getActiveViewLayer();
152
- if (typeof viewLayer === 'undefined') {
153
- console.warn(
154
- 'No active view layer, please select one in the data table'
155
- );
156
- return;
157
- }
158
- const refDataId = viewLayer.getDataId();
159
- const data = this.#app.createAnnotationData(refDataId);
160
- // render (will create draw layer)
161
- this.#app.addAndRenderAnnotationData(data, divId, refDataId);
162
- // item is added to the UI by the 'dataadd' listener
163
- };
164
- addItem.appendChild(addAnnotationGroupButton);
165
-
166
- // annotation list
167
- const annotList = document.createElement('ul');
168
- annotList.id = 'annotationgroup-list';
169
- annotList.className = 'data-list';
170
- annotList.appendChild(addItem);
171
-
172
- // setup and append
173
- this.#setupContainerDiv();
174
- this.#getContainerDiv().appendChild(annotList);
175
- }
176
-
177
- /**
178
- * Get the annotation html.
179
- *
180
- * @param {Annotation} annotation The annotation.
181
- * @param {string} dataId The annotation group dataId.
182
- * @returns {HTMLLIElement} The HTMl element.
183
- */
184
- #getAnnotationHtml(annotation, dataId) {
185
- const annotationDivId = getAnnotationDivId(annotation, dataId);
186
- const dataCtrl = this.#app.getDataController();
187
- const undoCtrl = this.#app.getUndoController();
188
-
189
- const infoButton = getButton('Info');
190
- const ibIdPrefix = 'ib-';
191
- infoButton.id = ibIdPrefix + annotationDivId;
192
- infoButton.title = 'Information';
193
- infoButton.onclick = (event) => {
194
- // do not propagate to parent that triggers goto
195
- event.stopPropagation();
196
- const target = event.target;
197
- // get annotatio
198
- const indices =
199
- splitAnnotationDivId(target.id.substring(vbIdPrefix.length));
200
- const clkDataId = indices.dataId;
201
- const annotationId = indices.annotationId;
202
- const annotationGroup = dataCtrl.get(clkDataId).annotationGroup;
203
- const clkAnnotation = annotationGroup.find(annotationId);
204
-
205
- let qStr = 'Quantification:\n';
206
- if (typeof clkAnnotation.quantification !== 'undefined') {
207
- const keys = Object.keys(clkAnnotation.quantification);
208
- for (const key of keys) {
209
- const quant = clkAnnotation.quantification[key];
210
- qStr += `- ${key}: ${quant.value.toPrecision(4)}`;
211
- if (typeof quant.unit !== 'undefined') {
212
- qStr += i18n.t(quant.unit);
213
- }
214
- qStr += '\n';
215
- }
216
- } else {
217
- qStr = 'No quantification.';
218
- }
219
- alert(qStr);
220
- };
221
-
222
- const inputColour = document.createElement('input');
223
- inputColour.type = 'color';
224
- inputColour.title = 'Change annotation colour';
225
- const inputColourPrefix = 'cb-';
226
- inputColour.id = inputColourPrefix + annotationDivId;
227
- inputColour.value = annotation.colour;
228
- inputColour.onclick = (event) => {
229
- // do not propagate to parent that triggers goto
230
- event.stopPropagation();
231
- };
232
- inputColour.onchange = (event) => {
233
- const target = event.target;
234
- const newColour = target.value;
235
- // get annotation
236
- const indices =
237
- splitAnnotationDivId(target.id.substring(inputColourPrefix.length));
238
- const chgDataId = indices.dataId;
239
- const annotationId = indices.annotationId;
240
- const annotationGroup = dataCtrl.get(chgDataId).annotationGroup;
241
- const chgAnnotation = annotationGroup.find(annotationId);
242
- // update
243
- if (newColour !== chgAnnotation.colour) {
244
- const drawController = new DrawController(annotationGroup);
245
- drawController.updateAnnotationWithCommand(
246
- annotationId,
247
- {colour: chgAnnotation.colour},
248
- {colour: newColour},
249
- undoCtrl.addToUndoStack
250
- );
251
- }
252
- };
253
-
254
- const viewButton = getButton('View');
255
- setButtonPressed(viewButton, false);
256
- const vbIdPrefix = 'vb-';
257
- viewButton.id = vbIdPrefix + annotationDivId;
258
- viewButton.title = 'Show/hide annotation';
259
- viewButton.onclick = (event) => {
260
- // do not propagate to parent (triggers goto)
261
- event.stopPropagation();
262
- const target = event.target;
263
- // get annotatio
264
- const indices =
265
- splitAnnotationDivId(target.id.substring(vbIdPrefix.length));
266
- const clkDataId = indices.dataId;
267
- const annotationId = indices.annotationId;
268
- const drawLayers =
269
- this.#app.getStageController().getDrawLayersByDataId(clkDataId);
270
- // toggle hidden
271
- if (isButtonPressed(target)) {
272
- setButtonPressed(target, false);
273
- for (const layer of drawLayers) {
274
- layer.setAnnotationVisibility(annotationId, true);
275
- }
276
- } else {
277
- setButtonPressed(target, true);
278
- for (const layer of drawLayers) {
279
- layer.setAnnotationVisibility(annotationId, false);
280
- }
281
- }
282
- };
283
-
284
- const deleteButton = getButton('Delete');
285
- const dbIdPrefix = 'db-';
286
- deleteButton.id = dbIdPrefix + annotationDivId;
287
- deleteButton.title = 'Delete annotation';
288
- deleteButton.onclick = (event) => {
289
- // do not propagate to parent (triggers goto)
290
- event.stopPropagation();
291
- const target = event.target;
292
- // get segment and mask
293
- const indices =
294
- splitAnnotationDivId(target.id.substring(dbIdPrefix.length));
295
- const clkDataId = indices.dataId;
296
- const annotationId = indices.annotationId;
297
- // delete if possible
298
- const drawController = new DrawController(
299
- dataCtrl.get(clkDataId).annotationGroup);
300
- // TODO reposition div at same position after delete undo?
301
- drawController.removeAnnotationWithCommand(
302
- annotationId,
303
- undoCtrl.addToUndoStack
304
- );
305
- };
306
-
307
- // disable/enable buttons if group is editable or not
308
- const annotationGroup = dataCtrl.get(dataId).annotationGroup;
309
- annotationGroup.addEventListener(
310
- 'annotationgroupeditablechange', function (event) {
311
- const disabled = !event.detail.data;
312
- inputColour.disabled = disabled;
313
- deleteButton.disabled = disabled;
314
- }
315
- );
316
-
317
- // content
318
- const contentDiv = document.createElement('div');
319
- contentDiv.className = 'data-item-list-item-content';
320
- let factoryName = 'unknown';
321
- if (typeof annotation.getFactory() !== 'undefined') {
322
- factoryName = annotation.getFactory().getName();
323
- }
324
- contentDiv.appendChild(getIconElement(factoryName));
325
- contentDiv.appendChild(document.createTextNode(
326
- ` ${annotation.trackingId}`));
327
-
328
- // actions
329
- const actionsDiv = document.createElement('div');
330
- actionsDiv.className = 'data-item-list-item-actions';
331
- actionsDiv.appendChild(infoButton);
332
- actionsDiv.appendChild(inputColour);
333
- actionsDiv.appendChild(viewButton);
334
- actionsDiv.appendChild(deleteButton);
335
-
336
- // list item
337
- const item = document.createElement('li');
338
- item.id = annotationDivId;
339
- item.className = 'data-item-list-item';
340
- item.appendChild(contentDiv);
341
- item.appendChild(actionsDiv);
342
- item.title = 'Go to annotation';
343
-
344
- // click on li to go to annotation
345
- item.addEventListener('click', (event) => {
346
- const target = event.currentTarget;
347
-
348
- // remove selected class from other rows
349
- const mainlist = this.#rootDoc.getElementById('annotationgroup-list');
350
- const items = mainlist.querySelectorAll('.data-item-list-item');
351
- items.forEach(item2 => item2.classList.remove('selected'));
352
- // mark this row as selected
353
- target.classList.add('selected');
354
-
355
- // get annotation
356
- const indices = splitAnnotationDivId(target.id);
357
- const clkDataId = indices.dataId;
358
- const annotationId = indices.annotationId;
359
- const clkAnnotationGroup = dataCtrl.get(clkDataId).annotationGroup;
360
- const clkAnnotation = clkAnnotationGroup.find(annotationId);
361
- const annotCentroid = clkAnnotation.getCentroid();
362
- if (typeof annotCentroid !== 'undefined') {
363
- const drawLayers =
364
- this.#app.getStageController().getDrawLayersByDataId(clkDataId);
365
- for (const layer of drawLayers) {
366
- layer.setCurrentPosition(annotCentroid);
367
- }
368
- } else {
369
- console.log('No centroid for annotation');
370
- }
371
- });
372
-
373
- return item;
374
- }
375
-
376
- /**
377
- * Get an annotation group html.
378
- *
379
- * @param {AnnotationGroup} annotationGroup The annotation group.
380
- * @param {string} dataId The annotation group dataId.
381
- * @returns {HTMLIement} The annotation list element.
382
- */
383
- #getAnnotationGroupHtml(annotationGroup, dataId) {
384
- // name
385
- const nameDiv = document.createElement('span');
386
- nameDiv.id = `${getAnnotationGroupDivId(dataId)}-name`;
387
- nameDiv.className = 'data-item-name';
388
- nameDiv.appendChild(document.createTextNode(`group #${dataId}`));
389
-
390
- // lock button
391
- const lockButton = getButton('Lock');
392
- setButtonPressed(lockButton, false);
393
- lockButton.id = `lockb-${getAnnotationGroupDivId(dataId)}`;
394
- lockButton.onclick = function (event) {
395
- const target = event.target;
396
- // toggle hidden
397
- if (isButtonPressed(target)) {
398
- setButtonPressed(target, false);
399
- if (typeof annotationGroup !== 'undefined') {
400
- annotationGroup.setEditable(true);
401
- }
402
- } else {
403
- setButtonPressed(target, true);
404
- if (typeof annotationGroup !== 'undefined') {
405
- annotationGroup.setEditable(false);
406
- }
407
- }
408
- };
409
-
410
- // save button
411
- const saveButton = getButton('Save');
412
- saveButton.title = 'Save annnotation group';
413
- saveButton.onclick = function () {
414
- const factory = new AnnotationGroupFactory();
415
- const sopUID = getUID('SOPInstanceUID');
416
- const extraTags = {
417
- MediaStorageSOPInstanceUID: sopUID,
418
- SOPInstanceUID: sopUID,
419
- InstanceNumber: 123,
420
- SeriesInstanceUID: getUID('SeriesInstanceUID'),
421
- SeriesNumber: 123,
422
- SeriesDescription: 'Annnotation made with dwv',
423
- };
424
- const dicomElements = factory.toDicom(annotationGroup, extraTags);
425
- // write
426
- const writer = new DicomWriter();
427
- let dicomBuffer = null;
428
- try {
429
- dicomBuffer = writer.getBuffer(dicomElements);
430
- } catch (error) {
431
- console.error(error);
432
- alert(error.message);
433
- }
434
- const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
435
- saveButton.href = window.URL.createObjectURL(blob);
436
-
437
- // temporary link to download
438
- const element = document.createElement('a');
439
- element.href = window.URL.createObjectURL(blob);
440
- element.download = `dicom-sr-${dataId}.dcm`;
441
- // trigger download
442
- element.click();
443
- URL.revokeObjectURL(element.href);
444
- };
445
-
446
- // hide button
447
- const hideLabelsButton = getButton('Label');
448
- setButtonPressed(hideLabelsButton, false);
449
- hideLabelsButton.id = 'b-hidelabels';
450
- hideLabelsButton.title = 'Show/hide annotation labels';
451
- hideLabelsButton.onclick = (event) => {
452
- const target = event.target;
453
- const drawLayer =
454
- this.#app.getStageController().getDrawLayersByDataId(dataId)[0];
455
- if (typeof drawLayer === 'undefined') {
456
- console.warn(`Cannot find draw layer with id ${dataId}`);
457
- }
458
- if (isButtonPressed(target)) {
459
- setButtonPressed(target, false);
460
- drawLayer.setLabelsVisibility(true);
461
- } else {
462
- setButtonPressed(target, true);
463
- drawLayer.setLabelsVisibility(false);
464
- }
465
- };
466
-
467
- // actions
468
- const actionGroupDiv = document.createElement('div');
469
- actionGroupDiv.id = `${getAnnotationGroupDivId(dataId)}-actions`;
470
- actionGroupDiv.className = 'data-item-actions';
471
- actionGroupDiv.appendChild(lockButton);
472
- actionGroupDiv.appendChild(saveButton);
473
- actionGroupDiv.appendChild(hideLabelsButton);
474
-
475
- // annotation list
476
- const listDiv = document.createElement('ul');
477
- listDiv.id = `${getAnnotationGroupDivId(dataId)}-list`;
478
- listDiv.className = 'data-item-list';
479
- for (const annotation of annotationGroup.getList()) {
480
- listDiv.appendChild(this.#getAnnotationHtml(annotation, dataId));
481
- }
482
-
483
- // data-item-header
484
- const headerDiv = document.createElement('div');
485
- headerDiv.id = `${getAnnotationGroupDivId(dataId)}-header`;
486
- headerDiv.className = 'data-item-header';
487
- headerDiv.appendChild(nameDiv);
488
- headerDiv.appendChild(actionGroupDiv);
489
-
490
- // data-item-content
491
- const contentDiv = document.createElement('div');
492
- contentDiv.id = `${getAnnotationGroupDivId(dataId)}-content`;
493
- contentDiv.className = 'data-item-content';
494
- contentDiv.appendChild(listDiv);
495
-
496
- // data-item
497
- const item = document.createElement('li');
498
- item.id = getAnnotationGroupDivId(dataId);
499
- item.className = 'data-item';
500
- item.appendChild(headerDiv);
501
- item.appendChild(contentDiv);
502
-
503
- return item;
504
- };
505
-
506
- /**
507
- * Handle 'dataadd' event.
508
- *
509
- * @param {CustomEvent} event The event.
510
- */
511
- #onDataAdd = (event) => {
512
- const dataId = event.detail.dataid;
513
- const dataCtrl = this.#app.getDataController();
514
- const data = dataCtrl.get(dataId);
515
- const ag = data.annotationGroup;
516
- if (typeof ag !== 'undefined') {
517
- // setup html if needed
518
- if (!this.#rootDoc.getElementById('annotationgroup-list')) {
519
- this.#setupHtml();
520
- }
521
- // annotation group as html
522
- const item = this.#getAnnotationGroupHtml(ag, event.detail.dataid);
523
- // add annotation group item
524
- const addItem = this.#rootDoc.getElementById('addannotationgroupitem');
525
- // remove and add after to make it last item
526
- addItem.remove();
527
-
528
- // update list
529
- const annotList = this.#rootDoc.getElementById('annotationgroup-list');
530
- annotList.appendChild(item);
531
- annotList.appendChild(addItem);
532
- }
533
- };
534
-
535
- /**
536
- * Handle 'drawlayeradd' event.
537
- *
538
- * @param {CustomEvent} event The event.
539
- */
540
- #onDrawLayerAdd = (event) => {
541
- const dataId = event.detail.dataid;
542
- const dataCtrl = this.#app.getDataController();
543
- const annotationGroup = dataCtrl.get(dataId).annotationGroup;
544
- // strike through non viewable annotations
545
- for (const annotation of annotationGroup.getList()) {
546
- let textDecoration = '';
547
- if (!annotation.canView()) {
548
- textDecoration = 'line-through';
549
- }
550
- const annotationDivId = getAnnotationDivId(annotation, dataId);
551
- const item = this.#rootDoc.getElementById(annotationDivId);
552
- if (item) {
553
- item.style['text-decoration-line'] = textDecoration;
554
- }
555
- }
556
- };
557
-
558
- /**
559
- * Handle 'annotationadd' event.
560
- *
561
- * @param {CustomEvent} event The event.
562
- */
563
- #onAnnotationAdd = (event) => {
564
- const annotation = event.detail.data;
565
- const dataId = event.detail.dataid;
566
- // add item to list
567
- const listDivId = `${getAnnotationGroupDivId(dataId)}-list`;
568
- const listDiv = this.#rootDoc.getElementById(listDivId);
569
- listDiv.appendChild(this.#getAnnotationHtml(annotation, dataId));
570
- };
571
-
572
- /**
573
- * Handle 'annotationupdate' event.
574
- *
575
- * @param {CustomEvent} event The event.
576
- */
577
- #onAnnotationUpdate = (event) => {
578
- const annotation = event.detail.data;
579
- const dataId = event.detail.dataid;
580
- const keys = event.detail.keys;
581
-
582
- if (typeof keys !== 'undefined') {
583
- const annotationDivId = getAnnotationDivId(annotation, dataId);
584
- // update colour input
585
- if (keys.includes('colour')) {
586
- const inputColour = this.#rootDoc.getElementById(
587
- `cb-${annotationDivId}`);
588
- inputColour.value = annotation.colour;
589
- }
590
- }
591
- };
592
-
593
- /**
594
- * Handle 'annotationremove' event.
595
- *
596
- * @param {CustomEvent} event The event.
597
- */
598
- #onAnnotationRemove = (event) => {
599
- const annotation = event.detail.data;
600
- const dataId = event.detail.dataid;
601
- // remove annotation from list
602
- const annotationDivId = getAnnotationDivId(annotation, dataId);
603
- const item = this.#rootDoc.getElementById(annotationDivId);
604
- item.remove();
605
- };
606
-
607
- }; // AnnotationUI