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

**URL:** https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753
**Category:** Support
**Created:** [May 10, 2021, 11:46am UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753 "2021-05-10T11:46:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hoongdt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hoongdt/32/3378_2.png) [@hoongdt](https://discourse.vtk.org/u/hoongdt)
#### Post date: [May 10, 2021, 11:46am UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/1 "2021-05-10T11:46:02Z")

</div>

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](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.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/450a8e55fa80f3cf5912dddbea24bd14a5965693.jpeg)  
Paraview

Yours,

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 10, 2021, 1:39pm UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/2 "2021-05-10T13:39:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hoongdt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hoongdt/32/3378_2.png) [@hoongdt](https://discourse.vtk.org/u/hoongdt)
#### Post date: [May 11, 2021, 6:09am UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/3 "2021-05-11T06:09:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 11, 2021, 7:45pm UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/4 "2021-05-11T19:45:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hoongdt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hoongdt/32/3378_2.png) [@hoongdt](https://discourse.vtk.org/u/hoongdt)
#### Post date: [May 12, 2021, 6:17am UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/5 "2021-05-12T06:17:40Z")

</div>

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,

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 12, 2021, 12:55pm UTC](https://discourse.vtk.org/t/vtk-interaction-zooming-panning-is-very-laggy-with-alpha-color/5753/6 "2021-05-12T12:55:31Z")

</div>

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.
