def scales(g): """ Compute the scale of each vertex inside the graph. One solution: If we have several edges of decomposition, we follow the deeper. The root is a real node or a false one? TODO: specification """ edge_type = g.edge_property("edge_type").copy() root = g.root has_decomposition = [ eid for eid in g.out_edges(root) if edge_type.get(eid) == '/' ] scale0 = 0 _scale = {root: scale0} if not has_decomposition: empty_vertex = True for name in g.vertex_property_names(): if g.root in g.vertex_property(name): empty_vertex = False break if empty_vertex: root_edge = g.out_edges(root).next() edge_type[root_edge] = '/' for v in breadth_first_search(g, root): parents = list(g.in_neighbors(v)) edges = list(g.in_edges(v)) if not parents: continue decompositions = [eid for eid in edges if edge_type.get(eid) == '/'] if decompositions: eid_max = None scale_max = 0 for eid in decompositions: s = _scale[g.source(eid)] if s > scale_max: scale_max = s eid_max = eid scale = scale_max + 1 else: scale = max(_scale.get(pid, 0) for pid in parents) _scale[v] = scale return _scale
def scales(g): """ Compute the scale of each vertex inside the graph. One solution: If we have several edges of decomposition, we follow the deeper. The root is a real node or a false one? TODO: specification """ edge_type = g.edge_property("edge_type").copy() root = g.root has_decomposition = [eid for eid in g.out_edges(root) if edge_type.get(eid) == '/'] scale0 = 0 _scale = {root : scale0} if not has_decomposition: empty_vertex = True for name in g.vertex_property_names(): if g.root in g.vertex_property(name): empty_vertex = False break if empty_vertex: root_edge = g.out_edges(root).next() edge_type[root_edge] = '/' for v in breadth_first_search(g, root): parents = list(g.in_neighbors(v)) edges = list(g.in_edges(v)) if not parents: continue decompositions = [eid for eid in edges if edge_type.get(eid) == '/'] if decompositions: eid_max = None scale_max = 0 for eid in decompositions: s = _scale[g.source(eid)] if s > scale_max: scale_max = s eid_max = eid scale = scale_max + 1 else: scale = max(_scale.get(pid,0) for pid in parents) _scale[v] = scale return _scale
def traverse2(self, vid): from openalea.container.traversal.graph import breadth_first_search g = self._graph edge_type = g.edge_property("edge_type") transform = g.vertex_property("transform") local_turtles = g.vertex_property("turtle_state") transfos = {g.root: pgl.Matrix4()} # CPL turtles = {g.root: TurtleState()} def parent(vid): for eid in g.in_edges(vid): if edge_type[eid] in ['<', '+', '/']: return g.source(eid) return vid def update_turtle(v, ts): local_turtle = local_turtles.get(v, TurtleState()) global_turtle = ts.combine(local_turtle) return global_turtle for v in breadth_first_search(g, vid): pid = parent(v) if pid == v and v != g.root: print "ERRRORRRR" print v continue # print "v",v # print "parent(v)", parent(v) # print "transfos", transfos #m = transfos[parent(v)] m = transfos.get(pid) # CPL ts = turtles.get(pid, TurtleState()) gt = global_turtle = update_turtle(v, ts) local_t = transform.get(v) if local_t == self.FUNCTIONAL: # Get the functional shape to compute the transformation and geometry # with the turtle state local_t = self.f_shape(v, global_turtle) # print "every m : ", m # Transform the current shape with the stack of transfos m from the root. # Store the result in the graph. self._local2global(v, m, global_turtle.color) # print "local_t : ", local_t if local_t == -1: m = adjust_lu(m) elif local_t == -2: #RV and RG local_m = grotation(m, gt.tropism) m = m * local_m elif local_t == -3: # RD local_m = directionalTropism(m, gt.tropism_direction, gt.tropism) m = m * local_m elif local_t == -4: # RO local_m = orthogonalTropism(m, gt.tropism_direction, gt.tropism) m = m * local_m elif local_t == -5: #RP and RN local_m = positionalTropism(m, gt.tropism_target, gt.tropism) m = m * local_m elif local_t: if local_t.getColumn(3) != Vector4(0, 0, 0, 1): m = m * local_t else: m = m * local_t else: # print m pass transfos[v] = m turtles[v] = global_turtle