]> Creatis software - creaRigidRegistration.git/blob - lib/Surface.cxx
New items
[creaRigidRegistration.git] / lib / Surface.cxx
1 #include "vtkImageData.h"
2 #include "vtkImageCast.h"
3 #include "vtkActor.h"
4 #include "vtkPoints.h"
5 #include "vtkPolyDataMapper.h"
6 #include "vtkPolyData.h"
7 #include "vtkProperty.h"
8 #include "vtkFloatArray.h"
9 #include "vtkType.h"
10 #include "vtkDataSetMapper.h"
11 #include "vtkCellArray.h"
12
13 #include "Surface.h"
14
15 #include <iostream>
16 #include <fstream>
17 #include <string>
18 #include <vector>
19
20 Surface::Surface(vtkImageData* imageData, int ZHeight, std::string iColor)
21 {
22         surfaceResult= vtkActor::New();
23         height=ZHeight;
24         color=iColor;   
25         //Original image type this case is an unsigned char (3)
26         imageType=imageData->GetScalarType();
27
28         //substracting the image
29         createSurface(imageData);
30 }
31
32 Surface::~Surface()
33 {
34         if(surfaceResult!=NULL)surfaceResult->Delete();
35 }
36
37 //----------------------------------------------------------------------------
38 // Methods
39 //----------------------------------------------------------------------------
40
41
42 /*
43 Calculate the new image and save it in the attribute imageResult
44 it is used if the user had given the imageData
45 */
46 void Surface::createSurface(vtkImageData* imageData)
47 {
48         //dimensions of the image (extent)
49         int ext[6];
50         //setting the dimensionality (1d or 2d or 3d )
51     int newDim[3];
52         //image spacing
53     double spc[3];
54   
55         //getting the information from the original image
56         imageData->GetSpacing(spc);
57         imageData->GetExtent(ext);
58         
59         //this a 2d image
60         newDim[0]=ext[1]-ext[0]+1;
61     newDim[1]=ext[3]-ext[2]+1;
62     newDim[2]=1;// in general it is ext[5]-ext[4]+1
63
64
65         //initializing the image that represents the substracted image
66         //initialize(newDim,spc);
67         //Time to substract
68         surface(imageData);     
69 }
70
71 /*
72          Setting the values for the
73 */
74 void Surface::surface(vtkImageData* imageData)
75 {
76         /*
77                 images pointers
78         */
79         vtkPoints* surfacePoints = vtkPoints::New();
80         vtkCellArray* surfaceCells = vtkCellArray::New();
81         int counter=0;
82
83         if(imageType == VTK_CHAR)
84         {
85                 // pointers to get into the image
86         char* dataImagePointer=NULL;
87         
88         // we start where the  image starts
89         dataImagePointer=(char*)imageData->GetScalarPointer(0,0,0);     
90         
91         /*
92          Image Size
93         */
94         int ext[6];
95         imageData->GetExtent(ext);
96         int sx,sy,sz;
97         sx=ext[1]-ext[0]+1;
98         sy=ext[3]-ext[2]+1;
99         sz=ext[5]-ext[4]+1;
100
101         //-----------------
102         //A3
103         //-----------------
104         //walking in the image
105         int i=0,j=0,k=0;
106         double sum1=0,sum2=0,sum3=0,sum4=0;     
107         for(i=0;i<sx;i++)
108         {
109                 for(j=0;j<sy;j++)
110                 {
111                         for(k=0;k<sz;k++)
112                         {
113                                 
114                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
115                                 dataImagePointer=(char*)imageData->GetScalarPointer(i,j,k);                             
116
117                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
118                                 sum1=sum1/(3*VTK_CHAR_MAX);                             
119
120                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
121
122                                 counter ++;
123                         }
124                 }
125         }
126
127         //This cycle creates the cells of the surface
128         int n =0;       
129         for(i=0;i<sx-1;i++)
130         {
131                 for(j=0;j<sy-1;j++)
132                 {
133                         for(k=0;k<sz;k++)
134                         {
135                                 surfaceCells->InsertNextCell(3);
136                                 surfaceCells->InsertCellPoint(n);
137                                 surfaceCells->InsertCellPoint(n+1);
138                                 surfaceCells->InsertCellPoint(n+sy+1);
139
140                                 surfaceCells->InsertNextCell(3);
141                                 surfaceCells->InsertCellPoint(n);
142                                 surfaceCells->InsertCellPoint(n+sy+1);
143                                 surfaceCells->InsertCellPoint(n+sy);
144
145                                 if(j<sy-2)
146                                 {
147                                         n++;
148                                 }
149                                 else
150                                 {
151                                         n=n+2;
152                                 }
153                                 
154                         }
155                 }
156         }               
157         }
158         else if(imageType == VTK_SIGNED_CHAR)
159         {
160                         // pointers to get into the image
161         signed char* dataImagePointer=NULL;
162         
163         // we start where the  image starts
164         dataImagePointer=(signed char*)imageData->GetScalarPointer(0,0,0);      
165         
166         /*
167          Image Size
168         */
169         int ext[6];
170         imageData->GetExtent(ext);
171         int sx,sy,sz;
172         sx=ext[1]-ext[0]+1;
173         sy=ext[3]-ext[2]+1;
174         sz=ext[5]-ext[4]+1;
175
176         //-----------------
177         //A3
178         //-----------------
179         //walking in the image
180         int i=0,j=0,k=0;
181         double sum1=0,sum2=0,sum3=0,sum4=0;     
182         for(i=0;i<sx;i++)
183         {
184                 for(j=0;j<sy;j++)
185                 {
186                         for(k=0;k<sz;k++)
187                         {
188                                 
189                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
190                                 dataImagePointer=(signed char*)imageData->GetScalarPointer(i,j,k);                              
191
192                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
193                                 sum1=sum1/(3*VTK_SIGNED_CHAR_MAX);                              
194
195                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
196
197                                 counter ++;
198                         }
199                 }
200         }
201
202         //This cycle creates the cells of the surface
203         int n =0;       
204         for(i=0;i<sx-1;i++)
205         {
206                 for(j=0;j<sy-1;j++)
207                 {
208                         for(k=0;k<sz;k++)
209                         {
210                                 surfaceCells->InsertNextCell(3);
211                                 surfaceCells->InsertCellPoint(n);
212                                 surfaceCells->InsertCellPoint(n+1);
213                                 surfaceCells->InsertCellPoint(n+sy+1);
214
215                                 surfaceCells->InsertNextCell(3);
216                                 surfaceCells->InsertCellPoint(n);
217                                 surfaceCells->InsertCellPoint(n+sy+1);
218                                 surfaceCells->InsertCellPoint(n+sy);
219
220                                 if(j<sy-2)
221                                 {
222                                         n++;
223                                 }
224                                 else
225                                 {
226                                         n=n+2;
227                                 }
228                                 
229                         }
230                 }
231         }
232
233         }
234         else if(imageType == VTK_UNSIGNED_CHAR)
235         {
236                 // pointers to get into the image
237         unsigned char* dataImagePointer=NULL;
238         
239         // we start where the  image starts
240         dataImagePointer=(unsigned char*)imageData->GetScalarPointer(0,0,0);    
241         
242         /*
243          Image Size
244         */
245         int ext[6];
246         imageData->GetExtent(ext);
247         int sx,sy,sz;
248         sx=ext[1]-ext[0]+1;
249         sy=ext[3]-ext[2]+1;
250         sz=ext[5]-ext[4]+1;
251
252         //-----------------
253         //A3
254         //-----------------
255         //walking in the image
256         int i=0,j=0,k=0;
257         double sum1=0,sum2=0,sum3=0,sum4=0;     
258         for(i=0;i<sx;i++)
259         {
260                 for(j=0;j<sy;j++)
261                 {
262                         for(k=0;k<sz;k++)
263                         {
264                                 
265                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
266                                 dataImagePointer=(unsigned char*)imageData->GetScalarPointer(i,j,k);                            
267
268                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
269                                 sum1=sum1/(3*VTK_UNSIGNED_CHAR_MAX);                            
270
271                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
272
273                                 counter ++;
274                         }
275                 }
276         }
277
278         //This cycle creates the cells of the surface
279         int n =0;       
280         for(i=0;i<sx-1;i++)
281         {
282                 for(j=0;j<sy-1;j++)
283                 {
284                         for(k=0;k<sz;k++)
285                         {
286                                 surfaceCells->InsertNextCell(3);
287                                 surfaceCells->InsertCellPoint(n);
288                                 surfaceCells->InsertCellPoint(n+1);
289                                 surfaceCells->InsertCellPoint(n+sy+1);
290
291                                 surfaceCells->InsertNextCell(3);
292                                 surfaceCells->InsertCellPoint(n);
293                                 surfaceCells->InsertCellPoint(n+sy+1);
294                                 surfaceCells->InsertCellPoint(n+sy);
295
296                                 if(j<sy-2)
297                                 {
298                                         n++;
299                                 }
300                                 else
301                                 {
302                                         n=n+2;
303                                 }
304                                 
305                         }
306                 }
307         }
308         }
309         else if(imageType == VTK_SHORT)
310         {
311                         // pointers to get into the image
312         short* dataImagePointer=NULL;
313         
314         // we start where the  image starts
315         dataImagePointer=(short*)imageData->GetScalarPointer(0,0,0);    
316         
317         /*
318          Image Size
319         */
320         int ext[6];
321         imageData->GetExtent(ext);
322         int sx,sy,sz;
323         sx=ext[1]-ext[0]+1;
324         sy=ext[3]-ext[2]+1;
325         sz=ext[5]-ext[4]+1;
326
327         //-----------------
328         //A3
329         //-----------------
330         //walking in the image
331         int i=0,j=0,k=0;
332         double sum1=0,sum2=0,sum3=0,sum4=0;     
333         for(i=0;i<sx;i++)
334         {
335                 for(j=0;j<sy;j++)
336                 {
337                         for(k=0;k<sz;k++)
338                         {
339                                 
340                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
341                                 dataImagePointer=(short*)imageData->GetScalarPointer(i,j,k);                            
342
343                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
344                                 sum1=sum1/(3*VTK_SHORT_MAX);                            
345
346                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
347
348                                 counter ++;
349                         }
350                 }
351         }
352
353         //This cycle creates the cells of the surface
354         int n =0;       
355         for(i=0;i<sx-1;i++)
356         {
357                 for(j=0;j<sy-1;j++)
358                 {
359                         for(k=0;k<sz;k++)
360                         {
361                                 surfaceCells->InsertNextCell(3);
362                                 surfaceCells->InsertCellPoint(n);
363                                 surfaceCells->InsertCellPoint(n+1);
364                                 surfaceCells->InsertCellPoint(n+sy+1);
365
366                                 surfaceCells->InsertNextCell(3);
367                                 surfaceCells->InsertCellPoint(n);
368                                 surfaceCells->InsertCellPoint(n+sy+1);
369                                 surfaceCells->InsertCellPoint(n+sy);
370
371                                 if(j<sy-2)
372                                 {
373                                         n++;
374                                 }
375                                 else
376                                 {
377                                         n=n+2;
378                                 }
379                                 
380                         }
381                 }
382         }
383
384         }
385         else if(imageType == VTK_UNSIGNED_SHORT)
386         {
387                         // pointers to get into the image
388         unsigned short* dataImagePointer=NULL;
389         
390         // we start where the  image starts
391         dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0);   
392         
393         /*
394          Image Size
395         */
396         int ext[6];
397         imageData->GetExtent(ext);
398         int sx,sy,sz;
399         sx=ext[1]-ext[0]+1;
400         sy=ext[3]-ext[2]+1;
401         sz=ext[5]-ext[4]+1;
402
403         //-----------------
404         //A3
405         //-----------------
406         //walking in the image
407         int i=0,j=0,k=0;
408         double sum1=0,sum2=0,sum3=0,sum4=0;     
409         for(i=0;i<sx;i++)
410         {
411                 for(j=0;j<sy;j++)
412                 {
413                         for(k=0;k<sz;k++)
414                         {
415                                 
416                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
417                                 dataImagePointer=(unsigned short*)imageData->GetScalarPointer(i,j,k);                           
418
419                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
420                                 sum1=sum1/(3*VTK_UNSIGNED_SHORT_MAX);                           
421
422                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
423
424                                 counter ++;
425                         }
426                 }
427         }
428
429         //This cycle creates the cells of the surface
430         int n =0;       
431         for(i=0;i<sx-1;i++)
432         {
433                 for(j=0;j<sy-1;j++)
434                 {
435                         for(k=0;k<sz;k++)
436                         {
437                                 surfaceCells->InsertNextCell(3);
438                                 surfaceCells->InsertCellPoint(n);
439                                 surfaceCells->InsertCellPoint(n+1);
440                                 surfaceCells->InsertCellPoint(n+sy+1);
441
442                                 surfaceCells->InsertNextCell(3);
443                                 surfaceCells->InsertCellPoint(n);
444                                 surfaceCells->InsertCellPoint(n+sy+1);
445                                 surfaceCells->InsertCellPoint(n+sy);
446
447                                 if(j<sy-2)
448                                 {
449                                         n++;
450                                 }
451                                 else
452                                 {
453                                         n=n+2;
454                                 }
455                                 
456                         }
457                 }
458         }
459
460         }
461         else if(imageType == VTK_INT)
462         {
463                         // pointers to get into the image
464         int* dataImagePointer=NULL;
465         
466         // we start where the  image starts
467         dataImagePointer=(int*)imageData->GetScalarPointer(0,0,0);      
468         
469         /*
470          Image Size
471         */
472         int ext[6];
473         imageData->GetExtent(ext);
474         int sx,sy,sz;
475         sx=ext[1]-ext[0]+1;
476         sy=ext[3]-ext[2]+1;
477         sz=ext[5]-ext[4]+1;
478
479         //-----------------
480         //A3
481         //-----------------
482         //walking in the image
483         int i=0,j=0,k=0;
484         double sum1=0,sum2=0,sum3=0,sum4=0;     
485         for(i=0;i<sx;i++)
486         {
487                 for(j=0;j<sy;j++)
488                 {
489                         for(k=0;k<sz;k++)
490                         {
491                                 
492                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
493                                 dataImagePointer=(int*)imageData->GetScalarPointer(i,j,k);                              
494
495                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
496                                 sum1=sum1/(3*VTK_INT_MAX);                              
497
498                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
499
500                                 counter ++;
501                         }
502                 }
503         }
504
505         //This cycle creates the cells of the surface
506         int n =0;       
507         for(i=0;i<sx-1;i++)
508         {
509                 for(j=0;j<sy-1;j++)
510                 {
511                         for(k=0;k<sz;k++)
512                         {
513                                 surfaceCells->InsertNextCell(3);
514                                 surfaceCells->InsertCellPoint(n);
515                                 surfaceCells->InsertCellPoint(n+1);
516                                 surfaceCells->InsertCellPoint(n+sy+1);
517
518                                 surfaceCells->InsertNextCell(3);
519                                 surfaceCells->InsertCellPoint(n);
520                                 surfaceCells->InsertCellPoint(n+sy+1);
521                                 surfaceCells->InsertCellPoint(n+sy);
522
523                                 if(j<sy-2)
524                                 {
525                                         n++;
526                                 }
527                                 else
528                                 {
529                                         n=n+2;
530                                 }
531                                 
532                         }
533                 }
534         }
535
536         }
537         else if(imageType == VTK_UNSIGNED_INT)
538         {
539                         // pointers to get into the image
540         unsigned int* dataImagePointer=NULL;
541         
542         // we start where the  image starts
543         dataImagePointer=(unsigned int*)imageData->GetScalarPointer(0,0,0);     
544         
545         /*
546          Image Size
547         */
548         int ext[6];
549         imageData->GetExtent(ext);
550         int sx,sy,sz;
551         sx=ext[1]-ext[0]+1;
552         sy=ext[3]-ext[2]+1;
553         sz=ext[5]-ext[4]+1;
554
555         //-----------------
556         //A3
557         //-----------------
558         //walking in the image
559         int i=0,j=0,k=0;
560         double sum1=0,sum2=0,sum3=0,sum4=0;     
561         for(i=0;i<sx;i++)
562         {
563                 for(j=0;j<sy;j++)
564                 {
565                         for(k=0;k<sz;k++)
566                         {
567                                 
568                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
569                                 dataImagePointer=(unsigned int*)imageData->GetScalarPointer(i,j,k);                             
570
571                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
572                                 sum1=sum1/(3*VTK_UNSIGNED_INT_MAX);                             
573
574                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
575
576                                 counter ++;
577                         }
578                 }
579         }
580
581         //This cycle creates the cells of the surface
582         int n =0;       
583         for(i=0;i<sx-1;i++)
584         {
585                 for(j=0;j<sy-1;j++)
586                 {
587                         for(k=0;k<sz;k++)
588                         {
589                                 surfaceCells->InsertNextCell(3);
590                                 surfaceCells->InsertCellPoint(n);
591                                 surfaceCells->InsertCellPoint(n+1);
592                                 surfaceCells->InsertCellPoint(n+sy+1);
593
594                                 surfaceCells->InsertNextCell(3);
595                                 surfaceCells->InsertCellPoint(n);
596                                 surfaceCells->InsertCellPoint(n+sy+1);
597                                 surfaceCells->InsertCellPoint(n+sy);
598
599                                 if(j<sy-2)
600                                 {
601                                         n++;
602                                 }
603                                 else
604                                 {
605                                         n=n+2;
606                                 }
607                                 
608                         }
609                 }
610         }
611
612         }
613         else if(imageType == VTK_LONG)
614         {
615                         // pointers to get into the image
616         long* dataImagePointer=NULL;
617         
618         // we start where the  image starts
619         dataImagePointer=(long*)imageData->GetScalarPointer(0,0,0);     
620         
621         /*
622          Image Size
623         */
624         int ext[6];
625         imageData->GetExtent(ext);
626         int sx,sy,sz;
627         sx=ext[1]-ext[0]+1;
628         sy=ext[3]-ext[2]+1;
629         sz=ext[5]-ext[4]+1;
630
631         //-----------------
632         //A3
633         //-----------------
634         //walking in the image
635         int i=0,j=0,k=0;
636         double sum1=0,sum2=0,sum3=0,sum4=0;     
637         for(i=0;i<sx;i++)
638         {
639                 for(j=0;j<sy;j++)
640                 {
641                         for(k=0;k<sz;k++)
642                         {
643                                 
644                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
645                                 dataImagePointer=(long*)imageData->GetScalarPointer(i,j,k);                             
646
647                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
648                                 sum1=sum1/(3*VTK_LONG_MAX);                             
649
650                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
651
652                                 counter ++;
653                         }
654                 }
655         }
656
657         //This cycle creates the cells of the surface
658         int n =0;       
659         for(i=0;i<sx-1;i++)
660         {
661                 for(j=0;j<sy-1;j++)
662                 {
663                         for(k=0;k<sz;k++)
664                         {
665                                 surfaceCells->InsertNextCell(3);
666                                 surfaceCells->InsertCellPoint(n);
667                                 surfaceCells->InsertCellPoint(n+1);
668                                 surfaceCells->InsertCellPoint(n+sy+1);
669
670                                 surfaceCells->InsertNextCell(3);
671                                 surfaceCells->InsertCellPoint(n);
672                                 surfaceCells->InsertCellPoint(n+sy+1);
673                                 surfaceCells->InsertCellPoint(n+sy);
674
675                                 if(j<sy-2)
676                                 {
677                                         n++;
678                                 }
679                                 else
680                                 {
681                                         n=n+2;
682                                 }
683                                 
684                         }
685                 }
686         }
687
688         }
689         else if(imageType == VTK_UNSIGNED_LONG)
690         {
691                         // pointers to get into the image
692         unsigned long* dataImagePointer=NULL;
693         
694         // we start where the  image starts
695         dataImagePointer=(unsigned long*)imageData->GetScalarPointer(0,0,0);    
696         
697         /*
698          Image Size
699         */
700         int ext[6];
701         imageData->GetExtent(ext);
702         int sx,sy,sz;
703         sx=ext[1]-ext[0]+1;
704         sy=ext[3]-ext[2]+1;
705         sz=ext[5]-ext[4]+1;
706
707         //-----------------
708         //A3
709         //-----------------
710         //walking in the image
711         int i=0,j=0,k=0;
712         double sum1=0,sum2=0,sum3=0,sum4=0;     
713         for(i=0;i<sx;i++)
714         {
715                 for(j=0;j<sy;j++)
716                 {
717                         for(k=0;k<sz;k++)
718                         {
719                                 
720                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
721                                 dataImagePointer=(unsigned long*)imageData->GetScalarPointer(i,j,k);                            
722
723                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
724                                 sum1=sum1/(3*VTK_UNSIGNED_LONG_MAX);                            
725
726                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
727
728                                 counter ++;
729                         }
730                 }
731         }
732
733         //This cycle creates the cells of the surface
734         int n =0;       
735         for(i=0;i<sx-1;i++)
736         {
737                 for(j=0;j<sy-1;j++)
738                 {
739                         for(k=0;k<sz;k++)
740                         {
741                                 surfaceCells->InsertNextCell(3);
742                                 surfaceCells->InsertCellPoint(n);
743                                 surfaceCells->InsertCellPoint(n+1);
744                                 surfaceCells->InsertCellPoint(n+sy+1);
745
746                                 surfaceCells->InsertNextCell(3);
747                                 surfaceCells->InsertCellPoint(n);
748                                 surfaceCells->InsertCellPoint(n+sy+1);
749                                 surfaceCells->InsertCellPoint(n+sy);
750
751                                 if(j<sy-2)
752                                 {
753                                         n++;
754                                 }
755                                 else
756                                 {
757                                         n=n+2;
758                                 }
759                                 
760                         }
761                 }
762         }
763
764         }
765         else if(imageType == VTK_FLOAT)
766         {               
767                         // pointers to get into the image
768         float* dataImagePointer=NULL;
769         
770         // we start where the  image starts
771         dataImagePointer=(float*)imageData->GetScalarPointer(0,0,0);    
772         
773         /*
774          Image Size
775         */
776         int ext[6];
777         imageData->GetExtent(ext);
778         int sx,sy,sz;
779         sx=ext[1]-ext[0]+1;
780         sy=ext[3]-ext[2]+1;
781         sz=ext[5]-ext[4]+1;
782
783         //-----------------
784         //A3
785         //-----------------
786         //walking in the image
787         int i=0,j=0,k=0;
788         double sum1=0,sum2=0,sum3=0,sum4=0;     
789         for(i=0;i<sx;i++)
790         {
791                 for(j=0;j<sy;j++)
792                 {
793                         for(k=0;k<sz;k++)
794                         {
795                                 
796                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
797                                 dataImagePointer=(float*)imageData->GetScalarPointer(i,j,k);                            
798
799                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
800                                 sum1=sum1/(3*VTK_FLOAT_MAX);                            
801
802                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
803
804                                 counter ++;
805                         }
806                 }
807         }
808
809         //This cycle creates the cells of the surface
810         int n =0;       
811         for(i=0;i<sx-1;i++)
812         {
813                 for(j=0;j<sy-1;j++)
814                 {
815                         for(k=0;k<sz;k++)
816                         {
817                                 surfaceCells->InsertNextCell(3);
818                                 surfaceCells->InsertCellPoint(n);
819                                 surfaceCells->InsertCellPoint(n+1);
820                                 surfaceCells->InsertCellPoint(n+sy+1);
821
822                                 surfaceCells->InsertNextCell(3);
823                                 surfaceCells->InsertCellPoint(n);
824                                 surfaceCells->InsertCellPoint(n+sy+1);
825                                 surfaceCells->InsertCellPoint(n+sy);
826
827                                 if(j<sy-2)
828                                 {
829                                         n++;
830                                 }
831                                 else
832                                 {
833                                         n=n+2;
834                                 }
835                                 
836                         }
837                 }
838         }
839
840         }
841         else if(imageType == VTK_DOUBLE)
842         {
843                 std::cout << "Got inside Double" << std::endl;
844                         // pointers to get into the image
845         double* dataImagePointer=NULL;
846         
847         // we start where the  image starts
848         dataImagePointer=(double*)imageData->GetScalarPointer(0,0,0);   
849         
850         /*
851          Image Size
852         */
853         int ext[6];
854         imageData->GetExtent(ext);
855         int sx,sy,sz;
856         sx=ext[1]-ext[0]+1;
857         sy=ext[3]-ext[2]+1;
858         sz=ext[5]-ext[4]+1;
859
860         //-----------------
861         //A3
862         //-----------------
863         //walking in the image
864         int i=0,j=0,k=0;
865         double sum1=0,sum2=0,sum3=0,sum4=0;     
866         for(i=0;i<sx;i++)
867         {
868                 for(j=0;j<sy;j++)
869                 {
870                         for(k=0;k<sz;k++)
871                         {
872                                 
873                                 // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface
874                                 dataImagePointer=(double*)imageData->GetScalarPointer(i,j,k);                           
875
876                                 sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]);
877                                 sum1=sum1/(3*VTK_DOUBLE_MAX);                           
878
879                                 surfacePoints->InsertPoint(counter, i, j, sum1*height);                         
880
881                                 counter ++;
882                         }
883                 }
884         }
885
886         //This cycle creates the cells of the surface
887         int n =0;       
888         for(i=0;i<sx-1;i++)
889         {
890                 for(j=0;j<sy-1;j++)
891                 {
892                         for(k=0;k<sz;k++)
893                         {
894                                 surfaceCells->InsertNextCell(3);
895                                 surfaceCells->InsertCellPoint(n);
896                                 surfaceCells->InsertCellPoint(n+1);
897                                 surfaceCells->InsertCellPoint(n+sy+1);
898
899                                 surfaceCells->InsertNextCell(3);
900                                 surfaceCells->InsertCellPoint(n);
901                                 surfaceCells->InsertCellPoint(n+sy+1);
902                                 surfaceCells->InsertCellPoint(n+sy);
903
904                                 if(j<sy-2)
905                                 {
906                                         n++;
907                                 }
908                                 else
909                                 {
910                                         n=n+2;
911                                 }
912                                 
913                         }
914                 }
915         }
916
917         }       
918
919         vtkPolyData* surfaceData = vtkPolyData::New();
920         surfaceData->SetPolys(surfaceCells);
921         surfaceData->SetPoints(surfacePoints);
922         surfaceData->Update();
923
924         vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New();
925         surfaceMapper->SetInput(surfaceData);
926         surfaceMapper->Update();
927
928     surfaceResult->SetMapper(surfaceMapper);
929         surfaceResult->GetProperty()->SetOpacity(1.0);
930
931         if (color == "RED")
932         {
933                 surfaceResult->GetProperty()->SetColor(1,0,0);
934         }
935         else if (color == "BLUE")
936         {
937                 surfaceResult->GetProperty()->SetColor(0,0,1);
938         }
939         else if (color == "GREEN")
940         {
941                 surfaceResult->GetProperty()->SetColor(0,1,0);
942         }
943         else
944         {
945                 surfaceResult->GetProperty()->SetColor(1,1,1);
946         }
947 }
948 /*
949 Returns the filtered image
950 */
951 vtkActor* Surface::getSurface()
952 {
953         return surfaceResult;
954 }