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