Medical Imaging Interaction Toolkit  2023.12.99-29da53b2
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
14 #define QmitkPiecewiseFunctionCanvas_h
15 
18 
19 #include <vtkPiecewiseFunction.h>
20 
22 {
23  Q_OBJECT
24 
25 public:
26  QmitkPiecewiseFunctionCanvas(QWidget *parent = nullptr, Qt::WindowFlags f = {});
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
QmitkPiecewiseFunctionCanvas::SetPiecewiseFunction
void SetPiecewiseFunction(vtkPiecewiseFunction *piecewiseFunction)
Definition: QmitkPiecewiseFunctionCanvas.h:31
QmitkTransferFunctionCanvas::MoveFunctionPoint
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
MITKQTWIDGETSEXT_EXPORT
#define MITKQTWIDGETSEXT_EXPORT
Definition: MitkQtWidgetsExtExports.h:15
QmitkPiecewiseFunctionCanvas::RemoveFunctionPoint
void RemoveFunctionPoint(double x) override
Definition: QmitkPiecewiseFunctionCanvas.h:42
QmitkTransferFunctionCanvas
Definition: QmitkTransferFunctionCanvas.h:24
QmitkTransferFunctionCanvas::GetFunctionSize
virtual int GetFunctionSize()=0
QmitkPiecewiseFunctionCanvas::GetFunctionSize
int GetFunctionSize() override
Definition: QmitkPiecewiseFunctionCanvas.h:59
QmitkPiecewiseFunctionCanvas::m_PiecewiseFunction
vtkPiecewiseFunction * m_PiecewiseFunction
Definition: QmitkPiecewiseFunctionCanvas.h:95
QmitkPiecewiseFunctionCanvas::AddFunctionPoint
int AddFunctionPoint(double x, double val) override
Definition: QmitkPiecewiseFunctionCanvas.h:41
QmitkTransferFunctionCanvas::paintEvent
void paintEvent(QPaintEvent *e) override
QmitkPiecewiseFunctionCanvas::GetFunctionMax
double GetFunctionMax()
Definition: QmitkPiecewiseFunctionCanvas.h:63
QmitkPiecewiseFunctionCanvas::m_Title
QString m_Title
Definition: QmitkPiecewiseFunctionCanvas.h:96
QmitkTransferFunctionCanvas.h
QmitkPiecewiseFunctionCanvas::DoubleClickOnHandle
void DoubleClickOnHandle(int) override
Definition: QmitkPiecewiseFunctionCanvas.h:60
QmitkPiecewiseFunctionCanvas::GetFunctionY
double GetFunctionY(int index) override
Definition: QmitkPiecewiseFunctionCanvas.h:54
QmitkPiecewiseFunctionCanvas::GetFunctionX
double GetFunctionX(int index) override
Definition: QmitkPiecewiseFunctionCanvas.h:53
QmitkPiecewiseFunctionCanvas::GetFunctionRange
double GetFunctionRange()
Definition: QmitkPiecewiseFunctionCanvas.h:65
QmitkTransferFunctionCanvas::SetMax
void SetMax(double max)
Definition: QmitkTransferFunctionCanvas.h:41
MitkQtWidgetsExtExports.h
QmitkTransferFunctionCanvas::SetMin
void SetMin(double min)
Definition: QmitkTransferFunctionCanvas.h:34
QmitkTransferFunctionCanvas::GetNearHandle
virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=32)=0
QmitkPiecewiseFunctionCanvas
Definition: QmitkPiecewiseFunctionCanvas.h:21
QmitkPiecewiseFunctionCanvas::GetFunctionMin
double GetFunctionMin()
Definition: QmitkPiecewiseFunctionCanvas.h:64
QmitkPiecewiseFunctionCanvas::ResetGO
void ResetGO()
Definition: QmitkPiecewiseFunctionCanvas.h:86
QmitkPiecewiseFunctionCanvas::RemoveAllFunctionPoints
void RemoveAllFunctionPoints()
Definition: QmitkPiecewiseFunctionCanvas.h:80