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 b51576efb1..f05e26533e 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp @@ -1,168 +1,192 @@ /*=================================================================== 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 // mitk image #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); connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &ExampleView::DoImageStatistics); connect(m_Controls.buttonGenerate, &QPushButton::clicked, this, &ExampleView::DoPixelMasking); } void ExampleView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { // 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); } 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(); + auto statistics = image->GetStatistics(); + auto minPixelValue = statistics->GetScalarValueMin(); + auto maxPixelValue = statistics->GetScalarValueMax(); - //get average + mitk::ImageStatisticsCalculator::Pointer imgStatisticsCalc= mitk::ImageStatisticsCalculator::New(); + imgStatisticsCalc->SetInputImage(image); - //get dev + mitk::ImageStatisticsCalculator::StatisticsContainer::Pointer imgStatisticsContained=imgStatisticsCalc->GetStatistics(); + auto avgPixelValue = imgStatisticsContained->GetMedian(); + auto devPixelValue = imgStatisticsContained->GetUniformity(); + + QString maxPixelValueString = QString::number(maxPixelValue); + QTableWidgetItem *max = new QTableWidgetItem(maxPixelValueString); + m_Controls.tableWidgetStatistics->setItem(0, 0, max); + + QString minPixelValueString = QString::number(minPixelValue); + QTableWidgetItem *min = new QTableWidgetItem(minPixelValueString); + m_Controls.tableWidgetStatistics->setItem(1, 0, min); + + QString avgPixelValueString = QString::number(avgPixelValue); + QTableWidgetItem *avg = new QTableWidgetItem(avgPixelValueString); + m_Controls.tableWidgetStatistics->setItem(2, 0, avg); + + QString devPixelValueString = QString::number(devPixelValue); + QTableWidgetItem *dev = new QTableWidgetItem(devPixelValueString); + m_Controls.tableWidgetStatistics->setItem(3, 0, dev); } } } void ExampleView::DoPixelMasking() { this->ProcessImage(); } void ExampleView::ProcessImage() { // 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 mask..."), tr("Enter name for the new mask"), QLineEdit::Normal, tr("Mask"), &ok); + , 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); } + } \ 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 7a5a8ebca6..0ec5a07df3 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h @@ -1,61 +1,62 @@ /*=================================================================== 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(); + Ui::ExampleViewControls m_Controls; }; #endif // ExampleView_h diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui index 8fad0e0310..e81ba12475 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui @@ -1,171 +1,181 @@ ExampleViewControls 0 0 222 481 0 0 QmitkTemplate Qt::RightToLeft 1 Qt::LeftToRight Image: QLabel { color: rgb(255, 0, 0) } Please select an image! false Do image processing Calculate Statistics: false 4 1 false false max min - dev + avg - avg + dev 0 Threshold - + + + false + + + -1023 + + + 1361 + + false Generate Qt::Vertical QSizePolicy::Expanding 20 220 QmitkDataStorageComboBox QComboBox
QmitkDataStorageComboBox.h