Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkToolRoiDataSelectionBox.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 ===================================================================*/
18 #include <QBoxLayout>
19 #include <QLabel>
20 #include <mitkProperties.h>
21 
23  : QWidget(parent), m_SelfCall(false), m_lastSelection(mitk::DataNode::New()), m_lastSelectedName(tr("none"))
24 {
25  QBoxLayout *mainLayout = new QVBoxLayout(this);
26  m_segmentationComboBox = new QComboBox(this);
27  QLabel *label = new QLabel("region of interest:", this);
29 
30  mainLayout->addWidget(label);
31  mainLayout->addWidget(m_segmentationComboBox);
32  mainLayout->addWidget(m_boundingObjectWidget);
33 
34  // connect signals
35  connect(
36  m_segmentationComboBox, SIGNAL(activated(const QString &)), this, SLOT(OnRoiDataSelectionChanged(const QString &)));
37  connect(m_boundingObjectWidget, SIGNAL(BoundingObjectsChanged()), this, SLOT(OnRoiDataSelectionChanged()));
38 
39  // create ToolManager
41 
42  // setup message delegates
45 
46  mainLayout->deleteLater();
47  label->deleteLater();
48 }
49 
51 {
54 
55  m_ToolManager->GetDataStorage()->RemoveNodeEvent.RemoveListener(
58 }
59 
61 {
62  m_ToolManager->SetDataStorage(storage);
65 
68 }
69 
71 {
72  return m_ToolManager->GetDataStorage();
73 }
74 
76 {
77  // remove old messagedelegates
80  // set new toolmanager
81  m_ToolManager = &manager;
82  // add new message delegates
83  m_ToolManager->RoiDataChanged += mitk::MessageDelegate<QmitkToolRoiDataSelectionBox>(
85 }
86 
88 {
89  return m_ToolManager;
90 }
91 
93 {
94  if (m_SelfCall)
95  return;
97 }
98 
100 {
101  if (m_SelfCall)
102  return;
103 
104  if (this->GetDataStorage()->GetAll()->size() == 1)
105  {
107  }
108 }
109 
111 {
112  this->OnRoiDataSelectionChanged(tr("bounding objects"));
113 }
114 
116 {
117  if (name.compare(tr("")) == 0)
118  return;
119 
120  m_lastSelectedName = name;
122  mitk::DataNode::Pointer selection = NULL;
123 
124  if (name.compare(tr("none")) == 0)
125  m_segmentationComboBox->setCurrentIndex(0);
126  else if (name.compare(tr("bounding objects")) == 0)
127  {
130  }
131  else
132  {
133  selection = m_ToolManager->GetDataStorage()->GetNamedNode(name.toLocal8Bit().data());
134 
135  if (m_lastSelection.IsNotNull())
136  m_lastSelection->SetProperty("outline binary", mitk::BoolProperty::New(false));
137  }
138 
139  if (selection == m_lastSelection)
140  return;
141 
142  m_lastSelection = selection;
143 
144  if (m_lastSelection.IsNotNull())
145  {
146  m_lastSelection->SetProperty("outline binary", mitk::BoolProperty::New(true));
147  m_lastSelection->SetProperty("outline width", mitk::FloatProperty::New(2.0));
148  }
149 
150  m_SelfCall = true;
151  m_ToolManager->SetRoiData(selection);
152  m_SelfCall = false;
153 }
154 
156 {
157  m_segmentationComboBox->clear();
158  m_segmentationComboBox->addItem(tr("none"));
159  m_segmentationComboBox->insertSeparator(1);
160 
161  // predicates for combobox
165  mitk::NodePredicateProperty::Pointer isHelperObject =
167  mitk::NodePredicateNot::Pointer isNotHelperObject = mitk::NodePredicateNot::New(isHelperObject);
168  mitk::NodePredicateAnd::Pointer segmentationPredicate =
169  mitk::NodePredicateAnd::New(isImage, isBinary, isNotHelperObject);
170 
172  m_ToolManager->GetDataStorage()->GetSubset(segmentationPredicate);
173  QStringList names;
174 
175  for (mitk::DataStorage::SetOfObjects::const_iterator it = allSegmentations->begin(); it != allSegmentations->end();
176  ++it)
177  {
178  mitk::DataNode::Pointer node = *it;
179 
180  QString name = QString::fromLocal8Bit(node->GetName().c_str());
181  names.append(name);
182  }
183  if (names.length() > 0)
184  {
185  m_segmentationComboBox->addItems(names);
186  m_segmentationComboBox->insertSeparator(names.length() + 2);
187  }
188 
189  m_segmentationComboBox->addItem(tr("bounding objects"));
190 
191  int id = m_segmentationComboBox->findText(m_lastSelectedName);
192  if (id < 0)
193  this->OnRoiDataSelectionChanged(tr("none"));
194  else
195  m_segmentationComboBox->setCurrentIndex(id);
196 }
197 
199 {
200  if (!flag)
201  this->OnRoiDataSelectionChanged(tr("none"));
202  m_segmentationComboBox->setEnabled(flag);
203 }
void AddListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:378
void SetDataStorage(mitk::DataStorage &storage)
Data management class that handles 'was created by' relations.
static Pointer New()
void DataStorageChanged(const mitk::DataNode *node)
DataCollection - Class to facilitate loading/accessing structured data.
virtual mitk::ToolManager * GetToolManager()
Returns ToolManager object.
void SetToolManager(mitk::ToolManager &manager)
itk::SmartPointer< const Self > ConstPointer
static Pointer New()
QmitkToolRoiDataSelectionBox(QWidget *parent=0, mitk::DataStorage *storage=0)
static Pointer New(const mitk::NodePredicateBase *_arg)
static Pointer New(const char *_arg)
static Pointer New()
static Pointer New(const char *_arg)
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
mitk::ToolManager::Pointer m_ToolManager
void SetDataStorage(mitk::DataStorage *dataStorage)
mitk::DataNode::Pointer GetAllBoundingObjects()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static mitk::ToolManagerProvider * GetInstance()
Returns an instance of ToolManagerProvider service.
QmitkBoundingObjectWidget * m_boundingObjectWidget
Manages and coordinates instances of mitk::Tool.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.