]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkBinaryThresholdImageFilter.h
*** empty log message ***
[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/18 10:45:43 $
6   Version:   $Revision: 1.13 $
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   //===================================================
43   template <class T>
44   class /*BBTK_EXPORT*/ BinaryThresholdImageFilter
45     : 
46     public bbtk::AtomicBlackBox,
47     public itk::BinaryThresholdImageFilter<T,T>
48   {
49     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
50                                       bbtk::AtomicBlackBox,T);
51     typedef itk::BinaryThresholdImageFilter<T,T> itkParent;
52     BBTK_DECLARE_ITK_INPUT(In,const T*);
53     BBTK_DECLARE_ITK_PARAM(LowerThreshold,typename T::PixelType);
54     BBTK_DECLARE_ITK_PARAM(UpperThreshold,typename T::PixelType);
55     BBTK_DECLARE_ITK_PARAM(InsideValue,typename T::PixelType);
56     BBTK_DECLARE_ITK_PARAM(OutsideValue,typename T::PixelType);
57     BBTK_DECLARE_ITK_OUTPUT(Out,T*);
58     BBTK_ITK_PROCESS();
59     BBTK_ITK_DELETE();
60
61   };
62   //===================================================
63   
64   //===================================================
65   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter,
66                                       bbtk::AtomicBlackBox);
67   BBTK_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
68   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
69   BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
70   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
71   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
72                       "Lower threshold",typename T::PixelType);
73   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
74                       "Upper threshold",typename T::PixelType);
75   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
76                       "Output value for pixels inside thresholds",
77                       typename T::PixelType);
78   BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
79                       "Output value for pixels outside thresholds",
80                       typename T::PixelType);
81   BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
82   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
83   //===================================================
84
85
86   //===================================================
87   //--
88   template <class T>
89   void BinaryThresholdImageFilter<T>::bbUserSetDefaultValues()
90   {
91     bbSetInputLowerThreshold(0);
92     bbSetInputUpperThreshold(100);
93     bbSetInputInsideValue(255);
94     bbSetInputOutsideValue(0);
95   }
96   template <class T>
97   void BinaryThresholdImageFilter<T>::bbUserInitializeProcessing()
98   {
99   }     
100   template <class T>
101   void BinaryThresholdImageFilter<T>::bbUserFinalizeProcessing()
102   {
103   }
104   
105   //===================================================
106
107
108
109
110
111
112
113
114
115
116   
117   //===================================================
118   // Generic "untemplatized" filter
119   //===================================================
120   class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
121     : 
122     public bbtk::AtomicBlackBox
123   {
124     BBTK_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
125                                   bbtk::AtomicBlackBox);
126     BBTK_DECLARE_INPUT(In,anyImagePointer);
127     BBTK_DECLARE_INPUT(LowerThreshold,double);
128     BBTK_DECLARE_INPUT(UpperThreshold,double);
129     BBTK_DECLARE_INPUT(InsideValue,double);
130     BBTK_DECLARE_INPUT(OutsideValue,double);
131     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
132     BBTK_PROCESS(ProcessSwitch);
133   private :
134     inline void ProcessSwitch();
135     template <class T> void Process();
136   };
137   //===================================================
138
139   
140   //===================================================
141
142   BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
143                                 bbtk::AtomicBlackBox);
144   BBTK_NAME("BinaryThresholdImageFilter");
145   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
146   BBTK_CATEGORY("filter;image");
147   BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
148   BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
149              "Input image. Can be any itk::Image<T,D>*",anyImagePointer,"");
150   BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
151              "Lower threshold",double,"");
152   BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
153              "Upper threshold",double,"");
154   BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
155              "Output value for pixels inside thresholds",double,"");
156   BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
157              "Output value for pixels outside thresholds",double,"");
158   BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
159               "Output image. Of the same type and dimension than the input image",
160               anyImagePointer,"");
161   BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
162   //===================================================
163
164
165
166
167   //===================================================
168
169   void BinaryThresholdImageFilterGeneric::ProcessSwitch()
170   {
171     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
172   }
173   //===================================================
174
175
176   //===================================================
177
178   template <class T> 
179   void BinaryThresholdImageFilterGeneric::Process()
180   {
181     bbtkDebugMessageInc("Core",9,
182                         "bbitk::BinaryThresholdImageFilterGeneric::Process<"
183                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
184  
185     typedef BinaryThresholdImageFilter<T> FilterType;
186     typename FilterType::Pointer f = FilterType::New("Temp");
187           typedef T* TPointer; 
188           f->bbSetInputIn( this->bbGetInputIn().get < TPointer > () );
189     f->bbSetInputLowerThreshold ( (typename T::PixelType)
190                                   this->bbGetInputLowerThreshold() );
191     f->bbSetInputUpperThreshold ( (typename T::PixelType)
192                                   this->bbGetInputUpperThreshold() );
193     f->bbSetInputInsideValue ( (typename T::PixelType)
194                                this->bbGetInputInsideValue() );
195     f->bbSetInputOutsideValue ( (typename T::PixelType)
196                                 this->bbGetInputOutsideValue() );
197     f->bbExecute();
198     f->bbGetOutputOut()->Register();
199     this->bbSetOutputOut( f->bbGetOutputOut() );
200
201     bbtkDebugDecTab("Core",9);
202   }
203
204   //===================================================
205
206         
207
208
209         
210
211         
212         
213 }
214 // EO namespace bbtk
215
216 #endif