def segmentValveByWallPlane(expectedValveRadius, point1, point2):


    centerPoint = (point1 + point2) / 2.0

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

    _ , polyData =  removeGround(polyData)

    viewDirection = SegmentationContext.getGlobalInstance().getViewDirection()
    polyData, origin, normal = applyPlaneFit(polyData, expectedNormal=-viewDirection, returnOrigin=True)


    perpLine = np.cross(point2 - point1, normal)
    #perpLine /= np.linalg.norm(perpLine)
    #perpLine * np.linalg.norm(point2 - point1)/2.0
    point3, point4 = centerPoint + perpLine/2.0, centerPoint - perpLine/2.0

    d = DebugData()
    d.addLine(point1, point2)
    d.addLine(point3, point4)
    updatePolyData(d.getPolyData(), 'crop lines', parent=getDebugFolder(), visible=False)

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

    searchRegion = thresholdPoints(polyData, 'dist_to_plane', [0.05, 0.5])
    searchRegion = cropToLineSegment(searchRegion, point1, point2)
    searchRegion = cropToLineSegment(searchRegion, point3, point4)

    updatePolyData(searchRegion, 'valve search region', parent=getDebugFolder(), color=[1,0,0], visible=False)

    searchRegionSpokes = shallowCopy(searchRegion)

    searchRegion, origin, _  = applyPlaneFit(searchRegion, expectedNormal=normal, perpendicularAxis=normal, returnOrigin=True)
    searchRegion = thresholdPoints(searchRegion, 'dist_to_plane', [-0.015, 0.015])

    updatePolyData(searchRegion, 'valve search region 2', parent=getDebugFolder(), color=[0,1,0], visible=False)


    largestCluster = extractLargestCluster(searchRegion, minClusterSize=1)

    updatePolyData(largestCluster, 'valve cluster', parent=getDebugFolder(), color=[0,1,0], visible=False)


    radiusLimit = [expectedValveRadius - 0.01, expectedValveRadius + 0.01] if expectedValveRadius else None
    #radiusLimit = None

    polyData, circleFit = extractCircle(largestCluster, distanceThreshold=0.01, radiusLimit=radiusLimit)
    updatePolyData(polyData, 'circle fit', parent=getDebugFolder(), visible=False)


    #polyData, circleFit = extractCircle(polyData, distanceThreshold=0.01)
    #showPolyData(polyData, 'circle fit', colorByName='z')


    radius = circleFit.GetCircleRadius()
    origin = np.array(circleFit.GetCircleOrigin())
    circleNormal = np.array(circleFit.GetCircleNormal())
    circleNormal = circleNormal/np.linalg.norm(circleNormal)

    if np.dot(circleNormal, normal) < 0:
        circleNormal *= -1

    # force use of the plane normal
    circleNormal = normal
    radius = expectedValveRadius

    d = DebugData()
    d.addLine(normal*radius - origin, origin + normal*radius)
    d.addCircle(origin, circleNormal, radius)
    updatePolyData(d.getPolyData(), 'valve axes', parent=getDebugFolder(), visible=False)


    zaxis = -circleNormal
    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) # this was added to be consistent with segmentValveByRim
    t = getTransformFromAxes(zaxis, -yaxis, xaxis) # this was added to be consistent with segmentValveByRim
    t.PostMultiply()
    t.Translate(origin)


    # Spoke angle fitting:
    if (1==0): # disabled jan 2015
        # extract the relative positon of the points to the valve axis:
        searchRegionSpokes = labelDistanceToLine(searchRegionSpokes, origin, [origin + circleNormal])
        searchRegionSpokes = thresholdPoints(searchRegionSpokes, 'distance_to_line', [0.05, radius-0.04])
        updatePolyData(searchRegionSpokes, 'valve spoke search', parent=getDebugFolder(), visible=False)
        searchRegionSpokesLocal = transformPolyData(searchRegionSpokes, t.GetLinearInverse() )
        points = vtkNumpy.getNumpyFromVtk(searchRegionSpokesLocal , 'Points')

        spoke_angle = findValveSpokeAngle(points)
    else:
        spoke_angle = 0

    spokeAngleTransform = transformUtils.frameFromPositionAndRPY([0,0,0], [0,0,spoke_angle])
    spokeTransform = transformUtils.copyFrame(t)
    spokeAngleTransform.Concatenate(spokeTransform)
    spokeObj = showFrame(spokeAngleTransform, 'spoke frame', parent=getDebugFolder(), visible=False, scale=radius)
    spokeObj.addToView(app.getDRCView())
    t = spokeAngleTransform

    tubeRadius = 0.017

    pose = transformUtils.poseFromTransform(t)
    desc = dict(classname='CapsuleRingAffordanceItem', Name='valve', uuid=newUUID(), pose=pose, Color=[0,1,0], Radius=float(radius), Segments=20)
    desc['Tube Radius'] = tubeRadius

    obj = affordanceManager.newAffordanceFromDescription(desc)
    obj.params = dict(radius=radius)
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/segmentation.py/segmentValveByWallPlane/swapped operands of `-`