Beispiel #1
0
def visualize(meshFname = None, dumpFname = None, nFrames = 100):

    # Create a rendering window and renderer
    transform = vtk.vtkTransform()
    transform.Scale(10.0, 10.0, 10.0)
     
    axes = vtk.vtkAxesActor()
    axes.SetUserTransform(transform)

    transform.Translate(2.0, -1.0, 0.0)
    axes.SetUserTransform(transform)

    renderer = vtk.vtkRenderer()
    renderer.AddActor(axes)
    
    camera = vtk.vtkCamera()
    camera.SetFocalPoint(0, 0, 0);
    renderer.SetActiveCamera(camera);

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)

     # Create a RenderWindowInteractor to permit manipulating the camera
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)

    scale = 0.1

    if dumpFname is not None:
	   with open(dumFname) as fp:
		lines = (line for line in fp if not line.strip()[:3].isalpha())
		sphereData = np.array(lines)

	   Natoms = len(sphereData) - nFrames

	   for i in range(nFrames):
		for data in sphereData[Natoms * nFrames: Natoms * (nFrames+1)]:
			plotSpheres(ren, data[1] * scale, data[2] * scale, data[3] * scale, 0.001)

    if meshFname is not None:
        polydata = loadStl(meshFname)
        renderer.AddActor(polyDataToActor(polydata))
        renderer.SetBackground(0.1, 0.1, 0.1)

    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
    renderer.ResetCamera()

    iren.Initialize()
    renWin.Render()
    iren.Start()
Beispiel #2
0
	def initVTKWidget(self,frame):
		
		"""Sets up vtkWidget inside frame.
		
		Also sets up corresponding renderer and interactor.
		
		Args:
			frame (QtGui.QFrame): Parenting frame.
			
		Returns:
			tuple: Tuple containing:
			
				* vtkWidget (vtk.qt4.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor): Qt vtk window interactor.
				* ren (vtk.vtkRenderer)
				* iren (vtk.vtkRenderWindowInteractor)
				
		"""
		
		vtkWidget = QVTKRenderWindowInteractor(frame)
		ren = vtk.vtkRenderer()
		vtkWidget.GetRenderWindow().AddRenderer(ren)
		iren = vtkWidget.GetRenderWindow().GetInteractor()
		iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
		ren.ResetCamera()
		
		return vtkWidget, ren, iren
Beispiel #3
0
    def __init__(self, parent):
        super(pnt_interactor, self).__init__(parent)
        self.ui = pt_main_window()
        self.ui.setupUi(self)
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
        style = vtk.vtkInteractorStyleTrackballCamera()
        style.AutoAdjustCameraClippingRangeOn()
        self.iren.SetInteractorStyle(style)
        self.ren.GetActiveCamera().ParallelProjectionOn()
        self.cp = self.ren.GetActiveCamera().GetPosition()
        self.fp = self.ren.GetActiveCamera().GetFocalPoint()
        self.iren.AddObserver("KeyPressEvent", self.keypress)

        self.PointSize = 2
        self.LineWidth = 1
        self.Zaspect = 1.0
        self.limits = np.empty(6)
        self.picking = False
        self.refWritten = False
        self.floatWritten = False

        self.ui.reloadButton.clicked.connect(
            lambda: self.get_input_data(None, None))
        self.ui.undoLastPickButton.clicked.connect(lambda: self.undo_pick())
        self.ui.writeButton.clicked.connect(lambda: self.write_new())
        self.ui.revertButton.clicked.connect(lambda: self.undo_revert())
        self.ui.reduceButton.clicked.connect(lambda: self.reduce_pnts())
        self.ui.showButton.clicked.connect(lambda: self.load_mat())
Beispiel #4
0
    def __init__(self, parent=None, fix_camera=True,
        background=None, size=None):
        '''
        fix_camera : more sensible default
        '''
        if parent is not None:
            self.renWin = parent.GetRenderWindow()
            self.iren = self.renWin.GetInteractor()
        else:
            self.renWin = vtk.vtkRenderWindow()
            if size is None:
                self.renWin.SetSize(800, 600)
            self.iren = vtk.vtkRenderWindowInteractor()
            self.iren.SetRenderWindow(self.renWin)

        self.ren = vtk.vtkRenderer()
        if background == 'white':
            self.ren.SetBackground(1, 1, 1)
        self.renWin.AddRenderer(self.ren)

        if fix_camera:
            camera = vtk.vtkInteractorStyleTrackballCamera()
            camera.SetCurrentRenderer(self.ren)
            self.iren.SetInteractorStyle(camera)

        self.picker = vtk.vtkCellPicker()
        self.iren.SetPicker(self.picker)
        self.picker.AddObserver("EndPickEvent", self.handle_pick)
Beispiel #5
0
	def setupInteractor(self,changeStyle=True):
		#Setup interactor
		self.iren = vtk.vtkTkRenderWindowInteractor()
		self.iren.SetRenderWindow(self.renWin)
		if changeStyle:
				style = vtk.vtkInteractorStyleTrackballCamera()
				self.iren.SetInteractorStyle(style)
Beispiel #6
0
def create_render_window(actors, callbacks, **kwargs):
    """ Creates VTK render window with an interactor.

    :param actors: list of VTK actors
    :type actors: list, tuple
    :param callbacks: callback functions for registering custom events
    :type callbacks: dict
    """
    # Get keyword arguments
    figure_size = kwargs.get('figure_size', (800, 600))
    camera_position = kwargs.get('camera_position', (0, 0, 100))

    # Find camera focal point
    center_points = []
    for actor in actors:
        center_points.append(actor.GetCenter())
    camera_focal_point = linalg.vector_mean(*center_points)

    # Create camera
    camera = vtk.vtkCamera()
    camera.SetPosition(*camera_position)
    camera.SetFocalPoint(*camera_focal_point)

    # Create renderer
    renderer = vtk.vtkRenderer()
    renderer.SetActiveCamera(camera)
    renderer.SetBackground(1.0, 1.0, 1.0)

    # Add actors to the scene
    for actor in actors:
        renderer.AddActor(actor)

    # Render window
    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(renderer)
    render_window.SetSize(*figure_size)

    # Render window interactor
    window_interactor = vtk.vtkRenderWindowInteractor()
    window_interactor.SetRenderWindow(render_window)

    # Add event observers
    for cb in callbacks:
        window_interactor.AddObserver(cb, callbacks[cb][0], callbacks[cb][1])  # cb name, cb function ref, cb priority

    # Render actors
    render_window.Render()

    # Set window name after render() is called
    render_window.SetWindowName("geomdl")

    # Use trackball camera
    interactor_style = vtk.vtkInteractorStyleTrackballCamera()
    window_interactor.SetInteractorStyle(interactor_style)

    # Start interactor
    window_interactor.Start()

    # Return window interactor instance
    return window_interactor
Beispiel #7
0
    def SetInteractorStyle(self, state):
        action = {
            const.STATE_PAN: {
                "MouseMoveEvent": self.OnPanMove,
                "LeftButtonPressEvent": self.OnPanClick,
                "LeftButtonReleaseEvent": self.OnReleasePanClick,
            },
            const.STATE_ZOOM: {
                "MouseMoveEvent": self.OnZoomMove,
                "LeftButtonPressEvent": self.OnZoomClick,
                "LeftButtonReleaseEvent": self.OnReleaseZoomClick,
            },
            const.STATE_SPIN: {
                "MouseMoveEvent": self.OnSpinMove,
                "LeftButtonPressEvent": self.OnSpinClick,
                "LeftButtonReleaseEvent": self.OnReleaseSpinClick,
            },
            const.STATE_WL: {
                "MouseMoveEvent": self.OnWindowLevelMove,
                "LeftButtonPressEvent": self.OnWindowLevelClick,
                "LeftButtonReleaseEvent": self.OnWindowLevelRelease,
            },
            const.STATE_DEFAULT: {},
            const.VOLUME_STATE_SEED: {"LeftButtonPressEvent": self.OnInsertSeed},
            const.STATE_MEASURE_DISTANCE: {"LeftButtonPressEvent": self.OnInsertLinearMeasurePoint},
            const.STATE_MEASURE_ANGLE: {"LeftButtonPressEvent": self.OnInsertAngularMeasurePoint},
        }

        if self._last_state in (const.STATE_MEASURE_DISTANCE, const.STATE_MEASURE_ANGLE):
            if self.measures and not self.measures[-1].text_actor:
                del self.measures[-1]

        if state == const.STATE_WL:
            self.on_wl = True
            if self.raycasting_volume:
                self.text.Show()
                self.interactor.Render()
        else:
            self.on_wl = False
            self.text.Hide()
            self.interactor.Render()

        if state in (const.STATE_MEASURE_DISTANCE, const.STATE_MEASURE_ANGLE):
            self.interactor.SetPicker(self.measure_picker)

        if state == const.STATE_ZOOM_SL:
            style = vtk.vtkInteractorStyleRubberBandZoom()
            self.interactor.SetInteractorStyle(style)
            self.style = style
        else:
            style = vtk.vtkInteractorStyleTrackballCamera()
            self.interactor.SetInteractorStyle(style)
            self.style = style

            # Check each event available for each mode
            for event in action[state]:
                # Bind event
                style.AddObserver(event, action[state][event])

        self._last_state = state
