1 /*=========================================================================
3 Module: $RCSfile: bbitkExtractImageFilter.h,v $
5 Date: $Date: 2009/05/18 10:45:43 $
6 Version: $Revision: 1.10 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
34 #include "bbtkAtomicBlackBox.h"
35 #include "itkExtractImageFilter.h"
36 #include "bbtkItkBlackBoxMacros.h"
37 #include "bbitkImage.h"
38 #include "bbitkImageRegion.h"
43 //===================================================
46 class /*BBTK_EXPORT*/ ExtractImageFilter
48 public bbtk::AtomicBlackBox,
49 public itk::ExtractImageFilter<T,T>
51 BBTK_TEMPLATE_BLACK_BOX_INTERFACE(ExtractImageFilter,
54 typedef itk::ExtractImageFilter<T,T> itkParent;
56 BBTK_DECLARE_ITK_INPUT(In,const T*);
57 BBTK_DECLARE_ITK_PARAM(ExtractionRegion,typename T::RegionType);
58 BBTK_DECLARE_ITK_OUTPUT(Out,T*);
63 //===================================================
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 //===================================================
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 //===================================================
93 //===================================================
94 // Generic "untemplatized" filter
95 //===================================================
96 class /*BBTK_EXPORT*/ ExtractImageFilterGeneric
97 : public bbtk::AtomicBlackBox
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);
106 void ProcessSwitch();
107 template <class T> void Process();
109 //===================================================
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 //===================================================
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.
132 void ExtractImageFilterGeneric::Process()
134 bbtkDebugMessageInc("Core",9,
135 "bbitk::ExtractImageFilterGeneric::Process<"
136 <<bbtk::TypeName<T>()<<">()"<<std::endl);
137 // T is the type of input image
139 // We define the type of the filter to use which is template
141 typedef ExtractImageFilter<ImageType> FilterType;
142 // Allocate the filter
143 typename FilterType::Pointer f = FilterType::New("Temp");
145 // Set the input In of the filter
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*>() );
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>() );
160 // Execute the filter
162 // Register its output or it will be deleted we delete the filter
163 f->bbGetOutputOut()->Register();
165 this->bbSetOutputOut( f->bbGetOutputOut() );
166 // Delete the temporary filter
169 bbtkDebugDecTab("Core",9);
171 //===================================================
174 // EO namespace bbitk