In the previous chapter, we created a main program that built a new OpenSim model and performed a forward simulation on it. Another way to utilize the OpenSim API is to use it to create new kinds of objects that are not available in OpenSim. 

One particularly common example of such objects is an Analysis. In OpenSim, an Analysis object defines a computation that gets performed repeatedly either during integration of the equations of motion in a forward simulation or during analysis of a trajectory. While OpenSim comes with a set of Analysis objects, users often wish to perform new kinds of computations to support their work/research needs. Instead of trying to anticipate all possible uses, OpenSim allows users to write their own Analysis and attach it to a simulation or to other tools in OpenSim that process trajectories. 
When creating an Analysis, you'll have to decide which of two different ways to implement it: 

  • Dynamic Library Option (Option A): In this scenario, your class implementing the OpenSim::Analysis interface will be built into a separate dynamic link library (.dll on Windows). Then, you will be able to load this dynamic library into the GUI or into your main program or have it be used by different tools. This approach allows you to share or distribute your Analysis more easily and to reuse it in your work without recompiling it. The disadvantage is having to define the class that includes properties that permit serialization to/from XML files.
  • Main Program Option (Option B): In this scenario, you compile your Analysis along with your main program for immediate use. The advantage of this is that you can, optionally, do away with implementing the parts of the Analysis API specific to serialization, so it is faster to write and test. The disadvantage is that you cannot use it in the GUI or embed it in XML files, which are the setup files for most of the OpenSim tools. Also, you will have to manually point your build system to the Analysis code you are using, rather than link to or load a library that you build once.

Your use case will dictate which approach to take for the long term. In some cases, you may start out using option B, do some testing, and then migrate to option A for the long term.

The OpenSim distribution includes templates for building an analysis plugin (Option A), as this is the more general case.  The template files (.cpp and .h), along with the needed CMake files, are located in the OpenSim 3.3 installation directory under OpenSim 3.3\sdk\APIExamples\Plugins\AnalysisPluginExample.  On a Windows system, the full path would typically be C:\OpenSim 3.3\sdk\APIExamples\Plugins\AnalysisPluginExample.