Initial Render() for multiple vtkRenderWindow is slow

I want to render about 40 vtkRenderWindow objects each with its own image. The issue is my initial render is slow, it takes about 100-200 ms per render window. My pipeline can be seen in the code below.
I am using vtk8.2 release version and my discrete Nvdia GPU is being used. Any subsequent calls to Render() are lightning fast.

Is there a way to reduce the time the initial Render() call takes?

Thank you.

	// Reading of data not included in timing
	vtkDICOMImageReader* imageReader = vtkDICOMImageReader::New(); // 512 kbs
	vtkImageData* imageData = vtkImageData::New();
	imageReader->SetFileName( filepath );
	imageData->DeepCopy( imageReader->GetOutput() );

	//timing starts here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	//Creation of objects
	vtkRenderWindow* renderWin = vtkRenderWindow::New();
	vtkImageActor* imageActor = vtkImageActor::New();
	vtkRenderer* renderer = vtkRenderer::New();

	// Add actors and data to the render window
	imageActor->SetInputData( imageData );
	renderWin->AddRenderer( renderer );
	vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
	interactor->SetRenderWindow( renderWin );
	renderer->AddActor( imageActor );

	// Render window
	//timing ends here >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Even with just running the following it takes about the same time.

    vtkRenderWindow* renderWin = vtkRenderWindow::New();

Each vtkRenderWindow requires its own OpenGL context, which requires a certain amount of resources and bookkeeping. Also, depending on your driver settings, the swap interval might be restricted to once per vblank, limiting you to e.g. 60 renders per second.

So instead of using 40 windows, it’s much much much more efficient to use 40 renderers inside a single window. This way, only one OpenGL context is needed, and only one Render() call is needed.

To place each renderer inside the window, use code like this:

// viewport uses normalized coords:
// 0.0 <= x <= 1.0 and 0.0 <= y <= 1.0

All of the renderers will share the window’s interactor.

1 Like

Thank you for the reply, unfortunately the way our program is structured its going to be a major overhaul and probably not feasible.