How do I know when volshow is done rendering?
이전 댓글 표시
I have a folder with hundreds of files containing 3D data. I want to loop through the files and output images to create a movie.
However, when I load new data to the volshow object, it takes a bit of time to render the scene. Hence, when I get the figure frame to write it to a file, I sometimes don't get the fully rendered scene. I don't want to add a pause after drawnow, because the rendering and data retireval is already quite slow. Is there a way to know exactly when volshow is done rendering so I can get the frame to write to an image?
obj = volshow(get_data(file(1)));
viewer = obj.Parent;
for i=1:length(file)
obj.Data = get_data(file(i));
drawnow
frame = getframe(viewer.Parent);
imwrite(frame.cdata, fullfile(save_dir, sprintf('%05i.jpg', i)))
end
댓글 수: 2
Walter Roberson
2025년 12월 7일
Unfortunately, I do not know of any way to do this.
Matt J
2025년 12월 7일
Hence, when I get the figure frame to write it to a file, I sometimes don't get the fully rendered scene
If so, I think you should report it is a bug. drawnow is supposed to block further execution until figure updating is complete. That's the whole point of drawnow.
답변 (1개)
Tim Jackman
2026년 1월 10일
편집: Tim Jackman
2026년 1월 10일
There are a couple of ways to help with this.
When volshow is processing and rendering a new volume, the viewer's Busy property is set to true, and then back to false once it has finished processing. You could add, after the drawnow (or in place of the drawnow really):
waitfor(viewer,"Busy",false)
and this will block MATLAB from moving on until the data has finished processing.
Beginning in the R2026a Prerelease, a better way would be to call getframe on the viewer directly, not on the viewer's figure ancestor. Swap to this:
frame = getframe(viewer);
This will do a little better for your video frame generation, ensuring the spinner is gone, the toolbar is hidden for the screenshot, etc. If you can't use the R2026a Prerelease, let me know and I can see what I can do about posting a function to do the equivalent of getframe(viewer);
카테고리
도움말 센터 및 File Exchange에서 Video Formats and Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!