How to visualise 10000 cell volume

I have tried to view this system in 3D using patch. It is very slow. I've seen other software do this much much faster, even with transparency. What am i missing?

2 Comments

Any data? I visualize easily millions of patches but it is difficult to help without a simple example of the data
Please explain any details. How are the "10000 cell volume" represented? If you post code and data, it is likely, that the speed can be improved.

Sign in to comment.

 Accepted Answer

Load nodes and faces in a unique structure and plot all patches in a single command
tic
nodes = []; faces = [];
for i = 1:length(PatchWork)
faces = [faces; PatchWork{i}.FaceVertices+size(nodes,1)];
nodes = [nodes; PatchWork{i}.VertexXYZs.'];
end
figure
patch('Faces',double(faces),'Vertices',nodes,'FaceColor','red');
view([1 1 1]);
toc
>> Elapsed time is 1.018881 seconds.

11 Comments

Thanks, your answer makes things work very well. I really appreciate you responding.
I was able to assign colors to specific faces easily.
Can I also set their visible attribute individually?
Kind regards...
I don't think so. You can select the faces you want to show/no show and plot them accordingly. Or you can use the attribute 'FaceAlpha' for transparency
Just a follow-up please:
OK, So if I use the 'FaceAlpha' set to 'Flat' and add 'FaceVertexAlphaData', I can consistently get transparency for faces that I want invisible (where .FaceVertexAlphaData is zero).
Trouble is that the visible faces appear partly (or in some cases fully) transparent.
It also seems that the range for the Alpha is from the lowest in alphadata to the highest, but even this seems not consistent across the whole range.
Is there a way to specify a consistent, known, range for alpha?
FaceAlpha is a scalar between 0 and 1 that sets the transparency (0 is completely transparent, 1 is opaque)
Thanks very much for your response.
Right, but best I can tell it must be 'FaceVertexAlphaData '
I get:
"Error using matlab.graphics.primitive.Patch/get
There is no FaceAlpha property on the Patch class. "
It does not seem to work for me.
See the image attached. Good where all transparent, but elsewhere (where FaceVertexAlphaData is 1.0) it appears to have some transparency which I don't want.
Helps if I attach it!!
Sorry, I need to set some faces transparent and some not.
The 'FaceAlpha' (and 'EdgeAlpha') are set to 'flat' to do this, and the 'FaceVertexAlphaData' must be used. I think the idea is that that array is normalised to a range of 0 to 1 and the values assigned on a face-by-face basis to achieve transparency.
The range on my 'FaceVertexAlphaData' is zero to one, and nothing in between.
Yet, I get transparency where I don't want it.
Thanks for your patience.
From the documentation of patch
'flat' — Use a different transparency for each face based on the values in the FaceVertexAlphaData property. First you must specify the FaceVertexAlphaData property as a vector containing one transparency value per face or vertex. The transparency value at the first vertex determines the transparency for the entire face.
So FaceVertexAlphaData is a node-based property. This can complicate what you want to do, because if the face inherited the transparency from its first node.
I don't know if there are alternatives, I would plot independently all faces that share the same transparency. For example, let's assume that the first half of the faces have FaceAlpha = 0.2 and the last half FaceAlpha = 1. there are 60000 faces in your example, so:
nodes = []; faces = [];
for i = 1:length(PatchWork)
faces = [faces; PatchWork{i}.FaceVertices+size(nodes,1)];
nodes = [nodes; PatchWork{i}.VertexXYZs.'];
end
figure, hold on
patch('Faces',double(faces(1:30000,:)),'Vertices',nodes,'FaceColor','b','FaceAlpha',0.2);
patch('Faces',double(faces(30001:end,:)),'Vertices',nodes,'FaceColor','r','FaceAlpha',1);
view([1 1 1]);
Hope it helps
Thanks again! I owe you.
For sure, that would do the job.
I need to think about "The transparency value at the first vertex of the face" which could be causing me problems. I don't think so, but I'll look into it.
It would be nice however if the 'FaceVertexAlphaData' feature would work as I think it should!
That would eliminate the need for me to parse the faces into two groups.
The point is: if there are duplicated nodes, so that each face has its own set of nodes, so you won't have problems in using 'FaceVertexAlphaData'.
There is still the fact that you must address the specific property to the right node. and this may not be simple if your data are generated by an unknown software/function (like an independent mesh generator). I actually haven't check your data in details, but you may know what you really have as input.
I usually work with non-duplicated nodes, like in finite element meshes. In this case, for example, one of your corner nodes is hsared by three faces. Suppose that this corner node is the first node for all 3 faces: so you cannod specify different transparencies for these faces.
Thanks again,
Those are several good points.
  • The first is that in my case, there are 10000 cells each with eight vertices and six faces. Vertices are [80000x3 double] and so, are independent for each cell. Faces are [60000x4] and point to the vertices. Each vertex is used three times (3-faces) and only in one cell.
  • Color and transparency are both assigned by face. The colors appear to be assigned correctly.
  • Your last point is good, but because I use duplicated nodes, not really applicable.
I think I should ask Mathworks about the 'FaceVertexAlphaData' feature, but your approach (above) will certainly work, although not quite as elegant or versatile as I would like.

Sign in to comment.

More Answers (1)

Pierre Lebel
Pierre Lebel on 25 Sep 2019
variable "PatchWork" attached,
code as follows:
for ib = 1:10000
zz(ib) = patch( app.UIAxes2 ...
, 'Faces',PatchWork{ib}.FaceVertices ...
, 'Vertices',PatchWork{ib}.VertexXYZs' ...
, 'FaceVertexCData', rand() ...
, 'FaceColor','flat');
end

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!