def segmentDrillAuto(point1, polyData=None):

    if polyData is None:
        inputObj = om.findObjectByName('pointcloud snapshot')
        polyData = inputObj.polyData

    expectedNormal = np.array([0.0, 0.0, 1.0])

    polyData, origin, normal = applyPlaneFit(polyData, expectedNormal=expectedNormal, perpendicularAxis=expectedNormal, searchOrigin=point1, searchRadius=0.4, angleEpsilon=0.2, returnOrigin=True)


    tablePoints = thresholdPoints(polyData, 'dist_to_plane', [-0.01, 0.01])
    updatePolyData(tablePoints, 'table plane points', parent=getDebugFolder(), visible=False)

    tablePoints = labelDistanceToPoint(tablePoints, point1)
    tablePointsClusters = extractClusters(tablePoints)
    tablePointsClusters.sort(key=lambda x: vtkNumpy.getNumpyFromVtk(x, 'distance_to_point').min())

    tablePoints = tablePointsClusters[0]
    updatePolyData(tablePoints, 'table points', parent=getDebugFolder(), visible=False)

    searchRegion = thresholdPoints(polyData, 'dist_to_plane', [0.03, 0.4])
    searchRegion = cropToSphere(searchRegion, point1, 0.30)
    drillPoints = extractLargestCluster(searchRegion, minClusterSize=1)


    # determine drill orientation (rotation about z axis)

    centroids = computeCentroids(drillPoints, axis=normal)

    centroidsPolyData = vtkNumpy.getVtkPolyDataFromNumpyPoints(centroids)
    d = DebugData()
    updatePolyData(centroidsPolyData, 'cluster centroids', parent=getDebugFolder(), visible=False)

    drillToTopPoint = np.array([-0.002904, -0.010029, 0.153182])

    zaxis = normal
    yaxis = centroids[0] - centroids[-1]
    yaxis /= np.linalg.norm(yaxis)
    xaxis = np.cross(yaxis, zaxis)
    xaxis /= np.linalg.norm(xaxis)
    yaxis = np.cross(zaxis, xaxis)

    # note this hack to orient the drill correctly:
    t = getTransformFromAxes(yaxis, -xaxis, zaxis)
    t.PreMultiply()
    t.Translate(-drillToTopPoint)
    t.PostMultiply()
    t.Translate(centroids[-1])

    drillMesh = getDrillMesh()

    aff = showPolyData(drillMesh, 'drill', cls=FrameAffordanceItem, visible=True)
    aff.actor.SetUserTransform(t)
    showFrame(t, 'drill frame', parent=aff, visible=False, scale=0.2).addToView(app.getDRCView())

    params = getDrillAffordanceParams(origin, xaxis, yaxis, zaxis)
    aff.setAffordanceParams(params)
    aff.updateParamsFromActorTransform()
    aff.addToView(app.getDRCView())
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/segmentation.py/segmentDrillAuto/original