]> 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 "bbtkUserBlackBox.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::UserBlackBox,
14     public itk::BinaryThresholdImageFilter<T,T>
15   {
16     BBTK_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
17                                   bbtk::UserBlackBox);
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_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
36   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
37   BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
38   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
39   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
40                       "Lower threshold",typename T::PixelType);
41   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
42                       "Upper threshold",typename T::PixelType);
43   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
44                       "Output value for pixels inside thresholds",
45                       typename T::PixelType);
46   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
47                       "Output value for pixels outside thresholds",
48                       typename T::PixelType);
49   BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
50   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
51   
52   //===================================================
53   // Generic "untemplatized" filter
54   //===================================================
55   class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
56     : 
57     public bbtk::UserBlackBox
58   {
59     BBTK_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
60                                   bbtk::UserBlackBox);
61     BBTK_DECLARE_INPUT(In,anyImagePointer);
62     BBTK_DECLARE_INPUT(LowerThreshold,double);
63     BBTK_DECLARE_INPUT(UpperThreshold,double);
64     BBTK_DECLARE_INPUT(InsideValue,double);
65     BBTK_DECLARE_INPUT(OutsideValue,double);
66     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
67     BBTK_PROCESS(ProcessSwitch);
68   private :
69     inline void ProcessSwitch();
70     template <class T> void Process();
71     void bbUserConstructor() { Init(); }
72     void bbUserCopyConstructor() { Init(); }
73     void Init();
74   };
75   
76   BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
77                                 bbtk::UserBlackBox);
78   BBTK_NAME("BinaryThresholdImageFilter");
79   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
80   BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
81   BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
82              "Input image. Can be any itk::Image<T,D>*",anyImagePointer);
83   BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
84              "Lower threshold",double);
85   BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
86              "Upper threshold",double);
87   BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
88              "Output value for pixels inside thresholds",double);
89   BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
90              "Output value for pixels outside thresholds",double);
91   BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
92               "Output image. Of the same type and dimension than the input image",
93               anyImagePointer);
94   BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
95
96
97
98   void BinaryThresholdImageFilterGeneric::ProcessSwitch()
99   {
100     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
101   }
102
103   template <class T> 
104   void BinaryThresholdImageFilterGeneric::Process()
105   {
106     bbtkDebugMessageInc("Core",9,
107                         "bbitk::BinaryThresholdImageFilterGeneric::Process<"
108                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
109  
110     typedef BinaryThresholdImageFilter<T> FilterType;
111     FilterType* f = FilterType::bbNew("Temp");
112     f->bbSetInputIn( this->bbGetInputIn().get<T*>());
113     f->bbSetInputLowerThreshold ( (typename T::PixelType)
114                                   this->bbGetInputLowerThreshold() );
115     f->bbSetInputUpperThreshold ( (typename T::PixelType)
116                                   this->bbGetInputUpperThreshold() );
117     f->bbSetInputInsideValue ( (typename T::PixelType)
118                                this->bbGetInputInsideValue() );
119     f->bbSetInputOutsideValue ( (typename T::PixelType)
120                                 this->bbGetInputOutsideValue() );
121     f->bbExecute();
122     f->bbGetOutputOut()->Register();
123     this->bbSetOutputOut( f->bbGetOutputOut() );
124     f->bbDelete();
125     bbtkDebugDecTab("Core",9);
126   }
127   
128   template <class T>
129   void BinaryThresholdImageFilter<T>::Init()
130   {
131     bbSetInputLowerThreshold(0);
132     bbSetInputUpperThreshold(100);
133     bbSetInputInsideValue(255);
134     bbSetInputOutsideValue(0);
135   }
136
137   void BinaryThresholdImageFilterGeneric::Init()
138   {
139     bbSetInputLowerThreshold(0);
140     bbSetInputUpperThreshold(100);
141     bbSetInputInsideValue(255);
142     bbSetInputOutsideValue(0);
143   }
144
145 }
146 // EO namespace bbtk
147
148 #endif