From f2e3ed51b2a5b2776c86223e873d765cb2b78c15 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 26 Aug 2012 15:56:38 +0200 Subject: [PATCH] Made nb_locations and nb_time_steps public. --- mtp_tracker.cc | 114 ++++++++++++++++++++++++------------------------- mtp_tracker.h | 2 +- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/mtp_tracker.cc b/mtp_tracker.cc index 825b4d1..793b672 100644 --- a/mtp_tracker.cc +++ b/mtp_tracker.cc @@ -37,28 +37,28 @@ void MTPTracker::free() { delete[] entrances; } -void MTPTracker::allocate(int nb_time_steps, int nb_locations) { +void MTPTracker::allocate(int t, int l) { free(); - _nb_locations = nb_locations; - _nb_time_steps = nb_time_steps; + nb_locations = l; + nb_time_steps = t; - detection_scores = allocate_array(_nb_time_steps, _nb_locations); - allowed_motion = allocate_array(_nb_locations, _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]; + 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++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { detection_scores[t][l] = 0.0; } } @@ -68,37 +68,37 @@ void MTPTracker::allocate(int nb_time_steps, int nb_locations) { } void MTPTracker::write(ostream *os) { - (*os) << _nb_locations << " " << _nb_time_steps <> allowed_motion[l][m]; } } - for(int l = 0; l < _nb_locations; l++) { + for(int l = 0; l < nb_locations; l++) { (*is) >> entrances[l]; } - for(int l = 0; l < _nb_locations; 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++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { (*is) >> detection_scores[t][l]; } } @@ -146,8 +146,8 @@ void MTPTracker::write_trajectories(ostream *os) { } MTPTracker::MTPTracker() { - _nb_locations = 0; - _nb_time_steps = 0; + nb_locations = 0; + nb_time_steps = 0; detection_scores = 0; allowed_motion = 0; @@ -169,11 +169,11 @@ MTPTracker::~MTPTracker() { } int MTPTracker::early_pair_node(int t, int l) { - return 1 + (2 * t + 0) * _nb_locations + l; + return 1 + (2 * t + 0) * nb_locations + l; } int MTPTracker::late_pair_node(int t, int l) { - return 1 + (2 * t + 1) * _nb_locations + l; + return 1 + (2 * t + 1) * nb_locations + l; } void MTPTracker::build_graph() { @@ -183,28 +183,28 @@ void MTPTracker::build_graph() { int nb_motions = 0, nb_exits = 0, nb_entrances = 0; - for(int l = 0; l < _nb_locations; l++) { + for(int l = 0; l < nb_locations; l++) { if(exits[l]) nb_exits++; if(entrances[l]) nb_entrances++; - for(int m = 0; m < _nb_locations; m++) { + for(int m = 0; m < nb_locations; m++) { if(allowed_motion[l][m]) nb_motions++; } } - int nb_vertices = 2 + 2 * _nb_time_steps * _nb_locations; + int nb_vertices = 2 + 2 * nb_time_steps * nb_locations; int nb_edges = // The edges from the source to the first frame, and from the last // frame to the sink - _nb_locations * 2 + + nb_locations * 2 + // The edges from the source to the entrances and from the exits // to the sink (in every time frames but the first for the // entrances, and last for the exits) - (_nb_time_steps - 1) * (nb_exits + nb_entrances) + + (nb_time_steps - 1) * (nb_exits + nb_entrances) + // The edges for the motions, between every successive frames - (_nb_time_steps - 1) * nb_motions + + (nb_time_steps - 1) * nb_motions + // The edges inside the duplicated nodes - _nb_locations * _nb_time_steps; + nb_locations * nb_time_steps; int *node_from = new int[nb_edges]; int *node_to = new int[nb_edges]; @@ -218,8 +218,8 @@ void MTPTracker::build_graph() { // lengths we will have to change before tracking, according to the // detection scores - for(int t = 0; t < _nb_time_steps; t++) { - for(int l = 0; l < _nb_locations; l++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { node_from[e] = early_pair_node(t, l); node_to[e] = late_pair_node(t, l); e++; @@ -228,17 +228,17 @@ void MTPTracker::build_graph() { // The edges from the source to the first time frame - for(int l = 0; l < _nb_locations; l++) { + for(int l = 0; l < nb_locations; l++) { node_from[e] = source; - node_to[e] = 1 + l + 0 * _nb_locations; + node_to[e] = 1 + l + 0 * nb_locations; _edge_lengths[e] = 0.0; e++; } // The edges from the last frame to the sink - for(int l = 0; l < _nb_locations; l++) { - node_from[e] = late_pair_node(_nb_time_steps - 1, l); + for(int l = 0; l < nb_locations; l++) { + node_from[e] = late_pair_node(nb_time_steps - 1, l); node_to[e] = sink; _edge_lengths[e] = 0.0; e++; @@ -246,9 +246,9 @@ void MTPTracker::build_graph() { // The edges between frames, corresponding to allowed motions - for(int t = 0; t < _nb_time_steps - 1; t++) { - for(int l = 0; l < _nb_locations; l++) { - for(int k = 0; k < _nb_locations; k++) { + for(int t = 0; t < nb_time_steps - 1; t++) { + for(int l = 0; l < nb_locations; l++) { + for(int k = 0; k < nb_locations; k++) { if(allowed_motion[l][k]) { node_from[e] = late_pair_node(t, l); node_to[e] = early_pair_node(t+1, k); @@ -262,15 +262,15 @@ void MTPTracker::build_graph() { // The edges from the source to the entrances, and from the exits to // the sink - for(int t = 0; t < _nb_time_steps; t++) { - for(int l = 0; l < _nb_locations; l++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { if(t > 0 && entrances[l]) { node_from[e] = source; node_to[e] = early_pair_node(t, l); _edge_lengths[e] = 0.0; e++; } - if(t < _nb_time_steps - 1 && exits[l]) { + if(t < nb_time_steps - 1 && exits[l]) { node_from[e] = late_pair_node(t, l); node_to[e] = sink; _edge_lengths[e] = 0.0; @@ -291,8 +291,8 @@ void MTPTracker::build_graph() { void MTPTracker::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++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { _edge_lengths[e++] = - detection_scores[t][l]; } } @@ -303,8 +303,8 @@ void MTPTracker::track() { ASSERT(_graph); int e = 0; - for(int t = 0; t < _nb_time_steps; t++) { - for(int l = 0; l < _nb_locations; l++) { + for(int t = 0; t < nb_time_steps; t++) { + for(int l = 0; l < nb_locations; l++) { _edge_lengths[e++] = - detection_scores[t][l]; } } @@ -333,7 +333,7 @@ scalar_t MTPTracker::trajectory_score(int k) { } int MTPTracker::trajectory_entrance_time(int k) { - return (_graph->paths[k]->nodes[1] - 1) / (2 * _nb_locations); + return (_graph->paths[k]->nodes[1] - 1) / (2 * nb_locations); } int MTPTracker::trajectory_duration(int k) { @@ -341,5 +341,5 @@ int MTPTracker::trajectory_duration(int k) { } int MTPTracker::trajectory_location(int k, int time_from_entry) { - return (_graph->paths[k]->nodes[2 * time_from_entry + 1] - 1) % _nb_locations; + return (_graph->paths[k]->nodes[2 * time_from_entry + 1] - 1) % nb_locations; } diff --git a/mtp_tracker.h b/mtp_tracker.h index 9574332..001bca1 100644 --- a/mtp_tracker.h +++ b/mtp_tracker.h @@ -33,7 +33,6 @@ using namespace std; #include "mtp_graph.h" class MTPTracker { - int _nb_locations, _nb_time_steps; scalar_t **_detection_score; int **_allowed_motion; int *_entrances, *_exits; @@ -47,6 +46,7 @@ class MTPTracker { public: // The spatial structure + int nb_locations, nb_time_steps; int **allowed_motion; int *entrances, *exits; -- 2.39.5