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