Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/VTKViewport/vtkInteractorStyleMPRSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
const cache = {
sliceNormal: [0, 0, 0],
sliceRange: [0, 0],
sliceCenter: [],
};

function updateScrollManipulator() {
Expand Down Expand Up @@ -301,6 +302,12 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {

const clampedSlice = clamp(slice, ...range);

let cameraOffset = [0, 0, 0];
if (cache.sliceCenter.length) {
const oldPos = camera.getFocalPoint();
vtkMath.subtract(oldPos, cache.sliceCenter, cameraOffset);
}

const center = [
(bounds[0] + bounds[1]) / 2.0,
(bounds[2] + bounds[3]) / 2.0,
Expand All @@ -323,12 +330,18 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
zeroPoint[2] + dop[2] * clampedSlice,
];

// Cache the center for comparison to calculate the next camera offset
cache.sliceCenter = [...slicePoint];

const cameraPos = [
slicePoint[0] - dop[0] * distance,
slicePoint[1] - dop[1] * distance,
slicePoint[2] - dop[2] * distance,
];

vtkMath.add(slicePoint, cameraOffset, slicePoint);
vtkMath.add(cameraPos, cameraOffset, cameraPos);

camera.setPosition(...cameraPos);
camera.setFocalPoint(...slicePoint);
return slicePoint;
Expand Down