Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The standard typical file format for Motion Capture and experimental motion capture data in the biomechanics community is C3D. C3D is a flexible format that can store marker, forces, forceplateforce plate, EMG, and event data. Despite being very flexible, data on in C3D files are stored as in binary format and require specialized readers to access. To read more information on the C3D file format, we encourage you to visit the C3D.org to learn more. 

From Starting with OpenSim 4.0, C3D reading and conversion into OpenSim formats are is available. Currently, use of C3D reading is limited to C++ and scripting and we will be working to make GUI support direct C3D reading native in the GUI in future releases. The easiest way of using to use OpenSim to read your C3D data is through the Matlab interface. Once you have setup OpenSim use in Matlab, you can read C3D files and write marker and force data to .trc and .mot file formats, easily. 

...

osimC3D

We have included a utility in Matlab side class that can be used to perform some common operations, such as rotating data, converting data into Matlab data types, and writing marker and force data to OpenSim file formatformats. The Matlab file can be found in your resources directory /Code/Matlab/Utilities/osimC3D.m. An example of using the osimC3D function is (in the expandable ) section below. Here In this example we

  • read a C3D file containing markers and forces, 
  • get some information about the data (rate, number of markers, and number of forces), 
  • rotate the data, and 
  • then write the markers to a .trc file, and the forces to a .mot file. 

Expand

Reading C3D files through Python and C++

...

Expand
Code Block
def test_C3DFileAdapter(self):
        try:
            adapter = osim.C3DFileAdapter()
        except AttributeError:
            # C3D support not available. OpenSim was not compiled with BTK.
            return
        tables = adapter.read(os.path.join(test_dir, 'walking2.c3d'), 0)
        markers = tables['markers']
        forces = tables['forces']
         
        tables = adapter.read(os.path.join(test_dir, 'walking5.c3d'), 1)
 
        # Marker data read from C3D.
        markers = tables['markers']
      
        # Flatten marker data.
        markersFlat = markers.flatten()
      
        # Make sure flattenned marker data is writable/readable to/from file.
        markersFilename = 'markers.sto'
        stoAdapter = osim.STOFileAdapter()
        stoAdapter.write(markersFlat, markersFilename)
        markersDouble = stoAdapter.read(markersFilename)
      
        # Forces data read from C3d.
        forces = tables['forces']
        fpCalMats = forces.getTableMetaDataVectorMatrix("CalibrationMatrices")
        fpCorners = forces.getTableMetaDataVectorMatrix("Corners")
        fpOrigins = forces.getTableMetaDataVectorMatrix("Origins")
      
        # Flatten forces data.
        forcesFlat = forces.flatten()
      
        # Make sure flattenned forces data is writable/readable to/from file.
        forcesFilename = 'forces.sto'
        stoAdapter.write(forcesFlat, forcesFilename)
        forcesDouble = stoAdapter.read(forcesFilename)
      
        # Clean up.
        os.remove(markersFilename)
        os.remove(forcesFilename)

 

Example code for using the C3DFileAdapter in C++ is found below. This code is part of a test script that runs the C3D reader and checks for correct values. 

...