trisurf handles related.....

11 views (last 30 days)
KSSV
KSSV on 11 Sep 2015
Commented: Jeremy Chouchoulis on 19 Apr 2024 at 17:41
Hi all
I have an issue with trisurf..I have a huge data from FEA. I want to make animation at the end. As the elements are triangular, I am using trisurf for animation. I want to use handles of trisurf for animation. My code is as follows:
h.fig = figure('Color','w') ;
h.ax = handle(axes) ;
h.surf = handle( trisurf(nodes,x,y,z)) ; %// create surface object
% set the data
set(h.surf,'Faces',nodes, 'XData',x , 'YData',x , 'ZData',z, 'Edgecolor','none')
set( h.ax,'XLim',xLim,'YLim',yLim,'ZLim',zLim )
But MATLAB hangs with the above lines. How to get the surface object with trisurf?
Thanks in advance.
Srinivas

Accepted Answer

Walter Roberson
Walter Roberson on 11 Sep 2015
When you use the handle() form, you should usually not use set() or get() and should instead access properties with dot notation. For now leave out the handle() calls:
h.fig = figure('Color','w') ;
h.ax = axes('Parent', h.fig) ;
h.surf = trisurf(nodes,x,y,z, 'Parent', h.ax) ; %// create surface object
% set the data
set(h.surf,'Faces',nodes, 'XData',x , 'YData',x , 'ZData',z, 'Edgecolor','none')
set( h.ax,'XLim',xLim,'YLim',yLim,'ZLim',zLim )
Also those set calls are not needed:
h.fig = figure('Color','w') ;
h.ax = axes('Parent', h.fig) ;
h.surf = trisurf(nodes,x,y,z, 'Parent', h.ax, 'EdgeColor', 'none') ; %// create surface object
  1 Comment
KSSV
KSSV on 14 Sep 2015
Dear Walter
I thank you once again for your prompt answer. (Earlier too you have answered my queries).
Regards
Srinivas

Sign in to comment.

More Answers (1)

Mike Garrity
Mike Garrity on 11 Sep 2015
Edited: Mike Garrity on 11 Sep 2015
The first question is how large your "huge" dataset is. It is possible that you've given it so much data that it's choking the graphics card.
But, the syntax you're using here is not correct. This gets a bit confusing, so bear with me.
The trisurf function creates a Patch object , rather than a Surface object. It has to do this because surface only supports "rectilinear grids". In other words, a grid which XData, YData, and ZData are 2-D matrices. That doesn't work with a "triangle mesh". You need a more general representation.
The native representation Patch uses is called "faces" and "vertices". The Vertices array is a 2-D matrix with 3 columns, where each row represents one of the vertices of your mesh. The Faces array is a 2-D matrix where each row represents one facet of your mesh. It does this using row indices into the Vertices array. In the case of a triangle mesh, the Faces array has 3 columns. The number in each of the four columns of a row tell you the three rows of the Vertices array which contain the coordinates of one of the corners of that triangle.
But Patch also has a different representation. It has properties named XData, YData, and ZData, just like the Surface object does. But these aren't "real", they're derived properties. When you set and get them, it is actually converting back and forth between that representation and the Faces/Vertices representation. I call this the "two faces of patch". You can get into quite a bit of trouble if you mix the Faces/Vertices model of patch with the XData/YData/ZData model of patch. You really want to stick to one or the other. It is quite possible in this case that you've told patch that instead of lots of triangles (small polygons), you want a small number of really large polygons. In this case, patch whill spend a lot of time trying to turn those big, complex (and incorrect) polygons into triangles.
Unfortunately, the help for trisurf talks about arguments named x, y, and z. This is confusing. This part of the help is not really talking about the XData, YData, and ZData properties of the patch object it will create. It's really talking about the columns of the Vertices property.
So I think that your code fragment should look like this (excuse the R2014b+ syntax here).
% Creation
h.fig = figure('Color','w') ;
h.ax = axes;
h.patch = trisurf(nodes,x,y,z);
% Animation
h.patch.Faces = nodes;
h.patch.Vertices = [x, y, z]; % assuming these are column vectors
h.EdgeColor = 'none';
xlim(h.ax,[min(x) max(x)])
ylim(h.ax,[min(y) max(y)])
zlim(h.ax,[min(z) max(z)])
So you could try this, but as I said, this may not be the problem. Could you tell us how big your Faces and Vertices matrices are, what version of MATLAB you're running, and what "opengl info" says about your machine?
When I run the code above on my machine, with the following fake data, the creation takes about 3/4 of a second, and the animation takes about 1/2 second.
nvert = 250000;
ntri = 150000;
x = randn(nvert,1);
y = randn(nvert,1);
z = randn(nvert,1);
nodes = randi(nvert,[ntri 3]);
But if I had used those x,y,z arrays as the XData, YData, and ZData properties, it would have taken a very long time.
  2 Comments
KSSV
KSSV on 14 Sep 2015
Dear Mike Garrity
Thanks a lot for making me things clear about trisurf. I have followed your code as well. It is working fine. I have nodes more then a lakh. With the code of yours it is not taking much time.
Jeremy Chouchoulis
Jeremy Chouchoulis on 19 Apr 2024 at 17:41
This information is still very much relevant for R2023b, thank you for the clear explanation Mike Garrity!
I stumbled upon the same issues w.r.t. the Patch object that trisurf gives as a handle for the visualization of Discontinuous Galerkin (DG) solution data. My hopes were to increase the plotting speed by working with handles to the trisurf patch object, instead of repeatedly calling a new trisurf command.
To my experience, working with a trisurf patch handle does only make difference if the amount of coordinates is little. When plotting a large amount of coordinates, I notice barely any difference in comparison to repeatedly using trisurf directly.
I would nevertheless agree that working in general with the patch handle is more efficient.
In this stackoverflow thread from 2021 similar conclusions have been made w.r.t. the performance.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!