Beispiel #8
0
def show(ren, title="pvtk", size=(300, 300)):
    """ Show window

    Parameters
    ----------
    ren: vtkRenderer() object
        as returned from function ren().
    title: string
        a string for the window title bar.
    size: (int, int)
        (width, height) of the window.
    """
    ren.ResetCameraClippingRange()

    window = vtk.vtkRenderWindow()
    window.AddRenderer(ren)
    window.SetWindowName(title)
    window.SetSize(size)

    style = vtk.vtkInteractorStyleTrackballCamera()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(window)
    iren.SetInteractorStyle(style)
    iren.Initialize()

    window.Render()
    iren.Start()
Beispiel #9
0
	def __init__(self, parent):
		super(pnt_interactor,self).__init__(parent)
		self.ui = pt_main_window()
		self.ui.setupUi(self)
		self.ren = vtk.vtkRenderer()
		self.ren.SetBackground(0.1, 0.2, 0.4)
		self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
		self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
		style=vtk.vtkInteractorStyleTrackballCamera()
		style.AutoAdjustCameraClippingRangeOn()
		self.iren.SetInteractorStyle(style)
		self.ren.GetActiveCamera().ParallelProjectionOn()
		self.cp=self.ren.GetActiveCamera().GetPosition()
		self.fp=self.ren.GetActiveCamera().GetFocalPoint()
		self.iren.AddObserver("KeyPressEvent", self.keypress)
		
		self.PointSize=2
		self.LineWidth=1
		self.Zaspect=1.0
		self.limits=np.empty(6)
		self.picking=False
		self.refWritten = False
		self.floatWritten = False
		
		self.ui.reloadButton.clicked.connect(lambda: self.get_input_data(None,None))
		self.ui.undoLastPickButton.clicked.connect(lambda: self.undo_pick())
		self.ui.writeButton.clicked.connect(lambda: self.write_new())
		self.ui.revertButton.clicked.connect(lambda: self.undo_revert())
		self.ui.reduceButton.clicked.connect(lambda: self.reduce_pnts())
		self.ui.levelButton.clicked.connect(lambda: self.level_pnts())
		self.ui.rxButton_pos.clicked.connect(lambda: self.svd('x',False))
		self.ui.ryButton_pos.clicked.connect(lambda: self.svd('y',False))
		self.ui.rxButton_neg.clicked.connect(lambda: self.svd('x',True))
		self.ui.ryButton_neg.clicked.connect(lambda: self.svd('y',True))
		self.ui.showButton.clicked.connect(lambda: self.load_mat())
Beispiel #10
0
def __test_adjust_sphere():
    import vtk

    n_points = 4
    points = []
    for i in xrange(n_points):
        p = np.random.random(3) * 100
        points.append(p)
    r, ctr = adjust_sphere(points)
    r2 = r / 10
    ren_win = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(ren_win)
    ren = vtk.vtkRenderer()
    ren_win.AddRenderer(ren)
    # draw points
    for p in points:
        __add_sphere_to_ren(p, r2, ren)
    #draw big sphere
    ac = __add_sphere_to_ren(ctr, r, ren)
    ac.GetProperty().SetColor((1, 0, 0))

    iren.Initialize()
    iren.Start()
Beispiel #11
0
    def StartInteractor(self):
        if self.rendering == False:
            print "Starting interactor"
            self.renderer = vtk.vtkRenderer()
            self.widget.GetRenderWindow().AddRenderer(self.renderer)
            camera = self.renderer.GetActiveCamera()
            camera.SetFocalPoint(0., 0., 0.)
            camera.SetPosition(50., 0., 0.)
            camera.Roll(-90)

            mouse = vtk.vtkInteractorStyleTrackballCamera()
            self.widget.SetInteractorStyle(mouse)

            #create some axes to indicate the orientation of the galaxy
            axes = vtk.vtkAxesActor()
            self.axisw = vtk.vtkOrientationMarkerWidget()
            self.axisw.SetOutlineColor(0.9300, 0.5700, 0.1300)
            self.axisw.SetOrientationMarker(axes)
            self.axisw.SetInteractor(self.widget._Iren)
            self.axisw.SetViewport(0.0, 0.0, 0.3, 0.3)
            self.axisw.SetEnabled(1)
            self.axisw.InteractiveOn()

            self.widget.GetRenderWindow().Render()

            self.rendering = True

        else:
            print "Interactor has already started"
Beispiel #12
0
    def __init__(self):
        super(MyWindow, self).__init__()
        os.chdir(functionPath)
        uic.loadUi("registration_gui.ui", self)
        os.chdir(startPath)
        # Connect buttons to functions
        # import moving data
        self.ptcldMovingButton.clicked.connect(self.import_data)
        # import fixed data
        self.ptcldFixedButton.clicked.connect(self.import_data)
        # execute qr_register function
        self.registrationButton.clicked.connect(self.qf_register)

        self.vl = QtGui.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.vtkFrame)
        self.vl.addWidget(self.vtkWidget)

        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        self.actor_moving = vtk.vtkActor()
        self.moving_color = (0, 0.2)
        self.actor_fixed = vtk.vtkActor()
        self.fixed_color = (.8, 1)

        self.ren.AddActor(self.actor_moving)
        self.ren.AddActor(self.actor_fixed)

        self.ren.ResetCamera()

        self.vtkFrame.setLayout(self.vl)
        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        self.show()
        self.iren.Initialize()
Beispiel #13
0
    def Start(self):
        ## create VTK interactor (this is the most important object)
        # this need a Tkinter GUI object (render_frame) and a VTK render window (renWindow) to work
        self.renWinInteractor = vtkTkRenderWindowInteractor(self.render_frame,
                                                            rw=self.renWindow,
                                                            width=600,
                                                            height=600)
        self.renWinInteractor.SetInteractorStyle(
            vtk.vtkInteractorStyleTrackballCamera(
            ))  # set the trackball behaviour
        # we can add additional configurations for this interactor here
        axes = vtk.vtkAxesActor()
        marker = vtk.vtkOrientationMarkerWidget()
        marker.SetOutlineColor(0.93, 0.57, 0.13)
        marker.SetOrientationMarker(axes)
        marker.SetInteractor(self.renWinInteractor)
        marker.SetViewport(0.0, 0.0, 0.4, 0.4)
        marker.SetEnabled(1)
        marker.InteractiveOff()

        ## initialize the interactor and align it to the frame
        self.renWinInteractor.Initialize()
        self.renWinInteractor.pack(side='top', fill='both', expand=1)
        self.renWindow.Render()
        self.renWinInteractor.Start()

        ## main loop
        self.root.mainloop()
