Esempio n. 1
0
def xu_method(mtg,
              startfrom,
              pointList,
              binlength,
              k=20,
              filter_short_branch=False,
              angle_between_trunk_and_lateral=60):
    rootpos = Vector3(mtg.property('position')[startfrom])
    root = len(pointList)
    connect_all_points = False if mtg.nb_vertices(
        mtg.max_scale()) > 1 else True
    pointList.append(rootpos)
    positions, parents, pointcomponents = skeleton_from_distance_to_root_clusters(
        pointList,
        root,
        binlength,
        k,
        connect_all_points=connect_all_points,
        verbose=True)
    del pointList[root]

    pgltree2mtg(mtg, startfrom, parents, positions, None, filter_short_branch,
                angle_between_trunk_and_lateral)

    return mtg
Esempio n. 2
0
def graphcolonization_method(
    mtg,
    startfrom,
    pointList,
    densities,
    minbinlength,
    maxbinlength,
    binlengthfunc,
    k=20,
    filter_short_branch=False,
    angle_between_trunk_and_lateral=60,
):
    rootpos = Vector3(mtg.property("position")[startfrom])
    root = len(pointList)
    connect_all_points = False if mtg.nb_vertices(mtg.max_scale()) > 1 else True
    pointList.append(rootpos)

    kclosests = k_closest_points_from_ann(pointList, k, True)
    kclosests = connect_all_connex_components(pointList, kclosests, True)

    mindensity, maxdensity = densities.getMinAndMax()
    deltadensity = maxdensity - mindensity
    binlengthfunc.clamped = False
    normeddensity = lambda x: binlengthfunc(abs(x - mindensity) / deltadensity)

    deltabinlength = maxbinlength - minbinlength
    binlength = lambda x: minbinlength + deltabinlength * normeddensity(x)

    class CustomSCA(GraphColonization):
        def __init__(self, *args):
            GraphColonization.__init__(self, *args)
            self.use_jonction_points = True

        def node_buds_preprocess(self, nid):
            # print 'node_buds_preprocess', nid
            pos = self.node_position(nid)
            components = self.node_components(nid)
            # print nid, self.parents[nid], pos, components

            self.grid.enable_points(components)
            aid = self.grid.closest_point(pos)
            self.grid.disable_points(components)
            adensity = densities[aid]

            l = binlength(adensity)
            self.setLengths(l)

    sc = GraphColonization(pointList, maxbinlength, kclosests, root)
    sc.run()

    nodes = sc.nodes
    parents = sc.parents

    del pointList[root]

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch, angle_between_trunk_and_lateral)

    return mtg
Esempio n. 3
0
def graphcolonization_method(mtg,
                             startfrom,
                             pointList,
                             densities,
                             minbinlength,
                             maxbinlength,
                             binlengthfunc,
                             k=20,
                             filter_short_branch=False,
                             angle_between_trunk_and_lateral=60):
    rootpos = Vector3(mtg.property('position')[startfrom])
    root = len(pointList)
    connect_all_points = False if mtg.nb_vertices(
        mtg.max_scale()) > 1 else True
    pointList.append(rootpos)

    kclosests = k_closest_points_from_ann(pointList, k, True)
    kclosests = connect_all_connex_components(pointList, kclosests, True)

    mindensity, maxdensity = densities.getMinAndMax()
    deltadensity = maxdensity - mindensity
    binlengthfunc.clamped = False
    normeddensity = lambda x: binlengthfunc(abs(x - mindensity) / deltadensity)

    deltabinlength = maxbinlength - minbinlength
    binlength = lambda x: minbinlength + deltabinlength * normeddensity(x)

    class CustomSCA(GraphColonization):
        def __init__(self, *args):
            GraphColonization.__init__(self, *args)
            self.use_jonction_points = True

        def node_buds_preprocess(self, nid):
            #print 'node_buds_preprocess', nid
            pos = self.node_position(nid)
            components = self.node_components(nid)
            # print nid, self.parents[nid], pos, components

            self.grid.enable_points(components)
            aid = self.grid.closest_point(pos)
            self.grid.disable_points(components)
            adensity = densities[aid]

            l = binlength(adensity)
            self.setLengths(l)

    sc = GraphColonization(pointList, maxbinlength, kclosests, root)
    sc.run()

    nodes = sc.nodes
    parents = sc.parents

    del pointList[root]

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch,
                angle_between_trunk_and_lateral)

    return mtg
