Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fractional segmentation #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4329,7 +4329,8 @@ class VolumeImageViewer {
client: _getClient(this[_clients], Enums.SOPClassUIDs.SEGMENTATION),
channel: segmentNumber
},
hasLoader: false
hasLoader: false,
segmentationType: refSegmentation.SegmentationType
}

const source = new DataTileSource({
Expand Down Expand Up @@ -4359,7 +4360,7 @@ class VolumeImageViewer {
windowWidth,
colormap: [
[...segment.style.paletteColorLookupTable.data.at(0), defaultSegmentStyle.backgroundOpacity],
[...segment.style.paletteColorLookupTable.data.at(-1)]
...segment.style.paletteColorLookupTable.data.slice(1)
]
}),
useInterimTilesOnError: false,
Expand Down Expand Up @@ -4438,15 +4439,6 @@ class VolumeImageViewer {
source.setLoader(loader)
}

const view = this[_map].getView()
const currentZoomLevel = view.getZoom()
if (
currentZoomLevel < segment.minZoomLevel ||
currentZoomLevel > segment.maxZoomLevel
) {
view.animate({ zoom: segment.minZoomLevel })
}

segment.layer.setVisible(true)
this.setSegmentStyle(segmentUID, styleOptions)
}
Expand Down Expand Up @@ -4490,32 +4482,16 @@ class VolumeImageViewer {
}

/**
* Set the style of a segment.
* Add segment overlay. The overlay shows the color palette of the segment.
*
* @param {string} segmentUID - Unique tracking identifier of segment
* @param {Object} styleOptions - Style options
* @param {number} [styleOptions.opacity] - Opacity
* @param {Object} segment - The segment for which to show the overlay
*/
setSegmentStyle (segmentUID, styleOptions = {}) {
if (!(segmentUID in this[_segments])) {
const error = new CustomError(
errorTypes.VISUALIZATION,
'Cannot set style of segment. ' +
`Could not find segment "${segmentUID}".`
)
throw this[_options].errorInterceptor(error) || error
}
const segment = this[_segments][segmentUID]

if (styleOptions.opacity != null) {
segment.style.opacity = styleOptions.opacity
segment.layer.setOpacity(styleOptions.opacity)
}

addOverlay (segment) {
let title = segment.segment.propertyType.CodeMeaning
const padding = Math.round((16 - title.length) / 2)
title = title.padStart(title.length + padding)
title = title.padEnd(title.length + 2 * padding)

const overlayElement = segment.overlay.getElement()
overlayElement.innerHTML = title
overlayElement.style = {}
Expand Down Expand Up @@ -4555,6 +4531,34 @@ class VolumeImageViewer {
this[_map].addOverlay(segment.overlay)
}

/**
* Set the style of a segment.
*
* @param {string} segmentUID - Unique tracking identifier of segment
* @param {Object} styleOptions - Style options
* @param {number} [styleOptions.opacity] - Opacity
*/
setSegmentStyle (segmentUID, styleOptions = {}) {
if (!(segmentUID in this[_segments])) {
const error = new CustomError(
errorTypes.VISUALIZATION,
'Cannot set style of segment. ' +
`Could not find segment "${segmentUID}".`
)
throw this[_options].errorInterceptor(error) || error
}
const segment = this[_segments][segmentUID]

if (styleOptions.opacity != null) {
segment.style.opacity = styleOptions.opacity
segment.layer.setOpacity(styleOptions.opacity)
}

if (segment.segmentationType === 'FRACTIONAL') {
this.addOverlay(segment)
}
}

/**
* Get the default style of a segment.
*
Expand Down
Loading