<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Hi Marc,</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Tue, Jul 28, 2015 at 10:19 AM, Marc Ruiz Altisent <span dir="ltr"><<a href="mailto:marc.ruiz+vtk@gmail.com" target="_blank">marc.ruiz+vtk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi, I'm the developer of a medical viewer that uses vtkCornerAnnotation to display image-related information in the corners of the window. I have found that updating the text for each frame is slow when the window is very big, like for example in a 5 MPixel medical display.<br><br></div>Previously we used the vtkRenderingFreeTypeOpenGL module and annotation updates were instantaneous no matter the window size, but it doesn't support UTF-8, so we decided to not use it anymore.<br><br></div>Now, with the default implementation in the vtkRenderingFreeType module, when the window is very big the updates take a considerable amount of time, to the point of making the application very laggy when scrolling through images. I have tried to limit the text size to a small number, but even then with a big window text rendering is slow and with a small window it's fast, so it's not directly related to text size. I don't know exactly what is causing the slowness, but according to profiling tests, the bottleneck is the vtkFreeTypeTools::RenderCharacter() method.<br><br></div>Could the performance of text rendering be improved? Currently I could revert back to using the vtkRenderingFreeTypeOpenGL module, even with its limitations, but since it will disappear in VTK 6.3 this would just be a short-term workaround.<br></div>
</blockquote></div><br></div><div class="gmail_extra">I suspect that vtkFreeTypeTools::RenderCharacter is not a bottleneck, though it would be eating up a lot of time in a profiler as it's where most of the heavy-lifting is done during text rendering.</div><div class="gmail_extra"><br></div><div class="gmail_extra">After taking a quick skim through the code, the more likely problem is in vtkCornerAnnotation::RenderOpaqueGeometry, which has the following loops:</div><div class="gmail_extra"><br></div><div class="gmail_extra">
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">      while (... /*annotation size is too small*/ &&</font><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">  </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">fontSize</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)"><</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">100</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">        {</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">        fontSize++;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">        for (int i = 0; i < NumTextPositions; i++)</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">          {</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">          this->TextMapper[i]-><span style="font-style:italic">GetTextProperty</span>()-><span style="font-style:italic">SetFontSize</span>(fontSize);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">          this->TextMapper[i]-><span style="font-style:italic">GetSize</span>(viewport, tempi + i * 2);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">          }</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">        /* Recompute dimensions of annotation */</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">        }</span><br></pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">      /* Followed by the same thing, but decrease font size to fit */</pre></div><div class="gmail_extra"><br></div><div class="gmail_extra">So it basically renders the text repeatedly, attempting to fit it to a box. Combining a high density display with the new DPI support in VTK and repeatedly rendering to fit a box like this will likely eat up a lot of time and thrash memory pretty hard.</div><div class="gmail_extra"><br></div><div class="gmail_extra">It looks like it's currently not possible to 'seed' the fontsize via the vtkCornerAnnotation API -- it just grabs the default font size from an unmodified vtkTextProperty object (line 460) as a starting point.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Can you file a bug for this? At the very least the initial fontsize should be able to be set, and at best this class should be refactored to use newer text renderering APIs like vtkTextRenderer::GetBoundingBox, which won't actually generate a texture but just compute the dimensions of the resulting image.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,</div><div class="gmail_extra">Dave</div></div>