Beispiel #14
0
    def __init__(self, parent=None):
        super(QtWidgets.QWidget, self).__init__(parent)

        # Create a VTK widget and add it to the QFrame.
        self.setLayout(QtWidgets.QVBoxLayout())
        self.mVtkWidget = QVTKRenderWindowInteractor(self)
        self.layout().addWidget(self.mVtkWidget)
        self.layout().setContentsMargins(0, 0, 0, 0)

        # Get the render window and set an interactor.
        self.mRenderWindow = self.mVtkWidget.GetRenderWindow()
        self.mInteractor = self.mRenderWindow.GetInteractor()
        self.mInteractor.SetInteractorStyle(
            vtk.vtkInteractorStyleTrackballCamera())
        self.mInteractor.Initialize()

        # Create a new renderer and set the background color.
        self.mRenderer = vtk.vtkRenderer()
        self.setBackgroundColor([0.5, 0.5, 0.5])
        self.mRenderWindow.AddRenderer(self.mRenderer)
        self.mFpsObserver = FpsObserver.FpsObserver(self.mRenderer)

        # Set the Vtk Window title.
        self.mTitleActor = None
        self.setTitle("pyVtkLib Demo")
    def __init__(self):
        qDebug('RendererHelper::__init__()')
        super().__init__()
        self.__m_vtkFboItem = None
        self.gl = QOpenGLFunctions()

        self.__m_mouseLeftButton:QMouseEvent = None
        self.__m_mouseEvent:QMouseEvent = None
        self.__m_moveEvent:QMouseEvent = None
        self.__m_wheelEvent:QWheelEvent = None

        self.__m_firstRender:bool = True

        self.renderWindow:vtk.vtkGenericOpenGLRenderWindow = vtk.vtkGenericOpenGLRenderWindow()
        self.renderer:vtk.vtkRenderer = vtk.vtkRenderer()
        self.renderWindow.AddRenderer(self.renderer)

        #* Interactor
        self.interactor:vtk.vtkGenericRenderWindowInteractor = vtk.vtkGenericRenderWindowInteractor()
        self.interactor.EnableRenderOff()
        self.renderWindow.SetInteractor(self.interactor)

        #* Initialize the OpenGL context for the renderer
        self.renderWindow.OpenGLInitContext()

        #* Interactor Style
        style = vtk.vtkInteractorStyleTrackballCamera()
        style.SetDefaultRenderer(self.renderer)
        style.SetMotionFactor(10.0)
        self.interactor.SetInteractorStyle(style)
Beispiel #16
0
    def run(self):
        renderer = vtk.vtkRenderer()
        renderer.SetBackground(0, 0, 0)

        camera = vtk.vtkCamera()
        camera.SetPosition((1, -1, -2))
        camera.SetViewUp((0, -1, 0))
        camera.SetFocalPoint((0, 0, 2))
        renderer.SetActiveCamera(camera)

        renwin = vtk.vtkRenderWindow()
        renwin.SetWindowName("Point Cloud Viewer")
        renwin.SetSize(800, 600)
        renwin.AddRenderer(renderer)

        interactor = vtk.vtkRenderWindowInteractor()
        interstyle = vtk.vtkInteractorStyleTrackballCamera()
        interactor.SetInteractorStyle(interstyle)
        interactor.SetRenderWindow(renwin)

        interactor.Initialize()

        cb = vtkTimerCallback(self.cinematic, self.render_path,
                              self.clear_points)
        cb.queue = self.queue

        interactor.AddObserver('TimerEvent', cb.execute)
        timerId = interactor.CreateRepeatingTimer(100)

        #start the interaction and timer
        interactor.Start()
Beispiel #17
0
    def __init__(self, parent=None, title=None, shape=(1, 1), off_screen=None, **kwargs):
        """ Initialize Qt interactor """
        if not has_pyqt:
            raise AssertionError('Requires PyQt5')
        QVTKRenderWindowInteractor.__init__(self, parent)
        BasePlotter.__init__(self, shape=shape, title=title)
        self.parent = parent

        # Create and start the interactive renderer
        self.ren_win = self.GetRenderWindow()
        for renderer in self.renderers:
            self.ren_win.AddRenderer(renderer)

        self.background_color = rcParams['background']
        if self.title:
            self.setWindowTitle(title)

        if off_screen is None:
            off_screen = pyvista.OFF_SCREEN

        if off_screen:
            self.ren_win.SetOffScreenRendering(1)
        else:
            self.iren = self.ren_win.GetInteractor()
            self.iren.RemoveObservers('MouseMoveEvent')  # slows window update?

            # Enter trackball camera mode
            istyle = vtk.vtkInteractorStyleTrackballCamera()
            self.SetInteractorStyle(istyle)
            self.add_axes()

            self.iren.Initialize()

            # QVTKRenderWindowInteractor doesn't have a "q" quit event
            self.iren.AddObserver("KeyPressEvent", self.key_quit)
Beispiel #18
0
    def __init__(
        self,
        threadLock,
        actorWrapper_1,
        axis=True,
    ):

        self.threadLock = threadLock
        self.ren = vtk.vtkRenderer()
        self.transform = vtk.vtkTransform()
        self.transform.Translate(0.0, 0.0, 0.0)
        self.axesActor = vtk.vtkAxesActor()
        self.axesActor.SetUserTransform(self.transform)
        self.axesActor.AxisLabelsOff()
        self.axesActor.SetTotalLength(1, 1, 1)
        self.ren.AddActor(self.axesActor)
        self.renWin = vtk.vtkRenderWindow()
        self.renWin.AddRenderer(self.ren)
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)

        # pending in this case
        self.ren.AddActor(actorWrapper_1.actor)
        self.renWin.Render()
        self.iren.Initialize()
        self.style = vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(self.style)
        self.iren.AddObserver("TimerEvent", self.update_visualisation)
        dt = 30  # ms -- fps
        timer_id = self.iren.CreateRepeatingTimer(dt)
def Viewer(cloud):
    """
    可视化点云及关键接触点,和公法线
    :param cloud:点云
    :return:
    """

    obj = VTKObject()
    obj.CreateFromArray(cloud[1].to_array())
    obj.AddNormals(cloud[2].to_array()[0:, 0:3])
    obj.SetupPipelineHedgeHog(10)
    ren = vtk.vtkRenderer()
    ren.AddActor(obj.GetActor())
    obj2 = VTKObject()
    obj2.CreateFromArray(cloud[0].to_array())
    ren.AddActor(obj2.GetActor())
    obj3 = VTKObject()
    obj3.CreateFromArray(cloud[1].to_array())
    obj3.GetActor().GetProperty().SetColor(1, 0, 0.0)
    obj3.GetActor().GetProperty().SetPointSize(10)
    ren.AddActor(obj3.GetActor())
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
    iren.Initialize()
    iren.Start()
Beispiel #20
0
    def __init__(self, background=(0.15, 0.15, 0.15), total_time_steps=None, timer_rate=60, gif_file=None):
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(background[0], background[1], background[2])
        self.ren_win = vtk.vtkRenderWindow()
        self.ren_win.AddRenderer(self.ren)
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.ren_win)
        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        self.actor_list = []
        self.mapper_list = []
        self.source_list = []
        self.screenshot_count = 0
        self.timer_rate = timer_rate
        self.gif_data = []
        if gif_file is not None:
            try:
                assert type(gif_file) is str
            except AssertionError:
                gif_file = str(gif_file)
            self.gif_file = gif_file
        else:
            self.gif_file = None

        if total_time_steps is not None:
            assert type(total_time_steps) is int
            self.timer_count = 0
            self.total_time_steps = total_time_steps
Beispiel #21
0
    def __init__(self, parent):
        super(QMeshViewer, self).__init__(parent)

        self.platformModel: vtk.vtkCubeSource = None
        self.platformGrid: vtk.vtkPolyData = None
        self.platformModelActor: vtk.vtkActor = None
        self.platformGridActor: vtk.vtkActor = None

        self.platformWidth: float = 200.0
        self.platformDepth: float = 200.0
        self.platformThickness: float = 2.0
        self.gridBottomHeight: float = 0.15
        self.gridSize: np.uint16 = 10

        # Make the actual QtWidget a child so that it can be re_parented
        self.interactor = QVTKRenderWindowInteractor(self)
        self.layout = QtWidgets.QHBoxLayout()
        self.layout.addWidget(self.interactor)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)

        self.initScene()
        self.initPlatform()
        self.initAxes()
        self.resetCamera()

        self.style = vtk.vtkInteractorStyleTrackballCamera()
        self.style.SetDefaultRenderer(self.renderer)
        self.interactor.SetInteractorStyle(self.style)
Beispiel #22
0
def example():
    # Create the renderer
    ren = vtk.vtkRenderer()
    # Create the window
    renWin = vtk.vtkRenderWindow()
    # Add the renderer to the window
    renWin.AddRenderer(ren)
    # Define an interactor. This controls how the user can interact with
    # things in the window.
    iren = vtk.vtkRenderWindowInteractor()
    # Set the window defined above as the window that the interactor
    # will work on.
    iren.SetRenderWindow(renWin)

    # Define the axes actor.
    axes = vtk.vtkAxesActor()
    # Add the axes actor to the window.
    ren.AddActor(axes)

    # The default interactor style doesn't work well for a mouse,
    # so we will redefine it as another pre-set style called 'track ball'.
    trackBallStyle = vtk.vtkInteractorStyleTrackballCamera()
    # Set the interactor style as the 'track ball' style defined above.
    iren.SetInteractorStyle(trackBallStyle)

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

    # Start the event loop.
    iren.Start()
    return
Beispiel #23
0
    def __init__(self, ren=None, iren=None, filename="zxh-ape.obj", RESIZE = 1, COLOR = True, RADISU = 0.01, xl = 4, yl = 4, zl = 4):
        # 参数初始化
        self.ren = ren
        self.iren = iren
        self.filename = filename
        self.RESIZE = RESIZE
        self.RADISU = RADISU
        self.COLOR = COLOR
        self.xl = xl
        self.yl = yl
        self.zl = zl

        # 设置背景颜色
        self.ren.SetBackground(237, 237, 237)

        # 用TrackballCamera的交互方式
        InteractorStyle = vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(InteractorStyle)

        # 初始化画图
        self.loadOBJ()
        self.drawFace()

        # 根据load进来的物体大小 自适应设置球体的半径大小
        self.RADISU = (self.ffd.max_x - self.ffd.min_x) * self.RADISU

        # 画点画线 增加监听器
        self.drawControlPoints()
        self.drawLines()
        self.addControlPointsObserver()
def __test_normalize():
    import vtk

    ref_point = PointWithRef()
    point2 = PointWithRef()
    for p in (ref_point, point2):
        p.point_pos = np.random.random(3) * 15 / 100
        p.ref_pos = np.random.random(3) * 15 / 100
        p.point_or = tuple(Quaternion.from_v_theta(np.random.random(3), np.random.random()).x)
        p.ref_or = tuple(Quaternion.from_v_theta(np.random.random(3), np.random.random()).x)

    ren_win = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(ren_win)
    ren = vtk.vtkRenderer()
    ren_win.AddRenderer(ren)

    # draw ref
    __draw_point_and_uni(ref_point, (1, 1, 1), ren)

    # draw original point
    __draw_point_and_uni(point2, (0, 1, 0), ren)

    #normalize
    point2_n = normalize_point_to_ref(point2, ref_point)
    __draw_point_and_uni(point2_n, (1, 0, 0), ren)

    iren.Initialize()
    iren.Start()
Beispiel #25
0
    def __init__(self, h=800, w=600):
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(0.1, 0.1, 0.1)

        # Add axes
        axes = vtk.vtkAxesActor()
        axes.GetXAxisCaptionActor2D().SetHeight(0.05)
        axes.GetYAxisCaptionActor2D().SetHeight(0.05)
        axes.GetZAxisCaptionActor2D().SetHeight(0.05)
        axes.SetCylinderRadius(0.03)
        axes.SetShaftTypeToCylinder()
        self.renderer.AddActor(axes)

        # Add render window
        self.renwin = vtk.vtkRenderWindow()
        self.renwin.SetWindowName("Point Cloud Viewer")
        self.renwin.SetSize(h, w)
        self.renwin.AddRenderer(self.renderer)

        # An interactor
        self.interactor = vtk.vtkRenderWindowInteractor()
        interstyle = vtk.vtkInteractorStyleTrackballCamera()
        self.interactor.SetInteractorStyle(interstyle)
        self.interactor.SetRenderWindow(self.renwin)

        self.camera_actors = []
Beispiel #26
0
    def __init__(self, background_color=(0, 0, 0)):
        """
        Main window of a BiorbdViz object. If one is interested in placing the main window inside another widget, they
        should call VktWindow first, add whatever widgets/layouts they want in the 'VtkWindow.main_layout',
        including, of course, the actual avatar from 'VtkWindow.vtkWidget'.
        Parameters
        ----------
        background_color : tuple(int)
            Color of the background
        """
        QtWidgets.QMainWindow.__init__(self)
        self.frame = QtWidgets.QFrame()
        self.setCentralWidget(self.frame)

        self.ren = vtkRenderer()
        self.ren.SetBackground(background_color)

        self.avatar_widget = QVTKRenderWindowInteractor(self.frame)
        self.avatar_widget.GetRenderWindow().SetSize(1000, 100)
        self.avatar_widget.GetRenderWindow().AddRenderer(self.ren)

        self.interactor = self.avatar_widget.GetRenderWindow().GetInteractor()
        self.interactor.SetInteractorStyle(vtkInteractorStyleTrackballCamera())
        self.interactor.Initialize()
        self.change_background_color(background_color)

        self.main_layout = QtWidgets.QGridLayout()
        self.main_layout.addWidget(self.avatar_widget)
        self.frame.setLayout(self.main_layout)

        self.show()
        app._in_event_loop = True
        self.is_active = True
        self.should_reset_camera = False
        app.processEvents()
Beispiel #27
0
    def getVtkInteractor(self):
        if (self.vtkInteractor == None):
            self.vtkInteractor = kwvtk.vtkRenderWindowInteractor()
            self.vtkInteractor.SetInteractorStyle(
                kwvtk.vtkInteractorStyleTrackballCamera())

        return self.vtkInteractor
Beispiel #28
0
	def __init__(self):
		self.outputs=[]
		self.paint=rgbPainter()
		self.scalingFactor=1.0
		self.showAxes=True
		self.showScalarBar=True
		self.showCaption=True
		self.showXYPlane=True
		self.showYZPlane=True
		self.showZXPlane=True
		self.nbSize=80
		self.sampleSpacing=8.0
	
		self.camera = vtk.vtkCamera()

		self.ren = vtk.vtkRenderer();
		self.renWin = vtk.vtkRenderWindow();
		self.renWin.AddRenderer(self.ren);
		self.renWin.SetWindowName("DESICOS-viewer v0.1 ")
		self.iren = vtk.vtkRenderWindowInteractor();
		self.iren.SetRenderWindow(self.renWin);
		style1 = vtk.vtkInteractorStyleTrackballCamera()
		self.iren.SetInteractorStyle(style1)
		self.ren.SetBackground(1, 1, 1);
		self.renWin.SetSize(800, 600);
Beispiel #29
0
    def createRenderWindow( self, **args ):
        blocking = args.get( 'blocking', False )
        renWin = args.get( 'renwin', None ) 
        if renWin == None:
            renWin = vtk.vtkRenderWindow()
            
        rendWinInteractor = renWin.GetInteractor()
        if rendWinInteractor == None:                
            rendWinInteractor = vtk.vtkRenderWindowInteractor() if blocking else vtk.vtkGenericRenderWindowInteractor()
            renWin.SetInteractor( rendWinInteractor )
            rendWinInteractor.SetRenderWindow(renWin)  
        
        self.renderWindowInteractor =  rendWinInteractor              
        self.renderer = vtk.vtkRenderer()
        renWin.AddRenderer( self.renderer )

        self.interactorStyle = vtk.vtkInteractorStyleTrackballCamera( )
        self.renderWindowInteractor.SetInteractorStyle( self.interactorStyle )
        self.interactorStyle.KeyPressActivationOff( )
        self.interactorStyle.SetEnabled(1)
                     
        if self.useDepthPeeling:
            self.renderer.UseDepthPeelingOn( )
            self.renderer.SetOcclusionRatio( 0.2 )       
            renWin.SetAlphaBitPlanes( 1 )
            renWin.SetMultiSamples( 0 )
            
        self.renderer.SetBackground(1.0, 1.0, 1.0)
        self.renderer.SetNearClippingPlaneTolerance( 0.0001 )    
        self.renderWindow = renWin
Beispiel #30
0
    def init(self):
        """
        """

        # Symbol behaviour initialisation
        self.draw_forward = ['F', 'B', 'G', 'R']
        self.move_forward = ['M']
        self.rotation = ['+', '-', '&', '^', '<', '>', '|']
        self.push_pop = ['[', ']']
        self.do_nothing = ['X']

        # Init heap / stack to remember position
        self.saved_pos = []
        self.saved_vector = []

        # VTK init
        self.renWin = vtk.vtkRenderWindow()
        self.renWin.SetSize(800, 600)
        self.renWin.SetWindowName("L-System : " + self.lsystem.name + " ( " + self.viewer_type + " )")

        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)

        self.style = vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(self.style)

        # Branch initial parameters
        self.radius = self.lsystem.radius
        self.length = self.lsystem.width
        self.angle = self.lsystem.angle
Beispiel #31
0
 def __init__(self, x, y):
     self.height = y
     self.width = x
     self.cam = vtk.vtkInteractorStyleTrackballCamera()
     self.renderer = vtk.vtkRenderer()
     self.renderWindow = vtk.vtkRenderWindow()
     self.interact = vtk.vtkRenderWindowInteractor()
Beispiel #32
0
    def __init__(self, parent, id, style):
        wx.Panel.__init__(self, parent, id, style=style)

        self.renderer = vtk.vtkRenderer()
        self.Interactor = wxVTKRenderWindowInteractor(self,
                                                      -1,
                                                      size=self.GetSize())
        self.Interactor.GetRenderWindow().AddRenderer(self.renderer)
        self.Interactor.Render()

        istyle = vtk.vtkInteractorStyleTrackballCamera()

        self.Interactor.SetInteractorStyle(istyle)

        hbox = wx.BoxSizer(wx.VERTICAL)
        hbox.Add(wx.StaticText(self, -1, 'Global Structure of Scaffold'))

        hbox.Add(self.Interactor, 1, wx.EXPAND)
        self.SetSizer(hbox)

        self.init_actor()
        self.add_axes()
        self.draw_surface()
        self.renderer.ResetCamera()

        pub.subscribe(self._draw_surface, 'Recalculating surface')
        pub.subscribe(self._calculate_porosity, 'Calculating porosity')
Beispiel #33
0
    def __init__(self, renderer=None, parent=None):

        # Every QT app needs a QApplication
        self.app = QApplication.instance()
        if self.app is None:
            self.app = QApplication(sys.argv)

        # Create the widget
        if renderer is None:
            self.renderer = vtk.vtkRenderer()
        else:
            self.renderer = renderer

        self.widget = QVTKRenderWindowInteractor(parent)

        self.widget.Initialize()
        self.widget.Start()

        # Set the interactor style
        self.widget.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

        # Get the render window from the widget
        self.renderWindow = self.widget.GetRenderWindow()
        self.renderWindow.AddRenderer(self.renderer)

        # show the widget
        self.widget.show()
Beispiel #34
0
    def __init__(self, app: QApplication, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.app: QApplication = app
        self.setupUi(self)

        self.chooseFileBtt.pressed.connect(self.choose_file)
        self.quitBtt.pressed.connect(self.close_app)
        self.loadBtt.pressed.connect(self.load_btt)
        self.deleteBtt.pressed.connect(self.del_btt)

        self.vtk_widget = QVTKRenderWindowInteractor(self.widget)
        self.vtk_widget.resize(self.widget.size())
        self.renderer = vtk.vtkRenderer()
        self.vtk_widget.GetRenderWindow().AddRenderer(self.renderer)
        self.interactor = self.vtk_widget.GetRenderWindow().GetInteractor()
        self.interactor.SetInteractorStyle(
            vtk.vtkInteractorStyleTrackballCamera())

        self.interactor.Initialize()
        self.renderer.GetActiveCamera().Elevation(-15)
        self.renderer.ResetCamera()

        self.model = QStandardItemModel()
        self.model.itemChanged.connect(self.render_view)
        self.listView.setModel(self.model)
        self.listView.show()

        self.threadpool = QThreadPool()

        self.show()
Beispiel #35
0
 def init_vtk_view(self):
     # 在之前创建的view_widget上添加vtk控件
     self.vtk_vertical_layout = QVBoxLayout(self.view_widget)
     self.vtk_widget = QVTKRenderWindowInteractor(self.view_widget)
     self.vtk_vertical_layout.addWidget(self.vtk_widget)
     # 1.创建RenderWindow窗口
     self.render_window = self.vtk_widget.GetRenderWindow()
     # 2.创建render
     self.renderer = vtk.vtkRenderer()
     self.renderer.SetBackground(1.0, 1.0, 1.0)  # 设置页面底部颜色值
     self.renderer.SetBackground2(0.1, 0.2, 0.4)  # 设置页面顶部颜色值
     self.renderer.SetGradientBackground(1)  # 开启渐变色背景设置
     self.render_window.AddRenderer(self.renderer)
     self.render_window.Render()
     # 3.设置交互方式
     self.iren = self.render_window.GetInteractor()  # 获取交互器
     self.style = vtk.vtkInteractorStyleTrackballCamera(
     )  # 交互器样式的一种,该样式下,用户是通过控制相机对物体作旋转、放大、缩小等操作
     # self.style = MyInteractor(self)
     self.style.SetDefaultRenderer(self.renderer)
     self.iren.SetInteractorStyle(self.style)
     # 拾取器
     cellPicker = vtk.vtkCellPicker()
     self.iren.SetPicker(cellPicker)
     # 4.添加坐标轴(加self,血的教训)
     axesActor = vtk.vtkAxesActor()
     self.axes_widget = vtk.vtkOrientationMarkerWidget()
     self.axes_widget.SetOrientationMarker(axesActor)
     self.axes_widget.SetInteractor(self.iren)
     self.axes_widget.EnabledOn()
     self.axes_widget.InteractiveOff()  # 坐标系是否可移动
     # 5.添加Actor
     self.original_actor = vtk.vtkActor()
Beispiel #36
0
def main(pairs):

    import __main__ as _main_module

    renderer = vtk.vtkRenderer()

    for op, file in pairs:
        handler_name = g_op_map[op]
        handler = _main_module.__dict__[handler_name]
        fname = file
        if not os.access(fname, os.R_OK):
            print "Missing file %s" % (fname)
            sys.exit(1)
        else:
            handler(fname, renderer)

    show_axes(renderer)

    # Create the usual rendering stuff.
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    renWin.SetSize(1000, 750)
    iren = vtk.vtkRenderWindowInteractor()
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
    iren.SetRenderWindow(renWin)

    # color
    renderer.SetBackground(.1, .2, .4)

    # Render the scene and start interaction.
    iren.Initialize()
    renWin.Render()
    iren.Start()
Beispiel #37
0
 def display(self):
     r"""
     Display the static mesh and the aligned within an interactive VTK 
     window 
     
     """
     if not hasattr(self.s, 'actor'):
         self.s.addActor()
     if not hasattr(self.m, 'actor'):
         self.m.addActor()
     # Generate a renderer window
     win = vtkRenWin()
     # Set the number of viewports
     win.setnumViewports(1)
     # Set the background colour
     win.setBackground([1, 1, 1])
     # Set camera projection
     renderWindowInteractor = vtk.vtkRenderWindowInteractor()
     renderWindowInteractor.SetRenderWindow(win)
     renderWindowInteractor.SetInteractorStyle(
         vtk.vtkInteractorStyleTrackballCamera())
     # Set camera projection
     win.setView()
     self.s.actor.setColor([1.0, 0.0, 0.0])
     self.s.actor.setOpacity(0.5)
     self.m.actor.setColor([0.0, 0.0, 1.0])
     self.m.actor.setOpacity(0.5)
     win.renderActors([self.s.actor, self.m.actor])
     win.Render()
     win.rens[0].GetActiveCamera().Azimuth(180)
     win.rens[0].GetActiveCamera().SetParallelProjection(True)
     win.Render()
     return win
Beispiel #38
0
    def updateContents(self, inputPorts):
        if self.view==None:
            self.view = pvsp.CreateRenderView()
            renWin = self.view.GetRenderWindow()
            self.SetRenderWindow(renWin)
            iren = renWin.GetInteractor()
            iren.SetNonInteractiveRenderDelay(0)
            iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

        del self.view.Representations[:]

        # Fetch variables from the input port
        (location, representations) = inputPorts
        
        for rep in representations:
            rep.set_view(self.view)
            rep.execute()

        # Set view specific properties
        self.view.CenterAxesVisibility = 0
        self.view.Background = [0.5, 0.5, 0.5]

        self.view.ResetCamera()
        self.view.StillRender()

        QCellWidget.updateContents(self, inputPorts)
    def visualize(self):
        ugrid = self.ugrid

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputData(ugrid)

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

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

        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(rw)
        renderer.AddActor(actor)

        interactor_style = vtk.vtkInteractorStyleTrackballCamera()

        iren.SetInteractorStyle(interactor_style)

        lut = vtk.vtkLookupTable()
        lut.SetHueRange(2 / 3, 0)
        lut.Build()

        mapper.SetLookupTable(lut)
        # actor.GetProperty().SetRepresentationToWireframe()

        iren.Initialize()
        rw.Render()
        iren.Start()
Beispiel #40
0
def initialize():

    # Create a rendering window and renderer
    transform = vtk.vtkTransform()
    transform.Scale(10.0, 10.0, 10.0)
     
    axes = vtk.vtkAxesActor()
    axes.SetUserTransform(transform)

    transform.Translate(3.0, -2.0, 0.0)
    axes.SetUserTransform(transform)

    ren = vtk.vtkRenderer()
    ren.AddActor(axes)
    ren.ResetCamera()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)

    # Create a RenderWindowInteractor to permit manipulating the camera
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)

    # enable user interface interactor
    iren.Initialize()
    renWin.Render()
    iren.Start()

    return ren, iren, renWin
