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 f17eafaffb..a7cd328c8e 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp @@ -1,236 +1,236 @@ /*=================================================================== 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 // mitk image #include #include #include #include #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(); + m_Controls.performImageStatisticsButton->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(); mitk::NodePredicateDimension::Pointer is3D = mitk::NodePredicateDimension::New(3); - m_Controls.comboBoxImageSelection->SetDataStorage(GetDataStorage()); + m_Controls.imageSelectionComboBox->SetDataStorage(GetDataStorage()); mitk::NodePredicateAnd::Pointer isAvailable = mitk::NodePredicateAnd::New(); isAvailable->AddPredicate(isImage); isAvailable->AddPredicate(is3D); - m_Controls.comboBoxImageSelection->SetPredicate(isAvailable); - 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*))); + m_Controls.imageSelectionComboBox->SetPredicate(isAvailable); + connect(m_Controls.performImageStatisticsButton, &QPushButton::clicked, this, &ExampleView::DoImageStatistics); + connect(m_Controls.generateButton, &QPushButton::clicked, this, &ExampleView::DoPixelMasking); + connect(m_Controls.imageSelectionComboBox, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(OnImageSelectionComboBoxChanged(const mitk::DataNode*))); } void ExampleView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { } -void ExampleView::OnComboBoxImageSelectionChanged(const mitk::DataNode *node) +void ExampleView::OnImageSelectionComboBoxChanged(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); + m_Controls.warningLabel->setVisible(true); + m_Controls.performImageStatisticsButton->setEnabled(false); + m_Controls.generateButton->setEnabled(false); + m_Controls.thresholdSpinbox->setEnabled(false); return; } - m_Controls.labelWarning->setVisible(false); - m_Controls.buttonPerformImageProcessing->setEnabled(true); - m_Controls.buttonGenerate->setEnabled(true); - m_Controls.spinboxThreshold->setEnabled(true); + m_Controls.warningLabel->setVisible(false); + m_Controls.performImageStatisticsButton->setEnabled(true); + m_Controls.generateButton->setEnabled(true); + m_Controls.thresholdSpinbox->setEnabled(true); m_Controls.tableWidgetStatistics->clearContents(); } void ExampleView::DoImageStatistics() { - auto node = m_Controls.comboBoxImageSelection->GetSelectedNode(); + auto node = m_Controls.imageSelectionComboBox->GetSelectedNode(); if (node == nullptr) { MITK_WARN << "no node selected"; } 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) { mitk::ImageStatisticsCalculator::Pointer imgStatisticsCalc= mitk::ImageStatisticsCalculator::New(); imgStatisticsCalc->SetInputImage(image); auto imgStatisticsContained = imgStatisticsCalc->GetStatistics()->GetStatisticsForTimeStep(0); auto stringMedian = mitk::ImageStatisticsConstants::MEDIAN(); auto medianPixelValue = imgStatisticsContained.GetValueConverted(stringMedian); auto stringUniformity = mitk::ImageStatisticsConstants::UNIFORMITY(); auto uniformityPixelValue = imgStatisticsContained.GetValueConverted(stringUniformity); auto stringMax = mitk::ImageStatisticsConstants::MAXIMUM(); auto maxPixelValue = imgStatisticsContained.GetValueConverted(stringMax); auto stringMin = mitk::ImageStatisticsConstants::MINIMUM(); auto minPixelValue = imgStatisticsContained.GetValueConverted(stringMin); //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(medianPixelValue); QTableWidgetItem *avg = new QTableWidgetItem(avgPixelValueString); m_Controls.tableWidgetStatistics->setItem(2, 0, avg); //Output dev QString devPixelValueString = QString::number(uniformityPixelValue); QTableWidgetItem *dev = new QTableWidgetItem(devPixelValueString); m_Controls.tableWidgetStatistics->setItem(3, 0, dev); } } } void ExampleView::DoPixelMasking() { - int pixelValueMask = m_Controls.spinboxThreshold->value(); + int pixelValueMask = m_Controls.thresholdSpinbox->value(); this->ProcessImage(pixelValueMask); } void ExampleView::ProcessImage(int pixelValueMask) { // check for valid node selected - auto node = m_Controls.comboBoxImageSelection->GetSelectedNode(); + auto node = m_Controls.imageSelectionComboBox->GetSelectedNode(); 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 cloned image mitk::Image::Pointer image = dynamic_cast(data); if (!image) { QMessageBox::information(nullptr, "Warning", "Please load and select an image before starting image processing."); return; } mitk::Image::Pointer maskedImage = image->Clone(); //Get pixel value mitk::ImagePixelWriteAccessor maskedImagePixelAccessor(maskedImage); mitk::ImagePixelReadAccessor imagePixelAccessor(image); int imageXLength = image->GetDimension(0); int imageYLength = image->GetDimension(1); int imageZLength = image->GetDimension(2); itk::Index<3> index; for (int x = 0; x < imageXLength; x++) { for (int y = 0; y < imageYLength; y++) { for (int z = 0; z < imageZLength; z++) { index[0] = x; index[1] = y; index[2] = z; if (imagePixelAccessor.GetPixelByIndex(index) >= pixelValueMask) { maskedImagePixelAccessor.SetPixelByIndex(index, 0); } } } } // Create a new data tree node // mitk::DataNode::Pointer maskedImageNode = mitk::DataNode::New(); // // fill the data tree node with the appropriate information // maskedImageNode->SetData(maskedImage); 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 8e3f8e8dab..af4e5afa64 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.h @@ -1,65 +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(int pixelValueMask); Ui::ExampleViewControls m_Controls; protected slots: - void OnComboBoxImageSelectionChanged(const mitk::DataNode* node); + void OnImageSelectionComboBoxChanged(const mitk::DataNode* node); }; #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 7163ec0aaf..6b134957cc 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui @@ -1,181 +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 median uniformity 0 - + Threshold - + false -1023 1361 - + false Generate Qt::Vertical QSizePolicy::Expanding 20 220 QmitkDataStorageComboBox QComboBox
QmitkDataStorageComboBox.h