2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 #include "vtkImageData.h"
28 #include "vtkImageCast.h"
30 #include "vtkPolyDataMapper.h"
31 #include "vtkPolyData.h"
32 #include "vtkProperty.h"
33 #include "vtkFloatArray.h"
35 #include "vtkDataSetMapper.h"
44 Surface::Surface(vtkImageData* imageData, int ZHeight, std::string iColor)
46 surfaceResult= vtkActor::New();
49 //Original image type this case is an unsigned char (3)
50 imageType=imageData->GetScalarType();
52 //substracting the image
53 createSurface(imageData);
58 if(surfaceResult!=NULL)surfaceResult->Delete();
61 //----------------------------------------------------------------------------
63 //----------------------------------------------------------------------------
67 Calculate the new image and save it in the attribute imageResult
68 it is used if the user had given the imageData
70 void Surface::createSurface(vtkImageData* imageData)
72 //dimensions of the image (extent)
74 //setting the dimensionality (1d or 2d or 3d )
79 //getting the information from the original image
80 imageData->GetSpacing(spc);
81 imageData->GetExtent(ext);
84 newDim[0]=ext[1]-ext[0]+1;
85 newDim[1]=ext[3]-ext[2]+1;
86 newDim[2]=1;// in general it is ext[5]-ext[4]+1
89 //initializing the image that represents the substracted image
90 //initialize(newDim,spc);
96 Setting the values for the
98 void Surface::surface(vtkImageData* imageData)
103 surfacePoints = vtkPoints::New();
104 surfaceCells = vtkCellArray::New();
106 if(imageType == VTK_CHAR)
108 // pointers to get into the image
109 char* dataImagePointer=NULL;
111 char max = VTK_CHAR_MAX;
113 surfaceByType(dataImagePointer, imageData, max);
115 else if(imageType == VTK_SIGNED_CHAR)
117 // pointers to get into the image
118 signed char* dataImagePointer=NULL;
120 signed char max = VTK_SIGNED_CHAR_MAX;
122 surfaceByType(dataImagePointer, imageData, max);
124 else if(imageType == VTK_UNSIGNED_CHAR)
126 // pointers to get into the image
127 unsigned char* dataImagePointer=NULL;
129 unsigned char max = VTK_UNSIGNED_CHAR_MAX;
131 surfaceByType(dataImagePointer, imageData, max);
133 else if(imageType == VTK_SHORT)
135 // pointers to get into the image
136 short* dataImagePointer=NULL;
138 short max = VTK_SHORT_MAX;
140 surfaceByType(dataImagePointer, imageData, max);
142 else if(imageType == VTK_UNSIGNED_SHORT)
144 // pointers to get into the image
145 unsigned short* dataImagePointer=NULL;
147 unsigned short max = VTK_UNSIGNED_SHORT_MAX;
149 surfaceByType(dataImagePointer, imageData, max);
151 else if(imageType == VTK_INT)
153 // pointers to get into the image
154 int* dataImagePointer=NULL;
156 int max = VTK_INT_MAX;
158 surfaceByType(dataImagePointer, imageData, max);
160 else if(imageType == VTK_UNSIGNED_INT)
162 // pointers to get into the image
163 unsigned int* dataImagePointer=NULL;
165 unsigned int max = VTK_UNSIGNED_INT_MAX;
167 surfaceByType(dataImagePointer, imageData, max);
169 else if(imageType == VTK_LONG)
171 // pointers to get into the image
172 long* dataImagePointer=NULL;
174 long max = VTK_LONG_MAX;
176 surfaceByType(dataImagePointer, imageData, max);
178 else if(imageType == VTK_UNSIGNED_LONG)
180 // pointers to get into the image
181 unsigned long* dataImagePointer=NULL;
183 unsigned long max = VTK_UNSIGNED_LONG_MAX;
185 surfaceByType(dataImagePointer, imageData, max);
187 else if(imageType == VTK_FLOAT)
189 // pointers to get into the image
190 float* dataImagePointer=NULL;
192 float max = VTK_FLOAT_MAX;
194 surfaceByType(dataImagePointer, imageData, max);
196 else if(imageType == VTK_DOUBLE)
198 // pointers to get into the image
199 double* dataImagePointer=NULL;
201 double max = VTK_DOUBLE_MAX;
203 surfaceByType(dataImagePointer, imageData, max);
206 vtkPolyData* surfaceData = vtkPolyData::New();
207 surfaceData->SetPolys(surfaceCells);
208 surfaceData->SetPoints(surfacePoints);
209 surfaceData->Update();
211 vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New();
212 surfaceMapper->SetInput(surfaceData);
213 surfaceMapper->Update();
215 surfaceResult->SetMapper(surfaceMapper);
216 surfaceResult->GetProperty()->SetOpacity(1.0);
220 surfaceResult->GetProperty()->SetColor(1,0,0);
222 else if (color == "BLUE")
224 surfaceResult->GetProperty()->SetColor(0,0,1);
226 else if (color == "GREEN")
228 surfaceResult->GetProperty()->SetColor(0,1,0);
232 surfaceResult->GetProperty()->SetColor(1,1,1);
237 Template for constructing the surface by image type
240 void Surface::surfaceByType(T* dataImagePointer, vtkImageData* imageData, T max)
244 // we start where the image starts
245 dataImagePointer=(T*)imageData->GetScalarPointer(0,0,0);
251 imageData->GetExtent(ext);
260 //walking in the image
263 //double sum2=0,sum3=0,sum4=0; // JPR : unused
271 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
272 dataImagePointer=(T*)imageData->GetScalarPointer(i,j,k);
274 sum1=(T)(dataImagePointer[0]) + (T)(dataImagePointer[1]) + (T)(dataImagePointer[2]);
277 surfacePoints->InsertPoint(counter, i, j, sum1*height);
284 //This cycle creates the cells of the surface
292 surfaceCells->InsertNextCell(3);
293 surfaceCells->InsertCellPoint(n);
294 surfaceCells->InsertCellPoint(n+1);
295 surfaceCells->InsertCellPoint(n+sy+1);
297 surfaceCells->InsertNextCell(3);
298 surfaceCells->InsertCellPoint(n);
299 surfaceCells->InsertCellPoint(n+sy+1);
300 surfaceCells->InsertCellPoint(n+sy);
317 Returns the filtered image
319 vtkActor* Surface::getSurface()
321 return surfaceResult;