Пример #1
0
    def __init__( self,  **args ):
        self.labelBuff = ""
        self.textDisplayMgr = None
        self.useGui = args.get( 'gui', True )
        self.renderWindow = args.get( 'renwin', self.createRenderWindow() )
        self.renderWindowInteractor = self.renderWindow.GetInteractor()
        self.renderWindowInteractor.SetInteractorStyle( NavigationInteractorStyle )
        self.cameraOrientation = {}
        self.maxStageHeight = 100.0
        self.observerTargets = set()
        self.xcenter = 100.0
        self.xwidth = 300.0
        self.ycenter = 0.0
        self.ywidth = 180.0
        self.gui_visibility = 0
        
        self.configuring = False
        self.configurationInteractorStyle = vtk.vtkInteractorStyleUser()
        self.activated = False
#        self.buttons = {}
        self.renderWindowSize = None

        self.isAltMode = False
        self.createColormap = True
        self.colormapManagers= {}
        self.colormapWidget = None 
        self.colormapWindowSize = None
        interactionButtons = self.getInteractionButtons()
        interactionButtons.addSliderButton( names=['VerticalScaling'], key='Z', toggle=True, label='Vertical Scaling', sliderLabels='Vertical Scale', interactionHandler=self.processVerticalScalingCommand, range_bounds=[ 0.1, 10.0 ], initValue= 1.0 )
        interactionButtons.addConfigButton( names=['ChooseColormap'], key='m', toggle=True, interactionHandler=self.processChooseColormapCommand, initValue=[ 'jet', False, False ]  )
        interactionButtons.addConfigButton( names=['ToggleClipping'], key='X', toggle=True, parents=['ToggleVolumePlot', 'ToggleSurfacePlot'], interactionHandler=self.processToggleClippingCommand  )
Пример #2
0
    def _BindInteractor(self):

        self.interactor_style = vtk.vtkInteractorStyleUser()

        self._RenderWindowInteractor.SetInteractorStyle(self.interactor_style)

        #obj = self.interactor_style
        obj = self._RenderWindowInteractor

        obj.AddObserver("LeftButtonPressEvent", self._OnButtonPress)
        obj.AddObserver("LeftButtonReleaseEvent", self._OnButtonRelease)

        obj.AddObserver("MiddleButtonPressEvent", self._OnButtonPress)
        obj.AddObserver("MiddleButtonReleaseEvent", self._OnButtonRelease)

        obj.AddObserver("RightButtonPressEvent", self._OnButtonPress)
        obj.AddObserver("RightButtonReleaseEvent", self._OnButtonRelease)

        obj.AddObserver("MouseMoveEvent", self._OnMotion)

        obj.AddObserver("KeyPressEvent", self._OnKeyPress)
        obj.AddObserver("KeyReleaseEvent", self._OnKeyRelease)
        obj.AddObserver("CharEvent", self._OnChar)

        obj.AddObserver("ConfigureEvent", self._OnConfigure)
        obj.AddObserver("EnterEvent", self._OnEnter)
        obj.AddObserver("LeaveEvent", self._OnLeave)

        obj.AddObserver("TimerEvent", self._OnTimer)
Пример #3
0
    def __init__(self, **args):
        self.useDepthPeeling = False
        self.labelBuff = ""
        self.textDisplayMgr = None
        blocking = args.get('blocking', False)
        self.renderWindow = args.get('renwin',
                                     self.createRenderWindow(blocking))
        self.renderWindowInteractor = self.renderWindow.GetInteractor()
        self.renderWindowInteractor.SetInteractorStyle(
            NavigationInteractorStyle)
        self.cameraOrientation = {}
        self.maxStageHeight = 100.0
        self.observerTargets = set()
        self.xcenter = 100.0
        self.xwidth = 300.0
        self.ycenter = 0.0
        self.ywidth = 180.0

        self.configuring = False
        self.configurationInteractorStyle = vtk.vtkInteractorStyleUser()
        self.activated = False
        #        self.buttons = {}
        self.renderWindowSize = None

        self.isAltMode = False
        self.createColormap = True
        self.colormapManagers = {}
        self.colormapWidget = None
        self.colormapWindowSize = None
        interactionButtons = self.getInteractionButtons()
        interactionButtons.addSliderButton(
            names=['VerticalScaling'],
            key='Z',
            toggle=True,
            label='Vertical Scaling',
            sliderLabels='Vertical Scale',
            interactionHandler=self.processVerticalScalingCommand,
            range_bounds=[0.1, 10.0],
            initValue=1.0)
        interactionButtons.addConfigButton(
            names=['ChooseColormap'],
            key='m',
            toggle=True,
            interactionHandler=self.processChooseColormapCommand,
            initValue=['jet', False, False])
        interactionButtons.addConfigButton(
            names=['ToggleClipping'],
            key='X',
            toggle=True,
            parents=['ToggleVolumePlot', 'ToggleSurfacePlot'],
            interactionHandler=self.processToggleClippingCommand)
        interactionButtons.addConfigButton(
            names=['Colorbar'],
            key='b',
            toggle=True,
            label='Show Colorbar',
            interactionHandler=self.processShowColorbarCommand)
