2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
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)
31 #include "bbvtkCreateImage.h"
32 #include "bbvtkPackage.h"
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CreateImage)
37 BBTK_BLACK_BOX_IMPLEMENTATION(CreateImage,bbtk::AtomicBlackBox);
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)
41 void CreateImage::Process()
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
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')
60 int outputformat = VTK_UNSIGNED_SHORT;
63 if (bbGetInputOutputFormat()=="VTK_BIT") outputformat = VTK_BIT; // 1
64 else if (bbGetInputOutputFormat()=="VTK_CHAR") outputformat = VTK_CHAR; // 2
65 else if (bbGetInputOutputFormat()=="MET_CHAR") outputformat = VTK_CHAR; // 2
66 else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR") outputformat = VTK_SIGNED_CHAR; // 15
67 else if (bbGetInputOutputFormat()=="MET_UCHAR") outputformat = VTK_UNSIGNED_CHAR; // 3
68 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR; // 3
69 else if (bbGetInputOutputFormat()=="VTK_SHORT") outputformat = VTK_SHORT; // 4
70 else if (bbGetInputOutputFormat()=="MET_SHORT") outputformat = VTK_SHORT; // 4
71 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT; // 5
72 else if (bbGetInputOutputFormat()=="MET_USHORT") outputformat = VTK_UNSIGNED_SHORT; // 5
73 else if (bbGetInputOutputFormat()=="VTK_INT") outputformat = VTK_INT; // 6
74 else if (bbGetInputOutputFormat()=="MET_INT") outputformat = VTK_INT; // 6
75 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT") outputformat = VTK_UNSIGNED_INT; // 7
76 else if (bbGetInputOutputFormat()=="MEY_UINT") outputformat = VTK_UNSIGNED_INT; // 7
77 else if (bbGetInputOutputFormat()=="VTK_LONG") outputformat = VTK_LONG; // 8
78 else if (bbGetInputOutputFormat()=="MET_LONG") outputformat = VTK_LONG; // 8
79 else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG; // 9
80 else if (bbGetInputOutputFormat()=="MET_ULONG") outputformat = VTK_UNSIGNED_LONG; // 9
81 else if (bbGetInputOutputFormat()=="VTK_FLOAT") outputformat = VTK_FLOAT; // 10
82 else if (bbGetInputOutputFormat()=="MET_FLOAT") outputformat = VTK_FLOAT; // 10
83 else if (bbGetInputOutputFormat()=="VTK_DOUBLE") outputformat = VTK_DOUBLE; // 11
84 else if (bbGetInputOutputFormat()=="MET_DOUBLE") outputformat = VTK_DOUBLE; // 11
88 spc[0] = bbGetInputSpacing()[0];
89 spc[1] = bbGetInputSpacing()[1];
90 spc[2] = bbGetInputSpacing()[2];
92 dim[0] = bbGetInputDimensions()[0];
93 dim[1] = bbGetInputDimensions()[1];
94 dim[2] = bbGetInputDimensions()[2];
96 imageoutput->Initialize();
97 imageoutput->SetScalarType( outputformat );
98 imageoutput->SetSpacing( spc );
99 imageoutput->SetDimensions( dim[0], dim[1], dim[2] );
100 imageoutput->AllocateScalars();
106 for (i=0; i<dim[0]; i++)
108 imageoutput->SetScalarComponentFromDouble(i,0,0, 0, bbGetInputInitialValue() );
111 sizeBlock= dim[0] * imageoutput->GetScalarSize();
112 for (j=1; j<dim[1]; j++)
114 memcpy( imageoutput->GetScalarPointer(0,j,0), imageoutput->GetScalarPointer() , sizeBlock );
117 sizeBlock= dim[0] * dim[1] * imageoutput->GetScalarSize();
118 for (k=0; k<dim[2]; k++)
120 memcpy( imageoutput->GetScalarPointer(0,0,k) ,imageoutput->GetScalarPointer() , sizeBlock );
123 imageoutput->Update();
124 imageoutput->Modified();
125 bbSetOutputOut(imageoutput);
131 // 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)
133 void CreateImage::bbUserSetDefaultValues()
137 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
138 std::vector<int> dim;
142 std::vector<double> spc;
147 bbSetInputDimensions(dim);
148 bbSetInputSpacing(spc);
149 bbSetInputOutputFormat("VTK_UNSIGNED_SHORT");
150 bbSetInputInitialValue(0);
154 // 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)
156 void CreateImage::bbUserInitializeProcessing()
159 // THE INITIALIZATION METHOD BODY :
161 // but this is where you should allocate the internal/output pointers
164 imageoutput = vtkImageData::New();
169 // 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)
171 void CreateImage::bbUserFinalizeProcessing()
174 // THE FINALIZATION METHOD BODY :
176 // but this is where you should desallocate the internal/output pointers
178 imageoutput->Delete();
181 }// EO namespace bbvtk