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)
4 #include "bbvtkInversCrop.h"
5 #include "bbvtkPackage.h"
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,InversCrop)
10 BBTK_BLACK_BOX_IMPLEMENTATION(InversCrop,bbtk::AtomicBlackBox);
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)
14 void InversCrop::Process()
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
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')
29 if (bbGetInputActive()==true)
31 if ( (bbGetInputImageFix()!=NULL) && (bbGetInputImageMove()!=NULL) )
33 if ( bbGetInputImageFix()->GetScalarType()==bbGetInputImageMove()->GetScalarType() )
39 //EED 2017-01-01 Migration VTK7
40 #if (VTK_MAJOR_VERSION <= 5)
41 bbGetInputImageFix()->GetWholeExtent(ext);
43 #if (VTK_MAJOR_VERSION >= 6)
44 bbGetInputImageFix()->GetExtent(ext);
46 dim[0]= ext[1]-ext[0]+1;
47 dim[1]= ext[3]-ext[2]+1;
48 dim[2]= ext[5]-ext[4]+1;
50 if (bbGetInputType()==0)
52 _imageoutput = vtkImageData::New();
53 _imageoutput->Initialize();
54 _imageoutput->SetSpacing( bbGetInputImageFix()->GetSpacing() );
55 _imageoutput->SetDimensions( dim[0], dim[1], dim[2] );
56 //EED 2017-01-01 Migration VTK7
57 #if (VTK_MAJOR_VERSION <= 5)
58 _imageoutput->SetScalarType( bbGetInputImageFix()->GetScalarType() );
59 _imageoutput->AllocateScalars();
61 #if (VTK_MAJOR_VERSION >= 6)
62 _imageoutput->AllocateScalars(bbGetInputImageFix()->GetScalarType() , 1);
65 // Duplicating Fix Image
66 long sizeimage = dim[0]*dim[1]*dim[2]*bbGetInputImageFix()->GetScalarSize();
67 memcpy( _imageoutput->GetScalarPointer() , bbGetInputImageFix()->GetScalarPointer() , sizeimage);
69 if (bbGetInputType()==1)
71 _imageoutput=bbGetInputImageFix();
74 // Copy the Move Image
78 //EED 2017-01-01 Migration VTK7
79 #if (VTK_MAJOR_VERSION <= 5)
80 bbGetInputImageMove()->GetWholeExtent(ext);
82 #if (VTK_MAJOR_VERSION >= 6)
83 bbGetInputImageMove()->GetExtent(ext);
85 int dimMoveX = ext[1]-ext[0]+1;
86 int dimMoveY = ext[3]-ext[2]+1;
87 int dimMoveZ = ext[5]-ext[4]+1;
88 int spxM = 0; // start px MoveImage
89 int sizeXM = 0; // sizeX MoveImage
90 px = bbGetInputOrigin()[0];
97 sizeXM = dimMoveX-spxM;
98 if (px+sizeXM>=dim[0]) sizeXM=dim[0]-px;
99 sizeXM = sizeXM * bbGetInputImageFix()->GetScalarSize();
100 for (k=0; k<dimMoveZ; k++)
102 for (j=0; j<dimMoveY; j++)
104 py = j+bbGetInputOrigin()[1];
105 pz = k+bbGetInputOrigin()[2];
106 if ( (py<dim[1]) && (pz<dim[2]) &&
107 (py>=0) && (pz>=0) &&
110 memcpy( _imageoutput->GetScalarPointer(px,py,pz) , bbGetInputImageMove()->GetScalarPointer(spxM,j,k) , sizeXM );
115 _imageoutput->Modified();
116 } else { // If Image Fixe Move the same GetScalarType
117 printf ("ERROR: InversCrop both ImageFixe and ImageMove need the same format.\n");
118 printf (" type ImageFix:%d type ImageMove:%d\n", bbGetInputImageFix()->GetScalarType(), bbGetInputImageMove()->GetScalarType() );
121 } else { // If Image Fixe Move != NULL
122 printf ("ERROR: InversCrop need ImageFixe and ImageMove to run.\n");
124 bbSetOutputOut(_imageoutput);
131 // 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)
133 void InversCrop::bbUserSetDefaultValues()
135 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
136 // Here we initialize the input 'In' to 0
137 bbSetInputActive(true);
139 bbSetInputImageFix(NULL);
140 bbSetInputImageMove(NULL);
141 std::vector<int> origin;
145 bbSetInputOrigin(origin);
149 // 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)
151 void InversCrop::bbUserInitializeProcessing()
154 // THE INITIALIZATION METHOD BODY :
156 // but this is where you should allocate the internal/output pointers
162 // 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)
164 void InversCrop::bbUserFinalizeProcessing()
167 // THE FINALIZATION METHOD BODY :
169 // but this is where you should desallocate the internal/output pointers
174 // EO namespace bbvtk