Пример #4
0
    def __init__(self, width=1400, height=1000, title='VTK Viewer'):

        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(1.0, 1.0, 1.0)

        self.render_window = vtk.vtkRenderWindow()
        self.render_window.AddRenderer(self.renderer)
        self.render_window.SetSize(width, height)

        self.root = Tkinter.Tk()
        self.root.title(title)
        self.render_window_interactor = vtkTkRenderWindowInteractorNoCharEvent(
            self.root, rw=self.render_window, width=width, height=height)
        self.render_window_interactor.Initialize()
        self.render_window_interactor.pack(fill='both', expand=1)

        self.cam_trackball = vtk.vtkInteractorStyleTrackballCamera()
        self.cam_trackball.SetCurrentRenderer(self.renderer)
        self.render_window_interactor.SetInteractorStyle(self.cam_trackball)
        self.cam_trackball.AddObserver('KeyPressEvent', self.on_key_press)
        self.key_callbacks = {}

        self.act_trackball = vtk.vtkInteractorStyleTrackballActor()
        self.act_trackball.SetCurrentRenderer(self.renderer)
        self.act_trackball.AddObserver('KeyPressEvent', self.on_key_press)
        self.act_trackball.AddObserver('InteractionEvent', self.on_actor_move)
        self.actor_move_callbacks = []

        self.mouse_pick_interactor = vtk.vtkInteractorStyleUser()
        self.mouse_pick_interactor.SetCurrentRenderer(self.renderer)
        self.mouse_pick_interactor.AddObserver('KeyPressEvent',
                                               self.on_key_press)
        self.mouse_pick_interactor.AddObserver('LeftButtonPressEvent',
                                               lambda x, y: self.pick(True))

        self.rubber_band_interactor = vtk.vtkInteractorStyleRubberBand3D()
        self.rubber_band_interactor.SetCurrentRenderer(self.renderer)
        self.rubber_band_interactor.AddObserver('KeyPressEvent',
                                                self.on_key_press)
        self.rubber_band_interactor.AddObserver('SelectionChangedEvent',
                                                self.on_box_select)
        self.box_select_callbacks = []

        # Create pickers
        self.cell_picker = vtk.vtkCellPicker()
        self.cell_picker.AddObserver("EndPickEvent", self.on_pick)
        self.point_picker = vtk.vtkPointPicker()
        self.point_picker.AddObserver("EndPickEvent", self.on_pick)
        self.pick_callbacks = []
Пример #5
0
    def __init__(self):
        super(SliceViewerWidget, self).__init__()

        self.color = [1, 1, 1]

        self.renderer = vtkRenderer()
        self.renderer.SetBackground(0.0, 0.0, 0.0)
        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(vtkInteractorStyleUser())
        self.rwi.GetRenderWindow().AddRenderer(self.renderer)
        self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay)
        self.rwi.GetRenderWindow().SetNumberOfLayers(2)

        # Set camera to parallel
        camera = self.renderer.GetActiveCamera()
        camera.SetParallelProjection(1)

        # Add new observers for mouse wheel
        self.AddObserver(self.rwi, "CharEvent", self.charTyped)
        self.AddObserver(self.rwi, "MouseWheelBackwardEvent",
                         self.mouseWheelChanged)
        self.AddObserver(self.rwi, "MouseWheelForwardEvent",
                         self.mouseWheelChanged)
        self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1)

        self.picker = vtkCellPicker()
        self.picker.SetTolerance(1e-6)

        self.locator = []

        self.setStyleSheet("background-color: #333")

        layout = QGridLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.rwi)
        self.setLayout(layout)
	def __init__(self):
		super(SliceViewerWidget, self).__init__()

		self.color = [1, 1, 1]

		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(vtkInteractorStyleUser())
		self.rwi.GetRenderWindow().AddRenderer(self.renderer)
		self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay)
		self.rwi.GetRenderWindow().SetNumberOfLayers(2)

		# Set camera to parallel
		camera = self.renderer.GetActiveCamera()
		camera.SetParallelProjection(1)

		# Add new observers for mouse wheel
		self.AddObserver(self.rwi, "CharEvent", self.charTyped)
		self.AddObserver(self.rwi, "MouseWheelBackwardEvent", self.mouseWheelChanged)
		self.AddObserver(self.rwi, "MouseWheelForwardEvent", self.mouseWheelChanged)
		self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1)

		self.picker = vtkCellPicker()
		self.picker.SetTolerance(1e-6)

		# Known state of mouse (maybe can ask the event as well...)
		self.leftButtonPressed = False

		self.locator = []

		layout = QGridLayout()
		layout.setSpacing(0)
		layout.setContentsMargins(0, 0, 0, 0)
		layout.addWidget(self.rwi)
		self.setLayout(layout)
