Example #1
0
    def draw(self):

        # Update location and movement
        self.update()

        # create a rendering window and renderer
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetSize(1200, 900)
        renWin.AddRenderer(ren)

        # Create camera
        camera = vtk.vtkCamera()
        #camera.SetPosition(0.5,10.0,0.0);
        #camera.Roll(-90)
        #ren.SetActiveCamera(camera)

        # create a renderwindowinteractor
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        # Add actors
        ren.AddActor(self.modelActor)
        ren.AddActor(self.axesActor)

        # enable user interface interactor
        iren.Initialize()
        renWin.Render()
        style = vtk.vtkInteractorStyleMultiTouchCamera()
        iren.SetInteractorStyle(style)
        iren.Start()
Example #2
0
 def __init__(self):
     super().__init__()
     # WIDGET
     self._widget = QWidget(self)
     self._widget.setAttribute(Qt.WA_TranslucentBackground)
     self.setCentralWidget(self._widget)
     self.resize(900, 900)
     self._widget.event = types.MethodType(self._handle_event, self._widget)
     self._widget.setAttribute(Qt.WA_AcceptTouchEvents)  # 与半透明分开设置
     # VTK
     self._vtk_widget = QVTKRenderWindowInteractor(self._widget)
     self._vtk_widget.resize(900, 900)
     self._ren_win = self._vtk_widget.GetRenderWindow()
     self._ren_win.GetInteractor().SetInteractorStyle(
         vtk.vtkInteractorStyleMultiTouchCamera())
     self._renderer = vtk.vtkOpenGLRenderer()
     self._renderer.SetBackground((0, 0, 0))
     self._renderer.AddActor(self._axis_actor())
     self._ren_win.AddRenderer(self._renderer)
     self._vtk_widget.Start()
     # BUTTON WIDGET
     widget = QWidget(self._widget)
     widget.resize(200, 200)
     widget.setStyleSheet('QWidget {background: red}')
     widget.setToolTip('button test')
     widget.show()
     button = QPushButton(widget)
     button.setStyleSheet('QPushButton {background: blue}')
     button.setText('test')
     button.clicked.connect(lambda: print('clicked'))
     button.show()
    def __init__(self):
        super().__init__()
        self._vtk_widget = QVTKRenderWindowInteractor()
        self._renderer = vtk.vtkRenderer()
        self._renderer_win = self._vtk_widget.GetRenderWindow()
        self._renderer_win.AddRenderer(self._renderer)
        self._renderer_win.GetInteractor().SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera())

        self._renderer_win.GetInteractor().AddObserver('TimerEvent', self._render_timer)
        self._renderer_win.GetInteractor().CreateRepeatingTimer(1000)

        self._renderer.AddActor(self.axes())
        self._renderer_win.GetInteractor().Initialize()
        self._vtk_widget.Start()
        self._vtk_widget.showFullScreen()

        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
        self.move(20, int((QApplication.primaryScreen().size().height() - self.size().height()) / 2) ) # 距离左侧20中心

        self._ui.btn_add_sphere.clicked.connect(lambda: self._renderer.AddActor(self.sphere_actor()))
        self._ui.btn_quit.clicked.connect(self.exit)
        self._ui.btn_add_line.clicked.connect(lambda: self._renderer.AddActor(self.line()))
        # self._ui.btn_remove_line.clicked.connect(lambda: self._renderer.RemoveActor(self.sphere_actor()))
        self._ui.btn_remove_line.clicked.connect(lambda: self._renderer.AddActor(self.remove_line()))
        self._line = None
Example #4
0
    def vtk_show(actors):
        ren = vtk.vtkRenderer()
        ren.UseHiddenLineRemovalOn()
        ren_win = vtk.vtkRenderWindow()
        ren_win.AddRenderer(ren)
        i_ren = vtk.vtkRenderWindowInteractor()
        i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera())
        i_ren.SetRenderWindow(ren_win)

        i_ren.AddObserver('TimerEvent', timer)
        i_ren.CreateRepeatingTimer(1)

        if actors.__class__ in [
                vtk.vtkActor, vtk.vtkAxesActor, vtk.vtkAssembly
        ]:
            ren.AddActor(actors)
        elif actors.__class__ is list:
            for actor in actors:
                ren.AddActor(actor)
        ren_win.SetSize(1800, 1800)
        # ren_win.Render()
        i_ren.Initialize()
        i_ren.Start()
        i_ren.Initialize()
        i_ren.Start()
