]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkGrayLevel.cxx
11e6c3a76d438e34ea18262c3713cab495d19313
[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 printf ("EED GrayLevel::Process Start\n");
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 //    vtkImageData  *m_image  =  vtkImageData::New();
32 //    m_image = bbGetInputImage();
33
34     double grayLevel                    = -9999;
35     std::vector<double> coord   = bbGetInputCoordinate();
36
37         int ext[6];
38         int maxX,maxY,maxZ;
39
40         double px,py,pz;
41         if (bbGetInputImage()!=NULL)
42         {
43                 double spc[3];
44                 bbGetInputImage()->GetSpacing(spc);
45                 bbGetInputImage()->GetExtent(ext);
46                 maxX = ext[1]-ext[0]+1;
47                 maxY = ext[3]-ext[2]+1;
48                 maxZ = ext[5]-ext[4]+1;
49
50                 if (coord.size()==3)
51                 { 
52                         if (bbGetInputWithSpacing()==true)
53                         {
54                                 px = coord[0]/spc[0];
55                                 py = coord[1]/spc[1];
56                                 pz = coord[2]/spc[2];
57                         } else {
58                                 px = coord[0];
59                                 py = coord[1];
60                                 pz = coord[2];
61                         }// if
62
63                         px=round(px);
64                         py=round(py);
65                         pz=round(pz);           
66                         if ( (px>=0) && (px<maxX) && (py>=0) && (py<maxY) &&(pz>=0) && (pz<maxZ)  )
67                         {
68                                 grayLevel = bbGetInputImage()->GetScalarComponentAsDouble( px,py,pz,0);
69                         } else {
70                                 grayLevel = -9991;
71                         } // if px py pz
72
73
74                 } // coord
75                 std::vector<double> lstGL;
76                 std::vector<double> lstX = bbGetInputLstPointsX();
77                 std::vector<double> lstY = bbGetInputLstPointsY();
78                 std::vector<double> lstZ = bbGetInputLstPointsZ();
79                 if ( (lstX.size()==lstY.size()) && (lstY.size()==lstZ.size()) )
80                 {
81                         long int i,size=lstX.size();
82                         for (i=0;i<size;i++)
83                         {       
84                                 if (bbGetInputWithSpacing()==true)
85                                 {
86                                         px = lstX[i]/spc[0];
87                                         py = lstY[i]/spc[1];
88                                         pz = lstZ[i]/spc[2];
89                                 } else {
90                                         px = lstX[i];
91                                         py = lstY[i];
92                                         pz = lstZ[i];                                   
93                                 }// if
94
95                                 px = round(px);
96                                 py = round(py);
97                                 pz = round(pz);
98                                 if ( (px>=0) && (px<maxX) && (py>=0) && (py<maxY) &&(pz>=0) && (pz<maxZ)  )
99                                 {
100                                         lstGL.push_back( bbGetInputImage()->GetScalarComponentAsDouble( px, py,pz,0) );
101                                 } else {
102                                         lstGL.push_back( -9991 );
103                                 }
104
105                         }// for 
106                         bbSetOutputLstGrayLevel(lstGL);
107                 } // if size of Lst
108         } // InputImage
109         bbSetOutputGrayLevel(grayLevel);
110
111 printf ("EED GrayLevel::Process End\n");
112
113 }
114
115 //===== 
116 // 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)
117 //===== 
118 void GrayLevel::bbUserSetDefaultValues()
119 {
120 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
121 //    Here we initialize the input 'In' to 0
122    bbSetInputImage(NULL);
123    bbSetInputWithSpacing(false);
124 }
125 //===== 
126 // 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)
127 //===== 
128 void GrayLevel::bbUserInitializeProcessing()
129 {
130
131 //  THE INITIALIZATION METHOD BODY :
132 //    Here does nothing 
133 //    but this is where you should allocate the internal/output pointers 
134 //    if any 
135
136   
137 }
138 //===== 
139 // 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)
140 //===== 
141 void GrayLevel::bbUserFinalizeProcessing()
142 {
143
144 //  THE FINALIZATION METHOD BODY :
145 //    Here does nothing 
146 //    but this is where you should desallocate the internal/output pointers 
147 //    if any
148   
149 }
150 }
151 // EO namespace bbcreaVtk
152
153