Introduction
A .trc (Track Row Column) file is a text table of the positions of motion
capture markers over time. Motion Analysis Corporation defined it for its capture
software, and biomechanics tools read and write it, above all OpenSim. It holds one row
per frame and three columns, X, Y and Z, per marker. It stores positions only: no
skeleton, joint angles or segment data. Joint angles and forces usually travel in
OpenSim’s motion and storage files.
Structure
The file is plain text, one record per line, with the tab character separating columns. Lines may end with LF or CR LF. Lines 1 to 5 are fixed; the data follows, usually after one blank line.
PathFileType 4 (X/Y/Z) walk1.trc
DataRate CameraRate NumFrames NumMarkers Units OrigDataRate OrigDataStartFrame OrigNumFrames
60.00 60.00 151 2 mm 60.00 1 151
Frame# Time R.ASIS L.ASIS
X1 Y1 Z1 X2 Y2 Z2
1 0.000000 617.247620 1055.275020 170.781980 639.606380 1044.258420 -88.909790
2 0.017000 617.998110 1053.217530 168.513170 641.236210 1042.278560 -90.932130
subject01_walk1.trc. Gaps between columns are single tabs; three tabs
after a marker name skip over its Y and Z columns.| Line | Content |
|---|---|
| 1 | PathFileType, a path type number, (X/Y/Z), then a file name or full path |
| 2 | The names of the header values |
| 3 | The header values, in the order of line 2 |
| 4 | Frame#, Time, then one name per marker, each in the column of that marker’s X value |
| 5 | Two empty columns, then X1 Y1 Z1 X2 Y2 Z2 and so on |
| 6 | Usually blank |
| 7 on | One line per frame |
First line
The word PathFileType identifies the format. The number after it is the
path type. OpenSim writes 4, and its older reader accepts 3
or 4. The two differ in line 3: a type 3 file is read without the three
“original” values. The third field is (X/Y/Z), and the last is the name
the file was saved under, which may be a full path. OpenSim’s newer reader checks only
the first word and keeps the rest of the line as text.
Header values
| Order | Name | Type | Meaning |
|---|---|---|---|
| 1 | DataRate | number | Sampling rate of the rows in this file, in hertz |
| 2 | CameraRate | number | Camera rate in hertz; OpenSim writes DataRate when it has no separate value |
| 3 | NumFrames | integer | Number of data rows |
| 4 | NumMarkers | integer | Number of markers; each row has 3 × NumMarkers + 2 columns |
| 5 | Units | text | Length unit of the coordinates, commonly mm |
| 6 | OrigDataRate | number | Rate of the original data; OpenSim defaults it to DataRate |
| 7 | OrigDataStartFrame | integer | Frame number given for the start of the data; OpenSim writes 0 when it has no value, and its older reader assumes 1 for type 3 |
| 8 | OrigNumFrames | integer | Number of frames in the original data; OpenSim defaults it to NumFrames |
Values may be padded with spaces, as in the OpenSim sample, whose frame counts are
written right-aligned. OpenSim’s documentation gives the capture time of frame
f as t = (f − OrigDataStartFrame) / DataRate. The files also
carry the time explicitly in their second column.
Units
These are the unit strings OpenSim recognises. Matching is exact, including case; any other string is an unknown unit. Only the length units make sense for marker positions.
| Unit | Accepted spellings |
|---|---|
| Millimetres | mm MM millimeters MILLIMETERS |
| Centimetres | cm CM centimeters CENTIMETERS |
| Metres | m M meters METERS |
| Radians | rad RAD radians RADIANS |
| Degrees | deg DEG degrees DEGREES |
| Seconds | sec SEC seconds SECONDS |
| Milliseconds | msec MSEC milliseconds MILLISECONDS |
| Newtons | N Newtons NEWTONS |
Marker columns
Line 4 starts with Frame# and Time. Each marker name is
followed by three tabs, so the next name stands above the next X column; the two
columns under Y and Z are empty. Names are free text without tabs, for example
R.ASIS or Top.Head. Line 5 labels each coordinate column
with the axis letter and the marker’s number counted from 1. The directions of the
axes are not declared in the file: they are whatever the capture system or the
program that exported it used. OpenSim expects the coordinates to have been rotated
into its model’s frame before import, and matches markers to the model by name.
Data rows
| Column | Content |
|---|---|
| 1 | Frame number, an integer |
| 2 | Time in seconds |
| 3 to 5 | X, Y, Z of marker 1, in the unit of line 3 |
| 6 on | X, Y, Z of each further marker |
A marker that was not seen in a frame leaves its three fields empty, with the tabs
kept, so the later columns do not move. Because of this the data rows must be split on
single tabs: splitting on runs of spaces or tabs shifts the columns after a gap.
OpenSim’s newer reader turns a marker with any of its three fields empty into
not-a-number values. Its older reader also accepts NaN written out.
Rows commonly end with a trailing tab.
How OpenSim reads a file
OpenSim has two readers with different tolerances.
| Rule | Table reader (TRCFileAdapter) | Older reader (MarkerData) |
|---|---|---|
| First line | First word must be PathFileType | Also needs path type 3 or 4 |
| Line 2 | Exactly the eight names, in order | Ignored |
| Line 3 | One value for each name | Five values for type 3, eight for type 4 |
| Line 4 | Empty fields dropped; the count must be NumMarkers + 2 | Names read tab by tab, three columns per marker |
| Line 5 | Checked label by label | Read and discarded |
| Blank lines before the data | Skipped | Skipped, as are blank lines within the data |
| End of data | First empty line or end of file | After NumFrames rows or at end of file |
| Wrong column count | Error | Extra coordinates ignored; a line without a leading frame number and time is skipped |
| Frame numbers | Discarded | Renumbered from the first one if they are not consecutive; NumFrames is reduced if the file is short |
When OpenSim writes a TRC file it puts the frame number as the row number counted
from 1, writes numbers with the precision of a double plus one digit, requires
DataRate and Units, and writes an empty line after
line 5. The older reader can also take marker data from an
OpenSim storage file whose columns are named
name.x, name.y, name.z; it then assumes metres
and 250 frames a second.
How the Biomechanical ToolKit reads and writes a file
The Biomechanical
ToolKit (BTK) checks only that a file starts with PathFileType and takes no account of the
path type. It looks the header values up by the names on line 2, not by position. It uses
NumMarkers, NumFrames, DataRate, OrigDataStartFrame
and Units, and assumes mm if there is no Units. A marker with an
empty field in a frame is treated as hidden in that frame. A file that states 0 markers but has frames is
read as unlabelled markers, named Unlabel#1 and so on from the number of tabs in each
row.
When it writes, BTK gives path type 4, puts the same rate in DataRate,
CameraRate and OrigDataRate, the first frame number in
OrigDataStartFrame and the number of rows in OrigNumFrames. It numbers the rows
from 1 and starts the time column at 0.
Divergence from the documentation
OpenSim’s documentation describes three header lines, two lines of column labels, a
blank line and the data, with the first row captured at frame
OrigDataStartFrame. Its older reader accepts the data with or without
that blank line. Its writer, when no start frame is known, writes 0
although it numbers the rows from 1, so the time column is the safer source of time.
The documentation says files are commonly tab-delimited; both readers in fact depend
on the tabs to place marker names and gaps.
In the explorer
Every line and tab-separated field is in the tree. The markers are drawn as points and played by the time column, each row opens as a picture with its values, and each marker opens as its path through the whole file, 500,000 rows to a picture, with its values. A marker that is not seen is not drawn. The header and rows are checked against what the two OpenSim readers expect, and every difference is listed. Y is drawn up; the file does not say which way its axes point. Files up to 256 MB are read.
Not described
This reference is built from OpenSim’s documentation and readers, not from Motion Analysis’s own definition.
Known, not yet covered
- Viewer: files over 256 MB are not read.
- Reference: the maker’s description of the format, in Appendix G (pages G-4 and G-5) of the EVaRT 4.2 manual, which was not available.
Unknown
- Reference: path type numbers other than 3 and 4, and what the number selects.
- Reference: whether anything other than
(X/Y/Z)is valid as the third field of line 1. - Reference: the maker’s definitions of
CameraRate,OrigDataRate,OrigDataStartFrameandOrigNumFrames.
Links
Software
- OpenSim – musculoskeletal modelling program that reads and writes TRC (Windows, macOS, Linux)
Developers
- TRCFileAdapter.cpp – OpenSim’s TRC reader and writer (C++)
- MarkerData.cpp – OpenSim’s older marker reader (C++)
- Units.cpp – the accepted unit strings (C++)
- btkTRCFileIO.cpp – the Biomechanical ToolKit’s TRC reader and writer (C++)
Reference
- Marker (.trc) files – OpenSim documentation
- subject01_walk1.trc – sample walking trial from the OpenSim models
- Motion Analysis TRC – short notes on the first line, University of Wisconsin course, 1999