-
Notifications
You must be signed in to change notification settings - Fork 35
/
annotation.js.html
847 lines (793 loc) · 26.2 KB
/
annotation.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: annotation.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: annotation.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { _fetchBulkdata } from './utils.js'
const _attrs = Symbol('attrs')
/**
* Annotation Group.
*
* Describes an item of the Annotation Group Sequence of a DICOM Microscopy Bulk
* Simple Annotations instance.
*
* @class
* @memberof annotation
*/
class AnnotationGroup {
/**
* @param {Object} options - Options
* @param {string} options.uid - Annotation Group UID
* @param {number} options.number - Annotation Group Number (one-based index value)
* @param {string} options.label - Annotation Group Label
* @param {string} options.algorithmName - Annotation Group Algorithm Name
* @param {Object} options.algorithmType - Annotation Group Algorithm Type
* @param {Object} options.propertyCategory - Annotation Property Category Code
* @param {Object} options.propertyType - Annotation Property Type Code
* @param {string} options.studyInstanceUID - Study Instance UID of Annotation instances
* @param {string} options.seriesInstanceUID - Series Instance UID of Annotation instances
* @param {string[]} options.sopInstanceUIDs - SOP Instance UIDs of Annotation instances
*/
constructor ({
uid,
number,
label,
propertyCategory,
propertyType,
algorithmType,
algorithmName,
studyInstanceUID,
seriesInstanceUID,
sopInstanceUIDs
}) {
this[_attrs] = {}
if (uid == null) {
throw new Error('Annotation Group UID is required.')
} else {
this[_attrs].uid = uid
}
if (number == null) {
throw new Error('Annotation Group Number is required.')
}
this[_attrs].number = number
if (label == null) {
throw new Error('Annotation Group Label is required.')
}
this[_attrs].label = label
if (propertyCategory == null) {
throw new Error('Annotation Property Category is required.')
}
this[_attrs].propertyCategory = propertyCategory
if (propertyType == null) {
throw new Error('Annotation Property Type is required.')
}
this[_attrs].propertyType = propertyType
if (algorithmName == null) {
throw new Error('Annotation Group Algorithm Name is required.')
}
this[_attrs].algorithmType = algorithmType
if (algorithmType == null) {
throw new Error('Annotation Group Generation Type is required.')
}
this[_attrs].algorithmName = algorithmName
if (studyInstanceUID == null) {
throw new Error('Study Instance UID is required.')
}
this[_attrs].studyInstanceUID = studyInstanceUID
if (seriesInstanceUID == null) {
throw new Error('Series Instance UID is required.')
}
this[_attrs].seriesInstanceUID = seriesInstanceUID
if (sopInstanceUIDs == null) {
throw new Error('SOP Instance UIDs are required.')
}
this[_attrs].sopInstanceUIDs = sopInstanceUIDs
Object.freeze(this)
}
/**
* Annotation Group UID
*
* @type string
*/
get uid () {
return this[_attrs].uid
}
/**
* Annotation Group Number.
*
* @type number
*/
get number () {
return this[_attrs].number
}
/**
* Annotation Group Label
*
* @type string
*/
get label () {
return this[_attrs].label
}
/**
* Annotation Group Algorithm Identification
*
* @type string
*/
get algorithmName () {
return this[_attrs].algorithmName
}
/**
* Annotation Group Generation Type
*
* @type Object
*/
get algorithmType () {
return this[_attrs].algorithmType
}
/**
* Annotation Property Category
*
* @type Object
*/
get propertyCategory () {
return this[_attrs].propertyCategory
}
/**
* Annotation Property Type
*
* @type Object
*/
get propertyType () {
return this[_attrs].propertyType
}
/**
* Study Instance UID of DICOM Microscopy Bulk Simple Annotations objects.
*
* @type string
*/
get studyInstanceUID () {
return this[_attrs].studyInstanceUID
}
/**
* Series Instance UID of DICOM Microscopy Bulk Simple Annotations objects.
*
* @type string
*/
get seriesInstanceUID () {
return this[_attrs].seriesInstanceUID
}
/**
* SOP Instance UIDs of DICOM Microscopy Bulk Simple Annotations objects.
*
* @type string[]
*/
get sopInstanceUIDs () {
return this[_attrs].sopInstanceUIDs
}
}
/**
* Fetch graphic data (point coordinates) of an annotation group.
*
* @param {Object} options
* @param {Object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {Object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {Object} options.client - DICOMweb client
*
* @returns {Promise<TypedArray>} Graphic data
*
* @private
*/
async function _fetchGraphicData ({
metadataItem,
bulkdataItem,
client
}) {
const uid = metadataItem.AnnotationGroupUID
if ('PointCoordinatesData' in metadataItem) {
return metadataItem.PointCoordinatesData
} else if ('DoublePointCoordinatesData' in metadataItem) {
return metadataItem.DoublePointCoordinatesData
} else {
if (bulkdataItem == null) {
throw new Error(
`Could not find bulkdata of annotation group "${uid}".`
)
} else {
if ('PointCoordinatesData' in bulkdataItem) {
console.info(`fetch point coordinate data of annotation group "${uid}"`)
return await _fetchBulkdata({
client,
reference: bulkdataItem.PointCoordinatesData
})
} else if ('DoublePointCoordinatesData' in bulkdataItem) {
console.info(`fetch point coordinate data of annotation group "${uid}"`)
return await _fetchBulkdata({
client,
reference: bulkdataItem.DoublePointCoordinatesData
})
} else {
throw new Error(
'Could not find "PointCoordinatesData" or ' +
'"DoublePointCoordinatesData" in bulkdata ' +
`of annotation group "${uid}".`
)
}
}
}
}
/**
* Fetch graphic index (long primitive point index) of an annotation group.
*
* @param {object} options
* @param {object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {object} options.client - DICOMweb client
*
* @returns {Promise<TypedArray|null>} Graphic index
*
* @private
*/
async function _fetchGraphicIndex ({
metadataItem,
bulkdataItem,
client
}) {
const uid = metadataItem.AnnotationGroupUID
const graphicType = metadataItem.GraphicType
if ('LongPrimitivePointIndexList' in metadataItem) {
return metadataItem.LongPrimitivePointIndexList
} else {
if (bulkdataItem == null) {
if (graphicType === 'POLYGON') {
throw new Error(
`Could not find bulkdata of annotation group "${uid}".`
)
} else {
return null
}
} else {
if ('LongPrimitivePointIndexList' in bulkdataItem) {
console.info(`fetch point index list of annotation group "${uid}"`)
return await _fetchBulkdata({
client,
reference: bulkdataItem.LongPrimitivePointIndexList
})
} else {
if (graphicType === 'POLYGON') {
throw new Error(
'Could not find "LongPrimitivePointIndexList" ' +
`in bulkdata of annotation group "${uid}".`
)
} else {
return null
}
}
}
}
}
/**
* Fetch measurement values of an annotation group.
*
* @param {object} options
* @param {object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {number} options.index - Zero-based index in the Measurements Sequence
* @param {object} options.client - DICOMweb client
*
* @returns {Promise<TypeArray>} Values
*
* @private
*/
async function _fetchMeasurementValues ({
metadataItem,
bulkdataItem,
index,
client
}) {
const uid = metadataItem.AnnotationGroupUID
const measurementMetadataItem = metadataItem.MeasurementsSequence[index]
const valuesMetadataItem = measurementMetadataItem.MeasurementValuesSequence[0]
if ('FloatingPointValues' in valuesMetadataItem) {
return valuesMetadataItem.FloatingPointValues
} else {
if (bulkdataItem == null) {
throw new Error(
`Could not find bulkdata of annotation group "${uid}".`
)
} else if (bulkdataItem.MeasurementsSequence == null) {
throw new Error(
`Could not find item #${index + 1} of "MeasurementSequence" ` +
`in bulkdata of annotation group "${uid}".`
)
} else {
const measurementBulkdataItem = bulkdataItem.MeasurementsSequence[index]
const valuesBulkdataItem = (
measurementBulkdataItem.MeasurementValuesSequence[0]
)
if ('FloatingPointValues' in valuesBulkdataItem) {
const nameItem = measurementMetadataItem.ConceptNameCodeSequence[0]
const name = nameItem.CodeMeaning
console.info(
`fetch measurement values for measurement #${index} "${name}"`
)
return await _fetchBulkdata({
client,
reference: valuesBulkdataItem.FloatingPointValues
})
} else {
throw new Error(
`Could not find "FloatingPointValues" in item #${index + 1} ` +
'of "MeasurementSequence" in bulkdata ' +
`of annotation group "${uid}".`
)
}
}
}
}
/**
* Fetch measurement annotation indices of an annotation group.
*
* @param {object} options
* @param {object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {number} options.index - Zero-based index in the Measurements Sequence
* @param {object} options.client - DICOMweb client
*
* @returns {Promise<TypeArray|null>} Annotation indices
*
* @private
*/
async function _fetchMeasurementIndices ({
metadataItem,
bulkdataItem,
index,
client
}) {
const uid = metadataItem.AnnotationGroupUID
const measurementMetadataItem = metadataItem.MeasurementsSequence[index]
const valuesMetadataItem = measurementMetadataItem.MeasurementValuesSequence[0]
if ('AnnotationIndexList' in valuesMetadataItem) {
return valuesMetadataItem.AnnotationIndexList
} else {
if (bulkdataItem == null) {
throw new Error(
`Could not find bulkdata of annotation group "${uid}".`
)
} else if (bulkdataItem.MeasurementsSequence == null) {
throw new Error(
`Could not find item #${index + 1} of "MeasurementSequence" ` +
`in bulkdata of annotation group "${uid}".`
)
} else {
const measurementBulkdataItem = bulkdataItem.MeasurementsSequence[index]
const valuesBulkdataItem = (
measurementBulkdataItem
.MeasurementValuesSequence[0]
)
if ('AnnotationIndexList' in valuesBulkdataItem) {
const nameItem = measurementMetadataItem.ConceptNameCodeSequence[0]
const name = nameItem.CodeMeaning
console.info(
`fetch measurement indices for measurement #${index} "${name}"`
)
return await _fetchBulkdata({
client,
reference: valuesBulkdataItem.AnnotationIndexList
})
} else {
return null
}
}
}
}
/**
* Fetch all measurements of an annotation group.
*
* @param {object} options
* @param {object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {object} options.client - DICOMweb client
*
* @returns {Promise<Array<object>>} Name, values, and indices of measurements
*
* @private
*/
async function _fetchMeasurements ({
metadataItem,
bulkdataItem,
client
}) {
const measurements = []
if (metadataItem.MeasurementsSequence !== undefined) {
for (let i = 0; i < metadataItem.MeasurementsSequence.length; i++) {
const item = metadataItem.MeasurementsSequence[i]
const name = item.ConceptNameCodeSequence[0]
const unit = item.MeasurementUnitsCodeSequence[0]
const values = await _fetchMeasurementValues({
metadataItem,
bulkdataItem,
index: i,
client
})
const indices = await _fetchMeasurementIndices({
metadataItem,
bulkdataItem,
index: i,
client
})
measurements.push({
name,
unit,
values,
indices
})
}
}
return measurements
}
/**
* Fetch an individual measurement of an annotation group.
*
* @param {object} options
* @param {object} options.metadataItem - Metadata of Annotation Group Sequence item
* @param {object} options.bulkdataItem - Bulkdata of Annotation Group Sequence item
* @param {object} options.index - Index of the Measurements Sequence item
* @param {object} options.client - DICOMweb client
*
* @returns {Promise<Array<object>>} Name, values, and indices of measurements
*
* @private
*/
async function _fetchMeasurement ({
metadataItem,
bulkdataItem,
index,
client
}) {
if (metadataItem.MeasurementsSequence == null) {
throw new Error(
'Measurements Sequence element is not contained in metadata.'
)
}
if (metadataItem.MeasurementsSequence.length === 0) {
throw new Error(
'Measurements Sequence element in empty.'
)
}
const item = metadataItem.MeasurementsSequence[index]
if (item == null) {
throw new Error(
`Measurements Sequence does not contain an item #${index}.`
)
}
const name = item.ConceptNameCodeSequence[0]
const unit = item.MeasurementUnitsCodeSequence[0]
const values = await _fetchMeasurementValues({
metadataItem,
bulkdataItem,
index,
client
})
const indices = await _fetchMeasurementIndices({
metadataItem,
bulkdataItem,
index,
client
})
return { name, unit, values, indices }
}
/**
* Get dimensionality of coordinates.
*
* @param {object} metadataItem - Metadata of Annotation Group Sequence item
*
* @returns {number} Dimensionality (2 or 3)
*
* @private
*/
function _getCoordinateDimensionality (metadataItem) {
if (metadataItem.CommonZCoordinateValue == null) {
if (metadataItem.AnnotationCoordinateType === '2D') {
return 2
}
return 3
}
return 2
}
/**
* Get common Z coordinate value that is shared across all annotations.
*
* @param {object} metadataItem - Metadata of Annotation Group Sequence item
*
* @returns {number} Value (NaN in case there is no common Z coordinate)
*
* @private
*/
function _getCommonZCoordinate (metadataItem) {
if (metadataItem.CommonZCoordinateValue == null) {
return Number.NaN
}
return Number(metadataItem.CommonZCoordinateValue)
}
/**
* Get coordinates of an annotation.
*
* @param {TypedArray} graphicData - Points coordinates of all annotations
* @param {number} offset - Offset for the annotation of interest.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
function _getCoordinates (graphicData, offset, commonZCoordinate) {
const point = [
graphicData[offset],
graphicData[offset + 1]
]
if (isNaN(commonZCoordinate)) {
point.push(graphicData[offset + 2])
} else {
point.push(commonZCoordinate)
}
return point
}
/**
* Get coordinates of a POINT annotation.
*
* @param {TypedArray} graphicData - Point coordinates of all annotations
* @param {TypedArray} graphicIndex - Annotation index of all annotations
* @param {number} coordinateDimensionality - Dimensionality of stored coordinates.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
* @param {number} annotationIndex - Index of the annotation of interest.
* @param {number} numberOfAnnotations - Total number of annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
function _getPoint (
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
) {
const length = coordinateDimensionality
const offset = annotationIndex * length
return _getCoordinates(graphicData, offset, commonZCoordinate)
}
/**
* Get coordinates of the centroid point of a RECTANGLE annotation.
*
* @param {TypedArray} graphicData - Point coordinates of all annotations
* @param {TypedArray} graphicIndex - Annotation index of all annotations
* @param {number} coordinateDimensionality - Dimensionality of stored coordinates.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
* @param {number} annotationIndex - Index of the annotation of interest.
* @param {number} numberOfAnnotations - Total number of annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
function _getRectangleCentroid (
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
) {
const length = coordinateDimensionality * 4
const offset = annotationIndex * length
const coordinates = []
for (let j = offset; j < offset + length; j++) {
const p = _getCoordinates(graphicData, j, commonZCoordinate)
coordinates.push(p)
j += coordinateDimensionality - 1
}
const topLeft = coordinates[0]
const topRight = coordinates[1]
const bottomLeft = coordinates[3]
return [
topLeft[0] + (topRight[0] - topLeft[0]) / 2,
topLeft[1] + (topLeft[1] - bottomLeft[1]) / 2,
0
]
}
/**
* Get coordinates of the centroid point of an ELLIPSE annotation.
*
* @param {TypedArray} graphicData - Point coordinates of all annotations
* @param {TypedArray} graphicIndex - Annotation index of all annotations
* @param {number} coordinateDimensionality - Dimensionality of stored coordinates.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
* @param {number} annotationIndex - Index of the annotation of interest.
* @param {number} numberOfAnnotations - Total number of annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
function _getEllipseCentroid (
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
) {
const length = coordinateDimensionality * 4
const offset = annotationIndex * length
const coordinates = []
for (let j = offset; j < offset + length; j++) {
const p = _getCoordinates(graphicData, j, commonZCoordinate)
coordinates.push(p)
j += coordinateDimensionality - 1
}
const majorAxisFirstEndpoint = coordinates[0]
const majorAxisSecondEndpoint = coordinates[1]
return [
(majorAxisSecondEndpoint[0] - majorAxisFirstEndpoint[0]) / 2,
(majorAxisSecondEndpoint[1] - majorAxisFirstEndpoint[1]) / 2,
0
]
}
/**
* Get coordinates of the centroid point of a POLYGON annotation.
*
* @param {TypedArray} graphicData - Point coordinates of all annotations
* @param {TypedArray} graphicIndex - Annotation index of all annotations
* @param {number} coordinateDimensionality - Dimensionality of stored coordinates.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
* @param {number} annotationIndex - Index of the annotation of interest.
* @param {number} numberOfAnnotations - Total number of annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
function _getPolygonCentroid (
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
) {
const offset = graphicIndex[annotationIndex] - 1
let length
if (annotationIndex < (numberOfAnnotations - 1)) {
length = graphicIndex[annotationIndex + 1] - offset
} else {
length = graphicData.length
}
// https://en.wikipedia.org/wiki/Centroid#Of_a_polygon
const point = [0, 0, 0]
let area = 0
for (let j = offset; j < offset + length; j++) {
const p0 = _getCoordinates(graphicData, j, commonZCoordinate)
let p1
if (j === (offset + length - 1)) {
p1 = _getCoordinates(graphicData, offset, commonZCoordinate)
} else {
const nextOffset = j + coordinateDimensionality
p1 = _getCoordinates(graphicData, nextOffset, commonZCoordinate)
}
const a = p0[0] * p1[1] - p1[0] * p0[1]
area += a
point[0] += (p0[0] + p1[0]) * a
point[1] += (p0[1] + p1[1]) * a
j += coordinateDimensionality - 1
}
area *= 0.5
point[0] /= 6 * area
point[1] /= 6 * area
return point
}
/**
* Get coordinates of the centroid point of an annotation.
*
* @param {string} graphicType - Type of annotations (POINT, POLYGON, etc.)
* @param {TypedArray} graphicData - Point coordinates of all annotations
* @param {TypedArray} graphicIndex - Annotation index of all annotations
* @param {number} coordinateDimensionality - Dimensionality of stored coordinates.
* @param {number} commonZCoordinate - Z coordinate that is shared across annotations.
* @param {number} annotationIndex - Index of the annotation of interest.
* @param {number} numberOfAnnotations - Total number of annotations.
*
* @returns {Array<number>} (x, y, z) or (column, row, slice) coordinates
*
* @private
*/
const _getCentroid = (
graphicType,
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
) => {
if (graphicType === 'POINT') {
return _getPoint(
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
)
} else if (graphicType === 'RECTANGLE') {
return _getRectangleCentroid(
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
)
} else if (graphicType === 'ELLIPSE') {
return _getEllipseCentroid(
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
)
} else if (graphicType === 'POLYGON') {
return _getPolygonCentroid(
graphicData,
graphicIndex,
coordinateDimensionality,
commonZCoordinate,
annotationIndex,
numberOfAnnotations
)
} else {
throw new Error(
`Encountered unexpected graphic type "${graphicType}".`
)
}
}
export {
AnnotationGroup,
_fetchGraphicData,
_fetchGraphicIndex,
_fetchMeasurements,
_fetchMeasurement,
_getCentroid,
_getCommonZCoordinate,
_getCoordinateDimensionality
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="annotation.html">annotation</a></li><li><a href="api.html">api</a></li><li><a href="color.html">color</a></li><li><a href="events.html">events</a></li><li><a href="mapping.html">mapping</a></li><li><a href="metadata.html">metadata</a></li><li><a href="opticalPath.html">opticalPath</a></li><li><a href="roi.html">roi</a></li><li><a href="scoord3d.html">scoord3d</a></li><li><a href="segment.html">segment</a></li><li><a href="utils.html">utils</a></li><li><a href="viewer.html">viewer</a></li></ul><h3>Classes</h3><ul><li><a href="annotation.AnnotationGroup.html">AnnotationGroup</a></li><li><a href="color.PaletteColorLookupTable.html">PaletteColorLookupTable</a></li><li><a href="mapping.ParameterMapping.html">ParameterMapping</a></li><li><a href="mapping.Transformation.html">Transformation</a></li><li><a href="metadata.Comprehensive3DSR.html">Comprehensive3DSR</a></li><li><a href="metadata.MicroscopyBulkSimpleAnnotations.html">MicroscopyBulkSimpleAnnotations</a></li><li><a href="metadata.ParametricMap.html">ParametricMap</a></li><li><a href="metadata.Segmentation.html">Segmentation</a></li><li><a href="metadata.SOPClass.html">SOPClass</a></li><li><a href="metadata.VLWholeSlideMicroscopyImage.html">VLWholeSlideMicroscopyImage</a></li><li><a href="module.exports_module.exports.html">exports</a></li><li><a href="opticalPath.OpticalPath.html">OpticalPath</a></li><li><a href="roi.ROI.html">ROI</a></li><li><a href="scoord3d.Ellipse.html">Ellipse</a></li><li><a href="scoord3d.Ellipsoid.html">Ellipsoid</a></li><li><a href="scoord3d.Multipoint.html">Multipoint</a></li><li><a href="scoord3d.Point.html">Point</a></li><li><a href="scoord3d.Polygon.html">Polygon</a></li><li><a href="scoord3d.Polyline.html">Polyline</a></li><li><a href="scoord3d.Scoord3D.html">Scoord3D</a></li><li><a href="segment.Segment.html">Segment</a></li><li><a href="viewer.LabelImageViewer.html">LabelImageViewer</a></li><li><a href="viewer.OverviewImageViewer.html">OverviewImageViewer</a></li><li><a href="viewer.VolumeImageViewer.html">VolumeImageViewer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addTask">addTask</a></li><li><a href="global.html#cancelTask">cancelTask</a></li><li><a href="global.html#decode">decode</a></li><li><a href="global.html#getStatistics">getStatistics</a></li><li><a href="global.html#handleMessageFromWorker">handleMessageFromWorker</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#loadWebWorkerTask">loadWebWorkerTask</a></li><li><a href="global.html#setTaskPriority">setTaskPriority</a></li><li><a href="global.html#spawnWebWorker">spawnWebWorker</a></li><li><a href="global.html#startTaskOnWebWorker">startTaskOnWebWorker</a></li><li><a href="global.html#terminateAllWebWorkers">terminateAllWebWorkers</a></li><li><a href="global.html#transform">transform</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Mon Sep 12 2022 22:55:18 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>