]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
Added Varian OBI file format
[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(NumberOfSteps, int);
64     itkGetConstMacro(NumberOfSteps, int);
65     itkSetMacro(VerboseStep, bool);
66     itkGetConstMacro(VerboseStep, bool);
67     itkBooleanMacro(VerboseStep);
68     GGO_DefineOption_Flag(verboseStep, SetVerboseStep);
69
70     itkSetMacro(WriteStep, bool);
71     itkGetConstMacro(WriteStep, bool);
72     itkBooleanMacro(WriteStep);
73     GGO_DefineOption_Flag(writeStep, SetWriteStep);
74
75     itkSetMacro(CurrentStepNumber, int);
76     itkGetConstMacro(CurrentStepNumber, int);
77     itkSetMacro(CurrentStepId, std::string);
78     itkGetConstMacro(CurrentStepId, std::string);
79     itkSetMacro(CurrentStepBaseId, std::string);
80     itkGetConstMacro(CurrentStepBaseId, std::string);
81     itkSetMacro(CurrentStepName, std::string);
82     itkGetConstMacro(CurrentStepName, std::string);
83
84     // Convenient function for verbose option
85     template<class OptionType>
86     void VerboseOption(std::string name, OptionType value);    
87     template<class OptionType>
88     void VerboseOption(std::string name, int nb, OptionType value);
89     template<class OptionType>
90     void VerboseOptionV(std::string name, int nb, OptionType * value);
91
92     // Error 
93     void SetLastError(std::string e);
94     void ResetLastError();
95     itkGetConstMacro(LastError, std::string);
96     bool HasError() { return (GetLastError() != ""); }
97     itkSetMacro(StopOnError, bool);
98     itkGetConstMacro(StopOnError, bool);
99     itkBooleanMacro(StopOnError);    
100
101     void SetWarning(std::string e);
102     itkGetConstMacro(Warning, std::string);
103     itkSetMacro(VerboseWarningOff, bool);
104     itkGetConstMacro(VerboseWarningOff, bool);
105     itkBooleanMacro(VerboseWarningOff);
106     GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff);
107     
108     // Use this function to stop (when threaded)
109     void MustStop();
110     
111   protected:
112     FilterBase();
113     virtual ~FilterBase() {}    
114     void StartNewStep(std::string s);
115     template<class TInternalImageType>
116     void StopCurrentStep(typename TInternalImageType::Pointer p);
117     void StopCurrentStep();
118
119     bool m_VerboseOption;  
120     bool m_VerboseStep;
121     bool m_WriteStep;
122     int m_CurrentStepNumber;
123     int m_NumberOfSteps;
124     std::string m_CurrentStepId;
125     std::string m_CurrentStepBaseId;
126     std::string m_LastError;
127     std::string m_CurrentStepName;
128     bool m_StopOnError;
129     std::string m_Warning;
130     bool m_VerboseWarningOff;
131     bool m_MustStop;
132
133   private:
134     FilterBase(const Self&); //purposely not implemented
135     void operator=(const Self&); //purposely not implemented
136     
137   }; // end class
138   //--------------------------------------------------------------------
139
140 } // end namespace clitk
141 //--------------------------------------------------------------------
142
143 #ifndef ITK_MANUAL_INSTANTIATION
144 #include "clitkFilterBase.txx"
145 #endif
146
147 #endif // CLITKFILTERBASE_H