Beispiel #41
0
def render(actors):
    renderer = vtk.vtkRenderer()

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

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

    actors.append(make_axis_actor())

    for actor in actors:
        actor.GetProperty().SetRepresentationToWireframe()
        renderer.AddActor(actor)

    renderer.SetBackground(0.1, 0.2, 0.4)
    render_window.SetSize(800, 800)

    interactor.Initialize()

    renderer.ResetCamera()
    renderer.GetActiveCamera().Zoom(1.5)
    render_window.Render()

    interactor.Start()
def DisplayVTKMesh(meshi,windowname):
    
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(meshi)
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetInterpolationToPhong()
    actor.GetProperty().SetAmbient(0.2)
    actor.GetProperty().SetDiffuse(0.7)
    actor.GetProperty().SetSpecular(0.6)
    actor.GetProperty().SetSpecularPower(100)
    actor.GetProperty().SetColor(0.8,0.8,1)
    ren1 = vtk.vtkRenderer()
    ren1.AddActor(actor)
    ren1.SetBackground(0, 0, 0)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)
    renWin.SetSize(300, 300)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    style = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)
    iren.Initialize()
    renWin.SetWindowName(windowname)
    iren.Start()
Beispiel #43
0
 def display(self):
     r"""
     Function to display the ampActor within in an interactable 
     vtkRenWin window
     
     Returns
     -------
     win: vtkRenWin
         The generated vtkRenWin
     
     """
     if not hasattr(self, 'actor'):
         self.addActor()
     # Generate a renderer window
     win = vtkRenWin()
     # Set the number of viewports
     win.setnumViewports(1)
     # Set the background colour
     win.setBackground([1, 1, 1])
     # Set camera projection
     renderWindowInteractor = vtk.vtkRenderWindowInteractor()
     renderWindowInteractor.SetRenderWindow(win)
     renderWindowInteractor.SetInteractorStyle(
         vtk.vtkInteractorStyleTrackballCamera())
     # Set camera projection
     win.setView()
     win.renderActors([
         self.actor,
     ])
     win.Render()
     win.rens[0].GetActiveCamera().Azimuth(0)
     win.rens[0].GetActiveCamera().SetParallelProjection(True)
     win.Render()
     return win
Beispiel #44
0
def show(ren,title='Fos',size=(300,300)):
    ''' Show window 
    
    Parameters
    ----------
    ren : vtkRenderer() object 
            as returned from function ren()
    title : string 
            a string for the window title bar
    size : (int, int) 
            (width,height) of the window
    
    Examples
    --------    
    >>> from dipy.viz import fos
    >>> r=fos.ren()    
    >>> lines=[np.random.rand(10,3),np.random.rand(20,3)]    
    >>> colors=[0.2,0.8]
    >>> c=fos.line(lines,colors)    
    >>> fos.add(r,c)
    >>> l=fos.label(r)
    >>> fos.add(r,l)
    >>> fos.show(r)
    '''
    ren.ResetCamera()        
    window = vtk.vtkRenderWindow()
    window.AddRenderer(ren)
    window.SetWindowName(title) 
    window.SetSize(size)
    style=vtk.vtkInteractorStyleTrackballCamera()        
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(window)
    iren.SetInteractorStyle(style)
    iren.Start()
Beispiel #45
0
    def __init__(self,parent):
        super(interactor, self).__init__(parent)
        self.ui = main_window()
        self.ui.setup(self)
        self.ren = vtk.vtkRenderer()
        colors = vtk.vtkNamedColors()
        self.ren.SetBackground(colors.GetColor3d("aliceblue"))

        self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
        style=vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(style)
        self.iren.AddObserver("KeyPressEvent", self.keypress)
        self.iren.AddObserver("MouseMoveEvent", self.on_mouse_move)
        self.ren.GetActiveCamera().ParallelProjectionOn()
        
        self.file = None #overwritten at launch
        make_logo(self.ren)
        
        self.ui.load_button.clicked.connect(self.load_vtu)
        self.ui.mesh_display.clicked.connect(self.toggle_edges)
        self.ui.clip_active_button.clicked.connect(self.clip)
        self.ui.extract_button.clicked.connect(self.extract)
        self.ui.export_line_button.clicked.connect(self.export_line)
        self.ui.update_contours_button.clicked.connect(self.update_scale_bar)
        self.ui.extract_boundaries_button.clicked.connect(self.get_boundaries)
Beispiel #46
0
    def __init__(self, parent):
        super(surf_int, self).__init__(parent)
        self.ui = sf_main_window()
        self.ui.setupUi(self)
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        self.ren.GetActiveCamera().ParallelProjectionOn()
        self.cp = self.ren.GetActiveCamera().GetPosition()
        self.fp = self.ren.GetActiveCamera().GetFocalPoint()
        self.iren.AddObserver("KeyPressEvent", self.keypress)

        self.PointSize = 2
        self.LineWidth = 1
        self.Zaspect = 1.0
        self.limits = np.empty(6)
        self.picking = False
        self.fitted = False

        self.ui.updateButton.clicked.connect(lambda: self.onUpdateSpline())
        self.ui.sectionButton.clicked.connect(lambda: self.Cut())
        self.ui.revertButton.clicked.connect(lambda: self.RemoveCut())
        self.ui.writeButton.clicked.connect(lambda: self.write())
        self.ui.reloadButton.clicked.connect(lambda: self.get_input_data())
        self.ui.undoLastPickButton.clicked.connect(lambda: self.undo_pick())
        self.ui.numEdit1.valueChanged.connect(self.changeUpdateBackground)
        self.ui.numEdit2.valueChanged.connect(self.changeUpdateBackground)
        self.ui.numEdit3.valueChanged.connect(self.changeUpdateBackground)
        self.ui.numEdit4.valueChanged.connect(self.changeUpdateBackground)
        self.ui.drx.valueChanged.connect(self.changeUpdateBackground)
        self.ui.dry.valueChanged.connect(self.changeUpdateBackground)
Beispiel #47
0
    def __init__(self, threadLock, actorWrapper, axis=True,):
        super(VTKVisualisation, self).__init__()

        self.threadLock = threadLock

        self.ren = vtk.vtkRenderer()
        self.ren.AddActor(actorWrapper.actor)

        self.axesActor = vtk.vtkAxesActor()
        self.axesActor.AxisLabelsOff()
        self.axesActor.SetTotalLength(1, 1, 1)
        self.ren.AddActor(self.axesActor)

        self.renWin = vtk.vtkRenderWindow()
        self.renWin.AddRenderer(self.ren)

        ## IREN
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)
        self.iren.Initialize()

        self.style = vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(self.style)

        self.iren.AddObserver("TimerEvent", self.update_visualisation)
        dt = 30 # ms
        timer_id = self.iren.CreateRepeatingTimer(dt)
Beispiel #48
0
    def __init__(self):
        """Init."""
        # Interactor responsible for moving the camera.
        self.trackball_camera = vtk.vtkInteractorStyleTrackballCamera()
        # Interactor responsible for moving/rotating a selected actor.
        self.trackball_actor = vtk.vtkInteractorStyleTrackballActor()
        # Interactor responsible for panning/zooming the camera.
        self.image = vtk.vtkInteractorStyleImage()

        # The picker allows us to know which object/actor is under the mouse.
        self.picker = vtk.vtkPropPicker()
        self.chosen_element = None
        self.event = Event()
        self.event2id = {}  # To map an event's name to an ID.

        # Define some interaction states
        self.left_button_down = False
        self.right_button_down = False
        self.middle_button_down = False
        self.active_props = set()

        self.history = deque(maxlen=10)  # Events history.

        self.selected_props = {"left_button": set(),
                               "right_button": set(),
                               "middle_button": set()}
