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