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 "vvConfiguration.h"
37 #include <vtkFileOutputWindow.h>
38 #include <vtkSmartPointer.h>
40 #include <itkFileOutputWindow.h>
41 #include <itkSmartPointer.h>
42 #include <itksys/SystemTools.hxx>
44 #include <sys/types.h>
48 void load_image_first_error()
50 std::cerr << "You need to load an image before adding an overlay!" << std::endl;
54 std::string create_timed_string()
59 struct tm* pt = localtime(&t);
63 strftime(st, size, "%Y%m%d-%H%M%S", pt);
68 //------------------------------------------------------------------------------
70 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
75 int main( int argc, char** argv )
81 QApplication app( argc, argv );
82 Q_INIT_RESOURCE(vvIcons);
85 // ATTENTION: Rômulo Pinho - 05/08/2011
86 // Forcing the locale of the application is necessary
87 // because QT initialization changes it to the locale
88 // of the language of the system. This can cause
89 // inconsistencies when, e.g., reading float values
90 // from DICOM fields with gdcm, since the decimal
91 // point may be changed for a comma (as in French).
92 // In practice, functions such as scanf and its
93 // variations are directly affected.
94 // https://bugreports.qt.nokia.com//browse/QTBUG-15247?page=com.atlassian.jira.plugin.system.issuetabpanels%253Achangehistory-tabpanel
97 std::string old_locale = setlocale(LC_NUMERIC, NULL);
98 setlocale(LC_NUMERIC, "POSIX");
103 //Try to give the window a sensible default size
104 int width=QApplication::desktop()->width()*0.8;
105 int height=QApplication::desktop()->height()*0.9;
106 if (width> 1.5*height)
108 window.resize(width,height);
112 std::vector<std::string> sequence_filenames;
113 enum {P_NORMAL,P_SEQUENCE,P_WINDOW,P_LEVEL};
114 int parse_mode=P_NORMAL;
115 int n_image_loaded=0;
116 std::string win(""), lev("");
118 bool link_images = false;
120 for (int i = 1; i < argc; i++) {
121 std::string current = argv[i];
122 if (!current.compare(0,2,"-h")) {
125 if (!current.compare(0,2,"--")) { //We are parsing an option
126 if (parse_mode == P_SEQUENCE) {//First finish the current sequence
127 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
128 sequence_filenames.clear();
131 if ((current=="--help") || (current=="-h")) {
132 std::cout << "vv " << VV_VERSION << ", the 2D, 2D+t, 3D and 3D+t (or 4D) image viewer" << std::endl << std::endl
133 << "Synopsis: vv file(s) [OPTIONS] file(s)" << std::endl << std::endl
134 << "Open file(s) for visualization." << std::endl << std::endl
135 << "OPTIONS may be:" << std::endl
136 << "--help \t Print command line help and exit." << std::endl
137 << "--window number\t Gray scale window width for all images." << std::endl
138 << "--level number \t Gray scale window level for all images." << std::endl
139 << "--linkall \t Link pan, zoom and spatial position of crosshair in images." << std::endl
140 << "--log \t Log output messages in vv-log directory." << std::endl
141 << "--state file \t Read display parameters from file." << std::endl
142 << "--sequence file\t Read all file(s) until next option in a single temporal sequence." << std::endl
144 << "These last options must follow a file name since they overlay something on an image:" << std::endl
145 << "--vf file \t Overlay the vector field in file." << std::endl
146 << "--overlay file \t Overlay the image in file with complementary colors." << std::endl
147 << "--fusion file \t Overlay the image in file with alpha blending and colormap." << std::endl
148 //<< "--roi file \t Overlay binary mask images. Option may be repeated on a single base image." << std::endl
149 << "--contour file \t Overlay DICOM RT-STRUCT contours." << std::endl;
152 if (current=="--vf") {
153 if (!n_image_loaded) load_image_first_error();
154 window.AddField(argv[i+1],n_image_loaded-1);
156 } else if (current=="--overlay") {
157 if (!n_image_loaded) load_image_first_error();
158 window.AddOverlayImage(n_image_loaded-1,argv[i+1]);
159 i++; //skip overlay name
160 } /*else if (current=="--roi") {
161 if (!n_image_loaded) load_image_first_error();
162 window.AddROI(n_image_loaded-1,argv[i+1]);
164 }*/ else if (current=="--contour") {
165 if (!n_image_loaded) load_image_first_error();
166 window.AddDCStructContour(n_image_loaded-1,argv[i+1]);
168 } else if (current=="--fusion") {
169 if (!n_image_loaded) load_image_first_error();
170 window.AddFusionImage(n_image_loaded-1,argv[i+1]);
171 i++; //skip fusion name
172 } else if (current == "--sequence") {
173 n_image_loaded++; //count only one for the sequence
174 parse_mode=P_SEQUENCE;
175 } else if (current == "--window") {
177 } else if (current == "--level") {
179 } else if (current == "--linkall") {
182 else if (current == "--log") {
183 std::string log_dir = QDir::tempPath().toStdString() + std::string("/vv-log");
185 if(itksys::SystemTools::FileExists(log_dir.c_str()) &&
186 !itksys::SystemTools::FileIsDirectory(log_dir.c_str())) {
187 std::cerr << "Error creating log directory, file exists and is not a directory." << std::endl;
189 } else if(!itksys::SystemTools::MakeDirectory(log_dir.c_str())) {
190 std::cerr << "Error creating log directory." << std::endl;
194 std::string log_file = log_dir + "/" + create_timed_string() + ".log";
196 itk::SmartPointer<itk::FileOutputWindow> itk_log = itk::FileOutputWindow::New();
197 itk_log->SetFileName(log_file.c_str());
200 itk::OutputWindow::SetInstance(itk_log);
202 vtkSmartPointer<vtkFileOutputWindow> vtk_log = vtkFileOutputWindow::New();
203 vtk_log->SetFileName(log_file.c_str());
206 vtkOutputWindow::SetInstance(vtk_log);
207 } else if (current == "--state") {
208 //window.ReadSavedStateFile(argv[i+1]);
209 vvReadState read_state;
210 read_state.Run(&window, argv[i+1]);
211 n_image_loaded += read_state.GetNumberOfImages();
215 } else if (parse_mode == P_SEQUENCE) {
216 sequence_filenames.push_back(current);
217 } else if (parse_mode == P_WINDOW) {
220 } else if (parse_mode == P_LEVEL) {
224 std::vector<std::string> image;
225 image.push_back(current);
226 window.LoadImages(image, vvImageReader::IMAGE);
230 if (parse_mode == P_SEQUENCE) { //Finish any current sequence
231 window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME);
232 sequence_filenames.clear();
237 if(win!="" && lev!="") {
238 window.SetWindowLevel(atof(win.c_str()), atof(lev.c_str()));
239 window.ApplyWindowLevelToAllImages();
243 window.LinkAllImages();
245 int ret = app.exec();
248 // restoring the locale, just to be clean...
249 setlocale(LC_NUMERIC, old_locale.c_str());