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