Medical Imaging Interaction Toolkit  2018.4.99-c7ee88da
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 (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>
17 
18 //QT headers
19 #include <QString>
21 #include <mitkRenderingManager.h>
22 #include <vtkCamera.h>
23 
24 const std::string QmitkToFSurfaceGenerationWidget::VIEW_ID = "org.mitk.views.qmitktofsurfacegenerationwidget";
25 
26 QmitkToFSurfaceGenerationWidget::QmitkToFSurfaceGenerationWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
27 , m_Controls(nullptr),
28  m_ToFDistanceImageToSurfaceFilter(nullptr),
29  m_ToFImageGrabber(nullptr),
30  m_CameraIntrinsics(nullptr),
31  m_Active(false)
32 {
33  CreateQtPartControl(this);
34 }
35 
37 {
38 }
39 
41 {
42  if (!m_Controls)
43  {
44  // create GUI widgets
45  m_Controls = new Ui::QmitkToFSurfaceGenerationWidgetControls;
46  m_Controls->setupUi(parent);
47  this->CreateConnections();
49  }
50 }
51 
53 {
54  if ( m_Controls )
55  {
56  connect( (QObject*)(m_Controls->m_Compute3DDataCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnCompute3DDataCheckboxChecked(bool)) );
57  connect( (QObject*)(m_Controls->m_DistanceColorMapCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnDistanceColorMapCheckBoxChecked(bool)) );
58  connect( (QObject*)(m_Controls->m_RGBTextureCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnRGBTextureCheckBoxChecked(bool)) );
59  connect( (QObject*)(m_Controls->m_TriangulationThresholdSpinbox), SIGNAL(valueChanged(double)), this, SLOT(OnTriangulationThresholdSpinBoxChanged()) );
60  connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptionsCheckboxChecked(bool)) );
61  connect( (QObject*)(m_Controls->m_RepresentationCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnRepresentationChanged(int)) );
62  connect( (QObject*)(m_Controls->m_ReconstructionCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnReconstructionChanged(int)) );
63  }
64 }
65 
67 {
68  return m_ToFDistanceImageToSurfaceFilter;
69 }
70 
72 {
73  this->m_Controls->m_TextureGroupBox->setVisible(checked);
74  this->m_Controls->m_TriangulationThresholdSpinbox->setVisible(checked);
75  this->m_Controls->m_ReconstructionCombobox->setVisible(checked);
76  this->m_Controls->m_RepresentationCombobox->setVisible(checked);
77  this->m_Controls->label->setVisible(checked);
78  this->m_Controls->label_2->setVisible(checked);
79  this->m_Controls->label_3->setVisible(checked);
80 }
81 
84  mitk::CameraIntrinsics::Pointer intrinsics,
86  vtkSmartPointer<vtkCamera> camera,
87  bool generateSurface,
88  bool showAdvancedOptions)
89 {
90  m_ToFDistanceImageToSurfaceFilter = filter;
91  m_ToFImageGrabber = grabber;
92  m_CameraIntrinsics = intrinsics;
93  m_Active = true;
94  m_Camera3d = camera;
95 
96  bool hasSurface = false;
97  m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
98  if(hasSurface)
99  {
100  this->m_Surface = mitk::Surface::New();
101  }
102  else
103  {
104  this->m_Surface = this->m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
105  }
106 
107  m_SurfaceNode = surface;
108  m_SurfaceNode->SetData(m_Surface);
109 
110  this->FindReconstructionModeProperty();
111  m_Controls->m_ShowAdvancedOptionsCheckbox->setChecked(showAdvancedOptions);
112  this->OnShowAdvancedOptionsCheckboxChecked(showAdvancedOptions);
113  m_Controls->m_Compute3DDataCheckbox->setChecked(generateSurface);
114 }
115 
117 {
118  if(!m_Active)
119  {
120  MITK_ERROR << "QmitkToFSurfaceGenerationWidget is not active - please call QmitkToFSurfaceGenerationWidget::Initialize() first";
121  }
122  return m_Active;
123 }
124 
126 {
127  if(IsActive())
128  {
129  this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
130  this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
131  }
132 }
133 
135 {
136  if(IsActive())
137  {
139  switch (index)
140  {
141  case 0:
142  {
144  break;
145  }
146  case 1:
147  {
149  break;
150  }
151  case 2:
152  {
154  break;
155  }
156  default:
157  {
158  MITK_ERROR << "ReconstructionModeType does not exist or is not known in QmitkToFSurfaceGenerationWidget.";
159  break;
160  }
161  }
162  this->m_ToFDistanceImageToSurfaceFilter->SetReconstructionMode( type );
163  }
164 }
165 
167 {
168  if(IsActive())
169  {
170  bool generateTriangularMesh = false; //PointCloud case
171  if( index == 0) //Surface case
172  {
173  generateTriangularMesh = true;
174  }
175  this->m_ToFDistanceImageToSurfaceFilter->SetGenerateTriangularMesh(generateTriangularMesh);
176  this->m_ToFImageGrabber->GetCameraDevice()->SetBoolProperty("GenerateTriangularMesh", generateTriangularMesh);
177 
178  this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
179  this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
180  this->m_Controls->m_TriangulationThresholdSpinbox->setEnabled(generateTriangularMesh);
181  }
182 }
183 
185 {
186  if(IsActive())
187  {
188  if(m_ToFImageGrabber->GetBoolProperty("HasRGBImage"))
189  {
190  if (checked)
191  {
192  // enable texture
193  this->m_SurfaceNode->SetProperty("Surface.Texture",mitk::SmartPointerProperty::New(this->m_ToFImageGrabber->GetOutput(3)));
194  } else {
195  // disable texture
196  this->m_SurfaceNode->GetPropertyList()->DeleteProperty("Surface.Texture");
197  }
198  }
199  }
200 }
201 
203 {
204  if(m_SurfaceNode.IsNotNull())
205  {
206  this->m_SurfaceNode->SetBoolProperty("scalar visibility", checked);
207  }
208 }
209 
211 {
212  if(IsActive())
213  {
214  //##### Code for surface #####
215  if (m_Controls->m_Compute3DDataCheckbox->isChecked())
216  {
217  bool hasSurface = false;
218  this->m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
219  if(hasSurface)
220  {
221  mitk::SmartPointerProperty::Pointer surfaceProp = dynamic_cast< mitk::SmartPointerProperty * >(this->m_ToFImageGrabber->GetCameraDevice()->GetProperty("ToFSurface"));
222  this->m_Surface->SetVtkPolyData( dynamic_cast< mitk::Surface* >( surfaceProp->GetSmartPointer().GetPointer() )->GetVtkPolyData() );
223  }
224  else
225  {
226  this->m_Surface = m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
227  }
228 
229  //update pipeline
230  this->m_Surface->Update();
231  return true;
232  }
233  //##### End code for surface #####
234  }
235  return false;
236 }
237 
239 {
240  if(checked)
241  {
242  //initialize the surface once
243  MITK_DEBUG << "OnSurfaceCheckboxChecked true";
244  this->m_SurfaceNode->SetData(this->m_Surface);
245 
246  this->OnRepresentationChanged(m_Controls->m_RepresentationCombobox->currentIndex());
247 
248  //we need to initialize (reinit) the surface, to make it fit into the renderwindow
250  this->m_Surface->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS, true);
251 
252  // correctly place the vtk camera for appropriate surface rendering
253  //1m distance to camera should be a nice default value for most cameras
254  m_Camera3d->SetPosition(0,0,0);
255  m_Camera3d->SetViewUp(0,-1,0);
256  m_Camera3d->SetFocalPoint(0,0,1);
257  if (this->m_CameraIntrinsics.IsNotNull())
258  {
259  // compute view angle from camera intrinsics
260  m_Camera3d->SetViewAngle(mitk::ToFProcessingCommon::CalculateViewAngle(m_CameraIntrinsics,m_ToFImageGrabber->GetCaptureWidth()));
261  }
262  else
263  {
264  m_Camera3d->SetViewAngle(45);
265  }
266  m_Camera3d->SetClippingRange(1, 10000);
267  }
268 }
269 
270 void QmitkToFSurfaceGenerationWidget::FindReconstructionModeProperty()
271 {
272  bool KinectReconstructionMode = false;
273  m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("KinectReconstructionMode",KinectReconstructionMode);
274  if(KinectReconstructionMode)
275  {
276  //set the reconstruction mode for kinect
277  this->m_ToFDistanceImageToSurfaceFilter->SetReconstructionMode(mitk::ToFDistanceImageToSurfaceFilter::Kinect);
278  m_Controls->m_ReconstructionCombobox->setDisabled(true);
279  m_Controls->m_ReconstructionCombobox->setCurrentIndex(2);
280  }
281  else
282  {
283  m_Controls->m_ReconstructionCombobox->setEnabled(true);
284  }
285 }
286 
288 {
289  return m_Surface;
290 }
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool preserveRoughOrientationInWorldSpace=false)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
mitk::Surface::Pointer GetSurface()
GetSurface Get the generated surface.
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
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...
QmitkToFSurfaceGenerationWidget(QWidget *p=nullptr, Qt::WindowFlags f1=nullptr)
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.