1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
23 #include <QApplication>
25 #include <QSplashScreen>
27 #include <QDesktopWidget>
30 #include "vvMainWindow.h"
31 #include "vvConstants.h"
33 #include <vtkFileOutputWindow.h>
34 #include <vtkSmartPointer.h>
35 #include <itkFileOutputWindow.h>
36 #include <itkSmartPointer.h>
38 #include <sys/types.h>
42 void load_image_first_error()
44 std::cerr << "You need to load an image before adding an overlay!" << std::endl;
48 std::string create_timed_string()
53 struct tm* pt = localtime(&t);
57 strftime(st, size, "%Y%m%d-%H%M%S", pt);
62 //------------------------------------------------------------------------------
63 int main( int argc, char** argv )
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));*/
73 QTimer::singleShot(2000, splash, SLOT(close()));
74 while (!splash->isHidden())
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)
84 window.resize(width,height);
88 std::vector<std::string> sequence_filenames;
89 enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
90 int parse_mode=P_NORMAL;
92 std::string win(""), lev("");
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();
103 if (current=="--vf") {
104 if (!n_image_loaded) load_image_first_error();
105 window.AddField(argv[i+1],n_image_loaded-1);
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]);
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") {
124 } else if (current == "--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;
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());
136 vtkOutputWindow::SetInstance(vtk_log);
138 itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
139 itk_log->SetFileName(log_file.c_str());
141 itk::OutputWindow::SetInstance(itk_log);
143 } else if (parse_mode == P_SEQUENCE) {
144 sequence_filenames.push_back(current);
145 } else if (parse_mode == P_WINDOW) {
148 } else if (parse_mode == P_LEVEL) {
152 std::vector<std::string> image;
153 image.push_back(current);
154 window.LoadImages(image,IMAGE);
158 if (parse_mode == P_SEQUENCE) { //Finish any current sequence
159 window.LoadImages(sequence_filenames,MERGEDWITHTIME);
160 sequence_filenames.clear();
165 if(win!="" && lev!="") {
166 window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
167 window.ApplyWindowLevelToAllImages();