1 #include "vtkImageData.h"
2 #include "vtkImageCast.h"
4 #include "vtkPolyDataMapper.h"
5 #include "vtkPolyData.h"
6 #include "vtkProperty.h"
7 #include "vtkFloatArray.h"
9 #include "vtkDataSetMapper.h"
18 Surface::Surface(vtkImageData* imageData, int ZHeight, std::string iColor)
20 surfaceResult= vtkActor::New();
23 //Original image type this case is an unsigned char (3)
24 imageType=imageData->GetScalarType();
26 //substracting the image
27 createSurface(imageData);
32 if(surfaceResult!=NULL)surfaceResult->Delete();
35 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
41 Calculate the new image and save it in the attribute imageResult
42 it is used if the user had given the imageData
44 void Surface::createSurface(vtkImageData* imageData)
46 //dimensions of the image (extent)
48 //setting the dimensionality (1d or 2d or 3d )
53 //getting the information from the original image
54 imageData->GetSpacing(spc);
55 imageData->GetExtent(ext);
58 newDim[0]=ext[1]-ext[0]+1;
59 newDim[1]=ext[3]-ext[2]+1;
60 newDim[2]=1;// in general it is ext[5]-ext[4]+1
63 //initializing the image that represents the substracted image
64 //initialize(newDim,spc);
70 Setting the values for the
72 void Surface::surface(vtkImageData* imageData)
77 surfacePoints = vtkPoints::New();
78 surfaceCells = vtkCellArray::New();
80 if(imageType == VTK_CHAR)
82 // pointers to get into the image
83 char* dataImagePointer=NULL;
85 char max = VTK_CHAR_MAX;
87 surfaceByType(dataImagePointer, imageData, max);
89 else if(imageType == VTK_SIGNED_CHAR)
91 // pointers to get into the image
92 signed char* dataImagePointer=NULL;
94 signed char max = VTK_SIGNED_CHAR_MAX;
96 surfaceByType(dataImagePointer, imageData, max);
98 else if(imageType == VTK_UNSIGNED_CHAR)
100 // pointers to get into the image
101 unsigned char* dataImagePointer=NULL;
103 unsigned char max = VTK_UNSIGNED_CHAR_MAX;
105 surfaceByType(dataImagePointer, imageData, max);
107 else if(imageType == VTK_SHORT)
109 // pointers to get into the image
110 short* dataImagePointer=NULL;
112 short max = VTK_SHORT_MAX;
114 surfaceByType(dataImagePointer, imageData, max);
116 else if(imageType == VTK_UNSIGNED_SHORT)
118 // pointers to get into the image
119 unsigned short* dataImagePointer=NULL;
121 unsigned short max = VTK_UNSIGNED_SHORT_MAX;
123 surfaceByType(dataImagePointer, imageData, max);
125 else if(imageType == VTK_INT)
127 // pointers to get into the image
128 int* dataImagePointer=NULL;
130 int max = VTK_INT_MAX;
132 surfaceByType(dataImagePointer, imageData, max);
134 else if(imageType == VTK_UNSIGNED_INT)
136 // pointers to get into the image
137 unsigned int* dataImagePointer=NULL;
139 unsigned int max = VTK_UNSIGNED_INT_MAX;
141 surfaceByType(dataImagePointer, imageData, max);
143 else if(imageType == VTK_LONG)
145 // pointers to get into the image
146 long* dataImagePointer=NULL;
148 long max = VTK_LONG_MAX;
150 surfaceByType(dataImagePointer, imageData, max);
152 else if(imageType == VTK_UNSIGNED_LONG)
154 // pointers to get into the image
155 unsigned long* dataImagePointer=NULL;
157 unsigned long max = VTK_UNSIGNED_LONG_MAX;
159 surfaceByType(dataImagePointer, imageData, max);
161 else if(imageType == VTK_FLOAT)
163 // pointers to get into the image
164 float* dataImagePointer=NULL;
166 float max = VTK_FLOAT_MAX;
168 surfaceByType(dataImagePointer, imageData, max);
170 else if(imageType == VTK_DOUBLE)
172 // pointers to get into the image
173 double* dataImagePointer=NULL;
175 double max = VTK_DOUBLE_MAX;
177 surfaceByType(dataImagePointer, imageData, max);
180 vtkPolyData* surfaceData = vtkPolyData::New();
181 surfaceData->SetPolys(surfaceCells);
182 surfaceData->SetPoints(surfacePoints);
183 surfaceData->Update();
185 vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New();
186 surfaceMapper->SetInput(surfaceData);
187 surfaceMapper->Update();
189 surfaceResult->SetMapper(surfaceMapper);
190 surfaceResult->GetProperty()->SetOpacity(1.0);
194 surfaceResult->GetProperty()->SetColor(1,0,0);
196 else if (color == "BLUE")
198 surfaceResult->GetProperty()->SetColor(0,0,1);
200 else if (color == "GREEN")
202 surfaceResult->GetProperty()->SetColor(0,1,0);
206 surfaceResult->GetProperty()->SetColor(1,1,1);
211 Template for constructing the surface by image type
214 void Surface::surfaceByType(T* dataImagePointer, vtkImageData* imageData, T max)
218 // we start where the image starts
219 dataImagePointer=(T*)imageData->GetScalarPointer(0,0,0);
225 imageData->GetExtent(ext);
234 //walking in the image
236 double sum1=0,sum2=0,sum3=0,sum4=0;
244 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
245 dataImagePointer=(T*)imageData->GetScalarPointer(i,j,k);
247 sum1=(T)(dataImagePointer[0]) + (T)(dataImagePointer[1]) + (T)(dataImagePointer[2]);
250 surfacePoints->InsertPoint(counter, i, j, sum1*height);
257 //This cycle creates the cells of the surface
265 surfaceCells->InsertNextCell(3);
266 surfaceCells->InsertCellPoint(n);
267 surfaceCells->InsertCellPoint(n+1);
268 surfaceCells->InsertCellPoint(n+sy+1);
270 surfaceCells->InsertNextCell(3);
271 surfaceCells->InsertCellPoint(n);
272 surfaceCells->InsertCellPoint(n+sy+1);
273 surfaceCells->InsertCellPoint(n+sy);
290 Returns the filtered image
292 vtkActor* Surface::getSurface()
294 return surfaceResult;