Example #1
0
    def show(self):

        axesActor = vtk.vtkAxesActor()
        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axesActor)
        axes.SetInteractor(self.interactor)
        axes.EnabledOn()
        self.interactor.RemoveObservers('CharEvent')

        self.balloonRep = vtk.vtkBalloonRepresentation()
        self.balloonRep.SetBalloonLayoutToImageRight()
        self.balloonRep = vtk.vtkBalloonRepresentation()
        self.balloonRep.SetBalloonLayoutToImageRight()
        self.balloonWidget = vtk.vtkBalloonWidget()
        self.balloonWidget.SetInteractor(self.interactor)
        self.balloonWidget.SetRepresentation(self.balloonRep)
        self.balloonWidget.EnabledOn()

        self.add_blocks()
        self.add_points()

        self.renwin.Render()
        self.renwin.SetWindowName("blockMeshBuilder v0.0.1")

        self.modeTextEdit("Block & Point")

        self.interactor.Initialize()
        self.interactor.Start()
Example #2
0
def main():
    colors = vtk.vtkNamedColors()

    # Sphere
    sphereSource = vtk.vtkSphereSource()
    sphereSource.SetCenter(-4.0, 0.0, 0.0)
    sphereSource.SetRadius(4.0)

    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphereSource.GetOutputPort())

    sphereActor = vtk.vtkActor()
    sphereActor.SetMapper(sphereMapper)
    sphereActor.GetProperty().SetColor(colors.GetColor3d('MistyRose'))

    # Regular Polygon
    regularPolygonSource = vtk.vtkRegularPolygonSource()
    regularPolygonSource.SetCenter(4.0, 0.0, 0.0)
    regularPolygonSource.SetRadius(4.0)

    regularPolygonMapper = vtk.vtkPolyDataMapper()
    regularPolygonMapper.SetInputConnection(regularPolygonSource.GetOutputPort())

    regularPolygonActor = vtk.vtkActor()
    regularPolygonActor.SetMapper(regularPolygonMapper)
    regularPolygonActor.GetProperty().SetColor(colors.GetColor3d('Cornsilk'))

    # A renderer and render window
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetWindowName('BalloonWidget')

    # An interactor
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # Create the widget
    balloonRep = vtk.vtkBalloonRepresentation()
    balloonRep.SetBalloonLayoutToImageRight()

    balloonWidget = vtk.vtkBalloonWidget()
    balloonWidget.SetInteractor(renderWindowInteractor)
    balloonWidget.SetRepresentation(balloonRep)
    balloonWidget.AddBalloon(sphereActor, 'This is a sphere')
    balloonWidget.AddBalloon(regularPolygonActor, 'This is a regular polygon')

    # Add the actors to the scene
    renderer.AddActor(sphereActor)
    renderer.AddActor(regularPolygonActor)
    renderer.SetBackground(colors.GetColor3d('SlateGray'))

    # Render an image (lights and cameras are created automatically)
    renderWindow.Render()
    balloonWidget.EnabledOn()

    # Begin mouse interaction
    renderWindowInteractor.Start()
    renderWindowInteractor.Initialize()
Example #3
0
 def __init__(self, screen_log):
     # initialize the class variables:
     self.box_list = []
     self.label_list = []
     self.balloon_widget = vtkBalloonWidget()
     self.node_table = {}
     self.screen_log = screen_log
     self.logger = logging.getLogger("")
Example #4
0
 def __init__(self, screen_log):
     # initialize the class variables:
     self.box_list = []
     self.label_list = []
     self.balloon_widget = vtkBalloonWidget()
     self.node_table = {}
     self.screen_log = screen_log
     self.logger = logging.getLogger("")
Example #5
0
def labelWidget(iren):
    '''利用widget给每一个模块添加label'''
    # Create the widget
    balloonRep = vtk.vtkBalloonRepresentation()
    balloonRep.SetBalloonLayoutToImageRight()

    balloonWidget = vtk.vtkBalloonWidget()
    balloonWidget.SetInteractor(iren)
    balloonWidget.SetRepresentation(balloonRep)
    '''
    balloonWidget.AddBalloon(sphereActor, "This is a sphere")
    balloonWidget.AddBalloon(regularPolygonActor, "This is a regular polygon")
    '''
    return balloonWidget
Example #6
0
renWin = vtk.vtkRenderWindow()
renWin.SetSize(3000, 1500)
iren = vtk.vtkRenderWindowInteractor()
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.SetRenderWindow(renWin)
#imageStyle=vtk.vtkInteractorStyleImage() # remove 3D interaction and only zoom, this would be ideal for the projection views (but at the moment cannot set only this style for one window)
#iren.SetInteractorStyle(imageStyle)
#compute and add axes
axes = CoordTranform.ReturnAxesActor()

balloonRep = vtk.vtkBalloonRepresentation()
balloonRep.SetBalloonLayoutToImageRight()
balloonRep.GetTextProperty().SetFontSize(30)

balloonWidget = vtk.vtkBalloonWidget()
balloonWidget.SetInteractor(iren)
balloonWidget.SetRepresentation(balloonRep)

# Define viewport ranges
X_divide = .65
Y_divide = .4
xmins = [0, X_divide, X_divide]
xmaxs = [X_divide, 1, 1]
ymins = [0, Y_divide, 0]
ymaxs = [1, 1, Y_divide]

renderer = []
camera = []
for i in range(3):
    renderer.append(vtk.vtkRenderer())
cy1 = vtk.vtkActor()
cy1.SetMapper(mapper)
cy1.AddPosition(5, 0, 0)

coneSource = vtk.vtkConeSource()
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInput(coneSource.GetOutput())
cone = vtk.vtkActor()
cone.SetMapper(coneMapper)
cone.AddPosition(0, 5, 0)

# Create the widget
rep = vtk.vtkBalloonRepresentation()
rep.SetBalloonLayoutToImageRight()

widget = vtk.vtkBalloonWidget()
widget.SetInteractor(iren)
widget.SetRepresentation(rep)
widget.AddBalloon(sph, "This is a sphere", None)
widget.AddBalloon(cy1, "This is a\ncylinder", image1.GetOutput())
widget.AddBalloon(cone, "This is a \ncone, \na really big cone, \nyou wouldn't believe how big", image1.GetOutput())

widget.AddObserver("WidgetActivateEvent", vtkBalloonCallback)

# Add the actors to the renderer, set the background and size

ren1.AddActor(sph)
ren1.AddActor(cy1)
ren1.AddActor(cone)
ren1.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(300, 300)
Example #8
0
def main():

    print(vtk.vtkVersion.GetVTKSourceVersion())

    colors = vtk.vtkNamedColors()
    # Set the background color.
    bkg = map(lambda x: x / 255.0, [26, 51, 102, 255])
    colors.SetColor("BkgColor", *bkg)

    # This creates a polygonal cylinder model with eight circumferential
    # facets.
    cylinder = vtk.vtkCylinderSource()
    cylinder.SetResolution(32)

    # The mapper is responsible for pushing the geometry into the graphics
    # library. It may also do color mapping, if scalars or other
    # attributes are defined.
    cylinderMapper = vtk.vtkPolyDataMapper()
    cylinderMapper.SetInputConnection(cylinder.GetOutputPort())

    # The actor is a grouping mechanism: besides the geometry (mapper), it
    # also has a property, transformation matrix, and/or texture map.
    # Here we set its color and rotate it -22.5 degrees.
    cylinderActor = vtk.vtkActor()
    cylinderActor.SetMapper(cylinderMapper)
    cylinderActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))
    cylinderActor.RotateX(30.0)
    cylinderActor.RotateY(-45.0)

    # Create the graphics structure. The renderer renders into the render
    # window. The render window interactor captures mouse events and will
    # perform appropriate camera or actor manipulation depending on the
    # nature of the events.
    ren = vtk.vtkRenderer()    
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the renderer, set the background and size
    ren.AddActor(cylinderActor)
    ren.SetBackground(colors.GetColor3d("BkgColor"))
    renWin.SetSize(800, 600)
    renWin.SetWindowName('CylinderExample')



    # Create the widget
    # https://lorensen.github.io/VTKExamples/site/Python/Widgets/BalloonWidget/
    balloonRep = vtk.vtkBalloonRepresentation()
    balloonRep.SetBalloonLayoutToImageRight()

    balloonWidget = vtk.vtkBalloonWidget()
    balloonWidget.SetInteractor(iren)
    balloonWidget.SetRepresentation(balloonRep)
    balloonWidget.AddBalloon(cylinderActor, "This is a cylinder")
    #balloonWidget.AddBalloon(regularPolygonActor, "This is a regular polygon")
    




    # This allows the interactor to initalize itself. It has to be
    # called before an event loop.
    iren.Initialize()

    # Add axis
    axes = vtk.vtkAxesActor()
    widget = vtk.vtkOrientationMarkerWidget()
    widget.SetOutlineColor( 0.9300, 0.5700, 0.1300 )
    widget.SetOrientationMarker( axes )
    widget.SetInteractor( iren )
    widget.SetViewport( 0.0, 0.0, 0.4, 0.4 )
    widget.SetEnabled( 1 )
    widget.InteractiveOn()

    iren.GetInteractorStyle().SetCurrentStyleToTrackballCamera()


    # We'll zoom in a little by accessing the camera and invoking a "Zoom"
    # method on it.
    ren.ResetCamera()
    ren.GetActiveCamera().Zoom(1.5)
    renWin.Render()

    # balloonWidget.EnabledOn()

    # Info
    print(renWin.GetRenderingBackend())
    print(renWin.ReportCapabilities())

    # Start the event loop.
    iren.Start()