From d1ab83f07c424a692ae94a56a1d80aa3e2f071c6 Mon Sep 17 00:00:00 2001 From: reyes Date: Tue, 31 May 2011 15:42:17 +0000 Subject: [PATCH] with `CVS:' are removed automatically --- packages/vtk/src/bbvtkSimpleMathematics.cxx | 436 ++++++++++++++++++++ 1 file changed, 436 insertions(+) create mode 100644 packages/vtk/src/bbvtkSimpleMathematics.cxx diff --git a/packages/vtk/src/bbvtkSimpleMathematics.cxx b/packages/vtk/src/bbvtkSimpleMathematics.cxx new file mode 100644 index 0000000..765d06f --- /dev/null +++ b/packages/vtk/src/bbvtkSimpleMathematics.cxx @@ -0,0 +1,436 @@ +#include "bbvtkSimpleMathematics.h" +#include "bbvtkPackage.h" +namespace bbvtk +{ + + void StaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value) + { + //double rta; + int scalar_type = img->GetScalarType(); + int* ext = img->GetExtent(); + if (i < ext[0]) + return; + if (i > ext[1]) + return; + + if (j < ext[2]) + return; + if (j > ext[3]) + return; + + if (k < ext[4]) + return; + if (k > ext[5]) + return; + + switch (scalar_type) + { + case VTK_CHAR: + char * ap2; + ap2 = (char *) img->GetScalarPointer(i,j,k); + *ap2 = (char) value; + break; + case VTK_UNSIGNED_CHAR: + unsigned char * ap3; + ap3 = (unsigned char *) img->GetScalarPointer(i,j,k); + *ap3 = (unsigned char) value; + break; + case VTK_SHORT: + short * ap4; + ap4 = (short *) img->GetScalarPointer(i,j,k); + *ap4 = (short) value; + break; + case VTK_UNSIGNED_SHORT: + unsigned short * ap5; + ap5 = (unsigned short *) img->GetScalarPointer(i,j,k); + *ap5 = (unsigned short) value; + break; + case VTK_INT: + int * ap6; + ap6 = (int *) img->GetScalarPointer(i,j,k); + *ap6 = (int) value; + break; + case VTK_UNSIGNED_INT: + unsigned int * ap7; + ap7 = (unsigned int *) img->GetScalarPointer(i,j,k); + *ap7 = (unsigned int) value; + break; + case VTK_LONG: + long * ap8; + ap8 = (long *) img->GetScalarPointer(i,j,k); + *ap8 = (long) value; + break; + case VTK_UNSIGNED_LONG: + unsigned long * ap9; + ap9 = (unsigned long *) img->GetScalarPointer(i,j,k); + *ap9 = (unsigned long) value; + break; + case VTK_FLOAT: + float * ap10; + ap10 = (float *) img->GetScalarPointer(i,j,k); + *ap10 = (float) value; + break; + case VTK_DOUBLE: + double * ap11; + ap11 = (double *) img->GetScalarPointer(i,j,k); + *ap11 = (double) value; + break; + } + } + + double StaticLecture::getPixelValue(int i, int j, int k, vtkImageData* img) + { + double rta; + int scalar_type = img->GetScalarType(); + int* ext = img->GetExtent(); + if (i < ext[0]) + i=ext[0]; + if (i > ext[1]) + i=ext[1]; + + if (j < ext[2]) + j=ext[2]; + if (j > ext[3]) + j=ext[3]; + + if (k < ext[4]) + k=ext[4]; + if (k > ext[5]) + k=ext[5]; + + switch (scalar_type) + { + case VTK_CHAR: + char * ap2; + ap2 = (char *) img->GetScalarPointer(i,j,k); + rta = (double) *ap2; + break; + case VTK_UNSIGNED_CHAR: + unsigned char * ap3; + ap3 = (unsigned char *) img->GetScalarPointer(i,j,k); + rta = (double) *ap3; + break; + case VTK_SHORT: + short * ap4; + ap4 = (short *) img->GetScalarPointer(i,j,k); + rta = (double) *ap4; + break; + case VTK_UNSIGNED_SHORT: + unsigned short * ap5; + ap5 = (unsigned short *) img->GetScalarPointer(i,j,k); + rta = (double) *ap5; + break; + case VTK_INT: + int * ap6; + ap6 = (int *) img->GetScalarPointer(i,j,k); + rta = (double) *ap6; + break; + case VTK_UNSIGNED_INT: + unsigned int * ap7; + ap7 = (unsigned int *) img->GetScalarPointer(i,j,k); + rta = (double) *ap7; + break; + case VTK_LONG: + long * ap8; + ap8 = (long *) img->GetScalarPointer(i,j,k); + rta = (double) *ap8; + break; + case VTK_UNSIGNED_LONG: + unsigned long * ap9; + ap9 = (unsigned long *) img->GetScalarPointer(i,j,k); + rta = (double) *ap9; + break; + case VTK_FLOAT: + float * ap10; + ap10 = (float *) img->GetScalarPointer(i,j,k); + rta = (double) *ap10; + break; + case VTK_DOUBLE: + double * ap11; + ap11 = (double *) img->GetScalarPointer(i,j,k); + rta = (double) *ap11; + break; + } + return rta; + } + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SimpleMathematics) +BBTK_BLACK_BOX_IMPLEMENTATION(SimpleMathematics,bbtk::AtomicBlackBox); +void SimpleMathematics::Process() +{ + +// THE MAIN PROCESSING METHOD BODY +// Here we simply set the input 'In' value to the output 'Out' +// And print out the output value +// INPUT/OUTPUT ACCESSORS ARE OF THE FORM : +// void bbSet{Input|Output}NAME(const TYPE&) +// const TYPE& bbGet{Input|Output}NAME() const +// Where : +// * NAME is the name of the input/output +// (the one provided in the attribute 'name' of the tag 'input') +// * TYPE is the C++ type of the input/output +// (the one provided in the attribute 'type' of the tag 'input') + + if (bbGetInputIn1() == NULL) + { + std::cout << "Set In1 at least" << std::endl; + return; + } + + ope->SetInput1((vtkDataObject*)bbGetInputIn1()); + bool onlyone = true; + + if (bbGetInputIn2() != NULL) + { + ope->SetInput2((vtkDataObject*)bbGetInputIn2()); + onlyone = false; + } + + ope->SetConstantK(bbGetInputInConstant()); + ope->SetConstantC(bbGetInputInConstant()); + + switch (bbGetInputOperation()) + { + case 0: + if (onlyone) + ope->SetOperationToAddConstant(); + else + ope->SetOperationToAdd(); + break; + case 1: + if (onlyone) + { + crearPredeterminado(); + ope->SetInput2((vtkDataSet*) constante); + ope->SetOperationToSubtract(); + } + else + { + ope->SetOperationToSubtract(); + } + break; + case 2: + if (onlyone) + ope->SetOperationToMultiply(); + else + ope->SetOperationToMultiplyByK(); + break; + case 3: + if (onlyone) + { + std::cout << "Set In2" << std::endl; + return; + } + else + { + ope->SetOperationToDivide(); + } + break; + case 4: + ope->SetOperationToInvert(); + break; + case 9: + ope->SetOperationToAbsoluteValue(); + break; + case 5: + if (onlyone) + { + std::cout << "Set In2" << std::endl; + return; + } + else + { + ope->SetOperationToSin(); + } + break; + case 6: + if (onlyone) + { + std::cout << "Set In2" << std::endl; + return; + } + else + { + ope->SetOperationToCos(); + } + break; + case 7: + if (onlyone) + { + std::cout << "Set In2" << std::endl; + return; + } + else + { + ope->SetOperationToExp(); + } + break; + case 8: + if (onlyone) + { + std::cout << "Set In2" << std::endl; + return; + } + else + { + ope->SetOperationToLog(); + } + break; + case 10: + substractWithMinimum(); + bbSetOutputOut(constante); + return; + break; + case 11: + MultiplyBy(); + bbSetOutputOut(constante); + return; + break; + default: + std::cout << "Invalid Operation" << std::endl; + return; + break; + } + + ope->Update(); + vtkImageData* salida = ope->GetOutput(); + + bbSetOutputOut(salida); + bbSignalOutputModification(); + +} +void SimpleMathematics::crearPredeterminado() +{ + int ext[6]; + vtkImageData* inicial = bbGetInputIn1(); + + + if (constante == NULL) + { + inicial->GetExtent(ext); + constante = vtkImageData::New(); + constante->SetExtent(ext); + constante->SetScalarType(inicial->GetScalarType()); + constante->AllocateScalars(); + constante->Update(); + } + + for (int i=ext[0]; i<=ext[1]; i++) + { + for (int j=ext[2]; j<=ext[3]; j++) + { + for (int k=ext[4]; k<=ext[5]; k++) + { + unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k); + *value = bbGetInputInConstant(); + } + } + } +} +void SimpleMathematics::substractWithMinimum() +{ + int ext[6]; + double spc[3]; + vtkImageData* inicial = bbGetInputIn1(); + + + if (constante == NULL) + { + inicial->GetExtent(ext); + inicial->GetSpacing(spc); + constante = vtkImageData::New(); + constante->SetExtent(ext); + constante->SetSpacing(spc); + constante->SetOrigin(inicial->GetOrigin()); + constante->SetScalarType(inicial->GetScalarType()); + constante->AllocateScalars(); + constante->Update(); + } + + for (int i=ext[0]; i<=ext[1]; i++) + { + for (int j=ext[2]; j<=ext[3]; j++) + { + for (int k=ext[4]; k<=ext[5]; k++) + { + double temp1 = lector.getPixelValue(i,j,k,inicial); + double temp = temp1 - bbGetInputInConstant(); + if (temp < 0) + temp = 0; + lector.setPixelValue(i,j,k,constante,temp); + } + } + } +} + +void SimpleMathematics::MultiplyBy() +{ + int ext[6]; + double spc[3]; + vtkImageData* inicial = bbGetInputIn1(); + + + if (constante == NULL) + { + inicial->GetExtent(ext); + inicial->GetSpacing(spc); + constante = vtkImageData::New(); + constante->SetExtent(ext); + constante->SetSpacing(spc); + constante->SetOrigin(inicial->GetOrigin()); + constante->SetScalarType(inicial->GetScalarType()); + constante->AllocateScalars(); + constante->Update(); + } + + for (int i=ext[0]; i<=ext[1]; i++) + { + for (int j=ext[2]; j<=ext[3]; j++) + { + for (int k=ext[4]; k<=ext[5]; k++) + { + double temp1 = lector.getPixelValue(i,j,k,inicial); + double temp = temp1 * bbGetInputInConstant(); + if (temp < 0) + temp = 0; + lector.setPixelValue(i,j,k,constante,temp); + } + } + } +} + +void SimpleMathematics::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputIn1(NULL); + bbSetInputIn2(NULL); + bbSetOutputOut(NULL); + bbSetInputInConstant(0); + ope = vtkImageMathematics::New(); + constante = NULL; +} +void SimpleMathematics::bbUserInitializeProcessing() +{ + +// THE INITIALIZATION METHOD BODY : +// Here does nothing +// but this is where you should allocate the internal/output pointers +// if any + + +} +void SimpleMathematics::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbvtk + + -- 2.45.1