def CreateAxes():
    global xAxis, yAxis, zAxis, popSplatter

    # Create axes.
    popSplatter.Update()
    bounds = popSplatter.GetOutput().GetBounds()
    axes = vtk.vtkAxes()
    axes.SetOrigin(bounds[0], bounds[2], bounds[4])
    axes.SetScaleFactor(popSplatter.GetOutput().GetLength()/5.0)

    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Label the axes.
    XText = vtk.vtkVectorText()
    XText.SetText(xAxis)

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(0.02, .02, .02)
    XActor.SetPosition(0.35, -0.05, -0.05)
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText(yAxis)

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(0.02, .02, .02)
    YActor.SetPosition(-0.05, 0.35, -0.05)
    YActor.GetProperty().SetColor(0, 0, 0)

    ZText = vtk.vtkVectorText()
    ZText.SetText(zAxis)

    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(0.02, .02, .02)
    ZActor.SetPosition(-0.05, -0.05, 0.35)
    ZActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor, ZActor
def CreateAxes():
    global xAxis, yAxis, zAxis, popSplatter

    # Create axes.
    popSplatter.Update()
    bounds = popSplatter.GetOutput().GetBounds()
    axes = vtk.vtkAxes()
    axes.SetOrigin(bounds[0], bounds[2], bounds[4])
    axes.SetScaleFactor(popSplatter.GetOutput().GetLength()/5.0)

    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Label the axes.
    XText = vtk.vtkVectorText()
    XText.SetText(xAxis)

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(0.02, .02, .02)
    XActor.SetPosition(0.35, -0.05, -0.05)
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText(yAxis)

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(0.02, .02, .02)
    YActor.SetPosition(-0.05, 0.35, -0.05)
    YActor.GetProperty().SetColor(0, 0, 0)

    ZText = vtk.vtkVectorText()
    ZText.SetText(zAxis)

    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(0.02, .02, .02)
    ZActor.SetPosition(-0.05, -0.05, 0.35)
    ZActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor, ZActor
Beispiel #3
0
 def showAxis(self):
     if self.axis:
         xmin, xmax, ymin, ymax, zmin, zmax = self.bounds[:]
         axes=vtk.vtkAxes()
         axes.SetOrigin(0.0,0.0,0.0)
         axes.SetScaleFactor(0.1*max([xmax-xmin,ymax-ymin,zmax-zmin]))
         axesTubes=vtk.vtkTubeFilter()
         axesTubes.SetInputConnection(axes.GetOutputPort())
         axesTubes.SetRadius(0.2)
         axesTubes.SetNumberOfSides(6)
         axesMapper=vtk.vtkPolyDataMapper() 
         axesMapper.SetInputConnection(axesTubes.GetOutputPort())
         axesActor=vtk.vtkActor() 
         axesActor.SetMapper(axesMapper)
         XText=vtk.vtkVectorText()    
         XText.SetText("X")
         XTextMapper=vtk.vtkPolyDataMapper() 
         XTextMapper.SetInputConnection(XText.GetOutputPort())
         XActor=vtk.vtkFollower()
         XActor.SetMapper(XTextMapper)
         XActor.SetScale(2.0, 2.0, 2.0)
         XActor.SetPosition(1.11*xmax, ymin, zmin)
         XActor.GetProperty().SetColor(0,0,0)
         XActor.SetCamera(self.cam)
         YText=vtk.vtkVectorText()    
         YText.SetText("Y")
         YTextMapper=vtk.vtkPolyDataMapper() 
         YTextMapper.SetInputConnection(YText.GetOutputPort())
         YActor=vtk.vtkFollower()
         YActor.SetMapper(YTextMapper)
         YActor.SetScale(2.0, 2.0, 2.0)
         YActor.SetPosition(xmin, 1.11*ymax, zmin)
         YActor.GetProperty().SetColor(0,0,0)
         YActor.SetCamera(self.cam)
         ZText=vtk.vtkVectorText()    
         ZText.SetText("Z")
         ZTextMapper=vtk.vtkPolyDataMapper() 
         ZTextMapper.SetInputConnection(ZText.GetOutputPort())
         ZActor=vtk.vtkFollower()
         ZActor.SetMapper(ZTextMapper)
         ZActor.SetScale(2.0, 2.0, 2.0)
         ZActor.SetPosition(xmin, ymin, 1.11*zmax)
         ZActor.GetProperty().SetColor(0,0,0)
         ZActor.SetCamera(self.cam)
         self.ren.AddActor(axesActor)
         self.ren.AddActor(XActor)
         self.ren.AddActor(YActor)
         self.ren.AddActor(ZActor)
Beispiel #4
0
        def MakeText(primitive):

            tf.update({primitive: vtk.vtkTriangleFilter()})
            tf[primitive].SetInputConnection(primitive.GetOutputPort())

            mp.update({primitive: vtk.vtkMassProperties()})
            mp[primitive].SetInputConnection(tf[primitive].GetOutputPort())

            # here we capture stdout and write it to a variable for processing.
            summary = StringIO.StringIO()
            # save the original stdout
            old_stdout = sys.stdout
            sys.stdout = summary

            print mp[primitive]
            summary = summary.getvalue()

            startSum = summary.find("  VolumeX")
            endSum = len(summary)
            print summary[startSum:]
            # Restore stdout
            sys.stdout = old_stdout

            vt.update({primitive: vtk.vtkVectorText()})
            vt[primitive].SetText(summary[startSum:])

            pdm.update({primitive: vtk.vtkPolyDataMapper()})
            pdm[primitive].SetInputConnection(vt[primitive].GetOutputPort())

            ta.update({primitive: vtk.vtkActor()})
            ta[primitive].SetMapper(pdm[primitive])
            ta[primitive].SetScale(.2, .2, .2)
            return ta[primitive]
