Skip to content

Commit d7510ba

Browse files
authored
feat: 🎸 Mouse wheel scrollable ref lines + pan fix (#116)
* feat: 🎸 Mouse wheel scrollable ref lines + pan fix * Fix placement of color indicator * Add setGet for disable scroll
1 parent 9480282 commit d7510ba

File tree

5 files changed

+274
-54
lines changed

5 files changed

+274
-54
lines changed

‎examples/VTKRotatableCrosshairsExample.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ class VTKRotatableCrosshairsExample extends Component {
207207
this.setState({ displayCrosshairs: shouldDisplayCrosshairs });
208208
};
209209

210+
resetCrosshairs = () => {
211+
const apis = this.apis;
212+
213+
apis.forEach(api => {
214+
api.resetOrientation();
215+
});
216+
217+
// Reset the crosshairs
218+
apis[0].svgWidgets.rotatableCrosshairsWidget.resetCrosshairs(apis, 0);
219+
};
220+
210221
render() {
211222
if (!this.state.volumes || !this.state.volumes.length) {
212223
return <h4>Loading...</h4>;
@@ -241,6 +252,7 @@ class VTKRotatableCrosshairsExample extends Component {
241252
? 'Switch To WL/Zoom/Pan/Scroll'
242253
: 'Switch To Crosshairs'}
243254
</button>
255+
<button onClick={this.resetCrosshairs}>reset crosshairs</button>
244256
</div>
245257
</div>
246258
<div className="row">

‎src/VTKViewport/View2D.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export default class View2D extends Component {
217217
const boundUpdateVOI = this.updateVOI.bind(this);
218218
const boundGetOrienation = this.getOrientation.bind(this);
219219
const boundSetOrientation = this.setOrientation.bind(this);
220+
const boundResetOrientation = this.resetOrientation.bind(this);
220221
const boundGetViewUp = this.getViewUp.bind(this);
221222
const boundGetSliceNormal = this.getSliceNormal.bind(this);
222223
const boundSetInteractorStyle = this.setInteractorStyle.bind(this);
@@ -261,6 +262,7 @@ export default class View2D extends Component {
261262
updateVOI: boundUpdateVOI,
262263
getOrientation: boundGetOrienation,
263264
setOrientation: boundSetOrientation,
265+
resetOrientation: boundResetOrientation,
264266
getViewUp: boundGetViewUp,
265267
getSliceNormal: boundGetSliceNormal,
266268
setInteractorStyle: boundSetInteractorStyle,
@@ -307,6 +309,23 @@ export default class View2D extends Component {
307309
currentIStyle.setSliceOrientation(sliceNormal, viewUp);
308310
}
309311

312+
resetOrientation() {
313+
const orientation = this.props.orientation || {
314+
sliceNormal: [0, 0, 1],
315+
viewUp: [0, -1, 0],
316+
};
317+
318+
// Reset orientation.
319+
this.setOrientation(orientation.sliceNormal, orientation.viewUp);
320+
321+
// Reset slice.
322+
const renderWindow = this.genericRenderWindow.getRenderWindow();
323+
const currentIStyle = renderWindow.getInteractor().getInteractorStyle();
324+
const range = currentIStyle.getSliceRange();
325+
326+
currentIStyle.setSlice((range[0] + range[1]) / 2);
327+
}
328+
310329
getApiProperty(propertyName) {
311330
return this.apiProperties[propertyName];
312331
}

‎src/VTKViewport/vtkInteractorStyleMPRSlice.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
7474
sliceCenter: [],
7575
};
7676

77-
function updateScrollManipulator() {
77+
publicAPI.updateScrollManipulator = () => {
7878
const range = publicAPI.getSliceRange();
7979
model.scrollManipulator.removeScrollListener();
8080
// The Scroll listener has min, max, step, and getValue setValue as params.
@@ -86,15 +86,15 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
8686
publicAPI.getSlice,
8787
publicAPI.scrollToSlice
8888
);
89-
}
89+
};
9090

9191
function setManipulators() {
9292
publicAPI.removeAllMouseManipulators();
9393
publicAPI.addMouseManipulator(model.trackballManipulator);
9494
publicAPI.addMouseManipulator(model.panManipulator);
9595
publicAPI.addMouseManipulator(model.zoomManipulator);
9696
publicAPI.addMouseManipulator(model.scrollManipulator);
97-
updateScrollManipulator();
97+
publicAPI.updateScrollManipulator();
9898
}
9999

100100
function isCameraViewInitialized(camera) {
@@ -219,7 +219,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
219219
const camera = renderer.getActiveCamera();
220220

221221
cameraSub = camera.onModified(() => {
222-
updateScrollManipulator();
222+
publicAPI.updateScrollManipulator();
223223
publicAPI.modified();
224224
});
225225

@@ -238,7 +238,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
238238
// TODO -> When we want a modular framework we'll have to rethink all this.
239239
// TODO -> We need to think of a more generic way to do this for all widget types eventually.
240240
// TODO -> We certainly need to be able to register widget types on instantiation.
241-
function handleButtonPress() {
241+
function handleButtonPress(callData) {
242242
const { apis, apiIndex } = model;
243243

244244
if (apis && apis[apiIndex] && apis[apiIndex].type === 'VIEW2D') {
@@ -250,11 +250,33 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
250250
api.svgWidgets.crosshairsWidget.updateCrosshairForApi(api);
251251
}
252252
if (api.svgWidgets.rotatableCrosshairsWidget) {
253-
api.svgWidgets.rotatableCrosshairsWidget.updateCrosshairForApi(api);
253+
updateRotatableCrosshairs(callData);
254254
}
255255
}
256256
}
257257

258+
function updateRotatableCrosshairs(callData) {
259+
const { apis, apiIndex } = model;
260+
const thisApi = apis[apiIndex];
261+
const { rotatableCrosshairsWidget } = thisApi.svgWidgets;
262+
const renderer = callData.pokedRenderer;
263+
const worldPos = thisApi.get('cachedCrosshairWorldPosition');
264+
265+
const camera = renderer.getActiveCamera();
266+
const directionOfProjection = camera.getDirectionOfProjection();
267+
268+
const halfSlabThickness = thisApi.getSlabThickness() / 2;
269+
270+
// Add half of the slab thickness to the world position, such that we select
271+
// The center of the slice.
272+
273+
for (let i = 0; i < worldPos.length; i++) {
274+
worldPos[i] += halfSlabThickness * directionOfProjection[i];
275+
}
276+
277+
rotatableCrosshairsWidget.moveCrosshairs(worldPos, apis, apiIndex);
278+
}
279+
258280
publicAPI.handleMiddleButtonPress = macro.chain(
259281
publicAPI.handleMiddleButtonPress,
260282
handleButtonPress
@@ -280,12 +302,12 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
280302
api.svgWidgets.crosshairsWidget.updateCrosshairForApi(api);
281303
}
282304
if (api.svgWidgets.rotatableCrosshairsWidget) {
283-
api.svgWidgets.rotatableCrosshairsWidget.updateCrosshairForApi(api);
305+
updateRotatableCrosshairs(callData);
284306
}
285307
}
286308
};
287309

288-
function handleButtonRelease(superButtonRelease) {
310+
function handleButtonRelease(superButtonRelease, callData) {
289311
if (model.state === States.IS_PAN) {
290312
publicAPI.endPan();
291313
const { apis, apiIndex } = model;
@@ -295,7 +317,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
295317
api.svgWidgets.crosshairsWidget.updateCrosshairForApi(api);
296318
}
297319
if (api.svgWidgets.rotatableCrosshairsWidget) {
298-
api.svgWidgets.rotatableCrosshairsWidget.updateCrosshairForApi(api);
320+
updateRotatableCrosshairs(callData);
299321
}
300322
}
301323

@@ -304,13 +326,13 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
304326

305327
publicAPI.superHandleMiddleButtonRelease =
306328
publicAPI.handleMiddleButtonRelease;
307-
publicAPI.handleMiddleButtonRelease = () => {
308-
handleButtonRelease(publicAPI.superHandleMiddleButtonRelease);
329+
publicAPI.handleMiddleButtonRelease = callData => {
330+
handleButtonRelease(publicAPI.superHandleMiddleButtonRelease, callData);
309331
};
310332

311333
publicAPI.superHandleRightButtonRelease = publicAPI.handleRightButtonRelease;
312-
publicAPI.handleRightButtonRelease = () => {
313-
handleButtonRelease(publicAPI.superHandleRightButtonRelease);
334+
publicAPI.handleRightButtonRelease = callData => {
335+
handleButtonRelease(publicAPI.superHandleRightButtonRelease, callData);
314336
};
315337

316338
publicAPI.setVolumeActor = actor => {
@@ -328,7 +350,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
328350
setViewUpInternal(viewportData.getCurrentViewUp());
329351
}
330352

331-
updateScrollManipulator();
353+
publicAPI.updateScrollManipulator();
332354
// NOTE: Disabling this because it makes it more difficult to switch
333355
// interactor styles. Need to find a better way to do this!
334356
//publicAPI.setSliceNormal(...publicAPI.getSliceNormal());

0 commit comments

Comments
 (0)