X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FSurface.cxx;h=08993a91925fc4959d37d82edd5c8549602f4154;hb=bb6bffc75df349b5f74f4197206718a87b42e4a7;hp=d1bf681285c718869e10275f3e685b4c4833a87d;hpb=aa1b23f7a0b103bc3fd8989c0e60b97697adbbc3;p=creaRigidRegistration.git diff --git a/lib/Surface.cxx b/lib/Surface.cxx index d1bf681..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,776 +74,149 @@ void Surface::surface(vtkImageData* imageData) /* images pointers */ - vtkPoints* surfacePoints = vtkPoints::New(); - vtkCellArray* surfaceCells = vtkCellArray::New(); - int counter=0; - - 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; - - //----------------- - //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); - - 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_SIGNED_CHAR_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_CHAR_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_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_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); + // pointers to get into the image + char* dataImagePointer=NULL; + + char max = VTK_CHAR_MAX; - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_LONG_MAX); + surfaceByType(dataImagePointer, imageData, max); + } + else if(imageType == VTK_SIGNED_CHAR) + { + // 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); - - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + // pointers to get into the image + unsigned char* dataImagePointer=NULL; - 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; + // pointers to get into the image + short* dataImagePointer=NULL; - //----------------- - //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); + short max = VTK_SHORT_MAX; - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_UNSIGNED_LONG_MAX); + surfaceByType(dataImagePointer, imageData, max); + } + else if(imageType == VTK_UNSIGNED_SHORT) + { + // pointers to get into the image + unsigned short* dataImagePointer=NULL; - surfacePoints->InsertPoint(counter, i, j, sum1*height); + unsigned short max = VTK_UNSIGNED_SHORT_MAX; - counter ++; - } - } + surfaceByType(dataImagePointer, imageData, max); } + else if(imageType == VTK_INT) + { + // pointers to get into the image + int* dataImagePointer=NULL; + + int max = VTK_INT_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 int* dataImagePointer=NULL; + + unsigned int max = VTK_UNSIGNED_INT_MAX; - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + surfaceByType(dataImagePointer, imageData, max); + } + else if(imageType == VTK_LONG) + { + // pointers to get into the image + long* dataImagePointer=NULL; + + long max = VTK_LONG_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; + // pointers to get into the image + float* dataImagePointer=NULL; - //----------------- - //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); + float max = VTK_FLOAT_MAX; - sum1=(int)(dataImagePointer[0]) + (int)(dataImagePointer[1]) + (int)(dataImagePointer[2]); - sum1=sum1/(3*VTK_FLOAT_MAX); + surfaceByType(dataImagePointer, imageData, max); + } + else if(imageType == VTK_DOUBLE) + { + // pointers to get into the image + double* dataImagePointer=NULL; - surfacePoints->InsertPoint(counter, i, j, sum1*height); + double max = VTK_DOUBLE_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); + vtkPolyData* surfaceData = vtkPolyData::New(); + surfaceData->SetPolys(surfaceCells); + surfaceData->SetPoints(surfacePoints); + surfaceData->Update(); - surfaceCells->InsertNextCell(3); - surfaceCells->InsertCellPoint(n); - surfaceCells->InsertCellPoint(n+sy+1); - surfaceCells->InsertCellPoint(n+sy); + vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New(); + surfaceMapper->SetInput(surfaceData); + surfaceMapper->Update(); - if(jSetMapper(surfaceMapper); + surfaceResult->GetProperty()->SetOpacity(1.0); + if (color == "RED") + { + surfaceResult->GetProperty()->SetColor(1,0,0); } - else if(imageType == VTK_DOUBLE) + else if (color == "BLUE") + { + surfaceResult->GetProperty()->SetColor(0,0,1); + } + else if (color == "GREEN") + { + surfaceResult->GetProperty()->SetColor(0,1,0); + } + else { - std::cout << "Got inside Double" << std::endl; - // pointers to get into the image - double* 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=(double*)imageData->GetScalarPointer(0,0,0); + dataImagePointer=(T*)imageData->GetScalarPointer(0,0,0); /* Image Size @@ -871,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=(double*)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_DOUBLE_MAX); + sum1=(T)(dataImagePointer[0]) + (T)(dataImagePointer[1]) + (T)(dataImagePointer[2]); + sum1=sum1/(3*max); surfacePoints->InsertPoint(counter, i, j, sum1*height); @@ -913,42 +284,13 @@ void Surface::surface(vtkImageData* imageData) } } } - - } - - 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 */ vtkActor* Surface::getSurface() { return surfaceResult; -} \ No newline at end of file +} +