1 #include "bbvtkUnaryOperations.h"
2 #include "bbvtkPackage.h"
7 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,UnaryOperations)
8 BBTK_BLACK_BOX_IMPLEMENTATION(UnaryOperations,bbtk::AtomicBlackBox);
9 void UnaryOperations::Process()
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
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')
24 if (bbGetInputIn1() == NULL)
26 std::cout << "Set In1 at least" << std::endl;
30 ope->SetInput1((vtkDataObject*)bbGetInputIn1());
33 ope->SetConstantK(bbGetInputInConstant());
34 ope->SetConstantC(bbGetInputInConstant());
36 switch (bbGetInputOperation())
39 ope->SetOperationToAddConstant();
43 //EED Borrame crearPredeterminado();
44 ope->SetInput2((vtkDataSet*) constante);
45 ope->SetOperationToSubtract();
48 ope->SetInput2((vtkDataSet*) constante);
49 ope->SetOperationToMultiply();
54 ope->SetOperationToDivide();
57 ope->SetOperationToInvert();
60 ope->SetOperationToAbsoluteValue();
64 ope->SetOperationToSin();
68 ope->SetOperationToCos();
73 ope->SetOperationToExp();
77 ope->SetOperationToLog();
80 substractWithMinimum();
81 bbSetOutputOut(constante);
86 bbSetOutputOut(constante);
90 std::cout << "Invalid Operation" << std::endl;
96 vtkImageData* salida = ope->GetOutput();
98 bbSetOutputOut(salida);
99 bbSignalOutputModification();
103 /* Borrame Eduardo - Juan Pablo
104 void UnaryOperations::crearPredeterminado()
107 vtkImageData* inicial = bbGetInputIn1();
110 if (constante == NULL)
112 inicial->GetExtent(ext);
113 constante = vtkImageData::New();
114 constante->SetExtent(ext);
115 constante->SetScalarType(inicial->GetScalarType());
116 constante->AllocateScalars();
120 for (int i=ext[0]; i<=ext[1]; i++)
122 for (int j=ext[2]; j<=ext[3]; j++)
124 for (int k=ext[4]; k<=ext[5]; k++)
126 unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k);
127 *value = bbGetInputInConstant();
135 void UnaryOperations::substractWithMinimum()
139 vtkImageData* inicial = bbGetInputIn1();
142 if (constante == NULL)
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();
155 for (int i=ext[0]; i<=ext[1]; i++)
157 for (int j=ext[2]; j<=ext[3]; j++)
159 for (int k=ext[4]; k<=ext[5]; k++)
161 double temp1 = lector.getPixelValue(i,j,k,inicial);
162 double temp = temp1 - bbGetInputInConstant();
165 lector.setPixelValue(i,j,k,constante,temp);
171 void UnaryOperations::MultiplyBy()
175 vtkImageData* inicial = bbGetInputIn1();
178 if (constante == NULL)
180 inicial->GetExtent(ext);
181 inicial->GetSpacing(spc);
182 constante = vtkImageData::New();
183 constante->SetExtent(ext);
184 constante->SetSpacing(spc);
185 constante->SetOrigin(inicial->GetOrigin());
186 constante->SetScalarType(inicial->GetScalarType());
187 constante->AllocateScalars();
191 for (int i=ext[0]; i<=ext[1]; i++)
193 for (int j=ext[2]; j<=ext[3]; j++)
195 for (int k=ext[4]; k<=ext[5]; k++)
197 double temp1 = lector.getPixelValue(i,j,k,inicial);
198 double temp = temp1 * bbGetInputInConstant();
201 lector.setPixelValue(i,j,k,constante,temp);
207 void UnaryOperations::bbUserSetDefaultValues()
210 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
211 // Here we initialize the input 'In' to 0
213 // bbSetInputIn2(NULL);
214 bbSetOutputOut(NULL);
215 bbSetInputInConstant(0);
216 bbSetInputOperation(0);
217 ope = vtkImageMathematics::New();
220 void UnaryOperations::bbUserInitializeProcessing()
223 // THE INITIALIZATION METHOD BODY :
225 // but this is where you should allocate the internal/output pointers
230 void UnaryOperations::bbUserFinalizeProcessing()
233 // THE FINALIZATION METHOD BODY :
235 // but this is where you should desallocate the internal/output pointers
240 // EO namespace bbvtk