]> Creatis software - bbtk.git/blob - packages/vtk/src/bbtkStaticLecture.cxx
#2981 BBTK Feature New Normal - FormatOutput of filters in string
[bbtk.git] / packages / vtk / src / bbtkStaticLecture.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 #include "bbtkStaticLecture.h"
29
30 #include <string>
31
32 int bbtkStaticLecture::GetTypeFormat( std::string formatStr , vtkImageData* image )
33 {
34         int outputformat = VTK_UNSIGNED_CHAR;
35         if (formatStr=="SAME")
36         {                                               
37                 if (image!=NULL) outputformat = image->GetScalarType();
38         }
39         else if (formatStr=="VTK_BIT")                          outputformat = VTK_BIT;                         // 1
40         else if (formatStr=="VTK_CHAR")                         outputformat = VTK_CHAR;                        // 2
41         else if (formatStr=="VTK_SIGNED_CHAR")          outputformat = VTK_SIGNED_CHAR;         // 15
42         else if (formatStr=="VTK_UNSIGNED_CHAR")        outputformat = VTK_UNSIGNED_CHAR;       // 3
43         else if (formatStr=="VTK_SHORT")                        outputformat = VTK_SHORT;                       // 4
44         else if (formatStr=="VTK_UNSIGNED_SHORT")       outputformat = VTK_UNSIGNED_SHORT;      // 5
45         else if (formatStr=="VTK_INT")                          outputformat = VTK_INT;                 // 6
46         else if (formatStr=="VTK_UNSIGNED_INT")         outputformat = VTK_UNSIGNED_INT;        // 7
47         else if (formatStr=="VTK_LONG")                         outputformat = VTK_LONG;                // 8  
48         else if (formatStr=="VTK_UNSIGNED_LONG")        outputformat = VTK_UNSIGNED_LONG;       // 9
49         else if (formatStr=="VTK_FLOAT")                        outputformat = VTK_FLOAT;               // 10
50         else if (formatStr=="VTK_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11 
51         else if (formatStr=="MET_CHAR")                         outputformat = VTK_CHAR;                        // 2
52         else if (formatStr=="MET_UCHAR")                        outputformat = VTK_UNSIGNED_CHAR;       // 3
53         else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;                       // 4
54         else if (formatStr=="MET_USHORT")                       outputformat = VTK_UNSIGNED_SHORT;      // 5
55         else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;               // 4
56         else if (formatStr=="MET_FLOAT")                        outputformat = VTK_FLOAT;               // 10
57         else if (formatStr=="MET_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11  
58
59     return outputformat;
60 }
61
62
63
64         void bbtkStaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value)
65         {
66                 //double rta;
67                 int scalar_type = img->GetScalarType();
68                 int* ext = img->GetExtent();
69                 if (i < ext[0])
70                         return;
71                 if (i > ext[1])
72                         return;
73
74                 if (j < ext[2])
75                         return;
76                 if (j > ext[3])
77                         return;
78
79                 if (k < ext[4])
80                         return;
81                 if (k > ext[5])
82                         return;
83
84                 switch (scalar_type)
85                 {
86                         case VTK_CHAR:
87                                 char * ap2;
88                                 ap2 = (char *) img->GetScalarPointer(i,j,k);
89                                 *ap2 = (char) value;
90                         break;
91                         case VTK_UNSIGNED_CHAR:
92                                 unsigned char * ap3;
93                                 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
94                                 *ap3 = (unsigned char) value;
95                         break;
96                         case VTK_SHORT:
97                                 short * ap4;
98                                 ap4 = (short *) img->GetScalarPointer(i,j,k);
99                                 *ap4 = (short) value;
100                         break;
101                         case VTK_UNSIGNED_SHORT:
102                                 unsigned short * ap5;
103                                 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
104                                 *ap5 = (unsigned short) value;
105                         break;
106                         case VTK_INT:
107                                 int * ap6;
108                                 ap6 = (int *) img->GetScalarPointer(i,j,k);
109                                 *ap6 = (int) value;
110                         break;
111                         case VTK_UNSIGNED_INT:
112                                 unsigned int * ap7;
113                                 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
114                                 *ap7 = (unsigned int) value;
115                         break;
116                         case VTK_LONG:
117                                 long * ap8;
118                                 ap8 = (long *) img->GetScalarPointer(i,j,k);
119                                 *ap8 = (long) value;
120                         break;
121                         case VTK_UNSIGNED_LONG:
122                                 unsigned long * ap9;
123                                 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
124                                 *ap9 = (unsigned long) value;
125                         break;
126                         case VTK_FLOAT:
127                                 float * ap10;
128                                 ap10 = (float *) img->GetScalarPointer(i,j,k);
129                                 *ap10 = (float) value;
130                         break;
131                         case VTK_DOUBLE:
132                                 double * ap11;
133                                 ap11 = (double *) img->GetScalarPointer(i,j,k);
134                                 *ap11 = (double) value;
135                         break;
136                 }
137         }
138         double bbtkStaticLecture::getPixelValue(int i, int j, int k, vtkImageData* img)
139         {
140                 double rta;
141                 int scalar_type = img->GetScalarType();
142                 int* ext = img->GetExtent();
143                 if (i < ext[0])
144                         i=ext[0];
145                 if (i > ext[1])
146                         i=ext[1];
147
148                 if (j < ext[2])
149                         j=ext[2];
150                 if (j > ext[3])
151                         j=ext[3];
152
153                 if (k < ext[4])
154                         k=ext[4];
155                 if (k > ext[5])
156                         k=ext[5];
157
158                 switch (scalar_type)
159                 {
160                         case VTK_CHAR:
161                                 char * ap2;
162                                 ap2 = (char *) img->GetScalarPointer(i,j,k);
163                                 rta = (double) *ap2;
164                         break;
165                         case VTK_UNSIGNED_CHAR:
166                                 unsigned char * ap3;
167                                 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
168                                 rta = (double) *ap3;
169                         break;
170                         case VTK_SHORT:
171                                 short * ap4;
172                                 ap4 = (short *) img->GetScalarPointer(i,j,k);
173                                 rta = (double) *ap4;
174                         break;
175                         case VTK_UNSIGNED_SHORT:
176                                 unsigned short * ap5;
177                                 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
178                                 rta = (double) *ap5;
179                         break;
180                         case VTK_INT:
181                                 int * ap6;
182                                 ap6 = (int *) img->GetScalarPointer(i,j,k);
183                                 rta = (double) *ap6;
184                         break;
185                         case VTK_UNSIGNED_INT:
186                                 unsigned int * ap7;
187                                 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
188                                 rta = (double) *ap7;
189                         break;
190                         case VTK_LONG:
191                                 long * ap8;
192                                 ap8 = (long *) img->GetScalarPointer(i,j,k);
193                                 rta = (double) *ap8;
194                         break;
195                         case VTK_UNSIGNED_LONG:
196                                 unsigned long * ap9;
197                                 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
198                                 rta = (double) *ap9;
199                         break;
200                         case VTK_FLOAT:
201                                 float * ap10;
202                                 ap10 = (float *) img->GetScalarPointer(i,j,k);
203                                 rta = (double) *ap10;
204                         break;
205                         case VTK_DOUBLE:
206                                 double * ap11;
207                                 ap11 = (double *) img->GetScalarPointer(i,j,k);
208                                 rta = (double) *ap11;
209                         break;
210                 }
211                 return rta;
212         }