# Slow when using vtkRenderer, vtkRenderWindow

**URL:** https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906
**Category:** Support
**Tags:** jobs, training, proposal
**Created:** [August 4, 2020, 1:05pm UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906 "2020-08-04T13:05:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [August 4, 2020, 1:05pm UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/1 "2020-08-04T13:05:50Z")

</div>

Hello

I received 3D Sensor data and developed 3D Viewer using VTK.  
The time to call both functions continues to increase.

* * *

**Global variable**  
**vtkNew m\_vtkRenderWindow;**  
**vtkNew m\_vtkRenderer;**

**UpdatePointerToWindow()**  
**{**  
**…**  
**m\_vtkRenderer-\>ResetCamera();**  
**…**

**…**  
**m\_vtkRenderWindow-\>Render();**  
**…**  
**}**

* * *

I want to know how to solve the problem I am having.  
Some of the codes in use are attached.

[Code.txt](https://discourse.vtk.org/uploads/short-url/rwm3M1xakc2C20rslNPIE4QJ3mA.txt) (2.2 KB)

Thanks!

---

<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: [August 4, 2020, 1:48pm UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/2 "2020-08-04T13:48:10Z")

</div>

You may receive hundreds of sensor data updates per second, but usually there is no need to update the screen more frequently than about 60Hz (and if your scene is complex then you may want limit refresh rate to a lower value to have some spare time on the main thread to do other things than rendering). Of course you also need to minimize changes in the update loop: you should pre-create all objects in advance and just update their properties (to avoid doing unnecessary computations and memory fragmentation).

In 3D Slicer we solved visualization of position-tracked instruments and live interventional imaging data by using “request render” mechanism implemented in [CTK toolkit](https://github.com/commontk/CTK/blob/master/Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.h) and do all sensor data collection and preprocessing in background threads. If you implement a medical application that I would strongly recommend to use these components that proven to work robustly in the operating room for various procedures (see [www.slicerigt.org](http://www.slicerigt.org)). If you work in a different domain then you can take source code or ideas from 3D Slicer and its extensions.

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [August 4, 2020, 3:01pm UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/4 "2020-08-04T15:01:52Z")

</div>

Thank you for your answer.  
I think I gave you insufficient information.

3D View is not fast. (=0.2Hz)

he problem is that the ResetCamera(), Render() functions call time is getting slower and slower and slower.

1  
ResetCamera(): 300ms  
Render(): 300ms

2  
ResetCamera(): 600ms  
Render(): 500ms

3  
ResetCamera(): 1100ms  
Render(): 900ms

…

---

<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: [August 4, 2020, 3:53pm UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/5 "2020-08-04T15:53:18Z")

</div>

Things getting slower in each iteration means that you don’t pre-create all objects in advance but you create new instances in each iteration (and maybe not even clean them up properly).

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [August 7, 2020, 3:16am UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/7 "2020-08-07T03:16:01Z")

</div>

Thank you very much.!!

After changing an object that was continuously created as a local variable to a global variable, it was confirmed that ResetCamera does not slow down.

However, it is still slow in Render.  
vtkNew m\_vtkRenderWindow;  
m\_vtkRenderWindow-\>Render();

Do I need to delete or remove?

---

<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: [August 7, 2020, 3:23am UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/8 "2020-08-07T03:23:35Z")

</div>

Do not recreate the render window for each rendering - that’s a very expensive operation.

What do you render and what frame rate you can achieve now?

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [August 7, 2020, 6:20am UTC](https://discourse.vtk.org/t/slow-when-using-vtkrenderer-vtkrenderwindow/3906/9 "2020-08-07T06:20:26Z")

</div>

Thank you.

As you said, changing the local variable to a member variable (global variable X) solved the problem.

As your advice, I will not recreate the Render window.

BR
