]> 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 "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_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
17                                   bbtk::AtomicBlackBox);
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::AtomicBlackBox
58   {
59     BBTK_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
60                                   bbtk::AtomicBlackBox);
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::AtomicBlackBox);
78   BBTK_NAME("BinaryThresholdImageFilter");
79   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
80   BBTK_CATEGORY("filter;image");
81   BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
82   BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
83              "Input image. Can be any itk::Image<T,D>*",anyImagePointer,"");
84   BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
85              "Lower threshold",double,"");
86   BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
87              "Upper threshold",double,"");
88   BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
89              "Output value for pixels inside thresholds",double,"");
90   BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
91              "Output value for pixels outside thresholds",double,"");
92   BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
93               "Output image. Of the same type and dimension than the input image",
94               anyImagePointer,"");
95   BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
96
97
98
99   void BinaryThresholdImageFilterGeneric::ProcessSwitch()
100   {
101     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
102   }
103
104   template <class T> 
105   void BinaryThresholdImageFilterGeneric::Process()
106   {
107     bbtkDebugMessageInc("Core",9,
108                         "bbitk::BinaryThresholdImageFilterGeneric::Process<"
109                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
110  
111     typedef BinaryThresholdImageFilter<T> FilterType;
112     FilterType* f = FilterType::bbNew("Temp");
113     f->bbSetInputIn( this->bbGetInputIn().get<T*>());
114     f->bbSetInputLowerThreshold ( (typename T::PixelType)
115                                   this->bbGetInputLowerThreshold() );
116     f->bbSetInputUpperThreshold ( (typename T::PixelType)
117                                   this->bbGetInputUpperThreshold() );
118     f->bbSetInputInsideValue ( (typename T::PixelType)
119                                this->bbGetInputInsideValue() );
120     f->bbSetInputOutsideValue ( (typename T::PixelType)
121                                 this->bbGetInputOutsideValue() );
122     f->bbExecute();
123     f->bbGetOutputOut()->Register();
124     this->bbSetOutputOut( f->bbGetOutputOut() );
125     f->bbDelete();
126     bbtkDebugDecTab("Core",9);
127   }
128   
129   template <class T>
130   void BinaryThresholdImageFilter<T>::Init()
131   {
132     bbSetInputLowerThreshold(0);
133     bbSetInputUpperThreshold(100);
134     bbSetInputInsideValue(255);
135     bbSetInputOutsideValue(0);
136   }
137
138   void BinaryThresholdImageFilterGeneric::Init()
139   {
140     bbSetInputLowerThreshold(0);
141     bbSetInputUpperThreshold(100);
142     bbSetInputInsideValue(255);
143     bbSetInputOutsideValue(0);
144   }
145
146 }
147 // EO namespace bbtk
148
149 #endif