]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkBinaryThresholdImageFilter.h
=== MAJOR RELEASE ====
[bbtk.git] / packages / itk / src / bbitkBinaryThresholdImageFilter.h
1 #ifdef _USE_ITK_
2
3 #include "bbtkAtomicBlackBox.h"
4 #include "itkBinaryThresholdImageFilter.h"
5 #include "bbitkImage.h"
6
7 namespace bbitk
8 {
9
10   template <class T>
11   class /*BBTK_EXPORT*/ BinaryThresholdImageFilter
12     : 
13     public bbtk::AtomicBlackBox,
14     public itk::BinaryThresholdImageFilter<T,T>
15   {
16     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
17                                       bbtk::AtomicBlackBox,T);
18     typedef itk::BinaryThresholdImageFilter<T,T> itkParent;
19     BBTK_DECLARE_ITK_INPUT(itkParent,In,const T*);
20     BBTK_DECLARE_ITK_PARAM(itkParent,LowerThreshold,typename T::PixelType);
21     BBTK_DECLARE_ITK_PARAM(itkParent,UpperThreshold,typename T::PixelType);
22     BBTK_DECLARE_ITK_PARAM(itkParent,InsideValue,typename T::PixelType);
23     BBTK_DECLARE_ITK_PARAM(itkParent,OutsideValue,typename T::PixelType);
24     BBTK_DECLARE_ITK_OUTPUT(itkParent,Out,T*);
25     BBTK_PROCESS(itkParent::Update);
26     void bbDelete() { itkParent::UnRegister(); }
27
28     void bbUserConstructor() { Init(); }
29     void bbUserCopyConstructor() { Init(); }
30     void Init();
31
32   };
33   
34   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter,
35                                       bbtk::AtomicBlackBox);
36   BBTK_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
37   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
38   BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
39   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
40   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
41                       "Lower threshold",typename T::PixelType);
42   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
43                       "Upper threshold",typename T::PixelType);
44   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
45                       "Output value for pixels inside thresholds",
46                       typename T::PixelType);
47   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
48                       "Output value for pixels outside thresholds",
49                       typename T::PixelType);
50   BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
51   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
52   
53   //===================================================
54   // Generic "untemplatized" filter
55   //===================================================
56   class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
57     : 
58     public bbtk::AtomicBlackBox
59   {
60     BBTK_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
61                                   bbtk::AtomicBlackBox);
62     BBTK_DECLARE_INPUT(In,anyImagePointer);
63     BBTK_DECLARE_INPUT(LowerThreshold,double);
64     BBTK_DECLARE_INPUT(UpperThreshold,double);
65     BBTK_DECLARE_INPUT(InsideValue,double);
66     BBTK_DECLARE_INPUT(OutsideValue,double);
67     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
68     BBTK_PROCESS(ProcessSwitch);
69   private :
70     inline void ProcessSwitch();
71     template <class T> void Process();
72     void bbUserConstructor() { Init(); }
73     void bbUserCopyConstructor() { Init(); }
74     void Init();
75   };
76   
77   BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
78                                 bbtk::AtomicBlackBox);
79   BBTK_NAME("BinaryThresholdImageFilter");
80   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
81   BBTK_CATEGORY("filter;image");
82   BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
83   BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
84              "Input image. Can be any itk::Image<T,D>*",anyImagePointer,"");
85   BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
86              "Lower threshold",double,"");
87   BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
88              "Upper threshold",double,"");
89   BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
90              "Output value for pixels inside thresholds",double,"");
91   BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
92              "Output value for pixels outside thresholds",double,"");
93   BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
94               "Output image. Of the same type and dimension than the input image",
95               anyImagePointer,"");
96   BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
97
98
99
100   void BinaryThresholdImageFilterGeneric::ProcessSwitch()
101   {
102     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
103   }
104
105   template <class T> 
106   void BinaryThresholdImageFilterGeneric::Process()
107   {
108     bbtkDebugMessageInc("Core",9,
109                         "bbitk::BinaryThresholdImageFilterGeneric::Process<"
110                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
111  
112     typedef BinaryThresholdImageFilter<T> FilterType;
113     typename FilterType::Pointer f = FilterType::New("Temp");
114     f->bbSetInputIn( this->bbGetInputIn().get<T*>());
115     f->bbSetInputLowerThreshold ( (typename T::PixelType)
116                                   this->bbGetInputLowerThreshold() );
117     f->bbSetInputUpperThreshold ( (typename T::PixelType)
118                                   this->bbGetInputUpperThreshold() );
119     f->bbSetInputInsideValue ( (typename T::PixelType)
120                                this->bbGetInputInsideValue() );
121     f->bbSetInputOutsideValue ( (typename T::PixelType)
122                                 this->bbGetInputOutsideValue() );
123     f->bbExecute();
124     f->bbGetOutputOut()->Register();
125     this->bbSetOutputOut( f->bbGetOutputOut() );
126
127     bbtkDebugDecTab("Core",9);
128   }
129   
130   template <class T>
131   void BinaryThresholdImageFilter<T>::Init()
132   {
133     bbSetInputLowerThreshold(0);
134     bbSetInputUpperThreshold(100);
135     bbSetInputInsideValue(255);
136     bbSetInputOutsideValue(0);
137   }
138
139   void BinaryThresholdImageFilterGeneric::Init()
140   {
141     bbSetInputLowerThreshold(0);
142     bbSetInputUpperThreshold(100);
143     bbSetInputInsideValue(255);
144     bbSetInputOutsideValue(0);
145   }
146
147 }
148 // EO namespace bbtk
149
150 #endif