]> Creatis software - clitk.git/blob - vv/vv.cxx
Command line options --window --level. Both are required to be accounted for.
[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 <QApplication>
21 #include <QPixmap>
22 #include <QSplashScreen>
23 #include <QTimer>
24 #include <QDesktopWidget>
25
26 #include "clitkIO.h"
27 #include "vvMainWindow.h"
28 #include "vvConstants.h"
29
30 void load_image_first_error()
31 {
32   std::cerr << "You need to load an image before adding an overlay!" << std::endl;
33   exit(1);
34 }
35
36 //------------------------------------------------------------------------------
37 int main( int argc, char** argv )
38 {
39   CLITK_INIT;
40
41   QApplication app( argc, argv );
42   Q_INIT_RESOURCE(vvIcons);
43   //QPixmap pixmap(":/splashscreen.PNG");
44   QSplashScreen *splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/new/prefix1/splashscreen.PNG")));
45   /*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));*/
46   //  splash->show();
47   QTimer::singleShot(2000, splash, SLOT(close()));
48   while (!splash->isHidden())
49     app.processEvents();
50
51   vvMainWindow window;
52
53   //Try to give the window a sensible default size
54   int width=QApplication::desktop()->width()*0.8;
55   int height=QApplication::desktop()->height()*0.9;
56   if (width> 1.5*height)
57     width=1.5*height;
58   window.resize(width,height);
59
60   window.show();
61
62   std::vector<std::string> sequence_filenames;
63   enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
64   int parse_mode=P_NORMAL;
65   int n_image_loaded=0;
66   std::string win(""), lev("");
67
68   if (argc >1) {
69     for (int i = 1; i < argc; i++) {
70       std::string current = argv[i];
71       if (!current.compare(0,2,"--")) { //We are parsing an option
72         if (parse_mode == P_SEQUENCE) {//First finish the current sequence
73           window.LoadImages(sequence_filenames,MERGEDWITHTIME);
74           sequence_filenames.clear();
75           parse_mode=P_NORMAL;
76         }
77         if (current=="--vf") {
78           if (!n_image_loaded) load_image_first_error();
79           window.AddField(argv[i+1],n_image_loaded-1);
80           i++; //skip vf name
81         } else if (current=="--overlay") {
82           if (!n_image_loaded) load_image_first_error();
83           window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
84           i++; //skip overlay name
85         } else if (current=="--roi") {
86           if (!n_image_loaded) load_image_first_error();
87           window.AddROI(n_image_loaded-1,argv[i+1]);
88           i++; //skip roi name
89         } else if (current=="--fusion") {
90           if (!n_image_loaded) load_image_first_error();
91           window.AddFusionImage(n_image_loaded-1,argv[i+1]);
92           i++; //skip fusion name
93         } else if (current == "--sequence") {
94           n_image_loaded++; //count only one for the sequence
95           parse_mode=P_SEQUENCE;
96         } else if (current == "--window") {
97           parse_mode=P_WINDOW;
98         } else if (current == "--level") {
99           parse_mode=P_LEVEL;
100         }
101       } else if (parse_mode == P_SEQUENCE) {
102         sequence_filenames.push_back(current);
103       } else if (parse_mode == P_WINDOW) {
104         win=current;
105         parse_mode=P_NORMAL;
106       } else if (parse_mode == P_LEVEL) {
107         lev=current;
108         parse_mode=P_NORMAL;
109       } else {
110         std::vector<std::string> image;
111         image.push_back(current);
112         window.LoadImages(image,IMAGE);
113         n_image_loaded++;
114       }
115     }
116     if (parse_mode == P_SEQUENCE) { //Finish any current sequence
117       window.LoadImages(sequence_filenames,MERGEDWITHTIME);
118       sequence_filenames.clear();
119       parse_mode=P_NORMAL;
120     }
121   }
122
123   if(win!="" && lev!="") {
124     window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
125     window.ApplyWindowLevelToAllImages();
126   }
127
128   return app.exec();
129 }