]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkUnaryOperations.cxx
f9e1589a813e1cf1c19829ed546b47a8c78f09ad
[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
80                         
81 /* EED 21Juin 2011 Borrame
82                 case 10:
83                         substractWithMinimum();
84                         bbSetOutputOut(constante);
85                         return;
86                 break;
87                 case 11:
88                         MultiplyBy();
89                         bbSetOutputOut(constante);
90                         return;
91                 break;
92 */  
93                         
94                 default:
95                         std::cout << "Invalid Operation" << std::endl;
96                         return;
97                 break;
98         }
99
100         ope->Update();
101         vtkImageData* salida = ope->GetOutput();
102
103         bbSetOutputOut(salida);
104         bbSignalOutputModification();
105
106 }
107
108 /* Borrame Eduardo - Juan Pablo
109 void UnaryOperations::crearPredeterminado()
110 {
111         int ext[6];
112         vtkImageData* inicial = bbGetInputIn1();
113
114
115         if (constante == NULL)
116         {
117                 inicial->GetExtent(ext);
118                 constante = vtkImageData::New();
119                 constante->SetExtent(ext);
120                 constante->SetScalarType(inicial->GetScalarType());
121                 constante->AllocateScalars();
122                 constante->Update();
123         }
124
125         for (int i=ext[0]; i<=ext[1]; i++)
126         {
127                 for (int j=ext[2]; j<=ext[3]; j++)
128                 {
129                         for (int k=ext[4]; k<=ext[5]; k++)
130                         {
131                                 unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k);
132                                 *value = bbGetInputInConstant();
133                         }
134                 }
135         }
136 }
137 */
138
139
140 void UnaryOperations::substractWithMinimum()
141 {
142         int ext[6];
143         double spc[3];
144         vtkImageData* inicial = bbGetInputIn1();
145
146
147         if (constante == NULL)
148         {
149                 inicial->GetExtent(ext);
150                 inicial->GetSpacing(spc);
151                 constante = vtkImageData::New();
152                 constante->SetExtent(ext);
153                 constante->SetSpacing(spc);
154                 constante->SetOrigin(inicial->GetOrigin());
155                 constante->SetScalarType(inicial->GetScalarType());
156                 constante->AllocateScalars();
157                 constante->Update();
158         }
159
160         for (int i=ext[0]; i<=ext[1]; i++)
161         {
162                 for (int j=ext[2]; j<=ext[3]; j++)
163                 {
164                         for (int k=ext[4]; k<=ext[5]; k++)
165                         {
166                                 double temp1 = lector.getPixelValue(i,j,k,inicial);
167                                 double temp = temp1 - bbGetInputInConstant();
168                                 if (temp < 0)
169                                         temp = 0;
170                                 lector.setPixelValue(i,j,k,constante,temp);
171                         }
172                 }
173         }
174 }
175
176
177 void UnaryOperations::bbUserSetDefaultValues()
178 {
179
180 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
181 //    Here we initialize the input 'In' to 0
182    bbSetInputIn1(NULL);
183    bbSetOutputOut(NULL);
184    bbSetInputInConstant(0);
185    bbSetInputOperation(0);
186    ope = vtkImageMathematics::New();
187    constante = NULL;
188 }
189 void UnaryOperations::bbUserInitializeProcessing()
190 {
191
192 //  THE INITIALIZATION METHOD BODY :
193 //    Here does nothing
194 //    but this is where you should allocate the internal/output pointers
195 //    if any
196
197
198 }
199 void UnaryOperations::bbUserFinalizeProcessing()
200 {
201
202 //  THE FINALIZATION METHOD BODY :
203 //    Here does nothing
204 //    but this is where you should desallocate the internal/output pointers
205 //    if any
206
207 }
208 }
209 // EO namespace bbvtk
210
211