All files / Sources/Rendering/OpenGL/Volume index.js

85.71% Statements 42/49
74.07% Branches 20/27
100% Functions 7/7
85.71% Lines 42/49

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                          15x     15x 36x     36x 18x     18x   18x 18x 18x 18x       15x 36x 18x     18x       15x 18x                 18x   18x   18x       15x 36x     36x     15x   18x 16x 16x 16x   16x 16x           16x     18x               1x                     15x     15x   15x 15x   15x 15x     15x     15x         1x             1x  
import { mat3, mat4 } from 'gl-matrix';
 
import * as macro from 'vtk.js/Sources/macros';
import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';
 
import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory';
 
// ----------------------------------------------------------------------------
// vtkOpenGLVolume methods
// ----------------------------------------------------------------------------
 
function vtkOpenGLVolume(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkOpenGLVolume');
 
  // Builds myself.
  publicAPI.buildPass = (prepass) => {
    Iif (!model.renderable || !model.renderable.getVisibility()) {
      return;
    }
    if (prepass) {
      model._openGLRenderWindow = publicAPI.getFirstAncestorOfType(
        'vtkOpenGLRenderWindow'
      );
      model._openGLRenderer =
        publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer');
      model.context = model._openGLRenderWindow.getContext();
      publicAPI.prepareNodes();
      publicAPI.addMissingNode(model.renderable.getMapper());
      publicAPI.removeUnusedNodes();
    }
  };
 
  publicAPI.queryPass = (prepass, renderPass) => {
    if (prepass) {
      Iif (!model.renderable || !model.renderable.getVisibility()) {
        return;
      }
      renderPass.incrementVolumeCount();
    }
  };
 
  publicAPI.traverseVolumePass = (renderPass) => {
    Iif (
      !model.renderable ||
      !model.renderable.getNestedVisibility() ||
      (model._openGLRenderer.getSelector() &&
        !model.renderable.getNestedPickable())
    ) {
      return;
    }
 
    publicAPI.apply(renderPass, true);
 
    model.children[0].traverse(renderPass);
 
    publicAPI.apply(renderPass, false);
  };
 
  // Renders myself
  publicAPI.volumePass = (prepass) => {
    Iif (!model.renderable || !model.renderable.getVisibility()) {
      return;
    }
    model.context.depthMask(!prepass);
  };
 
  publicAPI.getKeyMatrices = () => {
    // has the actor changed?
    if (model.renderable.getMTime() > model.keyMatrixTime.getMTime()) {
      model.renderable.computeMatrix();
      mat4.copy(model.MCWCMatrix, model.renderable.getMatrix());
      mat4.transpose(model.MCWCMatrix, model.MCWCMatrix);
 
      if (model.renderable.getIsIdentity()) {
        mat3.identity(model.normalMatrix);
      } else E{
        mat3.fromMat4(model.normalMatrix, model.MCWCMatrix);
        mat3.invert(model.normalMatrix, model.normalMatrix);
        mat3.transpose(model.normalMatrix, model.normalMatrix);
      }
      model.keyMatrixTime.modified();
    }
 
    return { mcwc: model.MCWCMatrix, normalMatrix: model.normalMatrix };
  };
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  // context: null,
  // keyMatrixTime: null,
  // normalMatrix: null,
  // MCWCMatrix: null,
  // _openGLRenderWindow: null,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Inheritance
  vtkViewNode.extend(publicAPI, model, initialValues);
 
  model.keyMatrixTime = {};
  macro.obj(model.keyMatrixTime, { mtime: 0 });
  // always set by getter
  model.normalMatrix = new Float64Array(9);
  model.MCWCMatrix = new Float64Array(16);
 
  // Build VTK API
  macro.setGet(publicAPI, model, ['context']);
 
  // Object methods
  vtkOpenGLVolume(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkOpenGLVolume');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };
 
// Register ourself to OpenGL backend if imported
registerOverride('vtkVolume', newInstance);