All files / packages/core/src/utilities getVoiFromSigmoidRGBTransferFunction.ts

0% Statements 0/16
100% Branches 0/0
0% Functions 0/3
0% Lines 0/15

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                                               
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
 
export default function getVoiFromSigmoidRGBTransferFunction(
  cfun: vtkColorTransferFunction
): [number, number] {
  let cfunRange = [];
  // @ts-ignore: vtk d ts problem
  const [lower, upper] = cfun.getRange();
  cfun.getTable(lower, upper, 1024, cfunRange);
  cfunRange = cfunRange.filter((v, k) => k % 3 === 0);
  const cfunDomain = [...Array(1024).keys()].map((v, k) => {
    return lower + ((upper - lower) / (1024 - 1)) * k;
  });
  const y1 = cfunRange[256];
  const logy1 = Math.log((1 - y1) / y1);
  const x1 = cfunDomain[256];
  const y2 = cfunRange[256 * 3];
  const logy2 = Math.log((1 - y2) / y2);
  const x2 = cfunDomain[256 * 3];
  const ww = Math.round((4 * (x2 - x1)) / (logy1 - logy2));
  const wc = Math.round(x1 + (ww * logy1) / 4);
  return [Math.round(wc - ww / 2), Math.round(wc + ww / 2)];
}