All files / Sources/Rendering/Misc/SynchronizableRenderWindow/ObjectManager index.js

11.73% Statements 27/230
4.34% Branches 4/92
12.69% Functions 8/63
12.32% Lines 27/219

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                                                                      1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                                                                                                                     1x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     2x                                                                                                           1x             1x             23x         23x         1x                                     1x                                                                                                                                                                                                   1x 1x     1x 23x 23x               1x 10x 10x 14x                         1x 1x         1x                                          
import * as macro from 'vtk.js/Sources/macros';
 
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkCamera from 'vtk.js/Sources/Rendering/Core/Camera';
import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray';
import vtkGlyph3DMapper from 'vtk.js/Sources/Rendering/Core/Glyph3DMapper';
import vtkLight from 'vtk.js/Sources/Rendering/Core/Light';
import vtkLookupTable from 'vtk.js/Sources/Common/Core/LookupTable';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData';
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property';
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow';
import vtkTexture from 'vtk.js/Sources/Rendering/Core/Texture';
import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume';
import vtkVolumeMapper from 'vtk.js/Sources/Rendering/Core/VolumeMapper';
import vtkVolumeProperty from 'vtk.js/Sources/Rendering/Core/VolumeProperty';
import vtkImageSlice from 'vtk.js/Sources/Rendering/Core/ImageSlice';
import vtkImageMapper from 'vtk.js/Sources/Rendering/Core/ImageMapper';
import vtkImageProperty from 'vtk.js/Sources/Rendering/Core/ImageProperty';
import vtkPiecewiseFunction from 'vtk.js/Sources/Common/DataModel/PiecewiseFunction';
import vtkCubeAxesActor from 'vtk.js/Sources/Rendering/Core/CubeAxesActor';
import vtkScalarBarActor from 'vtk.js/Sources/Rendering/Core/ScalarBarActor';
import vtkAxesActor from 'vtk.js/Sources/Rendering/Core/AxesActor';
 
import BehaviorManager from '../BehaviorManager';
 
// ----------------------------------------------------------------------------
// Some internal, module-level variables and methods
// ----------------------------------------------------------------------------
 
const TYPE_HANDLERS = {};
const WRAPPED_ID_RE = /instance:\${([^}]+)}/;
const WRAP_ID = (id) => `instance:$\{${id}}`;
const ONE_TIME_INSTANCE_TRACKERS = {};
const SKIPPED_INSTANCE_IDS = [];
const EXCLUDE_INSTANCE_MAP = {};
const DATA_ARRAY_MAPPER = {
  vtkPoints,
  vtkCellArray,
  vtkDataArray,
};
 
// ----------------------------------------------------------------------------
 
function extractCallArgs(synchronizerContext, argList) {
  return argList.map((arg) => {
    const m = WRAPPED_ID_RE.exec(arg);
    if (m) {
      return synchronizerContext.getInstance(m[1]);
    }
    return arg;
  });
}
 
// ----------------------------------------------------------------------------
 
function extractInstanceIds(argList) {
  return argList
    .map((arg) => WRAPPED_ID_RE.exec(arg))
    .filter((m) => m)
    .map((m) => m[1]);
}
 
// ----------------------------------------------------------------------------
 
function extractDependencyIds(state, depList = []) {
  if (state.dependencies) {
    state.dependencies.forEach((childState) => {
      depList.push(childState.id);
      extractDependencyIds(childState, depList);
    });
  }
  return depList;
}
 
// ----------------------------------------------------------------------------
 
function bindArrays(arraysToBind) {
  while (arraysToBind.length) {
    const [fn, args] = arraysToBind.shift();
    fn(...args);
  }
}
 
// ----------------------------------------------------------------------------
 
