本文整理汇总了Python中vtk.vtkSphereSource函数的典型用法代码示例。如果您正苦于以下问题:Python vtkSphereSource函数的具体用法?Python vtkSphereSource怎么用?Python vtkSphereSource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkSphereSource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, amt, radius):
Model.__init__(self)
self.source = vtk.vtkAppendPolyData()
for i in range(amt):
opX = 1.0
opY = 1.0
opZ = 1.0
if random() > 0.5:
opX *= -1.0
if random() > 0.5:
opY *= -1.0
if random() > 0.5:
opZ *= -1.0
sRad = 0.25 + ( random() * 0.25 )
x = float(random() * radius) * opX
y = float(random() * radius) * opY
z = float(random() * radius) * opZ
s = vtk.vtkSphereSource()
s.SetCenter(x,y,z)
s.SetRadius(float(sRad))
s.Update()
self.source.AddInput(s.GetOutput())
#add center
s = vtk.vtkSphereSource()
s.SetCenter(0.0, 0.0, 0.0)
s.SetRadius(0.5)
s.Update()
self.source.AddInput(s.GetOutput())
self.Update()
示例2: __init__
def __init__(self):
# Central dot
self.dot = vtk.vtkSphereSource()
self.dot.SetThetaResolution(20)
self.dot.SetRadius(.5)
self.dotMapper = vtk.vtkPolyDataMapper()
self.dotMapper.SetInputConnection(self.dot.GetOutputPort())
self.dotActor = vtk.vtkActor()
self.dotActor.SetMapper(self.dotMapper)
# Circular halo around dot
self.halo = vtk.vtkSphereSource()
self.halo.SetThetaResolution(20)
self.halo.SetRadius(2)
self.haloMapper = vtk.vtkPolyDataMapper()
self.haloMapper.SetInputConnection(self.halo.GetOutputPort())
self.haloActor = vtk.vtkActor()
self.haloActor.SetMapper(self.haloMapper)
self.dotActor.GetProperty().SetColor(red)
self.haloActor.GetProperty().SetColor(white)
self.haloActor.GetProperty().SetOpacity(0.1)
self.haloActor.GetProperty().SetSpecular(0.6)
self.actor = vtk.vtkAssembly()
self.actor.AddPart(self.dotActor)
self.actor.AddPart(self.haloActor)
示例3: get_electrode_glyphs
def get_electrode_glyphs(e_pts, e_colors):
e_glyph_shape = vtk.vtkSphereSource()
# cone.SetResolution(5)
# cone.SetHeight(2)
e_glyph_shape.SetRadius(3.0)
glyphs = vtk.vtkGlyph3D()
glyphs.SetSourceConnection(e_glyph_shape.GetOutputPort())
glyphs.SetColorModeToColorByScalar()
centroidsPD = vtk.vtkPolyData()
centroidsPD.SetPoints(e_pts)
centroidsPD.GetPointData().SetScalars(e_colors)
if vtk_major_version == 5:
glyphs.SetInput(centroidsPD)
else:
glyphs.SetInputData(centroidsPD)
glyphs.ScalingOff() # IMPORTANT
glyphs.Update()
glyphs.ScalingOff() # IMPORTANT
glyphs.Update()
return glyphs
示例4: make_sphereActor
def make_sphereActor (x, r, rgb, opacity):
points = vtk.vtkPoints()
points.InsertNextPoint(x[0], x[1], x[2])
diameter = vtk.vtkDoubleArray()
diameter.SetNumberOfComponents(1)
diameter.InsertNextTuple1(2.0*r)
pData = vtk.vtkPolyData()
pData.SetPoints(points)
pData.GetPointData().SetScalars(diameter)
pSource = vtk.vtkSphereSource()
pSource.SetPhiResolution(16)
pSource.SetThetaResolution(16)
pGlyph = vtk.vtkGlyph3D()
pGlyph.SetSource(pSource.GetOutput())
pGlyph.SetInput(pData)
pGlyph.ScalingOn()
pGlyph.SetScaleModeToScaleByScalar()
pMapper = vtk.vtkPolyDataMapper()
pMapper.ScalarVisibilityOff()
pMapper.SetInput(pGlyph.GetOutput())
pActor = vtk.vtkActor()
pActor.SetMapper(pMapper)
pActor.GetProperty().SetColor(rgb[0], rgb[1], rgb[2])
pActor.GetProperty().SetOpacity(opacity)
return pActor
示例5: __init__
def __init__(self, reader):
self.reader = reader
sg = self.src_glyph = vtk.vtkSphereSource()
sg.SetRadius(0.5)
sg.SetCenter(0.5, 0.0, 0.0)
g = self.glyph = vtk.vtkTensorGlyph()
g.SetInputConnection(self.reader.GetOutputPort())
g.SetSource(self.src_glyph.GetOutput())
g.SetScaleFactor(0.25)
# The normals are needed to generate the right colors and if
# not used some of the glyphs are black.
self.normals = vtk.vtkPolyDataNormals()
self.normals.SetInputConnection(g.GetOutputPort())
self.map = vtk.vtkPolyDataMapper()
self.map.SetInputConnection(self.normals.GetOutputPort())
self.act = vtk.vtkActor()
self.act.SetMapper(self.map)
# An outline.
self.of = vtk.vtkOutlineFilter()
self.of.SetInputConnection(self.reader.GetOutputPort())
self.out_map = vtk.vtkPolyDataMapper()
self.out_map.SetInputConnection(self.of.GetOutputPort())
self.out_act = vtk.vtkActor()
self.out_act.SetMapper(self.out_map)
示例6: __init__
def __init__(self, pos, radius=None, frame=None, scene=None, color='gray'):
if radius is None:
radius = ArticulationSphere.last_radius_update
self.init_radius = radius
self.src = vtk.vtkSphereSource()
self.src.SetThetaResolution(16)
self.src.SetPhiResolution(16)
self.src.SetCenter(pos)
self.src.SetRadius(radius)
self.mapper = vtk.vtkPolyDataMapper()
if USING_VTK6:
self.mapper.SetInputConnection(self.src.GetOutputPort())
else:
self.mapper.SetInput(self.src.GetOutput())
self.actor = vtk.vtkActor()
self.actor.SetMapper(self.mapper)
self.color = color # base color name
self.set_color()
self.actor.GetProperty().SetOpacity(0.25)
self.frame = frame
self.frame.ren.AddActor(self.actor)
self.scene = scene
self.selected_pts = []
self.is_selected = False
if self.scene.point_cloud_selection_enabled:
self.select_point_cloud()
self.callbacks = defaultdict(lambda: [lambda a: None])
# action_name -> list of callbacks to be called
# after action is performed (i.e. 'moved', 'delete', etc)
self.polytube_node = None # None -> sphere is "roaming"
# (i.e. not attached to any model)
self.frame.ren_win.Render()
示例7: __init__
def __init__(self, renderer):
Visualizer.__init__(self)
assert isinstance(renderer, vtk.vtkRenderer)
self.ren = renderer
# -------- add the beam ----
# geometry
self.beam = vtk.vtkCubeSource()
self.beam.SetXLength(st.visBeamLength)
self.beam.SetYLength(st.visBeamWidth)
self.beam.SetZLength(st.visBeamDepth)
# mapper
self.beamMapper = vtk.vtkPolyDataMapper()
self.beamMapper.SetInputConnection(self.beam.GetOutputPort())
# actor
self.beamActor = vtk.vtkLODActor()
self.beamActor.SetMapper(self.beamMapper)
# make it look nice
self.beamProp = self.beamActor.GetProperty()
self.beamProp.SetColor(101 / 255, 123 / 255, 131 / 255)
self.ren.AddActor(self.beamActor)
# -------- add the ball ----
# geometry
self.ball = vtk.vtkSphereSource()
self.ball.SetRadius(st.visR)
self.ball.SetThetaResolution(20)
self.ball.SetPhiResolution(20)
# mapper
self.ballMapper = vtk.vtkPolyDataMapper()
self.ballMapper.SetInputConnection(self.ball.GetOutputPort())
# actor
self.ballActor = vtk.vtkLODActor()
self.ballActor.SetMapper(self.ballMapper)
# make it look nice
self.ballProp = self.ballActor.GetProperty()
self.ballProp.SetColor(255 / 255, 255 / 255, 0)
self.ballProp.SetAmbient(0.2)
self.ballProp.SetDiffuse(0.8)
self.ballProp.SetSpecular(0.5)
self.ballProp.SetSpecularPower(0.5)
self.ren.AddActor(self.ballActor)
# add background
self.ren.GradientBackgroundOn()
self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)
# get everybody into the frame
self.ren.ResetCamera()
self.ren.GetActiveCamera().Zoom(1.7)
示例8: onApplyButtonClicked
def onApplyButtonClicked(self):
"""
Real algorithm should be in class VascularWallLogic.
"""
logging.info("applyButton is clicked.")
# Create models for sphere
self.sphere = vtk.vtkSphereSource()
# Model node
model = slicer.vtkMRMLModelNode()
model.SetAndObservePolyData(self.sphere.GetOutput())
# Display node
self.modelDisplay = slicer.vtkMRMLModelDisplayNode()
self.modelDisplay.SetSliceIntersectionVisibility(True)
self.modelDisplay.SetVisibility(self.showCheckBox.isChecked())
self.modelDisplay.SetOpacity(0.5)
self.modelDisplay.SetRepresentation(1)
slicer.mrmlScene.AddNode(self.modelDisplay)
model.SetAndObserveDisplayNodeID(self.modelDisplay.GetID())
# Add to scene
self.modelDisplay.SetInputPolyDataConnection(
model.GetPolyDataConnection())
slicer.mrmlScene.AddNode(model)
# Callback
self.UpdateSphere(0, 0)
self.rulerSelector.currentNode().AddObserver(
'ModifiedEvent', self.UpdateSphere)
示例9: CreateSphere
def CreateSphere(radius, color=None):
sphereSource = vtkSphereSource()
sphereSource.SetRadius(radius)
sphereSource.SetThetaResolution(18)
sphereSource.SetPhiResolution(18)
sphereMapper = vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
sphereActor = vtkActor()
sphereActor.PickableOff()
sphereActor.SetMapper(sphereMapper)
# Give the actor a custom color
ColorActor(sphereActor, color)
# Also give the sphere object the convenience methods of
# SetCenter() and GetCenter() that misses from the vtkActor
# class but is present in the vtkSphereSource class
def setCenter(x, y, z):
sphereSource.SetCenter(x, y, z)
def getCenter():
return sphereSource.GetCenter()
setattr(sphereActor, "SetCenter", setCenter)
setattr(sphereActor, "GetCenter", getCenter)
return sphereActor
示例10: __init__
def __init__(self, module_manager):
# initialise our base class
ModuleBase.__init__(self, module_manager)
# what a lame-assed filter, we have to make dummy inputs!
# if we don't have a dummy input (but instead a None input) it
# bitterly complains when we do a GetOutput() (it needs the input
# to know the type of the output) - and GetPolyDataOutput() also
# doesn't work.
# NB: this does mean that our probeFilter NEEDS a PolyData as
# probe geometry!
ss = vtk.vtkSphereSource()
ss.SetRadius(0)
self._dummyInput = ss.GetOutput()
#This is also retarded - we (sometimes, see below) need the "padder"
#to get the image extent big enough to satisfy the probe filter.
#No apparent logical reason, but it throws an exception if we don't.
self._padder = vtk.vtkImageConstantPad()
self._source = None
self._input = None
self._probeFilter = vtk.vtkProbeFilter()
self._probeFilter.SetInput(self._dummyInput)
NoConfigModuleMixin.__init__(
self,
{'Module (self)' : self,
'vtkProbeFilter' : self._probeFilter})
module_utils.setup_vtk_object_progress(self, self._probeFilter,
'Mapping source on input')
self.sync_module_logic_with_config()
示例11: __init__
def __init__(self,ext_actors=None): #ext_actors is a list of any external vtkActors.
#initializations:
self.renderer = vtk.vtkRenderer()
self.window = vtk.vtkRenderWindow()
self.window.SetSize(1000,1000)
self.mapper = vtk.vtkPolyDataMapper()
self.points = vtk.vtkPoints()
self.poly_data = vtk.vtkPolyData()
self.glyph3d = vtk.vtkGlyph3D()
self.actor = vtk.vtkActor()
self.point_s = vtk.vtkPointSource()
self.sphere = vtk.vtkSphereSource()
self.interactor= vtk.vtkRenderWindowInteractor()
self.inter_sty = PdbInteractorStyle()
self.axes_actor= vtk.vtkAxesActor()
#configurations:
self.point_s.SetNumberOfPoints(1)
self.sphere.SetRadius(1.0)
self.interactor.SetInteractorStyle(self.inter_sty)
self.interactor.SetRenderWindow(self.window)
self.axes_actor.SetTotalLength(100,100,100)
if ext_actors:
self.ex_actors = ext_actors
else:
self.ex_actors=[]
示例12: __init__
def __init__(self, profile=0, radius=2):
if not radius:
self.radius = Globals.renderProps["sphereSize"] * 1.1
else: self.radius = radius
self.z = 0
self.data = vtk.vtkPolyData()
self.sphere = vtk.vtkSphereSource()
self.sphere.SetRadius( Globals.referenceSize * self.radius )
self.sphere.SetPhiResolution( Globals.renderProps["spherePhiResolution"] )
self.sphere.SetThetaResolution( Globals.renderProps["sphereThetaResolution"] )
self.glyphPoints = vtk.vtkGlyph3D()
self.glyphPoints.SetInput( self.data )
self.glyphPoints.SetSource( self.sphere.GetOutput() )
self.mapper = vtk.vtkPolyDataMapper()
self.mapper.SetInputConnection( self.glyphPoints.GetOutputPort() )
self.actor = vtk.vtkActor()
self.actor.SetMapper(self.mapper)
if profile:
self.actor.GetProperty().SetColor(0,0,1)
else:
self.actor.GetProperty().SetColor(1,1,0)
Globals.ren.AddActor(self.actor)
示例13: __addVolumeSelectedActor
def __addVolumeSelectedActor(self, worldpos):
# Create a sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(worldpos)
sphereSource.SetRadius(0.5 + self.pick_radius / 2.0)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection( sphereSource.GetOutputPort() )
ren = self.GetRenderWindow().GetRenderers().GetFirstRenderer()
if self.actor is not None:
#remove old volume selected
ren.RemoveActor(self.actor)
self.actor = vtk.vtkActor()
self.actor.SetMapper(mapper)
#prop = vtk.vtkProperty()
#prop.ShadingOn()
#prop.SetInterpolationToGouraud()
#prop.EdgeVisibilityOff()
#prop.SetDiffuse(0.7)
#prop.SetSpecular(0.4)
#prop.SetSpecularPower(20)
#prop.SetColor(1.0, 1.0, 0)
#prop.SetOpacity(0.5)
#self.actor.SetProperty(prop)
ren.AddActor(self.actor)
示例14: TestSection_01_GenerateInputData
def TestSection_01_GenerateInputData(self):
self.inputSegmentationNode = slicer.vtkMRMLSegmentationNode()
slicer.mrmlScene.AddNode(self.inputSegmentationNode)
# Create new segments
import random
for segmentName in ['first', 'second', 'third']:
sphereSegment = vtkSegmentationCore.vtkSegment()
sphereSegment.SetName(segmentName)
sphereSegment.SetColor(random.uniform(0.0,1.0), random.uniform(0.0,1.0), random.uniform(0.0,1.0))
sphere = vtk.vtkSphereSource()
sphere.SetCenter(random.uniform(0,100),random.uniform(0,100),random.uniform(0,100))
sphere.SetRadius(random.uniform(20,30))
sphere.Update()
spherePolyData = sphere.GetOutput()
sphereSegment.AddRepresentation(
vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName(),
spherePolyData)
self.inputSegmentationNode.GetSegmentation().AddSegment(sphereSegment)
self.assertEqual(self.inputSegmentationNode.GetSegmentation().GetNumberOfSegments(), 3)
示例15: make_sphere
def make_sphere():
global renderer
# ---------------------------------------------------------------
# The following code is identical to render_demo.py...
# ---------------------------------------------------------------
# create a sphere
sphere_src = vtk.vtkSphereSource()
sphere_src.SetRadius(1.0)
sphere_src.SetCenter(0.0, 0.0, 0.0)
sphere_src.SetThetaResolution(20)
sphere_src.SetPhiResolution(20)
# extract the edges
edge_extractor = vtk.vtkExtractEdges()
edge_extractor.SetInputConnection(sphere_src.GetOutputPort())
# map sphere and edges separately
sphere_mapper = vtk.vtkPolyDataMapper()
sphere_mapper.SetInputConnection(sphere_src.GetOutputPort())
edge_mapper = vtk.vtkPolyDataMapper()
edge_mapper.SetInputConnection(edge_extractor.GetOutputPort())
# define different rendering styles for sphere and edges
sphere_actor = vtk.vtkActor()
sphere_actor.SetMapper(sphere_mapper)
sphere_actor.GetProperty().SetColor(1, 0.5, 0)
edge_actor = vtk.vtkActor()
edge_actor.SetMapper(edge_mapper)
edge_actor.GetProperty().SetColor(0, 0.5, 0)
edge_actor.GetProperty().SetLineWidth(3)
# add resulting primitives to renderer
renderer.AddActor(sphere_actor)
renderer.AddActor(edge_actor)