Tracker and TrackerPanel

Figure 3. Tracker Application

Basic Tracker application

The Tracker application includes the following elements:

TrackerPanel

Some useful tracker panel methods are shown in Listing 7.

Listing 7. TrackerPanel Methods

public void addTrack(TTrack track); // tracks may also be added using addDrawable()
public void removeTrack(TTrack track);
public boolean containsTrack(TTrack track);
public TTrack getTrack(String name); // may return null
public ArrayList getTracks();
public void setSelectedTrack(TTrack track); // target for mouse/keyboard input
public void setSelectedPoint(TPoint point); // target for mouse/keyboard input
public void setMagnification(double magnification);

If a tracker panel has two tracks with the same name, the getTrack() method returns the first one added.

The setMagnification() method magnifies the video image by the specified factor for more accurate marking with a mouse. TrackerPanel implements Scrollable and is typically placed in a ScrollPane so the entire image can be viewed even when magnified.

Selecting a track identifies it as the target for mouse and keyboard input. For example, a track must be selected in order to mark its steps with the mouse.

Selecting a point typically displays its coordinates or other data on Tracker's toolbar. The point's track is also selected.

Tracker

The Tracker class constructs a fully functional Tracker with frame, panels, menubars, toolbars and mouse handler as shown in Figure 3. Tracker's constructors and public methods are shown in Listing 8.

Listing 8. Tracker Methods

// constructors
public Tracker(); // constructs an empty Tracker
public Tracker(Video video); // constructs Tracker and opens video
public Tracker(String fileNames); // constructs Tracker and opens xml files

// instance methods
public TrackerPanel getTrackerPanel();
public TFrame getFrame();
public Object get(String propName);
public void set(String propName, Object value);

// main method
public static void main(String[] args) {
Tracker tracker = null;
if (args == null || args.length == 0) tracker = new Tracker();
else tracker = new Tracker(args[0]);
tracker.getFrame().setVisible(true);
}

Customizing Tracker

Figure 4. BallApp: A Custom Application

BallApp screenshot

The easiest way to customize Tracker is to open/create the desired video and tracks, save them in an xml data file (see Saving Tracker Data), and then open the saved data file in the main method of a custom application. Listing 9 shows the main() method of BallApp, an application that opens the xml file "Ball.trk" located in the "data" folder. The application opens the video and creates a "ball" track that is ready to mark as shown in Figure 4. Note that the bottom tab identifies the open data file.

Listing 9. BallApp

public static void main(String[] args) {
Tracker tracker = new Tracker("data/Ball.trk");
tracker.getFrame().setVisible(true);
}

Listing 10 shows another way to accomplish the same thing without a data file. In TrackerBallApp, the main method opens Tracker with a video in an untitled tab, sets the video clip properties, and adds the "Ball" point mass track. It also selects the ball so it is ready for marking.

Listing 10. TrackerBallApp

public static void main(String[] args) {

// create a video
Video video = null;
try {
video = new QTVideo("videos/TossOut.mov");
} catch (IOException ex) {}

// create tracker with the video and get the tracker panel
Tracker tracker = new Tracker(video);
TrackerPanel trackerPanel = tracker.getTrackerPanel();

// set start frame and step size of the video clip
trackerPanel.getPlayer().getVideoClip().setStartFrameNumber(5);
trackerPanel.getPlayer().getVideoClip().setStepSize(2);
video.goToStart();

// add a point mass track and select it for marking
PointMass p = new PointMass();
p.setName("Ball");
p.setMass(50);
trackerPanel.addTrack(p);
trackerPanel.setSelectedTrack(p);

// show the frame
tracker.getFrame().setVisible(true);
}

Figure 5 shows a screenshot of TrackerBallApp. It looks identical to BallApp except that the tab is untitled and Ball is capitalized.

Figure 5. TrackerBallApp: A Custom Application