function createNewArrayHandler(instance, arrayMetadata, arraysToBind) {
  return (values) => {
    const regMethod = arrayMetadata.registration
      ? arrayMetadata.registration
      : 'addArray';
    const location = arrayMetadata.location
      ? instance.getReferenceByName(arrayMetadata.location)
      : instance;
 
    // Try to prevent unncessary modified
    let previousArray = null;
    if (arrayMetadata.location) {
      previousArray = instance
        .getReferenceByName(arrayMetadata.location)
        .getArray(arrayMetadata.name);
    } else {
      previousArray = instance[`get${regMethod.substring(3)}`]();
    }
 
    if (previousArray) {
      if (previousArray.getData() !== values) {
        arraysToBind.push([
          previousArray.setData,
          [values, arrayMetadata.numberOfComponents],
        ]);
      }
      return previousArray;
    }
 
    const vtkClass = arrayMetadata.vtkClass
      ? arrayMetadata.vtkClass
      : 'vtkDataArray';
    const array = DATA_ARRAY_MAPPER[vtkClass].newInstance({
      ...arrayMetadata,
      values,
    });
 
    arraysToBind.push([location[regMethod], [array]]);
    return array;
  };
}
 
// ----------------------------------------------------------------------------
// Static methods for export
// ----------------------------------------------------------------------------
 
function update(type, instance, props, context) {
  if (!instance) {
    return Promise.reject(new Error(`No instance provided.`));
  }
  const handler = TYPE_HANDLERS[type];
  if (handler && handler.update) {
    return handler.update(instance, props, context);
  }
  return Promise.reject(new Error(`No updater for ${type}`));
}
 
// ----------------------------------------------------------------------------
 
function build(type, initialProps = {}) {
  const handler = TYPE_HANDLERS[type];
 
  if (handler && handler.build) {
    // DEBUG console.log(`new ${type} - ${initialProps.managedInstanceId}`);
    return handler.build(initialProps);
  }
 
  console.log('No builder for', type);
  return null;
}
 
// ----------------------------------------------------------------------------
 
function excludeInstance(type, propertyName, propertyValue) {
  EXCLUDE_INSTANCE_MAP[type] = {
    key: propertyName,
    value: propertyValue,
  };
}
 
// ----------------------------------------------------------------------------
 
function getSupportedTypes() {
  return Object.keys(TYPE_HANDLERS);
}
 
// ----------------------------------------------------------------------------
 
function clearTypeMapping() {
  Object.keys(TYPE_HANDLERS).forEach((key) => {
    delete TYPE_HANDLERS[key];
  });
}
 
// ----------------------------------------------------------------------------
 
function updateRenderWindow(instance, props, context) {
  return update('vtkRenderWindow', instance, props, context);
}
 
// ----------------------------------------------------------------------------
 
function clearAllOneTimeUpdaters() {
  Object.keys(ONE_TIME_INSTANCE_TRACKERS).forEach((key) => {
    delete ONE_TIME_INSTANCE_TRACKERS[key];
  });
}
 
// ----------------------------------------------------------------------------
 
function clearOneTimeUpdaters(...ids) {
  if (ids.length === 0) {
    return clearAllOneTimeUpdaters();
  }
 
  let array = ids;
  // allow an array passed as a single arg.
  if (array.length === 1 && Array.isArray(array[0])) {
    array = array[0];
  }
  array.forEach((instanceId) => {
    delete ONE_TIME_INSTANCE_TRACKERS[instanceId];
  });
  return array;
}
 
// ----------------------------------------------------------------------------
 
function notSkippedInstance(call) {
  if (call[1].length === 1) {
    return SKIPPED_INSTANCE_IDS.indexOf(call[1][0]) === -1;
  }
  let keep = false;
  for (let i = 0; i < call[1].length; i++) {
    keep = keep || SKIPPED_INSTANCE_IDS.indexOf(call[1][i]) === -1;
  }
  return keep;
}
 
// ----------------------------------------------------------------------------
// Updater functions
// ----------------------------------------------------------------------------
 