Beispiel #5
0
def AddStock(renderers, apf, filename, name, zPosition):
    print("Adding", name)

    # Read the data
    PolyDataRead = vtk.vtkPolyDataReader()
    PolyDataRead.SetFileName(filename)
    PolyDataRead.Update()

    TubeFilter = vtk.vtkTubeFilter()
    TubeFilter.SetInputConnection(PolyDataRead.GetOutputPort())
    TubeFilter.SetNumberOfSides(8)
    TubeFilter.SetRadius(0.5)
    TubeFilter.SetRadiusFactor(10000)

    Transform = vtk.vtkTransform()
    Transform.Translate(0, 0, zPosition)
    Transform.Scale(0.15, 1, 1)

    TransformFilter = vtk.vtkTransformPolyDataFilter()
    TransformFilter.SetInputConnection(TubeFilter.GetOutputPort())
    TransformFilter.SetTransform(Transform)

    apf.AddInputData(TransformFilter.GetOutput())

    # Create the labels.
    TextSrc = vtk.vtkVectorText()
    TextSrc.SetText(name)
    numberOfPoints = PolyDataRead.GetOutput().GetNumberOfPoints()

    nameIndex = int((numberOfPoints - 1) * 0.8)

    nameLocation = PolyDataRead.GetOutput().GetPoint(nameIndex)

    x = nameLocation[0] * 0.15
    y = nameLocation[1] + 5.0
    z = zPosition

    for r in range(0, len(renderers)):
        LabelMapper = vtk.vtkPolyDataMapper()
        LabelMapper.SetInputConnection(TextSrc.GetOutputPort())

        LabelActor = vtk.vtkFollower()
        LabelActor.SetMapper(LabelMapper)
        LabelActor.SetPosition(x, y, z)
        LabelActor.SetScale(2, 2, 2)
        LabelActor.SetOrigin(TextSrc.GetOutput().GetCenter())

        # Increment zPosition.
        zPosition += 8.0

        StockMapper = vtk.vtkPolyDataMapper()
        StockMapper.SetInputConnection(TransformFilter.GetOutputPort())
        StockMapper.SetScalarRange(0, 8000)
        StockActor = vtk.vtkActor()
        StockActor.SetMapper(StockMapper)

        renderers[r].AddActor(StockActor)
        renderers[r].AddActor(LabelActor)
        LabelActor.SetCamera(renderers[r].GetActiveCamera())
    return zPosition
    def add_marker(self, marker):
        print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(marker)"
        self.renderer.AddActor(marker)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x+size, y+size, z+size)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on():
            print "VisibilityOn"
            textActor.VisibilityOn()
        else:
            print "VisibilityOff"
            textActor.VisibilityOff()


        self.textActors[marker] = textActor
        print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(textActor)"
        self.renderer.AddActor(textActor)
Beispiel #7
0
    def __init__(self,
                 text,
                 position=(0, 0, 0),
                 follow_cam=True,
                 scale=1,
                 color=None,
                 opacity=None,
                 fig="gcf"):
        super().__init__(fig)
        # Create the 3D text and the associated mapper and follower (a type of
        # actor). Position the text so it is displayed over the origin of the
        # axes.

        self.source = vtk.vtkVectorText()
        self.text = text

        # This chunk is different to how most plots objects construct
        # themselves. So super().add_to_plot() wont work unfortunately.

        self.actor = vtk.vtkFollower()
        self.scale = scale
        self.position = position

        self.mapper = vtk.vtkPolyDataMapper()
        self.actor.SetMapper(self.mapper)

        self.property = self.actor.GetProperty()
        self.mapper.SetInputConnection(self.source.GetOutputPort())

        self.fig += self
        self.color_opacity(color, opacity)

        if follow_cam:
            self.actor.SetCamera(self.fig.renderer.GetActiveCamera())
Beispiel #8
0
    def __init__(self,
                 color=(1, 1, 1),
                 center=(0, 0, 0),
                 text="hello",
                 scale=1,
                 camera=[]):
        """ create text """
        self.src = vtk.vtkVectorText()
        self.SetText(text)
        #self.SetCamera(camera)
        transform = vtk.vtkTransform()

        transform.Translate(center[0], center[1], center[2])
        transform.Scale(scale, scale, scale)
        #transform.RotateY(90)
        #transform2 = vtk.vtkTransform()
        #transform.Concatenate(transform2)
        #transformFilter=vtk.vtkTransformPolyDataFilter()
        #transformFilter.SetTransform(transform)
        #transformFilter.SetInputConnection(self.src.GetOutputPort())
        #transformFilter.Update()

        #follower = vtk.vtkFollower()
        #follower.SetMapper

        self.SetUserTransform(transform)
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.src.GetOutputPort())
        self.SetMapper(self.mapper)
        self.SetColor(color)
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors.AddItem(ringActor)


        # a hack to keep vtk from casting my class when I put it in
        # the collection.  If I don't register some func, I lose all
        # the derived methods        
        self.observer.AddObserver('EndInteractionEvent', ringActor.silly_hack)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2*marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker] = textActor
        self.renderer.AddActor(textActor)
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors[marker.uuid] = ringActor

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2*marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker.uuid] = textActor
        self.renderer.AddActor(textActor)
def make_render_window():

    #cone actor
    cone = vtk.vtkConeSource()
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    #text actor following camera
    text = vtk.vtkVectorText()
    text.SetText("Origin")
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(text.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)

    ren = vtk.vtkRenderer()
    ren.AddActor(coneActor)
    ren.AddActor(textActor)
    textActor.SetCamera(ren.GetActiveCamera())

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    return renWin
Beispiel #12
0
 def __init__(self, color=(1,1,1), center=(0,0,0), text="hello", scale=1, camera=[]):
     """ create text """
     self.src = vtk.vtkVectorText()
     self.SetText(text)
     #self.SetCamera(camera)
     transform = vtk.vtkTransform()
     
     transform.Translate(center[0], center[1], center[2])
     transform.Scale(scale, scale, scale)
     #transform.RotateY(90)
     #transform2 = vtk.vtkTransform()
     #transform.Concatenate(transform2)
     #transformFilter=vtk.vtkTransformPolyDataFilter()
     #transformFilter.SetTransform(transform)
     #transformFilter.SetInputConnection(self.src.GetOutputPort())
     #transformFilter.Update()
     
     #follower = vtk.vtkFollower()
     #follower.SetMapper
     
     self.SetUserTransform(transform)
     self.mapper = vtk.vtkPolyDataMapper()
     self.mapper.SetInputConnection(self.src.GetOutputPort())
     self.SetMapper(self.mapper)
     self.SetColor(color)
Beispiel #13
0
    def _build_planet_actors(self, key: str, Center: np.array(3),
                             radius: float, color: str):
        sphereSource = vtk.vtkSphereSource()
        # Make the surface smooth.
        sphereSource.SetPhiResolution(100)
        sphereSource.SetThetaResolution(100)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphereSource.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(Colors.GetColor3d(color))
        sphereSource.SetCenter(Center[0], Center[1], Center[2])
        sphereSource.SetRadius(radius)

        # 标签
        vText = vtkVectorText()
        vText.SetText(key)
        textMapper = vtkPolyDataMapper()
        textMapper.SetInputConnection(vText.GetOutputPort())
        textActor = vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(0.05)
        # textActor.AddPosition(Center[0], Center[1], Center[2])
        textActor.SetPosition(Center[0], Center[1], Center[2])
        textActor.SetCamera(self.vtkWidget.renderer.GetActiveCamera())

        # 加入数据集
        self.dataProvider.add_sphere_source(key, sphereSource, textActor)
        self.vtkWidget.renderer.AddActor(actor)
        self.vtkWidget.renderer.AddActor(textActor)
        return
