MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkToFSurfaceGenerationWidget.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
18//QT headers
19#include <QString>
20#include <mitkSmartPointerProperty.h>
21#include <mitkRenderingManager.h>
22
23#include <vtkCamera.h>
24
25const std::string QmitkToFSurfaceGenerationWidget::VIEW_ID = "org.mitk.views.qmitktofsurfacegenerationwidget";
26
27QmitkToFSurfaceGenerationWidget::QmitkToFSurfaceGenerationWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
28, m_Controls(nullptr),
29 m_ToFDistanceImageToSurfaceFilter(nullptr),
30 m_ToFImageGrabber(nullptr),
31 m_CameraIntrinsics(nullptr),
32 m_Active(false)
33{
35}
36
40
42{
43 if (!m_Controls)
44 {
45 // create GUI widgets
46 m_Controls = new Ui::QmitkToFSurfaceGenerationWidgetControls;
47 m_Controls->setupUi(parent);
48 this->CreateConnections();
50 }
51}
52
54{
55 if ( m_Controls )
56 {
57 connect( (QObject*)(m_Controls->m_Compute3DDataCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnCompute3DDataCheckboxChecked(bool)) );
58 connect( (QObject*)(m_Controls->m_DistanceColorMapCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnDistanceColorMapCheckBoxChecked(bool)) );
59 connect( (QObject*)(m_Controls->m_RGBTextureCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnRGBTextureCheckBoxChecked(bool)) );
60 connect( (QObject*)(m_Controls->m_TriangulationThresholdSpinbox), SIGNAL(valueChanged(double)), this, SLOT(OnTriangulationThresholdSpinBoxChanged()) );
61 connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsCheckbox), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptionsCheckboxChecked(bool)) );
62 connect( (QObject*)(m_Controls->m_RepresentationCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnRepresentationChanged(int)) );
63 connect( (QObject*)(m_Controls->m_ReconstructionCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnReconstructionChanged(int)) );
64 }
65}
66
67mitk::ToFDistanceImageToSurfaceFilter::Pointer QmitkToFSurfaceGenerationWidget::GetToFDistanceImageToSurfaceFilter()
68{
69 return m_ToFDistanceImageToSurfaceFilter;
70}
71
73{
74 this->m_Controls->m_TextureGroupBox->setVisible(checked);
75 this->m_Controls->m_TriangulationThresholdSpinbox->setVisible(checked);
76 this->m_Controls->m_ReconstructionCombobox->setVisible(checked);
77 this->m_Controls->m_RepresentationCombobox->setVisible(checked);
78 this->m_Controls->label->setVisible(checked);
79 this->m_Controls->label_2->setVisible(checked);
80 this->m_Controls->label_3->setVisible(checked);
81}
82
83void QmitkToFSurfaceGenerationWidget::Initialize(mitk::ToFDistanceImageToSurfaceFilter::Pointer filter,
84 mitk::ToFImageGrabber::Pointer grabber,
85 mitk::CameraIntrinsics::Pointer intrinsics,
86 mitk::DataNode::Pointer surface,
88 bool generateSurface,
89 bool showAdvancedOptions)
90{
91 m_ToFDistanceImageToSurfaceFilter = filter;
92 m_ToFImageGrabber = grabber;
93 m_CameraIntrinsics = intrinsics;
94 m_Active = true;
95 m_Camera3d = camera;
96
97 bool hasSurface = false;
98 m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
99 if(hasSurface)
100 {
101 this->m_Surface = mitk::Surface::New();
102 }
103 else
104 {
105 this->m_Surface = this->m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
106 }
107
108 m_SurfaceNode = surface;
109 m_SurfaceNode->SetData(m_Surface);
110
111 this->FindReconstructionModeProperty();
112 m_Controls->m_ShowAdvancedOptionsCheckbox->setChecked(showAdvancedOptions);
113 this->OnShowAdvancedOptionsCheckboxChecked(showAdvancedOptions);
114 m_Controls->m_Compute3DDataCheckbox->setChecked(generateSurface);
115}
116
118{
119 if(!m_Active)
120 {
121 MITK_ERROR << "QmitkToFSurfaceGenerationWidget is not active - please call QmitkToFSurfaceGenerationWidget::Initialize() first";
122 }
123 return m_Active;
124}
125
127{
128 if(IsActive())
129 {
130 this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
131 this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
132 }
133}
134
136{
137 if(IsActive())
138 {
140 switch (index)
141 {
142 case 0:
143 {
145 break;
146 }
147 case 1:
148 {
150 break;
151 }
152 case 2:
153 {
155 break;
156 }
157 default:
158 {
159 MITK_ERROR << "ReconstructionModeType does not exist or is not known in QmitkToFSurfaceGenerationWidget.";
160 break;
161 }
162 }
163 this->m_ToFDistanceImageToSurfaceFilter->SetReconstructionMode( type );
164 }
165}
166
168{
169 if(IsActive())
170 {
171 bool generateTriangularMesh = false; //PointCloud case
172 if( index == 0) //Surface case
173 {
174 generateTriangularMesh = true;
175 }
176 this->m_ToFDistanceImageToSurfaceFilter->SetGenerateTriangularMesh(generateTriangularMesh);
177 this->m_ToFImageGrabber->GetCameraDevice()->SetBoolProperty("GenerateTriangularMesh", generateTriangularMesh);
178
179 this->m_ToFDistanceImageToSurfaceFilter->SetTriangulationThreshold( this->m_Controls->m_TriangulationThresholdSpinbox->value() );
180 this->m_ToFImageGrabber->GetCameraDevice()->SetFloatProperty("TriangulationThreshold", this->m_Controls->m_TriangulationThresholdSpinbox->value());
181 this->m_Controls->m_TriangulationThresholdSpinbox->setEnabled(generateTriangularMesh);
182 }
183}
184
186{
187 if(IsActive())
188 {
189 if(m_ToFImageGrabber->GetBoolProperty("HasRGBImage"))
190 {
191 if (checked)
192 {
193 // enable texture
194 this->m_SurfaceNode->SetProperty("Surface.Texture",mitk::SmartPointerProperty::New(this->m_ToFImageGrabber->GetOutput(3)));
195 } else {
196 // disable texture
197 this->m_SurfaceNode->GetPropertyList()->DeleteProperty("Surface.Texture");
198 }
199 }
200 }
201}
202
204{
205 if(m_SurfaceNode.IsNotNull())
206 {
207 this->m_SurfaceNode->SetBoolProperty("scalar visibility", checked);
208 }
209}
210
212{
213 if(IsActive())
214 {
215 //##### Code for surface #####
216 if (m_Controls->m_Compute3DDataCheckbox->isChecked())
217 {
218 bool hasSurface = false;
219 this->m_ToFImageGrabber->GetCameraDevice()->GetBoolProperty("HasSurface", hasSurface);
220 if(hasSurface)
221 {
222 mitk::SmartPointerProperty::Pointer surfaceProp = dynamic_cast< mitk::SmartPointerProperty * >(this->m_ToFImageGrabber->GetCameraDevice()->GetProperty("ToFSurface"));
223 this->m_Surface->SetVtkPolyData( dynamic_cast< mitk::Surface* >( surfaceProp->GetSmartPointer().GetPointer() )->GetVtkPolyData() );
224 }
225 else
226 {
227 this->m_Surface = m_ToFDistanceImageToSurfaceFilter->GetOutput(0);
228 }
229
230 //update pipeline
231 this->m_Surface->Update();
232 return true;
233 }
234 //##### End code for surface #####
235 }
236 return false;
237}
238
240{
241 if(checked)
242 {
243 //initialize the surface once
244 MITK_DEBUG << "OnSurfaceCheckboxChecked true";
245 this->m_SurfaceNode->SetData(this->m_Surface);
246
247 this->OnRepresentationChanged(m_Controls->m_RepresentationCombobox->currentIndex());
248
249 //we need to initialize (reinit) the surface, to make it fit into the renderwindow
250 mitk::RenderingManager::GetInstance()->InitializeViews(this->m_Surface->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS);
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
270void 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}
void OnDistanceColorMapCheckBoxChecked(bool checked)
OnDistanceColorMapCheckBoxChecked Show the distance color mapping (vtkColorTransferFunction) on the s...
void OnCompute3DDataCheckboxChecked(bool checked)
OnCompute3DDataCheckboxChecked Slot beeing called, if the "surface"-checkbox is clicked....
void OnTriangulationThresholdSpinBoxChanged()
Slot trigged from the triangulation threshold spin box. Changed the threshold for connecting a vertex...
void OnReconstructionChanged(int index)
OnReconstructionChanged Change the reconstruction mode of the ToFDistanceImageToSurfaceFilter.
mitk::ToFDistanceImageToSurfaceFilter::Pointer GetToFDistanceImageToSurfaceFilter()
GetToFDistanceImageToSurfaceFilter Get the internally used surface generation filter.
QmitkToFSurfaceGenerationWidget(QWidget *p=nullptr, Qt::WindowFlags f1={})
virtual void CreateQtPartControl(QWidget *parent)
bool UpdateSurface()
UpdateSurface Generate new surface data according to the device properties.
bool IsActive()
IsActive Check if the widget was initialized correctly.
void OnRepresentationChanged(int index)
OnRepresentationChanged Change the representation of the surface. In other words: disable/enable tria...
mitk::Surface::Pointer GetSurface()
GetSurface Get the generated surface.
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 OnShowAdvancedOptionsCheckboxChecked(bool checked)
OnShowAdvancedOptionsCheckboxChecked Show/hide advanced options.
void OnRGBTextureCheckBoxChecked(bool checked)
OnRGBTextureCheckBoxChecked Put the RGB image as texture on the generated surface/point cloud.
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.