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