]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMagnitudVector.cxx
#3261 creaVtk Feature New Normal - box MagnitudVector
[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 namespace bbcreaVtk
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MagnitudVector)
11 BBTK_BLACK_BOX_IMPLEMENTATION(MagnitudVector,bbtk::AtomicBlackBox);
12 //===== 
13 // 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)
14 //===== 
15 void MagnitudVector::Process()
16 {
17
18 // THE MAIN PROCESSING METHOD BODY
19 //   Here we simply set the input 'In' value to the output 'Out'
20 //   And print out the output value
21 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
22 //    void bbSet{Input|Output}NAME(const TYPE&)
23 //    const TYPE& bbGet{Input|Output}NAME() const 
24 //    Where :
25 //    * NAME is the name of the input/output
26 //      (the one provided in the attribute 'name' of the tag 'input')
27 //    * TYPE is the C++ type of the input/output
28 //      (the one provided in the attribute 'type' of the tag 'input')
29
30 //    bbSetOutputOut( bbGetInputIn() );
31 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
32
33         if ( (bbGetInputvX()!=NULL) && (bbGetInputvY()!=NULL) && (bbGetInputvZ()!=NULL) )
34         {
35                 if (imageoutput!=NULL) 
36                 {
37                         imageoutput->Delete();
38                 }       
39                 imageoutput = vtkImageData::New();
40                 imageoutput->Initialize();
41                 imageoutput->SetSpacing( bbGetInputvX()->GetSpacing() );
42                 int dim[3];
43                 int ext[6];
44 //EED 2017-01-01 Migration VTK7
45 #if (VTK_MAJOR_VERSION <= 5) 
46                 bbGetInputvX()->GetWholeExtent(ext );
47 #endif
48 #if (VTK_MAJOR_VERSION >= 6) 
49                 bbGetInputvX()->GetExtent(ext );
50 #endif
51                 dim[0]=ext[1]-ext[0]+1;
52                 dim[1]=ext[3]-ext[2]+1;
53                 dim[2]=ext[5]-ext[4]+1;
54                 imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
55                 imageoutput->SetExtent( ext );
56 //EED 2017-01-01 Migration VTK7
57 #if (VTK_MAJOR_VERSION <= 5) 
58                 imageoutput->SetWholeExtent( ext );
59                 imageoutput->SetScalarType( VTK_DOUBLE );       
60                 imageoutput->AllocateScalars();
61 #endif
62 #if (VTK_MAJOR_VERSION >= 6) 
63                 imageoutput->AllocateScalars( VTK_DOUBLE,1 );
64 #endif
65
66                 DEF_POINTER_IMAGE_VTK_CREA(vvX,ssvX,pvX,stvX,bbGetInputvX() )   
67                 DEF_POINTER_IMAGE_VTK_CREA(vvY,ssvY,pvY,stvY,bbGetInputvY() )   
68                 DEF_POINTER_IMAGE_VTK_CREA(vvZ,ssvZ,pvZ,stvZ,bbGetInputvZ() )   
69                 DEF_POINTER_IMAGE_VTK_CREA(vOut,ssOut,pOut,stOut,imageoutput )  
70                 long int i, size=dim[0]*dim[1]*dim[2];
71 #pragma omp parallel for
72                 for (i=0; i<size; i++)
73                 {
74                         GETVALUE2_VTK_CREA(vvX,pvX,stvX,i) 
75                         GETVALUE2_VTK_CREA(vvY,pvY,stvY,i) 
76                         GETVALUE2_VTK_CREA(vvZ,pvZ,stvZ,i) 
77                         if ( (vvX==0) && (vvY==0) &&(vvZ==0) ) 
78                         {
79                                 SETVALUE2_VTK_CREA( 0 ,pOut,stOut,i)
80                         } else {
81                                 SETVALUE2_VTK_CREA( sqrt(vvX*vvX + vvY*vvY + vvZ*vvZ),pOut,stOut,i)
82                         } // if vvX  vvY  vvZ  != 0
83
84                 } // for i
85
86         }//  vX vY vZ != NULL
87
88         bbSetOutputOut( imageoutput );
89 }
90 //===== 
91 // 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)
92 //===== 
93 void MagnitudVector::bbUserSetDefaultValues()
94 {
95
96 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
97 //    Here we initialize the input 'In' to 0
98         imageoutput=NULL;
99    bbSetInputvX(NULL);
100    bbSetInputvY(NULL);
101    bbSetInputvZ(NULL);
102   
103 }
104 //===== 
105 // 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)
106 //===== 
107 void MagnitudVector::bbUserInitializeProcessing()
108 {
109
110         imageoutput=NULL;
111 //  THE INITIALIZATION METHOD BODY :
112 //    Here does nothing 
113 //    but this is where you should allocate the internal/output pointers 
114 //    if any 
115
116   
117 }
118 //===== 
119 // 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)
120 //===== 
121 void MagnitudVector::bbUserFinalizeProcessing()
122 {
123
124 //  THE FINALIZATION METHOD BODY :
125 //    Here does nothing 
126 //    but this is where you should desallocate the internal/output pointers 
127 //    if any
128   
129 }
130 }
131 // EO namespace bbcreaVtk
132
133