Clean access to commonly used component lists in python and matlab
getComponentList may help a lot with this.
+1.
@jimmyDunne Are you still having issues with this? If so, can you provide more specfiics? Thanks!
@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.
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.
I just want to add a +1. This will be great and much appreciated.
@jimmyDunne and @humphreysb What are the specific concrete classes that you would like to have access to?
Muscles seems to be the issue. Wants to be able to get a list of the different types of muscles. getThelen2003MuscleList() getMillard*MuscleList()
@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);