]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImageBoundaries.cxx
4f7056052562970fc3543792562c20af4ac0535a
[bbtk.git] / packages / vtk / src / bbvtkImageBoundaries.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 "bbvtkImageBoundaries.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImageBoundaries)
10 BBTK_BLACK_BOX_IMPLEMENTATION(ImageBoundaries,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 ImageBoundaries::Process()
15 {
16         printf("bbtk:vtk::ImageBoundaries::Process start\n");
17         if (bbGetInputIn()!=NULL){
18                 int i,j,k;      
19                 int ext[6];
20                 double value;
21                 
22                 bbGetInputIn()->GetWholeExtent(ext);
23                 int maxX        = ext[1]-ext[0]+1;
24                 int maxY        = ext[3]-ext[2]+1;
25                 int maxZ        = ext[5]-ext[4]+1;
26                                 
27                 int bXMax       = 0;
28                 int bYMax       = 0;
29                 int bZMax       = 0;
30                 int bXMin       = maxX-1;
31                 int bYMin       = maxY-1;
32                 int bZMin       = maxZ-1;
33                 
34                 for (i=0 ; i<maxX ; i++)
35                 {
36                         for (j=0 ; j<maxY ; j++)
37                         {
38                                 for (k=0 ; k<maxZ ; k++)
39                                 {
40                                         value = bbGetInputIn()->GetScalarComponentAsDouble(i, j, k,0);
41                                         if ( (value>=bbGetInputLowerValue()) && (value<=bbGetInputUpperValue())  )
42                                         {
43                                                 if (i<bXMin) bXMin=i;
44                                                 if (j<bYMin) bYMin=j;
45                                                 if (k<bZMin) bZMin=k;
46                                                 if (i>bXMax) bXMax=i;
47                                                 if (j>bYMax) bYMax=j;
48                                                 if (k>bZMax) bZMax=k;
49                                         }
50                                 } // for k
51                         } // for j
52                 } // i
53                         
54                 std::vector<int> tmpIndex;              
55                 std::vector<int> tmpSize;
56                 
57                 if (bXMin>bXMax){
58                         tmpIndex.push_back(0);
59                         tmpIndex.push_back(0);
60                         tmpIndex.push_back(0);
61                         tmpSize.push_back(1);
62                         tmpSize.push_back(1);
63                         tmpSize.push_back(1);
64                 } else {
65                         tmpIndex.push_back(bXMin);
66                         tmpIndex.push_back(bYMin);
67                         tmpIndex.push_back(bZMin);
68                         tmpSize.push_back(bXMax-bXMin+1);
69                         tmpSize.push_back(bYMax-bYMin+1);
70                         tmpSize.push_back(bZMax-bZMin+1);
71                 }
72                         
73                 bbSetOutputIndex(tmpIndex);
74                 bbSetOutputSize(tmpSize);
75         } else {
76                 printf("bbtk warnning: bbtk:vtk:ImageBoundaries box, Input image (In) not initialized..\n");
77         }
78         printf("bbtk:vtk::ImageBoundaries::Process end\n");
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 ImageBoundaries::bbUserSetDefaultValues()
84 {
85         
86
87 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
88    bbSetInputIn(NULL);
89         bbSetInputLowerValue(0);
90         bbSetInputUpperValue(5000);
91   
92         std::vector<int> tmpIndex;
93         tmpIndex.push_back(0);
94         tmpIndex.push_back(0);
95         tmpIndex.push_back(0);
96
97         std::vector<int> tmpSize;
98         tmpSize.push_back(1);
99         tmpSize.push_back(1);
100         tmpSize.push_back(1);
101
102         bbSetOutputIndex(tmpIndex);
103         bbSetOutputSize(tmpSize);
104 }
105 //===== 
106 // 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)
107 //===== 
108 void ImageBoundaries::bbUserInitializeProcessing()
109 {
110
111 //  THE INITIALIZATION METHOD BODY :
112 //    Here does nothing 
113 //    but this is where you should allocate the internal/output pointers 
114 //    if any 
115
116   
117 }
118 //===== 
119 // 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)
120 //===== 
121 void ImageBoundaries::bbUserFinalizeProcessing()
122 {
123
124 //  THE FINALIZATION METHOD BODY :
125 //    Here does nothing 
126 //    but this is where you should desallocate the internal/output pointers 
127 //    if any
128   
129 }
130 }
131 // EO namespace bbvtk
132
133