Saving Tracker Data

Figure 5. Saving Data

Save menu

Tracker saves properties of the video clip, coordinate system and tracks in xml data files. When a saved data file is opened, Tracker loads the specified video, sets the clip and coordinate system properties, and creates new tracks with the specified identification and step positions.

Data files are easily human-read and can be edited with any text editor. The xml format conforms to the doctype specification defined in osp10.dtd. By convention, most Tracker data files use the extension "trk", although this is not required.

Saving and Loading Data Files

The VideoIO and TrackerIO classes, shown in Listing 13, define the static methods used to save and load xml data files.

Listing 13. VideoIO Methods

VideoIO methods:
public static void open(File file, VideoPanel vidPanel);
public static void save(File file, VideoPanel vidPanel);

TrackerIO methods:
public static File importFile(TrackerPanel trackerPanel);
public static File exportFile(TrackerPanel trackerPanel);

The VideoIO.save() method saves xml data for all objects associated with the specified video panel (video, clip, coords and drawables/tracks). If the file parameter is null, a standard save as dialog is displayed.

The VideoIO.open() method loads the xml data into the specified video panel. If file is null, a standard open dialog is displayed.

The TrackerIO.importFile() and TrackerIO.exportFile() methods import and export only those xml data elements selected by the user. The file is also user-selected from a standard file chooser.

The process of saving and loading xml data for custom classes is discussed in detail in the OSP XML tutorial.

A Sample XML Data File

Figure 6 shows the appearance of Tracker after loading Ball.trk, a typical xml data file.

Figure 6. Tracker with Ball.trk

PucksCollide.trk screenshot

Listing 14 shows the xml file itself. The data is saved in a combination of <object> elements and <property> elements. The root <object> in this case is a TrackerPanel.

Note that position data (e.g., the coordinate system origin) are saved in image coordinates, not world coordinates. They are therefore not suitable for direct analysis. Instead, the world data should be copied from a data table when needed.

Listing 14. Ball.trk

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE object SYSTEM "osp10.dtd">
<object class="org.opensourcephysics.cabrillo.tracker.TrackerPanel">
<property name="videoclip" type="object">
<object class="org.opensourcephysics.media.VideoClip">
<property name="video" type="object">
<object class="org.opensourcephysics.media.quicktime.QTVideo">
<property name="path" type="string">videos/TossOut.mov</property>
</object>
</property>
<property name="startframe" type="int">5</property>
<property name="stepsize" type="int">2</property>
<property name="stepcount" type="int">10</property>
</object>
</property>
<property name="coords" type="object">
<object class="org.opensourcephysics.media.ImageCoordSystem">
<property name="fixedorigin" type="boolean">true</property>
<property name="fixedangle" type="boolean">true</property>
<property name="fixedscale" type="boolean">true</property>
<property name="locked" type="boolean">false</property>
<property name="framedata" type="array" class="[Lorg.opensourcephysics.media.ImageCoordSystem$FrameData;">
<property name="[0]" type="object">
<object class="org.opensourcephysics.media.ImageCoordSystem$FrameData">
<property name="xorigin" type="double">180.0</property>
<property name="yorigin" type="double">120.0</property>
<property name="angle" type="double">0.0</property>
<property name="xscale" type="double">1.0</property>
<property name="yscale" type="double">1.0</property>
</object>
</property>
</property>
</object>
</property>
<property name="tracks" type="collection" class="java.util.ArrayList">
<property name="item0" type="object">
<object class="org.opensourcephysics.cabrillo.tracker.CoordAxes">
<property name="name" type="string">axes</property>
<property name="visible" type="boolean">false</property>
<property name="trail" type="boolean">false</property>
</object>
</property>
<property name="item1" type="object">
<object class="org.opensourcephysics.cabrillo.tracker.TapeMeasure">
<property name="name" type="string">tape measure</property>
<property name="visible" type="boolean">false</property>
<property name="trail" type="boolean">false</property>
<property name="fixedtape" type="boolean">true</property>
<property name="framedata" type="array" class="[Lorg.opensourcephysics.cabrillo.tracker.TapeMeasure$FrameData;">
<property name="[0]" type="object">
<object class="org.opensourcephysics.cabrillo.tracker.TapeMeasure$FrameData">
<property name="x1" type="double">130.0</property>
<property name="y1" type="double">110.0</property>
<property name="x2" type="double">230.0</property>
<property name="y2" type="double">110.0</property>
</object>
</property>
</property>
</object>
</property>
<property name="item2" type="object">
<object class="org.opensourcephysics.cabrillo.tracker.PointMass">
<property name="mass" type="double">1.0</property>
<property name="name" type="string">ball</property>
<property name="color" type="object">
<object class="java.awt.Color">
<property name="red" type="int">0</property>
<property name="green" type="int">0</property>
<property name="blue" type="int">255</property>
<property name="alpha" type="int">255</property>
</object>
</property>
<property name="visible" type="boolean">true</property>
<property name="trail" type="boolean">true</property>
<property name="framedata" type="array" class="[Lorg.opensourcephysics.cabrillo.tracker.PointMass$FrameData;"/>
</object>
</property>
</property>
<property name="selectedtrack" type="string">ball</property>
</object>