Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmlMitkTransferFunctionCanvas.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 __QmlMitkTransferFunctionCanvas_h
18 #define __QmlMitkTransferFunctionCanvas_h
19 
20 #include "MitkQmlItemsExports.h"
21 
22 #include <mitkSimpleHistogram.h>
23 #include <mitkRenderingManager.h>
24 
25 #include <QQuickPaintedItem>
26 
27 class MITKQMLITEMS_EXPORT QmlMitkTransferFunctionCanvas : public QQuickPaintedItem
28 {
29 
30  Q_OBJECT
31 
32 public:
33 
34  QmlMitkTransferFunctionCanvas(QQuickPaintedItem* parent = nullptr);
35 
37  {
38  return m_Histogram;
39  }
40 
42  {
43  m_Histogram = histogram;
44  }
45 
46  double GetMin()
47  {
48  return m_Min;
49  }
50 
51  void SetMin(double min)
52  {
53  this->m_Min = min;
54  SetLower(min);
55  }
56 
57  double GetMax()
58  {
59  return m_Max;
60  }
61 
62  void SetMax(double max)
63  {
64  this->m_Max = max;
65  SetUpper(max);
66  }
67 
68  double GetLower()
69  {
70  return m_Lower;
71  }
72 
73  void SetLower(double lower)
74  {
75  this->m_Lower = lower;
76  }
77 
78  double GetUpper()
79  {
80  return m_Upper;
81  }
82 
83  void SetUpper(double upper)
84  {
85  this->m_Upper = upper;
86  }
87 
88  virtual void paint(QPainter* painter) = 0;
89 
90  void mousePressEvent( QMouseEvent* mouseEvent ) override;
91  virtual void DoubleClickOnHandle(int handle) = 0;
92 
93  void mouseMoveEvent( QMouseEvent* mouseEvent ) override;
94  void mouseReleaseEvent( QMouseEvent* mouseEvent ) override;
95  void mouseDoubleClickEvent( QMouseEvent* mouseEvent ) override;
96  void keyPressEvent(QKeyEvent * event) override;
97  void PaintHistogram(QPainter* painter);
98 
99  virtual int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32) = 0;
100  virtual int AddFunctionPoint(double x,double val) = 0;
101  virtual void RemoveFunctionPoint(double x) = 0;
102  virtual void MoveFunctionPoint(int index, std::pair<double,double> pos) = 0;
103  virtual double GetFunctionX(int index) = 0;
104  virtual double GetFunctionY(int index) = 0;
105  virtual int GetFunctionSize() = 0;
107 
108  double m_Lower, m_Upper, m_Min, m_Max;
109 
110  std::pair<int,int> FunctionToCanvas(std::pair<double,double>);
111  std::pair<double,double> CanvasToFunction(std::pair<int,int>);
112 
114 
115  void SetImmediateUpdate(bool state);
116 
117  std::pair<double,double> ValidateCoord( std::pair<double,double> x )
118  {
119  double max = m_Histogram->GetMax();
120  double min = m_Histogram->GetMin();
121  if( x.first < min ) x.first = min;
122  if( x.first > max ) x.first = max;
123  if( x.second < 0 ) x.second = 0;
124  if( x.second > 1 ) x.second = 1;
125  return x;
126  }
127 
128  void SetX(float x)
129  {
130  if (m_GrabbedHandle != -1)
131  {
132  this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(x,GetFunctionY(m_GrabbedHandle))));
133  update();
135  }
136  }
137 
138  void SetY(float y)
139  {
140  if (m_GrabbedHandle != -1)
141  {
142  this->MoveFunctionPoint(m_GrabbedHandle, ValidateCoord(std::make_pair(GetFunctionX(m_GrabbedHandle),y)));
143  update();
145  }
146  }
147 
148 protected:
150  float m_Range;
151 
152  double m_GreyValue;
153  double m_Opacity;
154 
156 };
157 
158 #endif
std::pair< double, double > ValidateCoord(std::pair< double, double > x)
#define MITKQMLITEMS_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()
void SetHistogram(mitk::SimpleHistogram *histogram)
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)