diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp index 5068da74af..32681ecf1c 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp @@ -1,370 +1,397 @@ /*=================================================================== 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 "SpectralUnmixing.h" // Qt #include // mitk image #include // Include to perform Spectral Unmixing #include "mitkPASpectralUnmixingFilterBase.h" #include "mitkPALinearSpectralUnmixingFilter.h" #include "mitkPASpectralUnmixingSO2.h" #include "mitkPASpectralUnmixingFilterVigra.h" #include "mitkPASpectralUnmixingFilterLagrange.h" #include "mitkPASpectralUnmixingFilterSimplex.h" const std::string SpectralUnmixing::VIEW_ID = "org.mitk.views.spectralunmixing"; void SpectralUnmixing::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void SpectralUnmixing::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &SpectralUnmixing::DoImageProcessing); } void SpectralUnmixing::ClearWavelength() { m_Wavelengths.clear(); } +void SpectralUnmixing::SetWavlength(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter) +{ + ClearWavelength(); + int col = 0; + int Wavelength = 1; + while (m_Controls.inputtable->item(0, col) && Wavelength > 0) + { + QString Text = m_Controls.inputtable->item(0, col)->text(); + Wavelength = Text.toInt(); + if (Wavelength > 0) + m_SpectralUnmixingFilter->AddWavelength(Wavelength); + MITK_INFO(PluignVerbose) << "Wavelength: " << Wavelength << "nm \n"; + ++col; + } +} + +void SpectralUnmixing::SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter) +{ + unsigned int numberofChromophores = 0; + DeOxbool = m_Controls.checkBoxDeOx->isChecked(); + Oxbool = m_Controls.checkBoxOx->isChecked(); + Melaninbool = m_Controls.checkBoxMelanin->isChecked(); + Onebool = m_Controls.checkBoxAdd->isChecked(); + if (DeOxbool || Oxbool || Melaninbool || Onebool) + { + MITK_INFO(PluignVerbose) << "CHOSEN CHROMOPHORES:"; + } + if (Oxbool) + { + numberofChromophores += 1; + MITK_INFO(PluignVerbose) << "- Oxyhemoglobin"; + m_SpectralUnmixingFilter->AddChromophore( + mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); + } + if (DeOxbool) + { + numberofChromophores += 1; + MITK_INFO(PluignVerbose) << "- Deoxygenated hemoglobin"; + m_SpectralUnmixingFilter->AddChromophore( + mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); + } + if (Melaninbool) + { + numberofChromophores += 1; + MITK_INFO(PluignVerbose) << "- Melanin"; + m_SpectralUnmixingFilter->AddChromophore( + mitk::pa::PropertyCalculator::ChromophoreType::MELANIN); + } + if (Onebool) + { + numberofChromophores += 1; + MITK_INFO(PluignVerbose) << "- Additional Chromophore"; + m_SpectralUnmixingFilter->AddChromophore( + mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER); + } + if (numberofChromophores == 0) + { + mitkThrow() << "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!"; + } +} + void SpectralUnmixing::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); return; } } m_Controls.labelWarning->setVisible(true); m_Controls.buttonPerformImageProcessing->setEnabled(false); } mitk::pa::SpectralUnmixingFilterBase::Pointer SpectralUnmixing::GetFilterInstance(std::string algorithm) { mitk::pa::SpectralUnmixingFilterBase::Pointer spectralUnmixingFilter; if (algorithm == "householderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR); } else if (algorithm == "ldlt") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LDLT); } else if (algorithm == "llt") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LLT); } else if (algorithm == "colPivHouseholderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::COLPIVHOUSEHOLDERQR); } else if (algorithm == "jacobiSvd") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::JACOBISVD); } else if (algorithm == "fullPivLu") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVLU); } else if (algorithm == "fullPivHouseholderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVHOUSEHOLDERQR); } else if (algorithm == "NNLARS") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS); } else if (algorithm == "NNGoldfarb") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB); } else if (algorithm == "weighted") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED); //Tranfer GUI information(Weights) to filter int colunm = 0; int Weight = 1; while (m_Controls.inputtable->item(1, colunm) && Weight > 0) { QString Text = m_Controls.inputtable->item(1, colunm)->text(); Weight = Text.toInt(); if (Weight > 0) dynamic_cast(spectralUnmixingFilter.GetPointer()) ->AddWeight(Weight); ++colunm; } } else if (algorithm == "LS") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS); } else if (algorithm == "SimplexMax") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterSimplex::New(); } else mitkThrow() << "404 ALGORITHM NOT FOUND!"; return spectralUnmixingFilter; } void SpectralUnmixing::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (!node) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Template", "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) { std::stringstream message; std::string name; message << "PERFORMING SPECTRAL UNMIXING "; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; - MITK_INFO << message.str(); + MITK_INFO(PluignVerbose) << message.str(); - //Tranfer GUI information(Algortihm) to filter + + //******************************************************************************************************************* + + //Read GUI information(algorithm) auto qs = m_Controls.QComboBoxAlgorithm->currentText(); std::string Algorithm = qs.toUtf8().constData(); mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter = GetFilterInstance(Algorithm); - - m_SpectralUnmixingFilter->SetInput(image); - //Tranfer GUI information(Wavelength) to filter - ClearWavelength(); - int col = 0; - int Wavelength = 1; - while (m_Controls.inputtable->item(0, col) && Wavelength > 0) - { - QString Text = m_Controls.inputtable->item(0, col)->text(); - Wavelength = Text.toInt(); - if (Wavelength > 0) - m_SpectralUnmixingFilter->AddWavelength(Wavelength); - ++col; - } + SetWavlength(m_SpectralUnmixingFilter); - //Tranfer GUI information(Chromophores) to filter - unsigned int numberofChromophores = 0; - DeOxbool = m_Controls.checkBoxDeOx->isChecked(); - Oxbool = m_Controls.checkBoxOx->isChecked(); - bool Melaninbool = m_Controls.checkBoxMelanin->isChecked(); - bool Onebool = m_Controls.checkBoxAdd->isChecked(); - if (DeOxbool || Oxbool) - { - MITK_INFO << "CHOSEN CHROMOPHORES:"; - } - if (Oxbool) - { - numberofChromophores += 1; - MITK_INFO << "- Oxyhemoglobin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); - } - if (DeOxbool) - { - numberofChromophores += 1; - MITK_INFO << "- Deoxygenated hemoglobin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); - } - if (Melaninbool) - { - numberofChromophores += 1; - MITK_INFO << "- Melanin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::MELANIN); - } - if (Onebool) - { - numberofChromophores += 1; - MITK_INFO << "- Additional Chromophore"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER); - } - if (numberofChromophores == 0) - { - mitkThrow() << "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!"; - } + SetChromophore(m_SpectralUnmixingFilter); - MITK_INFO << "Updating Filter..."; + MITK_INFO(PluignVerbose) << "Updating Filter..."; m_SpectralUnmixingFilter->Update(); - int outputCounter = 0; + + + // Write Output images to Data Storage + int outputCounter = 0; + std::vector chromophoreVec = { "HbO2", "Hb", "Melanin", "Static Endmember" }; + std::vector boolVec = { Oxbool, DeOxbool, Melaninbool, Onebool}; + mitk::Image::Pointer m_Output; + for (unsigned int chromophore; chromophore < chromophoreVec.size(); ++chromophore) + { + if (boolVec[chromophore] == false) + continue; + else + { + m_Output = m_SpectralUnmixingFilter->GetOutput(outputCounter++); + WriteOutputToDataStorage(m_Output, chromophoreVec[chromophore] + Algorithm); + } + } + if (Oxbool) { mitk::Image::Pointer HbO2 = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeHbO2 = mitk::DataNode::New(); dataNodeHbO2->SetData(HbO2); dataNodeHbO2->SetName("HbO2 " + Algorithm); this->GetDataStorage()->Add(dataNodeHbO2); } if (DeOxbool) { mitk::Image::Pointer Hb = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeHb = mitk::DataNode::New(); dataNodeHb->SetData(Hb); dataNodeHb->SetName("Hb " + Algorithm); this->GetDataStorage()->Add(dataNodeHb); } if (Melaninbool) { mitk::Image::Pointer Melanin = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeMelanin = mitk::DataNode::New(); dataNodeMelanin->SetData(Melanin); dataNodeMelanin->SetName("Melanin " + Algorithm); this->GetDataStorage()->Add(dataNodeMelanin); } if (Onebool) { mitk::Image::Pointer One = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeOne = mitk::DataNode::New(); dataNodeOne->SetData(One); dataNodeOne->SetName("One " + Algorithm); this->GetDataStorage()->Add(dataNodeOne); } //Calculate oxygen saturation bool sO2bool = m_Controls.checkBoxsO2->isChecked(); if (sO2bool) { if (!DeOxbool) mitkThrow() << "SELECT CHROMOPHORE DEOXYHEMOGLOBIN!"; if (!Oxbool) mitkThrow() << "SELECT CHROMOPHORE OXYHEMOGLOBIN!"; - MITK_INFO << "CALCULATE OXYGEN SATURATION ..."; + MITK_INFO(PluignVerbose) << "CALCULATE OXYGEN SATURATION ..."; auto m_sO2 = mitk::pa::SpectralUnmixingSO2::New(); // Oxygen Saturation Setting for (int i = 0; i < 4; ++i) { if (m_Controls.inputtable->item(0, i)) { QString Text = m_Controls.tableSO2->item(0, i)->text(); float value = Text.toFloat(); - MITK_INFO << "value: " << value; + MITK_INFO(PluignVerbose) << "value: " << value; m_sO2->AddSO2Settings(value); } else m_sO2->AddSO2Settings(0); } // Initialize pipeline from SU filter class to SO2 class auto output1 = m_SpectralUnmixingFilter->GetOutput(0); auto output2 = m_SpectralUnmixingFilter->GetOutput(1); m_sO2->SetInput(0, output1); m_sO2->SetInput(1, output2); m_sO2->Update(); // Write Output images to Data Storage mitk::Image::Pointer sO2 = m_sO2->GetOutput(0); mitk::DataNode::Pointer dataNodesO2 = mitk::DataNode::New(); dataNodesO2->SetData(sO2); dataNodesO2->SetName("sO2" + Algorithm); this->GetDataStorage()->Add(dataNodesO2); - MITK_INFO << "[DONE]"; + MITK_INFO(PluignVerbose) << "[DONE]"; } mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); MITK_INFO << "Adding images to DataStorage...[DONE]"; } } } diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h index fd57cc12cf..e907531dd6 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h @@ -1,60 +1,82 @@ /*=================================================================== 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 SpectralUnmixing_h #define SpectralUnmixing_h #include #include #include #include "ui_SpectralUnmixingControls.h" class SpectralUnmixing : 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; + // 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; -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(); - - virtual void ClearWavelength(); + /// \brief called by QmitkFunctionality when DataManager's selection has changed + virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, + const QList &nodes) override; - Ui::SpectralUnmixingControls m_Controls; + /// \brief Called when the user clicks the GUI button + void DoImageProcessing(); - std::vector m_Wavelengths; - - mitk::pa::SpectralUnmixingFilterBase::Pointer GetFilterInstance(std::string algorithm); + virtual void ClearWavelength(); + + Ui::SpectralUnmixingControls m_Controls; + + std::vector m_Wavelengths; + + mitk::pa::SpectralUnmixingFilterBase::Pointer GetFilterInstance(std::string algorithm); + + // Selection of Chromophores + bool DeOxbool; + bool Oxbool; + bool Melaninbool; + bool Onebool; + bool PluignVerbose = false; + private: + + /* + * \brief passes the wavelength information from the GUI on to the spectral unmixing filter base method + * "AddWavelength". + * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base + */ + virtual void SetWavlength(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter); + + /* + * \brief passes the chromophore information from the GUI on to the spectral unmixing filter base method + * "AddChromophore". + * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base + * @throw "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!" if no chromophore was chosen + */ + virtual void SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter); + + virtual void WriteOutputToDataStorage(mitk::Image::Pointer m_Image, std::string name); - // Selection of Chromophores - bool DeOxbool; - bool Oxbool; }; #endif // SpectralUnmixing_h