@@ -142,6 +142,9 @@ function disposeOverviewMapLayers (map) {
142142 */
143143export function disposeLayer ( layer , disposeSource = false ) {
144144 console . info ( 'dispose layer:' , layer )
145+ if ( typeof layer ?. getSource !== 'function' ) {
146+ return
147+ }
145148 const source = layer . getSource ( )
146149 if ( disposeSource === true && source && source . clear ) {
147150 source . clear ( )
@@ -4329,7 +4332,8 @@ class VolumeImageViewer {
43294332 client : _getClient ( this [ _clients ] , Enums . SOPClassUIDs . SEGMENTATION ) ,
43304333 channel : segmentNumber
43314334 } ,
4332- hasLoader : false
4335+ hasLoader : false ,
4336+ segmentationType : refSegmentation . SegmentationType
43334337 }
43344338
43354339 const source = new DataTileSource ( {
@@ -4359,7 +4363,7 @@ class VolumeImageViewer {
43594363 windowWidth,
43604364 colormap : [
43614365 [ ...segment . style . paletteColorLookupTable . data . at ( 0 ) , defaultSegmentStyle . backgroundOpacity ] ,
4362- [ ...segment . style . paletteColorLookupTable . data . at ( - 1 ) ]
4366+ ...segment . style . paletteColorLookupTable . data . slice ( 1 )
43634367 ]
43644368 } ) ,
43654369 useInterimTilesOnError : false ,
@@ -4416,7 +4420,7 @@ class VolumeImageViewer {
44164420 * @param {Object } [styleOptions]
44174421 * @param {number } [styleOptions.opacity] - Opacity
44184422 */
4419- showSegment ( segmentUID , styleOptions = { } ) {
4423+ showSegment ( segmentUID , styleOptions = { } , shouldZoomIn = false ) {
44204424 if ( ! ( segmentUID in this [ _segments ] ) ) {
44214425 const error = new CustomError (
44224426 errorTypes . VISUALIZATION ,
@@ -4438,13 +4442,16 @@ class VolumeImageViewer {
44384442 source . setLoader ( loader )
44394443 }
44404444
4441- const view = this [ _map ] . getView ( )
4442- const currentZoomLevel = view . getZoom ( )
4443- if (
4444- currentZoomLevel < segment . minZoomLevel ||
4445- currentZoomLevel > segment . maxZoomLevel
4446- ) {
4447- view . animate ( { zoom : segment . minZoomLevel } )
4445+ if ( shouldZoomIn ) {
4446+ const view = this [ _map ] . getView ( )
4447+ const currentZoomLevel = view . getZoom ( )
4448+
4449+ if (
4450+ currentZoomLevel < segment . minZoomLevel ||
4451+ currentZoomLevel > segment . maxZoomLevel
4452+ ) {
4453+ view . animate ( { zoom : segment . minZoomLevel } )
4454+ }
44484455 }
44494456
44504457 segment . layer . setVisible ( true )
@@ -4490,32 +4497,16 @@ class VolumeImageViewer {
44904497 }
44914498
44924499 /**
4493- * Set the style of a segment.
4500+ * Add segment overlay. The overlay shows the color palette of the segment.
44944501 *
4495- * @param {string } segmentUID - Unique tracking identifier of segment
4496- * @param {Object } styleOptions - Style options
4497- * @param {number } [styleOptions.opacity] - Opacity
4502+ * @param {Object } segment - The segment for which to show the overlay
44984503 */
4499- setSegmentStyle ( segmentUID , styleOptions = { } ) {
4500- if ( ! ( segmentUID in this [ _segments ] ) ) {
4501- const error = new CustomError (
4502- errorTypes . VISUALIZATION ,
4503- 'Cannot set style of segment. ' +
4504- `Could not find segment "${ segmentUID } ".`
4505- )
4506- throw this [ _options ] . errorInterceptor ( error ) || error
4507- }
4508- const segment = this [ _segments ] [ segmentUID ]
4509-
4510- if ( styleOptions . opacity != null ) {
4511- segment . style . opacity = styleOptions . opacity
4512- segment . layer . setOpacity ( styleOptions . opacity )
4513- }
4514-
4504+ addSegmentOverlay ( segment ) {
45154505 let title = segment . segment . propertyType . CodeMeaning
45164506 const padding = Math . round ( ( 16 - title . length ) / 2 )
45174507 title = title . padStart ( title . length + padding )
45184508 title = title . padEnd ( title . length + 2 * padding )
4509+
45194510 const overlayElement = segment . overlay . getElement ( )
45204511 overlayElement . innerHTML = title
45214512 overlayElement . style = { }
@@ -4547,14 +4538,51 @@ class VolumeImageViewer {
45474538 context . fillStyle = `rgb(${ r } , ${ g } , ${ b } )`
45484539 context . fillRect ( 0 , height / colors . length * j , width , 1 )
45494540 }
4541+
4542+ const upperBound = document . createElement ( 'span' )
4543+ upperBound . innerHTML = '255'
4544+
4545+ const lowerBound = document . createElement ( 'span' )
4546+ lowerBound . innerHTML = '0'
4547+
4548+ overlayElement . appendChild ( upperBound )
45504549 overlayElement . appendChild ( canvas )
4550+ overlayElement . appendChild ( lowerBound )
45514551
45524552 const parentElement = overlayElement . parentNode
45534553 parentElement . style . display = 'inline'
45544554
45554555 this [ _map ] . addOverlay ( segment . overlay )
45564556 }
45574557
4558+ /**
4559+ * Set the style of a segment.
4560+ *
4561+ * @param {string } segmentUID - Unique tracking identifier of segment
4562+ * @param {Object } styleOptions - Style options
4563+ * @param {number } [styleOptions.opacity] - Opacity
4564+ */
4565+ setSegmentStyle ( segmentUID , styleOptions = { } ) {
4566+ if ( ! ( segmentUID in this [ _segments ] ) ) {
4567+ const error = new CustomError (
4568+ errorTypes . VISUALIZATION ,
4569+ 'Cannot set style of segment. ' +
4570+ `Could not find segment "${ segmentUID } ".`
4571+ )
4572+ throw this [ _options ] . errorInterceptor ( error ) || error
4573+ }
4574+ const segment = this [ _segments ] [ segmentUID ]
4575+
4576+ if ( styleOptions . opacity != null ) {
4577+ segment . style . opacity = styleOptions . opacity
4578+ segment . layer . setOpacity ( styleOptions . opacity )
4579+ }
4580+
4581+ if ( segment . segmentationType === 'FRACTIONAL' ) {
4582+ this . addSegmentOverlay ( segment )
4583+ }
4584+ }
4585+
45584586 /**
45594587 * Get the default style of a segment.
45604588 *
0 commit comments