Versions Compared

Key

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

...

Starting with OpenSim 4.0, C3D reading and conversion into OpenSim formats is available. Currently, use of C3D reading is limited to C++ and scripting and we will be working to support direct C3D reading in the GUI in future releases. The easiest way 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. 

...

  • 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

...


  • Code Block
    languagejava
    titleExport C3D Matlab
        %% Load OpenSim libs
        import org.opensim.modeling.*
        
        %% Get the path to a C3D file
        [filename, path] = uigetfile('*.c3d');
        c3dpath = fullfile(path,filename);
        
        %% Construct an opensimC3D object with input c3d path
        % Constructor takes full path to c3d file and an integer for forceplate
        % representation in output forces file (0 = electrical center, 1 = COP). 
        c3d = osimC3D(c3dpath,useCenterOfPressureAsMomentsPoint);
        
        %% Get some stats...
        % Get the number of marker trajectories
        nTrajectories = c3d.getNumTrajectories();
        % Get the marker data rate
        rMakers = c3d.getRate_marker();
        % Get the number of forces 
        nForces = c3d.getNumForces();
        % Get the force data rate
        rForces = c3d.getRate_force();
        
        % Get Start and end time
        t0 = c3d.getStartTime();
        tn = c3d.getEndTime();
        
        %% Rotate the data 
        c3d.rotateData('x',-90)
        
        %% Get the c3d in different forms
        % Get OpenSim tables
        markerTable = c3d.getTable_markers();
        forceTable = c3d.getTable_forces();
        % Get as Matlab Structures
        [markerStruct forceStruct] = c3d.getAsStructs();
        
        %% Convert COP (mm to m) and Moments (Nmm to Nm)
        if convertLengthUnits
            c3d.convertMillimeters2Meters();
        end
        
        %% Write the marker and force data to file
        % Define output file names
        basename = strtok(filename,'.');
        markersFilename = strcat(basename,'_markers.trc');
        
        switch useCenterOfPressureAsMomentsPoint
            case 0
                forcesFilename = strcat(basename,'_forces_EC.mot');
            case 1
                forcesFilename = strcat(basename,'_forces_COP.mot');
        end
        
        % Write marker data to trc file.
        c3d.writeTRC(markersFilename);
        
        % Write force data to mot file.
        c3d.writeMOT(forcesFilename);
    
    



Reading C3D files through Python and C++

...