#NEWLINE# def pcloud_and_lgroup_from_ranges( pointcloud , labels_to_ranges ) : #NEWLINE# #INDENT# "\n    Label the given pointcloud according to the given ordered dictionary\n    of labels to ranges. This assumes that you can semantically label the group\n    by using ranges in to the existing points e.g ::\n\n        labels_to_ranges = {'jaw': (0, 17, False)}\n\n    The third element of the range tuple is whether the range is a closed loop\n    or not. For example, for an eye landmark this would be ``True``, as you\n    do want to create a closed loop for an eye.\n\n    Parameters\n    ----------\n    pointcloud : :map:`PointCloud`\n        The pointcloud to apply semantic labels to.\n    labels_to_ranges : `ordereddict` {`str` -> (`int`, `int`, `bool`)}\n        Ordered dictionary of string labels to range tuples.\n\n    Returns\n    -------\n    new_pcloud : :map:`PointCloud`\n        New pointcloud with specific connectivity information applied.\n    mapping : `ordereddict` {`str` -> `int ndarray`}\n        For each label, the indices in to the pointcloud that belong to the\n        label.\n    " #NEWLINE# from menpo.shape import PointUndirectedGraph #NEWLINE# mapping = OrderedDict ( ) #NEWLINE# all_connectivity = [ ] #NEWLINE# for ( label , tup ) in labels_to_ranges . items ( ) : #NEWLINE# #INDENT# range_tuple = tup [ : ( - 1 ) ] #NEWLINE# close_loop = tup [ ( - 1 ) ] #NEWLINE# connectivity = connectivity_from_range ( range_tuple , close_loop = close_loop ) #NEWLINE# all_connectivity . append ( connectivity ) #NEWLINE# mapping [ label ] = np . arange ( * range_tuple ) #NEWLINE# #UNINDENT# all_connectivity = np . vstack ( all_connectivity ) #NEWLINE# new_pcloud = PointUndirectedGraph . init_from_edges ( labels_to_ranges . points , all_connectivity ) #NEWLINE# return ( new_pcloud , mapping )