Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (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 ============================================================================*/
14 #include <QBoxLayout>
15 #include <QLabel>
16 #include <mitkProperties.h>
17 
19  : QWidget(parent), m_SelfCall(false), m_lastSelection(mitk::DataNode::New()), m_lastSelectedName(tr("none"))
20 {
21  QBoxLayout *mainLayout = new QVBoxLayout(this);
22  m_segmentationComboBox = new QComboBox(this);
23  QLabel *label = new QLabel("region of interest:", this);
25 
26  mainLayout->addWidget(label);
27  mainLayout->addWidget(m_segmentationComboBox);
28  mainLayout->addWidget(m_boundingObjectWidget);
29 
30  // connect signals
31  connect(
32  m_segmentationComboBox, SIGNAL(activated(const QString &)), this, SLOT(OnRoiDataSelectionChanged(const QString &)));
33  connect(m_boundingObjectWidget, SIGNAL(BoundingObjectsChanged()), this, SLOT(OnRoiDataSelectionChanged()));
34 
35  // create ToolManager
37 
38  // setup message delegates
41 
42  mainLayout->deleteLater();
43  label->deleteLater();
44 }
45 
47 {
50 
51  m_ToolManager->GetDataStorage()->RemoveNodeEvent.RemoveListener(
54 }
55 
57 {
58  m_ToolManager->SetDataStorage(storage);
61 
64 }
65 
67 {
68  return m_ToolManager->GetDataStorage();
69 }
70 
72 {
73  // remove old messagedelegates
76  // set new toolmanager
77  m_ToolManager = &manager;
78  // add new message delegates
79  m_ToolManager->RoiDataChanged += mitk::MessageDelegate<QmitkToolRoiDataSelectionBox>(
81 }
82 
84 {
85  return m_ToolManager;
86 }
87 
89 {
90  if (m_SelfCall)
91  return;
93 }
94 
96 {
97  if (m_SelfCall)
98  return;
99 
100  if (this->GetDataStorage()->GetAll()->size() == 1)
101  {
103  }
104 }
105 
107 {
108  this->OnRoiDataSelectionChanged(tr("bounding objects"));
109 }
110 
112 {
113  if (name.compare(tr("")) == 0)
114  return;
115 
116  m_lastSelectedName = name;
118  mitk::DataNode::Pointer selection = nullptr;
119 
120  if (name.compare(tr("none")) == 0)
121  m_segmentationComboBox->setCurrentIndex(0);
122  else if (name.compare(tr("bounding objects")) == 0)
123  {
126  }
127  else
128  {
129  selection = m_ToolManager->GetDataStorage()->GetNamedNode(name.toLocal8Bit().data());
130 
131  if (m_lastSelection.IsNotNull())
132  m_lastSelection->SetProperty("outline binary", mitk::BoolProperty::New(false));
133  }
134 
135  if (selection == m_lastSelection)
136  return;
137 
138  m_lastSelection = selection;
139 
140  if (m_lastSelection.IsNotNull())
141  {
142  m_lastSelection->SetProperty("outline binary", mitk::BoolProperty::New(true));
143  m_lastSelection->SetProperty("outline width", mitk::FloatProperty::New(2.0));
144  }
145 
146  m_SelfCall = true;
147  m_ToolManager->SetRoiData(selection);
148  m_SelfCall = false;
149 }
150 
152 {
153  m_segmentationComboBox->clear();
154  m_segmentationComboBox->addItem(tr("none"));
155  m_segmentationComboBox->insertSeparator(1);
156 
157  // predicates for combobox
161  mitk::NodePredicateProperty::Pointer isHelperObject =
163  mitk::NodePredicateNot::Pointer isNotHelperObject = mitk::NodePredicateNot::New(isHelperObject);
164  mitk::NodePredicateAnd::Pointer segmentationPredicate =
165  mitk::NodePredicateAnd::New(isImage, isBinary, isNotHelperObject);
166 
167  mitk::DataStorage::SetOfObjects::ConstPointer allSegmentations =
168  m_ToolManager->GetDataStorage()->GetSubset(segmentationPredicate);
169  QStringList names;
170 
171  for (mitk::DataStorage::SetOfObjects::const_iterator it = allSegmentations->begin(); it != allSegmentations->end();
172  ++it)
173  {
174  mitk::DataNode::Pointer node = *it;
175 
176  QString name = QString::fromLocal8Bit(node->GetName().c_str());
177  names.append(name);
178  }
179  if (names.length() > 0)
180  {
181  m_segmentationComboBox->addItems(names);
182  m_segmentationComboBox->insertSeparator(names.length() + 2);
183  }
184 
185  m_segmentationComboBox->addItem(tr("bounding objects"));
186 
187  int id = m_segmentationComboBox->findText(m_lastSelectedName);
188  if (id < 0)
189  this->OnRoiDataSelectionChanged(tr("none"));
190  else
191  m_segmentationComboBox->setCurrentIndex(id);
192 }
193 
195 {
196  if (!flag)
197  this->OnRoiDataSelectionChanged(tr("none"));
198  m_segmentationComboBox->setEnabled(flag);
199 }
void SetDataStorage(mitk::DataStorage &storage)
Data management class that handles &#39;was created by&#39; 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)
static Pointer New()
static Pointer New(const mitk::NodePredicateBase *_arg)
void AddListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:374
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()
QmitkToolRoiDataSelectionBox(QWidget *parent=nullptr, mitk::DataStorage *storage=nullptr)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
static mitk::ToolManagerProvider * GetInstance()
Returns an instance of ToolManagerProvider service.
QmitkBoundingObjectWidget * m_boundingObjectWidget
Manages and coordinates instances of mitk::Tool.