I actually had the same problem. SetBlockColor()
of the mapper did not seem to have any effect neither did SetBlockVisibility()
. I found an example in the unittests and it turns out that you have to set
vtkNew<vtkCompositeDataDisplayAttributes> cdsa;
mapper->SetCompositeDataDisplayAttributes(cdsa);
only then setting block attributes will work fine. When setting per block colors and visibility make sure to use its flat index which is not the same as the index when you use SetBlock()
. In my case I had n polyDatas which I added to the root using SetBlock(0), SetBlock(1)...
and then changed their color SetBlockColor(1), SetBlockColor(2),...
.
You can also set colors within each polyData object as an alternative.
vtkNew<vtkUnsignedCharArray> colors;
colors->SetNumberOfComponents(3);
for (int i = 0; i < polyData->GetNumberOfCells(); ++i) {
colors->InsertNextTuple3(255, 0, 0);
}
polyData->GetCellData()->SetScalars(colors);