diff --git a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilter.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilter.h index c163cf30ea..e20542e8ee 100644 --- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilter.h +++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilter.h @@ -1,59 +1,60 @@ /*=================================================================== 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 MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H #define MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H #include "mitkImageToImageFilter.h" //Includes for smart pointer usage #include "mitkCommon.h" #include "itkLightObject.h" #include namespace mitk { namespace pa { class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingFilter : public mitk::ImageToImageFilter { public: mitkClassMacro(SpectralUnmixingFilter, mitk::ImageToImageFilter) itkFactorylessNewMacro(Self) //Contains all (so far) possible chromophores enum ChromophoreType { OXYGENATED, DEOXYGENATED }; void Test(); - /* for add wavelengths void AddWavelength(int wavelength); - std::vector m_Wavelengths; + std::vector m_Wavelength; + /* for add wavelengths + int size; */ protected: SpectralUnmixingFilter(); virtual ~SpectralUnmixingFilter(); private: - + virtual void GenerateData(); }; } } #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp index f03b1c2a28..0a9c859b8e 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp @@ -1,87 +1,101 @@ /*=================================================================== 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 mitk::pa::SpectralUnmixingFilter::SpectralUnmixingFilter() { + this->SetNumberOfIndexedOutputs(3); + + for (unsigned int i = 0; iSetNthOutput(i, mitk::Image::New()); + } + } mitk::pa::SpectralUnmixingFilter::~SpectralUnmixingFilter() { } void mitk::pa::SpectralUnmixingFilter::Test() { MITK_INFO << "Test"; } +void mitk::pa::SpectralUnmixingFilter::AddWavelength(int wavelength) +{ + m_Wavelength.push_back(wavelength); +} +void mitk::pa::SpectralUnmixingFilter::GenerateData() +{ + MITK_INFO << "Hallo Welt!"; - +} //// Not correct working alternativ for wavelengths /*void mitk::pa::SpectralUnmixingFilter::AddWavelength(int wavelength) { // Das ganze klappt noch nicht so! m_wavelengths wird nicht gespeichert ... if (m_Wavelengths.empty()) { size = 0; } m_Wavelengths.push_back(wavelength); size += 1; }*/ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // VERWORFENES ZEUG: /* void mitk::pa::SpectralUnmixingFilter::GetInputPictures() { MITK_INFO << "GET INPUT PICTURES..."; unsigned int numberOfInputs = GetNumberOfIndexedInputs(); unsigned int numberOfOutputs = GetNumberOfIndexedOutputs(); MITK_INFO << "Inputs: " << numberOfInputs << " Outputs: " << numberOfOutputs; if (m_Wavelengths.empty() || m_Wavelengths.size() != numberOfInputs || numberOfInputs < m_Chromophores.size()) { std::string invalidWavelengthError = "Not enough wavelengths given for calculation."; MITK_ERROR << invalidWavelengthError; mitkThrow() << invalidWavelengthError; } MITK_INFO << "LOADING...[DONE]"; } void mitk::pa::SpectralUnmixingFilter::AddChromophore(int chromophore) { MITK_INFO << "ADD CHROMOPHORE..."; m_Chromophores.push_back(chromophore); } Probably easier to implement in the Plugin like: if (slot x then do algorithm x) void mitk::pa::SpectralUnmixingFilter::ChooseAlgorithm(int algorithm) { MITK_INFO << "CHOOSE ALGORITHM..."; m_Chromophores.push_back(algorithm); }*/ 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 bee296101c..893093eb6c 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,170 +1,276 @@ /*=================================================================== 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 + // 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); } // 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"; } } // Not correct working alternativ for wavelengths /*void SpectralUnmixing::Wavelength() { auto m_SpectralUnmixingFilter = mitk::pa::SpectralUnmixingFilter::New(); wavelength = m_Controls.spinBoxAddWavelength->value(); m_SpectralUnmixingFilter->AddWavelength(wavelength); MITK_INFO << wavelength << " nm"; }*/ 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(); // actually do something here... // 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 == true) + if (DeOxbool || Oxbool) { MITK_INFO << "CHOSEN CHROMOPHORES:"; } - if (Oxbool == true) + if (Oxbool) { numberofChromophores += 1; MITK_INFO << "- Oxyhemoglobin"; } - if (DeOxbool == true) + if (DeOxbool) { numberofChromophores += 1; MITK_INFO << "- Deoxygenated hemoglobin"; } 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!"; } - + + //Test region: + + //code 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(); + + + auto m_SpectralUnmixingFilter = mitk::pa::SpectralUnmixingFilter::New(); + + 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(); + + + //try to make another wavelength impementation using "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(); + + + + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ next usefull? + + MITK_INFO << "ERROR TEST 1"; + + mitk::Image::Pointer HbO2 = m_SpectralUnmixingFilter->GetOutput(0); + HbO2->GetGeometry()->SetIndexToWorldTransform(inputImage->GetGeometry()->GetIndexToWorldTransform()); + MITK_INFO << "ERROR TEST 1"; + + // works ^ ; doesn't work v + + /* + mitk::ImageWriteAccessor writeOutputHbO2(HbO2, HbO2->GetVolumeData()); + MITK_INFO << "ERROR TEST 1"; + + double* outputArrayHbO2 = (double *)writeOutputHbO2.GetData(); + + MITK_INFO << "ERROR TEST 1"; + + mitk::DataNode::Pointer dataNodeHbO2 = mitk::DataNode::New(); + dataNodeHbO2->SetData(HbO2); + dataNodeHbO2->SetName("HbO2"); + this->GetDataStorage()->Add(dataNodeHbO2); + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); + + + + 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_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 a4d805ab56..5fa1c7289b 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,75 +1,86 @@ /*=================================================================== 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" +//test +#include "mitkPAPropertyCalculator.h" + + + + // Perform Spectral Unmixing //include "mitkPASpectralUnmixingFilter.h" //--> include does not work //solution fprr cpp file 'Just right-click on the project -> Configuration Properties -> C/C++ -> General -> Additional Include Directories.' //https://stackoverflow.com/questions/12561048/visual-studio-cannot-include-header-file /** \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; + 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(); unsigned int wavelength; unsigned int numberofChromophores; Ui::SpectralUnmixingControls m_Controls; + + // Test: + + mitk::pa::PropertyCalculator::Pointer m_PropertyCalculator; + }; #endif // SpectralUnmixing_h