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