Esempio n. 4
0
def livny_method_mtg(mtg, startfrom, pointList, nbcontractionsteps = 3, maxfiltering = 10, filter_short_branch = False, angle_between_trunk_and_lateral = 60):
    from mtgmanip import pgltree2mtg
    connect_all_points = False if mtg.nb_vertices(mtg.max_scale()) > 1 else True
    rootpos = Vector3(mtg.property('position')[startfrom])
    root = len(pointList)
    pointList.append(rootpos)
    positions, parents, radii = livny_method(pointList, root, connect_all_points, nbcontractionsteps, maxfiltering)
    del pointList[root]
    pgltree2mtg(mtg, startfrom, parents, positions, radii, filter_short_branch, angle_between_trunk_and_lateral)
Esempio n. 5
0
def adaptivespacecolonization_method(mtg,
                                     startfrom,
                                     pointList,
                                     densities,
                                     mingrowthlength,
                                     maxgrowthlength,
                                     growthlengthfunc,
                                     killradiusratio,
                                     perceptionradiusratio,
                                     min_nb_pt_per_bud,
                                     filter_short_branch=False,
                                     angle_between_trunk_and_lateral=60):
    rootpos = Vector3(mtg.property('position')[startfrom])

    mindensity, maxdensity = densities.getMinAndMax()
    deltadensity = maxdensity - mindensity
    growthlengthfunc.clamped = False
    normeddensity = lambda x: growthlengthfunc(
        abs(x - mindensity) / deltadensity)

    deltabinlength = maxgrowthlength - mingrowthlength
    binlength = lambda x: mingrowthlength + deltabinlength * normeddensity(x)

    print maxgrowthlength, maxgrowthlength * killradiusratio, maxgrowthlength * perceptionradiusratio

    class CustomSCA(SpaceColonization):
        def __init__(self, *args):
            SpaceColonization.__init__(self, *args)

        def node_buds_preprocess(self, nid):
            pos = self.node_position(nid)
            components = self.node_attractors(nid)
            # print nid, self.parents[nid], pos, components
            aid, aidist = findClosestFromSubset(pos, pointList, components)
            adensity = densities[aid]

            l = binlength(adensity)
            assert l >= mingrowthlength
            self.setLengths(l, killradiusratio, perceptionradiusratio)

    sc = CustomSCA(pointList, maxgrowthlength,
                   maxgrowthlength * killradiusratio,
                   maxgrowthlength * perceptionradiusratio, rootpos)
    sc.min_nb_pt_per_bud = min_nb_pt_per_bud
    sc.run()

    nodes = sc.nodes
    parents = sc.parents

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch,
                angle_between_trunk_and_lateral)

    return mtg
Esempio n. 6
0
def spacecolonization_method(mtg, startfrom, pointList, growthlength, killradiusratio, perceptionradiusratio, min_nb_pt_per_bud, filter_short_branch = False, angle_between_trunk_and_lateral = 60):
    rootpos = Vector3(mtg.property('position')[startfrom])

    sc = SpaceColonization(pointList, growthlength, growthlength*killradiusratio, growthlength*perceptionradiusratio, rootpos)
    sc.min_nb_pt_per_bud = min_nb_pt_per_bud
    sc.run()
    
    nodes = sc.nodes
    parents = sc.parents

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch, angle_between_trunk_and_lateral)

    return mtg    
