]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMultipleOperations.cxx
#3414 creaVtk Feature New Normal - openmp
[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)
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                         for (index=0;index<size;index++)
63                         {
64 if ( (k1omp==index) || (k2omp==index) || (k3omp==index) || 
65      (k4omp==index) || (k5omp==index) || (k6omp==index) ) { printf("  %d%\n", (int)(((double)index/(double)(size-1))*100 )); }
66
67                                 DEF_POINTER_IMAGE_VTK_CREA(vIn ,ssIn ,pIn ,stIn ,bbGetInputInLst()[0] )
68                                 int iLst,sizeLst= bbGetInputInLst().size();
69                                 double vInBack,acumDiff;
70                                 acumDiff=0;
71                                 for (iLst=0;iLst<sizeLst;iLst++) // volumes
72                                 {
73                                         pIn=(char*)( bbGetInputInLst()[iLst]->GetScalarPointer() );
74                                         GETVALUE2_VTK_CREA(vIn,pIn,stIn,index)
75                                         if (iLst!=0)
76                                         {
77                                                 acumDiff = acumDiff+abs(vIn-vInBack);
78                                         } 
79                                         vInBack=vIn;
80                                 } // for iLst
81                                 acumDiff = acumDiff/sizeLst;
82                                 SETVALUE2_VTK_CREA(acumDiff,pOut,stOut,index)
83                         } // for index
84                 } // if Type==20
85                 bbSetOutputOut( resultImage );
86         } // if InLst size
87 }
88 //===== 
89 // 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)
90 //===== 
91 void MultipleOperations::bbUserSetDefaultValues()
92 {
93
94 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
95 //    Here we initialize the input 'In' to 0
96   
97    bbSetInputType(0);
98    bbSetOutputOut(NULL);
99
100 }
101 //===== 
102 // 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)
103 //===== 
104 void MultipleOperations::bbUserInitializeProcessing()
105 {
106
107 //  THE INITIALIZATION METHOD BODY :
108 //    Here does nothing 
109 //    but this is where you should allocate the internal/output pointers 
110 //    if any 
111
112   
113 }
114 //===== 
115 // 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)
116 //===== 
117 void MultipleOperations::bbUserFinalizeProcessing()
118 {
119
120 //  THE FINALIZATION METHOD BODY :
121 //    Here does nothing 
122 //    but this is where you should desallocate the internal/output pointers 
123 //    if any
124   
125 }
126 }
127 // EO namespace bbcreaVtk
128
129