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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 428x 340x 340x 340x 340x 340x 340x 340x 340x 340x 340x 340x 340x 340x 96x 96x 96x 96x 96x 96x 362x 362x 96x 96x 96x 362x 362x 362x 118338x 9023x 9023x 4046x 4046x 4046x 10080x 4046x 58x 266x 58x 428x 4115x 6298x 1210x 1210x 3630x 1210x 1210x 1210x 702x 702x 702x 216x 216x 702x 96x 96x 362x 96x 96x 22432x 10471x 16727x 10471x 10471x 4727x 4727x 96x 96x 96x 96x 96x 96x 96x 96x 18214x | import Events from '../enums/Events'; import renderingEngineCache from './renderingEngineCache'; import eventTarget from '../eventTarget'; import uuidv4 from '../utilities/uuidv4'; import triggerEvent from '../utilities/triggerEvent'; import ViewportType from '../enums/ViewportType'; import BaseVolumeViewport from './BaseVolumeViewport'; import StackViewport from './StackViewport'; import viewportTypeUsesCustomRenderingPipeline from './helpers/viewportTypeUsesCustomRenderingPipeline'; import getOrCreateCanvas from './helpers/getOrCreateCanvas'; import { getShouldUseCPURendering, isCornerstoneInitialized, getConfiguration, } from '../init'; import type IStackViewport from '../types/IStackViewport'; import type IVolumeViewport from '../types/IVolumeViewport'; import viewportTypeToViewportClass from './helpers/viewportTypeToViewportClass'; import type * as EventTypes from '../types/EventTypes'; import type { PublicViewportInput, InternalViewportInput, NormalizedViewportInput, IViewport, } from '../types/IViewport'; import { OrientationAxis } from '../enums'; import type { VtkOffscreenMultiRenderWindow } from '../types'; import { StatsOverlay } from './helpers/stats'; // Rendering engines seem to not like rendering things less than 2 pixels per side export const VIEWPORT_MIN_SIZE = 2; /** * Base class for rendering engines that handle viewport rendering. * This abstract class provides the common functionality shared between * different rendering strategies * * @abstract */ abstract class BaseRenderingEngine { /** Unique identifier for renderingEngine */ readonly id: string; /** A flag which tells if the renderingEngine has been destroyed or not */ public hasBeenDestroyed: boolean; // eslint-disable-next-line @typescript-eslint/no-explicit-any public offscreenMultiRenderWindow: VtkOffscreenMultiRenderWindow; public offScreenCanvasContainer: HTMLDivElement; protected _viewports: Map<string, IViewport>; protected _needsRender = new Set<string>(); protected _animationFrameSet = false; protected _animationFrameHandle: number | null = null; protected useCPURendering: boolean; /** * @param uid - Unique identifier for RenderingEngine */ constructor(id?: string) { this.id = id ? id : uuidv4(); this.useCPURendering = getShouldUseCPURendering(); renderingEngineCache.set(this); Iif (!isCornerstoneInitialized()) { throw new Error( '@cornerstonejs/core is not initialized, run init() first' ); } this._viewports = new Map(); this.hasBeenDestroyed = false; const config = getConfiguration(); Iif (config?.debug?.statsOverlay) { StatsOverlay.setup(); } } /** * Enables the requested viewport and add it to the viewports. It will * properly create the Stack viewport or Volume viewport: * * 1) Checks if the viewport is defined already, if yes, remove it first * 2) Checks if the viewport is using a custom rendering pipeline, if no, * it calculates a new offscreen canvas with the new requested viewport * 3) Adds the viewport * * * ``` * renderingEngine.enableElement({ * viewportId: viewportId, * type: ViewportType.ORTHOGRAPHIC, * element, * defaultOptions: { * orientation: Enums.OrientationAxis.AXIAL, * background: [1, 0, 1], * }, * }) * ``` * * fires Events.ELEMENT_ENABLED * * @param viewportInputEntry - viewport specifications */ public enableElement(viewportInputEntry: PublicViewportInput): void { const viewportInput = this._normalizeViewportInputEntry(viewportInputEntry); this._throwIfDestroyed(); const { element, viewportId } = viewportInput; // Throw error if no canvas Iif (!element) { throw new Error('No element provided'); } // 1. Get the viewport from the list of available viewports. const viewport = this.getViewport(viewportId); // 1.a) If there is a found viewport, we remove the viewport and create a new viewport Iif (viewport) { this.disableElement(viewportId); } // 2.a) See if viewport uses a custom rendering pipeline. const { type } = viewportInput; const viewportUsesCustomRenderingPipeline = viewportTypeUsesCustomRenderingPipeline(type); // 2.b) Retrieving the list of viewports for calculation of the new size for // offScreen canvas. // If the viewport being added uses a custom pipeline, or we aren't using // GPU rendering, we don't need to resize the offscreen canvas. if (!this.useCPURendering && !viewportUsesCustomRenderingPipeline) { this.enableVTKjsDrivenViewport(viewportInput); } else E{ // 3 Add the requested viewport to rendering Engine this.addCustomViewport(viewportInput); } // 5. Set the background color for the canvas const canvas = getOrCreateCanvas(element); const { background } = viewportInput.defaultOptions; this.fillCanvasWithBackgroundColor(canvas, background); } /** * Disables the requested viewportId from the rendering engine: * * 1) It removes the viewport from the the list of viewports * 2) remove the renderer from the offScreen render window if using vtk.js driven * rendering pipeline * 3) resetting the viewport to remove the canvas attributes and canvas data * 4) resize the offScreen appropriately (if using vtk.js driven rendering pipeline) * * fires Events.ELEMENT_ENABLED * * @param viewportId - viewport Id * */ public disableElement(viewportId: string): void { this._throwIfDestroyed(); // 1. Getting the viewport to remove it const viewport = this.getViewport(viewportId); // 2 To throw if there is no viewport stored in rendering engine if (!viewport) { console.warn(`viewport ${viewportId} does not exist`); return; } // 3. Reset the viewport to remove attributes, and reset the canvas this._resetViewport(viewport); // 4. Remove the related renderer from the offScreenMultiRenderWindow if ( !viewportTypeUsesCustomRenderingPipeline(viewport.type) && !this.useCPURendering ) { // Only remove renderer if offscreenMultiRenderWindow exists (not in ContextPoolRenderingEngine) if (this.offscreenMultiRenderWindow) { this.offscreenMultiRenderWindow.removeRenderer(viewportId); } } // 5. Remove the requested viewport from the rendering engine this._removeViewport(viewportId); viewport.isDisabled = true; // 6. Avoid rendering for the disabled viewport this._needsRender.delete(viewportId); // 7. Clear RAF if no viewport is left const viewports = this.getViewports(); if (!viewports.length) { this._clearAnimationFrame(); } // Note: we should not call resize at the end of here, the reason is that // in batch rendering, we might disable a viewport and enable others at the same // time which would interfere with each other. So we just let the enable // to call resize, and also resize getting called by applications on the // DOM resize event. } /** * It takes an array of viewport input objects including element, viewportId, type * and defaultOptions. It will add the viewport to the rendering engine and enables them. * * * ```typescript *renderingEngine.setViewports([ * { * viewportId: axialViewportId, * type: ViewportType.ORTHOGRAPHIC, * element: document.getElementById('axialDiv'), * defaultOptions: { * orientation: Enums.OrientationAxis.AXIAL, * }, * }, * { * viewportId: sagittalViewportId, * type: ViewportType.ORTHOGRAPHIC, * element: document.getElementById('sagittalDiv'), * defaultOptions: { * orientation: Enums.OrientationAxis.SAGITTAL, * }, * }, * { * viewportId: customOrientationViewportId, * type: ViewportType.ORTHOGRAPHIC, * element: document.getElementById('customOrientationDiv'), * defaultOptions: { * orientation: { viewPlaneNormal: [0, 0, 1], viewUp: [0, 1, 0] }, * }, * }, * ]) * ``` * * fires Events.ELEMENT_ENABLED * * @param viewportInputEntries - Array<PublicViewportInput> */ public setViewports(publicViewportInputEntries: PublicViewportInput[]): void { const viewportInputEntries = this._normalizeViewportInputEntries( publicViewportInputEntries ); this._throwIfDestroyed(); this._reset(); // 1. Split viewports based on whether they use vtk.js or a custom pipeline. const vtkDrivenViewportInputEntries: NormalizedViewportInput[] = []; const customRenderingViewportInputEntries: NormalizedViewportInput[] = []; viewportInputEntries.forEach((vpie) => { if ( !this.useCPURendering && !viewportTypeUsesCustomRenderingPipeline(vpie.type) ) { vtkDrivenViewportInputEntries.push(vpie); } else E{ customRenderingViewportInputEntries.push(vpie); } }); this.setVtkjsDrivenViewports(vtkDrivenViewportInputEntries); this.setCustomViewports(customRenderingViewportInputEntries); // Making sure the setViewports api also can fill the canvas // properly viewportInputEntries.forEach((vp) => { const canvas = getOrCreateCanvas(vp.element); const { background } = vp.defaultOptions; this.fillCanvasWithBackgroundColor(canvas, background); }); } /** * Resizes the offscreen viewport and recalculates translations to on screen canvases. * It is up to the parent app to call the resize of the on-screen canvas changes. * This is left as an app level concern as one might want to debounce the changes, or the like. * * @param immediate - Whether all of the viewports should be rendered immediately. * @param keepCamera - Whether to keep the camera for other viewports while resizing the offscreen canvas */ public resize(immediate = true, keepCamera = true): void { this._throwIfDestroyed(); // 1. Get the viewports' canvases const viewports = this._getViewportsAsArray(); const vtkDrivenViewports = []; const customRenderingViewports = []; viewports.forEach((vpie) => { if (!viewportTypeUsesCustomRenderingPipeline(vpie.type)) { vtkDrivenViewports.push(vpie); } else { customRenderingViewports.push(vpie); } }); if (vtkDrivenViewports.length) { this._resizeVTKViewports(vtkDrivenViewports, keepCamera, immediate); } if (customRenderingViewports.length) { this._resizeUsingCustomResizeHandler( customRenderingViewports, keepCamera, immediate ); } } /** * Returns the viewport by Id * * @returns viewport */ public getViewport(viewportId: string): IViewport { return this._viewports?.get(viewportId); } /** * getViewports Returns an array of all `Viewport`s on the `RenderingEngine` instance. * * @returns Array of viewports */ public getViewports(): IViewport[] { this._throwIfDestroyed(); return this._getViewportsAsArray(); } /** * Retrieves a stack viewport by its ID. used just for type safety * * @param viewportId - The ID of the viewport to retrieve. * @returns The stack viewport with the specified ID. * @throws Error if the viewport with the given ID does not exist or is not a StackViewport. */ public getStackViewport(viewportId: string): IStackViewport { this._throwIfDestroyed(); const viewport = this.getViewport(viewportId); if (!viewport) { throw new Error(`Viewport with Id ${viewportId} does not exist`); } if (!(viewport instanceof StackViewport)) { throw new Error(`Viewport with Id ${viewportId} is not a StackViewport.`); } return viewport; } /** * Filters all the available viewports and return the stack viewports * @returns stack viewports registered on the rendering Engine */ public getStackViewports(): IStackViewport[] { this._throwIfDestroyed(); const viewports = this.getViewports(); return viewports.filter( (vp) => vp instanceof StackViewport ) as IStackViewport[]; } /** * Return all the viewports that are volume viewports * @returns An array of VolumeViewport objects. */ public getVolumeViewports(): IVolumeViewport[] { this._throwIfDestroyed(); const viewports = this.getViewports(); const isVolumeViewport = ( viewport: IViewport ): viewport is BaseVolumeViewport => { return viewport instanceof BaseVolumeViewport; }; return viewports.filter(isVolumeViewport) as IVolumeViewport[]; } /** * Renders all viewports on the next animation frame. * * fires Events.IMAGE_RENDERED */ public render(): void { const viewports = this.getViewports(); const viewportIds = viewports.map((vp) => vp.id); this._setViewportsToBeRenderedNextFrame(viewportIds); } /** * Renders any viewports viewing the given Frame Of Reference. * * @param FrameOfReferenceUID - The unique identifier of the * Frame Of Reference. */ public renderFrameOfReference = (FrameOfReferenceUID: string): void => { const viewports = this._getViewportsAsArray(); const viewportIdsWithSameFrameOfReferenceUID = viewports.map((vp) => { if (vp.getFrameOfReferenceUID() === FrameOfReferenceUID) { return vp.id; } }); this.renderViewports(viewportIdsWithSameFrameOfReferenceUID); }; /** * Renders the provided Viewport IDs. * */ public renderViewports(viewportIds: string[]): void { this._setViewportsToBeRenderedNextFrame(viewportIds); } /** * Renders only a specific `Viewport` on the next animation frame. * * @param viewportId - The Id of the viewport. */ public renderViewport(viewportId: string): void { this._setViewportsToBeRenderedNextFrame([viewportId]); } /** * destroy the rendering engine. It will remove all the viewports and, * if the rendering engine is using the GPU, it will also destroy the GPU * resources. */ public destroy(): void { if (this.hasBeenDestroyed) { return; } StatsOverlay.cleanup(); // remove vtk rendered first before resetting the viewport if (!this.useCPURendering) { const viewports = this._getViewportsAsArray(); viewports.forEach((vp) => { if (this.offscreenMultiRenderWindow) { this.offscreenMultiRenderWindow.removeRenderer(vp.id); } }); // Free up WebGL resources if (this.offscreenMultiRenderWindow) { this.offscreenMultiRenderWindow.delete(); } // Make sure all references go stale and are garbage collected. delete this.offscreenMultiRenderWindow; } this._reset(); renderingEngineCache.delete(this.id); this.hasBeenDestroyed = true; } /** * Fill the canvas with the background color * @param canvas - The canvas element to draw on. * @param backgroundColor - An array of three numbers between 0 and 1 that * specify the red, green, and blue values of the background color. */ public fillCanvasWithBackgroundColor( canvas: HTMLCanvasElement, backgroundColor: [number, number, number] ): void { const ctx = canvas.getContext('2d'); // Default to black if no background color is set let fillStyle: string; if (backgroundColor) { const rgb = backgroundColor.map((f) => Math.floor(255 * f)); fillStyle = `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`; } else E{ fillStyle = 'black'; } // We draw over the previous stack with the background color while we // wait for the next stack to load ctx.fillStyle = fillStyle; ctx.fillRect(0, 0, canvas.width, canvas.height); } private _normalizeViewportInputEntry( viewportInputEntry: PublicViewportInput ) { const { type, defaultOptions } = viewportInputEntry; let options = defaultOptions; if (!options || Object.keys(options).length === 0) { options = { background: [0, 0, 0], orientation: null, displayArea: null, }; Iif (type === ViewportType.ORTHOGRAPHIC) { options = { ...options, orientation: OrientationAxis.AXIAL, }; } } return { ...viewportInputEntry, defaultOptions: options, }; } private _normalizeViewportInputEntries( viewportInputEntries: PublicViewportInput[] ): NormalizedViewportInput[] { const normalizedViewportInputs = []; viewportInputEntries.forEach((viewportInput) => { normalizedViewportInputs.push( this._normalizeViewportInputEntry(viewportInput) ); }); return normalizedViewportInputs; } private _resizeUsingCustomResizeHandler( customRenderingViewports: StackViewport[], keepCamera = true, immediate = true ) { // 1. If viewport has a custom resize method, call it here. customRenderingViewports.forEach((vp) => { if (typeof vp.resize === 'function') { vp.resize(); } }); // 3. Reset viewport cameras customRenderingViewports.forEach((vp) => { const prevCamera = vp.getCamera(); vp.resetCamera(); if (keepCamera) { vp.setCamera(prevCamera); } }); // 2. If render is immediate: Render all if (immediate) { this.render(); } } /** * Disables the requested viewportId from the rendering engine: * 1) It removes the viewport from the the list of viewports * 2) remove the renderer from the offScreen render window * 3) resetting the viewport to remove the canvas attributes and canvas data * 4) resize the offScreen appropriately * * @param viewportId - viewport Id * */ private _removeViewport(viewportId: string): void { // 1. Get the viewport const viewport = this.getViewport(viewportId); if (!viewport) { console.warn(`viewport ${viewportId} does not exist`); return; } // 2. Delete the viewports from the the viewports this._viewports.delete(viewportId); } /** * Adds a viewport using a custom rendering pipeline to the `RenderingEngine`. * * @param viewportInputEntry - Information object used to * construct and enable the viewport. */ private addCustomViewport(viewportInputEntry: PublicViewportInput): void { const { element, viewportId, type, defaultOptions } = viewportInputEntry; // Make the element not focusable, we use this for modifier keys to work element.tabIndex = -1; const canvas = getOrCreateCanvas(element); // Add a viewport with no offset const { clientWidth, clientHeight } = canvas; // Set the canvas to be same resolution as the client. // Note: This ignores devicePixelRatio for now. We may want to change it in the // future but it has no benefit for the Cornerstone CPU rendering pathway at the // moment anyway. if (canvas.width !== clientWidth || canvas.height !== clientHeight) { canvas.width = clientWidth; canvas.height = clientHeight; } const viewportInput = { id: viewportId, renderingEngineId: this.id, element, // div type, canvas, sx: 0, // No offset, uses own renderer sy: 0, sWidth: clientWidth, sHeight: clientHeight, defaultOptions: defaultOptions || {}, }; // 4. Create a proper viewport based on the type of the viewport const ViewportType = viewportTypeToViewportClass[type]; const viewport = new ViewportType(viewportInput); // 5. Storing the viewports this._viewports.set(viewportId, viewport); const eventDetail: EventTypes.ElementEnabledEventDetail = { element, viewportId, renderingEngineId: this.id, }; triggerEvent(eventTarget, Events.ELEMENT_ENABLED, eventDetail); } /** * Returns the renderer for a given viewportId. * @param viewportId - The Id of the viewport. * @returns The renderer for the viewport. */ public getRenderer(viewportId) { return this.offscreenMultiRenderWindow.getRenderer(viewportId); } /** * Returns the offscreen multi-render window used for rendering. */ public getOffscreenMultiRenderWindow( viewportId?: string ): VtkOffscreenMultiRenderWindow { if (this.useCPURendering) { throw new Error( 'Offscreen multi render window is not available when using CPU rendering.' ); } return this.offscreenMultiRenderWindow; } /** * Sets multiple viewports using custom rendering * pipelines to the `RenderingEngine`. * * @param viewportInputEntries - An array of information * objects used to construct and enable the viewports. */ private setCustomViewports(viewportInputEntries: PublicViewportInput[]) { viewportInputEntries.forEach((vpie) => { this.addCustomViewport(vpie); }); } /** * @method _getViewportsAsArray Returns an array of all viewports * * @returns Array of viewports. */ protected _getViewportsAsArray(): IViewport[] { return Array.from(this._viewports.values()); } private _setViewportsToBeRenderedNextFrame(viewportIds: string[]) { // Add the viewports to the set of flagged viewports viewportIds.forEach((viewportId) => { this._needsRender.add(viewportId); }); // Render any flagged viewports this._render(); } /** * Sets up animation frame if necessary */ private _render() { // If we have viewports that need rendering and we have not already // set the RAF callback to run on the next frame. if (this._needsRender.size > 0 && !this._animationFrameSet) { this._animationFrameHandle = window.requestAnimationFrame( this._renderFlaggedViewports ); // Set the flag that we have already set up the next RAF call. this._animationFrameSet = true; } } /** * Reset the viewport by removing the data attributes * and clearing the context of draw. It also emits an element disabled event * * @param viewport - The `Viewport` to render. */ private _resetViewport(viewport: IViewport) { const renderingEngineId = this.id; const { element, canvas, id: viewportId } = viewport; const eventDetail: EventTypes.ElementDisabledEventDetail = { element, viewportId, renderingEngineId, }; viewport.removeWidgets(); // Trigger first before removing the data attributes, as we need the enabled // element to remove tools associated with the viewport triggerEvent(eventTarget, Events.ELEMENT_DISABLED, eventDetail); element.removeAttribute('data-viewport-uid'); element.removeAttribute('data-rendering-engine-uid'); // clear drawing const context = canvas.getContext('2d'); context.clearRect(0, 0, canvas.width, canvas.height); } private _clearAnimationFrame() { window.cancelAnimationFrame(this._animationFrameHandle); this._needsRender.clear(); this._animationFrameSet = false; this._animationFrameHandle = null; } /** * Resets the `RenderingEngine` */ private _reset() { const viewports = this._getViewportsAsArray(); viewports.forEach((viewport) => { this._resetViewport(viewport); }); this._clearAnimationFrame(); this._viewports = new Map(); } /** * Throws an error if trying to interact with the `RenderingEngine` * instance after its `destroy` method has been called. */ protected _throwIfDestroyed() { Iif (this.hasBeenDestroyed) { throw new Error( 'this.destroy() has been manually called to free up memory, can not longer use this instance. Instead make a new one.' ); } } /** * Resizes viewports that use VTK.js for rendering. * This method must be implemented by subclasses to define their specific * resizing strategy. */ protected abstract _resizeVTKViewports( vtkDrivenViewports: (IStackViewport | IVolumeViewport)[], keepCamera: boolean, immediate: boolean ): void; /** * Enables a viewport to be driven by the offscreen vtk.js rendering engine. * This method must be implemented by subclasses to define their specific * viewport enabling strategy. * * @param viewportInputEntry - Information object used to * construct and enable the viewport. */ protected abstract enableVTKjsDrivenViewport( viewportInputEntry: NormalizedViewportInput ): void; /** * Adds a viewport driven by vtk.js to the `RenderingEngine`. * This method must be implemented by subclasses to define their specific * approach to adding VTK.js driven viewports. * * @param viewportInputEntry - Information object used to construct and enable the viewport. * @param offscreenCanvasProperties - Optional properties for configuring the offscreen canvas. */ protected abstract addVtkjsDrivenViewport( viewportInputEntry: InternalViewportInput, offscreenCanvasProperties?: unknown ): void; /** * Renders all viewports. * This method must be implemented by subclasses to define their specific * rendering strategy */ protected abstract _renderFlaggedViewports(): void; /** * Sets multiple vtk.js driven viewports to * the `RenderingEngine`. * This method must be implemented by subclasses to define their specific * approach to setting multiple VTK.js driven viewports. * * @param viewportInputEntries - An array of information * objects used to construct and enable the viewports. */ protected abstract setVtkjsDrivenViewports( viewportInputEntries: NormalizedViewportInput[] ): void; /** * Renders a particular `Viewport`'s on screen canvas. * This method must be implemented by subclasses to define how to copy * from the offscreen canvas to the onscreen canvas. * * @param viewport - The `Viewport` to render. * @param offScreenCanvas - The offscreen canvas to render from. */ protected abstract _renderViewportFromVtkCanvasToOnscreenCanvas( viewport: IViewport, offScreenCanvas: HTMLCanvasElement ): EventTypes.ImageRenderedEventDetail; } export default BaseRenderingEngine; |