Beispiel #49
0
    def __init__(self, parent: QWidget, geographic_bounds: dict, cities: list):
        self.parent = parent
        self.geographic_bounds = geographic_bounds
        self.cities = cities
        self.vtk_widget = QVTKRenderWindowInteractor(parent)
        self.vtk_widget.resize(parent.size())
        self.renderer = vtk.vtkRenderer()
        self.vtk_widget.GetRenderWindow().AddRenderer(self.renderer)
        self.interactor = self.vtk_widget.GetRenderWindow().GetInteractor()
        self.interactor.SetInteractorStyle(
            vtk.vtkInteractorStyleTrackballCamera())

        self.actors = {
            'precipitation': [],
            'clouds': [],
            'wind': [],
            'temperature': [],
            'pressure': []
        }
        self.map_actor = None
        self.legend_actors = {'temperature': [], 'pressure': []}

        self.initialize_map()
        self.initialize_legend()
        self.interactor.Initialize()
        self.renderer.GetActiveCamera().Elevation(-15)
        self.renderer.ResetCamera()
Beispiel #50
0
    def __init__(self, rwi, renderer):
        # nnsmit-edit
        self.overlay_active = 0;
        # end edit
        self.rwi = rwi
        self.renderer = renderer

        istyle = vtk.vtkInteractorStyleTrackballCamera()
        rwi.SetInteractorStyle(istyle)

        # we unbind the existing mousewheel handler so it doesn't
        # interfere
        rwi.Unbind(wx.EVT_MOUSEWHEEL)
        rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel)

        self.ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)]
        lut = self.ipws[0].GetLookupTable()
        for ipw in self.ipws:
            ipw.SetInteractor(rwi)
            ipw.SetLookupTable(lut)

	    # nnsmit-edit
    	self.overlay_ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)]
        lut2 = self.overlay_ipws[0].GetLookupTable()
        lut2.SetNumberOfTableValues(3)
        lut2.SetTableValue(0,0,0,0,0)
        lut2.SetTableValue(1,0.5,0,1,1)
        lut2.SetTableValue(2,1,0,0,1)
        lut2.Build()
        for ipw_overlay in self.overlay_ipws:
            ipw_overlay.SetInteractor(rwi)
            ipw_overlay.SetLookupTable(lut2)
            ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL)

        # now actually connect the sync_overlay observer
        for i,ipw in enumerate(self.ipws):
            ipw.AddObserver('InteractionEvent',lambda vtk_o, vtk_e, i=i: self.observer_sync_overlay(self.ipws,i))
        # end edit

        # we only set the picker on the visible IPW, else the
        # invisible IPWs block picking!
        self.picker = vtk.vtkCellPicker()
        self.picker.SetTolerance(0.005)
        self.ipws[0].SetPicker(self.picker)

        self.outline_source = vtk.vtkOutlineCornerFilter()
        m = vtk.vtkPolyDataMapper()
        m.SetInput(self.outline_source.GetOutput())
        a = vtk.vtkActor()
        a.SetMapper(m)
        a.PickableOff()
        self.outline_actor = a

        self.dv_orientation_widget = DVOrientationWidget(rwi)

        # this can be used by clients to store the current world
        # position
        self.current_world_pos = (0,0,0)
        self.current_index_pos = (0,0,0)
Beispiel #51
0
def PlotGrids_wFEM(grids):
    """ Plots CFD structured grids with a single FEM """

    N = len(grids)
    HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)]
    RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples)
    
    actors = []
    for i in range(len(grids)):
        
        # Create mapper
        mapper = vtk.vtkDataSetMapper()
        if vtk.vtkVersion().GetVTKMajorVersion() >5:
            mapper.SetInput(grids[i])
        else:
            mapper.SetInputData(grids[i])
        
        # Create actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().EdgeVisibilityOn()
        if i != 0:
            actor.GetProperty().SetRepresentationToWireframe()
            actor.GetProperty().SetColor(RGB_tuples[i])
        actor.GetProperty().LightingOff()
        actors.append(actor)
        
    # Add FEM Actor to renderer window
    ren = vtk.vtkRenderer()
#    ren.SetBackground(0.3, 0.3, 0.3)
    ren.SetBackground(0.8, 0.8, 0.8)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    
    # Allow user to interact
    istyle = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(istyle)
    

    
    # Add actor
    for actor in actors:
        ren.AddActor(actor)
    
    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()
    
    # Render
    iren.Initialize()
    renWin.Render()
    iren.Start()
 def __init__(self):
     self.renwin = vtk.vtkRenderWindow()
     self.iren = vtk.vtkRenderWindowInteractor()
     self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
     self.renwin.SetInteractor(self.iren)
     self.ren = vtk.vtkRenderer()
     self.renwin.AddRenderer(self.ren)
     self.iren.Initialize()
    def updateContents(self, inputPorts):
        """ updateContents(inputPorts: tuple)
        Updates the cell contents with new vtkRenderer
        
        """
        renWin = self.GetRenderWindow()
        for iHandler in self.iHandlers:
            if iHandler.observer:
                iHandler.observer.vtkInstance.SetInteractor(None)
            iHandler.clear()

        # Remove old renderers first
        oldRenderers = self.getRendererList()
        for renderer in oldRenderers:
            renWin.RemoveRenderer(renderer)
            renderer.SetRenderWindow(None)
        del oldRenderers

        (renderers, renderView, self.iHandlers, iStyle, picker) = inputPorts
        if renderView:
            renderView.vtkInstance.SetupRenderWindow(renWin)
            renderers = [renderView.vtkInstance.GetRenderer()]
        self.renderer_maps = {}
        for renderer in renderers:
            if renderView == None:
                vtkInstance = renderer.vtkInstance
                renWin.AddRenderer(vtkInstance)
                self.renderer_maps[vtkInstance] = renderer.moduleInfo["moduleId"]
            else:
                vtkInstance = renderer
            if hasattr(vtkInstance, "IsActiveCameraCreated"):
                if not vtkInstance.IsActiveCameraCreated():
                    vtkInstance.ResetCamera()
                else:
                    vtkInstance.ResetCameraClippingRange()

        iren = renWin.GetInteractor()
        if picker:
            iren.SetPicker(picker.vtkInstance)

        # Update interactor style
        self.removeObserversFromInteractorStyle()
        if renderView == None:
            if iStyle == None:
                iStyleInstance = vtk.vtkInteractorStyleTrackballCamera()
            else:
                iStyleInstance = iStyle.vtkInstance
            iren.SetInteractorStyle(iStyleInstance)
        self.addObserversToInteractorStyle()

        for iHandler in self.iHandlers:
            if iHandler.observer:
                iHandler.observer.vtkInstance.SetInteractor(iren)
        renWin.Render()

        # Capture window into history for playback
        # Call this at the end to capture the image after rendering
        QCellWidget.updateContents(self, inputPorts)
def vtk_visualize(point_list, view_thresh):
    point_cloud = VtkPointCloud()
    x_thresh = view_thresh[0]
    y_thresh = view_thresh[1]
    z_thresh = view_thresh[2]

    for i in range(len(point_list)):
        point_coords = point_list[i]

        if (point_coords[0] > x_thresh[0]) and (point_coords[0] < x_thresh[1]) and \
                (point_coords[1] > y_thresh[0]) and (point_coords[1] < y_thresh[1]) and \
                (point_coords[2] > z_thresh[0]) and (point_coords[2] < z_thresh[1]):
            color_num = 0.7
        else:
            color_num = -1
        point_cloud.addPoint(point_list[i], color_num)

    # Add the velodyne plane
    for x in np.linspace(-4, 4, 100):
        for y in np.linspace(0, 2, 25):
            tmp_coords = np.array([x, 0, y])
            point_cloud.addPoint(tmp_coords, 1)
    # Add the floor plane
    plane_center = (-4, -4, -0.55)
    normal = (0, 0, 1)
    point1 = ([-4, 10, -0.55])
    point2 = ([4, -4, -0.55])
    point_cloud.addPlane(plane_center, normal, point1, point2)

    # Renderer
    renderer = vtk.vtkRenderer()
    renderer.AddActor(point_cloud.point_vtkActor)
    renderer.AddActor(point_cloud.plane_vtkActor)

    renderer.SetBackground(0.0, 0.0, 0.0)
    renderer.ResetCamera()

    # Render Window
    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(renderer)

    # Interactor
    render_window_interactor = vtk.vtkRenderWindowInteractor()
    render_window_interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    render_window_interactor.SetRenderWindow(render_window)

    '''Add camera coordinates'''
    axes = vtk.vtkAxesActor()
    widget = vtk.vtkOrientationMarkerWidget()
    widget.SetOutlineColor(0.9300, 0.5700, 0.1300)
    widget.SetOrientationMarker(axes)
    widget.SetInteractor(render_window_interactor)
    widget.SetViewport(0.0, 0.0, 0.4, 0.4)
    widget.SetEnabled(1)
    widget.InteractiveOn()
    render_window.Render()
    render_window_interactor.Start()