Beispiel #14
0
        def MakeText(primitive):

            tf.update({primitive: vtk.vtkTriangleFilter()})
            tf[primitive].SetInputConnection(primitive.GetOutputPort())

            mp.update({primitive: vtk.vtkMassProperties()})
            mp[primitive].SetInputConnection(tf[primitive].GetOutputPort())

            # here we capture stdout and write it to a variable for processing.
            summary = StringIO.StringIO()
            # save the original stdout
            old_stdout = sys.stdout
            sys.stdout = summary

            print mp[primitive]
            summary = summary.getvalue()

            startSum = summary.find("  VolumeX")
            endSum = len(summary)
            print summary[startSum:]
            # Restore stdout
            sys.stdout = old_stdout

            vt.update({primitive: vtk.vtkVectorText()})
            vt[primitive].SetText(summary[startSum:])

            pdm.update({primitive: vtk.vtkPolyDataMapper()})
            pdm[primitive].SetInputConnection(vt[primitive].GetOutputPort())

            ta.update({primitive: vtk.vtkActor()})
            ta[primitive].SetMapper(pdm[primitive])
            ta[primitive].SetScale(0.2, 0.2, 0.2)
            return ta[primitive]
Beispiel #15
0
    def add_marker(self, marker):
        if debug:
            print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(marker)"
        self.renderer.AddActor(marker)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x+size, y+size, z+size)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on():
            if debug:
                print "VisibilityOn"
            textActor.VisibilityOn()
        else:
            if debug:
                print "VisibilityOff"
            textActor.VisibilityOff()


        self.textActors[marker] = textActor
        if debug:
            print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(textActor)"
        self.renderer.AddActor(textActor)
Beispiel #16
0
def main():
    colors = vtk.vtkNamedColors()

    textSource = vtk.vtkVectorText()
    textSource.SetText('Hello')
    textSource.Update()

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

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('DarkSlateGray'))

    # Create a renderer, render window, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetWindowName('VectorText')

    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()
Beispiel #17
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkVectorText(), 'Processing.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Beispiel #18
0
    def add_picker(self):
        # Create a cell picker.
        picker = vtk.vtkCellPicker()
        # Create a Python function to create the text for the text mapper used
        # to display the results of picking.
        source = vtk.vtkVectorText()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor((0, 0, 0))
        follower.SetScale(0.2)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
        follower.VisibilityOff()

        def annotate_pick(obj, event):
            if picker.GetCellId() < 0:
                follower.VisibilityOff()
            else:
                pick_pos = picker.GetPickPosition()
                mapper = picker.GetMapper()
                if mapper in self.mapper_map:
                    site = self.mapper_map[mapper]
                    output = [site.species_string, "Frac. coords: " +
                                                   " ".join(["{:.4f}".format(c)
                                                             for c in
                                                             site.frac_coords])]
                    source.SetText("\n".join(output))
                    follower.SetPosition(pick_pos)
                    follower.VisibilityOn()
        picker.AddObserver("EndPickEvent", annotate_pick)
        self.picker = picker
        self.iren.SetPicker(picker)
Beispiel #19
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event == 'add marker':
            marker = args[0]
            self.add_ring_actor(marker)
        elif event == 'remove marker':
            marker = args[0]
            self.remove_ring_actor(marker)
        elif event == 'move marker':
            # ring actor will update automatically because it shares
            # the sphere source
            marker, pos = args
            textActor = self.textActors[marker]
            textActor.SetPosition(pos)

        elif event == 'color marker':
            marker, color = args
            actor = self.get_actor_for_marker(marker)
            actor.update()
        elif event == 'label marker':
            marker, label = args
            marker.set_label(label)
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)
        elif event == 'observers update plane':
            self.update_plane()

        self.update_rings()
        self.Render()
Beispiel #20
0
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors.AddItem(ringActor)

        # a hack to keep vtk from casting my class when I put it in
        # the collection.  If I don't register some func, I lose all
        # the derived methods
        self.observer.AddObserver('EndInteractionEvent', ringActor.silly_hack)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2 * marker.get_size()
        textActor.SetScale(size, size, size)
        x, y, z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker] = textActor
        self.renderer.AddActor(textActor)
Beispiel #21
0
def create_actors(x, y, temperature, is_visible):
    if temperature is None:
        return None, None

    cube_source = vtk.vtkCubeSource()
    cube_source.SetXLength(30)
    cube_source.SetYLength(30)
    cube_source.SetZLength(1)
    cube_source.SetCenter(x, y - 19, 0)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(cube_source.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    temperature_label = temperature_labels[get_temperature_label_index(
        temperature)]
    actor.GetProperty().SetColor(
        temperature_colors.GetColor3d(temperature_label))
    actor.SetVisibility(is_visible)

    atext = vtk.vtkVectorText()
    atext.SetText("{:.1f}".format(temperature).center(5))
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(8, 8, 8)
    textActor.AddPosition(x - 16, y - 23, 1)
    textActor.GetProperty().SetColor(0, 0, 0)
    textActor.SetVisibility(is_visible)

    return actor, textActor
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='color marker':
            marker, color = args
            marker.set_color(color)
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            
            if shared.debug: print "Create VTK-Text", marker.get_label()
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)

        elif event=='move marker':
            marker, center = args
            marker.set_center(center)
            #update the select boxes and text actor
            textActor = self.textActors[marker]
            size = marker.get_size()
            textActor.SetScale(size, size, size)
            x,y,z = marker.get_center()
            textActor.SetPosition(x+size, y+size, z+size)

            if self.boxes.has_key(marker):
                selectActor = self.boxes[marker]
                boxSource = vtk.vtkCubeSource()
                boxSource.SetBounds(marker.GetBounds())
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInput(boxSource.GetOutput())
                selectActor.SetMapper(mapper)
                
        elif event=='labels on':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOn()
        elif event=='labels off':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOff()
        #elif event=='select marker':
        #    marker = args[0]
        #    actor = create_box_actor_around_marker(marker)
        #    if shared.debug: print "PlaneWidgetsXYZ.update_viewer(): self.renderer.AddActor(actor)"
        #    self.renderer.AddActor(actor)
        #    self.boxes[marker] = actor
        #elif event=='unselect marker':
        #    marker = args[0]
        #    actor = self.boxes[marker]
        #    print "pwxyz: u m", repr(marker), repr(actor)
        #    self.renderer.RemoveActor(actor)
        #    del self.boxes[marker]
        elif event=="set axes directions":
            self.add_axes_labels()
            EventHandler().notify('observers update plane')
        
        self.Render()
