示例#1
0
    def __init__(self, **kwargs):
        text_rep = vtk.vtkTextRepresentation()
        text_rep.GetPositionCoordinate().SetValue(0.01, 0.02)
        text_rep.GetPosition2Coordinate().SetValue(.3, .96)

        text_widget = vtk.vtkTextWidget()

        text_widget.SetRepresentation(text_rep)

        text_actor = text_widget.GetTextActor()
        text_actor.SetTextScaleModeToNone()
        text_actor.UseBorderAlignOn()
        text_actor.SetMaximumLineHeight(0.03)

        text_prop = text_rep.GetTextActor().GetTextProperty()
        text_prop.SetColor(0., 0, 0)
        text_prop.SetFontSize(12)
        text_prop.SetJustificationToLeft()
        text_prop.SetVerticalJustificationToTop()

        self.text_widget = text_widget
        self.text_rep = text_rep
        self.text_prop = text_prop

        self._process_kwargs(**kwargs)
示例#2
0
    def __init__(self, **kwargs):
        text_rep = vtk.vtkTextRepresentation();
        text_rep.GetPositionCoordinate().SetValue(0.01, 0.02)
        text_rep.GetPosition2Coordinate().SetValue(.3, .96)

        text_widget = vtk.vtkTextWidget()

        text_widget.SetRepresentation(text_rep)

        text_actor = text_widget.GetTextActor()
        text_actor.SetTextScaleModeToNone()
        text_actor.UseBorderAlignOn()
        text_actor.SetMaximumLineHeight(0.03)

        text_prop = text_rep.GetTextActor().GetTextProperty()
        text_prop.SetColor(0., 0, 0)
        text_prop.SetFontSize(12)
        text_prop.SetJustificationToLeft()
        text_prop.SetVerticalJustificationToTop()

        self.text_widget = text_widget
        self.text_rep = text_rep
        self.text_prop = text_prop

        self._process_kwargs(**kwargs)
示例#3
0
 def do_test(self):
     vw = vtk.vtkTextWidget()
     vr = vtk.vtkTextRepresentation()
     vw.SetRepresentation(vr)
     w = vcs.vtk_ui.widget.Widget(self.inter, vw)
     assert w.repr == vr, "Representation improperly set"
     assert w.interactor == self.inter, "Interactor improperly set"
     assert w.manager == vcs.vtk_ui.manager.get_manager(self.inter), "Manager improperly set"
     assert w in w.manager.widgets, "Widget improperly registered"
     self.passed = 0
示例#4
0
文件: text.py 项目: UNESCO-IHE/uvcdat
    def __init__(self,
                 interactor,
                 string,
                 movable=False,
                 on_move=None,
                 on_drag=None,
                 on_click=None,
                 on_release=None,
                 fgcolor=(1, 1, 1),
                 size=24,
                 font="Arial",
                 left=0,
                 top=0,
                 textproperty=None):
        widget = vtkTextWidget()

        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.SetTextActor(self.actor)

        super(Label, self).__init__(interactor, widget)

        #self.widget.ResizableOff()
        self.movable = movable
        self.action = on_click
        self.release_action = on_release
        self.move_action = on_move
        self.dragged = on_drag

        self.left, self.top = left, top
        self.top_offset = 0

        # Assigned by Widget.__init__
        self.repr.MovingOff()
        self.repr.PickableOff()
        self.repr.SetShowBorderToOff()

        self.actor.SetTextScaleModeToNone()

        # Map events to draggable actions, because standard events aren't propagated
        self.add_event_handler("StartInteractionEvent", self.drag_clicked)
        self.add_event_handler("InteractionEvent", self.drag_moved)
        self.add_event_handler("EndInteractionEvent", self.drag_released)
        self.add_event_handler("StartInteractionEvent", self.click)
        self.add_event_handler("EndInteractionEvent", self.release)

        self.register()
示例#5
0
def main():
    colors = vtk.vtkNamedColors()

    # colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0])

    source = vtk.vtkSphereSource()

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

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

    renderer = vtk.vtkRenderer()
    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(renderer)

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

    # Create the TextActor
    text_actor = vtk.vtkTextActor()
    text_actor.SetInput('This is a test')
    text_actor.GetTextProperty().SetColor(colors.GetColor3d('Lime'))

    # Create the text representation. Used for positioning the text_actor
    text_representation = vtk.vtkTextRepresentation()
    text_representation.GetPositionCoordinate().SetValue(0.15, 0.15)
    text_representation.GetPosition2Coordinate().SetValue(0.7, 0.2)

    # Create the TextWidget
    # Note that the SelectableOff method MUST be invoked!
    # According to the documentation :
    #
    # SelectableOn/Off indicates whether the interior region of the widget can be
    # selected or not. If not, then events (such as left mouse down) allow the user
    # to 'move' the widget, and no selection is possible. Otherwise the
    # SelectRegion() method is invoked.
    text_widget = vtk.vtkTextWidget()
    text_widget.SetRepresentation(text_representation)

    text_widget.SetInteractor(interactor)
    text_widget.SetTextActor(text_actor)
    text_widget.SelectableOff()

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('MidnightBLue'))
    render_window.SetSize(300, 300)
    render_window.SetWindowName('TextWidget')

    interactor.Initialize()
    render_window.Render()
    text_widget.On()
    interactor.Start()
示例#6
0
 def do_test(self):
     vw = vtk.vtkTextWidget()
     vr = vtk.vtkTextRepresentation()
     vw.SetRepresentation(vr)
     w = vcs.vtk_ui.widget.Widget(self.inter, vw)
     assert w.repr == vr, "Representation improperly set"
     assert w.interactor == self.inter, "Interactor improperly set"
     assert w.manager == vcs.vtk_ui.manager.get_manager(
         self.inter), "Manager improperly set"
     assert w in w.manager.widgets, "Widget improperly registered"
     self.passed = 0
示例#7
0
    def testTextWidget(self):

        # Create fake data
        #
        ss = vtk.vtkSphereSource()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(ss.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)

        ren.AddActor(actor)
        ren.SetBackground(0.1, 0.2, 0.4)
        renWin.SetSize(300, 300)

        iRen.Initialize()
        renWin.Render()

        widget = vtk.vtkTextWidget()
        widget.SetInteractor(iRen)
        widget.On()
        widget.GetTextActor().SetInput("This is a test")
        widget.GetTextActor().GetTextProperty().SetColor(0, 1, 0)
        widget.GetRepresentation().GetPositionCoordinate().SetValue(.15, .15)
        widget.GetRepresentation().GetPosition2Coordinate().SetValue(.7, .2)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(actor)
        ren.SetBackground(.1, .2, .4)

        iRen.Initialize()
        renWin.Render()

        # render and interact with data

        renWin.Render()

        img_file = "TestTextWidget.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
示例#8
0
    def testTextWidget(self):

        # Create fake data
        #
        ss = vtk.vtkSphereSource()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(ss.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)

        ren.AddActor(actor)
        ren.SetBackground(0.1, 0.2, 0.4)
        renWin.SetSize(300, 300)

        iRen.Initialize()
        renWin.Render()

        widget = vtk.vtkTextWidget()
        widget.SetInteractor(iRen)
        widget.On()
        widget.GetTextActor().SetInput("This is a test")
        widget.GetTextActor().GetTextProperty().SetColor(0, 1, 0)
        widget.GetRepresentation().GetPositionCoordinate().SetValue(.15, .15)
        widget.GetRepresentation().GetPosition2Coordinate().SetValue(.7, .2)


        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(actor)
        ren.SetBackground(.1, .2, .4)

        iRen.Initialize()
        renWin.Render()

        # render and interact with data

        renWin.Render()


        img_file = "TestTextWidget.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
示例#9
0
    def draw(self):
        self._renderWindowInteractor.Initialize()
        self._renderWindowInteractor.SetInteractorStyle(self._interactorStyle)

        axes = vtk.vtkAxesActor()
        widget = vtk.vtkOrientationMarkerWidget()
        widget.SetOutlineColor(0.9300, 0.5700, 0.1300)
        widget.SetOrientationMarker(axes)
        widget.SetInteractor(self._renderWindowInteractor)
        #widget.SetViewport(0.0, 0.0, 0.1, 0.1)
        widget.SetViewport(0.0, 0.0, 0.2, 0.4)
        widget.SetEnabled(True)
        widget.InteractiveOn()

        textWidget = vtk.vtkTextWidget()

        textRepresentation = vtk.vtkTextRepresentation()
        textRepresentation.GetPositionCoordinate().SetValue(.0, .0)
        textRepresentation.GetPosition2Coordinate().SetValue(.3, .04)
        textWidget.SetRepresentation(textRepresentation)

        textWidget.SetInteractor(self._renderWindowInteractor)
        textWidget.SetTextActor(self._textActor)
        textWidget.SelectableOff()
        textWidget.On()

        self._rendererScene.ResetCamera()
        camPos = self._rendererScene.GetActiveCamera().GetPosition()
        self._rendererScene.GetActiveCamera().SetPosition(
            (camPos[2], camPos[1], camPos[0]))
        self._rendererScene.GetActiveCamera().SetViewUp((0.0, 0.0, 1.0))
        self._rendererScene.GetActiveCamera().Zoom(1.4)

        self._renderWindowScene.Render()

        if self._addedBSpline:
            self._contextViewPlotCurv.GetRenderWindow().SetMultiSamples(0)
            self._contextViewPlotCurv.GetInteractor().Initialize()
            self._contextViewPlotCurv.GetInteractor().SetInteractorStyle(
                self._contextInteractorStyleCurv)
            #self._contextViewPlotCurv.GetInteractor().Start()

            self._contextViewPlotTors.GetRenderWindow().SetMultiSamples(0)
            self._contextViewPlotTors.GetInteractor().Initialize()
            self._contextViewPlotTors.GetInteractor().SetInteractorStyle(
                self._contextInteractorStyleTors)
            self._contextViewPlotTors.GetInteractor().Start()
        else:
            self._renderWindowInteractor.Start()
示例#10
0
def points_render(points, dirpath=None, vertice_number=None):
    colors = vtk.vtkNamedColors()
    points_actor = create_points_actor(points)

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

    if dirpath is not None and vertice_number is not None:
        # Create the widget
        textActor = vtk.vtkTextActor()
        textActor.SetInput("KeyPress 'F5' to Refresh")
        textActor.GetTextProperty().SetColor(0.0, 1.0, 0.0)
        textWidget = vtk.vtkTextWidget()

        textRepresentation = vtk.vtkTextRepresentation()
        textRepresentation.GetPositionCoordinate().SetValue(.05, .05)
        textRepresentation.GetPosition2Coordinate().SetValue(.1, .1)
        textWidget.SetRepresentation(textRepresentation)
        textWidget.SetInteractor(renderWindowInteractor)
        textWidget.SetTextActor(textActor)
        textWidget.SelectableOff()
        textWidget.EnabledOn()

        # callback = UpdateObserver(points, dirpath, renderer)
        # renderWindowInteractor.AddObserver('KeyPressEvent', callback)

        style = KeyPressInteractorStyle(points, dirpath,
                                        renderWindowInteractor, vertice_number,
                                        points_actor)
        renderWindowInteractor.SetInteractorStyle(style)

    # Add the actor to the scene
    renderer.AddActor(points_actor)

    renderer.SetBackground(
        colors.GetColor3d("Green"))  # Background color green

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Initialize()
    renderWindowInteractor.CreateRepeatingTimer(5000)
    renderWindowInteractor.Start()
示例#11
0
    def draw(self):
        self._renderWindowInteractor.Initialize()
        self._renderWindowInteractor.SetInteractorStyle(self._interactorStyle)

        axes = vtk.vtkAxesActor()
        widget = vtk.vtkOrientationMarkerWidget()
        widget.SetOutlineColor(0.9300, 0.5700, 0.1300)
        widget.SetOrientationMarker(axes)
        widget.SetInteractor(self._renderWindowInteractor)
        #widget.SetViewport(0.0, 0.0, 0.1, 0.1)
        widget.SetViewport(0.0, 0.0, 0.2, 0.4)
        widget.SetEnabled(True)
        widget.InteractiveOn()

        textWidget = vtk.vtkTextWidget()
 
        textRepresentation = vtk.vtkTextRepresentation()
        textRepresentation.GetPositionCoordinate().SetValue(.0,.0 )
        textRepresentation.GetPosition2Coordinate().SetValue(.3,.04 )
        textWidget.SetRepresentation(textRepresentation)
 
        textWidget.SetInteractor(self._renderWindowInteractor)
        textWidget.SetTextActor(self._textActor)
        textWidget.SelectableOff()
        textWidget.On()

        self._rendererScene.ResetCamera()
        camPos = self._rendererScene.GetActiveCamera().GetPosition()
        self._rendererScene.GetActiveCamera().SetPosition((camPos[2],camPos[1],camPos[0]))
        self._rendererScene.GetActiveCamera().SetViewUp((0.0,0.0,1.0))
        self._rendererScene.GetActiveCamera().Zoom(1.4)

        self._renderWindowScene.Render()

        if self._addedBSpline:
            self._contextViewPlotCurv.GetRenderWindow().SetMultiSamples(0)
            self._contextViewPlotCurv.GetInteractor().Initialize()
            self._contextViewPlotCurv.GetInteractor().SetInteractorStyle(self._contextInteractorStyleCurv)
            #self._contextViewPlotCurv.GetInteractor().Start()

            self._contextViewPlotTors.GetRenderWindow().SetMultiSamples(0)
            self._contextViewPlotTors.GetInteractor().Initialize()
            self._contextViewPlotTors.GetInteractor().SetInteractorStyle(self._contextInteractorStyleTors)
            self._contextViewPlotTors.GetInteractor().Start()
        else:
            self._renderWindowInteractor.Start()
示例#12
0
def main():
    # Map actor
    print("Genarate map actor...")
    map_actor = generate_map()

    # Actor plane
    print("Genarate plane actor...")
    plane_actor = generate_plane_path()

    # Text actor
    text_actor = vtk.vtkTextActor()
    text_actor.GetTextProperty().SetColor(1, 1, 1)
    text_actor.SetInput("0 m")

    # Render
    print('Setting the renderer')
    renderer = vtk.vtkRenderer()
    renderer.AddActor(map_actor)
    renderer.AddActor(plane_actor)
    renderer.AddActor(text_actor)
    renderer.SetBackground(0, 0, 0)

    # My interactor
    print('Setting my interactor')
    style = MyInteractor(map_actor, text_actor)
    style.SetDefaultRenderer(renderer)

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    renWin.SetSize(WINDOW_WIDTH_SIZE, WINDOW_HEIGTH_SIZE)

    print("Finish")

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.SetInteractorStyle(style)

    text_widget = vtk.vtkTextWidget()
    text_widget.SetTextActor(text_actor)
    text_widget.SetInteractor(iren)
    text_widget.SelectableOff()
    text_widget.On()

    iren.Initialize()
    renWin.Render()
    iren.Start()
示例#13
0
def poly_render(points, faces, fresh_time, interval):
    '''
    points:vtkPoints
    faces:array
    '''
    colors = vtk.vtkNamedColors()
    actor = create_points_actor(points)
    # Create the widget
    textActor = vtk.vtkTextActor()
    textActor.SetInput("Refresh: Once every second")
    textActor.GetTextProperty().SetColor(0.0, 1.0, 0.0)
    textWidget = vtk.vtkTextWidget()

    textRepresentation = vtk.vtkTextRepresentation()
    textRepresentation.GetPositionCoordinate().SetValue(.1, .1)
    textRepresentation.GetPosition2Coordinate().SetValue(.1, .1)
    textWidget.SetRepresentation(textRepresentation)

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

    textWidget.SetInteractor(renderWindowInteractor)
    textWidget.SetTextActor(textActor)
    textWidget.SelectableOff()
    textWidget.EnabledOn()

    style = KeyPressInteractorStyle(points, faces, renderWindowInteractor,
                                    actor, interval)
    renderWindowInteractor.SetInteractorStyle(style)

    # Add the actor to the scene
    renderer.AddActor(actor)

    renderer.SetBackground(
        colors.GetColor3d("Green"))  # Background color green

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Initialize()
    renderWindowInteractor.CreateRepeatingTimer(fresh_time)
    renderWindowInteractor.Start()
示例#14
0
def points_render(points, steamfile, vertice_number):
    colors = vtk.vtkNamedColors()
    actor = create_points_actor(points)
    # Create the widget
    textActor = vtk.vtkTextActor()
    textActor.SetInput("Refresh: Once every 5 seconds")
    textActor.GetTextProperty().SetColor(0.0, 1.0, 0.0)
    textWidget = vtk.vtkTextWidget()

    textRepresentation = vtk.vtkTextRepresentation()
    textRepresentation.GetPositionCoordinate().SetValue(.05, .05)
    textRepresentation.GetPosition2Coordinate().SetValue(.1, .1)
    textWidget.SetRepresentation(textRepresentation)

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

    textWidget.SetInteractor(renderWindowInteractor)
    textWidget.SetTextActor(textActor)
    textWidget.SelectableOff()
    textWidget.EnabledOn()

    style = KeyPressInteractorStyle(points, steamfile, renderWindowInteractor,
                                    vertice_number, actor)
    renderWindowInteractor.SetInteractorStyle(style)

    # Add the actor to the scene
    renderer.AddActor(actor)

    renderer.SetBackground(
        colors.GetColor3d("Green"))  # Background color green

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Initialize()
    renderWindowInteractor.CreateRepeatingTimer(5000)
    renderWindowInteractor.Start()
