]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkUnaryOperations.cxx
*** empty log message ***
[bbtk.git] / packages / vtk / src / bbvtkUnaryOperations.cxx
1 #include "bbvtkUnaryOperations.h"
2 #include "bbvtkPackage.h"
3 namespace bbvtk
4 {
5
6
7 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,UnaryOperations)
8 BBTK_BLACK_BOX_IMPLEMENTATION(UnaryOperations,bbtk::AtomicBlackBox);
9 void UnaryOperations::Process()
10 {
11
12 // THE MAIN PROCESSING METHOD BODY
13 //   Here we simply set the input 'In' value to the output 'Out'
14 //   And print out the output value
15 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
16 //    void bbSet{Input|Output}NAME(const TYPE&)
17 //    const TYPE& bbGet{Input|Output}NAME() const
18 //    Where :
19 //    * NAME is the name of the input/output
20 //      (the one provided in the attribute 'name' of the tag 'input')
21 //    * TYPE is the C++ type of the input/output
22 //      (the one provided in the attribute 'type' of the tag 'input')
23
24         if (bbGetInputIn1() == NULL)
25         {
26                 std::cout << "Set In1 at least" << std::endl;
27                 return;
28         }
29
30         ope->SetInput1((vtkDataObject*)bbGetInputIn1());
31
32
33         ope->SetConstantK(bbGetInputInConstant());
34         ope->SetConstantC(bbGetInputInConstant());
35
36         switch (bbGetInputOperation())
37         {
38                 case 0:
39                                 ope->SetOperationToAddConstant();
40
41                 break;
42                 case 1:
43 //EED Borrame                           crearPredeterminado();
44                                 ope->SetInput2((vtkDataSet*) constante);
45                                 ope->SetOperationToSubtract();
46                 break;
47                 case 2:
48                 ope->SetInput2((vtkDataSet*) constante);
49                                 ope->SetOperationToMultiply();
50
51                 break;
52                 case 3:
53
54                                 ope->SetOperationToDivide();
55                 break;
56                 case 4:
57                          ope->SetOperationToInvert();
58                 break;
59                 case 9:
60                          ope->SetOperationToAbsoluteValue();
61                 break;
62                 case 5:
63
64                                 ope->SetOperationToSin();
65                 break;
66                 case 6:
67
68                         ope->SetOperationToCos();
69
70                 break;
71                 case 7:
72
73                                 ope->SetOperationToExp();
74                 break;
75                 case 8:
76
77                                 ope->SetOperationToLog();
78                 break;
79                 case 10:
80                         substractWithMinimum();
81                         bbSetOutputOut(constante);
82                         return;
83                 break;
84                 case 11:
85                         MultiplyBy();
86                         bbSetOutputOut(constante);
87                         return;
88                 break;
89                 default:
90                         std::cout << "Invalid Operation" << std::endl;
91                         return;
92                 break;
93         }
94
95         ope->Update();
96         vtkImageData* salida = ope->GetOutput();
97
98         bbSetOutputOut(salida);
99         bbSignalOutputModification();
100
101 }
102
103 /* Borrame Eduardo - Juan Pablo
104 void UnaryOperations::crearPredeterminado()
105 {
106         int ext[6];
107         vtkImageData* inicial = bbGetInputIn1();
108
109
110         if (constante == NULL)
111         {
112                 inicial->GetExtent(ext);
113                 constante = vtkImageData::New();
114                 constante->SetExtent(ext);
115                 constante->SetScalarType(inicial->GetScalarType());
116                 constante->AllocateScalars();
117                 constante->Update();
118         }
119
120         for (int i=ext[0]; i<=ext[1]; i++)
121         {
122                 for (int j=ext[2]; j<=ext[3]; j++)
123                 {
124                         for (int k=ext[4]; k<=ext[5]; k++)
125                         {
126                                 unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k);
127                                 *value = bbGetInputInConstant();
128                         }
129                 }
130         }
131 }
132 */
133
134
135 void UnaryOperations::substractWithMinimum()
136 {
137         int ext[6];
138         double spc[3];
139         vtkImageData* inicial = bbGetInputIn1();
140
141
142         if (constante == NULL)
143         {
144                 inicial->GetExtent(ext);
145                 inicial->GetSpacing(spc);
146                 constante = vtkImageData::New();
147                 constante->SetExtent(ext);
148                 constante->SetSpacing(spc);
149                 constante->SetOrigin(inicial->GetOrigin());
150                 constante->SetScalarType(inicial->GetScalarType());
151                 constante->AllocateScalars();
152                 constante->Update();
153         }
154
155         for (int i=ext[0]; i<=ext[1]; i++)
156         {
157                 for (int j=ext[2]; j<=ext[3]; j++)
158                 {
159                         for (int k=ext[4]; k<=ext[5]; k++)
160                         {
161                                 double temp1 = lector.getPixelValue(i,j,k,inicial);
162                                 double temp = temp1 - bbGetInputInConstant();
163                                 if (temp < 0)
164                                         temp = 0;
165                                 lector.setPixelValue(i,j,k,constante,temp);
166                         }
167                 }
168         }
169 }
170
171
172 void UnaryOperations::bbUserSetDefaultValues()
173 {
174
175 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
176 //    Here we initialize the input 'In' to 0
177    bbSetInputIn1(NULL);
178    bbSetOutputOut(NULL);
179    bbSetInputInConstant(0);
180    bbSetInputOperation(0);
181    ope = vtkImageMathematics::New();
182    constante = NULL;
183 }
184 void UnaryOperations::bbUserInitializeProcessing()
185 {
186
187 //  THE INITIALIZATION METHOD BODY :
188 //    Here does nothing
189 //    but this is where you should allocate the internal/output pointers
190 //    if any
191
192
193 }
194 void UnaryOperations::bbUserFinalizeProcessing()
195 {
196
197 //  THE FINALIZATION METHOD BODY :
198 //    Here does nothing
199 //    but this is where you should desallocate the internal/output pointers
200 //    if any
201
202 }
203 }
204 // EO namespace bbvtk
205
206