]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMagnitudVector.cxx
#3491 vtk9itk5wx3-macos
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkMagnitudVector.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 "bbcreaVtkMagnitudVector.h"
5 #include "bbcreaVtkPackage.h"
6 #include "creaVtk_MACROS.h"
7 #include <math.h>
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MagnitudVector)
13 BBTK_BLACK_BOX_IMPLEMENTATION(MagnitudVector,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 MagnitudVector::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 ( (bbGetInputvX()!=NULL) && (bbGetInputvY()!=NULL) && (bbGetInputvZ()!=NULL) )
36         {
37                 if (imageoutput!=NULL) 
38                 {
39                         imageoutput->Delete();
40                 }       
41                 imageoutput = vtkImageData::New();
42                 imageoutput->Initialize();
43                 imageoutput->SetSpacing( bbGetInputvX()->GetSpacing() );
44                 int dim[3];
45                 int ext[6];
46 //EED 2017-01-01 Migration VTK7
47 #if (VTK_MAJOR_VERSION <= 5) 
48                 bbGetInputvX()->GetWholeExtent(ext );
49 #endif
50 #if (VTK_MAJOR_VERSION >= 6) 
51                 bbGetInputvX()->GetExtent(ext );
52 #endif
53                 dim[0]=ext[1]-ext[0]+1;
54                 dim[1]=ext[3]-ext[2]+1;
55                 dim[2]=ext[5]-ext[4]+1;
56                 imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
57                 imageoutput->SetExtent( ext );
58 //EED 2017-01-01 Migration VTK7
59 #if (VTK_MAJOR_VERSION <= 5) 
60                 imageoutput->SetWholeExtent( ext );
61                 imageoutput->SetScalarType( VTK_DOUBLE );       
62                 imageoutput->AllocateScalars();
63 #endif
64 #if (VTK_MAJOR_VERSION >= 6) 
65                 imageoutput->AllocateScalars( VTK_DOUBLE,1 );
66 #endif
67
68                 DEF_POINTER_IMAGE_VTK_CREA(vvX,ssvX,pvX,stvX,bbGetInputvX() )   
69                 DEF_POINTER_IMAGE_VTK_CREA(vvY,ssvY,pvY,stvY,bbGetInputvY() )   
70                 DEF_POINTER_IMAGE_VTK_CREA(vvZ,ssvZ,pvZ,stvZ,bbGetInputvZ() )   
71                 DEF_POINTER_IMAGE_VTK_CREA(vOut,ssOut,pOut,stOut,imageoutput )  
72                 long int i, size=dim[0]*dim[1]*dim[2];
73
74 long int k1omp=(double)(size-1)*0.0;
75 long int k2omp=(double)(size-1)*0.2;
76 long int k3omp=(double)(size-1)*0.4;
77 long int k4omp=(double)(size-1)*0.6;
78 long int k5omp=(double)(size-1)*0.8;
79 long int k6omp=(double)(size-1)*1.0;
80 printf("EED MagnitudVector::Process (with openmp)\n");
81                 #pragma omp parallel for
82                 for (i=0; i<size; i++)
83                 {
84 if ( (k1omp==i) || (k2omp==i) || (k3omp==i) || 
85      (k4omp==i) || (k5omp==i) || (k6omp==i) ) { printf("  %d%\n", (int)(((double)i/(double)(size-1))*100 )); }
86                         double vvXtmpOMP;
87                         double vvYtmpOMP;
88                         double vvZtmpOMP;
89                         GETVALUE2_VTK_CREA(vvXtmpOMP,pvX,stvX,i) 
90                         GETVALUE2_VTK_CREA(vvYtmpOMP,pvY,stvY,i) 
91                         GETVALUE2_VTK_CREA(vvZtmpOMP,pvZ,stvZ,i) 
92                         if ( (vvXtmpOMP==0) && (vvYtmpOMP==0) &&(vvZtmpOMP==0) ) 
93                         {
94                                 SETVALUE2_VTK_CREA( 0 ,pOut,stOut,i)
95                         } else {
96                                 SETVALUE2_VTK_CREA( sqrt(vvXtmpOMP*vvXtmpOMP + vvYtmpOMP*vvYtmpOMP + vvZtmpOMP*vvZtmpOMP) ,pOut,stOut,i)
97                         } // if vvX  vvY  vvZ  != 0
98
99                 } // for i
100
101         }//  vX vY vZ != NULL
102
103         bbSetOutputOut( imageoutput );
104 }
105 //===== 
106 // 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)
107 //===== 
108 void MagnitudVector::bbUserSetDefaultValues()
109 {
110
111 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
112 //    Here we initialize the input 'In' to 0
113         imageoutput=NULL;
114    bbSetInputvX(NULL);
115    bbSetInputvY(NULL);
116    bbSetInputvZ(NULL);
117   
118 }
119 //===== 
120 // 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)
121 //===== 
122 void MagnitudVector::bbUserInitializeProcessing()
123 {
124
125         imageoutput=NULL;
126 //  THE INITIALIZATION METHOD BODY :
127 //    Here does nothing 
128 //    but this is where you should allocate the internal/output pointers 
129 //    if any 
130
131   
132 }
133 //===== 
134 // 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)
135 //===== 
136 void MagnitudVector::bbUserFinalizeProcessing()
137 {
138
139 //  THE FINALIZATION METHOD BODY :
140 //    Here does nothing 
141 //    but this is where you should desallocate the internal/output pointers 
142 //    if any
143   
144 }
145 }
146 // EO namespace bbcreaVtk
147
148