Skip to content

Commit c605981

Browse files
committed
Automatically scale size of annotations
1 parent 2acd0f8 commit c605981

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

src/viewer.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,8 @@ class VolumeImageViewer {
33363336
/**
33373337
* Remove an annotation group.
33383338
*
3339-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3339+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3340+
* group
33403341
*/
33413342
removeAnnotationGroup (annotationGroupUID) {
33423343
if (!(annotationGroupUID in this[_annotationGroups])) {
@@ -3364,7 +3365,8 @@ class VolumeImageViewer {
33643365
/**
33653366
* Show an annotation group.
33663367
*
3367-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3368+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3369+
* group
33683370
* @param {Object} styleOptions
33693371
* @param {number} [styleOptions.opacity] - Opacity
33703372
* @param {number[]} [styleOptions.color] - RGB color triplet
@@ -3386,7 +3388,8 @@ class VolumeImageViewer {
33863388
/**
33873389
* Hide an annotation group.
33883390
*
3389-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3391+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3392+
* group
33903393
*/
33913394
hideAnnotationGroup (annotationGroupUID) {
33923395
if (!(annotationGroupUID in this[_annotationGroups])) {
@@ -3403,7 +3406,8 @@ class VolumeImageViewer {
34033406
/**
34043407
* Is annotation group visible.
34053408
*
3406-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3409+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3410+
* group
34073411
*/
34083412
isAnnotationGroupVisible (annotationGroupUID) {
34093413
if (!(annotationGroupUID in this[_annotationGroups])) {
@@ -3419,12 +3423,13 @@ class VolumeImageViewer {
34193423
/**
34203424
* Set style of an annotation group.
34213425
*
3422-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3426+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3427+
* group
34233428
* @param {Object} styleOptions - Style options
34243429
* @param {number} [styleOptions.opacity] - Opacity
34253430
* @param {number[]} [styleOptions.color] - RGB color triplet
34263431
* @param {Object} [styleOptions.measurement] - Selected measurement for
3427-
* colorizing annotations
3432+
* pseudo-coloring of annotations using measurement values
34283433
*/
34293434
setAnnotationGroupStyle (annotationGroupUID, styleOptions = {}) {
34303435
if (!(annotationGroupUID in this[_annotationGroups])) {
@@ -3459,6 +3464,22 @@ class VolumeImageViewer {
34593464
)
34603465
}
34613466

3467+
const markerType = 'circle'
3468+
const topLayerIndex = 0
3469+
const topLayerPixelSpacing = this[_pyramid].pixelSpacings[topLayerIndex]
3470+
const baseLayerIndex = this[_pyramid].metadata.length - 1
3471+
const baseLayerPixelSpacing = this[_pyramid].pixelSpacings[baseLayerIndex]
3472+
const diameter = 5 * 10 ** -3 // micometer
3473+
const markerSize = [
3474+
'interpolate',
3475+
['exponential', 2],
3476+
['zoom'],
3477+
1,
3478+
Math.max(diameter / topLayerPixelSpacing[0], 1),
3479+
this[_pyramid].resolutions.length,
3480+
Math.min(diameter / baseLayerPixelSpacing[0], 50)
3481+
]
3482+
34623483
const name = styleOptions.measurement
34633484
if (name) {
34643485
const measurementIndex = groupItem.MeasurementsSequence.findIndex(item => {
@@ -3473,19 +3494,12 @@ class VolumeImageViewer {
34733494
}
34743495
const properties = source.getProperties()
34753496
const key = `measurementValue${measurementIndex.toString()}`
3497+
34763498
if (properties[key]) {
34773499
const style = {
34783500
symbol: {
3479-
symbolType: 'circle',
3480-
size: [
3481-
'interpolate',
3482-
['linear'],
3483-
['zoom'],
3484-
1,
3485-
2,
3486-
this[_pyramid].metadata.length,
3487-
15
3488-
],
3501+
symbolType: markerType,
3502+
size: markerSize,
34893503
opacity: annotationGroup.style.opacity
34903504
}
34913505
}
@@ -3518,16 +3532,8 @@ class VolumeImageViewer {
35183532
// Only replace the layer if necessary
35193533
const style = {
35203534
symbol: {
3521-
symbolType: 'circle',
3522-
size: [
3523-
'interpolate',
3524-
['linear'],
3525-
['zoom'],
3526-
1,
3527-
2,
3528-
this[_pyramid].metadata.length,
3529-
15
3530-
],
3535+
symbolType: markerType,
3536+
size: markerSize,
35313537
color: [
35323538
'match',
35333539
['get', 'selected'],
@@ -3557,7 +3563,8 @@ class VolumeImageViewer {
35573563
/**
35583564
* Get default style of an annotation group.
35593565
*
3560-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3566+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3567+
* group
35613568
*
35623569
* @returns {Object} - Default style settings
35633570
*/
@@ -3578,7 +3585,8 @@ class VolumeImageViewer {
35783585
/**
35793586
* Get style of an annotation group.
35803587
*
3581-
* @param {string} annotationGroupUID - Unique identifier of an annotation group
3588+
* @param {string} annotationGroupUID - Unique identifier of an annotation
3589+
* group
35823590
*
35833591
* @returns {Object} - Style settings
35843592
*/
@@ -3706,7 +3714,7 @@ class VolumeImageViewer {
37063714

37073715
refSegmentation.SegmentSequence.forEach((item, index) => {
37083716
const segmentNumber = Number(item.SegmentNumber)
3709-
console.info(`add segment # ${segmentNumber}`)
3717+
console.info(`add segment #${segmentNumber}`)
37103718
let segmentUID = _generateUID({
37113719
value: refSegmentation.SOPInstanceUID + segmentNumber.toString()
37123720
})

0 commit comments

Comments
 (0)