diff --git a/Modules/Simulation/files.cmake b/Modules/Simulation/files.cmake index e19aea7607..0171ffbecb 100644 --- a/Modules/Simulation/files.cmake +++ b/Modules/Simulation/files.cmake @@ -1,19 +1,23 @@ set(CPP_FILES mitkGetSimulationService.cpp mitkExportMitkVisitor.cpp mitkIndexROI.cpp mitkISimulationService.cpp + mitkRoundRobinSchedulingAlgorithm.cpp mitkSetVtkRendererVisitor.cpp + mitkSchedulableProcess.cpp + mitkScheduler.cpp + mitkSchedulingAlgorithmBase.cpp mitkSimulation.cpp mitkSimulationActivator.cpp mitkSimulationIOFactory.cpp mitkSimulationObjectFactory.cpp mitkSimulationReader.cpp mitkSimulationSerializer.cpp mitkSimulationService.cpp mitkSimulationVtkMapper3D.cpp mitkSimulationWriter.cpp mitkSimulationWriterFactory.cpp mitkVtkModel.cpp mitkVtkSimulationPolyDataMapper.cpp ) diff --git a/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.cpp b/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.cpp new file mode 100644 index 0000000000..d0568d9b5a --- /dev/null +++ b/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.cpp @@ -0,0 +1,35 @@ +/*=================================================================== + +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 "mitkSchedulableProcess.h" +#include "mitkRoundRobinSchedulingAlgorithm.h" + +mitk::RoundRobinSchedulingAlgorithm::RoundRobinSchedulingAlgorithm(std::vector* processQueue) + : SchedulingAlgorithmBase(processQueue) +{ +} + +mitk::RoundRobinSchedulingAlgorithm::~RoundRobinSchedulingAlgorithm() +{ +} + +mitk::SchedulableProcess* mitk::RoundRobinSchedulingAlgorithm::GetNextProcess() +{ + if (m_ProcessQueue->size() > 1) + std::swap(m_ProcessQueue->front(), m_ProcessQueue->back()); + + return m_ProcessQueue->back(); +} diff --git a/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.h b/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.h new file mode 100644 index 0000000000..699460993d --- /dev/null +++ b/Modules/Simulation/mitkRoundRobinSchedulingAlgorithm.h @@ -0,0 +1,38 @@ +/*=================================================================== + +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 mitkRoundRobinSchedulingAlgorithm_h +#define mitkRoundRobinSchedulingAlgorithm_h + +#include "mitkSchedulingAlgorithmBase.h" + +namespace mitk +{ + class RoundRobinSchedulingAlgorithm : public SchedulingAlgorithmBase + { + public: + explicit RoundRobinSchedulingAlgorithm(std::vector* processQueue); + ~RoundRobinSchedulingAlgorithm(); + + SchedulableProcess* GetNextProcess(); + + private: + RoundRobinSchedulingAlgorithm(const RoundRobinSchedulingAlgorithm&); + RoundRobinSchedulingAlgorithm& operator=(const RoundRobinSchedulingAlgorithm&); + }; +} + +#endif diff --git a/Modules/Simulation/mitkSchedulableProcess.cpp b/Modules/Simulation/mitkSchedulableProcess.cpp new file mode 100644 index 0000000000..5ed4245c4d --- /dev/null +++ b/Modules/Simulation/mitkSchedulableProcess.cpp @@ -0,0 +1,42 @@ +/*=================================================================== + +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 "mitkSchedulableProcess.h" + +mitk::SchedulableProcess::SchedulableProcess(int priority) + : m_Priority(priority), + m_LastTimeSliceInMSec(-1) +{ +} + +mitk::SchedulableProcess::~SchedulableProcess() +{ +} + +int mitk::SchedulableProcess::GetPriority() const +{ + return m_Priority; +} + +int mitk::SchedulableProcess::GetLastTimeSliceInMSec() const +{ + return m_LastTimeSliceInMSec; +} + +void mitk::SchedulableProcess::SetLastTimeSliceInMSec(int lastTimeSliceInMSec) +{ + m_LastTimeSliceInMSec = lastTimeSliceInMSec; +} diff --git a/Modules/Simulation/mitkSchedulableProcess.h b/Modules/Simulation/mitkSchedulableProcess.h new file mode 100644 index 0000000000..2495732042 --- /dev/null +++ b/Modules/Simulation/mitkSchedulableProcess.h @@ -0,0 +1,43 @@ +/*=================================================================== + +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 mitkSchedulableProcess_h +#define mitkSchedulableProcess_h + +#include + +namespace mitk +{ + class MitkSimulation_EXPORT SchedulableProcess + { + public: + explicit SchedulableProcess(int priority = 0); + virtual ~SchedulableProcess(); + + int GetPriority() const; + int GetLastTimeSliceInMSec() const; + void SetLastTimeSliceInMSec(int timeSliceInMSec); + + private: + SchedulableProcess(const SchedulableProcess&); + SchedulableProcess& operator=(const SchedulableProcess&); + + int m_Priority; + int m_LastTimeSliceInMSec; + }; +} + +#endif diff --git a/Modules/Simulation/mitkScheduler.cpp b/Modules/Simulation/mitkScheduler.cpp new file mode 100644 index 0000000000..d5099cff59 --- /dev/null +++ b/Modules/Simulation/mitkScheduler.cpp @@ -0,0 +1,63 @@ +/*=================================================================== + +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 "mitkRoundRobinSchedulingAlgorithm.h" +#include "mitkSchedulableProcess.h" +#include "mitkScheduler.h" +#include +#include + +mitk::Scheduler::Scheduler(SchedulingAlgorithm::Enum algorithm) +{ + switch (algorithm) + { + case mitk::SchedulingAlgorithm::RoundRobin: + m_Algorithm = new mitk::RoundRobinSchedulingAlgorithm(&m_ProcessQueue); + + default: + assert(false); + } +} + +mitk::Scheduler::~Scheduler() +{ + delete m_Algorithm; +} + +void mitk::Scheduler::AddProcess(SchedulableProcess* process) +{ + if (process == NULL) + return; + + if (std::find(m_ProcessQueue.begin(), m_ProcessQueue.end(), process) == m_ProcessQueue.end()) + m_ProcessQueue.push_back(process); +} + +void mitk::Scheduler::RemoveProcess(SchedulableProcess* process) +{ + if (process == NULL) + return; + + std::vector::iterator it = std::find(m_ProcessQueue.begin(), m_ProcessQueue.end(), process); + + if (it != m_ProcessQueue.end()) + m_ProcessQueue.erase(it); +} + +mitk::SchedulableProcess* mitk::Scheduler::GetNextProcess() +{ + return m_Algorithm->GetNextProcess(); +} diff --git a/Modules/Simulation/mitkScheduler.h b/Modules/Simulation/mitkScheduler.h new file mode 100644 index 0000000000..52f5152c8a --- /dev/null +++ b/Modules/Simulation/mitkScheduler.h @@ -0,0 +1,55 @@ +/*=================================================================== + +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 mitkScheduler_h +#define mitkScheduler_h + +#include +#include + +namespace mitk +{ + class SchedulableProcess; + class SchedulingAlgorithmBase; + + namespace SchedulingAlgorithm + { + enum Enum + { + RoundRobin + }; + } + + class MitkSimulation_EXPORT Scheduler + { + public: + explicit Scheduler(SchedulingAlgorithm::Enum algorithm = SchedulingAlgorithm::RoundRobin); + ~Scheduler(); + + void AddProcess(SchedulableProcess* process); + void RemoveProcess(SchedulableProcess* process); + SchedulableProcess* GetNextProcess(); + + private: + Scheduler(const Scheduler&); + Scheduler& operator=(const Scheduler&); + + std::vector m_ProcessQueue; + SchedulingAlgorithmBase* m_Algorithm; + }; +} + +#endif diff --git a/Modules/Simulation/mitkSchedulingAlgorithmBase.cpp b/Modules/Simulation/mitkSchedulingAlgorithmBase.cpp new file mode 100644 index 0000000000..5533cf4e3b --- /dev/null +++ b/Modules/Simulation/mitkSchedulingAlgorithmBase.cpp @@ -0,0 +1,27 @@ +/*=================================================================== + +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 "mitkSchedulableProcess.h" +#include "mitkSchedulingAlgorithmBase.h" + +mitk::SchedulingAlgorithmBase::SchedulingAlgorithmBase(std::vector* processQueue) + : m_ProcessQueue(processQueue) +{ +} + +mitk::SchedulingAlgorithmBase::~SchedulingAlgorithmBase() +{ +} diff --git a/Modules/Simulation/mitkSchedulingAlgorithmBase.h b/Modules/Simulation/mitkSchedulingAlgorithmBase.h new file mode 100644 index 0000000000..ef4927eaa9 --- /dev/null +++ b/Modules/Simulation/mitkSchedulingAlgorithmBase.h @@ -0,0 +1,43 @@ +/*=================================================================== + +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 mitkSchedulingAlgorithmBase_h +#define mitkSchedulingAlgorithmBase_h + +#include + +namespace mitk +{ + class SchedulableProcess; + + class SchedulingAlgorithmBase + { + public: + explicit SchedulingAlgorithmBase(std::vector* processQueue); + virtual ~SchedulingAlgorithmBase(); + + virtual SchedulableProcess* GetNextProcess() = 0; + + protected: + std::vector* m_ProcessQueue; + + private: + SchedulingAlgorithmBase(const SchedulingAlgorithmBase&); + SchedulingAlgorithmBase& operator=(const SchedulingAlgorithmBase&); + }; +} + +#endif diff --git a/Modules/Simulation/mitkSimulation.h b/Modules/Simulation/mitkSimulation.h index 14bb251782..ac016de5a5 100644 --- a/Modules/Simulation/mitkSimulation.h +++ b/Modules/Simulation/mitkSimulation.h @@ -1,59 +1,60 @@ /*=================================================================== 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 mitkSimulation_h #define mitkSimulation_h #include +#include #include #include #include namespace mitk { - class MitkSimulation_EXPORT Simulation : public BaseData + class MitkSimulation_EXPORT Simulation : public BaseData, public SchedulableProcess { public: mitkClassMacro(Simulation, BaseData); itkFactorylessNewMacro(Self) itkCloneMacro(Self) void Animate(); sofa::core::visual::DrawTool* GetDrawTool(); sofa::simulation::Node::SPtr GetRootNode() const; sofa::simulation::Simulation::SPtr GetSOFASimulation() const; void Reset(); void SetAnimationFlag(bool animate); void SetDt(double dt); void SetRootNode(sofa::simulation::Node::SPtr rootNode); bool RequestedRegionIsOutsideOfTheBufferedRegion(); void SetRequestedRegion(const itk::DataObject*); void SetRequestedRegionToLargestPossibleRegion(); void UpdateOutputInformation(); bool VerifyRequestedRegion(); private: Simulation(); ~Simulation(); sofa::simulation::Simulation::SPtr m_SOFASimulation; sofa::simulation::Node::SPtr m_RootNode; sofa::core::visual::DrawToolGL m_DrawTool; }; } #endif