def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkGaussianCubeReader(), 'Reading vtkGaussianCube.', (), ('vtkGaussianCube',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkGaussianCubeReader(), 'Reading vtkGaussianCube.', (), ('vtkGaussianCube', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
renWin.SetSize(300, 300) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) camera = vtk.vtkCamera() camera.ParallelProjectionOn() camera.SetViewUp(0, 1, 0) camera.SetFocalPoint(12, 10.5, 15) camera.SetPosition(-70, 15, 34) camera.ComputeViewPlaneNormal() ren1.SetActiveCamera(camera) # Create the reader for the data # vtkStructuredPointsReader reader reader = vtk.vtkGaussianCubeReader() reader.SetFileName(VTK_DATA_ROOT + "/Data/m4_TotalDensity.cube") reader.SetHBScale(1.1) reader.SetBScale(10) reader.Update() range = reader.GetGridOutput().GetPointData().GetScalars().GetRange() min = range[0] max = range[1] readerSS = vtk.vtkImageShiftScale() readerSS.SetInputData(reader.GetGridOutput()) readerSS.SetShift(min * -1) readerSS.SetScale(255 / (max - min)) readerSS.SetOutputScalarTypeToUnsignedChar()
#coding:utf-8 import vtk import os density = vtk.vtkGaussianCubeReader() curdir, fname = os.path.split(__file__) density.SetFileName(os.path.join(curdir, "models/crown.den.cube")) density.Update() grid = density.GetGridOutput() bound = grid.GetBounds() plane = vtk.vtkPlaneSource() plane.SetResolution(100, 100) t = vtk.vtkTransform() t.Scale(bound[1] - bound[0], bound[3] - bound[2], bound[5] - bound[4]) t.Translate(0.5, 0.5, 0.5) trans = vtk.vtkTransformPolyDataFilter() trans.SetTransform(t) trans.SetInputConnection(plane.GetOutputPort()) probe = vtk.vtkProbeFilter() probe.SetInputConnection(trans.GetOutputPort()) probe.SetSourceData(grid) # Update probe filter to get valid scalar range probe.Update() srange = probe.GetOutput().GetScalarRange() # print srange
#!/usr/bin/python import vtk potential_cation = vtk.vtkGaussianCubeReader() potential_cation.SetFileName("crownK.pot.cube") potential_cation.SetBScale(20) potential_cation.SetHBScale(20) potential_cation.Update() sphere = vtk.vtkSphereSource() sphere.SetRadius(1.0) sphere.SetThetaResolution(16) sphere.SetPhiResolution(16) glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(potential_cation.GetOutputPort()) glyph.SetSourceConnection(sphere.GetOutputPort()) glyph.OrientOn() glyph.SetColorMode(1) glyph.SetScaleMode(2) glyph.ScalingOn() atomMapper = vtk.vtkPolyDataMapper() atomMapper.SetInputConnection(glyph.GetOutputPort()) atomActor = vtk.vtkActor() atomActor.SetMapper(atomMapper) tube = vtk.vtkTubeFilter() tube.SetInputConnection(potential_cation.GetOutputPort())
#coding:utf-8 import vtk import os curdir, fname = os.path.split(__file__) model_path = os.path.join(curdir, 'models/crown.den.cube') density_neutral = vtk.vtkGaussianCubeReader() density_neutral.SetFileName(os.path.join(curdir, "models/crown.den.cube")) density_neutral.Update() potential_cation = vtk.vtkGaussianCubeReader() potential_cation.SetFileName(os.path.join(curdir, "models/crownK.pot.cube")) potential_cation.Update() potential_neutral = vtk.vtkGaussianCubeReader() potential_neutral.SetFileName(os.path.join(curdir, "models/crown.pot.cube")) potential_neutral.Update() contour = vtk.vtkContourFilter() contour.SetInputData(density_neutral.GetGridOutput()) contour.SetValue(0, 0.05) potential_difference = vtk.vtkImageMathematics() potential_difference.SetOperationToSubtract() potential_difference.SetInput1Data(potential_cation.GetGridOutput()) potential_difference.SetInput2Data(potential_neutral.GetGridOutput()) probe = vtk.vtkProbeFilter() probe.SetInputConnection(contour.GetOutputPort()) probe.SetSourceConnection(potential_difference.GetOutputPort()) # Update probe filter to get valid scalar range
def RenderCubeInVTK(filename = 'test.cube', mindatum = 0.0, maxdatum = 0.0): global renWin ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ####################### # Read in Gaussian cube ####################### CubeData = vtk.vtkGaussianCubeReader() CubeData.SetFileName(filename) CubeData.Update() #Get intrinsic scale from data scale = sum([x**2 for x in CubeData.GetTransform().GetScale()]) CubeData.SetHBScale(scale) #scaling factor to compute bonds with hydrogens CubeData.SetBScale(scale) #scaling factor for other bonds CubeData.Update() ################### #Calculate scalings #VTK only knows how to render integer data in the interval [0,255] or [0,65535] #Here, we calculate scaling factors to map the cube data to the interval. if mindatum == maxdatum == 0.0: if DEBUG: print "Autodetecting range" mindatum, maxdatum = CubeData.GetGridOutput().GetPointData().GetScalars().GetRange() # Find the remapped value that corresponds to zero zeropoint = int(2**ColorDepth*(-mindatum)/(maxdatum-mindatum)) absmaxdatum = max(-mindatum, maxdatum) maxnegativeintensity = min(1.0, 1.0 - (absmaxdatum - abs(mindatum))/absmaxdatum) minnegativeintensity = 0.0 if zeropoint < 0: minpositiveintensity = - zeropoint/(2**ColorDepth*absmaxdatum) else: minpositiveintensity = 0.0 maxpositiveintensity = min(1.0, 1.0 - (absmaxdatum - abs(maxdatum))/absmaxdatum) if DEBUG: print "Range plotted = [%f,%f]" % (mindatum, maxdatum) print "Negative colors = [0,%d)" % max(0,zeropoint) print "Negative intensities = [%f,%f]" % (maxnegativeintensity,minnegativeintensity) print "Positive colors = (%d,%d)" % (max(0,zeropoint), 2**ColorDepth) print "Positive intensities = [%f,%f]" % (minpositiveintensity,maxpositiveintensity) print "On this scale, zero = %d" % zeropoint ################################ # Calculate opacity transfer map #The code here differentiates between two cases: #1. the scalar data are all positive, so it's just a simple linear ramp #2. the scalar data are signed, so do two linear ramps opacityTransferFunction = vtk.vtkPiecewiseFunction() if zeropoint < 0: opacityTransferFunction.AddPoint( 0, minpositiveintensity) else: opacityTransferFunction.AddPoint( 0, maxnegativeintensity) opacityTransferFunction.AddPoint(zeropoint, 0.0) opacityTransferFunction.AddPoint(2**ColorDepth-1, maxpositiveintensity) opacityTransferFunction.ClampingOn() ########################### # Create color transfer map colorTransferFunction = vtk.vtkColorTransferFunction() r1, g1, b1 = NegativeColor r2, g2, b2 = PositiveColor r0, g0, b0 = BackgroundColor if zeropoint < 0: colorTransferFunction.AddRGBPoint( 0, r1, g1, b1) else: colorTransferFunction.AddRGBPoint( 0, r1, g1, b1) colorTransferFunction.AddRGBPoint(zeropoint-1, r1, g1, b1) colorTransferFunction.AddRGBPoint(zeropoint , r0, g0, b0) colorTransferFunction.AddRGBPoint(zeropoint+1, r2, g2, b2) colorTransferFunction.AddRGBPoint(2**ColorDepth-1, r2, g2, b2) ######################## # Now apply the scalings ScaledData = vtk.vtkImageShiftScale() ScaledData.SetInput(CubeData.GetGridOutput()) ScaledData.SetShift(-mindatum) ScaledData.SetScale((2**ColorDepth-1)/(maxdatum-mindatum)) if ColorDepth == 16: ScaledData.SetOutputScalarTypeToUnsignedShort() elif ColorDepth == 8: ScaledData.SetOutputScalarTypeToUnsignedChar() else: print print "Error! Unsupported color depth given" print print "valid values are 8 or 16" print raise ValueError ############################### # Form combined coloring scheme volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() # The mapper / ray cast function know how to render the data compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() volumeMapper = vtk.vtkVolumeRayCastMapper() volumeMapper.SetVolumeRayCastFunction(compositeFunction) volumeMapper.SetInput(ScaledData.GetOutput()) #Create a coarse representation #Actually a fake - won't display anything compositeFunction2 = vtk.vtkVolumeRayCastIsosurfaceFunction() compositeFunction2.SetIsoValue(2**ColorDepth-1) volumeMapperCoarse = vtk.vtkVolumeRayCastMapper() volumeMapperCoarse.SetVolumeRayCastFunction(compositeFunction2) volumeMapperCoarse.SetInput(ScaledData.GetOutput()) # Create volumetric object to be rendered # Use level of detail prop so that it won't take forever to look around volume = vtk.vtkLODProp3D() id1 = volume.AddLOD(volumeMapper, volumeProperty, 0.) volume.SetLODProperty(id1, volumeProperty) id2 = volume.AddLOD(volumeMapperCoarse, volumeProperty, 0.) volume.SetLODProperty(id2, volumeProperty) # At this point, we can position and orient the volume ################################# # End of volumetric data pipeline ################################# ######### #Contours ######### contour = vtk.vtkContourFilter() contour.SetInput(CubeData.GetGridOutput()) contour.SetNumberOfContours(1) contour.SetValue(0, 0.0) contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInput(contour.GetOutput()) contourMapper.SetScalarRange(0,0) contourMapper.GetLookupTable().SetNumberOfTableValues(1) r0, g0, b0 = NodeColor contourMapper.GetLookupTable().SetTableValue(0, r0, g0, b0, NodeAlpha) contourActor = vtk.vtkLODActor() contourActor.SetMapper(contourMapper) contourActor.GetProperty().SetOpacity(NodeAlpha) ########################################## # Create a wireframe outline of the volume ########################################## frame = vtk.vtkOutlineFilter() frame.SetInput(CubeData.GetGridOutput()) frameMapper = vtk.vtkPolyDataMapper() frameMapper.SetInput(frame.GetOutput()) frameActor = vtk.vtkLODActor() frameActor.SetMapper(frameMapper) frameActor.GetProperty().SetColor(FrameColor) frameActor.GetProperty().SetOpacity(FrameAlpha) ###################### # Draw balls for atoms ###################### Sphere = vtk.vtkSphereSource() Sphere.SetThetaResolution(16) Sphere.SetPhiResolution(16) Sphere.SetRadius(0.4) Glyph = vtk.vtkGlyph3D() Glyph.SetInput(CubeData.GetOutput()) Glyph.SetColorMode(1) Glyph.SetColorModeToColorByScalar() Glyph.SetScaleModeToScaleByVectorComponents() Glyph.SetSource(Sphere.GetOutput()) AtomsMapper = vtk.vtkPolyDataMapper() AtomsMapper.SetInput(Glyph.GetOutput()) AtomsMapper.SetImmediateModeRendering(1) AtomsMapper.UseLookupTableScalarRangeOff() AtomsMapper.SetScalarVisibility(1) AtomsMapper.SetScalarModeToDefault() Atoms = vtk.vtkLODActor() Atoms.SetMapper(AtomsMapper) ############ # Draw bonds ############ Tube = vtk.vtkTubeFilter() Tube.SetInput(CubeData.GetOutput()) BondsMapper = vtk.vtkPolyDataMapper() BondsMapper.SetInput(Tube.GetOutput()) Bonds = vtk.vtkLODActor() Bonds.SetMapper(BondsMapper) ####################### # Now compose the image ####################### if DrawVolume: ren.AddVolume(volume) if DrawNodes: ren.AddActor(contourActor) if DrawFrame: ren.AddActor(frameActor) if DrawAtoms: ren.AddActor(Atoms) if DrawBonds: ren.AddActor(Bonds) ren.SetBackground(BackgroundColor) renWin.SetSize(OutputHeight, OutputWidth) ###################################### # Let VTK do its magic and render away ###################################### renWin.Render() ################################### # Now allow user to play with image ################################### def Keypress(obj, event): #This function handles keyboard interaction key = obj.GetKeySym() if key == 'd' or key == 'F13': WriteToPNG() elif key == 'h' or key == 'question' or key =='?': PrintHelp() elif key == 'c': camera = ren.GetActiveCamera() print "Camera info:" print "------------" print "Position is: ", camera.GetPosition() print "Focal point is:", camera.GetFocalPoint() print "Orientation is:", ren.GetActiveCamera().GetOrientation() print "WXYZ", ren.GetActiveCamera().GetOrientationWXYZ() print "View up direction is:", camera.GetViewUp() print "Direction of projection is:", camera.GetDirectionOfProjection() else: if DEBUG: print 'User pressed key:', key if Interactive: iren.SetDesiredUpdateRate(25.0) #25 fps when camera is moving around iren.SetStillUpdateRate(0.0) #0 fps when camera is not moving iren.Initialize() #The default interaction style is joystick, which seems unnatural style = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(style) iren.AddObserver("KeyPressEvent", Keypress) iren.Start() else: WriteToPNG()
def ScanCubeForRange(filename = 'test.cube'): CubeData = vtk.vtkGaussianCubeReader() CubeData.SetFileName(filename) CubeData.Update() return CubeData.GetGridOutput().GetPointData().GetScalars().GetRange()
def RenderCubeInVTK(filename='test.cube', mindatum=0.0, maxdatum=0.0): global renWin ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ####################### # Read in Gaussian cube ####################### CubeData = vtk.vtkGaussianCubeReader() CubeData.SetFileName(filename) CubeData.Update() #Get intrinsic scale from data scale = sum([x**2 for x in CubeData.GetTransform().GetScale()]) CubeData.SetHBScale(scale) #scaling factor to compute bonds with hydrogens CubeData.SetBScale(scale) #scaling factor for other bonds CubeData.Update() ################### #Calculate scalings #VTK only knows how to render integer data in the interval [0,255] or [0,65535] #Here, we calculate scaling factors to map the cube data to the interval. if mindatum == maxdatum == 0.0: if DEBUG: print "Autodetecting range" mindatum, maxdatum = CubeData.GetGridOutput().GetPointData( ).GetScalars().GetRange() # Find the remapped value that corresponds to zero zeropoint = int(2**ColorDepth * (-mindatum) / (maxdatum - mindatum)) absmaxdatum = max(-mindatum, maxdatum) maxnegativeintensity = min( 1.0, 1.0 - (absmaxdatum - abs(mindatum)) / absmaxdatum) minnegativeintensity = 0.0 if zeropoint < 0: minpositiveintensity = -zeropoint / (2**ColorDepth * absmaxdatum) else: minpositiveintensity = 0.0 maxpositiveintensity = min( 1.0, 1.0 - (absmaxdatum - abs(maxdatum)) / absmaxdatum) if DEBUG: print "Range plotted = [%f,%f]" % (mindatum, maxdatum) print "Negative colors = [0,%d)" % max(0, zeropoint) print "Negative intensities = [%f,%f]" % (maxnegativeintensity, minnegativeintensity) print "Positive colors = (%d,%d)" % (max(0, zeropoint), 2**ColorDepth) print "Positive intensities = [%f,%f]" % (minpositiveintensity, maxpositiveintensity) print "On this scale, zero = %d" % zeropoint ################################ # Calculate opacity transfer map #The code here differentiates between two cases: #1. the scalar data are all positive, so it's just a simple linear ramp #2. the scalar data are signed, so do two linear ramps opacityTransferFunction = vtk.vtkPiecewiseFunction() if zeropoint < 0: opacityTransferFunction.AddPoint(0, minpositiveintensity) else: opacityTransferFunction.AddPoint(0, maxnegativeintensity) opacityTransferFunction.AddPoint(zeropoint, 0.0) opacityTransferFunction.AddPoint(2**ColorDepth - 1, maxpositiveintensity) opacityTransferFunction.ClampingOn() ########################### # Create color transfer map colorTransferFunction = vtk.vtkColorTransferFunction() r1, g1, b1 = NegativeColor r2, g2, b2 = PositiveColor r0, g0, b0 = BackgroundColor if zeropoint < 0: colorTransferFunction.AddRGBPoint(0, r1, g1, b1) else: colorTransferFunction.AddRGBPoint(0, r1, g1, b1) colorTransferFunction.AddRGBPoint(zeropoint - 1, r1, g1, b1) colorTransferFunction.AddRGBPoint(zeropoint, r0, g0, b0) colorTransferFunction.AddRGBPoint(zeropoint + 1, r2, g2, b2) colorTransferFunction.AddRGBPoint(2**ColorDepth - 1, r2, g2, b2) ######################## # Now apply the scalings ScaledData = vtk.vtkImageShiftScale() ScaledData.SetInput(CubeData.GetGridOutput()) ScaledData.SetShift(-mindatum) ScaledData.SetScale((2**ColorDepth - 1) / (maxdatum - mindatum)) if ColorDepth == 16: ScaledData.SetOutputScalarTypeToUnsignedShort() elif ColorDepth == 8: ScaledData.SetOutputScalarTypeToUnsignedChar() else: print print "Error! Unsupported color depth given" print print "valid values are 8 or 16" print raise ValueError ############################### # Form combined coloring scheme volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() # The mapper / ray cast function know how to render the data compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() volumeMapper = vtk.vtkVolumeRayCastMapper() volumeMapper.SetVolumeRayCastFunction(compositeFunction) volumeMapper.SetInput(ScaledData.GetOutput()) #Create a coarse representation #Actually a fake - won't display anything compositeFunction2 = vtk.vtkVolumeRayCastIsosurfaceFunction() compositeFunction2.SetIsoValue(2**ColorDepth - 1) volumeMapperCoarse = vtk.vtkVolumeRayCastMapper() volumeMapperCoarse.SetVolumeRayCastFunction(compositeFunction2) volumeMapperCoarse.SetInput(ScaledData.GetOutput()) # Create volumetric object to be rendered # Use level of detail prop so that it won't take forever to look around volume = vtk.vtkLODProp3D() id1 = volume.AddLOD(volumeMapper, volumeProperty, 0.) volume.SetLODProperty(id1, volumeProperty) id2 = volume.AddLOD(volumeMapperCoarse, volumeProperty, 0.) volume.SetLODProperty(id2, volumeProperty) # At this point, we can position and orient the volume ################################# # End of volumetric data pipeline ################################# ######### #Contours ######### contour = vtk.vtkContourFilter() contour.SetInput(CubeData.GetGridOutput()) contour.SetNumberOfContours(1) contour.SetValue(0, 0.0) contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInput(contour.GetOutput()) contourMapper.SetScalarRange(0, 0) contourMapper.GetLookupTable().SetNumberOfTableValues(1) r0, g0, b0 = NodeColor contourMapper.GetLookupTable().SetTableValue(0, r0, g0, b0, NodeAlpha) contourActor = vtk.vtkLODActor() contourActor.SetMapper(contourMapper) contourActor.GetProperty().SetOpacity(NodeAlpha) ########################################## # Create a wireframe outline of the volume ########################################## frame = vtk.vtkOutlineFilter() frame.SetInput(CubeData.GetGridOutput()) frameMapper = vtk.vtkPolyDataMapper() frameMapper.SetInput(frame.GetOutput()) frameActor = vtk.vtkLODActor() frameActor.SetMapper(frameMapper) frameActor.GetProperty().SetColor(FrameColor) frameActor.GetProperty().SetOpacity(FrameAlpha) ###################### # Draw balls for atoms ###################### Sphere = vtk.vtkSphereSource() Sphere.SetThetaResolution(16) Sphere.SetPhiResolution(16) Sphere.SetRadius(0.4) Glyph = vtk.vtkGlyph3D() Glyph.SetInput(CubeData.GetOutput()) Glyph.SetColorMode(1) Glyph.SetColorModeToColorByScalar() Glyph.SetScaleModeToScaleByVectorComponents() Glyph.SetSource(Sphere.GetOutput()) AtomsMapper = vtk.vtkPolyDataMapper() AtomsMapper.SetInput(Glyph.GetOutput()) AtomsMapper.SetImmediateModeRendering(1) AtomsMapper.UseLookupTableScalarRangeOff() AtomsMapper.SetScalarVisibility(1) AtomsMapper.SetScalarModeToDefault() Atoms = vtk.vtkLODActor() Atoms.SetMapper(AtomsMapper) ############ # Draw bonds ############ Tube = vtk.vtkTubeFilter() Tube.SetInput(CubeData.GetOutput()) BondsMapper = vtk.vtkPolyDataMapper() BondsMapper.SetInput(Tube.GetOutput()) Bonds = vtk.vtkLODActor() Bonds.SetMapper(BondsMapper) ####################### # Now compose the image ####################### if DrawVolume: ren.AddVolume(volume) if DrawNodes: ren.AddActor(contourActor) if DrawFrame: ren.AddActor(frameActor) if DrawAtoms: ren.AddActor(Atoms) if DrawBonds: ren.AddActor(Bonds) ren.SetBackground(BackgroundColor) renWin.SetSize(OutputHeight, OutputWidth) ###################################### # Let VTK do its magic and render away ###################################### renWin.Render() ################################### # Now allow user to play with image ################################### def Keypress(obj, event): #This function handles keyboard interaction key = obj.GetKeySym() if key == 'd' or key == 'F13': WriteToPNG() elif key == 'h' or key == 'question' or key == '?': PrintHelp() elif key == 'c': camera = ren.GetActiveCamera() print "Camera info:" print "------------" print "Position is: ", camera.GetPosition() print "Focal point is:", camera.GetFocalPoint() print "Orientation is:", ren.GetActiveCamera().GetOrientation() print "WXYZ", ren.GetActiveCamera().GetOrientationWXYZ() print "View up direction is:", camera.GetViewUp() print "Direction of projection is:", camera.GetDirectionOfProjection( ) else: if DEBUG: print 'User pressed key:', key if Interactive: iren.SetDesiredUpdateRate(25.0) #25 fps when camera is moving around iren.SetStillUpdateRate(0.0) #0 fps when camera is not moving iren.Initialize() #The default interaction style is joystick, which seems unnatural style = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(style) iren.AddObserver("KeyPressEvent", Keypress) iren.Start() else: WriteToPNG()
def ScanCubeForRange(filename='test.cube'): CubeData = vtk.vtkGaussianCubeReader() CubeData.SetFileName(filename) CubeData.Update() return CubeData.GetGridOutput().GetPointData().GetScalars().GetRange()
#!/usr/bin/python """This script takes two cube files: electron density and electrostatic potential. It computes electron density isosurface and plots electric potential (by numerical differentiation of the electrostatic potential) on the isosurface. Electric field's magnitude is represented by the length of the lines, while the direction is shown with colour. The direction is determined by taking the dot product of electric field vector and electron density gradient; this way, one can see where the field is directed towards or away from the molecular surface.""" import vtk density = vtk.vtkGaussianCubeReader() density.SetFileName("crown.den.cube") density.Update() potential = vtk.vtkGaussianCubeReader() potential.SetFileName("crownK.pot.cube") potential.SetBScale(20) potential.SetHBScale(15) potential.Update() sphere = vtk.vtkSphereSource() sphere.SetCenter(0, 0, 0) sphere.SetRadius(1.0) sphere.SetThetaResolution(16) sphere.SetPhiResolution(16) glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(potential.GetOutputPort()) glyph.SetSourceConnection(sphere.GetOutputPort())