[vtkusers] Please Help: How to convert vtkPolyData into vtkImageData?
Hala ALBakour
haloul02 at yahoo.co.uk
Mon Dec 31 07:27:18 EST 2007
Dear all,
I am strugling to convert poly data in vtk into
image/volume data using the vtkProbeFilter class, the
reason I want to do this is to apply slicing on the
output image to extract x,y values for every 2D slice,
I don't know the most sensible way of doing it as I am
very new to this area, but this my piece of code which
is not working, the extracted output image I get is
always empty, I am trying to apply the filter here on
a simple cube polydata, am I doing something wrong
here, should I use something else in addition to the
probe filter, I could not find enough materials and
examples illustrating the usage of the ProbeFilter,
please advise,
Hala
int i;
float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0},
{0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}};
vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
{1,2,6,5}, {2,3,7,6}, {3,0,4,7}};
vtkPolyData *cube = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
vtkIntArray *scalars = vtkIntArray::New();
// Load the point, cell, and data attributes.
for (i=0; i<8; i++) points->InsertPoint(i,x[i]);
for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
for (i=0; i<8; i++) scalars->InsertTuple1(i,i);
// We now assign the pieces to the vtkPolyData.
cube->SetPoints(points);
points->Delete();
cube->SetPolys(polys);
polys->Delete();
cube->GetPointData()->SetScalars(scalars);
scalars->Delete();
vtkImageData* m_currentImageData =
vtkImageData::New();
m_currentImageData->SetDimensions(26,26,26);
vtkImageData* samplingArray = vtkImageData::New();
samplingArray->SetNumberOfScalarComponents(1);
samplingArray->SetScalarTypeToInt();
samplingArray->SetSpacing(1,1,1);
samplingArray->SetDimensions(26,26,26);
samplingArray->SetOrigin( 0,0,0 );
samplingArray->Update();
vtkProbeFilter* filter = vtkProbeFilter::New();
filter->SetInput(samplingArray);
filter->SetSource(cube);
m_currentImageData->DeepCopy(filter->GetImageDataOutput());
__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
More information about the vtkusers
mailing list