]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkExtractImageFilter.h
e6597613bb233c8998f7cd4d11b64ab993383ba3
[bbtk.git] / packages / itk / src / bbitkExtractImageFilter.h
1 #ifdef _USE_ITK_
2
3 #include "bbtkAtomicBlackBox.h"
4 #include "itkExtractImageFilter.h"
5 #include "bbitkImage.h"
6 #include "bbitkImageRegion.h"
7
8 namespace bbitk
9 {
10
11   
12   template <class T>
13   class /*BBTK_EXPORT*/ ExtractImageFilter
14     : 
15     public bbtk::AtomicBlackBox,
16     public itk::ExtractImageFilter<T,T>
17   {
18     BBTK_USER_BLACK_BOX_INTERFACE(ExtractImageFilter,bbtk::AtomicBlackBox);
19     typedef itk::ExtractImageFilter<T,T> itkParent;
20
21     BBTK_DECLARE_ITK_INPUT(itkParent,In,const T*);
22     BBTK_DECLARE_ITK_PARAM(itkParent,ExtractionRegion,typename T::RegionType);
23     BBTK_DECLARE_ITK_OUTPUT(itkParent,Out,T*);
24     BBTK_PROCESS(itkParent::Update);
25     
26     void bbDelete() { itkParent::UnRegister(); }
27   };
28
29
30   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
31   BBTK_NAME("ExtractImageFilter<"+bbtk::TypeName<T>()+">");
32   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
33   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
34   BBTK_TEMPLATE_INPUT(ExtractImageFilter,In,"Input image",const T*);
35   BBTK_TEMPLATE_INPUT(ExtractImageFilter,ExtractionRegion,"Extraction region",typename T::RegionType);
36   BBTK_TEMPLATE_OUTPUT(ExtractImageFilter,Out,"Output image",T*);
37   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
38   
39   //===================================================
40   // Generic "untemplatized" filter
41   //===================================================
42   class /*BBTK_EXPORT*/ ExtractImageFilterGeneric
43     : public bbtk::AtomicBlackBox
44   {
45     BBTK_USER_BLACK_BOX_INTERFACE(ExtractImageFilterGeneric,
46                                   bbtk::AtomicBlackBox);
47     BBTK_DECLARE_INPUT(In,anyImagePointer);
48     BBTK_DECLARE_INPUT(Region,anyImageRegion);
49     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
50     BBTK_PROCESS(ProcessSwitch);
51   private :
52     inline void ProcessSwitch();
53     template <class T> void Process();
54   };
55   
56   BBTK_BEGIN_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric,
57                                 bbtk::AtomicBlackBox);
58   BBTK_NAME("ExtractImageFilter");
59   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
60   BBTK_CATEGORY("image;filter");
61   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
62   BBTK_INPUT(ExtractImageFilterGeneric,In,"Input image",anyImagePointer);
63   BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion);
64   BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer);
65   BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
66   void ExtractImageFilterGeneric::ProcessSwitch()
67   {
68      BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
69   }
70
71   template <class T>
72   void ExtractImageFilterGeneric::Process()
73   {
74     bbtkDebugMessageInc("Core",9,
75                         "bbitk::ExtractImageFilterGeneric::Process<"
76                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
77     typedef T ImageType;
78     typedef ExtractImageFilter<ImageType> FilterType;
79     FilterType* f = FilterType::bbNew("Temp");
80     f->bbSetInputIn( this->bbGetInputIn().unsafe_get<T*>() );
81     f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
82     f->bbExecute();
83     f->bbGetOutputOut()->Register();
84     this->bbSetOutputOut( f->bbGetOutputOut() );
85     f->bbDelete();
86
87     bbtkDebugDecTab("Core",9);
88   }
89
90 }
91 // EO namespace bbitk
92
93 #endif