예제 #1
0
 def get_cursor_position_world(self):
     x, y = self.GetEventPosition()
     xyz = [x, y, 0.0]
     picker = vtk.vtkWorldPointPicker()
     picker.Pick(xyz, self.renderer)
     ppos = picker.GetPickPosition()
     return ppos
예제 #2
0
    def __init_gui(self):
        self.interactor = wxVTKRenderWindowInteractor(self, -1, size=self.GetSize())

        scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL)
        self.scroll = scroll

        self.mip_ctrls = ContourMIPConfig(self, self.orientation)
        self.mip_ctrls.Hide()

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.interactor, 1, wx.EXPAND|wx.GROW)
        sizer.Add(scroll, 0, wx.EXPAND|wx.GROW)

        background_sizer = wx.BoxSizer(wx.VERTICAL)
        background_sizer.AddSizer(sizer, 1, wx.EXPAND|wx.GROW|wx.ALL, 2)
        #background_sizer.Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2)
        self.SetSizer(background_sizer)
        background_sizer.Fit(self)

        self.Layout()
        self.Update()
        self.SetAutoLayout(1)

        self.pick = vtk.vtkWorldPointPicker()
        self.interactor.SetPicker(self.pick)
예제 #3
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = self.viewer.orientation
        self.matrix = None

        self.operation = BRUSH_FOREGROUND

        self.mg_size = 3

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("EnterEvent", self.OnEnterInteractor)
        self.AddObserver("LeaveEvent", self.OnLeaveInteractor)

        self.RemoveObservers("MouseWheelForwardEvent")
        self.RemoveObservers("MouseWheelBackwardEvent")
        self.AddObserver("MouseWheelForwardEvent",self.WOnScrollForward)
        self.AddObserver("MouseWheelBackwardEvent", self.WOnScrollBackward)

        self.AddObserver("LeftButtonPressEvent", self.OnBrushClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease)
        self.AddObserver("MouseMoveEvent", self.OnBrushMove)

        Publisher.subscribe(self.expand_watershed, 'Expand watershed to 3D ' + self.orientation)
        Publisher.subscribe(self.set_operation, 'Set watershed operation')
예제 #4
0
 def get_cursor_position_world(self):
     x, y = self.GetEventPosition()
     xyz = [x, y, 0.0]
     picker = vtk.vtkWorldPointPicker()
     picker.Pick(xyz, self.renderer)
     ppos = picker.GetPickPosition()
     return ppos
예제 #5
0
 def pick_mouse_position(self):
     """Get corresponding mouse location in the 3D plot."""
     if self.mouse_position is None:
         self.store_mouse_position()
     picker = vtk.vtkWorldPointPicker()
     picker.Pick(self.mouse_position[0], self.mouse_position[1], 0, self.renderer)
     return picker.GetPickPosition()
예제 #6
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = self.viewer.orientation
        self.matrix = None

        self.operation = BRUSH_FOREGROUND

        self.mg_size = 3

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("EnterEvent", self.OnEnterInteractor)
        self.AddObserver("LeaveEvent", self.OnLeaveInteractor)

        self.RemoveObservers("MouseWheelForwardEvent")
        self.RemoveObservers("MouseWheelBackwardEvent")
        self.AddObserver("MouseWheelForwardEvent", self.WOnScrollForward)
        self.AddObserver("MouseWheelBackwardEvent", self.WOnScrollBackward)

        self.AddObserver("LeftButtonPressEvent", self.OnBrushClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease)
        self.AddObserver("MouseMoveEvent", self.OnBrushMove)

        Publisher.subscribe(self.expand_watershed,
                            'Expand watershed to 3D ' + self.orientation)
        Publisher.subscribe(self.set_operation, 'Set watershed operation')
예제 #7
0
    def __init_gui(self):
        self.interactor = wxVTKRenderWindowInteractor(self,
                                                      -1,
                                                      size=self.GetSize())

        scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL)
        self.scroll = scroll

        self.mip_ctrls = ContourMIPConfig(self, self.orientation)
        self.mip_ctrls.Hide()

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.interactor, 1, wx.EXPAND | wx.GROW)
        sizer.Add(scroll, 0, wx.EXPAND | wx.GROW)

        background_sizer = wx.BoxSizer(wx.VERTICAL)
        background_sizer.AddSizer(sizer, 1, wx.EXPAND | wx.GROW | wx.ALL, 2)
        #background_sizer.Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2)
        self.SetSizer(background_sizer)
        background_sizer.Fit(self)

        self.Layout()
        self.Update()
        self.SetAutoLayout(1)

        self.pick = vtk.vtkWorldPointPicker()
        self.interactor.SetPicker(self.pick)
