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

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

tuned leisure colors

File size: 7.8 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
98    polygon = landuse['coords']
99
100    numpoints = len(polygon)
101    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
102    f.write("/* osm_id={0} */\n".format(landuse['osm_id']))
103
104    for i,point in enumerate(polygon):
105        x,y = point
106        if (i!=numpoints-1):
107            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
108        else:
109            f.write("  <{x}, {y}>\n".format(x=x,y=y))
110
111    color = landuseparams[0]
112
113    f.write("""
114    texture {{
115        pigment {{
116            color rgb {0}
117        }}
118        finish {{
119            ambient 1
120            /*specular 0.5
121            roughness 0.05
122            reflection 0.5*/
123        }}
124    }}
125}}
126\n""".format(color))
127    if landusetype in landusetypes:
128        pass
129    else:
130        pov_text(f,x,y,landusetype)
131
132#-----------------------------------------------------------------------------
133
134leisuretypes = {
135    'park':['<0.7,1,0.6>'],'common':['<0.7,1,0.6>'],
136    'pitch':['<0.3,1,0.8>'],'sports_centre':['<0.3,1,0.8>'],
137    'track':['<0.9,0.7,0.6>'],
138    'playground':['<0.2,0.9,0.9>'],
139    'garden':['<1,1,0.1>'],
140    'unknown':['<1,0,1>']
141    }
142
143def pov_leisure(f,leisure):
144    leisuretype = leisure['leisure']
145    if leisuretype in leisuretypes:
146        leisureparams = leisuretypes.get(leisuretype)
147    else:
148        leisureparams = leisuretypes.get('unknown')
149
150    polygon = leisure['coords']
151
152    numpoints = len(polygon)
153    f.write("prism {{ linear_spline  0, 0.02, {0},\n".format(numpoints))
154    f.write("/* osm_id={0} */\n".format(leisure['osm_id']))
155
156    for i,point in enumerate(polygon):
157        x,y = point
158        if (i!=numpoints-1):
159            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
160        else:
161            f.write("  <{x}, {y}>\n".format(x=x,y=y))
162
163    color = leisureparams[0]
164
165    f.write("""
166    texture {{
167        pigment {{
168            color rgb {0}
169        }}
170        finish {{
171            ambient 1
172            /*specular 0.5
173            roughness 0.05
174            reflection 0.5*/
175        }}
176    }}
177}}
178\n""".format(color))
179    if leisuretype in leisuretypes:
180        pass
181    else:
182        pov_text(f,x,y,leisuretype)
183
184#-----------------------------------------------------------------------------
185
186waterwaytypes = {
187    'riverbank':['<0.2,0.2,0.9>'],
188    'dock':['<0.2,0.2,0.8>']
189    }
190
191def pov_waterway(f,waterway):
192    waterwaytype = waterway['waterway']
193    waterwayparams = waterwaytypes.get(waterwaytype)
194
195    polygon = waterway['coords']
196    numpoints = len(polygon)
197    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
198    f.write("/* osm_id={0} */\n".format(waterway['osm_id']))
199
200    for i,point in enumerate(polygon):
201        x,y = point
202        if (i!=numpoints-1):
203            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
204        else:
205            f.write("  <{x}, {y}>\n".format(x=x,y=y))
206
207    color = waterwayparams[0]
208
209    f.write("""
210    texture {{
211        pigment {{
212            color rgb {0}
213        }}
214        finish {{
215            ambient 1
216            /*specular 0.5
217            roughness 0.05
218            reflection 0.5*/
219        }}
220    }}
221}}
222\n""".format(color))
223
224def pov_water(f,water):
225    polygon = water['coords']
226    numpoints = len(polygon)
227    f.write("prism {{ linear_spline  0, 0.01, {0},\n".format(numpoints))
228    f.write("/* osm_id={0} */\n".format(water['osm_id']))
229
230    for i,point in enumerate(polygon):
231        x,y = point
232        if (i!=numpoints-1):
233            f.write("  <{x}, {y}>,\n".format(x=x,y=y))
234        else:
235            f.write("  <{x}, {y}>\n".format(x=x,y=y))
236
237    color = waterwaytypes['riverbank'][0]
238
239    f.write("""
240    texture {{
241        pigment {{
242            color rgb {color}
243        }}
244        finish {{
245            ambient 1
246            /*specular 0.5
247            roughness 0.05
248            reflection 0.5*/
249        }}
250    }}
251}}
252\n""".format(color=color))
253
254def pov_globals(f):
255    globsettings = """
256#include "colors.inc"
257global_settings {{
258    assumed_gamma 2.0
259    noise_generator 2
260}}
261"""
262    f.write(globsettings.format())
263
264def pov_camera(f,osraydb):
265
266    bottom = osraydb.bottom
267    left = osraydb.left
268    top = osraydb.top
269    right = osraydb.right
270    map_size_x = right-left
271    map_size_y = top-bottom
272   
273    print "map size x = ",map_size_x
274    print "map size y = ",map_size_y
275   
276    #image_aspect = float(options['width'])/float(options['height'])
277    map_aspect = map_size_x/map_size_y
278
279    zoom = 1.0
280    zoom = map_size_y/zoom
281
282    f.write("""
283camera {{
284   orthographic
285   location <0, 10000, 0>
286   sky <0, 1, 0>
287   direction <0, 0, 1>
288   right <{aspect}*{zoom}, 0, 0>
289   up <0, 1*{zoom}*cos(radians({angle})), 0> /* this stretches in y to compensate for the rotate below */
290   look_at <0, 0, 0>
291   rotate <-{angle},0,0>
292   scale <1,1,1>
293   translate <{middle_x},0,{middle_z}>
294}}
295""".format(middle_x=avg(left,right),middle_z=avg(bottom,top),zoom=zoom,angle=10,aspect=map_aspect))
296    f.write("""
297/* ground */
298box {{
299    <{0}, -0.5, {1}>, <{2}, -0.0, {3}>
300    pigment {{
301        color rgb <1, 1, 1>
302    }}
303    finish {{
304        ambient 1
305    }}
306}}
307""".format(left,bottom,right,top))
308
309def create_ground_texture(osraydb,options,texturename):
310    f_ground = open(texturename, 'w')
311
312    pov_globals(f_ground)
313    pov_camera(f_ground,osraydb)
314
315    landuses = osraydb.select_landuse_areas()
316    for landuse in landuses:
317        pov_landuse(f_ground,landuse)
318
319    leisures = osraydb.select_leisure_areas()
320    for leisure in leisures:
321        pov_leisure(f_ground,leisure)
322
323    waterways = []
324    for waterwaytype in waterwaytypes.iterkeys():
325        waterways += osraydb.select_waterway(waterwaytype)
326    for waterway in waterways:
327        pov_waterway(f_ground,waterway)
328
329    waters = osraydb.select_naturalwater()
330    for water in waters:
331        pov_water(f_ground,water)
332
333    f_ground.close()
334
335    print "--> povray texture"
336    image_dimension_parameters = "-W"+str(options['width'])+" -H"+str(options['height'])
337    result = commands.getstatusoutput('povray -Iscene-osray-landuse-texture.pov -UV '+image_dimension_parameters+' +Q4 +A')
338    print "--> povray texture=",result[1]
339
Note: See TracBrowser for help on using the repository browser.