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