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