Page 1 of 1

Visualizer / MatLab Api

Posted: Tue Feb 01, 2022 9:44 am
by akoussou
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

Re: Visualizer / MatLab Api

Posted: Tue Feb 08, 2022 5:43 am
by akoussou
Dear OpenSim experts,

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

Thanks in advance,

Regards

Re: Visualizer / MatLab Api

Posted: Tue Feb 08, 2022 10:24 am
by alessiag
Dear Axel,
I'm not an expert of OpenSim, however to visualize an existing .mot file I used this code:

Re: Visualizer / MatLab Api

Posted: Tue Feb 08, 2022 10:36 am
by alessiag
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

Re: Visualizer / MatLab Api

Posted: Thu Feb 17, 2022 12:52 am
by akoussou
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

Re: Visualizer / MatLab Api

Posted: Mon Feb 21, 2022 5:58 am
by alessiag
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

Re: Visualizer / MatLab Api

Posted: Fri Feb 25, 2022 9:25 am
by akoussou
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.

Re: Visualizer / MatLab Api

Posted: Fri Mar 11, 2022 5:20 am
by akoussou
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