Hello,blow code was used to set cell color:
void SceneObject::coloringSelectedCells() {
vtkNew nc;
auto orbg = property()->GetColor();
double originalColor[4] = { orbg[0] * 255, orbg[1] * 255, orbg[2] * 255, 1 };
auto newColor = nc->GetColor4d(“Red”).GetData();
auto const originalColorIdx = 0;
auto const newColorIdx = 1;
auto size = data()->GetNumberOfCells();//setup scalars
vtkNew scalars;
scalars->SetNumberOfTuples(size); //LP why can’t size be 2 here?
//preserve surface color
for (vtkIdType i = 0; i < size; i++) {
scalars->SetTuple1(i, originalColorIdx);
}//set cell color
for (auto const id : selectedCells) {
scalars->SetTuple1(id, newColorIdx);
}
data()->GetCellData()->SetScalars(scalars);
asActor()->GetMapper()->SetScalarRange(0, size - 1);//setup lookup table
vtkNew lut;
lut->SetNumberOfTableValues(size);
lut->SetTableValue(originalColorIdx, originalColor);
lut->SetTableValue(newColorIdx, newColor);
// lut->SetVectorModeToRGBColors();
lut->Build();
asActor()->GetMapper()->SetLookupTable(lut);_parent->rerender(this);
}
Strangely,opacity got changed,how to prevent opactiy change?