]> Creatis software - clitk.git/blob - vv/vv.cxx
Romulo:
[clitk.git] / vv / vv.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #include <utility>
19 #include <cassert>
20 #include <ctime>
21 #include <string>
22 #include <ostream>
23 #include <QApplication>
24 #include <QPixmap>
25 #include <QSplashScreen>
26 #include <QTimer>
27 #include <QDesktopWidget>
28
29 #include "clitkIO.h"
30 #include "vvMainWindow.h"
31 #include "vvConstants.h"
32
33 #include <vtkFileOutputWindow.h>
34 #include <vtkSmartPointer.h>
35 #include <itkFileOutputWindow.h>
36 #include <itkSmartPointer.h>
37
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include  <errno.h> 
41
42 void load_image_first_error()
43 {
44   std::cerr << "You need to load an image before adding an overlay!" << std::endl;
45   exit(1);
46 }
47
48 std::string create_timed_string()
49 {
50   time_t t;
51   time(&t);
52   
53   struct tm* pt = localtime(&t);
54   
55   const int size = 64;
56   char st[size];
57   strftime(st, size, "%Y%m%d-%H%M%S", pt);
58   
59   return st;
60 }
61
62 //------------------------------------------------------------------------------
63 int main( int argc, char** argv )
64 {
65   CLITK_INIT;
66
67   QApplication app( argc, argv );
68   Q_INIT_RESOURCE(vvIcons);
69   //QPixmap pixmap(":/splashscreen.PNG");
70   QSplashScreen *splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/new/prefix1/splashscreen.PNG")));
71   /*splash->showMessage("VV 1.0 developped by Léon Bérard c`ancer center http://oncora1.lyon.fnclcc.fr and CREATIS-LRMN http://www.creatis.insa-lyon.fr",(Qt::AlignRight | Qt::AlignBottom));*/
72   //  splash->show();
73   QTimer::singleShot(2000, splash, SLOT(close()));
74   while (!splash->isHidden())
75     app.processEvents();
76
77   vvMainWindow window;
78
79   //Try to give the window a sensible default size
80   int width=QApplication::desktop()->width()*0.8;
81   int height=QApplication::desktop()->height()*0.9;
82   if (width> 1.5*height)
83     width=1.5*height;
84   window.resize(width,height);
85
86   window.show();
87
88   std::vector<std::string> sequence_filenames;
89   enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
90   int parse_mode=P_NORMAL;
91   int n_image_loaded=0;
92   std::string win(""), lev("");
93
94   if (argc >1) {
95     for (int i = 1; i < argc; i++) {
96       std::string current = argv[i];
97       if (!current.compare(0,2,"--")) { //We are parsing an option
98         if (parse_mode == P_SEQUENCE) {//First finish the current sequence
99           window.LoadImages(sequence_filenames,MERGEDWITHTIME);
100           sequence_filenames.clear();
101           parse_mode=P_NORMAL;
102         }
103         if (current=="--vf") {
104           if (!n_image_loaded) load_image_first_error();
105           window.AddField(argv[i+1],n_image_loaded-1);
106           i++; //skip vf name
107         } else if (current=="--overlay") {
108           if (!n_image_loaded) load_image_first_error();
109           window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
110           i++; //skip overlay name
111         } else if (current=="--roi") {
112           if (!n_image_loaded) load_image_first_error();
113           window.AddROI(n_image_loaded-1,argv[i+1]);
114           i++; //skip roi name
115         } else if (current=="--fusion") {
116           if (!n_image_loaded) load_image_first_error();
117           window.AddFusionImage(n_image_loaded-1,argv[i+1]);
118           i++; //skip fusion name
119         } else if (current == "--sequence") {
120           n_image_loaded++; //count only one for the sequence
121           parse_mode=P_SEQUENCE;
122         } else if (current == "--window") {
123           parse_mode=P_WINDOW;
124         } else if (current == "--level") {
125           parse_mode=P_LEVEL;
126         } else if (current == "--log") {
127           std::string log_dir = "/tmp/vv-log";
128           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); 
129           if (err && errno != EEXIST)
130             std::cout << "Error creating log directory with errno " << errno << std::endl;
131
132           std::string log_file = log_dir + "/" + create_timed_string() + ".log";
133           vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
134           vtk_log->SetFileName(log_file.c_str());
135           vtk_log->FlushOn();
136           vtkOutputWindow::SetInstance(vtk_log);
137           
138           itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
139           itk_log->SetFileName(log_file.c_str());
140           itk_log->FlushOn();
141           itk::OutputWindow::SetInstance(itk_log);
142         }
143       } else if (parse_mode == P_SEQUENCE) {
144         sequence_filenames.push_back(current);
145       } else if (parse_mode == P_WINDOW) {
146         win=current;
147         parse_mode=P_NORMAL;
148       } else if (parse_mode == P_LEVEL) {
149         lev=current;
150         parse_mode=P_NORMAL;
151       } else {
152         std::vector<std::string> image;
153         image.push_back(current);
154         window.LoadImages(image,IMAGE);
155         n_image_loaded++;
156       }
157     }
158     if (parse_mode == P_SEQUENCE) { //Finish any current sequence
159       window.LoadImages(sequence_filenames,MERGEDWITHTIME);
160       sequence_filenames.clear();
161       parse_mode=P_NORMAL;
162     }
163   }
164
165   if(win!="" && lev!="") {
166     window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
167     window.ApplyWindowLevelToAllImages();
168   }
169
170   return app.exec();
171 }