Skip to content

fix: 🐛 Fix scroll issues with rotatable crosshairs #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
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
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