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