]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
1cd75794d6aa2bdc190c4d6bca4c755979cdd6a9
[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 "clitkCommon.h"
24 #include "clitkTimer.h"
25 #include "clitkFilterMacros.txx"
26 #include "clitkLabelizeParameters.h"
27
28 // itk
29 #include "itkObject.h"
30
31 namespace clitk {
32   
33   //--------------------------------------------------------------------
34   /*
35     Convenient class to manage options from GGO (gengetopt) to filter
36   */
37   //--------------------------------------------------------------------
38   class FilterBase
39   {
40
41   public:
42     // Standard class typedefs
43     typedef FilterBase  Self;
44     
45     // Run-time type information (and related methods)
46     itkTypeMacro(FilterBase, Object);
47
48     // Needed by itkSetMacro (cannot inherit from itkObject because of
49     // multiple inheritance)
50     virtual void Modified() {} 
51     virtual bool GetDebug() const { return false; }
52
53     // To put in class that inherit from FilterBase
54 #define FILTERBASE_INIT                                                 \
55     virtual void Modified() { Superclass::Modified(); }                 \
56     virtual bool GetDebug() const { return Superclass::GetDebug(); }
57
58     // Verbose options management
59     itkSetMacro(VerboseOption, bool);
60     itkGetConstMacro(VerboseOption, bool);
61     itkBooleanMacro(VerboseOption);
62     GGO_DefineOption_Flag(verboseOption, SetVerboseOption);
63
64     // Steps management
65     itkSetMacro(NumberOfSteps, int);
66     itkGetConstMacro(NumberOfSteps, int);
67     itkSetMacro(VerboseStep, bool);
68     itkGetConstMacro(VerboseStep, bool);
69     itkBooleanMacro(VerboseStep);
70     GGO_DefineOption_Flag(verboseStep, SetVerboseStep);
71
72     itkSetMacro(WriteStep, bool);
73     itkGetConstMacro(WriteStep, bool);
74     itkBooleanMacro(WriteStep);
75     GGO_DefineOption_Flag(writeStep, SetWriteStep);
76
77     itkSetMacro(CurrentStepNumber, int);
78     itkGetConstMacro(CurrentStepNumber, int);
79     itkSetMacro(CurrentStepId, std::string);
80     itkGetConstMacro(CurrentStepId, std::string);
81     itkSetMacro(CurrentStepBaseId, std::string);
82     itkGetConstMacro(CurrentStepBaseId, std::string);
83     itkSetMacro(CurrentStepName, std::string);
84     itkGetConstMacro(CurrentStepName, std::string);
85
86     // Convenient function for verbose option
87     template<class OptionType>
88     void VerboseOption(std::string name, OptionType value);    
89     template<class OptionType>
90     void VerboseOption(std::string name, int nb, OptionType value);
91     template<class OptionType>
92     void VerboseOptionV(std::string name, int nb, OptionType * value);
93
94     void SetWarning(std::string e);
95     itkGetConstMacro(Warning, std::string);
96     itkSetMacro(VerboseWarningOff, bool);
97     itkGetConstMacro(VerboseWarningOff, bool);
98     itkBooleanMacro(VerboseWarningOff);
99     GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff);
100     
101     // Use this function to cancel the filter between step
102     void Cancel();
103     bool Cancelled();
104
105   protected:
106     FilterBase();
107     virtual ~FilterBase() {}    
108     void StartNewStep(std::string s);
109     template<class TInternalImageType>
110     void StopCurrentStep(typename TInternalImageType::Pointer p);
111     void StopCurrentStep();
112
113     bool m_VerboseOption;  
114     bool m_VerboseStep;
115     bool m_WriteStep;
116     int m_CurrentStepNumber;
117     int m_NumberOfSteps;
118     std::string m_CurrentStepId;
119     std::string m_CurrentStepBaseId;
120     std::string m_CurrentStepName;
121     std::string m_Warning;
122     bool m_VerboseWarningOff;
123     bool m_IsCancelled;
124     Timer m_CurrentStepTimer;
125     
126
127   private:
128     FilterBase(const Self&); //purposely not implemented
129     void operator=(const Self&); //purposely not implemented
130     
131   }; // end class
132   //--------------------------------------------------------------------
133
134 } // end namespace clitk
135 //--------------------------------------------------------------------
136
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "clitkFilterBase.txx"
139 #endif
140
141 #endif // CLITKFILTERBASE_H