]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkBinaryThresholdImageFilter.h
e6fdd1060b9602b0d1762d2077c0c234e72cb7bb
[bbtk.git] / packages / itk / src / bbitkBinaryThresholdImageFilter.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkBinaryThresholdImageFilter.h,v $
4   Language:  C++
5   Date:      $Date: 2009/05/15 14:57:58 $
6   Version:   $Revision: 1.12 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 #ifdef _USE_ITK_
33
34 #include "bbtkAtomicBlackBox.h"
35 #include "itkBinaryThresholdImageFilter.h"
36 #include "bbtkItkBlackBoxMacros.h"
37 #include "bbitkImage.h"
38
39 namespace bbitk
40 {
41
42   template <class T>
43   class /*BBTK_EXPORT*/ BinaryThresholdImageFilter
44     : 
45     public bbtk::AtomicBlackBox,
46     public itk::BinaryThresholdImageFilter<T,T>
47   {
48     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
49                                       bbtk::AtomicBlackBox,T);
50     typedef itk::BinaryThresholdImageFilter<T,T> itkParent;
51     BBTK_DECLARE_ITK_INPUT(In,const T*);
52     BBTK_DECLARE_ITK_PARAM(LowerThreshold,typename T::PixelType);
53     BBTK_DECLARE_ITK_PARAM(UpperThreshold,typename T::PixelType);
54     BBTK_DECLARE_ITK_PARAM(InsideValue,typename T::PixelType);
55     BBTK_DECLARE_ITK_PARAM(OutsideValue,typename T::PixelType);
56     BBTK_DECLARE_ITK_OUTPUT(Out,T*);
57     BBTK_ITK_PROCESS();
58     BBTK_ITK_DELETE();
59
60
61   };
62   
63   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter,
64                                       bbtk::AtomicBlackBox);
65   BBTK_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
66   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
67   BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
68   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
69   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
70                       "Lower threshold",typename T::PixelType);
71   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
72                       "Upper threshold",typename T::PixelType);
73   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
74                       "Output value for pixels inside thresholds",
75                       typename T::PixelType);
76   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
77                       "Output value for pixels outside thresholds",
78                       typename T::PixelType);
79   BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
80   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
81   
82   //===================================================
83   // Generic "untemplatized" filter
84   //===================================================
85   class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
86     : 
87     public bbtk::AtomicBlackBox
88   {
89     BBTK_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
90                                   bbtk::AtomicBlackBox);
91     BBTK_DECLARE_INPUT(In,anyImagePointer);
92     BBTK_DECLARE_INPUT(LowerThreshold,double);
93     BBTK_DECLARE_INPUT(UpperThreshold,double);
94     BBTK_DECLARE_INPUT(InsideValue,double);
95     BBTK_DECLARE_INPUT(OutsideValue,double);
96     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
97     BBTK_PROCESS(ProcessSwitch);
98   private :
99     inline void ProcessSwitch();
100     template <class T> void Process();
101   };
102   
103   BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
104                                 bbtk::AtomicBlackBox);
105   BBTK_NAME("BinaryThresholdImageFilter");
106   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
107   BBTK_CATEGORY("filter;image");
108   BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
109   BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
110              "Input image. Can be any itk::Image<T,D>*",anyImagePointer,"");
111   BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
112              "Lower threshold",double,"");
113   BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
114              "Upper threshold",double,"");
115   BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
116              "Output value for pixels inside thresholds",double,"");
117   BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
118              "Output value for pixels outside thresholds",double,"");
119   BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
120               "Output image. Of the same type and dimension than the input image",
121               anyImagePointer,"");
122   BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
123
124
125
126   void BinaryThresholdImageFilterGeneric::ProcessSwitch()
127   {
128     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
129   }
130
131   template <class T> 
132   void BinaryThresholdImageFilterGeneric::Process()
133   {
134     bbtkDebugMessageInc("Core",9,
135                         "bbitk::BinaryThresholdImageFilterGeneric::Process<"
136                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
137  
138     typedef BinaryThresholdImageFilter<T> FilterType;
139     typename FilterType::Pointer f = FilterType::New("Temp");
140           typedef T* TPointer; 
141           f->bbSetInputIn( this->bbGetInputIn().get < TPointer > () );
142     f->bbSetInputLowerThreshold ( (typename T::PixelType)
143                                   this->bbGetInputLowerThreshold() );
144     f->bbSetInputUpperThreshold ( (typename T::PixelType)
145                                   this->bbGetInputUpperThreshold() );
146     f->bbSetInputInsideValue ( (typename T::PixelType)
147                                this->bbGetInputInsideValue() );
148     f->bbSetInputOutsideValue ( (typename T::PixelType)
149                                 this->bbGetInputOutsideValue() );
150     f->bbExecute();
151     f->bbGetOutputOut()->Register();
152     this->bbSetOutputOut( f->bbGetOutputOut() );
153
154     bbtkDebugDecTab("Core",9);
155   }
156
157         
158 ////--  
159 //  template <class T>
160 //  void BinaryThresholdImageFilter<T>::bbUserSetDefaultValues()
161 //  {
162 //    bbSetInputLowerThreshold(0);
163 //    bbSetInputUpperThreshold(100);
164 //    bbSetInputInsideValue(255);
165 //    bbSetInputOutsideValue(0);
166 //  }
167
168   void BinaryThresholdImageFilterGeneric::bbUserSetDefaultValues()
169   {
170     bbSetInputLowerThreshold(0);
171     bbSetInputUpperThreshold(100);
172     bbSetInputInsideValue(255);
173     bbSetInputOutsideValue(0);
174   }
175
176  //--
177
178         template <class T>
179         void BinaryThresholdImageFilter<T>::bbUserInitializeProcessing()
180         {
181         }
182         
183         void BinaryThresholdImageFilterGeneric::bbUserInitializeProcessing()
184         {
185         }
186         
187 //--
188         
189         //--
190         
191         template <class T>
192         void BinaryThresholdImageFilter<T>::bbUserFinalizeProcessing()
193         {
194         }
195         
196         void BinaryThresholdImageFilterGeneric::bbUserFinalizeProcessing()
197         {
198         }
199         
200         
201         
202 }
203 // EO namespace bbtk
204
205 #endif