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://www.centreleonberard.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 ===========================================================================**/
24 #include <QApplication>
26 #include <QSplashScreen>
28 #include <QDesktopWidget>
32 #include "vvMainWindow.h"
33 #include <vtkFileOutputWindow.h>
34 #include <vtkSmartPointer.h>
35 #include <itkFileOutputWindow.h>
36 #include <itkSmartPointer.h>
37 #include <itksys/SystemTools.hxx>
39 #include <sys/types.h>
43 void load_image_first_error()
45 std::cerr << "You need to load an image before adding an overlay!" << std::endl;
49 std::string create_timed_string()
54 struct tm* pt = localtime(&t);
58 strftime(st, size, "%Y%m%d-%H%M%S", pt);
63 //------------------------------------------------------------------------------
65 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
70 int main( int argc, char** argv )
76 QApplication app( argc, argv );
77 Q_INIT_RESOURCE(vvIcons);
81 //Try to give the window a sensible default size
82 int width=QApplication::desktop()->width()*0.8;
83 int height=QApplication::desktop()->height()*0.9;
84 if (width> 1.5*height)
86 window.resize(width,height);
90 std::vector<std::string> sequence_filenames;
91 enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
92 int parse_mode=P_NORMAL;
94 std::string win(""), lev("");
97 for (int i = 1; i < argc; i++) {
98 std::string current = argv[i];
99 if (!current.compare(0,2,"--")) { //We are parsing an option
100 if (parse_mode == P_SEQUENCE) {//First finish the current sequence
101 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
102 sequence_filenames.clear();
105 if (current=="--vf") {
106 if (!n_image_loaded) load_image_first_error();
107 window.AddField(argv[i+1],n_image_loaded-1);
109 } else if (current=="--overlay") {
110 if (!n_image_loaded) load_image_first_error();
111 window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
112 i++; //skip overlay name
113 } else if (current=="--roi") {
114 if (!n_image_loaded) load_image_first_error();
115 window.AddROI(n_image_loaded-1,argv[i+1]);
117 } else if (current=="--fusion") {
118 if (!n_image_loaded) load_image_first_error();
119 window.AddFusionImage(n_image_loaded-1,argv[i+1]);
120 i++; //skip fusion name
121 } else if (current == "--sequence") {
122 n_image_loaded++; //count only one for the sequence
123 parse_mode=P_SEQUENCE;
124 } else if (current == "--window") {
126 } else if (current == "--level") {
128 } else if (current == "--log") {
129 std::string log_dir = QDir::tempPath().toStdString() + std::string("/vv-log");
131 if(itksys::SystemTools::FileExists(log_dir.c_str()) &&
132 !itksys::SystemTools::FileIsDirectory(log_dir.c_str())) {
133 std::cerr << "Error creating log directory, file exists and is not a directory." << std::endl;
135 } else if(!itksys::SystemTools::MakeDirectory(log_dir.c_str())) {
136 std::cerr << "Error creating log directory." << std::endl;
140 std::string log_file = log_dir + "/" + create_timed_string() + ".log";
142 itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
143 itk_log->SetFileName(log_file.c_str());
146 itk::OutputWindow::SetInstance(itk_log);
148 vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
149 vtk_log->SetFileName(log_file.c_str());
152 vtkOutputWindow::SetInstance(vtk_log);
154 } else if (parse_mode == P_SEQUENCE) {
155 sequence_filenames.push_back(current);
156 } else if (parse_mode == P_WINDOW) {
159 } else if (parse_mode == P_LEVEL) {
163 std::vector<std::string> image;
164 image.push_back(current);
165 window.LoadImages(image, vvImageReader::IMAGE);
169 if (parse_mode == P_SEQUENCE) { //Finish any current sequence
170 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
171 sequence_filenames.clear();
176 if(win!="" && lev!="") {
177 window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
178 window.ApplyWindowLevelToAllImages();