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 b03a104288..a5f528d0d6 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleView.cpp @@ -1,219 +1,233 @@ /*=================================================================== 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 #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 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::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; + auto node = m_Controls.comboBoxImageSelection->GetSelectedNode(); + if (node == nullptr) { + MITK_WARN << "no node selected"; - 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() { int pixelValueMask = m_Controls.spinboxThreshold->value(); this->ProcessImage(pixelValueMask); } 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) + if (!image) + { + QMessageBox::information(nullptr, "Warning", "Please load and select an image before starting image processing."); + return; + } + mitk::Image::Pointer maskedImage = image; + + //Get Dimensions, first only 3d + if (maskedImage->GetDimension() != 3) { - 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); + QMessageBox::information(nullptr, "Warning", "Please select a 3D image."); + return; } + unsigned int* maskedImageDimensionSizes = maskedImage->GetDimensions(); + //Get pixel value + mitk::ImagePixelWriteAccessor maskedImagePixelAccessor(maskedImage); + // 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/ExampleViewControls.ui b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/ExampleViewControls.ui index e81ba12475..7163ec0aaf 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 - avg + median - dev + uniformity 0 Threshold false -1023 1361 false Generate Qt::Vertical QSizePolicy::Expanding 20 220 QmitkDataStorageComboBox QComboBox
QmitkDataStorageComboBox.h