All files / Sources/Rendering/Core/Renderer index.js

79.41% Statements 243/306
71.28% Branches 72/101
62.5% Functions 30/48
80.88% Lines 237/293

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                  1x     440x                 220x     220x       220x       220x         220x                           220x       3x   3x 1x       1x   1x 1x 1x                     220x                   220x 220x   220x   220x 4x           4x 4x 4x   4x     220x 11x       11x 11x 11x 11x     220x 212x 212x 212x       220x 9595x 212x   9595x     220x 184x       184x     220x 8x 8x 9x   8x   220x 220x         220x                 220x             220x 220x         220x                 220x 220x 215x 215x 215x     220x       220x 2x 2x   220x         220x   220x 207x       207x           207x 207x   207x       207x 207x           220x 62x 62x   62x       220x 46x 46x   46x       220x 116x               116x   116x 116x     116x 116x 116x     220x 110x               110x   110x 110x     110x 110x 110x       220x 3312x               3312x 3312x   3312x 3312x 3312x         220x 3333x               3333x 3333x   3333x 3333x 3333x     220x 156x 156x 156x 156x 156x 156x 156x   156x     156x 804x 804x 803x 803x 785x   785x 150x   785x 165x   785x 153x   785x 150x   785x 144x   785x 148x           156x 22x 22x     156x     220x 149x 149x   149x 20x 20x     129x   129x 129x               129x   129x 129x 129x   129x 129x 129x 129x 129x 129x 129x     129x     129x                             129x 129x 129x     129x 129x 6x 6x       129x 129x           129x     129x     129x 129x               129x   129x     220x 183x   183x 2x 2x       181x 181x           181x       181x 181x 51x   130x     130x     181x 30x 30x 30x       181x         181x   181x       181x         181x 95x           181x 6x   181x       181x 181x     220x 219x 219x 219x       220x   220x   220x 4058x 4058x 4058x 248x   4058x 4058x 1564x   4058x     488x   302x             1x                                                                                                                                 220x     220x     220x 220x 220x     220x                       220x                                                   220x 220x 220x     220x         1x          
import { mat4, vec3 } from 'gl-matrix';
 
import * as macro from 'vtk.js/Sources/macros';
import vtkCamera from 'vtk.js/Sources/Rendering/Core/Camera';
import vtkLight from 'vtk.js/Sources/Rendering/Core/Light';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkViewport from 'vtk.js/Sources/Rendering/Core/Viewport';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
 
const { vtkDebugMacro, vtkErrorMacro, vtkWarningMacro } = macro;
 
function notImplemented(method) {
  return () => vtkErrorMacro(`vtkRenderer::${method} - NOT IMPLEMENTED`);
}
 
// ----------------------------------------------------------------------------
// vtkRenderer methods
// ----------------------------------------------------------------------------
 
