]> Creatis software - crea.git/blob - appli/creaNewProject/NewProject/bbtk_mySamplePackage_PKG/src/bbmySamplePackagemySampleBoxWithITK.h
b0532e414c57d71689cf9e57a1f307ee462515bf
[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 //              3.2. Define the ProcessTemplate method with the 
21 //                 BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
22 //
23 //      Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
24 //
25 //
26
27
28
29 // Definition of the DIM and TYPE of the itkImage ..
30 #define BBTK_ITK_IMAGE_DIM_2
31 #define BBTK_ITK_IMAGE_DIM_3
32 #define BBTK_ITK_IMAGE_DIM_4
33 #define BBTK_ITK_IMAGE_TYPE_int8_t
34 #define BBTK_ITK_IMAGE_TYPE_uint8_t
35 #define BBTK_ITK_IMAGE_TYPE_int16_t
36 #define BBTK_ITK_IMAGE_TYPE_uint16_t
37 #define BBTK_ITK_IMAGE_TYPE_int32_t
38 #define BBTK_ITK_IMAGE_TYPE_uint32_t
39 #define BBTK_ITK_IMAGE_TYPE_float
40 #define BBTK_ITK_IMAGE_TYPE_double
41
42
43
44 #include "bbmySamplePackage_EXPORT.h"
45 #include "bbtkAtomicBlackBox.h"
46 #include "iostream"
47
48 #include "bbitkImage.h"
49
50 #include <itkBinaryThresholdImageFilter.h>
51
52 #include "itkResampleImageFilter.h"
53 #include "itkNearestNeighborInterpolateImageFunction.h"
54
55 namespace bbmySamplePackage
56 {
57
58 class bbmySamplePackage_EXPORT mySampleBoxWithITK
59  : 
60    public bbtk::AtomicBlackBox
61 {
62   BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
63
64   BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
65   BBTK_DECLARE_INPUT(Lower,double);
66   BBTK_DECLARE_INPUT(Upper,double);
67   BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
68         
69   BBTK_PROCESS(Process);
70 private:
71   inline void Process();
72   template <class T> void ProcessTemplated();
73   itk::Object* mOutput;
74 };
75
76 BBTK_BEGIN_DESCRIBE_BLACK_BOX(mySampleBoxWithITK,bbtk::AtomicBlackBox);
77         BBTK_NAME("mySampleBoxWithITK");
78         BBTK_AUTHOR("Info-Dev");
79         BBTK_DESCRIPTION("Example ITK box - CreaNewProject");
80         BBTK_CATEGORY("filter");
81         BBTK_INPUT(mySampleBoxWithITK,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
82         BBTK_INPUT(mySampleBoxWithITK,Lower,"(200 default) Lower value for the threshold*",double,"");
83         BBTK_INPUT(mySampleBoxWithITK,Upper,"(1200 default) Upper value for the threshold*",double,"");
84         BBTK_OUTPUT(mySampleBoxWithITK,Out,"Output Image",bbitk::anyImagePointer,"");
85 BBTK_END_DESCRIBE_BLACK_BOX(mySampleBoxWithITK);
86
87         
88         
89 //===================================================
90 void mySampleBoxWithITK::Process()
91 {
92         bbtk::TypeInfo t = bbGetInputIn().type();
93         BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
94 }
95 //===================================================
96         
97
98 //===================================================
99 template <class ImageType> 
100 void mySampleBoxWithITK::ProcessTemplated()
101 {
102         bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
103
104         typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
105         typename FilterType::Pointer filter = FilterType::New();
106         
107         // Input
108         ImageType* in = this->bbGetInputIn().get<ImageType*>();
109         filter->SetInput( in );
110         filter->SetInsideValue (255);
111         filter->SetOutsideValue (0);
112         filter->SetLowerThreshold( bbGetInputLower() );
113         filter->SetUpperThreshold( bbGetInputUpper() );
114
115         filter->Update();
116         filter->GetOutput()->Register();
117         if (mOutput) mOutput->UnRegister();
118         mOutput = filter->GetOutput();
119         this->bbSetOutputOut( filter->GetOutput() );
120         
121         bbtkDebugDecTab("Core",9);
122 }
123 //===================================================
124         
125 }
126 // EO namespace bbmySamplePackage
127
128 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
129