MITK-IGT
IGT Extension of MITK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
QmitkToFScreenshotMaker.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
13// Qmitk
15#include <QmitkServiceListWidget.h>
16
17// Mitk
18#include <mitkToFCameraDevice.h>
19#include <mitkIOUtil.h>
20
21// Qt
22#include <QString>
23#include <QStringList>
24#include <QMessageBox>
25
26const std::string QmitkToFScreenshotMaker::VIEW_ID = "org.mitk.views.tofscreenshotmaker";
27
29 : QmitkAbstractView(),
30 m_SavingCounter(0)
31{
32}
33
37
41
43{
44 // create GUI widgets from the Qt Designer's .ui file
45 m_Controls.setupUi( parent );
46 connect( (QObject*)(m_Controls.m_MakeScreenshot), SIGNAL(clicked()), this, SLOT(OnMakeScreenshotClicked()) );
47
48 connect( m_Controls.m_ConnectedDeviceServiceListWidget, SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(OnSelectCamera()));
49
50 std::string filter = "";
51 m_Controls.m_ConnectedDeviceServiceListWidget->Initialize<mitk::ToFImageSource>("ToFImageSourceName", filter);
52
53 std::string defaultPath = "/tmp/";
54#ifdef _WIN32
55 defaultPath = "C:/tmp/";
56#endif
57 m_Controls.m_PathToSaveFiles->setText(defaultPath.c_str());
58}
59
61{
62 //Update gui according to device properties
63 mitk::ToFImageGrabber* source = static_cast<mitk::ToFImageGrabber*>(m_Controls.m_ConnectedDeviceServiceListWidget->GetSelectedService<mitk::ToFImageSource>());
64 mitk::ToFCameraDevice* device = source->GetCameraDevice();
65 m_Controls.m_MakeScreenshot->setEnabled(device->IsCameraActive());
66
67 //todo: where do i get correct file extensions?
68 std::vector<std::string> fileExtensions;
69 fileExtensions.push_back(".png");
70 fileExtensions.push_back(".nrrd");
71 fileExtensions.push_back(".jpg");
72 QStringList extensions;
73 for( unsigned int i = 0; i < fileExtensions.size(); ++i)
74 {
75 extensions.append(QString(fileExtensions.at(i).c_str()));
76 }
77 this->UpdateGUIElements(device, "no depth property available", m_Controls.m_SaveDepth, m_Controls.m_DepthFormat, extensions, ".nrrd");
78 //usually you want to save depth data, but there is no "HasDepthImage" property, because every depth
79 //camera should provide a depth image
80 m_Controls.m_SaveDepth->setChecked(true);
81 m_Controls.m_SaveDepth->setEnabled(true);
82 m_Controls.m_DepthFormat->setEnabled(true);
83
84 this->UpdateGUIElements(device, "HasAmplitudeImage", m_Controls.m_SaveAmplitude ,
85 m_Controls.m_AmplitudeFormat, extensions, ".nrrd");
86 this->UpdateGUIElements(device, "HasIntensityImage", m_Controls.m_SaveIntensity,
87 m_Controls.m_IntensityFormat, extensions, ".nrrd");
88 this->UpdateGUIElements(device, "HasRGBImage", m_Controls.m_SaveColor,
89 m_Controls.m_ColorFormat, extensions, ".png"); //png is nice default for calibration
90 this->UpdateGUIElements(device, "HasRawImage", m_Controls.m_SaveRaw,
91 m_Controls.m_RawFormat, extensions, ".nrrd");
92}
93
94void QmitkToFScreenshotMaker::UpdateGUIElements(mitk::ToFCameraDevice* device, const char* ToFImageType,
95 QCheckBox* saveCheckBox, QComboBox* saveTypeComboBox,
96 QStringList fileExentions, const char* preferredFormat)
97{
98 bool isTypeProvidedByDevice = false;
99 device->GetBoolProperty(ToFImageType, isTypeProvidedByDevice);
100 saveCheckBox->setChecked(isTypeProvidedByDevice);
101 saveCheckBox->setEnabled(isTypeProvidedByDevice);
102
103 saveTypeComboBox->clear();
104 saveTypeComboBox->setEnabled(isTypeProvidedByDevice);
105 saveTypeComboBox->addItems(fileExentions);
106 int index = saveTypeComboBox->findText(preferredFormat);
107 if ( index != -1 ) { // -1 for not found
108 saveTypeComboBox->setCurrentIndex(index);
109 }
110}
111
113{
114 mitk::ToFImageGrabber* source = static_cast<mitk::ToFImageGrabber*>(m_Controls.m_ConnectedDeviceServiceListWidget->GetSelectedService<mitk::ToFImageSource>());
115 source->Update();
116
117 //### Save Images
118 this->SaveImage(source->GetOutput(0), m_Controls.m_SaveDepth->isChecked(),
119 m_Controls.m_PathToSaveFiles->text().toStdString(), std::string("Depth_"),
120 m_Controls.m_DepthFormat->currentText().toStdString());
121 this->SaveImage(source->GetOutput(1), m_Controls.m_SaveAmplitude->isChecked(),
122 m_Controls.m_PathToSaveFiles->text().toStdString(), std::string("Amplitude_"),
123 m_Controls.m_AmplitudeFormat->currentText().toStdString());
124 this->SaveImage(source->GetOutput(2), m_Controls.m_SaveIntensity->isChecked(),
125 m_Controls.m_PathToSaveFiles->text().toStdString(), std::string("Intensity_"),
126 m_Controls.m_IntensityFormat->currentText().toStdString());
127 this->SaveImage(source->GetOutput(3), m_Controls.m_SaveColor->isChecked(),
128 m_Controls.m_PathToSaveFiles->text().toStdString(), std::string("Color_"),
129 m_Controls.m_ColorFormat->currentText().toStdString());
130 //todo, where is the raw data?
131
132 //todo what about the surface or pre-processed data?
133 m_SavingCounter++;
134}
135
136void QmitkToFScreenshotMaker::SaveImage(mitk::Image::Pointer image, bool saveImage, std::string path, std::string name, std::string extension)
137{
138 if(saveImage)
139 {
140 std::stringstream outdepthimage;
141 outdepthimage << path << name<< m_SavingCounter << extension;
142 mitk::IOUtil::Save( image, outdepthimage.str() );
143 }
144}
Ui::QmitkToFScreenshotMakerControls m_Controls
void CreateQtPartControl(QWidget *parent) override
void OnMakeScreenshotClicked()
OnMakeScreenshotClicked Slot called when the "Make screenshot" button is pressed.
void OnSelectCamera()
OnSelectCamera Slot called to update the GUI according to the selected image source.
static const std::string VIEW_ID
Virtual interface and base class for all Time-of-Flight devices.
virtual bool IsCameraActive()
returns true if the camera is connected and started
bool GetBoolProperty(const char *propertyKey, bool &boolValue)
get a bool from the property list
Image source providing ToF images. Interface for filters provided in ToFProcessing module.
ToFCameraDevice * GetCameraDevice()
Get the currently set ToF camera device.
Image source providing ToF images. Interface for filters provided in ToFProcessing module.