diff --git a/Modules/PhotoacousticSimulation/Testing/Resources/allsources.xml b/Modules/PhotoacousticSimulation/Testing/Resources/allsources.xml
new file mode 100644
index 0000000000..36a213c5f9
--- /dev/null
+++ b/Modules/PhotoacousticSimulation/Testing/Resources/allsources.xml
@@ -0,0 +1,70 @@
+
+
+
+ 1
+
+ POINT
+ 0.3
+ 0.2
+ 0.1
+
+
+
+ -0.1
+ 0.1
+ UNIFORM
+
+
+ -0.2
+ 0.2
+ UNIFORM
+
+
+
+
+ 1
+
+ RECTANGLE
+ 0.4
+ 0.5
+ 0.6
+ 0.7
+ 0.8
+ 0.9
+
+
+
+ -0.3
+ 0.3
+ GAUSSIAN
+
+
+ -0.4
+ 0.4
+ GAUSSIAN
+
+
+
+
+ 1
+
+ CIRCLE
+ 0.4
+ 0.5
+ 0.6
+ 0.5
+
+
+
+ -0.3
+ 0.3
+ GAUSSIAN
+
+
+ -0.4
+ 0.4
+ GAUSSIAN
+
+
+
+
diff --git a/Modules/PhotoacousticSimulation/Testing/Resources/circlesource.xml b/Modules/PhotoacousticSimulation/Testing/Resources/circlesource.xml
new file mode 100644
index 0000000000..14ef65dd58
--- /dev/null
+++ b/Modules/PhotoacousticSimulation/Testing/Resources/circlesource.xml
@@ -0,0 +1,25 @@
+
+
+
+ 1
+
+ CIRCLE
+ 0.3
+ 0.2
+ 0.1
+ 2
+
+
+
+ -0.1
+ 0.1
+ GAUSSIAN
+
+
+ -0.2
+ 0.2
+ UNIFORM
+
+
+
+
diff --git a/Modules/PhotoacousticSimulation/Testing/Resources/rectanglesource.xml b/Modules/PhotoacousticSimulation/Testing/Resources/rectanglesource.xml
new file mode 100644
index 0000000000..7c9a4f2f9e
--- /dev/null
+++ b/Modules/PhotoacousticSimulation/Testing/Resources/rectanglesource.xml
@@ -0,0 +1,27 @@
+
+
+
+ 1
+
+ RECTANGLE
+ 0.3
+ 0.2
+ 0.1
+ 1
+ 2
+ 3
+
+
+
+ -0.1
+ 0.1
+ UNIFORM
+
+
+ -0.2
+ 0.2
+ UNIFORM
+
+
+
+
diff --git a/Modules/PhotoacousticSimulation/Testing/Resources/twopointsources.xml b/Modules/PhotoacousticSimulation/Testing/Resources/twopointsources.xml
new file mode 100644
index 0000000000..5054ee51c8
--- /dev/null
+++ b/Modules/PhotoacousticSimulation/Testing/Resources/twopointsources.xml
@@ -0,0 +1,45 @@
+
+
+
+ 1
+
+ POINT
+ 0.3
+ 0.2
+ 0.1
+
+
+
+ -0.1
+ 0.1
+ UNIFORM
+
+
+ -0.2
+ 0.2
+ UNIFORM
+
+
+
+
+ 1
+
+ POINT
+ 0.4
+ 0.5
+ 0.6
+
+
+
+ -0.3
+ 0.3
+ GAUSSIAN
+
+
+ -0.4
+ 0.4
+ GAUSSIAN
+
+
+
+
diff --git a/Modules/PhotoacousticSimulation/Testing/files.cmake b/Modules/PhotoacousticSimulation/Testing/files.cmake
index 536a64738f..615e5513a6 100644
--- a/Modules/PhotoacousticSimulation/Testing/files.cmake
+++ b/Modules/PhotoacousticSimulation/Testing/files.cmake
@@ -1,29 +1,33 @@
set(MODULE_TESTS
# IMPORTANT: If you plan to deactivate / comment out a test please write a bug number to the commented out line of code.
#
# Example: #mitkMyTest #this test is commented out because of bug 12345
#
# It is important that the bug is open and that the test will be activated again before the bug is closed. This assures that
# no test is forgotten after it was commented out. If there is no bug for your current problem, please add a new one and
# mark it as critical.
################## ON THE FENCE TESTS #################################################
# none
################## DISABLED TESTS #####################################################
# none
################# RUNNING TESTS #######################################################
mitkPhotoacousticTissueGeneratorTest.cpp
mitkPhotoacousticVectorTest.cpp
mitkPhotoacousticVolumeTest.cpp
mitkPhotoacousticVesselTest.cpp
mitkPhotoacousticVesselTreeTest.cpp
mitkPhotoacousticVesselMeanderStrategyTest.cpp
mitkMcxyzXmlTest.cpp
)
set(RESOURCE_FILES
pointsource.xml
+circlesource.xml
+rectanglesource.xml
+twopointsources.xml
+allsources.xml
)
diff --git a/Modules/PhotoacousticSimulation/Testing/mitkMcxyzXmlTest.cpp b/Modules/PhotoacousticSimulation/Testing/mitkMcxyzXmlTest.cpp
index e95c4a4f59..7b986decdf 100644
--- a/Modules/PhotoacousticSimulation/Testing/mitkMcxyzXmlTest.cpp
+++ b/Modules/PhotoacousticSimulation/Testing/mitkMcxyzXmlTest.cpp
@@ -1,75 +1,120 @@
/*===================================================================
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
#include
#include
// us
#include
#include
#include
#include
#include
class mitkMcxyzXmlTestSuite : public mitk::TestFixture
{
CPPUNIT_TEST_SUITE(mitkMcxyzXmlTestSuite);
- MITK_TEST(TestPointSourceProbeCreation);
-
+ MITK_TEST(TestPointSourceProbe);
+ MITK_TEST(TestCircleSourceProbe);
+ MITK_TEST(TestRectangleSourceProbe);
+ MITK_TEST(TestTwoPointSourcesProbe);
+ MITK_TEST(TestAllSourcesProbe);
CPPUNIT_TEST_SUITE_END();
private:
mitk::PhotoacousticProbe::Pointer m_Probe;
- const char* m_XmlProbePointSource;
+ std::string m_XmlProbePointSource;
+ std::string m_XmlProbeCircleSource;
+ std::string m_XmlProbeRectangleSource;
+ std::string m_XmlProbeTwoPointSources;
+ std::string m_XmlProbeAllSources;
public:
void setUp()
{
- us::ModuleResource pointSourceXml = us::GetModuleContext()->GetModule()->GetResource("pointsource.xml");
- std::string lines = "";
+ LoadXmlFile("pointsource.xml", &m_XmlProbePointSource);
+ LoadXmlFile("circlesource.xml", &m_XmlProbeCircleSource);
+ LoadXmlFile("rectanglesource.xml", &m_XmlProbeRectangleSource);
+ LoadXmlFile("twopointsources.xml", &m_XmlProbeTwoPointSources);
+ LoadXmlFile("allsources.xml", &m_XmlProbeAllSources);
+ }
+
+ void LoadXmlFile(std::string filename, std::string* lines)
+ {
+ us::ModuleResource pointSourceXml = us::GetModuleContext()->GetModule()->GetResource(filename);
std::string line;
- us::ModuleResourceStream stream(pointSourceXml);
- stream.std::istream::imbue(std::locale("en_GB.UTF-8"));
- while(std::getline(stream, line))
+ if(pointSourceXml.IsValid() && pointSourceXml.IsFile())
+ {
+ us::ModuleResourceStream stream(pointSourceXml);
+ stream.std::istream::imbue(std::locale("en_GB.UTF-8"));
+ while(std::getline(stream, line))
+ {
+ *lines = *lines + line + " ";
+ }
+ }
+ else
{
- lines = lines + line + "\n";
+ MITK_ERROR << "Xml file was not valid";
}
+ }
- m_XmlProbePointSource = lines.c_str();
+ void TestPointSourceProbe()
+ {
+ m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbePointSource.c_str(), true);
+ CPPUNIT_ASSERT(true == m_Probe->IsValid());
}
- void TestPointSourceProbeCreation()
+ void TestCircleSourceProbe()
{
- //std::string file = "/home/groehl/mbi/MITK/Modules/PhotoacousticSimulation/Testing/Resources/pointsource.xml";
- m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbePointSource, true);
+ m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbeCircleSource.c_str(), true);
+ CPPUNIT_ASSERT(true == m_Probe->IsValid());
+ }
+ void TestRectangleSourceProbe()
+ {
+ m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbeRectangleSource.c_str(), true);
CPPUNIT_ASSERT(true == m_Probe->IsValid());
+ }
+ void TestTwoPointSourcesProbe()
+ {
+ m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbeTwoPointSources.c_str(), true);
+ CPPUNIT_ASSERT(true == m_Probe->IsValid());
+ }
+
+ void TestAllSourcesProbe()
+ {
+ m_Probe = mitk::PhotoacousticProbe::New(m_XmlProbeAllSources.c_str(), true);
+ CPPUNIT_ASSERT(true == m_Probe->IsValid());
}
void tearDown()
{
- m_XmlProbePointSource = nullptr;
+ m_XmlProbePointSource = "";
+ m_XmlProbeCircleSource = "";
+ m_XmlProbeRectangleSource = "";
+ m_XmlProbeTwoPointSources = "";
+ m_XmlProbeAllSources = "";
m_Probe = nullptr;
}
};
MITK_TEST_SUITE_REGISTRATION(mitkMcxyzXml)
diff --git a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp
index cc12e37e1e..7c86a4b87e 100644
--- a/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp
+++ b/Modules/PhotoacousticSimulation/src/ProbeDesign/mitkPhotoacousticProbe.cpp
@@ -1,126 +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"
-void mitk::PhotoacousticProbe::InitProbe(TiXmlDocument xmlDoc)
-{
-
- TiXmlElement* root= xmlDoc.FirstChildElement("Probe");
- if(root)
- {
- for(TiXmlElement* element = root->FirstChildElement("LightSource");
- element !=nullptr; element = element->NextSiblingElement("LightSource"))
- {
- mitk::PhotoacousticLightSource::Pointer lightSource = mitk::PhotoacousticLightSource::New(element, m_Verbose);
- if(lightSource.IsNotNull() && lightSource->IsValid())
- {
- m_LightSources.push_back(lightSource);
- m_TotalEnergy += lightSource->GetEnergy();
- }
- }
- }
-
- m_IsValid = m_LightSources.size()>0;
-
- if(!m_IsValid)
- {
- MITK_ERROR << "Creation of a valid Photoacoustic Probe failed.";
- }
- else
- {
- if(m_Verbose)
- {
- MITK_INFO << "Successfully created Photoacoustic Probe.";
- }
- }
-}
-
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)
{
MITK_INFO << "reading of document was " << (success ? "" : "not ") << "successful";
MITK_INFO << "Content of the Xml file:";
xmlDoc.Print();
}
if(success)
{
InitProbe(xmlDoc);
}
else
{
if(m_Verbose)
{
MITK_ERROR << "Could not load xml file";
}
}
}
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)
{
- MITK_INFO << "reading document was " << (success==nullptr ? "" : "not ")<< "successful (" << atoi(success) << ")" ;
+ MITK_INFO << "reading document was " << (success==nullptr ? "" : "not ")<< "successful (" << (success==nullptr ? "NULL" : success) << ")" ;
MITK_INFO << "Content of the Xml file:";
xmlDoc.Print();
}
- if(atoi(success)==0)
+ if(success == nullptr || atoi(success)==0)
{
InitProbe(xmlDoc);
}
else
{
if(m_Verbose)
{
MITK_ERROR << "Could not load xml file";
}
}
}
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");
+ if(root)
+ {
+ for(TiXmlElement* element = root->FirstChildElement("LightSource");
+ element !=nullptr; element = element->NextSiblingElement("LightSource"))
+ {
+ 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)
+ {
+ MITK_ERROR << "Creation of a valid Photoacoustic Probe failed.";
+ }
+ else
+ {
+ if(m_Verbose)
+ {
+ MITK_INFO << "Successfully created Photoacoustic Probe.";
+ }
+ }
+}