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

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

tuning

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