def convert_to_hierarchical(contours):
    """
    convert list of contours into a hierarchical structure
    slice > frame > heartpart -- Contour
    :param contours: list of Contour objects
    :return: a hierarchical structure which contains Contour objects
    """
    hierarchical_contours = {}
    for contour in contours:
        if not(contour.slice in hierarchical_contours.keys()):
            hierarchical_contours[contour.slice] = {}
        if not(contour.frame in hierarchical_contours[contour.slice].keys()):
            hierarchical_contours[contour.slice][contour.frame] = {}
        hierarchical_contours[contour.slice][contour.frame][contour.part] = contour
    return hierarchical_contours