Visualizer / MatLab Api
Posted: 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 :
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
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();
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