Display data with a "preset" LookupTable


In ParaView & VTK.js, there are several Color table presets (stored in ColorMaps.json), and functions to transform these presets into valid LookupTables.

I’ve tried to replicate those codes into classic C++ API, but cannot achieve the desired result.
I simply want to make a valid LookupTable to pass to my Mapper, starting from the values inside ColorMaps.json.

My current code looks like :

auto preset = Preset["jet"]; // jet is a double[] with values from RGBPoints
vtkNew<vtkColorTransferFunction> xfer;
for (int i=0; i<preset.length/4; i++) xfer->AddRGBPoint(preset[4*i+0], preset[4*i+1], preset[4*i+2], preset[4*i+3]));

vtkNew<vtkLookupTable> table;
for (int i=0; i<256; i++)
	auto rgb = new double[3];
	xfer->GetColor(n / 256.0, rgb);
	table->SetTableValue(i, rgb[0], rgb[1], rgb[2], 1);

This code actually works when the chosen Preset has X values range [0 … 1].
When Preset has [-1 … +1], for example “JET”, the code is obviously not good.
I can of course look at Preset actual range and change the second for loop accordingly, but I wonder if there was better / simpler ways to achieve some kind of automatic translation from vtkColorTransferFunction to vtkLookupTable ?

Thanks !