function vtkRenderer(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkRenderer');
 
  // Events
  const COMPUTE_VISIBLE_PROP_BOUNDS_EVENT = {
    type: 'ComputeVisiblePropBoundsEvent',
    renderer: publicAPI,
  };
  const RESET_CAMERA_CLIPPING_RANGE_EVENT = {
    type: 'ResetCameraClippingRangeEvent',
    renderer: publicAPI,
  };
  const RESET_CAMERA_EVENT = {
    type: 'ResetCameraEvent',
    renderer: publicAPI,
  };
 
  publicAPI.updateCamera = () => {
    if (!model.activeCamera) {
      vtkDebugMacro('No cameras are on, creating one.');
      // the get method will automagically create a camera
      // and reset it since one hasn't been specified yet.
      publicAPI.getActiveCameraAndResetIfCreated();
    }
 
    // update the viewing transformation
    model.activeCamera.render(publicAPI);
 
    return true;
  };
 
  publicAPI.updateLightsGeometryToFollowCamera = () => {
    // only update the light's geometry if this Renderer is tracking
    // this lights.  That allows one renderer to view the lights that
    // another renderer is setting up.
    const camera = publicAPI.getActiveCameraAndResetIfCreated();
 
    model.lights.forEach((light) => {
      Iif (light.lightTypeIsSceneLight()) {
        // Do nothing. Don't reset the transform matrix because applications
        // may have set a custom matrix. Only reset the transform matrix in
        // vtkLight::SetLightTypeToSceneLight()
      } else if (light.lightTypeIsHeadLight()) {
        // update position and orientation of light to match camera.
        light.setPositionFrom(camera.getPositionByReference());
        light.setFocalPointFrom(camera.getFocalPointByReference());
        light.modified(camera.getMTime());
      } else Eif (light.lightTypeIsCameraLight()) {
        light.setTransformMatrix(
          camera.getCameraLightTransformMatrix(mat4.create())
        );
      } else {
        vtkErrorMacro('light has unknown light type', light.get());
      }
    });
  };
 
  publicAPI.updateLightGeometry = () => {
    if (model.lightFollowCamera) {
      // only update the light's geometry if this Renderer is tracking
      // this lights.  That allows one renderer to view the lights that
      // another renderer is setting up.
      return publicAPI.updateLightsGeometryToFollowCamera();
    }
    return true;
  };
 
  publicAPI.allocateTime = notImplemented('allocateTime');
  publicAPI.updateGeometry = notImplemented('updateGeometry');
 
  publicAPI.getVTKWindow = () => model._renderWindow;
 
  publicAPI.setLayer = (layer) => {
    vtkDebugMacro(
      publicAPI.getClassName(),
      publicAPI,
      'setting Layer to ',
      layer
    );
    if (model.layer !== layer) {
      model.layer = layer;
      publicAPI.modified();
    }
    publicAPI.setPreserveColorBuffer(!!layer);
  };
 
  publicAPI.setActiveCamera = (camera) => {
    Iif (model.activeCamera === camera) {
      return false;
    }
 
    model.activeCamera = camera;
    publicAPI.modified();
    publicAPI.invokeEvent({ type: 'ActiveCameraEvent', camera });
    return true;
  };
 
  publicAPI.makeCamera = () => {
    const camera = vtkCamera.newInstance();
    publicAPI.invokeEvent({ type: 'CreateCameraEvent', camera });
    return camera;
  };
 
  // Replace the set/get macro method
  publicAPI.getActiveCamera = () => {
    if (!model.activeCamera) {
      model.activeCamera = publicAPI.makeCamera();
    }
    return model.activeCamera;
  };
 
  publicAPI.getActiveCameraAndResetIfCreated = () => {
    Iif (!model.activeCamera) {
      publicAPI.getActiveCamera();
      publicAPI.resetCamera();
    }
    return model.activeCamera;
  };
 
  publicAPI.getActors = () => {
    model.actors = [];
    model.props.forEach((prop) => {
      model.actors = model.actors.concat(prop.getActors());
    });
    return model.actors;
  };
  publicAPI.addActor = publicAPI.addViewProp;
  publicAPI.removeActor = (actor) => {
    model.actors = model.actors.filter((a) => a !== actor);
    publicAPI.removeViewProp(actor);
    publicAPI.modified();
  };
  publicAPI.removeAllActors = () => {
    const actors = publicAPI.getActors();
    actors.forEach((actor) => {
      publicAPI.removeViewProp(actor);
    });
    model.actors = [];
    publicAPI.modified();
  };
 
  publicAPI.getVolumes = () => {
    model.volumes = [];
    model.props.forEach((prop) => {
      model.volumes = model.volumes.concat(prop.getVolumes());
    });
    return model.volumes;
  };
  publicAPI.addVolume = publicAPI.addViewProp;
  publicAPI.removeVolume = (volume) => {
    model.volumes = model.volumes.filter((v) => v !== volume);
    publicAPI.removeViewProp(volume);
    publicAPI.modified();
  };
  publicAPI.removeAllVolumes = () => {
    const volumes = publicAPI.getVolumes();
    volumes.forEach((volume) => {
      publicAPI.removeViewProp(volume);
    });
    model.volumes = [];
    publicAPI.modified();
  };
 
  publicAPI.hasLight = (light) => model.lights.includes(light);
  publicAPI.addLight = (light) => {
    if (light && !publicAPI.hasLight(light)) {
      model.lights.push(light);
      publicAPI.modified();
    }
  };
  publicAPI.removeLight = (light) => {
    model.lights = model.lights.filter((l) => l !== light);
    publicAPI.modified();
  };
  publicAPI.removeAllLights = () => {
    model.lights = [];
    publicAPI.modified();
  };
  publicAPI.setLightCollection = (lights) => {
    model.lights = lights;
    publicAPI.modified();
  };
 
  publicAPI.makeLight = vtkLight.newInstance;
 
  publicAPI.createLight = () => {
    Iif (!model.automaticLightCreation) {
      return;
    }
 
    Iif (model._createdLight) {
      publicAPI.removeLight(model._createdLight);
      model._createdLight.delete();
      model._createdLight = null;
    }
 
    model._createdLight = publicAPI.makeLight();
    publicAPI.addLight(model._createdLight);
 
    model._createdLight.setLightTypeToHeadLight();
 
    // set these values just to have a good default should LightFollowCamera
    // be turned off.
    model._createdLight.setPosition(publicAPI.getActiveCamera().getPosition());
    model._createdLight.setFocalPoint(
      publicAPI.getActiveCamera().getFocalPoint()
    );
  };
 
  // requires the aspect ratio of the viewport as X/Y
  publicAPI.normalizedDisplayToWorld = (x, y, z, aspect) => {
    let vpd = publicAPI.normalizedDisplayToProjection(x, y, z);
    vpd = publicAPI.projectionToView(vpd[0], vpd[1], vpd[2], aspect);
 
    return publicAPI.viewToWorld(vpd[0], vpd[1], vpd[2]);
  };
 
  // requires the aspect ratio of the viewport as X/Y
  publicAPI.worldToNormalizedDisplay = (x, y, z, aspect) => {
    let vpd = publicAPI.worldToView(x, y, z);
    vpd = publicAPI.viewToProjection(vpd[0], vpd[1], vpd[2], aspect);
 
    return publicAPI.projectionToNormalizedDisplay(vpd[0], vpd[1], vpd[2]);
  };
 
  // requires the aspect ratio of the viewport as X/Y
  publicAPI.viewToWorld = (x, y, z) => {
    Iif (model.activeCamera === null) {
      vtkErrorMacro(
        'ViewToWorld: no active camera, cannot compute view to world, returning 0,0,0'
      );
      return [0, 0, 0];
    }
 
    // get the view matrix from the active camera
    const matrix = model.activeCamera.getViewMatrix();
 
    mat4.invert(matrix, matrix);
    mat4.transpose(matrix, matrix);
 
    // Transform point to world coordinates
    const result = new Float64Array([x, y, z]);
    vec3.transformMat4(result, result, matrix);
    return result;
  };
 
  publicAPI.projectionToView = (x, y, z, aspect) => {
    Iif (model.activeCamera === null) {
      vtkErrorMacro(
        'ProjectionToView: no active camera, cannot compute projection to view, returning 0,0,0'
      );
      return [0, 0, 0];
    }
 
    // get the projection transformation from the active camera
    const matrix = model.activeCamera.getProjectionMatrix(aspect, -1.0, 1.0);
 
    mat4.invert(matrix, matrix);
    mat4.transpose(matrix, matrix);
 
    // Transform point to world coordinates
    const result = new Float64Array([x, y, z]);
    vec3.transformMat4(result, result, matrix);
    return result;
  };
 
  // Convert world point coordinates to view coordinates.
  publicAPI.worldToView = (x, y, z) => {
    Iif (model.activeCamera === null) {
      vtkErrorMacro(
        'WorldToView: no active camera, cannot compute view to world, returning 0,0,0'
      );
      return [0, 0, 0];
    }
 
    // get the view transformation from the active camera
    const matrix = model.activeCamera.getViewMatrix();
    mat4.transpose(matrix, matrix);
 
    const result = new Float64Array([x, y, z]);
    vec3.transformMat4(result, result, matrix);
    return result;
  };
 
  // Convert world point coordinates to view coordinates.
  // requires the aspect ratio of the viewport as X/Y
  publicAPI.viewToProjection = (x, y, z, aspect) => {
    Iif (model.activeCamera === null) {
      vtkErrorMacro(
        'ViewToProjection: no active camera, cannot compute view to projection, returning 0,0,0'
      );
      return [0, 0, 0];
    }
 
    // get the projeciton transformation from the active camera
    const matrix = model.activeCamera.getProjectionMatrix(aspect, -1.0, 1.0);
    mat4.transpose(matrix, matrix);
 
    const result = new Float64Array([x, y, z]);
    vec3.transformMat4(result, result, matrix);
    return result;
  };
 
  publicAPI.computeVisiblePropBounds = () => {
    model.allBounds[0] = vtkBoundingBox.INIT_BOUNDS[0];
    model.allBounds[1] = vtkBoundingBox.INIT_BOUNDS[1];
    model.allBounds[2] = vtkBoundingBox.INIT_BOUNDS[2];
    model.allBounds[3] = vtkBoundingBox.INIT_BOUNDS[3];
    model.allBounds[4] = vtkBoundingBox.INIT_BOUNDS[4];
    model.allBounds[5] = vtkBoundingBox.INIT_BOUNDS[5];
    let nothingVisible = true;
 
    publicAPI.invokeEvent(COMPUTE_VISIBLE_PROP_BOUNDS_EVENT);
 
    // loop through all props
    for (let index = 0; index < model.props.length; ++index) {
      const prop = model.props[index];
      if (prop.getVisibility() && prop.getUseBounds()) {
        const bounds = prop.getBounds();
        if (bounds && vtkMath.areBoundsInitialized(bounds)) {
          nothingVisible = false;
 
          if (bounds[0] < model.allBounds[0]) {
            model.allBounds[0] = bounds[0];
          }
          if (bounds[1] > model.allBounds[1]) {
            model.allBounds[1] = bounds[1];
          }
          if (bounds[2] < model.allBounds[2]) {
            model.allBounds[2] = bounds[2];
          }
          if (bounds[3] > model.allBounds[3]) {
            model.allBounds[3] = bounds[3];
          }
          if (bounds[4] < model.allBounds[4]) {
            model.allBounds[4] = bounds[4];
          }
          if (bounds[5] > model.allBounds[5]) {
            model.allBounds[5] = bounds[5];
          }
        }
      }
    }
 
    if (nothingVisible) {
      vtkMath.uninitializeBounds(model.allBounds);
      vtkDebugMacro("Can't compute bounds, no 3D props are visible");
    }
 
    return model.allBounds;
  };
 
  publicAPI.resetCamera = (bounds = null) => {
    const boundsToUse = bounds || publicAPI.computeVisiblePropBounds();
    const center = [0, 0, 0];
 
    if (!vtkMath.areBoundsInitialized(boundsToUse)) {
      vtkDebugMacro('Cannot reset camera!');
      return false;
    }
 
    let vn = null;
 
    if (publicAPI.getActiveCamera()) {
      vn = model.activeCamera.getViewPlaneNormal();
    } else E{
      vtkErrorMacro('Trying to reset non-existent camera');
      return false;
    }
 
    // Reset the perspective zoom factors, otherwise subsequent zooms will cause
    // the view angle to become very small and cause bad depth sorting.
    model.activeCamera.setViewAngle(30.0);
 
    center[0] = (boundsToUse[0] + boundsToUse[1]) / 2.0;
    center[1] = (boundsToUse[2] + boundsToUse[3]) / 2.0;
    center[2] = (boundsToUse[4] + boundsToUse[5]) / 2.0;
 
    let w1 = boundsToUse[1] - boundsToUse[0];
    let w2 = boundsToUse[3] - boundsToUse[2];
    let w3 = boundsToUse[5] - boundsToUse[4];
    w1 *= w1;
    w2 *= w2;
    w3 *= w3;
    let radius = w1 + w2 + w3;
 
    // If we have just a single point, pick a radius of 1.0
    radius = radius === 0 ? 1.0 : radius;
 
    // compute the radius of the enclosing sphere
    radius = Math.sqrt(radius) * 0.5;
 
    // default so that the bounding sphere fits within the view fustrum
 
    // compute the distance from the intersection of the view frustum with the
    // bounding sphere. Basically in 2D draw a circle representing the bounding
    // sphere in 2D then draw a horizontal line going out from the center of
    // the circle. That is the camera view. Then draw a line from the camera
    // position to the point where it intersects the circle. (it will be tangent
    // to the circle at this point, this is important, only go to the tangent
    // point, do not draw all the way to the view plane). Then draw the radius
    // from the tangent point to the center of the circle. You will note that
    // this forms a right triangle with one side being the radius, another being
    // the target distance for the camera, then just find the target dist using
    // a sin.
    const angle = vtkMath.radiansFromDegrees(model.activeCamera.getViewAngle());
    const parallelScale = radius;
    const distance = radius / Math.sin(angle * 0.5);
 
    // check view-up vector against view plane normal
    const vup = model.activeCamera.getViewUp();
    if (Math.abs(vtkMath.dot(vup, vn)) > 0.999) {
      vtkWarningMacro('Resetting view-up since view plane normal is parallel');
      model.activeCamera.setViewUp(-vup[2], vup[0], vup[1]);
    }
 
    // update the camera
    model.activeCamera.setFocalPoint(center[0], center[1], center[2]);
    model.activeCamera.setPosition(
      center[0] + distance * vn[0],
      center[1] + distance * vn[1],
      center[2] + distance * vn[2]
    );
 
    publicAPI.resetCameraClippingRange(boundsToUse);
 
    // setup default parallel scale
    model.activeCamera.setParallelScale(parallelScale);
 
    // update reasonable world to physical values
    model.activeCamera.setPhysicalScale(radius);
    model.activeCamera.setPhysicalTranslation(
      -center[0],
      -center[1],
      -center[2]
    );
 
    // Here to let parallel/distributed compositing intercept
    // and do the right thing.
    publicAPI.invokeEvent(RESET_CAMERA_EVENT);
 
    return true;
  };
 
  publicAPI.resetCameraClippingRange = (bounds = null) => {
    const boundsToUse = bounds || publicAPI.computeVisiblePropBounds();
 
    if (!vtkMath.areBoundsInitialized(boundsToUse)) {
      vtkDebugMacro('Cannot reset camera clipping range!');
      return false;
    }
 
    // Make sure we have an active camera
    publicAPI.getActiveCameraAndResetIfCreated();
    Iif (!model.activeCamera) {
      vtkErrorMacro('Trying to reset clipping range of non-existent camera');
      return false;
    }
 
    // Get the exact range for the bounds
    const range = model.activeCamera.computeClippingRange(boundsToUse);
 
    // do not let far - near be less than 0.1 of the window height
    // this is for cases such as 2D images which may have zero range
    let minGap = 0.0;
    if (model.activeCamera.getParallelProjection()) {
      minGap = 0.2 * model.activeCamera.getParallelScale();
    } else {
      const angle = vtkMath.radiansFromDegrees(
        model.activeCamera.getViewAngle()
      );
      minGap = 0.2 * Math.tan(angle / 2.0) * range[1];
    }
 
    if (range[1] - range[0] < minGap) {
      minGap = minGap - range[1] + range[0];
      range[1] += minGap / 2.0;
      range[0] -= minGap / 2.0;
    }
 
    // Do not let the range behind the camera throw off the calculation.
    Iif (range[0] < 0.0) {
      range[0] = 0.0;
    }
 
    // Give ourselves a little breathing room
    range[0] =
      0.99 * range[0] - (range[1] - range[0]) * model.clippingRangeExpansion;
    range[1] =
      1.01 * range[1] + (range[1] - range[0]) * model.clippingRangeExpansion;
 
    // Make sure near is not bigger than far
    range[0] = range[0] >= range[1] ? 0.01 * range[1] : range[0];
 
    // Make sure near is at least some fraction of far - this prevents near
    // from being behind the camera or too close in front. How close is too
    // close depends on the resolution of the depth buffer
    if (!model.nearClippingPlaneTolerance) {
      model.nearClippingPlaneTolerance = 0.01;
    }
 
    // make sure the front clipping range is not too far from the far clippnig
    // range, this is to make sure that the zbuffer resolution is effectively
    // used
    if (range[0] < model.nearClippingPlaneTolerance * range[1]) {
      range[0] = model.nearClippingPlaneTolerance * range[1];
    }
    model.activeCamera.setClippingRange(range[0], range[1]);
 
    // Here to let parallel/distributed compositing intercept
    // and do the right thing.
    publicAPI.invokeEvent(RESET_CAMERA_CLIPPING_RANGE_EVENT);
    return false;
  };
 
  publicAPI.setRenderWindow = (renderWindow) => {
    if (renderWindow !== model._renderWindow) {
      model._vtkWindow = renderWindow;
      model._renderWindow = renderWindow;
    }
  };
 
  publicAPI.visibleActorCount = () =>
    model.props.filter((prop) => prop.getVisibility()).length;
  publicAPI.visibleVolumeCount = publicAPI.visibleActorCount;
 
  publicAPI.getMTime = () => {
    let m1 = model.mtime;
    const m2 = model.activeCamera ? model.activeCamera.getMTime() : 0;
    if (m2 > m1) {
      m1 = m2;
    }
    const m3 = model._createdLight ? model._createdLight.getMTime() : 0;
    if (m3 > m1) {
      m1 = m3;
    }
    return m1;
  };
 
  publicAPI.getTransparent = () => !!model.preserveColorBuffer;
 
  publicAPI.isActiveCameraCreated = () => !!model.activeCamera;
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  pickedProp: null,
  activeCamera: null,
 
  allBounds: [],
  ambient: [1, 1, 1],
 
  allocatedRenderTime: 100,
  timeFactor: 1,
 
  automaticLightCreation: true,
 
  twoSidedLighting: true,
  lastRenderTimeInSeconds: -1,
 
  renderWindow: null,
  lights: [],
  actors: [],
  volumes: [],
 
  lightFollowCamera: true,
 
  numberOfPropsRendered: 0,
 
  propArray: null,
 
  pathArray: null,
 
  layer: 0,
  preserveColorBuffer: false,
  preserveDepthBuffer: false,
 
  computeVisiblePropBounds: vtkMath.createUninitializedBounds(),
 
  interactive: true,
 
  nearClippingPlaneTolerance: 0,
  clippingRangeExpansion: 0.05,
 
  erase: true,
  draw: true,
 
  useShadows: false,
 
  useDepthPeeling: false,
  occlusionRatio: 0,
  maximumNumberOfPeels: 4,
 
  selector: null,
  delegate: null,
 
  texturedBackground: false,
  backgroundTexture: null,
 
  environmentTexture: null,
  environmentTextureDiffuseStrength: 1,
  environmentTextureSpecularStrength: 1,
  useEnvironmentTextureAsBackground: false,
 
  pass: 0,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Inheritance
  vtkViewport.extend(publicAPI, model, initialValues);
 
  // make sure background has 4 entries. Default to opaque black
  Iif (!model.background) model.background = [0, 0, 0, 1];
  while (model.background.length < 3) model.background.push(0);
  if (model.background.length === 3) model.background.push(1);
 
  // Build VTK API
  macro.get(publicAPI, model, [
    '_renderWindow',
 
    'allocatedRenderTime',
    'timeFactor',
 
    'lastRenderTimeInSeconds',
    'numberOfPropsRendered',
    'lastRenderingUsedDepthPeeling',
 
    'selector',
  ]);
  macro.setGet(publicAPI, model, [
    'twoSidedLighting',
    'lightFollowCamera',
    'automaticLightCreation',
    'erase',
    'draw',
    'nearClippingPlaneTolerance',
    'clippingRangeExpansion',
    'backingStore',
    'interactive',
    'layer',
    'preserveColorBuffer',
    'preserveDepthBuffer',
    'useDepthPeeling',
    'occlusionRatio',
    'maximumNumberOfPeels',
    'delegate',
    'backgroundTexture',
    'texturedBackground',
    'environmentTexture',
    'environmentTextureDiffuseStrength',
    'environmentTextureSpecularStrength',
    'useEnvironmentTextureAsBackground',
    'useShadows',
    'pass',
  ]);
  macro.getArray(publicAPI, model, ['actors', 'volumes', 'lights']);
  macro.setGetArray(publicAPI, model, ['background'], 4, 1.0);
  macro.moveToProtected(publicAPI, model, ['renderWindow']);
 
  // Object methods
  vtkRenderer(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkRenderer');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };