diff --git a/Modules/PhotoacousticsLib/include/mitkPAMonteCarloThreadHandler.h b/Modules/PhotoacousticsLib/include/mitkPAMonteCarloThreadHandler.h index 7dc40fa691..a459c83564 100644 --- a/Modules/PhotoacousticsLib/include/mitkPAMonteCarloThreadHandler.h +++ b/Modules/PhotoacousticsLib/include/mitkPAMonteCarloThreadHandler.h @@ -1,66 +1,95 @@ /*=================================================================== 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 MITKMONTECARLOTHREADHANDLER_H #define MITKMONTECARLOTHREADHANDLER_H #include #include #include //Includes for smart pointer usage #include "mitkCommon.h" #include "itkLightObject.h" namespace mitk { namespace pa { /** * @brief The PhotoacousticStatefulObject class * Designed for inheritence. Provides a state member variable and convenience methods to check * for the state. */ class MITKPHOTOACOUSTICSLIB_EXPORT MonteCarloThreadHandler : public itk::LightObject { public: mitkClassMacroItkParent(MonteCarloThreadHandler, itk::LightObject) mitkNewMacro2Param(MonteCarloThreadHandler, long, bool) + mitkNewMacro3Param(MonteCarloThreadHandler, long, bool, bool) long GetNextWorkPackage(); void SetPackageSize(long sizeInMilliseconsOrNumberOfPhotons); + itkGetMacro(NumberPhotonsToSimulate, long); + itkGetMacro(NumberPhotonsRemaining, long); + itkGetMacro(WorkPackageSize, long); + itkGetMacro(SimulationTime, long); + itkGetMacro(SimulateOnTimeBasis, bool); + itkGetMacro(Verbose, bool); + protected: long m_NumberPhotonsToSimulate; long m_NumberPhotonsRemaining; long m_WorkPackageSize; long m_SimulationTime; long m_Time; bool m_SimulateOnTimeBasis; + bool m_Verbose; std::mutex m_MutexRemainingPhotonsManipulation; /** * @brief PhotoacousticThreadhandler * @param timInMilliseconsOrNumberofPhotons * @param simulateOnTimeBasis */ MonteCarloThreadHandler(long timInMilliseconsOrNumberofPhotons, bool simulateOnTimeBasis); + + /** + * @brief PhotoacousticThreadhandler + * @param timInMilliseconsOrNumberofPhotons + * @param simulateOnTimeBasis + * @param verbose + */ + MonteCarloThreadHandler(long timInMilliseconsOrNumberofPhotons, bool simulateOnTimeBasis, bool verbose); virtual ~MonteCarloThreadHandler(); }; + + /** + * @brief Equal A function comparing two thread handlers for beeing equal + * + * @param rightHandSide A object to be compared + * @param leftHandSide A object to be compared + * @param eps tolarence for comparison. You can use mitk::eps in most cases. + * @param verbose flag indicating if the user wants detailed console output or not. + * @return true, if all subsequent comparisons are true, false otherwise + */ + MITKPHOTOACOUSTICSLIB_EXPORT bool Equal(const MonteCarloThreadHandler::Pointer leftHandSide, + const MonteCarloThreadHandler::Pointer rightHandSide, double eps, bool verbose); } } #endif // MITKMONTECARLOTHREADHANDLER_H diff --git a/Modules/PhotoacousticsLib/src/Utils/Thread/mitkPAMonteCarloThreadHandler.cpp b/Modules/PhotoacousticsLib/src/Utils/Thread/mitkPAMonteCarloThreadHandler.cpp index 2681ebe693..ce8aea1df5 100644 --- a/Modules/PhotoacousticsLib/src/Utils/Thread/mitkPAMonteCarloThreadHandler.cpp +++ b/Modules/PhotoacousticsLib/src/Utils/Thread/mitkPAMonteCarloThreadHandler.cpp @@ -1,74 +1,143 @@ /*=================================================================== 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 "mitkPAMonteCarloThreadHandler.h" #include "mitkCommon.h" -mitk::pa::MonteCarloThreadHandler::MonteCarloThreadHandler(long timInMilliseconsOrNumberofPhotons, bool simulateOnTimeBasis) +mitk::pa::MonteCarloThreadHandler::MonteCarloThreadHandler(long timInMillisecondsOrNumberofPhotons, bool simulateOnTimeBasis) : + MonteCarloThreadHandler(timInMillisecondsOrNumberofPhotons, simulateOnTimeBasis, true) { +} + +mitk::pa::MonteCarloThreadHandler::MonteCarloThreadHandler(long timInMillisecondsOrNumberofPhotons, bool simulateOnTimeBasis, bool verbose) +{ + m_Verbose = verbose; m_SimulateOnTimeBasis = simulateOnTimeBasis; + m_WorkPackageSize = 10000L; + m_SimulationTime = 0; + m_Time = 0; + m_NumberPhotonsToSimulate = 0; + m_NumberPhotonsRemaining = 0; + if (m_SimulateOnTimeBasis) { - m_SimulationTime = timInMilliseconsOrNumberofPhotons; + m_SimulationTime = timInMillisecondsOrNumberofPhotons; m_Time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); - m_WorkPackageSize = 10000L; } else { - m_NumberPhotonsToSimulate = timInMilliseconsOrNumberofPhotons; - m_NumberPhotonsRemaining = timInMilliseconsOrNumberofPhotons; - m_WorkPackageSize = 10000L; + m_NumberPhotonsToSimulate = timInMillisecondsOrNumberofPhotons; + m_NumberPhotonsRemaining = timInMillisecondsOrNumberofPhotons; } + MITK_INFO << "Created!"; } mitk::pa::MonteCarloThreadHandler::~MonteCarloThreadHandler() { } long mitk::pa::MonteCarloThreadHandler::GetNextWorkPackage() { long workPackageSize = 0; if (m_SimulateOnTimeBasis) { long now = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); if (now - m_Time <= m_SimulationTime) { workPackageSize = m_WorkPackageSize; - std::cout << "" << std::endl; + if (m_Verbose) + { + std::cout << "" << std::endl; + } } } else { m_MutexRemainingPhotonsManipulation.lock(); if (m_NumberPhotonsRemaining < m_WorkPackageSize) + { workPackageSize = m_NumberPhotonsRemaining; + } else + { workPackageSize = m_WorkPackageSize; + } m_NumberPhotonsRemaining -= workPackageSize; m_MutexRemainingPhotonsManipulation.unlock(); - std::cout << "" << std::endl; + if (m_Verbose) + { + std::cout << "" << std::endl; + } } return workPackageSize; } void mitk::pa::MonteCarloThreadHandler::SetPackageSize(long sizeInMilliseconsOrNumberOfPhotons) { m_WorkPackageSize = sizeInMilliseconsOrNumberOfPhotons; } + +bool mitk::pa::Equal(const MonteCarloThreadHandler::Pointer leftHandSide, + const MonteCarloThreadHandler::Pointer rightHandSide, double eps, bool verbose) +{ + if (rightHandSide->GetNumberPhotonsRemaining() != leftHandSide->GetNumberPhotonsRemaining()) + { + MITK_INFO(verbose) << "Number of Photons remaining wasnt equal: lhs=" << + leftHandSide->GetNumberPhotonsRemaining() << " rhs=" << rightHandSide->GetNumberPhotonsRemaining(); + return false; + } + + if (rightHandSide->GetNumberPhotonsToSimulate() != leftHandSide->GetNumberPhotonsToSimulate()) + { + MITK_INFO(verbose) << "Number of Photons to simulate wasnt equal: lhs=" << + leftHandSide->GetNumberPhotonsToSimulate() << " rhs=" << rightHandSide->GetNumberPhotonsToSimulate(); + return false; + } + + if (rightHandSide->GetWorkPackageSize() != leftHandSide->GetWorkPackageSize()) + { + MITK_INFO(verbose) << "WorkPackageSize wasnt equal: lhs=" << + leftHandSide->GetWorkPackageSize() << " rhs=" << rightHandSide->GetWorkPackageSize(); + return false; + } + + if (rightHandSide->GetSimulationTime() != leftHandSide->GetSimulationTime()) + { + MITK_INFO(verbose) << "Simulationtime wasnt equal: lhs=" << + leftHandSide->GetSimulationTime() << " rhs=" << rightHandSide->GetSimulationTime(); + return false; + } + + if (rightHandSide->GetSimulateOnTimeBasis() != leftHandSide->GetSimulateOnTimeBasis()) + { + MITK_INFO(verbose) << "simulation on time basis wasnt equal: lhs=" << + leftHandSide->GetSimulateOnTimeBasis() << " rhs=" << rightHandSide->GetSimulateOnTimeBasis(); + return false; + } + + if (rightHandSide->GetVerbose() != leftHandSide->GetVerbose()) + { + MITK_INFO(verbose) << "Verbose wasnt equal: lhs=" << + leftHandSide->GetVerbose() << " rhs=" << rightHandSide->GetVerbose(); + return false; + } + + return true; +}