Exemplo n.º 1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkTextSource(), 'Processing.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 2
0
def main():
    colors = vtk.vtkNamedColors()

    textSource = vtk.vtkTextSource()
    textSource.SetText("Hello")
    textSource.SetForegroundColor(colors.GetColor3d('DarkSlateGray'))
    textSource.SetBackgroundColor(colors.GetColor3d('NavajoWhite'))
    textSource.BackingOn()
    textSource.Update()

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(textSource.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    # Create a renderer, render window, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # Add the actor to the scene
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('Bisque'))

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Start()
Exemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkTextSource(),
                                       'Processing.', (), ('vtkPolyData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemplo n.º 4
0
    def _draw_text(self):
        text = u' %.3f ' % \
                self.CalculateAngle()
        x, y, z = self.points[1]
        textsource = vtk.vtkTextSource()
        textsource.SetText(text)
        textsource.SetBackgroundColor((250 / 255.0, 247 / 255.0, 218 / 255.0))
        textsource.SetForegroundColor(self.colour)

        m = vtk.vtkPolyDataMapper2D()
        m.SetInputConnection(textsource.GetOutputPort())

        a = vtk.vtkActor2D()
        a.SetMapper(m)
        a.DragableOn()
        a.GetPositionCoordinate().SetCoordinateSystemToWorld()
        a.GetPositionCoordinate().SetValue(x, y, z)
        self.text_actor = a
Exemplo n.º 5
0
    def _draw_text(self):
        text = u' %.2f ' % \
                self.CalculateAngle()
        x,y,z= self.points[1]
        textsource = vtk.vtkTextSource()
        textsource.SetText(text)
        textsource.SetBackgroundColor((250/255.0, 247/255.0, 218/255.0))
        textsource.SetForegroundColor(self.colour)

        m = vtk.vtkPolyDataMapper2D()
        m.SetInputConnection(textsource.GetOutputPort())

        a = vtk.vtkActor2D()
        a.SetMapper(m)
        a.DragableOn()
        a.GetPositionCoordinate().SetCoordinateSystemToWorld()
        a.GetPositionCoordinate().SetValue(x,y,z)
        self.text_actor = a
Exemplo n.º 6
0
    def _draw_text(self):
        p1, p2 = self.points
        text = ' %.2f mm ' % \
                math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p1, p2))
        x, y, z = [(i + j) / 2 for i, j in zip(p1, p2)]
        textsource = vtk.vtkTextSource()
        textsource.SetText(text)
        textsource.SetBackgroundColor((250 / 255.0, 247 / 255.0, 218 / 255.0))
        textsource.SetForegroundColor(self.colour)

        m = vtk.vtkPolyDataMapper2D()
        m.SetInputConnection(textsource.GetOutputPort())

        a = vtk.vtkActor2D()
        a.SetMapper(m)
        a.DragableOn()
        a.GetPositionCoordinate().SetCoordinateSystemToWorld()
        a.GetPositionCoordinate().SetValue(x, y, z)
        a.GetProperty().SetColor((0, 1, 0))
        self.text_actor = a
Exemplo n.º 7
0
    def _draw_text(self):
        p1, p2 = self.points
        text = ' %.2f mm ' % \
                math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p1, p2))
        x,y,z=[(i+j)/2 for i,j in zip(p1, p2)]
        textsource = vtk.vtkTextSource()
        textsource.SetText(text)
        textsource.SetBackgroundColor((250/255.0, 247/255.0, 218/255.0))
        textsource.SetForegroundColor(self.colour)

        m = vtk.vtkPolyDataMapper2D()
        m.SetInputConnection(textsource.GetOutputPort())

        a = vtk.vtkActor2D()
        a.SetMapper(m)
        a.DragableOn()
        a.GetPositionCoordinate().SetCoordinateSystemToWorld()
        a.GetPositionCoordinate().SetValue(x,y,z)
        a.GetProperty().SetColor((0, 1, 0))
        self.text_actor = a
Exemplo n.º 8
0
# This program demonstrates how VTK can be used to render a text
# The user can also interact with the text by using the mouse

# load VTK
import vtk

# Create a Text source and set the text
text = vtk.vtkTextSource()
text.SetText("UPPMAX")
text.SetForegroundColor(0.6,0.2,0.2)

# Create a mapper and set the Text source as input 
textMapper = vtk.vtkPolyDataMapper()
textMapper.SetInputConnection(text.GetOutputPort())

# Create an actor and set the mapper as input
textActor = vtk.vtkActor()
textActor.SetMapper(textMapper)

# Create a renderer
ren = vtk.vtkRenderer()

# Assign the actor to the renderer
ren.AddActor(textActor)

# Create a rendering window
renWin = vtk.vtkRenderWindow()

