# Clip a cylinder shell to produce a a trim loop. shell = vtk.vtkCylinderSource() shell.SetCenter(0,0,0) shell.SetResolution(cylRes) shell.SetHeight(5) shell.CappingOff() shell.Update() clippedShell = vtk.vtkPolyDataPlaneClipper() clippedShell.SetInputConnection(shell.GetOutputPort()) clippedShell.SetPlane(plane) clippedShell.ClippingLoopsOn() clippedShell.CappingOff() clippedShell.Update() sampleImp = vtk.vtkSampleImplicitFunctionFilter() sampleImp.SetInputConnection(clippedShell.GetOutputPort(1)) sampleImp.SetImplicitFunction(plane) sampleImp.ComputeGradientsOff() sampleImp.SetScalarArrayName("scalars") sampleImp.Update() clippedShellMapper = vtk.vtkPolyDataMapper() clippedShellMapper.SetInputConnection(sampleImp.GetOutputPort()) clippedShellMapper.ScalarVisibilityOff() clippedShellActor = vtk.vtkActor() clippedShellActor.SetMapper(clippedShellMapper); trimMapper = vtk.vtkPolyDataMapper() trimMapper.SetInputConnection(sampleImp.GetOutputPort(0))
sphere.SetCenter( 0.0,0.0,0.0) sphere.SetRadius(0.25) sample = vtk.vtkSampleFunction() sample.SetImplicitFunction(sphere) sample.SetModelBounds(-0.5,0.5, -0.5,0.5, -0.5,0.5) sample.SetSampleDimensions(res,res,res) sample.ComputeNormalsOff() sample.Update() # Now create some new attributes to interpolate cyl = vtk.vtkCylinder() cyl.SetRadius(0.1) cyl.SetAxis(1,1,1) attr = vtk.vtkSampleImplicitFunctionFilter() attr.SetInputConnection(sample.GetOutputPort()) attr.SetImplicitFunction(cyl) attr.ComputeGradientsOn() attr.Update() # The cut plane plane = vtk.vtkPlane() plane.SetOrigin(-.2,-.2,-.2) plane.SetNormal(1,1,1) # Perform the cutting on named scalars cut = vtk.vtkFlyingEdgesPlaneCutter() cut.SetInputConnection(attr.GetOutputPort()) cut.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "scalars") cut.SetPlane(plane)