示例#15
0
文件: text.py 项目: UNESCO-IHE/uvcdat
    def __init__(self, interactor, string, movable=False, on_move=None, on_drag=None, on_click=None, on_release=None, fgcolor=(1,1,1), size=24, font="Arial", left=0, top=0, textproperty=None):
        widget = vtkTextWidget()

        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.SetTextActor(self.actor)

        super(Label, self).__init__(interactor, widget)

        #self.widget.ResizableOff()
        self.movable = movable
        self.action = on_click
        self.release_action = on_release
        self.move_action = on_move
        self.dragged = on_drag

        self.left, self.top = left, top
        self.top_offset = 0

        # Assigned by Widget.__init__
        self.repr.MovingOff()
        self.repr.PickableOff()
        self.repr.SetShowBorderToOff()

        self.actor.SetTextScaleModeToNone()

        # Map events to draggable actions, because standard events aren't propagated
        self.add_event_handler("StartInteractionEvent", self.drag_clicked)
        self.add_event_handler("InteractionEvent", self.drag_moved)
        self.add_event_handler("EndInteractionEvent", self.drag_released)
        self.add_event_handler("StartInteractionEvent", self.click)
        self.add_event_handler("EndInteractionEvent", self.release)

        self.register()
示例#16
0
text_representation.GetPositionCoordinate().SetValue(200, 200)
text_representation.GetPosition2Coordinate().SetValue(200, 200)

text_representation.SetShowBorderToOn()

text_actor.GetTextProperty().SetFontSize(0)

# Create the TextWidget
# Note that the SelectableOff method MUST be invoked!
# According to the documentation :
#
# SelectableOn/Off indicates whether the interior region of the widget can be
# selected or not. If not, then events (such as left mouse down) allow the user
# to "move" the widget, and no selection is possible. Otherwise the
# SelectRegion() method is invoked.
text_widget = vtk.vtkTextWidget()
text_widget.SetRepresentation(text_representation)
text_widget.SetInteractor(interactor)
text_widget.SetTextActor(text_actor)
text_widget.SelectableOff()
text_widget.ResizableOff()
text_widget.On()

print(text_widget.GetTextActor())
print(text_actor.GetPositionCoordinate(), text_actor.GetPosition2Coordinate())

