def pickPoint(displayPoint,
              view,
              obj=None,
              pickType='points',
              tolerance=0.01,
              returnNormal=False):

    assert pickType in ('points', 'cells', 'render')

    view = view or app.getCurrentRenderView()
    assert view

    if isinstance(obj, str):
        obj = om.findObjectByName(obj)
        assert obj

    if pickType == 'render':
        picker = vtk.vtkPropPicker()
    else:
        picker = vtk.vtkPointPicker(
        ) if pickType == 'points' else vtk.vtkCellPicker()
        picker.SetTolerance(tolerance)

    if obj:
        if isinstance(obj, list):
            for o in obj:
                picker.AddPickList(o.actor)
            obj = None
        else:
            picker.AddPickList(obj.actor)
        picker.PickFromListOn()

    picker.Pick(displayPoint[0], displayPoint[1], 0, view.renderer())
    pickedProp = picker.GetViewProp()
    pickedPoint = np.array(picker.GetPickPosition())
    pickedDataset = pickedProp.GetMapper().GetInput() if isinstance(
        pickedProp, vtk.vtkActor) else None

    pickedNormal = np.zeros(3)

    if returnNormal:
        if pickType == 'cells':
            pickedNormal = np.array(picker.GetPickNormal())
        elif pickType == 'points' and pickedDataset:
            pointId = picker.GetPointId()
            normals = pickedDataset.GetPointData().GetNormals()
            if normals:
                pickedNormal = np.array(normals.GetTuple3(pointId))

    if obj:
        if returnNormal:
            return (pickedPoint, pickedNormal) if pickedProp else (None, None)
        else:
            return pickedPoint if pickedProp else None
    else:
        return (pickedPoint, pickedProp, pickedDataset,
                pickedNormal) if returnNormal else (pickedPoint, pickedProp,
                                                    pickedDataset)
Exemple #2
0
def pickPoint(displayPoint, view, obj=None, pickType='points', tolerance=0.01, returnNormal=False):

    assert pickType in ('points', 'cells', 'render')

    view = view or app.getCurrentRenderView()
    assert view

    if isinstance(obj, str):
        obj = om.findObjectByName(obj)
        assert obj


    if pickType == 'render':
        picker = vtk.vtkPropPicker()
    else:
        picker = vtk.vtkPointPicker() if pickType == 'points' else vtk.vtkCellPicker()
        picker.SetTolerance(tolerance)


    if obj is not None:
        if isinstance(obj, list):
            for o in obj:
                picker.AddPickList(o.actor)
            obj = None
        else:
            picker.AddPickList(obj.actor)
        picker.PickFromListOn()

    picker.Pick(displayPoint[0], displayPoint[1], 0, view.renderer())
    pickedProp = picker.GetViewProp()
    pickedPoint = np.array(picker.GetPickPosition())
    pickedDataset = pickedProp.GetMapper().GetInput() if isinstance(pickedProp, vtk.vtkActor) else None

    pickedNormal = np.zeros(3)

    if returnNormal:
        if pickType == 'cells':
          pickedNormal = np.array(picker.GetPickNormal())
        elif pickType == 'points' and pickedDataset:
          pointId = picker.GetPointId()
          normals = pickedDataset.GetPointData().GetNormals()
          if normals:
              pickedNormal = np.array(normals.GetTuple3(pointId))

    #if pickedDataset and pickType == 'cells':
    #    print 'point id:', pickedDataset.GetCell(picker.GetCellId()).GetPointIds().GetId(picker.GetSubId())
    #if pickType == 'points':
    #    print 'point id:', picker.GetPointId()

    if obj:
        if returnNormal:
            return (pickedPoint, pickedNormal) if pickedProp else (None, None)
        else:
            return pickedPoint if pickedProp else None
    else:
        return (pickedPoint, pickedProp, pickedDataset, pickedNormal) if returnNormal else (pickedPoint, pickedProp, pickedDataset)
