+++ /dev/null
-#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
-
-
+++ /dev/null
-#ifndef __bbvtkSimpleMathematics_h_INCLUDED__
-#define __bbvtkSimpleMathematics_h_INCLUDED__
-#include "bbvtk_EXPORT.h"
-#include "bbtkAtomicBlackBox.h"
-#include "iostream"
-
-
-#include <vtkImageMathematics.h>
-#include <vtkImageData.h>
-#include <vtkType.h>
-#include <vtkImageData.h>
-
-
-namespace bbvtk
-{
-
-
-class StaticLecture
-{
-public:
- void setPixelValue(int i, int j, int k, vtkImageData* img, double value);
- double getPixelValue(int i, int j, int k, vtkImageData* img);
-};
-
-
-class bbvtk_EXPORT SimpleMathematics
- :
- public bbtk::AtomicBlackBox
-{
- BBTK_BLACK_BOX_INTERFACE(SimpleMathematics,bbtk::AtomicBlackBox);
- BBTK_DECLARE_INPUT(In1,vtkImageData*);
- BBTK_DECLARE_INPUT(In2,vtkImageData*);
- BBTK_DECLARE_INPUT(Operation,int);
- BBTK_DECLARE_INPUT(InConstant,double);
- BBTK_DECLARE_OUTPUT(Out,vtkImageData*);
- BBTK_PROCESS(Process);
- void Process();
-
- void crearPredeterminado();
- void substractWithMinimum();
- void MultiplyBy();
-
- StaticLecture lector;
-
- vtkImageMathematics* ope;
- vtkImageData* constante;
-};
-
-BBTK_BEGIN_DESCRIBE_BLACK_BOX(SimpleMathematics,bbtk::AtomicBlackBox);
-BBTK_NAME("SimpleMathematics");
-BBTK_AUTHOR("_author_");
-BBTK_DESCRIPTION("_description_");
-BBTK_CATEGORY("__CATEGORY__");
-BBTK_INPUT(SimpleMathematics,In1,"",vtkImageData*,"");
-BBTK_INPUT(SimpleMathematics,In2,"",vtkImageData*,"");
-BBTK_INPUT(SimpleMathematics,InConstant,"",double,"");
-BBTK_INPUT(SimpleMathematics,Operation,"0:Add, 1:subtract, 2:multiply, 3:divide, 4:invert, 5:sin, 6:cos, 7:exp, 8:log, 9:abs",int,"");
-BBTK_OUTPUT(SimpleMathematics,Out,"",vtkImageData*,"");
-BBTK_END_DESCRIBE_BLACK_BOX(SimpleMathematics);
-}
-// EO namespace bbSimpleProcessing
-
-#endif // __bbvtkSimpleMathematics_h_INCLUDED__
-
-