21 #include <qmessagebox.h>
22 #include <qfiledialog.h>
23 #include <qcombobox.h>
31 #include <itksys/SystemTools.hxx>
39 , m_IntegrationTime(0)
40 , m_ModulationFrequency(0)
41 , m_SelectedCameraName(
"")
59 m_Controls =
new Ui::QmitkToFConnectionWidgetControls2;
62 this->HideAllParameterWidgets();
65 std::string empty=
"";
100 QString selectedCamera = QString::fromStdString(device->GetNameOfClass());
102 this->HideAllParameterWidgets();
104 if (selectedCamera.contains(
"PMD"))
106 this->
m_Controls->m_PMDParameterWidget->show();
108 else if (selectedCamera.contains(
"MESA"))
110 this->
m_Controls->m_MESAParameterWidget->show();
112 else if (selectedCamera.contains(
"Kinect"))
114 this->
m_Controls->m_KinectParameterWidget->show();
116 else if (selectedCamera.contains(
"Structure"))
118 this->
m_Controls->m_StructureParameterWidget->show();
120 m_Controls->m_ConnectCameraButton->setEnabled(
true);
122 emit (selectedCamera);
125 void QmitkToFConnectionWidget::HideAllParameterWidgets()
127 this->
m_Controls->m_PMDParameterWidget->hide();
128 this->
m_Controls->m_MESAParameterWidget->hide();
129 this->
m_Controls->m_KinectParameterWidget->hide();
130 this->
m_Controls->m_StructureParameterWidget->hide();
137 if (
m_Controls->m_ConnectCameraButton->text()==
"Connect")
143 QString tmpFileName(
"");
144 QString fileFilter(
"");
145 QString selectedCamera = QString::fromStdString(device->GetNameOfClass());
152 if (selectedCamera.contains(
"Kinect") )
159 if (selectedCamera.contains(
"Structure") )
166 if (selectedCamera.contains(
"Player"))
169 if (selectedCamera.contains(
"PMD"))
171 fileFilter.append(
"PMD Files (*.pmd)");
175 fileFilter.append(
"NRRD Images (*.nrrd);;PIC Images - deprecated (*.pic)");
179 tmpFileName = QFileDialog::getOpenFileName(NULL,
"Play Image From...",
"", fileFilter);
182 if (tmpFileName.isEmpty())
184 m_Controls->m_ConnectCameraButton->setChecked(
false);
185 m_Controls->m_ConnectCameraButton->setEnabled(
true);
189 QMessageBox::information(
this,
"Template functionality",
"Please select a valid image before starting some action.");
193 if(selectedCamera.contains(
"PMDPlayer"))
195 this->
m_ToFImageGrabber->SetStringProperty(
"PMDFileName", tmpFileName.toStdString().c_str() );
199 std::string msg =
"";
203 std::string dir = itksys::SystemTools::GetFilenamePath( tmpFileName.toStdString() );
204 std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( tmpFileName.toStdString() );
205 std::string extension = itksys::SystemTools::GetFilenameLastExtension( tmpFileName.toStdString() );
208 if (extension !=
".pic" && extension !=
".nrrd")
210 msg = msg +
"Invalid file format, please select a \".nrrd\"-file";
211 throw std::logic_error(msg.c_str());
216 int found = baseFilename.rfind(
"_DistanceImage");
218 if (found == static_cast<int>(std::string::npos))
220 found = baseFilename.rfind(
"_AmplitudeImage");
223 if (found == static_cast<int>(std::string::npos))
225 found = baseFilename.rfind(
"_IntensityImage");
228 if (found == static_cast<int>(std::string::npos))
230 found = baseFilename.rfind(
"_RGBImage");
233 if (found == static_cast<int>(std::string::npos))
235 msg = msg +
"Input file name must end with \"_DistanceImage\", \"_AmplitudeImage\", \"_IntensityImage\" or \"_RGBImage\"!";
236 throw std::logic_error(msg.c_str());
239 std::string baseFilenamePrefix = baseFilename.substr(0,found);
242 std::string distanceImageFileName = dir +
"/" + baseFilenamePrefix +
"_DistanceImage" + extension;
243 std::string amplitudeImageFileName = dir +
"/" + baseFilenamePrefix +
"_AmplitudeImage" + extension;
244 std::string intensityImageFileName = dir +
"/" + baseFilenamePrefix +
"_IntensityImage" + extension;
245 std::string rgbImageFileName = dir +
"/" + baseFilenamePrefix +
"_RGBImage" + extension;
248 if (!itksys::SystemTools::FileExists(distanceImageFileName.c_str(),
true))
254 this->
m_ToFImageGrabber->SetStringProperty(
"DistanceImageFileName", distanceImageFileName.c_str());
256 if (!itksys::SystemTools::FileExists(amplitudeImageFileName.c_str(),
true))
261 this->
m_ToFImageGrabber->SetStringProperty(
"AmplitudeImageFileName", amplitudeImageFileName.c_str());
263 if (!itksys::SystemTools::FileExists(intensityImageFileName.c_str(),
true))
269 this->
m_ToFImageGrabber->SetStringProperty(
"IntensityImageFileName", intensityImageFileName.c_str());
271 if (!itksys::SystemTools::FileExists(rgbImageFileName.c_str(),
true))
277 this->
m_ToFImageGrabber->SetStringProperty(
"RGBImageFileName", rgbImageFileName.c_str());
281 catch (std::exception &e)
284 QMessageBox::critical(
this,
"Error", e.what() );
285 m_Controls->m_ConnectCameraButton->setChecked(
false);
286 m_Controls->m_ConnectCameraButton->setEnabled(
true);
296 m_Controls->m_ConnectCameraButton->setText(
"Disconnect");
310 if (selectedCamera.contains(
"PMD"))
312 this->
m_Controls->m_PMDParameterWidget->ActivateAllParameters();
314 else if (selectedCamera.contains(
"MESA"))
316 this->
m_Controls->m_MESAParameterWidget->ActivateAllParameters();
318 else if (selectedCamera.contains(
"Kinect"))
320 this->
m_Controls->m_KinectParameterWidget->ActivateAllParameters();
322 else if (selectedCamera.contains(
"Structure"))
324 this->
m_Controls->m_StructureParameterWidget->ActivateAllParameters();
328 this->HideAllParameterWidgets();
338 QMessageBox::critical(
this,
"Error",
"Connection failed. Check if you have installed the latest driver for your system." );
339 m_Controls->m_ConnectCameraButton->setChecked(
false);
340 m_Controls->m_ConnectCameraButton->setEnabled(
true);
341 m_Controls->m_ConnectCameraButton->setText(
"Connect");
346 }
catch(std::exception &e)
349 QMessageBox::critical(
this,
"Connection failed.", e.what() );
350 m_Controls->m_ConnectCameraButton->setChecked(
false);
351 m_Controls->m_ConnectCameraButton->setEnabled(
true);
352 m_Controls->m_ConnectCameraButton->setText(
"Connect");
357 m_Controls->m_ConnectCameraButton->setEnabled(
true);
360 if (QMessageBox::question(
this,
"Camera parameters",
"Do you want to specify your own camera intrinsics?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
363 QString fileName = QFileDialog::getOpenFileName(
this,
"Open camera intrinsics",
"/",
"*.xml");
365 cameraIntrinsics->FromXMLFile(fileName.toStdString());
367 }
catch ( std::exception &e ) {
368 MITK_WARN <<
"Error loading camera intrinsics: " << e.what();
378 QMessageBox::information(
this,
"Camera connection",
"No camera selected, please select a range camera");
379 m_Controls->m_ConnectCameraButton->setChecked(
false);
382 else if (
m_Controls->m_ConnectCameraButton->text()==
"Disconnect")
386 m_Controls->m_ConnectCameraButton->setText(
"Connect");
397 this->
m_Controls->m_ConnectCameraButton->animateClick();
itk::SmartPointer< Self > Pointer
Virtual interface and base class for all Time-of-Flight devices.