예제 #8
0
    def __init__(self,
                 vertices=True,
                 faces=True,
                 actors=True,
                 world_coords=True):
        """ Picking Manager helps with picking 3D objects

        Parameters
        -----------
        vertices : bool
            If True allows to pick vertex indices.
        faces : bool
            If True allows to pick face indices.
        actors : bool
            If True allows to pick actor indices.
        world_coords : bool
            If True allows to pick xyz position in world coordinates.
        """

        self.pickers = {}
        if vertices:
            self.pickers['vertices'] = vtk.vtkPointPicker()
        if faces:
            self.pickers['faces'] = vtk.vtkCellPicker()
        if actors:
            self.pickers['actors'] = vtk.vtkPropPicker()
        if world_coords:
            self.pickers['world_coords'] = vtk.vtkWorldPointPicker()
예제 #9
0
    def CloseProject(self):
        for slice_data in self.slice_data_list:
            del slice_data

        self.slice_data_list = []
        self.layout = (1, 1)
        self.orientation_texts = []
        self.slice_number = 0
        self.cursor = None
        self.wl_text = None
        self.pick = vtk.vtkWorldPointPicker()
예제 #10
0
 def CloseProject(self):
     for slice_data in self.slice_data_list:
         del slice_data
         
     self.slice_data_list = []
     self.layout = (1, 1)
     self.orientation_texts = []
     self.slice_number = 0
     self.cursor = None
     self.wl_text = None
     self.pick = vtk.vtkWorldPointPicker()
예제 #11
0
    def OnLeftButtonDown(self, obj, eventType):

        # Get 2D click location on window
        clickPos = self.iren.GetEventPosition()

        # Get corresponding click location in the 3D plot
        picker = vtk.vtkWorldPointPicker()
        picker.Pick(clickPos[0], clickPos[1], 0, self.renderer)
        self.pickpoint = np.asarray(picker.GetPickPosition()).reshape((-1, 3))

        self.iren.AddObserver('LeftButtonPressEvent',
                              self.OnLeftButtonDown)
예제 #12
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = viewer.orientation
        self.slice_actor = viewer.slice_data.actor
        self.slice_data = viewer.slice_data

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("MouseMoveEvent", self.OnCrossMove)
        self.AddObserver("LeftButtonPressEvent", self.OnCrossMouseClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnReleaseLeftButton)
예제 #13
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = viewer.orientation
        self.slice_actor = viewer.slice_data.actor
        self.slice_data = viewer.slice_data

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("MouseMoveEvent", self.OnCrossMove)
        self.AddObserver("LeftButtonPressEvent", self.OnCrossMouseClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnReleaseLeftButton)
예제 #14
0
 def Draw3DLine(self):
     eventPos = self.iren.GetEventPosition()
     picker = vtk.vtkWorldPointPicker()
     picker.Pick(eventPos[0], eventPos[1], 0, self.ren[0])
     globalPos = picker.GetPickPosition()
     coneSource = vtk.vtkConeSource()
     coneSource.SetCenter(globalPos)
     coneMapper = vtk.vtkPolyDataMapper()
     coneMapper.SetInputConnection(coneSource.GetOutputPort())
     self.testActor = vtk.vtkActor()
     self.testActor.SetMapper(coneMapper)
     self.testActor.GetProperty().SetColor(1, 0, 0)
     self.ren[1].AddActor(self.testActor)
예제 #15
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = self.viewer.orientation

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("EnterEvent", self.OnEnterInteractor)
        self.AddObserver("LeaveEvent", self.OnLeaveInteractor)

        self.AddObserver("LeftButtonPressEvent", self.OnBrushClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease)
        self.AddObserver("MouseMoveEvent", self.OnBrushMove)
예제 #16
0
def cbLeftButtonPressEvt(obj, ev):
    # Won't work
    global renderWindow
    global renderer
    global _Cross
    print('left button')
    if type(obj) == vtk.vtkInteractorStyleImage:
        mousePosition = obj.GetInteractor().GetLastEventPosition()
        _picker = vtk.vtkWorldPointPicker()
        _picker.Pick(mousePosition[0], mousePosition[1], 0.0, renderer)

        pickPosition = _picker.GetPickPosition()
        _Cross.SetPosition(pickPosition[0], pickPosition[1], pickPosition[2])
        renderWindow.Render()
