As the title describe, I want to set the cell with zero field data to total opactity, but It doesn’t work, here is the simple code I have tried, can anybody help me, thanks!
void simpleVtk()
{
vtkNew<vtkPoints> points;
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(1, 1, 0);
points->InsertNextPoint(0, 1, 0);
points->InsertNextPoint(2, 0, 0);
points->InsertNextPoint(2, 1, 0);
vtkNew<vtkFloatArray> scalar;
scalar->InsertNextTuple1(0.0);
scalar->InsertNextTuple1(50.0);
scalar->InsertNextTuple1(100.0);
scalar->InsertNextTuple1(200.0);
vtkNew<vtkCellArray> polys;
vtkIdType ptIndexs[3];
ptIndexs[0] = 0;
ptIndexs[1] = 1;
ptIndexs[2] = 2;
polys->InsertNextCell(3, ptIndexs);
ptIndexs[0] = 0;
ptIndexs[1] = 2;
ptIndexs[2] = 3;
polys->InsertNextCell(3, ptIndexs);
ptIndexs[0] = 1;
ptIndexs[1] = 4;
ptIndexs[2] = 5;
polys->InsertNextCell(3, ptIndexs);
ptIndexs[0] = 1;
ptIndexs[1] = 5;
ptIndexs[2] = 2;
polys->InsertNextCell(3, ptIndexs);
vtkNew<vtkPolyData> polydata;
polydata->SetPolys(polys);
polydata->SetPoints(points);
polydata->GetCellData()->SetScalars(scalar);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(polydata);
mapper->SetScalarRange(scalar->GetRange());
mapper->Update();
vtkNew<vtkDiscretizableColorTransferFunction> colorTransferFunction;
//vtkNew<vtkColorTransferFunction> colorTransferFunction;
double rgbPoints[] = { 0,
0.23137254902,
0.298039215686,
0.752941176471,
0.5,
0.865,
0.865,
0.865,
1,
0.705882352941,
0.0156862745098,
0.149019607843 };
double range[2];
range[0] = scalar->GetRange()[0];
range[1] = scalar->GetRange()[1];
const double scale = range[1] - range[0];
for (auto i = 0; i < 3; i++)
{
colorTransferFunction->AddRGBPoint(range[0]+rgbPoints[4 * i]*scale, rgbPoints[4 * i + 1], rgbPoints[4 * i + 2], rgbPoints[4 * i + 3]);
}
//colorTransferFunction->SetNanOpacity(0);
//colorTransferFunction->SetNanColorRGBA(0, 0, 0, 1);
vtkNew<vtkPiecewiseFunction> opacityFunction;
opacityFunction->AddSegment(0, 1, 0.01, 1);
opacityFunction->AddSegment(0.01, 0, range[1], 0);
colorTransferFunction->EnableOpacityMappingOn();
colorTransferFunction->SetScalarOpacityFunction(opacityFunction);
colorTransferFunction->Build();
mapper->SetLookupTable(colorTransferFunction);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> window;
window->SetSize(800, 800);
window->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(window);
renderer->AddActor(actor);
window->Render();
interactor->Start();
}