Пример #7
0
    def __init__(self, width=1400, height=1000, title='VTK Viewer'):
        
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(1.0, 1.0, 1.0)
        
        self.render_window = vtk.vtkRenderWindow()
        self.render_window.AddRenderer(self.renderer)
        self.render_window.SetSize(width, height)

        self.root = Tkinter.Tk()
        self.root.title(title)
        self.render_window_interactor = vtkTkRenderWindowInteractorNoCharEvent(self.root, rw=self.render_window, width=width, height=height)
        self.render_window_interactor.Initialize()
        self.render_window_interactor.pack(fill='both', expand=1)

        self.cam_trackball = vtk.vtkInteractorStyleTrackballCamera()
        self.cam_trackball.SetCurrentRenderer(self.renderer)
        self.render_window_interactor.SetInteractorStyle(self.cam_trackball)
        self.cam_trackball.AddObserver('KeyPressEvent', self.on_key_press)
        self.key_callbacks = {}

        self.act_trackball = vtk.vtkInteractorStyleTrackballActor()
        self.act_trackball.SetCurrentRenderer(self.renderer)
        self.act_trackball.AddObserver('KeyPressEvent', self.on_key_press)
        self.act_trackball.AddObserver('InteractionEvent', self.on_actor_move)
        self.actor_move_callbacks = []

        self.mouse_pick_interactor = vtk.vtkInteractorStyleUser()
        self.mouse_pick_interactor.SetCurrentRenderer(self.renderer)
        self.mouse_pick_interactor.AddObserver('KeyPressEvent', self.on_key_press)
        self.mouse_pick_interactor.AddObserver('LeftButtonPressEvent', lambda x, y: self.pick(True))

        self.rubber_band_interactor = vtk.vtkInteractorStyleRubberBand3D()
        self.rubber_band_interactor.SetCurrentRenderer(self.renderer)
        self.rubber_band_interactor.AddObserver('KeyPressEvent', self.on_key_press)
        self.rubber_band_interactor.AddObserver('SelectionChangedEvent', self.on_box_select)
        self.box_select_callbacks = []

        # Create pickers
        self.cell_picker = vtk.vtkCellPicker()
        self.cell_picker.AddObserver("EndPickEvent", self.on_pick)
        self.point_picker = vtk.vtkPointPicker()
        self.point_picker.AddObserver("EndPickEvent", self.on_pick)
        self.pick_callbacks = []
	def __init__(self):
		super(SliceCompareViewerWidget, self).__init__()

		self.renderer = vtkRenderer()
		self.renderer.SetBackground(0.0, 0.0, 0.0)
		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(vtkInteractorStyleUser())
		self.rwi.GetRenderWindow().AddRenderer(self.renderer)
		self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay)
		self.rwi.GetRenderWindow().SetNumberOfLayers(2)

		# Set camera to parallel
		camera = self.renderer.GetActiveCamera()
		camera.SetParallelProjection(1)

		# Add new observers for mouse wheel
		self.AddObserver(self.rwi, "CharEvent", self.charTyped)
		self.AddObserver(self.rwi, "MouseWheelBackwardEvent", self.mouseWheelChanged)
		self.AddObserver(self.rwi, "MouseWheelForwardEvent", self.mouseWheelChanged)
		self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1)

		self.picker = vtkCellPicker()
		self.picker.SetTolerance(1e-6)

		self.locator = []

		self.setStyleSheet("background-color: #333")

		layout = QGridLayout()
		layout.setSpacing(0)
		layout.setContentsMargins(0, 0, 0, 0)
		layout.addWidget(self.rwi)
		self.setLayout(layout)
