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