def get_first_param_value(mtg, propname): from openalea.mtg.traversal import iter_mtg2 scale = mtg.max_scale() prop = mtg.property(propname) for vid in iter_mtg2(mtg, mtg.root): if vid in prop and mtg.scale(vid) == scale and not prop[vid] is None: return prop[vid]
def potted_syrah(): """Returns an `openalea.mtg` representing a potted syrah grapevine.""" digit = join(sources_dir, 'grapevine_pot.csv') g = architecture.vine_mtg(digit) # Local Coordinates Correction for v in traversal.iter_mtg2(g, g.root): n = g.node(g.Trunk(v, Scale=1)[0]) theta = 180 if int(n.index()) < 200 else -90 if int(n.index()) < 300 else 0 architecture.vine_orientation(g, v, theta, local_rotation=True) # rotation for v in traversal.iter_mtg2(g, g.root): architecture.vine_orientation(g, v, 90., local_rotation=False) for v in traversal.iter_mtg2(g, g.root): architecture.vine_phyto_modular(g, v) architecture.vine_mtg_properties(g, v) architecture.vine_mtg_geometry(g, v) architecture.vine_transform(g, v) return g
def threshold_filter(mtg, propname): from openalea.mtg.traversal import iter_mtg2 prop = mtg.property(propname) nprop = dict() for vid in iter_mtg2(mtg, mtg.root): if vid in prop: parent = mtg.parent(vid) if parent and parent in prop: pvalue = nprop.get(parent, prop[parent]) if pvalue < prop[vid]: nprop[vid] = pvalue prop.update(nprop)
def threshold_filter(mtg, propname): from openalea.mtg.traversal import iter_mtg2 prop = mtg.property(propname) nprop = dict() for vid in iter_mtg2(mtg, mtg.root): if vid in prop: parent = mtg.parent(vid) if parent and parent in prop: pvalue = nprop.get(parent,prop[parent]) if pvalue < prop[vid]: nprop[vid] = pvalue prop.update(nprop)
def mtg(self): """ Convert the MTG into a XML tree. """ g = self._g # Create a DocType at the begining of the file # Traverse the MTG self.trees = [] self.xml_nodes = {} self.branching_point = {} # self.spaces = 0 for tree_id in g.components_iter(g.root): self.Tree(tree_id) for vid in traversal.iter_mtg2(g, tree_id): if vid == tree_id: continue self.process_vertex(vid)
from os import getcwd from openalea.mtg import traversal from openalea.plantgl.all import Scene from hydroshoot import architecture, display, model # ============================================================================= # Construct the plant mock-up # ============================================================================= # Path for plant digitalization data. g = architecture.vine_mtg('grapevine_pot.csv') # Local Coordinates Correction for v in traversal.iter_mtg2(g, g.root): n = g.node(g.Trunk(v, Scale=1)[0]) theta = 180 if int(n.index()) < 200 else -90 if int(n.index()) < 300 else 0 architecture.vine_orientation(g, v, theta, local_rotation=True) # Scene rotation for v in traversal.iter_mtg2(g, g.root): architecture.vine_orientation(g, v, 90., local_rotation=False) for v in traversal.iter_mtg2(g, g.root): architecture.vine_phyto_modular(g, v) architecture.vine_mtg_properties(g, v) architecture.vine_mtg_geometry(g, v) architecture.vine_transform(g, v) # Display of the plant mock-up (result in 'fig_01_plant_mock_up.png')