function genericUpdater(instance, state, context) {
  context.start(); // -> start(generic-updater)
 
  // First update our own properties
  instance.set(state.properties);
 
  // Now handle dependencies
  if (state.dependencies) {
    state.dependencies.forEach((childState) => {
      const { id, type } = childState;
 
      if (EXCLUDE_INSTANCE_MAP[type]) {
        const { key, value } = EXCLUDE_INSTANCE_MAP[type];
        if (!key || childState.properties[key] === value) {
          SKIPPED_INSTANCE_IDS.push(WRAP_ID(id));
          return;
        }
      }
 
      let childInstance = context.getInstance(id);
      if (!childInstance) {
        childInstance = build(type, { managedInstanceId: id });
        context.registerInstance(id, childInstance);
      }
      update(type, childInstance, childState, context);
    });
  }
 
  if (state.calls) {
    state.calls.filter(notSkippedInstance).forEach((call) => {
      // DEBUG console.log('==>', call[0], extractCallArgs(context, call[1]));
      instance[call[0]].apply(null, extractCallArgs(context, call[1]));
    });
  }
 
  // if some arrays need to be be fetch
  const dependencies = [];
  if (state.arrays) {
    const arraysToBind = [];
    const promises = Object.values(state.arrays).map((arrayMetadata) => {
      context.start(); // -> start(arrays)
      return context
        .getArray(arrayMetadata.hash, arrayMetadata.dataType, context)
        .then(createNewArrayHandler(instance, arrayMetadata, arraysToBind))
        .catch((error) => {
          console.log(
            'Error fetching array',
            JSON.stringify(arrayMetadata),
            error
          );
        })
        .finally(context.end); // -> end(arrays)
    });
    context.start(); // -> start(arraysToBind)
    dependencies.push(
      Promise.all(promises)
        .then(() => {
          // Since some arrays are getting updated, we should modify our dataset
          if (arraysToBind.length) {
            instance.modified();
          }
          bindArrays(arraysToBind);
          return true;
        })
        .catch((error) => {
          console.error(
            'Error in array handling for state',
            JSON.stringify(state),
            error
          );
        })
        .finally(context.end) // -> end(arraysToBind)
    );
  }
  context.end(); // -> end(generic-updater)
  return Promise.all(dependencies);
}
 
// ----------------------------------------------------------------------------
 
function oneTimeGenericUpdater(instance, state, context) {
  if (!ONE_TIME_INSTANCE_TRACKERS[state.id]) {
    genericUpdater(instance, state, context);
  }
 
  ONE_TIME_INSTANCE_TRACKERS[state.id] = true;
}
 
// ----------------------------------------------------------------------------
 
function rendererUpdater(instance, state, context) {
  // Don't do start/end on the context here because we don't need to hold up
  // rendering for the book-keeping we do after the genericUpdater finishes.
 
  // First allow generic update process to happen as usual
  genericUpdater(instance, state, context);
 
  // Any view props that were removed in the previous phase, genericUpdater(...),
  // may have left orphaned children in our instance cache.  Below is where those
  // refs can be tracked in the first place, and then later removed as necessary
  // to allow garbage collection.
 
  // In some cases, seemingly with 'vtkColorTransferFunction', the server side
  // object id may be conserved even though the actor and mapper containing or
  // using it were deleted.  In this case we must not unregister an instance
  // which is depended upon by an incoming actor just because it was also
  // depended upon by an outgoing one.
  const allActorsDeps = new Set();
 
  // Here we gather the list of dependencies (instance ids) for each view prop and
  // store them on the instance, in case that view prop is later removed.
  if (state.dependencies) {
    state.dependencies.forEach((childState) => {
      const viewPropInstance = context.getInstance(childState.id);
      if (viewPropInstance) {
        const flattenedDepIds = extractDependencyIds(childState);
        viewPropInstance.set({ flattenedDepIds }, true);
        flattenedDepIds.forEach((depId) => allActorsDeps.add(depId));
      }
    });
  }
 
  // Look for 'removeViewProp' calls and clean up references to dependencies of
  // those view props.
  const unregisterCandidates = new Set();
 
  if (state.calls) {
    state.calls
      .filter(notSkippedInstance)
      .filter((call) => call[0] === 'removeViewProp')
      .forEach((call) => {
        // extract any ids associated with a 'removeViewProp' call (though really there
        // should just be a single one), and use them to build a flat list of all
        // representation dependency ids which we can then use our synchronizer context
        // to unregister
        extractInstanceIds(call[1]).forEach((vpId) => {
          const deps = context
            .getInstance(vpId)
            .get('flattenedDepIds').flattenedDepIds;
          if (deps) {
            // Consider each dependency for un-registering
            deps.forEach((depId) => unregisterCandidates.add(depId));
          }
          // Consider the viewProp itself for un-registering
          unregisterCandidates.add(vpId);
        });
      });
  }
 
  // Now unregister any instances that are no longer needed
  const idsToUnregister = [...unregisterCandidates].filter(
    (depId) => !allActorsDeps.has(depId)
  );
  idsToUnregister.forEach((depId) => context.unregisterInstance(depId));
}
 
