VTK interaction (zooming, panning) is very laggy with alpha color

Hi guys,

I have a problem with VTK graphics. The interaction is very slow when alpha color is set in the color map. The panning and zooming is very laggy which makes the program not so responsive.

My vtkPolyData saved using vtkXMLPolyDataWriter
https://1drv.ms/u/s!AklyhGnzAg_viJx8oi9BY2mpMiKIQg?e=fiPaX1

And this is my test code

// Load data
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName("D:/cubes.vtp");
reader->Update();
auto polyData = reader->GetOutput();

// Update the alpha value
auto scalar = dynamic_cast<vtkUnsignedCharArray*>(polyData->GetCellData()->GetScalars());
auto tNum = scalar->GetNumberOfTuples();
for (auto i = 0; i < tNum; i++) {
	auto color = scalar->GetTuple(i);
	color[3] = 200; // Vtk is slow with alpha=200. If no alpha (color[3] = 255), everything is good.
	scalar->SetTuple(i, color);
}

// Displaying
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polyData);
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

I tried with Paraview, it’s also slow when “Enable opacity mapping for surfaces” is on.


Paraview

Yours,

You may achieve several magnitudes faster rendering of such volumes using GPU volume raycasting.

Hi Andras,

Thanks for replying. Could you please give more details about GPU volume raycasting with VTK? There’re 64000 cubes in my cubes.vtp file. I don’t think it’s a big volume with VTK. Because the rendering is very fast, only there’re issue with interaction.

Yours,
Dang Thai Hung

Point picking is also faster if you render the volume as a volume. It can take a while to check each of 64000 cells, while casting a ray in a volume is very fast. Not all picker can be used with volume rendering actors, but as far as I remember, the basic cell picker works.

Hi Andras,

Thanks for the reply. I just use a traditional vtkPolyData to render the cubes. The rendering goes fast. The slow interaction I mentioned is about the VTK built-in zoom, pan when transparency is set.

Yours,

Correct rendering of semi-transparent meshes are much slower because you need to render the triangles in the correct order (need to use depth peeling or similar technique) and you need to render all of them (if the triangles are opaque then it is enough to render the one that is closest to the camera).

Volume raycasting mappers can render semi-transparent cubic elements in a rectilinear grid several magnitudes faster. Therefore, if you are lucky to have such structured data set and you have rendering performance issues then volume raycasting may be a good approach.