]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMultipleOperations.cxx
#3497 MultipleOperations box average option in creaVtk
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkMultipleOperations.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 "bbcreaVtkMultipleOperations.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,MultipleOperations)
13 BBTK_BLACK_BOX_IMPLEMENTATION(MultipleOperations,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 MultipleOperations::Process()
18 {
19 // THE MAIN PROCESSING METHOD BODY
20 //   Here we simply set the input 'In' value to the output 'Out'
21 //   And print out the output value
22 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
23 //    void bbSet{Input|Output}NAME(const TYPE&)
24 //    const TYPE& bbGet{Input|Output}NAME() const 
25 //    Where :
26 //    * NAME is the name of the input/output
27 //      (the one provided in the attribute 'name' of the tag 'input')
28 //    * TYPE is the C++ type of the input/output
29 //      (the one provided in the attribute 'type' of the tag 'input')
30
31         if ( bbGetInputInLst().size()>0 )
32         {
33                 int                     extImage[6];
34                 vtkImageData    *resultImage=NULL;
35                 bbGetInputInLst()[0]->GetExtent( extImage );
36                 int dimXImage   = extImage[1]-extImage[0]+1;
37                 int dimYImage   = extImage[3]-extImage[2]+1;
38                 int dimZImage   = extImage[5]-extImage[4]+1;
39                 if (bbGetOutputOut()!=NULL) 
40                 {
41                         bbGetOutputOut()->Delete();
42                 }       
43                 resultImage = vtkImageData::New();
44                 resultImage->Initialize();
45                 resultImage->SetSpacing( bbGetInputInLst()[0]->GetSpacing() );
46                 resultImage->SetDimensions(  dimXImage, dimYImage, dimZImage );
47                 resultImage->AllocateScalars( bbGetInputInLst()[0]->GetScalarType(),1 );
48                 long int index,size=dimXImage*dimYImage*dimZImage;
49                 DEF_POINTER_IMAGE_VTK_CREA(vOut,ssOut,pOut,stOut,resultImage )
50                 if ((bbGetInputType()==20) ||  (bbGetInputType()==21) )
51                 {
52
53 long int k1omp=(double)(size-1)*0.0;
54 long int k2omp=(double)(size-1)*0.2;
55 long int k3omp=(double)(size-1)*0.4;
56 long int k4omp=(double)(size-1)*0.6;
57 long int k5omp=(double)(size-1)*0.8;
58 long int k6omp=(double)(size-1)*1.0;
59
60 printf("EED MultipleOperations::Process (with openmp)\n");
61 #pragma omp parallel for
62
63             for (index=0;index<size;index++)
64                         {
65 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) || 
66      (k4omp==index) || (k5omp==index) || (k6omp==index) ) { printf("  %d%\n", (int)(((double)index/(double)(size-1))*100 )); }
67
68                                 DEF_POINTER_IMAGE_VTK_CREA(vIn ,ssIn ,pIn ,stIn ,bbGetInputInLst()[0] )
69                 
70                 int iLst,sizeLst= bbGetInputInLst().size();
71                 double vInBack  ;
72                 double acumDiff ;
73                 vInBack  = 0;
74                 acumDiff = 0;
75                                 for ( iLst=0 ; iLst < sizeLst ; iLst++ ) // volumes
76                                 {
77                                         pIn=(char*)( bbGetInputInLst()[iLst]->GetScalarPointer() );
78                                         GETVALUE2_VTK_CREA(vIn,pIn,stIn,index)
79                                         if (iLst!=0)
80                                         {
81                         if (bbGetInputType()==20)
82                         {
83                             acumDiff = acumDiff+abs(vIn-vInBack);
84                             vInBack=vIn;
85                         } // if 20
86                         if (bbGetInputType()==21)
87                         {
88                             acumDiff = acumDiff+vIn;
89                         } // if 20
90                                         }
91                                 } // for iLst
92                                 acumDiff = acumDiff/sizeLst;
93                                 SETVALUE2_VTK_CREA(acumDiff,pOut,stOut,index)
94                         } // for index
95                 } // if Type==20
96                 bbSetOutputOut( resultImage );
97         } // if InLst size
98 }
99 //===== 
100 // 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)
101 //===== 
102 void MultipleOperations::bbUserSetDefaultValues()
103 {
104
105 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
106 //    Here we initialize the input 'In' to 0
107   
108    bbSetInputType(0);
109    bbSetOutputOut(NULL);
110
111 }
112 //===== 
113 // 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)
114 //===== 
115 void MultipleOperations::bbUserInitializeProcessing()
116 {
117
118 //  THE INITIALIZATION METHOD BODY :
119 //    Here does nothing 
120 //    but this is where you should allocate the internal/output pointers 
121 //    if any 
122
123   
124 }
125 //===== 
126 // 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)
127 //===== 
128 void MultipleOperations::bbUserFinalizeProcessing()
129 {
130
131 //  THE FINALIZATION METHOD BODY :
132 //    Here does nothing 
133 //    but this is where you should desallocate the internal/output pointers 
134 //    if any
135   
136 }
137 }
138 // EO namespace bbcreaVtk
139
140