Skip to content

Commit

Permalink
feat(windowlevelreset): add an option to reset the window width/level…
Browse files Browse the repository at this point in the history
… values
  • Loading branch information
bnmajor committed Mar 14, 2023
1 parent 013232c commit 5bae94e
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Rendering/Images/createImagesRenderingMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function createImagesRenderingMachine(options, context) {
'LABEL_IMAGE_LABEL_NAMES_CHANGED',
'COMPARE_IMAGES',
'WINDOW_LEVEL_TOGGLED',
'IMAGE_COLOR_RANGE_RESET',
],
{ actions: forwardToNamedActor }
),
Expand Down
3 changes: 3 additions & 0 deletions src/Rendering/createRenderingMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ const createRenderingMachine = (options, context) => {
WINDOW_LEVEL_TOGGLED: {
actions: forwardTo('images'),
},
IMAGE_COLOR_RANGE_RESET: {
actions: forwardTo('images'),
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/UI/Images/createImagesUIMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ function createImagesUIMachine(options, context) {
forwardTo('transferFunctionManipulators'),
],
},
IMAGE_COLOR_RANGE_RESET: {
actions: ['applyWindowLevelReset'],
},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/UI/createUIMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ function createUIMachine(options, context) {
WINDOW_LEVEL_TOGGLED: {
actions: forwardTo('images'),
},
IMAGE_COLOR_RANGE_RESET: {
actions: forwardTo('images'),
},
START_DATA_UPDATE: { actions: forwardTo('layers') },
FINISH_DATA_UPDATE: { actions: forwardTo('layers') },
POST_RENDER: { actions: forwardTo('layers') },
Expand Down
25 changes: 25 additions & 0 deletions src/UI/reference-ui/src/Images/applyWindowingReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function applyWindowLevelReset(context, { data }) {
const actorContext = context.images.actorContext.get(data.name)
const component = actorContext.selectedComponent
const bounds = actorContext.colorRangeBounds.get(component)

const wMax = bounds[1] - bounds[0]
const lMin = bounds[0]
const level = wMax / 2 + lMin
const width = wMax

const newRange = () => {
return [level - width / 2, level + width / 2]
}

context.service.send({
type: 'IMAGE_COLOR_RANGE_CHANGED',
data: {
name: data.name,
component,
range: newRange(),
},
})
}

export default applyWindowLevelReset
3 changes: 3 additions & 0 deletions src/UI/reference-ui/src/Images/createColorRangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import style from '../ItkVtkViewer.module.css'

import createInterpolationButton from './createInterpolationButton'
import createColorMapIconSelector from '../createColorMapIconSelector'
import createWindowLevelReset from './createWindowLevelReset'

function createColorRangeInput(context, imageUIGroup) {
const viewerDOMId = context.id
Expand Down Expand Up @@ -88,6 +89,8 @@ function createColorRangeInput(context, imageUIGroup) {
})
context.images.colorMapSelector = colorMapSelector

createWindowLevelReset(context, colorRangeInputRow)

imageUIGroup.appendChild(colorRangeInputRow)
}

Expand Down
36 changes: 36 additions & 0 deletions src/UI/reference-ui/src/Images/createWindowLevelReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import style from '../ItkVtkViewer.module.css'
import applyContrastSensitiveStyleToElement from '../applyContrastSensitiveStyleToElement'

import { resetImageIconDataUri } from 'itk-viewer-icons'

function createWindowLevelReset(context, uiContainer) {
const windowLevelResetButton = document.createElement('div')
windowLevelResetButton.innerHTML = `
<div itk-vtk-tooltip itk-vtk-tooltip-left itk-vtk-tooltip-content="Reset range to ROI" class="${style.windowLevelButton}">
<img src="${resetImageIconDataUri}" alt="gradient opacity"/>
</div>
`
const windowLevelResetButtonInput = windowLevelResetButton.children[0]
const windowLevelResetButtonLabel = windowLevelResetButton.children[1]
applyContrastSensitiveStyleToElement(
context,
'invertibleButton',
windowLevelResetButtonLabel
)
context.images.windowLevelResetButtonLabel = windowLevelResetButtonLabel
context.images.windowLevelResetButtonInput = windowLevelResetButtonInput

windowLevelResetButton.addEventListener('click', event => {
event.preventDefault()
event.stopPropagation()
context.service.send({
type: 'IMAGE_COLOR_RANGE_RESET',
data: {
name: context.images.selectedName,
},
})
})
uiContainer.appendChild(windowLevelResetButton)
}

export default createWindowLevelReset
2 changes: 2 additions & 0 deletions src/UI/reference-ui/src/Images/imagesUIMachineOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scaleSelector from './scaleSelector'
import { applyPiecewiseFunctionPointsToEditor } from './createTransferFunctionWidget'
import { applyCinematicChanged } from './cinematic'
import toggleWindowLevel from './toggleWindowLevel'
import applyWindowLevelReset from './applyWindowingReset'

const imagesUIMachineOptions = {
actions: {
Expand All @@ -43,6 +44,7 @@ const imagesUIMachineOptions = {
applyPiecewiseFunctionGaussians,
applyPiecewiseFunctionPointsToEditor,
toggleWindowLevel,
applyWindowLevelReset,

toggleShadow,
applyGradientOpacity,
Expand Down
2 changes: 1 addition & 1 deletion src/UI/reference-ui/src/ItkVtkViewer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
transition-duration: 0.3s;
transition-timing-function: ease-in-out;
transition-delay: 0.8s;
z-index: 1;
z-index: 3000;
}

[itk-vtk-tooltip]:hover::before {
Expand Down
4 changes: 2 additions & 2 deletions src/UI/reference-ui/src/createColorMapIconSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function createColorMapIconSelector(colorMapSelectorDiv) {
const rows = 20
const cols = 4
const iconSelectParameters = {
selectedIconWidth: 160,
selectedIconWidth: 140,
selectedIconHeight: 22,
selectedBoxPadding: 1,
iconsWidth: 80,
Expand All @@ -19,7 +19,7 @@ function createColorMapIconSelector(colorMapSelectorDiv) {
colorMapSelectorDiv,
iconSelectParameters
)
colorMapSelectorDiv.style.width = '174px'
colorMapSelectorDiv.style.width = '154px'
// put above lower down label map color selector
colorMapSelectorDiv.style.zIndex = '2001'

Expand Down
3 changes: 3 additions & 0 deletions src/createViewerMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ const createViewerMachine = (options, context, eventEmitterCallback) => {
WINDOW_LEVEL_TOGGLED: {
actions: [forwardTo('ui'), forwardTo('rendering')],
},
IMAGE_COLOR_RANGE_RESET: {
actions: [forwardTo('ui'), forwardTo('rendering')],
},
},
},
},
Expand Down

0 comments on commit 5bae94e

Please sign in to comment.