]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkExtractImageFilter.h
*** empty log message ***
[bbtk.git] / packages / itk / src / bbitkExtractImageFilter.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkExtractImageFilter.h,v $
4   Language:  C++
5   Date:      $Date: 2009/05/18 10:45:43 $
6   Version:   $Revision: 1.10 $
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 "itkExtractImageFilter.h"
36 #include "bbtkItkBlackBoxMacros.h"
37 #include "bbitkImage.h"
38 #include "bbitkImageRegion.h"
39
40 namespace bbitk
41 {
42
43   //===================================================
44   /// Template filter
45   template <class T>
46   class /*BBTK_EXPORT*/ ExtractImageFilter
47     : 
48     public bbtk::AtomicBlackBox,
49     public itk::ExtractImageFilter<T,T>
50   {
51     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(ExtractImageFilter,
52                                       bbtk::AtomicBlackBox,
53                                       T);
54     typedef itk::ExtractImageFilter<T,T> itkParent;
55
56     BBTK_DECLARE_ITK_INPUT(In,const T*);
57     BBTK_DECLARE_ITK_PARAM(ExtractionRegion,typename T::RegionType);
58     BBTK_DECLARE_ITK_OUTPUT(Out,T*);
59
60     BBTK_ITK_PROCESS();
61     BBTK_ITK_DELETE();
62   };
63   //===================================================
64
65
66   //===================================================
67   // Descriptor of template filter 
68   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter,
69                                       bbtk::AtomicBlackBox);
70   BBTK_NAME("ExtractImageFilter<"+bbtk::TypeName<T>()+">");
71   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
72   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
73   BBTK_TEMPLATE_INPUT(ExtractImageFilter,In,"Input image",const T*);
74   BBTK_TEMPLATE_INPUT(ExtractImageFilter,ExtractionRegion,"Extraction region",typename T::RegionType);
75   BBTK_TEMPLATE_OUTPUT(ExtractImageFilter,Out,"Output image",T*);
76   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
77   //===================================================
78
79   //===================================================
80   template <class T> void ExtractImageFilter<T>::bbUserSetDefaultValues() {}
81   template <class T> void ExtractImageFilter<T>::bbUserInitializeProcessing(){}
82   template <class T> void ExtractImageFilter<T>::bbUserFinalizeProcessing() {}
83   //===================================================
84   
85
86
87
88
89
90
91
92
93   //===================================================
94   // Generic "untemplatized" filter
95   //===================================================
96   class /*BBTK_EXPORT*/ ExtractImageFilterGeneric
97     : public bbtk::AtomicBlackBox
98   {
99     BBTK_BLACK_BOX_INTERFACE(ExtractImageFilterGeneric,
100                              bbtk::AtomicBlackBox);
101     BBTK_DECLARE_INPUT(In,anyImagePointer);
102     BBTK_DECLARE_INPUT(Region,anyImageRegion);
103     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
104     BBTK_PROCESS(ProcessSwitch);
105   private :
106     void ProcessSwitch();
107     template <class T> void Process();
108   };
109   //===================================================
110   
111   //===================================================
112   // Descriptor of generic filter
113   BBTK_BEGIN_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric,
114                                 bbtk::AtomicBlackBox);
115   BBTK_NAME("ExtractImageFilter");
116   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
117   BBTK_CATEGORY("image;filter");
118   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
119   BBTK_INPUT(ExtractImageFilterGeneric,In,"Input image",anyImagePointer,"");
120   BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion,"");
121   BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer,"");
122   BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
123   //===================================================
124
125
126   //===================================================
127   // The main processing method is template on the itk image type 
128   // which was set to the input. 
129   // It is called by the ProcessSwitch method which checks the input In type
130   // and calls Process<T> where T is the right type.
131   template <class T>
132   void ExtractImageFilterGeneric::Process()
133   {
134     bbtkDebugMessageInc("Core",9,
135                         "bbitk::ExtractImageFilterGeneric::Process<"
136                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
137     // T is the type of input image
138     typedef T ImageType;
139     // We define the type of the filter to use which is template 
140     // on the image type
141     typedef ExtractImageFilter<ImageType> FilterType;
142     // Allocate the filter
143     typename FilterType::Pointer f = FilterType::New("Temp");
144
145     // Set the input In of the filter
146     // Here we :
147     // 1) Get **OUR** input 'In' by bbGetInputIn()
148     //    It is a anyImagePointer
149     // 2) We **KNOW** that the actual type stored by the anyImagePointer
150     //    is ImageType* hence we get the value stored using the 
151     //    unsafe_get method (which is a template method on the return type)
152     f->bbSetInputIn( this->bbGetInputIn().unsafe_get<ImageType*>() );
153     
154     // The same for the ImageRegion except that we use 'get' and not 
155     // 'unsafe get' because the region dimension passed by the user may not be 
156     // compatible with the image dimension.
157     // If get fails it throws an exception which must be caught outside 
158     f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
159
160     // Execute the filter
161     f->bbExecute();
162     // Register its output or it will be deleted we delete the filter
163     f->bbGetOutputOut()->Register();
164     // Set OUR output
165     this->bbSetOutputOut( f->bbGetOutputOut() );
166     // Delete the temporary filter
167     f->bbDelete();
168
169     bbtkDebugDecTab("Core",9);
170   }
171   //===================================================
172
173 }
174 // EO namespace bbitk
175
176 #endif