Example #5
0
 def __init__(self):
     super().__init__()
     # WINDOW
     self._widget = QWidget(self)
     self._widget.resize(500, 500)
     self.resize(500, 500)
     self.setCentralWidget(self._widget)
     self._widget.setAttribute(Qt.WA_AcceptTouchEvents
                               | Qt.WA_TranslucentBackground)
     self._widget.setWindowFlags(Qt.NoDropShadowWindowHint)
     # VTK
     self._vtk_widget = QVTKRenderWindowInteractor(self._widget)
     self._vtk_widget.SetInteractorStyle(
         vtk.vtkInteractorStyleMultiTouchCamera())
     self._vtk_widget.resize(500, 500)
     # WIDGET
     self._widget1 = QWidget(self._widget)
     self._widget1.resize(100, 100)
     self._widget1.setStyleSheet(
         'background-color: rgba(120, 120, 120, 100)')
     self._widget1.move(100, 100)
     self._test_btn1 = QPushButton('jaiodhjiajd1', self._widget1)
     self._test_btn1.resize(70, 30)
     self._test_btn1.move(50, 30)
     self._test_btn1.show()
     self._widget2 = QWidget(self._widget)
     self._widget2.resize(100, 100)
     self._widget2.setStyleSheet(
         'background-color: rgba(120, 120, 120, 100)')
     self._test_btn2 = QPushButton('sdoijajdiada', self._widget2)
     self._test_btn2.resize(70, 30)
     self._test_btn2.move(50, 50)
     self._widget2.move(150, 150)
     self._widget2.show()
     # UI
     self._btn = QPushButton('btn1', self._widget)
     self._btn.resize(30, 30)
     self._btn.move(300, 280)
     self._btn.clicked.connect(self._set_widget1_visible)
     self._btn.show()
     self._btn2 = QPushButton('btn2', self._widget)
     self._btn2.resize(30, 30)
     self._btn2.move(300, 300)
     self._btn2.clicked.connect(self._set_widget2_visible)
     self._btn2.show()
     # ATTR
     self._a = False
     self._b = False
     # RENDER
     self._render = vtk.vtkRenderer()
     self._ren_win = self._vtk_widget.GetRenderWindow()
     self._render.AddActor(self.axes())
Example #6
0
    def __init__(self):
        super().__init__()
        # SIGNAL
        self._nuc = GuideRemote()
        self._nuc.sign_data.connect(self._data)
        self._nuc.sign_event.connect(self._event)
        self._nuc.sign_error.connect(self._error)

        # DATA
        self._lines = dict()
        self._lines[1] = OneLine([1, 0, 0], 3)
        self._lines[2] = OneLine([0, 0, 1], 3)
        self._lines[1].set_points([0.72, 0.63, 0.0], [0.72, 0.63, 4.8])
        self._lines[2].set_points([7.0, 0.63, 0.0], [7.0, 0.63, 4.8])

        # VTK
        self._vtk_widget = QVTKRenderWindowInteractor()
        self._render = vtk.vtkRenderer()
        self._render.AddActor(self._lines[1].actor)
        self._render.AddActor(self._lines[2].actor)
        self._render.SetBackground(1, 1, 1)
        self._ren_win = self._vtk_widget.GetRenderWindow()
        self._ren_win.AddRenderer(self._render)
        self._ren_win.GetInteractor().SetInteractorStyle(
            vtk.vtkInteractorStyleMultiTouchCamera())

        # TIMER
        self._ren_win.GetInteractor().AddObserver('TimerEvent',
                                                  self._render_timer)
        self._ren_win.GetInteractor().CreateRepeatingTimer(10)

        # QT
        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
                            | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Tool)
        self.setWindowOpacity(1)
        self.move(20, (QApplication.primaryScreen().size().height() -
                       self.size().height()) / 2)

        # LAUNCH
        self._ren_win.SetSize(700, 700)
        self._vtk_widget.Start()
        self._vtk_widget.showFullScreen()

        # QT BTN
        self._ui.tcp_works.stateChanged.connect(self._set_tcp_launch)
        self._ui.btn_quit.clicked.connect(self.exit)
