def segmentValve(expectedValveRadius, point1, point2):

    inputObj = om.findObjectByName('pointcloud snapshot')
    polyData = inputObj.polyData

    viewPlaneNormal = np.array(getSegmentationView().camera().GetViewPlaneNormal())

    polyData, _, wallNormal = applyPlaneFit(polyData, expectedNormal=viewPlaneNormal, searchOrigin=point1, searchRadius=0.2, angleEpsilon=0.7, returnOrigin=True)


    wallPoints = thresholdPoints(polyData, 'dist_to_plane', [-0.01, 0.01])
    updatePolyData(wallPoints, 'wall points', parent=getDebugFolder(), visible=False)


    polyData, _, _ = applyPlaneFit(polyData, expectedNormal=wallNormal, searchOrigin=point2, searchRadius=expectedValveRadius, angleEpsilon=0.2, returnOrigin=True)
    valveCluster = thresholdPoints(polyData, 'dist_to_plane', [-0.01, 0.01])
    valveCluster = cropToSphere(valveCluster, point2, expectedValveRadius*2)
    valveCluster = extractLargestCluster(valveCluster,  minClusterSize=1)
    updatePolyData(valveCluster, 'valve cluster', parent=getDebugFolder(), visible=False)
    origin = np.average(vtkNumpy.getNumpyFromVtk(valveCluster, 'Points') , axis=0)

    zaxis = wallNormal
    xaxis = [0, 0, 1]
    yaxis = np.cross(zaxis, xaxis)
    xaxis = np.cross(yaxis, zaxis)
    xaxis /= np.linalg.norm(xaxis)
    yaxis /= np.linalg.norm(yaxis)
    t = getTransformFromAxes(xaxis, yaxis, zaxis)
    t.PostMultiply()
    t.Translate(origin)

    zwidth = 0.03
    radius = expectedValveRadius


    d = DebugData()
    d.addLine(np.array([0,0,-zwidth/2.0]), np.array([0,0,zwidth/2.0]), radius=radius)

    name = 'valve affordance'
    obj = showPolyData(d.getPolyData(), name, cls=FrameAffordanceItem, parent='affordances', color=[0,1,0])
    obj.actor.SetUserTransform(t)
    obj.addToView(app.getDRCView())
    refitWallCallbacks.append(functools.partial(refitValveAffordance, obj))

    params = dict(axis=zaxis, radius=radius, length=zwidth, origin=origin, xaxis=xaxis, yaxis=yaxis, zaxis=zaxis,
                  xwidth=radius, ywidth=radius, zwidth=zwidth,
                  otdf_type='steering_cyl', friendly_name='valve')

    obj.setAffordanceParams(params)
    obj.updateParamsFromActorTransform()

    frameObj = showFrame(obj.actor.GetUserTransform(), name + ' frame', parent=obj, scale=radius, visible=False)
    frameObj.addToView(app.getDRCView())
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/segmentation.py/segmentValve/original