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

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 8/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                                            3x   3x 6x   6x   6x 6x 6x   6x      
/**
 * A utility that can be used to invert (in place) an RgbTransferFunction.
 *
 * @example
 * Grabbing a reference to the RGB Transfer function from the viewport:
 * ```
 * const rgbTransferFunction = viewport
 *   .getActor()
 *   .getProperty()
 *   .getRGBTransferFunction(0);
 *
 * rgbTransferFunction.setRange(0, 5);
 *
 * invertRgbTransferFunction(rgbTransferFunction);
 * ```
 *
 * @see {@link https://kitware.github.io/vtk-js/api/Rendering_Core_ColorTransferFunction.html|VTK.js: ColorTransferFunction}
 * @param rgbTransferFunction
 */
export default function invertRgbTransferFunction(
  rgbTransferFunction: any
): void {
  const size = rgbTransferFunction.getSize();
 
  for (let index = 0; index < size; index++) {
    const nodeValue1 = [];
 
    rgbTransferFunction.getNodeValue(index, nodeValue1);
 
    nodeValue1[1] = 1 - nodeValue1[1];
    nodeValue1[2] = 1 - nodeValue1[2];
    nodeValue1[3] = 1 - nodeValue1[3];
 
    rgbTransferFunction.setNodeValue(index, nodeValue1);
  }
}