Example #7
0
 def __init__(self):
     super().__init__()
     self._vtk_widget = QVTKRenderWindowInteractor()
     self._ren = vtk.vtkRenderer()
     self._ren_win = self._vtk_widget.GetRenderWindow()
     self._ren_win.AddRenderer(self._ren)
     self._ren_win.GetInteractor().SetInteractorStyle(
         vtk.vtkInteractorStyleMultiTouchCamera())
     self._ren_win.GetInteractor().AddObserver('TimerEvent',
                                               self._render_timer)
     self._ren_win.GetInteractor().CreateRepeatingTimer(100)
     # ADD ACTOR
     self._ren.AddActor(self.axes())
     self._ren_win.GetInteractor().Initialize()
     self._ren.SetTexturedBackground(True)
     # self._ren.SetBackgroundTexture()
     self._vtk_widget.Start()
     self._vtk_widget.showFullScreen()
     # UI
     self._ui = Ui_MainWindow()
     self._ui.setupUi(self)
     self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
                         | Qt.NoDropShadowWindowHint)
     self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
     self.move(20,
               int((QApplication.primaryScreen().size().height() -
                    self.size().height()) / 2))  # 距离左侧20中心
     # TEXT
     self._txt = Text(color=(1, 0, 0), size=250, bold=True)
     self._txt.set_input('forward')
     self._txt1 = Text(color=(0, 1, 0), size=150, bold=True)
     self._txt1.set_font_pos(500, 500)
     self._txt1.set_input('I am your dad')
     self._ren.AddActor(self._txt1.txt)
     win_size = self._vtk_widget.GetSize()
     self._txt.set_font_pos(int(win_size[0] / 2),
                            int(win_size[1] / 2 + 200))  # 设置字体在屏幕中间
     # BTN
     self._ui.btn_stop.clicked.connect(self.exit)
     self._ui.btn_welcome.clicked.connect(
         lambda: self._txt.set_input('welcome'))
     self._ui.btn_forward.clicked.connect(
         lambda: self._txt.set_input('forward'))
     self._ui.btn_back.clicked.connect(lambda: self._txt.set_input('back'))
     self._ui.btn_add_text.clicked.connect(
         lambda: self._ren.AddActor(self._txt.txt))
     self._ui.btn_del_text.clicked.connect(
         lambda: self._ren.RemoveActor(self._txt.txt))
     # SIGNAL
     signal.signal(signal.SIGINT, self.closeEvent)
Example #8
0
def vtk_show(actor_list):
    ren1 = vtk.vtkRenderer()
    ren1.UseHiddenLineRemovalOn()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera())
    iren.SetRenderWindow(renWin)
    for actor in actor_list:
        ren1.AddActor(actor)
    renWin.SetSize(1800, 1800)
    iren.Initialize()
    renWin.Render()
    iren.Start()
Example #9
0
    def drawVTK(self, drawAxis = True, actorsToAdd = None, animate = False):

        # Update joints
        self.JointList[-1].update()

        # create a rendering window and renderer
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetSize(1200, 900)
        renWin.AddRenderer(ren)

        # Create camera
        camera = vtk.vtkCamera()
        #camera.SetPosition(0.5,10.0,0.0);
        #camera.Roll(-90)
        #ren.SetActiveCamera(camera)

        # create a renderwindowinteractor
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        # Add actors

        for j in self.JointList[1::]:
            ren.AddActor(j.modelActor)
            if drawAxis:
                ren.AddActor(j.axesActor)

        # Axes for world
        ren.AddActor(self.JointList[0].axesActor)

        # Added Actors
        if actorsToAdd is not None:
            for a in actorsToAdd:
                ren.AddActor(a)

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

        if animate:
            iren.AddObserver('TimerEvent', self.animationCallBack)
            timerId = iren.CreateRepeatingTimer(100);


        style = vtk.vtkInteractorStyleMultiTouchCamera()
        iren.SetInteractorStyle(style)
        iren.Start()
Example #10
0
 def vtk_show(actors):
     ren = vtk.vtkRenderer()
     ren.UseHiddenLineRemovalOn()
     ren_win = vtk.vtkRenderWindow()
     ren_win.AddRenderer(ren)
     i_ren = vtk.vtkRenderWindowInteractor()
     i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera())
     i_ren.SetRenderWindow(ren_win)
     if actors.__class__ in [vtk.vtkActor, vtk.vtkAxesActor]:
         ren.AddActor(actors)
     elif actors.__class__ is list:
         for actor in actors:
             ren.AddActor(actor)
     ren_win.SetSize(1800, 1800)
     ren_win.Render()
     i_ren.Initialize()
     i_ren.Start()
     i_ren.Initialize()
     i_ren.Start()
