Ejemplo n.º 1
0
    def addCaption(self, **args):
        self.captionKey += 1
        existing_caption = self.captions.get(self.captionKey, None)
        if not existing_caption:
            text = args.get('text', "Right-click to edit")
            color = args.get('color', [0, 0, 1])
            #            pos = QtCore.QPointF( self.cellWidget.current_pos )

            captionRep = vtk.vtkCaptionRepresentation()
            captionWidget = vtk.vtkCaptionWidget()
            captionWidget.SetInteractor(self.iren)
            captionWidget.SetRepresentation(captionRep)
            captionWidget.SelectableOn()
            captionWidget.ResizableOn()
            captionWidget.AddObserver('AnyEvent', self.captionObserver)
            pos0 = args.get('pos0', [0.8, 0.8])
            pos1 = args.get('pos1', [0.2, 0.05])
            apos = args.get('apos', [20.0, 20.0, 0.0])
            captionRep.SetPosition(pos0[0], pos0[1])
            captionRep.SetPosition2(pos1[0], pos1[1])
            captionRep.SetAnchorPosition(apos)
            captionActor = captionRep.GetCaptionActor2D()
            captionWidget.GetEventTranslator().SetTranslation(
                vtk.vtkCommand.RightButtonPressEvent,
                vtk.vtkWidgetEvent.Select)
            captionWidget.GetEventTranslator().SetTranslation(
                vtk.vtkCommand.RightButtonReleaseEvent,
                vtk.vtkWidgetEvent.EndSelect)

            captionActor.SetCaption(text)
            captionActor.BorderOn()
            #            captionActor.SetAttachmentPoint(  pos.x(), pos.y(), 0.0  )
            captionActor.GetCaptionTextProperty().BoldOff()
            captionActor.GetCaptionTextProperty().ItalicOff()
            captionActor.GetCaptionTextProperty().ShadowOff()
            captionActor.GetCaptionTextProperty().SetFontFamilyToArial()
            captionActor.GetCaptionTextProperty().SetJustificationToCentered()
            captionActor.ThreeDimensionalLeaderOff()
            captionActor.LeaderOn()
            captionActor.SetLeaderGlyphSize(10.0)
            captionActor.GetProperty().SetColor(color[0], color[1], color[2])
            captionActor.SetMaximumLeaderGlyphSize(10.0)
            self.captions[self.captionKey] = captionWidget
            captionWidget.On()
            return captionWidget
Ejemplo n.º 2
0
    def addCaption( self, **args ):
        self.captionKey += 1
        existing_caption = self.captions.get( self.captionKey, None )
        if not existing_caption:
            text = args.get('text', "Right-click to edit" )            
            color= args.get( 'color',  [ 0, 0, 1 ] )
#            pos = QtCore.QPointF( self.cellWidget.current_pos )

            captionRep =  vtk.vtkCaptionRepresentation() 
            captionWidget = vtk.vtkCaptionWidget()
            captionWidget.SetInteractor(self. iren )
            captionWidget.SetRepresentation(captionRep)
            captionWidget.SelectableOn() 
            captionWidget.ResizableOn() 
            captionWidget.AddObserver( 'AnyEvent', self.captionObserver )
            pos0 = args.get( 'pos0',  [ 0.8, 0.8 ] )
            pos1 = args.get( 'pos1',  [ 0.2, 0.05 ] )
            apos = args.get( 'apos',  [ 20.0, 20.0, 0.0 ] )
            captionRep.SetPosition( pos0[0], pos0[1]  )
            captionRep.SetPosition2( pos1[0], pos1[1]  )
            captionRep.SetAnchorPosition( apos )
            captionActor = captionRep.GetCaptionActor2D() 
            captionWidget.GetEventTranslator().SetTranslation( vtk.vtkCommand.RightButtonPressEvent, vtk.vtkWidgetEvent.Select )
            captionWidget.GetEventTranslator().SetTranslation( vtk.vtkCommand.RightButtonReleaseEvent, vtk.vtkWidgetEvent.EndSelect )
            
            captionActor.SetCaption( text )
            captionActor.BorderOn()
#            captionActor.SetAttachmentPoint(  pos.x(), pos.y(), 0.0  ) 
            captionActor.GetCaptionTextProperty().BoldOff()
            captionActor.GetCaptionTextProperty().ItalicOff()
            captionActor.GetCaptionTextProperty().ShadowOff()
            captionActor.GetCaptionTextProperty().SetFontFamilyToArial()
            captionActor.GetCaptionTextProperty().SetJustificationToCentered()
            captionActor.ThreeDimensionalLeaderOff()
            captionActor.LeaderOn()
            captionActor.SetLeaderGlyphSize( 10.0 )
            captionActor.GetProperty().SetColor ( color[0], color[1], color[2] )
            captionActor.SetMaximumLeaderGlyphSize( 10.0 )
            self.captions[ self.captionKey ] = captionWidget
            captionWidget.On()
            return captionWidget
iren.SetRenderWindow(renWin)

# Create a test pipeline
ss = vtk.vtkSphereSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(ss.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create the widget and its representation
rep = vtk.vtkCaptionActor2D()
rep.SetCaption("This is a test\nAnd it has two lines")
rep.GetTextActor().GetTextProperty().SetJustificationToCentered()
rep.GetTextActor().GetTextProperty().SetVerticalJustificationToCentered()

widget = vtk.vtkCaptionWidget()
widget.SetInteractor(iren)
widget.SetCaptionActor2D(rep)

# Add the actors to the renderer, set the background and size
ren1.AddActor(actor)
ren1.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(300, 300)

# record events
recorder = vtk.vtkInteractorEventRecorder()
recorder.SetInteractor(iren)
recorder.SetFileName("C:/record.log")

# render the image