[vtkusers] how to use vtkImplicitPlaneWidget on image data?

paul biegel hammermanneke at hotmail.com
Fri Jul 29 05:10:25 EDT 2011


Hi all,

I used the code below to visualize a mesh and use an implicit plane widget
to cut
through that mesh (see attachment). Now I want to do the same with image
data 
and I only want to display the image data onto the implicit plane. Any idea
how to 
do that?

Kind regards,
Paul Biegel


*****************************************************************
import vtk

# cut function
def Cut(v):
    clipper.SetValue(v)
    cutEdges.SetValue(0, v)
    cutStrips.Update()
    cutPoly.SetPoints(cutStrips.GetOutput().GetPoints())
    cutPoly.SetPolys(cutStrips.GetOutput().GetLines())
    cutMapper.Update()
    renWin.Render()

# callback function
def myCallback(obj, event):
    global plane, selectActor
    obj.GetPlane(plane)
    Cut(0.0)# Associate the line widget with the interactor	
	
# read mesh
mesh = vtk.vtkUnstructuredGridReader()
mesh.SetFileName(r"mesh.vtk")
mesh.Update()

surfaceFilter = vtk.vtkDataSetSurfaceFilter()
surfaceFilter.SetInput(mesh.GetOutput())
surfaceFilter.Update() 

meshNormals = vtk.vtkPolyDataNormals()
meshNormals.SetInput(surfaceFilter.GetOutput())

# clip data
plane = vtk.vtkPlane()
clipper = vtk.vtkClipPolyData()
clipper.SetInput(meshNormals.GetOutput())
clipper.SetClipFunction(plane)
clipper.GenerateClipScalarsOn()
clipper.GenerateClippedOutputOn()
clipper.SetValue(0.0)

clipMapper = vtk.vtkPolyDataMapper()
clipMapper.SetInput(clipper.GetOutput())
clipMapper.ScalarVisibilityOff()

backProp = vtk.vtkProperty()
backProp.SetDiffuseColor((1.0,0.0,0.0))

clipActor = vtk.vtkActor()
clipActor.SetMapper(clipMapper)
clipActor.GetProperty().SetColor((0.0,1.0,0.0))
clipActor.SetBackfaceProperty(backProp)

# cut mesh
cutEdges = vtk.vtkCutter()
cutEdges.SetInput(meshNormals.GetOutput())
cutEdges.SetCutFunction(plane)
cutEdges.GenerateCutScalarsOn()
cutEdges.SetValue(0, 0.0)

cutStrips = vtk.vtkStripper()
cutStrips.SetInput(cutEdges.GetOutput())
cutStrips.Update()

cutPoly = vtk.vtkPolyData()
cutPoly.SetPoints(cutStrips.GetOutput().GetPoints())
cutPoly.SetPolys(cutStrips.GetOutput().GetLines())

cutTriangles = vtk.vtkTriangleFilter()
cutTriangles.SetInput(cutPoly)

cutMapper = vtk.vtkPolyDataMapper()
cutMapper.SetInput(cutTriangles.GetOutput())

cutActor = vtk.vtkActor()
cutActor.SetMapper(cutMapper)
cutActor.GetProperty().SetColor((0.0,0.0,1.0))

# The clipped part of the mesh is rendered wireframe.
restMapper = vtk.vtkPolyDataMapper()
restMapper.SetInput(clipper.GetClippedOutput())
restMapper.ScalarVisibilityOff()

restActor = vtk.vtkActor()
restActor.SetMapper(restMapper)
restActor.GetProperty().SetRepresentationToWireframe()

# Create graphics stuff
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
interactorStyle = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(interactorStyle)
iren.SetRenderWindow(renWin)

# Create plane stuff
planeWidget = vtk.vtkImplicitPlaneWidget()
planeWidget.SetNormalToZAxis(1)
planeWidget.DrawPlaneOff()
planeWidget.SetInteractor(iren)
planeWidget.SetPlaceFactor(1.5)
planeWidget.SetInput(meshNormals.GetOutput())
planeWidget.PlaceWidget()
planeWidget.AddObserver("InteractionEvent", myCallback)
planeWidget.On()

# Add the actors to the renderer, set the background and size
ren.AddActor(clipActor)
ren.AddActor(cutActor)
ren.AddActor(restActor)
ren.SetBackground(0.0, 0.0, 0.0)
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(30)
ren.GetActiveCamera().Dolly(0.03)
ren.ResetCameraClippingRange()

renWin.SetSize(700, 700)
iren.Initialize()
renWin.Render()
iren.Start() 

http://vtk.1045678.n5.nabble.com/file/n4646313/mesh.png 

--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-use-vtkImplicitPlaneWidget-on-image-data-tp4646313p4646313.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list