def test_mtglpy_topvine(): fn = path('vinemtg_n.lpy') if not fn.exists(): return l = Lsystem(str(fn)) parameters = {} parameters['carto_file'] = 'geom_n.dat' parameters['picle_file'] = 'vine_n.dat' parameters['TTfin'] = None #l.context().updateNamespace(parameters) c_iter = l.getLastIterationNb() nbstep = l.derivationLength - c_iter tree = l.iterate(l.axiom, c_iter, nbstep) scene = l.sceneInterpretation(tree) mtg = lpy2mtg(tree, l, scene) print(len(mtg)) axial_tree = AxialTree() axial_tree = mtg2lpy(mtg, l, axial_tree) g = lpy2mtg(axial_tree, l, scene) assert len(g) == len(mtg) #axial_tree = mtg2axialtree(mtg, scale, parameters, axial_tree) # Check assert True return mtg, tree, axial_tree
def Tree2Scene(axialtree, lsystem=None): """ Convert AxialTree to PGL Scene """ if type(axialtree) != AxialTree: axialtree = AxialTree(axialtree) if lsystem: return lsystem.sceneInterpretation(axialtree) else: return (generateScene(axialtree), )
def str2mtg(s): #s = s.replace('N', 'F') tree = AxialTree(s) l = Lsystem() l.addInterpretationRule('N --> F', 0) geom_tree = l.homomorphism(tree) scene = l.sceneInterpretation(geom_tree) scale = dict(list(zip(('P', 'A', 'N', 'L', 'F'), (1, 2, 3, 3, 3)))) mtg = axialtree2mtg(tree, scale, scene) return tree, mtg, scene
def __init__(self): l = LsysContext() l.makeCurrent() m1 = ParamModule('A', Apex()) m2 = ParamModule('A', Apex()) m3 = ParamModule('A', Apex()) m4 = ParamModule('A', Apex()) m5 = ParamModule('A', Apex()) m6 = ParamModule('A', Apex()) self.axialtree = AxialTree([m1, m2, m3, m4, m5, m6])
def notify(self, sender, event): """ Function called by observed objects """ lcode = self.node.get_input('Code') self.lsystem.set(lcode) axiom = self.node.get_input('Axiom') if len(axiom) > 0: self.lsystem.axiom = AxialTree(axiom) derivationLength = self.node.get_input('DerivationLength') if derivationLength >= 0: self.lsystem.derivationLength = derivationLength self.codeeditor.setText(lcode)
def run(lsystem, axiom='', nbstep=-1, parameters={}): """ Run a lsystem """ c_iter = lsystem.getLastIterationNb() if nbstep < 0: nbstep = lsystem.derivationLength - c_iter if len(axiom) == 0: axiom = lsystem.axiom elif type(axiom) == str: lsystem.makeCurrent() axiom = AxialTree(axiom) lsystem.done() if len(parameters) > 0: lsystem.context().updateNamespace(parameters) return lsystem.iterate(axiom, c_iter, nbstep), lsystem
def lsystem(file_name, axiom='', derivationlength=-1, parameters={}): """ Build a lsystem object from file_name """ l = Lsystem(file_name, parameters) if len(axiom): l.makeCurrent() if type(axiom) != AxialTree: axiom = AxialTree(axiom) l.axiom = axiom #l.done() if derivationlength >= 0: l.derivationLength = derivationlength return l
def plot(axiom='', lsystem=None): """ Plot a string """ if len(axiom) == 0: axiom = lsystem.axiom elif type(axiom) != AxialTree: if lsystem: lsystem.makeCurrent() axiom = AxialTree(axiom) if lsystem: lsystem.done() if (lsystem): Viewer.animation(False) lsystem.plot(axiom) else: plot(axiom) return (axiom, )
def create_test_lstring(): """Create a lstring to play with (in test for instance) >>> l = create_test_lstring() """ from openalea.lpy import AxialTree, ParamModule from openalea.plantik import Apex, Leaf, Internode, Branch, \ GrowthUnit, Plant N = 5 P = ParamModule('P', Plant(1)) A = ParamModule('A', Apex()) L = ParamModule('L', Leaf(resource_per_day=0.5)) I = ParamModule('I', Internode()) B = ParamModule('B', Branch()) U = ParamModule('U', GrowthUnit()) a = AxialTree([B, U, A, I, L, A, I, L, A, I, L, A]) return a
def test_mtglpy(): fn = path('ex_luz4.lpy') if not fn.exists(): return l = Lsystem('ex_luz4.lpy') tree = l.iterate() scene = l.sceneInterpretation(tree) mtg = lpy2mtg(tree, l, scene) print(len(mtg)) axial_tree = AxialTree() axial_tree = mtg2lpy(mtg, l, axial_tree) print(len(axial_tree)) #axial_tree = mtg2axialtree(mtg, scale, parameters, axial_tree) # Check assert True return mtg, tree
def axialtree(lstring): """ Build an axial tree object """ return AxialTree(lstring)
# :return: adapted axialtree # """ # # def repr_geom(self): # return __scene # # scene = lsystem.sceneInterpretation(axialtree) # axialtree.__scene = scene # axialtree._repr_geom_ = types.MethodType(repr_geom, axialtree) # # return axialtree context = {} lsystem = Lsystem() axialtree = AxialTree() # axialtree = adapt_axialtree(axialtree, lsystem) code = ''' """ input = lstring="_(0.01)-(90)F(1)" output = lstring """ N = 2 derivation length: N production: F(x) :
def shoot_grow(g, demand_only=True): lsys = Lsystem(str(os.path.join(lsysdir, 'morphogenesis.lpy')), {'demand_only': demand_only}) lsys.axiom = mtg2lpy(g, lsys, AxialTree()) axt = lsys.iterate() scene = lsys.sceneInterpretation(axt) return lpy2mtg(axt, lsys, scene)