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