2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #ifndef __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
30 #define __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
34 // To create a new Package with boxes that use itk don't forget 3 steps:
36 // 1. Modify de CMakeList.txt file of the whole project to include cmake itk mechanism.
37 // 1.1 Put ON the option SET(USE_ITK ON)
39 // 2. Modify de CMakeList.txt file of this package.
40 // 2.1. Uncomment the line SET(${BBTK_PACKAGE_NAME}_USE_ITK ON)
41 // 2.2. Add the lines:
42 // ${BBTK_DIR}/../../../include/bbitk # linux
43 // ${BBTK_DIR}/include/bbitk # windows
44 // In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS section
46 // 3. In the .h file of your box, don't forget:
47 // 3.1. Define the DIM and the TYPE of the images
48 // (Comment out the BBTK_ITK_IMAGE_DIM_xxx
49 // and the BBTK_ITK_IMAGE_TYPE_xxx_t you don't need)
51 // // Definition of the DIM and TYPE of the itkImage ..
52 // #define BBTK_ITK_IMAGE_DIM_2
53 // #define BBTK_ITK_IMAGE_DIM_3
54 // #define BBTK_ITK_IMAGE_DIM_4
55 // #define BBTK_ITK_IMAGE_TYPE_int8_t
56 // #define BBTK_ITK_IMAGE_TYPE_uint8_t
57 // #define BBTK_ITK_IMAGE_TYPE_int16_t
58 // #define BBTK_ITK_IMAGE_TYPE_uint16_t
59 // #define BBTK_ITK_IMAGE_TYPE_int32_t
60 // #define BBTK_ITK_IMAGE_TYPE_uint32_t
61 // #define BBTK_ITK_IMAGE_TYPE_float
62 // #define BBTK_ITK_IMAGE_TYPE_double
63 // 3.2. Define the ProcessTemplate method with the
64 // BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
66 // Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
72 // Definition of the DIM and TYPE of the itkImage ..
73 #define BBTK_ITK_IMAGE_DIM_2
74 #define BBTK_ITK_IMAGE_DIM_3
75 #define BBTK_ITK_IMAGE_DIM_4
76 #define BBTK_ITK_IMAGE_TYPE_int8_t
77 #define BBTK_ITK_IMAGE_TYPE_uint8_t
78 #define BBTK_ITK_IMAGE_TYPE_int16_t
79 #define BBTK_ITK_IMAGE_TYPE_uint16_t
80 #define BBTK_ITK_IMAGE_TYPE_int32_t
81 #define BBTK_ITK_IMAGE_TYPE_uint32_t
82 #define BBTK_ITK_IMAGE_TYPE_float
83 #define BBTK_ITK_IMAGE_TYPE_double
87 #include "bbmySamplePackage_EXPORT.h"
88 #include "bbtkAtomicBlackBox.h"
91 #include "bbitkImage.h"
93 #include <itkBinaryThresholdImageFilter.h>
95 #include "itkResampleImageFilter.h"
96 #include "itkNearestNeighborInterpolateImageFunction.h"
98 namespace bbmySamplePackage
101 class bbmySamplePackage_EXPORT mySampleBoxWithITK
103 public bbtk::AtomicBlackBox
105 BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
107 BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
108 BBTK_DECLARE_INPUT(Lower,double);
109 BBTK_DECLARE_INPUT(Upper,double);
110 BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
112 BBTK_PROCESS(Process);
114 inline void Process();
115 template <class T> void ProcessTemplated();
116 itk::Object* mOutput;
119 BBTK_BEGIN_DESCRIBE_BLACK_BOX(mySampleBoxWithITK,bbtk::AtomicBlackBox);
120 BBTK_NAME("mySampleBoxWithITK");
121 BBTK_AUTHOR("Info-Dev");
122 BBTK_DESCRIPTION("Example ITK box - CreaNewProject");
123 BBTK_CATEGORY("filter");
124 BBTK_INPUT(mySampleBoxWithITK,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
125 BBTK_INPUT(mySampleBoxWithITK,Lower,"(200 default) Lower value for the threshold*",double,"");
126 BBTK_INPUT(mySampleBoxWithITK,Upper,"(1200 default) Upper value for the threshold*",double,"");
127 BBTK_OUTPUT(mySampleBoxWithITK,Out,"Output Image",bbitk::anyImagePointer,"");
128 BBTK_END_DESCRIBE_BLACK_BOX(mySampleBoxWithITK);
132 //===================================================
133 void mySampleBoxWithITK::Process()
135 bbtk::TypeInfo t = bbGetInputIn().type();
136 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
138 //===================================================
141 //===================================================
142 template <class ImageType>
143 void mySampleBoxWithITK::ProcessTemplated()
145 bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
147 typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
148 typename FilterType::Pointer filter = FilterType::New();
151 ImageType* in = this->bbGetInputIn().get<ImageType*>();
152 filter->SetInput( in );
153 filter->SetInsideValue (255);
154 filter->SetOutsideValue (0);
155 filter->SetLowerThreshold( bbGetInputLower() );
156 filter->SetUpperThreshold( bbGetInputUpper() );
159 filter->GetOutput()->Register();
160 if (mOutput) mOutput->UnRegister();
161 mOutput = filter->GetOutput();
162 this->bbSetOutputOut( filter->GetOutput() );
164 bbtkDebugDecTab("Core",9);
166 //===================================================
169 // EO namespace bbmySamplePackage
171 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__