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