All files / Sources/Filters/Sources/ArrowSource index.js

92.3% Statements 36/39
40% Branches 2/5
100% Functions 3/3
92.3% Lines 36/39

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                        13x     12x       12x 12x 12x 12x 12x   12x 12x 12x     12x           12x 12x 12x 12x   12x 12x     12x         12x 12x 12x   12x 12x   12x       12x                       12x             12x         13x             1x                           13x     13x 13x               13x 13x 13x         1x          
import macro from 'vtk.js/Sources/macros';
import vtkAppendPolyData from 'vtk.js/Sources/Filters/General/AppendPolyData';
import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource';
import vtkCylinderSource from 'vtk.js/Sources/Filters/Sources/CylinderSource';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';
 
// ----------------------------------------------------------------------------
// vtkArrowSource methods
// ----------------------------------------------------------------------------
 
function vtkArrowSource(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkArrowSource');
 
  function requestData(inData, outData) {
    Iif (model.deleted) {
      return;
    }
 
    const cylinder = vtkCylinderSource.newInstance({ capping: true });
    cylinder.setResolution(model.shaftResolution);
    cylinder.setRadius(model.shaftRadius);
    cylinder.setHeight(1.0 - model.tipLength);
    cylinder.setCenter(0, (1.0 - model.tipLength) * 0.5, 0.0);
 
    const cylinderPD = cylinder.getOutputData();
    const cylinderPts = cylinderPD.getPoints().getData();
    const cylinderNormals = cylinderPD.getPointData().getNormals().getData();
 
    // Apply transformation to the cylinder
    vtkMatrixBuilder
      .buildFromDegree()
      .rotateZ(-90)
      .apply(cylinderPts)
      .apply(cylinderNormals);
 
    const cone = vtkConeSource.newInstance();
    cone.setResolution(model.tipResolution);
    cone.setHeight(model.tipLength);
    cone.setRadius(model.tipRadius);
 
    const conePD = cone.getOutputData();
    const conePts = conePD.getPoints().getData();
 
    // Apply transformation to the cone
    vtkMatrixBuilder
      .buildFromRadian()
      .translate(1.0 - model.tipLength * 0.5, 0.0, 0.0)
      .apply(conePts);
 
    const append = vtkAppendPolyData.newInstance();
    append.setInputData(cylinderPD);
    append.addInputData(conePD);
 
    const appendPD = append.getOutputData();
    const appendPts = appendPD.getPoints().getData();
    // Center the arrow about [0, 0, 0]
    vtkMatrixBuilder
      .buildFromRadian()
      .translate(-0.5 + model.tipLength * 0.5, 0.0, 0.0)
      .apply(appendPts);
    Iif (model.invert) {
      // Apply transformation to the arrow
      vtkMatrixBuilder
        .buildFromRadian()
        .rotateFromDirections([1, 0, 0], model.direction)
        .scale(-1, -1, -1)
        .apply(appendPts);
 
      // Update output
      outData[0] = appendPD;
    } else {
      // Apply transformation to the arrow
      vtkMatrixBuilder
        .buildFromRadian()
        .rotateFromDirections([1, 0, 0], model.direction)
        .scale(1, 1, 1)
        .apply(appendPts);
 
      // Update output
      outData[0] = append.getOutputData();
    }
  }
 
  // Expose methods
  publicAPI.requestData = requestData;
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  tipResolution: 6,
  tipRadius: 0.1,
  tipLength: 0.35,
  shaftResolution: 6,
  shaftRadius: 0.03,
  invert: false,
  direction: [1.0, 0.0, 0.0],
  pointType: 'Float64Array',
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Build VTK API
  macro.obj(publicAPI, model);
  macro.setGet(publicAPI, model, [
    'tipResolution',
    'tipRadius',
    'tipLength',
    'shaftResolution',
    'shaftRadius',
    'invert',
  ]);
  macro.setGetArray(publicAPI, model, ['direction'], 3);
  macro.algo(publicAPI, model, 0, 1);
  vtkArrowSource(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkArrowSource');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };