Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkToFSurfaceGenerationWidget.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>
21 
22 //QT headers
23 #include <QString>
25 #include <mitkRenderingManager.h>
26 #include <vtkCamera.h>
27 
28 const std::string QmitkToFSurfaceGenerationWidget::VIEW_ID = "org.mitk.views.qmitktofsurfacegenerationwidget";
29 
30 QmitkToFSurfaceGenerationWidget::QmitkToFSurfaceGenerationWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
31 , m_Controls(NULL),
32  m_ToFDistanceImageToSurfaceFilter(NULL),
33  m_ToFImageGrabber(NULL),
34  m_CameraIntrinsics(NULL),
35  m_Active(false)
36 {
37  CreateQtPartControl(this);
38 }
39 
41 {
42 }
43 
45 {
46  if (!m_Controls)
47  {
48  // create GUI widgets
49  m_Controls = new Ui::QmitkToFSurfaceGenerationWidgetControls;
50  m_Controls->setupUi(parent);
51  this->CreateConnections();
53  }
54 }
55 
57 {
58  if ( m_Controls )
59  {
60  connect( (QObject*)(m_Controls->m_Compute3DDataCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnCompute3DDataCheckboxChecked(bool)) );
61  connect( (QObject*)(m_Controls->m_DistanceColorMapCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnDistanceColorMapCheckBoxChecked(bool)) );
62  connect( (QObject*)(m_Controls->m_RGBTextureCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnRGBTextureCheckBoxChecked(bool)) );
63  connect( (QObject*)(m_Controls->m_TriangulationThresholdSpinbox), SIGNAL(valueChanged(double)), this, SLOT(OnTriangulationThresholdSpinBoxChanged()) );
64  connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptionsCheckboxChecked(bool)) );
65  connect( (QObject*)(m_Controls->m_RepresentationCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnRepresentationChanged(int)) );
66  connect( (QObject*)(m_Controls->m_ReconstructionCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnReconstructionChanged(int)) );
67  }
68 }
69 
71 {
72  return m_ToFDistanceImageToSurfaceFilter;
73 }
74 
76 {
77  this->m_Controls->m_TextureGroupBox->setVisible(checked);
78  this->m_Controls->m_TriangulationThresholdSpinbox->setVisible(checked);
79  this->m_Controls->m_ReconstructionCombobox->setVisible(checked);
80  this->m_Controls->m_RepresentationCombobox->setVisible(checked);
81  this->m_Controls->label->setVisible(checked);
82  this->m_Controls->label_2->setVisible(checked);
83  this->m_Controls->label_3->setVisible(checked);
84 }
85 
90  vtkSmartPointer<vtkCamera> camera,
91  bool generateSurface,
92  bool showAdvancedOptions)
93 {
94  m_ToFDistanceImageToSurfaceFilter = filter;
95  m_ToFImageGrabber = grabber;
96  m_CameraIntrinsics = intrinsics;
97  m_Active = true;
98  m_Camera3d = camera;
99 
100  bool hasSurface = false;
101  m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
102  if(hasSurface)
103  {
104  this->m_Surface = mitk::Surface::New();
105  }
106  else
107  {
108  this->m_Surface = this->m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
109  }
110 
111  m_SurfaceNode = surface;
112  m_SurfaceNode->SetData(m_Surface);
113 
114  this->FindReconstructionModeProperty();
115  m_Controls->m_ShowAdvancedOptionsCheckbox->setChecked(showAdvancedOptions);
116  this->OnShowAdvancedOptionsCheckboxChecked(showAdvancedOptions);
117  m_Controls->m_Compute3DDataCheckbox->setChecked(generateSurface);
118 }
119 
121 {
122  if(!m_Active)
123  {
124  MITK_ERROR << "QmitkToFSurfaceGenerationWidget is not active - please call QmitkToFSurfaceGenerationWidget::Initialize() first";
125  }
126  return m_Active;
127 }
128 
130 {
131  if(IsActive())
132  {
133  this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
134  this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
135  }
136 }
137 
139 {
140  if(IsActive())
141  {
143  switch (index)
144  {
145  case 0:
146  {
148  break;
149  }
150  case 1:
151  {
153  break;
154  }
155  case 2:
156  {
158  break;
159  }
160  default:
161  {
162  MITK_ERROR << "ReconstructionModeType does not exist or is not known in QmitkToFSurfaceGenerationWidget.";
163  break;
164  }
165  }
166  this->m_ToFDistanceImageToSurfaceFilter->SetReconstructionMode( type );
167  }
168 }
169 
171 {
172  if(IsActive())
173  {
174  bool generateTriangularMesh = false; //PointCloud case
175  if( index == 0) //Surface case
176  {
177  generateTriangularMesh = true;
178  }
179  this->m_ToFDistanceImageToSurfaceFilter->SetGenerateTriangularMesh(generateTriangularMesh);
180  this->m_ToFImageGrabber->GetCameraDevice()->SetBoolProperty("GenerateTriangularMesh", generateTriangularMesh);
181 
182  this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
183  this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
184  this->m_Controls->m_TriangulationThresholdSpinbox->setEnabled(generateTriangularMesh);
185  }
186 }
187 
189 {
190  if(IsActive())
191  {
192  if(m_ToFImageGrabber->GetBoolProperty("HasRGBImage"))
193  {
194  if (checked)
195  {
196  // enable texture
197  this->m_SurfaceNode->SetProperty("Surface.Texture",mitk::SmartPointerProperty::New(this->m_ToFImageGrabber->GetOutput(3)));
198  } else {
199  // disable texture
200  this->m_SurfaceNode->GetPropertyList()->DeleteProperty("Surface.Texture");
201  }
202  }
203  }
204 }
205 
207 {
208  if(m_SurfaceNode.IsNotNull())
209  {
210  this->m_SurfaceNode->SetBoolProperty("scalar visibility", checked);
211  }
212 }
213 
215 {
216  if(IsActive())
217  {
218  //##### Code for surface #####
219  if (m_Controls->m_Compute3DDataCheckbox->isChecked())
220  {
221  bool hasSurface = false;
222  this->m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
223  if(hasSurface)
224  {
225  mitk::SmartPointerProperty::Pointer surfaceProp = dynamic_cast< mitk::SmartPointerProperty * >(this->m_ToFImageGrabber->GetCameraDevice()->GetProperty("ToFSurface"));
226  this->m_Surface->SetVtkPolyData( dynamic_cast< mitk::Surface* >( surfaceProp->GetSmartPointer().GetPointer() )->GetVtkPolyData() );
227  }
228  else
229  {
230  this->m_Surface = m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
231  }
232 
233  //update pipeline
234  this->m_Surface->Update();
235  return true;
236  }
237  //##### End code for surface #####
238  }
239  return false;
240 }
241 
243 {
244  if(checked)
245  {
246  //initialize the surface once
247  MITK_DEBUG << "OnSurfaceCheckboxChecked true";
248  this->m_SurfaceNode->SetData(this->m_Surface);
249 
250  this->OnRepresentationChanged(m_Controls->m_RepresentationCombobox->currentIndex());
251 
252  //we need to initialize (reinit) the surface, to make it fit into the renderwindow
254  this->m_Surface->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS, true);
255 
256  // correctly place the vtk camera for appropriate surface rendering
257  //1m distance to camera should be a nice default value for most cameras
258  m_Camera3d->SetPosition(0,0,0);
259  m_Camera3d->SetViewUp(0,-1,0);
260  m_Camera3d->SetFocalPoint(0,0,1);
261  if (this->m_CameraIntrinsics.IsNotNull())
262  {
263  // compute view angle from camera intrinsics
264  m_Camera3d->SetViewAngle(mitk::ToFProcessingCommon::CalculateViewAngle(m_CameraIntrinsics,m_ToFImageGrabber->GetCaptureWidth()));
265  }
266  else
267  {
268  m_Camera3d->SetViewAngle(45);
269  }
270  m_Camera3d->SetClippingRange(1, 10000);
271  }
272 }
273 
274 void QmitkToFSurfaceGenerationWidget::FindReconstructionModeProperty()
275 {
276  bool KinectReconstructionMode = false;
277  m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("KinectReconstructionMode",KinectReconstructionMode);
278  if(KinectReconstructionMode)
279  {
280  //set the reconstruction mode for kinect
281  this->m_ToFDistanceImageToSurfaceFilter->SetReconstructionMode(mitk::ToFDistanceImageToSurfaceFilter::Kinect);
282  m_Controls->m_ReconstructionCombobox->setDisabled(true);
283  m_Controls->m_ReconstructionCombobox->setCurrentIndex(2);
284  }
285  else
286  {
287  m_Controls->m_ReconstructionCombobox->setEnabled(true);
288  }
289 }
290 
292 {
293  return m_Surface;
294 }
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool preserveRoughOrientationInWorldSpace=false)
QmitkToFSurfaceGenerationWidget(QWidget *p=0, Qt::WindowFlags f1=0)
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
mitk::Surface::Pointer GetSurface()
GetSurface Get the generated surface.
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
ReconstructionModeType
The ReconstructionModeType enum: Defines the reconstruction mode, if using no interpixeldistances and...
static ToFScalarType CalculateViewAngle(mitk::CameraIntrinsics::Pointer intrinsics, unsigned int dimX)
Calculates the horizontal view angle of the camera with the given intrinsics.
bool IsActive()
IsActive Check if the widget was initialized correctly.
void OnReconstructionChanged(int index)
OnReconstructionChanged Change the reconstruction mode of the ToFDistanceImageToSurfaceFilter.
Property containing a smart-pointer.
void OnTriangulationThresholdSpinBoxChanged()
Slot trigged from the triangulation threshold spin box. Changed the threshold for connecting a vertex...
void OnRGBTextureCheckBoxChecked(bool checked)
OnRGBTextureCheckBoxChecked Put the RGB image as texture on the generated surface/point cloud...
mitk::ToFDistanceImageToSurfaceFilter::Pointer GetToFDistanceImageToSurfaceFilter()
GetToFDistanceImageToSurfaceFilter Get the internally used surface generation filter.
static RenderingManager * GetInstance()
virtual void CreateQtPartControl(QWidget *parent)
void OnCompute3DDataCheckboxChecked(bool checked)
OnCompute3DDataCheckboxChecked Slot beeing called, if the "surface"-checkbox is clicked. This method initializes the surface once, if it is necessary.
void OnDistanceColorMapCheckBoxChecked(bool checked)
OnDistanceColorMapCheckBoxChecked Show the distance color mapping (vtkColorTransferFunction) on the s...
bool UpdateSurface()
UpdateSurface Generate new surface data according to the device properties.
Ui::QmitkToFSurfaceGenerationWidgetControls * m_Controls
void Initialize(mitk::ToFDistanceImageToSurfaceFilter::Pointer filter, mitk::ToFImageGrabber::Pointer grabber, mitk::CameraIntrinsics::Pointer intrinsics, mitk::DataNode::Pointer surface, vtkSmartPointer< vtkCamera > camera, bool generateSurface=false, bool showAdvancedOptions=true)
Initialize Initialize the surface generation widget.
void OnRepresentationChanged(int index)
OnRepresentationChanged Change the representation of the surface. In other words: disable/enable tria...
static Pointer New()
void OnShowAdvancedOptionsCheckboxChecked(bool checked)
OnShowAdvancedOptionsCheckboxChecked Show/hide advanced options.