]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
b8a154a8b2e7502f245dbe459670fac77bdaf9f4
[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://oncora1.lyon.fnclcc.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 options from GGO (gengetopt) to filter
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     // Steps management
73     itkSetMacro(NumberOfSteps, int);
74     itkGetConstMacro(NumberOfSteps, int);
75     itkSetMacro(VerboseStepFlag, bool);
76     itkGetConstMacro(VerboseStepFlag, bool);
77     itkBooleanMacro(VerboseStepFlag);
78
79     itkSetMacro(WriteStepFlag, bool);
80     itkGetConstMacro(WriteStepFlag, bool);
81     itkBooleanMacro(WriteStepFlag);
82
83     itkSetMacro(CurrentStepNumber, int);
84     itkGetConstMacro(CurrentStepNumber, int);
85     itkSetMacro(CurrentStepId, std::string);
86     itkGetConstMacro(CurrentStepId, std::string);
87     itkSetMacro(CurrentStepBaseId, std::string);
88     itkGetConstMacro(CurrentStepBaseId, std::string);
89     itkSetMacro(CurrentStepName, std::string);
90     itkGetConstMacro(CurrentStepName, std::string);
91     
92     void StartSubStep();
93     void StopSubStep();
94     
95     // Convenient function for verbose option
96     template<class OptionType>
97     void VerboseOption(std::string name, OptionType value);    
98     template<class OptionType>
99     void VerboseOption(std::string name, int nb, OptionType value);
100     template<class OptionType>
101     void VerboseOptionV(std::string name, int nb, OptionType * value);
102
103     void SetWarning(std::string e);
104     itkGetConstMacro(Warning, std::string);
105     itkSetMacro(VerboseWarningFlag, bool);
106     itkGetConstMacro(VerboseWarningFlag, bool);
107     itkBooleanMacro(VerboseWarningFlag);
108     
109     // Use this function to cancel the filter between step
110     void Cancel();
111     bool Cancelled();
112
113   protected:
114     FilterBase();
115     virtual ~FilterBase() {}    
116     void StartNewStep(std::string s);
117     template<class TInternalImageType>
118     void StopCurrentStep(typename TInternalImageType::Pointer p);
119     void StopCurrentStep();
120
121     bool m_VerboseFlag;  
122     bool m_VerboseOptionFlag;  
123     bool m_VerboseStepFlag;
124     bool m_VerboseMemoryFlag;
125     bool m_WriteStepFlag;
126     int m_CurrentStepNumber;
127     int m_NumberOfSteps;
128     std::string m_CurrentStepId;
129     std::string m_CurrentStepBaseId;
130     std::string m_CurrentStepName;
131     std::string m_Warning;
132     bool m_VerboseWarningFlag;
133     bool m_IsCancelled;
134     Timer m_CurrentStepTimer;
135
136     std::vector<int> m_SubstepNumbers;
137     std::vector<std::string> m_SubstepID;
138         
139   private:
140     FilterBase(const Self&); //purposely not implemented
141     void operator=(const Self&); //purposely not implemented
142     
143   }; // end class
144   //--------------------------------------------------------------------
145
146 } // end namespace clitk
147 //--------------------------------------------------------------------
148
149 #ifndef ITK_MANUAL_INSTANTIATION
150 #include "clitkFilterBase.txx"
151 #endif
152
153 #endif // CLITKFILTERBASE_H