Skip to content

Commit

Permalink
fix: 🐛 Fix scroll issues with rotatable crosshairs (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesAPetts authored Oct 13, 2020
1 parent f487c93 commit e9ca239
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
5 changes: 4 additions & 1 deletion examples/VTKRotatableCrosshairsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ class VTKRotatableCrosshairsExample extends Component {
// // add istyle
api.setInteractorStyle({
istyle,
configuration: { apis, apiIndex: viewportIndex },
configuration: {
apis,
apiIndex: viewportIndex,
},
});

//api.setInteractorStyle({ istyle });
Expand Down
15 changes: 1 addition & 14 deletions src/VTKViewport/vtkInteractorStyleMPRSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,12 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
}
}

function updateRotatableCrosshairs(callData) {
function updateRotatableCrosshairs() {
const { apis, apiIndex } = model;
const thisApi = apis[apiIndex];
const { rotatableCrosshairsWidget } = thisApi.svgWidgets;
const renderer = callData.pokedRenderer;
const worldPos = thisApi.get('cachedCrosshairWorldPosition');

const camera = renderer.getActiveCamera();
const directionOfProjection = camera.getDirectionOfProjection();

const halfSlabThickness = thisApi.getSlabThickness() / 2;

// Add half of the slab thickness to the world position, such that we select
// The center of the slice.

for (let i = 0; i < worldPos.length; i++) {
worldPos[i] += halfSlabThickness * directionOfProjection[i];
}

rotatableCrosshairsWidget.moveCrosshairs(worldPos, apis, apiIndex);
}

Expand Down
28 changes: 28 additions & 0 deletions src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {
const thisApi = apis[apiIndex];
let { position } = callData;

setOtherApisInactive();

const { rotatableCrosshairsWidget } = thisApi.svgWidgets;

if (!rotatableCrosshairsWidget) {
Expand Down Expand Up @@ -81,6 +83,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {

lineRotateHandles.selected = true;

// Set this line active.
if (lineIndex === 0) {
lines[0].active = true;
lines[1].active = false;
Expand Down Expand Up @@ -128,10 +131,35 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {
line.active = false;
});

setOtherApisInactive();

// What is the fallback? Pan? Do nothing for now.
model.operation = { type: null };
}

function setOtherApisInactive() {
// Set other apis inactive

const { apis, apiIndex } = model;

apis.forEach((api, index) => {
if (index !== apiIndex) {
const { rotatableCrosshairsWidget } = api.svgWidgets;

if (!rotatableCrosshairsWidget) {
throw new Error(
'Must use rotatable crosshair svg widget with this istyle.'
);
}

const lines = rotatableCrosshairsWidget.getReferenceLines();

lines[0].active = false;
lines[1].active = false;
}
});
}

function distanceFromLine(line, point) {
const [a, b] = line.points;
const c = point;
Expand Down

0 comments on commit e9ca239

Please sign in to comment.