diff --git a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp index e65b026001..23df49e71b 100644 --- a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp +++ b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp @@ -1,134 +1,134 @@ /*=================================================================== 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 "mitkPhotoacousticProbe.h" mitk::PhotoacousticProbe::PhotoacousticProbe(std::string file, bool verbose) : m_TotalEnergy(0), m_Verbose(verbose) { TiXmlDocument xmlDoc(file); bool success = xmlDoc.LoadFile(TIXML_ENCODING_UTF8); if(m_Verbose) { std::cout << "reading of document was " << (success ? "" : "not ") << "successful" << std::endl; std::cout << "Content of the Xml file:" << std::endl; xmlDoc.Print(); } if(success) { InitProbe(xmlDoc); } else { if(m_Verbose) { std::cerr << "Could not load xml file" << std::endl; } } } mitk::PhotoacousticProbe::PhotoacousticProbe(const char* fileStream, bool verbose) : m_TotalEnergy(0), m_Verbose(verbose) { TiXmlDocument xmlDoc; const char* success = xmlDoc.Parse(fileStream, 0, TIXML_ENCODING_UTF8); if(m_Verbose) { std::cout << "reading document was " << (success==nullptr ? "" : "not ")<< "successful (" << (success==nullptr ? "NULL" : success) << ")" << std::endl ; std::cout << "Content of the Xml file:" << std::endl; xmlDoc.Print(); } if(success == nullptr || atoi(success)==0) { InitProbe(xmlDoc); } else { if(m_Verbose) { std::cerr << "Could not load xml file" << std::endl; } } } mitk::PhotoacousticProbe::~PhotoacousticProbe() { } mitk::PhotoacousticLightSource::PhotonInformation mitk::PhotoacousticProbe::GetNextPhoton(double rng1, double rnd2, double rnd3, double rnd4, double rnd5, double rnd6, double rnd7, double rnd8) { rng1 = rng1*m_TotalEnergy; double currentEnergy = 0; for(mitk::PhotoacousticLightSource::Pointer lightSource : m_LightSources) { currentEnergy += lightSource->GetEnergy(); if(currentEnergy>=rng1) return lightSource->GetNextPhoton(rnd2, rnd3, rnd4, rnd5, rnd6, rnd7, rnd8); } //Last resort: If something goes wrong, return a position from the first source. return m_LightSources[0]->GetNextPhoton(rnd2, rnd3, rnd4, rnd5, rnd6, rnd7, rnd8); } bool mitk::PhotoacousticProbe::IsValid() { return m_IsValid; } void mitk::PhotoacousticProbe::InitProbe(TiXmlDocument xmlDoc) { m_IsValid = true; - TiXmlElement* root= xmlDoc.FirstChildElement("Probe"); + TiXmlElement* root= xmlDoc.FirstChildElement(XML_TAG_PROBE); if(root) { - for(TiXmlElement* element = root->FirstChildElement("LightSource"); - element !=nullptr; element = element->NextSiblingElement("LightSource")) + for(TiXmlElement* element = root->FirstChildElement(XML_TAG_LIGHT_SOURCE); + element !=nullptr; element = element->NextSiblingElement(XML_TAG_LIGHT_SOURCE)) { mitk::PhotoacousticLightSource::Pointer lightSource = mitk::PhotoacousticLightSource::New(element, m_Verbose); if(lightSource.IsNotNull() && lightSource->IsValid()) { m_LightSources.push_back(lightSource); m_TotalEnergy += lightSource->GetEnergy(); } else { m_IsValid = false; } } } else { m_IsValid = false; } if(!m_IsValid) { std::cerr << "Creation of a valid Photoacoustic Probe failed." << std::endl; } else { if(m_Verbose) { std::cout << "Successfully created Photoacoustic Probe." << std::endl; } } } diff --git a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.h b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.h index 03e8571352..005e5e3fae 100644 --- a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.h +++ b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.h @@ -1,68 +1,71 @@ /*=================================================================== 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 MITKPHOTOACOUSTICPROBE_H #define MITKPHOTOACOUSTICPROBE_H #include #include //Includes for smart pointer usage #include "mitkCommon.h" #include "itkLightObject.h" #include "mitkPhotoacousticLightSource.h" #include #include namespace mitk { /** * @brief The PhotoacousticProbe class * The representation of a PhotoacousticProbe */ class MITKPHOTOACOUSTICSIMULATION_EXPORT PhotoacousticProbe : public itk::LightObject { public: mitkClassMacroItkParent(mitk::PhotoacousticProbe, itk::LightObject) mitkNewMacro2Param(Self, std::string, bool) mitkNewMacro2Param(Self, const char*, bool) + const std::string XML_TAG_PROBE = "Probe"; + const std::string XML_TAG_LIGHT_SOURCE = "LightSource"; + mitk::PhotoacousticLightSource::PhotonInformation GetNextPhoton(double rng1, double rnd2, double rnd3, double rnd4, double rnd5, double rnd6, double rnd7, double rnd8); bool IsValid(); PhotoacousticProbe(std::string xmlFile, bool verbose); PhotoacousticProbe(const char* fileStream, bool verbose); virtual ~PhotoacousticProbe(); protected: std::vector m_LightSources; bool m_IsValid; double m_TotalEnergy; bool m_Verbose; void InitProbe(TiXmlDocument document); }; } #endif // MITKPHOTOACOUSTICPROBE_H