Пример #1
0
    def onClicked(self, pos):
        picker = vtk.vtkPicker()
        picker.Pick(pos.x(), pos.y(), 0, self._vtk_renderer)

        picked_actor = picker.GetActor()
        if picked_actor is None:
            if self._last_picked_actor is not None:
                self._last_picked_actor.GetProperty().SetColor(
                    self._last_picked_property.GetColor())
            self.componentSelected.emit(None)
        elif picked_actor != self._last_picked_actor:
            property = picked_actor.GetProperty()
            if self._last_picked_actor is not None:
                self._last_picked_actor.GetProperty().SetColor(
                    self._last_picked_property.GetColor())

            self._last_picked_property.SetColor(property.GetColor())

            # FIXME: set color from preferences
            property.SetColor([1, 1, 1])
            property.SetDiffuse(1.0)
            property.SetSpecular(0.0)

            comp_name = self._actor_to_comp_name[picked_actor]
            self.componentSelected.emit(comp_name)

        self._last_picked_actor = picked_actor
Пример #2
0
    def middle_button_press_event(self, obj, event):
        # get event position of click event

        self.PickedProducer = None
        self.PickedActor = None


        clickPos = self.GetInteractor().GetEventPosition()

        pickers = []
        picked_actors = []
        # go through every renderer and pick
        for r in self.ren_list:
            pickers.append(vtk.vtkPicker())
            pickers[-1].Pick(clickPos[0], clickPos[1], 0, r)
            picked_actors.append(pickers[-1].GetActor())

        # select the actual actor picked (if exists)
        for pa in picked_actors:
            if pa is not None:
                self.PickedActor = pa
                #self.PickedActor.Update()

        if self.PickedActor is not None:
            _m = self.PickedActor.GetMapper()
            _i = _m.GetInputConnection(0, 0)
            _p = _i.GetProducer()

            #print(type(_p))

        if type(_p) is not InterfaceSphere and type(_p) is not CustomTransformPolyDataFilter and _p is not None:
            # then go deeper
            alg = _p.GetInputConnection(0, 0)
            self.PickedProducer = alg.GetProducer()

        else:
            self.PickedProducer = _p

            if self.PickedProducer is not None:
                # print("Moving actor: ",type(self.PickedActor))
                # print("Producer: ",type(self.PickedProducer))
                if type(self.PickedProducer) is InterfaceSphere:
                    _c = self.PickedActor.GetCenter()
                    self.geo_data.interface_modify(self.PickedProducer.index, X=_c[0], Y=_c[1], Z=_c[2])
                elif type(self.PickedProducer) is CustomTransformPolyDataFilter:
                    _c = self.PickedActor.GetCenter()
                    self.geo_data.foliation_modify(self.PickedProducer.index, X=_c[0], Y=_c[1], Z=_c[2])


            # print(str(type(self.PickedProducer)))
        self.OnMiddleButtonDown()
        return
Пример #3
0
 def on_mouse_event(self, event):
     assert isinstance(event, wx.MouseEvent)
     mouseX, mouseY = event.GetPosition()
     window_y = self.render_window.GetSize()[1]
     picker = vtk.vtkPicker()
     has_something = picker.Pick(mouseX, window_y - mouseY, 0, self.renderer)
     p3ds = picker.GetProp3Ds()
     p3ds = [
         p3ds.GetItemAsObject(idx) 
         for idx in range(p3ds.GetNumberOfItems())]
     points = picker.GetPickedPositions()
     points = [
         points.GetPoint(idx) 
         for idx in range(points.GetNumberOfPoints())]
     for actor, (x, y, z) in zip(p3ds, points):
         pick_event = PickEvent(event, x, y, z, actor)
         self.GetEventHandler().ProcessEvent(pick_event)
Пример #4
0
def select_point(obj, ev):
    x, y = obj.GetLastEventPosition()
    print('picking pixel: ' + str(x) + ' and ' + str(y))
    global ren
    global quadric
    picker = vtk.vtkPicker()
    picker.Pick(x, y, 0, ren)
    obj.SetPicker(picker)
    picked = picker.GetPickedPositions().GetPoint(0)
    #print picked
    print('picked value: ' + str(picked[0]) + ';' + str(picked[1]) + ';' +
          str(picked[2]))
    ## crop area
    quadric.SetCenter(picked[0], picked[1], picked[2])
    quadric.SetScale(100, 100, 100)
    sliderRepSX.SetValue(100)
    sliderRepSY.SetValue(100)
    sliderRepSZ.SetValue(100)
    print quadric
    #getSliderObjects(sliderRepPX, sliderWidgetPX, "Position X", iren, quadric.GetCenter()[0], 25, 225, 1050, 500, posXSliderCallback)
    #getSliderObjects(sliderRepPY, sliderWidgetPY, "Position Y", iren, quadric.GetCenter()[1], 25, 225, 1050, 300, posYSliderCallback)
    #getSliderObjects(sliderRepPZ, sliderWidgetPZ, "Position Z", iren, quadric.GetCenter()[2], 25, 225, 1050, 100, posZSliderCallback)
    functionToStencil.Modified()
    functionToStencil.Update()
    stencil.Modified()
    stencil.Update()
    volume.Modified()
    volume.Update()
    ## Draw the center of area
    global IP, pkd
    pkd.append(picked)
    IP = IP + 1
    sphere = vtk.vtkSphereSource()
    sphere.SetCenter(picked[0], picked[1], picked[2])
    sphere.SetRadius(2)
    #print sphere
    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphere.GetOutputPort())
    sphereActor = vtk.vtkActor()
    sphereActor.SetMapper(sphereMapper)
    #print sphereActor
    #global ren
    ren.AddActor(sphereActor)
