Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | 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 * as vtkMath from 'vtk.js/Sources/Common/Core/Math'; import widgetBehavior from 'vtk.js/Sources/Widgets/Widgets3D/AngleWidget/behavior'; import stateGenerator from 'vtk.js/Sources/Widgets/Widgets3D/AngleWidget/state'; import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'; // ---------------------------------------------------------------------------- // Factory // ---------------------------------------------------------------------------- function vtkAngleWidget(publicAPI, model) { model.classHierarchy.push('vtkAngleWidget'); // --- Widget Requirement --------------------------------------------------- model.methodsToLink = [ 'activeScaleFactor', 'activeColor', 'useActiveColor', 'glyphResolution', 'defaultScale', 'scaleInPixels', ]; model._onManipulatorChanged = () => { model.widgetState.getMoveHandle().setManipulator(model.manipulator); model.widgetState.getHandleList().forEach((handle) => { handle.setManipulator(model.manipulator); }); }; publicAPI.getRepresentationsForViewType = (viewType) => { switch (viewType) { case ViewTypes.DEFAULT: case ViewTypes.GEOMETRY: case ViewTypes.SLICE: case ViewTypes.VOLUME: default: return [ { builder: vtkSphereHandleRepresentation, labels: ['handles', 'moveHandle'], }, { builder: vtkPolyLineRepresentation, labels: ['handles', 'moveHandle'], }, ]; } }; // --- Public methods ------------------------------------------------------- // Returns angle in radians publicAPI.getAngle = () => { const handles = model.widgetState.getHandleList(); if (handles.length !== 3) { return 0; } if ( !handles[0].getOrigin() || !handles[1].getOrigin() || !handles[2].getOrigin() ) { return 0; } const vec1 = [0, 0, 0]; const vec2 = [0, 0, 0]; vtkMath.subtract(handles[0].getOrigin(), handles[1].getOrigin(), vec1); vtkMath.subtract(handles[2].getOrigin(), handles[1].getOrigin(), vec2); return vtkMath.angleBetweenVectors(vec1, vec2); }; // -------------------------------------------------------------------------- // initialization // -------------------------------------------------------------------------- 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); }); // Default manipulator publicAPI.setManipulator( model.manipulator || vtkPlanePointManipulator.newInstance({ useCameraNormal: true }) ); } // ---------------------------------------------------------------------------- const defaultValues = (initialValues) => ({ // manipulator: null, 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']); vtkAngleWidget(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkAngleWidget'); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |