]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCreateImage.cxx
#3385 BBTK Bug New Normal - box FilesFromDirectory CreateImage InvertCrop ComboBox...
[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
61         if (imageoutput!=NULL) 
62         {
63                 imageoutput->Delete();
64                 imageoutput = NULL;
65         } // if imageoutput
66
67         if ( !((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0)) )
68         {
69                 double  spc[3];
70                 int             outputformat = VTK_UNSIGNED_SHORT;
71                 spc[0] = bbGetInputSpacing()[0];
72                 spc[1] = bbGetInputSpacing()[1];
73                 spc[2] = bbGetInputSpacing()[2];
74                 if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;                 // 1
75                 else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;                                // 2
76                 else if (bbGetInputOutputFormat()=="MET_CHAR")                          outputformat = VTK_CHAR;                                // 2
77                 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;         // 15
78                 else if (bbGetInputOutputFormat()=="MET_UCHAR")                         outputformat = VTK_UNSIGNED_CHAR;       // 3
79                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;       // 3
80                 else if (bbGetInputOutputFormat()=="VTK_SHORT")                         outputformat = VTK_SHORT;               // 4
81                 else if (bbGetInputOutputFormat()=="MET_SHORT")                         outputformat = VTK_SHORT;               // 4
82                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;      // 5
83                 else if (bbGetInputOutputFormat()=="MET_USHORT")                        outputformat = VTK_UNSIGNED_SHORT;      // 5
84                 else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;                 // 6
85                 else if (bbGetInputOutputFormat()=="MET_INT")                           outputformat = VTK_INT;                 // 6
86                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;        // 7 
87                 else if (bbGetInputOutputFormat()=="MEY_UINT")                          outputformat = VTK_UNSIGNED_INT;        // 7 
88                 else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;                // 8
89                 else if (bbGetInputOutputFormat()=="MET_LONG")                          outputformat = VTK_LONG;                // 8
90                 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;       // 9
91                 else if (bbGetInputOutputFormat()=="MET_ULONG")                         outputformat = VTK_UNSIGNED_LONG;       // 9
92                 else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;               // 10
93                 else if (bbGetInputOutputFormat()=="MET_FLOAT")                         outputformat = VTK_FLOAT;               // 10
94                 else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11           
95                 else if (bbGetInputOutputFormat()=="MET_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11  
96
97                 if ((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0))
98                 {
99                         dim[0]=1;
100                         dim[1]=1;
101                         dim[2]=1;
102                 }
103                 if ((spc[0]<=0)||(spc[1]<=0)||(spc[2]<=0))
104                 {
105                         spc[0]=1;
106                         spc[1]=1;
107                         spc[2]=1;
108                 }
109                 imageoutput = vtkImageData::New();
110                 imageoutput->Initialize();
111                 imageoutput->SetSpacing( spc );
112                 imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
113
114         //EED 2017-01-01 Migration VTK7
115         #if (VTK_MAJOR_VERSION <= 5) 
116                 imageoutput->SetScalarType( outputformat );     
117                 imageoutput->AllocateScalars();
118         #endif
119         #if (VTK_MAJOR_VERSION >= 6) 
120                 imageoutput->AllocateScalars( outputformat,1 );
121         #endif
122                 
123                 int i,j,k;
124                 long sizeBlock; 
125
126                 for (i=0; i<dim[0]; i++)
127                 {
128                         imageoutput->SetScalarComponentFromDouble(i,0,0, 0, bbGetInputInitialValue() );
129                 } // for i
130                 
131                 sizeBlock= dim[0] * imageoutput->GetScalarSize();
132                 for (j=1; j<dim[1]; j++)
133                 {
134                         memcpy(  imageoutput->GetScalarPointer(0,j,0), imageoutput->GetScalarPointer()  , sizeBlock );
135                 } // for j              
136
137                 sizeBlock= dim[0] * dim[1] * imageoutput->GetScalarSize();
138                 for (k=0; k<dim[2]; k++)
139                 {
140                         memcpy(  imageoutput->GetScalarPointer(0,0,k) ,imageoutput->GetScalarPointer()  , sizeBlock );
141                 } // for k
142                 
143
144         //EED 2017-01-01 Migration VTK7
145         #if (VTK_MAJOR_VERSION <= 5) 
146                 imageoutput->Update();
147         #endif
148         #if (VTK_MAJOR_VERSION >= 6) 
149                 // ..
150         #endif
151                 imageoutput->Modified();
152         } // if dim = 0
153
154         bbSetOutputOut(imageoutput);
155 }       
156         
157 //===== 
158 // 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)
159 //===== 
160 void CreateImage::bbUserSetDefaultValues()
161 {
162         imageoutput=NULL;
163
164 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
165         std::vector<int> dim;
166         dim.push_back(250);
167         dim.push_back(250);
168         dim.push_back(250);
169         std::vector<double> spc;
170         spc.push_back(1.0);
171         spc.push_back(1.0);
172         spc.push_back(1.0);
173         
174         bbSetInputDimensions(dim);
175         bbSetInputSpacing(spc);
176         bbSetInputOutputFormat("VTK_UNSIGNED_SHORT");
177         bbSetInputInitialValue(0);
178 }
179         
180 //===== 
181 // 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)
182 //===== 
183 void CreateImage::bbUserInitializeProcessing()
184 {
185
186 //  THE INITIALIZATION METHOD BODY :
187 //    Here does nothing 
188 //    but this is where you should allocate the internal/output pointers 
189 //    if any 
190
191 //EED 2017-12-7         imageoutput = vtkImageData::New();
192
193 }
194         
195 //===== 
196 // 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)
197 //===== 
198 void CreateImage::bbUserFinalizeProcessing()
199 {
200
201 //  THE FINALIZATION METHOD BODY :
202 //    Here does nothing 
203 //    but this is where you should desallocate the internal/output pointers 
204 //    if any
205         imageoutput->Delete();
206 }
207
208 }// EO namespace bbvtk
209
210