def write_points(f, contours, starts=None):
    """
    Outputs the contours as a "points" file with each line in the file listing the object id,
    contour id within the object, and then x, y, and z for each point. This file is directly
    compatible with the IMOD program point2model. The file-like object f must have a write
    method. An optional argument starts is a dictionary of starting values for the contour
    numbers for each object, defaulting to all 1s. This function returns the ending values
    for use to another call to write_points as the starts.
    """
    if starts is None: starts = {}
    for obj_id,conts in contours.iteritems():
        for cont_id,cont in enumerate(conts, starts.setdefault(obj_id, 1)):
            for x,y,z in cont:
                f.write("%d %d %.2f %.2f %.2f\n" % (obj_id, cont_id, x, y, z))
        starts[obj_id] += len(conts)
    return starts