add callback for tracking analysis progress
[mussa.git] / alg / nway_paths.cpp
index 4f49deb6806c4694c47faac9112b19a7c582af98..419d5edfbf03441171fb3f32add1fdd8f609aced 100644 (file)
@@ -15,6 +15,7 @@
 #include <boost/filesystem/fstream.hpp>
 namespace fs = boost::filesystem;
 
+#include "alg/mussa_callback.hpp"
 #include "alg/nway_paths.hpp"
 #include "alg/conserved_path.hpp"
 #include "mussa_exceptions.hpp"
@@ -25,6 +26,7 @@ namespace fs = boost::filesystem;
 using namespace std;
 
 NwayPaths::NwayPaths()
+  : progress_cb(0)
 {
 }
 
@@ -34,6 +36,7 @@ NwayPaths::setup(int w, int t)
   threshold = t;
   soft_thres = threshold;
   win_size = w;
+  progress_cb = 0;
   pathz.clear();
 
   //cout << "nway: thres = " << threshold
@@ -56,6 +59,16 @@ int NwayPaths::get_window() const
   return win_size;
 }
 
+void NwayPaths::set_progress_callback(analysis_callback cb)
+{
+  progress_cb = cb;
+}
+
+analysis_callback NwayPaths::get_progress_callback() const
+{
+  return progress_cb;
+}
+
 // dumbly goes thru and combines path windows exactly adjacent (ie + 1 index)
 // doesn't deal with interleaved adjacency
 void
@@ -72,17 +85,20 @@ NwayPaths::simple_refine()
 
   //cout << "path number is: " << pathz.size() << endl;
   pathz_i = pathz.begin();
+  int path_count = 0;
 
   // only try to extend when pathz isn't empty.
   if (pathz_i != pathz.end())
   {
     ext_path = *pathz_i;
+    ++path_count;
 
     while(pathz_i != pathz.end())
     {
       // keep track of current path and advance to next path
       cur_path = pathz_i;
       ++pathz_i;
+      ++path_count;
 
       if (pathz_i == pathz.end()) {
         end = true;
@@ -111,6 +127,9 @@ NwayPaths::simple_refine()
           ext_path = *next_path;
         }
       }
+      if (progress_cb) {
+        progress_cb("refine", path_count-1, pathz.size());
+      }
     }
   }
   //cout << "r_path number is: " << refined_pathz.size() << endl;