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 "bbcreaVtkApplyMask.h"
5 #include "bbcreaVtkPackage.h"
7 #include "creaVtk_MACROS.h"
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ApplyMask)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ApplyMask,bbtk::AtomicBlackBox);
15 // 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)
17 void ApplyMask::Process()
20 // THE MAIN PROCESSING METHOD BODY
21 // Here we simply set the input 'In' value to the output 'Out'
22 // And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 // void bbSet{Input|Output}NAME(const TYPE&)
25 // const TYPE& bbGet{Input|Output}NAME() const
27 // * NAME is the name of the input/output
28 // (the one provided in the attribute 'name' of the tag 'input')
29 // * TYPE is the C++ type of the input/output
30 // (the one provided in the attribute 'type' of the tag 'input')
32 // bbSetOutputOut( bbGetInputIn() );
33 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
35 if ((bbGetInputImage()!=NULL) && (bbGetInputMask()!=NULL))
39 vtkImageData *resultImage=NULL;
40 bbGetInputImage()->GetExtent( extImage );
41 bbGetInputImage()->GetExtent( extMask );
42 int dimXImage = extImage[1]-extImage[0]+1;
43 int dimYImage = extImage[3]-extImage[2]+1;
44 int dimZImage = extImage[5]-extImage[4]+1;
45 int dimXMask = extMask[1]-extMask[0]+1;
46 int dimYMask = extMask[3]-extMask[2]+1;
47 int dimZMask = extMask[5]-extMask[4]+1;
48 double background = bbGetInputBackground();
49 double bgToAnalice = bbGetInputBackgroundToAnalice();
51 if (bbGetInputType()==0)
53 if (bbGetOutputOut()!=NULL)
55 bbGetOutputOut()->Delete();
58 resultImage = vtkImageData::New();
59 resultImage->Initialize();
60 resultImage->SetSpacing( bbGetInputImage()->GetSpacing() );
61 resultImage->SetDimensions( dimXImage, dimYImage, dimZImage );
62 resultImage->AllocateScalars( bbGetInputImage()->GetScalarType(),1 );
65 if (bbGetInputType()==1)
67 resultImage=bbGetInputImage();
70 if (bbGetInputType()==2)
72 resultImage=bbGetInputImage();
75 if (bbGetInputType()==3)
77 resultImage=bbGetInputImage();
81 if ((dimXImage==dimXMask) &&
82 (dimYImage==dimYMask) &&
83 (dimZImage==dimZMask))
85 long int i, size = dimXImage * dimYImage * dimZImage;
86 DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI, bbGetInputImage() );
87 DEF_POINTER_IMAGE_VTK_CREA(vM,ssM,pM,stM, bbGetInputMask() );
88 DEF_POINTER_IMAGE_VTK_CREA(vO,ssO,pO,stO, resultImage );
89 long int k1omp=(double)(size-1)*0.0;
90 long int k2omp=(double)(size-1)*0.2;
91 long int k3omp=(double)(size-1)*0.4;
92 long int k4omp=(double)(size-1)*0.6;
93 long int k5omp=(double)(size-1)*0.8;
94 long int k6omp=(double)(size-1)*1.0;
95 printf("EED ApplyMask::Process (with openmp)\n");
96 #pragma omp parallel for
99 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) ||
100 (k4omp==i) || (k5omp==i) || (k6omp==i) ) { printf(" %d%\n", (int)(((double)i/(double)(size-1))*100 )); }
104 GETVALUE2_VTK_CREA(vMtmpOMP,pM,stM,i);
105 if (bbGetInputType()==0) //Applay mask to new Image
107 GETVALUE2_VTK_CREA(vItmpOMP,pI,stI,i);
108 if (vMtmpOMP!=bgToAnalice)
112 vOtmpOMP = background;
114 SETVALUE2_VTK_CREA(vOtmpOMP,pO,stO,i);
116 if (bbGetInputType()==1) //Modifiy the Input image with the Label value in Mask place
118 if (vMtmpOMP!=bgToAnalice)
120 vOtmpOMP = bbGetInputLabel();
121 SETVALUE2_VTK_CREA(vOtmpOMP,pO,stO,i);
124 if (bbGetInputType()==2) //Modifiy the Input image with the Mask value
126 if (vMtmpOMP!=bgToAnalice)
129 SETVALUE2_VTK_CREA(vOtmpOMP,pO,stO,i);
134 resultImage->Modified();
135 bbSetOutputOut( resultImage );
136 } // if Image && Mask
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)
141 void ApplyMask::bbUserSetDefaultValues()
144 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
145 // Here we initialize the input 'In' to 0
146 bbSetInputImage(NULL);
147 bbSetInputMask(NULL);
148 bbSetInputBackground(0); // output image Type 0
149 bbSetInputBackgroundToAnalice(0);
150 bbSetInputLabel(255);
152 bbSetOutputOut(NULL);
156 // 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)
158 void ApplyMask::bbUserInitializeProcessing()
161 // THE INITIALIZATION METHOD BODY :
163 // but this is where you should allocate the internal/output pointers
169 // 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)
171 void ApplyMask::bbUserFinalizeProcessing()
174 // THE FINALIZATION METHOD BODY :
176 // but this is where you should desallocate the internal/output pointers
181 // EO namespace bbcreaVtk