+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Santé)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
#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);
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ surfaceData->Update();
+#else
+ // ..
+#endif
+
+ vtkPolyDataMapper* surfaceMapper = vtkPolyDataMapper::New();
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ surfaceMapper->SetInput(surfaceData);
+#else
+ surfaceMapper->SetInputData(surfaceData);
+#endif
+ 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(imageType == VTK_SHORT)
+ 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
//-----------------
//walking in the image
int i=0,j=0,k=0;
- double sum1=0,sum2=0,sum3=0,sum4=0;
+ double sum1=0;
+ //double sum2=0,sum3=0,sum4=0; // JPR : unused
for(i=0;i<sx;i++)
{
for(j=0;j<sy;j++)
{
// 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
*/