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