]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkApplyMask.cxx
#3238 creaVtk Feature New Normal - ApplyMask box
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkApplyMask.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 "bbcreaVtkApplyMask.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "creaVtk_MACROS.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ApplyMask)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ApplyMask,bbtk::AtomicBlackBox);
14 //===== 
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)
16 //===== 
17 void ApplyMask::Process()
18 {
19
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 
26 //    Where :
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')
31
32 //    bbSetOutputOut( bbGetInputIn() );
33 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34
35         if ((bbGetInputImage()!=NULL) && (bbGetInputMask()!=NULL))
36         {
37                 int extImage[6];
38                 bbGetInputImage()->GetExtent( extImage );
39                 int dimXImage = extImage[1]-extImage[0]+1;
40                 int dimYImage = extImage[3]-extImage[2]+1;
41                 int dimZImage = extImage[5]-extImage[4]+1;
42
43                 int extMask[6];
44                 bbGetInputImage()->GetExtent( extMask );
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
49
50                 if (bbGetOutputOut()!=NULL) 
51                 {
52                         bbGetOutputOut()->Delete();
53                 }       
54
55                 vtkImageData *resultImage=NULL;
56                 resultImage = vtkImageData::New();
57                 resultImage->Initialize();
58                 resultImage->SetSpacing( bbGetInputImage()->GetSpacing() );
59                 resultImage->SetDimensions(  dimXImage, dimYImage, dimZImage );
60                 resultImage->AllocateScalars( bbGetInputImage()->GetScalarType(),1 );
61                         
62
63                 if ((dimXImage==dimXMask) &&
64                         (dimYImage==dimYMask) &&
65                         (dimZImage==dimZMask)) 
66                         {
67
68
69                                 long int i, size = dimXImage * dimYImage * dimZImage;
70                                 #pragma omp parallel for 
71                                 for (i=0; i<size;i++)
72                                 {
73
74                                         DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI, bbGetInputImage() );
75                                         DEF_POINTER_IMAGE_VTK_CREA(vM,ssM,pM,stM, bbGetInputMask() );
76                                         DEF_POINTER_IMAGE_VTK_CREA(vO,ssO,pO,stO, resultImage );
77
78                                         GETVALUE2_VTK_CREA(vI,pI,stI,i);
79                                         GETVALUE2_VTK_CREA(vM,pM,stM,i);
80                                         if (vM!=0)
81                                         {
82                                                 vO = vI;
83                                         } else {
84                                                 vO = bbGetInputBackground(); 
85                                         }
86                                         SETVALUE2_VTK_CREA(vO,pO,stO,i);        
87                                 } // for
88                 } //if dim
89         bbSetOutputOut( resultImage );
90         } // if Image && Mask   
91
92 }
93 //===== 
94 // 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)
95 //===== 
96 void ApplyMask::bbUserSetDefaultValues()
97 {
98
99 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
100 //    Here we initialize the input 'In' to 0
101    bbSetInputImage(NULL);
102    bbSetInputMask(NULL);
103    bbSetInputBackground(0);
104    bbSetOutputOut(NULL);
105   
106 }
107 //===== 
108 // 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)
109 //===== 
110 void ApplyMask::bbUserInitializeProcessing()
111 {
112
113 //  THE INITIALIZATION METHOD BODY :
114 //    Here does nothing 
115 //    but this is where you should allocate the internal/output pointers 
116 //    if any 
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 ApplyMask::bbUserFinalizeProcessing()
124 {
125
126 //  THE FINALIZATION METHOD BODY :
127 //    Here does nothing 
128 //    but this is where you should desallocate the internal/output pointers 
129 //    if any
130   
131 }
132 }
133 // EO namespace bbcreaVtk
134
135