]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
7403f37fe0a041fa6a1b0ea85c696b65e1a302f7
[clitk.git] / common / clitkFilterBase.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 #ifndef CLITKFILTERBASE_H
20 #define CLITKFILTERBASE_H
21
22 // clitk
23 #include "clitkTimer.h"
24 #include "clitkFilterMacros.txx"
25 #include "clitkLabelizeParameters.h"
26
27 // itk
28 #include "itkObject.h"
29
30 namespace clitk {
31   
32   //--------------------------------------------------------------------
33   /*
34     Convenient class to manage frequent options
35   */
36   //--------------------------------------------------------------------
37   class FilterBase
38   {
39
40   public:
41     // Standard class typedefs
42     typedef FilterBase  Self;
43     
44     // Run-time type information (and related methods)
45     itkTypeMacro(FilterBase, Object);
46
47     // Needed by itkSetMacro (cannot inherit from itkObject because of
48     // multiple inheritance)
49     virtual void Modified() {} 
50     virtual bool GetDebug() const { return false; }
51
52     // To put in class that inherit from FilterBase
53 #define FILTERBASE_INIT                                                 \
54     virtual void Modified() { Superclass::Modified(); }                 \
55     virtual bool GetDebug() const { return Superclass::GetDebug(); }
56
57     // Verbose options management
58     itkSetMacro(VerboseFlag, bool);
59     itkGetConstMacro(VerboseFlag, bool);
60     itkBooleanMacro(VerboseFlag);
61
62     // Verbose Options
63     itkSetMacro(VerboseOptionFlag, bool);
64     itkGetConstMacro(VerboseOptionFlag, bool);
65     itkBooleanMacro(VerboseOptionFlag);
66
67     // Verbose Memory
68     itkSetMacro(VerboseMemoryFlag, bool);
69     itkGetConstMacro(VerboseMemoryFlag, bool);
70     itkBooleanMacro(VerboseMemoryFlag);
71
72     // Verbose ImageSize
73     itkSetMacro(VerboseImageSizeFlag, bool);
74     itkGetConstMacro(VerboseImageSizeFlag, bool);
75     itkBooleanMacro(VerboseImageSizeFlag);
76
77     // Steps management
78     itkSetMacro(NumberOfSteps, int);
79     itkGetConstMacro(NumberOfSteps, int);
80     itkSetMacro(VerboseStepFlag, bool);
81     itkGetConstMacro(VerboseStepFlag, bool);
82     itkBooleanMacro(VerboseStepFlag);
83
84     itkSetMacro(WriteStepFlag, bool);
85     itkGetConstMacro(WriteStepFlag, bool);
86     itkBooleanMacro(WriteStepFlag);
87
88     itkSetMacro(CurrentStepNumber, int);
89     itkGetConstMacro(CurrentStepNumber, int);
90     itkSetMacro(CurrentStepId, std::string);
91     itkGetConstMacro(CurrentStepId, std::string);
92     itkSetMacro(CurrentStepBaseId, std::string);
93     itkGetConstMacro(CurrentStepBaseId, std::string);
94     itkSetMacro(CurrentStepName, std::string);
95     itkGetConstMacro(CurrentStepName, std::string);
96     
97     void StartSubStep();
98     void StopSubStep();
99     
100     // Convenient function for verbose option
101     template<class OptionType>
102     void VerboseOption(std::string name, OptionType value);    
103     template<class OptionType>
104     void VerboseOption(std::string name, int nb, OptionType value);
105     template<class OptionType>
106     void VerboseOptionV(std::string name, int nb, OptionType * value);
107
108     void SetWarning(std::string e);
109     itkGetConstMacro(Warning, std::string);
110     itkSetMacro(VerboseWarningFlag, bool);
111     itkGetConstMacro(VerboseWarningFlag, bool);
112     itkBooleanMacro(VerboseWarningFlag);
113     
114     // Use this function to cancel the filter between step
115     void Cancel();
116     bool Cancelled();
117
118   protected:
119     FilterBase();
120     virtual ~FilterBase() {}    
121     void StartNewStep(std::string s, bool endl=true);
122     template<class TInternalImageType>
123     void StopCurrentStep(typename TInternalImageType::Pointer p, std::string txt="");
124     void StopCurrentStep();
125
126     bool m_VerboseFlag;  
127     bool m_VerboseOptionFlag;  
128     bool m_VerboseStepFlag;
129     bool m_VerboseMemoryFlag;
130     bool m_VerboseImageSizeFlag;
131     bool m_WriteStepFlag;
132     int m_CurrentStepNumber;
133     int m_NumberOfSteps;
134     std::string m_CurrentStepId;
135     std::string m_CurrentStepBaseId;
136     std::string m_CurrentStepName;
137     std::string m_Warning;
138     bool m_VerboseWarningFlag;
139     bool m_IsCancelled;
140     Timer m_CurrentStepTimer;
141
142     std::vector<int> m_SubstepNumbers;
143     std::vector<std::string> m_SubstepID;
144         
145   private:
146     FilterBase(const Self&); //purposely not implemented
147     void operator=(const Self&); //purposely not implemented
148     
149   }; // end class
150   //--------------------------------------------------------------------
151
152 } // end namespace clitk
153 //--------------------------------------------------------------------
154
155 #ifndef ITK_MANUAL_INSTANTIATION
156 #include "clitkFilterBase.txx"
157 #endif
158
159 #endif // CLITKFILTERBASE_H