]> Creatis software - crea.git/blob - appli/creaNewProject/NewProject/bbtk_mySamplePackage_PKG/src/bbmySamplePackagemySampleBoxWithITK.h
c2c36f6af2290bf4bc708c3792f829c4aef61ab3
[crea.git] / appli / creaNewProject / NewProject / bbtk_mySamplePackage_PKG / src / bbmySamplePackagemySampleBoxWithITK.h
1
2 #ifndef __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
3 #define __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
4
5 //
6 //
7 // To create a new Package with boxes that use itk don't forget 3 steps:
8 //
9 // 1. Modify de CMakeList.txt file of the whole project to include cmake itk mechanism.
10 //              1.1 Put ON the option          SET(USE_ITK       ON)
11 //
12 // 2. Modify de CMakeList.txt file of this package.
13 //              2.1. Uncomment the line  SET(${BBTK_PACKAGE_NAME}_USE_ITK  ON)
14 //              2.2. Add the line:       
15 //                              ${BBTK_DIR}/../../../include/bbitk
16 //                   In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS   section
17 //
18 // 3. In the .h file of your box, don't forget:
19 //              3.1. Define the DIM and the TYPE of the images
20 //                   (Comment out the BBTK_ITK_IMAGE_DIM_xxx
21 //                    and the BBTK_ITK_IMAGE_TYPE_xxx_t you don't need)
22 //              3.2. Define the ProcessTemplate method with the 
23 //                 BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
24 //
25 //      Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
26 //
27 //
28
29
30
31 // Definition of the DIM and TYPE of the itkImage ..
32 #define BBTK_ITK_IMAGE_DIM_2
33 #define BBTK_ITK_IMAGE_DIM_3
34 #define BBTK_ITK_IMAGE_DIM_4
35 #define BBTK_ITK_IMAGE_TYPE_int8_t
36 #define BBTK_ITK_IMAGE_TYPE_uint8_t
37 #define BBTK_ITK_IMAGE_TYPE_int16_t
38 #define BBTK_ITK_IMAGE_TYPE_uint16_t
39 #define BBTK_ITK_IMAGE_TYPE_int32_t
40 #define BBTK_ITK_IMAGE_TYPE_uint32_t
41 #define BBTK_ITK_IMAGE_TYPE_float
42 #define BBTK_ITK_IMAGE_TYPE_double
43
44
45
46 #include "bbmySamplePackage_EXPORT.h"
47 #include "bbtkAtomicBlackBox.h"
48 #include "iostream"
49
50 #include "bbitkImage.h"
51
52 #include <itkBinaryThresholdImageFilter.h>
53
54 #include "itkResampleImageFilter.h"
55 #include "itkNearestNeighborInterpolateImageFunction.h"
56
57 namespace bbmySamplePackage
58 {
59
60 class bbmySamplePackage_EXPORT mySampleBoxWithITK
61  : 
62    public bbtk::AtomicBlackBox
63 {
64   BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
65
66   BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
67   BBTK_DECLARE_INPUT(Lower,double);
68   BBTK_DECLARE_INPUT(Upper,double);
69   BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
70         
71   BBTK_PROCESS(Process);
72 private:
73   inline void Process();
74   template <class T> void ProcessTemplated();
75   itk::Object* mOutput;
76 };
77
78 BBTK_BEGIN_DESCRIBE_BLACK_BOX(mySampleBoxWithITK,bbtk::AtomicBlackBox);
79         BBTK_NAME("mySampleBoxWithITK");
80         BBTK_AUTHOR("Info-Dev");
81         BBTK_DESCRIPTION("Example ITK box - CreaNewProject");
82         BBTK_CATEGORY("filter");
83         BBTK_INPUT(mySampleBoxWithITK,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
84         BBTK_INPUT(mySampleBoxWithITK,Lower,"(200 default) Lower value for the threshold*",double,"");
85         BBTK_INPUT(mySampleBoxWithITK,Upper,"(1200 default) Upper value for the threshold*",double,"");
86         BBTK_OUTPUT(mySampleBoxWithITK,Out,"Output Image",bbitk::anyImagePointer,"");
87 BBTK_END_DESCRIBE_BLACK_BOX(mySampleBoxWithITK);
88
89         
90         
91 //===================================================
92 void mySampleBoxWithITK::Process()
93 {
94         bbtk::TypeInfo t = bbGetInputIn().type();
95         BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
96 }
97 //===================================================
98         
99
100 //===================================================
101 template <class ImageType> 
102 void mySampleBoxWithITK::ProcessTemplated()
103 {
104         bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
105
106         typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
107         typename FilterType::Pointer filter = FilterType::New();
108         
109         // Input
110         ImageType* in = this->bbGetInputIn().get<ImageType*>();
111         filter->SetInput( in );
112         filter->SetInsideValue (255);
113         filter->SetOutsideValue (0);
114         filter->SetLowerThreshold( bbGetInputLower() );
115         filter->SetUpperThreshold( bbGetInputUpper() );
116
117         filter->Update();
118         filter->GetOutput()->Register();
119         if (mOutput) mOutput->UnRegister();
120         mOutput = filter->GetOutput();
121         this->bbSetOutputOut( filter->GetOutput() );
122         
123         bbtkDebugDecTab("Core",9);
124 }
125 //===================================================
126         
127 }
128 // EO namespace bbmySamplePackage
129
130 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
131