Пример #9
0
    def _BindInteractor(self):

        self.interactor_style = vtk.vtkInteractorStyleUser()

        self._RenderWindowInteractor.SetInteractorStyle(self.interactor_style)

        obj = self.interactor_style

        obj.AddObserver("LeftButtonPressEvent",
                        self._OnButtonPress)
        obj.AddObserver("LeftButtonReleaseEvent",
                        self._OnButtonRelease)

        obj.AddObserver("MiddleButtonPressEvent",
                        self._OnButtonPress)
        obj.AddObserver("MiddleButtonReleaseEvent",
                        self._OnButtonRelease)

        obj.AddObserver("RightButtonPressEvent",
                        self._OnButtonPress)
        obj.AddObserver("RightButtonReleaseEvent",
                        self._OnButtonRelease)

        obj.AddObserver("MouseMoveEvent",
                        self._OnMotion)

        obj.AddObserver("KeyPressEvent",
                        self._OnKeyPress)
        obj.AddObserver("KeyReleaseEvent",
                        self._OnKeyRelease)
        obj.AddObserver("CharEvent", self._OnChar)
        obj.AddObserver("TimerEvent",
                        self._OnTimer)

        # these events bind to the interactor rather than the style
        obj.AddObserver("ConfigureEvent",
                        self._OnConfigure)
        obj.AddObserver("EnterEvent",
                        self._OnEnter)
        obj.AddObserver("LeaveEvent",
                        self._OnLeave)
Пример #10
0
    def __init__(self,
                 width,
                 height,
                 colormap,
                 color,
                 parent_interactor=None,
                 on_save=None,
                 on_cancel=None):
        self.render_window = vtk.vtkRenderWindow()
        self.render_window.SetWindowName("Color Picker")
        self.render_window.SetNumberOfLayers(3)
        self.render_window.SetSize(width, height)
        self.color_renderer = vtk.vtkRenderer()
        self.parent_interactor = parent_interactor

        if colormap is None:
            colormap = "default"
        if not vcs.iscolormap(colormap):
            colormap = vcs.getcolormap(colormap)

        self.colormap = colormap
        self.colors = [[int(c / 100.0 * 255.0) for c in colormap.index[i]]
                       for i in range(len(colormap.index))]

        self.actor = make_color_plane(16, 16, self.colors)

        self.color_renderer.SetViewport([.1, .1, .9, .9])
        self.color_renderer.SetBackground((.5, .5, .5))
        self.color_renderer.AddActor(self.actor)
        self.color_renderer.InteractiveOff()
        self.color_renderer.SetLayer(1)

        bg = vtk.vtkRenderer()
        bg.SetBackground(1, 1, 1)
        bg.SetViewport([0, 0, 1, 1])
        bg.SetLayer(0)
        self.render_window.AddRenderer(bg)
        self.render_window.AddRenderer(self.color_renderer)
        inter = vtk.vtkRenderWindowInteractor()

        self.style = vtk.vtkInteractorStyleUser()
        inter.SetInteractorStyle(self.style)
        inter.SetRenderWindow(self.render_window)
        manager = vcs.vtk_ui.manager.get_manager(inter)
        self.render_window.AddRenderer(manager.renderer)
        self.render_window.AddRenderer(manager.actor_renderer)
        manager.elevate()
        self.render_window.Render()

        self.on_save = on_save
        self.on_cancel = on_cancel

        maps = vcs.elements["colormap"]

        current_state = None
        states = []
        self.colormaps = []
        for ind, mapname in enumerate(maps.keys()):
            states.append(ButtonState(label=mapname))
            if colormap.name == mapname:
                current_state = ind
            self.colormaps.append(maps[mapname])

        self.colormap_button = Button(inter,
                                      states=states,
                                      action=self.change_map,
                                      left=10,
                                      top=10)
        self.colormap_button.set_state(current_state)

        self.save_button = Button(inter,
                                  action=self.save,
                                  label="Choose Color",
                                  left=int(width * .75) - 10,
                                  top=int(height * .85))
        self.cancel_button = Button(inter,
                                    action=self.cancel,
                                    label="Cancel",
                                    left=10,
                                    top=int(height * .85))

        self.colormap_button.show()
        self.save_button.show()
        self.cancel_button.show()

        self.make_current()

        self.selectedMapper = vtk.vtkDataSetMapper()
        self.selectedActor = vtk.vtkActor()
        self.selectedActor.SetMapper(self.selectedMapper)
        self.selectedActor.GetProperty().EdgeVisibilityOn()
        self.selectedActor.GetProperty().SetEdgeColor(0, 0, 0)
        self.selectedActor.GetProperty().SetLineWidth(3)
        self.color = color
        # Make sure the current color is selected
        self.selectCell(color)
        self.color_renderer.AddActor(self.selectedActor)
        self.click_handler = inter.AddObserver(
            vtk.vtkCommand.LeftButtonReleaseEvent, self.clickEvent)

        def noop(obj, event):
            pass

        self.char_handler = inter.AddObserver(vtk.vtkCommand.CharEvent, noop)
