]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSliceImage.cxx
#3194 BBTK Feature New Normal - Update surfaceTexture box with new lookuptables
[bbtk.git] / packages / vtk / src / bbvtkSliceImage.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 "bbvtkSliceImage.h"
29 #include "bbvtkPackage.h"
30 namespace bbvtk
31 {
32
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SliceImage)
34 BBTK_BLACK_BOX_IMPLEMENTATION(SliceImage,bbtk::AtomicBlackBox);
35 void SliceImage::Process()
36 {
37
38 printf("EED ********************************** bbtk-box vtk:SliceImage (Deprecated)\n");
39 printf("EED **********************************   >> use bbtk-box creaMaracasVisu:SliceImage \n");
40         vtkImageData* original = bbGetInputIn();
41
42         if (original == NULL)
43         {
44                 std::cout << "Set In" << std::endl;
45                 return;
46         }
47
48         //if (lastId == bbGetInputZ())
49         //      return;
50
51         int z = bbGetInputZ();
52         int max_z;
53
54         int ext[6];
55         int newDim[3];
56         double space[3];
57         double origin[3];
58
59         original->GetSpacing(space);
60         original->GetExtent(ext);
61         original->GetOrigin(origin);
62         original->GetDimensions(newDim);
63         max_z = newDim[2];
64         newDim[2] = 1;
65
66         int scalar_type = original->GetScalarType();
67
68         if (final == NULL)
69         {
70                 final = vtkImageData::New();
71                 final->SetSpacing(space);
72                 final->SetDimensions(newDim);
73                 final->SetScalarType(scalar_type);
74                 final->AllocateScalars();
75                 final->Update();
76         }
77
78         bbSetOutputMax(max_z);
79
80         if (z>=max_z)
81         {
82                 z = max_z-1;
83         }
84
85         for (int i=0; i<newDim[0]; i++){
86                 for (int j=0; j<newDim[1]; j++){
87                         switch (scalar_type)
88                         {
89                                 case VTK_CHAR:
90                                         char * ap2;
91                                         ap2 = (char *) final->GetScalarPointer(i,j,0);
92                                         *ap2 = *((char*) (original->GetScalarPointer(i,j,z)));
93                                 break;
94                                 case VTK_UNSIGNED_CHAR:
95                                         unsigned char * ap3;
96                                         ap3 = (unsigned char *) final->GetScalarPointer(i,j,0);
97                                         *ap3 = *((unsigned char *)(original->GetScalarPointer(i,j,z)));
98                                 break;
99                                 case VTK_SHORT:
100                                         short * ap4;
101                                         ap4 = (short *) final->GetScalarPointer(i,j,0);
102                                         *ap4 = *((short *)(original->GetScalarPointer(i,j,z)));
103                                 break;
104                                 case VTK_UNSIGNED_SHORT:
105                                         unsigned short * ap5;
106                                         ap5 = (unsigned short *) final->GetScalarPointer(i,j,0);
107                                         *ap5 = *((unsigned short *)(original->GetScalarPointer(i,j,z)));
108                                 break;
109                                 case VTK_INT:
110                                         int * ap6;
111                                         ap6 = (int *) final->GetScalarPointer(i,j,0);
112                                         *ap6 = *((int *)(original->GetScalarPointer(i,j,z)));
113                                 break;
114                                 case VTK_UNSIGNED_INT:
115                                         unsigned int * ap7;
116                                         ap7 = (unsigned int *) final->GetScalarPointer(i,j,0);
117                                         *ap7 = *((unsigned int *)(original->GetScalarPointer(i,j,z)));
118                                 break;
119                                 case VTK_LONG:
120                                         long * ap8;
121                                         ap8 = (long *) final->GetScalarPointer(i,j,0);
122                                         *ap8 = *((long *)(original->GetScalarPointer(i,j,z)));
123                                 break;
124                                 case VTK_UNSIGNED_LONG:
125                                         unsigned long * ap9;
126                                         ap9 = (unsigned long *) final->GetScalarPointer(i,j,0);
127                                         *ap9 = *((unsigned long *)(original->GetScalarPointer(i,j,z)));
128                                 break;
129                                 case VTK_FLOAT:
130                                         float * ap10;
131                                         ap10 = (float *) final->GetScalarPointer(i,j,0);
132                                         *ap10 = *((float *)(original->GetScalarPointer(i,j,z)));
133                                 break;
134                                 case VTK_DOUBLE:
135                                         double * ap11;
136                                         ap11 = (double *) final->GetScalarPointer(i,j,0);
137                                         *ap11 = *((double *)(original->GetScalarPointer(i,j,z)));
138                                 break;
139                         }
140                 }
141         }
142
143         caster = vtkImageCast::New();
144         caster->SetInput(final);
145         caster->SetOutputScalarTypeToShort();
146         caster->Update();
147
148         bbSetOutputOut(caster->GetOutput());
149
150         std::cout << "updated slice " << z << std::endl;
151         bbSignalOutputModification();
152         lastId = bbGetInputZ();
153 }
154 void SliceImage::bbUserSetDefaultValues()
155 {
156
157 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
158 //    Here we initialize the input 'In' to 0
159    bbSetInputIn(NULL);
160    bbSetOutputOut(NULL);
161    final = NULL;
162
163 }
164 void SliceImage::bbUserInitializeProcessing()
165 {
166
167 //  THE INITIALIZATION METHOD BODY :
168 //    Here does nothing
169 //    but this is where you should allocate the internal/output pointers
170 //    if any
171
172
173 }
174 void SliceImage::bbUserFinalizeProcessing()
175 {
176
177 //  THE FINALIZATION METHOD BODY :
178 //    Here does nothing
179 //    but this is where you should desallocate the internal/output pointers
180 //    if any
181
182 }
183 }
184 // EO namespace bbvtk
185
186