]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkExtractImageFilter.h
*** empty log message ***
[bbtk.git] / packages / itk / src / bbitkExtractImageFilter.h
1 #ifdef _USE_ITK_
2
3 #include "bbtkUserBlackBox.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::UserBlackBox,
16     public itk::ExtractImageFilter<T,T>
17   {
18     BBTK_USER_BLACK_BOX_INTERFACE(ExtractImageFilter,bbtk::UserBlackBox);
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::UserBlackBox
44   {
45     BBTK_USER_BLACK_BOX_INTERFACE(ExtractImageFilterGeneric,
46                                   bbtk::UserBlackBox);
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,bbtk::UserBlackBox);
57   BBTK_NAME("ExtractImageFilter");
58   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
59   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
60   BBTK_INPUT(ExtractImageFilterGeneric,In,"Input image",anyImagePointer);
61   BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion);
62   BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer);
63   BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
64   void ExtractImageFilterGeneric::ProcessSwitch()
65   {
66      BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
67   }
68
69   template <class T>
70   void ExtractImageFilterGeneric::Process()
71   {
72     bbtkDebugMessageInc("Core",9,
73                         "bbitk::ExtractImageFilterGeneric::Process<"
74                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
75     typedef T ImageType;
76     typedef ExtractImageFilter<ImageType> FilterType;
77     FilterType* f = FilterType::bbNew("Temp");
78     f->bbSetInputIn( this->bbGetInputIn().unsafe_get<T*>() );
79     f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
80     f->bbExecute();
81     f->bbGetOutputOut()->Register();
82     this->bbSetOutputOut( f->bbGetOutputOut() );
83     f->bbDelete();
84
85     bbtkDebugDecTab("Core",9);
86   }
87
88 }
89 // EO namespace bbitk
90
91 #endif