How do I color image data by its associated cell data?

Ok I think I have this figured out now. The key was to set scalar mode to use cell field data

		mapper->SetInputConnection(filter->GetOutputPort());
		mapper->SetLookupTable(lut);
		mapper->SetColorModeToMapScalars();			
		mapper->ScalarVisibilityOn();	
		mapper->SetScalarModeToUseCellFieldData();
		mapper->SelectColorArray("Volume Fraction (-)");
		mapper->ColorByArrayComponent("Volume Fraction (-)", 0);

I was also able to change the color with the original code by calling SetActiveScalars on the reader.

So it seems like the “active scalar” is used when SetScalarModeToUseCellData is on. If SetScalarModeToUseCellFieldData is on, I can just change the coloring with the mapper itself by subsequently calling ColorByArrayComponent.

1 Like