Ejemplo n.º 1
0
 def _update_picking_callback(self, on_mouse_move, on_button_press,
                              on_button_release, on_pick):
     add_obs = self.plotter.iren.add_observer
     add_obs(vtkCommand.RenderEvent, on_mouse_move)
     add_obs(vtkCommand.LeftButtonPressEvent, on_button_press)
     add_obs(vtkCommand.EndInteractionEvent, on_button_release)
     self.plotter.picker = vtkCellPicker()
     self.plotter.picker.AddObserver(vtkCommand.EndPickEvent, on_pick)
     self.plotter.picker.SetVolumeOpacityIsovalue(0.)
Ejemplo n.º 2
0
    def __init__(self, viewer):
        super().__init__(viewer)

        self.state_code = const.SLICE_STATE_CROSS
        self.picker = vtkCellPicker()
        self.picker.SetTolerance(1e-3)
        # self.picker.SetUseCells(True)
        self.viewer.interactor.SetPicker(self.picker)
        self.AddObserver("LeftButtonPressEvent", self.OnCrossMouseClick)
Ejemplo n.º 3
0
    def SetInput(self, imagedata):
        axes = PLANE_DATA[self.orientation][0]  # "x", "y" or "z"
        colour = PLANE_DATA[self.orientation][1]

        #if self.orientation == SAGITAL:
        #    spacing = min(imagedata.GetSpacing())
        #    permute = vtk.vtkImagePermute()
        #    permute.SetInput(imagedata)
        #    permute.GetOutput().ReleaseDataFlagOn()
        #    permute.SetOutputSpacing(spacing, spacing, spacing)
        #    imagedata = permute.GetOutput()

        # Picker for enabling plane motion.
        # Allows selection of a cell by shooting a ray into graphics window
        picker = vtkCellPicker()
        picker.SetTolerance(0.005)
        picker.PickFromListOn()

        # 3D widget for reslicing image data.
        # This 3D widget defines a plane that can be interactively placed in an image volume.
        widget = vtkImagePlaneWidget()
        widget.SetInput(imagedata)
        widget.SetSliceIndex(self.index)
        widget.SetPicker(picker)
        widget.SetKeyPressActivationValue(axes)
        widget.SetInteractor(self.iren)
        widget.TextureVisibilityOff()
        widget.DisplayTextOff()
        widget.RestrictPlaneToVolumeOff()
        exec("widget.SetPlaneOrientationTo" + axes.upper() + "Axes()")
        widget.AddObserver("InteractionEvent", self.Update)
        self.widget = widget

        prop = widget.GetPlaneProperty()
        prop.SetColor(colour)

        # Syncronize coloured outline with texture appropriately
        source = vtkPlaneSource()
        source.SetOrigin(widget.GetOrigin())
        source.SetPoint1(widget.GetPoint1())
        source.SetPoint2(widget.GetPoint2())
        source.SetNormal(widget.GetNormal())
        self.source = source

        mapper = vtkPolyDataMapper()
        mapper.SetInput(source.GetOutput())

        actor = vtkActor()
        actor.SetMapper(mapper)
        actor.SetTexture(widget.GetTexture())
        actor.VisibilityOff()
        self.actor = actor

        self.render.AddActor(actor)
Ejemplo n.º 4
0
    def SetInteractor(self, interactor):

        self.interactor = interactor
        self.render = interactor.GetRenderWindow().GetRenderers(
        ).GetFirstRenderer()

        istyle = vtkInteractorStyleImage()
        istyle.SetInteractor(interactor)
        istyle.AutoAdjustCameraClippingRangeOn()
        interactor.SetInteractorStyle(istyle)

        istyle.AddObserver("LeftButtonPressEvent", self.Click)
        istyle.AddObserver("LeftButtonReleaseEvent", self.Release)
        istyle.AddObserver("MouseMoveEvent", self.Moved)

        pick = self.pick = vtkCellPicker()
Ejemplo n.º 5
0
    def __init__(self, *args):
        GtkGLExtVTKRenderWindowBase.__init__(self)

        self._CurrentRenderer = None
        self._CurrentCamera = None
        self._CurrentZoom = 1.0
        self._CurrentLight = None

        self._ViewportCenterX = 0
        self._ViewportCenterY = 0

        self._Picker = vtkCellPicker()
        self._PickedAssembly = None
        self._PickedProperty = vtkProperty()
        self._PickedProperty.SetColor(1, 0, 0)
        self._PrePickedProperty = None

        self._OldFocus = None

        # these record the previous mouse position
        self._LastX = 0
        self._LastY = 0
Ejemplo n.º 6
0
    def __init__(self, *args):
        GtkGLExtVTKRenderWindowBase.__init__(self)

        self._CurrentRenderer = None
        self._CurrentCamera = None
        self._CurrentZoom = 1.0
        self._CurrentLight = None

        self._ViewportCenterX = 0
        self._ViewportCenterY = 0

        self._Picker = vtkCellPicker()
        self._PickedAssembly = None
        self._PickedProperty = vtkProperty()
        self._PickedProperty.SetColor(1, 0, 0)
        self._PrePickedProperty = None

        self._OldFocus = None

        # these record the previous mouse position
        self._LastX = 0
        self._LastY = 0
