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
QmitkToolDistanceWidget.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 
18 
19 #include <QGridLayout>
20 #include <itkDataObject.h>
22 #include <math.h>
23 
24 
25 
26 
28 : QWidget(parent), m_Controls(NULL), m_DistanceLabels(NULL)
29 {
30  this->CreateQtPartControl( this );
31 }
32 
34 {
36  delete m_DistanceLabels;
37  m_DistanceLabels = NULL;
38  m_Controls = NULL;
39 }
40 
42 {
43  if (!m_Controls)
44  {
45  // create GUI widgets
46  m_Controls = new Ui::QmitkToolDistanceWidgetControls;
47  m_Controls->setupUi(parent);
48  m_Controls->m_StatusLabel->setText(QString("No tracking tools connected. Please set up a connection first."));
49 
50  this->CreateConnections();
51  }
52 }
53 
55 {
56 
57 }
58 
59 void QmitkToolDistanceWidget::CreateToolDistanceMatrix(itk::ProcessObject::DataObjectPointerArray & outputs)
60 {
61 
62  if(outputs.size() > 1)
63  {
64  this->show();
65 
66  mitk::NavigationData* navData;
67 
68 
69  if(m_DistanceLabels == NULL)
70  {
71  m_DistanceLabels = new DistanceLabelType;
72  }
73 
74  if(m_DistanceLabels->isEmpty())
75  {
76  this->m_Controls->m_StatusLabel->setText("");
77 
78  QLabel* label;
79 
80 
81  // labeling of matrix
82  for (unsigned int i = 0; i < outputs.size()-1; i++)
83  {
84  navData = dynamic_cast<mitk::NavigationData*>(outputs.at(i).GetPointer());
85  label = new QLabel(navData->GetName(),this);
86  label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
87  this->m_Controls->m_GridLayout->addWidget(label,i+1,0);
88 
89  navData = dynamic_cast<mitk::NavigationData*>(outputs.at(i+1).GetPointer());
90  label = new QLabel(navData->GetName(),this);
91  label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
92  this->m_Controls->m_GridLayout->addWidget(label,0,i+1);
93  }
94 
95 
96  for(unsigned int i = 0; i < outputs.size()-1; i++)
97  {
98  QVector<QLabel*>* rowDistances = new QVector<QLabel*>();
99 
100  for(unsigned int j = i+1; j < outputs.size(); j++)
101  {
102  // distance labels initializing
103  label = new QLabel(QString("---"), this);
104  label->setFrameStyle(QFrame::Box | QFrame::Sunken);
105  label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
106  rowDistances->append(label);
107 
108  //initial distance label adding to the QGridLayout
109  this->m_Controls->m_GridLayout->addWidget(label,i+1,j);
110  }
111  this->m_DistanceLabels->append(*rowDistances);
112  }
113  }
114  }
115  else
116  {
117  this->m_Controls->m_StatusLabel->setText(QString("For distance information please connect at least two tools"));
118  }
119 
120 }
121 
122 
123 
124  void QmitkToolDistanceWidget::ShowDistanceValues(itk::ProcessObject::DataObjectPointerArray & outputs)
125  {
126 
127  mitk::NavigationData* navData;
128  mitk::NavigationData* nextNavData;
129 
130  for(int i=0; i < m_DistanceLabels->size(); i++)
131  {
132  int j = i+1;
133 
134  for(int k=0; k < m_DistanceLabels->at(i).size(); k++)
135  {
136  navData = dynamic_cast<mitk::NavigationData*>(outputs.at(i).GetPointer());
137  nextNavData = dynamic_cast<mitk::NavigationData*>(outputs.at(j++).GetPointer());
138 
139  if(navData == NULL || nextNavData == NULL)
140  return;
141 
142  mitk::NavigationData::PositionType::RealType distance = navData->GetPosition().EuclideanDistanceTo(nextNavData->GetPosition());
143  distance = floor(distance * 10.) / 10.;
144  QString distanceStr;
145  if(!navData->IsDataValid() || !nextNavData->IsDataValid())
146  {
147  distanceStr = "---";
148  }
149  else
150  {
151  distanceStr.setNum(distance);
152  distanceStr += " mm";
153  }
154  this->m_DistanceLabels->at(i).at(k)->setText(distanceStr);
155  }
156  }
157  }
158 
160  {
161 
162  while(m_Controls->m_GridLayout->count() > 0)
163  {
164  QWidget* widget = m_Controls->m_GridLayout->itemAt(0)->widget();
165  m_Controls->m_GridLayout->removeWidget(widget);
166  delete widget;
167  }
168  delete this->m_DistanceLabels;
169  this->m_DistanceLabels = NULL;
170 
171  this->m_Controls->m_StatusLabel->setText(QString("For distance information please set up the connection again."));
172 
173  }
174 
176  {
177  for(int i = 0; i < m_DistanceLabels->size(); i++)
178  {
179  for(int j= 0; j < m_DistanceLabels->at(i).size(); j++)
180  {
181  this->m_DistanceLabels->at(i).at(j)->setText(QString("---"));
182  }
183  }
184  }
185 
186 
187 
188 
void ClearDistanceMatrix()
This method clears the whole tool distances matrix.
virtual const char * GetName() const
returns the name of the NavigationData object
Navigation Data.
void CreateQtPartControl(QWidget *parent)
void SetDistanceLabelValuesInvalid()
This method set's all distance entries in the matrix to "---". Can be used e.g. if tracking is stoppe...
QVector< QVector< QLabel * > > DistanceLabelType
void ShowDistanceValues(itk::ProcessObject::DataObjectPointerArray &outputs)
This method displays the matrix with the distances between the tracking source's outputs in a QGridLa...
virtual ~QmitkToolDistanceWidget()
default destructor
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
void CreateToolDistanceMatrix(itk::ProcessObject::DataObjectPointerArray &outputs)
This method creates the initial distances matrix and labels it with the connected tool names...
Ui::QmitkToolDistanceWidgetControls * m_Controls
gui widgets
QmitkToolDistanceWidget(QWidget *parent)
default constructor