newImage = NULL;
processed=false;
newImage = NULL;
+ resample = NULL;
+ result = NULL;
}
/*
//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(); }
}
//------------------------------------------------------------
double factorX = 1;
double factorY = 1;
- vtkImageResample *resample = vtkImageResample::New();
- vtkImageData *result;
+ resample = vtkImageResample::New();
+ result = vtkImageData::New();
if(numPixelsImg1<numPixelsImg2)
{
resample->SetInput(image1);
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)
{
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)
{
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)
{
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)
{
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)
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)
{
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)
{
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)
{
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)
{
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)
{
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);
}
newImage->Update();
// newImage->Modified();
}
+/**Template used for the different image types
+*/
+template <class T>
+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
void setCols(int cols);
void setRows(int rows);
+ template <class T> void createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY);
// --- Atributes --- //
private:
//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;
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(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)
{
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<sx;i++)
+template <class T>
+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;i<sx;i++)
+ {
+ for(j=0;j<sy;j++)
{
- for(j=0;j<sy;j++)
+ for(k=0;k<sz;k++)
{
- for(k=0;k<sz;k++)
- {
- // 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=(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
*/
constructing image substract
*/
void substract(vtkImageData* imageData1, vtkImageData* imageData2);
+
+ /*
+ Template method of substract for different image types
+ */
+ template <class T> void substractByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *imageData1, vtkImageData *imageData2);
#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"
/*
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;i<sx;i++)
+ surfaceByType(dataImagePointer, imageData, max);
+ }
+ else if(imageType == VTK_SIGNED_CHAR)
{
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(char*)imageData->GetScalarPointer(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;i<sx-1;i++)
+ else if(imageType == VTK_UNSIGNED_CHAR)
{
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
+ surfaceByType(dataImagePointer, imageData, max);
}
- else if(imageType == VTK_SIGNED_CHAR)
- {
- // pointers to get into the image
- signed char* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(signed 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;
-
- //-----------------
- //A3
- //-----------------
- //walking in the image
- int i=0,j=0,k=0;
- double sum1=0,sum2=0,sum3=0,sum4=0;
- for(i=0;i<sx;i++)
+ else if(imageType == VTK_SHORT)
{
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(signed char*)imageData->GetScalarPointer(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;i<sx-1;i++)
+ else if(imageType == VTK_UNSIGNED_SHORT)
{
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
+ surfaceByType(dataImagePointer, imageData, max);
}
+ else if(imageType == VTK_INT)
+ {
+ // pointers to get into the image
+ int* dataImagePointer=NULL;
+
+ int max = VTK_INT_MAX;
+ surfaceByType(dataImagePointer, imageData, max);
}
- else if(imageType == VTK_UNSIGNED_CHAR)
+ else if(imageType == VTK_UNSIGNED_INT)
{
// pointers to get into the image
- unsigned char* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(unsigned 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;
+ 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;i<sx;i++)
+ surfaceByType(dataImagePointer, imageData, max);
+ }
+ else if(imageType == VTK_LONG)
{
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(unsigned char*)imageData->GetScalarPointer(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;i<sx-1;i++)
+ float max = VTK_FLOAT_MAX;
+
+ surfaceByType(dataImagePointer, imageData, max);
+ }
+ else if(imageType == VTK_DOUBLE)
{
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
+ surfaceByType(dataImagePointer, imageData, max);
}
+
+ vtkPolyData* surfaceData = vtkPolyData::New();
+ surfaceData->SetPolys(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 <class T>
+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
{
// 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);
}
}
}
+}
- }
- 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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(unsigned short*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_INT)
- {
- // pointers to get into the image
- int* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(int*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(int*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_UNSIGNED_INT)
- {
- // pointers to get into the image
- unsigned int* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(unsigned int*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(unsigned int*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_LONG)
- {
- // pointers to get into the image
- long* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(long*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(long*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_UNSIGNED_LONG)
- {
- // pointers to get into the image
- unsigned long* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(unsigned long*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(unsigned long*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_FLOAT)
- {
- // pointers to get into the image
- float* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(float*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(float*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
- else if(imageType == VTK_DOUBLE)
- {
- std::cout << "Got inside Double" << std::endl;
- // pointers to get into the image
- double* dataImagePointer=NULL;
-
- // we start where the image starts
- dataImagePointer=(double*)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;i<sx;i++)
- {
- for(j=0;j<sy;j++)
- {
- for(k=0;k<sz;k++)
- {
-
- // 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=(double*)imageData->GetScalarPointer(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;i<sx-1;i++)
- {
- for(j=0;j<sy-1;j++)
- {
- for(k=0;k<sz;k++)
- {
- surfaceCells->InsertNextCell(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(j<sy-2)
- {
- n++;
- }
- else
- {
- n=n+2;
- }
-
- }
- }
- }
-
- }
-
- vtkPolyData* surfaceData = vtkPolyData::New();
- surfaceData->SetPolys(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
*/
#include "vtkImageData.h"
#include "vtkProp3D.h"
#include "vtkRenderer.h"
+#include "vtkPoints.h"
+#include "vtkCellArray.h"
#include <string>
vtkActor* getSurface();
/*
- constructing image substract
+ constructing image surface
*/
void surface(vtkImageData* imageData);
+
+ /*
+ Template for constructing the surface by image type
+ */
+ template <class T> void surfaceByType(T* dataImagePointer, vtkImageData* imageData, T max);
The type of image being viewed
*/
int imageType;
+
+ /*
+ The points of the surface
+ */
+ vtkPoints* surfacePoints;
+
+ /*
+ Cells to be constructed from the surface
+ */
+ vtkCellArray* surfaceCells;
};
//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);
}
/*
{
//We delete the existing transform
if (_transform != NULL ) { _transform->Delete(); }
+ if (_matrix != NULL ) { _matrix->Delete(); }
}
/*
_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();
}
double _scaleZ;
//vtkImageData *_image;
vtkTransform *_transform;
+
+ //
+ vtkMatrix4x4 *_matrix;
};
#endif
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
double* dataImagePointer1 = NULL;
double* dataImagePointer2 = NULL;
double* dataImageResultPointer = NULL;
+
+ createImageByType(dataImagePointer1, dataImagePointer2, dataImageResultPointer, img1, img2, sizeX, sizeY);
+ }
+
+ _newImage->Update();
+}
+
+template <class T>
+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();
}
/*
//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 <class T> void createImageByType(T* dataImagePointer1, T* dataImagePointer2, T* dataImageResultPointer, vtkImageData *img1, vtkImageData *img2, int sizeX, int sizeY);
+
// --- Atributes --- //
private: