]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageCutByAxis.cxx
#3513 CleanMeshWithPatch
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkImageCutByAxis.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 "bbcreaVtkImageCutByAxis.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageCutByAxis)
10 BBTK_BLACK_BOX_IMPLEMENTATION(ImageCutByAxis,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void ImageCutByAxis::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29 //    bbSetOutputOut( bbGetInputIn() );
30 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
31   
32
33         vtkImageData *newData=vtkImageData::New();
34         newData->DeepCopy( bbGetInputIn() );
35
36         int ext[6];
37         
38 //EED 2017-01-01 Migration VTK7
39 #if VTK_MAJOR_VERSION <= 5
40         bbGetInputIn()->GetWholeExtent(ext);
41 #else
42         bbGetInputIn()->GetExtent(ext);
43 #endif
44
45         double  dimX    = ext[1]-ext[0]+1;
46         double  dimY    = ext[3]-ext[2]+1;
47         double  dimZ    = ext[5]-ext[4]+1;
48
49         int     x       = bbGetInputPoint()[0];
50         int     y       = bbGetInputPoint()[1];
51         int     z       = bbGetInputPoint()[2];
52
53         int i,j,k;
54         bool c1=false;
55         bool c2=false;
56         bool c3=false;
57         bool c4=false;
58     bool c5=false;
59     bool c6=false;
60     bool c7=false;
61     bool c8=false;
62
63         if ( bbGetInputType()=="x-y-z+" ) 
64         {
65                 if (bbGetInputTypeOrientation()==0)  { c1=false;        c2=true;        c3=true;        c4=true;        }
66                 if (bbGetInputTypeOrientation()==1)  { c1=true;         c2=false;       c3=true;        c4=true;        }
67                 if (bbGetInputTypeOrientation()==2)  { c1=true;         c2=false;       c3=true;        c4=true;        }
68         if (bbGetInputTypeOrientation()==3)  { c1=false;    c2=true;    c3=true;    c4=true;    }
69         }
70
71     if ( bbGetInputType()=="x+y+z+"    )
72     {
73         if (bbGetInputTypeOrientation()==3)  { c1=false;    c2=false;    c3=false;    c4=false;  c5=true;    c6=false;    c7=false;    c8=false;  }
74     }
75
76     
77     
78         if (bbGetInputInsideVol()==true)
79         {
80                 c1=!c1;
81                 c2=!c2;
82                 c3=!c3;
83                 c4=!c4;
84         } // IndideVol
85
86     printf("EED  ImageCutByAxis::Process\n");
87     if (c1==true) printf("EED  ImageCutByAxis::Process flag 1\n");
88     if (c2==true) printf("EED  ImageCutByAxis::Process flag 2\n");
89     if (c3==true) printf("EED  ImageCutByAxis::Process flag 3\n");
90     if (c4==true) printf("EED  ImageCutByAxis::Process flag 4\n");
91
92         int xmin,xmax,ymin,ymax,zmin,zmax;
93
94 //      void *imgPtr;
95 //              imgPtr=bbGetInputIn()->GetScalarPointer(x,y,z,0);
96 //              memset( bbGetInputIn()->GetScalarPointer() );
97         
98         if (c1==true)
99         {
100         if (bbGetInputTypeOrientation()==0)  { xmin=0; xmax=x; ymin=0;      ymax=y;         zmin=0; zmax=1;         }
101         if (bbGetInputTypeOrientation()==1)  { xmin=0; xmax=x; ymin=dimY-z; ymax=dimY;      zmin=0; zmax=1;         }
102         if (bbGetInputTypeOrientation()==2)  { xmin=0; xmax=y; ymin=dimY-z; ymax=dimY;      zmin=0; zmax=1;             }
103         if (bbGetInputTypeOrientation()==3)  { xmin=0; xmax=x; ymin=0;      ymax=y;         zmin=0; zmax=z;    }   // xyz
104         printf("EED  ImageCutByAxis::Process x=%d %d      y= %d %d     z=%d %d\n", xmin,xmax , ymin,ymax, zmin,zmax );
105
106         for (k=zmin;k<zmax;k++){
107             for (j=ymin;j<ymax;j++){
108                 for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,k,0,0);} // for i
109             } // for j
110         } // for k
111         }  // c1
112
113         if (c2==true)
114         {
115                 if (bbGetInputTypeOrientation()==0)  { xmin=0; xmax=x; ymin=y; ymax=dimY;                       }
116                 if (bbGetInputTypeOrientation()==1)  { xmin=0; xmax=x; ymin=0; ymax=dimY-z;                     }
117                 if (bbGetInputTypeOrientation()==2)  { xmin=0; xmax=y; ymin=0; ymax=dimY-z;             }
118         if (bbGetInputTypeOrientation()==3)  { xmin=0; xmax=x; ymin=y; ymax=dimY;             }
119                 for (j=ymin;j<ymax;j++){
120                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
121                 } // for j
122         } //c2
123
124         if (c3==true)  
125         { 
126                 if (bbGetInputTypeOrientation()==0)  { xmin=x; xmax=dimX; ymin=0;       ymax=y;     }
127                 if (bbGetInputTypeOrientation()==1)  { xmin=x; xmax=dimX; ymin=dimY-z;  ymax=dimY;      }
128                 if (bbGetInputTypeOrientation()==2)  { xmin=y; xmax=dimX; ymin=dimY-z;  ymax=dimY;      }
129         if (bbGetInputTypeOrientation()==3)  { xmin=x; xmax=dimX; ymin=0;       ymax=y;     }
130                 for (j=ymin;j<ymax;j++){
131                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
132                 } // for j
133         } //c3
134
135         if (c4==true)  
136         {  
137                 if (bbGetInputTypeOrientation()==0)  { xmin=x; xmax=dimX; ymin=y; ymax=dimY;            }
138                 if (bbGetInputTypeOrientation()==1)  { xmin=x; xmax=dimX; ymin=0; ymax=dimY-z;          }
139                 if (bbGetInputTypeOrientation()==2)  { xmin=y; xmax=dimX; ymin=0; ymax=dimY-z;          }
140         if (bbGetInputTypeOrientation()==3)  { xmin=x; xmax=dimX; ymin=y; ymax=dimY;         }
141                 for (j=ymin;j<ymax;j++){
142                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
143                 } // for j
144
145         } //c4
146     
147     
148     if (c5==true)
149     {
150         if (bbGetInputTypeOrientation()==0)  { xmin=0; xmax=x;    ymin=0;      ymax=y;           zmin=0; zmax=1;         }
151         if (bbGetInputTypeOrientation()==1)  { xmin=0; xmax=x;    ymin=dimY-z; ymax=dimY;        zmin=0; zmax=1;       }
152         if (bbGetInputTypeOrientation()==2)  { xmin=0; xmax=y;    ymin=dimY-z; ymax=dimY;         zmin=0; zmax=1;       }
153         if (bbGetInputTypeOrientation()==3)  { xmin=x; xmax=dimX; ymin=y;      ymax=dimY;         zmin=z; zmax=dimZ;    }   // xyz
154         printf("EED  ImageCutByAxis::Process x=%d %d      y= %d %d     z=%d %d\n", xmin,xmax , ymin,ymax, zmin,zmax );
155
156         for (k=zmin;k<zmax;k++){
157             for (j=ymin;j<ymax;j++){
158                 for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,k,0,0);} // for i
159             } // for j
160         } // for k
161     }  // c1
162
163     
164     
165     
166         newData->Modified();
167         bbSetOutputOut( newData );
168
169 }
170 //===== 
171 // 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)
172 //===== 
173 void ImageCutByAxis::bbUserSetDefaultValues()
174 {
175
176 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
177 //    Here we initialize the input 'In' to 0
178    bbSetInputIn(NULL);
179    bbSetInputType("x-y-z+");
180    bbSetInputInsideVol(true);
181    std::vector<int> point;
182    point.push_back(0);
183    point.push_back(0);
184    point.push_back(0);
185    bbSetInputPoint(point);
186 }
187 //===== 
188 // 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)
189 //===== 
190 void ImageCutByAxis::bbUserInitializeProcessing()
191 {
192
193 //  THE INITIALIZATION METHOD BODY :
194 //    Here does nothing 
195 //    but this is where you should allocate the internal/output pointers 
196 //    if any 
197
198   
199 }
200 //===== 
201 // 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)
202 //===== 
203 void ImageCutByAxis::bbUserFinalizeProcessing()
204 {
205
206 //  THE FINALIZATION METHOD BODY :
207 //    Here does nothing 
208 //    but this is where you should desallocate the internal/output pointers 
209 //    if any
210   
211 }
212 }
213 // EO namespace bbcreaVtk
214
215