Пример #5
0
    def _pick_glyph(self, ex, ey):
        """Give current VTK display position.
        """
        p = vtk.vtkPicker()
        p.SetTolerance(0.00001) # this is perhaps still too large

       
        for i in self._cobjects:
            if isinstance(i, DeVIDECanvasGlyph):
                for prop in i.props:
                    p.AddPickList(prop)

        p.PickFromListOn()

        ret = p.Pick((ex, ey, 0), self._ren)
        
        if ret:
            #pc = p.GetProp3Ds()
            #pc.InitTraversal()
            #prop = pc.GetNextItemAsObject()
            prop = p.GetAssembly() # for now we only want this.
            try:
                picked_cobject = self.prop_to_glyph[prop]
            except KeyError:
                dprint("_pick_glyph:: couldn't find prop in p2g dict")
                return None
            else:
                # need to find out WHICH sub-actor was picked.
                if p.GetPath().GetNumberOfItems() == 2:
                    sub_prop = \
                        p.GetPath().GetItemAsObject(1).GetViewProp()

                else:
                    sub_prop = None

                # our assembly is one level deep, so 1 is the one we
                # want (actor at leaf node)

                return (picked_cobject, sub_prop)

        return None
Пример #6
0
# Set up the actor
a = vtk.vtkActor()
a.SetMapper(m)
a.GetProperty().EdgeVisibilityOn()
a.GetProperty().SetEdgeColor(1, 1, 1)

# Render the actor
r = vtk.vtkRenderer()
r.AddViewProp(a)
r.SetBackground(0, 0, 0)
rw = vtk.vtkRenderWindow()
rw.AddRenderer(r)
rw.Render()

# Define the pickers
propPicker = vtk.vtkPicker()
cellPicker = vtk.vtkCellPicker()
pointPicker = vtk.vtkPointPicker()

# this can be switched on to print some debug output
debug = False


def propPick(p, xy, data):
    """
    Pick a prop. camera has been positioned such that a ray pick at
    screen-coordinates p hits points with x-y coordinates xy.
    data contains: expected pick result, block#
    """
    errors = 0
    result = propPicker.Pick(p[0], p[1], 0, r) == 1
Пример #7
0
mapper.SliceFacesCameraOn()
imageSlice = vtk.vtkImageSlice()
imageSlice.SetMapper(mapper)
imageSlice.GetProperty().SetColorLevel(127.5)
imageSlice.GetProperty().SetColorWindow(255)
renderer=vtk.vtkRenderer()
renderer.AddViewProp(imageSlice)

window=vtk.vtkRenderWindow()
window.SetSize(size,size)
window.AddRenderer(renderer)

window.Render()
pp = vtk.vtkPointPicker()
cp = vtk.vtkCellPicker()
p  = vtk.vtkPicker()
errors = 0
for (i,j,cid,pid) in ((20,40,-1,-1),(160,100,821341,825800),(240,300,938658,943010)):
    pos=[i,j]

    # Test prop picker
    result = p.Pick(pos[0],pos[1],0,renderer)
    if (result != 0) != (pid != -1):
      errors += 1
      print("Picker at {} returns {} expected".format(pos,result) )

    # Test cell picker
    result = cp.Pick(pos[0],pos[1],0,renderer)
    if (result != 0) != (pid != -1):
      errors += 1
      print("Cellpicker at {} returns {} expected {}".format(pos, (result != 0), (pid != -1) ) )
# Set up the actor
a=vtk.vtkActor()
a.SetMapper(m)
a.GetProperty().EdgeVisibilityOn()
a.GetProperty().SetEdgeColor(1,1,1)

# Render the actor
r = vtk.vtkRenderer()
r.AddViewProp(a)
r.SetBackground(0,0,0)
rw = vtk.vtkRenderWindow()
rw.AddRenderer(r)
rw.Render()

# Define the pickers
propPicker = vtk.vtkPicker()
cellPicker = vtk.vtkCellPicker()
pointPicker = vtk.vtkPointPicker()

# this can be switched on to print some debug output
debug=False

def propPick(p,xy,data):
    """
    Pick a prop. camera has been positioned such that a ray pick at
    screen-coordinates p hits points with x-y coordinates xy.
    data contains: expected pick result, block#
    """
    errors = 0
    result=propPicker.Pick(p[0],p[1],0,r)==1
    if result != data[0]: