source: subversion/applications/rendering/parking/osray/osray_buildings.py @ 22312

Last change on this file since 22312 was 22300, checked in by kdrangmeister, 9 years ago

bugfix

File size: 4.0 KB
Line 
1# -*- coding: utf-8 -*-
2# by kay - basic functions
3
4from osray_db import *
5from osray_geom import *
6
7Radiosity = True
8
9buildingtypes = {
10    'yes':['<1,0.8,0.8>',1.0],
11    'office':['<1,0.6,0.6>',1.0],
12    'apartments':['<0.8,1,0.6>',1.0],
13    'garages':['<0.8,0.8,0.8>',1.0],
14    }
15amenitybuildingtypes = {
16    'place_of_worship':['<1,1,0.6>',1.0],
17    'hospital':['<1,0.6,0.6>',1.0],
18    'theatre':['<1,0.6,1>',1.0],
19    'university':['<0.6,1,0.8>',1.0],
20    'parking':['<0.6,0.6,1>',1.0]
21    }
22
23
24def pov_declare_building_textures(f):
25    if Radiosity:
26        declare_building_texture = """
27#declare texture_building_{buildingtype} =
28    texture {{
29        pigment {{
30            color rgb {color}
31        }}
32        finish {{
33            diffuse 0.8
34            ambient 0
35        }}
36    }}
37"""
38    else:
39        declare_building_texture = """
40#declare texture_building_{buildingtype} =
41    texture {{
42        pigment {{
43            color rgb {color}
44        }}
45        finish {{
46            specular 0.5
47            roughness 0.05
48            ambient 0.3
49            /*reflection 0.5*/
50        }}
51    }}
52"""
53    for buildingtype in buildingtypes.keys():
54        buildingparams = buildingtypes.get(buildingtype)
55        color = buildingparams[0]
56        f.write(declare_building_texture.format(color=color,buildingtype=buildingtype))
57    for buildingtype in amenitybuildingtypes.keys():
58        buildingparams = amenitybuildingtypes.get(buildingtype)
59        color = buildingparams[0]
60        f.write(declare_building_texture.format(color=color,buildingtype=buildingtype))
61
62def get_building_texture(building,amenity,cladding):
63    buildingparams = buildingtypes.get(building)
64    texture = building
65    if amenity!=None:
66        if amenitybuildingtypes.has_key(amenity): # if amenity is known, use that color
67            texture = amenity
68    if cladding!=None:
69        if claddingtypes.has_key(cladding): # if cladding is known, use that color
70            texture = cladding
71    return texture
72
73def pov_building(f,building):
74    buildingtype = building[2]
75    #buildingtype = 'secondary'
76    buildingparams = buildingtypes.get(buildingtype)
77
78    linestring = building[1]
79    linestring = linestring[8:] # cut off the "POLYGON("
80    linestring = linestring[:-1] # cut off the ")"
81
82    heightstring = building[4] # building:height
83    if (heightstring==None):
84        heightstring = building[3]
85        if (heightstring==None):
86            height = 10.0
87        else:
88            height = parse_length_in_meters(heightstring,0.01)
89    else:
90        height = parse_length_in_meters(heightstring,0.01)
91
92    amenity = building[5]
93    #print amenity
94
95    points = linestring.split(',')#.strip('(').strip(')')
96    #print points
97
98    numpoints = len(points)
99    f.write("prism {{ linear_spline  0, 1, {0},\n".format(numpoints))
100    f.write("/* osm_id={0} */\n".format(building[0]))
101
102    for i,point in enumerate(points):
103        latlon = point.split(' ')
104        if (i==0):
105            firstpoint="<{0}, {1}>\n".format(latlon[0],latlon[1])
106        if (i!=numpoints-1):
107            f.write("  <{0}, {1}>,\n".format(latlon[0].strip('(').strip(')'),latlon[1].strip('(').strip(')')))
108        else:
109            f.write("  <{0}, {1}>\n".format(latlon[0].strip('(').strip(')'),latlon[1].strip('(').strip(')')))
110    #f.write(firstpoint)
111
112    color = buildingparams[0]
113    if amenitybuildingtypes.has_key(amenity): # if amenity is known, use that color
114        amenitybuildingparams = amenitybuildingtypes.get(amenity)
115        color = amenitybuildingparams[0]
116
117    texture = get_building_texture(buildingtype,amenity,None)
118    f.write("""texture {{ texture_building_{texture} }}""".format(texture=texture))
119    f.write("""
120    scale <1, {height}, 1>
121}}
122\n""".format(height=height))
123
124def render_buidings(f,osraydb,options):
125    Radiosity = options['radiosity']
126    pov_declare_building_textures(f)
127    buildings = []
128    for buildingtype in buildingtypes.iterkeys():
129        buildings += osraydb.select_buildings(buildingtype)
130   
131    for building in buildings:
132        pov_building(f,building)
133
Note: See TracBrowser for help on using the repository browser.