]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCreateImage.cxx
no message
[bbtk.git] / packages / vtk / src / bbvtkCreateImage.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbvtkCreateImage.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CreateImage)
10 BBTK_BLACK_BOX_IMPLEMENTATION(CreateImage,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14 void CreateImage::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29         
30         double  spc[6];
31         int             dim[3]; 
32         int             outputformat = VTK_UNSIGNED_SHORT;
33         
34         if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;
35         else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;
36         else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;
37         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;
38         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;
39         else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;
40         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;
41         else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;
42         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;
43         else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;
44         else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;
45                 
46         spc[0] = bbGetInputSpacing()[0];
47         spc[1] = bbGetInputSpacing()[1];
48         spc[2] = bbGetInputSpacing()[2];
49         
50         dim[0] =  bbGetInputDimensions()[0];
51         dim[1] =  bbGetInputDimensions()[1];
52         dim[2] =  bbGetInputDimensions()[2];
53         
54         imageoutput->Initialize();
55         imageoutput->SetScalarType( outputformat );     
56         imageoutput->SetSpacing( spc );
57         imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
58         imageoutput->AllocateScalars();
59         
60                 
61                 int i,j,k;
62                 for (i=0; i<dim[0]; i++)
63                 {
64                         for (j=0; j<dim[1]; j++)
65                         {
66                                 for (k=0; k<dim[2]; k++)
67                                 {
68                                         imageoutput->SetScalarComponentFromDouble(i,j,k, 0, bbGetInputInitialValue() );
69                                 } // for k
70                         } // for j
71                 } // for i
72                 
73                 bbSetOutputOut(imageoutput);
74
75 }       
76         
77 //===== 
78 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
79 //===== 
80 void CreateImage::bbUserSetDefaultValues()
81 {
82         imageoutput=NULL;
83
84 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
85         std::vector<int> dim;
86         dim.push_back(250);
87         dim.push_back(250);
88         dim.push_back(250);
89         std::vector<double> spc;
90         dim.push_back(1.0);
91         dim.push_back(1.0);
92         dim.push_back(1.0);
93         
94         bbSetInputDimensions(dim);
95         bbSetInputSpacing(spc);
96         bbSetInputOutputFormat("VTK_UNSIGNED_SHORT");
97         bbSetInputInitialValue(0);
98 }
99         
100 //===== 
101 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
102 //===== 
103 void CreateImage::bbUserInitializeProcessing()
104 {
105
106 //  THE INITIALIZATION METHOD BODY :
107 //    Here does nothing 
108 //    but this is where you should allocate the internal/output pointers 
109 //    if any 
110
111         imageoutput = vtkImageData::New();
112
113 }
114         
115 //===== 
116 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
117 //===== 
118 void CreateImage::bbUserFinalizeProcessing()
119 {
120
121 //  THE FINALIZATION METHOD BODY :
122 //    Here does nothing 
123 //    but this is where you should desallocate the internal/output pointers 
124 //    if any
125         imageoutput->Delete();
126
127 }
128 }
129 // EO namespace bbvtk
130
131