]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkApplyMask.cxx
52c1ed2d2ac50373316af68e4a7085a0eeaad67f
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkApplyMask.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkApplyMask.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "creaVtk_MACROS.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ApplyMask)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ApplyMask,bbtk::AtomicBlackBox);
14 //===== 
15 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
16 //===== 
17 void ApplyMask::Process()
18 {
19
20 // THE MAIN PROCESSING METHOD BODY
21 //   Here we simply set the input 'In' value to the output 'Out'
22 //   And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 //    void bbSet{Input|Output}NAME(const TYPE&)
25 //    const TYPE& bbGet{Input|Output}NAME() const 
26 //    Where :
27 //    * NAME is the name of the input/output
28 //      (the one provided in the attribute 'name' of the tag 'input')
29 //    * TYPE is the C++ type of the input/output
30 //      (the one provided in the attribute 'type' of the tag 'input')
31
32 //    bbSetOutputOut( bbGetInputIn() );
33 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34
35         if ((bbGetInputImage()!=NULL) && (bbGetInputMask()!=NULL))
36         {
37                 int                             extImage[6];
38                 int                             extMask[6];
39                 vtkImageData            *resultImage=NULL;
40                 bbGetInputImage()->GetExtent( extImage );
41                 bbGetInputImage()->GetExtent( extMask );
42                 int dimXImage           = extImage[1]-extImage[0]+1;
43                 int dimYImage           = extImage[3]-extImage[2]+1;
44                 int dimZImage           = extImage[5]-extImage[4]+1;
45                 int dimXMask            = extMask[1]-extMask[0]+1;
46                 int dimYMask            = extMask[3]-extMask[2]+1;
47                 int dimZMask            = extMask[5]-extMask[4]+1;
48
49                 double background       = bbGetInputBackground();
50                 double bgToAnalice      = bbGetInputBackgroundToAnalice();
51
52                 if (bbGetInputType()==0)
53                 {
54                         if (bbGetOutputOut()!=NULL) 
55                         {
56                                 bbGetOutputOut()->Delete();
57                         }       
58
59                         resultImage = vtkImageData::New();
60                         resultImage->Initialize();
61                         resultImage->SetSpacing( bbGetInputImage()->GetSpacing() );
62                         resultImage->SetDimensions(  dimXImage, dimYImage, dimZImage );
63                         resultImage->AllocateScalars( bbGetInputImage()->GetScalarType(),1 );
64                 } // if Type==0                 
65
66                 if (bbGetInputType()==1)
67                 {
68                         resultImage=bbGetInputImage();
69                 } // if Type==1
70
71                 if (bbGetInputType()==2)
72                 {
73                         resultImage=bbGetInputImage();
74                 } // if Type==2
75
76                 if (bbGetInputType()==3)
77                 {
78                         resultImage=bbGetInputImage();
79                 } // if Type==3
80
81
82                 if ((dimXImage==dimXMask) &&
83                         (dimYImage==dimYMask) &&
84                         (dimZImage==dimZMask)) 
85                         {
86                                 long int i, size = dimXImage * dimYImage * dimZImage;
87                                 #pragma omp parallel for 
88                                 for (i=0; i<size;i++)
89                                 {
90                                         DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI, bbGetInputImage() );
91                                         DEF_POINTER_IMAGE_VTK_CREA(vM,ssM,pM,stM, bbGetInputMask() );
92                                         DEF_POINTER_IMAGE_VTK_CREA(vO,ssO,pO,stO, resultImage );
93                                         GETVALUE2_VTK_CREA(vM,pM,stM,i);
94
95                                         if (bbGetInputType()==0)  //Applay mask to new Image
96                                         {               
97                                                 GETVALUE2_VTK_CREA(vI,pI,stI,i);
98                                                 if (vM!=bgToAnalice)
99                                                 {
100                                                         vO = vI;
101                                                 } else {
102                                                         vO = background; 
103                                                 } // if vM
104                                                 SETVALUE2_VTK_CREA(vO,pO,stO,i);        
105                                         } // if Type==0
106
107                                         if (bbGetInputType()==1)  //Modifiy the Input image with the Label value in Mask place
108                                         {               
109                                                 if (vM!=bgToAnalice)
110                                                 {
111                                                         vO = bbGetInputLabel();
112                                                         SETVALUE2_VTK_CREA(vO,pO,stO,i);        
113                                                 }
114                                         } // if Type==1
115
116                                         if (bbGetInputType()==2)  //Modifiy the Input image with the Mask value
117                                         {               
118                                                 if (vM!=bgToAnalice)
119                                                 {
120                                                         vO = vM;
121                                                         SETVALUE2_VTK_CREA(vO,pO,stO,i);        
122                                                 }
123                                         } // if Type==2
124
125                                 } // for
126                 } //if dim
127                 bbSetOutputOut( resultImage );
128         } // if Image && Mask   
129 }
130 //===== 
131 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
132 //===== 
133 void ApplyMask::bbUserSetDefaultValues()
134 {
135
136 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
137 //    Here we initialize the input 'In' to 0
138    bbSetInputImage(NULL);
139    bbSetInputMask(NULL);
140    bbSetInputBackground(0);             // output image Type 0
141    bbSetInputBackgroundToAnalice(0);
142    bbSetInputLabel(255);
143    bbSetInputType(0);
144    bbSetOutputOut(NULL);
145   
146 }
147 //===== 
148 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
149 //===== 
150 void ApplyMask::bbUserInitializeProcessing()
151 {
152
153 //  THE INITIALIZATION METHOD BODY :
154 //    Here does nothing 
155 //    but this is where you should allocate the internal/output pointers 
156 //    if any 
157
158   
159 }
160 //===== 
161 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
162 //===== 
163 void ApplyMask::bbUserFinalizeProcessing()
164 {
165
166 //  THE FINALIZATION METHOD BODY :
167 //    Here does nothing 
168 //    but this is where you should desallocate the internal/output pointers 
169 //    if any
170   
171 }
172 }
173 // EO namespace bbcreaVtk
174
175