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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import macro from 'vtk.js/Sources/macros'; import vtkCanvasView from 'vtk.js/Sources/Rendering/Misc/CanvasView'; import vtkImageStream from 'vtk.js/Sources/IO/Core/ImageStream'; import vtkInteractorStyleRemoteMouse from 'vtk.js/Sources/Interaction/Style/InteractorStyleRemoteMouse'; import vtkRenderWindowInteractor from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor'; const SHARED_IMAGE_STREAM = vtkImageStream.newInstance(); export const connectImageStream = SHARED_IMAGE_STREAM.connect; export const disconnectImageStream = SHARED_IMAGE_STREAM.disconnect; // ---------------------------------------------------------------------------- // vtkRemoteView methods // ---------------------------------------------------------------------------- function vtkRemoteView(publicAPI, model) { // Set our className model.classHierarchy.push('vtkRemoteView'); // Constructor model.canvasView = vtkCanvasView.newInstance(); model.interactorStyle = vtkInteractorStyleRemoteMouse.newInstance(); model.interactor = vtkRenderWindowInteractor.newInstance(); model.interactor.setView(model.canvasView); model.interactor.initialize(); model.interactor.setInteractorStyle(model.interactorStyle); // Mouse model.interactorStyle.onRemoteMouseEvent((e) => { if (model.session && model.rpcMouseEvent) { model.session.call(model.rpcMouseEvent, [e]); } }); // Wheel model.interactorStyle.onRemoteWheelEvent((e) => { if (model.session && model.rpcWheelEvent) { model.session.call(model.rpcWheelEvent, [e]); } }); // Gesture model.interactorStyle.onRemoteGestureEvent((e) => { if (model.session && model.rpcGestureEvent) { model.session.call(model.rpcGestureEvent, [e]); } }); // -------------------------------------------------------------------------- // API // -------------------------------------------------------------------------- publicAPI.delete = macro.chain(() => { model.session = null; if (model.canvasView) { model.canvasView.setViewStream(null); model.canvasView.delete(); } if (model.interactor) { model.interactor.delete(); } if (model.viewStream) { model.viewStream.delete(); } }, publicAPI.delete); // -------------------------------------------------------------------------- // remote handing // -------------------------------------------------------------------------- publicAPI.setViewStream = (viewStream) => { model.viewStream = viewStream; model.canvasView.setViewStream(model.viewStream); // Configure image quality model.viewStream.setStillQuality(model.stillQuality); model.viewStream.setStillRatio(model.stillRatio); model.viewStream.setInteractiveQuality(model.interactiveQuality); model.viewStream.setInteractiveRatio(model.interactiveRatio); // Link user interactions model.interactor.onStartAnimation(model.viewStream.startInteraction); model.interactor.onEndAnimation(model.viewStream.endInteraction); publicAPI.setViewId(viewStream.getViewId()); }; publicAPI.setViewId = (id) => { if (!model.viewStream) { publicAPI.setViewStream(SHARED_IMAGE_STREAM.createViewStream(id)); } model.viewStream.setViewId(id); model.interactorStyle.setRemoteEventAddOn({ view: id }); publicAPI.modified(); }; // -------------------------------------------------------------------------- // DOM handling // -------------------------------------------------------------------------- publicAPI.setContainer = (container) => { if (model.container) { model.interactor.unbindEvents(container); } // Capture container model.container = container; model.canvasView.setContainer(model.container); // Attach listeners if (container) { model.interactor.bindEvents(container); publicAPI.resize(); } }; // -------------------------------------------------------------------------- publicAPI.resize = () => { if (model.container && model.canvasView) { const { width, height } = model.container.getBoundingClientRect(); model.canvasView.setSize(width, height); publicAPI.render(); } }; // -------------------------------------------------------------------------- publicAPI.render = () => { if (model.viewStream) { model.viewStream.render(); } }; // -------------------------------------------------------------------------- publicAPI.resetCamera = () => { if (model.viewStream) { model.viewStream.resetCamera(); } }; // -------------------------------------------------------------------------- // viewStream setters // -------------------------------------------------------------------------- const internal = { modified: publicAPI.modified }; macro.set(internal, model, [ 'interactiveQuality', 'interactiveRatio', 'stillQuality', 'stillRatio', ]); publicAPI.setInteractiveQuality = (q) => { const changeDetected = internal.setInteractiveQuality(q); if (model.viewStream && changeDetected) { model.viewStream.setInteractiveQuality(model.interactiveQuality); } return changeDetected; }; publicAPI.setInteractiveRatio = (r) => { const changeDetected = internal.setInteractiveRatio(r); if (model.viewStream && changeDetected) { model.viewStream.setInteractiveRatio(model.interactiveRatio); } return changeDetected; }; publicAPI.setStillQuality = (q) => { const changeDetected = internal.setStillQuality(q); if (model.viewStream && changeDetected) { model.viewStream.setStillQuality(model.stillQuality); } return changeDetected; }; publicAPI.setStillRatio = (r) => { const changeDetected = internal.setStillRatio(r); if (model.viewStream && changeDetected) { model.viewStream.setStillRatio(model.stillRatio); } return changeDetected; }; // Initialize viewStream if available Iif (model.viewStream) { publicAPI.setViewStream(model.viewStream); } } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { viewId: '-1', interactiveQuality: 60, interactiveRatio: 1 / window.devicePixelRatio, stillQuality: 100, stillRatio: 1, rpcMouseEvent: 'viewport.mouse.interaction', rpcGestureEvent: null, rpcWheelEvent: null, }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); macro.obj(publicAPI, model, initialValues); macro.get(publicAPI, model, [ 'container', 'viewStream', 'canvasView', 'interactor', 'interactorStyle', 'interactiveQuality', 'interactiveRatio', 'stillQuality', 'stillRatio', ]); macro.setGet(publicAPI, model, [ 'session', 'rpcMouseEvent', 'rpcGestureEvent', 'rpcWheelEvent', ]); // Object methods vtkRemoteView(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkRemoteView'); // ---------------------------------------------------------------------------- export default { newInstance, extend, SHARED_IMAGE_STREAM, connectImageStream, disconnectImageStream, }; |