source: subversion/applications/rendering/parking/osray/osray.py @ 22439

Revision 22439, 7.8 KB checked in by kdrangmeister, 4 years ago (diff)

tuning; amenity=parking

Line 
1# -*- coding: utf-8 -*-
2# by kay drangmeister
3
4import sys
5import commands
6import psycopg2
7import csv
8import re
9import string
10from numpy import *
11from osray_db import *
12from osray_ground import *
13from osray_streets import *
14from osray_buildings import *
15from osray_furniture import *
16from optparse import OptionParser
17
18Radiosity = True
19gutter_factor = 1.2
20
21def pov_globals(f):
22    if Radiosity:
23        globsettings = """
24#include "colors.inc"
25global_settings {{
26    assumed_gamma 1.0
27    noise_generator 2
28
29    ambient_light rgb <0.1,0.1,0.1>
30    radiosity {{
31        count 30
32        error_bound 0.01
33        recursion_limit 3
34        pretrace_end 0.0005
35        brightness 1
36    }}
37}}
38"""
39    else:
40        globsettings = """
41#include "colors.inc"
42global_settings {{
43    assumed_gamma 2.0
44    noise_generator 2
45    ambient_light rgb <0.8,0.8,0.8>
46    max_trace_level 10
47}}
48"""
49    f.write(globsettings.format())
50
51def pov_camera(f,osraydb,options):
52
53    bottom = float(osraydb.bottom)
54    left = float(osraydb.left)
55    top = float(osraydb.top)
56    right = float(osraydb.right)
57    map_size_x = right-left
58    map_size_y = top-bottom
59    middle_x = avg(left,right)
60    middle_y = avg(bottom,top)
61
62    print "map size x = ",map_size_x
63    print "map size y = ",map_size_y
64   
65    image_aspect = float(options['width'])/float(options['height'])
66    map_aspect = map_size_x/map_size_y
67
68    isometric_angle = 20 # in °
69    zoom = gutter_factor
70    zoom = map_size_y/zoom
71
72    f.write("""
73camera {{
74   orthographic
75   location <0, 10000, 0>
76   sky <0, 1, 0>
77   direction <0, 0, 1>
78   right <{aspect}*{zoom}, 0, 0>
79   up <0, 1*{zoom}*cos(radians({angle})), 0> /* this stretches in y to compensate for the rotate below */
80   look_at <0, 0, 0>
81   rotate <-{angle},0,0>
82   scale <1,1,1>
83   translate <{middle_x},0,{middle_y}>
84}}
85""".format(middle_x=middle_x,middle_y=middle_y,zoom=zoom,angle=isometric_angle,aspect=map_aspect))
86    if Radiosity:
87        ground_finish = """
88    finish {
89        diffuse 0.7
90        ambient 0.0
91    }
92"""       
93    else:
94        ground_finish = """
95    finish {
96        specular 0.5
97        roughness 0.05
98        ambient 0.2
99    }
100"""
101    f.write("""
102/* ground */
103box {{
104    <{left}, -0.5, {bottom}>, <{right}, -0.2, {top}>
105    texture {{
106        pigment {{
107            /* color rgb <1, 1, 1> */
108            image_map {{
109                png "scene-osray-landuse-texture.png"
110                map_type 0
111                interpolate 2
112            }}
113        }}
114        rotate <90,0,0>
115        scale <{xs},1,{ys}>
116        translate <{left},0,{bottom}>
117    }}
118    {finish}
119}}
120/* sky */
121sky_sphere {{
122    pigment {{
123        gradient y
124        color_map {{
125/*
126            [ 0.5 color rgb <0.5,0.6,0.6> ]
127            [ 1.0 color rgb <0.5,0.5,0.6> ]
128*/
129            [ 0.5 color rgb <0.12,0.12,0.12> ]
130            [ 1.0 color rgb <0.1,0.1,0.1> ]
131        }}
132        scale 20000
133        translate -10
134    }}
135}}
136""".format(left=left,bottom=bottom,right=right,top=top,xs=map_size_x,ys=map_size_y,finish=ground_finish))
137
138    #f.write("""light_source {{ <{0}, 50000, {1}>, rgb <0.5, 0.5, 0.5> }}\n""".format(avg(left*1.5,right*0.5),avg(bottom*1.5,top*0.5)))
139    #f.write("""light_source {{ <{0}, 5000, {1}>, rgb <0.5, 0.5, 0.5> }}\n""".format(avg(left*0.5,right*1.5),avg(bottom*1.5,top*0.5)))
140    #f.write("""light_source {{ <300000+{0}, 1000000, -1000000+{1}>, rgb <1, 1, 1> fade_power 0 }}\n""".format(avg(left,right),avg(bottom,top)))
141    if Radiosity:
142        arealight_sun = ""
143        arealight_sky = ""
144        if options['hq']:
145            arealight_sun = """    area_light <100000, 0, 0>, <0, 0, 100000>, 3, 3
146    adaptive 1
147    circular
148"""
149            arealight_sky = """    area_light <1000000, 0, 0>, <0, 0, 1000000>, 3, 3
150    adaptive 1
151    circular
152"""
153        f.write("""
154/* The Sun */
155light_source {{
156    <0, 1000000,0>,
157    rgb <1, 1, 0.9>
158    fade_power 0
159    {arealight}
160    rotate <45,10,0>
161    translate <{middle_x},0,{middle_y}>
162}}
163\n""".format(middle_x=middle_x,middle_y=middle_y,arealight=arealight_sun))
164        f.write("""
165/* Sky blue */
166light_source {{
167    <0, 1000000,0>,
168    rgb <0.1, 0.1, 0.2>
169    fade_power 0
170    {arealight}
171    translate <{middle_x},0,{middle_y}>
172}}
173\n""".format(middle_x=middle_x,middle_y=middle_y,arealight=arealight_sky))
174    else:
175        arealight_sun = ""
176        arealight_sky = ""
177        if options['hq']:
178            arealight_sun = """    area_light <100000, 0, 0>, <0, 0, 100000>, 6, 6
179    adaptive 1
180    circular
181"""
182            arealight_sky = """    area_light <1000000, 0, 0>, <0, 0, 1000000>, 6, 6
183    adaptive 1
184    circular
185"""
186        f.write("""
187/* The Sun */
188light_source {{
189    <0, 1000000,0>,
190    rgb <1, 1, 0.9>
191    fade_power 0
192    {arealight}
193    rotate <45,10,0>
194    translate <{middle_x},0,{middle_y}>
195}}
196\n""".format(middle_x=middle_x,middle_y=middle_y,arealight=arealight_sun))
197        f.write("""
198/* Sky blue */
199light_source {{
200    <0, 1000000,0>,
201    rgb <0.2, 0.2, 0.22>
202    fade_power 0
203    {arealight}
204    translate <{middle_x},0,{middle_y}>
205}}
206\n""".format(middle_x=middle_x,middle_y=middle_y,arealight=arealight_sky))
207
208    left,bottom,right,top = scale_coords(left,bottom,right,top,1.1)
209    f.write("""
210#declare boundbox = box {{
211    <0, -1, 0>, <1, 1, 1>
212    scale <{sizex},50,{sizey}>
213    translate <{left},0,{bottom}>
214}}
215""".format(left=left,bottom=bottom,right=right,top=top,sizex=right-left,sizey=top-bottom))
216
217def main(options):
218    print "In main(). Options: ",options
219
220    bbox = options['bbox']
221    bbox = scale_bbox(bbox,gutter_factor)
222    options['bbox']=bbox
223
224    create_textures = not(options['quick'])
225    osraydb = OsrayDB(options)
226
227    f = open('/home/kayd/workspace/Parking/osray/scene-osray.pov', 'w')
228
229    pov_globals(f)
230    pov_camera(f,osraydb,options)
231   
232    if create_textures:
233        create_ground_texture(osraydb,options,'/home/kayd/workspace/Parking/osray/scene-osray-landuse-texture.pov')
234        #pass
235   
236    render_highways(f,osraydb,options)
237    render_buidings(f,osraydb,options)
238    render_furniture(f,osraydb,options)
239    f.close()
240   
241    command = 'povray'
242    image_parameter = '-Iscene-osray.pov'
243    image_dimension_parameters = "-W"+str(options['width'])+" -H"+str(options['height'])
244    if options['hq']==True:
245        antialiasing_parameters = '+A0.1 +AM2 +R3 -J'
246        misc_parameters = '+UV +Q9'
247    else:
248        antialiasing_parameters = '-A'
249        misc_parameters = '+UV +Q4'
250    commandline = string.join([command,image_parameter,image_dimension_parameters,antialiasing_parameters,misc_parameters])
251    result = commands.getstatusoutput(commandline)
252    print result[1]
253    osraydb.shutdown()
254
255if __name__ == "__main__":
256    parser = OptionParser()
257    parser.add_option("-d", "--dsn", dest="dsn", help="database name and host (e.g. 'dbname=gis')", default="dbname=gis")
258    parser.add_option("-p", "--prefix", dest="prefix", help="database table prefix (e.g. 'planet_osm')", default="planet_osm")
259    parser.add_option("-q", "--quick", action="store_true", dest="quick", default=False, help="don't generate textures, but use existing ones")
260    parser.add_option("-b", "--bbox", dest="bbox", help="the bounding box as string ('9.94861 49.79293,9.96912 49.80629')", default="9.94861 49.79293,9.96912 49.80629")
261    parser.add_option("-H", "--height", dest="height", help="image height in pixels", default="768", type='int')
262    parser.add_option("-W", "--width", dest="width", help="image width in pixels", default="1024", type='int')
263    parser.add_option("-Q", "--high-quality", action="store_true", dest="hq", default=False, help="high quality rendering")
264    parser.add_option("-R", "--radiosity", action="store_true", dest="radiosity", default=False, help="radiosity rendering")
265    (options, args) = parser.parse_args()
266    #if options.a and options.b:
267    #    parser.error("options -a and -b are mutually exclusive")
268    print options
269    main(options.__dict__)
270    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.