Пример #11
0
    def update(self, **kwargs):
        """
        Updates the child results and renders the results.
        """
        super(RenderWindow, self).update(**kwargs)

        # Setup interactor
        if self.isOptionValid('test') and self.getOption('test'):
            self.__vtkwindow.OffScreenRenderingOn()

        elif self.isOptionValid('style'):
            if self.__vtkinteractor is None:
                self.__vtkinteractor = self.__vtkwindow.MakeRenderWindowInteractor(
                )

            style = self.getOption('style').lower()
            self.setOption(
                'style',
                None)  # avoids calling this function unless it changes
            if style == 'interactive':
                b = base.KeyPressInteractorStyle(self.__vtkinteractor)
                self.__vtkinteractor.SetInteractorStyle(b)
            elif style == 'interactive2d':
                self.__vtkinteractor.SetInteractorStyle(
                    vtk.vtkInteractorStyleImage())
            elif style == 'modal':
                self.__vtkinteractor.SetInteractorStyle(
                    vtk.vtkInteractorStyleUser())

        if self.isOptionValid('motion_factor'):
            self.__vtkinteractor.GetInteractorStyle(). \
                SetMotionFactor(self.getOption('motion_factor'))

        # Background settings
        self._results[0].updateOptions(self._options)

        # vtkRenderWindow Settings
        if self.isOptionValid('offscreen'):
            self.__vtkwindow.SetOffScreenRendering(self.getOption('offscreen'))

        if self.isOptionValid('smoothing'):
            smooth = self.getOption('smoothing')
            self.__vtkwindow.SetLineSmoothing(smooth)
            self.__vtkwindow.SetPolygonSmoothing(smooth)
            self.__vtkwindow.SetPointSmoothing(smooth)

        if self.isOptionValid('size'):
            self.__vtkwindow.SetSize(self.getOption('size'))

        self.__vtkwindow.Render()

        # Setup the result objects
        n = self.__vtkwindow.GetNumberOfLayers()
        for result in self._results:
            renderer = result.getVTKRenderer()
            if self.isOptionValid('antialiasing'):
                if VTK_MAJOR_VERSION < 8:
                    self.__vtkwindow.SetAAFrames(
                        self.getOption('antialiasing'))
                else:
                    renderer.SetUseFXAA(True)
                    self.__vtkwindow.SetMultiSamples(
                        self.getOption('antialiasing'))

            if not self.__vtkwindow.HasRenderer(renderer):
                self.__vtkwindow.AddRenderer(renderer)
            if result.needsUpdate():
                result.update()
            n = max(n, renderer.GetLayer() + 1)
        self.__vtkwindow.SetNumberOfLayers(n)

        if (self.__active is None) and len(self._results) > 1:
            self.setActive(self._results[1])

        # Observers
        if self.__vtkinteractor:
            for observer in self.getOption('observers'):
                if not isinstance(observer, observers.ChiggerObserver):
                    msg = "The supplied observer of type {} must be a {} object."
                    raise mooseutils.MooseException(
                        msg.format(type(observer), observers.ChiggerObserver))

                elif not observer.isActive() is None:
                    observer.init(self)

        self.__vtkwindow.Render()
