1 #include "bbvtkSimpleMathematics.h"
2 #include "bbvtkPackage.h"
6 void StaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value)
9 int scalar_type = img->GetScalarType();
10 int* ext = img->GetExtent();
30 ap2 = (char *) img->GetScalarPointer(i,j,k);
33 case VTK_UNSIGNED_CHAR:
35 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
36 *ap3 = (unsigned char) value;
40 ap4 = (short *) img->GetScalarPointer(i,j,k);
43 case VTK_UNSIGNED_SHORT:
45 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
46 *ap5 = (unsigned short) value;
50 ap6 = (int *) img->GetScalarPointer(i,j,k);
53 case VTK_UNSIGNED_INT:
55 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
56 *ap7 = (unsigned int) value;
60 ap8 = (long *) img->GetScalarPointer(i,j,k);
63 case VTK_UNSIGNED_LONG:
65 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
66 *ap9 = (unsigned long) value;
70 ap10 = (float *) img->GetScalarPointer(i,j,k);
71 *ap10 = (float) value;
75 ap11 = (double *) img->GetScalarPointer(i,j,k);
76 *ap11 = (double) value;
81 double StaticLecture::getPixelValue(int i, int j, int k, vtkImageData* img)
84 int scalar_type = img->GetScalarType();
85 int* ext = img->GetExtent();
105 ap2 = (char *) img->GetScalarPointer(i,j,k);
108 case VTK_UNSIGNED_CHAR:
110 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
115 ap4 = (short *) img->GetScalarPointer(i,j,k);
118 case VTK_UNSIGNED_SHORT:
119 unsigned short * ap5;
120 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
125 ap6 = (int *) img->GetScalarPointer(i,j,k);
128 case VTK_UNSIGNED_INT:
130 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
135 ap8 = (long *) img->GetScalarPointer(i,j,k);
138 case VTK_UNSIGNED_LONG:
140 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
145 ap10 = (float *) img->GetScalarPointer(i,j,k);
146 rta = (double) *ap10;
150 ap11 = (double *) img->GetScalarPointer(i,j,k);
151 rta = (double) *ap11;
157 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SimpleMathematics)
158 BBTK_BLACK_BOX_IMPLEMENTATION(SimpleMathematics,bbtk::AtomicBlackBox);
159 void SimpleMathematics::Process()
162 // THE MAIN PROCESSING METHOD BODY
163 // Here we simply set the input 'In' value to the output 'Out'
164 // And print out the output value
165 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
166 // void bbSet{Input|Output}NAME(const TYPE&)
167 // const TYPE& bbGet{Input|Output}NAME() const
169 // * NAME is the name of the input/output
170 // (the one provided in the attribute 'name' of the tag 'input')
171 // * TYPE is the C++ type of the input/output
172 // (the one provided in the attribute 'type' of the tag 'input')
174 if (bbGetInputIn1() == NULL)
176 std::cout << "Set In1 at least" << std::endl;
180 ope->SetInput1((vtkDataObject*)bbGetInputIn1());
183 if (bbGetInputIn2() != NULL)
185 ope->SetInput2((vtkDataObject*)bbGetInputIn2());
189 ope->SetConstantK(bbGetInputInConstant());
190 ope->SetConstantC(bbGetInputInConstant());
192 switch (bbGetInputOperation())
196 ope->SetOperationToAddConstant();
198 ope->SetOperationToAdd();
203 crearPredeterminado();
204 ope->SetInput2((vtkDataSet*) constante);
205 ope->SetOperationToSubtract();
209 ope->SetOperationToSubtract();
214 ope->SetOperationToMultiply();
216 ope->SetOperationToMultiplyByK();
221 std::cout << "Set In2" << std::endl;
226 ope->SetOperationToDivide();
230 ope->SetOperationToInvert();
233 ope->SetOperationToAbsoluteValue();
238 std::cout << "Set In2" << std::endl;
243 ope->SetOperationToSin();
249 std::cout << "Set In2" << std::endl;
254 ope->SetOperationToCos();
260 std::cout << "Set In2" << std::endl;
265 ope->SetOperationToExp();
271 std::cout << "Set In2" << std::endl;
276 ope->SetOperationToLog();
280 substractWithMinimum();
281 bbSetOutputOut(constante);
286 bbSetOutputOut(constante);
290 std::cout << "Invalid Operation" << std::endl;
296 vtkImageData* salida = ope->GetOutput();
298 bbSetOutputOut(salida);
299 bbSignalOutputModification();
302 void SimpleMathematics::crearPredeterminado()
305 vtkImageData* inicial = bbGetInputIn1();
308 if (constante == NULL)
310 inicial->GetExtent(ext);
311 constante = vtkImageData::New();
312 constante->SetExtent(ext);
313 constante->SetScalarType(inicial->GetScalarType());
314 constante->AllocateScalars();
318 for (int i=ext[0]; i<=ext[1]; i++)
320 for (int j=ext[2]; j<=ext[3]; j++)
322 for (int k=ext[4]; k<=ext[5]; k++)
324 unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k);
325 *value = bbGetInputInConstant();
330 void SimpleMathematics::substractWithMinimum()
334 vtkImageData* inicial = bbGetInputIn1();
337 if (constante == NULL)
339 inicial->GetExtent(ext);
340 inicial->GetSpacing(spc);
341 constante = vtkImageData::New();
342 constante->SetExtent(ext);
343 constante->SetSpacing(spc);
344 constante->SetOrigin(inicial->GetOrigin());
345 constante->SetScalarType(inicial->GetScalarType());
346 constante->AllocateScalars();
350 for (int i=ext[0]; i<=ext[1]; i++)
352 for (int j=ext[2]; j<=ext[3]; j++)
354 for (int k=ext[4]; k<=ext[5]; k++)
356 double temp1 = lector.getPixelValue(i,j,k,inicial);
357 double temp = temp1 - bbGetInputInConstant();
360 lector.setPixelValue(i,j,k,constante,temp);
366 void SimpleMathematics::MultiplyBy()
370 vtkImageData* inicial = bbGetInputIn1();
373 if (constante == NULL)
375 inicial->GetExtent(ext);
376 inicial->GetSpacing(spc);
377 constante = vtkImageData::New();
378 constante->SetExtent(ext);
379 constante->SetSpacing(spc);
380 constante->SetOrigin(inicial->GetOrigin());
381 constante->SetScalarType(inicial->GetScalarType());
382 constante->AllocateScalars();
386 for (int i=ext[0]; i<=ext[1]; i++)
388 for (int j=ext[2]; j<=ext[3]; j++)
390 for (int k=ext[4]; k<=ext[5]; k++)
392 double temp1 = lector.getPixelValue(i,j,k,inicial);
393 double temp = temp1 * bbGetInputInConstant();
396 lector.setPixelValue(i,j,k,constante,temp);
402 void SimpleMathematics::bbUserSetDefaultValues()
405 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
406 // Here we initialize the input 'In' to 0
409 bbSetOutputOut(NULL);
410 bbSetInputInConstant(0);
411 ope = vtkImageMathematics::New();
414 void SimpleMathematics::bbUserInitializeProcessing()
417 // THE INITIALIZATION METHOD BODY :
419 // but this is where you should allocate the internal/output pointers
424 void SimpleMathematics::bbUserFinalizeProcessing()
427 // THE FINALIZATION METHOD BODY :
429 // but this is where you should desallocate the internal/output pointers
434 // EO namespace bbvtk