Optimizing drawnow for large real-time simulation

Hi everyone. I am using this basic setup for a real-time simulation. The profiler states that most of the time (60%) is spent in drawnow. My geometries are made of ~6000 vertices ( v ) and ~14000 faces ( f ). I am currently reaching 15 frames per second (fps) and would like to target ~20 fps. I have tried replacing drawnow with pause() but it either gets too slow or it starts skipping frames. Do you have any suggestions?
  • I have tried switching between renderers without any success and modifying e.g. 'XData' instead of 'vertices' results in improper rendering and is not recommended (see comment below).
dt=0.02;
hsurf=trisurf(f,v(:,1),v(:,2),v(:,3));
axis([-15 15 -15 15 -15 15]);
for t:1:T
v=function_to_update_vertices(v,dt);
set(hsurf,'vertices',v); %faces stays the same
drawnow
end

回答 (1 件)

Sean de Wolski
Sean de Wolski 2013 年 4 月 12 日
編集済み: Sean de Wolski 2013 年 4 月 12 日

0 投票

Have you tried using all three renderers to see which is the fastest for this application? Or are you tied to OpenGL for transparency?
My only other suggestion might be to try setting the 'XData', 'YData', 'ZData' explicitly rather than the 'Vertices' which then have to calculate the above. I do not know if this will improve speed or not.

4 件のコメント

Linus
Linus 2013 年 4 月 12 日
編集済み: Linus 2013 年 4 月 12 日
I have tried zbuffer, opengl and painter. They all perform equal or worse. I tried setting the XYZData and it is very much faster (50fps) however it does not render properly. MATLAB explains why: http://www.mathworks.se/support/solutions/en/data/1-4NCW8K/index.html?product=SL&solution=1-4NCW8K
Sean de Wolski
Sean de Wolski 2013 年 4 月 12 日
Hi Linus,
I don't have time to look into this right now, but the last sentence of that solution says:
"Hence, to summarize if one creates a patch using the 'Vertices' and 'Faces' model then the 'XData', 'YData' or 'ZData' properties should not be used, and vice versa."
So what if you never do the faces vertices to begin with?
Linus
Linus 2013 年 4 月 12 日
No worries. I saw that too. It may be an option.
Linus
Linus 2013 年 4 月 15 日
編集済み: Linus 2013 年 4 月 15 日
After reserching a bit, I have two reservations into changing from "vertices" to "XYZData". 1) The resulting arrays will duplicate the vertices, resulting in significant larger memory usage. This is however not that big of a deal since I use relatively low number of vertices. 2) The function function_to_update_vertices updates vertices stored in the "vertices format" (i.e. Numverticesx3 matrix) and I will need to add additional operations to convert to XYZData format (i.e. Nx3 => 3xNumfaces) . I will need to either change function_to_update_vertices (which is not an option), or find a fast way to switch from "vertices" to "XYZData". Any suggestions or comments are much appreciated.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2013 年 4 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by