opensim-core icon indicating copy to clipboard operation
opensim-core copied to clipboard

Clean access to commonly used component lists in python and matlab

Open chrisdembia opened this issue 11 years ago • 8 comments

getComponentList may help a lot with this.

chrisdembia avatar Sep 29 '15 21:09 chrisdembia

+1.

jimmyDunne avatar Sep 30 '15 17:09 jimmyDunne

@jimmyDunne Are you still having issues with this? If so, can you provide more specfiics? Thanks!

jenhicks avatar Oct 06 '16 18:10 jenhicks

@jenhicks sure.

Having to safedowncast into a concrete class is confusing. It is also annoying to script for because you have to find the concrete class type and do an eval (matlab)

%% Matlab...
class_string = char( myclass.getConcreteClass )
eval(['concrete_class = ' class_string '.safeDowncast(myclass)'])

This happens a lot with different muscle types when you want to change their properties or get some access to an underlying component.

jimmyDunne avatar Oct 06 '16 18:10 jimmyDunne

This has been addressed for Python. For example, the following works; no downcasting necessary:

        model = osim.Model(os.path.join(test_dir, "arm26.osim"))
        muscle = model.getComponent('BICshort');
        # No downcasting necessary!
        muscle.get_max_isometric_force(); # Method on Muscle.

That was introduced by PR #1039.

Issue #1036 has some ideas for achieving a similar interface in MATLAB.

chrisdembia avatar Oct 06 '16 21:10 chrisdembia

I just want to add a +1. This will be great and much appreciated.

humphreysb avatar Oct 06 '16 21:10 humphreysb

@jimmyDunne and @humphreysb What are the specific concrete classes that you would like to have access to?

jenhicks avatar Oct 11 '16 21:10 jenhicks

Muscles seems to be the issue. Wants to be able to get a list of the different types of muscles. getThelen2003MuscleList() getMillard*MuscleList()

jenhicks avatar Oct 20 '16 18:10 jenhicks

@klshrinidhi As discussed, here's some code you could use for the test case:

// Create a model with Thelen2003 and Millard2012Equilibrium muscles.
auto model = Model();
auto* muscle1 = new Thelen2003Muscle("Darryl", 1., 0.5, 0.5, 0.);
auto* muscle2 = new Millard2012EquilibriumMuscle("Matt", 1., 0.5, 0.5, 0.);
model.addComponent(muscle1);
model.addComponent(muscle2);

// Test iterators.
const auto& listMuscle = model.getComponentList<Muscle>();
assert(std::distance(listMuscle.begin(), listMuscle.end()) == 2);

const auto& listThelen = model.getComponentList<Thelen2003Muscle>();
assert(std::distance(listThelen.begin(), listThelen.end()) == 1);

const auto& listMillard = model.getComponentList<Millard2012EquilibriumMuscle>();
assert(std::distance(listMillard.begin(), listMillard.end()) == 1);

tkuchida avatar Oct 20 '16 21:10 tkuchida