author | Radek Brich <radek.brich@devl.cz> |
Wed, 19 Aug 2009 09:18:29 +0200 | |
branch | pyrit |
changeset 101 | 50a994a57849 |
parent 97 | 2a853d284a6a |
permissions | -rwxr-xr-x |
97
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
from pyrit import * |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
from lworeader import LoadLightwaveLwoFile |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
from plyreader import LoadStanfordPlyFile |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
from math import * |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
from time import time |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
rt = Raytracer() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
top = KdTree() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
rt.setTop(top) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
rt.setBgColour((0.2,0.3,0.8)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
cam = Camera(eye=(-8,3,4),lookat=(0,-0.5,1)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
rt.setCamera(cam) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
carmodel = "../models/lwo/Nissan300ZX.lwo" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
bunnymodel = "../models/ply/bunny/bun_zipper.ply" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
print "Loading file", carmodel |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
facenum = LoadLightwaveLwoFile(rt, carmodel, scale=0.4) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
print "Loaded", facenum, "faces" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
matbunny = Material(colour=(0.4, 0.5, 0.9)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
matbunny.setTransmissivity(0.65, 1.3) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
matbunny.setReflectivity(0.3) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
matbunny.setSmooth(True) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
print "Loading file", bunnymodel |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
facenum = LoadStanfordPlyFile(rt, bunnymodel, |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
matbunny, scale=(20.0, 20.0, -20.0), trans=(-1,-1.8,3.5)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
print "Loaded", facenum, "faces" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
mat = Material(colour=(0.5, 0.5, 0.5)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
ground = Box(L=(-10,-2,-10), H=(10,-1.2,10), material=mat) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
rt.addShape(ground) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
lwall = Box(L=(-10,-2,-4), H=(10,10,-3), material=mat) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
rt.addShape(lwall) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
mat = Material(colour=(0.5, 0.5, 0.5)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
mat.setReflectivity(0.7) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
backwall = Box(L=(8,-2, -10), H=(10,10,10), material=mat) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
rt.addShape(backwall) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
45 |
light1 = Light(position=(-5.0, 20.0, 8.0), colour=(0.9, 0.9, 0.9)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
46 |
rt.addLight(light1) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
light2 = Light(position=(5.0, 10.0, 10.0), colour=(0.9, 0.7, 0.7)) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
rt.addLight(light2) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
t1 = time() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
51 |
top.optimize() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
t2 = time() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
print "kd-tree built in", (t2-t1), "s" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
sampler = DefaultSampler(1024, 768) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
sampler.setOversample(1) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
rt.setSampler(sampler) |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
t1 = time() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
rt.render() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
t2 = time() |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
print "rendered in", (t2-t1), "s" |
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
|
2a853d284a6a
added bench.py demo which prints tree build and render times
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
sampler.getPixmap().writePNG('bench.png') |