Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmlMitkColorTransferFunctionCanvas.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 __QmlMitkColorTransferFunctionCanvas_h
18 #define __QmlMitkColorTransferFunctionCanvas_h
19 
21 #include <MitkQmlItemsExports.h>
22 
23 #include <vtkColorTransferFunction.h>
24 
26 {
27  Q_OBJECT
28  Q_PROPERTY(double greyValue READ getGreyValue WRITE setGreyValue)
29 
30 public:
31 
32  QmlMitkColorTransferFunctionCanvas(QQuickPaintedItem* parent = nullptr);
33  virtual void paint(QPainter* painter ) override;
34  int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32) override;
35  void SetTitle(const QString& title);
36 
37  void setGreyValue(double value);
38  double getGreyValue();
39 
40  void SetColorTransferFunction(vtkColorTransferFunction* colorTransferFunction)
41  {
42  this->m_ColorTransferFunction = colorTransferFunction;
43  this->SetMin(colorTransferFunction->GetRange()[0]);
44  this->SetMax(colorTransferFunction->GetRange()[1]);
45  setEnabled(true);
46  update();
47  }
48 
49  int AddFunctionPoint(double x, double) override
50  {
51  return m_ColorTransferFunction->AddRGBPoint(x,m_ColorTransferFunction->GetRedValue(x),m_ColorTransferFunction->GetGreenValue(x),m_ColorTransferFunction->GetBlueValue(x));
52  }
53 
54  void RemoveFunctionPoint(double x) override
55  {
56  int old_size = GetFunctionSize();
57  m_ColorTransferFunction->RemovePoint(x);
58  if (GetFunctionSize() + 1 != old_size)
59  {
60  std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
61  std::cout << "called with x=" << x << std::endl;
62  }
63  }
64 
65  double GetFunctionX(int index) override
66  {
67  return m_ColorTransferFunction->GetDataPointer()[index*4];
68  }
69 
70  int GetFunctionSize() override
71  {
72  return m_ColorTransferFunction->GetSize();
73  }
74 
75  void DoubleClickOnHandle(int handle) override;
76  void MoveFunctionPoint(int index, std::pair<double,double> pos) override;
77 
78  void AddRGB(double x, double r, double g, double b);
79 
80  double GetFunctionMax()
81  {
82  return m_ColorTransferFunction->GetRange()[1];
83  }
84 
85  double GetFunctionMin()
86  {
87  return m_ColorTransferFunction->GetRange()[0];
88  }
89 
91  {
92  double range;
93  if((m_ColorTransferFunction->GetRange()[0])==0)
94  {
95  range = m_ColorTransferFunction->GetRange()[1];
96  return range;
97  }
98  else
99  {
100  range = (m_ColorTransferFunction->GetRange()[1])-(m_ColorTransferFunction->GetRange()[0]);
101  return range;
102  }
103  }
104 
106  {
107  m_ColorTransferFunction->AddRGBSegment(this->GetFunctionMin(),1,0,0,this->GetFunctionMax(),1,1,0);
108  }
109 
110  double GetFunctionY(int) override
111  {
112  return 0.0;
113  }
114 
115  static void create();
116 
117 protected:
118  vtkColorTransferFunction* m_ColorTransferFunction;
119  QString m_Title;
120 
121  double m_GreyValue;
122 
123 signals:
124  void sync();
125 
126 };
127 
128 #endif
#define MITKQMLITEMS_EXPORT
void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
virtual int GetFunctionSize()=0
virtual void DoubleClickOnHandle(int handle)=0
virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=32)=0
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
virtual void paint(QPainter *painter)=0