def temperature_actor(x, y, temp, col):
    cube_source = vtk.vtkCubeSource()
    cube_source.SetXLength(30)
    cube_source.SetYLength(30)
    cube_source.SetZLength(1)
    cube_source.SetCenter(x, y - 19, 0)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(cube_source.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(col)
    actor.SetVisibility(True)

    atext = vtk.vtkVectorText()
    atext.SetText("{:.0f}".format(temp).center(4))
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(8, 8, 8)
    textActor.AddPosition(x - 15, y - 23, 1)
    textActor.GetProperty().SetColor(1, 1, 1)
    textActor.SetVisibility(True)

    return actor, textActor
Beispiel #24
0
    def add_picker(self):
        # Create a cell picker.
        picker = vtk.vtkCellPicker()
        # Create a Python function to create the text for the text mapper used
        # to display the results of picking.
        source = vtk.vtkVectorText()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor((0, 0, 0))
        follower.SetScale(0.2)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
        follower.VisibilityOff()

        def annotate_pick(obj, event):
            if picker.GetCellId() < 0:
                follower.VisibilityOff()
            else:
                pick_pos = picker.GetPickPosition()
                mapper = picker.GetMapper()
                if mapper in self.mapper_map:
                    site = self.mapper_map[mapper]
                    output = [
                        site.species_string, "Frac. coords: " + " ".join(
                            ["{:.4f}".format(c) for c in site.frac_coords])
                    ]
                    source.SetText("\n".join(output))
                    follower.SetPosition(pick_pos)
                    follower.VisibilityOn()

        picker.AddObserver("EndPickEvent", annotate_pick)
        self.picker = picker
        self.iren.SetPicker(picker)
    def mark(x, y, z):
        #function for placing a landmark sphere
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(1)
        res = 20
        sphere.SetThetaResolution(res)
        sphere.SetPhiResolution(res)
        sphere.SetCenter(x, y, z)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphere.GetOutputPort())

        marker = vtk.vtkActor()
        marker.SetMapper(mapper)
        renderer.AddActor(marker)
        marker.GetProperty().SetColor((1, 0, 0))

        #annotate the mark
        atext = vtk.vtkVectorText()
        atext.SetText(str(len(landmarks) + 1))
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(3, 3, 3)
        textActor.AddPosition(x, y, z)
        textActor.SetCamera(renderer.GetActiveCamera())
        actortextdict[marker] = textActor
        renderer.AddActor(textActor)

        show_m.iren.Render()
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='add marker':
            marker = args[0]
            self.add_ring_actor(marker)
        elif event=='remove marker':
            marker = args[0]
            self.remove_ring_actor(marker)
        elif event=='move marker':
            # ring actor will update automatically because it shares
            # the sphere source
            marker, pos = args
            textActor = self.textActors[marker]
            textActor.SetPosition(pos)

        elif event=='color marker':
            marker, color = args
            actor = self.get_actor_for_marker(marker)
            actor.update()
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)
        elif event=='observers update plane':
            self.update_plane()
            
        self.update_rings()
        self.Render()
 def label_ring_actor(self, marker, label):
     marker.set_label(label)
     text = vtk.vtkVectorText()
     text.SetText(marker.get_label())
     textMapper = vtk.vtkPolyDataMapper()
     textMapper.SetInput(text.GetOutput())
     textActor = self.textActors[marker.uuid]
     textActor.SetMapper(textMapper)
Beispiel #28
0
 def setup(self):
     self.axes = self.addPart(ObjectBase(vtk.vtkAxes()))
     self.xcone = self.addPart(ObjectBase(vtk.vtkConeSource()))
     self.xcone._actor.SetScale(0.1,0.05,0.05)
     self.xcone._actor.AddPosition(1.0,0.0,0.0)
     self.xcone._actor.GetProperty().SetColor(1.0,0.3,0.3)
     self.ycone = self.addPart(ObjectBase(vtk.vtkConeSource()))
     self.ycone._actor.SetScale(0.1,0.05,0.05)
     self.ycone._actor.RotateZ(90.0)
     self.ycone._actor.AddPosition(0.0,1.0,0.0)
     self.ycone._actor.GetProperty().SetColor(1.0,1.0,0.0)
     self.zcone = self.addPart(ObjectBase(vtk.vtkConeSource()))
     self.zcone._actor.SetScale(0.1,0.05,0.05)
     self.zcone._actor.RotateY(-90.0)
     self.zcone._actor.AddPosition(0.0,0.0,1.0)
     self.zcone._actor.GetProperty().SetColor(0.3,1.0,0.3)
     self.balls = self.addPart(ObjectBase(vtk.vtkSphereSource()))
     self.balls._actor.SetScale(0.05,0.05,0.05)
     self.balls._actor.GetProperty().SetColor(0.3,0.3,1.0)
     self.xtxt = ObjectBase(vtk.vtkVectorText(),
                                         actorType=vtk.vtkFollower)
     self.xtxt._source.SetText('X')
     self.xtxt._actor.SetScale(0.1,0.1,0.1)
     self.xtxt._actor.AddPosition(1.0,0.0,0.0)
     self.xtxt._actor.GetProperty().SetColor(1.0,0.3,0.3)
     self.addPart(self.xtxt)
     self.ytxt = ObjectBase(vtk.vtkVectorText(),
                                         actorType=vtk.vtkFollower)
     self.ytxt._source.SetText('Y')
     self.ytxt._actor.SetScale(0.1,0.1,0.1)
     self.ytxt._actor.AddPosition(0.0,1.0,0.0)
     self.ytxt._actor.GetProperty().SetColor(1.0,1.0,0.0)
     self.addPart(self.ytxt)
     self.ztxt = ObjectBase(vtk.vtkVectorText(),
                                         actorType=vtk.vtkFollower)
     self.ztxt._source.SetText('Z')
     self.ztxt._actor.SetScale(0.1,0.1,0.1)
     self.ztxt._actor.AddPosition(0.0,0.0,1.0)
     self.ztxt._actor.GetProperty().SetColor(0.3,1.0,0.3)
     self.addPart(self.ztxt)
     self.ntxt = ObjectBase(vtk.vtkVectorText(),
                                         actorType=vtk.vtkFollower)
     self.ntxt._source.SetText('0')
     self.ntxt._actor.SetScale(0.1,0.1,0.1)
     self.ntxt._actor.GetProperty().SetColor(0.3,0.3,1.0)
     self.addPart(self.ntxt)