Esempio n. 7
0
def xu_method(
    mtg, startfrom, pointList, binlength, k=20, filter_short_branch=False, angle_between_trunk_and_lateral=60
):
    rootpos = Vector3(mtg.property("position")[startfrom])
    root = len(pointList)
    connect_all_points = False if mtg.nb_vertices(mtg.max_scale()) > 1 else True
    pointList.append(rootpos)
    positions, parents, pointcomponents = skeleton_from_distance_to_root_clusters(
        pointList, root, binlength, k, connect_all_points=connect_all_points, verbose=True
    )
    del pointList[root]

    pgltree2mtg(mtg, startfrom, parents, positions, None, filter_short_branch, angle_between_trunk_and_lateral)

    return mtg
Esempio n. 8
0
def livny_method_mtg(mtg,
                     startfrom,
                     pointList,
                     nbcontractionsteps=3,
                     maxfiltering=10,
                     filter_short_branch=False,
                     angle_between_trunk_and_lateral=60):
    from mtgmanip import pgltree2mtg
    connect_all_points = False if mtg.nb_vertices(
        mtg.max_scale()) > 1 else True
    rootpos = Vector3(mtg.property('position')[startfrom])
    root = len(pointList)
    pointList.append(rootpos)
    positions, parents, radii = livny_method(pointList, root,
                                             connect_all_points,
                                             nbcontractionsteps, maxfiltering)
    del pointList[root]
    pgltree2mtg(mtg, startfrom, parents, positions, radii, filter_short_branch,
                angle_between_trunk_and_lateral)
Esempio n. 9
0
def adaptivespacecolonization_method(mtg, startfrom, pointList, densities, mingrowthlength, maxgrowthlength, growthlengthfunc, killradiusratio, perceptionradiusratio, min_nb_pt_per_bud, filter_short_branch = False, angle_between_trunk_and_lateral = 60):
    rootpos = Vector3(mtg.property('position')[startfrom])

    mindensity, maxdensity = densities.getMinAndMax()
    deltadensity = maxdensity - mindensity
    growthlengthfunc.clamped = False
    normeddensity = lambda x : growthlengthfunc(abs(x - mindensity)/deltadensity)

    deltabinlength = maxgrowthlength-mingrowthlength
    binlength = lambda x: mingrowthlength + deltabinlength * normeddensity(x) 

    print maxgrowthlength, maxgrowthlength*killradiusratio, maxgrowthlength*perceptionradiusratio

    class CustomSCA(SpaceColonization):
        def __init__(self, *args):
            SpaceColonization.__init__(self,*args)
          
        def node_buds_preprocess(self,nid):
              pos = self.node_position(nid)
              components = self.node_attractors(nid)
              # print nid, self.parents[nid], pos, components
              aid, aidist = findClosestFromSubset(pos, pointList, components)
              adensity  = densities[aid]

              l = binlength(adensity)
              assert l >= mingrowthlength
              self.setLengths(l,killradiusratio,perceptionradiusratio)

    sc = CustomSCA(pointList, maxgrowthlength, maxgrowthlength*killradiusratio, maxgrowthlength*perceptionradiusratio, rootpos)
    sc.min_nb_pt_per_bud = min_nb_pt_per_bud
    sc.run()
    
    nodes = sc.nodes
    parents = sc.parents

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch, angle_between_trunk_and_lateral)

    return mtg    
Esempio n. 10
0
def spacecolonization_method(mtg,
                             startfrom,
                             pointList,
                             growthlength,
                             killradiusratio,
                             perceptionradiusratio,
                             min_nb_pt_per_bud,
                             filter_short_branch=False,
                             angle_between_trunk_and_lateral=60):
    rootpos = Vector3(mtg.property('position')[startfrom])

    sc = SpaceColonization(pointList, growthlength,
                           growthlength * killradiusratio,
                           growthlength * perceptionradiusratio, rootpos)
    sc.min_nb_pt_per_bud = min_nb_pt_per_bud
    sc.run()

    nodes = sc.nodes
    parents = sc.parents

    pgltree2mtg(mtg, startfrom, parents, nodes, None, filter_short_branch,
                angle_between_trunk_and_lateral)

    return mtg