X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=tracker.cc;h=4d12e6145d38bd702bbabc8a2c805c305f1880ee;hb=b55dae20c1b56dac452dda6ab2831ea6388c079b;hp=d3397cf4736a9c14c5aaa1b3d8bf5335f267a1ed;hpb=9dba69873c4b22f885a70740df7f57b0d6a37fd6;p=mtp.git diff --git a/tracker.cc b/tracker.cc index d3397cf..4d12e61 100644 --- a/tracker.cc +++ b/tracker.cc @@ -22,29 +22,131 @@ using namespace std; -Tracker::Tracker(int nb_time_steps, int nb_locations) { +void Tracker::free() { + delete[] _edge_lengths; + delete _graph; + deallocate_array(detection_scores); + deallocate_array(allowed_motion); + delete[] exits; + delete[] entrances; +} + +void Tracker::allocate(int nb_time_steps, int nb_locations) { + free(); + _nb_locations = nb_locations; _nb_time_steps = nb_time_steps; - detection_score = allocate_array(_nb_time_steps, _nb_locations); + detection_scores = allocate_array(_nb_time_steps, _nb_locations); allowed_motion = allocate_array(_nb_locations, _nb_locations); entrances = new int[_nb_locations]; exits = new int[_nb_locations]; - for(int l = 0; l < nb_locations; l++) { + for(int l = 0; l < _nb_locations; l++) { entrances[l] = 0; exits[l] = 0; - for(int m = 0; m < nb_locations; m++) { + for(int m = 0; m < _nb_locations; m++) { allowed_motion[l][m] = 0; } } for(int t = 0; t < _nb_time_steps; t++) { for(int l = 0; l < _nb_locations; l++) { - detection_score[t][l] = 0.0; + detection_scores[t][l] = 0.0; + } + } + + _edge_lengths = 0; + _graph = 0; +} + +void Tracker::write(ostream *os) { + (*os) << _nb_locations << " " << _nb_time_steps <> nb_locations >> nb_time_steps; + + allocate(nb_time_steps, nb_locations); + + for(int l = 0; l < _nb_locations; l++) { + for(int m = 0; m < _nb_locations; m++) { + (*is) >> allowed_motion[l][m]; + } + } + + for(int l = 0; l < _nb_locations; l++) { + (*is) >> entrances[l]; + } + + for(int l = 0; l < _nb_locations; l++) { + (*is) >> exits[l]; + } + + for(int t = 0; t < _nb_time_steps; t++) { + for(int l = 0; l < _nb_locations; l++) { + (*is) >> detection_scores[t][l]; + } + } +} + +void Tracker::write_trajectories(ostream *os) { + for(int t = 0; t < nb_trajectories(); t++) { + (*os) << t + << " " << trajectory_entrance_time(t) + << " " << trajectory_duration(t) + << " " << trajectory_score(t); + for(int u = 0; u < trajectory_duration(t); u++) { + (*os) << " " << trajectory_location(t, u); } + (*os) << endl; } +} + +Tracker::Tracker() { + _nb_locations = 0; + _nb_time_steps = 0; + + detection_scores = 0; + allowed_motion = 0; + + entrances = 0; + exits = 0; _edge_lengths = 0; _graph = 0; @@ -53,7 +155,7 @@ Tracker::Tracker(int nb_time_steps, int nb_locations) { Tracker::~Tracker() { delete[] _edge_lengths; delete _graph; - deallocate_array(detection_score); + deallocate_array(detection_scores); deallocate_array(allowed_motion); delete[] exits; delete[] entrances; @@ -173,17 +275,19 @@ void Tracker::print_graph_dot(ostream *os) { int e = 0; for(int t = 0; t < _nb_time_steps; t++) { for(int l = 0; l < _nb_locations; l++) { - _edge_lengths[e++] = - detection_score[t][l]; + _edge_lengths[e++] = - detection_scores[t][l]; } } _graph->print_dot(os); } void Tracker::track() { + ASSERT(_graph); + int e = 0; for(int t = 0; t < _nb_time_steps; t++) { for(int l = 0; l < _nb_locations; l++) { - _edge_lengths[e++] = - detection_score[t][l]; + _edge_lengths[e++] = - detection_scores[t][l]; } }