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