# Add the renderer to the window
renWin.AddRenderer(ren)
Exemplo n.º 9
0
def main():
    colors = vtk.vtkNamedColors()

    # Set the background color.
    colors.SetColor("BkgColor", [51, 77, 102, 255])

    sourceObjects = list()
    sourceObjects.append(vtk.vtkSphereSource())
    sourceObjects[-1].SetPhiResolution(21)
    sourceObjects[-1].SetThetaResolution(21)

    sourceObjects.append(vtk.vtkConeSource())
    sourceObjects[-1].SetResolution(51)

    sourceObjects.append(vtk.vtkCylinderSource())
    sourceObjects[-1].SetResolution(51)

    sourceObjects.append(vtk.vtkCubeSource())
    sourceObjects.append(vtk.vtkPlaneSource())
    sourceObjects.append(vtk.vtkTextSource())
    sourceObjects[-1].SetText("Hello")
    sourceObjects[-1].BackingOff()

    sourceObjects.append(vtk.vtkPointSource())
    sourceObjects[-1].SetNumberOfPoints(500)

    sourceObjects.append(vtk.vtkDiskSource())
    sourceObjects[-1].SetCircumferentialResolution(51)

    sourceObjects.append(vtk.vtkLineSource())

    renderers = list()
    mappers = list()
    actors = list()
    textmappers = list()
    textactors = list()

    # Create one text property for all.
    textProperty = vtk.vtkTextProperty()
    textProperty.SetFontSize(16)
    textProperty.SetJustificationToCentered()

    backProperty = vtk.vtkProperty()
    backProperty.SetColor(colors.GetColor3d("Red"))

    # Create a source, renderer, mapper, and actor
    # for each object.
    for i in range(0, len(sourceObjects)):
        mappers.append(vtk.vtkPolyDataMapper())
        mappers[i].SetInputConnection(sourceObjects[i].GetOutputPort())

        actors.append(vtk.vtkActor())
        actors[i].SetMapper(mappers[i])
        actors[i].GetProperty().SetColor(colors.GetColor3d("Seashell"))
        actors[i].SetBackfaceProperty(backProperty)

        textmappers.append(vtk.vtkTextMapper())
        textmappers[i].SetInput(sourceObjects[i].GetClassName())
        textmappers[i].SetTextProperty(textProperty)

        textactors.append(vtk.vtkActor2D())
        textactors[i].SetMapper(textmappers[i])
        textactors[i].SetPosition(120, 16)
        renderers.append(vtk.vtkRenderer())

    gridDimensions = 3

    # We need a renderer even if there is no actor.
    for i in range(len(sourceObjects), gridDimensions ** 2):
        renderers.append(vtk.vtkRenderer())

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("Source Objects Demo")
    rendererSize = 300
    renderWindow.SetSize(rendererSize * gridDimensions, rendererSize * gridDimensions)

    for row in range(0, gridDimensions):
        for col in range(0, gridDimensions):
            index = row * gridDimensions + col
            x0 = float(col) / gridDimensions
            y0 = float(gridDimensions - row - 1) / gridDimensions
            x1 = float(col + 1) / gridDimensions
            y1 = float(gridDimensions - row) / gridDimensions
            renderWindow.AddRenderer(renderers[index])
            renderers[index].SetViewport(x0, y0, x1, y1)

            if index > (len(sourceObjects) - 1):
                continue

            renderers[index].AddActor(actors[index])
            renderers[index].AddActor(textactors[index])
            renderers[index].SetBackground(colors.GetColor3d("BkgColor"))
            renderers[index].ResetCamera()
            renderers[index].GetActiveCamera().Azimuth(30)
            renderers[index].GetActiveCamera().Elevation(30)
            renderers[index].GetActiveCamera().Zoom(0.8)
            renderers[index].ResetCameraClippingRange()

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    interactor.Start()
# This program demonstrates how VTK can be used to render a text
# The user can also interact with the text by using the mouse

# load VTK
import vtk

# Create a Text source and set the text
text = vtk.vtkTextSource()
text.SetText("UPPMAX")
text.SetForegroundColor(0.6,0.2,0.2)

# Create a mapper and set the Text source as input
textMapper = vtk.vtkPolyDataMapper()
textMapper.SetInputConnection(text.GetOutputPort())

# Create an actor and set the mapper as input
textActor = vtk.vtkActor()
textActor.SetMapper(textMapper)

# Create a renderer
ren = vtk.vtkRenderer()

# Assign the actor to the renderer
ren.AddActor(textActor)

# Create a rendering window
renWin = vtk.vtkRenderWindow()