Example #11
0
    def __init__(self):
        super().__init__()
        # DATA
        self._lines = dict()
        self._lines[1] = OneLine((1, 0, 0), 3)
        self._lines[2] = OneLine((0, 0, 1), 3)
        self._lines[1].set_points([0.72, 0.63, 0.0], [0.72, 0.63, 5.0])
        self._lines[2].set_points([7.0, 0.63, 0.0], [7.0, 0.63, 5.0])

        # VTK
        self._vtk_widget = QVTKRenderWindowInteractor()
        self._renderer = vtk.vtkRenderer()
        self._renderer.AddActor(self._lines[1].actor)
        self._renderer.AddActor(self._lines[2].actor)
        self._ren_win = self._vtk_widget.GetRenderWindow()
        self._ren_win.AddRenderer(self._renderer)
        self._ren_win.GetInteractor().SetInteractorStyle(
            vtk.vtkInteractorStyleMultiTouchCamera())

        # TIMER
        self._ren_win.GetInteractor().AddObserver('TimerEvent',
                                                  self._render_timer)
        self._ren_win.GetInteractor().CreateRepeatingTimer(10)

        # QT
        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
                            | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
        self.move(20, (QApplication.primaryScreen().size().height() -
                       self.size().height()) / 2)
        self._ui.btn_quit.clicked.connect(self.exit)

        # LAUNCH
        self._ren_win.SetSize(700, 700)
        self._vtk_widget.Start()
        self._vtk_widget.showFullScreen()

        # THREAD
        self._thread = threading.Thread(target=self._working)
        self._thread.daemon = True
        self._thread.start()
Example #12
0
    def __init__(self):
        super().__init__()
        self._vtk_widget = QVTKRenderWindowInteractor()
        self._renderer = vtk.vtkRenderer()
        self._renderer_win = self._vtk_widget.GetRenderWindow()
        self._renderer_win.AddRenderer(self._renderer)
        self._renderer_win.GetInteractor().SetInteractorStyle(
            vtk.vtkInteractorStyleMultiTouchCamera())
        # self._vtk_widget.SetInteractorStyle(MyEvent())

        self._renderer.AddActor(self.axes())
        self._renderer_win.GetInteractor().Initialize()
        self._vtk_widget.Start()
        self._vtk_widget.showFullScreen()

        # axesActor = vtk.vtkAxesActor()
        # axes = vtk.vtkOrientationMarkerWidget()
        # axes.SetOrientationMarker(axesActor)
        # axes.SetInteractor(self._vtk_widget)
        # axes.EnabledOn()
        # axes.InteractiveOn()

        self._screen_size = QApplication.primaryScreen().size()

        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self.resize(self._screen_size)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
                            | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
        self.move(20,
                  int((QApplication.primaryScreen().size().height() -
                       self.size().height()) / 2))  # 距离左侧20中心

        self._ui.btn_add_sphere.clicked.connect(
            lambda: self._renderer.AddActor(self.sphere_actor()))
        self._ui.btn_quit.clicked.connect(self.exit)
        self._ui.btn_add_line.clicked.connect(
            lambda: self._renderer.AddActor(self.line()))
        self._ui.btn_remove_line.clicked.connect(
            lambda: self._renderer.AddActor(self.remove_line()))
Example #13
0
    def __init__(self):
        super().__init__()

        self.points = vtk.vtkPoints()

        self._vtk_widget = QVTKRenderWindowInteractor()
        self._render = vtk.vtkRenderer()
        self._render.AddActor(self.points_actor())
        self._render.SetBackground(0, 0, 0)
        self._ren_win = self._vtk_widget.GetRenderWindow()
        self._ren_win.AddRenderer(self._render)
        self._ren_win.GetInteractor().SetInteractorStyle(
            vtk.vtkInteractorStyleMultiTouchCamera())

        self._ren_win.GetInteractor().AddObserver('TimerEvent',
                                                  self._render_timer)
        self._ren_win.GetInteractor().CreateRepeatingTimer(10)

        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
                            | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)  # 半透明
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Tool)
        self.setWindowOpacity(1)
        self.move(20, (QApplication.primaryScreen().size().height() -
                       self.size().height()) / 2)

        self._thread = threading.Thread(target=self._working)
        self._thread_switch = False
        self._thread.daemon = True
        self._thread.start()

        self._ren_win.SetSize(700, 700)
        self._vtk_widget.Start()
        self._vtk_widget.showFullScreen()

        self._ui.btn_quit.clicked.connect(self.quit)
