How to show different 2D text in different position in high performance?

I want to show many 2D text (>200). As far as I know, if I create vtkTextActor for each of them, I think it may be slow (because meanwhile I need to show large amount of other element). So what method should I use?

Hi, I have a solution (may not so good). The solution is ugly, but have big improvement then per string per actor. But, I have tested, the following solution is still a little bit slow. Seems, if too many input to the vtkGlyph3DMapper, it will slow down not only the mapper code but also the Render() call part. It’s very strange, because I think too many input to the vtkGlyph3DMapper won’t slow down the Render() call. Can anyone tell me why? And How can I optimize?

// for each char, make a source
std::vector<vtkNew<vtkVectorText>> text_source;
text_source.resize(255);
int i = 0;
for (auto& e: text_source)
{
      char c = char(0) + i;
      std::string s(1, c);
      e->SetText(s.c_str());
      i++;
}

// Then use instacing to show large amount of string. (each string can be split into several char)
vtkNew<vtkGlyph3DMapper> obj_mapper;
for (int i = 0; i < 255; i++)
{
     obj_mapper->SetSourceConnection(i, text_source[i]->GetOutputPort());
}
....

// use a vtkFollower to render 2D text
vtkNew<vtkFollower> actor;
actor->SetMapper(obj_mapper);

Seems, if too many input to the vtkGlyph3DMapper, it will slow down not only the mapper code but also the Render() call part. It’s very strange, because I think too many input to the vtkGlyph3DMapper won’t slow down the Render() call. Can anyone tell me why?

All your new approach really did was move the overhead up the rendering pipeline from looping over many actors to mapping that many source polydata.

And How can I optimize?

Generally, text rendering in terminals/text editors takes a different, highly effiicient approach. Have you tried use texture coordinates which map into a texture atlas?

The new batched rendering methods that we are exploring in the experimental webgpu backend might improve performance of your first approach.

1 Like

Thanks for your reply. I think I got a new technique. Could you tell me some keyword or which class can I use in vtk to do texture altas and texture coordinate?