Ejemplo n.º 7
0
    def __init__(self, parent, ID, *args, **kw):
        """Default class constructor.
        @param parent: parent window
        @param ID: window id
        @param **kw: wxPython keywords (position, size, style) plus the
        'stereo' keyword
        """
        # miscellaneous protected variables
        self._CurrentRenderer = None
        self._CurrentCamera = None
        self._CurrentZoom = 1.0
        self._CurrentLight = None

        self._ViewportCenterX = 0
        self._ViewportCenterY = 0

        self._Picker = vtkCellPicker()
        self._PickedActor = None
        self._PickedProperty = vtkProperty()
        self._PickedProperty.SetColor(1,0,0)
        self._PrePickedProperty = None

        # these record the previous mouse position
        self._LastX = 0
        self._LastY = 0

        # the current interaction mode (Rotate, Pan, Zoom, etc)
        self._Mode = None
        self._ActiveButton = None

        # private attributes
        self.__OldFocus = None

        # used by the LOD actors
        self._DesiredUpdateRate = 15
        self._StillUpdateRate = 0.0001

        # First do special handling of some keywords:
        # stereo, position, size, width, height, style

        try:
            stereo = bool(kw['stereo'])
            del kw['stereo']
        except KeyError:
            stereo = False

        try:
            position = kw['position']
            del kw['position']
        except KeyError:
            position = wx.DefaultPosition

        try:
            size = kw['size']
            del kw['size']
        except KeyError:
            try:
                size = parent.GetSize()
            except AttributeError:
                size = wx.DefaultSize

        # wx.WANTS_CHARS says to give us e.g. TAB
        # wx.NO_FULL_REPAINT_ON_RESIZE cuts down resize flicker under GTK
        style = wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE

        try:
            style = style | kw['style']
            del kw['style']
        except KeyError:
            pass

        # the enclosing frame must be shown under GTK or the windows
        #  don't connect together properly
        l = []
        p = parent
        while p: # make a list of all parents
            l.append(p)
            p = p.GetParent()
        l.reverse() # sort list into descending order
        for p in l:
            p.Show(1)

        # initialize the wx.Window
        if baseClass.__name__ == 'GLCanvas':
            # Set the doublebuffer attribute of the GL canvas.
            baseClass.__init__(self, parent, ID, pos=position, size=size,
                               style=style,
                               attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER])
        else:
            baseClass.__init__(self, parent, ID, pos=position, size=size,
                               style=style)

        # create the RenderWindow and initialize it
        self._RenderWindow = vtkRenderWindow()
        self._RenderWindow.SetSize(size.width, size.height)

        if stereo:
            self._RenderWindow.StereoCapableWindowOn()
            self._RenderWindow.SetStereoTypeToCrystalEyes()

        self.__handle = None

        # refresh window by doing a Render
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        # turn off background erase to reduce flicker
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)

        # Bind the events to the event converters
        self.Bind(wx.EVT_RIGHT_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_LEFT_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_MIDDLE_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_RIGHT_UP, self._OnButtonUp)
        self.Bind(wx.EVT_LEFT_UP, self._OnButtonUp)
        self.Bind(wx.EVT_MIDDLE_UP, self._OnButtonUp)
        self.Bind(wx.EVT_MOTION, self.OnMotion)

        self.Bind(wx.EVT_ENTER_WINDOW, self._OnEnterWindow)
        self.Bind(wx.EVT_LEAVE_WINDOW, self._OnLeaveWindow)

        self.Bind(wx.EVT_CHAR, self.OnChar)

        # 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.
        self.Bind(wx.EVT_CHAR, self.OnKeyDown)
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)

        self.Bind(wx.EVT_SIZE, self._OnSize)
        self.Bind(wx.EVT_MOVE, self.OnMove)

        self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
