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

90.9% Statements 10/11
50% Branches 1/2
100% Functions 1/1
90% Lines 9/10

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                                              4x       4x   4x 8x   8x   8x 8x 8x   8x      
/**
 * 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 {
  // cut in case there is no function at all
  Iif (!rgbTransferFunction) {
    return;
  }
 
  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);
  }
}