vtkColorMaps getPresetByName with vtk.js as external script

From https://kitware.github.io/vtk-js/examples/ScalarToRGBA.html
there are those lines to preset a lookup table:

import vtkColorMaps from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps';
import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';

const lookupTable = vtkColorTransferFunction.newInstance();
const preset = vtkColorMaps.getPresetByName('erdc_rainbow_bright');
lookupTable.applyColorMap(preset);
lookupTable.setMappingRange(...dataRange);
lookupTable.updateRange();

But how to do the same when you use vtk.js as an external script ?
I cannot find how to instantiate vtkColorMaps.

const lookup = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
const preset = vtk.Rendering.Core.???????
preset.getPresetByName('erdc_rainbow_bright');
lookup.applyColorMap(preset);
lookup.build();

Hi Patrick,

This is a missing export. I will add the export in and you should be able to use it shortly like so:

const vtkColorMaps = vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps;
const preset = vtkColorMaps.getPresetByName('erdc_rainbow_light');

Update: the latest vtk.js version now supports the above export. Let me know if it doesn’t work for you for some reason.

Thank you for the support and action !
It works now.
Also note that ‘erdc_rainbow_light’ is now named ‘erdc_rainbow_bright’

var lookup = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
var preset = vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps.getPresetByName('erdc_rainbow_bright');
lookup.applyColorMap(preset);
lookup.setNanColor(1.0, 1.0, 1.0, 1.0);    // should be after applyColorMap
lookup.build();

To get all preset color maps:

console.log(vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps.rgbPresetNames);

image

1 Like