Example #14
0
    def __init__(self, parent=None):
        super(VTKBackPlot, self).__init__(parent)
        LOG.debug("---------using refactored vtk code")

        self._datasource = LinuxCncDataSource()

        self.parent = parent
        self.ploter_enabled = True
        self.touch_enabled = False
        self.program_view_when_loading_program = False
        self.program_view_when_loading_program_view = 'p'
        self.pan_mode = False
        self.line = None
        self._last_filename = str()
        self.rotating = 0
        self.panning = 0
        self.zooming = 0

        # assume that we are standing upright and compute azimuth around that axis
        self.natural_view_up = (0, 0, 1)

        # properties
        self._background_color = QColor(0, 0, 0)
        self._background_color2 = QColor(0, 0, 0)
        self._enableProgramTicks = True

        self._default_traverse_color = QColor(200, 35, 35, 255)
        self._default_arcfeed_color = QColor(110, 110, 255, 255)
        self._default_feed_color = QColor(210, 210, 255, 255)
        self._default_dwell_color = QColor(0, 0, 255, 255)
        self._default_user_color = QColor(0, 100, 255, 255)

        self._traverse_color = self._default_traverse_color
        self._arcfeed_color = self._default_arcfeed_color
        self._feed_color = self._default_feed_color
        self._dwel_color = self._default_dwell_color
        self._user_color = self._default_user_color

        self.active_wcs_index = self._datasource.getActiveWcsIndex()
        self.wcs_offsets = self._datasource.getWcsOffsets()
        self.active_wcs_offset = self._datasource.getActiveWcsOffsets()
        self.g92_offset = self._datasource.getG92_offset()

        LOG.debug("---------active_wcs_index {}".format(self.active_wcs_index))
        LOG.debug("---------active_wcs_offset {}".format(self.active_wcs_offset))
        LOG.debug("---------wcs_offsets {}".format(self.wcs_offsets))

        self.original_g5x_offset = [0.0] * NUMBER_OF_WCS
        self.original_g92_offset = [0.0] * NUMBER_OF_WCS

        self.spindle_position = (0.0, 0.0, 0.0)
        self.spindle_rotation = (0.0, 0.0, 0.0)
        self.tooltip_position = (0.0, 0.0, 0.0)

        self.camera = vtk.vtkCamera()
        self.camera.ParallelProjectionOn()

        if self._datasource.isMachineMetric():
            self.position_mult = 1000 #500 here works for me
            self.clipping_range_near = 0.01
            self.clipping_range_far = 10000.0 #TODO: check this value
        else:
            self.position_mult = 100
            self.clipping_range_near = 0.001
            self.clipping_range_far = 1000.0 #TODO: check this value

        self.camera.SetClippingRange(self.clipping_range_near, self.clipping_range_far)
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetActiveCamera(self.camera)

        self.renderer_window = self.GetRenderWindow()
        self.renderer_window.AddRenderer(self.renderer)

        # self.nav_style = vtk.vtkInteractorStyleTrackballCamera()
        self.nav_style = vtk.vtkInteractorStyleMultiTouchCamera() if self.touch_enabled else None

        self.interactor = self.renderer_window.GetInteractor()
        self.interactor.SetInteractorStyle(self.nav_style)
        self.interactor.SetRenderWindow(self.renderer_window)

        if not IN_DESIGNER:

            self.machine_actor = MachineActor(self._datasource)
            self.machine_actor.SetCamera(self.camera)

            self.axes_actor = AxesActor(self._datasource)

            LOG.debug("---------translate1: {}".format(self.active_wcs_offset[:3]))
            LOG.debug("---------active_wcs_offset: {}".format(self.active_wcs_offset))

            transform = vtk.vtkTransform()
            transform.Translate(*self.active_wcs_offset[:3])
            transform.RotateZ(self.active_wcs_offset[9])
            self.axes_actor.SetUserTransform(transform)

            self.path_cache_actor = PathCacheActor(self.tooltip_position)
            
            self.spindle_model = self._datasource._inifile.find("DISPLAY", "SPINDLE")
            
            if self.spindle_model is not None:
                self.spindle_actor = SpindleActor(self._datasource, self.spindle_model)
                
            self.tool_actor = ToolActor(self._datasource)
            self.tool_offset_actor = ToolOffsetActor(self._datasource)

            self.offset_axes = OrderedDict()
            self.program_bounds_actors = OrderedDict()
            self.show_program_bounds = bool()

            # Add the observers to watch for particular events. These invoke Python functions.
            self.interactor.AddObserver("LeftButtonPressEvent", self.button_event)
            self.interactor.AddObserver("LeftButtonReleaseEvent", self.button_event)
            self.interactor.AddObserver("MiddleButtonPressEvent", self.button_event)
            self.interactor.AddObserver("MiddleButtonReleaseEvent", self.button_event)
            self.interactor.AddObserver("RightButtonPressEvent", self.button_event)
            self.interactor.AddObserver("RightButtonReleaseEvent", self.button_event)
            self.interactor.AddObserver("MouseMoveEvent", self.mouse_move)
            self.interactor.AddObserver("KeyPressEvent", self.keypress)
            self.interactor.AddObserver("MouseWheelForwardEvent", self.mouse_scroll_forward)
            self.interactor.AddObserver("MouseWheelBackwardEvent", self.mouse_scroll_backward)

            self.interactor.Initialize()
            self.renderer_window.Render()
            self.interactor.Start()

            # Add the observers to watch for particular events. These invoke Python functions.
            self._datasource.programLoaded.connect(self.load_program)
            self._datasource.positionChanged.connect(self.update_position)
            self._datasource.motionTypeChanged.connect(self.motion_type)
            self._datasource.g5xOffsetChanged.connect(self.update_g5x_offset)
            self._datasource.g92OffsetChanged.connect(self.update_g92_offset)
            self._datasource.offsetTableChanged.connect(self.on_offset_table_changed)
            self._datasource.activeOffsetChanged.connect(self.update_active_wcs)
            self._datasource.toolTableChanged.connect(self.update_tool)
            self._datasource.toolOffsetChanged.connect(self.update_tool)
            # self.status.g5x_index.notify(self.update_g5x_index)

            # view settings
            connectSetting('backplot.show-spindle', self.showSpindle)
            connectSetting('backplot.show-grid', self.showGrid)
            connectSetting('backplot.show-program-bounds', self.showProgramBounds)
            # connectSetting('backplot.show-program-labels', self.showProgramLabels)
            # connectSetting('backplot.show-program-ticks', self.showProgramTicks)
            connectSetting('backplot.show-machine-bounds', self.showMachineBounds)
            connectSetting('backplot.show-machine-labels', self.showMachineLabels)
            connectSetting('backplot.show-machine-ticks', self.showMachineTicks)
            connectSetting('backplot.perspective-view', self.viewPerspective)
            connectSetting('backplot.view', self.setView)
            connectSetting('backplot.multitool-colors', self.showMultiColorPath)
