Skip to content
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
39 changes: 37 additions & 2 deletions src/VTKViewport/View2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 },
};

Expand Down Expand Up @@ -215,9 +218,11 @@ 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);
const boundResetWindowLevel = this.resetWindowLevel.bind(this);
const boundGetViewUp = this.getViewUp.bind(this);
const boundGetSliceNormal = this.getSliceNormal.bind(this);
const boundSetInteractorStyle = this.setInteractorStyle.bind(this);
Expand Down Expand Up @@ -260,9 +265,11 @@ export default class View2D extends Component {
_component: this,
updateImage: boundUpdateImage,
updateVOI: boundUpdateVOI,
setInitialVOI: boundSetInitialVOI,
getOrientation: boundGetOrienation,
setOrientation: boundSetOrientation,
resetOrientation: boundResetOrientation,
resetWindowLevel: boundResetWindowLevel,
getViewUp: boundGetViewUp,
getSliceNormal: boundGetSliceNormal,
setInteractorStyle: boundSetInteractorStyle,
Expand Down Expand Up @@ -314,7 +321,6 @@ export default class View2D extends Component {
sliceNormal: [0, 0, 1],
viewUp: [0, -1, 0],
};

// Reset orientation.
this.setOrientation(orientation.sliceNormal, orientation.viewUp);

Expand All @@ -326,6 +332,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];
}
Expand Down Expand Up @@ -444,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 } });
}
Expand Down