def binByScalar(lidarData, scalarArrayName, binWidth, binLabelsArrayName='bin_labels'):
    '''
    Gets the array with name scalarArrayName from lidarData.
    Computes bins by dividing the scalar array into bins of size binWidth.
    Adds a new label array to the lidar points identifying which bin the point belongs to,
    where the first bin is labeled with 0.
    Returns the new, labeled lidar data and the bins.
    The bins are an array where each value represents a bin edge.
    '''

    scalars = vtkNumpy.getNumpyFromVtk(lidarData, scalarArrayName)
    bins = np.arange(scalars.min(), scalars.max()+binWidth, binWidth)
    binLabels = np.digitize(scalars, bins) - 1
    assert(len(binLabels) == len(scalars))
    newData = shallowCopy(lidarData)
    vtkNumpy.addNumpyToVtk(newData, binLabels, binLabelsArrayName)
    return newData, bins
dataset/ETHPy150Open RobotLocomotion/director/src/python/director/segmentation.py/binByScalar/original