]> Creatis software - bbtk.git/blob - packages/vtk/src/bbtkStaticLecture.cxx
e166919ed9f2b09e368ab4ca7ce63cddc105a2f3
[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
31         void bbtkStaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value)
32         {
33                 //double rta;
34                 int scalar_type = img->GetScalarType();
35                 int* ext = img->GetExtent();
36                 if (i < ext[0])
37                         return;
38                 if (i > ext[1])
39                         return;
40
41                 if (j < ext[2])
42                         return;
43                 if (j > ext[3])
44                         return;
45
46                 if (k < ext[4])
47                         return;
48                 if (k > ext[5])
49                         return;
50
51                 switch (scalar_type)
52                 {
53                         case VTK_CHAR:
54                                 char * ap2;
55                                 ap2 = (char *) img->GetScalarPointer(i,j,k);
56                                 *ap2 = (char) value;
57                         break;
58                         case VTK_UNSIGNED_CHAR:
59                                 unsigned char * ap3;
60                                 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
61                                 *ap3 = (unsigned char) value;
62                         break;
63                         case VTK_SHORT:
64                                 short * ap4;
65                                 ap4 = (short *) img->GetScalarPointer(i,j,k);
66                                 *ap4 = (short) value;
67                         break;
68                         case VTK_UNSIGNED_SHORT:
69                                 unsigned short * ap5;
70                                 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
71                                 *ap5 = (unsigned short) value;
72                         break;
73                         case VTK_INT:
74                                 int * ap6;
75                                 ap6 = (int *) img->GetScalarPointer(i,j,k);
76                                 *ap6 = (int) value;
77                         break;
78                         case VTK_UNSIGNED_INT:
79                                 unsigned int * ap7;
80                                 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
81                                 *ap7 = (unsigned int) value;
82                         break;
83                         case VTK_LONG:
84                                 long * ap8;
85                                 ap8 = (long *) img->GetScalarPointer(i,j,k);
86                                 *ap8 = (long) value;
87                         break;
88                         case VTK_UNSIGNED_LONG:
89                                 unsigned long * ap9;
90                                 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
91                                 *ap9 = (unsigned long) value;
92                         break;
93                         case VTK_FLOAT:
94                                 float * ap10;
95                                 ap10 = (float *) img->GetScalarPointer(i,j,k);
96                                 *ap10 = (float) value;
97                         break;
98                         case VTK_DOUBLE:
99                                 double * ap11;
100                                 ap11 = (double *) img->GetScalarPointer(i,j,k);
101                                 *ap11 = (double) value;
102                         break;
103                 }
104         }
105         double bbtkStaticLecture::getPixelValue(int i, int j, int k, vtkImageData* img)
106         {
107                 double rta;
108                 int scalar_type = img->GetScalarType();
109                 int* ext = img->GetExtent();
110                 if (i < ext[0])
111                         i=ext[0];
112                 if (i > ext[1])
113                         i=ext[1];
114
115                 if (j < ext[2])
116                         j=ext[2];
117                 if (j > ext[3])
118                         j=ext[3];
119
120                 if (k < ext[4])
121                         k=ext[4];
122                 if (k > ext[5])
123                         k=ext[5];
124
125                 switch (scalar_type)
126                 {
127                         case VTK_CHAR:
128                                 char * ap2;
129                                 ap2 = (char *) img->GetScalarPointer(i,j,k);
130                                 rta = (double) *ap2;
131                         break;
132                         case VTK_UNSIGNED_CHAR:
133                                 unsigned char * ap3;
134                                 ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
135                                 rta = (double) *ap3;
136                         break;
137                         case VTK_SHORT:
138                                 short * ap4;
139                                 ap4 = (short *) img->GetScalarPointer(i,j,k);
140                                 rta = (double) *ap4;
141                         break;
142                         case VTK_UNSIGNED_SHORT:
143                                 unsigned short * ap5;
144                                 ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
145                                 rta = (double) *ap5;
146                         break;
147                         case VTK_INT:
148                                 int * ap6;
149                                 ap6 = (int *) img->GetScalarPointer(i,j,k);
150                                 rta = (double) *ap6;
151                         break;
152                         case VTK_UNSIGNED_INT:
153                                 unsigned int * ap7;
154                                 ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
155                                 rta = (double) *ap7;
156                         break;
157                         case VTK_LONG:
158                                 long * ap8;
159                                 ap8 = (long *) img->GetScalarPointer(i,j,k);
160                                 rta = (double) *ap8;
161                         break;
162                         case VTK_UNSIGNED_LONG:
163                                 unsigned long * ap9;
164                                 ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
165                                 rta = (double) *ap9;
166                         break;
167                         case VTK_FLOAT:
168                                 float * ap10;
169                                 ap10 = (float *) img->GetScalarPointer(i,j,k);
170                                 rta = (double) *ap10;
171                         break;
172                         case VTK_DOUBLE:
173                                 double * ap11;
174                                 ap11 = (double *) img->GetScalarPointer(i,j,k);
175                                 rta = (double) *ap11;
176                         break;
177                 }
178                 return rta;
179         }