Exporting Simbody visualizer "movie" directly from MATLAB API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
D T
Posts: 24
Joined: Thu Nov 21, 2019 3:40 pm

Exporting Simbody visualizer "movie" directly from MATLAB API

Post by D T » Fri Nov 27, 2020 11:43 pm

Hi all,

I have a MATLAB script that produces a looping visualizer motion (it is a MOCO solution storage file). This visualization will loop until closed as of right now.

I would like to export this visual loop (about one second long) as either a video file or collection of separate images (much like the View>Save Movie option provided in the visualizer's GUI) directly from my MATLAB script without manually doing this in the GUI.

I have reviewed Common Scripting Commands page and tug of war example as well as the doxygen pages for the visualize class reference in both OpenSim and MOCO's pages. I could not find any mention of an ability to directly call this GUI option from MATLAB rather than the visualizer's GUI.

Is this option currently available for the Simbody visualizer, and if so, how might I do this?

Thank you for any/all information.

Tags:

User avatar
Tylan Templin
Posts: 40
Joined: Mon Jan 15, 2018 10:55 am

Re: Exporting Simbody visualizer "movie" directly from MATLAB API

Post by Tylan Templin » Fri Sep 10, 2021 1:09 pm

Were you able to figure out a solution for this? I am also interested in making a video using the API visualizer without having to select View> Save Movie

Best,

Ty

User avatar
Neha Das
Posts: 1
Joined: Wed Apr 27, 2022 5:12 am

Re: Exporting Simbody visualizer "movie" directly from MATLAB API

Post by Neha Das » Fri Dec 23, 2022 5:42 am

A bit late here, but a very hacky workaround I found is to modify the simbody visualizer code (in <SIMBODY_SRC>/Simbody/Visualizer/simbody-visualizer/simbody-visualizer.cpp) such that it ALWAYS saves the video in a path specified by an environmental variable, whenever the visualizer is opened by your (C++/matlab/python) application.

Then recompile simbody following instructions in simbody github repo - https://github.com/simbody/simbody and finally copy the binary <SIMBODY_INSTALL_DIR>/libexec/simbody/simbody-visualizer to <OPENSIM_INSTALL_DIR>/libexec/simbody/simbody-visualizer. You may want to save the original simbody-visualizer first.

Then in your application, you can copy/rename the generated video directory.

Here is a minimally modified version of simbody-visualizer.cpp that can allow you to do this:
simbody-visualizer.cpp
(115.31 KiB) Downloaded 74 times
I set two environment variables that allow for saving the videos:
SAVE_OSIM_VID : set as 1 to save a video everytime the visualizer is ran.
PATH_OSIM_VID : set the absolute path of the directory where you want the video to be saved.

There may occur issues when using multi-processing, multi-threading etc. that have to be handled in your application.
Original Source: https://github.com/spMohanty/simbody/bl ... alizer.cpp

User avatar
Weichao Gong
Posts: 2
Joined: Sun Feb 26, 2023 11:21 pm

Re: Exporting Simbody visualizer "movie" directly from MATLAB API

Post by Weichao Gong » Thu Mar 09, 2023 3:17 am

Hi Neha

I followed the solution you mentioned in the previous reply, which is re-building the Simbody binararies and replacing the simbody-visualizer.exe in the Opensim dir with the new one.

Then I ran the code, ended up with a exception, saying:

RuntimeError: std::exception in 'SimTK::State const & OpenSim::Manager::integrate(double)': SimTK Exception thrown at VisualizerProtocol.cpp:583:
Error detected by Simbody method VisualizerProtocol: An attempt to write() 1 bytes to pipe 5 failed with errno=22 (Invalid argument).
(Required condition 'status!=-1' was not met.)

By the way, I did not find the dir <SIMBODY_INSTALL_DIR>/libexec/simbody/simbody-visualizer and <OPENSIM_INSTALL_DIR>/libexec/simbody/simbody-visualizer, the file that I generated and replaced is <SIMBODY_INSTALL_DIR>\bin\simbody-visualizer.exe and <OPENSIM_INSTALL_DIR>\bin\simbody-visualizer.exe. Did I do it wrong?

Could you please give a look at this and guide me how to fix it?

Thank you so much!

POST REPLY