source: subversion/applications/rendering/parking/osray/osray_network.py @ 22368

Revision 22368, 1.1 KB checked in by kdrangmeister, 4 years ago (diff)

roads as network - layer heights averaged

Line 
1# -*- coding: utf-8 -*-
2# by kay - basic functions
3
4import networkx as nx
5
6class osrayNetwork():
7
8    G = None
9
10    def __init__(self):
11        self.G = nx.Graph()
12
13    def add_highway(self,highway_way,layer):
14        lastpoint = None
15        for point in highway_way:
16            self.G.add_node(point)
17            print "adding node:",point
18            if(lastpoint!=None):
19                self.G.add_edge(lastpoint,point,layer=layer)
20                print "adding edge:",(lastpoint,point,layer)
21            lastpoint=point
22        print "G=",self.G.number_of_nodes(),self.G.number_of_edges()
23
24    def calculate_height_on_nodes(self):
25        for n in self.G.nodes():
26            neighbors = self.G.neighbors(n)
27            sum_height = 0.0
28            for m in neighbors:
29                edge = self.G[n][m]
30                print "Edge(n,m)=",n,m,edge
31                sum_height += edge['layer']*5.0
32            self.G.node[n]['height'] = sum_height/len(neighbors)
33
34    def get_height(self,n):
35        return self.G.node[n]['height']
36
37    def printG(self):
38        print "G=",self.G.edges()
39
40           
Note: See TracBrowser for help on using the repository browser.