interactor.Initialize()
render_window.Render()
interactor.Start()
示例#17
0
 def Add_GenActors(self,iren,renWin,method,lut,ren,window,current_Actors,flag2D):
     import vtk
     # Create the TextActor
     ASDGenActors.time_label = vtk.vtkTextActor()
     ASDGenActors.time_label.SetInput(str('{: 4.2f}'.format(0.00)+' ns'))
     ASDGenActors.time_label.GetTextProperty().SetColor((0, 0, 0))
     # Create the text representation. Used for positioning the text_actor
     ASDGenActors.time_label_rep = vtk.vtkTextRepresentation()
     ASDGenActors.time_label_rep.GetPositionCoordinate().SetValue(0.80, 0.90)
     ASDGenActors.time_label_rep.GetPosition2Coordinate().SetValue(0.10, 0.10)
     ########################################################################
     # Creating the actual widget
     ########################################################################
     ASDGenActors.time_label_widget = vtk.vtkTextWidget()
     ASDGenActors.time_label_widget.SetRepresentation(ASDGenActors.time_label_rep)
     ASDGenActors.time_label_widget.SetInteractor(iren)
     ASDGenActors.time_label_widget.SetTextActor(ASDGenActors.time_label)
     ASDGenActors.time_label_widget.SelectableOff()
     ASDGenActors.time_label_widget.Off()
     ########################################################################
     # Creation of the data structures for the data clipping
     ########################################################################
     # Right now this only can clip polydata, which is fine for 2D structures
     # however, for the 3d Delaunay tessellation, the output is an unstructured
     # grid, which means that annother type of clipper is required
     ########################################################################
     ASDGenActors.plane = vtk.vtkPlane()
     ASDGenActors.plane.SetOrigin(current_Actors.xmin, current_Actors.ymid, current_Actors.zmid)
     ASDGenActors.plane.SetNormal(1, 0, 0)
     ########################################################################
     # Check which kind of clipper must be used, as 2D and 3D data must be
     # treated differently
     ########################################################################
     if flag2D:
         ASDGenActors.clipper = vtk.vtkClipPolyData()
     else:
         ASDGenActors.clipper = vtk.vtkClipVolume()
     # Set the common variables for the clipper mapper
     ASDGenActors.clipper.SetInputConnection(method.GetOutputPort())
     ASDGenActors.clipper.SetClipFunction(ASDGenActors.plane)
     ASDGenActors.clipper.InsideOutOn()
     # Mapper of the clipper
     ASDGenActors.clipperMapper = vtk.vtkDataSetMapper()
     ASDGenActors.clipperMapper.SetScalarRange(method.GetInput().GetScalarRange())
     ASDGenActors.clipperMapper.SetInputConnection(ASDGenActors.clipper.GetOutputPort())
     ASDGenActors.clipperMapper.SetLookupTable(lut)
     # Creating the actor
     ASDGenActors.clipperActor = vtk.vtkLODActor()
     ASDGenActors.clipperActor.SetMapper(ASDGenActors.clipperMapper)
     ASDGenActors.clipperActor.VisibilityOff()
     # Adding the actor to the scene
     ren.AddActor(ASDGenActors.clipperActor)
     ########################################################################
     # Setting the information for the scalar bar widget
     ########################################################################
     # Create the scalar bar actor
     ASDGenActors.scalar_bar = vtk.vtkScalarBarActor()
     ASDGenActors.scalar_bar.SetLookupTable(lut)
     ASDGenActors.scalar_bar.GetLabelTextProperty().SetColor(0.0,0.0,0.0)
     ASDGenActors.scalar_bar.SetNumberOfLabels(5)
     ASDGenActors.scalar_bar.GetLabelTextProperty().ShadowOff()
     ASDGenActors.scalar_bar.GetLabelTextProperty().BoldOn()
     ASDGenActors.scalar_bar.GetLabelTextProperty().ItalicOff()
     ASDGenActors.scalar_bar.GetLabelTextProperty().SetFontSize(8)
     ASDGenActors.scalar_bar.SetLabelFormat("%-#6.1E")
     ASDGenActors.scalar_bar.SetBarRatio(0.5)
     ASDGenActors.scalar_bar.DrawBackgroundOn()
     ASDGenActors.scalar_bar.DrawTickLabelsOn()
     # Create the scalar bar widget
     ASDGenActors.scalar_bar_widget = vtk.vtkScalarBarWidget()
     ASDGenActors.scalar_bar_widget.SetScalarBarActor(ASDGenActors.scalar_bar)
     # Representation to actually control where the scalar bar is
     ASDGenActors.scalarBarRep = ASDGenActors.scalar_bar_widget.GetRepresentation()
     ASDGenActors.scalarBarRep.SetOrientation(0)  # 0 = Horizontal, 1 = Vertical
     ASDGenActors.scalarBarRep.GetPositionCoordinate().SetValue(0.30,0.05)
     ASDGenActors.scalarBarRep.GetPosition2Coordinate().SetValue(0.50,0.05)
     ASDGenActors.scalar_bar_widget.SetInteractor(iren)
     ASDGenActors.scalar_bar_widget.On()
     ########################################################################
     # Setting the information for the axes widget
     ########################################################################
     # Create the axes actor
     try:
         ASDGenActors.axes
     except:
         ASDGenActors.axes = vtk.vtkAxesActor()
         ASDGenActors.axes.SetShaftTypeToCylinder()
         ASDGenActors.axes.SetCylinderRadius(0.05)
         ASDGenActors.axes.SetNormalizedShaftLength(0.85,0.85,0.85)
         ASDGenActors.axes.SetNormalizedTipLength(0.40,0.40,0.40)
         ASDGenActors.axes.SetConeResolution(40)
         ASDGenActors.axes.SetCylinderResolution(40)
         # The properties of the text can be controlled independently
         ASDGenActors.axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0.0,0.0,0.0)
         ASDGenActors.axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0.0,0.0,0.0)
         ASDGenActors.axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0.0,0.0,0.0)
         ASDGenActors.axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
         ASDGenActors.axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
         ASDGenActors.axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
     else:
         pass
     ########################################################################
     # The axes actor is then used as an orientation marker widget, the advantage
     # of setting it up as a widget is that it is interactive and one can move it
     # and that it moves as the zoom changes
     # Must make sure that the widget is part of the main class so that it can
     # be actually rendered and no segfaults occur
     ########################################################################
     try:
         ASDGenActors.OrientMarker
     except:
         ASDGenActors.OrientMarker= vtk.vtkOrientationMarkerWidget()
         ASDGenActors.OrientMarker.SetOutlineColor(0.9300, 0.5700, 0.1300)
         ASDGenActors.OrientMarker.SetOrientationMarker(ASDGenActors.axes)
         ASDGenActors.OrientMarker.SetViewport(0.0, 0.0, 0.2, 0.2)
         ASDGenActors.OrientMarker.SetInteractor(iren)
         ASDGenActors.OrientMarker.EnabledOn() # <== application freeze-crash
         ASDGenActors.OrientMarker.InteractiveOn()
     else:
         pass
     iren.Start()
     renWin.Render()
     return
