]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCreateImage.cxx
Clean code
[bbtk.git] / packages / vtk / src / bbvtkCreateImage.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 //=====
29 // 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)
30 //===== 
31 #include "bbvtkCreateImage.h"
32 #include "bbvtkPackage.h"
33 namespace bbvtk
34 {
35
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CreateImage)
37 BBTK_BLACK_BOX_IMPLEMENTATION(CreateImage,bbtk::AtomicBlackBox);
38 //===== 
39 // 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)
40 //===== 
41 void CreateImage::Process()
42 {
43
44 // THE MAIN PROCESSING METHOD BODY
45 //   Here we simply set the input 'In' value to the output 'Out'
46 //   And print out the output value
47 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
48 //    void bbSet{Input|Output}NAME(const TYPE&)
49 //    const TYPE& bbGet{Input|Output}NAME() const 
50 //    Where :
51 //    * NAME is the name of the input/output
52 //      (the one provided in the attribute 'name' of the tag 'input')
53 //    * TYPE is the C++ type of the input/output
54 //      (the one provided in the attribute 'type' of the tag 'input')
55
56     int         dim[3];
57         dim[0]  = bbGetInputDimensions()[0];
58         dim[1]  = bbGetInputDimensions()[1];
59         dim[2]  = bbGetInputDimensions()[2];
60         if (imageoutput!=NULL)
61         {
62                 imageoutput->Delete();
63                 imageoutput = NULL;
64         } // if imageoutput
65
66         if ( !((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0)) )
67         {
68                 double  spc[3];
69                 int             outputformat = VTK_UNSIGNED_SHORT;
70
71                 spc[0]  = 1;
72                 spc[1]  = 1;
73                 spc[2]  = 1;
74                 if  ( bbGetInputSpacing().size()==3 )
75                 {
76                         spc[0] = bbGetInputSpacing()[0];
77                         spc[1] = bbGetInputSpacing()[1];
78                         spc[2] = bbGetInputSpacing()[2];
79                         if ((spc[0]<=0)||(spc[1]<=0)||(spc[2]<=0))
80                         {
81                                 spc[0] = 1;
82                                 spc[1] = 1;
83                                 spc[2] = 1;
84                         }
85                 } // size spc 3
86                 if  ( bbGetInputSpacing().size()==2 )
87                 {
88                         spc[0] = bbGetInputSpacing()[0];
89                         spc[1] = bbGetInputSpacing()[1];
90                         if ((spc[0]<=0)||(spc[1]<=0))
91                         {
92                                 spc[0] = 1;
93                                 spc[1] = 1;
94                         }
95                 } // if size spc 2
96
97                 
98                 if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;                 // 1
99                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;                                // 2
100                 else if (bbGetInputOutputFormat()=="MET_CHAR")                          outputformat = VTK_CHAR;                                // 2
101                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;         // 15
102                 else if (bbGetInputOutputFormat()=="MET_UCHAR")                         outputformat = VTK_UNSIGNED_CHAR;       // 3
103                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;       // 3
104                 else if (bbGetInputOutputFormat()=="VTK_SHORT")                         outputformat = VTK_SHORT;               // 4
105                 else if (bbGetInputOutputFormat()=="MET_SHORT")                         outputformat = VTK_SHORT;               // 4
106                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;      // 5
107                 else if (bbGetInputOutputFormat()=="MET_USHORT")                        outputformat = VTK_UNSIGNED_SHORT;      // 5
108                 else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;                 // 6
109                 else if (bbGetInputOutputFormat()=="MET_INT")                           outputformat = VTK_INT;                 // 6
110                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;        // 7 
111                 else if (bbGetInputOutputFormat()=="MET_UINT")                          outputformat = VTK_UNSIGNED_INT;        // 7 
112                 else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;                // 8
113                 else if (bbGetInputOutputFormat()=="MET_LONG")                          outputformat = VTK_LONG;                // 8
114                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;       // 9
115                 else if (bbGetInputOutputFormat()=="MET_ULONG")                         outputformat = VTK_UNSIGNED_LONG;       // 9
116                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;               // 10
117                 else if (bbGetInputOutputFormat()=="MET_FLOAT")                         outputformat = VTK_FLOAT;               // 10
118                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11           
119                 else if (bbGetInputOutputFormat()=="MET_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11  
120
121                 if ((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0))
122                 {
123                         dim[0] = 1;
124                         dim[1] = 1;
125                         dim[2] = 1;
126                 }
127
128                 imageoutput = vtkImageData::New();
129                 imageoutput->Initialize();
130                 imageoutput->SetSpacing( spc );
131                 imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
132
133         //EED 2017-01-01 Migration VTK7
134         #if (VTK_MAJOR_VERSION <= 5) 
135                 imageoutput->SetScalarType( outputformat );     
136                 imageoutput->AllocateScalars();
137         #endif
138         #if (VTK_MAJOR_VERSION >= 6) 
139                 imageoutput->AllocateScalars( outputformat,1 );
140         #endif
141                 
142                 int i,j,k;
143                 long sizeBlock; 
144                 for (i=0; i<dim[0]; i++)
145                 {
146                         imageoutput->SetScalarComponentFromDouble(i,0,0, 0, bbGetInputInitialValue() );
147                 } // for i
148                 sizeBlock= dim[0] * imageoutput->GetScalarSize();
149                 for (j=1; j<dim[1]; j++)
150                 {
151                         memcpy(  imageoutput->GetScalarPointer(0,j,0), imageoutput->GetScalarPointer()  , sizeBlock );
152                 } // for j              
153                 sizeBlock= dim[0] * dim[1] * imageoutput->GetScalarSize();
154                 for (k=0; k<dim[2]; k++)
155                 {
156                         memcpy(  imageoutput->GetScalarPointer(0,0,k) ,imageoutput->GetScalarPointer()  , sizeBlock );
157                 } // for k
158         //EED 2017-01-01 Migration VTK7
159         #if (VTK_MAJOR_VERSION <= 5) 
160                 imageoutput->Update();
161         #endif
162         #if (VTK_MAJOR_VERSION >= 6) 
163                 // ..
164         #endif
165                 imageoutput->Modified();
166         } // if dim = 0
167         bbSetOutputOut(imageoutput);
168 }
169         
170 //===== 
171 // 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)
172 //===== 
173 void CreateImage::bbUserSetDefaultValues()
174 {
175         imageoutput=NULL;
176
177 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
178         std::vector<int> dim;
179         dim.push_back(250);
180         dim.push_back(250);
181         dim.push_back(250);
182         std::vector<double> spc;
183         spc.push_back(1.0);
184         spc.push_back(1.0);
185         spc.push_back(1.0);
186         
187         bbSetInputDimensions(dim);
188         bbSetInputSpacing(spc);
189         bbSetInputOutputFormat("VTK_UNSIGNED_SHORT");
190         bbSetInputInitialValue(0);
191 }
192         
193 //===== 
194 // 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)
195 //===== 
196 void CreateImage::bbUserInitializeProcessing()
197 {
198
199 //  THE INITIALIZATION METHOD BODY :
200 //    Here does nothing 
201 //    but this is where you should allocate the internal/output pointers 
202 //    if any 
203
204 //EED 2017-12-7         imageoutput = vtkImageData::New();
205
206 }
207         
208 //===== 
209 // 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)
210 //===== 
211 void CreateImage::bbUserFinalizeProcessing()
212 {
213
214 //  THE FINALIZATION METHOD BODY :
215 //    Here does nothing 
216 //    but this is where you should desallocate the internal/output pointers 
217 //    if any
218         imageoutput->Delete();
219 }
220
221 }// EO namespace bbvtk
222
223