Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
QmitkEditPointDialog.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 
13 #include "QmitkEditPointDialog.h"
14 
15 #include <QGridLayout>
16 #include <QLabel>
17 #include <QLineEdit>
18 #include <QMessageBox>
19 #include <QPushButton>
20 
21 static void EmitWarning(const QString &message, const QString &title)
22 {
23  MITK_WARN << message.toStdString();
24  QMessageBox::warning(nullptr, title, message);
25 }
26 
27 static bool ValidatePrecision(double value)
28 {
29  return std::log10(std::abs(value)) + 1.0 <= std::numeric_limits<double>::digits10;
30 }
31 
32 static bool ValidateCoordinate(const QString &name, double value)
33 {
34  auto hasValidPrecision = ValidatePrecision(value);
35  if (!hasValidPrecision)
36  EmitWarning(QString("Point set %1 coordinate is outside double precision range.").arg(name),
37  "Invalid point set input");
38 
39  return hasValidPrecision;
40 }
41 
42 struct QmitkEditPointDialogData
43 {
44  mitk::PointSet *m_PointSet;
46  QLineEdit *m_XCoord;
47  QLineEdit *m_YCoord;
48  QLineEdit *m_ZCoord;
49  int m_Timestep;
50 };
51 
52 QmitkEditPointDialog::QmitkEditPointDialog(QWidget *parent, Qt::WindowFlags f)
53  : QDialog(parent, f), d(new QmitkEditPointDialogData)
54 {
55  this->setWindowTitle("Edit Point Dialog");
56  d->m_PointSet = nullptr;
57  d->m_Timestep = 0;
58  d->m_XCoord = new QLineEdit;
59  d->m_YCoord = new QLineEdit;
60  d->m_ZCoord = new QLineEdit;
61  QPushButton *_OKButton = new QPushButton("OK");
62  connect(_OKButton, SIGNAL(clicked(bool)), this, SLOT(OnOkButtonClicked(bool)));
63 
64  auto layout = new QGridLayout;
65  layout->addWidget(new QLabel("X: "), 0, 0, 1, 1);
66  layout->addWidget(d->m_XCoord, 0, 1, 1, 1);
67  layout->addWidget(new QLabel("Y: "), 1, 0, 1, 1);
68  layout->addWidget(d->m_YCoord, 1, 1, 1, 1);
69  layout->addWidget(new QLabel("Z: "), 2, 0, 1, 1);
70  layout->addWidget(d->m_ZCoord, 2, 1, 1, 1);
71  layout->addWidget(_OKButton, 3, 0, 2, 1);
72  this->setLayout(layout);
73 }
74 
76 {
77  delete d;
78 }
79 
81 {
82  d->m_PointSet = _PointSet;
83  d->m_PointId = _PointId;
84  d->m_Timestep = timestep;
85  mitk::PointSet::PointType p = d->m_PointSet->GetPoint(d->m_PointId, d->m_Timestep);
86  d->m_XCoord->setText(QString::number(p.GetElement(0), 'f', 3));
87  d->m_YCoord->setText(QString::number(p.GetElement(1), 'f', 3));
88  d->m_ZCoord->setText(QString::number(p.GetElement(2), 'f', 3));
89 }
90 
92 {
93  if (d->m_PointSet == nullptr)
94  {
95  MITK_WARN << "Pointset is 0.";
96  this->reject();
97  }
98  // check if digits of input value exceed double precision
99  auto x = d->m_XCoord->text().toDouble();
100  auto y = d->m_YCoord->text().toDouble();
101  auto z = d->m_ZCoord->text().toDouble();
102 
103  if (ValidateCoordinate("X", x) && ValidateCoordinate("Y", y) && ValidateCoordinate("Z", z))
104  {
105  auto point = d->m_PointSet->GetPoint(d->m_PointId, d->m_Timestep);
106  point.SetElement(0, x);
107  point.SetElement(1, y);
108  point.SetElement(2, z);
109  d->m_PointSet->SetPoint(d->m_PointId, point);
110  this->accept();
111  }
112 }
QmitkEditPointDialogData * d
DataType::PointIdentifier PointIdentifier
Definition: mitkPointSet.h:133
#define MITK_WARN
Definition: mitkLogMacros.h:19
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:75
static bool ValidatePrecision(double value)
static bool ValidateCoordinate(const QString &name, double value)
static void EmitWarning(const QString &message, const QString &title)
QmitkEditPointDialog(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
void SetPoint(mitk::PointSet *_PointSet, mitk::PointSet::PointIdentifier _PointId, int timestep=0)