示例#18
0
interactor.SetRenderWindow(render_window)
 
# Create the TextActor
text_actor = vtk.vtkTextActor()
text_actor.SetInput("This is a test")
text_actor.GetTextProperty().SetColor((0, 1, 1))
 
# Create the text representation. Used for positioning the text_actor
text_representation = vtk.vtkTextRepresentation()
text_representation.GetPositionCoordinate().SetValue(0.15, 0.15)
text_representation.GetPosition2Coordinate().SetValue(0.7, 0.2)
 
# Create the TextWidget
# Note that the SelectableOff method MUST be invoked!
# According to the documentation :
#
# SelectableOn/Off indicates whether the interior region of the widget can be
# selected or not. If not, then events (such as left mouse down) allow the user
# to "move" the widget, and no selection is possible. Otherwise the
# SelectRegion() method is invoked.
text_widget = vtk.vtkTextWidget()
text_widget.SetRepresentation(text_representation)
text_widget.SetInteractor(interactor)
text_widget.SetTextActor(text_actor)
text_widget.SelectableOff()
text_widget.On()
 
interactor.Initialize()
render_window.Render()
interactor.Start()
示例#19
0
sliderRepPX = vtk.vtkSliderRepresentation2D()
sliderWidgetPX = vtk.vtkSliderWidget()

sliderRepPY = vtk.vtkSliderRepresentation2D()
sliderWidgetPY = vtk.vtkSliderWidget()

sliderRepPZ = vtk.vtkSliderRepresentation2D()
sliderWidgetPZ = vtk.vtkSliderWidget()

#getSliderObjects(sliderRepPX, sliderWidgetPX, "Position X", iren, quadric.GetCenter()[0], 25, 225, 1050, 500, posXSliderCallback)
#getSliderObjects(sliderRepPY, sliderWidgetPY, "Position Y", iren, quadric.GetCenter()[1], 25, 225, 1050, 300, posYSliderCallback)
#getSliderObjects(sliderRepPZ, sliderWidgetPZ, "Position Z", iren, quadric.GetCenter()[2], 25, 225, 1050, 100, posZSliderCallback)
'''

## Reset button modified
retext = vtk.vtkTextWidget()
textactor = vtk.vtkTextActor()
retext.SetTextActor(textactor)
retext.SetInteractor(iren)
retext.On()
retext.GetTextActor().SetInput("Reset")
retext.GetTextActor().GetTextProperty().SetColor(0, 1, 0)
#retext.GetRepresentation().GetPositionCoordinate().SetCoordinateSystemToDisplay()
#retext.GetRepresentation().GetPositionCoordinate().SetValue(1050,520,0)
#retext.GetRepresentation().GetPosition2Coordinate().SetCoordinateSystemToDisplay()
#retext.GetRepresentation().GetPosition2Coordinate().SetValue(1051,521,0)
retext.GetRepresentation().SetPosition(0.8, 0.8)
retext.SelectableOn()
retext.AddObserver('WidgetActivateEvent', reset_data)

widget = vtk.vtkTextWidget()