diff --git a/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.cpp b/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.cpp index a4742d0c97..f6115cf088 100644 --- a/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.cpp +++ b/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.cpp @@ -1,310 +1,317 @@ /*=================================================================== 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 "PASimulator.h" // Qt #include #include #include // mitk #include #include #include #ifdef __linux__ #include #include #else #include #endif #include #include const std::string PASimulator::VIEW_ID = "org.mitk.views.pasimulator"; void PASimulator::SetFocus() { m_Controls.pushButtonShowRandomTissue->setFocus(); } void PASimulator::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect(m_Controls.pushButtonShowRandomTissue, SIGNAL(clicked()), this, SLOT(DoImageProcessing()) ); connect(m_Controls.checkBoxGauss, SIGNAL(stateChanged(int)), this, SLOT(ClickedGaussBox())); connect(m_Controls.pushButtonOpenPath, SIGNAL(clicked()), this, SLOT(OpenFolder()) ); connect(m_Controls.pushButtonOpenBinary, SIGNAL(clicked()), this, SLOT(OpenBinary()) ); connect(m_Controls.checkBoxGenerateBatch, SIGNAL(clicked()), this, SLOT(UpdateVisibilityOfBatchCreation()) ); connect(m_Controls.pushButtonAjustWavelength, SIGNAL(clicked()), this, SLOT(UpdateParametersAccordingToWavelength()) ); connect(m_Controls.checkBoxRngSeed, SIGNAL(clicked()), this, SLOT(ClickedCheckboxFixedSeed()) ); + connect(m_Controls.checkBoxRandomizeParameters, SIGNAL(clicked()), this, SLOT(ClickedRandomizePhysicalParameters()) ); m_Controls.spinboxSigma->setEnabled(false); m_Controls.labelSigma->setEnabled(false); m_Controls.label_NrrdFilePath->setText((std::string(getenv("HOME"))+"/").c_str()); m_PhotoacousticPropertyCalculator = mitk::PhotoacousticPropertyCalculator::New(); UpdateVisibilityOfBatchCreation(); + ClickedRandomizePhysicalParameters(); ClickedCheckboxFixedSeed(); ClickedGaussBox(); } +void PASimulator::ClickedRandomizePhysicalParameters() +{ + m_Controls.spinboxRandomizeParameters->setEnabled(m_Controls.checkBoxRandomizeParameters->isChecked()); +} + void PASimulator::ClickedCheckboxFixedSeed() { m_Controls.spinBoxRngSeed->setEnabled(m_Controls.checkBoxRngSeed->isChecked()); } void PASimulator::UpdateParametersAccordingToWavelength() { int wavelength = m_Controls.spinboxWavelength->value(); double bloodOxygenation = m_Controls.spinboxBloodOxygenSaturation->value()/100; mitk::PhotoacousticPropertyCalculator::Properties result = m_PhotoacousticPropertyCalculator->CalculatePropertyForSpecificWavelength( mitk::PhotoacousticPropertyCalculator::TissueType::BLOOD, wavelength, bloodOxygenation); m_Controls.spinboxMaxAbsorption->setValue(result.mua); m_Controls.spinboxMinAbsorption->setValue(result.mua); m_Controls.spinboxBloodVesselScattering->setValue(result.mus); m_Controls.spinboxBloodVesselAnisotropy->setValue(result.g); result = m_PhotoacousticPropertyCalculator->CalculatePropertyForSpecificWavelength( mitk::PhotoacousticPropertyCalculator::TissueType::EPIDERMIS, wavelength, bloodOxygenation); m_Controls.spinboxSkinAbsorption->setValue(result.mua); m_Controls.spinboxSkinScattering->setValue(result.mus); m_Controls.spinboxSkinAnisotropy->setValue(result.g); result = m_PhotoacousticPropertyCalculator->CalculatePropertyForSpecificWavelength( mitk::PhotoacousticPropertyCalculator::TissueType::FAT, wavelength, bloodOxygenation); m_Controls.spinboxFatAbsorption->setValue(result.mua); m_Controls.spinboxFatScattering->setValue(result.mus); m_Controls.spinboxFatAnisotropy->setValue(result.g); result = m_PhotoacousticPropertyCalculator->CalculatePropertyForSpecificWavelength( mitk::PhotoacousticPropertyCalculator::TissueType::STANDARD_TISSUE, wavelength, bloodOxygenation); m_Controls.spinboxBackgroundAbsorption->setValue(result.mua); m_Controls.spinboxBackgroundScattering->setValue(result.mus); m_Controls.spinboxBackgroundAnisotropy->setValue(result.g); } void PASimulator::UpdateVisibilityOfBatchCreation() { m_Controls.widgetBatchFile->setVisible(m_Controls.checkBoxGenerateBatch->isChecked()); } void PASimulator::DoImageProcessing() { if(m_Controls.checkBoxGenerateBatch->isChecked()) { if(m_Controls.labelBinarypath->text().isNull() || m_Controls.labelBinarypath->text().isEmpty()) { QMessageBox::warning(nullptr, QString("Warning"), QString("You need to specify the binary first!")); return; } } int numberOfVolumes = m_Controls.spinboxNumberVolumes->value(); if(numberOfVolumes<1) { QMessageBox::warning(nullptr, QString("Warning"), QString("You need to create at least one volume!")); return; } // Getting values from UI double maxAbsorption = m_Controls.spinboxMaxAbsorption->value(); double minAbsorption = m_Controls.spinboxMinAbsorption->value(); double maxBending= m_Controls.spinboxMaxBending->value(); double minBending = m_Controls.spinboxMinBending->value(); double maxRadius = m_Controls.spinboxMaxDiameter->value(); double minRadius = m_Controls.spinboxMinDiameter->value(); int maxVessels = m_Controls.spinboxMaxVessels->value(); int minVessels = m_Controls.spinboxMinVessels->value(); int xDim = m_Controls.spinboxXDim->value(); int yDim = m_Controls.spinboxYDim->value(); int zDim = m_Controls.spinboxZDim->value(); int mcflag = m_Controls.spinboxMcFlag->value(); int launchflag = m_Controls.spinboxLaunchFlag->value(); int boundaryflag = m_Controls.spinboxboundaryFlag->value(); double launchPointX = m_Controls.spinboxLaunchpointX->value(); double launchPointY = m_Controls.spinboxLaunchpointY->value(); double launchPointZ = m_Controls.spinboxLaunchpointZ->value(); double focusPointX = m_Controls.spinboxFocuspointX->value(); double focusPointY = m_Controls.spinboxFocuspointY->value(); double focusPointZ = m_Controls.spinboxFocuspointZ->value(); double trajectoryVectorX = m_Controls.spinboxTrajectoryVectorX->value(); double trajectoryVectorY = m_Controls.spinboxTrajectoryVectorY->value(); double trajectoryVectorZ = m_Controls.spinboxTrajectoryVectorZ->value(); double radius = m_Controls.spinboxRadius->value(); double waist = m_Controls.spinboxWaist->value(); double sigma = m_Controls.spinboxSigma->value(); bool doGauss = m_Controls.checkBoxGauss->isChecked(); double basicAbsorption = m_Controls.spinboxBackgroundAbsorption->value(); double basicScattering = m_Controls.spinboxBackgroundScattering->value(); double basicAnisotropy = m_Controls.spinboxBackgroundAnisotropy->value(); double airThickness = m_Controls.spinboxAirThickness->value(); double fatPercentage = m_Controls.spinboxFatPercentage->value(); double fatAbsorption = m_Controls.spinboxFatAbsorption->value(); double fatScattering = m_Controls.spinboxFatScattering->value(); double fatAnisotropy = m_Controls.spinboxFatAnisotropy->value(); double skinThickness = m_Controls.spinboxSkinThickness->value(); double skinAbsorption = m_Controls.spinboxSkinAbsorption->value(); double skinScattering = m_Controls.spinboxSkinScattering->value(); double skinAnisotropy = m_Controls.spinboxSkinAnisotropy->value(); bool randomizePhysicalProperties = m_Controls.checkBoxRandomizeParameters->isChecked(); - double randomPercentage = m_Controls.spinboxRandomizeSigma->value(); + double randomPercentage = m_Controls.spinboxRandomizeParameters->value(); double spacing = m_Controls.spinboxSpacing->value(); int bifurcationFrequency = m_Controls.spinboxBifurcationFrequency->value(); double vesselScattering = m_Controls.spinboxBloodVesselScattering->value(); double vesselAnisotropy = m_Controls.spinboxBloodVesselAnisotropy->value(); bool useRngSeed = m_Controls.checkBoxRngSeed->isChecked(); long rngSeed = m_Controls.spinBoxRngSeed->value(); for(int volumeIndex = 0; volumeIndex < numberOfVolumes; volumeIndex++) { MITK_DEBUG << "Generating in silico data"; mitk::PhotoacousticVolume::Pointer volume = mitk::PhotoacousticTissueGenerator::GenerateInSilicoData(xDim, yDim, zDim, spacing, basicAbsorption, basicScattering, basicAnisotropy, airThickness, skinAbsorption, skinScattering, skinAnisotropy, skinThickness, fatAbsorption, fatScattering, fatAnisotropy, fatPercentage, randomizePhysicalProperties, randomPercentage, minVessels, maxVessels, minBending, maxBending, minAbsorption, maxAbsorption, minRadius, maxRadius, mcflag, launchflag, boundaryflag, launchPointX, launchPointY, launchPointZ, focusPointX, focusPointY, focusPointZ, trajectoryVectorX, trajectoryVectorY, trajectoryVectorZ, radius, waist, sigma, doGauss, bifurcationFrequency, vesselScattering, vesselAnisotropy, useRngSeed, rngSeed, &mitk::PhotoacousticVesselMeanderStrategy::CalculateRandomlyDivergingPosition); MITK_DEBUG << "Generating mitk::Image"; mitk::Image::Pointer tissueVolume = volume->ConvertToMitkImage(); if(m_Controls.checkBoxGenerateBatch->isChecked()) { std::string volumeNumber = ""; if(volumeIndex<10) { volumeNumber = "00" + std::to_string(volumeIndex); } else if(volumeIndex<100) { volumeNumber = "0" + std::to_string(volumeIndex); } else { volumeNumber = std::to_string(volumeIndex); } std::string outputFolderName = m_Controls.label_NrrdFilePath->text().toStdString() + m_Controls.lineEditTissueName->text().toStdString() + volumeNumber; std::string savePath = outputFolderName + ".nrrd"; mitk::IOUtil::Save(tissueVolume, savePath); std::string filename = "executescript"; std::string filenameAllSimulation = "simulate_all"; #ifdef __linux__ mkdir(outputFolderName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); filename += ".sh"; filenameAllSimulation += ".sh"; #else mkdir(outputFolderName.c_str()); filename += ".bat"; filenameAllSimulation += ".bat"; #endif std::ofstream file(outputFolderName+"/"+filename); if(file.is_open()) { for(double d = -1.8; d <=1.9; d+=0.12) { file << m_Controls.labelBinarypath->text().toStdString() << " -i " << savePath << " -o " << outputFolderName << "/" << m_Controls.lineEditTissueName->text().toStdString() << "_yo" << round(d*100) / 100 << ".nrrd" << " -yo " << round(d*100) / 100 << " -n " << (m_Controls.spinboxNumberPhotons->value()*1000L) << "\n"; } file.close(); } std::ofstream fileAllSimulation(m_Controls.label_NrrdFilePath->text().toStdString()+"/"+filenameAllSimulation, std::ios_base::app); if(fileAllSimulation.is_open()) { for(double d = -1.8; d <=1.9; d+=0.12) { fileAllSimulation << m_Controls.labelBinarypath->text().toStdString() << " -i " << savePath << " -o " << outputFolderName << "/" << m_Controls.lineEditTissueName->text().toStdString() << "_yo" << round(d*100) / 100 << ".nrrd" << " -yo " << round(d*100) / 100 << " -n " << (m_Controls.spinboxNumberPhotons->value()*1000L) << "\n"; } fileAllSimulation.close(); } } mitk::DataNode::Pointer dataNode = mitk::DataNode::New(); dataNode->SetData(tissueVolume); dataNode->SetName(m_Controls.lineEditTissueName->text().toStdString()); this->GetDataStorage()->Add(dataNode); mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); } MITK_DEBUG << "Handing stuff to UI Thread now.."; } void PASimulator::ClickedGaussBox() { if(m_Controls.checkBoxGauss->isChecked()) { m_Controls.spinboxSigma->setEnabled(true); m_Controls.labelSigma->setEnabled(true); } else { m_Controls.spinboxSigma->setEnabled(false); m_Controls.labelSigma->setEnabled(false); } } void PASimulator::OpenFolder() { m_Controls.label_NrrdFilePath->setText(QFileDialog::getExistingDirectory().append("/")); } void PASimulator::OpenBinary() { m_Controls.labelBinarypath->setText(QFileDialog::getOpenFileName()); } diff --git a/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.h b/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.h index 3d8056f9ed..db409bd8e9 100644 --- a/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.h +++ b/Plugins/org.mitk.gui.qt.photoacousticsimulation/src/internal/PASimulator.h @@ -1,76 +1,77 @@ /*=================================================================== 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 PASimulator_h #define PASimulator_h #include #include #include "ui_PASimulatorControls.h" #include "mitkPhotoacousticTissueGenerator.h" #include "mitkPhotoacousticVolume.h" #include "mitkPhotoacousticPropertyCalculator.h" /** \brief PASimulator \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 PASimulator : 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 slots: /// \brief Called when the user clicks the GUI button void DoImageProcessing(); void ClickedGaussBox(); void ClickedCheckboxFixedSeed(); + void ClickedRandomizePhysicalParameters(); void OpenFolder(); void OpenBinary(); void UpdateVisibilityOfBatchCreation(); void UpdateParametersAccordingToWavelength(); protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; Ui::PASimulatorControls m_Controls; mitk::PhotoacousticPropertyCalculator::Pointer m_PhotoacousticPropertyCalculator; private: }; #endif // PASimulator_h