Exemple #3
0
def pickPoint(displayPoint, view, obj=None, pickType='points', tolerance=0.01):
    """

    :param displayPoint:
    :param view:
    :param obj:
    :param pickType:
    :param tolerance:
    :return: FieldContainer with fields
        pickedPoint
        pickedProp
        pickedDataset
        pickedNormal - is None if no normal can be comp
        pickedCellId - is None unless pickType="cells"
    """

    assert pickType in ('points', 'cells', 'render')

    view = view or app.getCurrentRenderView()
    assert view

    if isinstance(obj, str):
        obj = om.findObjectByName(obj)
        assert obj


    if pickType == 'render':
        picker = vtk.vtkPropPicker()
    else:
        picker = vtk.vtkPointPicker() if pickType == 'points' else vtk.vtkCellPicker()
        picker.SetTolerance(tolerance)


    if obj is not None:
        if isinstance(obj, list):
            for o in obj:
                picker.AddPickList(o.actor)
            obj = None
        else:
            picker.AddPickList(obj.actor)
        picker.PickFromListOn()

    picker.Pick(displayPoint[0], displayPoint[1], 0, view.renderer())
    pickedProp = picker.GetViewProp()
    pickedPoint = np.array(picker.GetPickPosition())
    pickedDataset = pickedProp.GetMapper().GetInput() if isinstance(pickedProp, vtk.vtkActor) else None


    if pickType == "cells":
        pickedCellId = picker.GetCellId()
    else:
        pickedCellId = None

    # populate pickedNormal if possible
    pickedNormal = None
    if pickType == 'cells':
      pickedNormal = np.array(picker.GetPickNormal())
    elif pickType == 'points' and pickedDataset:
      pointId = picker.GetPointId()
      normals = pickedDataset.GetPointData().GetNormals()
      if normals:
          pickedNormal = np.array(normals.GetTuple3(pointId))

    #if pickedDataset and pickType == 'cells':
    #    print 'point id:', pickedDataset.GetCell(picker.GetCellId()).GetPointIds().GetId(picker.GetSubId())
    #if pickType == 'points':
    #    print 'point id:', picker.GetPointId()


    fields = FieldContainer(
        pickedPoint=pickedPoint,
        pickedProp=pickedProp,
        pickedDataset=pickedDataset,
        pickedNormal=pickedNormal,
        pickedCellId=pickedCellId
    )
    return fields
Exemple #4
0
def pickPoint(displayPoint, view, obj=None, pickType='points', tolerance=0.01):
    """

    :param displayPoint:
    :param view:
    :param obj:
    :param pickType:
    :param tolerance:
    :return: FieldContainer with fields
        pickedPoint
        pickedProp
        pickedDataset
        pickedNormal - is None if no normal can be comp
        pickedCellId - is None unless pickType="cells"
    """

    assert pickType in ('points', 'cells', 'render')

    view = view or app.getCurrentRenderView()
    assert view

    if isinstance(obj, str):
        obj = om.findObjectByName(obj)
        assert obj

    if pickType == 'render':
        picker = vtk.vtkPropPicker()
    else:
        picker = vtk.vtkPointPicker(
        ) if pickType == 'points' else vtk.vtkCellPicker()
        picker.SetTolerance(tolerance)

    if obj is not None:
        if isinstance(obj, list):
            for o in obj:
                picker.AddPickList(o.actor)
            obj = None
        else:
            picker.AddPickList(obj.actor)
        picker.PickFromListOn()

    picker.Pick(displayPoint[0], displayPoint[1], 0, view.renderer())
    pickedProp = picker.GetViewProp()
    pickedPoint = np.array(picker.GetPickPosition())
    pickedDataset = pickedProp.GetMapper().GetInput() if isinstance(
        pickedProp, vtk.vtkActor) else None

    if pickType == "cells":
        pickedCellId = picker.GetCellId()
    else:
        pickedCellId = None

    # populate pickedNormal if possible
    pickedNormal = None
    if pickType == 'cells':
        pickedNormal = np.array(picker.GetPickNormal())
    elif pickType == 'points' and pickedDataset:
        pointId = picker.GetPointId()
        normals = pickedDataset.GetPointData().GetNormals()
        if normals:
            pickedNormal = np.array(normals.GetTuple3(pointId))

    #if pickedDataset and pickType == 'cells':
    #    print 'point id:', pickedDataset.GetCell(picker.GetCellId()).GetPointIds().GetId(picker.GetSubId())
    #if pickType == 'points':
    #    print 'point id:', picker.GetPointId()

    fields = FieldContainer(pickedPoint=pickedPoint,
                            pickedProp=pickedProp,
                            pickedDataset=pickedDataset,
                            pickedNormal=pickedNormal,
                            pickedCellId=pickedCellId)
    return fields