]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkExtractImageFilter.h
MacOSX build
[bbtk.git] / packages / itk / src / bbitkExtractImageFilter.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkExtractImageFilter.h,v $
4   Language:  C++
5   Date:      $Date: 2008/11/12 12:47:03 $
6   Version:   $Revision: 1.9 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31
32 #ifdef _USE_ITK_
33
34 #include "bbtkAtomicBlackBox.h"
35 #include "itkExtractImageFilter.h"
36 #include "bbtkItkBlackBoxMacros.h"
37 #include "bbitkImage.h"
38 #include "bbitkImageRegion.h"
39
40 namespace bbitk
41 {
42
43   
44   template <class T>
45   class /*BBTK_EXPORT*/ ExtractImageFilter
46     : 
47     public bbtk::AtomicBlackBox,
48     public itk::ExtractImageFilter<T,T>
49   {
50     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(ExtractImageFilter,
51                                       bbtk::AtomicBlackBox,
52                                       T);
53     typedef itk::ExtractImageFilter<T,T> itkParent;
54
55     BBTK_DECLARE_ITK_INPUT(In,const T*);
56     BBTK_DECLARE_ITK_PARAM(ExtractionRegion,typename T::RegionType);
57     BBTK_DECLARE_ITK_OUTPUT(Out,T*);
58
59     BBTK_ITK_PROCESS();
60     BBTK_ITK_DELETE();
61   };
62
63
64   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter,
65                                       bbtk::AtomicBlackBox);
66   BBTK_NAME("ExtractImageFilter<"+bbtk::TypeName<T>()+">");
67   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
68   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
69   BBTK_TEMPLATE_INPUT(ExtractImageFilter,In,"Input image",const T*);
70   BBTK_TEMPLATE_INPUT(ExtractImageFilter,ExtractionRegion,"Extraction region",typename T::RegionType);
71   BBTK_TEMPLATE_OUTPUT(ExtractImageFilter,Out,"Output image",T*);
72   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
73   
74   //===================================================
75   // Generic "untemplatized" filter
76   //===================================================
77   class /*BBTK_EXPORT*/ ExtractImageFilterGeneric
78     : public bbtk::AtomicBlackBox
79   {
80     BBTK_BLACK_BOX_INTERFACE(ExtractImageFilterGeneric,
81                              bbtk::AtomicBlackBox);
82     BBTK_DECLARE_INPUT(In,anyImagePointer);
83     BBTK_DECLARE_INPUT(Region,anyImageRegion);
84     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
85     BBTK_PROCESS(ProcessSwitch);
86   private :
87     inline void ProcessSwitch();
88     template <class T> void Process();
89   };
90   
91   BBTK_BEGIN_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric,
92                                 bbtk::AtomicBlackBox);
93   BBTK_NAME("ExtractImageFilter");
94   BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
95   BBTK_CATEGORY("image;filter");
96   BBTK_DESCRIPTION("Decrease the image size by cropping the image to the selected region bounds (bbification of itk::ExtractImageFilter)");
97   BBTK_INPUT(ExtractImageFilterGeneric,In,"Input image",anyImagePointer,"");
98   BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion,"");
99   BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer,"");
100   BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
101   void ExtractImageFilterGeneric::ProcessSwitch()
102   {
103      BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
104   }
105
106   template <class T>
107   void ExtractImageFilterGeneric::Process()
108   {
109     bbtkDebugMessageInc("Core",9,
110                         "bbitk::ExtractImageFilterGeneric::Process<"
111                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
112     typedef T ImageType;
113     typedef ExtractImageFilter<ImageType> FilterType;
114     typename FilterType::Pointer f = FilterType::New("Temp");
115           typedef ImageType* ImageTypePointer; 
116     f->bbSetInputIn( this->bbGetInputIn().unsafe_get<ImageTypePointer>() );
117     f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
118     f->bbExecute();
119     f->bbGetOutputOut()->Register();
120     this->bbSetOutputOut( f->bbGetOutputOut() );
121     //  f->bbDelete();
122
123     bbtkDebugDecTab("Core",9);
124   }
125
126 }
127 // EO namespace bbitk
128
129 #endif