Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Step5.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 
26 #include "mitkPointSet.h"
27 // NEW INCLUDE
29 
30 #include <QApplication>
31 #include <QHBoxLayout>
32 #include <itksys/SystemTools.hxx>
33 #include <mitkIOUtil.h>
34 
35 //##Documentation
36 //## @brief Interactively add points
37 //##
38 //## As in Step4, load one or more data sets (many image,
39 //## surface and other formats) and create 3 views on the data.
40 //## Additionally, we want to interactively add points. A node containing
41 //## a PointSet as data is added to the data tree and a PointSetDataInteractor
42 //## is associated with the node, which handles the interaction. The
43 //## @em interaction @em pattern is defined in a state-machine, stored in an
44 //## external XML file. Thus, we need to load a state-machine
45 //## The interaction patterns defines the @em events,
46 //## on which the interactor reacts (e.g., which mouse buttons are used to
47 //## set a point), the @em transition to the next state (e.g., the initial
48 //## may be "empty point set") and associated @a actions (e.g., add a point
49 //## at the position where the mouse-click occured).
50 int main(int argc, char *argv[])
51 {
52  QApplication qtapplication(argc, argv);
53 
54  if (argc < 2)
55  {
56  fprintf(
57  stderr, "Usage: %s [filename1] [filename2] ...\n\n", itksys::SystemTools::GetFilenameName(argv[0]).c_str());
58  return 1;
59  }
60 
61  // Register Qmitk-dependent global instances
63 
64  //*************************************************************************
65  // Part I: Basic initialization
66  //*************************************************************************
67 
68  // Create a DataStorage
70 
71  //*************************************************************************
72  // Part II: Create some data by reading files
73  //*************************************************************************
74  int i;
75  for (i = 1; i < argc; ++i)
76  {
77  // For testing
78  if (strcmp(argv[i], "-testing") == 0)
79  continue;
80 
81  // Load datanode (eg. many image formats, surface formats, etc.)
83 
84  //*********************************************************************
85  // Part III: Put the data into the datastorage
86  //*********************************************************************
87  // Add the node to the DataStorage
88  if (dataNodes->empty())
89  {
90  fprintf(stderr, "Could not open file %s \n\n", argv[i]);
91  exit(2);
92  }
93  }
94 
95  //*************************************************************************
96  // Part V: Create windows and pass the tree to it
97  //*************************************************************************
98 
99  // Create toplevel widget with horizontal layout
100  QWidget toplevelWidget;
101  QHBoxLayout layout;
102  layout.setSpacing(2);
103  layout.setMargin(0);
104  toplevelWidget.setLayout(&layout);
105 
106  //*************************************************************************
107  // Part Va: 3D view
108  //*************************************************************************
109 
110  // Create a renderwindow
111  QmitkRenderWindow renderWindow(&toplevelWidget);
112  layout.addWidget(&renderWindow);
113 
114  // Tell the renderwindow which (part of) the tree to render
115 
116  renderWindow.GetRenderer()->SetDataStorage(ds);
117 
118  // Use it as a 3D view
120 
121  // Reposition the camera to include all visible actors
122  renderWindow.GetRenderer()->GetVtkRenderer()->ResetCamera();
123 
124  //*************************************************************************
125  // Part Vb: 2D view for slicing axially
126  //*************************************************************************
127 
128  // Create QmitkSliceWidget, which is based on the class
129  // QmitkRenderWindow, but additionally provides sliders
130  QmitkSliceWidget view2(&toplevelWidget);
131  layout.addWidget(&view2);
132 
133  // Tell the QmitkSliceWidget which (part of) the tree to render.
134  // By default, it slices the data axially
135  view2.SetDataStorage(ds);
138  // We want to see the position of the slice in 2D and the
139  // slice itself in 3D: add it to the tree!
140  ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode());
141 
142  //*************************************************************************
143  // Part Vc: 2D view for slicing sagitally
144  //*************************************************************************
145 
146  // Create QmitkSliceWidget, which is based on the class
147  // QmitkRenderWindow, but additionally provides sliders
148  QmitkSliceWidget view3(&toplevelWidget);
149  layout.addWidget(&view3);
150 
151  // Tell the QmitkSliceWidget which (part of) the tree to render
152  // and to slice sagitall
153  view3.SetDataStorage(ds);
155 
156  // We want to see the position of the slice in 2D and the
157  // slice itself in 3D: add it to the tree!
158  ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode());
159 
160  // *******************************************************
161  // ****************** START OF NEW PART ******************
162  // *******************************************************
163 
164  //*************************************************************************
165  // Part VI: For allowing to interactively add points ...
166  //*************************************************************************
167 
168  // ATTENTION: It is very important that the renderer already know their DataStorage,
169  // because registerig DataInteractors with the render windows is done automatically
170  // and only works if the BaseRenderer and the DataStorage know each other.
171 
172  // Create PointSet and a node for it
175  // Store the point set in the DataNode
176  pointSetNode->SetData(pointSet);
177 
178  // Add the node to the tree
179  ds->Add(pointSetNode);
180 
181  // Create PointSetDataInteractor
183  // Set the StateMachine pattern that describes the flow of the interactions
184  interactor->LoadStateMachine("PointSet.xml");
185  // Set the configuration file, which describes the user interactions that trigger actions
186  // in this file SHIFT + LeftClick triggers add Point, but by modifying this file,
187  // it could as well be changes to any other user interaction.
188  interactor->SetEventConfig("PointSetConfig.xml");
189 
190  // Assign the pointSetNode to the interactor,
191  // alternatively one could also add the DataInteractor to the pointSetNode using the SetDataInteractor() method.
192  interactor->SetDataNode(pointSetNode);
193 
194  // *******************************************************
195  // ******************* END OF NEW PART *******************
196  // *******************************************************
197 
198  //*************************************************************************
199  // Part VII: Qt-specific initialization
200  //*************************************************************************
201  toplevelWidget.show();
202 
203 // For testing
204 #include "QtTesting.h"
205  if (strcmp(argv[argc - 1], "-testing") != 0)
206  return qtapplication.exec();
207  else
208  return QtTesting();
209 }
itk::SmartPointer< Self > Pointer
DataNode * GetCurrentWorldGeometry2DNode()
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
int main(int argc, char *argv[])
Interactively add points.
Definition: Step5.cpp:50
static Pointer New()
MITKQTWIDGETS_EXPORT void QmitkRegisterClasses()
Tests for type compatibility (dynamic_cast).
itk::SmartPointer< const Self > ConstPointer
mitk::VtkPropRenderer * GetRenderer()
static Pointer New()
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)