diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp index 565ecbd1da..b99c4c7b36 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp +++ b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp @@ -1,129 +1,207 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Qmitk #include "PAUSMotionCompensation.h" // Qt #include // mitk image #include const std::string PAUSMotionCompensation::VIEW_ID = "org.mitk.views.pausmotioncompensation"; void PAUSMotionCompensation::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void PAUSMotionCompensation::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); connect( m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &PAUSMotionCompensation::DoImageProcessing); + connect( + m_Controls.buttonUpdateParameters, &QPushButton::clicked, this, &PAUSMotionCompensation::DoUpdateParameters); } void PAUSMotionCompensation::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { + // Clear the combo box where we choose the photoacoustic image + m_Controls.comboBoxPA->clear(); + // Make sure that there are exactle 2 nodes selected - if (nodes.size() == 2) - { - // 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); - return; - } + if (nodes.size() != 2) { + m_Controls.labelWarning->setVisible(true); + m_Controls.buttonPerformImageProcessing->setEnabled(false); + return; + } + + // Make sure that the image data is okay + foreach (mitk::DataNode::Pointer node, nodes) { + if (node.IsNull() || !dynamic_cast(node->GetData())) { + m_Controls.labelWarning->setVisible(true); + m_Controls.buttonPerformImageProcessing->setEnabled(false); + return; } + + // Add the image names to the combo box + m_Controls.comboBoxPA->addItem(QString::fromStdString(node->GetName())); } - m_Controls.labelWarning->setVisible(true); - m_Controls.buttonPerformImageProcessing->setEnabled(false); + + m_Controls.labelWarning->setVisible(false); + m_Controls.buttonPerformImageProcessing->setEnabled(true); + } void PAUSMotionCompensation::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); // Make sure that there are two images selected if (nodes.empty() || nodes.size() != 2) { QMessageBox::information(nullptr, "Warning", "Please select two images before starting image processing."); return; } - //TODO: I need to process two nodes and get the BaseData. - mitk::DataNode *node = nodes.front(); + mitk::DataNode::Pointer paNode, usNode; - if (!node) - { - // Nothing selected. Inform the user and return - QMessageBox::information(nullptr, "Template", "Please load and select 2 images before starting image processing."); + foreach (mitk::DataNode::Pointer node, nodes) { + if(m_Controls.comboBoxPA->itemText(m_Controls.comboBoxPA->currentIndex()) == QString::fromStdString(node->GetName())) { + paNode = node; + } else { + usNode = node; + } + } + + if(paNode.IsNull() || usNode.IsNull()) { + MITK_INFO << "One of the nodes is empty. This may happen, if the two images have the same name. Please rename one of them."; + QMessageBox::information(nullptr, "Template", "One of the nodes is empty. This may happen, if the two images have the same name. Please rename one of them."); 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) + mitk::BaseData *paData = paNode->GetData(); + mitk::BaseData *usData = usNode->GetData(); + if (paData && usData) { // 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::Image *paImage = dynamic_cast(paData); + mitk::Image *usImage = dynamic_cast(usData); + if (paImage && usImage) { std::stringstream message; std::string name; - message << "Performing image processing for image "; - if (node->GetName(name)) + message << "Performing motion compensation for image "; + if (paNode->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } + message << " and "; + if (usNode->GetName(name)) { + message << "'" << name << "'"; + } message << "."; MITK_INFO << message.str(); // actually do something here... - m_Filter->SetInput(0, image); - m_Filter->SetInput(1, image); + m_Filter->SetPaInput(paImage); + m_Filter->SetUsInput(usImage); m_Filter->Update(); - // node->SetData(m_Filter->GetOutput(0)); - // mitk::Image *test = m_Filter->GetOutput(0); - m_Filter->GetOutput(0); - m_Filter->GetOutput(1); - // node->SetData(test); + mitk::Image::Pointer paOutput = m_Filter->GetPaOutput(); + mitk::Image::Pointer usOutput = m_Filter->GetUsOutput(); + + auto paOutNode = mitk::DataNode::New(); + paOutNode->SetData(paOutput); + paOutNode->SetName(paNode->GetName() + " compensated"); - MITK_INFO << "We are back in the plugin."; + this->GetDataStorage()->Add(paOutNode); - auto newNode = mitk::DataNode::New(); - // newNode->SetData(test); - newNode->SetName("Test"); + auto usOutNode = mitk::DataNode::New(); + usOutNode->SetData(usOutput); + usOutNode->SetName(usNode->GetName() + " compensated"); - this->GetDataStorage()->Add(newNode); + this->GetDataStorage()->Add(usOutNode); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } + +void PAUSMotionCompensation::DoUpdateParameters() { + + bool ok; + + unsigned int batchSize = m_Controls.lineBatchSize->text().toInt(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetBatchSize(batchSize); + + double pyrScale = m_Controls.linePyrScale->text().toDouble(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetPyrScale(pyrScale); + + unsigned int levels = m_Controls.lineLevels->text().toInt(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetLevels(levels); + + unsigned int winSize = m_Controls.lineWinSize->text().toInt(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetWinSize(winSize); + + unsigned int iterations = m_Controls.lineIterations->text().toInt(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetIterations(iterations); + + unsigned int polyN = m_Controls.linePolyN->text().toInt(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetPolyN(polyN); + + double polySigma = m_Controls.linePolySigma->text().toDouble(&ok); + if(!ok) { + QMessageBox::information(nullptr, "Warning", "Invalid parameter."); + return; + } + m_Filter->SetPolySigma(polySigma); +} diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.h b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.h index d04a194bee..d47836b4b1 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.h +++ b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.h @@ -1,62 +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 PAUSMotionCompensation_h #define PAUSMotionCompensation_h #include #include #include "ui_PAUSMotionCompensationControls.h" #include "mitkPhotoacousticMotionCorrectionFilter.h" /** \brief PAUSMotionCompensation Photoacoustic and ultrasound image motion correction can be performed with this plugin. Internally OpenCV2 calc OpticalFlowFarneback is used. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class PAUSMotionCompensation : 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 DoImageProcessing(); + void DoUpdateParameters(); Ui::PAUSMotionCompensationControls m_Controls; - mitk::PhotoacousticMotionCorrectionFilter::Pointer m_Filter = mitk::PhotoacousticMotionCorrectionFilter::New(); }; #endif // PAUSMotionCompensation_h diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensationControls.ui b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensationControls.ui index 72f68af55b..8afd79a28c 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensationControls.ui +++ b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensationControls.ui @@ -1,162 +1,179 @@ PAUSMotionCompensationControls 0 0 242 - 391 + 555 0 0 QmitkTemplate QLabel { color: rgb(255, 0, 0) } Please select 2 images! + + + + Photoacoustic image + + + + + + + + + + Do image processing + + + Start processing + + + Batch size 5 Pyramid scale: 0.5 Levels: 3 Averaging window size: 15 Iterations: 3 Pixel neighborhood for poly-expan: 5 Standard deviation: 1.1 - - - Do image processing - + - Start processing + Update Parameters Qt::Vertical QSizePolicy::Expanding 20 220