Beispiel #29
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkVectorText(),
                                       'Processing.', (), ('vtkPolyData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
    def add_axes_labels(self):
        labels = shared.labels
        self.axes_labels=labels
        self.axes_labels_actors=[]
        size = abs(self.imageData.GetSpacing()[0]) * 5
        for i,b in enumerate(self.imageData.GetBounds()):
            coords = list(self.imageData.GetCenter())
            coords[i/2] = b*1.12
            idx_label = 1*i #historical reasons for using this
            label = labels[idx_label]
            if shared.debug: print i,b, coords, label
            if self.orientation == 0:
                if label in ["R","L"]:
                    continue
            if self.orientation == 1:
                if label in ["A","P"]:
                    continue
            if self.orientation == 2:
                if label in ["S","I"]:
                    continue

            #Orientation should be correct due to reading affine in vtkNifti
            text = vtk.vtkVectorText()
            text.SetText(label)
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = vtk.vtkFollower()
            textActor.SetMapper(textMapper)
            textActor.SetScale(size, size, size)
            x,y,z = coords
            textActor.SetPosition(x, y, z)
            textActor.GetProperty().SetColor(*self.axes_labels_color)
            textActor.SetCamera(self.camera)
            self.axes_labels_actors.append(textActor)
            self.renderer.AddActor(textActor)

        #Reorient camera to have head up
        center = self.imageData.GetCenter()
        spacing = self.imageData.GetSpacing()
        bounds = np.array(self.imageData.GetBounds())
        if shared.debug: print "***center,spacing,bounds", center,spacing,bounds
        pos = [center[0], center[1], center[2]]
        camera_up = [0,0,0]
        if self.orientation == 0:
            pos[0] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[2] = 1 
        elif self.orientation == 1:
            pos[1] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[2] = 1
        elif self.orientation == 2:
            pos[2] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[0] = -1
        if shared.debug: print camera_up
        fpu = center, pos, tuple(camera_up)
        if shared.debug: print "***fpu2:", fpu
        self.set_camera(fpu)
        self.scroll_depth(self.sliceIncrement)
Beispiel #31
0
 def add_text(self, message):
     """Appends text to the text list."""
     # Text
     text = vtkVectorText()
     text.SetText(message)
     # Mapper
     text_mapper = vtkPolyDataMapper()
     text_mapper.SetInputConnection(text.GetOutputPort())
     self.text_mappers.append(text_mapper)
Beispiel #32
0
def plot_embedding_3d(X, Y, title=None):

    renderer = vtk.vtkRenderer()
    renderer.GradientBackgroundOn()
    renderer.SetBackground2(0.05, 0.05, 0.05)
    renderer.SetBackground(0.25, 0.25, 0.31)

    x_min, x_max = np.min(X, 0), np.max(X, 0)
    X = (X - x_min) / (x_max - x_min)

    camera = renderer.GetActiveCamera()

    for i, pos in enumerate(X):
        #         print(i, pos)
        text = vtk.vtkVectorText()
        text.SetText('M' if Y[i] > 0 else 'B')
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(text.GetOutputPort())
        actor = vtk.vtkFollower()
        actor.SetMapper(mapper)
        actor.SetScale(0.02, 0.02, 0.02)
        actor.AddPosition(pos)
        actor.SetCamera(camera)
        if Y[i]:
            actor.GetProperty().SetColor(1.0, 0.8, 0.25)
        else:
            actor.GetProperty().SetColor(0.25, 0.75, 0.9)
        renderer.AddActor(actor)

    renderer.ResetCamera()
    renderer.ResetCameraClippingRange()

    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    renwin.SetSize(800, 800)
    renwin.Render()

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(renwin)
    iren.Start()

    #     focal = camera.GetFocalPoint()
    #     pos = camera.GetPosition()

    #     camera.SetFocalPoint(focal)
    #     camera.SetPosition(pos)
    # camera.Azimuth(20);
    # camera.Elevation(40);
    # # renderer.SetActiveCamera(camera)
    # camera.Roll(50);

    # renderer.ResetCamera()
    # renderer.ResetCameraClippingRange()

    return renderer
Beispiel #33
0
 def BuildLabelActor(self, text, op_dict):
     label = vtk.vtkVectorText()
     label.SetText(text)
     labelTransform = self.TransformLabel(label, op_dict)
     labelTransformFilter = self.TransformLabelFilter(label, labelTransform)
     labelMapper = vtk.vtkPolyDataMapper()
     labelMapper.SetInput(labelTransformFilter.GetOutput())
     actor = vtk.vtkFollower()
     actor.SetMapper(labelMapper)
     return actor
def setup_pipeline_objs(colors, robot_id, points=False):
    """
    Internal function to initialise vtk objects.
    :return: reader_list, actor_list, mapper_list
    """

    if points:
        sphereSource = vtk.vtkSphereSource()
        sphereSource.SetCenter(0, 0, 0)
        sphereSource.SetRadius(0.3)

        # Create a mapper and actor
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphereSource.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(uniform(0.0, 1.0), uniform(0.0, 1.0), uniform(0.0, 1.0))

        text = vtk.vtkVectorText()
        text.SetText(robot_id)
        text_mapper = vtk.vtkPolyDataMapper()
        text_mapper.SetInputConnection(text.GetOutputPort())
        text_actor = vtk.vtkActor()
        text_actor.SetMapper(text_mapper)
        text_actor.GetProperty().SetColor(uniform(0.0, 1.0), uniform(0.0, 1.0), uniform(0.0, 1.0))
        text_actor.AddPosition(0, 0, 1)
        text_actor.RotateX(60)
        text_actor.SetScale(0.5)

        assembly = vtk.vtkAssembly()
        assembly.AddPart(actor)
        assembly.AddPart(text_actor)


        return [], [assembly], []
    stl_files = setup_file_names(4)
    print("STL FILES: {}".format(stl_files))
    reader_list = [0] * len(stl_files)
    actor_list = [0] * len(stl_files)
    # print("Actor List: {}".format(actor_list))

    mapper_list = [0] * len(stl_files)
    for i in range(len(stl_files)):
        reader_list[i] = vtk.vtkSTLReader()
        loc = pkg_resources.resource_filename("components", '/'.join(('simulator','media', stl_files[i])))
        # print(loc)
        reader_list[i].SetFileName(loc)
        mapper_list[i] = vtk.vtkPolyDataMapper()
        mapper_list[i].SetInputConnection(reader_list[i].GetOutputPort())
        actor_list[i] = vtk.vtkActor()
        actor_list[i].SetMapper(mapper_list[i])
        actor_list[i].GetProperty().SetColor(colors[i])  # (R,G,B)
        actor_list[i].SetScale(0.013)

    return reader_list, actor_list, mapper_list
Beispiel #35
0
def main():
    colors = vtk.vtkNamedColors()

    # Create the axes and the associated mapper and actor.
    axes = vtk.vtkAxes()
    axes.SetOrigin(0, 0, 0)
    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axes.GetOutputPort())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Create the 3D text and the associated mapper and follower (a type of actor).  Position the text so it is displayed over the origin of the axes.
    atext = vtk.vtkVectorText()
    atext.SetText('Origin')
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(0.2, 0.2, 0.2)
    textActor.AddPosition(0, -0.1, 0)
    textActor.GetProperty().SetColor(colors.GetColor3d('Peacock'))

    # Create the Renderer, RenderWindow, and RenderWindowInteractor.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(640, 480)

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

    style = vtk.vtkInteractorStyleTrackballCamera()
    interactor.SetInteractorStyle(style)

    # Add the actors to the renderer.
    renderer.AddActor(axesActor)
    renderer.AddActor(textActor)

    renderer.SetBackground(colors.GetColor3d('Silver'))

    # Zoom in closer.
    renderer.ResetCamera()
    renderer.GetActiveCamera().Zoom(1.6)

    renderer.SetBackground(colors.GetColor3d('Silver'))

    # Reset the clipping range of the camera; set the camera of the follower; render.
    renderer.ResetCameraClippingRange()
    textActor.SetCamera(renderer.GetActiveCamera())

    interactor.Initialize()
    renderWindow.SetWindowName('TextOrigin')
    renderWindow.Render()
    interactor.Start()
