Visualizer / MatLab Api

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Visualizer / MatLab Api

Post by Axel Koussou » Tue Feb 01, 2022 9:44 am

Dear OpenSim experts,

I have developed a MatLab API program to animate a model with pre-calculated gait angle values (.mot files) and I would like to use the visualizer to check that the model's movement is correct :

Code: Select all

model.setUseVisualizer(true);
state=model.initSystem();
model.updVisualizer().updSimbodyVisualizer().setBackgroundColor(Vec3(1));
model.updVisualizer().updSimbodyVisualizer().drawFrameNow(state);

% Data contains joint angle values at every frame. 
num_timepoints = size(Data,1);
num_coordinates = size(Data,2);

for t=1:num_timepoints
    
    %Updtate joint angle
    for i=0:num_coordinates-1
        model.updCoordinateSet().get(i).setValue(state,Data(t,i+1),false);
    end   
    
    model.assemble(state)
    model.equilibrateMuscles(state)
    model.updVisualizer().updSimbodyVisualizer().drawFrameNow(state);
    %Or :
    %model.realizePosition(state)  
    %model.getVisualizer().show(state)
    
    model.updVisualizer().updSimbodyVisualizer().setShowFrameNumber(true);
    
end
%These lines don't work. I am forced to close the window manually. 
% model.updVisualizer().updSimbodyVisualizer().setShutdownWhenDestructed(true);
% model.updVisualizer().updSimbodyVisualizer().shutdown(); 
First, I would like to know how I could proceed to close the visualizer window at the end of the gait trial. As stated at the end of the code example, the last two lines (found here : https://simtk.org/api_docs/simbody/3.5/ ... lizer.html) do not work (nothing changes) and I am forced to close the visualizer window manually.

Second, I would like to know if there is a way to adapt the visualization so that the camera follows the model during the whole trial. Currently, the camera is fixed and if I do not adapt manually, my model "goes out" of my visualization window.
I have seen that the visualizer got some properties related to the camera, but I did not see one adapted to what I want.

Thanks in advance,

Regards

Tags:

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Visualizer / MatLab Api

Post by Axel Koussou » Tue Feb 08, 2022 5:43 am

Dear OpenSim experts,

Since I have not get any answer, I take the liberty to refresh this post.

Thanks in advance,

Regards

User avatar
Alessia Giordan
Posts: 10
Joined: Tue Jul 20, 2021 3:53 pm

Re: Visualizer / MatLab Api

Post by Alessia Giordan » Tue Feb 08, 2022 10:24 am

Dear Axel,
I'm not an expert of OpenSim, however to visualize an existing .mot file I used this code:
Last edited by Alessia Giordan on Wed Feb 09, 2022 1:48 am, edited 3 times in total.

User avatar
Alessia Giordan
Posts: 10
Joined: Tue Jul 20, 2021 3:53 pm

Re: Visualizer / MatLab Api

Post by Alessia Giordan » Tue Feb 08, 2022 10:36 am

Dear Axel,
I'm not an expert of OpenSim, however I used this Python code to visualize an existing motion file (.mot):

myModel = osim.Model('./OpenSense/' + modelFileName) # Load the model into the GUI

myModel.initSystem()
table = osim.TimeSeriesTable('./'+folder_name+'/IKResults/ik_'+root_name+'_orientations.mot')

osim.ModelVisualizer.addDirToGeometrySearchPaths(geometrypath)
osim.VisualizerUtilities.showMotion(myModel, table)


With the function osim.VisualizerUtilities.showMotion(), you open a Visualizer window and you can change the speed of the motion and close the Visualizer clicking the 'Escape' key. However, this solution is not perfect, because I'm having a problem with seeing my model right now (see attachments).
Anyway, I hope this can help you and if you find a better solution, please write me soon.

Kindly,

Alessia Giordan

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Visualizer / MatLab Api

Post by Axel Koussou » Thu Feb 17, 2022 12:52 am

Dear Alessia,

Thank you for your answer, and sorry for my late response.

I am not an OpenSim expert either !

osim.VisualizerUtilities.showMotion does not work for me. I do not know why. It seems that the VisualizerUtilities class is not known in MatLab. Do you know if it is specific to Python or am I missing something?

Thus, so far to control the movement of the camera I use the fonction model.getVisualizer().updSimbodyVisualizer().pointCameraAt(); but I still do not properly manage to follow the model througout the trial since I am not sure of how this function works. I can't find any explanation on the API Guide about this function. I found this function after using methodsview to find all the functions related to the Visualizer class : methodsview(model.getVisualizer().updSimbodyVisualizer())

Concerning the closure of the visualizer window, I still have not find a way to automatically do it. The two lines at the end of my code (see my last post) do not work.

Thnaks in advance,

Regards

User avatar
Alessia Giordan
Posts: 10
Joined: Tue Jul 20, 2021 3:53 pm

Re: Visualizer / MatLab Api

Post by Alessia Giordan » Mon Feb 21, 2022 5:58 am

Hi Axel,

This is the Matlab code that replicates what I did in Python:

import org.opensim.modeling.*
modelFileName = 'ScapulothorachicJoint_Shoulder_calibrated.osim'; % The path to an input model
vis = VisualizerUtilities();
myModel = Model(strcat('./', modelFileName));

mot = 'ik_MT_012005D6_009-001_orientations.mot';

table = TimeSeriesTable(strcat('./IKResults/',mot));
vis.showModel(myModel);
vis.showMotion(myModel, table);


However, as you can see, I can visualize the static model with the function showModel(), but the visualizer window of showMotion() is still blank and I don't understand why..
If you find something, please let me know.

Kindly

Alessia

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Visualizer / MatLab Api

Post by Axel Koussou » Fri Feb 25, 2022 9:25 am

Hi Alessia,

I am sorry but the line :

vis = VisualizerUtilities();

does not work on my MatLab. So I can not help you.

I hope you will find an answer.

Regards.

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Visualizer / MatLab Api

Post by Axel Koussou » Fri Mar 11, 2022 5:20 am

Dear OpenSim experts,

Since I did not have a complete answer, I take the liberty to re-open this question.

Is there anyone who can explain me how I can manage to visualize a model that I animate with pre-calculated gait angle values (.mot files).

As explained in my first post, I have trouble closing the Visualizer window and to follow the model throughout the gait trial.

Thanks in advance,

Regards

POST REPLY