# Add the renderer to the window
renWin.AddRenderer(ren)
Exemplo n.º 11
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Created oriented text
text0Source = vtk.vtkTextSource()
text0Source.SetText("Text Source with Scalars (default)")
text0Mapper = vtk.vtkPolyDataMapper()
text0Mapper.SetInputConnection(text0Source.GetOutputPort())
text0Actor = vtk.vtkActor()
text0Actor.SetMapper(text0Mapper)
text0Actor.SetScale(.1,.1,.1)
text0Actor.AddPosition(0,2,0)
text1Source = vtk.vtkTextSource()
text1Source.SetText("Text Source with Scalars")
text1Source.SetForegroundColor(1,0,0)
text1Source.SetBackgroundColor(1,1,1)
text1Mapper = vtk.vtkPolyDataMapper()
text1Mapper.SetInputConnection(text1Source.GetOutputPort())
text1Actor = vtk.vtkActor()
text1Actor.SetMapper(text1Mapper)
text1Actor.SetScale(.1,.1,.1)
text2Source = vtk.vtkTextSource()
text2Source.SetText("Text Source without Scalars")
text2Source.BackingOff()
text2Mapper = vtk.vtkPolyDataMapper()
text2Mapper.SetInputConnection(text2Source.GetOutputPort())
text2Mapper.ScalarVisibilityOff()
text2Actor = vtk.vtkActor()
Exemplo n.º 12
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Created oriented text
text0Source = vtk.vtkTextSource()
text0Source.SetText("Text Source with Scalars (default)")
text0Mapper = vtk.vtkPolyDataMapper()
text0Mapper.SetInputConnection(text0Source.GetOutputPort())
text0Actor = vtk.vtkActor()
text0Actor.SetMapper(text0Mapper)
text0Actor.SetScale(.1, .1, .1)
text0Actor.AddPosition(0, 2, 0)
text1Source = vtk.vtkTextSource()
text1Source.SetText("Text Source with Scalars")
text1Source.SetForegroundColor(1, 0, 0)
text1Source.SetBackgroundColor(1, 1, 1)
text1Mapper = vtk.vtkPolyDataMapper()
text1Mapper.SetInputConnection(text1Source.GetOutputPort())
text1Actor = vtk.vtkActor()
text1Actor.SetMapper(text1Mapper)
text1Actor.SetScale(.1, .1, .1)
text2Source = vtk.vtkTextSource()
text2Source.SetText("Text Source without Scalars")
text2Source.BackingOff()
text2Mapper = vtk.vtkPolyDataMapper()
text2Mapper.SetInputConnection(text2Source.GetOutputPort())
text2Mapper.ScalarVisibilityOff()
text2Actor = vtk.vtkActor()
Exemplo n.º 13
0
import vtk


# Create a sphere
text_source = vtk.vtkTextSource()
text_source.SetText("Hello")
text_source.SetForegroundColor(1.0, 0.0, 0.0)
text_source.BackingOn()
text_source.Update()

# Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(text_source.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)

# Add the actor to the scene
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)  # Background color white

# Render and interact
render_window.Render()
render_window_interactor.Start()
Exemplo n.º 14
0
def vtk_text(texts,
             arr_type='str',
             color=True,
             cols=8,
             sep=5,
             scale=(1, 1, 1),
             rot=(0, 0, 0),
             translate=(0, 0, 0)):
    """
  Visualizes text using vtk.
  If parse_and_color is set to True, it will parse the text and color "O" green and "X" red.
  """
    vtk_actors = []
    for n, text_str in enumerate(texts):
        x = (n % cols) * sep
        y = (n // cols) * sep

        if arr_type == 'float':
            if text_str < 0.333:
                col = (1, 0, 0)
            elif text_str < 0.666:
                col = (1, 1, 1)
            else:
                col = (0, 1, 0)
            if not color:
                col = (1, 1, 1)
            text_str = '%.1f%%' % (text_str * 100.)
        elif arr_type == 'boolean_list':
            text_arr = ['O' if boolean else 'X' for boolean in text_str]
        elif arr_type == 'text':
            col = (1, 1, 1)
        else:
            raise Exception('Unknown array type.')

        if arr_type == 'boolean_list':
            for k, boolean in enumerate(text_arr):
                text_source = vtk.vtkTextSource()
                col = (0, 1, 0) if boolean == 'O' else (1, 0, 0)
                text_source.SetForegroundColor(*col)
                text_source.SetText(boolean)
                text_mapper = vtk.vtkPolyDataMapper()
                text_mapper.SetInputConnection(text_source.GetOutputPort())

                additional_x_disp = k * 0.1
                text_actor = vtk.vtkActor()
                text_actor.SetMapper(text_mapper)
                trans = (translate[0] + x + additional_x_disp,
                         translate[1] + y, translate[2])
                vtk_transform_actor(text_actor,
                                    scale=scale,
                                    rot=rot,
                                    translate=trans)
                vtk_actors.append(text_actor)
        else:
            text_source = vtk.vtkTextSource()
            text_source.SetForegroundColor(*col)
            text_source.SetText(text_str)
            text_mapper = vtk.vtkPolyDataMapper()
            text_mapper.SetInputConnection(text_source.GetOutputPort())

            text_actor = vtk.vtkActor()
            text_actor.SetMapper(text_mapper)
            trans = (translate[0] + x, translate[1] + y, translate[2])
            vtk_transform_actor(text_actor,
                                scale=scale,
                                rot=rot,
                                translate=trans)
            vtk_actors.append(text_actor)

    return vtk_actors
Exemplo n.º 15
0
import vtk


#Create a sphere
text_source = vtk.vtkTextSource()
text_source.SetText("Hello")
text_source.SetForegroundColor(1.0, 0.0, 0.0)
text_source.BackingOn()
text_source.Update()

#Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(text_source.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

#Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)

#Add the actor to the scene
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1) # Background color white

#Render and interact
render_window.Render()
render_window_interactor.Start()