]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx
#3304 creaVtk Bug New Normal - GrayLevel box
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkGrayLevel.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 "bbcreaVtkGrayLevel.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,GrayLevel)
10 BBTK_BLACK_BOX_IMPLEMENTATION(GrayLevel,bbtk::AtomicBlackBox);
11 //===== 
12 // 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)
13 //===== 
14 void GrayLevel::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29 //    vtkImageData  *m_image  =  vtkImageData::New();
30 //    m_image = bbGetInputImage();
31
32     double grayLevel                    = -9999;
33     std::vector<double> coord   = bbGetInputCoordinate();
34         double px,py,pz;
35         if (bbGetInputImage()!=NULL)
36         {
37                 double spc[3];
38                 bbGetInputImage()->GetSpacing(spc);
39                 if (coord.size()>=2)
40                 { 
41                         if (bbGetInputWithSpacing()==true)
42                         {
43                                 px = round(coord[0]/spc[0]);
44                                 py = round(coord[1]/spc[1]);
45                                 pz = round(coord[2]/spc[2]);
46                         } else {
47                                 px = round(coord[0]);
48                                 py = round(coord[1]);
49                                 pz = round(coord[2]);
50                         }// if
51                         grayLevel = bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0);
52                 } // coord
53                 std::vector<double> lstGL;
54                 std::vector<double> lstX = bbGetInputLstPointsX();
55                 std::vector<double> lstY = bbGetInputLstPointsY();
56                 std::vector<double> lstZ = bbGetInputLstPointsZ();
57                 if ( (lstX.size()==lstY.size()) && (lstY.size()==lstZ.size()) )
58                 {
59                         long int i,size=lstX.size();
60                         for (i=0;i<size;i++)
61                         {       
62                                 if (bbGetInputWithSpacing()==true)
63                                 {
64                                         px = round(lstX[i]/spc[0]);
65                                         py = round(lstY[i]/spc[1]);
66                                         pz = round(lstZ[i]/spc[2]);
67                                 } else {
68                                         px = round(lstX[i]);
69                                         py = round(lstY[i]);
70                                         pz = round(lstZ[i]);                                    
71                                 }// if
72                                 lstGL.push_back( bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0) );
73                         }// for 
74                         bbSetOutputLstGrayLevel(lstGL);
75                 } // if size of Lst
76         } // InputImage
77         bbSetOutputGrayLevel(grayLevel);
78 }
79
80 //===== 
81 // 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)
82 //===== 
83 void GrayLevel::bbUserSetDefaultValues()
84 {
85 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
86 //    Here we initialize the input 'In' to 0
87    bbSetInputImage(NULL);
88    bbSetInputWithSpacing(false);
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 GrayLevel::bbUserInitializeProcessing()
94 {
95
96 //  THE INITIALIZATION METHOD BODY :
97 //    Here does nothing 
98 //    but this is where you should allocate the internal/output pointers 
99 //    if any 
100
101   
102 }
103 //===== 
104 // 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)
105 //===== 
106 void GrayLevel::bbUserFinalizeProcessing()
107 {
108
109 //  THE FINALIZATION METHOD BODY :
110 //    Here does nothing 
111 //    but this is where you should desallocate the internal/output pointers 
112 //    if any
113   
114 }
115 }
116 // EO namespace bbcreaVtk
117
118