Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
Step4.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkRegisterClasses.h"
18 #include "QmitkRenderWindow.h"
19 #include "QmitkSliceWidget.h"
20 
22 #include "mitkProperties.h"
23 #include "mitkRenderingManager.h"
25 #include <mitkIOUtil.h>
26 
27 #include <QApplication>
28 #include <QHBoxLayout>
29 #include <itksys/SystemTools.hxx>
30 #include <mitkImage.h>
31 
32 //##Documentation
33 //## @brief Use several views to explore data
34 //##
35 //## As in Step2 and Step3, load one or more data sets (many image,
36 //## surface and other formats), but create 3 views on the data.
37 //## The QmitkRenderWindow is used for displaying a 3D view as in Step3,
38 //## but without volume-rendering.
39 //## Furthermore, we create two 2D views for slicing through the data.
40 //## We use the class QmitkSliceWidget, which is based on the class
41 //## QmitkRenderWindow, but additionally provides sliders
42 //## to slice through the data. We create two instances of
43 //## QmitkSliceWidget, one for axial and one for sagittal slicing.
44 //## The two slices are also shown at their correct position in 3D as
45 //## well as intersection-line, each in the other 2D view.
46 int main(int argc, char *argv[])
47 {
48  QApplication qtapplication(argc, argv);
49 
50  if (argc < 2)
51  {
52  fprintf(
53  stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str());
54  return 1;
55  }
56 
57  // Register Qmitk-dependent global instances
59 
60  //*************************************************************************
61  // Part I: Basic initialization
62  //*************************************************************************
63 
64  // Create a DataStorage
66 
67  //*************************************************************************
68  // Part II: Create some data by reading files
69  //*************************************************************************
70  int i;
71  for (i = 1; i < argc; ++i)
72  {
73  // For testing
74  if (strcmp(argv[i], "-testing") == 0)
75  continue;
76 
77  //*********************************************************************
78  // Part III: Put the data into the datastorage
79  //*********************************************************************
80  // Load datanode (eg. many image formats, surface formats, etc.)
81  mitk::IOUtil::Load(argv[i], *ds);
82  }
83 
84  //*************************************************************************
85  // Part IV: Create windows and pass the tree to it
86  //*************************************************************************
87 
88  // Create toplevel widget with horizontal layout
89  QWidget toplevelWidget;
90  QHBoxLayout layout;
91  layout.setSpacing(2);
92  layout.setMargin(0);
93  toplevelWidget.setLayout(&layout);
94 
95  //*************************************************************************
96  // Part IVa: 3D view
97  //*************************************************************************
98 
99  // Create a renderwindow
100  QmitkRenderWindow renderWindow(&toplevelWidget);
101  layout.addWidget(&renderWindow);
102 
103  // Tell the renderwindow which (part of) the datastorage to render
104  renderWindow.GetRenderer()->SetDataStorage(ds);
105 
106  // Use it as a 3D view
108 
109  // Reposition the camera to include all visible actors
110  renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera();
111 
112  // *******************************************************
113  // ****************** START OF NEW PART ******************
114  // *******************************************************
115 
116  //*************************************************************************
117  // Part IVb: 2D view for slicing axially
118  //*************************************************************************
119 
120  // Create QmitkSliceWidget, which is based on the class
121  // QmitkRenderWindow, but additionally provides sliders
122  QmitkSliceWidget view2(&toplevelWidget);
123  layout.addWidget(&view2);
124  view2.SetLevelWindowEnabled(true);
125  // Tell the QmitkSliceWidget which (part of) the tree to render.
126  // By default, it slices the data axially
127  view2.SetDataStorage(ds);
128 
129  // Get the image from the data storage. A predicate (mitk::NodePredicateBase)
130  // is used to get only nodes of the type mitk::Image.
132 
134  // We want to see the position of the slice in 2D and the
135  // slice itself in 3D: add it to the datastorage!
136  ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode());
137 
138  //*************************************************************************
139  // Part IVc: 2D view for slicing sagitally
140  //*************************************************************************
141 
142  // Create QmitkSliceWidget, which is based on the class
143  // QmitkRenderWindow, but additionally provides sliders
144  QmitkSliceWidget view3(&toplevelWidget);
145  layout.addWidget(&view3);
146  view3.SetDataStorage(ds);
147  // Tell the QmitkSliceWidget which (part of) the datastorage to render
148  // and to slice sagitally
150  // We want to see the position of the slice in 2D and the
151  // slice itself in 3D: add it to the datastorage!
152  ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode());
153 
154  // *******************************************************
155  // ******************* END OF NEW PART *******************
156  // *******************************************************
157 
158  //*************************************************************************
159  // Part V: Qt-specific initialization
160  //*************************************************************************
161  toplevelWidget.show();
162 
163 // for testing
164 #include "QtTesting.h"
165  if (strcmp(argv[argc - 1], "-testing") != 0)
166  return qtapplication.exec();
167  else
168  return QtTesting();
169 }
170 
DataNode * GetCurrentWorldGeometry2DNode()
int main(int argc, char *argv[])
Use several views to explore data.
Definition: Step4.cpp:46
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
MITKQTWIDGETS_EXPORT void QmitkRegisterClasses()
Tests for type compatibility (dynamic_cast).
itk::SmartPointer< const Self > ConstPointer
mitk::VtkPropRenderer * GetRenderer()
void SetLevelWindowEnabled(bool enable)
MITK implementation of the QVTKWidget.
virtual mitk::VtkPropRenderer * GetRenderer()
void SetData(mitk::DataStorage::SetOfObjects::ConstIterator it)
virtual void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
int QtTesting()
Definition: QtTesting.cpp:22
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
vtkRenderer * GetVtkRenderer() const
void SetDataStorage(mitk::StandaloneDataStorage::Pointer storage)