Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkToFVisualisationSettingsWidget.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 (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 
14 
15 #include <mitkTransferFunction.h>
18 
19 //QT headers
20 #include <QString>
22 #include <mitkTransferFunction.h>
23 
24 const std::string QmitkToFVisualisationSettingsWidget::VIEW_ID = "org.mitk.views.qmitktofvisualisationsettingswidget";
25 
26 QmitkToFVisualisationSettingsWidget::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 {
40  CreateQtPartControl(this);
41 }
42 
44 {
45 }
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());
86 }
87 
89 {
90  m_Controls->m_RangeSlider->setMaximum(m_Controls->m_RangeSliderMaxEdit->text().toInt());
91  UpdateRanges();
92  m_Controls->m_ColorTransferFunctionCanvas->update();
93 }
94 
96 {
97  m_Controls->m_RangeSlider->setMinimum(m_Controls->m_RangeSliderMinEdit->text().toInt());
98  UpdateRanges();
99  m_Controls->m_ColorTransferFunctionCanvas->update();
100 }
101 
102 void QmitkToFVisualisationSettingsWidget::OnSpanChanged(int /*lower*/, int /*upper*/)
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 
126 void QmitkToFVisualisationSettingsWidget::UpdateSurfaceProperty()
127 {
128  if(this->m_MitkSurfaceNode.IsNotNull())
129  {
131  transferFunction->SetColorTransferFunction(this->GetSelectedColorTransferFunction());
132 
133  this->m_MitkSurfaceNode->SetProperty("Surface.TransferFunction", mitk::TransferFunctionProperty::New(transferFunction));
134  }
135 }
136 
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 
271 void 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 
293 void 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 );
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 );
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 );
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 
377 {
378  return this->m_Widget1ColorTransferFunction;
379 }
380 
382 {
383  return this->m_Widget2ColorTransferFunction;
384 }
385 
387 {
388  return this->m_Widget3ColorTransferFunction;
389 }
390 
392 {
393  int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
394  if (currentWidgetIndex==0)
395  {
396  return this->m_Widget1ColorTransferFunction;
397  }
398  else if (currentWidgetIndex==1)
399  {
400  return this->m_Widget2ColorTransferFunction;
401  }
402  else if (currentWidgetIndex==2)
403  {
404  return this->m_Widget3ColorTransferFunction;
405  }
406  else
407  {
408  return this->m_Widget3ColorTransferFunction;
409  }
410 }
411 
413 {
414  return this->m_Controls->m_SelectWidgetCombobox->currentIndex();
415 }
void UpdateCanvas()
Invokes an update of the ColorTransferFunctionCanvas. Called when the ColorTransferFunction has chang...
int m_Widget3TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 3 (intensity im...
#define MITK_INFO
Definition: mitkLogMacros.h:18
void OnWidgetSelected(int index)
Updates the GUI according to the widget / image selection.
void OnSpanChanged(int lower, int upper)
Slot called when the range span has changed.
mitk::DataNode::Pointer m_MitkSurfaceNode
DataNode holding the surface.
Ui::QmitkToFVisualisationSettingsWidgetControls * m_Controls
mitk::DataNode::Pointer m_MitkDistanceImageNode
DataNode holding the range image of the ToF camera as set by Initialize()
vtkColorTransferFunction * m_Widget3ColorTransferFunction
vtkColorTransferFunction of widget 3 (intensity) that can be used to define a TransferFunctionPropert...
int m_RangeSliderMin
Minimal value of the transfer function range. Initialized to the minimal value of the corresponding i...
static RenderingManager * GetInstance()
QmitkToFVisualisationSettingsWidget(QWidget *p=nullptr, Qt::WindowFlags f1=nullptr)
vtkColorTransferFunction * GetWidget2ColorTransferFunction()
Access the color transfer function of widget 2 (distance image)
Image class for storing images.
Definition: mitkImage.h:72
void UpdateRanges()
Resets the ColorTransferFunctionCanvas according to the lower and upper value of the RangeSlider...
vtkColorTransferFunction * m_Widget1ColorTransferFunction
vtkColorTransferFunction of widget 1 (distance) that can be used to define a TransferFunctionProperty...
static Pointer New()
void OnRangeSliderMinChanged()
Slot called when the line edit of the minimal value of the range slider has changed. Leads to an update of the range slider.
int GetSelectedImageIndex()
Return the index of the selected image: 0 = Distance, 1 = Amplitude, 2 = Intensity.
static T max(T x, T y)
Definition: svm.cpp:56
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
int m_RangeSliderMax
Maximal value of the transfer function range. Initialized to the maximal value of the corresponding i...
void OnTransferFunctionReset()
Resets the transfer function according to the currently selected widget / image.
static T min(T x, T y)
Definition: svm.cpp:53
int m_Widget2TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 2 (amplitude im...
void OnRangeSliderMaxChanged()
Slot called when the line edit of the maximal value of the range slider has changed. Leads to an update of the range slider.
vtkColorTransferFunction * GetWidget1ColorTransferFunction()
Access the color transfer function of widget 1 (distance image)
mitk::DataNode::Pointer m_MitkIntensityImageNode
DataNode holding the intensity image of the ToF camera as set by Initialize()
void OnResetSlider()
Slot invoking a reset of the RangeSlider to the minimal and maximal values of the according image...
vtkColorTransferFunction * m_Widget2ColorTransferFunction
vtkColorTransferFunction of widget 2 (amplitude) that can be used to define a TransferFunctionPropert...
mitk::DataNode::Pointer m_MitkAmplitudeImageNode
DataNode holding the amplitude image of the ToF camera as set by Initialize()
int m_Widget1TransferFunctionType
member holding the type of the transfer function applied to the image shown in widget 1 (distance ima...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
void OnTransferFunctionTypeSelected(int index)
Sets the TransferFunctionType members according to the selection of the widget and the transfer type...
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
vtkColorTransferFunction * GetWidget3ColorTransferFunction()
Access the color transfer function of widget 3 (distance image)
vtkColorTransferFunction * GetSelectedColorTransferFunction()
Access the color transfer of the currently selected widget.