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)
42 // ${BBTK_DIR}/../../../include/bbitk
43 // In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS section
45 // 3. In the .h file of your box, don't forget:
46 // 3.1. Define the DIM and the TYPE of the images
47 // (Comment out the BBTK_ITK_IMAGE_DIM_xxx
48 // and the BBTK_ITK_IMAGE_TYPE_xxx_t you don't need)
49 // 3.2. Define the ProcessTemplate method with the
50 // BBTK_TEMPLATE_ITK_IMAGE_SWITCH mechanism.
52 // Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
58 // Definition of the DIM and TYPE of the itkImage ..
59 #define BBTK_ITK_IMAGE_DIM_2
60 #define BBTK_ITK_IMAGE_DIM_3
61 #define BBTK_ITK_IMAGE_DIM_4
62 #define BBTK_ITK_IMAGE_TYPE_int8_t
63 #define BBTK_ITK_IMAGE_TYPE_uint8_t
64 #define BBTK_ITK_IMAGE_TYPE_int16_t
65 #define BBTK_ITK_IMAGE_TYPE_uint16_t
66 #define BBTK_ITK_IMAGE_TYPE_int32_t
67 #define BBTK_ITK_IMAGE_TYPE_uint32_t
68 #define BBTK_ITK_IMAGE_TYPE_float
69 #define BBTK_ITK_IMAGE_TYPE_double
73 #include "bbmySamplePackage_EXPORT.h"
74 #include "bbtkAtomicBlackBox.h"
77 #include "bbitkImage.h"
79 #include <itkBinaryThresholdImageFilter.h>
81 #include "itkResampleImageFilter.h"
82 #include "itkNearestNeighborInterpolateImageFunction.h"
84 namespace bbmySamplePackage
87 class bbmySamplePackage_EXPORT mySampleBoxWithITK
89 public bbtk::AtomicBlackBox
91 BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
93 BBTK_DECLARE_INPUT(In,bbitk::anyImagePointer);
94 BBTK_DECLARE_INPUT(Lower,double);
95 BBTK_DECLARE_INPUT(Upper,double);
96 BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
98 BBTK_PROCESS(Process);
100 inline void Process();
101 template <class T> void ProcessTemplated();
102 itk::Object* mOutput;
105 BBTK_BEGIN_DESCRIBE_BLACK_BOX(mySampleBoxWithITK,bbtk::AtomicBlackBox);
106 BBTK_NAME("mySampleBoxWithITK");
107 BBTK_AUTHOR("Info-Dev");
108 BBTK_DESCRIPTION("Example ITK box - CreaNewProject");
109 BBTK_CATEGORY("filter");
110 BBTK_INPUT(mySampleBoxWithITK,In,"Input image. Can be any itk::Image<T,D>*",bbitk::anyImagePointer,"");
111 BBTK_INPUT(mySampleBoxWithITK,Lower,"(200 default) Lower value for the threshold*",double,"");
112 BBTK_INPUT(mySampleBoxWithITK,Upper,"(1200 default) Upper value for the threshold*",double,"");
113 BBTK_OUTPUT(mySampleBoxWithITK,Out,"Output Image",bbitk::anyImagePointer,"");
114 BBTK_END_DESCRIBE_BLACK_BOX(mySampleBoxWithITK);
118 //===================================================
119 void mySampleBoxWithITK::Process()
121 bbtk::TypeInfo t = bbGetInputIn().type();
122 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
124 //===================================================
127 //===================================================
128 template <class ImageType>
129 void mySampleBoxWithITK::ProcessTemplated()
131 bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
133 typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
134 typename FilterType::Pointer filter = FilterType::New();
137 ImageType* in = this->bbGetInputIn().get<ImageType*>();
138 filter->SetInput( in );
139 filter->SetInsideValue (255);
140 filter->SetOutsideValue (0);
141 filter->SetLowerThreshold( bbGetInputLower() );
142 filter->SetUpperThreshold( bbGetInputUpper() );
145 filter->GetOutput()->Register();
146 if (mOutput) mOutput->UnRegister();
147 mOutput = filter->GetOutput();
148 this->bbSetOutputOut( filter->GetOutput() );
150 bbtkDebugDecTab("Core",9);
152 //===================================================
155 // EO namespace bbmySamplePackage
157 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__