]> Creatis software - clitk.git/blobdiff - vv/vv.cxx
Romulo:
[clitk.git] / vv / vv.cxx
index 71974f1e6124dea74f279b35825a76edf7b369c2..8fcc382cf7d1709683691b1c8ae085d842d9f034 100644 (file)
--- a/vv/vv.cxx
+++ b/vv/vv.cxx
@@ -17,6 +17,9 @@
 ======================================================================-====*/
 #include <utility>
 #include <cassert>
+#include <ctime>
+#include <string>
+#include <ostream>
 #include <QApplication>
 #include <QPixmap>
 #include <QSplashScreen>
 #include "vvMainWindow.h"
 #include "vvConstants.h"
 
+#include <vtkFileOutputWindow.h>
+#include <vtkSmartPointer.h>
+#include <itkFileOutputWindow.h>
+#include <itkSmartPointer.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include  <errno.h> 
+
 void load_image_first_error()
 {
   std::cerr << "You need to load an image before adding an overlay!" << std::endl;
   exit(1);
 }
 
+std::string create_timed_string()
+{
+  time_t t;
+  time(&t);
+  
+  struct tm* pt = localtime(&t);
+  
+  const int size = 64;
+  char st[size];
+  strftime(st, size, "%Y%m%d-%H%M%S", pt);
+  
+  return st;
+}
+
 //------------------------------------------------------------------------------
 int main( int argc, char** argv )
 {
@@ -60,9 +86,10 @@ int main( int argc, char** argv )
   window.show();
 
   std::vector<std::string> sequence_filenames;
-  enum {P_NORMAL,P_SEQUENCE};
+  enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
   int parse_mode=P_NORMAL;
   int n_image_loaded=0;
+  std::string win(""), lev("");
 
   if (argc >1) {
     for (int i = 1; i < argc; i++) {
@@ -77,41 +104,67 @@ int main( int argc, char** argv )
           if (!n_image_loaded) load_image_first_error();
           window.AddField(argv[i+1],n_image_loaded-1);
           i++; //skip vf name
-        } 
-        else if (current=="--overlay") {
-            if (!n_image_loaded) load_image_first_error();
-            window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
-            i++; //skip overlay name
-          } 
-        else if (current=="--roi") {
-            if (!n_image_loaded) load_image_first_error();
-            window.AddROI(n_image_loaded-1,argv[i+1]);
-            i++; //skip roi name
-          }
-        else if (current=="--fusion") {
-            if (!n_image_loaded) load_image_first_error();
-            window.AddFusionImage(n_image_loaded-1,argv[i+1]);
-            i++; //skip fusion name
-          }
-        else if (current == "--sequence") {
+        } else if (current=="--overlay") {
+          if (!n_image_loaded) load_image_first_error();
+          window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
+          i++; //skip overlay name
+        } else if (current=="--roi") {
+          if (!n_image_loaded) load_image_first_error();
+          window.AddROI(n_image_loaded-1,argv[i+1]);
+          i++; //skip roi name
+        } else if (current=="--fusion") {
+          if (!n_image_loaded) load_image_first_error();
+          window.AddFusionImage(n_image_loaded-1,argv[i+1]);
+          i++; //skip fusion name
+        } else if (current == "--sequence") {
           n_image_loaded++; //count only one for the sequence
-          parse_mode=P_SEQUENCE; }
-      }
-      else if (parse_mode == P_SEQUENCE)
+          parse_mode=P_SEQUENCE;
+        } else if (current == "--window") {
+          parse_mode=P_WINDOW;
+        } else if (current == "--level") {
+          parse_mode=P_LEVEL;
+        } else if (current == "--log") {
+         std::string log_dir = "/tmp/vv-log";
+         int err = mkdir(log_dir.c_str(), S_IRWXU | S_IRUSR | S_IWUSR | S_IRWXG | S_IRGRP | S_IWGRP | S_IRWXO | S_IROTH | S_IWOTH); 
+         if (err && errno != EEXIST)
+           std::cout << "Error creating log directory with errno " << errno << std::endl;
+
+         std::string log_file = log_dir + "/" + create_timed_string() + ".log";
+         vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
+         vtk_log->SetFileName(log_file.c_str());
+         vtk_log->FlushOn();
+         vtkOutputWindow::SetInstance(vtk_log);
+         
+         itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
+         itk_log->SetFileName(log_file.c_str());
+         itk_log->FlushOn();
+         itk::OutputWindow::SetInstance(itk_log);
+       }
+      } else if (parse_mode == P_SEQUENCE) {
         sequence_filenames.push_back(current);
-      else {
-        DD(current);
-        std::vector<std::string> image; image.push_back(current);
+      } else if (parse_mode == P_WINDOW) {
+        win=current;
+        parse_mode=P_NORMAL;
+      } else if (parse_mode == P_LEVEL) {
+        lev=current;
+        parse_mode=P_NORMAL;
+      } else {
+        std::vector<std::string> image;
+        image.push_back(current);
         window.LoadImages(image,IMAGE);
         n_image_loaded++;
       }
     }
-    if (parse_mode == P_SEQUENCE) {//Finish any current sequence
+    if (parse_mode == P_SEQUENCE) { //Finish any current sequence
       window.LoadImages(sequence_filenames,MERGEDWITHTIME);
       sequence_filenames.clear();
       parse_mode=P_NORMAL;
     }
+  }
 
+  if(win!="" && lev!="") {
+    window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
+    window.ApplyWindowLevelToAllImages();
   }
 
   return app.exec();