Beispiel #36
0
 def __init__(self, **kwargs):
     text = vtk.vtkVectorText()
     text.SetText("Hello")
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(text.GetOutputPort())
     actor = vtk.vtkActor()
     actor.SetMapper(mapper)
     actor.SetScale(0.02)
     actor.RotateY(180.0)
     self.actor = actor
     self.mapper = mappe
Beispiel #37
0
def generateAxes(printer):
    xmax, ymax, zmax = printer.getPrintingDimensions()
    axes = vtk.vtkAxes()
    axes.SetOrigin(-xmax/2, -ymax/2, 0)
    axes.SetScaleFactor(20)
    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(2)
    axesTubes.SetNumberOfSides(4)
    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)
    XText = vtk.vtkVectorText()
    XText.SetText('X')
    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())
    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(5, 5, 5)
    XActor.SetPosition(-xmax/2 + 20, -ymax/2 - 10, 5)
    XActor.GetProperty().SetColor(1, 0, 0)
    YText = vtk.vtkVectorText()
    YText.SetText('Y')
    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())
    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(5, 5, 5)
    YActor.SetPosition(-xmax/2 - 5, -ymax/2 + 20, 5)
    YActor.GetProperty().SetColor(1, 1, 0)
    ZText = vtk.vtkVectorText()
    ZText.SetText('Z')
    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())
    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(5, 5, 5)
    ZActor.SetPosition(-xmax/2, -ymax/2, 25)
    ZActor.GetProperty().SetColor(0, 1, 0)
    return axesActor, XActor, YActor, ZActor
Beispiel #38
0
def getAxes(Origin, scale=1):
    axes = vtk.vtkAxes()
    axes.SetOrigin(*Origin)
    axes.SetScaleFactor(scale)

    axesTubes = vtk.vtkTubeFilter()

    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(0.01)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    XText = vtk.vtkVectorText()
    XText.SetText("x")

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(.1, .1, .1)
    XActor.SetPosition(1, Origin[1], Origin[2])
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText("y")

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(.1, .1, .1)
    YActor.SetPosition(Origin[0], 1, Origin[2])
    YActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor
Beispiel #39
0
def getAxes(Origin, scale = 1):
    axes = vtk.vtkAxes()
    axes.SetOrigin(*Origin)
    axes.SetScaleFactor(scale)

    axesTubes = vtk.vtkTubeFilter()

    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(0.01)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    XText = vtk.vtkVectorText()
    XText.SetText("x")

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(.1, .1, .1)
    XActor.SetPosition(1, Origin[1], Origin[2])
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText("y")

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(.1, .1, .1)
    YActor.SetPosition(Origin[0], 1, Origin[2])
    YActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor
Beispiel #40
0
 def add_text(self, coords, text, color = (0,0,0)):
     source = vtk.vtkVectorText()
     source.SetText(text)
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(source.GetOutputPort())
     follower = vtk.vtkFollower()
     follower.SetMapper(mapper)
     follower.GetProperty().SetColor(color)
     follower.SetPosition(coords)
     follower.SetScale(0.5)
     self.ren.AddActor(follower)
     follower.SetCamera(self.ren.GetActiveCamera())
Beispiel #41
0
 def get_axis_label_actor(self, text, position, ren):
     atext = vtk.vtkVectorText()
     atext.SetText(text)
     textMapper = vtk.vtkPolyDataMapper()
     textMapper.SetInputConnection(atext.GetOutputPort())
     textActor = vtk.vtkFollower()
     textActor.SetMapper(textMapper)
     textActor.SetScale(20, 20, 20)
     textActor.AddPosition(position[0], position[1], position[2])
     textActor.GetProperty().SetColor(0, 0, 0)
     textActor.SetCamera(ren.GetActiveCamera())
     return textActor
Beispiel #42
0
def makeTextActor(text,size,pos):
    at = vtk.vtkVectorText()
    at.SetText(text)
    tMap = vtk.vtkPolyDataMapper()
    tMap.SetInputConnection(at.GetOutputPort())
    tAct = vtk.vtkFollower()
    tAct.SetMapper(tMap)
    tAct.GetProperty().SetColor(0,0,0)
    tAct.SetScale(size)
    tAct.SetPosition(pos)
    tAct.PickableOff()
    return tAct
Beispiel #43
0
 def setup(self):
     #self.textSrc = vtk.vtkTextSource()
     self.textSrc = vtk.vtkVectorText()
     self.textSrc.SetText('SMILE')
     #self.textSrc.BackingOff()
     self.extruder = vtk.vtkLinearExtrusionFilter()
     self.extruder.SetInput(self.textSrc.GetOutput())
     self.extruder.SetVector(0,0,0.4)
     self.normals = vtk.vtkPolyDataNormals()
     self.normals.SplittingOff()
     self.normals.SetInput(self.extruder.GetOutput())
     self.setSource(self.normals)
     self._actor.GetProperty().SetAmbient(0.8)
Beispiel #44
0
    def __init__(self, text='None'):

        self.source = vtk.vtkVectorText()
        self.source.SetText(text)
        self.source.Update()

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.source.GetOutputPort())

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

        return