Пример #12
0
    def __init__(self, renderwindowinteractor, renderer):

        self._rwi = renderwindowinteractor
        self._ren = renderer

        # need this to do same mouse capturing as original RWI under Win
        self._rwi_use_capture = \
                vtk.wx.wxVTKRenderWindowInteractor._useCapture

        # we can't switch on Line/Point/Polygon smoothing here,
        # because the renderwindow has already been initialised
        # we do it in main_frame.py right after we create the RWI

        # parent 2 ctor
        SubjectMixin.__init__(self)

        self._cobjects = []
        # dict for mapping from prop back to cobject
        self.prop_to_glyph = {}
        self._previousRealCoords = None
        self._potentiallyDraggedObject = None
        self._draggedObject = None

        
        self._ren.SetBackground(1.0,1.0,1.0)
        self._ren.GetActiveCamera().SetParallelProjection(1)

        # set a sensible initial zoom
        self._zoom(0.004)


        istyle = vtk.vtkInteractorStyleUser()
        #istyle = vtk.vtkInteractorStyleImage()
        self._rwi.SetInteractorStyle(istyle)

        self._rwi.Bind(wx.EVT_RIGHT_DOWN, self._handler_rd)
        self._rwi.Bind(wx.EVT_RIGHT_UP, self._handler_ru)
        self._rwi.Bind(wx.EVT_LEFT_DOWN, self._handler_ld)
        self._rwi.Bind(wx.EVT_LEFT_UP, self._handler_lu)
        self._rwi.Bind(wx.EVT_MIDDLE_DOWN, self._handler_md)
        self._rwi.Bind(wx.EVT_MIDDLE_UP, self._handler_mu)
        self._rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_wheel)
        self._rwi.Bind(wx.EVT_MOTION, self._handler_motion)

        self._rwi.Bind(wx.EVT_LEFT_DCLICK, self._handler_ldc)

        #self._rwi.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
        #self._rwi.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)

        # If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions
        # of all characters are always returned.  EVT_CHAR also performs
        # other necessary keyboard-dependent translations.
        # * we unbind the char handler added by the wxRWI (else alt-w
        # for example gets interpreted as w for wireframe e.g.)
        self._rwi.Unbind(wx.EVT_CHAR)
        self._rwi.Bind(wx.EVT_CHAR, self._handler_char)
        #self._rwi.Bind(wx.EVT_KEY_UP, self.OnKeyUp)



        self._observer_ids = []

        self.event = DeVIDECanvasEvent()
Пример #13
0
    def __init__(self, width, height, colormap, color, parent_interactor=None, on_save=None, on_cancel=None):
        self.render_window = vtk.vtkRenderWindow()
        self.render_window.SetWindowName("Color Picker")
        self.render_window.SetNumberOfLayers(3)
        self.render_window.SetSize(width, height)
        self.color_renderer = vtk.vtkRenderer()
        self.parent_interactor = parent_interactor

        if colormap is None:
            colormap = "default"
        if not vcs.iscolormap(colormap):
            colormap = vcs.getcolormap(colormap)

        self.colormap = colormap
        self.colors =  [[int(c / 100.0 * 255.0) for c in colormap.index[i]] for i in range(len(colormap.index))]

        self.actor = make_color_plane(16, 16, self.colors)

        self.color_renderer.SetViewport([.1, .1, .9, .9])
        self.color_renderer.SetBackground((.5, .5, .5))
        self.color_renderer.AddActor(self.actor)
        self.color_renderer.InteractiveOff()
        self.color_renderer.SetLayer(1)

        bg = vtk.vtkRenderer()
        bg.SetBackground(1,1,1)
        bg.SetViewport([0,0,1,1])
        bg.SetLayer(0)
        self.render_window.AddRenderer(bg)
        self.render_window.AddRenderer(self.color_renderer)
        inter = vtk.vtkRenderWindowInteractor()

        self.style = vtk.vtkInteractorStyleUser()
        inter.SetInteractorStyle(self.style)
        inter.SetRenderWindow(self.render_window)
        manager = vcs.vtk_ui.manager.get_manager(inter)
        self.render_window.AddRenderer(manager.renderer)
        self.render_window.AddRenderer(manager.actor_renderer)
        manager.elevate()
        self.render_window.Render()

        self.on_save = on_save
        self.on_cancel = on_cancel

        maps = vcs.elements["colormap"]

        current_state = None
        states = []
        self.colormaps = []
        for ind, mapname in enumerate(maps.keys()):
            states.append(ButtonState(label=mapname))
            if colormap.name == mapname:
                current_state = ind
            self.colormaps.append(maps[mapname])

        self.colormap_button = Button(inter, states=states, action=self.change_map, left = 10, top=10)
        self.colormap_button.set_state(current_state)

        self.save_button = Button(inter, action=self.save, label="Choose Color", left=int(width * .75) - 10, top=int(height * .85))
        self.cancel_button = Button(inter, action=self.cancel, label="Cancel", left=10, top=int(height * .85))

        self.colormap_button.show()
        self.save_button.show()
        self.cancel_button.show()

        self.make_current()

        self.selectedMapper = vtk.vtkDataSetMapper()
        self.selectedActor = vtk.vtkActor()
        self.selectedActor.SetMapper(self.selectedMapper);
        self.selectedActor.GetProperty().EdgeVisibilityOn();
        self.selectedActor.GetProperty().SetEdgeColor(0,0,0);
        self.selectedActor.GetProperty().SetLineWidth(3);
        self.color = color
        # Make sure the current color is selected
        self.selectCell(color)
        self.color_renderer.AddActor(self.selectedActor)
        self.click_handler = inter.AddObserver(vtk.vtkCommand.LeftButtonReleaseEvent, self.clickEvent)
        def noop(obj, event):
            pass
        self.char_handler = inter.AddObserver(vtk.vtkCommand.CharEvent, noop)
