Medical Imaging Interaction Toolkit  2021.10.99-fd647480
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_INCLUDED
14 #define QMITKTRANSFERFUNCTIONCANVAS_H_INCLUDED
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
#define MITKQTWIDGETSEXT_EXPORT
virtual double GetMax() const =0
Returns the maximum value of the histogram.
virtual double GetMin() const =0
Returns the minimal value of the histogram.
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
std::pair< double, double > ValidateCoord(std::pair< double, double > x)
static RenderingManager * GetInstance()
void SetQLineEdits(QLineEdit *xEdit, QLineEdit *yEdit)
mitk::SimpleHistogram * GetHistogram()
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
void SetHistogram(mitk::SimpleHistogram *histogram)