dwv 0.35.0-beta.21 → 0.35.0-beta.23

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.
@@ -0,0 +1 @@
1
+ class LabelingWorker{#t;#n;#i;constructor(){}#e(t){if(t<0)return t;let n=t;for(;this.#n[n]!==n;)n=this.#n[n];let i=t;for(;this.#n[i]!==i;){const t=this.#n[i];this.#n[i]=n,i=t}return n}#s(t,n){this.#n[this.#e(t)]=this.#e(n)}regenerateLabels(t,n,i,e){void 0!==this.#t&&this.#t===e||(this.#t=e,this.#n=new Int32Array(e),this.#i=new Int32Array(e));for(let e=0;e<i[0];e++)for(let s=0;s<i[1];s++)for(let l=0;l<i[2];l++){const i=n[0]*e+n[1]*s+n[2]*l;this.#n[i]=i,this.#i[i]=-1;const o=t[i];if(o>0){const a=i-n[0],r=i-n[1],h=i-n[2];let u=0;e>0&&(u=t[a]);let d=0;s>0&&(d=t[r]);let f=0;l>0&&(f=t[h]);let b=0;e>0&&(b=this.#i[a]);let c=0;s>0&&(c=this.#i[r]);let g=0;l>0&&(g=this.#i[h]),u!==o&&d!==o&&f!==o?this.#i[i]=i:u===o&&d!==o&&f!==o?this.#i[i]=this.#e(b):u!==o&&d===o&&f!==o?this.#i[i]=this.#e(c):u!==o&&d!==o&&f===o?this.#i[i]=this.#e(g):u!==o&&d===o&&f===o?(this.#s(c,g),this.#i[i]=this.#e(c)):u===o&&d!==o&&f===o?(this.#s(b,g),this.#i[i]=this.#e(b)):u===o&&d===o&&f!==o?(this.#s(b,c),this.#i[i]=this.#e(b)):u===o&&d===o&&f===o&&(this.#s(b,c),this.#s(b,g),this.#i[i]=this.#e(b))}}}#l(t,n){const i=new Array(n.length);let e=t,s=0;for(let t=n.length-1;t>0;--t)s=n[t],i[t]=Math.floor(e/s),e-=i[t]*s;return i[0]=e,i}#o(t,n){const i={};for(let e=0;e<this.#i.length;e++){const s=this.#e(this.#i[e]);if(s>=0){const l=this.#l(e,n),o=i[s];void 0===o?i[s]={id:t[e],sum:l,count:1}:(o.sum[0]+=l[0],o.sum[1]+=l[1],o.sum[2]+=l[2],o.count++)}}return Object.values(i).map((t=>{const n=Array(t.sum.length).fill(0);for(let i=0;i<t.sum.length;i++)n[i]=t.sum[i]/t.count;return{id:t.id,centroidIndex:n,count:t.count}}))}calculateFromEvent(t){const n=t.imageBuffer,i=t.unitVectors,e=t.sizes,s=t.totalSize;return this.regenerateLabels(n,i,e,s),this.#o(n,i)}}const labelingWorker=new LabelingWorker;"undefined"==typeof window||window!==window.window?self.addEventListener("message",(function(t){self.postMessage({labels:labelingWorker.calculateFromEvent(t.data)})})):self.labelingWorker=labelingWorker;
package/dist/dwv.d.ts CHANGED
@@ -17,19 +17,37 @@ export declare function addTagsToDictionary(group: string, tags: {
17
17
  */
18
18
  export declare class Annotation {
19
19
  /**
20
- * The ID.
20
+ * Tracking id, unique within domain.
21
21
  *
22
22
  * @type {string}
23
23
  */
24
- id: string;
24
+ trackingId: string;
25
25
  /**
26
- * The reference image SOP UID.
26
+ * Tracking Unique id.
27
27
  *
28
28
  * @type {string}
29
29
  */
30
- referenceSopUID: string;
30
+ trackingUid: string;
31
31
  /**
32
- * The mathematical shape.
32
+ * Referenced image SOP isntance UID.
33
+ *
34
+ * @type {string}
35
+ */
36
+ referencedSopInstanceUID: string;
37
+ /**
38
+ * Referenced image SOP class UID.
39
+ *
40
+ * @type {string}
41
+ */
42
+ referencedSopClassUID: string;
43
+ /**
44
+ * Referenced frame number.
45
+ *
46
+ * @type {number|undefined}
47
+ */
48
+ referencedFrameNumber: number | undefined;
49
+ /**
50
+ * Mathematical shape.
33
51
  *
34
52
  * @type {object}
35
53
  */
@@ -41,11 +59,11 @@ export declare class Annotation {
41
59
  */
42
60
  referencePoints: Point2D[] | undefined;
43
61
  /**
44
- * The color: for example 'green', '#00ff00' or 'rgb(0,255,0)'.
62
+ * Colour: for example 'green', '#00ff00' or 'rgb(0,255,0)'.
45
63
  *
46
- * @type {string|undefined}
64
+ * @type {string}
47
65
  */
48
- colour: string | undefined;
66
+ colour: string;
49
67
  /**
50
68
  * Annotation quantification.
51
69
  *
@@ -54,11 +72,11 @@ export declare class Annotation {
54
72
  quantification: object | undefined;
55
73
  /**
56
74
  * Text expression. Can contain variables surrounded with '{}' that will
57
- * be extracted from the quantification object.
75
+ * be extracted from the quantification object.
58
76
  *
59
- * @type {string|undefined}
77
+ * @type {string}
60
78
  */
61
- textExpr: string | undefined;
79
+ textExpr: string;
62
80
  /**
63
81
  * Label position. If undefined, the default shape
64
82
  * label position will be used.
@@ -67,7 +85,7 @@ export declare class Annotation {
67
85
  */
68
86
  labelPosition: Point2D | undefined;
69
87
  /**
70
- * The plane origin, the 3D position of index [0, 0, k].
88
+ * Plane origin: 3D position of index [0, 0, k].
71
89
  *
72
90
  * @type {Point3D|undefined}
73
91
  */
@@ -78,6 +96,10 @@ export declare class Annotation {
78
96
  * @type {Point3D[]|undefined}
79
97
  */
80
98
  planePoints: Point3D[] | undefined;
99
+ /**
100
+ * Set the annotation id and uid.
101
+ */
102
+ setIds(): void;
81
103
  /**
82
104
  * Get the concepts ids of the annotation meta data.
83
105
  *
@@ -96,9 +118,9 @@ export declare class Annotation {
96
118
  * Add annotation meta data.
97
119
  *
98
120
  * @param {DicomCode} concept The concept code.
99
- * @param {DicomCode} value The value code.
121
+ * @param {DicomCode|string} value The value code.
100
122
  */
101
- addMetaItem(concept: DicomCode, value: DicomCode): void;
123
+ addMetaItem(concept: DicomCode, value: DicomCode | string): void;
102
124
  /**
103
125
  * Remove an annotation meta data.
104
126
  *
@@ -118,6 +140,13 @@ export declare class Annotation {
118
140
  * @param {ViewController} viewController The associated view controller.
119
141
  */
120
142
  init(viewController: ViewController): void;
143
+ /**
144
+ * Check if the annotation can be displayed: true if it has
145
+ * an associated view controller.
146
+ *
147
+ * @returns {boolean} True if the annotation can be displayed.
148
+ */
149
+ canView(): boolean;
121
150
  /**
122
151
  * Check if an input view is compatible with the annotation.
123
152
  *
@@ -227,9 +256,9 @@ export declare class AnnotationGroup {
227
256
  /**
228
257
  * Remove an annotation.
229
258
  *
230
- * @param {string} id The id of the annotation to remove.
259
+ * @param {string} uid The UID of the annotation to remove.
231
260
  */
232
- remove(id: string): void;
261
+ remove(uid: string): void;
233
262
  /**
234
263
  * Set the associated view controller.
235
264
  *
@@ -239,10 +268,10 @@ export declare class AnnotationGroup {
239
268
  /**
240
269
  * Find an annotation.
241
270
  *
242
- * @param {string} id The id of the annotation to find.
271
+ * @param {string} uid The UID of the annotation to find.
243
272
  * @returns {Annotation|undefined} The found annotation.
244
273
  */
245
- find(id: string): Annotation | undefined;
274
+ find(uid: string): Annotation | undefined;
246
275
  /**
247
276
  * Get the meta data.
248
277
  *
@@ -262,9 +291,9 @@ export declare class AnnotationGroup {
262
291
  * Get a meta data value.
263
292
  *
264
293
  * @param {string} key The meta data key.
265
- * @returns {string|object} The meta data value.
294
+ * @returns {string|object|undefined} The meta data value.
266
295
  */
267
- getMetaValue(key: string): string | object;
296
+ getMetaValue(key: string): string | object | undefined;
268
297
  /**
269
298
  * Set a meta data.
270
299
  *
@@ -323,7 +352,8 @@ export declare class AnnotationGroupFactory {
323
352
  [x: string]: DataElement;
324
353
  }): AnnotationGroup;
325
354
  /**
326
- * Convert an annotation group into a DICOM SR object.
355
+ * Convert an annotation group into a DICOM SR object using the
356
+ * TID 1500 template.
327
357
  *
328
358
  * @param {AnnotationGroup} annotationGroup The annotation group.
329
359
  * @param {Object<string, any>} [extraTags] Optional list of extra tags.
@@ -334,6 +364,22 @@ export declare class AnnotationGroupFactory {
334
364
  }): {
335
365
  [x: string]: DataElement;
336
366
  };
367
+ /**
368
+ * Convert a annotation groups into a DICOM CAD report SR object using
369
+ * the TID 4100 template.
370
+ *
371
+ * @param {AnnotationGroup[]} annotationGroups The annotation groups.
372
+ * @param {object[]} responseEvaluations List of response evaluations
373
+ * as {current, measure}.
374
+ * @param {string} comment Report comment.
375
+ * @param {Object<string, any>} [extraTags] Optional list of extra tags.
376
+ * @returns {Object<string, DataElement>} A list of dicom elements.
377
+ */
378
+ toDicomCADReport(annotationGroups: AnnotationGroup[], responseEvaluations: object[], comment: string, extraTags?: {
379
+ [x: string]: any;
380
+ }): {
381
+ [x: string]: DataElement;
382
+ };
337
383
  #private;
338
384
  }
339
385
 
@@ -1377,15 +1423,19 @@ export declare class DicomCode {
1377
1423
  */
1378
1424
  export declare class DicomData {
1379
1425
  /**
1380
- * @param {object} meta The DICOM meta data.
1426
+ * @param {Object<string, DataElement>} meta The DICOM meta data.
1381
1427
  */
1382
- constructor(meta: object);
1428
+ constructor(meta: {
1429
+ [x: string]: DataElement;
1430
+ });
1383
1431
  /**
1384
1432
  * DICOM meta data.
1385
1433
  *
1386
- * @type {object}
1434
+ * @type {Object<string, DataElement>}
1387
1435
  */
1388
- meta: object;
1436
+ meta: {
1437
+ [x: string]: DataElement;
1438
+ };
1389
1439
  /**
1390
1440
  * Image extracted from meta data.
1391
1441
  *
@@ -1398,6 +1448,12 @@ export declare class DicomData {
1398
1448
  * @type {AnnotationGroup|undefined}
1399
1449
  */
1400
1450
  annotationGroup: AnnotationGroup | undefined;
1451
+ /**
1452
+ * Image buffer used to build image.
1453
+ *
1454
+ * @type {any|undefined}
1455
+ */
1456
+ buffer: any | undefined;
1401
1457
  }
1402
1458
 
1403
1459
  /**
@@ -1500,11 +1556,11 @@ export declare class DicomSRContent {
1500
1556
  */
1501
1557
  relationshipType: string;
1502
1558
  /**
1503
- * Content sequence (0040,A730).
1559
+ * Content sequence.
1504
1560
  *
1505
- * @type {DicomSRContent[]|undefined}
1561
+ * @type {DicomSRContent[]}
1506
1562
  */
1507
- contentSequence: DicomSRContent[] | undefined;
1563
+ contentSequence: DicomSRContent[];
1508
1564
  /**
1509
1565
  * Value.
1510
1566
  *
@@ -1518,6 +1574,15 @@ export declare class DicomSRContent {
1518
1574
  * @returns {string} The object as string.
1519
1575
  */
1520
1576
  toString(prefix?: string): string;
1577
+ /**
1578
+ * Check if this content has input header values.
1579
+ *
1580
+ * @param {string} valueType The value type.
1581
+ * @param {DicomCode} conceptNameCode The concept name code.
1582
+ * @param {string} relationshipType The relationship type.
1583
+ * @returns {boolean} True if equal.
1584
+ */
1585
+ hasHeader(valueType: string, conceptNameCode: DicomCode, relationshipType: string): boolean;
1521
1586
  }
1522
1587
 
1523
1588
  /**
@@ -1615,10 +1680,10 @@ export declare class DrawController {
1615
1680
  /**
1616
1681
  * Get an annotation.
1617
1682
  *
1618
- * @param {string} id The annotation id.
1683
+ * @param {string} uid The annotation UID.
1619
1684
  * @returns {Annotation|undefined} The annotation.
1620
1685
  */
1621
- getAnnotation(id: string): Annotation | undefined;
1686
+ getAnnotation(uid: string): Annotation | undefined;
1622
1687
  /**
1623
1688
  * Get the annotation group.
1624
1689
  *
@@ -1653,27 +1718,27 @@ export declare class DrawController {
1653
1718
  /**
1654
1719
  * Remove an anotation for the list.
1655
1720
  *
1656
- * @param {string} id The id of the annotation to remove.
1721
+ * @param {string} uid The UID of the annotation to remove.
1657
1722
  */
1658
- removeAnnotation(id: string): void;
1723
+ removeAnnotation(uid: string): void;
1659
1724
  /**
1660
1725
  * Remove an annotation via a remove command (triggers draw actions).
1661
1726
  *
1662
- * @param {string} id The annotation id.
1727
+ * @param {string} uid The annotation UID.
1663
1728
  * @param {Function} exeCallback The undo stack callback.
1664
1729
  */
1665
- removeAnnotationWithCommand(id: string, exeCallback: Function): void;
1730
+ removeAnnotationWithCommand(uid: string, exeCallback: Function): void;
1666
1731
  /**
1667
1732
  * Update an annotation via an update command (triggers draw actions).
1668
1733
  *
1669
- * @param {string} id The annotation id.
1734
+ * @param {string} uid The annotation UID.
1670
1735
  * @param {object} originalProps The original annotation properties
1671
1736
  * that will be updated.
1672
1737
  * @param {object} newProps The new annotation properties
1673
1738
  * that will replace the original ones.
1674
1739
  * @param {Function} exeCallback The undo stack callback.
1675
1740
  */
1676
- updateAnnotationWithCommand(id: string, originalProps: object, newProps: object, exeCallback: Function): void;
1741
+ updateAnnotationWithCommand(uid: string, originalProps: object, newProps: object, exeCallback: Function): void;
1677
1742
  /**
1678
1743
  * Remove all annotations via remove commands (triggers draw actions).
1679
1744
  *
@@ -2302,6 +2367,21 @@ export declare class Geometry {
2302
2367
  #private;
2303
2368
  }
2304
2369
 
2370
+ /**
2371
+ * Get the meta data as simple elements:
2372
+ * - indexed by tag names instead of tag keys,
2373
+ * - no element object, just value if not sequence nor merged item.
2374
+ *
2375
+ * @param {Object<string, DataElement>} metaData The meta data
2376
+ * index by tag keys.
2377
+ * @returns {Object<string, any>} The simple elements.
2378
+ */
2379
+ export declare function getAsSimpleElements(metaData: {
2380
+ [x: string]: DataElement;
2381
+ }): {
2382
+ [x: string]: any;
2383
+ };
2384
+
2305
2385
  /**
2306
2386
  * Get the default DICOM seg tags as an object.
2307
2387
  *
@@ -2931,6 +3011,10 @@ declare class Image_2 {
2931
3011
  * Note: Uses the raw buffer values.
2932
3012
  */
2933
3013
  compose(rhs: Image_2, operator: Function): Image_2;
3014
+ /**
3015
+ * Recalculate labels.
3016
+ */
3017
+ recalculateLabels(): void;
2934
3018
  #private;
2935
3019
  }
2936
3020
  export { Image_2 as Image }
@@ -3458,12 +3542,14 @@ export declare class MaskFactory {
3458
3542
  * @param {Uint8Array | Int8Array |
3459
3543
  * Uint16Array | Int16Array |
3460
3544
  * Uint32Array | Int32Array} pixelBuffer The pixel buffer.
3545
+ * @param {Image} [refImage] Reference image, code will use its
3546
+ * origins if present (best) or try to calculate them.
3461
3547
  * @returns {Image} A new Image.
3462
3548
  * @throws Error for missing or wrong data.
3463
3549
  */
3464
3550
  create(dataElements: {
3465
3551
  [x: string]: DataElement;
3466
- }, pixelBuffer: Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array): Image_2;
3552
+ }, pixelBuffer: Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array, refImage?: Image_2): Image_2;
3467
3553
  /**
3468
3554
  * Convert a mask image into a DICOM segmentation object.
3469
3555
  *
@@ -4369,12 +4455,20 @@ export declare class PositionHelper {
4369
4455
  *
4370
4456
  * Inspired from {@link https://stackoverflow.com/a/49729715/3639892}.
4371
4457
  *
4372
- * Can be a solution to not have trailing zero as when
4373
- * using toFixed or toPrecision.
4374
- * '+number.toFixed(precision)' does not pass all the tests...
4458
+ * `toPrecision` uses all non zero digits of the number:
4459
+ * (123.009).toPrecision(4) = "123.0";
4460
+ * (0.09).toPrecision(4) = "0.09000".
4461
+ *
4462
+ * `toFixed` does not always behave as expected:
4463
+ * (123.009).toFixed(2) = "123.01";
4464
+ * (0.009).toFixed(2) = "0.01";
4465
+ * but
4466
+ * (-0.005).toFixed(2) = "-0.01" (expecting 0);
4467
+ * (1.005).toFixed(2) = "1" (expecting 1.01).
4375
4468
  *
4376
4469
  * @param {number} number The number to round.
4377
- * @param {number} precision The rounding precision.
4470
+ * @param {number} precision The rounding precision, ie the result number
4471
+ * of digits after the comma.
4378
4472
  * @returns {number} The rounded number.
4379
4473
  */
4380
4474
  export declare function precisionRound(number: number, precision: number): number;
@@ -5120,7 +5214,7 @@ export declare const toolList: {
5120
5214
  * const group = new Konva.Group();
5121
5215
  * group.name('love-group');
5122
5216
  * group.visible(true);
5123
- * group.id(annotation.id);
5217
+ * group.id(annotation.trackingUid);
5124
5218
  * group.add(shape);
5125
5219
  * return group;
5126
5220
  * }
@@ -5605,6 +5699,12 @@ export declare class ViewController {
5605
5699
  * @returns {string} The modality.
5606
5700
  */
5607
5701
  getModality(): string;
5702
+ /**
5703
+ * Get the image SOP class UID.
5704
+ *
5705
+ * @returns {string|undefined} The uid.
5706
+ */
5707
+ getSopClassUid(): string | undefined;
5608
5708
  /**
5609
5709
  * Get the window/level presets names.
5610
5710
  *