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