Increasing HG2 framerate when updating large meshes: mission impossible?

1 view (last 30 days)
Dear all,
since the introduction of HG2 I have been fighting with its associated performance issues. This is mostly why I've continued using with my dear old R2012a with HG1. Now I'm trying to force myself to move to HG2 versions...but without success!
One of the typical things I have to do is visualizing animations of quite large meshes which change their properties. I do this with typical for-loops containing set(...,'vertices',...) to update the coordinates of the vertices.
While HG1 was ok in terms of speed (apart from the never solved issue of bug 415190), performance of HG2 are so poor that, for me, it is almost unusable for the above mentioned tasks. And new matlab versions do not seem to improve the performance to a level even comparable with HG1.
This is an example code, with a relatively small mesh, to see the issue (I use much larger meshes, so the problem is much worse):
---------------
[x,y,z,v] = flow;
[F1,V1]=isosurface(x,y,z,v,-3);
F1=[F1;F1+max(F1(:))]; %just to increase the mesh dimension
V1=[V1;V1+10]; %just to increase the mesh dimension
[F2,V2]=isosurface(x,y,z,v,-1);
F2=[F2;F2+max(F2(:))]; %just to increase the mesh dimension
V2=[V2;V2+10]; %just to increase the mesh dimension
figure
p1 = patch('faces',F1,'vertices',V1,'Facecolor','y','Edgecolor','k');
p2 = patch('faces',F2,'vertices',V2,'Facecolor','m','Edgecolor','b');
axis equal;
view(3)
tic;
for i=1:100
set(p1,'vertices',V1+pi*i);
set(p2,'vertices',V2+pi*i);
drawnow;
end
fprintf('fps=%0.3f',i/toc);
------------------------
Results:
R2012a (HG1): fps=92.766
R2017a (HG2): fps=19.848
Ratio R2012a/R2017a : 4.7
The difference is striking! Of course HG2 graphics has a nicer rendering, but an fps reduced by a factor of almost 5 is a little bit a too high price for smoother and nicer rendering...
So now my question: is there any way to have HG2 to get close to HG1 performance for this task? If not, this is somewhat a serious problem, because, on the one hand, keeping coding with old matlab releases is not recommended. At the same time, moving to new releases is prevented from the performance reduction of the graphical engine.
Any answer/suggestion/magical trick?
Thanks,
Gabriele

Answers (2)

Yair Altman
Yair Altman on 20 Mar 2017
Edited: Yair Altman on 20 Mar 2017
There is indeed a performance penalty for HG2 compared to HG1. One thing that could alleviate the pain is to use the new 'limitrate' input of the drawnow function
  1 Comment
Gabriele
Gabriele on 20 Mar 2017
Dear Yair, thanks.
I actually already tried using the limitrate option of drawnow in my actual application.
It helps because you do not get stuck waiting for the refresh.
However, you do not get as fluid animations as in the old HG1 due to the inherent performance difference between HG2 and HG1.
So, to some extent, limitrate is working around doing basically automatically what one (being a bit desperate ;-) ) would do manually: reducing the number of actually rendered frames.
Surely, having a workaround is better than not having one. At the same time, however, it would be useful to have a real solution, because the dropping of performance, for this specific task, between HG1 and HG2 is really huge.
Gabriele

Sign in to comment.


Sean de Wolski
Sean de Wolski on 20 Mar 2017
What about using an hgtransform?
t = hgtransform;
set([p1 p2],'parent',t);
for i=1:100
tform = makehgtform('translate',zeros(1,3)+(pi+i));
set(t,'Matrix',tform);
% set(p1,'vertices',V1+pi*i);
% set(p2,'vertices',V2+pi*i);
drawnow;
Note that with drawnow limitrate, I get 1000fps, not sure if this is what you want or not.
  1 Comment
Gabriele
Gabriele on 20 Mar 2017
Dear Sean, thanks for the idea.
I also was thinking to use hgtransform.
However, in a series of cases the mesh is modifying shape (in my example I was just translating data for simplicity). This, to my knowledge, cannot be handled directly through makehgtform.
Regarding drawnow with limitrate option, see my reply to Yair.
thanks, Gabriele

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!