Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkPointListViewWidget.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 
14 
15 #include "QmitkEditPointDialog.h"
16 #include "QmitkPointListModel.h"
17 #include "QmitkStdMultiWidget.h"
18 
19 #include "mitkInteractionConst.h"
20 #include "mitkPointOperation.h"
21 #include "mitkRenderingManager.h"
22 
23 #include <QKeyEvent>
24 
26  : QListWidget(parent), m_TimeStep(0), m_SelfCall(false), m_MultiWidget(nullptr)
27 {
28  QListWidget::setAlternatingRowColors(true);
29  // logic
30 
31  QListWidget::setSelectionBehavior(QAbstractItemView::SelectRows);
32  QListWidget::setSelectionMode(QAbstractItemView::SingleSelection);
33 
34  connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnItemDoubleClicked(QListWidgetItem *)));
35 
36  connect(this, SIGNAL(currentRowChanged(int)), this, SLOT(OnCurrentRowChanged(int)));
37 }
38 
40 {
41  this->SetPointSet(nullptr); // remove listener
42 }
43 
45 {
46  if (!m_PointSet.IsExpired())
47  {
48  auto pointSet = m_PointSet.Lock();
49 
50  pointSet->RemoveObserver(m_PointSetModifiedTag);
51  pointSet->RemoveObserver(m_PointSetDeletedTag);
52  }
53 
54  m_PointSet = pointSet;
55 
56  if (!m_PointSet.IsExpired())
57  {
58  auto pointSet = m_PointSet.Lock();
59 
60  auto onPointSetDeleted = itk::SimpleMemberCommand<QmitkPointListViewWidget>::New();
61  onPointSetDeleted->SetCallbackFunction(this, &QmitkPointListViewWidget::OnPointSetDeleted);
62  m_PointSetDeletedTag = pointSet->AddObserver(itk::DeleteEvent(), onPointSetDeleted);
63 
64  auto onPointSetModified = itk::SimpleMemberCommand<QmitkPointListViewWidget>::New();
65  onPointSetModified->SetCallbackFunction(this, &QmitkPointListViewWidget::OnPointSetChanged);
66  m_PointSetModifiedTag = pointSet->AddObserver(itk::DeleteEvent(), onPointSetModified);
67  }
68 
69  this->Update();
70 }
71 
73 {
74  return m_PointSet.Lock();
75 }
76 
78 {
79  m_TimeStep = t;
80  this->Update();
81 }
82 
84 {
85  return m_TimeStep;
86 }
87 
89 {
90  m_MultiWidget = multiWidget;
91 }
92 
94 {
95  return m_MultiWidget;
96 }
97 
99 {
100  if (!m_SelfCall)
101  this->Update();
102 }
103 
105 {
106  this->SetPointSet(nullptr);
107  this->Update();
108 }
109 
111 {
112  QmitkEditPointDialog _EditPointDialog(this);
113  _EditPointDialog.SetPoint(m_PointSet.Lock(), this->row(item), m_TimeStep);
114  _EditPointDialog.exec();
115 }
116 
118 {
119  this->Update(true);
120 }
121 
123 {
124  if (m_PointSet.IsExpired())
125  return;
126 
127  int key = e->key();
128  switch (key)
129  {
130  case Qt::Key_F2:
131  this->MoveSelectedPointUp();
132  break;
133  case Qt::Key_F3:
134  this->MoveSelectedPointDown();
135  break;
136  case Qt::Key_Delete:
137  this->RemoveSelectedPoint();
138  break;
139  default:
140  break;
141  }
142 }
143 
145 {
146  if (m_PointSet.IsExpired())
147  return;
148 
149  auto pointSet = m_PointSet.Lock();
150 
152  selectedID = pointSet->SearchSelectedPoint(m_TimeStep);
153  mitk::PointOperation *doOp =
154  new mitk::PointOperation(mitk::OpMOVEPOINTUP, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
155  pointSet->ExecuteOperation(doOp);
156  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
157 }
158 
160 {
161  if (m_PointSet.IsExpired())
162  return;
163 
164  auto pointSet = m_PointSet.Lock();
165 
167  selectedID = pointSet->SearchSelectedPoint(m_TimeStep);
168  mitk::PointOperation *doOp =
169  new mitk::PointOperation(mitk::OpMOVEPOINTDOWN, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
170  pointSet->ExecuteOperation(doOp);
171  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
172 }
173 
175 {
176  if (m_PointSet.IsExpired())
177  return;
178 
179  auto pointSet = m_PointSet.Lock();
180 
182  selectedID = pointSet->SearchSelectedPoint(m_TimeStep);
183  mitk::PointOperation *doOp =
184  new mitk::PointOperation(mitk::OpREMOVE, pointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
185  pointSet->ExecuteOperation(doOp);
186  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
187 }
188 
189 void QmitkPointListViewWidget::Update(bool currentRowChanged)
190 {
191  if (m_SelfCall)
192  return;
193 
194  if (m_PointSet.IsExpired())
195  {
196  this->clear();
197  return;
198  }
199 
200  auto pointSet = m_PointSet.Lock();
201 
202  m_SelfCall = true;
203  QString text;
204  int i = 0;
205 
206  mitk::PointSet::DataType::Pointer pointset = pointSet->GetPointSet(m_TimeStep);
207  for (mitk::PointSet::PointsContainer::Iterator it = pointset->GetPoints()->Begin();
208  it != pointset->GetPoints()->End();
209  ++it)
210  {
211  text = QString("%0: (%1, %2, %3)")
212  .arg(i, 3)
213  .arg(it.Value().GetElement(0), 0, 'f', 3)
214  .arg(it.Value().GetElement(1), 0, 'f', 3)
215  .arg(it.Value().GetElement(2), 0, 'f', 3);
216 
217  if (i == this->count())
218  this->addItem(text); // insert text
219  else
220  this->item(i)->setText(text); // update text
221 
222  if (currentRowChanged)
223  {
224  if (i == this->currentRow())
225  pointSet->SetSelectInfo(this->currentRow(), true, m_TimeStep);
226  else
227  pointSet->SetSelectInfo(it->Index(), false, m_TimeStep); // select nothing now
228  }
229  ++i;
230  }
231 
232  // remove unnecessary listwidgetitems
233  while (pointSet->GetPointSet(m_TimeStep)->GetPoints()->Size() < (unsigned int)this->count())
234  {
235  QListWidgetItem *item = this->takeItem(this->count() - 1);
236  delete item;
237  }
238 
239  // update selection in pointset or in the list widget
240  if (!currentRowChanged)
241  {
242  if (pointSet->GetNumberOfSelected(m_TimeStep) > 1)
243  {
245  std::cerr << "Point set has multiple selected points. This view is not designed for more than one selected point."
246  << std::endl;
247  }
248 
249  int selectedIndex = pointSet->SearchSelectedPoint(m_TimeStep);
250  if (selectedIndex != -1) // no selected point is found
251  {
252  this->setCurrentRow(selectedIndex);
253  }
254  }
255  m_SelfCall = false;
256 }
void OnPointSetChanged()
observer for point set "modified" events
A dialog for editing points directly (coordinates) via TextEdits.
itk::SmartPointer< T > Lock() const
void OnItemDoubleClicked(QListWidgetItem *item)
QmitkStdMultiWidget * GetMultiWidget() const
return the QmitkStdMultiWidget that is used for updating render window crosshair
void SetMultiWidget(QmitkStdMultiWidget *multiWidget)
assign a QmitkStdMultiWidget for updating render window crosshair
Constants for most interaction classes, due to the generic StateMachines.
mitk::WeakPointer< mitk::PointSet > m_PointSet
DataType::PointIdentifier PointIdentifier
Definition: mitkPointSet.h:133
void OnPointSetDeleted()
observer for point set "delete" events
int GetTimeStep() const
which time step to display/model
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:75
The &#39;QmitkStdMultiWidget&#39; is a &#39;QmitkAbstractMultiWidget&#39; that is used to display multiple render win...
void Update(bool currentRowChanged=false)
static RenderingManager * GetInstance()
bool IsExpired() const noexcept
Operation that handles all actions on one Point.
void SetTimeStep(int t)
which time step to display/model
QmitkPointListViewWidget(QWidget *parent=nullptr)
void SetPointSet(mitk::PointSet *pointSet)
assign a point set for observation
void OnCurrentRowChanged(int)
called when the selection of the view widget changes
void keyPressEvent(QKeyEvent *e) override
react to F2, F3 and DEL keys
const mitk::PointSet * GetPointSet() const
which point set to work on
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
QmitkStdMultiWidget * m_MultiWidget
used to position the planes on a selected point
void SetPoint(mitk::PointSet *_PointSet, mitk::PointSet::PointIdentifier _PointId, int timestep=0)