2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by and Copyright (C) Francois Fleuret //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
21 Tracker::Tracker(int nb_locations, int nb_time_steps) {
22 _nb_locations = nb_locations;
23 _nb_time_steps = nb_time_steps;
24 _detection_score = allocate_array<scalar_t>(nb_locations, nb_time_steps);
25 _allowed_motion = allocate_array<int>(nb_locations, nb_locations);
26 for(int l = 0; l < nb_locations; l++) {
27 for(int m = 0; m < nb_locations; m++) {
28 _allowed_motion[l][m] = 0;
36 void Tracker::set_allowed_motion(int from_location, int to_location) {
37 _allowed_motion[from_location][to_location] = 1;
40 void Tracker::set_detection_score(int location, int time, scalar_t score) {
43 void Tracker::track() {
45 cout << "Building graph." << endl;
48 for(int l = 0; l < _nb_locations; l++) {
49 for(int m = 0; m < _nb_locations; m++) {
50 if(_allowed_motion[l][m]) nb_motions++;
54 int nb_vertices = 2 + 2 * (_nb_time_steps + 1) * _nb_locations;
55 int nb_edges = _nb_locations * 2 // From source and to sink
56 + _nb_time_steps * nb_motions // Motions
57 + _nb_locations * _nb_time_steps; // Doubling of nodes to force
58 // one target per location
60 int source = 0, sink = nb_vertices - 1;
61 int *node_from = new int[nb_edges];
62 int *node_to = new int[nb_edges];
63 scalar_t *edge_length = new scalar_t[nb_edges];
66 for(int l = 0; l < _nb_locations; l++) {
67 node_from[e] = source;
68 node_to[e] = 1 + l + 0 * _nb_locations;
73 for(int t = 0; t <= _nb_time_steps; t++) {
74 for(int l = 0; l < _nb_locations; l++) {
75 node_from[e] = 1 + (2 * (t + 0) + 0) * _nb_locations + l;
76 node_to[e] = 1 + (2 * (t + 0) + 1) * _nb_locations + l;
77 edge_length[e] = _detection_score[t][l];
79 if(t == _nb_time_steps) {
80 node_from[e] = 1 + (2 * (t + 0) + 0) * _nb_locations + l;
85 for(int k = 0; k < _nb_locations; k++) {
86 if(_allowed_motion[l][k]) {
87 node_from[e] = 1 + (2 * (t + 0) + 1) * _nb_locations + l;
88 node_to[e] = 1 + (2 * (t + 1) + 0) * _nb_locations + k;
98 // void Tracker::track() {
99 // int e = _nb_locations;
100 // for(int t = 0; t <= _nb_time_steps; t++) {
101 // for(int l = 0; l < _nb_locations; l++) {
102 // edge_length[e] = _detection_score[t][l];
104 // if(t == _nb_time_steps) {
107 // e += _nb_locations;
113 int Tracker::nb_trajectories() {
116 int Tracker::trajectory_start_time(int k) {
119 int Tracker::trajectory_end_time(int k) {
122 int Tracker::trajectory_location(int k, int time) {