+#define FILENAME_SIZE 1024
+
+char trajectory_filename[FILENAME_SIZE];
+char graph_filename[FILENAME_SIZE];
+int verbose;
+
+void usage(ostream *os) {
+ (*os) << "mtp [-h|--help] [-v|--verbose] [-t|--trajectory-filename <trajectory filename>] [-g|--graph-filename <graph filename>] [<tracking parameter file>]" << endl;
+}
+
+scalar_t diff_in_second(struct timeval *start, struct timeval *end) {
+ return
+ scalar_t(end->tv_sec - start->tv_sec) +
+ scalar_t(end->tv_usec - start->tv_usec)/1000000;
+}
+
+void do_tracking(istream *in_tracker) {
+ timeval start_time, end_time;
+ MTPTracker *tracker = new MTPTracker();
+
+ if(verbose) { cout << "Reading the tracking parameters." << endl; }
+ tracker->read(in_tracker);
+
+ if(verbose) { cout << "Building the graph ... "; cout.flush(); }
+ gettimeofday(&start_time, 0);
+ tracker->build_graph();
+ gettimeofday(&end_time, 0);
+ if(verbose) { cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; }
+
+ if(verbose) { cout << "Tracking ... "; cout.flush(); }
+ gettimeofday(&start_time, 0);
+ tracker->track();
+ gettimeofday(&end_time, 0);
+ if(verbose) { cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; }
+
+ if(strcmp(trajectory_filename, "")) {
+ ofstream out_traj(trajectory_filename);
+ tracker->write_trajectories(&out_traj);
+ if(verbose) { cout << "Wrote " << trajectory_filename << "." << endl; }
+ } else {
+ tracker->write_trajectories(&cout);
+ }
+
+ if(strcmp(graph_filename, "") != 0) {
+ ofstream out_dot(graph_filename);
+ tracker->print_graph_dot(&out_dot);
+ if(verbose) { cout << "Wrote " << graph_filename << "." << endl; }
+ }
+
+ delete tracker;
+}
+
+static struct option long_options[] = {
+ { "trajectory-file", 1, 0, 't' },
+ { "graph-file", 1, 0, 'g' },
+ { "help", no_argument, 0, 'h' },
+ { "verbose", no_argument, 0, 'v' },
+ { 0, 0, 0, 0 }
+};