From 4615f45956c888ea7e3a913ce390d31313f5ab5c Mon Sep 17 00:00:00 2001 From: Lucie Macron Date: Tue, 1 Dec 2020 17:19:28 +0100 Subject: [PATCH 1/2] ENH: Add possibility to reset windowLevel in 2D view --- src/VTKViewport/View2D.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/VTKViewport/View2D.js b/src/VTKViewport/View2D.js index 1b42660b..1b423727 100644 --- a/src/VTKViewport/View2D.js +++ b/src/VTKViewport/View2D.js @@ -13,6 +13,7 @@ import ViewportOverlay from '../ViewportOverlay/ViewportOverlay.js'; import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'; import { createSub } from '../lib/createSub.js'; import realsApproximatelyEqual from '../lib/math/realsApproximatelyEqual'; +import { toLowHighRange } from '../lib/windowLevelRangeConverter'; import createLabelPipeline from './createLabelPipeline'; import { uuidv4 } from './../helpers'; import setGlobalOpacity from './setGlobalOpacity'; @@ -68,8 +69,10 @@ export default class View2D extends Component { paintEnd: createSub(), }; this.interactorStyleSubs = []; + const initialVOI = this.getVOI(props.volumes[0]); this.state = { - voi: this.getVOI(props.volumes[0]), + voi: Object.assign({}, initialVOI), + initialVOI: Object.assign({}, initialVOI), rotation: { theta: 0, phi: 0 }, }; @@ -218,6 +221,7 @@ export default class View2D extends Component { const boundGetOrienation = this.getOrientation.bind(this); const boundSetOrientation = this.setOrientation.bind(this); const boundResetOrientation = this.resetOrientation.bind(this); + const boundResetWindowLevel = this.resetWindowLevel.bind(this); const boundGetViewUp = this.getViewUp.bind(this); const boundGetSliceNormal = this.getSliceNormal.bind(this); const boundSetInteractorStyle = this.setInteractorStyle.bind(this); @@ -263,6 +267,7 @@ export default class View2D extends Component { getOrientation: boundGetOrienation, setOrientation: boundSetOrientation, resetOrientation: boundResetOrientation, + resetWindowLevel: boundResetWindowLevel, getViewUp: boundGetViewUp, getSliceNormal: boundGetSliceNormal, setInteractorStyle: boundSetInteractorStyle, @@ -314,7 +319,6 @@ export default class View2D extends Component { sliceNormal: [0, 0, 1], viewUp: [0, -1, 0], }; - // Reset orientation. this.setOrientation(orientation.sliceNormal, orientation.viewUp); @@ -326,6 +330,31 @@ export default class View2D extends Component { currentIStyle.setSlice((range[0] + range[1]) / 2); } + resetWindowLevel() { + const renderWindow = this.genericRenderWindow.getRenderWindow(); + const interactorStyle = renderWindow.getInteractor().getInteractorStyle(); + + const volumeActor = interactorStyle.getVolumeActor(); + if (volumeActor) { + const lowHigh = toLowHighRange( + this.state.initialVOI.windowWidth, + this.state.initialVOI.windowCenter + ); + + volumeActor + .getProperty() + .getRGBTransferFunction(0) + .setMappingRange(lowHigh.lower, lowHigh.upper); + + this.updateVOI( + this.state.initialVOI.windowWidth, + this.state.initialVOI.windowCenter + ); + + renderWindow.render(); + } + } + getApiProperty(propertyName) { return this.apiProperties[propertyName]; } From b7dbc484cbd65d718e2023f6538b8d79cd1be151 Mon Sep 17 00:00:00 2001 From: Lucie Macron Date: Fri, 8 Jan 2021 08:48:21 +0100 Subject: [PATCH 2/2] BUG: Fix initial VOI in 2D View --- src/VTKViewport/View2D.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/VTKViewport/View2D.js b/src/VTKViewport/View2D.js index 1b423727..10b2c8bf 100644 --- a/src/VTKViewport/View2D.js +++ b/src/VTKViewport/View2D.js @@ -218,6 +218,7 @@ export default class View2D extends Component { this.genericRenderWindow.resize(); const boundUpdateVOI = this.updateVOI.bind(this); + const boundSetInitialVOI = this.setInitialVOI.bind(this); const boundGetOrienation = this.getOrientation.bind(this); const boundSetOrientation = this.setOrientation.bind(this); const boundResetOrientation = this.resetOrientation.bind(this); @@ -264,6 +265,7 @@ export default class View2D extends Component { _component: this, updateImage: boundUpdateImage, updateVOI: boundUpdateVOI, + setInitialVOI: boundSetInitialVOI, getOrientation: boundGetOrienation, setOrientation: boundSetOrientation, resetOrientation: boundResetOrientation, @@ -473,6 +475,10 @@ export default class View2D extends Component { this.setState({ voi: { windowWidth, windowCenter } }); } + setInitialVOI(windowWidth, windowCenter) { + this.setState({ initialVOI: { windowWidth, windowCenter } }); + } + updateRotationOverlay(theta, phi) { this.setState({ rotation: { theta, phi } }); }