]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkBinaryOperations.cxx
748357bcad6c345ba6bfebfb95d2a66c0d2e765a
[bbtk.git] / packages / vtk / src / bbvtkBinaryOperations.cxx
1 #include "bbvtkBinaryOperations.h"
2 #include "bbvtkPackage.h"
3 namespace bbvtk
4 {
5
6
7 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,BinaryOperations)
8 BBTK_BLACK_BOX_IMPLEMENTATION(BinaryOperations,bbtk::AtomicBlackBox);
9 void BinaryOperations::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         if (bbGetInputIn2() != NULL)
33         {
34                 ope->SetInput2((vtkDataObject*)bbGetInputIn2());
35
36         }
37         else
38         {
39             std::cout << "Set In2" << std::endl;
40         return;
41         }
42
43
44
45         switch (bbGetInputOperation())
46         {
47                 case 0:
48                                 ope->SetOperationToAdd();
49                 break;
50                 case 1:
51                                 ope->SetOperationToSubtract();
52
53                 break;
54                 case 2:
55                                 ope->SetOperationToMultiply();
56                 break;
57                 case 3:
58                                 ope->SetOperationToDivide();
59                 break;
60                 default:
61                         std::cout << "Invalid Operation" << std::endl;
62                         return;
63                 break;
64         }
65
66         ope->Update();
67         vtkImageData* salida = ope->GetOutput();
68
69         bbSetOutputOut(salida);
70         bbSignalOutputModification();
71
72 }
73 void BinaryOperations::crearPredeterminado()
74 {
75         int ext[6];
76         vtkImageData* inicial = bbGetInputIn1();
77
78
79         if (constante == NULL)
80         {
81                 inicial->GetExtent(ext);
82                 constante = vtkImageData::New();
83                 constante->SetExtent(ext);
84                 constante->SetScalarType(inicial->GetScalarType());
85                 constante->AllocateScalars();
86                 constante->Update();
87         }
88
89         for (int i=ext[0]; i<=ext[1]; i++)
90         {
91                 for (int j=ext[2]; j<=ext[3]; j++)
92                 {
93                         for (int k=ext[4]; k<=ext[5]; k++)
94                         {
95                                 unsigned short* value = (unsigned short*)constante->GetScalarPointer(i,j,k);
96                                 *value = bbGetInputInConstant();
97                         }
98                 }
99         }
100 }
101
102
103 void BinaryOperations::bbUserSetDefaultValues()
104 {
105
106 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
107 //    Here we initialize the input 'In' to 0
108    bbSetInputIn1(NULL);
109    bbSetInputIn2(NULL);
110    bbSetOutputOut(NULL);
111    bbSetInputInConstant(0);
112    ope = vtkImageMathematics::New();
113    constante = NULL;
114 }
115 void BinaryOperations::bbUserInitializeProcessing()
116 {
117
118 //  THE INITIALIZATION METHOD BODY :
119 //    Here does nothing
120 //    but this is where you should allocate the internal/output pointers
121 //    if any
122
123
124 }
125 void BinaryOperations::bbUserFinalizeProcessing()
126 {
127
128 //  THE FINALIZATION METHOD BODY :
129 //    Here does nothing
130 //    but this is where you should desallocate the internal/output pointers
131 //    if any
132
133 }
134 }
135 // EO namespace bbvtk
136
137