source: subversion/applications/rendering/parking/osray/osray_ground.py @ 22409

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

tuning

File size: 7.9 KB
Line 
1# -*- coding: utf-8 -*-
2# by kay - create color texture map for ground
3
4import sys
5import commands
6import psycopg2
7import csv
8import re
9from numpy import *
10from osray_db import *
11from osray_geom import *
12
13def pov_text(f,x,y,txt):
14    f.write("""text {{
15    ttf "timrom.ttf" "{txt}" 1, 0
16    pigment {{ rgbt <0.5,0.5,0.5,0.5> }}
17    translate <-{center},0,0>
18    rotate <90, 0, 0>
19    scale <18,0,18>
20    translate <{x},0.3,{y}>
21}}
22\n""".format(txt=txt,x=x,y=y,center=0.25*len(txt)))
23
24landusetypes = {
25    'residential':['<1,0.9,0.8>'],
26
27    'retail':['<1,1,0.9>'],
28    'commercial':['<1,1,0.9>'],
29    'industrial':['<1,1,0.7>'],
30
31    'hospital':['<1,0.8,0.8>'],
32    'landfill':['<0.6,0.7,0.4>'],
33   
34    'recreation_ground':['<0.8,0.9,0.8>'],
35    'city_green':['<0.7,0.9,0.7>'],
36    'village_green':['<0.7,0.9,0.7>'],
37    'meadow':['<0.7,0.9,0.7>'],
38    'grass':['<0.7,0.9,0.6>'],
39
40    'cemetery':['<0.8,0.85,0.8>'],
41
42    'farm':['<0.8,0.9,0.6>'],
43    'farmland':['<0.8,0.9,0.7>'],
44    'farmyard':['<0.8,0.9,0.7>'],
45    'vineyard':['<0.5,0.9,0.6>'],
46
47    'allotments':['<0.6,0.7,0.6>'],
48
49    'forest':['<0.5,0.8,0.5>'],
50    'wood':['<0.5,0.8,0.5>'],
51    'unknown':['<1,0,1>']
52    }
53"""
54basin (4356)
55quarry (2410)
56construction (1649)
57reservoir (1475)
58greenfield (1206)
59landfill (1038)
60brownfield (1036)
61orchard (956)
62railway (768)
63military (685)
64wood (491)
65garages (275)
66piste (89)
67mine_spoils (77)
68greenhouse_horticulture (74)
69scrub (65)
70water (54)
71Sand (41)
72building (39)
73park (36)
74resis (34)
75plaza (31)
76civil (31)
77garden (28)
78mining (22)
79yes (22)
80mixed (22)
81common (21)
82paddock (15)
83fields (15)
84Gehege (13)
85conservation (13)
86sport (12)
87green (12)
88wasteland (12)
89"""
90
91def pov_landuse(f,landuse):
92    landusetype = landuse['landuse']
93    if landusetype in landusetypes:
94        landuseparams = landusetypes.get(landusetype)
95    else:
96        landuseparams = landusetypes.get('unknown')
97        print "### unknown landuse '{l}' found in osm_id {id}".format(l=landusetype,id=landuse['osm_id']) 
98
99    polygon = landuse['coords']
100
101    numpoints = len(polygon)
102    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
103    f.write("/* osm_id={0} */\n".format(landuse['osm_id']))
104
105    for i,point in enumerate(polygon):
106        x,y = point
107        if (i!=numpoints-1):
108            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
109        else:
110            f.write("  <{x}, {y}>\n".format(x=x,y=y))
111
112    color = landuseparams[0]
113
114    f.write("""
115    texture {{
116        pigment {{
117            color rgb {0}
118        }}
119        finish {{
120            ambient 1
121            /*specular 0.5
122            roughness 0.05
123            reflection 0.5*/
124        }}
125    }}
126}}
127\n""".format(color))
128    if landusetype in landusetypes:
129        pass
130    else:
131        pov_text(f,x,y,landusetype)
132
133#-----------------------------------------------------------------------------
134
135leisuretypes = {
136    'park':['<0.7,1,0.6>'],'common':['<0.7,1,0.6>'],
137    'pitch':['<0.3,1,0.8>'],'sports_centre':['<0.3,1,0.8>'],
138    'track':['<0.9,0.7,0.6>'],
139    'playground':['<0.2,0.9,0.9>'],
140    'garden':['<1,1,0.4>'],
141    'unknown':['<1,0,1>']
142    }
143
144def pov_leisure(f,leisure):
145    leisuretype = leisure['leisure']
146    if leisuretype in leisuretypes:
147        leisureparams = leisuretypes.get(leisuretype)
148    else:
149        leisureparams = leisuretypes.get('unknown')
150
151    polygon = leisure['coords']
152
153    numpoints = len(polygon)
154    f.write("prism {{ linear_spline  0, 0.02, {0},\n".format(numpoints))
155    f.write("/* osm_id={0} */\n".format(leisure['osm_id']))
156
157    for i,point in enumerate(polygon):
158        x,y = point
159        if (i!=numpoints-1):
160            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
161        else:
162            f.write("  <{x}, {y}>\n".format(x=x,y=y))
163
164    color = leisureparams[0]
165
166    f.write("""
167    texture {{
168        pigment {{
169            color rgb {0}
170        }}
171        finish {{
172            ambient 1
173            /*specular 0.5
174            roughness 0.05
175            reflection 0.5*/
176        }}
177    }}
178}}
179\n""".format(color))
180    if leisuretype in leisuretypes:
181        pass
182    else:
183        pov_text(f,x,y,leisuretype)
184
185#-----------------------------------------------------------------------------
186
187waterwaytypes = {
188    'riverbank':['<0.2,0.2,0.9>'],
189    'dock':['<0.2,0.2,0.8>']
190    }
191
192def pov_waterway(f,waterway):
193    waterwaytype = waterway['waterway']
194    waterwayparams = waterwaytypes.get(waterwaytype)
195
196    polygon = waterway['coords']
197    numpoints = len(polygon)
198    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
199    f.write("/* osm_id={0} */\n".format(waterway['osm_id']))
200
201    for i,point in enumerate(polygon):
202        x,y = point
203        if (i!=numpoints-1):
204            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
205        else:
206            f.write("  <{x}, {y}>\n".format(x=x,y=y))
207
208    color = waterwayparams[0]
209
210    f.write("""
211    texture {{
212        pigment {{
213            color rgb {0}
214        }}
215        finish {{
216            ambient 1
217            /*specular 0.5
218            roughness 0.05
219            reflection 0.5*/
220        }}
221    }}
222}}
223\n""".format(color))
224
225def pov_water(f,water):
226    polygon = water['coords']
227    numpoints = len(polygon)
228    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
229    f.write("/* osm_id={0} */\n".format(water['osm_id']))
230
231    for i,point in enumerate(polygon):
232        x,y = point
233        if (i!=numpoints-1):
234            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
235        else:
236            f.write("  <{x}, {y}>\n".format(x=x,y=y))
237
238    color = waterwaytypes['riverbank'][0]
239
240    f.write("""
241    texture {{
242        pigment {{
243            color rgb {color}
244        }}
245        finish {{
246            ambient 1
247            /*specular 0.5
248            roughness 0.05
249            reflection 0.5*/
250        }}
251    }}
252}}
253\n""".format(color=color))
254
255def pov_globals(f):
256    globsettings = """
257#include "colors.inc"
258global_settings {{
259    assumed_gamma 2.0
260    noise_generator 2
261}}
262"""
263    f.write(globsettings.format())
264
265def pov_camera(f,osraydb):
266
267    bottom = osraydb.bottom
268    left = osraydb.left
269    top = osraydb.top
270    right = osraydb.right
271    map_size_x = right-left
272    map_size_y = top-bottom
273   
274    #print "map size x = ",map_size_x
275    #print "map size y = ",map_size_y
276   
277    #image_aspect = float(options['width'])/float(options['height'])
278    map_aspect = map_size_x/map_size_y
279
280    zoom = 1.0
281    zoom = map_size_y/zoom
282
283    f.write("""
284camera {{
285   orthographic
286   location <0, 10000, 0>
287   sky <0, 1, 0>
288   direction <0, 0, 1>
289   right <{aspect}*{zoom}, 0, 0>
290   up <0, 1*{zoom}*cos(radians({angle})), 0> /* this stretches in y to compensate for the rotate below */
291   look_at <0, 0, 0>
292   rotate <-{angle},0,0>
293   scale <1,1,1>
294   translate <{middle_x},0,{middle_z}>
295}}
296""".format(middle_x=avg(left,right),middle_z=avg(bottom,top),zoom=zoom,angle=10,aspect=map_aspect))
297    f.write("""
298/* ground */
299box {{
300    <{0}, -0.5, {1}>, <{2}, -0.0, {3}>
301    pigment {{
302        color rgb <1, 1, 1>
303    }}
304    finish {{
305        ambient 1
306    }}
307}}
308""".format(left,bottom,right,top))
309
310def create_ground_texture(osraydb,options,texturename):
311    f_ground = open(texturename, 'w')
312
313    pov_globals(f_ground)
314    pov_camera(f_ground,osraydb)
315
316    landuses = osraydb.select_landuse_areas()
317    for landuse in landuses:
318        pov_landuse(f_ground,landuse)
319
320    leisures = osraydb.select_leisure_areas()
321    for leisure in leisures:
322        pov_leisure(f_ground,leisure)
323
324    waterways = []
325    for waterwaytype in waterwaytypes.iterkeys():
326        waterways += osraydb.select_waterway(waterwaytype)
327    for waterway in waterways:
328        pov_waterway(f_ground,waterway)
329
330    waters = osraydb.select_naturalwater()
331    for water in waters:
332        pov_water(f_ground,water)
333
334    f_ground.close()
335
336    print "--> povray texture"
337    image_dimension_parameters = "-W"+str(options['width'])+" -H"+str(options['height'])
338    result = commands.getstatusoutput('povray -Iscene-osray-landuse-texture.pov -UV '+image_dimension_parameters+' +Q4 +A')
339    print "--> povray texture=",result[1]
340
Note: See TracBrowser for help on using the repository browser.