]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageCutByAxis.cxx
Bug Modified pipeline
[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;
54         bool c1=false;
55         bool c2=false;
56         bool c3=false;
57         bool c4=false;
58
59         if ( bbGetInputType()=="x-y-z+" ) 
60         {
61                 if (bbGetInputTypeOrientation()==0)  { c1=false;        c2=true;        c3=true;        c4=true;        }
62                 if (bbGetInputTypeOrientation()==1)  { c1=true;         c2=false;       c3=true;        c4=true;        }
63                 if (bbGetInputTypeOrientation()==2)  { c1=true;         c2=false;       c3=true;        c4=true;        }
64         }
65
66         if (bbGetInputInsideVol()==true)
67         {
68                 c1=!c1;
69                 c2=!c2;
70                 c3=!c3;
71                 c4=!c4;
72         } // IndideVol
73
74
75         int xmin,xmax,ymin,ymax;
76
77 //      void *imgPtr;
78 //              imgPtr=bbGetInputIn()->GetScalarPointer(x,y,z,0);
79 //              memset( bbGetInputIn()->GetScalarPointer() );
80         
81         if (c1==true)
82         {
83                 if (bbGetInputTypeOrientation()==0)  { xmin=0; xmax=x; ymin=0; ymax=y;                          }
84                 if (bbGetInputTypeOrientation()==1)  { xmin=0; xmax=x; ymin=dimY-z; ymax=dimY;          }
85                 if (bbGetInputTypeOrientation()==2)  { xmin=0; xmax=y; ymin=dimY-z; ymax=dimY;          }
86                 for (j=ymin;j<ymax;j++){
87                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
88                 } // for j
89         }  // c1
90
91         if (c2==true)
92         { 
93                 if (bbGetInputTypeOrientation()==0)  { xmin=0; xmax=x; ymin=y; ymax=dimY;                       }
94                 if (bbGetInputTypeOrientation()==1)  { xmin=0; xmax=x; ymin=0; ymax=dimY-z;                     }
95                 if (bbGetInputTypeOrientation()==2)  { xmin=0; xmax=y; ymin=0; ymax=dimY-z;             }
96                 for (j=ymin;j<ymax;j++){
97                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
98                 } // for j
99         } //c2
100
101         if (c3==true)  
102         { 
103                 if (bbGetInputTypeOrientation()==0)  { xmin=x; xmax=dimX; ymin=0; ymax=y;                       }
104                 if (bbGetInputTypeOrientation()==1)  { xmin=x; xmax=dimX; ymin=dimY-z; ymax=dimY;       }
105                 if (bbGetInputTypeOrientation()==2)  { xmin=y; xmax=dimX; ymin=dimY-z; ymax=dimY;       }
106                 for (j=ymin;j<ymax;j++){
107                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
108                 } // for j
109         } //c3
110
111         if (c4==true)  
112         {  
113                 if (bbGetInputTypeOrientation()==0)  { xmin=x; xmax=dimX; ymin=y; ymax=dimY;            }
114                 if (bbGetInputTypeOrientation()==1)  { xmin=x; xmax=dimX; ymin=0; ymax=dimY-z;          }
115                 if (bbGetInputTypeOrientation()==2)  { xmin=y; xmax=dimX; ymin=0; ymax=dimY-z;          }
116                 for (j=ymin;j<ymax;j++){
117                         for (i=xmin;i<xmax;i++){newData->SetScalarComponentFromDouble(i,j,0,0,0);} // for i
118                 } // for j
119
120         } //c4
121         newData->Modified();
122         bbSetOutputOut( newData );
123
124 }
125 //===== 
126 // 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)
127 //===== 
128 void ImageCutByAxis::bbUserSetDefaultValues()
129 {
130
131 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
132 //    Here we initialize the input 'In' to 0
133    bbSetInputIn(NULL);
134    bbSetInputType("x-y-z+");
135    bbSetInputInsideVol(true);
136    std::vector<int> point;
137    point.push_back(0);
138    point.push_back(0);
139    point.push_back(0);
140    bbSetInputPoint(point);
141 }
142 //===== 
143 // 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)
144 //===== 
145 void ImageCutByAxis::bbUserInitializeProcessing()
146 {
147
148 //  THE INITIALIZATION METHOD BODY :
149 //    Here does nothing 
150 //    but this is where you should allocate the internal/output pointers 
151 //    if any 
152
153   
154 }
155 //===== 
156 // 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)
157 //===== 
158 void ImageCutByAxis::bbUserFinalizeProcessing()
159 {
160
161 //  THE FINALIZATION METHOD BODY :
162 //    Here does nothing 
163 //    but this is where you should desallocate the internal/output pointers 
164 //    if any
165   
166 }
167 }
168 // EO namespace bbcreaVtk
169
170