import macro from 'vtk.js/Sources/macros'; import vtkCompositeCameraManipulator from 'vtk.js/Sources/Interaction/Manipulators/CompositeCameraManipulator'; import vtkCompositeMouseManipulator from 'vtk.js/Sources/Interaction/Manipulators/CompositeMouseManipulator'; import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
function vtkMouseCameraSliceManipulator(publicAPI, model) { model.classHierarchy.push('vtkMouseCameraSliceManipulator');
publicAPI.onButtonDown = (interactor, renderer, position) => { model.previousPosition = position; };
publicAPI.onMouseMove = (interactor, renderer, position) => { if (!position) { return; }
const dy = position.y - model.previousPosition.y;
const camera = renderer.getActiveCamera(); const range = camera.getClippingRange(); let distance = camera.getDistance();
let viewportHeight = 0.0; if (camera.getParallelProjection()) { viewportHeight = 2.0 * camera.getParallelScale(); } else { const angle = vtkMath.radiansFromDegrees(camera.getViewAngle()); viewportHeight = 2.0 * distance * Math.tan(0.5 * angle); }
const size = interactor.getView().getViewportSize(renderer); const delta = (dy * viewportHeight) / size[1]; distance += delta;
if (distance < range[0]) { distance = range[0] + viewportHeight * 1e-3; } if (distance > range[1]) { distance = range[1] - viewportHeight * 1e-3; } camera.setDistance(distance);
model.previousPosition = position; };
publicAPI.onScroll = (interactor, renderer, delta) => { if (!delta) { return; }
let scrollDelta = 1.0 - delta; scrollDelta *= 25;
const camera = renderer.getActiveCamera(); const range = camera.getClippingRange(); let distance = camera.getDistance(); distance += scrollDelta;
if (distance < range[0]) { distance = range[0]; } if (distance > range[1]) { distance = range[1]; } camera.setDistance(distance); }; }
const DEFAULT_VALUES = {};
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model); vtkCompositeCameraManipulator.extend(publicAPI, model, initialValues); vtkCompositeMouseManipulator.extend(publicAPI, model, initialValues);
vtkMouseCameraSliceManipulator(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkMouseCameraSliceManipulator' );
export default { newInstance, extend };
|