From bb6bffc75df349b5f74f4197206718a87b42e4a7 Mon Sep 17 00:00:00 2001 From: trillos Date: Wed, 18 Nov 2009 09:54:40 +0000 Subject: [PATCH] Added template methods --- lib/CheckBoard.cpp | 586 ++++------------------------- lib/CheckBoard.h | 7 + lib/Substraction.cxx | 825 +++++----------------------------------- lib/Substraction.h | 5 + lib/Surface.cxx | 875 ++++++------------------------------------- lib/Surface.h | 19 +- lib/Transformer.cxx | 10 +- lib/Transformer.h | 3 + lib/Transparency.cxx | 186 ++------- lib/Transparency.h | 5 +- 10 files changed, 336 insertions(+), 2185 deletions(-) diff --git a/lib/CheckBoard.cpp b/lib/CheckBoard.cpp index afa33d2..b766835 100644 --- a/lib/CheckBoard.cpp +++ b/lib/CheckBoard.cpp @@ -14,6 +14,8 @@ CheckBoard::CheckBoard() newImage = NULL; processed=false; newImage = NULL; + resample = NULL; + result = NULL; } /* @@ -25,6 +27,8 @@ CheckBoard::~CheckBoard() //if (image1 != NULL ) { image1->Delete(); } //if (image2 != NULL ) { image2->Delete(); } if (newImage != NULL ) { newImage->Delete(); } + if (resample != NULL ) { resample->Delete(); } + if (result != NULL ) { result->Delete(); } } //------------------------------------------------------------ @@ -63,8 +67,8 @@ void CheckBoard::calculateImage() double factorX = 1; double factorY = 1; - vtkImageResample *resample = vtkImageResample::New(); - vtkImageData *result; + resample = vtkImageResample::New(); + result = vtkImageData::New(); if(numPixelsImg1SetInput(image1); @@ -149,55 +153,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, char* dataImagePointer1 = NULL; char* dataImagePointer2 = NULL; char* dataImageResultPointer = NULL; - - dataImagePointer1 = (char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (char*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (char*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (char) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (char) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_SIGNED_CHAR) { @@ -205,54 +162,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, signed char* dataImagePointer1 = NULL; signed char* dataImagePointer2 = NULL; signed char* dataImageResultPointer = NULL; - - dataImagePointer1 = (signed char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (signed char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (signed char*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (signed char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (signed char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (signed char*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (signed char) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (signed char) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_UNSIGNED_CHAR) { @@ -260,54 +171,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, unsigned char* dataImagePointer1 = NULL; unsigned char* dataImagePointer2 = NULL; unsigned char* dataImageResultPointer = NULL; - - dataImagePointer1 = (unsigned char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned char*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned char*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned char) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned char) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_SHORT) { @@ -315,54 +180,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, short* dataImagePointer1 = NULL; short* dataImagePointer2 = NULL; short* dataImageResultPointer = NULL; - - dataImagePointer1 = (short*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (short*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (short*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (short*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (short*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (short*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (short) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (short) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_UNSIGNED_SHORT) { @@ -370,54 +189,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, unsigned short* dataImagePointer1 = NULL; unsigned short* dataImagePointer2 = NULL; unsigned short* dataImageResultPointer = NULL; - - dataImagePointer1 = (unsigned short*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned short*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned short*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned short*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned short*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned short*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned short) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned short) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_INT) @@ -426,54 +199,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, int* dataImagePointer1 = NULL; int* dataImagePointer2 = NULL; int* dataImageResultPointer = NULL; - - dataImagePointer1 = (int*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (int*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (int*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (int*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (int*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (int*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (int) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (int) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_UNSIGNED_INT) { @@ -481,54 +208,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, unsigned int* dataImagePointer1 = NULL; unsigned int* dataImagePointer2 = NULL; unsigned int* dataImageResultPointer = NULL; - - dataImagePointer1 = (unsigned int*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned int*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned int*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned int*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned int*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned int*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned int) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned int) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_LONG) { @@ -536,54 +217,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, long* dataImagePointer1 = NULL; long* dataImagePointer2 = NULL; long* dataImageResultPointer = NULL; - - dataImagePointer1 = (long*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (long*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (long*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (long*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (long*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (long*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (long) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (long) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_UNSIGNED_LONG) { @@ -591,53 +226,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, unsigned long* dataImagePointer1 = NULL; unsigned long* dataImagePointer2 = NULL; unsigned long* dataImageResultPointer = NULL; - - dataImagePointer1 = (unsigned long*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned long*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned long*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned long*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned long*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned long*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned long) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (unsigned long) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_FLOAT) { @@ -645,54 +235,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, float* dataImagePointer1 = NULL; float* dataImagePointer2 = NULL; float* dataImageResultPointer = NULL; - - dataImagePointer1 = (float*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (float*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (float*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (float*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (float*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (float*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (float) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (float) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } else if(imageType == VTK_DOUBLE) { @@ -700,53 +244,8 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, double* dataImagePointer1 = NULL; double* dataImagePointer2 = NULL; double* dataImageResultPointer = NULL; - - dataImagePointer1 = (double*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (double*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (double*) newImage->GetScalarPointer(0,0,0); - - if(squaresX == 0) - { - squaresX = 1; - } - if(squaresY == 0) - { - squaresY = 1; - } - int divX = sizeX/squaresX; - int divY = sizeY/squaresY; - int i, j, counterX, counterY; - for(i = 0; i < sizeX; i++) - { - counterY = 0; - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (double*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (double*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (double*)newImage->GetScalarPointer(i,j,0); - - if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (double) *dataImagePointer1; - } - else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) - { - *dataImageResultPointer = (double) *dataImagePointer2; - } - - if(counterX >= 2*divX) - { - counterX = 0; - } - else if(counterY >= 2*divY) - { - counterY = 0; - } - counterY++; - } - counterX++; - } + createImageByType(dataImagePointer1,dataImagePointer2,dataImageResultPointer,img1,img2,sizeX,sizeY); } @@ -754,6 +253,57 @@ void CheckBoard::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, newImage->Update(); // newImage->Modified(); } +/**Template used for the different image types +*/ +template +void CheckBoard::createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY) +{ + dataImagePointer1 = (T*) img1->GetScalarPointer(0,0,0); + dataImagePointer2 = (T*) img2->GetScalarPointer(0,0,0); + dataImageResultPointer = (T*) newImage->GetScalarPointer(0,0,0); + + if(squaresX == 0) + { + squaresX = 1; + } + if(squaresY == 0) + { + squaresY = 1; + } + + int divX = sizeX/squaresX; + int divY = sizeY/squaresY; + int i, j, counterX, counterY; + for(i = 0; i < sizeX; i++) + { + counterY = 0; + for(j = 0; j < sizeY; j++) + { + dataImagePointer1 = (T*)img1->GetScalarPointer(i,j,0); + dataImagePointer2 = (T*)img2->GetScalarPointer(i,j,0); + dataImageResultPointer = (T*)newImage->GetScalarPointer(i,j,0); + if( (counterX <= divX && counterY <= divY) || ((counterX >= divX && counterX <= 2*divX) && (counterY >= divY && counterY <= 2*divY)) ) + { + *dataImageResultPointer = (T) *dataImagePointer1; + } + else //if( ((counterX >= divX && counterX <= 2*divX) && counterY <= divY) || (counterX <= divX && (counterY >= divY && counterY <= 2*divY)) ) + { + *dataImageResultPointer = (T) *dataImagePointer2; + } + + if(counterX >= 2*divX) + { + counterX = 0; + } + else if(counterY >= 2*divY) + { + counterY = 0; + } + counterY++; + } + counterX++; + } +} /* * Get new image diff --git a/lib/CheckBoard.h b/lib/CheckBoard.h index cc1ef87..d777478 100644 --- a/lib/CheckBoard.h +++ b/lib/CheckBoard.h @@ -33,6 +33,7 @@ class CheckBoard void setCols(int cols); void setRows(int rows); + template void createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY); // --- Atributes --- // private: @@ -48,6 +49,12 @@ class CheckBoard //Resulting image vtkImageData *newImage; + //Image Resampler + vtkImageResample *resample; + + //Rsulting image from the resampler + vtkImageData *result; + //Total number of divisions for the X axis (colums) int squaresX; diff --git a/lib/Substraction.cxx b/lib/Substraction.cxx index ee25e70..c0be6d8 100644 --- a/lib/Substraction.cxx +++ b/lib/Substraction.cxx @@ -116,74 +116,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) char* dataImagePointer1=NULL; char* dataImagePointer2=NULL; char* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(char*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(char*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(char*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(char*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(char*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(char*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(char) lowerColor[0]; - dataImageResultPointer[1] =(char) lowerColor[1]; - dataImageResultPointer[2] =(char) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(char) upperColor[0]; - dataImageResultPointer[1] =(char) upperColor[1]; - dataImageResultPointer[2] =(char) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(char) mediumColor[0]; - dataImageResultPointer[1] =(char) mediumColor[1]; - dataImageResultPointer[2] =(char) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_UNSIGNED_CHAR) { @@ -194,74 +128,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) unsigned char* dataImagePointer1=NULL; unsigned char* dataImagePointer2=NULL; unsigned char* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(unsigned char*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(unsigned char*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(unsigned char*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(unsigned char) lowerColor[0]; - dataImageResultPointer[1] =(unsigned char) lowerColor[1]; - dataImageResultPointer[2] =(unsigned char) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(unsigned char) upperColor[0]; - dataImageResultPointer[1] =(unsigned char) upperColor[1]; - dataImageResultPointer[2] =(unsigned char) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(unsigned char) mediumColor[0]; - dataImageResultPointer[1] =(unsigned char) mediumColor[1]; - dataImageResultPointer[2] =(unsigned char) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_SIGNED_CHAR) { @@ -272,74 +140,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) signed char* dataImagePointer1=NULL; signed char* dataImagePointer2=NULL; signed char* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(signed char*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(signed char*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(signed char*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(signed char*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(signed char*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(signed char*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(signed char) lowerColor[0]; - dataImageResultPointer[1] =(signed char) lowerColor[1]; - dataImageResultPointer[2] =(signed char) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(signed char) upperColor[0]; - dataImageResultPointer[1] =(signed char) upperColor[1]; - dataImageResultPointer[2] =(signed char) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(signed char) mediumColor[0]; - dataImageResultPointer[1] =(signed char) mediumColor[1]; - dataImageResultPointer[2] =(signed char) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_SHORT) { @@ -350,74 +152,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) short* dataImagePointer1=NULL; short* dataImagePointer2=NULL; short* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(short*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(short*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(short*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(short*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(short*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(short*)imageResult->GetScalarPointer(i,j,k); - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(short) lowerColor[0]; - dataImageResultPointer[1] =(short) lowerColor[1]; - dataImageResultPointer[2] =(short) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(short) upperColor[0]; - dataImageResultPointer[1] =(short) upperColor[1]; - dataImageResultPointer[2] =(short) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(short) mediumColor[0]; - dataImageResultPointer[1] =(short) mediumColor[1]; - dataImageResultPointer[2] =(short) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_UNSIGNED_SHORT) { @@ -428,74 +164,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) unsigned short* dataImagePointer1=NULL; unsigned short* dataImagePointer2=NULL; unsigned short* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(unsigned short*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(unsigned short*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(unsigned short*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(unsigned short*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(unsigned short*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(unsigned short*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(unsigned short) lowerColor[0]; - dataImageResultPointer[1] =(unsigned short) lowerColor[1]; - dataImageResultPointer[2] =(unsigned short) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(unsigned short) upperColor[0]; - dataImageResultPointer[1] =(unsigned short) upperColor[1]; - dataImageResultPointer[2] =(unsigned short) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(unsigned short) mediumColor[0]; - dataImageResultPointer[1] =(unsigned short) mediumColor[1]; - dataImageResultPointer[2] =(unsigned short) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_INT) { @@ -506,74 +176,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) int* dataImagePointer1=NULL; int* dataImagePointer2=NULL; int* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(int*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(int*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(int*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(int*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(int*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(int*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(int) lowerColor[0]; - dataImageResultPointer[1] =(int) lowerColor[1]; - dataImageResultPointer[2] =(int) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(int) upperColor[0]; - dataImageResultPointer[1] =(int) upperColor[1]; - dataImageResultPointer[2] =(int) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(int) mediumColor[0]; - dataImageResultPointer[1] =(int) mediumColor[1]; - dataImageResultPointer[2] =(int) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_UNSIGNED_INT) { @@ -584,74 +188,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) unsigned int* dataImagePointer1=NULL; unsigned int* dataImagePointer2=NULL; unsigned int* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(unsigned int*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(unsigned int*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(unsigned int*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(unsigned int*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(unsigned int*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(unsigned int*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(unsigned int) lowerColor[0]; - dataImageResultPointer[1] =(unsigned int) lowerColor[1]; - dataImageResultPointer[2] =(unsigned int) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(unsigned int) upperColor[0]; - dataImageResultPointer[1] =(unsigned int) upperColor[1]; - dataImageResultPointer[2] =(unsigned int) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(unsigned int) mediumColor[0]; - dataImageResultPointer[1] =(unsigned int) mediumColor[1]; - dataImageResultPointer[2] =(unsigned int) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_LONG) { @@ -662,74 +200,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) long* dataImagePointer1=NULL; long* dataImagePointer2=NULL; long* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(long*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(long*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(long*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(long*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(long*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(long*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(long) lowerColor[0]; - dataImageResultPointer[1] =(long) lowerColor[1]; - dataImageResultPointer[2] =(long) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(long) upperColor[0]; - dataImageResultPointer[1] =(long) upperColor[1]; - dataImageResultPointer[2] =(long) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(long) mediumColor[0]; - dataImageResultPointer[1] =(long) mediumColor[1]; - dataImageResultPointer[2] =(long) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_UNSIGNED_LONG) { @@ -740,74 +212,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) unsigned long* dataImagePointer1=NULL; unsigned long* dataImagePointer2=NULL; unsigned long* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(unsigned long*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(unsigned long*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(unsigned long*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(unsigned long*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(unsigned long*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(unsigned long*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(unsigned long) lowerColor[0]; - dataImageResultPointer[1] =(unsigned long) lowerColor[1]; - dataImageResultPointer[2] =(unsigned long) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(unsigned long) upperColor[0]; - dataImageResultPointer[1] =(unsigned long) upperColor[1]; - dataImageResultPointer[2] =(unsigned long) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(unsigned long) mediumColor[0]; - dataImageResultPointer[1] =(unsigned long) mediumColor[1]; - dataImageResultPointer[2] =(unsigned long) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_FLOAT) { @@ -818,74 +224,8 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) float* dataImagePointer1=NULL; float* dataImagePointer2=NULL; float* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(float*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(float*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(float*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(float*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(float*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(float*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(float) lowerColor[0]; - dataImageResultPointer[1] =(float) lowerColor[1]; - dataImageResultPointer[2] =(float) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(float) upperColor[0]; - dataImageResultPointer[1] =(float) upperColor[1]; - dataImageResultPointer[2] =(float) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(float) mediumColor[0]; - dataImageResultPointer[1] =(float) mediumColor[1]; - dataImageResultPointer[2] =(float) mediumColor[2]; - nZ++; - } - counter++; - } - } - } + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); } else if(imageType == VTK_DOUBLE) { @@ -896,76 +236,83 @@ void Substraction::substract(vtkImageData* imageData1, vtkImageData* imageData2) double* dataImagePointer1=NULL; double* dataImagePointer2=NULL; double* dataImageResultPointer=NULL; - // we start where the image starts - dataImagePointer1=(double*)imageData1->GetScalarPointer(0,0,0); - dataImagePointer2=(double*)imageData2->GetScalarPointer(0,0,0); - dataImageResultPointer=(double*)imageResult->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData1->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - sizeImage=sx*sy*sz; + + substractByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, imageData1, imageData2); + } +} - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; - double sum1=0,sum2=0; - for(i=0;i +void Substraction::substractByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *imageData1, vtkImageData *imageData2) +{ + // we start where the image starts + dataImagePointer1=(T*)imageData1->GetScalarPointer(0,0,0); + dataImagePointer2=(T*)imageData2->GetScalarPointer(0,0,0); + dataImageResultPointer=(T*)imageResult->GetScalarPointer(0,0,0); + /* + Image Size + */ + int ext[6]; + imageData1->GetExtent(ext); + int sx,sy,sz; + sx=ext[1]-ext[0]+1; + sy=ext[3]-ext[2]+1; + sz=ext[5]-ext[4]+1; + + sizeImage=sx*sy*sz; + //----------------- + //A3 + //----------------- + //walking in the image + int i=0,j=0,k=0,counter=0,nU=0,nL=0,nZ=0; + double sum1=0,sum2=0; + for(i=0;iGetScalarComponentAsFloat(i,j,k,0); - - // we get the pointer to the position (i,j,k)y that way we can get the - //grey level and we can change it - dataImagePointer1=(double*)imageData1->GetScalarPointer(i,j,k); - dataImagePointer2=(double*)imageData2->GetScalarPointer(i,j,k); - dataImageResultPointer=(double*)imageResult->GetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); - sum1=sum1/3; - sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); - sum2=sum2/3; - if((sum1 - sum2) < lZeroLevel) - { - dataImageResultPointer[0] =(double) lowerColor[0]; - dataImageResultPointer[1] =(double) lowerColor[1]; - dataImageResultPointer[2] =(double) lowerColor[2]; - nL++; - } - else if((sum1 - sum2) > uZeroLevel) - { - dataImageResultPointer[0] =(double) upperColor[0]; - dataImageResultPointer[1] =(double) upperColor[1]; - dataImageResultPointer[2] =(double) upperColor[2]; - nU++; - } - else - { - dataImageResultPointer[0] =(double) mediumColor[0]; - dataImageResultPointer[1] =(double) mediumColor[1]; - dataImageResultPointer[2] =(double) mediumColor[2]; - nZ++; - } - counter++; + // this is for getting just the grey level in that position + //originalValue=(short)imageData->GetScalarComponentAsFloat(i,j,k,0); + + // we get the pointer to the position (i,j,k)y that way we can get the + //grey level and we can change it + + dataImagePointer1=(T*)imageData1->GetScalarPointer(i,j,k); + dataImagePointer2=(T*)imageData2->GetScalarPointer(i,j,k); + dataImageResultPointer=(T*)imageResult->GetScalarPointer(i,j,k); + + sum1=(int)(dataImagePointer1[0]) + (int)(dataImagePointer1[1]) + (int)(dataImagePointer1[2]); + sum1=sum1/3; + sum2=(int)(dataImagePointer2[0]) + (int)(dataImagePointer2[1]) + (int)(dataImagePointer2[2]); + sum2=sum2/3; + if((sum1 - sum2) < lZeroLevel) + { + dataImageResultPointer[0] =(T) lowerColor[0]; + dataImageResultPointer[1] =(T) lowerColor[1]; + dataImageResultPointer[2] =(T) lowerColor[2]; + nL++; } + else if((sum1 - sum2) > uZeroLevel) + { + dataImageResultPointer[0] =(T) upperColor[0]; + dataImageResultPointer[1] =(T) upperColor[1]; + dataImageResultPointer[2] =(T) upperColor[2]; + nU++; + } + else + { + dataImageResultPointer[0] =(T) mediumColor[0]; + dataImageResultPointer[1] =(T) mediumColor[1]; + dataImageResultPointer[2] =(T) mediumColor[2]; + nZ++; + } + counter++; } } } } + /* Returns the filtered image */ diff --git a/lib/Substraction.h b/lib/Substraction.h index 85a3991..747caf4 100644 --- a/lib/Substraction.h +++ b/lib/Substraction.h @@ -42,6 +42,11 @@ class Substraction constructing image substract */ void substract(vtkImageData* imageData1, vtkImageData* imageData2); + + /* + Template method of substract for different image types + */ + template void substractByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *imageData1, vtkImageData *imageData2); diff --git a/lib/Surface.cxx b/lib/Surface.cxx index ac7467d..08993a9 100644 --- a/lib/Surface.cxx +++ b/lib/Surface.cxx @@ -1,14 +1,12 @@ #include "vtkImageData.h" #include "vtkImageCast.h" #include "vtkActor.h" -#include "vtkPoints.h" #include "vtkPolyDataMapper.h" #include "vtkPolyData.h" #include "vtkProperty.h" #include "vtkFloatArray.h" #include "vtkType.h" #include "vtkDataSetMapper.h" -#include "vtkCellArray.h" #include "Surface.h" @@ -76,243 +74,149 @@ void Surface::surface(vtkImageData* imageData) /* images pointers */ - vtkPoints* surfacePoints = vtkPoints::New(); - vtkCellArray* surfaceCells = vtkCellArray::New(); - int counter=0; - + surfacePoints = vtkPoints::New(); + surfaceCells = vtkCellArray::New(); + if(imageType == VTK_CHAR) { // pointers to get into the image - char* dataImagePointer=NULL; - - // we start where the image starts - dataImagePointer=(char*)imageData->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; + char* dataImagePointer=NULL; + + char max = VTK_CHAR_MAX; - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_CHAR_MAX); + // pointers to get into the image + signed char* dataImagePointer=NULL; - surfacePoints->InsertPoint(counter, i, j, sum1*height); + signed char max = VTK_SIGNED_CHAR_MAX; - counter ++; - } - } + surfaceByType(dataImagePointer, imageData, max); } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); + // pointers to get into the image + unsigned char* dataImagePointer=NULL; - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + unsigned char max = VTK_UNSIGNED_CHAR_MAX; - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_SIGNED_CHAR_MAX); + // pointers to get into the image + short* dataImagePointer=NULL; - surfacePoints->InsertPoint(counter, i, j, sum1*height); + short max = VTK_SHORT_MAX; - counter ++; - } - } + surfaceByType(dataImagePointer, imageData, max); } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); + // pointers to get into the image + unsigned short* dataImagePointer=NULL; - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + unsigned short max = VTK_UNSIGNED_SHORT_MAX; - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; + unsigned int* dataImagePointer=NULL; + + unsigned int max = VTK_UNSIGNED_INT_MAX; - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); + // pointers to get into the image + long* dataImagePointer=NULL; + + long max = VTK_LONG_MAX; - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_UNSIGNED_CHAR_MAX); + surfaceByType(dataImagePointer, imageData, max); + } + else if(imageType == VTK_UNSIGNED_LONG) + { + // pointers to get into the image + unsigned long* dataImagePointer=NULL; - surfacePoints->InsertPoint(counter, i, j, sum1*height); + unsigned long max = VTK_UNSIGNED_LONG_MAX; - counter ++; - } - } + surfaceByType(dataImagePointer, imageData, max); } + else if(imageType == VTK_FLOAT) + { + // pointers to get into the image + float* dataImagePointer=NULL; - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); + // pointers to get into the image + double* dataImagePointer=NULL; - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + double max = VTK_DOUBLE_MAX; - if(jSetPolys(surfaceCells); + surfaceData->SetPoints(surfacePoints); + surfaceData->Update(); + + vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New(); + surfaceMapper->SetInput(surfaceData); + surfaceMapper->Update(); + + surfaceResult->SetMapper(surfaceMapper); + surfaceResult->GetProperty()->SetOpacity(1.0); + + if (color == "RED") + { + surfaceResult->GetProperty()->SetColor(1,0,0); } - else if(imageType == VTK_SHORT) + else if (color == "BLUE") + { + surfaceResult->GetProperty()->SetColor(0,0,1); + } + else if (color == "GREEN") + { + surfaceResult->GetProperty()->SetColor(0,1,0); + } + else { - // pointers to get into the image - short* dataImagePointer=NULL; + surfaceResult->GetProperty()->SetColor(1,1,1); + } +} + +/* +Template for constructing the surface by image type +*/ +template +void Surface::surfaceByType(T* dataImagePointer, vtkImageData* imageData, T max) +{ + int counter=0; // we start where the image starts - dataImagePointer=(short*)imageData->GetScalarPointer(0,0,0); + dataImagePointer=(T*)imageData->GetScalarPointer(0,0,0); /* Image Size @@ -338,10 +242,10 @@ void Surface::surface(vtkImageData* imageData) { // we get the pointer to the position (i,j,k)y that way we can get the position of the point in the surface - dataImagePointer=(short*)imageData->GetScalarPointer(i,j,k); + dataImagePointer=(T*)imageData->GetScalarPointer(i,j,k); - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_SHORT_MAX); + sum1=(T)(dataImagePointer[0]) + (T)(dataImagePointer[1]) + (T)(dataImagePointer[2]); + sum1=sum1/(3*max); surfacePoints->InsertPoint(counter, i, j, sum1*height); @@ -380,571 +284,8 @@ void Surface::surface(vtkImageData* imageData) } } } +} - } - else if(imageType == VTK_UNSIGNED_SHORT) - { - // pointers to get into the image - unsigned short* dataImagePointer=NULL; - - // we start where the image starts - dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_UNSIGNED_SHORT_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_INT_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_UNSIGNED_INT_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_LONG_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_UNSIGNED_LONG_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_FLOAT_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jGetScalarPointer(0,0,0); - - /* - Image Size - */ - int ext[6]; - imageData->GetExtent(ext); - int sx,sy,sz; - sx=ext[1]-ext[0]+1; - sy=ext[3]-ext[2]+1; - sz=ext[5]-ext[4]+1; - - //----------------- - //A3 - //----------------- - //walking in the image - int i=0,j=0,k=0; - double sum1=0,sum2=0,sum3=0,sum4=0; - for(i=0;iGetScalarPointer(i,j,k); - - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_DOUBLE_MAX); - - surfacePoints->InsertPoint(counter, i, j, sum1*height); - - counter ++; - } - } - } - - //This cycle creates the cells of the surface - int n =0; - for(i=0;iInsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+1); - surfaceCells->InsertCellPoint(n+sy+1); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); - - if(jSetPolys(surfaceCells); - surfaceData->SetPoints(surfacePoints); - surfaceData->Update(); - - vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New(); - surfaceMapper->SetInput(surfaceData); - surfaceMapper->Update(); - - surfaceResult->SetMapper(surfaceMapper); - surfaceResult->GetProperty()->SetOpacity(1.0); - - if (color == "RED") - { - surfaceResult->GetProperty()->SetColor(1,0,0); - } - else if (color == "BLUE") - { - surfaceResult->GetProperty()->SetColor(0,0,1); - } - else if (color == "GREEN") - { - surfaceResult->GetProperty()->SetColor(0,1,0); - } - else - { - surfaceResult->GetProperty()->SetColor(1,1,1); - } -} /* Returns the filtered image */ diff --git a/lib/Surface.h b/lib/Surface.h index ed7a826..20e0f8b 100644 --- a/lib/Surface.h +++ b/lib/Surface.h @@ -1,6 +1,8 @@ #include "vtkImageData.h" #include "vtkProp3D.h" #include "vtkRenderer.h" +#include "vtkPoints.h" +#include "vtkCellArray.h" #include @@ -34,9 +36,14 @@ class Surface vtkActor* getSurface(); /* - constructing image substract + constructing image surface */ void surface(vtkImageData* imageData); + + /* + Template for constructing the surface by image type + */ + template void surfaceByType(T* dataImagePointer, vtkImageData* imageData, T max); @@ -63,5 +70,15 @@ class Surface The type of image being viewed */ int imageType; + + /* + The points of the surface + */ + vtkPoints* surfacePoints; + + /* + Cells to be constructed from the surface + */ + vtkCellArray* surfaceCells; }; diff --git a/lib/Transformer.cxx b/lib/Transformer.cxx index 8c34e09..e6e6c8b 100644 --- a/lib/Transformer.cxx +++ b/lib/Transformer.cxx @@ -15,10 +15,9 @@ Transformer::Transformer() //If the transform already exists, we delete it before we create a new transform //and set the matrix with the identity matrix _transform= vtkTransform::New(); - vtkMatrix4x4 *_matrix = vtkMatrix4x4::New(); + _matrix = vtkMatrix4x4::New(); _matrix->Identity(); - _transform->SetMatrix(_matrix); - + _transform->SetMatrix(_matrix); } /* @@ -28,6 +27,7 @@ Transformer::~Transformer() { //We delete the existing transform if (_transform != NULL ) { _transform->Delete(); } + if (_matrix != NULL ) { _matrix->Delete(); } } /* @@ -96,8 +96,8 @@ void Transformer::Run() _transform->Identity(); _transform->Translate(_centerPoint[0], _centerPoint[1], _centerPoint[2]); - _transform->Scale(_scaleX, _scaleY,_scaleZ); _transform->RotateWXYZ(_angle, 0, 0, 1); - + _transform->Scale(_scaleX, _scaleY,_scaleZ); + _transform->Update(); } diff --git a/lib/Transformer.h b/lib/Transformer.h index 327eae6..e7a40e0 100644 --- a/lib/Transformer.h +++ b/lib/Transformer.h @@ -27,6 +27,9 @@ private: double _scaleZ; //vtkImageData *_image; vtkTransform *_transform; + + // + vtkMatrix4x4 *_matrix; }; #endif diff --git a/lib/Transparency.cxx b/lib/Transparency.cxx index eee092b..1459e2d 100644 --- a/lib/Transparency.cxx +++ b/lib/Transparency.cxx @@ -138,20 +138,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX char* dataImagePointer2 = NULL; char* dataImageResultPointer = NULL; - dataImagePointer1 = (char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (char*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (char*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (char)*dataImagePointer1*_percent + (char)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_SIGNED_CHAR) { @@ -160,20 +147,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX signed char* dataImagePointer2 = NULL; signed char* dataImageResultPointer = NULL; - dataImagePointer1 = (signed char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (signed char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (signed char*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (signed char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (signed char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (signed char*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (signed char)*dataImagePointer1*_percent + (signed char)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_UNSIGNED_CHAR) { @@ -182,20 +156,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX unsigned char* dataImagePointer2 = NULL; unsigned char* dataImageResultPointer = NULL; - dataImagePointer1 = (unsigned char*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned char*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned char*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned char*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned char*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned char*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (unsigned char)*dataImagePointer1*_percent + (unsigned char)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_SHORT) { @@ -204,20 +165,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX short* dataImagePointer2 = NULL; short* dataImageResultPointer = NULL; - dataImagePointer1 = (short*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (short*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (short*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (short*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (short*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (short*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (short)*dataImagePointer1*_percent + (short)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_UNSIGNED_SHORT) { @@ -226,20 +174,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX unsigned short* dataImagePointer2 = NULL; unsigned short* dataImageResultPointer = NULL; - dataImagePointer1 = (unsigned short*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned short*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned short*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned short*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned short*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned short*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (unsigned short)*dataImagePointer1*_percent + (unsigned short)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_INT) { @@ -248,20 +183,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX int* dataImagePointer2 = NULL; int* dataImageResultPointer = NULL; - dataImagePointer1 = (int*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (int*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (int*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (int*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (int*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (int*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (int)*dataImagePointer1*_percent + (int)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_UNSIGNED_INT) { @@ -270,20 +192,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX unsigned int* dataImagePointer2 = NULL; unsigned int* dataImageResultPointer = NULL; - dataImagePointer1 = (unsigned int*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned int*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned int*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned int*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned int*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned int*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (unsigned int)*dataImagePointer1*_percent + (unsigned int)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_LONG) { @@ -292,20 +201,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX long* dataImagePointer2 = NULL; long* dataImageResultPointer = NULL; - dataImagePointer1 = (long*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (long*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (long*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (long*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (long*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (long*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (long)*dataImagePointer1*_percent + (long)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_UNSIGNED_LONG) { @@ -314,20 +210,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX unsigned long* dataImagePointer2 = NULL; unsigned long* dataImageResultPointer = NULL; - dataImagePointer1 = (unsigned long*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (unsigned long*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (unsigned long*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (unsigned long*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (unsigned long*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (unsigned long*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (unsigned long)*dataImagePointer1*_percent + (unsigned long)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_FLOAT) { @@ -336,20 +219,7 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX float* dataImagePointer2 = NULL; float* dataImageResultPointer = NULL; - dataImagePointer1 = (float*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (float*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (float*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) - { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (float*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (float*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (float*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (float)*dataImagePointer1*_percent + (float)*dataImagePointer2*(1-_percent); - } - } + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); } else if(_type == VTK_DOUBLE) { @@ -357,24 +227,32 @@ void Transparency::createImage(vtkImageData *img1, vtkImageData *img2, int sizeX double* dataImagePointer1 = NULL; double* dataImagePointer2 = NULL; double* dataImageResultPointer = NULL; + + createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY); + } + + _newImage->Update(); +} + +template +void Transparency::createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY) +{ + int i, j; - dataImagePointer1 = (double*) img1->GetScalarPointer(0,0,0); - dataImagePointer2 = (double*) img2->GetScalarPointer(0,0,0); - dataImageResultPointer = (double*) _newImage->GetScalarPointer(0,0,0); - for(i = 0; i < sizeX; i++) + dataImagePointer1 = (T*) img1->GetScalarPointer(0,0,0); + dataImagePointer2 = (T*) img2->GetScalarPointer(0,0,0); + dataImageResultPointer = (T*) _newImage->GetScalarPointer(0,0,0); + for(i = 0; i < sizeX; i++) + { + for(j = 0; j < sizeY; j++) { - for(j = 0; j < sizeY; j++) - { - dataImagePointer1 = (double*)img1->GetScalarPointer(i,j,0); - dataImagePointer2 = (double*)img2->GetScalarPointer(i,j,0); - dataImageResultPointer = (double*)_newImage->GetScalarPointer(i,j,0); - - *dataImageResultPointer = (double)*dataImagePointer1*_percent + (double)*dataImagePointer2*(1-_percent); - } + dataImagePointer1 = (T*)img1->GetScalarPointer(i,j,0); + dataImagePointer2 = (T*)img2->GetScalarPointer(i,j,0); + dataImageResultPointer = (T*)_newImage->GetScalarPointer(i,j,0); + + *dataImageResultPointer = (T)*dataImagePointer1*_percent + (T)*dataImagePointer2*(1-_percent); } } - - _newImage->Update(); } /* diff --git a/lib/Transparency.h b/lib/Transparency.h index f75c4df..c28214f 100644 --- a/lib/Transparency.h +++ b/lib/Transparency.h @@ -26,9 +26,12 @@ class Transparency //Initialize newImage points void initialize(int dimensions[], double spacing[]); - //Constructs new transparent image + //Constructs a new transparent image void createImage(vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY); + //Template for constructing the image by image type + template void createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY); + // --- Atributes --- // private: -- 2.47.1