]> Creatis software - creaRigidRegistration.git/blob - lib/CheckBoard.cpp
*** empty log message ***
[creaRigidRegistration.git] / lib / CheckBoard.cpp
1 #include "CheckBoard.h"
2
3
4 /*
5 * Constructor
6 */
7 //------------------------------------------------------------
8 CheckBoard::CheckBoard()
9 {
10         image1=NULL;
11         image2=NULL;
12         squaresX=0;
13         squaresY=0;
14         newImage = NULL;
15         processed=false;
16 }
17
18 /*
19 * Destructor
20 */
21 //------------------------------------------------------------
22 CheckBoard::~CheckBoard()
23 {
24         //if (image1 != NULL ) { image1->Delete(); }
25         //if (image2 != NULL ) { image2->Delete(); }
26         if (newImage != NULL ) { newImage->Delete(); }
27 }
28
29 //------------------------------------------------------------
30 void CheckBoard::calculateImage()
31 {
32
33         if(image1!=NULL && image2!=NULL)
34         {
35
36                 // IMAGE 1
37                         
38                 // Information from image1
39                 image1->GetSpacing(spcImg1);
40                 image1->GetExtent(extImg1);
41
42                 type = image1->GetScalarType();
43                 
44                 // The Z dimension is 1 for a 2D image
45                 dimImg1[0] = extImg1[1] - extImg1[0]+1;
46                 dimImg1[1] = extImg1[3] - extImg1[2]+1;
47                 dimImg1[2] = 1;
48
49                 //IMAGE 2
50
51                 // Information from image2
52                 image2->GetSpacing(spcImg2);
53                 image2->GetExtent(extImg2);
54                 
55                 // The Z dimension is 1 for a 2D image
56                 dimImg2[0] = extImg2[1] - extImg2[0]+1;
57                 dimImg2[1] = extImg2[3] - extImg2[2]+1;
58                 dimImg2[2] = 1;
59
60                 long numPixelsImg1 = dimImg1[0]*dimImg1[1];
61                 long numPixelsImg2 = dimImg2[0]*dimImg2[1];
62                 
63                 double factorX = 1;
64                 double factorY = 1;
65                 vtkImageResample *resample = vtkImageResample::New();
66                 vtkImageData *result;
67                 if(numPixelsImg1<numPixelsImg2)
68                 {
69                         resample->SetInput(image1);
70                         factorX = (double)extImg2[1]/extImg1[1];
71                         factorY = (double)extImg2[3]/extImg1[3];
72                         resample->SetAxisMagnificationFactor(0,factorX);
73                         resample->SetAxisMagnificationFactor(1,factorY);
74                         resample->SetInformationInput(image2);
75
76                         initialize(dimImg2, spcImg2);
77                         result = resample->GetOutput();
78                         result->Update();
79                         createImage(result,image2,dimImg2[0],dimImg2[1]);               
80                         
81                 } //if
82                 else if (numPixelsImg1>numPixelsImg2)
83                 {
84                         resample->SetInput(image2);
85                         factorX = (double)extImg1[1]/extImg2[1];
86                         factorY = (double)extImg1[3]/extImg2[3];
87                         resample->SetAxisMagnificationFactor(0,factorX);
88                         resample->SetAxisMagnificationFactor(1,factorY);
89                         resample->SetInformationInput(image1);
90
91                         initialize(dimImg1, spcImg1);
92                         result = resample->GetOutput();
93                         
94                         result->Update();
95
96                         createImage(image1,result,dimImg1[0],dimImg1[1]);
97                 } // else if
98                 else
99                 {
100                         //If both images have the same number of pixels, the resultant image will have the 
101                         //properties of the first image.
102                         resample->SetInput(image2);
103                         factorX = (double)extImg1[1]/extImg2[1];
104                         factorY = (double)extImg1[3]/extImg2[3];
105                         resample->SetAxisMagnificationFactor(0,factorX);
106                         resample->SetAxisMagnificationFactor(1,factorY);
107                         resample->SetInformationInput(image1);
108
109                         initialize(dimImg1, spcImg1);
110
111                         result = resample->GetOutput();
112                         result->Update();
113                         
114                         createImage(image1,result,dimImg1[0],dimImg1[1]);
115
116                 } //else
117                 
118                 resample->Delete();             
119                 processed=true;
120         }
121 }
122
123 //------------------------------------------------------------
124 void CheckBoard::initialize(int dimensions[], double spacing[])
125 {
126         // Setting the new image
127         newImage = vtkImageData::New();
128         newImage->SetScalarType(type);
129         newImage->SetSpacing(spacing);
130         newImage->SetDimensions(dimensions);
131         newImage->AllocateScalars();
132         newImage->Update();
133
134 }
135
136 //------------------------------------------------------------
137 void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY)
138 {
139         int imageType=img1->GetScalarType();
140
141         if(imageType == VTK_CHAR)
142         {
143                 //POINTERS: 
144                 char* dataImagePointer1 = NULL;
145                 char* dataImagePointer2 = NULL;
146                 char* dataImageResultPointer = NULL;
147         
148                 dataImagePointer1 = (char*) img1->GetScalarPointer(0,0,0);
149                 dataImagePointer2 = (char*) img2->GetScalarPointer(0,0,0);
150                 dataImageResultPointer = (char*) newImage->GetScalarPointer(0,0,0);
151         
152                 if(squaresX == 0)
153                 {
154                         squaresX = 1;
155                 }
156                 if(squaresY == 0)
157                 {
158                         squaresY = 1;
159                 }    
160
161                 int divX = sizeX/squaresX;
162                 int divY = sizeY/squaresY;
163                 int i, j, counterX, counterY;
164                 for(i = 0; i < sizeX; i++)
165                 {
166                         counterY = 0; 
167                         for(j = 0; j < sizeY; j++)
168                         {
169                                 dataImagePointer1 = (char*)img1->GetScalarPointer(i,j,0);
170                                 dataImagePointer2 = (char*)img2->GetScalarPointer(i,j,0);
171                                 dataImageResultPointer = (char*)newImage->GetScalarPointer(i,j,0);
172
173                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
174                                 {
175                                         *dataImageResultPointer = (char) *dataImagePointer1;
176                                 }
177                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
178                                 {
179                                         *dataImageResultPointer = (char) *dataImagePointer2;
180                                 }
181
182                                 if(counterX >= 2*divX)
183                                 {
184                                         counterX = 0;
185                                 }
186                                 else if(counterY >= 2*divY)
187                                 {
188                                         counterY = 0;
189                                 }
190                         
191                                 counterY++;
192                         }
193                         counterX++;
194                 }
195
196         }
197         else if(imageType == VTK_SIGNED_CHAR)
198         {
199                 //POINTERS: 
200                 signed char* dataImagePointer1 = NULL;
201                 signed char* dataImagePointer2 = NULL;
202                 signed char* dataImageResultPointer = NULL;
203         
204                 dataImagePointer1 = (signed char*) img1->GetScalarPointer(0,0,0);
205                 dataImagePointer2 = (signed char*) img2->GetScalarPointer(0,0,0);
206                 dataImageResultPointer = (signed char*) newImage->GetScalarPointer(0,0,0);
207         
208                 if(squaresX == 0)
209                 {
210                         squaresX = 1;
211                 }
212                 if(squaresY == 0)
213                 {
214                         squaresY = 1;
215                 }    
216
217                 int     divX = sizeX/squaresX;
218                 int divY = sizeY/squaresY;
219                 int i, j, counterX, counterY;
220                 for(i = 0; i < sizeX; i++)
221                 {
222                         counterY = 0; 
223                         for(j = 0; j < sizeY; j++)
224                         {
225                                 dataImagePointer1 = (signed char*)img1->GetScalarPointer(i,j,0);
226                                 dataImagePointer2 = (signed char*)img2->GetScalarPointer(i,j,0);
227                                 dataImageResultPointer = (signed char*)newImage->GetScalarPointer(i,j,0);
228
229                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
230                                 {
231                                         *dataImageResultPointer = (signed char) *dataImagePointer1;
232                                 }
233                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
234                                 {
235                                         *dataImageResultPointer = (signed char) *dataImagePointer2;
236                                 }
237
238                                 if(counterX >= 2*divX)
239                                 {
240                                         counterX = 0;
241                                 }
242                                 else if(counterY >= 2*divY)
243                                 {
244                                         counterY = 0;
245                                 }
246                         
247                                 counterY++;
248                         }
249                         counterX++;
250                 }
251         }
252         else if(imageType == VTK_UNSIGNED_CHAR)
253         {
254                 //POINTERS: 
255                 unsigned char* dataImagePointer1 = NULL;
256                 unsigned char* dataImagePointer2 = NULL;
257                 unsigned char* dataImageResultPointer = NULL;
258         
259                 dataImagePointer1 = (unsigned char*) img1->GetScalarPointer(0,0,0);
260                 dataImagePointer2 = (unsigned char*) img2->GetScalarPointer(0,0,0);
261                 dataImageResultPointer = (unsigned char*) newImage->GetScalarPointer(0,0,0);
262         
263                 if(squaresX == 0)
264                 {
265                         squaresX = 1;
266                 }
267                 if(squaresY == 0)
268                 {
269                         squaresY = 1;
270                 }    
271
272                 int divX = sizeX/squaresX;
273                 int divY = sizeY/squaresY;
274                 int i, j, counterX, counterY;
275                 for(i = 0; i < sizeX; i++)
276                 {
277                         counterY = 0; 
278                         for(j = 0; j < sizeY; j++)
279                         {
280                                 dataImagePointer1 = (unsigned char*)img1->GetScalarPointer(i,j,0);
281                                 dataImagePointer2 = (unsigned char*)img2->GetScalarPointer(i,j,0);
282                                 dataImageResultPointer = (unsigned char*)newImage->GetScalarPointer(i,j,0);
283
284                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
285                                 {
286                                         *dataImageResultPointer = (unsigned char) *dataImagePointer1;
287                                 }
288                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
289                                 {
290                                         *dataImageResultPointer = (unsigned char) *dataImagePointer2;
291                                 }
292
293                                 if(counterX >= 2*divX)
294                                 {
295                                         counterX = 0;
296                                 }
297                                 else if(counterY >= 2*divY)
298                                 {
299                                         counterY = 0;
300                                 }
301                         
302                                 counterY++;
303                         }
304                         counterX++;
305                 }
306         }
307         else if(imageType == VTK_SHORT)
308         {
309         //POINTERS: 
310                 short* dataImagePointer1 = NULL;
311                 short* dataImagePointer2 = NULL;
312                 short* dataImageResultPointer = NULL;
313         
314                 dataImagePointer1 = (short*) img1->GetScalarPointer(0,0,0);
315                 dataImagePointer2 = (short*) img2->GetScalarPointer(0,0,0);
316                 dataImageResultPointer = (short*) newImage->GetScalarPointer(0,0,0);
317         
318                 if(squaresX == 0)
319                 {
320                         squaresX = 1;
321                 }
322                 if(squaresY == 0)
323                 {
324                         squaresY = 1;
325                 }    
326
327                 int divX = sizeX/squaresX;
328                 int divY = sizeY/squaresY;
329                 int i, j, counterX, counterY;
330                 for(i = 0; i < sizeX; i++)
331                 {
332                         counterY = 0; 
333                         for(j = 0; j < sizeY; j++)
334                         {
335                                 dataImagePointer1 = (short*)img1->GetScalarPointer(i,j,0);
336                                 dataImagePointer2 = (short*)img2->GetScalarPointer(i,j,0);
337                                 dataImageResultPointer = (short*)newImage->GetScalarPointer(i,j,0);
338
339                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
340                                 {
341                                         *dataImageResultPointer = (short) *dataImagePointer1;
342                                 }
343                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
344                                 {
345                                         *dataImageResultPointer = (short) *dataImagePointer2;
346                                 }
347
348                                 if(counterX >= 2*divX)
349                                 {
350                                         counterX = 0;
351                                 }
352                                 else if(counterY >= 2*divY)
353                                 {
354                                         counterY = 0;
355                                 }
356                         
357                                 counterY++;
358                         }
359                         counterX++;
360                 }
361         }
362         else if(imageType == VTK_UNSIGNED_SHORT)
363         {
364                 //POINTERS: 
365                 unsigned short* dataImagePointer1 = NULL;
366                 unsigned short* dataImagePointer2 = NULL;
367                 unsigned short* dataImageResultPointer = NULL;
368         
369                 dataImagePointer1 = (unsigned short*) img1->GetScalarPointer(0,0,0);
370                 dataImagePointer2 = (unsigned short*) img2->GetScalarPointer(0,0,0);
371                 dataImageResultPointer = (unsigned short*) newImage->GetScalarPointer(0,0,0);
372         
373                 if(squaresX == 0)
374                 {
375                         squaresX = 1;
376                 }
377                 if(squaresY == 0)
378                 {
379                         squaresY = 1;
380                 }    
381
382                 int divX = sizeX/squaresX;
383                 int divY = sizeY/squaresY;
384                 int i, j, counterX, counterY;
385                 for(i = 0; i < sizeX; i++)
386                 {
387                         counterY = 0; 
388                         for(j = 0; j < sizeY; j++)
389                         {
390                                 dataImagePointer1 = (unsigned short*)img1->GetScalarPointer(i,j,0);
391                                 dataImagePointer2 = (unsigned short*)img2->GetScalarPointer(i,j,0);
392                                 dataImageResultPointer = (unsigned short*)newImage->GetScalarPointer(i,j,0);
393
394                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
395                                 {
396                                         *dataImageResultPointer = (unsigned short) *dataImagePointer1;
397                                 }
398                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
399                                 {
400                                         *dataImageResultPointer = (unsigned short) *dataImagePointer2;
401                                 }
402
403                                 if(counterX >= 2*divX)
404                                 {
405                                         counterX = 0;
406                                 }
407                                 else if(counterY >= 2*divY)
408                                 {
409                                         counterY = 0;
410                                 }
411                         
412                                 counterY++;
413                         }
414                         counterX++;
415                 }
416         }
417
418         else if(imageType == VTK_INT)
419         {
420                 //POINTERS: 
421                 int* dataImagePointer1 = NULL;
422                 int* dataImagePointer2 = NULL;
423                 int* dataImageResultPointer = NULL;
424         
425                 dataImagePointer1 = (int*) img1->GetScalarPointer(0,0,0);
426                 dataImagePointer2 = (int*) img2->GetScalarPointer(0,0,0);
427                 dataImageResultPointer = (int*) newImage->GetScalarPointer(0,0,0);
428         
429                 if(squaresX == 0)
430                 {
431                         squaresX = 1;
432                 }
433                 if(squaresY == 0)
434                 {
435                         squaresY = 1;
436                 }    
437
438                 int divX = sizeX/squaresX;
439                 int divY = sizeY/squaresY;
440                 int i, j, counterX, counterY;
441                 for(i = 0; i < sizeX; i++)
442                 {
443                         counterY = 0; 
444                         for(j = 0; j < sizeY; j++)
445                         {
446                                 dataImagePointer1 = (int*)img1->GetScalarPointer(i,j,0);
447                                 dataImagePointer2 = (int*)img2->GetScalarPointer(i,j,0);
448                                 dataImageResultPointer = (int*)newImage->GetScalarPointer(i,j,0);
449
450                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
451                                 {
452                                         *dataImageResultPointer = (int) *dataImagePointer1;
453                                 }
454                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
455                                 {
456                                         *dataImageResultPointer = (int) *dataImagePointer2;
457                                 }
458
459                                 if(counterX >= 2*divX)
460                                 {
461                                         counterX = 0;
462                                 }
463                                 else if(counterY >= 2*divY)
464                                 {
465                                         counterY = 0;
466                                 }
467                         
468                                 counterY++;
469                         }
470                         counterX++;
471                 }
472         }
473         else if(imageType == VTK_UNSIGNED_INT)
474         {
475                 //POINTERS: 
476                 unsigned int* dataImagePointer1 = NULL;
477                 unsigned int* dataImagePointer2 = NULL;
478                 unsigned int* dataImageResultPointer = NULL;
479         
480                 dataImagePointer1 = (unsigned int*) img1->GetScalarPointer(0,0,0);
481                 dataImagePointer2 = (unsigned int*) img2->GetScalarPointer(0,0,0);
482                 dataImageResultPointer = (unsigned int*) newImage->GetScalarPointer(0,0,0);
483         
484                 if(squaresX == 0)
485                 {
486                         squaresX = 1;
487                 }
488                 if(squaresY == 0)
489                 {
490                         squaresY = 1;
491                 }    
492
493                 int divX = sizeX/squaresX;
494                 int divY = sizeY/squaresY;
495                 int i, j, counterX, counterY;
496                 for(i = 0; i < sizeX; i++)
497                 {
498                         counterY = 0; 
499                         for(j = 0; j < sizeY; j++)
500                         {
501                                 dataImagePointer1 = (unsigned int*)img1->GetScalarPointer(i,j,0);
502                                 dataImagePointer2 = (unsigned int*)img2->GetScalarPointer(i,j,0);
503                                 dataImageResultPointer = (unsigned int*)newImage->GetScalarPointer(i,j,0);
504
505                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
506                                 {
507                                         *dataImageResultPointer = (unsigned int) *dataImagePointer1;
508                                 }
509                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
510                                 {
511                                         *dataImageResultPointer = (unsigned int) *dataImagePointer2;
512                                 }
513
514                                 if(counterX >= 2*divX)
515                                 {
516                                         counterX = 0;
517                                 }
518                                 else if(counterY >= 2*divY)
519                                 {
520                                         counterY = 0;
521                                 }
522                         
523                                 counterY++;
524                         }
525                         counterX++;
526                 }
527         }
528         else if(imageType == VTK_LONG)
529         {
530                 //POINTERS: 
531                 long* dataImagePointer1 = NULL;
532                 long* dataImagePointer2 = NULL;
533                 long* dataImageResultPointer = NULL;
534         
535                 dataImagePointer1 = (long*) img1->GetScalarPointer(0,0,0);
536                 dataImagePointer2 = (long*) img2->GetScalarPointer(0,0,0);
537                 dataImageResultPointer = (long*) newImage->GetScalarPointer(0,0,0);
538         
539                 if(squaresX == 0)
540                 {
541                         squaresX = 1;
542                 }
543                 if(squaresY == 0)
544                 {
545                         squaresY = 1;
546                 }    
547
548                 int divX = sizeX/squaresX;
549                 int divY = sizeY/squaresY;
550                 int i, j, counterX, counterY;
551                 for(i = 0; i < sizeX; i++)
552                 {
553                         counterY = 0; 
554                         for(j = 0; j < sizeY; j++)
555                         {
556                                 dataImagePointer1 = (long*)img1->GetScalarPointer(i,j,0);
557                                 dataImagePointer2 = (long*)img2->GetScalarPointer(i,j,0);
558                                 dataImageResultPointer = (long*)newImage->GetScalarPointer(i,j,0);
559
560                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
561                                 {
562                                         *dataImageResultPointer = (long) *dataImagePointer1;
563                                 }
564                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
565                                 {
566                                         *dataImageResultPointer = (long) *dataImagePointer2;
567                                 }
568
569                                 if(counterX >= 2*divX)
570                                 {
571                                         counterX = 0;
572                                 }
573                                 else if(counterY >= 2*divY)
574                                 {
575                                         counterY = 0;
576                                 }
577                         
578                                 counterY++;
579                         }
580                         counterX++;
581                 }
582         }
583         else if(imageType == VTK_UNSIGNED_LONG)
584         {
585                 //POINTERS: 
586                 unsigned long* dataImagePointer1 = NULL;
587                 unsigned long* dataImagePointer2 = NULL;
588                 unsigned long* dataImageResultPointer = NULL;
589         
590                 dataImagePointer1 = (unsigned long*) img1->GetScalarPointer(0,0,0);
591                 dataImagePointer2 = (unsigned long*) img2->GetScalarPointer(0,0,0);
592                 dataImageResultPointer = (unsigned long*) newImage->GetScalarPointer(0,0,0);
593         
594                 if(squaresX == 0)
595                 {
596                         squaresX = 1;
597                 }
598                 if(squaresY == 0)
599                 {
600                         squaresY = 1;
601                 }    
602
603                 int divX = sizeX/squaresX;
604                 int divY = sizeY/squaresY;
605                 int i, j, counterX, counterY;
606                 for(i = 0; i < sizeX; i++)
607                 {
608                         counterY = 0; 
609                         for(j = 0; j < sizeY; j++)
610                         {
611                                 dataImagePointer1 = (unsigned long*)img1->GetScalarPointer(i,j,0);
612                                 dataImagePointer2 = (unsigned long*)img2->GetScalarPointer(i,j,0);
613                                 dataImageResultPointer = (unsigned long*)newImage->GetScalarPointer(i,j,0);
614
615                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
616                                 {
617                                         *dataImageResultPointer = (unsigned long) *dataImagePointer1;
618                                 }
619                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
620                                 {
621                                         *dataImageResultPointer = (unsigned long) *dataImagePointer2;
622                                 }
623
624                                 if(counterX >= 2*divX)
625                                 {
626                                         counterX = 0;
627                                 }
628                                 else if(counterY >= 2*divY)
629                                 {
630                                         counterY = 0;
631                                 }                       
632                                 counterY++;
633                         }
634                         counterX++;
635                 }
636         }
637         else if(imageType == VTK_FLOAT)
638         {
639                 //POINTERS: 
640                 float* dataImagePointer1 = NULL;
641                 float* dataImagePointer2 = NULL;
642                 float* dataImageResultPointer = NULL;
643         
644                 dataImagePointer1 = (float*) img1->GetScalarPointer(0,0,0);
645                 dataImagePointer2 = (float*) img2->GetScalarPointer(0,0,0);
646                 dataImageResultPointer = (float*) newImage->GetScalarPointer(0,0,0);
647         
648                 if(squaresX == 0)
649                 {
650                         squaresX = 1;
651                 }
652                 if(squaresY == 0)
653                 {
654                         squaresY = 1;
655                 }    
656
657                 int divX = sizeX/squaresX;
658                 int divY = sizeY/squaresY;
659                 int i, j, counterX, counterY;
660                 for(i = 0; i < sizeX; i++)
661                 {
662                         counterY = 0; 
663                         for(j = 0; j < sizeY; j++)
664                         {
665                                 dataImagePointer1 = (float*)img1->GetScalarPointer(i,j,0);
666                                 dataImagePointer2 = (float*)img2->GetScalarPointer(i,j,0);
667                                 dataImageResultPointer = (float*)newImage->GetScalarPointer(i,j,0);
668
669                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
670                                 {
671                                         *dataImageResultPointer = (float) *dataImagePointer1;
672                                 }
673                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
674                                 {
675                                         *dataImageResultPointer = (float) *dataImagePointer2;
676                                 }
677
678                                 if(counterX >= 2*divX)
679                                 {
680                                         counterX = 0;
681                                 }
682                                 else if(counterY >= 2*divY)
683                                 {
684                                         counterY = 0;
685                                 }
686                         
687                                 counterY++;
688                         }
689                         counterX++;
690                 }
691         }
692         else if(imageType == VTK_DOUBLE)
693         {
694                 //POINTERS: 
695                 double* dataImagePointer1 = NULL;
696                 double* dataImagePointer2 = NULL;
697                 double* dataImageResultPointer = NULL;
698         
699                 dataImagePointer1 = (double*) img1->GetScalarPointer(0,0,0);
700                 dataImagePointer2 = (double*) img2->GetScalarPointer(0,0,0);
701                 dataImageResultPointer = (double*) newImage->GetScalarPointer(0,0,0);
702         
703                 if(squaresX == 0)
704                 {
705                         squaresX = 1;
706                 }
707                 if(squaresY == 0)
708                 {
709                         squaresY = 1;
710                 }    
711
712                 int divX = sizeX/squaresX;
713                 int divY = sizeY/squaresY;
714                 int i, j, counterX, counterY;
715                 for(i = 0; i < sizeX; i++)
716                 {
717                         counterY = 0; 
718                         for(j = 0; j < sizeY; j++)
719                         {
720                                 dataImagePointer1 = (double*)img1->GetScalarPointer(i,j,0);
721                                 dataImagePointer2 = (double*)img2->GetScalarPointer(i,j,0);
722                                 dataImageResultPointer = (double*)newImage->GetScalarPointer(i,j,0);
723
724                                 if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) )
725                                 {
726                                         *dataImageResultPointer = (double) *dataImagePointer1;
727                                 }
728                                 else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) )
729                                 {
730                                         *dataImageResultPointer = (double) *dataImagePointer2;
731                                 }
732
733                                 if(counterX >= 2*divX)
734                                 {
735                                         counterX = 0;
736                                 }
737                                 else if(counterY >= 2*divY)
738                                 {
739                                         counterY = 0;
740                                 }                       
741                                 counterY++;
742                         }
743                         counterX++;
744                 }
745         }
746
747                 
748         //std::cout << "The image has been checkboardized!" << std::endl;
749    newImage->Update();
750 //   newImage->Modified();
751 }
752
753 /*
754 * Get new image
755 */
756 //------------------------------------------------------------
757 vtkImageData* CheckBoard::getFilteredImage()
758 {
759         if(processed){
760                 return newImage;
761         }
762         else{
763                 return NULL;
764         }
765 }
766
767 //------------------------------------------------------------
768 void CheckBoard::setInputImage1(vtkImageData *_image)
769 {
770         image1=_image;
771 }
772
773 //------------------------------------------------------------
774 void CheckBoard::setInputImage2(vtkImageData *_image)
775 {
776         image2=_image;
777 }
778
779 //------------------------------------------------------------
780 void CheckBoard::setCols(int cols)
781 {
782         squaresX=cols;
783 }
784
785 //------------------------------------------------------------
786 void CheckBoard::setRows(int rows)
787 {
788         squaresY=rows;
789 }
790