diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp index f05e26533e..b03a104288 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp @@ -1,192 +1,219 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#include <-research // Blueberry #include #include // Qmitk #include "ExampleView.h" // Qt #include #include #include #include #include -#include +#include #include // mitk image #include #include #include #include #include #include #include +#include const std::string ExampleView::VIEW_ID = "org.mitk.views.exampleview"; void ExampleView::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void ExampleView::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); + mitk::TNodePredicateDataType::Pointer isImage = mitk::TNodePredicateDataType::New(); + m_Controls.comboBoxImageSelection->SetDataStorage(GetDataStorage()); + m_Controls.comboBoxImageSelection->SetPredicate(isImage); connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &ExampleView::DoImageStatistics); connect(m_Controls.buttonGenerate, &QPushButton::clicked, this, &ExampleView::DoPixelMasking); + connect(m_Controls.comboBoxImageSelection, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(OnComboBoxImageSelectionChanged(const mitk::DataNode*))); } void ExampleView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { - // iterate all selected objects, adjust warning visibility + /* iterate all selected objects, adjust warning visibility foreach (mitk::DataNode::Pointer node, nodes) { if (node.IsNotNull() && dynamic_cast(node->GetData())) { m_Controls.labelWarning->setVisible(false); m_Controls.buttonPerformImageProcessing->setEnabled(true); m_Controls.buttonGenerate->setEnabled(true); m_Controls.spinboxThreshold->setEnabled(true); return; } } m_Controls.labelWarning->setVisible(true); m_Controls.buttonPerformImageProcessing->setEnabled(false); m_Controls.buttonGenerate->setEnabled(false); - m_Controls.spinboxThreshold->setEnabled(false); + m_Controls.spinboxThreshold->setEnabled(false); */ +} + +void ExampleView::OnComboBoxImageSelectionChanged(const mitk::DataNode *node) +{ + if (node == nullptr) + { + m_Controls.labelWarning->setVisible(true); + m_Controls.buttonPerformImageProcessing->setEnabled(false); + m_Controls.buttonGenerate->setEnabled(false); + m_Controls.spinboxThreshold->setEnabled(false); + return; + } + m_Controls.labelWarning->setVisible(false); + m_Controls.buttonPerformImageProcessing->setEnabled(true); + m_Controls.buttonGenerate->setEnabled(true); + m_Controls.spinboxThreshold->setEnabled(true); } void ExampleView::DoImageStatistics() { QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (node == nullptr) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Warning", "Please load and select an image before starting image processing."); return; } // here we have a valid mitk::DataNode // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); if (data) { // test if this data item is an image or not (could also be a surface or something totally different) mitk::Image *image = dynamic_cast(data); if (image) { auto statistics = image->GetStatistics(); auto minPixelValue = statistics->GetScalarValueMin(); auto maxPixelValue = statistics->GetScalarValueMax(); mitk::ImageStatisticsCalculator::Pointer imgStatisticsCalc= mitk::ImageStatisticsCalculator::New(); imgStatisticsCalc->SetInputImage(image); mitk::ImageStatisticsCalculator::StatisticsContainer::Pointer imgStatisticsContained=imgStatisticsCalc->GetStatistics(); auto avgPixelValue = imgStatisticsContained->GetMedian(); auto devPixelValue = imgStatisticsContained->GetUniformity(); + //Output max QString maxPixelValueString = QString::number(maxPixelValue); QTableWidgetItem *max = new QTableWidgetItem(maxPixelValueString); m_Controls.tableWidgetStatistics->setItem(0, 0, max); + //Output min QString minPixelValueString = QString::number(minPixelValue); QTableWidgetItem *min = new QTableWidgetItem(minPixelValueString); m_Controls.tableWidgetStatistics->setItem(1, 0, min); + //Output avg QString avgPixelValueString = QString::number(avgPixelValue); QTableWidgetItem *avg = new QTableWidgetItem(avgPixelValueString); m_Controls.tableWidgetStatistics->setItem(2, 0, avg); + //Output dev QString devPixelValueString = QString::number(devPixelValue); QTableWidgetItem *dev = new QTableWidgetItem(devPixelValueString); m_Controls.tableWidgetStatistics->setItem(3, 0, dev); } } } + + void ExampleView::DoPixelMasking() { - this->ProcessImage(); + int pixelValueMask = m_Controls.spinboxThreshold->value(); + this->ProcessImage(pixelValueMask); } -void ExampleView::ProcessImage() +void ExampleView::ProcessImage(int pixelValueMask) { // check for valid node selected QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (node == nullptr) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Warning", "Please load and select an image before starting image processing."); return; } mitk::BaseData* data = node->GetData(); //get data from node if (data != nullptr) { //Ask for the name of the mask bool ok = false; QString name = QInputDialog::getText(QApplication::activeWindow() , tr("Add masked image..."), tr("Enter name for the new masked image"), QLineEdit::Normal, tr("maskedImage"), &ok); if (!ok || name.isEmpty()) return; //Create copy image mitk::Image *image = dynamic_cast(data); if (image) { mitk::Image::Pointer maskedImage = image; + // Create a new data tree node + // + mitk::DataNode::Pointer maskedImageNode = mitk::DataNode::New(); + // + // fill the data tree node with the appropriate information + // + maskedImageNode->SetData(image); + maskedImageNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); + maskedImageNode->SetProperty("opacity", mitk::FloatProperty::New(1)); + // + // add the node to the ds + // + this->GetDataStorage()->Add(maskedImageNode); } - // - // Create a new data tree node - // - mitk::DataNode::Pointer maskedImageNode = mitk::DataNode::New(); - // - // fill the data tree node with the appropriate information - // - maskedImageNode->SetData(image); - maskedImageNode->SetProperty("name", mitk::StringProperty::New(name.toStdString())); - maskedImageNode->SetProperty("opacity", mitk::FloatProperty::New(1)); - // - // add the node to the ds - // - this->GetDataStorage()->Add(maskedImageNode); } } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h index 0ec5a07df3..8e3f8e8dab 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h @@ -1,62 +1,65 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef ExampleView_h #define ExampleView_h #include #include #include "ui_ExampleViewControls.h" /** \brief ExampleView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class ExampleView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList &nodes) override; - + /// \brief Called when the user clicks the GUI button void DoImageStatistics(); void DoPixelMasking(); - void ProcessImage(); + void ProcessImage(int pixelValueMask); Ui::ExampleViewControls m_Controls; +protected slots: + + void OnComboBoxImageSelectionChanged(const mitk::DataNode* node); }; #endif // ExampleView_h