Beispiel #55
0
    def __init__(self):

        self.scene = Scene()
        self.frame = MainWindow(self.scene)

        self.camera_style = vtk.vtkInteractorStyleTrackballCamera()
        self.camera_style.AddObserver('LeftButtonPressEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('LeftButtonReleaseEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('MiddleButtonPressEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('MiddleButtonReleaseEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('RightButtonPressEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('RightButtonReleaseEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('MouseWheelForwardEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('MouseWheelBackwardEvent',
                                      self.bimodal_mouse_handler)
        self.camera_style.AddObserver('KeyPressEvent', lambda a, b: None)

        self.actor_style = vtk.vtkInteractorStyleTrackballActor()
        self.actor_style.AddObserver('LeftButtonPressEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('LeftButtonReleaseEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('MiddleButtonPressEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('MiddleButtonReleaseEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('RightButtonPressEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('RightButtonReleaseEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('MouseWheelForwardEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('MouseWheelBackwardEvent',
                                     self.bimodal_mouse_handler)
        self.actor_style.AddObserver('KeyPressEvent', lambda a, b: None)

        self.frame.iren.SetInteractorStyle(self.camera_style)
        self.frame.iren.AddObserver('KeyPressEvent', self.keypress_handler)
        self.frame.ren.SetBackground(name_to_rgb_float(MAIN_WIN_BG_COLOR))
        self.scene.frame = self.frame

        axes = vtk.vtkAxes()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(axes.GetOutputPort())
        self.frame.axes_actor = vtk.vtkActor()
        self.frame.axes_actor.SetMapper(mapper)
        self.frame.axes_actor.GetProperty().SetLineWidth(1)
        self.frame.axes_actor.SetVisibility(START_WITH_AXES)
        self.frame.ren.AddActor(self.frame.axes_actor)
Beispiel #56
0
 def setup_pipeline(self):
     self.renderer = vtk.vtkRenderer()
     self.render_window.AddRenderer(self.renderer)
     self.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
     self.render_window.SetInteractor(self.interactor)
     self.renderer.SetBackground(0.2,0.2,0.2)
     camara = self.renderer.GetActiveCamera()
     camara.SetPosition(0,1,0)
     camara.SetFocalPoint(1,0,0)
     camara.SetViewUp(0,0,-1)
Beispiel #57
0
 def SetInteractor(self, iact):
     self.delegate.SetInteractor(iact)
     
     self.viewInteractorStyle = vtkInteractorStyleTrackballCamera()
     iact.SetInteractorStyle(self.viewInteractorStyle)
     
     self.leftClickObserverId = iact.AddObserver(
         "LeftButtonPressEvent", self.HandleLeftClick
         )
     return
Beispiel #58
0
    def __init__( self, parent, imode_callback, rmode_callback, ppos_callback, ao, **kwargs ):
        # initialize Panel
        if 'id' not in kwargs:
            kwargs['id'] = wx.ID_ANY
        wx.Panel.__init__( self, parent, **kwargs )

        self.setInteractionMode = imode_callback
        self.setInteractionMode(True)
        
        self.recordingMode = False
        self.setRecordingMode = rmode_callback
        self.setRecordingMode(False)
        
        self.setPickerPos = ppos_callback
        
        self.ao = ao
        self.aa = False
        self.firstRender = True

        self.vtkWidget = wxVTKRenderWindowInteractor(self, wx.ID_ANY)
        self.iren = self.vtkWidget._Iren
        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
        
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(0,0,0)
        self.imageLayer = {}
        self.CISID = -1  # Current Image Set ID
        self.imageLayer[self.CISID] = IBCRenderer(self.renderer, self.iren.Render)
        self.bacteriaLayer = BacteriaLayer(self.renderer, self.iren.Render)
        
        self.viewCamActive = True
        
        # for interactive clipping
        self.planes = vtk.vtkPlanes()
        
        self.ellipsoid = None
        self.ellipsoidTextActor = None
        
        # The SetInteractor method is how 3D widgets are associated with the
        # render window interactor. Internally, SetInteractor sets up a bunch
        # of callbacks using the Command/Observer mechanism (AddObserver()).
        self.boxWidget = vtk.vtkBoxWidget()
        self.boxWidget.SetInteractor(self.iren)
        self.boxWidget.SetPlaceFactor(1.0)

        # init vtk window
        self.vtkWidget.Enable(1)
        self.vtkWidget.AddObserver("ExitEvent", lambda o,e,f=parent: f.Close())
        self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer)
        
        # Bind VTK events
        self.iren.AddObserver("KeyPressEvent", self.OnKeyDown)
        
        self.Sizer = wx.BoxSizer()
        self.Sizer.Add(self.vtkWidget, 1, wx.EXPAND)
	def __init__(self):
		super(RenderWidget, self).__init__()

		# Default volume renderer
		self.renderer = vtkRenderer()
		self.renderer.SetBackground2(0.4, 0.4, 0.4)
		self.renderer.SetBackground(0.1, 0.1, 0.1)
		self.renderer.SetGradientBackground(True)
		self.renderer.SetLayer(0)

		# Overlay renderer which is synced with the default renderer
		self.rendererOverlay = vtkRenderer()
		self.rendererOverlay.SetLayer(1)
		self.rendererOverlay.SetInteractive(0)
		self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras)

		self.rwi = QVTKRenderWindowInteractor(parent=self)
		self.rwi.SetInteractorStyle(vtkInteractorStyleTrackballCamera())
		self.rwi.GetRenderWindow().AddRenderer(self.renderer)
		self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay)
		self.rwi.GetRenderWindow().SetNumberOfLayers(2)
		self.rwi.SetDesiredUpdateRate(0)

		self.imagePlaneWidgets = [vtkImagePlaneWidget() for i in range(3)]
		for index in range(3):
			self.imagePlaneWidgets[index].DisplayTextOn()
			self.imagePlaneWidgets[index].SetInteractor(self.rwi)
			# Disable the margin for free rotation
			self.imagePlaneWidgets[index].SetMarginSizeX(0.0)
			self.imagePlaneWidgets[index].SetMarginSizeY(0.0)

		self.mapper = vtkOpenGLGPUVolumeRayCastMapper()
		self.mapper.SetAutoAdjustSampleDistances(1)
		self.volume = None
		self.imageData = None
		self.VolumeVisualization = None
		self.shouldResetCamera = False
		self.gridItems = []
		self.orientationGridItems = []

		self.clippingBox = ClippingBox()
		self.clippingBox.setWidget(self)

		# Keep track of the base and user transforms
		self.baseTransform = vtkTransform()
		self.userTransform = vtkTransform()

		self.setMinimumWidth(340)
		self.setMinimumHeight(340)

		layout = QGridLayout(self)
		layout.setSpacing(0)
		layout.setContentsMargins(0, 0, 0, 0)
		layout.addWidget(self.rwi, 0, 0)
		self.setLayout(layout)
Beispiel #60
0
def PlotEdges(mesh, angle):
    featureEdges = vtk.vtkFeatureEdges()
    if vtk.vtkVersion().GetVTKMajorVersion() >5:
        featureEdges.SetInputData(mesh)
    else:
        featureEdges.SetInput(mesh)
    featureEdges.FeatureEdgesOn()
    featureEdges.BoundaryEdgesOff()
    featureEdges.NonManifoldEdgesOff()
    featureEdges.ManifoldEdgesOff()
    featureEdges.SetFeatureAngle(angle)
    
    
    edgeMapper = vtk.vtkPolyDataMapper();
    edgeMapper.SetInputConnection(featureEdges.GetOutputPort());
    
    edgeActor = vtk.vtkActor();
    edgeActor.GetProperty().SetLineWidth(5);
    edgeActor.SetMapper(edgeMapper)
    
    
    mapper = vtk.vtkDataSetMapper()
    if vtk.vtkVersion().GetVTKMajorVersion() >5:
        mapper.SetInputData(mesh)
    else:
        mapper.SetInput(mesh)

    
    # Actor
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().LightingOff()    
        
    ###############################
    # Display
    ###############################
    
    # Render
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    
    # Allow user to interact
    istyle = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(istyle)
    
    ren.AddActor(actor)
    ren.AddActor(edgeActor)
    
        
    iren.Initialize()
    renWin.Render()
    iren.Start()