diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp index 0a9c859b8e..bef4b6ff07 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilter.cpp @@ -1,101 +1,144 @@ /*=================================================================== 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!"; + + //Test region:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + //code from "old" SUF.cpp + + // now creats to identical output images lieke the input for hb and hb02 + + MITK_INFO << "GENERATING DATA.."; + unsigned int numberOfInputs = GetNumberOfIndexedInputs(); + unsigned int numberOfOutputs = GetNumberOfIndexedOutputs(); + + + for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) + { + GetOutput(outputIdx)->Initialize(GetInput(0)); + } + + long 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]"; + + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + } //// 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 893093eb6c..3767b2f6e6 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,276 +1,256 @@ /*=================================================================== 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) { MITK_INFO << "CHOSEN CHROMOPHORES:"; } if (Oxbool) { numberofChromophores += 1; MITK_INFO << "- Oxyhemoglobin"; } 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 - /* + HbO2->GetGeometry()->SetIndexToWorldTransform(inputImage->GetGeometry()->GetIndexToWorldTransform()); + 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::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); MITK_INFO << "Adding images to DataStorage...[DONE]"; -*/ - - - - - - + } } }