Пример #14
0
    def update(self, **kwargs):
        """
        Updates the child results and renders the results.
        """
        super(RenderWindow, self).update(**kwargs)

        # Setup interactor
        if self.isOptionValid('test') and self.getOption('test'):
            self.__vtkwindow.OffScreenRenderingOn()

        elif self.isOptionValid('style'):
            if self.__vtkinteractor is None:
                self.__vtkinteractor = self.__vtkwindow.MakeRenderWindowInteractor()

            style = self.getOption('style').lower()
            self.setOption('style', None) # avoids calling this function unless it changes
            if style == 'interactive':
                b = base.KeyPressInteractorStyle(self.__vtkinteractor)
                self.__vtkinteractor.SetInteractorStyle(b)
            elif style == 'interactive2d':
                self.__vtkinteractor.SetInteractorStyle(vtk.vtkInteractorStyleImage())
            elif style == 'modal':
                self.__vtkinteractor.SetInteractorStyle(vtk.vtkInteractorStyleUser())

        # Background settings
        self._results[0].updateOptions(self._options)

        # vtkRenderWindow Settings
        if self.isOptionValid('offscreen'):
            self.__vtkwindow.SetOffScreenRendering(self.getOption('offscreen'))

        if self.isOptionValid('smoothing'):
            smooth = self.getOption('smoothing')
            self.__vtkwindow.SetLineSmoothing(smooth)
            self.__vtkwindow.SetPolygonSmoothing(smooth)
            self.__vtkwindow.SetPointSmoothing(smooth)

        if self.isOptionValid('antialiasing'):
            self.__vtkwindow.SetAAFrames(self.getOption('antialiasing'))

        if self.isOptionValid('multisamples'):
            self.__vtkwindow.SetMultiSamples(self.getOption('multisamples'))

        if self.isOptionValid('size'):
            self.__vtkwindow.SetSize(self.getOption('size'))

        self.__vtkwindow.Render()

        # Setup the result objects
        n = self.__vtkwindow.GetNumberOfLayers()
        for result in self._results:
            renderer = result.getVTKRenderer()
            if not self.__vtkwindow.HasRenderer(renderer):
                self.__vtkwindow.AddRenderer(renderer)
            if result.needsUpdate():
                result.update()
            n = max(n, renderer.GetLayer() + 1)
        self.__vtkwindow.SetNumberOfLayers(n)

        if (self.__active is None) and len(self._results) > 1:
            self.setActive(self._results[1])

        # Observers
        if self.__vtkinteractor:
            for observer in self.getOption('observers'):
                if not isinstance(observer, observers.ChiggerObserver):
                    msg = "The supplied observer of type {} must be a {} object."
                    raise mooseutils.MooseException(msg.format(type(observer),
                                                               observers.ChiggerObserver))

                elif not observer.isActive() is None:
                    observer.init(self)

        self.__vtkwindow.Render()
Пример #15
0
def wheelBackward(widget, event_string):
    mouseWheelBackward(iRen,ren)

def mouseMove(widget, event_string):
    global left, middle, right
    if left == 1:
        mouseLeftMove(iRen,ren)
    if middle == 1:
        mouseMiddleMove(iRen,ren)
    if right == 1:
        mouseRightMove(iRen,ren)
    if ( (left == 0) and (middle == 0) and (right == 0) ) :
        pass

