Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkPiecewiseFunctionCanvas.h
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 #ifndef QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED
18 #define QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED
19 
22 
23 #include <vtkPiecewiseFunction.h>
24 
26 {
27  Q_OBJECT
28 
29 public:
30  QmitkPiecewiseFunctionCanvas(QWidget *parent = nullptr, Qt::WindowFlags f = nullptr);
31  virtual void paintEvent(QPaintEvent *e) override;
32  void SetTitle(const QString &title);
33  int GetNearHandle(int x, int y, unsigned int maxSquaredDistance = 32) override;
34 
35  void SetPiecewiseFunction(vtkPiecewiseFunction *piecewiseFunction)
36  {
37  this->m_PiecewiseFunction = piecewiseFunction;
38  this->SetMin(m_PiecewiseFunction->GetRange()[0]);
39  this->SetMax(m_PiecewiseFunction->GetRange()[1]);
40  setEnabled(true);
41 
42  update();
43  }
44 
45  int AddFunctionPoint(double x, double val) override { return m_PiecewiseFunction->AddPoint(x, val); }
46  void RemoveFunctionPoint(double x) override
47  {
48  int old_size = GetFunctionSize();
49  m_PiecewiseFunction->RemovePoint(x);
50  if (GetFunctionSize() + 1 != old_size)
51  {
52  std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
53  std::cout << "called with x=" << x << std::endl;
54  }
55  }
56 
57  double GetFunctionX(int index) override { return m_PiecewiseFunction->GetDataPointer()[index * 2]; }
58  double GetFunctionY(int index) override
59  {
60  return m_PiecewiseFunction->GetValue(m_PiecewiseFunction->GetDataPointer()[index * 2]);
61  }
62 
63  int GetFunctionSize() override { return m_PiecewiseFunction->GetSize(); }
64  void DoubleClickOnHandle(int) override {}
65  void MoveFunctionPoint(int index, std::pair<double, double> pos) override;
66 
67  double GetFunctionMax() { return m_PiecewiseFunction->GetRange()[1]; }
68  double GetFunctionMin() { return m_PiecewiseFunction->GetRange()[0]; }
70  {
71  double range;
72  if ((m_PiecewiseFunction->GetRange()[0]) < 0)
73  {
74  range = (m_PiecewiseFunction->GetRange()[1]) - (m_PiecewiseFunction->GetRange()[0]);
75  return range;
76  }
77  else
78  {
79  range = m_PiecewiseFunction->GetRange()[1];
80  return range;
81  }
82  }
83 
85  {
86  m_PiecewiseFunction->AddSegment(this->GetFunctionMin(), 0, this->GetFunctionMax(), 1);
87  m_PiecewiseFunction->AddPoint(0.0, 0.0);
88  }
89 
90  void ResetGO()
91  { // Gradient Opacity
92  m_PiecewiseFunction->AddSegment(this->GetFunctionMin(), 0, 0, 1);
93  m_PiecewiseFunction->AddSegment(0, 1, ((this->GetFunctionRange()) * 0.125), 1);
94  m_PiecewiseFunction->AddSegment(((this->GetFunctionRange()) * 0.125), 1, ((this->GetFunctionRange()) * 0.2), 1);
95  m_PiecewiseFunction->AddSegment(((this->GetFunctionRange()) * 0.2), 1, ((this->GetFunctionRange()) * 0.25), 1);
96  }
97 
98 protected:
99  vtkPiecewiseFunction *m_PiecewiseFunction;
100  QString m_Title;
101 };
102 
103 #endif
virtual void paintEvent(QPaintEvent *e) override
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
double GetFunctionY(int index) override
virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=32)=0
#define MITKQTWIDGETSEXT_EXPORT
double GetFunctionX(int index) override
void SetPiecewiseFunction(vtkPiecewiseFunction *piecewiseFunction)
void RemoveFunctionPoint(double x) override
virtual int GetFunctionSize()=0
int AddFunctionPoint(double x, double val) override