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 // 3.2. Define the ProcessTemplate method with the
21 // BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
23 // Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
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
44 #include "bbmySamplePackage_EXPORT.h"
45 #include "bbtkAtomicBlackBox.h"
48 #include "bbitkImage.h"
50 #include <itkBinaryThresholdImageFilter.h>
52 #include "itkResampleImageFilter.h"
53 #include "itkNearestNeighborInterpolateImageFunction.h"
55 namespace bbmySamplePackage
58 class bbmySamplePackage_EXPORT mySampleBoxWithITK
60 public bbtk::AtomicBlackBox
62 BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
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);
69 BBTK_PROCESS(Process);
71 inline void Process();
72 template <class T> void ProcessTemplated();
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);
89 //===================================================
90 void mySampleBoxWithITK::Process()
92 bbtk::TypeInfo t = bbGetInputIn().type();
93 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
95 //===================================================
98 //===================================================
99 template <class ImageType>
100 void mySampleBoxWithITK::ProcessTemplated()
102 bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
104 typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
105 typename FilterType::Pointer filter = FilterType::New();
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() );
116 filter->GetOutput()->Register();
117 if (mOutput) mOutput->UnRegister();
118 mOutput = filter->GetOutput();
119 this->bbSetOutputOut( filter->GetOutput() );
121 bbtkDebugDecTab("Core",9);
123 //===================================================
126 // EO namespace bbmySamplePackage
128 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__