diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp index 445e1c391a..02c382298f 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp @@ -1,115 +1,121 @@ /*=================================================================== 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 "mitkPASpectralUnmixingFilter.h" #include #include // Includes for AddEnmemberMatrix #include "mitkPAPropertyCalculator.h" #include mitk::pa::SpectralUnmixingFilter::SpectralUnmixingFilter() { this->SetNumberOfIndexedOutputs(2); for (unsigned int i = 0; iSetNthOutput(i, mitk::Image::New()); } m_PropertyCalculator = mitk::pa::PropertyCalculator::New(); } mitk::pa::SpectralUnmixingFilter::~SpectralUnmixingFilter() { } void mitk::pa::SpectralUnmixingFilter::AddWavelength(int wavelength) { m_Wavelength.push_back(wavelength); } void mitk::pa::SpectralUnmixingFilter::SetChromophores(ChromophoreType chromophore) { m_Chromophore.push_back(chromophore); } void mitk::pa::SpectralUnmixingFilter::GenerateData() { //code recreaction from "old" SUF.cpp // now creats to identical output images like the input for hb and hb02 MITK_INFO << "GENERATING DATA.."; numberOfInputs = GetNumberOfIndexedInputs(); numberOfOutputs = GetNumberOfIndexedOutputs(); for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) { GetOutput(outputIdx)->Initialize(GetInput(0)); } length = GetOutput(0)->GetDimension(0)*GetOutput(0)->GetDimension(1)*GetOutput(0)->GetDimension(2); for (int i = 0; i < length; i++) { for (unsigned int j = 0; j < numberOfInputs; j++) { mitk::Image::Pointer input = GetInput(j); mitk::ImageReadAccessor readAccess(input, input->GetVolumeData()); } for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) { mitk::Image::Pointer output = GetOutput(outputIdx); mitk::ImageWriteAccessor writeOutput(output, output->GetVolumeData()); double* outputArray = (double *)writeOutput.GetData(); } } MITK_INFO << "GENERATING DATA...[DONE]"; AddEndmemberMatrix(); } //Void creats Matrix with #chromophores rows and #wavelengths columns //so Matrix Element (i,j) contains the Absorbtion of chromophore j @ wavelength i void mitk::pa::SpectralUnmixingFilter::AddEndmemberMatrix() { numberofchromophores = m_Chromophore.size(); numberofwavelengths = m_Wavelength.size(); Eigen::Matrix EndmemberMatrix(numberofchromophores, numberofwavelengths); //loop over j rows (Chromophores) for(unsigned int j =0; j < numberofchromophores; ++j) { //loop over i columns (Wavelength) for (unsigned int i = 0; i < numberofwavelengths; ++i) { //writes @ Matrix element (i,j) the absorbtion wavelength of the propertycalculator.cpp - EndmemberMatrix(j,i)= m_PropertyCalculator->GetAbsorptionForWavelength( - static_cast(m_Chromophore[j]), m_Wavelength[i]); + EndmemberMatrix(j,i)= m_PropertyCalculator->GetAbsorptionForWavelength( + static_cast(m_Chromophore[j]), m_Wavelength[i]); + if (EndmemberMatrix(i, j) == 0) + { + m_Wavelength.clear(); + MITK_INFO << "size: "<< m_Wavelength.size(); + mitkThrow() << "WAVELENGTH NOT SUPPORTED!"; + } /* Test to see what gets written in the Matrix: MITK_INFO << "map type: " << static_cast(m_Chromophore[j]); MITK_INFO << "wavelength: " << m_Wavelength[i]; - MITK_INFO << "Matrixelement: (" << j << ", " << i << ") Absorbtion: " << EndmemberMatrix(j, i);*/ + MITK_INFO << "Matrixelement: (" << j << ", " << i << ") Absorbtion: " << EndmemberMatrix(j, i);/**/ } } MITK_INFO << "GENERATING ENMEMBERMATRIX SUCCESSFUL!"; } 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 e7a73d32ba..f1f6f28f96 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,238 +1,243 @@ /*=================================================================== 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 //test mitk image #include #include #include // Include to perform Spectral Unmixing #include "mitkPASpectralUnmixingFilter.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); connect(m_Controls.ButtonAddWavelength, &QPushButton::clicked, this, &SpectralUnmixing::Wavelength); + connect(m_Controls.ButtonClearWavelength, &QPushButton::clicked, this, &SpectralUnmixing::ClearWavelength); } // Add Wavelength is working, BUT in the Plugin! Not with same implementation at the filter // probably because the m_wavelengths vector is created new every time and not 'saved'. // Alternativ as comment here and at the filter. void SpectralUnmixing::Wavelength() { if (m_Wavelengths.empty()) { size = 0; } wavelength = m_Controls.spinBoxAddWavelength->value(); m_Wavelengths.push_back(wavelength); MITK_INFO << "ADD WAVELENGTH: " << wavelength << "nm"; size += 1; // size implemented like this because '.size' is const MITK_INFO << "ALL WAVELENGTHS: "; for (int i = 0; i < size; ++i) { MITK_INFO << m_Wavelengths[i] << "nm"; } } +void SpectralUnmixing::ClearWavelength() +{ + m_Wavelengths.clear(); +} + 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); } 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 (SOON)"; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; MITK_INFO << message.str(); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ auto m_SpectralUnmixingFilter = mitk::pa::SpectralUnmixingFilter::New(); // Checking which chromophores wanted for SU if none throw exeption! numberofChromophores = 0; DeOxbool = m_Controls.checkBoxDeOx->isChecked(); Oxbool = m_Controls.checkBoxOx->isChecked(); if (DeOxbool || Oxbool) { MITK_INFO << "CHOSEN CHROMOPHORES:"; } if (Oxbool) { numberofChromophores += 1; MITK_INFO << "- Oxyhemoglobin"; // Set chromophore Oxyhemoglobon: m_SpectralUnmixingFilter->SetChromophores( mitk::pa::SpectralUnmixingFilter::ChromophoreType(1)); } if (DeOxbool) { numberofChromophores += 1; MITK_INFO << "- Deoxygenated hemoglobin"; // Set chromophore Deoxygenated hemoglobin: m_SpectralUnmixingFilter->SetChromophores( mitk::pa::SpectralUnmixingFilter::ChromophoreType(2)); } if (numberofChromophores == 0) { mitkThrow() << "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!"; } // Checking if number of wavelengths >= number of chromophores if (numberofChromophores > size) { mitkThrow() << "PRESS 'IGNORE' AND ADD MORE WAVELENGTHS!"; } //code recreaction from "old" SU.cpp MITK_INFO << "GENERATING DATA..."; unsigned int numberOfInputs = size; unsigned int numberOfOutputs = numberofChromophores; MITK_INFO << "Inputs: " << numberOfInputs << " Outputs: " << numberOfOutputs; mitk::DataStorage::Pointer storage = this->GetDataStorage(); mitk::DataNode::Pointer node = nodes.front(); mitk::Image* inputImage = dynamic_cast(data); const unsigned int dimensions[]{ inputImage->GetDimension(0), inputImage->GetDimension(1), 1 }; // just the first sequence for starters TODO GENERALIZE unsigned int dimension = 3; mitk::PixelType TPixel = mitk::MakeScalarPixelType(); // another wavelength impementation for fiter needs "above" one for (unsigned int imageIndex = 0; imageIndex < numberOfInputs; imageIndex++) { mitk::Image::Pointer fooImage = mitk::Image::New(); fooImage->Initialize(TPixel, dimension, dimensions); wavelength = m_Wavelengths[imageIndex]; MITK_INFO << wavelength; m_SpectralUnmixingFilter->AddWavelength(wavelength); mitk::ImageReadAccessor inputAcc(inputImage, inputImage->GetSliceData(imageIndex)); fooImage->SetSlice(inputAcc.GetData(), 0); m_SpectralUnmixingFilter->SetInput(imageIndex, fooImage); } + MITK_INFO << "Updating Filter..."; m_SpectralUnmixingFilter->Update(); mitk::Image::Pointer HbO2 = m_SpectralUnmixingFilter->GetOutput(0); HbO2->GetGeometry()->SetIndexToWorldTransform(inputImage->GetGeometry()->GetIndexToWorldTransform()); mitk::ImageWriteAccessor writeOutputHbO2(HbO2, HbO2->GetVolumeData()); double* outputArrayHbO2 = (double *)writeOutputHbO2.GetData(); mitk::DataNode::Pointer dataNodeHbO2 = mitk::DataNode::New(); dataNodeHbO2->SetData(HbO2); dataNodeHbO2->SetName("HbO2"); this->GetDataStorage()->Add(dataNodeHbO2); - - - + mitk::Image::Pointer Hb = m_SpectralUnmixingFilter->GetOutput(1); Hb->GetGeometry()->SetIndexToWorldTransform(inputImage->GetGeometry()->GetIndexToWorldTransform()); mitk::ImageWriteAccessor writeOutputHb(Hb, Hb->GetVolumeData()); double* outputArrayHb = (double *)writeOutputHb.GetData(); mitk::DataNode::Pointer dataNodeHb = mitk::DataNode::New(); dataNodeHb->SetData(Hb); dataNodeHb->SetName("Hb"); this->GetDataStorage()->Add(dataNodeHb); 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 3299af9540..7a00e8e250 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,74 +1,75 @@ /*=================================================================== 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 "ui_SpectralUnmixingControls.h" #include "mitkPAPropertyCalculator.h" /** \brief SpectralUnmixing \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 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; // Add Wavelengths with button: int size = 0; std::vector m_Wavelengths; bool DeOxbool; bool Oxbool; 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 Wavelength(); + virtual void ClearWavelength(); unsigned int wavelength; unsigned int numberofChromophores; Ui::SpectralUnmixingControls m_Controls; mitk::pa::PropertyCalculator::Pointer m_PropertyCalculator; }; #endif // SpectralUnmixing_h diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixingControls.ui b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixingControls.ui index e9200f8e55..987bdd90b0 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixingControls.ui +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixingControls.ui @@ -1,116 +1,123 @@ SpectralUnmixingControls 0 0 222 399 0 0 QmitkTemplate Oxyhemoglobin true Do image processing Do Something Qt::Vertical 20 40 QLabel { color: rgb(255, 0, 0) } Please select an image! true Deoxygenated hemoglobin true true false Add Wavelength [nm] 2000 + + + + Clear all Wavelengths + + +