From: dsarrut Date: Thu, 22 Jul 2010 05:46:00 +0000 (+0000) Subject: add MustStop function (for interrupting a filter) X-Git-Tag: v1.2.0~519 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=868922dc773690f1be8f21159f10fc4702e5c09f;p=clitk.git add MustStop function (for interrupting a filter) --- diff --git a/common/clitkFilterBase.cxx b/common/clitkFilterBase.cxx index 2b42720..07b9925 100644 --- a/common/clitkFilterBase.cxx +++ b/common/clitkFilterBase.cxx @@ -22,13 +22,13 @@ //-------------------------------------------------------------------- clitk::FilterBase::FilterBase() { - m_MustStop = false; + SetMustStop(false); SetVerboseOption(false); SetCurrentStepNumber(0); SetCurrentStepBaseId(""); StopOnErrorOn(); ResetLastError(); - VerboseWarningOffOn(); // OffOn, it's cool not ? + VerboseWarningOffOn(); // OffOn, it's cool no ? SetWarning(""); } //-------------------------------------------------------------------- @@ -68,6 +68,8 @@ void clitk::FilterBase::SetWarning(std::string e) //-------------------------------------------------------------------- void clitk::FilterBase::StartNewStep(std::string s) { + //m_CurrentStepTimer.Reset(); + // m_CurrentStepTimer.Start(); m_CurrentStepNumber++; if (GetCurrentStepBaseId() != "") { std::ostringstream oss; @@ -92,15 +94,32 @@ void clitk::FilterBase::StartNewStep(std::string s) //-------------------------------------------------------------------- void clitk::FilterBase::StopCurrentStep() { - + // m_CurrentStepTimer.Stop(); + // m_CurrentStepTimer.Print(std::cout); + // std::ostringstream oss; + //oss << " (" << + // m_CurrentStepName = m_CurrentStepName +" } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::FilterBase::MustStop() +void clitk::FilterBase::SetMustStop(bool b) { - m_MustStop = true; + m_MustStop = b; + if (GetMustStop()) { + SetLastError("Filter is interrupted."); + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +bool clitk::FilterBase::GetMustStop() +{ + if (m_MustStop) return true; + if (HasError()) return true; + return false; } //-------------------------------------------------------------------- diff --git a/common/clitkFilterBase.h b/common/clitkFilterBase.h index ef0a0d9..a53a181 100644 --- a/common/clitkFilterBase.h +++ b/common/clitkFilterBase.h @@ -21,6 +21,7 @@ // clitk #include "clitkCommon.h" +#include "clitkTimer.h" #include "clitkFilterMacros.txx" #include "clitkLabelizeParameters.h" @@ -106,7 +107,8 @@ namespace clitk { GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff); // Use this function to stop (when threaded) - void MustStop(); + void SetMustStop(bool b); + bool GetMustStop(); protected: FilterBase(); @@ -129,6 +131,7 @@ namespace clitk { std::string m_Warning; bool m_VerboseWarningOff; bool m_MustStop; + Timer m_CurrentStepTimer; private: FilterBase(const Self&); //purposely not implemented @@ -140,6 +143,8 @@ namespace clitk { } // end namespace clitk //-------------------------------------------------------------------- +#define StartNewStepOrStop(s) StartNewStep(s); if (GetMustStop()) return; + #ifndef ITK_MANUAL_INSTANTIATION #include "clitkFilterBase.txx" #endif diff --git a/common/clitkFilterBase.txx b/common/clitkFilterBase.txx index c00d18a..baee570 100644 --- a/common/clitkFilterBase.txx +++ b/common/clitkFilterBase.txx @@ -60,6 +60,7 @@ void clitk::FilterBase::VerboseOptionV(std::string name, int nb, OptionType * va template void clitk::FilterBase::StopCurrentStep(typename TInternalImageType::Pointer p) { + StopCurrentStep(); if (m_WriteStep) { std::ostringstream name; name << "step-" << GetCurrentStepId() << ".mhd"; diff --git a/common/clitkImageToImageGenericFilterBase.cxx b/common/clitkImageToImageGenericFilterBase.cxx index 1da0144..285b496 100644 --- a/common/clitkImageToImageGenericFilterBase.cxx +++ b/common/clitkImageToImageGenericFilterBase.cxx @@ -35,6 +35,7 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string m_FailOnImageTypeError = true; m_ReadOnDisk = true; m_LastError = ""; + StopOnErrorOn(); } //-------------------------------------------------------------------- @@ -307,4 +308,14 @@ typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsig //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::ImageToImageGenericFilterBase::MustStop() +{ + if (m_FilterBase != NULL) { + m_FilterBase->SetMustStop(true); + } +} +//-------------------------------------------------------------------- + + diff --git a/common/clitkImageToImageGenericFilterBase.h b/common/clitkImageToImageGenericFilterBase.h index 4b27950..262d6fc 100644 --- a/common/clitkImageToImageGenericFilterBase.h +++ b/common/clitkImageToImageGenericFilterBase.h @@ -92,6 +92,12 @@ namespace clitk { // Get the associated filter FilterBase * GetFilterBase() { return m_FilterBase; } + + // Indicate that the filter must stop as soon as possible (if threaded) + void MustStop(); + itkSetMacro(StopOnError, bool); + itkGetConstMacro(StopOnError, bool); + itkBooleanMacro(StopOnError); protected: bool m_ReadOnDisk; @@ -122,6 +128,7 @@ namespace clitk { std::string m_LastError; void SetFilterBase(FilterBase * f) { m_FilterBase = f; } FilterBase * m_FilterBase; + bool m_StopOnError; }; // end class clitk::ImageToImageGenericFilter