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 "vvToolsList.h"
34 #include <vtkFileOutputWindow.h>
35 #include <vtkSmartPointer.h>
36 #include <itkFileOutputWindow.h>
37 #include <itkSmartPointer.h>
38 #include <itksys/SystemTools.hxx>
40 #include <sys/types.h>
44 void load_image_first_error()
46 std::cerr << "You need to load an image before adding an overlay!" << std::endl;
50 std::string create_timed_string()
55 struct tm* pt = localtime(&t);
59 strftime(st, size, "%Y%m%d-%H%M%S", pt);
64 //------------------------------------------------------------------------------
66 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
71 int main( int argc, char** argv )
77 QApplication app( argc, argv );
78 Q_INIT_RESOURCE(vvIcons);
82 //Try to give the window a sensible default size
83 int width=QApplication::desktop()->width()*0.8;
84 int height=QApplication::desktop()->height()*0.9;
85 if (width> 1.5*height)
87 window.resize(width,height);
91 std::vector<std::string> sequence_filenames;
92 enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
93 int parse_mode=P_NORMAL;
95 std::string win(""), lev("");
98 for (int i = 1; i < argc; i++) {
99 std::string current = argv[i];
100 if (!current.compare(0,2,"--")) { //We are parsing an option
101 if (parse_mode == P_SEQUENCE) {//First finish the current sequence
102 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
103 sequence_filenames.clear();
106 if (current=="--vf") {
107 if (!n_image_loaded) load_image_first_error();
108 window.AddField(argv[i+1],n_image_loaded-1);
110 } else if (current=="--overlay") {
111 if (!n_image_loaded) load_image_first_error();
112 window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
113 i++; //skip overlay name
114 } else if (current=="--roi") {
115 if (!n_image_loaded) load_image_first_error();
116 window.AddROI(n_image_loaded-1,argv[i+1]);
118 } else if (current=="--fusion") {
119 if (!n_image_loaded) load_image_first_error();
120 window.AddFusionImage(n_image_loaded-1,argv[i+1]);
121 i++; //skip fusion name
122 } else if (current == "--sequence") {
123 n_image_loaded++; //count only one for the sequence
124 parse_mode=P_SEQUENCE;
125 } else if (current == "--window") {
127 } else if (current == "--level") {
129 } else if (current == "--log") {
130 std::string log_dir = QDir::tempPath().toStdString() + std::string("/vv-log");
132 if(itksys::SystemTools::FileExists(log_dir.c_str()) &&
133 !itksys::SystemTools::FileIsDirectory(log_dir.c_str())) {
134 std::cerr << "Error creating log directory, file exists and is not a directory." << std::endl;
136 } else if(!itksys::SystemTools::MakeDirectory(log_dir.c_str())) {
137 std::cerr << "Error creating log directory." << std::endl;
141 std::string log_file = log_dir + "/" + create_timed_string() + ".log";
143 itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
144 itk_log->SetFileName(log_file.c_str());
147 itk::OutputWindow::SetInstance(itk_log);
149 vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
150 vtk_log->SetFileName(log_file.c_str());
153 vtkOutputWindow::SetInstance(vtk_log);
155 } else if (parse_mode == P_SEQUENCE) {
156 sequence_filenames.push_back(current);
157 } else if (parse_mode == P_WINDOW) {
160 } else if (parse_mode == P_LEVEL) {
164 std::vector<std::string> image;
165 image.push_back(current);
166 window.LoadImages(image, vvImageReader::IMAGE);
170 if (parse_mode == P_SEQUENCE) { //Finish any current sequence
171 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
172 sequence_filenames.clear();
177 if(win!="" && lev!="") {
178 window.WindowLevelChanged(atof(win.c_str()), atof(lev.c_str()), 6, 0);
179 window.ApplyWindowLevelToAllImages();