From 8e9577b513e5c23835d0e2cb58e5ccc04e90544a Mon Sep 17 00:00:00 2001 From: dsarrut Date: Tue, 15 Feb 2011 10:39:55 +0000 Subject: [PATCH] add verbose memory --- common/clitkFilterBase.cxx | 38 +++++++++++++++++++------ common/clitkFilterBase.h | 58 +++++++++++++++++++++++--------------- common/clitkFilterBase.txx | 10 ++++--- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/common/clitkFilterBase.cxx b/common/clitkFilterBase.cxx index 09797d8..bea1b15 100644 --- a/common/clitkFilterBase.cxx +++ b/common/clitkFilterBase.cxx @@ -23,11 +23,14 @@ //-------------------------------------------------------------------- clitk::FilterBase::FilterBase() { - SetVerboseOption(false); + SetVerboseOptionFlag(false); SetCurrentStepNumber(0); SetCurrentStepBaseId(""); - VerboseWarningOffOn(); // OffOn, it's cool no ? + VerboseWarningFlagOn(); + VerboseWarningFlagOff(); + VerboseMemoryFlagOff(); SetWarning(""); + VerboseWarningFlagOn(); m_IsCancelled = false; } //-------------------------------------------------------------------- @@ -37,7 +40,7 @@ clitk::FilterBase::FilterBase() void clitk::FilterBase::SetWarning(std::string e) { m_Warning = e; - if (!GetVerboseWarningOff()) { + if (GetVerboseWarningFlag()) { std::cout << GetWarning() << std::endl; } } @@ -64,7 +67,7 @@ void clitk::FilterBase::StartNewStep(std::string s) } m_CurrentStepName = "Step "+GetCurrentStepId()+" -- "+s; - if (m_VerboseStep) { + if (GetVerboseStepFlag()) { std::cout << m_CurrentStepName << std::endl; //"Step " << GetCurrentStepId() << " -- " << s << std::endl; } @@ -89,9 +92,28 @@ void clitk::FilterBase::Cancel() //-------------------------------------------------------------------- - bool clitk::FilterBase::Cancelled() - { - return m_IsCancelled; - } +bool clitk::FilterBase::Cancelled() +{ + return m_IsCancelled; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- +void clitk::FilterBase::StartSubStep() { + m_SubstepNumbers.push_back(GetCurrentStepNumber()); + m_SubstepID.push_back(GetCurrentStepId()); + SetCurrentStepBaseId(GetCurrentStepId()); + SetCurrentStepNumber(0);; +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +void clitk::FilterBase::StopSubStep() { + int s = m_SubstepNumbers.back(); + m_SubstepNumbers.pop_back(); + SetCurrentStepNumber(s); + SetCurrentStepBaseId(m_SubstepID.back()); + m_SubstepID.pop_back(); +} diff --git a/common/clitkFilterBase.h b/common/clitkFilterBase.h index 94736f7..b8a154a 100644 --- a/common/clitkFilterBase.h +++ b/common/clitkFilterBase.h @@ -55,23 +55,30 @@ namespace clitk { virtual bool GetDebug() const { return Superclass::GetDebug(); } // Verbose options management - itkSetMacro(VerboseOption, bool); - itkGetConstMacro(VerboseOption, bool); - itkBooleanMacro(VerboseOption); - GGO_DefineOption_Flag(verboseOption, SetVerboseOption); + itkSetMacro(VerboseFlag, bool); + itkGetConstMacro(VerboseFlag, bool); + itkBooleanMacro(VerboseFlag); + + // Verbose Options + itkSetMacro(VerboseOptionFlag, bool); + itkGetConstMacro(VerboseOptionFlag, bool); + itkBooleanMacro(VerboseOptionFlag); + + // Verbose Memory + itkSetMacro(VerboseMemoryFlag, bool); + itkGetConstMacro(VerboseMemoryFlag, bool); + itkBooleanMacro(VerboseMemoryFlag); // Steps management itkSetMacro(NumberOfSteps, int); itkGetConstMacro(NumberOfSteps, int); - itkSetMacro(VerboseStep, bool); - itkGetConstMacro(VerboseStep, bool); - itkBooleanMacro(VerboseStep); - GGO_DefineOption_Flag(verboseStep, SetVerboseStep); + itkSetMacro(VerboseStepFlag, bool); + itkGetConstMacro(VerboseStepFlag, bool); + itkBooleanMacro(VerboseStepFlag); - itkSetMacro(WriteStep, bool); - itkGetConstMacro(WriteStep, bool); - itkBooleanMacro(WriteStep); - GGO_DefineOption_Flag(writeStep, SetWriteStep); + itkSetMacro(WriteStepFlag, bool); + itkGetConstMacro(WriteStepFlag, bool); + itkBooleanMacro(WriteStepFlag); itkSetMacro(CurrentStepNumber, int); itkGetConstMacro(CurrentStepNumber, int); @@ -81,7 +88,10 @@ namespace clitk { itkGetConstMacro(CurrentStepBaseId, std::string); itkSetMacro(CurrentStepName, std::string); itkGetConstMacro(CurrentStepName, std::string); - + + void StartSubStep(); + void StopSubStep(); + // Convenient function for verbose option template void VerboseOption(std::string name, OptionType value); @@ -92,10 +102,9 @@ namespace clitk { void SetWarning(std::string e); itkGetConstMacro(Warning, std::string); - itkSetMacro(VerboseWarningOff, bool); - itkGetConstMacro(VerboseWarningOff, bool); - itkBooleanMacro(VerboseWarningOff); - GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff); + itkSetMacro(VerboseWarningFlag, bool); + itkGetConstMacro(VerboseWarningFlag, bool); + itkBooleanMacro(VerboseWarningFlag); // Use this function to cancel the filter between step void Cancel(); @@ -109,19 +118,24 @@ namespace clitk { void StopCurrentStep(typename TInternalImageType::Pointer p); void StopCurrentStep(); - bool m_VerboseOption; - bool m_VerboseStep; - bool m_WriteStep; + bool m_VerboseFlag; + bool m_VerboseOptionFlag; + bool m_VerboseStepFlag; + bool m_VerboseMemoryFlag; + bool m_WriteStepFlag; int m_CurrentStepNumber; int m_NumberOfSteps; std::string m_CurrentStepId; std::string m_CurrentStepBaseId; std::string m_CurrentStepName; std::string m_Warning; - bool m_VerboseWarningOff; + bool m_VerboseWarningFlag; bool m_IsCancelled; Timer m_CurrentStepTimer; - + + std::vector m_SubstepNumbers; + std::vector m_SubstepID; + private: FilterBase(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented diff --git a/common/clitkFilterBase.txx b/common/clitkFilterBase.txx index baee570..064f3be 100644 --- a/common/clitkFilterBase.txx +++ b/common/clitkFilterBase.txx @@ -17,12 +17,13 @@ ======================================================================-====*/ #include "clitkImageCommon.h" +#include "clitkMemoryUsage.h" //-------------------------------------------------------------------- template void clitk::FilterBase::VerboseOption(std::string name, OptionType value) { - if (!this->GetVerboseOption()) return; + if (!this->GetVerboseOptionFlag()) return; std::cout << "Set option '" << name << "' = " << value << std::endl; } //-------------------------------------------------------------------- @@ -32,7 +33,7 @@ void clitk::FilterBase::VerboseOption(std::string name, OptionType value) template void clitk::FilterBase::VerboseOption(std::string name, int nb, OptionType value) { - if (!this->GetVerboseOption()) return; + if (!this->GetVerboseOptionFlag()) return; if (nb==0) std::cout << "Set option '" << name << "' not given" << std::endl; else { std::cout << "Set option '" << name << "' = " << value << std::endl; @@ -45,7 +46,7 @@ void clitk::FilterBase::VerboseOption(std::string name, int nb, OptionType value template void clitk::FilterBase::VerboseOptionV(std::string name, int nb, OptionType * value) { - if (!this->GetVerboseOption()) return; + if (!this->GetVerboseOptionFlag()) return; if (nb==0) std::cout << "Set option '" << name << "' not given" << std::endl; else { std::cout << "Set option '" << name << "'[" << nb << "] "; @@ -61,11 +62,12 @@ template void clitk::FilterBase::StopCurrentStep(typename TInternalImageType::Pointer p) { StopCurrentStep(); - if (m_WriteStep) { + if (m_WriteStepFlag) { std::ostringstream name; name << "step-" << GetCurrentStepId() << ".mhd"; clitk::writeImage(p, name.str()); } + clitk::PrintMemory(GetVerboseMemoryFlag(), "End of step"); } //-------------------------------------------------------------------- -- 2.47.1