# This is where the interaction style is defined
style = vtk.vtkInteractorStyleUser()
iRen.SetInteractorStyle(style)

style.AddObserver("LeftButtonPressEvent", leftDown)
style.AddObserver("LeftButtonReleaseEvent", leftUp)
style.AddObserver("MiddleButtonPressEvent", middleDown)
style.AddObserver("MiddleButtonReleaseEvent", middleUp)
style.AddObserver("RightButtonPressEvent", rightDown)
style.AddObserver("RightButtonReleaseEvent", rightUp)
style.AddObserver("MouseWheelForwardEvent", wheelForward)
style.AddObserver("MouseWheelBackwardEvent", wheelBackward)
style.AddObserver("MouseMoveEvent", mouseMove)

iRen.Initialize()
renWin.Render()
Пример #16
0
    def update(self, **kwargs):
        """
        Updates the child results and renders the results.
        """
        super(RenderWindow, self).update(**kwargs)

        # Setup interactor
        if self.isOptionValid('test') and self.getOption('test'):
            self.__vtkwindow.OffScreenRenderingOn()

        elif self.isOptionValid('style'):
            if self.__vtkinteractor is None:
                self.__vtkinteractor = self.__vtkwindow.MakeRenderWindowInteractor()

            style = self.getOption('style').lower()
            self.setOption('style', None) # avoids calling this function unless it changes
            if style == 'interactive':
                b = base.KeyPressInteractorStyle(self.__vtkinteractor)
                self.__vtkinteractor.SetInteractorStyle(b)
            elif style == 'interactive2d':
                self.__vtkinteractor.SetInteractorStyle(vtk.vtkInteractorStyleImage())
            elif style == 'modal':
                self.__vtkinteractor.SetInteractorStyle(vtk.vtkInteractorStyleUser())

        # Background settings
        self._results[0].updateOptions(self._options)

        # vtkRenderWindow Settings
        if self.isOptionValid('offscreen'):
            self.__vtkwindow.SetOffScreenRendering(self.getOption('offscreen'))

        if self.isOptionValid('smoothing'):
            smooth = self.getOption('smoothing')
            self.__vtkwindow.SetLineSmoothing(smooth)
            self.__vtkwindow.SetPolygonSmoothing(smooth)
            self.__vtkwindow.SetPointSmoothing(smooth)

        if self.isOptionValid('antialiasing'):
            self.__vtkwindow.SetAAFrames(self.getOption('antialiasing'))

        if self.isOptionValid('multisamples'):
            self.__vtkwindow.SetMultiSamples(self.getOption('multisamples'))

        if self.isOptionValid('size'):
            self.__vtkwindow.SetSize(self.getOption('size'))

        self.__vtkwindow.Render()

        # Setup the result objects
        n = self.__vtkwindow.GetNumberOfLayers()
        for result in self._results:
            renderer = result.getVTKRenderer()
            if not self.__vtkwindow.HasRenderer(renderer):
                self.__vtkwindow.AddRenderer(renderer)
            if result.needsUpdate():
                result.update()
            n = max(n, renderer.GetLayer() + 1)
        self.__vtkwindow.SetNumberOfLayers(n)

        if (self.__active is None) and len(self._results) > 1:
            self.setActive(self._results[1])

        self.__vtkwindow.Render()
Пример #17
0

def mouseMove(widget, event_string):
    global left, middle, right
    if left == 1:
        mouseLeftMove(iRen, ren)
    if middle == 1:
        mouseMiddleMove(iRen, ren)
    if right == 1:
        mouseRightMove(iRen, ren)
    if (left == 0) and (middle == 0) and (right == 0):
        pass


# This is where the interaction style is defined
style = vtk.vtkInteractorStyleUser()
iRen.SetInteractorStyle(style)

style.AddObserver("LeftButtonPressEvent", leftDown)
style.AddObserver("LeftButtonReleaseEvent", leftUp)
style.AddObserver("MiddleButtonPressEvent", middleDown)
style.AddObserver("MiddleButtonReleaseEvent", middleUp)
style.AddObserver("RightButtonPressEvent", rightDown)
style.AddObserver("RightButtonReleaseEvent", rightUp)
style.AddObserver("MouseWheelForwardEvent", wheelForward)
style.AddObserver("MouseWheelBackwardEvent", wheelBackward)
style.AddObserver("MouseMoveEvent", mouseMove)

iRen.Initialize()
renWin.Render()