]> Creatis software - crea.git/blob - appli/creaNewProject/NewProject/bbtk_mySamplePackage_PKG/src/bbmySamplePackagemySampleBoxWithITK.h
Feature #1763
[crea.git] / appli / creaNewProject / NewProject / bbtk_mySamplePackage_PKG / src / bbmySamplePackagemySampleBoxWithITK.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
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.
14 #
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
19 #  liability. 
20 #
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 # ------------------------------------------------------------------------ */ 
24
25
26 #ifndef __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
27 #define __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
28
29 //
30 //
31 // To create a new Package with boxes that use itk don't forget 3 steps:
32 //
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)
35 //
36 // 2. Modify de CMakeList.txt file of this package.
37 //              2.1. Uncomment the line  SET(${BBTK_PACKAGE_NAME}_USE_ITK  ON)
38 //              2.2. Add the line:       
39 //                              ${BBTK_DIR}/../../../include/bbitk
40 //                   In the SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS   section
41 //
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.
48 //
49 //      Note: We use a generic bbtk_itk_pointer to transfere the itkImage..
50 //
51 //
52
53
54
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
67
68
69
70 #include "bbmySamplePackage_EXPORT.h"
71 #include "bbtkAtomicBlackBox.h"
72 #include "iostream"
73
74 #include "bbitkImage.h"
75
76 #include <itkBinaryThresholdImageFilter.h>
77
78 #include "itkResampleImageFilter.h"
79 #include "itkNearestNeighborInterpolateImageFunction.h"
80
81 namespace bbmySamplePackage
82 {
83
84 class bbmySamplePackage_EXPORT mySampleBoxWithITK
85  : 
86    public bbtk::AtomicBlackBox
87 {
88   BBTK_BLACK_BOX_INTERFACE(mySampleBoxWithITK,bbtk::AtomicBlackBox);
89
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);
94         
95   BBTK_PROCESS(Process);
96 private:
97   inline void Process();
98   template <class T> void ProcessTemplated();
99   itk::Object* mOutput;
100 };
101
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);
112
113         
114         
115 //===================================================
116 void mySampleBoxWithITK::Process()
117 {
118         bbtk::TypeInfo t = bbGetInputIn().type();
119         BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->ProcessTemplated);
120 }
121 //===================================================
122         
123
124 //===================================================
125 template <class ImageType> 
126 void mySampleBoxWithITK::ProcessTemplated()
127 {
128         bbtkDebugMessageInc("Core",9,"bbitk::BinaryThresholdImageFilter::Process<"<<bbtk::TypeName<ImageType>()<<">()"<<std::endl);
129
130         typedef itk::BinaryThresholdImageFilter<ImageType,ImageType> FilterType;
131         typename FilterType::Pointer filter = FilterType::New();
132         
133         // Input
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() );
140
141         filter->Update();
142         filter->GetOutput()->Register();
143         if (mOutput) mOutput->UnRegister();
144         mOutput = filter->GetOutput();
145         this->bbSetOutputOut( filter->GetOutput() );
146         
147         bbtkDebugDecTab("Core",9);
148 }
149 //===================================================
150         
151 }
152 // EO namespace bbmySamplePackage
153
154 #endif // __bbmySamplePackagemySampleBoxWithITK_h_INCLUDED__
155