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