Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
QmitkTransferFunctionCanvas.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 QmitkTransferFunctionCanvas_h
14 #define QmitkTransferFunctionCanvas_h
15 
17 
18 #include <mitkRenderingManager.h>
19 #include <mitkSimpleHistogram.h>
20 
21 #include <QLineEdit>
22 #include <QWidget>
23 
25 {
26  Q_OBJECT
27 
28 public:
29  QmitkTransferFunctionCanvas(QWidget *parent = nullptr, Qt::WindowFlags f = nullptr);
30 
31  mitk::SimpleHistogram *GetHistogram() { return m_Histogram; }
32  void SetHistogram(mitk::SimpleHistogram *histogram) { m_Histogram = histogram; }
33  double GetMin() { return m_Min; }
34  void SetMin(double min)
35  {
36  this->m_Min = min;
37  SetLower(min);
38  }
39 
40  double GetMax() { return m_Max; }
41  void SetMax(double max)
42  {
43  this->m_Max = max;
44  SetUpper(max);
45  }
46 
47  double GetLower() { return m_Lower; }
48  void SetLower(double lower) { this->m_Lower = lower; }
49  double GetUpper() { return m_Upper; }
50  void SetUpper(double upper) { this->m_Upper = upper; }
51  void mousePressEvent(QMouseEvent *mouseEvent) override;
52  void paintEvent(QPaintEvent *e) override;
53  virtual void DoubleClickOnHandle(int handle) = 0;
54 
55  void mouseMoveEvent(QMouseEvent *mouseEvent) override;
56  void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
57  void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override;
58  void PaintHistogram(QPainter &p);
59 
60  virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance = 32) = 0;
61  virtual int AddFunctionPoint(double x, double val) = 0;
62  virtual void RemoveFunctionPoint(double x) = 0;
63  virtual void MoveFunctionPoint(int index, std::pair<double, double> pos) = 0;
64  virtual double GetFunctionX(int index) = 0;
65  virtual double GetFunctionY(int index) = 0;
66  virtual int GetFunctionSize() = 0;
68 
69  double m_Lower, m_Upper, m_Min, m_Max;
70 
71  std::pair<int, int> FunctionToCanvas(std::pair<double, double>);
72  std::pair<double, double> CanvasToFunction(std::pair<int, int>);
73 
75 
76  void keyPressEvent(QKeyEvent *e) override;
77 
78  void SetImmediateUpdate(bool state);
79 
80  std::pair<double, double> ValidateCoord(std::pair<double, double> x)
81  {
82  double max = m_Histogram->GetMax();
83  double min = m_Histogram->GetMin();
84  if (x.first < min)
85  x.first = min;
86  if (x.first > max)
87  x.first = max;
88  if (x.second < 0)
89  x.second = 0;
90  if (x.second > 1)
91  x.second = 1;
92  return x;
93  }
94 
95  void SetX(float x)
96  {
97  if (m_GrabbedHandle != -1)
98  {
99  this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(x, GetFunctionY(m_GrabbedHandle))));
100  update();
102  }
103  }
104 
105  void SetY(float y)
106  {
107  if (m_GrabbedHandle != -1)
108  {
109  this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(GetFunctionX(m_GrabbedHandle), y)));
110  update();
112  }
113  }
114 
115  void SetQLineEdits(QLineEdit *xEdit, QLineEdit *yEdit)
116  {
117  m_XEdit = xEdit;
118  m_YEdit = yEdit;
119  m_LineEditAvailable = true;
120  }
121 
122 protected:
124  float m_Range;
125 
127  QLineEdit *m_XEdit;
128  QLineEdit *m_YEdit;
129 };
130 
131 #endif
QmitkTransferFunctionCanvas::SetY
void SetY(float y)
Definition: QmitkTransferFunctionCanvas.h:105
QmitkTransferFunctionCanvas::m_GrabbedHandle
int m_GrabbedHandle
Definition: QmitkTransferFunctionCanvas.h:67
mitk::RenderingManager::GetInstance
static RenderingManager * GetInstance()
mitk::SimpleHistogram
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
Definition: mitkSimpleHistogram.h:34
QmitkTransferFunctionCanvas::GetLower
double GetLower()
Definition: QmitkTransferFunctionCanvas.h:47
MITKQTWIDGETSEXT_EXPORT
#define MITKQTWIDGETSEXT_EXPORT
Definition: MitkQtWidgetsExtExports.h:15
QmitkTransferFunctionCanvas::m_LineEditAvailable
bool m_LineEditAvailable
Definition: QmitkTransferFunctionCanvas.h:126
QmitkTransferFunctionCanvas::m_YEdit
QLineEdit * m_YEdit
Definition: QmitkTransferFunctionCanvas.h:128
QmitkTransferFunctionCanvas::ValidateCoord
std::pair< double, double > ValidateCoord(std::pair< double, double > x)
Definition: QmitkTransferFunctionCanvas.h:80
QmitkTransferFunctionCanvas
Definition: QmitkTransferFunctionCanvas.h:24
QmitkTransferFunctionCanvas::GetHistogram
mitk::SimpleHistogram * GetHistogram()
Definition: QmitkTransferFunctionCanvas.h:31
QmitkTransferFunctionCanvas::SetUpper
void SetUpper(double upper)
Definition: QmitkTransferFunctionCanvas.h:50
QmitkTransferFunctionCanvas::m_ImmediateUpdate
bool m_ImmediateUpdate
Definition: QmitkTransferFunctionCanvas.h:123
mitk::RenderingManager::RequestUpdateAll
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
QmitkTransferFunctionCanvas::SetLower
void SetLower(double lower)
Definition: QmitkTransferFunctionCanvas.h:48
QmitkTransferFunctionCanvas::GetMax
double GetMax()
Definition: QmitkTransferFunctionCanvas.h:40
QmitkTransferFunctionCanvas::SetHistogram
void SetHistogram(mitk::SimpleHistogram *histogram)
Definition: QmitkTransferFunctionCanvas.h:32
QmitkTransferFunctionCanvas::GetUpper
double GetUpper()
Definition: QmitkTransferFunctionCanvas.h:49
QmitkTransferFunctionCanvas::m_Range
float m_Range
Definition: QmitkTransferFunctionCanvas.h:124
mitk::SimpleHistogram::GetMin
virtual double GetMin() const =0
Returns the minimal value of the histogram.
QmitkTransferFunctionCanvas::SetQLineEdits
void SetQLineEdits(QLineEdit *xEdit, QLineEdit *yEdit)
Definition: QmitkTransferFunctionCanvas.h:115
mitkSimpleHistogram.h
QmitkTransferFunctionCanvas::m_XEdit
QLineEdit * m_XEdit
Definition: QmitkTransferFunctionCanvas.h:127
QmitkTransferFunctionCanvas::SetMax
void SetMax(double max)
Definition: QmitkTransferFunctionCanvas.h:41
MitkQtWidgetsExtExports.h
mitk::SimpleHistogram::GetMax
virtual double GetMax() const =0
Returns the maximum value of the histogram.
QmitkTransferFunctionCanvas::m_Upper
double m_Upper
Definition: QmitkTransferFunctionCanvas.h:69
QmitkTransferFunctionCanvas::SetMin
void SetMin(double min)
Definition: QmitkTransferFunctionCanvas.h:34
QmitkTransferFunctionCanvas::GetMin
double GetMin()
Definition: QmitkTransferFunctionCanvas.h:33
mitkRenderingManager.h
QmitkTransferFunctionCanvas::SetX
void SetX(float x)
Definition: QmitkTransferFunctionCanvas.h:95
QmitkTransferFunctionCanvas::m_Histogram
mitk::SimpleHistogram * m_Histogram
Definition: QmitkTransferFunctionCanvas.h:74