All files / Sources/Imaging/Core/AbstractImageInterpolator InterpolationInfo.js

31.81% Statements 7/22
16.66% Branches 2/12
40% Functions 2/5
31.81% Lines 7/22

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    1x                       1x                                       3452163x             3054210x 3054210x 3054210x 3054210x                                                                            
import { ImageBorderMode, InterpolationMode } from './Constants';
 
export const vtkInterpolationInfo = {
  pointer: null,
  extent: [0, -1, 0, -1, 0, -1],
  increments: [0, 0, 0],
  scalarType: null, // dataType
  dataTypeSize: 1, // BYTES_PER_ELEMENT
  numberOfComponents: 1,
  borderMode: ImageBorderMode.CLAMP,
  interpolationMode: InterpolationMode.LINEAR,
  extraInfo: null,
};
 
export const vtkInterpolationWeights = {
  ...vtkInterpolationInfo,
  positions: [0, 0, 0],
  weights: null,
  weightExtent: [0, -1, 0, -1, 0, -1],
  kernelSize: [1, 1, 1],
  workspace: null,
  lastY: null,
  lastZ: null,
};
 
export function vtkInterpolationMathFloor(x) {
  const integer = Math.floor(x);
  return {
    floored: integer,
    error: x - integer,
  };
}
 
export function vtkInterpolationMathRound(x) {
  return Math.round(x);
}
 
//----------------------------------------------------------------------------
// Perform a clamp to limit an index to [b, c] and subtract b.
 
export function vtkInterpolationMathClamp(a, b, c) {
  let clamp = a <= c ? a : c;
  clamp -= b;
  clamp = clamp >= 0 ? clamp : 0;
  return clamp;
}
 
//----------------------------------------------------------------------------
// Perform a wrap to limit an index to [b, c] and subtract b.
 
export function vtkInterpolationMathWrap(a, b, c) {
  const range = c - b + 1;
  let wrap = a - b;
  wrap %= range;
  // required for some % implementations
  wrap = wrap >= 0 ? wrap : wrap + range;
  return wrap;
}
 
//----------------------------------------------------------------------------
// Perform a mirror to limit an index to [b, c] and subtract b.
 
export function vtkInterpolationMathMirror(a, b, c) {
  const range = c - b;
  const ifzero = range === 0 ? 1 : 0;
  const range2 = 2 * range + ifzero;
  let mirror = a - b;
  mirror = mirror >= 0 ? mirror : -mirror;
  mirror %= range2;
  mirror = mirror <= range ? mirror : range2 - mirror;
  return mirror;
}
 
export default {
  vtkInterpolationInfo,
  vtkInterpolationWeights,
  vtkInterpolationMathFloor,
  vtkInterpolationMathRound,
  vtkInterpolationMathClamp,
  vtkInterpolationMathWrap,
  vtkInterpolationMathMirror,
};