Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkPAMonteCarloThreadHandler.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 
14 #include "mitkCommon.h"
15 
16 mitk::pa::MonteCarloThreadHandler::MonteCarloThreadHandler(long timInMillisecondsOrNumberofPhotons, bool simulateOnTimeBasis) :
17  MonteCarloThreadHandler(timInMillisecondsOrNumberofPhotons, simulateOnTimeBasis, true){}
18 
19 mitk::pa::MonteCarloThreadHandler::MonteCarloThreadHandler(long timInMillisecondsOrNumberofPhotons, bool simulateOnTimeBasis, bool verbose)
20 {
22  m_SimulateOnTimeBasis = simulateOnTimeBasis;
23  m_WorkPackageSize = 10000L;
24  m_SimulationTime = 0;
25  m_Time = 0;
28 
30  {
31  m_SimulationTime = timInMillisecondsOrNumberofPhotons;
32  m_Time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
33  }
34  else
35  {
36  m_NumberPhotonsToSimulate = timInMillisecondsOrNumberofPhotons;
37  m_NumberPhotonsRemaining = timInMillisecondsOrNumberofPhotons;
38  }
39 }
40 
42 {
43 }
44 
46 {
47  long workPackageSize = 0;
49  {
50  long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
51  if (now - m_Time <= m_SimulationTime)
52  {
53  workPackageSize = m_WorkPackageSize;
54  if (m_Verbose)
55  {
56  std::cout << "<filter-progress-text progress='" << ((double)(now - m_Time) / m_SimulationTime) << "'></filter-progress-text>" << std::endl;
57  }
58  }
59  }
60  else
61  {
63 
65  {
66  workPackageSize = m_NumberPhotonsRemaining;
67  }
68  else
69  {
70  workPackageSize = m_WorkPackageSize;
71  }
72 
73  m_NumberPhotonsRemaining -= workPackageSize;
75 
76  if (m_Verbose)
77  {
78  std::cout << "<filter-progress-text progress='" << 1.0 - ((double)m_NumberPhotonsRemaining / m_NumberPhotonsToSimulate) << "'></filter-progress-text>" << std::endl;
79  }
80  }
81 
82  return workPackageSize;
83 }
84 
85 void mitk::pa::MonteCarloThreadHandler::SetPackageSize(long sizeInMilliseconsOrNumberOfPhotons)
86 {
87  m_WorkPackageSize = sizeInMilliseconsOrNumberOfPhotons;
88 }
89 
90 bool mitk::pa::Equal(const MonteCarloThreadHandler::Pointer leftHandSide,
91  const MonteCarloThreadHandler::Pointer rightHandSide, double /*eps*/, bool verbose)
92 {
93  if (rightHandSide->GetNumberPhotonsRemaining() != leftHandSide->GetNumberPhotonsRemaining())
94  {
95  MITK_INFO(verbose) << "Number of Photons remaining wasnt equal: lhs=" <<
96  leftHandSide->GetNumberPhotonsRemaining() << " rhs=" << rightHandSide->GetNumberPhotonsRemaining();
97  return false;
98  }
99 
100  if (rightHandSide->GetNumberPhotonsToSimulate() != leftHandSide->GetNumberPhotonsToSimulate())
101  {
102  MITK_INFO(verbose) << "Number of Photons to simulate wasnt equal: lhs=" <<
103  leftHandSide->GetNumberPhotonsToSimulate() << " rhs=" << rightHandSide->GetNumberPhotonsToSimulate();
104  return false;
105  }
106 
107  if (rightHandSide->GetWorkPackageSize() != leftHandSide->GetWorkPackageSize())
108  {
109  MITK_INFO(verbose) << "WorkPackageSize wasnt equal: lhs=" <<
110  leftHandSide->GetWorkPackageSize() << " rhs=" << rightHandSide->GetWorkPackageSize();
111  return false;
112  }
113 
114  if (rightHandSide->GetSimulationTime() != leftHandSide->GetSimulationTime())
115  {
116  MITK_INFO(verbose) << "Simulationtime wasnt equal: lhs=" <<
117  leftHandSide->GetSimulationTime() << " rhs=" << rightHandSide->GetSimulationTime();
118  return false;
119  }
120 
121  if (rightHandSide->GetSimulateOnTimeBasis() != leftHandSide->GetSimulateOnTimeBasis())
122  {
123  MITK_INFO(verbose) << "simulation on time basis wasnt equal: lhs=" <<
124  leftHandSide->GetSimulateOnTimeBasis() << " rhs=" << rightHandSide->GetSimulateOnTimeBasis();
125  return false;
126  }
127 
128  if (rightHandSide->GetVerbose() != leftHandSide->GetVerbose())
129  {
130  MITK_INFO(verbose) << "Verbose wasnt equal: lhs=" <<
131  leftHandSide->GetVerbose() << " rhs=" << rightHandSide->GetVerbose();
132  return false;
133  }
134 
135  return true;
136 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
void SetPackageSize(long sizeInMilliseconsOrNumberOfPhotons)
MITKPHOTOACOUSTICSLIB_EXPORT bool Equal(const MonteCarloThreadHandler::Pointer leftHandSide, const MonteCarloThreadHandler::Pointer rightHandSide, double eps, bool verbose)
Equal A function comparing two thread handlers for beeing equal.
bool verbose(false)
MonteCarloThreadHandler(long timInMilliseconsOrNumberofPhotons, bool simulateOnTimeBasis)
PhotoacousticThreadhandler.
The PhotoacousticStatefulObject class Designed for inheritence. Provides a state member variable and ...