2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */
26 #ifndef __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
27 #define __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
31 // To create a new Package with boxes that use itk don't forget 3 steps:
33 // 1. Modify de CMakeList.txt file of the whole project to include cmake itk mechanism.
34 // 1.1 Put ON the option SET(USE_ITK ON)
36 // 2. Modify de CMakeList.txt file of this package.
37 // 2.1. Uncomment the line SET(${BBTK_PACKAGE_NAME}_USE_ITK ON)
39 // ${BBTK_DIR}/../../../include/bbitk
40 // In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS section
42 // 3. In the .h file of your box, don't forget:
43 // 3.1. Define the DIM and the TYPE of the images
44 // (Comment out the BBTK_ITK_IMAGE_DIM_xxx
45 // and the BBTK_ITK_IMAGE_TYPE_xxx_t you don't need)
46 // 3.2. Define the ProcessTemplate method with the
47 // BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
49 // Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
55 // Definition of the DIM and TYPE of the itkImage ..
56 #define BBTK_ITK_IMAGE_DIM_2
57 #define BBTK_ITK_IMAGE_DIM_3
58 #define BBTK_ITK_IMAGE_DIM_4
59 #define BBTK_ITK_IMAGE_TYPE_int8_t
60 #define BBTK_ITK_IMAGE_TYPE_uint8_t
61 #define BBTK_ITK_IMAGE_TYPE_int16_t
62 #define BBTK_ITK_IMAGE_TYPE_uint16_t
63 #define BBTK_ITK_IMAGE_TYPE_int32_t
64 #define BBTK_ITK_IMAGE_TYPE_uint32_t
65 #define BBTK_ITK_IMAGE_TYPE_float
66 #define BBTK_ITK_IMAGE_TYPE_double
70 #include "bbmySamplePackage_EXPORT.h"
71 #include "bbtkAtomicBlackBox.h"
74 #include "bbitkImage.h"
76 #include <itkBinaryThresholdImageFilter.h>
78 #include "itkResampleImageFilter.h"
79 #include "itkNearestNeighborInterpolateImageFunction.h"
81 namespace bbmySamplePackage
84 class bbmySamplePackage_EXPORT mySampleBoxWithITK
86 public bbtk::AtomicBlackBox
88 BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
90 BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
91 BBTK_DECLARE_INPUT(Lower,double);
92 BBTK_DECLARE_INPUT(Upper,double);
93 BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
95 BBTK_PROCESS(Process);
97 inline void Process();
98 template <class T> void ProcessTemplated();
102 BBTK_BEGIN_DESCRIBE_BLACK_BOX(mySampleBoxWithITK,bbtk::AtomicBlackBox);
103 BBTK_NAME("mySampleBoxWithITK");
104 BBTK_AUTHOR("Info-Dev");
105 BBTK_DESCRIPTION("Example ITK box - CreaNewProject");
106 BBTK_CATEGORY("filter");
107 BBTK_INPUT(mySampleBoxWithITK,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
108 BBTK_INPUT(mySampleBoxWithITK,Lower,"(200 default) Lower value for the threshold*",double,"");
109 BBTK_INPUT(mySampleBoxWithITK,Upper,"(1200 default) Upper value for the threshold*",double,"");
110 BBTK_OUTPUT(mySampleBoxWithITK,Out,"Output Image",bbitk::anyImagePointer,"");
111 BBTK_END_DESCRIBE_BLACK_BOX(mySampleBoxWithITK);
115 //===================================================
116 void mySampleBoxWithITK::Process()
118 bbtk::TypeInfo t = bbGetInputIn().type();
119 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
121 //===================================================
124 //===================================================
125 template <class ImageType>
126 void mySampleBoxWithITK::ProcessTemplated()
128 bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
130 typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
131 typename FilterType::Pointer filter = FilterType::New();
134 ImageType* in = this->bbGetInputIn().get<ImageType*>();
135 filter->SetInput( in );
136 filter->SetInsideValue (255);
137 filter->SetOutsideValue (0);
138 filter->SetLowerThreshold( bbGetInputLower() );
139 filter->SetUpperThreshold( bbGetInputUpper() );
142 filter->GetOutput()->Register();
143 if (mOutput) mOutput->UnRegister();
144 mOutput = filter->GetOutput();
145 this->bbSetOutputOut( filter->GetOutput() );
147 bbtkDebugDecTab("Core",9);
149 //===================================================
152 // EO namespace bbmySamplePackage
154 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__