def tree_to_array(cls, tree, region_number_to_name_bidict=None):

        if region_number_to_name_bidict is None:
            if tree.region_number_to_name_bidict is not None:
                region_number_to_name_bidict = copy.deepcopy(
                    tree.region_number_to_name_bidict)
            else:
                region_number_to_name_bidict = AutoRegionToIntMapTable()

        vertices = [None] * (len(tree) + 1)
        connectivity = []
        section_types = []
        section_index = SectionIndexerDF(morph=tree, offset=1).dict
        section_index[tree.get_dummy_section()] = 0

        for seg in tree._every_section():
            index = section_index[seg]

            # Store the vertices:
            vertices[index] = seg.get_distal_npa4()

            # Store the link to the parent:
            if not seg.is_dummy_section():
                connectivity.append((index, section_index[seg.parent]))

            # Store the type:
            if not seg.is_dummy_section():
                region = seg.region
                if region:
                    section_types.append(
                        region_number_to_name_bidict.region_name_to_int(
                            region.name))
                else:
                    section_types.append(0)

        return MorphologyArray(vertices=vertices,
                               connectivity=connectivity,
                               dummy_vertex_index=0,
                               section_types=section_types)
    def tree_to_array(cls, tree, region_number_to_name_bidict=None):

        if region_number_to_name_bidict is None:
            if tree.region_number_to_name_bidict is not None:
                region_number_to_name_bidict = copy.deepcopy(tree.region_number_to_name_bidict)
            else:
                region_number_to_name_bidict = AutoRegionToIntMapTable()

        vertices = [None] * (len(tree) + 1)
        connectivity = []
        section_types = []
        section_index = SectionIndexerDF(morph=tree, offset=1).dict
        section_index[tree.get_dummy_section()] = 0

        for seg in tree._every_section():
            index = section_index[seg]

            # Store the vertices:
            vertices[index] = seg.get_distal_npa4()

            # Store the link to the parent:
            if not seg.is_dummy_section():
                connectivity.append((index, section_index[seg.parent]))

            # Store the type:
            if not seg.is_dummy_section():
                region = seg.region
                if region:
                    section_types.append(region_number_to_name_bidict.region_name_to_int(region.name))
                else:
                    section_types.append(0)

        return MorphologyArray(vertices=vertices,
                            connectivity=connectivity,
                            dummy_vertex_index=0,
                            section_types=section_types)