SMILX  1.01
milxImageViewer.cpp
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 //Qt
19 #include <QApplication>
20 #include <QMainWindow>
21 
22 #include "milxQtFile.h"
23 #include "milxQtImage.h"
24 
25 int main(int argc, char *argv[])
26 {
27  QApplication app(argc,argv);
28  QMainWindow mainWindow;
29 
30  QPixmap icon(":resources/smilx_icon.png");
31  app.setWindowIcon(QIcon(icon));
32 
33  if (argc < 2)
34  {
35  cerr << "milxImageViewer Application:" << endl;
36  cerr << "For quick and fast display of image files." << endl;
37  cerr << "View configuration always matches sMILX settings wherever possible." << endl;
38  cerr << "Usage:" << endl;
39  cerr << "<Image Filename> " << endl;
40  return EXIT_FAILURE;
41  }
42 
43  std::string inputSurfaceFilename = argv[1];
44 
45  //Load the vertex table from CSV file
46  milxQtImage *image = new milxQtImage(&mainWindow); //app takes ownership so need to be on stack, not heap
47  milxQtFile *reader = new milxQtFile(&mainWindow);
48  bool success = reader->openImage(inputSurfaceFilename.c_str(), image);
49 
50  if(!success)
51  {
52  cerr << "Error opening image file." << endl;
53  return EXIT_FAILURE;
54  }
55 
56  image->generateImage();
57 
58  //Setup size
59  QSize desktopSize = qApp->desktop()->availableGeometry().size();
60  int newWidth = 2.0*desktopSize.width()/3.0 + 0.5;
61  int newHeight = 4.0*desktopSize.height()/5.0 + 0.5;
62  int xOffset = (desktopSize.width()-newWidth)/2.0;
63  int yOffset = (desktopSize.height()-newHeight)/2.0;
64  mainWindow.resize( QSize(newWidth, newHeight) );
65  mainWindow.move( QPoint(xOffset, yOffset) );
66 
67  //Setup view to match sMILX
68  QSettings settings("Shekhar Chandra", "milxQt");
69  int defaultViewMode = 2; //axial
70  int defaultOrientationTypeMode = 0; //radiological
71  image->setView(settings.value("defaultView", defaultViewMode).toInt());
72  image->setDefaultOrientation(settings.value("defaultOrientationType", defaultOrientationTypeMode).toInt());
73 
74  //Setup menu
75  QMenuBar *menuBar = new QMenuBar(&mainWindow);
76  //File
77  QMenu *menuFile = menuBar->addMenu("File");
78  image->createMenu(menuFile);
79  QAction *actionExit = menuFile->addAction("Exit");
80  QObject::connect(actionExit, SIGNAL(activated()), &mainWindow, SLOT(close()));
81  mainWindow.setMenuBar(menuBar);
82 
83  mainWindow.setWindowTitle("milxImageViewer");
84  mainWindow.setCentralWidget(image);
85  mainWindow.show();
86 
87  return app.exec();
88 }
This class represents the MILX Qt Image Display object using VTK.
Definition: milxQtImage.h:118
This class represents the MILX Qt File I/O object using VTK/ITK/Qt.
Definition: milxQtFile.h:60
virtual void createMenu(QMenu *menu)
Create the menu for the data in this object. Used for context menu and file menus.
void setView(int viewMode)
Change view to view mode identified by number. 0-axial, 1-coronal, 2-sagittal.
void generateImage(const bool quietly=false)
Assigns the array data to the image and setups up the viewer.
bool openImage(const QString filename, vtkImageData *data)
Opens an image file, which is any of the following: JPEG, PNG, DICOM, TIFF, NIFTI, HDR etc.
Definition: milxQtFile.cpp:75
int main(int argc, char *argv[])
void setDefaultOrientation(int orientMode)
Change orientation mode to one of the supported standards. Default: Radiological. ...