本文整理汇总了Python中vtk.vtkTextActor函数的典型用法代码示例。如果您正苦于以下问题:Python vtkTextActor函数的具体用法?Python vtkTextActor怎么用?Python vtkTextActor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkTextActor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Initialize
def Initialize(self):
if not self.Renderer:
self.Renderer = vtk.vtkRenderer()
self.Renderer.SetBackground(self.Background)
self.RenderWindow = vtk.vtkRenderWindow()
self.RenderWindow.AddRenderer(self.Renderer)
self.RenderWindow.SetSize(self.WindowSize[0],self.WindowSize[1])
self.RenderWindow.SetPosition(self.WindowPosition[0],self.WindowPosition[1])
self.RenderWindow.SetPointSmoothing(self.PointSmoothing)
self.RenderWindow.SetLineSmoothing(self.LineSmoothing)
self.RenderWindow.SetPolygonSmoothing(self.PolygonSmoothing)
self.RenderWindowInteractor = vtk.vtkRenderWindowInteractor()
#if 'vtkCocoaRenderWindowInteractor' in dir(vtk) and vtk.vtkCocoaRenderWindowInteractor.SafeDownCast(self.RenderWindowInteractor):
# self.RenderWindowInteractor = vtkvmtk.vtkvmtkCocoaRenderWindowInteractor()
self.RenderWindow.SetInteractor(self.RenderWindowInteractor)
self.RenderWindowInteractor.SetInteractorStyle(vtkvmtk.vtkvmtkInteractorStyleTrackballCamera())
self.RenderWindowInteractor.GetInteractorStyle().KeyPressActivationOff()
self.RenderWindowInteractor.GetInteractorStyle().AddObserver("CharEvent",self.CharCallback)
self.RenderWindowInteractor.GetInteractorStyle().AddObserver("KeyPressEvent",self.KeyPressCallback)
self.AddKeyBinding('x','Take screenshot.',self.ScreenshotCallback,'0')
self.AddKeyBinding('r','Reset camera.',self.ResetCameraCallback,'0')
#self.AddKeyBinding('w','Show wireframe.',None,'0')
#self.AddKeyBinding('r','Reset camera.',self.ResetCameraCallback, '0')
#self.AddKeyBinding('s','Show surface.', None,'0')
#self.AddKeyBinding('e','Quit renderer.',self.QuitRendererCallback,'0')
self.AddKeyBinding('q','Quit renderer/proceed.',self.QuitRendererCallback,'0')
#self.AddKeyBinding('3','3D.', None,'0')
#self.TextActorStd = vtk.vtkTextActor()
#self.TextActorStd.SetPosition(self.PositionStd)
#self.Renderer.AddActor(self.TextActorStd)
fontSize = int(self._GetScreenFontSize())
self.TextActor = vtk.vtkTextActor()
self.TextActor.GetTextProperty().SetFontSize(fontSize)
self.TextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
self.TextActor.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport()
self.TextActor.SetPosition(self.Position)
self.Renderer.AddActor(self.TextActor)
#self.TextActorOpmode = vtk.vtkTextActor()
#self.TextActorOpmode.SetPosition(self.PositionOpmode)
#self.Renderer.AddActor(self.TextActorOpmode)
self.TextInputActor = vtk.vtkTextActor()
self.TextInputActor.GetTextProperty().SetFontSize(fontSize)
self.TextInputActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
self.TextInputActor.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport()
self.TextInputActor.SetPosition(self.InputPosition)
if self.UseRendererInputStream:
self.InputStream = vmtkRendererInputStream(self)
示例2: __init__
def __init__(self, displayAxes = True):
threading.Thread.__init__(self)
self.footText = "PyVSim ver. " + VERSION
self.windowTitle = "PyVSim Visualization window - powered by VTK"
self.windowColor = [0,0.25,0.40]
self.windowSize = [800,800]
self.actorlist = None
self.displayAxes = displayAxes
self.rend = vtk.vtkRenderer()
self.window = vtk.vtkRenderWindow()
self.interactor = vtk.vtkRenderWindowInteractor()
self.legend = vtk.vtkTextActor()
self.rend.SetBackground(self.windowColor[0],
self.windowColor[1],
self.windowColor[2])
self.window.SetSize(self.windowSize[0],self.windowSize[0])
self.window.AddRenderer(self.rend)
self.interactor.SetRenderWindow(self.window)
self.legend.GetTextProperty().SetFontSize(12)
self.legend.SetPosition2(0,0)
self.legend.SetInput(self.footText)
self.rend.AddActor(self.legend)
示例3: drawVTKText
def drawVTKText(text,position,fontSize=18,color=[0,0,0],renderer=None):
"""Draws text in renderer.
Args:
text (str): Text.
position (numpy.ndarray): Position where to draw it.
Keyword Args:
fontSize (int): Font Size.
color (list): Color of text in normed RGB values.
renderer (vtk.vtkRenderer): Renderer to draw in.
Returns:
vtk.vtkTextActor: Text actor
"""
txt = vtk.vtkTextActor()
txt.SetInput(text)
txtprop=txt.GetTextProperty()
txtprop.SetFontFamilyToArial()
txtprop.SetFontSize(fontSize)
txtprop.SetColor(color[0],color[1],color[2])
txt.SetDisplayPosition(position[0],position[1])
if renderer!=None:
renderer.AddActor(txt)
return txt
示例4: __init__
def __init__(self, parent, visualizer, **kws):
"""
Initialization
"""
self.x, self.y, self.z = -1, -1, -1
VisualizationModule.__init__(self, parent, visualizer, **kws)
#self.name = "Scale bar"
self.renew = 1
self.mapper = vtk.vtkDataSetMapper()
self.actor = vtk.vtkActor()
self.actor.SetMapper(self.mapper)
self.width = 10
self.widthPx = 100
self.voxelSize = (1, 1, 1)
self.renderer = self.parent.getRenderer()
self.renderer.AddActor(self.actor)
self.polyLine = vtk.vtkPolyLine()
#self.mapper.SetInput(self.polyLine.GetOutput())
self.actor.GetProperty().SetColor(1, 1, 1)
self.textActor = vtk.vtkTextActor()
#self.textActor.ScaledTextOn()
self.renderer.AddActor2D(self.textActor)
iactor = self.wxrenwin.GetRenderWindow().GetInteractor()
style = iactor.GetInteractorStyle()
# style.AddObserver("StartInteractionEvent",self.updateLine)
style.AddObserver("EndInteractionEvent", self.updateRendering)
示例5: createAnnotations
def createAnnotations(self):
# Add axes.
self.axesActor = vtk.vtkAxesActor()
self.axesActor.SetTotalLength(30,30,30)
self.axesActor.SetShaftTypeToCylinder()
self.axesActor.SetCylinderRadius(.05)
self.axesActor.GetXAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone()
self.axesActor.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(12)
self.axesActor.GetXAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
self.axesActor.GetXAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
self.axesActor.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
self.axesActor.GetYAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone()
self.axesActor.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(12)
self.axesActor.GetYAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
self.axesActor.GetYAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
self.axesActor.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
self.axesActor.GetZAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone()
self.axesActor.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(12)
self.axesActor.GetZAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff()
self.axesActor.GetZAxisCaptionActor2D().GetCaptionTextProperty().BoldOff()
self.axesActor.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
self.addActor(self.axesActor)
# Add handling info.
self.infoText = vtk.vtkTextActor()
self.infoText.SetInput("Rotate: Left mouse button\nPan: Middle mouse button\nZoom: Right mouse button")
self.infoText.GetTextProperty()
self.infoText.GetTextProperty().SetFontFamilyToArial()
self.infoText.GetTextProperty().SetFontSize(11)
self.infoText.GetTextProperty().SetColor(.6,.6,.6)
self.infoText.SetDisplayPosition(20,30)
self.addActor(self.infoText)
示例6: __init__
def __init__(self, _drawModel):
self.legendActor = vtk.vtkScalarBarActor()
self.legendActor.SetNumberOfLabels(8)
(self.minCon, self.maxCon) = (0, 0)
self.plane = 'XY'
self.planePos = 0
self.ren = None
dM = ref(_drawModel)
self.drawModel = dM()
self.currentDrawingFunction = None
self.currentActors = {} # dictionary of current actors
self.drawingFcnName = "" # holds a string describing name of the drawing fcn . Used to determine if current actors need to be removed before next drawing
self.drawingFcnHasChanged = True
self.fieldTypes = None
self.currentDrawingParameters = DrawingParameters()
# self.currentFieldType = ("Cell_Field", FIELD_TYPES[0])
self.currentFieldType = ("Cell_Field", 'CellField')
self.__initDist = 0 # initial camera distance - used in zoom functions
self.min_max_text_actor = vtk.vtkTextActor()
# CUSTOM ACTORS
self.customActors = {} # {visName: CustomActorsStorage() }
self.currentCustomVisName = '' # stores name of the current custom visualization
self.currentVisName = '' # stores name of the current visualization
self.cameraSettingsDict = {} # {fieldName:CameraSettings()}
示例7: onRenderEnd
def onRenderEnd(self, event=None, e2=None):
"""
Called when rendering ends
"""
self.rendering = 0
if self.rubberband:
self.iren.SetInteractorStyle(self.oldStyle)
self.rubberband = 0
if self.showFPS:
if not self.textActor:
self.textActor = vtk.vtkTextActor()
prop = self.textActor.GetTextProperty()
prop.SetFontSize(14)
self.textActor.SetTextProperty(prop)
# changing w,h to width,height (SS 25.06.07)
width, height = self.renderer.GetSize()
self.textActor.SetDisplayPosition(width - 85, height - 50)
self.renderer.AddActor(self.textActor)
t = time.time() - self.endTime
if not t:
return
fps = 1.0 / t
self.endTime = time.time()
renderTime = self.renderer.GetLastRenderTimeInSeconds()
txt = "fps %.1f\ntime %.3fs" % (fps, renderTime)
self.textActor.SetInput(txt)
示例8: add
def add(**kwargs):
ren = vtk.vtkRenderer()
ren.SetBackground(0.5, 0.5, 0.5)
#ren.SetViewport(0, 0, 0.5, 1)
renWin.AddRenderer(ren)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(elev.GetOutputPort())
mapper.SetLookupTable(lut)
mapper.SetInterpolateScalarsBeforeMapping(kwargs['interpolate_scalars_before_mapping'])
mapper.SetScalarMaterialMode(kwargs["material_mode"])
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren.AddActor(actor)
prop = actor.GetProperty()
prop.SetAmbient(kwargs['ambient'])
prop.SetDiffuse(kwargs['diffuse'])
prop.SetAmbientColor(1, 0, 0)
prop.SetDiffuseColor(0, 1, 0)
textActorL = vtk.vtkTextActor()
txt = " InterpolateScalarsBeforeMapping: %d\n"\
" ScalarMaterialMode: %s\n"\
" Ambient: %.2f\t Ambient Color: 1, 0, 0\n"\
" Diffuse: %.2f\t Diffuse Color: 0, 1, 0"
txt = txt % (kwargs['interpolate_scalars_before_mapping'],
mapper.GetScalarMaterialModeAsString(), prop.GetAmbient(), prop.GetDiffuse())
textActorL.SetInput(txt)
ren.AddActor(textActorL)
return (ren, actor, mapper)
示例9: CreateTextActor
def CreateTextActor(text,textprop,xpos,ypos,
justification="left",
verticaljustification="bottom") :
textactor = vtk.vtkTextActor()
textactor.SetInput(text)
textactor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
textactor.SetPosition(xpos,ypos)
textactor.GetTextProperty().SetFontFamily(textprop.GetFontFamily())
textactor.GetTextProperty().SetColor(textprop.GetColor())
if justification in (-1,"left") :
textactor.GetTextProperty().SetJustificationToLeft()
elif justification in (0,"center","middle") :
textactor.GetTextProperty().SetJustificationToCentered()
elif justification in (1,"right") :
textactor.GetTextProperty().SetJustificationToRight()
if verticaljustification in (-1,"bottom") :
textactor.GetTextProperty().SetVerticalJustificationToBottom()
elif verticaljustification in (0,"center","middle") :
textactor.GetTextProperty().SetVerticalJustificationToCentered()
elif verticaljustification in (1,"top") :
textactor.GetTextProperty().SetVerticalJustificationToTop()
return textactor
示例10: genTextActor
def genTextActor(renderer,string=None,x=None,y=None,to='default',tt='default',cmap=None):
if isinstance(to,str):
to = vcs.elements["textorientation"][to]
if isinstance(tt,str):
tt = vcs.elements["texttable"][tt]
if tt.priority==0:
return []
if string is None:
string = tt.string
if x is None:
x = tt.x
if y is None:
y = tt.y
if x is None or y is None or string in [['',],[]]:
return []
n = max(len(x),len(y),len(string))
for a in [x,y,string]:
while len(a)<n:
a.append(a[-1])
sz = renderer.GetRenderWindow().GetSize()
actors=[]
pts = vtk.vtkPoints()
geo = None
if vcs.elements["projection"][tt.projection].type!="linear":
# Need to figure out new WC
Npts = 20
for i in range(Npts+1):
X = tt.worldcoordinate[0]+float(i)/Npts*(tt.worldcoordinate[1]-tt.worldcoordinate[0])
for j in range(Npts+1):
Y = tt.worldcoordinate[2]+float(j)/Npts*(tt.worldcoordinate[3]-tt.worldcoordinate[2])
pts.InsertNextPoint(X,Y,0.)
geo,pts = project(pts,tt.projection,tt.worldcoordinate,geo=None)
wc = pts.GetBounds()[:4]
#renderer.SetViewport(tt.viewport[0],tt.viewport[2],tt.viewport[1],tt.viewport[3])
renderer.SetWorldPoint(wc)
for i in range(n):
t = vtk.vtkTextActor()
p=t.GetTextProperty()
prepTextProperty(p,sz,to,tt,cmap)
pts = vtk.vtkPoints()
pts.InsertNextPoint(x[i],y[i],0.)
if geo is not None:
geo,pts = project(pts,tt.projection,tt.worldcoordinate,geo=geo)
X,Y,tz=pts.GetPoint(0)
X,Y = world2Renderer(renderer,X,Y,tt.viewport,wc)
else:
X,Y = world2Renderer(renderer,x[i],y[i],tt.viewport,tt.worldcoordinate)
t.SetPosition(X,Y)
t.SetInput(string[i])
#T=vtk.vtkTransform()
#T.Scale(1.,sz[1]/606.,1.)
#T.RotateY(to.angle)
#t.SetUserTransform(T)
renderer.AddActor(t)
actors.append(t)
return actors
示例11: text_actor
def text_actor(string, fgcolor, size, font):
"""
Build a text actor with some sane defaults
"""
actor = vtkTextActor()
actor.SetInput(string)
props = actor.GetTextProperty()
__set_font(font, props)
props.SetFontSize(size)
props.SetColor(*fgcolor)
props.SetBackgroundColor(white_or_black(*fgcolor))
props.SetBackgroundOpacity(0)
# Sane defaults.
props.SetJustificationToCentered()
props.SetVerticalJustificationToTop()
if string.find("\n") != -1:
lines = string.split("\n")
width = size * max([len(s) for s in lines])
actor.SetPosition(width / 2.0, 0)
return actor
示例12: __init__
def __init__(self, interactor, string, movable=False, on_move=None, on_drag=None, on_click=None, fgcolor=(
1, 1, 1), size=24, font="Arial", left=0, top=0, textproperty=None):
if textproperty is not None:
self.actor = vtkTextActor()
self.actor.SetInput(string)
self.actor.SetTextProperty(textproperty)
if textproperty.GetBackgroundColor() == textproperty.GetColor():
textproperty.SetBackgroundColor(
*
white_or_black(
*
textproperty.GetColor()))
else:
self.actor = text_actor(string, fgcolor, size, font)
widget = WidgetReprShim(interactor, self.actor)
super(Label, self).__init__(interactor, widget)
self.movable = movable
self.action = on_click
self.move_action = on_move
self.dragged = on_drag
self.actor.SetTextScaleModeToNone()
self.actor.SetUseBorderAlign(False)
self.actor.VisibilityOff()
self.left = left
self.top = top
self.register()
示例13: genTextActor
def genTextActor(renderer,string=None,x=None,y=None,to='default',tt='default',cmap=None):
if isinstance(to,str):
to = vcs.elements["textorientation"][to]
if isinstance(tt,str):
tt = vcs.elements["texttable"][tt]
if tt.priority==0:
return
if string is None:
string = tt.string
if x is None:
x = tt.x
if y is None:
y = tt.y
if x is None or y is None or string in [['',],[]]:
return
n = max(len(x),len(y),len(string))
for a in [x,y,string]:
while len(a)<n:
a.append(a[-1])
sz = renderer.GetRenderWindow().GetSize()
for i in range(n):
t = vtk.vtkTextActor()
p=t.GetTextProperty()
prepTextProperty(p,sz,to,tt,cmap)
t.SetInput(string[i])
X,Y = world2Renderer(renderer,x[i],y[i],tt.viewport,tt.worldcoordinate)
t.SetPosition(X,Y)
#T=vtk.vtkTransform()
#T.Scale(1.,sz[1]/606.,1.)
#T.RotateY(to.angle)
#t.SetUserTransform(T)
renderer.AddActor(t)
return
示例14: legendActor
def legendActor(text):
"""Display the given text in the lower left corner of the window.
"""
actor = vtk.vtkTextActor()
actor.GetTextProperty().SetFontSize(24)
actor.SetInput(text)
actor.GetTextProperty().SetColor(0, 0, 0)
return actor
示例15: Execute
def Execute(self):
self._SourceSeedIds.Initialize()
if not self.vmtkRenderer:
self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
self.vmtkRenderer.Initialize()
self.OwnRenderer = 1
glyphs = vtk.vtkGlyph3D()
glyphSource = vtk.vtkSphereSource()
glyphs.SetInputData(self.PickedSeeds)
glyphs.SetSourceConnection(glyphSource.GetOutputPort())
glyphs.SetScaleModeToDataScalingOff()
glyphs.SetScaleFactor(self._Surface.GetLength()*0.01)
glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInputConnection(glyphs.GetOutputPort())
self.SeedActor = vtk.vtkActor()
self.SeedActor.SetMapper(glyphMapper)
self.SeedActor.GetProperty().SetColor(1.0,0.0,0.0)
self.SeedActor.PickableOff()
self.vmtkRenderer.Renderer.AddActor(self.SeedActor)
self.vmtkRenderer.AddKeyBinding('u','Undo.',self.UndoCallback)
self.vmtkRenderer.AddKeyBinding('space','Add points.',self.PickCallback)
surfaceMapper = vtk.vtkPolyDataMapper()
surfaceMapper.SetInputData(self._Surface)
surfaceMapper.ScalarVisibilityOff()
surfaceActor = vtk.vtkActor()
surfaceActor.SetMapper(surfaceMapper)
surfaceActor.GetProperty().SetOpacity(1)
self.vmtkRenderer.Renderer.AddActor(surfaceActor)
# create a text actor
txt = vtk.vtkTextActor()
info = "Position mouse and press space. "
info += "Select seeds in this order: RSpv, RIpv, LIpv, LSpv. "
info += "Fifth seed requires --use_laa_seed command."
txt.SetInput(info)
txtprop=txt.GetTextProperty()
txtprop.SetFontFamilyToArial()
txtprop.SetFontSize(13)
txtprop.SetColor(1, 1, 1)
txt.SetDisplayPosition(0, 10)
self.vmtkRenderer.Renderer.AddActor(txt)
any = 0
while any == 0:
self.InitializeSeeds()
self.vmtkRenderer.Render()
any = self.PickedSeedIds.GetNumberOfIds()
self._SourceSeedIds.DeepCopy(self.PickedSeedIds)
if self.OwnRenderer:
self.vmtkRenderer.Deallocate()