ColorTransferFunction - Stepped colors

Hi there,

I am using a vtkColorTransfer function to apply colors to scalar values in my polydata. I am then applying this function to my scalarBarActor. This looks like the image below:

I am wondering if there is a way to not have blended colors, and rather have stepped coloring, similar to below:

Screenshot 2022-10-12 111218

Any help/guidance would be much appreciated!

Thanks

For a little more context - I am using images generated from vtk and creating gifs. The scalar bar in the gif is not being generated well inside of the gif due to the color limitations of gif files. I’d like to control the colors in the lookup table so that the generated gifs match the images rendered in vtk

Did you consider vtkLookupTable that support “indexed” colors ?

I did not!

Is there an example implementation of this somewhere do you know?

Thanks

1 Like

Great thank you very much, i’ll give this a go!

After giving this a go, unfortunately it doesn’t seem like the colors applied in the lookup table are mapping to values. The scalar bar reflects this as it doesn’t contain any range of colors.

Any ideas what I am missing here? See below for code, and current output

Apologies in advance if its obvious, really hard to find documentation on this anywhere.

I’ve got some code somewhere that works as such:

const lut = vtkLookupTable.newInstance();
const data = new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255]);
const table = vtkDataArray.newInstance({
  values: data,
  numberOfComponents: 4
});
lut.setTable(table);
mapper.setLookupTable(lut);
mapper.setColorByArrayName("Scalars");
mapper.setColorModeToMapScalars();

Could it work also for you ?

1 Like

That has worked!

Thank you very much - I can stop tearing my hair out now :slight_smile:

Have a great day

Have a look at this example ElevationBandsWithGlyphs