Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkTransferFunctionWidget.cpp
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 
18 
20 
21 QmitkTransferFunctionWidget::QmitkTransferFunctionWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
22 {
23  this->setupUi(this);
24 
25  // signals and slots connections
26  connect(m_XEditScalarOpacity, SIGNAL(textEdited(const QString &)), this, SLOT(SetXValueScalar(const QString &)));
27  connect(m_YEditScalarOpacity, SIGNAL(textEdited(const QString &)), this, SLOT(SetYValueScalar(const QString &)));
28 
29  connect(m_XEditGradientOpacity, SIGNAL(textEdited(const QString &)), this, SLOT(SetXValueGradient(const QString &)));
30  connect(m_YEditGradientOpacity, SIGNAL(textEdited(const QString &)), this, SLOT(SetYValueGradient(const QString &)));
31 
32  connect(m_XEditColor, SIGNAL(textEdited(const QString &)), this, SLOT(SetXValueColor(const QString &)));
33 
34  m_RangeSlider->setMinimum(-2048);
35  m_RangeSlider->setMaximum(2048);
36  connect(m_RangeSlider, SIGNAL(valuesChanged(int, int)), this, SLOT(OnSpanChanged(int, int)));
37 
38  // reset button
39  connect(m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider()));
40 
41  m_ScalarOpacityFunctionCanvas->SetQLineEdits(m_XEditScalarOpacity, m_YEditScalarOpacity);
42  m_GradientOpacityCanvas->SetQLineEdits(m_XEditGradientOpacity, m_YEditGradientOpacity);
43  m_ColorTransferFunctionCanvas->SetQLineEdits(m_XEditColor, nullptr);
44 
45  m_ScalarOpacityFunctionCanvas->SetTitle("Grayvalue -> Opacity");
46  m_GradientOpacityCanvas->SetTitle("Grayvalue/Gradient -> Opacity");
47  m_ColorTransferFunctionCanvas->SetTitle("Grayvalue -> Color");
48 }
49 
51 {
52 }
53 
54 void QmitkTransferFunctionWidget::SetScalarLabel(const QString &scalarLabel)
55 {
56  m_textLabelX->setText(scalarLabel);
57  m_textLabelX_2->setText(scalarLabel);
58  m_textLabelX_3->setText(scalarLabel);
59 
60  m_ScalarOpacityFunctionCanvas->SetTitle(scalarLabel + " -> Opacity");
61  m_GradientOpacityCanvas->SetTitle(scalarLabel + "/Gradient -> Opacity");
62  m_ColorTransferFunctionCanvas->SetTitle(scalarLabel + " -> Color");
63 }
64 
66 {
67  m_ScalarOpacityWidget->setVisible(show);
68 }
69 
71 {
72  m_ColorWidget->setVisible(show);
73 }
74 
76 {
77  m_GradientOpacityWidget->setVisible(show);
78 }
79 
81 {
82  m_ScalarOpacityWidget->setEnabled(enable);
83 }
84 
86 {
87  m_ColorWidget->setEnabled(enable);
88 }
89 
91 {
92  m_GradientOpacityWidget->setEnabled(enable);
93 }
94 
96 {
97  if (node)
98  {
99  tfpToChange = dynamic_cast<mitk::TransferFunctionProperty *>(node->GetProperty("TransferFunction", renderer));
100 
101  if (!tfpToChange)
102  {
103  if (!dynamic_cast<mitk::Image *>(node->GetData()))
104  {
105  MITK_WARN << "QmitkTransferFunctionWidget::SetDataNode called with non-image node";
106  goto turnOff;
107  }
108 
109  node->SetProperty("TransferFunction", tfpToChange = mitk::TransferFunctionProperty::New());
110  }
111 
113 
114  if (mitk::BaseData *data = node->GetData())
115  {
117 
118  m_RangeSliderMin = h->GetMin();
119  m_RangeSliderMax = h->GetMax();
120 
121  m_RangeSlider->blockSignals(true);
122  m_RangeSlider->setMinimum(m_RangeSliderMin);
123  m_RangeSlider->setMaximum(m_RangeSliderMax);
124  m_RangeSlider->setMinimumValue(m_RangeSliderMin);
125  m_RangeSlider->setMaximumValue(m_RangeSliderMax);
126  m_RangeSlider->blockSignals(false);
127 
128  m_ScalarOpacityFunctionCanvas->SetHistogram(h);
129  m_GradientOpacityCanvas->SetHistogram(h);
130  m_ColorTransferFunctionCanvas->SetHistogram(h);
131  }
132 
133  OnUpdateCanvas();
134 
135  return;
136  }
137 
138 turnOff:
139 
140  m_ScalarOpacityFunctionCanvas->setEnabled(false);
141  m_ScalarOpacityFunctionCanvas->SetHistogram(nullptr);
142  m_GradientOpacityCanvas->setEnabled(false);
143  m_GradientOpacityCanvas->SetHistogram(nullptr);
144  m_ColorTransferFunctionCanvas->setEnabled(false);
145  m_ColorTransferFunctionCanvas->SetHistogram(nullptr);
146  tfpToChange = nullptr;
147 }
148 
150 {
151  if (tfpToChange.IsNull())
152  return;
153 
155 
156  if (tf.IsNull())
157  return;
158 
159  m_ScalarOpacityFunctionCanvas->SetPiecewiseFunction(tf->GetScalarOpacityFunction());
160  m_GradientOpacityCanvas->SetPiecewiseFunction(tf->GetGradientOpacityFunction());
161  m_ColorTransferFunctionCanvas->SetColorTransferFunction(tf->GetColorTransferFunction());
162 
163  UpdateRanges();
164 
165  m_ScalarOpacityFunctionCanvas->update();
166  m_GradientOpacityCanvas->update();
167  m_ColorTransferFunctionCanvas->update();
168 }
169 
171 {
172  if (!text.endsWith("."))
173  {
174  m_ScalarOpacityFunctionCanvas->SetX(text.toFloat());
176  }
177 }
178 
180 {
181  if (!text.endsWith("."))
182  {
183  m_ScalarOpacityFunctionCanvas->SetY(text.toFloat());
185  }
186 }
187 
189 {
190  if (!text.endsWith("."))
191  {
192  m_GradientOpacityCanvas->SetX(text.toFloat());
194  }
195 }
196 
198 {
199  if (!text.endsWith("."))
200  {
201  m_GradientOpacityCanvas->SetY(text.toFloat());
203  }
204 }
205 
207 {
208  if (!text.endsWith("."))
209  {
210  m_ColorTransferFunctionCanvas->SetX(text.toFloat());
212  }
213 }
214 
216 {
217  int lower = m_RangeSlider->minimumValue();
218  int upper = m_RangeSlider->maximumValue();
219 
220  m_ScalarOpacityFunctionCanvas->SetMin(lower);
221  m_ScalarOpacityFunctionCanvas->SetMax(upper);
222 
223  m_GradientOpacityCanvas->SetMin(lower);
224  m_GradientOpacityCanvas->SetMax(upper);
225 
226  m_ColorTransferFunctionCanvas->SetMin(lower);
227  m_ColorTransferFunctionCanvas->SetMax(upper);
228 }
229 
231 {
232  UpdateRanges();
233 
234  m_GradientOpacityCanvas->update();
235  m_ColorTransferFunctionCanvas->update();
236  m_ScalarOpacityFunctionCanvas->update();
237 }
238 
240 {
241  m_RangeSlider->blockSignals(true);
242  m_RangeSlider->setMaximumValue(m_RangeSliderMax);
243  m_RangeSlider->setMinimumValue(m_RangeSliderMin);
244  m_RangeSlider->blockSignals(false);
245 
246  UpdateRanges();
247  m_GradientOpacityCanvas->update();
248  m_ColorTransferFunctionCanvas->update();
249  m_ScalarOpacityFunctionCanvas->update();
250 }
The TransferFunctionProperty class Property class for the mitk::TransferFunction. ...
Base of all data objects.
Definition: mitkBaseData.h:39
void SetXValueGradient(const QString text)
Organizes the rendering process.
void OnSpanChanged(int lower, int upper)
virtual double GetMax() const =0
Returns the maximum value of the histogram.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
virtual double GetMin() const =0
Returns the minimal value of the histogram.
#define MITK_WARN
Definition: mitkLogMacros.h:23
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
static RenderingManager * GetInstance()
void SetScalarLabel(const QString &scalarLabel)
void SetYValueGradient(const QString text)
mitk::SimpleHistogramCache histogramCache
QmitkTransferFunctionWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
mitk::TransferFunctionProperty::Pointer tfpToChange
void SetDataNode(mitk::DataNode *node, const mitk::BaseRenderer *renderer=nullptr)
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66