]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkApplyMask.cxx
#3329 creaVtk Feature New Normal - new options for Applay mask box
[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                 if (bbGetInputType()==0)
50                 {
51                         if (bbGetOutputOut()!=NULL) 
52                         {
53                                 bbGetOutputOut()->Delete();
54                         }       
55
56                         resultImage = vtkImageData::New();
57                         resultImage->Initialize();
58                         resultImage->SetSpacing( bbGetInputImage()->GetSpacing() );
59                         resultImage->SetDimensions(  dimXImage, dimYImage, dimZImage );
60                         resultImage->AllocateScalars( bbGetInputImage()->GetScalarType(),1 );
61                 } // if Type==0                 
62
63                 if (bbGetInputType()==1)
64                 {
65                         resultImage=bbGetInputImage();
66                 } // if Type==1
67
68                 if (bbGetInputType()==2)
69                 {
70                         resultImage=bbGetInputImage();
71                 } // if Type==2
72
73                 if (bbGetInputType()==3)
74                 {
75                         resultImage=bbGetInputImage();
76                 } // if Type==3
77
78
79                 if ((dimXImage==dimXMask) &&
80                         (dimYImage==dimYMask) &&
81                         (dimZImage==dimZMask)) 
82                         {
83                                 long int i, size = dimXImage * dimYImage * dimZImage;
84                                 #pragma omp parallel for 
85                                 for (i=0; i<size;i++)
86                                 {
87                                         DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI, bbGetInputImage() );
88                                         DEF_POINTER_IMAGE_VTK_CREA(vM,ssM,pM,stM, bbGetInputMask() );
89                                         DEF_POINTER_IMAGE_VTK_CREA(vO,ssO,pO,stO, resultImage );
90                                         GETVALUE2_VTK_CREA(vM,pM,stM,i);
91
92                                         if (bbGetInputType()==0)  //Applay mask to new Image
93                                         {               
94                                                 GETVALUE2_VTK_CREA(vI,pI,stI,i);
95                                                 if (vM!=0)
96                                                 {
97                                                         vO = vI;
98                                                 } else {
99                                                         vO = bbGetInputBackground(); 
100                                                 }
101                                                 SETVALUE2_VTK_CREA(vO,pO,stO,i);        
102                                         } // if Type==0
103
104                                         if (bbGetInputType()==1)  //Modifiy the Input image with the Label value in Mask place
105                                         {               
106                                                 if (vM!=0)
107                                                 {
108                                                         vO = bbGetInputLabel();
109                                                         SETVALUE2_VTK_CREA(vO,pO,stO,i);        
110                                                 }
111                                         } // if Type==0
112
113                                         if (bbGetInputType()==2)  //Modifiy the Input image with the Mask value
114                                         {               
115                                                 if (vM!=0)
116                                                 {
117                                                         vO = vM;
118                                                         SETVALUE2_VTK_CREA(vO,pO,stO,i);        
119                                                 }
120                                         } // if Type==0
121
122                                 } // for
123                 } //if dim
124         bbSetOutputOut( resultImage );
125         } // if Image && Mask   
126
127 }
128 //===== 
129 // 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)
130 //===== 
131 void ApplyMask::bbUserSetDefaultValues()
132 {
133
134 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
135 //    Here we initialize the input 'In' to 0
136    bbSetInputImage(NULL);
137    bbSetInputMask(NULL);
138    bbSetInputBackground(0);
139    bbSetInputLabel(255);
140    bbSetInputType(0);
141    bbSetOutputOut(NULL);
142   
143 }
144 //===== 
145 // 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)
146 //===== 
147 void ApplyMask::bbUserInitializeProcessing()
148 {
149
150 //  THE INITIALIZATION METHOD BODY :
151 //    Here does nothing 
152 //    but this is where you should allocate the internal/output pointers 
153 //    if any 
154
155   
156 }
157 //===== 
158 // 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)
159 //===== 
160 void ApplyMask::bbUserFinalizeProcessing()
161 {
162
163 //  THE FINALIZATION METHOD BODY :
164 //    Here does nothing 
165 //    but this is where you should desallocate the internal/output pointers 
166 //    if any
167   
168 }
169 }
170 // EO namespace bbcreaVtk
171
172