]> Creatis software - clitk.git/blob - common/clitkFilterBase.h
add exception if error
[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(VerboseOption, bool);
59     itkGetConstMacro(VerboseOption, bool);
60     itkBooleanMacro(VerboseOption);
61     GGO_DefineOption_Flag(verboseOption, SetVerboseOption);
62
63     // Steps management
64     itkSetMacro(NumberOfSteps, int);
65     itkGetConstMacro(NumberOfSteps, int);
66     itkSetMacro(VerboseStep, bool);
67     itkGetConstMacro(VerboseStep, bool);
68     itkBooleanMacro(VerboseStep);
69     GGO_DefineOption_Flag(verboseStep, SetVerboseStep);
70
71     itkSetMacro(WriteStep, bool);
72     itkGetConstMacro(WriteStep, bool);
73     itkBooleanMacro(WriteStep);
74     GGO_DefineOption_Flag(writeStep, SetWriteStep);
75
76     itkSetMacro(CurrentStepNumber, int);
77     itkGetConstMacro(CurrentStepNumber, int);
78     itkSetMacro(CurrentStepId, std::string);
79     itkGetConstMacro(CurrentStepId, std::string);
80     itkSetMacro(CurrentStepBaseId, std::string);
81     itkGetConstMacro(CurrentStepBaseId, std::string);
82     itkSetMacro(CurrentStepName, std::string);
83     itkGetConstMacro(CurrentStepName, std::string);
84
85     // Convenient function for verbose option
86     template<class OptionType>
87     void VerboseOption(std::string name, OptionType value);    
88     template<class OptionType>
89     void VerboseOption(std::string name, int nb, OptionType value);
90     template<class OptionType>
91     void VerboseOptionV(std::string name, int nb, OptionType * value);
92
93     void SetWarning(std::string e);
94     itkGetConstMacro(Warning, std::string);
95     itkSetMacro(VerboseWarningOff, bool);
96     itkGetConstMacro(VerboseWarningOff, bool);
97     itkBooleanMacro(VerboseWarningOff);
98     GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff);
99     
100     // Use this function to cancel the filter between step
101     void Cancel();
102     bool Cancelled();
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     int m_NumberOfSteps;
117     std::string m_CurrentStepId;
118     std::string m_CurrentStepBaseId;
119     std::string m_CurrentStepName;
120     std::string m_Warning;
121     bool m_VerboseWarningOff;
122     bool m_IsCancelled;
123     Timer m_CurrentStepTimer;
124     
125
126   private:
127     FilterBase(const Self&); //purposely not implemented
128     void operator=(const Self&); //purposely not implemented
129     
130   }; // end class
131   //--------------------------------------------------------------------
132
133 } // end namespace clitk
134 //--------------------------------------------------------------------
135
136 #ifndef ITK_MANUAL_INSTANTIATION
137 #include "clitkFilterBase.txx"
138 #endif
139
140 #endif // CLITKFILTERBASE_H