]> Creatis software - clitk.git/blob - vv/vv.cxx
a hopefully better option parser for vv
[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};
64   int parse_mode=P_NORMAL;
65   int n_image_loaded=0;
66
67   if (argc >1) {
68     for (int i = 1; i < argc; i++) {
69       std::string current = argv[i];
70       if (!current.compare(0,2,"--")) { //We are parsing an option
71         if (parse_mode == P_SEQUENCE) {//First finish the current sequence
72           window.LoadImages(sequence_filenames,MERGEDWITHTIME);
73           sequence_filenames.clear();
74           parse_mode=P_NORMAL;
75         }
76         if (current=="--vf") {
77           if (!n_image_loaded) load_image_first_error();
78           window.AddField(argv[i+1],n_image_loaded-1);
79           i++; //skip vf name
80         } 
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           } 
86         else if (current=="--roi") {
87             if (!n_image_loaded) load_image_first_error();
88             window.AddROI(n_image_loaded-1,argv[i+1]);
89             i++; //skip roi name
90           } 
91         else if (current == "--sequence") {
92           n_image_loaded++; //count only one for the sequence
93           parse_mode=P_SEQUENCE; }
94       }
95       else if (parse_mode == P_SEQUENCE)
96         sequence_filenames.push_back(current);
97       else {
98         DD(current);
99         std::vector<std::string> image; image.push_back(current);
100         window.LoadImages(image,IMAGE);
101         n_image_loaded++;
102       }
103     }
104     if (parse_mode == P_SEQUENCE) {//Finish any current sequence
105       window.LoadImages(sequence_filenames,MERGEDWITHTIME);
106       sequence_filenames.clear();
107       parse_mode=P_NORMAL;
108     }
109
110   }
111
112   return app.exec();
113 }