Medical Imaging Interaction Toolkit  2018.4.99-c0f884b2
Medical Imaging Interaction Toolkit
Step6.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 "Step6.h"
14 
15 #include "QmitkRenderWindow.h"
16 #include "QmitkSliceWidget.h"
17 
18 #include "mitkProperties.h"
19 #include "mitkRenderingManager.h"
20 
21 #include "mitkPointSet.h"
23 
24 #include "mitkImageAccessByItk.h"
25 
26 #include "mitkRenderingManager.h"
27 #include <mitkIOUtil.h>
28 
29 #include <QHBoxLayout>
30 #include <QLabel>
31 #include <QLineEdit>
32 #include <QPushButton>
33 #include <QPushButton>
34 #include <QVBoxLayout>
35 
36 //##Documentation
37 //## @brief Start region-grower at interactively added points
38 Step6::Step6(int argc, char *argv[], QWidget *parent) : QWidget(parent)
39 {
40  // load data as in the previous steps; a reference to the first loaded
41  // image is kept in the member m_FirstImage and used as input for the
42  // region growing
43  Load(argc, argv);
44 }
45 
47 {
48  // setup the widgets as in the previous steps, but with an additional
49  // QVBox for a button to start the segmentation
50  this->SetupWidgets();
51 
52  // Create controlsParent widget with horizontal layout
53  QWidget *controlsParent = new QWidget(this);
54  this->layout()->addWidget(controlsParent);
55 
56  QHBoxLayout *hlayout = new QHBoxLayout(controlsParent);
57  hlayout->setSpacing(2);
58 
59  QLabel *labelThresholdMin = new QLabel("Lower Threshold:", controlsParent);
60  hlayout->addWidget(labelThresholdMin);
61 
62  m_LineEditThresholdMin = new QLineEdit("-1000", controlsParent);
63  hlayout->addWidget(m_LineEditThresholdMin);
64 
65  QLabel *labelThresholdMax = new QLabel("Upper Threshold:", controlsParent);
66  hlayout->addWidget(labelThresholdMax);
67 
68  m_LineEditThresholdMax = new QLineEdit("-400", controlsParent);
69  hlayout->addWidget(m_LineEditThresholdMax);
70 
71  // create button to start the segmentation and connect its clicked()
72  // signal to method StartRegionGrowing
73  QPushButton *startButton = new QPushButton("start region growing", controlsParent);
74  hlayout->addWidget(startButton);
75 
76  connect(startButton, SIGNAL(clicked()), this, SLOT(StartRegionGrowing()));
77  if (m_FirstImage.IsNull())
78  startButton->setEnabled(false);
79 
80  // as in Step5, create PointSet (now as a member m_Seeds) and
81  // associate a interactor to it
82 
85  pointSetNode->SetData(m_Seeds);
86  pointSetNode->SetProperty("layer", mitk::IntProperty::New(2));
87  m_DataStorage->Add(pointSetNode);
88 
89  // Create PointSetDataInteractor
91  interactor->LoadStateMachine("PointSet.xml");
92  interactor->SetEventConfig("PointSetConfig.xml");
93  interactor->SetDataNode(pointSetNode);
94 }
95 
97 {
98  return m_LineEditThresholdMin->text().toInt();
99 }
100 
102 {
103  return m_LineEditThresholdMax->text().toInt();
104 }
105 
107 {
109 
111 }
112 
113 void Step6::Load(int argc, char *argv[])
114 {
115  //*************************************************************************
116  // Part I: Basic initialization
117  //*************************************************************************
118 
120 
121  //*************************************************************************
122  // Part II: Create some data by reading files
123  //*************************************************************************
124  int i;
125  for (i = 1; i < argc; ++i)
126  {
127  // For testing
128  if (strcmp(argv[i], "-testing") == 0)
129  continue;
130 
131  // Load datanode (eg. many image formats, surface formats, etc.)
132  mitk::StandaloneDataStorage::SetOfObjects::Pointer dataNodes = mitk::IOUtil::Load(argv[i], *m_DataStorage);
133 
134  if (dataNodes->empty())
135  {
136  fprintf(stderr, "Could not open file %s \n\n", argv[i]);
137  exit(2);
138  }
139 
140  mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(dataNodes->at(0)->GetData());
141  if ((m_FirstImage.IsNull()) && (image.IsNotNull()))
143  }
144 }
145 
147 {
148  //*************************************************************************
149  // Part I: Create windows and pass the datastorage to it
150  //*************************************************************************
151 
152  // Create toplevel widget with vertical layout
153  QVBoxLayout *vlayout = new QVBoxLayout(this);
154  vlayout->setMargin(0);
155  vlayout->setSpacing(2);
156 
157  // Create viewParent widget with horizontal layout
158  QWidget *viewParent = new QWidget(this);
159  vlayout->addWidget(viewParent);
160 
161  QHBoxLayout *hlayout = new QHBoxLayout(viewParent);
162  hlayout->setMargin(0);
163  hlayout->setSpacing(2);
164 
165  //*************************************************************************
166  // Part Ia: 3D view
167  //*************************************************************************
168 
169  // Create a renderwindow
170  QmitkRenderWindow *renderWindow = new QmitkRenderWindow(viewParent);
171  hlayout->addWidget(renderWindow);
172 
173  // Tell the renderwindow which (part of) the tree to render
174  renderWindow->GetRenderer()->SetDataStorage(m_DataStorage);
175 
176  // Use it as a 3D view
178 
179  // Reposition the camera to include all visible actors
180  renderWindow->GetRenderer()->GetVtkRenderer()->ResetCamera();
181 
182  //*************************************************************************
183  // Part Ib: 2D view for slicing axially
184  //*************************************************************************
185 
186  // Create QmitkSliceWidget, which is based on the class
187  // QmitkRenderWindow, but additionally provides sliders
188  QmitkSliceWidget *view2 = new QmitkSliceWidget(viewParent);
189  hlayout->addWidget(view2);
190 
191  // Tell the QmitkSliceWidget which (part of) the tree to render.
192  // By default, it slices the data axially
194  mitk::DataStorage::SetOfObjects::ConstPointer rs = m_DataStorage->GetAll();
195  view2->SetData(rs->Begin(), mitk::SliceNavigationController::Axial);
196 
197  // We want to see the position of the slice in 2D and the
198  // slice itself in 3D: add it to the tree!
200 
201  //*************************************************************************
202  // Part Ic: 2D view for slicing sagitally
203  //*************************************************************************
204 
205  // Create QmitkSliceWidget, which is based on the class
206  // QmitkRenderWindow, but additionally provides sliders
207  QmitkSliceWidget *view3 = new QmitkSliceWidget(viewParent);
208  hlayout->addWidget(view3);
209 
210  // Tell the QmitkSliceWidget which (part of) the tree to render
211  // and to slice sagitally
214 
215  // We want to see the position of the slice in 2D and the
216  // slice itself in 3D: add it to the tree!
218 
219  //*************************************************************************
220  // Part II: handle updates: To avoid unnecessary updates, we have to
221  //*************************************************************************
222  // define when to update. The RenderingManager serves this purpose, and
223  // each RenderWindow has to be registered to it.
224  /*mitk::RenderingManager *renderingManager =
225  mitk::RenderingManager::GetInstance();
226  renderingManager->AddRenderWindow( renderWindow );
227  renderingManager->AddRenderWindow( view2->GetRenderWindow() );
228  renderingManager->AddRenderWindow( view3->GetRenderWindow() );*/
229 }
230 
virtual DataNode * GetCurrentWorldPlaneGeometryNode()
Get a DataNode pointing to a data object containing the current 2D-worldgeometry. ...
vtkRenderer * GetVtkRenderer() const
Step6(int argc, char *argv[], QWidget *parent=nullptr)
Start region-grower at interactively added points.
Definition: Step6.cpp:38
void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
virtual int GetThresholdMin()
Definition: Step6.cpp:96
static Pointer New()
virtual void StartRegionGrowing()
Definition: Step6.cpp:106
void Load(int argc, char *argv[])
Definition: Step6.cpp:113
mitk::Image::Pointer m_FirstImage
Definition: Step6.h:47
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
friend void RegionGrowing(itk::Image< TPixel, VImageDimension > *itkImage, Step6 *step6)
mitk::VtkPropRenderer * GetRenderer()
static Pointer New()
static RenderingManager * GetInstance()
Image class for storing images.
Definition: mitkImage.h:72
MITK implementation of the QVTKWidget.
virtual mitk::VtkPropRenderer * GetRenderer()
virtual int GetThresholdMax()
Definition: Step6.cpp:101
QLineEdit * m_LineEditThresholdMin
Definition: Step6.h:53
mitk::Image::Pointer image
virtual void SetupWidgets()
Definition: Step6.cpp:146
mitk::PointSet::Pointer m_Seeds
Definition: Step6.h:48
void SetData(mitk::DataStorage::SetOfObjects::ConstIterator it)
static Pointer New()
void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
virtual void Initialize()
Definition: Step6.cpp:46
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
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
mitk::StandaloneDataStorage::Pointer m_DataStorage
Definition: Step6.h:46
QLineEdit * m_LineEditThresholdMax
Definition: Step6.h:54
void SetDataStorage(mitk::StandaloneDataStorage::Pointer storage)