Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Clarify text and example for safeDownCast

...

If you are calling a method or function (e.g., getting or setting properties) that you are pretty sure should work, but you are getting an error that it the method doesn't exist, this may mean that you need to do something called downcasting. In the C++ programming language, programmers can use a concept called "inheritance" to build up complexity without re-using writing the same code multiple times. For example, in OpenSim Thelen2003Muscle and MillardMuscle both rely on code in the common parent Muscle class that they "inherit" from.

Matlab doesn't use this concept of inheritance so If you have a handle to a base class object (e.g.  Muscle)  you may need to downcast an the object like Muscle to one of its derived (or concrete) classes, like the Thelen2003Muscle, in order to gain access to properties and methods specific to the concrete class.

In this code example, we do XXXXX.

...


Then to get a version of the object that you can call the functions of interest on, you use safeDownCast()

Code Block
>>> musclesmuscle = model.getMuscles().get(0);    #the object you get here is of base class Muscle
>>> thelenMuscle = Thelen2003Muscle.safeDownCast(muscle) >>> ADD CODE TO DO SOMETHING # to use a method specific to Thelen2003Muscle you need to safeDownCast
>>> timeConstant = thelenMuscle.getActivationTimeConstant()


Case 2: The thing (class) I want to create has a name like Array_<double>.

...

Adding Geometry Paths to Matlab 

OpenSim verified verifies that Model's Geometry mesh files exists when you load a model and whenever you subsequently operate on it. If you have a Geometry file defined in your model, and the Geometry path is not set, you will get a warning for each piece of Geometry that can't be found, as shown in the image below.

...