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