// ----------------------------------------------------------------------------
 
function vtkRenderWindowUpdater(instance, state, context) {
  // For each renderer we may be removing from this render window, we should first
  // remove all of the renderer's view props, then have the render window re-render
  // itself.  This will clear the screen, at which point we can go about the normal
  // updater process.
  if (state.calls) {
    state.calls
      .filter(notSkippedInstance)
      .filter((call) => call[0] === 'removeRenderer')
      .forEach((call) => {
        extractInstanceIds(call[1]).forEach((renId) => {
          const renderer = context.getInstance(renId);
          // Take brief detour through the view props to unregister the dependencies
          // of each one
          const viewProps = renderer.getViewProps();
          viewProps.forEach((viewProp) => {
            const deps = viewProp.get('flattenedDepIds').flattenedDepIds;
            if (deps) {
              deps.forEach((depId) => context.unregisterInstance(depId));
            }
            context.unregisterInstance(context.getInstanceId(viewProp));
          });
        });
      });
  }
 
  instance.render();
 
  // Now just do normal update process
  genericUpdater(instance, state, context);
 
  // Manage any associated behaviors
  BehaviorManager.applyBehaviors(instance, state, context);
}
 
// ----------------------------------------------------------------------------
 
function colorTransferFunctionUpdater(instance, state, context) {
  context.start(); // -> start(colorTransferFunctionUpdater)
  if (!state.properties.nodes) {
    instance.set(state.properties);
  } else {
    const nodes = state.properties.nodes.map(
      ([x, r, g, b, midpoint, sharpness]) => ({
        x,
        r,
        g,
        b,
        midpoint,
        sharpness,
      })
    );
    instance.set({ ...state.properties, nodes }, true);
  }
  context.end(); // -> end(colorTransferFunctionUpdater)
}
 
function piecewiseFunctionUpdater(instance, state, context) {
  context.start(); // -> start(piecewiseFunctionUpdater)
  if (!state.properties.nodes) {
    instance.set(state.properties);
  } else {
    const nodes = state.properties.nodes.map(([x, y, midpoint, sharpness]) => ({
      x,
      y,
      midpoint,
      sharpness,
    }));
    instance.set({ ...state.properties, nodes }, true);
    instance.sortAndUpdateRange();
  }
  // instance.modified();
  context.end(); // -> end(piecewiseFunctionUpdater)
}
 
// ----------------------------------------------------------------------------
 
function removeUnavailableArrays(fields, availableNames) {
  const namesToDelete = [];
  const size = fields.getNumberOfArrays();
  for (let i = 0; i < size; i++) {
    const array = fields.getArray(i);
    const name = array.getName();
    if (!availableNames.has(name)) {
      namesToDelete.push(name);
    }
  }
  for (let i = 0; i < namesToDelete.length; i++) {
    fields.removeArray(namesToDelete[i]);
  }
}
/**
 * Get a unique string suitable for use as state.arrays key.
 * @param {object} arrayMeta
 * @returns {string} array key
 */
