[vtkusers] Having trouble getting output from vtkCutter
Anja Ende
anja.ende at googlemail.com
Wed Jul 9 11:25:18 EDT 2008
Hello everyone,
I am having trouble getting polydata output from a vtkCutter object.
The use scenario is as follows:
I have a binary 3D volume as the input and what I need to do is get 2D
polygon data out depending on where I choose to intersect the volume
with my vtkPlane object. So, I do the following:
assuming I have a vtkImageData * image as input
// m_mc is my vtkImageMarchingCubes object.
// image is the input 3D image
m_mc->SetInput(image);
m_mc->ComputeNormalsOff();
m_mc->ComputeGradientsOff();
double * range = image->GetScalarRange();
// We get a contour where the binary bits are turned on.
m_mc->SetValue(0, range[1]); // range[1] = 1
m_mc->Update();
So, verifying the output data as follows, gives the following result:
vtkPolyData * data = m_mc->GetOutput();
std::cout << data->GetNumberOfVerts() << " " << data->GetNumberOfLines()
<< " " << data->GetNumberOfPolys() << " " <<
data->GetNumberOfCells() << std::endl;
And the output is:
0 0 100 100
So there is some output from the marching cubes object.
So, now I am trying to cut this data at the relevant places. For
testing, I just iterate through the slices and move the cutting plane
through the volume as follows:
// Get the origin and spacing of the input image
double * origin = image->GetOrigin();
double * spacing = image->GetSpacing();
// plane is my vtkPlane object instance
plane->SetOrigin(origin[0], origin[1], origin[2]);
// cutter is the vtkCutter instance
cutter->SetInput(data);
// numSlices is the number of slices in the original image
for (int i = 0; i < numSlices; ++i)
{
// shift the origin to cut at the current slice
plane->SetOrigin(origin[0] , origin[1] , origin[2]
+ i * spacing[2]);
cutter->SetCutFunction(plane);
cutter->Update();
// stripper is the vtkStripper instance
stripper->SetInput(cutter->GetOutput());
stripper->Update();
// poly is the vtkPolyData object
poly->SetPoints(stripper->GetOutput()->GetPoints());
poly->SetPolys(stripper->GetOutput()->GetLines());
vtkCellArray * ca = poly->GetPolys();
ca->InitTraversal();
vtkPoints * points = poly->GetPoints();
double pt[3] = {0.0, 0.0, 0.0};
vtkIdType npts;
vtkIdType *pts;
while(ca->GetNextCell(npts,pts))
{ // Never gets here! }
}
So, as you can see, I never get any output back from the
vtkCutter/vtkStripper. I am really not sure what I am missing here!
The input is a NIFTI file and if someone is interested, I can send the
input file to you.
I would really appreciate any help you might be able to give me on
this as I have a very urgent requirement.
Many thanks,
Anja
More information about the vtkusers
mailing list