MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkToFVisualisationSettingsWidget.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15#include <mitkTransferFunction.h>
16#include <mitkTransferFunctionProperty.h>
17#include <mitkImageStatisticsHolder.h>
18
19//QT headers
20#include <QString>
21#include <mitkTransferFunctionProperty.h>
22#include <mitkTransferFunction.h>
23
24const std::string QmitkToFVisualisationSettingsWidget::VIEW_ID = "org.mitk.views.qmitktofvisualisationsettingswidget";
25
26QmitkToFVisualisationSettingsWidget::QmitkToFVisualisationSettingsWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
27, m_Controls(nullptr)
28, m_RangeSliderMin(0)
29, m_RangeSliderMax(0)
30, m_MitkDistanceImageNode(nullptr)
31, m_MitkAmplitudeImageNode(nullptr)
32, m_MitkIntensityImageNode(nullptr)
33, m_Widget1ColorTransferFunction(nullptr)
34, m_Widget2ColorTransferFunction(nullptr)
35, m_Widget3ColorTransferFunction(nullptr)
36, m_Widget1TransferFunctionType(1)
37, m_Widget2TransferFunctionType(0)
38, m_Widget3TransferFunctionType(0)
39{
41}
42
46
48{
49 if (!m_Controls)
50 {
51 // create GUI widgets
52 m_Controls = new Ui::QmitkToFVisualisationSettingsWidgetControls;
53 m_Controls->setupUi(parent);
54 this->CreateConnections();
55 }
56}
57
59{
60 if ( m_Controls )
61 {
62 connect( (QObject*)(m_Controls->m_SelectWidgetCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnWidgetSelected(int)) );
63 connect( (QObject*)(m_Controls->m_SelectTransferFunctionTypeCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnTransferFunctionTypeSelected(int)) );
64 connect( (QObject*)(m_Controls->m_TransferFunctionResetButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnTransferFunctionReset()) );
65 connect(m_Controls->m_XEditColor, SIGNAL(returnPressed()), this, SLOT(OnSetXValueColor()));
66 connect(m_Controls->m_RangeSliderMaxEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMaxChanged()));
67 connect(m_Controls->m_RangeSliderMinEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMinChanged()));
68 connect(m_Controls->m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider()));
69 connect(m_Controls->m_RangeSlider, SIGNAL(valuesChanged(int, int) ),this, SLOT( OnSpanChanged(int , int ) ));
70 connect(m_Controls->m_AdvancedOptionsCheckbox, SIGNAL(toggled(bool) ),this, SLOT( OnShowAdvancedOptionsCheckboxChecked(bool) ));
71
72 m_Controls->m_RangeSlider->setMaximum(2048);
73 m_Controls->m_RangeSlider->setMinimum(-2048);
74
75 m_Controls->m_ColorTransferFunctionCanvas->SetQLineEdits(m_Controls->m_XEditColor, nullptr);
76 m_Controls->m_ColorTransferFunctionCanvas->SetTitle(""/*"Value -> Grayscale/Color"*/);
77
79 }
80}
81
83{
84 m_Controls->m_ColorTransferFunctionCanvas->SetX(m_Controls->m_XEditColor->text().toFloat());
85 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
86}
87
89{
90 m_Controls->m_RangeSlider->setMaximum(m_Controls->m_RangeSliderMaxEdit->text().toInt());
92 m_Controls->m_ColorTransferFunctionCanvas->update();
93}
94
96{
97 m_Controls->m_RangeSlider->setMinimum(m_Controls->m_RangeSliderMinEdit->text().toInt());
99 m_Controls->m_ColorTransferFunctionCanvas->update();
100}
101
103{
104 UpdateRanges();
105 m_Controls->m_ColorTransferFunctionCanvas->update();
106}
107
109{
110 m_Controls->m_RangeSlider->setMaximumValue(m_RangeSliderMax);
111 m_Controls->m_RangeSlider->setMinimumValue(m_RangeSliderMin);
112
113 UpdateRanges();
114 m_Controls->m_ColorTransferFunctionCanvas->update();
115}
116
118{
119 int lower = m_Controls->m_RangeSlider->minimumValue();
120 int upper = m_Controls->m_RangeSlider->maximumValue();
121
122 m_Controls->m_ColorTransferFunctionCanvas->SetMin(lower);
123 m_Controls->m_ColorTransferFunctionCanvas->SetMax(upper);
124}
125
126void QmitkToFVisualisationSettingsWidget::UpdateSurfaceProperty()
127{
128 if(this->m_MitkSurfaceNode.IsNotNull())
129 {
130 mitk::TransferFunction::Pointer transferFunction = mitk::TransferFunction::New();
131 transferFunction->SetColorTransferFunction(this->GetSelectedColorTransferFunction());
132
133 this->m_MitkSurfaceNode->SetProperty("Surface.TransferFunction", mitk::TransferFunctionProperty::New(transferFunction));
134 }
135}
136
137void QmitkToFVisualisationSettingsWidget::Initialize(mitk::DataNode* distanceImageNode, mitk::DataNode* amplitudeImageNode,
138 mitk::DataNode* intensityImageNode, mitk::DataNode* surfaceNode)
139{
140 this->m_MitkDistanceImageNode = distanceImageNode;
141 this->m_MitkAmplitudeImageNode = amplitudeImageNode;
142 this->m_MitkIntensityImageNode = intensityImageNode;
143 this->m_MitkSurfaceNode = surfaceNode;
144
145 // Initialize transfer functions for image DataNodes such that:
146 // Widget1 (Distance): color from red (2nd min) to blue (max)
147 // Widget2 (Amplitude): grey value from black (2nd min) to white (max)
148 // Widget3 (Intensity): grey value from black (2nd min) to white (max)
150 {
151 m_Controls->m_ColorTransferFunctionCanvas->setEnabled(false);
152 }
153 else
154 {
155 m_Controls->m_ColorTransferFunctionCanvas->setEnabled(true);
156 int numberOfImages = 0;
158 {
159 m_Widget1ColorTransferFunction = vtkColorTransferFunction::New();
161 m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType);
162 numberOfImages++;
163 }
165 {
166 m_Widget2ColorTransferFunction = vtkColorTransferFunction::New();
168 numberOfImages++;
169 }
171 {
172 m_Widget3ColorTransferFunction = vtkColorTransferFunction::New();
174 numberOfImages++;
175 }
176 m_Controls->m_SelectWidgetCombobox->setMaxCount(numberOfImages);
177 }
178 this->ReinitTransferFunction(0,1);
179 this->ReinitTransferFunction(1,0);
180 this->ReinitTransferFunction(2,0);
181}
182
184{
185 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->GetSelectedColorTransferFunction() );
186 UpdateRanges();
187 m_Controls->m_ColorTransferFunctionCanvas->update();
188}
189
191{
192 int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
193 if (currentWidgetIndex == 0)
194 {
195 this->m_Widget1TransferFunctionType = index;
196 }
197 else if (currentWidgetIndex == 1)
198 {
199 this->m_Widget2TransferFunctionType = index;
200 }
201 else if (currentWidgetIndex == 2)
202 {
203 this->m_Widget3TransferFunctionType = index;
204 }
205 else
206 {
207 return;
208 }
209 this->UpdateSurfaceProperty();
210}
211
213{
214 this->m_Controls->m_MappingGroupBox->setVisible(checked);
215 this->m_Controls->m_SelectTransferFunctionTypeCombobox->setVisible(checked);
216 this->m_Controls->m_SelectWidgetCombobox->setVisible(checked);
217 this->m_Controls->m_TransferFunctionResetButton->setVisible(checked);
218}
219
221{
222 int currentWidgetIndex = index;
223
224 double valMin[6];
225 double valMax[6];
226 int numPoints;
227 if (currentWidgetIndex == 0)
228 {
229 m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType);
230 numPoints = this->m_Widget1ColorTransferFunction->GetSize();
231 this->m_Widget1ColorTransferFunction->GetNodeValue( 0, valMin );
232 this->m_Widget1ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
233 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction );
234 }
235 else if (currentWidgetIndex == 1)
236 {
237 m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget2TransferFunctionType);
238 numPoints = this->m_Widget2ColorTransferFunction->GetSize();
239 this->m_Widget2ColorTransferFunction->GetNodeValue( 0, valMin );
240 this->m_Widget2ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
241 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction );
242 }
243 else if (currentWidgetIndex == 2)
244 {
245 m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget3TransferFunctionType);
246 numPoints = this->m_Widget3ColorTransferFunction->GetSize();
247 this->m_Widget3ColorTransferFunction->GetNodeValue( 0, valMin );
248 this->m_Widget3ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
249 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction );
250 }
251 else if (currentWidgetIndex == 3)
252 {
253 }
254 else
255 {
256 return;
257 }
258 m_RangeSliderMin = valMin[0];
259 m_RangeSliderMax = valMax[0];
260 int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1;
261 m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border);
262 m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border);
263 m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border));
264 m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border));
265 m_Controls->m_RangeSlider->setRange( m_RangeSliderMin, m_RangeSliderMax);
266 UpdateRanges();
267 m_Controls->m_ColorTransferFunctionCanvas->update();
268 this->UpdateSurfaceProperty();
269}
270
271void QmitkToFVisualisationSettingsWidget::ResetTransferFunction(vtkColorTransferFunction* colorTransferFunction, int type, double min, double max)
272{
273 colorTransferFunction->RemoveAllPoints();
274 if (type == 0)
275 {
276 colorTransferFunction->AddRGBPoint(min, 0, 0, 0);
277 colorTransferFunction->AddRGBPoint(max, 1, 1, 1);
278 }
279 else
280 {
281 if (min>0.01)
282 {
283 colorTransferFunction->AddRGBPoint(0.0, 0, 0, 0);
284 colorTransferFunction->AddRGBPoint(min-0.01, 0, 0, 0);
285 }
286 colorTransferFunction->AddRGBPoint(min, 1, 0, 0);
287 colorTransferFunction->AddRGBPoint(min+(max-min)/2, 1, 1, 0);
288 colorTransferFunction->AddRGBPoint(max, 0, 0, 1);
289 }
290 colorTransferFunction->SetColorSpaceToHSV();
291}
292
293void QmitkToFVisualisationSettingsWidget::ReinitTransferFunction(int widget, int type)
294{
295 switch (widget)
296 {
297 case 0:
298 {
299 mitk::Image::Pointer distanceImage = dynamic_cast<mitk::Image*>(m_MitkDistanceImageNode->GetData());
300 // use second minimum to draw 0 values (that are usually segmented) black
301 m_RangeSliderMin = distanceImage->GetStatistics()->GetScalarValue2ndMin();
302 m_RangeSliderMax = distanceImage->GetStatistics()->GetScalarValueMax();
303 MITK_INFO<<"Distance Min: "<<m_RangeSliderMin;
304 MITK_INFO<<"Distance Max: "<<m_RangeSliderMax;
305 ResetTransferFunction(this->m_Widget1ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
306 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction );
307 mitk::TransferFunction::Pointer tf1 = mitk::TransferFunction::New();
308 tf1->SetColorTransferFunction( m_Widget1ColorTransferFunction );
309 m_MitkDistanceImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf1));
310 break;
311 }
312 case 1:
313 {
315 {
316 mitk::Image::Pointer amplitudeImage = dynamic_cast<mitk::Image*>(m_MitkAmplitudeImageNode->GetData());
317 if (amplitudeImage.IsNotNull())
318 {
319 m_RangeSliderMin = amplitudeImage->GetStatistics()->GetScalarValueMin();
320 m_RangeSliderMax = amplitudeImage->GetStatistics()->GetScalarValueMax();
321 MITK_INFO<<"Amplitude Min: "<<m_RangeSliderMin;
322 MITK_INFO<<"Amplitude Max: "<<m_RangeSliderMax;
323 ResetTransferFunction(this->m_Widget2ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
324 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction );
325 mitk::TransferFunction::Pointer tf2 = mitk::TransferFunction::New();
326 tf2->SetColorTransferFunction( m_Widget2ColorTransferFunction );
327 m_MitkAmplitudeImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf2));
328 }
329 }
330 break;
331 }
332 case 2:
333 {
335 {
336 mitk::Image::Pointer intensityImage = dynamic_cast<mitk::Image*>(m_MitkIntensityImageNode->GetData());
337 if (intensityImage.IsNotNull())
338 {
339 m_RangeSliderMin = intensityImage->GetStatistics()->GetScalarValueMin();
340 m_RangeSliderMax = intensityImage->GetStatistics()->GetScalarValueMax();
341 MITK_INFO<<"Intensity Min: "<<m_RangeSliderMin;
342 MITK_INFO<<"Intensity Max: "<<m_RangeSliderMax;
343 ResetTransferFunction(this->m_Widget3ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
344 m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction );
345 mitk::TransferFunction::Pointer tf3 = mitk::TransferFunction::New();
346 tf3->SetColorTransferFunction( m_Widget3ColorTransferFunction );
347 m_MitkIntensityImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf3));
348 }
349 }
350 break;
351 }
352 default:
353 break;
354 }
355 this->UpdateSurfaceProperty();
356}
357
359{
360 int currentTransferFunctionTypeIndex = m_Controls->m_SelectTransferFunctionTypeCombobox->currentIndex();
361 int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
362
363 this->ReinitTransferFunction(currentWidgetIndex,currentTransferFunctionTypeIndex);
364
365 int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1;
366 m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border);
367 m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border);
368 m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border));
369 m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border));
370 m_Controls->m_RangeSlider->setRange( m_RangeSliderMin, m_RangeSliderMax);
371 UpdateRanges();
372 m_Controls->m_ColorTransferFunctionCanvas->update();
373 this->UpdateSurfaceProperty();
374}
375
380
385
390
392{
393 int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
394 if (currentWidgetIndex==0)
395 {
397 }
398 else if (currentWidgetIndex==1)
399 {
401 }
402 else if (currentWidgetIndex==2)
403 {
405 }
406 else
407 {
409 }
410}
411
413{
414 return this->m_Controls->m_SelectWidgetCombobox->currentIndex();
415}
void OnResetSlider()
Slot invoking a reset of the RangeSlider to the minimal and maximal values of the according image.
int m_Widget1TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 1 (distance ima...
void OnTransferFunctionReset()
Resets the transfer function according to the currently selected widget / image.
vtkColorTransferFunction * m_Widget1ColorTransferFunction
vtkColorTransferFunction of widget 1 (distance) that can be used to define a TransferFunctionProperty
QmitkToFVisualisationSettingsWidget(QWidget *p=nullptr, Qt::WindowFlags f1={})
mitk::DataNode::Pointer m_MitkDistanceImageNode
DataNode holding the range image of the ToF camera as set by Initialize()
mitk::DataNode::Pointer m_MitkSurfaceNode
DataNode holding the surface.
Ui::QmitkToFVisualisationSettingsWidgetControls * m_Controls
int GetSelectedImageIndex()
Return the index of the selected image: 0 = Distance, 1 = Amplitude, 2 = Intensity.
vtkColorTransferFunction * GetWidget2ColorTransferFunction()
Access the color transfer function of widget 2 (distance image)
vtkColorTransferFunction * GetSelectedColorTransferFunction()
Access the color transfer of the currently selected widget.
int m_Widget2TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 2 (amplitude im...
void OnRangeSliderMinChanged()
Slot called when the line edit of the minimal value of the range slider has changed....
void OnSpanChanged(int lower, int upper)
Slot called when the range span has changed.
mitk::DataNode::Pointer m_MitkAmplitudeImageNode
DataNode holding the amplitude image of the ToF camera as set by Initialize()
vtkColorTransferFunction * GetWidget3ColorTransferFunction()
Access the color transfer function of widget 3 (distance image)
vtkColorTransferFunction * m_Widget2ColorTransferFunction
vtkColorTransferFunction of widget 2 (amplitude) that can be used to define a TransferFunctionPropert...
mitk::DataNode::Pointer m_MitkIntensityImageNode
DataNode holding the intensity image of the ToF camera as set by Initialize()
void OnRangeSliderMaxChanged()
Slot called when the line edit of the maximal value of the range slider has changed....
void OnWidgetSelected(int index)
Updates the GUI according to the widget / image selection.
int m_RangeSliderMax
Maximal value of the transfer function range. Initialized to the maximal value of the corresponding i...
void UpdateCanvas()
Invokes an update of the ColorTransferFunctionCanvas. Called when the ColorTransferFunction has chang...
int m_RangeSliderMin
Minimal value of the transfer function range. Initialized to the minimal value of the corresponding i...
vtkColorTransferFunction * m_Widget3ColorTransferFunction
vtkColorTransferFunction of widget 3 (intensity) that can be used to define a TransferFunctionPropert...
vtkColorTransferFunction * GetWidget1ColorTransferFunction()
Access the color transfer function of widget 1 (distance image)
void UpdateRanges()
Resets the ColorTransferFunctionCanvas according to the lower and upper value of the RangeSlider.
void OnTransferFunctionTypeSelected(int index)
Sets the TransferFunctionType members according to the selection of the widget and the transfer type.
int m_Widget3TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 3 (intensity im...
void Initialize(mitk::DataNode *distanceImageNode=nullptr, mitk::DataNode *amplitudeImageNode=nullptr, mitk::DataNode *intensityImageNode=nullptr, mitk::DataNode *surfaceNode=nullptr)
initialize the widget with the images to be shown