[vtkusers] intersect plane and vtkPolyData

João Domingos joao.sousa.domingos at gmail.com
Mon Jul 30 08:17:23 EDT 2012


Dear all,

I was trying to use the PolyDataToImageData example (
http://www.vtk.org/Wiki/VTK/Examples/PolyData/PolyDataToImageData) to get
the intersection of a vtkPolyData with a plane in a given orientation, but
to start with, I cannot even run the example in python. With the code below
I get a TypeError: no overloads of SetInput() take 0 arguments


#--------------------------------------------------------------------------------
# Create LV segmentation image where the foreground voxels are 1 and the
background voxels are 0. Internally vtkPolyDataToImageStencil is utilized.
The resultant image is saved to disk
 spacing = np.zeros(3)

whiteImage = vtk.vtkImageData()
bounds = self.dsurf.dense_representation_grid.GetBounds()
 spacing[0] = 0.0960 # desired volume spacing (.mha info): ElementSpacing =
0.0960 0.0968 0.0726
 spacing[1] = 0.0968
spacing[2] = 0.0726
whiteImage.SetSpacing(spacing)
 # Compute dimensions:
 dim = []
dim.append((bounds[1] - bounds[0])/spacing[0])
dim.append((bounds[3] - bounds[2])/spacing[1])
 dim.append((bounds[5] - bounds[4])/spacing[2])

whiteImage.SetDimensions(dim)
 whiteImage.SetExtent(0, dim[0]-1,0,dim[1]-1,0,dim[2]-1)

origin = np.zeros(3)

origin[0] = bounds[0] + spacing[0] / 2;
  origin[1] = bounds[2] + spacing[1] / 2;
  origin[2] = bounds[4] + spacing[2] / 2;
  whiteImage.SetOrigin(origin);

whiteImage.SetScalarTypeToUnsignedChar()
whiteImage.AllocateScalars();

inval = 255;
  outval = 0;
  count = whiteImage.GetNumberOfPoints();
  for i in range(0,count):
    whiteImage.GetPointData().GetScalars().SetTuple1(i, inval);

# polygonal data --> image stencil:
pol2stenc = vtk.vtkPolyDataToImageStencil()
 pol2stenc.SetInput(self.dsurf.dense_representation_grid)
pol2stenc.SetOutputOrigin(origin);
  pol2stenc.SetOutputSpacing(spacing);
  pol2stenc.SetOutputWholeExtent(whiteImage.GetExtent());
  pol2stenc.Update();

# cut the corresponding white image and set the background:
 imgstenc = vtk.vtkImageStencil
imgstenc.SetInput(whiteImage);
  imgstenc.SetStencilConnection(pol2stenc.GetOutputPort());
 imgstenc.ReverseStencilOff();
  imgstenc.SetBackgroundValue(outval);
  imgstenc.Update();

  writer = vtk.vtkMetaImageWriter()
  writer.SetFileName("SphereVolume.mhd");
 writer.SetInputData(imgstenc.GetOutput());
writer.Write();
#------------------------------------------------------------------------------------


Do you see what can the problem be? Also, I have a plane, vtkImageReslice
type, that I want to specifically give as input to the vtkImageStencil (If
I'm not mistaken) to get the intersection of my vtkPolyData with that
oriented plane. How can I do this the most simple way?


Many thanks for your time,
Joao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120730/b78328cd/attachment.htm>


More information about the vtkusers mailing list