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
QmitkColorTransferFunctionCanvas.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 QMITKCOLORTRANSFERFUNCTIONCANVAS_H_INCLUDED
18 #define QMITKCOLORTRANSFERFUNCTIONCANVAS_H_INCLUDED
19 
22 
23 #include <vtkColorTransferFunction.h>
24 
26 {
27  Q_OBJECT
28 
29 public:
30  QmitkColorTransferFunctionCanvas(QWidget *parent = nullptr, Qt::WindowFlags f = nullptr);
31  virtual void paintEvent(QPaintEvent *e) override;
32  int GetNearHandle(int x, int y, unsigned int maxSquaredDistance = 32) override;
33  void SetTitle(const QString &title);
34 
35  void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
36  {
37  this->m_ColorTransferFunction = colorTransferFunction;
38  this->SetMin(colorTransferFunction->GetRange()[0]);
39  this->SetMax(colorTransferFunction->GetRange()[1]);
40  setEnabled(true);
41  update();
42  }
43 
44  int AddFunctionPoint(double x, double) override
45  {
46  return m_ColorTransferFunction->AddRGBPoint(x,
47  m_ColorTransferFunction->GetRedValue(x),
48  m_ColorTransferFunction->GetGreenValue(x),
49  m_ColorTransferFunction->GetBlueValue(x));
50  }
51 
52  void RemoveFunctionPoint(double x) override
53  {
54  int old_size = GetFunctionSize();
55  m_ColorTransferFunction->RemovePoint(x);
56  if (GetFunctionSize() + 1 != old_size)
57  {
58  std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
59  std::cout << "called with x=" << x << std::endl;
60  }
61  }
62 
63  double GetFunctionX(int index) override { return m_ColorTransferFunction->GetDataPointer()[index * 4]; }
64  int GetFunctionSize() override { return m_ColorTransferFunction->GetSize(); }
65  void DoubleClickOnHandle(int handle) override;
66  void MoveFunctionPoint(int index, std::pair<double, double> pos) override;
67 
68  void AddRGB(double x, double r, double g, double b);
69 
70  double GetFunctionMax() { return m_ColorTransferFunction->GetRange()[1]; }
71  double GetFunctionMin() { return m_ColorTransferFunction->GetRange()[0]; }
73  {
74  double range;
75  if ((m_ColorTransferFunction->GetRange()[0]) == 0)
76  {
77  range = m_ColorTransferFunction->GetRange()[1];
78  return range;
79  }
80  else
81  {
82  range = (m_ColorTransferFunction->GetRange()[1]) - (m_ColorTransferFunction->GetRange()[0]);
83  return range;
84  }
85  }
86 
88  {
89  m_ColorTransferFunction->AddRGBSegment(this->GetFunctionMin(), 1, 0, 0, this->GetFunctionMax(), 1, 1, 0);
90  }
91 
92  double GetFunctionY(int) override { return 0.0; }
93 protected:
94  vtkColorTransferFunction *m_ColorTransferFunction;
95  QString m_Title;
96 };
97 
98 #endif
virtual void paintEvent(QPaintEvent *e) override
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=32)=0
#define MITKQTWIDGETSEXT_EXPORT
int AddFunctionPoint(double x, double) override
virtual void DoubleClickOnHandle(int handle)=0
void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
virtual int GetFunctionSize()=0