import macro from 'vtk.js/Sources/macros'; import vtkAbstractWidgetFactory from 'vtk.js/Sources/Widgets/Core/AbstractWidgetFactory'; import vtkPlanePointManipulator from 'vtk.js/Sources/Widgets/Manipulators/PlaneManipulator'; import vtkPolyLineRepresentation from 'vtk.js/Sources/Widgets/Representations/PolyLineRepresentation'; import vtkSphereHandleRepresentation from 'vtk.js/Sources/Widgets/Representations/SphereHandleRepresentation'; import { distance2BetweenPoints } from 'vtk.js/Sources/Common/Core/Math';
import widgetBehavior from 'vtk.js/Sources/Widgets/Widgets3D/DistanceWidget/behavior'; import stateGenerator from 'vtk.js/Sources/Widgets/Widgets3D/DistanceWidget/state';
import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
function vtkDistanceWidget(publicAPI, model) { model.classHierarchy.push('vtkDistanceWidget');
const superClass = { ...publicAPI };
model.methodsToLink = [ 'activeScaleFactor', 'activeColor', 'useActiveColor', 'glyphResolution', 'defaultScale', 'scaleInPixels', ];
publicAPI.getRepresentationsForViewType = (viewType) => { switch (viewType) { case ViewTypes.DEFAULT: case ViewTypes.GEOMETRY: case ViewTypes.SLICE: case ViewTypes.VOLUME: default: return [ { builder: vtkSphereHandleRepresentation, labels: ['handles'] }, { builder: vtkSphereHandleRepresentation, labels: ['moveHandle'] }, { builder: vtkPolyLineRepresentation, labels: ['handles', 'moveHandle'], }, ]; } };
publicAPI.getDistance = () => { const handles = model.widgetState.getHandleList(); if (handles.length !== 2) { return 0; } if (!handles[0].getOrigin() || !handles[1].getOrigin()) { return 0; } return Math.sqrt( distance2BetweenPoints(handles[0].getOrigin(), handles[1].getOrigin()) ); };
publicAPI.setManipulator = (manipulator) => { superClass.setManipulator(manipulator); model.widgetState.getMoveHandle().setManipulator(manipulator); model.widgetState.getHandleList().forEach((handle) => { handle.setManipulator(manipulator); }); };
model.widgetState.onBoundsChange((bounds) => { const center = [ (bounds[0] + bounds[1]) * 0.5, (bounds[2] + bounds[3]) * 0.5, (bounds[4] + bounds[5]) * 0.5, ]; model.widgetState.getMoveHandle().setOrigin(center); });
publicAPI.setManipulator( model.manipulator || vtkPlanePointManipulator.newInstance({ useCameraNormal: true }) ); }
const defaultValues = (initialValues) => ({ behavior: widgetBehavior, widgetState: stateGenerator(), ...initialValues, });
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, defaultValues(initialValues));
vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues); macro.setGet(publicAPI, model, ['manipulator']);
vtkDistanceWidget(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkDistanceWidget');
export default { newInstance, extend };
|