demos/demo_PIL.py
author Radek Brich <radek.brich@devl.cz>
Sat, 10 May 2008 14:29:37 +0200
branchpyrit
changeset 95 ca7d4c665531
parent 90 f6a72eb99631
child 96 9eb71e76c7fd
permissions -rwxr-xr-x
build script fixes, add ldflags build option update and enhance demos fix bug in 4x grid oversampling warn if writePNG called while compiled without libpng make shapes in ShapeList const and add many other const needed due to snowball effect slightly optimize Camera::makeRayPacket using _mm_shuffle_ps make Vector SIMD vectorization disabled by default (causes problems) fix bug in implicit reflection of transmissive surfaces, when surface's reflection parameter is set to zero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
90
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from pyrit import *
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import Image
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
rt = Raytracer()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
top = KdTree()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
rt.setTop(top)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
rt.setCamera(Camera())
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
light1 = Light(position=(0.0, 5.0, -5.0), colour=(0.7, 0.3, 0.6))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
rt.addLight(light1)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
light2 = Light(position=(-2.0, 10.0, -2.0), colour=(0.4, 0.6, 0.3))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
rt.addLight(light2)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
mat0 = Material(colour=(0.7, 0.7, 0.7))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
box = Box(L=(-20.0, -1.2, -20.0), H=(20.0, -1.0, 20.0), material=mat0)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
rt.addShape(box)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
mat1 = Material(colour=(1.0, 0.0, 0.0))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
bigsphere = Sphere(centre=(3.0, 2.0, -7.0), radius=3.0, material=mat1)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
rt.addShape(bigsphere)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
mat2 = Material(colour=(0.0, 1.0, 0.0))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
smallsphere = Sphere(centre=(-5.5, 1.5, -8.0), radius=2.0, material=mat2)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
rt.addShape(smallsphere)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
mat3 = Material(colour=(0.0, 0.0, 1.0))
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
tinysphere = Sphere(centre=(-1.2, 0.0, -2.0), radius=0.5, material=mat3)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
rt.addShape(tinysphere)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
top.optimize()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
imagesize = (800, 600)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
sampler = DefaultSampler(imagesize)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
rt.setSampler(sampler)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
rt.render()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
pixmap = sampler.getPixmap()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
data = pixmap.getCharData()
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
img = Image.fromstring("RGB", imagesize, data)
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
img.save('demo_PIL.png')