Example #15
0
    skinMapper.ScalarVisibilityOff()

    skin = vtk.vtkOpenGLActor()
    skin.SetMapper(skinMapper)
    skin.GetProperty().SetDiffuseColor(colors.GetColor3d(color))
    skin.GetProperty().SetSpecular(.3)
    skin.GetProperty().SetSpecularPower(20)
    return skin


renderer = vtk.vtkOpenGLRenderer()
# renderer.AddActor(extract("Vertebraes", 1))
renderer.AddActor(extract("Pelvis", 3))
renderer.AddActor(extract("Spinal cord", 1))
renderer.AddActor(extract("Discs", 4))
renderer.SetBackground(0, 0, 0)

renderWin = vtk.vtkRenderWindow()
renderWin.AddRenderer(renderer)
renderInteractor = vtk.vtkRenderWindowInteractor()
style = vtk.vtkInteractorStyleMultiTouchCamera()
renderInteractor.SetInteractorStyle(style)
renderInteractor.SetRenderWindow(renderWin)

renderWin.SetSize(400, 400)

# Launching the renderer
renderInteractor.Initialize()
renderWin.Render()
renderInteractor.Start()
Example #16
0
def vis(dicom_path, np_lung, np_fill):
    # Renderers
    viz1, viz2, viz3, viz4, viz5, viz6, viz7 = [Visualize() for i in range(7)]

    # Setting Viewports
    viz1.viz_SetViewport(0.0, 0.502, 0.331, 1.0)
    viz2.viz_SetViewport(0.335, 0.502, 0.664, 1.0)
    viz3.viz_SetViewport(0.668, 0.502, 1.0, 1.0)
    viz4.viz_SetViewport(0.0, 0.0, 0.248, 0.498)
    viz5.viz_SetViewport(0.252, 0.0, 0.498, 0.498)
    viz6.viz_SetViewport(0.502, 0.0, 0.748, 0.498)
    viz7.viz_SetViewport(0.752, 0.0, 1.0, 0.498)

    viz1.viz_SetViewportName('Original Scan', 10, 25)
    viz2.viz_SetViewportName('Segmented Lungs', 10, 25)
    viz3.viz_SetViewportName('Segmented Trachea', 10, 25)
    viz4.viz_SetViewportName('Right lung', 10, 25)
    viz5.viz_SetViewportName('Right trachea', 10, 25)
    viz6.viz_SetViewportName('Left lung', 10, 25)
    viz7.viz_SetViewportName('Left trachea', 10, 25)

    # Setting background
    viz1.viz_SetBackground(1.0, 1.0, 1.0)
    viz2.viz_SetBackground(1.0, 1.0, 1.0)
    viz3.viz_SetBackground(1.0, 1.0, 1.0)
    viz4.viz_SetBackground(1.0, 1.0, 1.0)
    viz5.viz_SetBackground(1.0, 1.0, 1.0)
    viz6.viz_SetBackground(1.0, 1.0, 1.0)
    viz7.viz_SetBackground(1.0, 1.0, 1.0)

    # Getting data
    np_trachea = np_fill - np_lung
    # m_r = np_lung[:, :int(np_lung.shape[1] / 2), :int(np_lung.shape[2] / 2)]
    # m_l = np_lung[:, int(np_lung.shape[1] / 2):, int(np_lung.shape[2] / 2):]
    m_r = np_lung[:, :, :int(np_lung.shape[2] / 2)]
    m_l = np_lung[:, :, int(np_lung.shape[2] / 2):]

    # m_f_r = np_fill[:, :int(np_fill.shape[1] / 2), :int(np_fill.shape[2] / 2)]
    # m_f_l = np_fill[:, int(np_fill.shape[1] / 2):, int(np_fill.shape[2] / 2):]
    m_f_r = np_fill[:, :, :int(np_fill.shape[2] / 2)]
    m_f_l = np_fill[:, :, int(np_fill.shape[2] / 2):]

    # m_pul_r = np_trachea[:, :int(np_trachea.shape[1] / 2), :int(np_trachea.shape[2] / 2)]
    # m_pul_l = np_trachea[:, int(np_trachea.shape[1] / 2):, int(np_trachea.shape[2] / 2):]
    m_pul_r = np_trachea[:, :, :int(np_trachea.shape[2] / 2)]
    m_pul_l = np_trachea[:, :, int(np_trachea.shape[2] / 2):]
    try:
        r_ratio = np.count_nonzero(m_pul_r) / np.count_nonzero(m_r)
    except:
        r_ratio = 0.0
    try:
        l_ratio = np.count_nonzero(m_pul_l) / np.count_nonzero(m_l)
    except:
        l_ratio = 0.0

    r_vol = np.count_nonzero(m_r) / 1000
    l_vol = np.count_nonzero(m_l) / 1000

    viz4.viz_SetViewportName("R Lung volume: {:.5f} cc".format(r_vol), 10, 50)
    viz5.viz_SetViewportName(
        "R Trachea to lung volume ratio: {:.5f}".format(r_ratio), 10, 50)
    viz6.viz_SetViewportName("L Lung volume: {:.5f} cc".format(l_vol), 10, 50)
    viz7.viz_SetViewportName(
        "L Trachea to lung volume ratio: {:.5f}".format(l_ratio), 10, 50)

    # Setting Data
    #viz1.viz_SetData(scan)
    viz1.viz_VisualizeDICOM(dicom_path)
    viz2.viz_SetData(np_lung)
    viz3.viz_SetData(np_trachea)
    viz4.viz_SetData(m_r)
    viz5.viz_SetData(m_pul_r)
    viz6.viz_SetData(m_l)
    viz7.viz_SetData(m_pul_l)

    # Adding color
    #viz1.viz_AddColorFunctionPoint(0, 85/255.0, 0.0, 0.0)
    viz2.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)
    viz3.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)
    viz4.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)
    viz5.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)
    viz6.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)
    viz7.viz_AddColorFunctionPoint(0, 85 / 255.0, 0.0, 0.0)

    # Adding Opacity
    #viz1.viz_AddOpacityFunctionPoint(0, 0.0)
    #viz1.viz_AddOpacityFunctionPoint(255, 1.0)
    #viz1.viz_AddOpacityFunctionPoint(3, 10.0)

    viz2.viz_AddOpacityFunctionPoint(0, 0.0)
    viz2.viz_AddOpacityFunctionPoint(255, 1.0)
    viz2.viz_AddOpacityFunctionPoint(3, 0.2)

    viz3.viz_AddOpacityFunctionPoint(0, 0.0)
    viz3.viz_AddOpacityFunctionPoint(255, 1.0)
    viz3.viz_AddOpacityFunctionPoint(3, 10.0)

    viz4.viz_AddOpacityFunctionPoint(0, 0.0)
    viz4.viz_AddOpacityFunctionPoint(255, 1.0)
    viz4.viz_AddOpacityFunctionPoint(3, 0.2)

    viz5.viz_AddOpacityFunctionPoint(0, 0.0)
    viz5.viz_AddOpacityFunctionPoint(255, 1.0)
    viz5.viz_AddOpacityFunctionPoint(3, 10.0)

    viz6.viz_AddOpacityFunctionPoint(0, 0.0)
    viz6.viz_AddOpacityFunctionPoint(255, 1.0)
    viz6.viz_AddOpacityFunctionPoint(3, 0.2)

    viz7.viz_AddOpacityFunctionPoint(0, 0.0)
    viz7.viz_AddOpacityFunctionPoint(255, 1.0)
    viz7.viz_AddOpacityFunctionPoint(3, 10.0)

    # Setting light
    viz1.viz_SetLighting(1.0, 1.0, 1.0)
    viz2.viz_SetLighting(5.0, 5.0, 5.0)
    viz3.viz_SetLighting(1.0, 1.0, 1.0)
    viz4.viz_SetLighting(10.0, 10.0, 10.0)
    viz5.viz_SetLighting(1.0, 1.0, 1.0)
    viz6.viz_SetLighting(10.0, 10.0, 10.0)
    viz7.viz_SetLighting(1.0, 1.0, 1.0)

    # Final steps for visualizing
    #viz1.viz_visualize()
    viz2.viz_visualize()
    viz3.viz_visualize()
    viz4.viz_visualize()
    viz5.viz_visualize()
    viz6.viz_visualize()
    viz7.viz_visualize()

    # Renderer window
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(viz1.GetRenderer())
    renWin.AddRenderer(viz2.GetRenderer())
    renWin.AddRenderer(viz3.GetRenderer())
    renWin.AddRenderer(viz4.GetRenderer())
    renWin.AddRenderer(viz5.GetRenderer())
    renWin.AddRenderer(viz6.GetRenderer())
    renWin.AddRenderer(viz7.GetRenderer())

    iren = vtk.vtkRenderWindowInteractor()
    #style = vtk.vtkInteractorStyleTrackballActor()
    style = vtk.vtkInteractorStyleMultiTouchCamera()
    iren.SetInteractorStyle(style)
    iren.SetRenderWindow(renWin)
    renWin.SetFullScreen(1)
    renWin.Render()
    iren.Start()
Example #17
0
    actor.GetZAxisCaptionActor2D().SetWidth(0.01)
    return actor


def Cube():
    pass


if __name__ == '__main__':

    camera = vtk.vtkCamera()
    # camera.Yaw(1)
    ren = vtk.vtkRenderer()
    # ren.SetActiveCamera(camera)
    ren_win = vtk.vtkRenderWindow()
    ren_win.AddRenderer(ren)
    i_ren = vtk.vtkRenderWindowInteractor()
    i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera())
    i_ren.SetNumberOfFlyFrames(1)
    # i_ren.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
    i_ren.SetRenderWindow(ren_win)
    style = vtk.vtkInteractorStyle()
    a = style.OnMouseWheelForward()
    b = style.OnRightButtonDown()
    print(a, b)

    ren.AddActor(actor_axis())
    ren_win.SetSize(1800, 1800)
    i_ren.Initialize()
    i_ren.Start()