Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
19 #include <mitkTransferFunction.h>
22 
23 //QT headers
24 #include <QString>
26 #include <mitkTransferFunction.h>
27 
28 const std::string QmitkToFVisualisationSettingsWidget::VIEW_ID = "org.mitk.views.qmitktofvisualisationsettingswidget";
29 
30 QmitkToFVisualisationSettingsWidget::QmitkToFVisualisationSettingsWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
31 , m_Controls(nullptr)
32 , m_RangeSliderMin(0)
33 , m_RangeSliderMax(0)
34 , m_MitkDistanceImageNode(nullptr)
35 , m_MitkAmplitudeImageNode(nullptr)
36 , m_MitkIntensityImageNode(nullptr)
37 , m_Widget1ColorTransferFunction(nullptr)
38 , m_Widget2ColorTransferFunction(nullptr)
39 , m_Widget3ColorTransferFunction(nullptr)
40 , m_Widget1TransferFunctionType(1)
41 , m_Widget2TransferFunctionType(0)
42 , m_Widget3TransferFunctionType(0)
43 {
44  CreateQtPartControl(this);
45 }
46 
48 {
49 }
50 
52 {
53  if (!m_Controls)
54  {
55  // create GUI widgets
56  m_Controls = new Ui::QmitkToFVisualisationSettingsWidgetControls;
57  m_Controls->setupUi(parent);
58  this->CreateConnections();
59  }
60 }
61 
63 {
64  if ( m_Controls )
65  {
66  connect( (QObject*)(m_Controls->m_SelectWidgetCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnWidgetSelected(int)) );
67  connect( (QObject*)(m_Controls->m_SelectTransferFunctionTypeCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnTransferFunctionTypeSelected(int)) );
68  connect( (QObject*)(m_Controls->m_TransferFunctionResetButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnTransferFunctionReset()) );
69  connect(m_Controls->m_XEditColor, SIGNAL(returnPressed()), this, SLOT(OnSetXValueColor()));
70  connect(m_Controls->m_RangeSliderMaxEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMaxChanged()));
71  connect(m_Controls->m_RangeSliderMinEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMinChanged()));
72  connect(m_Controls->m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider()));
73  connect(m_Controls->m_RangeSlider, SIGNAL(spanChanged(int, int) ),this, SLOT( OnSpanChanged(int , int ) ));
74  connect(m_Controls->m_AdvancedOptionsCheckbox, SIGNAL(toggled(bool) ),this, SLOT( OnShowAdvancedOptionsCheckboxChecked(bool) ));
75 
76  m_Controls->m_RangeSlider->setMaximum(2048);
77  m_Controls->m_RangeSlider->setMinimum(-2048);
78 
79  m_Controls->m_ColorTransferFunctionCanvas->SetQLineEdits(m_Controls->m_XEditColor, nullptr);
80  m_Controls->m_ColorTransferFunctionCanvas->SetTitle(""/*"Value -> Grayscale/Color"*/);
81 
83  }
84 }
85 
87 {
88  m_Controls->m_ColorTransferFunctionCanvas->SetX(m_Controls->m_XEditColor->text().toFloat());
90 }
91 
93 {
94  m_Controls->m_RangeSlider->setMaximum(m_Controls->m_RangeSliderMaxEdit->text().toInt());
95  UpdateRanges();
96  m_Controls->m_ColorTransferFunctionCanvas->update();
97 }
98 
100 {
101  m_Controls->m_RangeSlider->setMinimum(m_Controls->m_RangeSliderMinEdit->text().toInt());
102  UpdateRanges();
103  m_Controls->m_ColorTransferFunctionCanvas->update();
104 }
105 
106 void QmitkToFVisualisationSettingsWidget::OnSpanChanged(int /*lower*/, int /*upper*/)
107 {
108  UpdateRanges();
109  m_Controls->m_ColorTransferFunctionCanvas->update();
110 }
111 
113 {
114  m_Controls->m_RangeSlider->setMaximumValue(m_RangeSliderMax);
115  m_Controls->m_RangeSlider->setMinimumValue(m_RangeSliderMin);
116 
117  UpdateRanges();
118  m_Controls->m_ColorTransferFunctionCanvas->update();
119 }
120 
122 {
123  int lower = m_Controls->m_RangeSlider->minimumValue();
124  int upper = m_Controls->m_RangeSlider->maximumValue();
125 
126  m_Controls->m_ColorTransferFunctionCanvas->SetMin(lower);
127  m_Controls->m_ColorTransferFunctionCanvas->SetMax(upper);
128 }
129 
130 void QmitkToFVisualisationSettingsWidget::UpdateSurfaceProperty()
131 {
132  if(this->m_MitkSurfaceNode.IsNotNull())
133  {
135  transferFunction->SetColorTransferFunction(this->GetSelectedColorTransferFunction());
136 
137  this->m_MitkSurfaceNode->SetProperty("Surface.TransferFunction", mitk::TransferFunctionProperty::New(transferFunction));
138  }
139 }
140 
142  mitk::DataNode* intensityImageNode, mitk::DataNode* surfaceNode)
143 {
144  this->m_MitkDistanceImageNode = distanceImageNode;
145  this->m_MitkAmplitudeImageNode = amplitudeImageNode;
146  this->m_MitkIntensityImageNode = intensityImageNode;
147  this->m_MitkSurfaceNode = surfaceNode;
148 
149  // Initialize transfer functions for image DataNodes such that:
150  // Widget1 (Distance): color from red (2nd min) to blue (max)
151  // Widget2 (Amplitude): grey value from black (2nd min) to white (max)
152  // Widget3 (Intensity): grey value from black (2nd min) to white (max)
154  {
155  m_Controls->m_ColorTransferFunctionCanvas->setEnabled(false);
156  }
157  else
158  {
159  m_Controls->m_ColorTransferFunctionCanvas->setEnabled(true);
160  int numberOfImages = 0;
162  {
165  m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType);
166  numberOfImages++;
167  }
169  {
172  numberOfImages++;
173  }
175  {
178  numberOfImages++;
179  }
180  m_Controls->m_SelectWidgetCombobox->setMaxCount(numberOfImages);
181  }
182  this->ReinitTransferFunction(0,1);
183  this->ReinitTransferFunction(1,0);
184  this->ReinitTransferFunction(2,0);
185 }
186 
188 {
189  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->GetSelectedColorTransferFunction() );
190  UpdateRanges();
191  m_Controls->m_ColorTransferFunctionCanvas->update();
192 }
193 
195 {
196  int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
197  if (currentWidgetIndex == 0)
198  {
199  this->m_Widget1TransferFunctionType = index;
200  }
201  else if (currentWidgetIndex == 1)
202  {
203  this->m_Widget2TransferFunctionType = index;
204  }
205  else if (currentWidgetIndex == 2)
206  {
207  this->m_Widget3TransferFunctionType = index;
208  }
209  else
210  {
211  return;
212  }
213  this->UpdateSurfaceProperty();
214 }
215 
217 {
218  this->m_Controls->m_MappingGroupBox->setVisible(checked);
219  this->m_Controls->m_SelectTransferFunctionTypeCombobox->setVisible(checked);
220  this->m_Controls->m_SelectWidgetCombobox->setVisible(checked);
221  this->m_Controls->m_TransferFunctionResetButton->setVisible(checked);
222 }
223 
225 {
226  int currentWidgetIndex = index;
227 
228  double valMin[6];
229  double valMax[6];
230  int numPoints;
231  if (currentWidgetIndex == 0)
232  {
233  m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType);
234  numPoints = this->m_Widget1ColorTransferFunction->GetSize();
235  this->m_Widget1ColorTransferFunction->GetNodeValue( 0, valMin );
236  this->m_Widget1ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
237  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction );
238  }
239  else if (currentWidgetIndex == 1)
240  {
241  m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget2TransferFunctionType);
242  numPoints = this->m_Widget2ColorTransferFunction->GetSize();
243  this->m_Widget2ColorTransferFunction->GetNodeValue( 0, valMin );
244  this->m_Widget2ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
245  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction );
246  }
247  else if (currentWidgetIndex == 2)
248  {
249  m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget3TransferFunctionType);
250  numPoints = this->m_Widget3ColorTransferFunction->GetSize();
251  this->m_Widget3ColorTransferFunction->GetNodeValue( 0, valMin );
252  this->m_Widget3ColorTransferFunction->GetNodeValue( numPoints-1, valMax );
253  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction );
254  }
255  else if (currentWidgetIndex == 3)
256  {
257  }
258  else
259  {
260  return;
261  }
262  m_RangeSliderMin = valMin[0];
263  m_RangeSliderMax = valMax[0];
264  int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1;
265  m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border);
266  m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border);
267  m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border));
268  m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border));
269  m_Controls->m_RangeSlider->setRange( m_RangeSliderMin, m_RangeSliderMax);
270  UpdateRanges();
271  m_Controls->m_ColorTransferFunctionCanvas->update();
272  this->UpdateSurfaceProperty();
273 }
274 
275 void QmitkToFVisualisationSettingsWidget::ResetTransferFunction(vtkColorTransferFunction* colorTransferFunction, int type, double min, double max)
276 {
277  colorTransferFunction->RemoveAllPoints();
278  if (type == 0)
279  {
280  colorTransferFunction->AddRGBPoint(min, 0, 0, 0);
281  colorTransferFunction->AddRGBPoint(max, 1, 1, 1);
282  }
283  else
284  {
285  if (min>0.01)
286  {
287  colorTransferFunction->AddRGBPoint(0.0, 0, 0, 0);
288  colorTransferFunction->AddRGBPoint(min-0.01, 0, 0, 0);
289  }
290  colorTransferFunction->AddRGBPoint(min, 1, 0, 0);
291  colorTransferFunction->AddRGBPoint(min+(max-min)/2, 1, 1, 0);
292  colorTransferFunction->AddRGBPoint(max, 0, 0, 1);
293  }
294  colorTransferFunction->SetColorSpaceToHSV();
295 }
296 
297 void QmitkToFVisualisationSettingsWidget::ReinitTransferFunction(int widget, int type)
298 {
299  switch (widget)
300  {
301  case 0:
302  {
303  mitk::Image::Pointer distanceImage = dynamic_cast<mitk::Image*>(m_MitkDistanceImageNode->GetData());
304  // use second minimum to draw 0 values (that are usually segmented) black
305  m_RangeSliderMin = distanceImage->GetStatistics()->GetScalarValue2ndMin();
306  m_RangeSliderMax = distanceImage->GetStatistics()->GetScalarValueMax();
307  MITK_INFO<<"Distance Min: "<<m_RangeSliderMin;
308  MITK_INFO<<"Distance Max: "<<m_RangeSliderMax;
309  ResetTransferFunction(this->m_Widget1ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
310  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction );
312  tf1->SetColorTransferFunction( m_Widget1ColorTransferFunction );
313  m_MitkDistanceImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf1));
314  break;
315  }
316  case 1:
317  {
319  {
320  mitk::Image::Pointer amplitudeImage = dynamic_cast<mitk::Image*>(m_MitkAmplitudeImageNode->GetData());
321  if (amplitudeImage.IsNotNull())
322  {
323  m_RangeSliderMin = amplitudeImage->GetStatistics()->GetScalarValueMin();
324  m_RangeSliderMax = amplitudeImage->GetStatistics()->GetScalarValueMax();
325  MITK_INFO<<"Amplitude Min: "<<m_RangeSliderMin;
326  MITK_INFO<<"Amplitude Max: "<<m_RangeSliderMax;
327  ResetTransferFunction(this->m_Widget2ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
328  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction );
330  tf2->SetColorTransferFunction( m_Widget2ColorTransferFunction );
331  m_MitkAmplitudeImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf2));
332  }
333  }
334  break;
335  }
336  case 2:
337  {
339  {
340  mitk::Image::Pointer intensityImage = dynamic_cast<mitk::Image*>(m_MitkIntensityImageNode->GetData());
341  if (intensityImage.IsNotNull())
342  {
343  m_RangeSliderMin = intensityImage->GetStatistics()->GetScalarValueMin();
344  m_RangeSliderMax = intensityImage->GetStatistics()->GetScalarValueMax();
345  MITK_INFO<<"Intensity Min: "<<m_RangeSliderMin;
346  MITK_INFO<<"Intensity Max: "<<m_RangeSliderMax;
347  ResetTransferFunction(this->m_Widget3ColorTransferFunction, type, this->m_RangeSliderMin, this->m_RangeSliderMax);
348  m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction );
350  tf3->SetColorTransferFunction( m_Widget3ColorTransferFunction );
351  m_MitkIntensityImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf3));
352  }
353  }
354  break;
355  }
356  default:
357  break;
358  }
359  this->UpdateSurfaceProperty();
360 }
361 
363 {
364  int currentTransferFunctionTypeIndex = m_Controls->m_SelectTransferFunctionTypeCombobox->currentIndex();
365  int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
366 
367  this->ReinitTransferFunction(currentWidgetIndex,currentTransferFunctionTypeIndex);
368 
369  int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1;
370  m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border);
371  m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border);
372  m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border));
373  m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border));
374  m_Controls->m_RangeSlider->setRange( m_RangeSliderMin, m_RangeSliderMax);
375  UpdateRanges();
376  m_Controls->m_ColorTransferFunctionCanvas->update();
377  this->UpdateSurfaceProperty();
378 }
379 
381 {
382  return this->m_Widget1ColorTransferFunction;
383 }
384 
386 {
387  return this->m_Widget2ColorTransferFunction;
388 }
389 
391 {
392  return this->m_Widget3ColorTransferFunction;
393 }
394 
396 {
397  int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex();
398  if (currentWidgetIndex==0)
399  {
400  return this->m_Widget1ColorTransferFunction;
401  }
402  else if (currentWidgetIndex==1)
403  {
404  return this->m_Widget2ColorTransferFunction;
405  }
406  else if (currentWidgetIndex==2)
407  {
408  return this->m_Widget3ColorTransferFunction;
409  }
410  else
411  {
412  return this->m_Widget3ColorTransferFunction;
413  }
414 }
415 
417 {
418  return this->m_Controls->m_SelectWidgetCombobox->currentIndex();
419 }
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:22
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:76
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:70
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:67
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:66
vtkColorTransferFunction * GetWidget3ColorTransferFunction()
Access the color transfer function of widget 3 (distance image)
vtkColorTransferFunction * GetSelectedColorTransferFunction()
Access the color transfer of the currently selected widget.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.