All files / Sources/Common/DataModel/Cell index.js

58.22% Statements 46/79
32.14% Branches 9/28
58.33% Functions 7/12
58.1% Lines 43/74

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                    92x   92x 120x 7x 7x 7x 23x     113x 113x 113x 62x         113x 113x     2132x 2132x 2132x 2132x 2132x   113x       92x                                                     92x                     92x   1x   1x 3x   3x       3x   3x       1x     92x   92x 3x     92x 92x 92x                               1x               92x   92x   92x 92x     92x   92x         1x          
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
 
// ----------------------------------------------------------------------------
// vtkCell methods
// ----------------------------------------------------------------------------
 
function vtkCell(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkCell');
 
  publicAPI.initialize = (points, pointIdsList = null) => {
    if (!pointIdsList) {
      model.points = points;
      model.pointsIds = new Array(points.getNumberOfPoints());
      for (let i = points.getNumberOfPoints() - 1; i >= 0; --i) {
        model.pointsIds[i] = i;
      }
    } else {
      model.pointsIds = pointIdsList;
      let triangleData = model.points.getData();
      if (triangleData.length !== 3 * model.pointsIds.length) {
        triangleData = macro.newTypedArray(
          points.getDataType(),
          3 * model.pointsIds.length
        );
      }
      const pointsData = points.getData();
      model.pointsIds.forEach((pointId, index) => {
        // const start = 3 * pointId;
        // pointsData.set(p.subarray(start, start + 3), 3 * index);
        let pointOffset = 3 * pointId;
        let trianglePointOffset = 3 * index;
        triangleData[trianglePointOffset] = pointsData[pointOffset];
        triangleData[++trianglePointOffset] = pointsData[++pointOffset];
        triangleData[++trianglePointOffset] = pointsData[++pointOffset];
      });
      model.points.setData(triangleData);
    }
  };
 
  publicAPI.getBounds = () => {
    const nbPoints = model.points.getNumberOfPoints();
    const x = [];
    if (nbPoints) {
      model.points.getPoint(0, x);
      model.bounds[0] = x[0];
      model.bounds[1] = x[0];
      model.bounds[2] = x[1];
      model.bounds[3] = x[1];
      model.bounds[4] = x[2];
      model.bounds[5] = x[2];
 
      for (let i = 1; i < nbPoints; i++) {
        model.points.getPoint(i, x);
        model.bounds[0] = x[0] < model.bounds[0] ? x[0] : model.bounds[0];
        model.bounds[1] = x[0] > model.bounds[1] ? x[0] : model.bounds[1];
        model.bounds[2] = x[1] < model.bounds[2] ? x[1] : model.bounds[2];
        model.bounds[3] = x[1] > model.bounds[3] ? x[1] : model.bounds[3];
        model.bounds[4] = x[2] < model.bounds[4] ? x[2] : model.bounds[4];
        model.bounds[5] = x[2] > model.bounds[5] ? x[2] : model.bounds[5];
      }
    } else {
      vtkMath.uninitializeBounds(model.bounds);
    }
    return model.bounds;
  };
 
  publicAPI.getLength2 = () => {
    publicAPI.getBounds();
    let length = 0.0;
    let diff = 0;
    for (let i = 0; i < 3; i++) {
      diff = model.bounds[2 * i + 1] - model.bounds[2 * i];
      length += diff * diff;
    }
    return length;
  };
 
  publicAPI.getParametricDistance = (pcoords) => {
    let pDist;
    let pDistMax = 0.0;
 
    for (let i = 0; i < 3; i++) {
      Iif (pcoords[i] < 0.0) {
        pDist = -pcoords[i];
      } else Iif (pcoords[i] > 1.0) {
        pDist = pcoords[i] - 1.0;
      } else {
        // inside the cell in the parametric direction
        pDist = 0.0;
      }
      Iif (pDist > pDistMax) {
        pDistMax = pDist;
      }
    }
    return pDistMax;
  };
 
  publicAPI.getNumberOfPoints = () => model.points.getNumberOfPoints();
 
  publicAPI.deepCopy = (cell) => {
    cell.initialize(model.points, model.pointsIds);
  };
 
  publicAPI.getCellDimension = () => {}; // virtual
  publicAPI.intersectWithLine = (p1, p2, tol, t, x, pcoords, subId) => {}; // virtual
  publicAPI.evaluatePosition = (
    x,
    closestPoint,
    subId,
    pcoords,
    dist2,
    weights
  ) => {
    macro.vtkErrorMacro('vtkCell.evaluatePosition is not implemented.');
  }; // virtual
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  bounds: [-1, -1, -1, -1, -1, -1],
  pointsIds: [],
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  macro.obj(publicAPI, model);
 
  if (!model.points) {
    model.points = vtkPoints.newInstance();
  }
 
  macro.get(publicAPI, model, ['points', 'pointsIds']);
 
  vtkCell(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkCell');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };