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