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