]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
Remove transparency for screenshot
[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     virtual const char *GetNameOfClass() const
46       {
47       return "FilterBase";
48       }
49
50     // Needed by itkSetMacro (cannot inherit from itkObject because of
51     // multiple inheritance)
52     virtual void Modified() {} 
53     virtual bool GetDebug() const { return false; }
54
55     // To put in class that inherit from FilterBase
56 #define FILTERBASE_INIT                                                 \
57     virtual void Modified() { Superclass::Modified(); }                 \
58     virtual bool GetDebug() const { return Superclass::GetDebug(); }
59
60     // Verbose options management
61     itkSetMacro(VerboseFlag, bool);
62     itkGetConstMacro(VerboseFlag, bool);
63     itkBooleanMacro(VerboseFlag);
64
65     // Verbose Options
66     itkSetMacro(VerboseOptionFlag, bool);
67     itkGetConstMacro(VerboseOptionFlag, bool);
68     itkBooleanMacro(VerboseOptionFlag);
69
70     // Verbose Memory
71     itkSetMacro(VerboseMemoryFlag, bool);
72     itkGetConstMacro(VerboseMemoryFlag, bool);
73     itkBooleanMacro(VerboseMemoryFlag);
74
75     // Verbose ImageSize
76     itkSetMacro(VerboseImageSizeFlag, bool);
77     itkGetConstMacro(VerboseImageSizeFlag, bool);
78     itkBooleanMacro(VerboseImageSizeFlag);
79
80     // Steps management
81     itkSetMacro(NumberOfSteps, int);
82     itkGetConstMacro(NumberOfSteps, int);
83     itkSetMacro(VerboseStepFlag, bool);
84     itkGetConstMacro(VerboseStepFlag, bool);
85     itkBooleanMacro(VerboseStepFlag);
86
87     itkSetMacro(WriteStepFlag, bool);
88     itkGetConstMacro(WriteStepFlag, bool);
89     itkBooleanMacro(WriteStepFlag);
90
91     itkSetMacro(CurrentStepNumber, int);
92     itkGetConstMacro(CurrentStepNumber, int);
93     itkSetMacro(CurrentStepId, std::string);
94     itkGetConstMacro(CurrentStepId, std::string);
95     itkSetMacro(CurrentStepBaseId, std::string);
96     itkGetConstMacro(CurrentStepBaseId, std::string);
97     itkSetMacro(CurrentStepName, std::string);
98     itkGetConstMacro(CurrentStepName, std::string);
99     
100     void StartSubStep();
101     void StopSubStep();
102     
103     // Convenient function for verbose option
104     template<class OptionType>
105     void VerboseOption(std::string name, OptionType value);    
106     template<class OptionType>
107     void VerboseOption(std::string name, int nb, OptionType value);
108     template<class OptionType>
109     void VerboseOptionV(std::string name, int nb, OptionType * value);
110
111     void SetWarning(std::string e);
112     itkGetConstMacro(Warning, std::string);
113     itkSetMacro(VerboseWarningFlag, bool);
114     itkGetConstMacro(VerboseWarningFlag, bool);
115     itkBooleanMacro(VerboseWarningFlag);
116     
117     // Use this function to cancel the filter between step
118     void Cancel();
119     bool Cancelled();
120
121   protected:
122     FilterBase();
123     virtual ~FilterBase() {}    
124     void StartNewStep(std::string s, bool endl=true);
125     template<class TInternalImageType>
126     void StopCurrentStep(typename TInternalImageType::Pointer p, std::string txt="");
127     void StopCurrentStep();
128
129     bool m_VerboseFlag;  
130     bool m_VerboseOptionFlag;  
131     bool m_VerboseStepFlag;
132     bool m_VerboseMemoryFlag;
133     bool m_VerboseImageSizeFlag;
134     bool m_WriteStepFlag;
135     int m_CurrentStepNumber;
136     int m_NumberOfSteps;
137     std::string m_CurrentStepId;
138     std::string m_CurrentStepBaseId;
139     std::string m_CurrentStepName;
140     std::string m_Warning;
141     bool m_VerboseWarningFlag;
142     bool m_IsCancelled;
143     Timer m_CurrentStepTimer;
144
145     std::vector<int> m_SubstepNumbers;
146     std::vector<std::string> m_SubstepID;
147         
148   private:
149     FilterBase(const Self&); //purposely not implemented
150     void operator=(const Self&); //purposely not implemented
151     
152   }; // end class
153   //--------------------------------------------------------------------
154
155 } // end namespace clitk
156 //--------------------------------------------------------------------
157
158 #ifndef ITK_MANUAL_INSTANTIATION
159 #include "clitkFilterBase.txx"
160 #endif
161
162 #endif // CLITKFILTERBASE_H