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