]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageToLstPoints.cxx
#3479 LaplacianFilter box and ImageToPoints box
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkImageToLstPoints.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 "bbcreaVtkImageToLstPoints.h"
5 #include "bbcreaVtkPackage.h"
6 namespace bbcreaVtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageToLstPoints)
10 BBTK_BLACK_BOX_IMPLEMENTATION(ImageToLstPoints,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 ImageToLstPoints::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     std::vector<int> lstX;
30     std::vector<int> lstY;
31     std::vector<int> lstZ;
32     std::vector<double> lstValues;
33     vtkImageData *img=bbGetInputIn();
34     if (img!=NULL)
35     {
36         int dim[3];
37         int ext[6];
38         img->GetExtent(ext);
39         dim[0]                      = ext[1]-ext[0]+1;
40         dim[1]                      = ext[3]-ext[2]+1;
41         dim[2]                      = ext[5]-ext[4]+1;
42         std::vector<int> lstExt     = bbGetInputExtent();
43         if (lstExt.size()!=6)
44         {
45             lstExt.clear();
46             for (int i=0; i<6; i++) lstExt.push_back( ext[i] );
47         } else {
48             
49             if (lstExt[0]<0)        lstExt[0] = 0;
50             if (lstExt[1]>=dim[0])  lstExt[1] = dim[0]-1;
51             if (lstExt[2]<0)        lstExt[2] = 0;
52             if (lstExt[3]>=dim[1])  lstExt[3] = dim[1]-1;
53             if (lstExt[4]<0)        lstExt[4] = 0;
54             if (lstExt[5]>=dim[2])  lstExt[5] = dim[2]-1;
55         } // if lstExt size
56         double range[2];
57         img->GetScalarRange(range);
58         std::vector<double> lstRange   = bbGetInputRange();
59         if (lstRange.size()!=2)
60         {
61             lstRange.clear();
62             for (int i=0; i<2; i++) lstRange.push_back( range[i] );
63         } // if lstRange size
64
65         double background=bbGetInputBackground();
66         int x,y,z;
67         double value;
68         for (z=lstExt[4] ;  z<=lstExt[5] ; z++)
69         {
70             for (y=lstExt[2] ;  y<=lstExt[3] ; y++)
71             {
72                 for (x=lstExt[0] ;  x<=lstExt[1] ; x++)
73                 {
74                     value = img->GetScalarComponentAsDouble(x,y,z,0);
75                     if ((value>=lstRange[0])  && (value<=lstRange[1]))
76                     {
77                         lstX.push_back(x);
78                         lstY.push_back(y);
79                         lstZ.push_back(z);
80                         lstValues.push_back(value);
81                     } else {
82                         if ( bbGetInputType() == 1 )
83                         {
84                             lstX.push_back(x);
85                             lstY.push_back(y);
86                             lstZ.push_back(z);
87                             lstValues.push_back(background);
88                         }
89                     }// if value
90                 }// for x
91             }// for y
92         }// for z
93         
94     } // if bbGetInputIn()
95     bbSetOutputLstPointsX( lstX );
96     bbSetOutputLstPointsY( lstY );
97     bbSetOutputLstPointsZ( lstZ );
98     bbSetOutputLstValues( lstValues );
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 ImageToLstPoints::bbUserSetDefaultValues()
105 {
106 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
107 //    Here we initialize the input 'In' to 0
108     bbSetInputIn(NULL);
109     bbSetInputType(0);
110     bbSetInputBackground(0);
111 }
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 ImageToLstPoints::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 ImageToLstPoints::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