]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkInversCrop.cxx
#3467 Bug: InvertCrop Dimension of 2D or 3D
[bbtk.git] / packages / vtk / src / bbvtkInversCrop.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 "bbvtkInversCrop.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,InversCrop)
10 BBTK_BLACK_BOX_IMPLEMENTATION(InversCrop,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 InversCrop::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 printf("\n\n EED InversCrop::Process Start \n" );
30
31         if (bbGetInputActive()==true)
32         {
33             if ( (bbGetInputImageFix()!=NULL) && (bbGetInputImageMove()!=NULL) )
34             {
35              if ( bbGetInputImageFix()->GetScalarType()==bbGetInputImageMove()->GetScalarType() ) 
36              {
37                 // Creating Image
38                 int dim[3];
39                 int ext[6];
40         
41 //EED 2017-01-01 Migration VTK7
42 #if (VTK_MAJOR_VERSION <= 5) 
43         bbGetInputImageFix()->GetWholeExtent(ext);
44 #endif
45 #if (VTK_MAJOR_VERSION >= 6) 
46         bbGetInputImageFix()->GetExtent(ext);
47 #endif
48                 dim[0]= ext[1]-ext[0]+1;
49                 dim[1]= ext[3]-ext[2]+1;
50                 dim[2] = 1;
51                 if (bbGetInputImageFix()->GetDataDimension()==3) 
52                 {
53                         dim[2] = ext[5]-ext[4]+1;
54                 } 
55                 
56 printf("EED InversCrop::Process 1   %d\n", bbGetInputImageFix()->GetDataDimension()    );
57 printf("EED InversCrop::Process 2   %d %d  %d \n",dim[0],dim[1],dim[2]  );
58
59                 if (bbGetInputType()==0)
60                 {
61                         _imageoutput = vtkImageData::New();
62                         _imageoutput->Initialize();
63                         _imageoutput->SetSpacing( bbGetInputImageFix()->GetSpacing() );
64                         _imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );                 
65 //EED 2017-01-01 Migration VTK7
66 #if (VTK_MAJOR_VERSION <= 5) 
67                         _imageoutput->SetScalarType( bbGetInputImageFix()->GetScalarType() );
68                         _imageoutput->AllocateScalars();
69 #endif
70 #if (VTK_MAJOR_VERSION >= 6) 
71                         _imageoutput->AllocateScalars(bbGetInputImageFix()->GetScalarType() , 1);
72 #endif
73                         
74                         // Duplicating Fix Image
75                         long sizeimage = dim[0]*dim[1]*dim[2]*bbGetInputImageFix()->GetScalarSize();    
76                         memcpy( _imageoutput->GetScalarPointer() , bbGetInputImageFix()->GetScalarPointer() , sizeimage);
77                 }
78                 if (bbGetInputType()==1)
79                 {
80                         _imageoutput=bbGetInputImageFix();
81                 }
82
83                 // Copy the Move Image
84                 int j,k; 
85                 int px,py,pz;
86
87 //EED 2017-01-01 Migration VTK7
88 #if (VTK_MAJOR_VERSION <= 5) 
89                 bbGetInputImageMove()->GetWholeExtent(ext);
90 #endif
91 #if (VTK_MAJOR_VERSION >= 6) 
92                 bbGetInputImageMove()->GetExtent(ext);
93 #endif
94                 int dimMoveX    = ext[1]-ext[0]+1;
95                 int dimMoveY    = ext[3]-ext[2]+1;
96                 int dimMoveZ    = 1;
97                 if (bbGetInputImageMove()->GetDataDimension()==3) 
98                 {
99                         dimMoveZ = ext[5]-ext[4]+1;
100                 } 
101 printf("EED InversCrop::Process 3   %d %d  %d \n",dimMoveX,dimMoveY,dimMoveZ  );
102
103
104                 double org[3];
105                 org[0]=0;
106                 org[1]=0;
107                 org[2]=0;
108                 
109                 if (bbGetInputOrigin().size()==3)
110                 {
111                         org[0]=bbGetInputOrigin()[0];
112                         org[1]=bbGetInputOrigin()[1];
113                         org[2]=bbGetInputOrigin()[2];
114                 }
115                 
116                 if (bbGetInputOrigin().size()==2)
117                 {
118                         org[0]=bbGetInputOrigin()[0];
119                         org[1]=bbGetInputOrigin()[1];
120                 }
121
122                 if (bbGetInputOrigin().size()==1)
123                 {
124                         org[0]=bbGetInputOrigin()[0];
125                 }
126
127                 
128                 int spxM                = 0;  // start px MoveImage
129                 int sizeXM              = 0;  // sizeX MoveImage
130 printf("EED InversCrop::Process 3.1   sizeOrigin %d \n", bbGetInputOrigin().size() );
131 printf("EED InversCrop::Process 3.1   Origin %f  %f %f\n", org[0],org[1],org[2] );
132
133                 px                              = org[0];
134                 spxM                    = 0;
135                 if (px<0)
136                 { 
137                    spxM = px*(-1);
138                    px   = 0;
139                 }
140                 sizeXM  = dimMoveX-spxM;
141                 if (px+sizeXM>=dim[0]) { sizeXM=dim[0]-px; }
142                 sizeXM  = sizeXM * bbGetInputImageFix()->GetScalarSize();
143 printf("4. \n");
144                 for (k=0; k<dimMoveZ; k++)
145                 {
146                    for (j=0; j<dimMoveY; j++)
147                    {
148                         py = j+org[1];
149                                 if (bbGetInputImageMove()->GetDataDimension()==3) 
150                                 {
151                                         pz = k+org[2];
152                                 } else {
153                                         pz = k;
154                                 }// Dimension 3
155                                 if ( (py<dim[1]) && (pz<dim[2]) &&
156                                  (py>=0)    && (pz>=0)  &&
157                                          (sizeXM>0) ) 
158                                 {
159 printf("5. \n");
160
161                                         memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM );
162 printf("6. \n");
163
164                                 }
165
166                    } // for j
167                 } // for k
168 printf("EED InversCrop::Process 7   %d %d  %d \n",px,py,pz  );
169
170                 _imageoutput->Modified();
171         } else { // If Image Fixe Move the same GetScalarType
172                    printf ("ERROR: InversCrop  both ImageFixe and ImageMove need the same format.\n");
173                    printf ("       type ImageFix:%d   type ImageMove:%d\n", bbGetInputImageFix()->GetScalarType(), bbGetInputImageMove()->GetScalarType() );
174
175               }  
176             } else { // If Image Fixe Move != NULL
177                         printf ("ERROR: InversCrop  need ImageFixe and ImageMove to run.\n");
178            } 
179          bbSetOutputOut(_imageoutput);
180
181         } // if Active
182 printf("EED InversCrop::Process End \n" );
183
184 }
185
186 //===== 
187 // 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)
188 //===== 
189 void InversCrop::bbUserSetDefaultValues()
190 {
191 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
192 //    Here we initialize the input 'In' to 0
193    bbSetInputActive(true);
194    bbSetInputType(0);
195    bbSetInputImageFix(NULL);
196    bbSetInputImageMove(NULL);
197    std::vector<int> origin;
198    origin.push_back(0);
199    origin.push_back(0);
200    origin.push_back(0);
201    bbSetInputOrigin(origin);
202    _imageoutput=NULL;
203 }
204 //===== 
205 // 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)
206 //===== 
207 void InversCrop::bbUserInitializeProcessing()
208 {
209
210 //  THE INITIALIZATION METHOD BODY :
211 //    Here does nothing 
212 //    but this is where you should allocate the internal/output pointers 
213 //    if any 
214
215   
216 }
217 //===== 
218 // 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)
219 //===== 
220 void InversCrop::bbUserFinalizeProcessing()
221 {
222
223 //  THE FINALIZATION METHOD BODY :
224 //    Here does nothing 
225 //    but this is where you should desallocate the internal/output pointers 
226 //    if any
227   
228 }
229 }
230 // EO namespace bbvtk
231
232