2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbitkExtractImageFilter.h,v $
32 Date: $Date: 2012/11/16 08:50:39 $
33 Version: $Revision: 1.11 $
34 =========================================================================*/
40 #include "bbtkAtomicBlackBox.h"
41 #include "itkExtractImageFilter.h"
42 #include "bbtkItkBlackBoxMacros.h"
43 #include "bbitkImage.h"
44 #include "bbitkImageRegion.h"
49 //===================================================
52 class /*BBTK_EXPORT*/ ExtractImageFilter
54 public bbtk::AtomicBlackBox,
55 public itk::ExtractImageFilter<T,T>
57 BBTK_TEMPLATE_BLACK_BOX_INTERFACE(ExtractImageFilter,
60 typedef itk::ExtractImageFilter<T,T> itkParent;
62 BBTK_DECLARE_ITK_INPUT(In,const T*);
63 BBTK_DECLARE_ITK_PARAM(ExtractionRegion,typename T::RegionType);
64 BBTK_DECLARE_ITK_OUTPUT(Out,T*);
69 //===================================================
72 //===================================================
73 // Descriptor of template filter
74 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter,
75 bbtk::AtomicBlackBox);
76 BBTK_NAME("ExtractImageFilter<"+bbtk::TypeName<T>()+">");
77 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
78 BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
79 BBTK_TEMPLATE_INPUT(ExtractImageFilter,In,"Input image",const T*);
80 BBTK_TEMPLATE_INPUT(ExtractImageFilter,ExtractionRegion,"Extraction region",typename T::RegionType);
81 BBTK_TEMPLATE_OUTPUT(ExtractImageFilter,Out,"Output image",T*);
82 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
83 //===================================================
85 //===================================================
86 template <class T> void ExtractImageFilter<T>::bbUserSetDefaultValues() {}
87 template <class T> void ExtractImageFilter<T>::bbUserInitializeProcessing(){}
88 template <class T> void ExtractImageFilter<T>::bbUserFinalizeProcessing() {}
89 //===================================================
99 //===================================================
100 // Generic "untemplatized" filter
101 //===================================================
102 class /*BBTK_EXPORT*/ ExtractImageFilterGeneric
103 : public bbtk::AtomicBlackBox
105 BBTK_BLACK_BOX_INTERFACE(ExtractImageFilterGeneric,
106 bbtk::AtomicBlackBox);
107 BBTK_DECLARE_INPUT(In,anyImagePointer);
108 BBTK_DECLARE_INPUT(Region,anyImageRegion);
109 BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
110 BBTK_PROCESS(ProcessSwitch);
112 void ProcessSwitch();
113 template <class T> void Process();
115 //===================================================
117 //===================================================
118 // Descriptor of generic filter
119 BBTK_BEGIN_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric,
120 bbtk::AtomicBlackBox);
121 BBTK_NAME("ExtractImageFilter");
122 BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
123 BBTK_CATEGORY("image;filter");
124 BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
125 BBTK_INPUT(ExtractImageFilterGeneric,In,"Input image",anyImagePointer,"");
126 BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion,"");
127 BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer,"");
128 BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
129 //===================================================
132 //===================================================
133 // The main processing method is template on the itk image type
134 // which was set to the input.
135 // It is called by the ProcessSwitch method which checks the input In type
136 // and calls Process<T> where T is the right type.
138 void ExtractImageFilterGeneric::Process()
140 bbtkDebugMessageInc("Core",9,
141 "bbitk::ExtractImageFilterGeneric::Process<"
142 <<bbtk::TypeName<T>()<<">()"<<std::endl);
143 // T is the type of input image
145 // We define the type of the filter to use which is template
147 typedef ExtractImageFilter<ImageType> FilterType;
148 // Allocate the filter
149 typename FilterType::Pointer f = FilterType::New("Temp");
151 // Set the input In of the filter
153 // 1) Get **OUR** input 'In' by bbGetInputIn()
154 // It is a anyImagePointer
155 // 2) We **KNOW** that the actual type stored by the anyImagePointer
156 // is ImageType* hence we get the value stored using the
157 // unsafe_get method (which is a template method on the return type)
158 f->bbSetInputIn( this->bbGetInputIn().unsafe_get<ImageType*>() );
160 // The same for the ImageRegion except that we use 'get' and not
161 // 'unsafe get' because the region dimension passed by the user may not be
162 // compatible with the image dimension.
163 // If get fails it throws an exception which must be caught outside
164 f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
166 // Execute the filter
168 // Register its output or it will be deleted we delete the filter
169 f->bbGetOutputOut()->Register();
171 this->bbSetOutputOut( f->bbGetOutputOut() );
172 // Delete the temporary filter
175 bbtkDebugDecTab("Core",9);
177 //===================================================
180 // EO namespace bbitk