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