Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmlMitkPiecewiseFunctionCanvas.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 __QmlMitkPieceWiseFunctionCanvas_h
18 #define __QmlMitkPieceWiseFunctionCanvas_h
19 
21 #include <MitkQmlItemsExports.h>
22 
23 #include <vtkPiecewiseFunction.h>
24 
26 #include <mitkDataNode.h>
27 
29 {
30  Q_OBJECT
31  Q_PROPERTY(double greyValue READ getGreyValue WRITE setGreyValue)
32  Q_PROPERTY(double opacity READ getOpacity WRITE setOpacity)
33 
34 public:
35 
36  QmlMitkPiecewiseFunctionCanvas(QQuickPaintedItem* parent = nullptr);
37  void paint(QPainter* painter ) override;
38  void SetTitle(const QString& title);
39  int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32) override;
40 
42 
43  void setGreyValue(double value);
44  double getGreyValue();
45 
46  void setOpacity(double opacity);
47  double getOpacity();
48 
49  void SetPiecewiseFunction(vtkPiecewiseFunction* piecewiseFunction)
50  {
51  this->m_PiecewiseFunction = piecewiseFunction;
52  this->SetMin(m_PiecewiseFunction->GetRange()[0]);
53  this->SetMax(m_PiecewiseFunction->GetRange()[1]);
54  setEnabled(true);
55 
56  update();
57  }
58 
59  int AddFunctionPoint(double x,double val) override
60  {
61  return m_PiecewiseFunction->AddPoint(x,val);
62  }
63 
64  void RemoveFunctionPoint(double x) override
65  {
66  int old_size = GetFunctionSize();
67  m_PiecewiseFunction->RemovePoint(x);
68  if (GetFunctionSize() + 1 != old_size)
69  {
70  std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
71  std::cout << "called with x=" << x << std::endl;
72  }
73  }
74 
75  double GetFunctionX(int index) override
76  {
77  return m_PiecewiseFunction->GetDataPointer()[index*2];
78  }
79 
80  double GetFunctionY(int index) override
81  {
82  return m_PiecewiseFunction->GetValue(m_PiecewiseFunction->GetDataPointer()[index*2]);
83  }
84 
85  int GetFunctionSize() override
86  {
87  return m_PiecewiseFunction->GetSize();
88  }
89 
90  void DoubleClickOnHandle(int) override
91  {
92  }
93 
94  void MoveFunctionPoint(int index, std::pair<double,double> pos) override;
95 
96  double GetFunctionMax()
97  {
98  return m_PiecewiseFunction->GetRange()[1];
99  }
100 
101  double GetFunctionMin()
102  {
103  return m_PiecewiseFunction->GetRange()[0];
104  }
105 
107  {
108  double range;
109  if((m_PiecewiseFunction->GetRange()[0])<0)
110  {
111  range = (m_PiecewiseFunction->GetRange()[1])-(m_PiecewiseFunction->GetRange()[0]);
112  return range;
113  }
114  else
115  {
116  range = m_PiecewiseFunction->GetRange()[1];
117  return range;
118  }
119  }
120 
122  {
123  m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,this->GetFunctionMax(),1);
124  m_PiecewiseFunction->AddPoint(0.0,0.0);
125  }
126 
127  void ResetGO()
128  {
129  //Gradient Opacity
130  m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,0,1);
131  m_PiecewiseFunction->AddSegment(0,1,((this->GetFunctionRange())*0.125),1);
132  m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.125),1,((this->GetFunctionRange())*0.2),1);
133  m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.2),1,((this->GetFunctionRange())*0.25),1);
134  }
135 
136  void mousePressEvent( QMouseEvent* mouseEvent ) override;
137  void mouseMoveEvent( QMouseEvent* mouseEvent ) override;
138  void mouseReleaseEvent( QMouseEvent* mouseEvent ) override;
139  void mouseDoubleClickEvent( QMouseEvent* mouseEvent ) override;
140  void keyPressEvent(QKeyEvent* keyEvent) override;
141 
142  static void create();
143 
144 protected:
145  vtkPiecewiseFunction* m_PiecewiseFunction;
146  QString m_Title;
148 
149  double m_GreyValue;
150  double m_Opacity;
151 
152 signals:
153  void sync();
154 };
155 
156 #endif
void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override
#define MITKQMLITEMS_EXPORT
void mouseMoveEvent(QMouseEvent *mouseEvent) override
void mousePressEvent(QMouseEvent *mouseEvent) override
virtual int GetFunctionSize()=0
void mouseReleaseEvent(QMouseEvent *mouseEvent) override
void keyPressEvent(QKeyEvent *event) override
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
int AddFunctionPoint(double x, double val) override