Ejemplo n.º 8
0
    def __init__(self, parent, ID, *args, **kw):
        """Default class constructor.
        @param parent: parent window
        @param ID: window id
        @param **kw: wxPython keywords (position, size, style) plus the
        'stereo' keyword
        """
        # miscellaneous protected variables
        self._CurrentRenderer = None
        self._CurrentCamera = None
        self._CurrentZoom = 1.0
        self._CurrentLight = None

        self._ViewportCenterX = 0
        self._ViewportCenterY = 0

        self._Picker = vtkCellPicker()
        self._PickedActor = None
        self._PickedProperty = vtkProperty()
        self._PickedProperty.SetColor(1,0,0)
        self._PrePickedProperty = None

        # these record the previous mouse position
        self._LastX = 0
        self._LastY = 0

        # the current interaction mode (Rotate, Pan, Zoom, etc)
        self._Mode = None
        self._ActiveButton = None

        # private attributes
        self.__OldFocus = None

        # used by the LOD actors
        self._DesiredUpdateRate = 15
        self._StillUpdateRate = 0.0001

        # First do special handling of some keywords:
        # stereo, position, size, width, height, style

        try:
            stereo = bool(kw['stereo'])
            del kw['stereo']
        except KeyError:
            stereo = False

        try:
            position = kw['position']
            del kw['position']
        except KeyError:
            position = wx.DefaultPosition

        try:
            size = kw['size']
            del kw['size']
        except KeyError:
            try:
                size = parent.GetSize()
            except AttributeError:
                size = wx.DefaultSize

        # wx.WANTS_CHARS says to give us e.g. TAB
        # wx.NO_FULL_REPAINT_ON_RESIZE cuts down resize flicker under GTK
        style = wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE

        try:
            style = style | kw['style']
            del kw['style']
        except KeyError:
            pass

        # the enclosing frame must be shown under GTK or the windows
        #  don't connect together properly
        l = []
        p = parent
        while p: # make a list of all parents
            l.append(p)
            p = p.GetParent()
        l.reverse() # sort list into descending order
        for p in l:
            p.Show(1)

        # initialize the wx.Window
        if baseClass.__name__ == 'GLCanvas':
            # Set the doublebuffer attribute of the GL canvas.
            baseClass.__init__(self, parent, ID, pos=position, size=size,
                               style=style,
                               attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER])
        else:
            baseClass.__init__(self, parent, ID, pos=position, size=size,
                               style=style)

        # create the RenderWindow and initialize it
        self._RenderWindow = vtkRenderWindow()
        self._RenderWindow.SetSize(size.width, size.height)

        if stereo:
            self._RenderWindow.StereoCapableWindowOn()
            self._RenderWindow.SetStereoTypeToCrystalEyes()

        self.__handle = None

        # refresh window by doing a Render
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        # turn off background erase to reduce flicker
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)

        # Bind the events to the event converters
        self.Bind(wx.EVT_RIGHT_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_LEFT_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_MIDDLE_DOWN, self._OnButtonDown)
        self.Bind(wx.EVT_RIGHT_UP, self._OnButtonUp)
        self.Bind(wx.EVT_LEFT_UP, self._OnButtonUp)
        self.Bind(wx.EVT_MIDDLE_UP, self._OnButtonUp)
        self.Bind(wx.EVT_MOTION, self.OnMotion)

        self.Bind(wx.EVT_ENTER_WINDOW, self._OnEnterWindow)
        self.Bind(wx.EVT_LEAVE_WINDOW, self._OnLeaveWindow)

        self.Bind(wx.EVT_CHAR, self.OnChar)

        # 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.
        self.Bind(wx.EVT_CHAR, self.OnKeyDown)
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)

        self.Bind(wx.EVT_SIZE, self._OnSize)
        self.Bind(wx.EVT_MOVE, self.OnMove)

        self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
        self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
Ejemplo n.º 9
0
    def __init__(self, master, cnf={}, **kw):
        """
        Constructor.

        Keyword arguments:

          rw -- Use passed render window instead of creating a new one.

          stereo -- If True, generate a stereo-capable window.
          Defaults to False.

          focus_on_enter -- If True, use a focus-follows-mouse mode.
          Defaults to False where the widget will use a click-to-focus
          mode.
        """
        # load the necessary extensions into tk
        vtkLoadPythonTkWidgets(master.tk)

        try: # check to see if a render window was specified
            renderWindow = kw['rw']
        except KeyError:
            renderWindow = vtkRenderWindow()

        try:  # was a stereo rendering context requested?
            if kw['stereo']:
               renderWindow.StereoCapableWindowOn()
               del kw['stereo']
        except KeyError:
            pass

        # check if focus should follow mouse
        if kw.get('focus_on_enter'):
            self._FocusOnEnter = 1
            del kw['focus_on_enter']
        else:
            self._FocusOnEnter = 0

        kw['rw'] = renderWindow.GetAddressAsString("vtkRenderWindow")
        tkinter.Widget.__init__(self, master, 'vtkTkRenderWidget', cnf, kw)

        self._CurrentRenderer = None
        self._CurrentCamera = None
        self._CurrentZoom = 1.0
        self._CurrentLight = None

        self._ViewportCenterX = 0
        self._ViewportCenterY = 0

        self._Picker = vtkCellPicker()
        self._PickedAssembly = None
        self._PickedProperty = vtkProperty()
        self._PickedProperty.SetColor(1,0,0)
        self._PrePickedProperty = None

        self._OldFocus = None

        # used by the LOD actors
        self._DesiredUpdateRate = 15
        self._StillUpdateRate = 0.0001

        # these record the previous mouse position
        self._LastX = 0
        self._LastY = 0

        # private attributes
        self.__InExpose = 0

        # create the Tk bindings
        self.BindTkRenderWidget()