Beispiel #45
0
 def addVertex(self,index):
     coord=self.vertices[index]
     self.vActors[index]=self.addPoint(coord)
     text=vtk.vtkVectorText()
     text.SetText(str(index))
     tMapper=vtk.vtkPolyDataMapper()
     tMapper.SetInput(text.GetOutput())
     tActor = vtk.vtkFollower()
     tActor.SetMapper(tMapper)
     tActor.SetScale(2*self.vRadius,2*self.vRadius,2*self.vRadius)
     tActor.AddPosition(coord[0]+self.vRadius,coord[1]+self.vRadius,coord[2]+self.vRadius)
     tActor.SetCamera(self.cam)
     tActor.GetProperty().SetColor(1.0,0.,0.)
     self.ren.AddActor(tActor)
Beispiel #46
0
def Text3D(string, depth=0.5):
    """ Create 3D text from a string"""
    vec_text = vtk.vtkVectorText()
    vec_text.SetText(string)

    extrude = vtk.vtkLinearExtrusionFilter()
    extrude.SetInputConnection(vec_text.GetOutputPort())
    extrude.SetExtrusionTypeToNormalExtrusion()
    extrude.SetVector(0, 0, 1)
    extrude.SetScaleFactor(depth)

    tri_filter = vtk.vtkTriangleFilter()
    tri_filter.SetInputConnection(extrude.GetOutputPort())
    tri_filter.Update()
    return pyvista.wrap(tri_filter.GetOutput())
Beispiel #47
0
def add_text(_renderer, position, text="TEXT", color=[0.5, 0.5, 0.5], scale=0.1):
    # Create text with the x-y-z coordinate system
    _text = vtk.vtkVectorText()
    _text.SetText(text)
    mapper_text = vtk.vtkPolyDataMapper()
    mapper_text.SetInputConnection(_text.GetOutputPort())
    # actor_text_origin = vtk.vtkActor()
    actor_text = vtk.vtkFollower()
    # actor_text.SetCamera(_renderer.GetActiveCamera())
    actor_text.SetMapper(mapper_text)
    actor_text.SetScale(scale, scale, scale)
    actor_text.GetProperty().SetColor(color)
    actor_text.AddPosition([sum(x) for x in zip(position, [0, -0.1, 0])])  # plus of 2 arrays

    _renderer.AddActor(actor_text)
def CreateTextItem(text, scale, camera, color=None):
    textSource = vtkVectorText()
    textSource.SetText(text)

    textMapper = vtkPolyDataMapper()
    textMapper.SetInputConnection(textSource.GetOutputPort())

    textFollower = vtkFollower()
    textFollower.SetMapper(textMapper)
    textFollower.SetCamera(camera)
    textFollower.SetScale(scale)

    # Give the actor a custom color
    ColorActor(textFollower, color)

    return textFollower
def CreateTextItem(text, scale, camera, color=None):
	textSource = vtkVectorText()
	textSource.SetText(text)

	textMapper = vtkPolyDataMapper()
	textMapper.SetInputConnection(textSource.GetOutputPort())

	textFollower = vtkFollower()
	textFollower.SetMapper(textMapper)
	textFollower.SetCamera(camera)
	textFollower.SetScale(scale)

	# Give the actor a custom color
	ColorActor(textFollower, color)

	return textFollower
Beispiel #50
0
def label(text='Origin',
          pos=(0, 0, 0),
          scale=(0.2, 0.2, 0.2),
          color=(1, 1, 1)):
    """Create a label actor.

    This actor will always face the camera

    Parameters
    ----------
    text : str
        Text for the label.
    pos : (3,) array_like, optional
        Left down position of the label.
    scale : (3,) array_like
        Changes the size of the label.
    color : (3,) array_like
        Label color as ``(r,g,b)`` tuple.

    Returns
    -------
    l : vtkActor object
        Label.

    Examples
    --------
    >>> from fury import window, actor
    >>> scene = window.Scene()
    >>> l = actor.label(text='Hello')
    >>> scene.add(l)
    >>> #window.show(scene)

    """
    atext = vtk.vtkVectorText()
    atext.SetText(text)

    textm = vtk.vtkPolyDataMapper()
    textm.SetInputConnection(atext.GetOutputPort())

    texta = vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)

    texta.GetProperty().SetColor(color)
    texta.SetPosition(pos)

    return texta
    def add_axes_labels(self):
        #if shared.debug: print "***Adding axes labels"
        #if shared.debug: print labels
        labels = shared.labels
        #labels = list(np.array(labels)[[4,5,2,3,0,1]])
        self.axes_labels=labels
        self.axes_labels_actors=[]
        size = abs(self.imageData.GetSpacing()[0]) * 5
        #if shared.debug: print "***size", size
        for i,b in enumerate(self.imageData.GetBounds()):
            coords = list(self.imageData.GetCenter())
            coords[i/2] = b*1.1
            #Correction for negative spacings
            idx_label = 1*i
            label = labels[idx_label]
            if shared.debug: print i,b, coords, label
            #Orientation should be correct due to reading affine in vtkNifti
            text = vtk.vtkVectorText()
            text.SetText(label)
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = vtk.vtkFollower()
            textActor.SetMapper(textMapper)
            textActor.SetScale(size, size, size)
            x,y,z = coords
            textActor.SetPosition(x, y, z)
            textActor.GetProperty().SetColor(*self.axes_labels_color)
            textActor.SetCamera(self.camera)
            self.axes_labels_actors.append(textActor)
            self.renderer.AddActor(textActor)

        #Reorient camera to have head up
        center = self.imageData.GetCenter()
        spacing = self.imageData.GetSpacing()
        bounds = np.array(self.imageData.GetBounds())
        if shared.debug: print "***center,spacing,bounds", center,spacing,bounds
        #idx_left = labels.index("L")
        pos = [center[0], center[1], center[2]]
        pos[0] +=  max((bounds[1::2]-bounds[0::2]))*2
        #idx_sup = labels.index("S")
        camera_up = [0,0,0]
        camera_up[2] = 1
        if shared.debug: print camera_up
        fpu = center, pos, tuple(camera_up)
        if shared.debug: print "***fpu2:", fpu
        self.set_camera(fpu)
 def vtk_label_iod(receptor_dirs, triangles, renderers):
     dists = get_mean_interommatidial_distance(receptor_dirs, triangles)
     pi = 3.1415926535897931
     R2D = 180.0 / pi
     for v, dist in zip(receptor_dirs, dists):
         atext = vtk.vtkVectorText()
         atext.SetText("%.1f" % (dist * R2D, ))
         textMapper = vtk.vtkPolyDataMapper()
         textMapper.SetInputConnection(atext.GetOutputPort())
         textActor = vtk.vtkFollower()
         textActor.SetMapper(textMapper)
         scale = 0.03
         textActor.SetScale(scale, scale, scale)
         mult = 1.02
         textActor.AddPosition(v.x * mult, v.y * mult, v.z * mult)
         for renderer in renderers:
             renderer.AddActor(textActor)
 def vtk_label_iod( receptor_dirs, triangles, renderers ):
     dists = get_mean_interommatidial_distance( receptor_dirs, triangles )
     pi = 3.1415926535897931
     R2D = 180.0/pi
     for v,dist in zip(receptor_dirs,dists):
         atext = vtk.vtkVectorText()
         atext.SetText("%.1f"%(dist*R2D,))
         textMapper = vtk.vtkPolyDataMapper()
         textMapper.SetInput(atext.GetOutput())
         textActor = vtk.vtkFollower()
         textActor.SetMapper(textMapper)
         scale = 0.03
         textActor.SetScale(scale, scale, scale)
         mult = 1.02
         textActor.AddPosition(v.x*mult,v.y*mult,v.z*mult)
         for renderer in renderers:
             renderer.AddActor( textActor )
