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

0% Statements 0/9
100% Branches 0/0
0% Functions 0/1
0% Lines 0/8

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                                                                           
/**
 * A utility that can be used to scale (in place) an RgbTransferFunction. We
 * often use this to scale the transfer function based on a PET calculation.
 *
 * @example
 * Grabbing a reference to the RGB Transfer function from the viewport:
 * ```
 * const rgbTransferFunction = viewport
 *   .getActor()
 *   .getProperty()
 *   .getRGBTransferFunction(0);
 *
 * scaleRgbTransferFunction(rgbTransferFunction, 2);
 * ```
 *
 * @see {@link https://kitware.github.io/vtk-js/api/Rendering_Core_ColorTransferFunction.html|VTK.js: ColorTransferFunction}
 * @param rgbTransferFunction
 * @param scalingFactor
 */
export default function scaleRGBTransferFunction(
  rgbTransferFunction: any,
  scalingFactor: number
): void {
  const size = rgbTransferFunction.getSize();
 
  for (let index = 0; index < size; index++) {
    const nodeValue1 = [];
 
    rgbTransferFunction.getNodeValue(index, nodeValue1);
 
    nodeValue1[1] = nodeValue1[1] * scalingFactor;
    nodeValue1[2] = nodeValue1[2] * scalingFactor;
    nodeValue1[3] = nodeValue1[3] * scalingFactor;
 
    rgbTransferFunction.setNodeValue(index, nodeValue1);
  }
}