function getArrayKey(arrayMeta) {
  // Two arrays can have exactly the same hash so try to distinquish with name.
  const namePart = arrayMeta.name ? `_${arrayMeta.name}` : '';
  return `${arrayMeta.hash}_${arrayMeta.dataType}${namePart}`;
}
 
function createDataSetUpdate(piecesToFetch = []) {
  return (instance, state, context) => {
    context.start(); // -> start(dataset-update)
 
    // Make sure we provide container for std arrays
    const localProperties = { ...state.properties };
    if (!state.arrays) {
      state.arrays = {};
    }
 
    // Array members
    // => convert old format to generic state.arrays
    for (let i = 0; i < piecesToFetch.length; i++) {
      const key = piecesToFetch[i];
      if (state.properties[key]) {
        const arrayMeta = state.properties[key];
        arrayMeta.registration = `set${macro.capitalize(key)}`;
        const arrayKey = getArrayKey(arrayMeta);
        state.arrays[arrayKey] = arrayMeta;
        delete localProperties[key];
      }
    }
 
    // Extract dataset fields
    const fieldsArrays = state.properties.fields || [];
    for (let i = 0; i < fieldsArrays.length; i++) {
      const arrayMeta = fieldsArrays[i];
      const arrayKey = getArrayKey(arrayMeta);
      state.arrays[arrayKey] = arrayMeta;
    }
    delete localProperties.fields;
 
    // Reset any pre-existing fields array
    const arrayToKeep = {
      pointData: new Set(),
      cellData: new Set(),
      fieldData: new Set(),
    };
    fieldsArrays.forEach(({ location, name }) => {
      arrayToKeep[location].add(name);
    });
    removeUnavailableArrays(instance.getPointData(), arrayToKeep.pointData);
    removeUnavailableArrays(instance.getCellData(), arrayToKeep.cellData);
 
    // Generic handling
    const cleanState = { ...state };
    cleanState.properties = localProperties;
    const res = genericUpdater(instance, cleanState, context);
 
    // Finish what we started
    context.end(); // -> end(dataset-update)
    return res;
  };
}
 
const polydataUpdater = createDataSetUpdate([
  'points',
  'polys',
  'verts',
  'lines',
  'strips',
]);
const imageDataUpdater = createDataSetUpdate([]);
 
// ----------------------------------------------------------------------------
// Construct the type mapping
// ----------------------------------------------------------------------------
 
function setTypeMapping(type, buildFn = null, updateFn = genericUpdater) {
  Iif (!build && !update) {
    delete TYPE_HANDLERS[type];
    return;
  }
 
  TYPE_HANDLERS[type] = { build: buildFn, update: updateFn };
}
 
// ----------------------------------------------------------------------------
 
const DEFAULT_ALIASES = {
  vtkMapper: [
    'vtkOpenGLPolyDataMapper',
    'vtkCompositePolyDataMapper2',
    'vtkDataSetMapper',
  ],
  vtkProperty: ['vtkOpenGLProperty'],
  vtkRenderer: ['vtkOpenGLRenderer'],
  vtkCamera: ['vtkOpenGLCamera'],
  vtkColorTransferFunction: ['vtkPVDiscretizableColorTransferFunction'],
  vtkActor: ['vtkOpenGLActor', 'vtkPVLODActor'],
  vtkLight: ['vtkOpenGLLight', 'vtkPVLight'],
  vtkTexture: ['vtkOpenGLTexture'],
  vtkImageMapper: ['vtkOpenGLImageSliceMapper'],
  vtkVolumeMapper: ['vtkFixedPointVolumeRayCastMapper'],
};
 
// ----------------------------------------------------------------------------
 
