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 "vvReadState.h"
34 #include "vvToolsList.h"
35 #include <vtkFileOutputWindow.h>
36 #include <vtkSmartPointer.h>
37 #include <itkFileOutputWindow.h>
38 #include <itkSmartPointer.h>
39 #include <itksys/SystemTools.hxx>
41 #include <sys/types.h>
45 void load_image_first_error()
47 std::cerr << "You need to load an image before adding an overlay!" << std::endl;
51 std::string create_timed_string()
56 struct tm* pt = localtime(&t);
60 strftime(st, size, "%Y%m%d-%H%M%S", pt);
65 //------------------------------------------------------------------------------
67 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
72 int main( int argc, char** argv )
78 QApplication app( argc, argv );
79 Q_INIT_RESOURCE(vvIcons);
82 // ATTENTION: Rômulo Pinho - 05/08/2011
83 // Forcing the locale of the application is necessary
84 // because QT initialization changes it to the locale
85 // of the language of the system. This can cause
86 // inconsistencies when, e.g., reading float values
87 // from DICOM fields with gdcm, since the decimal
88 // point may be changed for a comma (as in French).
89 // In practice, functions such as scanf and its
90 // variations are directly affected.
91 // https://bugreports.qt.nokia.com//browse/QTBUG-15247?page=com.atlassian.jira.plugin.system.issuetabpanels%253Achangehistory-tabpanel
94 std::string old_locale = setlocale(LC_NUMERIC, NULL);
95 setlocale(LC_NUMERIC, "POSIX");
100 //Try to give the window a sensible default size
101 int width=QApplication::desktop()->width()*0.8;
102 int height=QApplication::desktop()->height()*0.9;
103 if (width> 1.5*height)
105 window.resize(width,height);
109 std::vector<std::string> sequence_filenames;
110 enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
111 int parse_mode=P_NORMAL;
112 int n_image_loaded=0;
113 std::string win(""), lev("");
116 for (int i = 1; i < argc; i++) {
117 std::string current = argv[i];
118 if (!current.compare(0,2,"--")) { //We are parsing an option
119 if (parse_mode == P_SEQUENCE) {//First finish the current sequence
120 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
121 sequence_filenames.clear();
124 if (current=="--vf") {
125 if (!n_image_loaded) load_image_first_error();
126 window.AddField(argv[i+1],n_image_loaded-1);
128 } else if (current=="--overlay") {
129 if (!n_image_loaded) load_image_first_error();
130 window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
131 i++; //skip overlay name
132 } else if (current=="--roi") {
133 if (!n_image_loaded) load_image_first_error();
134 window.AddROI(n_image_loaded-1,argv[i+1]);
136 } else if (current=="--fusion") {
137 if (!n_image_loaded) load_image_first_error();
138 window.AddFusionImage(n_image_loaded-1,argv[i+1]);
139 i++; //skip fusion name
140 } else if (current == "--sequence") {
141 n_image_loaded++; //count only one for the sequence
142 parse_mode=P_SEQUENCE;
143 } else if (current == "--window") {
145 } else if (current == "--level") {
147 } else if (current == "--log") {
148 std::string log_dir = QDir::tempPath().toStdString() + std::string("/vv-log");
150 if(itksys::SystemTools::FileExists(log_dir.c_str()) &&
151 !itksys::SystemTools::FileIsDirectory(log_dir.c_str())) {
152 std::cerr << "Error creating log directory, file exists and is not a directory." << std::endl;
154 } else if(!itksys::SystemTools::MakeDirectory(log_dir.c_str())) {
155 std::cerr << "Error creating log directory." << std::endl;
159 std::string log_file = log_dir + "/" + create_timed_string() + ".log";
161 itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
162 itk_log->SetFileName(log_file.c_str());
165 itk::OutputWindow::SetInstance(itk_log);
167 vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
168 vtk_log->SetFileName(log_file.c_str());
171 vtkOutputWindow::SetInstance(vtk_log);
172 } else if (current == "--state") {
173 //window.ReadSavedStateFile(argv[i+1]);
174 vvReadState read_state;
175 read_state.Run(&window, argv[i+1]);
176 n_image_loaded += read_state.GetNumberOfImages();
180 } else if (parse_mode == P_SEQUENCE) {
181 sequence_filenames.push_back(current);
182 } else if (parse_mode == P_WINDOW) {
185 } else if (parse_mode == P_LEVEL) {
189 std::vector<std::string> image;
190 image.push_back(current);
191 window.LoadImages(image, vvImageReader::IMAGE);
195 if (parse_mode == P_SEQUENCE) { //Finish any current sequence
196 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
197 sequence_filenames.clear();
202 if(win!="" && lev!="") {
203 window.SetWindowLevel(atof(win.c_str()), atof(lev.c_str()));
204 window.ApplyWindowLevelToAllImages();
208 int ret = app.exec();
211 // restoring the locale, just to be clean...
212 setlocale(LC_NUMERIC, old_locale.c_str());