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