const DEFAULT_MAPPING = {
  vtkAxesActor: {
    build: vtkAxesActor.newInstance,
    update: genericUpdater,
  },
  vtkRenderWindow: {
    build: vtkRenderWindow.newInstance,
    update: vtkRenderWindowUpdater,
  },
  vtkRenderer: {
    build: vtkRenderer.newInstance,
    update: rendererUpdater,
  },
  vtkLookupTable: {
    build: vtkLookupTable.newInstance,
    update: genericUpdater,
  },
  vtkCamera: {
    build: vtkCamera.newInstance,
    update: oneTimeGenericUpdater,
  },
  vtkPolyData: {
    build: vtkPolyData.newInstance,
    update: polydataUpdater,
  },
  vtkImageData: {
    build: vtkImageData.newInstance,
    update: imageDataUpdater,
  },
  vtkMapper: {
    build: vtkMapper.newInstance,
    update: genericUpdater,
  },
  vtkGlyph3DMapper: {
    build: vtkGlyph3DMapper.newInstance,
    update: genericUpdater,
  },
  vtkProperty: {
    build: vtkProperty.newInstance,
    update: genericUpdater,
  },
  vtkActor: {
    build: vtkActor.newInstance,
    update: genericUpdater,
  },
  vtkLight: {
    build: vtkLight.newInstance,
    update: genericUpdater,
  },
  vtkColorTransferFunction: {
    build: vtkColorTransferFunction.newInstance,
    update: colorTransferFunctionUpdater,
  },
  vtkTexture: {
    build: vtkTexture.newInstance,
    update: genericUpdater,
  },
  vtkVolume: {
    build: vtkVolume.newInstance,
    update: genericUpdater,
  },
  vtkVolumeMapper: {
    build: vtkVolumeMapper.newInstance,
    update: genericUpdater,
  },
  vtkVolumeProperty: {
    build: vtkVolumeProperty.newInstance,
    update: genericUpdater,
  },
  vtkImageSlice: {
    build: vtkImageSlice.newInstance,
    update: genericUpdater,
  },
  vtkImageMapper: {
    build: vtkImageMapper.newInstance,
    update: genericUpdater,
  },
  vtkImageProperty: {
    build: vtkImageProperty.newInstance,
    update: genericUpdater,
  },
  vtkPiecewiseFunction: {
    build: vtkPiecewiseFunction.newInstance,
    update: piecewiseFunctionUpdater,
  },
  vtkCubeAxesActor: {
    build: vtkCubeAxesActor.newInstance,
    update: genericUpdater,
  },
  vtkScalarBarActor: {
    build: vtkScalarBarActor.newInstance,
    update: genericUpdater,
  },
};
 
// ----------------------------------------------------------------------------
 
function setDefaultMapping(reset = true) {
  if (reset) {
    clearTypeMapping();
  }
 
  Object.keys(DEFAULT_MAPPING).forEach((type) => {
    const mapping = DEFAULT_MAPPING[type];
    setTypeMapping(type, mapping.build, mapping.update);
  });
}
 
// ----------------------------------------------------------------------------
 
function applyDefaultAliases() {
  // Add aliases
  Object.keys(DEFAULT_ALIASES).forEach((name) => {
    const aliases = DEFAULT_ALIASES[name];
    aliases.forEach((alias) => {
      TYPE_HANDLERS[alias] = TYPE_HANDLERS[name];
    });
  });
}
 
// ----------------------------------------------------------------------------
 
function alwaysUpdateCamera() {
  setTypeMapping('vtkCamera', vtkCamera.newInstance);
  applyDefaultAliases();
}
 
// ----------------------------------------------------------------------------
setDefaultMapping();
applyDefaultAliases();
// ----------------------------------------------------------------------------
 
// Avoid handling any lights at the moment
// => vtk seems fine and PV could be fine as well but not tested so keeping PV exclude
EXCLUDE_INSTANCE_MAP.vtkPVLight = {};
 
// ----------------------------------------------------------------------------
// Publicly exposed methods
// ----------------------------------------------------------------------------
 
export default {
  build,
  update,
  genericUpdater,
  oneTimeGenericUpdater,
  setTypeMapping,
  clearTypeMapping,
  getSupportedTypes,
  clearOneTimeUpdaters,
  updateRenderWindow,
  excludeInstance,
  setDefaultMapping,
  applyDefaultAliases,
  alwaysUpdateCamera,
};