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