Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPAProbe.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkPAProbe.h"
14 
15 mitk::pa::Probe::Probe(std::string file, bool verbose) :
16  m_TotalEnergy(0),
17  m_Verbose(verbose)
18 {
19  TiXmlDocument xmlDoc(file);
20  bool success = xmlDoc.LoadFile(TIXML_ENCODING_UTF8);
21  if (m_Verbose)
22  {
23  std::cout << "reading of document was " << (success ? "" : "not ") << "successful" << std::endl;
24  std::cout << "Content of the Xml file:" << std::endl;
25  xmlDoc.Print();
26  }
27  if (success)
28  {
29  InitProbe(xmlDoc);
30  }
31  else
32  {
33  if (m_Verbose)
34  {
35  std::cerr << "Could not load xml file" << std::endl;
36  }
37  }
38 }
39 
40 mitk::pa::Probe::Probe(const char* fileStream, bool verbose) :
41  m_TotalEnergy(0),
42  m_Verbose(verbose)
43 {
44  TiXmlDocument xmlDoc;
45  const char* success = xmlDoc.Parse(fileStream, nullptr, TIXML_ENCODING_UTF8);
46  if (m_Verbose)
47  {
48  std::cout << "reading document was " << (success == nullptr ? "" : "not ") << "successful (" << (success == nullptr ? "NULL" : success) << ")" << std::endl;
49  std::cout << "Content of the Xml file:" << std::endl;
50  xmlDoc.Print();
51  }
52  if (success == nullptr || atoi(success) == 0)
53  {
54  InitProbe(xmlDoc);
55  }
56  else
57  {
58  if (m_Verbose)
59  {
60  std::cerr << "Could not load xml file" << std::endl;
61  }
62  }
63 }
64 
66 {
67 }
68 
70  double rnd3, double rnd4, double rnd5,
71  double rnd6, double rnd7, double rnd8)
72 {
73  rng1 = rng1*m_TotalEnergy;
74  double currentEnergy = 0;
75  for (LightSource::Pointer lightSource : m_LightSources)
76  {
77  currentEnergy += lightSource->GetEnergy();
78  if (currentEnergy >= rng1)
79  return lightSource->GetNextPhoton(rnd2, rnd3, rnd4, rnd5, rnd6, rnd7, rnd8);
80  }
81 
82  //Last resort: If something goes wrong, return a position from the first source.
83  return m_LightSources[0]->GetNextPhoton(rnd2, rnd3, rnd4, rnd5, rnd6, rnd7, rnd8);
84 }
85 
87 {
88  return m_IsValid;
89 }
90 
91 void mitk::pa::Probe::InitProbe(TiXmlDocument xmlDoc)
92 {
93  m_IsValid = true;
94 
95  TiXmlElement* root = xmlDoc.FirstChildElement(XML_TAG_PROBE);
96  if (root)
97  {
98  for (TiXmlElement* element = root->FirstChildElement(XML_TAG_LIGHT_SOURCE);
99  element != nullptr; element = element->NextSiblingElement(XML_TAG_LIGHT_SOURCE))
100  {
101  LightSource::Pointer lightSource = LightSource::New(element, m_Verbose);
102  if (lightSource.IsNotNull() && lightSource->IsValid())
103  {
104  m_LightSources.push_back(lightSource);
105  m_TotalEnergy += lightSource->GetEnergy();
106  }
107  else
108  {
109  m_IsValid = false;
110  }
111  }
112  }
113  else
114  {
115  m_IsValid = false;
116  }
117 
118  if (!m_IsValid)
119  {
120  std::cerr << "Creation of a valid Photoacoustic Probe failed." << std::endl;
121  }
122  else
123  {
124  if (m_Verbose)
125  {
126  std::cout << "Successfully created Photoacoustic Probe." << std::endl;
127  }
128  }
129 }
void InitProbe(TiXmlDocument document)
Definition: mitkPAProbe.cpp:91
std::vector< LightSource::Pointer > m_LightSources
Definition: mitkPAProbe.h:56
LightSource::PhotonInformation GetNextPhoton(double rng1, double rnd2, double rnd3, double rnd4, double rnd5, double rnd6, double rnd7, double rnd8)
Definition: mitkPAProbe.cpp:69
bool mitkNewMacro2Param(Self, const char *, bool) const std const std::strin XML_TAG_LIGHT_SOURCE)
Definition: mitkPAProbe.h:43
bool verbose(false)
~Probe() override
Definition: mitkPAProbe.cpp:65
double m_TotalEnergy
Definition: mitkPAProbe.h:58
Probe(std::string xmlFile, bool verbose)
Definition: mitkPAProbe.cpp:15