Beispiel #54
0
def addlabel(ren,text='Origin',pos=(0,0,0),scale=(0.1,0.1,0.1)):
    
    atext=vtk.vtkVectorText()
    atext.SetText(text)
    
    textm=vtk.vtkPolyDataMapper()
    textm.SetInput(atext.GetOutput())
    
    texta=vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)    
    texta.SetPosition(pos)
    
    ren.AddActor(texta)
    
    texta.SetCamera(ren.GetActiveCamera())
    
    return texta
Beispiel #55
0
    def __init__(self, text="test", color=cyan, center=(0, 0, 0), scale=1):
        self.textSource = vtk.vtkVectorText()
        self.textSource.SetText(text)
        self.scale = scale

        self.transform = vtk.vtkTransform()

        self.transform.Translate(center[0], center[1], center[2])
        self.transform.Scale(self.scale, self.scale, self.scale)
        self.transformFilter = vtk.vtkTransformPolyDataFilter()
        self.transformFilter.SetTransform(self.transform)
        self.transformFilter.SetInputConnection(self.textSource.GetOutputPort())
        self.transformFilter.Update()

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.transformFilter.GetOutputPort())
        self.SetMapper(self.mapper)
        self.SetColor(color)
Beispiel #56
0
def drawText(featurePoints, featureText):
    textActorList = []

    #print(len(featureText))
    #print(featurePoints)
    #print(len(featurePoints))
    for i in range(len(featurePoints)):
        atext = vtk.vtkVectorText()
        atext.SetText(featureText[i])
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(0.05, 0.05, 0.05)
        textActor.AddPosition(featurePoints[i])
        textActorList.append(textActor)
    return textActorList
Beispiel #57
0
    def __init__(self,text="test",color=cyan,center=(0,0,0),scale=1):
        self.textSource = vtk.vtkVectorText()
        self.textSource.SetText( text )
        self.scale = scale

        self.transform = vtk.vtkTransform()
        
        self.transform.Translate(center[0], center[1], center[2] )
        self.transform.Scale(self.scale, self.scale, self.scale)
        self.transformFilter=vtk.vtkTransformPolyDataFilter()
        self.transformFilter.SetTransform(self.transform)
        self.transformFilter.SetInputConnection(self.textSource.GetOutputPort())
        self.transformFilter.Update()
        
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection( self.transformFilter.GetOutputPort() )
        self.SetMapper(self.mapper)
        self.SetColor(color)
Beispiel #58
0
    def init_draw(self, center, radius, ren, **kwargs):
        # Convert color to rgb.
        my_color = kwargs.get('color', 'b')
        label = kwargs.get('label', '')
        rgb_color = 255 * colorConverter.to_rgba(my_color)

        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(radius)
        sphere.SetThetaResolution(20)
        sphere.SetPhiResolution(40)

        sphere_mapper = vtk.vtkPolyDataMapper()
        sphere_mapper.SetInputConnection(sphere.GetOutputPort())

        sphere_actor = vtk.vtkActor()
        sphere_actor.SetMapper(sphere_mapper)
        sphere_actor.GetProperty().SetColor(rgb_color[0], 
                                            rgb_color[1], 
                                            rgb_color[2])

        transform = vtk.vtkTransform()
        transform.Translate(center[0], center[1], center[2])
        sphere_actor.SetUserMatrix(transform.GetMatrix())

        ren.AddActor(sphere_actor)
        self.actor = sphere_actor
  
        # Add label to the figure
        text_source = vtk.vtkVectorText()
        text_source.SetText(label)
        text_source.Update()
        text_mapper = vtk.vtkPolyDataMapper()
        text_mapper.SetInputConnection(text_source.GetOutputPort())         
        text_actor1 = vtk.vtkActor()
        text_actor1.SetMapper(text_mapper)
        text_actor1.GetProperty().SetColor(rgb_color[0], 
                                           rgb_color[1], 
                                           rgb_color[2])
        text_actor1.SetScale(0.05)
        center1 = text_actor1.GetCenter()
        text_actor1.RotateX(90)
        text_actor1.AddPosition(center)
        text_actor1.AddPosition([0., 0., radius + 0.1])
        ren.AddActor(text_actor1)
Beispiel #59
0
Datei: fos.py Projekt: arokem/Fos
def label(ren,text='Origin',pos=(0,0,0),scale=(0.2,0.2,0.2),color=(1,1,1)):
    
    ''' Create a label actor 
    This actor will always face the camera
    
    Parameters
    ----------
    ren : vtkRenderer() object as returned from ren()
    text : a text for the label
    pos : left down position of the label
    scale : change the size of the label 
    color : (r,g,b) and RGB tuple
    
    Returns
    ----------
    vtkActor object
    
    Examples
    --------  
    >>> from dipy.viz import fos  
    >>> r=fos.ren()    
    >>> l=fos.label(r)
    >>> fos.add(r,l)
    >>> fos.show(r)
    '''
    atext=vtk.vtkVectorText()
    atext.SetText(text)
    
    textm=vtk.vtkPolyDataMapper()
    textm.SetInput(atext.GetOutput())
    
    texta=vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)    

    texta.GetProperty().SetColor(color)
    texta.SetPosition(pos)
    
    ren.AddActor(texta)
    texta.SetCamera(ren.GetActiveCamera())
        
    return texta
Beispiel #60
0
    def add_text(self, coords, text, color=(0, 0, 0)):
        """
        Add text at a coordinate.

        Args:
            coords: Coordinates to add text at.
            text: Text to place.
            color: Color for text as RGB. Defaults to black.
        """
        source = vtk.vtkVectorText()
        source.SetText(text)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor(color)
        follower.SetPosition(coords)
        follower.SetScale(0.5)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())