예제 #17
0
 def menu(self, x, y, ids):
     renderer = self.getRenderer()
     picker = vtk.vtkWorldPointPicker()
     ret = picker.Pick([x, y, 0], renderer)
     point = picker.GetPickPosition()
     epsilon = self.computeEpsilon(renderer, point[2])
     bbox = vtk.vtkBoundingBox()
     bbox.AddPoint(point[0] + epsilon, point[1] + epsilon,
                   point[2] + epsilon)
     bbox.AddPoint(point[0] - epsilon, point[1] - epsilon,
                   point[2] - epsilon)
     for id in ids:
         if self.getObject(id)['bbox'].Intersects(bbox):
             return id
     return 0
예제 #18
0
    def __init__(self, viewer):
        DefaultInteractorStyle.__init__(self, viewer)

        self.viewer = viewer
        self.orientation = self.viewer.orientation

        self.picker = vtk.vtkWorldPointPicker()

        self.AddObserver("EnterEvent", self.OnEnterInteractor)
        self.AddObserver("LeaveEvent", self.OnLeaveInteractor)

        self.AddObserver("LeftButtonPressEvent", self.OnBrushClick)
        self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease)
        self.AddObserver("MouseMoveEvent", self.OnBrushMove)

        self.RemoveObservers("MouseWheelForwardEvent")
        self.RemoveObservers("MouseWheelBackwardEvent")
        self.AddObserver("MouseWheelForwardEvent", self.EOnScrollForward)
        self.AddObserver("MouseWheelBackwardEvent", self.EOnScrollBackward)
예제 #19
0
파일: Picker.py 프로젝트: sldion/DNACC
    def __init__ (self, master, renwin):
        debug ("In Picker::__init__ ()")
        self.renwin = renwin
        self.master = master
        self.pointpicker = vtk.vtkPointPicker()
        self.cellpicker = vtk.vtkCellPicker()
        self.worldpicker = vtk.vtkWorldPointPicker()
        self.probe_point = vtk.vtkPoints()
        self.probe_data = vtk.vtkPolyData()
        self.pick_type_var = Tkinter.IntVar()
        self.tol_var = Tkinter.DoubleVar ()
        self.tol_var.set(self.pointpicker.GetTolerance())
        self.root = None
        self.txt = None

        # Use a set of axis to show the picked point.
        self.p_source = vtk.vtkAxes ()
        self.p_mapper = vtk.vtkPolyDataMapper ()
        self.p_actor = vtk.vtkActor ()

        self._initialize ()
import vtk
import math
import numpy
import slicer_read_Dataset
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

DEBUG_MODE = 0

#-------- Initialization ------------------

worldPicker = vtk.vtkWorldPointPicker()
clickPointsList = []
renderer = vtk.vtkRenderer()
aslice = range(10)
color = range(10)
actor = range(10)
mpv_renderer = range(4)


# Start by loading some data.
reader = vtk.vtkImageReader2()
reader.SetFilePrefix("../Dataset/quarter")
reader.SetDataExtent(0, 63, 0, 63, 1, 93)
reader.SetDataSpacing(1, 1, 1)
#reader.SetDataSpacing(3.2, 3.2, 1.5)
reader.SetDataOrigin(0.0, 0.0, 0.0)
reader.SetDataScalarTypeToUnsignedShort()
reader.UpdateWholeExtent()

# Calculate the center of the volume
import vtk
import math
import numpy
import slicer_read_Dataset
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

DEBUG_MODE = 0

#-------- Initialization ------------------

worldPicker = vtk.vtkWorldPointPicker()
clickPointsList = []
renderer = vtk.vtkRenderer()
aslice = range(10)
color = range(10)
actor = range(10)
mpv_renderer = range(4)

# Start by loading some data.
reader = vtk.vtkImageReader2()
reader.SetFilePrefix("../Dataset/quarter")
reader.SetDataExtent(0, 63, 0, 63, 1, 93)
reader.SetDataSpacing(1, 1, 1)
#reader.SetDataSpacing(3.2, 3.2, 1.5)
reader.SetDataOrigin(0.0, 0.0, 0.0)
reader.SetDataScalarTypeToUnsignedShort()
reader.UpdateWholeExtent()

# Calculate the center of the volume