]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkCreateImage.cxx
Feature #1774
[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         
57         double  spc[6];
58         int             dim[3]; 
59         int             outputformat = VTK_UNSIGNED_SHORT;
60         
61         if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;
62         else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;
63         else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;
64         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;
65         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;
66         else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;
67         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;
68         else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;
69         else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;
70         else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;
71         else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;
72                 
73         spc[0] = bbGetInputSpacing()[0];
74         spc[1] = bbGetInputSpacing()[1];
75         spc[2] = bbGetInputSpacing()[2];
76         
77         dim[0] =  bbGetInputDimensions()[0];
78         dim[1] =  bbGetInputDimensions()[1];
79         dim[2] =  bbGetInputDimensions()[2];
80         
81         imageoutput->Initialize();
82         imageoutput->SetScalarType( outputformat );     
83         imageoutput->SetSpacing( spc );
84         imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
85         imageoutput->AllocateScalars();
86         
87                 
88                 int i,j,k;
89                 for (i=0; i<dim[0]; i++)
90                 {
91                         for (j=0; j<dim[1]; j++)
92                         {
93                                 for (k=0; k<dim[2]; k++)
94                                 {
95                                         imageoutput->SetScalarComponentFromDouble(i,j,k, 0, bbGetInputInitialValue() );
96                                 } // for k
97                         } // for j
98                 } // for i
99                 
100                 bbSetOutputOut(imageoutput);
101
102 }       
103         
104 //===== 
105 // 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)
106 //===== 
107 void CreateImage::bbUserSetDefaultValues()
108 {
109         imageoutput=NULL;
110
111 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
112         std::vector<int> dim;
113         dim.push_back(250);
114         dim.push_back(250);
115         dim.push_back(250);
116         std::vector<double> spc;
117         dim.push_back(1.0);
118         dim.push_back(1.0);
119         dim.push_back(1.0);
120         
121         bbSetInputDimensions(dim);
122         bbSetInputSpacing(spc);
123         bbSetInputOutputFormat("VTK_UNSIGNED_SHORT");
124         bbSetInputInitialValue(0);
125 }
126         
127 //===== 
128 // 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)
129 //===== 
130 void CreateImage::bbUserInitializeProcessing()
131 {
132
133 //  THE INITIALIZATION METHOD BODY :
134 //    Here does nothing 
135 //    but this is where you should allocate the internal/output pointers 
136 //    if any 
137
138         imageoutput = vtkImageData::New();
139
140 }
141         
142 //===== 
143 // 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)
144 //===== 
145 void CreateImage::bbUserFinalizeProcessing()
146 {
147
148 //  THE FINALIZATION METHOD BODY :
149 //    Here does nothing 
150 //    but this is where you should desallocate the internal/output pointers 
151 //    if any
152         imageoutput->Delete();
153
154 }
155 }
156 // EO namespace bbvtk
157
158