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