2 #ifndef __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
3 #define __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
7 // To create a new Package with boxes that use itk don't forget 3 steps:
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)
12 // 2. Modify de CMakeList.txt file of this package.
13 // 2.1. Uncomment the line SET(${BBTK_PACKAGE_NAME}_USE_ITK ON)
15 // ${BBTK_DIR}/../../../include/bbitk
16 // In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS section
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.
25 // Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
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
46 #include "bbmySamplePackage_EXPORT.h"
47 #include "bbtkAtomicBlackBox.h"
50 #include "bbitkImage.h"
52 #include <itkBinaryThresholdImageFilter.h>
54 #include "itkResampleImageFilter.h"
55 #include "itkNearestNeighborInterpolateImageFunction.h"
57 namespace bbmySamplePackage
60 class bbmySamplePackage_EXPORT mySampleBoxWithITK
62 public bbtk::AtomicBlackBox
64 BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
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);
71 BBTK_PROCESS(Process);
73 inline void Process();
74 template <class T> void ProcessTemplated();
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);
91 //===================================================
92 void mySampleBoxWithITK::Process()
94 bbtk::TypeInfo t = bbGetInputIn().type();
95 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
97 //===================================================
100 //===================================================
101 template <class ImageType>
102 void mySampleBoxWithITK::ProcessTemplated()
104 bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
106 typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
107 typename FilterType::Pointer filter = FilterType::New();
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() );
118 filter->GetOutput()->Register();
119 if (mOutput) mOutput->UnRegister();
120 mOutput = filter->GetOutput();
121 this->bbSetOutputOut( filter->GetOutput() );
123 bbtkDebugDecTab("Core",9);
125 //===================================================
128 // EO namespace bbmySamplePackage
130 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__