[vtkusers] How to crop a rectangular volume of interest from an image when your roi is defined as polydata?

Sachin Jambawalikar sachinjam at gmail.com
Mon Feb 16 12:57:32 EST 2009


Hi all,

I  generated a  vtkcube source and then used vtktransform to scale
translate and rotate the cube so that it become a rectangular voi .
I use the  vtkTransformPolydataFilter  to apply the transform to the
cube data. This polydata is then mapped into a vtkactor and added
along with exisitng volume data to vtksliceviewer2.
This works well and I see a rectangular voi shifted , scaled and
translated from center of my volume data.

However what I'm trying to develop is a vtk slice viewer which will
show   the region of intersection of the volume of interest and the
image data in each slice (like an alpha-blended overlay rather than a
polygon actor which occlude the slice). I need to generate a subvolume
of the Original data from this transformed rectangular voi.  I have
seen people using vtkextractvoi by first using vtkoutlinefilter to
generate a bounding box. However bounding box limits are not the same
as the polydata (because when I display an actor from vtkoutlinefilter
it is bigger and doesnot show angulation as shown by the trinangulated
polydata actor)

What I need to do is extract  a subvolume form Image data
corresponding to the  rectangular voi. Create a composite volume (or
overlay the  voi volume )and then hopefully be able to show the voi
volume
transparent overlayed on Image data so as I move through the slices
Ican see the structure of the original data  inside the voi. I have
attached the code  as to how i generate my rectangular voi and it
seems to work.


Thanks for all your help

Regards
--Sachin





vtkImagedata=reader.GetOutput()

(xMin, xMax, yMin, yMax, zMin, zMax) = reader.GetOutput().GetWholeExtent()
(sx, sy, sz) = reader.GetOutput().GetSpacing()
print sz
(ox, oy, oz) = reader.GetOutput().GetOrigin()
#print (x0, y0, z0)
center = [ox + sx * 0.5 * (xMin + xMax),
         oy + sy * 0.5 * (yMin + yMax),
         oz + sz * 0.5 * (zMin + zMax)]



# An outline is shown for context.
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(reader.GetOutputPort())

outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())

outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)

####roi
cube = vtk.vtkCubeSource()
cube.SetXLength(1);
cube.SetYLength(1);
cube.SetZLength(1);
vtkmath=vtk.vtkMath()


transP1 = vtk.vtkTransform()
transP1.Identity()
transP1.PostMultiply()

transP1.Scale(10, 27.5,9.942770958)
transP1.RotateX(22.90897369)
transP1.RotateY(0.1529316902)

#transP1.RotateX(0)
transP1.RotateZ(0.7547413111)

transP1.Translate(center[0]-22, center[1]-17, center[2]+11)


tpd1 = vtk.vtkTransformPolyDataFilter()
tpd1.SetInputConnection(cube.GetOutputPort())
tpd1.SetTransform(transP1)

#triangulate points
triangle=vtk.vtkTriangleFilter()
triangle.SetInputConnection(tpd1.GetOutputPort())

#outTpd1 = vtk.vtkOutlineFilter()
#outTpd1.SetInputConnection(triangle.GetOutputPort())

#mapper
mapTpd1 = vtk.vtkPolyDataMapper()
#mapTpd1.SetInputConnection(outTpd1.GetOutputPort())
mapTpd1.SetInputConnection(triangle.GetOutputPort())

#Actor
roiActor = vtk.vtkActor()
roiActor.SetMapper(mapTpd1)
roiActor.GetProperty().SetColor(1, 0, 0)



More information about the vtkusers mailing list