Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkColorTransferFunctionCanvas_h
14 #define QmitkColorTransferFunctionCanvas_h
15 
18 
19 #include <vtkColorTransferFunction.h>
20 
22 {
23  Q_OBJECT
24 
25 public:
26  QmitkColorTransferFunctionCanvas(QWidget *parent = nullptr, Qt::WindowFlags f = {});
27  void paintEvent(QPaintEvent *e) override;
28  int GetNearHandle(int x, int y, unsigned int maxSquaredDistance = 100) override;
29  void SetTitle(const QString &title);
30 
31  void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
32  {
33  this->m_ColorTransferFunction = colorTransferFunction;
34  this->SetMin(colorTransferFunction->GetRange()[0]);
35  this->SetMax(colorTransferFunction->GetRange()[1]);
36  setEnabled(true);
37  update();
38  }
39 
40  int AddFunctionPoint(double x, double) override
41  {
42  return m_ColorTransferFunction->AddRGBPoint(x,
43  m_ColorTransferFunction->GetRedValue(x),
44  m_ColorTransferFunction->GetGreenValue(x),
45  m_ColorTransferFunction->GetBlueValue(x));
46  }
47 
48  void RemoveFunctionPoint(double x) override
49  {
50  int old_size = GetFunctionSize();
51  m_ColorTransferFunction->RemovePoint(x);
52  if (GetFunctionSize() + 1 != old_size)
53  {
54  std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
55  std::cout << "called with x=" << x << std::endl;
56  }
57  }
58 
59  double GetFunctionX(int index) override { return m_ColorTransferFunction->GetDataPointer()[index * 4]; }
60  int GetFunctionSize() override { return m_ColorTransferFunction->GetSize(); }
61  void DoubleClickOnHandle(int handle) override;
62  void MoveFunctionPoint(int index, std::pair<double, double> pos) override;
63 
64  void AddRGB(double x, double r, double g, double b);
65 
66  double GetFunctionMax() { return m_ColorTransferFunction->GetRange()[1]; }
67  double GetFunctionMin() { return m_ColorTransferFunction->GetRange()[0]; }
69  {
70  double range;
71  if ((m_ColorTransferFunction->GetRange()[0]) == 0)
72  {
73  range = m_ColorTransferFunction->GetRange()[1];
74  return range;
75  }
76  else
77  {
78  range = (m_ColorTransferFunction->GetRange()[1]) - (m_ColorTransferFunction->GetRange()[0]);
79  return range;
80  }
81  }
82 
84  {
85  m_ColorTransferFunction->AddRGBSegment(this->GetFunctionMin(), 1, 0, 0, this->GetFunctionMax(), 1, 1, 0);
86  }
87 
88  double GetFunctionY(int) override { return 0.0; }
89 protected:
90  vtkColorTransferFunction *m_ColorTransferFunction;
91  QString m_Title;
92 };
93 
94 #endif
QmitkTransferFunctionCanvas::MoveFunctionPoint
virtual void MoveFunctionPoint(int index, std::pair< double, double > pos)=0
MITKQTWIDGETSEXT_EXPORT
#define MITKQTWIDGETSEXT_EXPORT
Definition: MitkQtWidgetsExtExports.h:15
QmitkColorTransferFunctionCanvas::AddFunctionPoint
int AddFunctionPoint(double x, double) override
Definition: QmitkColorTransferFunctionCanvas.h:40
QmitkColorTransferFunctionCanvas::GetFunctionMin
double GetFunctionMin()
Definition: QmitkColorTransferFunctionCanvas.h:67
QmitkColorTransferFunctionCanvas::m_ColorTransferFunction
vtkColorTransferFunction * m_ColorTransferFunction
Definition: QmitkColorTransferFunctionCanvas.h:90
QmitkColorTransferFunctionCanvas::SetColorTransferFunction
void SetColorTransferFunction(vtkColorTransferFunction *colorTransferFunction)
Definition: QmitkColorTransferFunctionCanvas.h:31
QmitkTransferFunctionCanvas
Definition: QmitkTransferFunctionCanvas.h:24
QmitkColorTransferFunctionCanvas::GetFunctionX
double GetFunctionX(int index) override
Definition: QmitkColorTransferFunctionCanvas.h:59
QmitkColorTransferFunctionCanvas::GetFunctionY
double GetFunctionY(int) override
Definition: QmitkColorTransferFunctionCanvas.h:88
QmitkTransferFunctionCanvas::GetFunctionSize
virtual int GetFunctionSize()=0
QmitkTransferFunctionCanvas::paintEvent
void paintEvent(QPaintEvent *e) override
QmitkTransferFunctionCanvas::GetNearHandle
virtual int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=100)=0
QmitkTransferFunctionCanvas::DoubleClickOnHandle
virtual void DoubleClickOnHandle(int handle)=0
QmitkTransferFunctionCanvas.h
QmitkColorTransferFunctionCanvas
Definition: QmitkColorTransferFunctionCanvas.h:21
QmitkColorTransferFunctionCanvas::GetFunctionRange
double GetFunctionRange()
Definition: QmitkColorTransferFunctionCanvas.h:68
QmitkColorTransferFunctionCanvas::GetFunctionMax
double GetFunctionMax()
Definition: QmitkColorTransferFunctionCanvas.h:66
QmitkColorTransferFunctionCanvas::m_Title
QString m_Title
Definition: QmitkColorTransferFunctionCanvas.h:91
QmitkTransferFunctionCanvas::SetMax
void SetMax(double max)
Definition: QmitkTransferFunctionCanvas.h:41
MitkQtWidgetsExtExports.h
QmitkTransferFunctionCanvas::SetMin
void SetMin(double min)
Definition: QmitkTransferFunctionCanvas.h:34
QmitkColorTransferFunctionCanvas::GetFunctionSize
int GetFunctionSize() override
Definition: QmitkColorTransferFunctionCanvas.h:60
QmitkColorTransferFunctionCanvas::RemoveAllFunctionPoints
void RemoveAllFunctionPoints()
Definition: QmitkColorTransferFunctionCanvas.h:83
QmitkColorTransferFunctionCanvas::RemoveFunctionPoint
void RemoveFunctionPoint(double x) override
Definition: QmitkColorTransferFunctionCanvas.h:48