Added the fields force_empty_first_frame and force_empty_last_frame in MTPTracker.
authorFrancois Fleuret <francois@fleuret.org>
Mon, 3 Sep 2012 08:08:08 +0000 (10:08 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Mon, 3 Sep 2012 08:08:08 +0000 (10:08 +0200)
README.txt
mtp_example.cc
mtp_tracker.cc
mtp_tracker.h

index 742dde3..2ce7e31 100644 (file)
@@ -106,6 +106,8 @@ bool:allowed_motion_from_1_to_1 ... bool:allowed_motion_from_1_to_L
 ...
 bool:allowed_motion_from_L_to_1 ... bool:allowed_motion_from_L_to_L
 
 ...
 bool:allowed_motion_from_L_to_1 ... bool:allowed_motion_from_L_to_L
 
+bool:force_empty_first_frame bool:force_empty_last_frame
+
 bool:is_an_entrance_1 ... bool:is_an_entrance_L
 
 bool:is_an_exit_1 ... bool:is_an_exit_L
 bool:is_an_entrance_1 ... bool:is_an_entrance_L
 
 bool:is_an_exit_1 ... bool:is_an_exit_L
index fffeacb..92d4062 100644 (file)
@@ -64,6 +64,9 @@ int main(int argc, char **argv) {
     tracker->exits[nb_locations - 1] = 1;
   }
 
     tracker->exits[nb_locations - 1] = 1;
   }
 
+  tracker->force_empty_first_frame = 0;
+  tracker->force_empty_last_frame = 0;
+
   // We construct the graph corresponding to this structure
 
   tracker->build_graph();
   // We construct the graph corresponding to this structure
 
   tracker->build_graph();
index c7c6602..b4e70ab 100644 (file)
@@ -63,12 +63,15 @@ void MTPTracker::allocate(int t, int l) {
     }
   }
 
     }
   }
 
+  force_empty_first_frame = 0;
+  force_empty_last_frame = 0;
+
   _edge_lengths = 0;
   _graph = 0;
 }
 
 void MTPTracker::write(ostream *os) {
   _edge_lengths = 0;
   _graph = 0;
 }
 
 void MTPTracker::write(ostream *os) {
-  (*os) << nb_locations << " " << nb_time_steps <<endl;
+  (*os) << nb_locations << " " << nb_time_steps << endl;
 
   (*os) << endl;
 
 
   (*os) << endl;
 
@@ -81,6 +84,10 @@ void MTPTracker::write(ostream *os) {
 
   (*os) << endl;
 
 
   (*os) << endl;
 
+  (*os) << force_empty_first_frame << " " << force_empty_last_frame << endl;
+
+  (*os) << endl;
+
   for(int l = 0; l < nb_locations; l++) {
     (*os) << entrances[l];
     if(l < nb_locations - 1) (*os) << " "; else (*os) << endl;
   for(int l = 0; l < nb_locations; l++) {
     (*os) << entrances[l];
     if(l < nb_locations - 1) (*os) << " "; else (*os) << endl;
@@ -116,6 +123,8 @@ void MTPTracker::read(istream *is) {
     }
   }
 
     }
   }
 
+  (*is) >> force_empty_first_frame >> force_empty_last_frame;
+
   for(int l = 0; l < nb_locations; l++) {
     (*is) >> entrances[l];
   }
   for(int l = 0; l < nb_locations; l++) {
     (*is) >> entrances[l];
   }
@@ -194,9 +203,6 @@ void MTPTracker::build_graph() {
   int nb_vertices = 2 + 2 * nb_time_steps * nb_locations;
 
   int nb_edges =
   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 +
     // 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)
     // 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)
@@ -206,6 +212,20 @@ void MTPTracker::build_graph() {
     // The edges inside the duplicated nodes
     nb_locations * nb_time_steps;
 
     // The edges inside the duplicated nodes
     nb_locations * nb_time_steps;
 
+  // Edges from the source to the first frame
+  if(force_empty_first_frame) {
+    nb_edges += nb_entrances;
+  } else {
+    nb_edges += nb_locations;
+  }
+
+  // Edges from the last frame to the sink
+  if(force_empty_last_frame) {
+    nb_edges += nb_exits;
+  } else {
+    nb_edges += nb_locations;
+  }
+
   int *node_from = new int[nb_edges];
   int *node_to = new int[nb_edges];
 
   int *node_from = new int[nb_edges];
   int *node_to = new int[nb_edges];
 
@@ -229,19 +249,23 @@ void MTPTracker::build_graph() {
   // The edges from the source to the first time frame
 
   for(int l = 0; l < nb_locations; l++) {
   // The edges from the source to the first time frame
 
   for(int l = 0; l < nb_locations; l++) {
-    node_from[e] = source;
-    node_to[e] = 1 + l + 0 * nb_locations;
-    _edge_lengths[e] = 0.0;
-    e++;
+    if(!force_empty_first_frame || entrances[l]) {
+      node_from[e] = source;
+      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++) {
   }
 
   // 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);
-    node_to[e] = sink;
-    _edge_lengths[e] = 0.0;
-    e++;
+    if(!force_empty_last_frame || exits[l]) {
+      node_from[e] = late_pair_node(nb_time_steps - 1, l);
+      node_to[e] = sink;
+      _edge_lengths[e] = 0.0;
+      e++;
+    }
   }
 
   // The edges between frames, corresponding to allowed motions
   }
 
   // The edges between frames, corresponding to allowed motions
index 001bca1..1dcb94c 100644 (file)
@@ -49,6 +49,7 @@ public:
   int nb_locations, nb_time_steps;
   int **allowed_motion;
   int *entrances, *exits;
   int nb_locations, nb_time_steps;
   int **allowed_motion;
   int *entrances, *exits;
+  int force_empty_first_frame, force_empty_last_frame;
 
   // The detection scores at each location and time
   scalar_t **detection_scores;
 
   // The detection scores at each location and time
   scalar_t **detection_scores;