Overrall performances on a very simple scene, disappoiting/weird results ...

Hi dear friends,

I’m very new to VTK, and I’m currently testing/stressing it to evaluate its potential for replacing our current OpenGL frontend.

The setup is quite simple :

  • Windows 10
  • Latest VTK compiled with VS2022, Release, x64, static Libs
  • VTK wrapped inside a C++CLI DLL
  • C++ CLI DLL used from a x64 C# WinForms application

The scene is coming from a CAD software and represent an House (500 actors, 20k vertices).
Each actor is bound to a PolyData representing a tessellated 3D solid (so only triangles).
The code for actors is :

vtkNew<vtkPolyData> vtkpoly;
vtkNew<vtkPoints> vtkpts;
for (int i=0; i<points->Length/3; i++) vtkpts->InsertNextPoint(points[3*i+0], points[3*i+1], points[3*i+2]);
vtkpoly->SetPoints(vtkpts);

vtkNew<vtkCellArray> vtkfaces;
for (int i=0; i<faces->Length; i++)
{
	for (int j=0; j<faces[i]->Length/3; j++)
	{
		vtkNew<vtkTriangle> triangle;
		for (int k=0; k<3; k++) triangle->GetPointIds()->SetId(k, faces[i][3*j+k]);
		vtkfaces->InsertNextCell(triangle);
	}
}
vtkpoly->SetPolys(vtkfaces);

vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputDataObject(vtkpoly);
vtkNew<vtkActor> vtkactor;
vtkactor->SetMapper(mapper);

All other parameters for vtkRenderWindow / vtkRenderer are left to defaults.
In the same application I have another OpenGL frontend so that I can make side by side FPS comparisons.

On the exact same scene, my current OpenGL engine gives >60fps (screen limited), VTK gives <20fps.
The difference is especially visible when rotating, were the 1rst engine is way smoother than VTK.

Moreover, when I add any widget or a vtkCornerAnnotation, VTK framerate drop 50% (FPS is near 10-15fps in this case).

I’ve exported the scene in VTP and viewed it inside ParaView, and I did not see any of the above issues.

My questions :

  • Am I doing something wrong ?
  • Are there any “secret settings” that could increase the VTK FPS ?

Thanks guys :slight_smile:

ParaView is built on VTK, so if there are no issues using PV then something is amiss… You are not calling the code you shared each frame are you? The way you are creating the cell array is also extremely inefficient: instantiating a cell vtkTriangle in an inner loop is a bad idea. There are several ways to create cell arrays, even the simplest to use vtkCellArray::InsertNextCell(npts,pts) is going to be much faster than what you shared. Also, there is going to be a performance hit as you use lots of actors - when you use PV are you actually loading 500 actors?

Thanks for the advice for entities creation !
Your point is pretty obvious indeed, I’ll make the adjustments.

No I’m not calling the code each frame, but once and for all before showing VTK window.

In PV I’m loading a .VTP that contains only one PolyData with all triangles in it, so the direct performance comparison is not relevant.
By the way I have to be able to have one color per entity, and the possibility to select each one independently, so I guess I’m stick with my 500 actors …

Well there are many tricks that can be played if you want one or just a few actors. Cell scalars can be used to color different polygons corresponding to different entities. Picking can be performed with the appropriate entity lookup table etc. The trick with VTK is there are many ways to do the same thing, and the performance differences can be immense (like orders of magnitude).

According to you, are the following mandatory elements feasible with only one Actor and “tricks” ?

  • Individual color (with alpha)
  • Individual picking
  • Individual visibility

Visibility is harder. And anyway 500 actors may not be a problem, some smart folks have worked on this, so it’s worth writing a simple benchmark to evaluate this before jumping to conclusions.

Yes, and if I add another 500 actors (to display “contours” edges), the FPS stays about the same.

Other weird things :

  • If I put a vtkCornerAnnotation the FPS drops by 50%
  • If I use 500 vtkPropAssembly with 2 children (one for triangles, one for edges), FPS drops by 30% compared to adding 1000 actors directly to the Renderer.

I did not read everything int the thread but VTK is not made to display lots of actors, but big geometries in a few actors.

1 Like

I’ve tested with one Actor holding all the geometry => fps is same as my other OpenGL engine.
I guess I will have to cope with it, and rely on those “famous tricks” !