[vtk.js] vtkLookupTable.setNumberOfTableValues is not a function

Hello

I’m trying to build a custom LUT, but I can’t translate one example from python/c++ to javascript. My code fails at the line vtkLookupTable.setNumberOfTableValues(256) saying that it is not a function.

What is wrong here?

    function buildLookupTable(){
        // Same colors as for 2D
        const grad = ["#FFFAFA", "#FFEDD6", "#FFE1B2", "#FFD58E", "#FFC96B",
        "#FFBD47", "#FFB123", "#FFA500", "#FF8D00", "#FF7500", "#FF5E00", 
        "#FF4600", "#FF2F00", "#FF1700", "#FF0000"];
        // Build the color transfer function
        let ctransfer = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
        for (i = 0; i < grad.length; i++) {
            let color = hexToRgbA(grad[i]);
            ctransfer.addRGBPoint(i, ...color);
        }
        ctransfer.build();
        // Build the lookup table with 256 colors and 1/5 transparent
        let numberOfColors = 256;
        let lut = vtk.Common.Core.vtkLookupTable.newInstance();
        lut.setNumberOfTableValues(numberOfColors);
        for (i = 0; i < numberOfColors; i++) {
            let rgb  = ctransfer.getColor( ((i * grad.length)/numberOfColors ) );
            lut.setTableValue(i, rgb[0],rgb[1],rgb[1], Math.min(1, i*5/numberOfColors));
        }
        lut.setNanColor(1,0,1,0);
        lut.build();
        return lut;
    }

Best regards
Alex

This is harder than I thought: setTableValue is also not a function!!

Is there a way to build a LookupTable in vtk.js??

I found a way, although it is really odd and not as I expect the api to work

Final working example:

// grad is an array of string hex colors
function buildLookupTable(grad){
        // Build the color transfer function
        let ctransfer = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
        for (i = 0; i < grad.length; i++) {
            let rgb = hexToRgbA(grad[i]);
            ctransfer.addRGBPoint(i, rgb[0], rgb[1], rgb[2]); // There is no way to add alpha here
        }
        ctransfer.build();
        // Build the lookup table
        let lut = vtk.Common.Core.vtkLookupTable.newInstance();
        let numberOfColors = lut.getNumberOfColors(); // Default 256 colors
        // Build the color table (returns as Float32Array)
        let colorArray = ctransfer.getUint8Table(0,numberOfColors-1,numberOfColors,true); // true adds space for alpha channel
        for (i = 0; i < numberOfColors/5; i++) { // 1/5 transparent with increased opacity
            colorArray[i * 4 + 3] = i*5;
        }
        // Convert to vtkDataArray
        let colorTable = vtk.Common.Core.vtkDataArray.newInstance({
            name: "Color Data Array",
            values: colorArray,
            numberOfComponents: 4  // 4 components R, G, B, A
        }); 
        // Assign the table and build the lut
        lut.setTable(colorTable);
        lut.build();
        return lut;
    }